-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.s
executable file
·240 lines (214 loc) · 4.65 KB
/
page.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
******************************************************************************************
*
* Primary page controller.
* ========================================================================================
*
******************************************************************************************
SetupPage
jsr TEXT ; ensure we are out of graphics modes as application has some!
jsr PRINT ; position cursor on bottom line
dfb _HOME
dfb 23,$8D
dfb _CLREOL
dfb $00
ldx #_init ; vector offset
jsr _VCALL
ror noscroll ; set flag based on C
sty maxlines
sta maxlines+1
stz topline
stz topline+1
DrawPage
jsr PRINT ; Clear and then draw the content area
dfb _HOME,$8d,$8d,0
; If we aren't scrolling, call _display vector ONCE and then handle keyboard.
bit noscroll
bpl :scroll
lda #0
tay
ldx #_display
jsr _VCALL
jmp KeyboardWait
; We are scrolling, for each line, redraw it
:scroll lda #0
:loop pha
clc
adc topline
sta printline
lda topline+1
adc #0
sta printline+1
cmp maxlines+1
blt :drwlin
lda printline
cmp maxlines
bge :erase
:drwlin lda printline+1
ldy printline
ldx #_display
jsr _VCALL
bra :incr
:erase jsr PRINT
dfb _CLREOL,$8D,0
:incr pla
inc
cmp #PAGELEN
blt :loop
; Handle all keyboard interactions
KeyboardWait
lda KEYBOARD
bpl KeyboardWait
; Uppercase the if it's A-Z
cmp #"a"
blt :goodky
cmp #"z"+1
bge :goodky
and #$df ; uppercase mask
:goodky sta KEYCLEAR
bit OpenApple
bpl :keys
; OpenApple handler
jsr SetScreen
bcs :oakeys
jsr CLRSCRN
jmp SetupPage
; Standard open-apple keys that are always available
:oakeys jsr HandleKey
MenuKey "Q";:Quit
MenuKey "*";:Mon
dfb 0
; Open-Apple arrow keys only if scrolling is enabled
bit noscroll
bmi :local0
jsr HandleKey
MenuKey UpArrow;:PgUp
MenuKey DownArrow;:PgDn
dfb 0
:local0 jmp :local
; Normal key handler (only when scrolling)
:keys bit noscroll
bmi :local0
jsr HandleKey
MenuKey UpArrow;:Up
MenuKey DownArrow;:Down
dfb 0
jmp :local
; OA-Up
:PgUp ldy #15
:uploop jsr :up1
dey
bne :uploop
beq :back ; always
; OA-Down
:PgDn ldy #15
:dnloop jsr :down1
dey
bne :dnloop
beq :back ; always
; OA-Q
:Quit jsr PRODOSMLI
dfb _MLIQUIT
da QUITPARM
:back jmp DrawPage ; fall through and common return
; OA-*
:Mon jsr PRINT
asc _CLS,"Press CTRL-Y to re-enter AFScanner.",$8D,$00
jmp MONITOR
; Up
:Up jsr :up1
jmp DrawPage
; Down
:Down jsr :down1
jmp DrawPage
; "Local" subroutines
; if topline+PAGELEN >= maxlines then return
; topline = topline + 1
:down1 clc
lda topline
adc #PAGELEN
sta printline
lda printline+1
adc #0
sta printline+1
cmp maxlines+1
bcc :minus1
lda printline
cmp maxlines
bge :rts
:minus1 inc topline
bne :rts
inc topline+1
rts
; if topline = 0 then return
; topline = topline - 1
:up1 lda topline
ora topline+1
beq :rts ; already = 0
sec
lda topline
sbc #1
sta topline
lda topline+1
sbc #0
sta topline+1
:rts rts
:local ldx #_keypress
; Fall through and JMP to _keypress which takes control for local page keys
* Simple vector call from ZP based on X register
_VCALL jmp: ($00,x) ; Merlin32 needs to know 16 bit JMP, ":" does that
* Handle screen change - both called by app init and normal keyboard handler
SetScreen
ldx #0
:next bit :data,x
bpl :notf
cmp :data,x
beq :setup
pha
txa
clc
adc #7
tax
pla
bra :next
:notf sec ; Not found
rts
:setup ldy #0
:copy inx
lda :data,x
sta _init,y
iny
cpy #6
bne :copy
clc
rts
*
* Data per page: Apple ASCII, Initialization, Display, Keypress (7 bytes)
*
* Definitions:
* - BYTE = Character to match on, case insensitive
* - ADDR = Initialize routine (load track, calculate lookup tables, etc).
* Return:
* A:Y for number of lines,
* Carry: Set = no scrolling (graphics, form, etc), Clear = scrolling.
* Note: Initialization should also display 24th line for the page.
* (Cursor is there and line is clear.)
* - ADDR = Display routine. Called with A:Y for line number. Should end with $8D and is
* responsible for clearing the line.
* - ADDR = Keypress handler. NOT A SUBROUTINE. This routine has a number of entry
* points it might call. KeyboardWait for another keypress or SetupPage to
* reinitialize and redraw.
*
:data
dfb "A"
da AboutInit, AboutDisplay, AboutKeypress
dfb "F"
da FieldInit, FieldDisplay, FieldKeypress
dfb "B"
da BrowseInit, BrowseDisplay, BrowseKeypress
dfb "G"
da HgrInit, HgrDisplay, HgrKeypress
dfb "C"
da CountInit, CountDisplay, CountKeypress
dfb "T"
da TestInit, TestDisplay, TestKeypress
dfb 0 ; end