aboutsummaryrefslogtreecommitdiff
path: root/console.s
blob: b02403d840be4578407313faf17bf7814e47c9d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119


 .include "atari.inc"
 .export _clrtobot, _clrtoeol, _clr_screen, _clrtoline, _cspaces, _cblank, _backspace
 .export _rvs_on, _rvs_off

 .import mul40        ; from cc65's runtime
 .importzp tmp3       ; ditto
 .import _revflag     ; conio/revers.s
 .import bump_destptr ; these two are
 .importzp destptr    ; from draw_lorcha.s
 .import _cspace

 .ifdef CART_TARGET
  .segment "HIGHCODE"
 .else
  .code
 .endif


; void clr_screen(void);
; void clrtobot(void);
; void clrtoeol(void);
; void clrtoline(unsigned char line);

; this stuff doesn't disturb conio's (and the OS's) idea of the
; current cursor position. It's *way* faster than writing them in
; C in terms of cclear() (which uses one cputc() call per blank).

_clr_screen: ; same as gotoxy(0,0); clrtobot();
 lda #0
 sta ROWCRS
 sta COLCRS

_clrtobot: ; same as clrtoline(24);
 lda #24
 bne _clrtoline

_clrtoeol:
 lda ROWCRS
 ; fall through to _clrtoline

_clrtoline:
 sta tmp3 ; stash our arg

 ;lda #0
 ;sta OLDCHR ; stop conio from redrawing stuff after we clear it,
             ; no longer needed with our custom conio.

 ; setup destptr to start of current line, NOT
 ; current cursor position.
 lda ROWCRS
 jsr mul40  ; AX = A*40 (addr of start-of-row)
 clc
 adc SAVMSC ; add AX to screen pointer
 sta destptr
 txa
 adc SAVMSC+1
 sta destptr+1

 ; X = current row, Y = current column. Stop clearing a line when Y == 40,
 ; we're done when X == 24. Apologies, the names X and Y are backwards
 ; compared to proper Cartesian coordinates.
 ldx ROWCRS
 ldy COLCRS
 lda #0

clrloop:
 sta (destptr),y ; blank a character (A == 0, screen code for a space)
 iny
 cpy #40
 bne clrloop
 ldy #0
 inx
 cpx tmp3
 bcs done

 jsr bump_destptr
 lda #0
 tay
 beq clrloop

done:
 rts

_cspaces:
 sta tmp3
@lp:
 jsr _cspace
 dec tmp3
 bne @lp
 rts

_backspace:
 dec COLCRS
 lda #1
 ; fall through to _cblank

_cblank:
 tax
 lda COLCRS
 pha
 lda ROWCRS
 pha
 txa
 jsr _cspaces
 pla
 sta ROWCRS
 pla
 sta COLCRS
 rts

_rvs_on:
 lda #$80
 .byte $2c ; BIT absolute opcode
_rvs_off:
 lda #0
 sta _revflag
 rts