]> git.sur5r.net Git - cc65/blob - libsrc/geos/conio/cputc.s
cr/lf hell fixed
[cc65] / libsrc / geos / conio / cputc.s
1
2 ;
3 ; Maciej 'YTM/Elysium' Witkowiak
4 ;
5 ; 27.10.2001
6 ; 06.03.2002
7
8 ; void cputcxy (unsigned char x, unsigned char y, char c);
9 ; void cputc (char c);
10
11             .export _cputcxy, _cputc, update_cursor
12
13             .import _gotoxy, fixcursor
14             .import popa
15             .import xsize,ysize
16             .importzp cursor_x, cursor_y, cursor_c, cursor_r
17
18             .include "../inc/const.inc"
19             .include "../inc/geossym.inc"
20             .include "../inc/jumptab.inc"
21
22 _cputcxy:
23         pha                     ; Save C
24         jsr     popa            ; Get Y
25         jsr     _gotoxy         ; Set cursor, drop x
26         pla                     ; Restore C
27
28 ; Plot a character - also used as internal function
29
30 _cputc:
31         tax                     ; save character
32 ; some characters are not safe for PutChar
33         cmp     #$20
34         bcs     L1
35         cmp     #CR
36         beq     do_cr
37         cmp     #LF
38         beq     do_lf
39         cmp     #$1d
40         bne     L00
41         ldx     #BACKSPACE
42         sec
43         bcs     L2
44 L00:    cmp     #ESC_GRAPHICS
45         beq     L0
46         cmp     #ESC_RULER
47         beq     L0
48         cmp     #GOTOX
49         beq     L0
50         cmp     #GOTOY
51         beq     L0
52         cmp     #GOTOXY
53         beq     L0
54         cmp     #NEWCARDSET
55         beq     L0
56         cmp     #$1e
57         bne     L1
58 L0:     rts
59
60 L1:     clc
61 L2:     php
62         lda     cursor_x
63         sta     r11L
64         lda     cursor_x+1
65         sta     r11H
66         lda     cursor_y
67         sta     r1H
68         txa
69         jsr     PutChar
70         plp
71         bcs     update_cursor
72
73         inc     cursor_c
74         lda     cursor_c
75         cmp     xsize                   ; hit right margin?
76         bne     update_cursor
77         lda     #0                      ; yes - do cr+lf
78         sta     cursor_c
79 do_lf:  inc     cursor_r
80         lda     cursor_r
81         cmp     ysize                   ; hit bottom margin?
82         bne     update_cursor
83         dec     cursor_r                ; yes - stay in the last line
84
85 update_cursor:
86         jsr     fixcursor
87         lda     cursor_x
88         sta     r4L
89         lda     cursor_x+1
90         sta     r4H
91         lda     cursor_y
92         sec
93         sbc     curHeight
94         sta     r5L
95         lda     #1              ; update cursor prompt position
96         sta     r3L
97         jmp     PosSprite
98
99 do_cr:  lda     #0
100         sta     cursor_c
101         beq     update_cursor
102