-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.s
executable file
·189 lines (175 loc) · 3.84 KB
/
util.s
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
******************************************************************************************
*
* Utility routines
* ========================================================================================
*
******************************************************************************************
* Setup the data buffer
SETUPDATA LDA #>DATASTART
STA DATA+1
LDA #<DATASTART
STA DATA
LDA #>DATALEN
STA TEMP ; number of pages to load
RTS
* Print identifier and 4 and 4 encoded number
* Acc = character
* Output = " ?=" where ? is char in Acc
PRDATA PHA
LDA #" "
JSR COUT
PLA
JSR COUT
LDA #"="
JSR COUT
LDA (DATA),Y
SEC
ROL
INY
AND (DATA),Y
JMP PRHEX
* Output routine uses simple RLE type encoding
* High bit set = character;
* High bit clear =
* $00 = exit
* $01 = print byte from address
* $02-$7F = repeat next character
*
* There are two entry points:
* - PRINT = inline text being printed out; implicit PTR increment at start
* - PRINTP = print address passed in AX; no implicit PTR increment at start
PRINT PLA
STA PTR
PLA
STA PTR+1
JSR :MORE
LDA PTR+1
PHA
LDA PTR
PHA
RTS
PRINTP STA PTR+1
STX PTR
BRA :START
:MORE JSR INCPTR
:START LDX #1 ; Assume 1 char to be output
LDA (PTR)
BEQ :EXIT
BMI :SINGLE
CMP #1
BNE :REPEAT
JSR INCPTR
LDA (PTR)
STA PTR2
JSR INCPTR
LDA (PTR)
STA PTR2+1
LDA (PTR2)
JSR PRHEX
BRA :MORE
:REPEAT TAX
JSR INCPTR
LDA (PTR)
:SINGLE JSR COUT
DEX
BNE :SINGLE
BEQ :MORE
:EXIT RTS
INCPTR INC PTR
BNE :EXIT
INC PTR+1
:EXIT RTS
* Clear the data portion of the screen
* (Lines 3-22) and reposition to line 3.
CLRSCRN LDA #_HOME
JSR COUT
JSR PRCR
LDY #20
:1 JSR PRCR ; next line
LDA #_CLREOL
JSR COUT
DEY
BNE :1
LDA #_HOME
JSR COUT
JSR PRCR ; move to row 3
JMP PRCR
* Read a byte
* If invalid, carry is set (anything NOT 0-9,A-F is invalid)
READBYTE JSR READHEX
BCS :EXIT
ASL
ASL
ASL
ASL
STA TEMP
JSR READHEX ; carry falls through to exit
ORA TEMP
:EXIT RTS
READHEX JSR GETCH
JSR COUT
CMP #"9"+1
BCC :NUMERIC
CMP #"F"+1
BCC :ALPHA
:BAD SEC
RTS
:NUMERIC SEC
SBC #"0"
BVS :BAD
:GOOD CLC
RTS
:ALPHA SEC
SBC #"A"
BVS :BAD
ADC #10
:GOOD2 CLC
RTS
* ProDOS QUIT parameter tables
QUITPARM DFB 4 ; 4 parameters
DFB 0 ; 0 is the only quit type
DA 0 ; reserved
DFB 0 ; reserved
DA 0 ; reserved
; On entry:
; Acc = keypress
; Stack = address of table (format: key address key address 0)
; Will not return if key found, a JMP will be performed.
; If not found, return with carry set.
HandleKey
sta TEMP
pla
sta PTR
pla
sta PTR+1
ldy #0
:next
iny
lda (PTR),y
bpl :notFound
cmp TEMP
beq :jmp
iny
iny
bra :next
; Jump to keypress handler
:jmp iny
lda (PTR),y
sta PTR2
iny
lda (PTR),y
sta PTR2+1
jmp (PTR2)
; Not found - return to caller (Y + PTR = return address - 1)
:notFound
clc
tya
adc PTR
tax
lda #0
adc PTR+1
pha
phx
lda TEMP
sec
rts