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