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