-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1.asm
528 lines (476 loc) · 6.64 KB
/
p1.asm
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
textmem = $8000
curcol = $8100
currow = $8102
keymem = $8104
buffer = $8106
#define WAIT rst 8
.org $00
jp startup
.org $08
jp delay
.org $10
jp putstring
.org $18
jp Display
.org $20
jp putchar
.org $28
jp puthex
.org $30
jp getk
.org $38
jp startup
.org $53
jp startup
.db $5A,$A5 ; thanks moody
.org $0064
.db "Vera OS",0
.db "TI-83 Plus",0
startup:
di
ld sp,$FFF8
ld a,0
out (0),a
ld a,$ff
out (1),a
ld a,$08
out (3),a
ld a,0
out (3),a
ld a,$08
out (3),a
ld a,6
out (4),a
ld a,0
out (6),a
ld a,$41
out (7),a
WAIT
ld a,00
out ($10),a
WAIT
ld a,3
out ($10),a
WAIT
ld a,5
out ($10),a
WAIT
ld a,8
out ($10),a
WAIT
ld a,$10
out ($10),a
WAIT
ld a,$18
out ($10),a
WAIT
ld a,$40
out ($10),a
WAIT
ld a,$f0
out ($10),a
WAIT
ld hl,$8000
ld (hl),0
ld de,$8001
ld bc,$7fff
ldir
ld hl,$8000
ld (hl),$20
ld de,$8001
ld bc,$7f
ldir
ld hl,welcome_str
call putstring
call newline
jp CLI_start
welcome_str:
; 1234567890123456
.db " Welcome to ",255
.db " ",248,242,243,244,245,246,247,248,$0a
.db "A calclover's OS",0
; ========================
; Command line interface
; ========================
CLI_start:
loop:
ld a,'>'
call putchar
ld a,(curcol)
inc a
ld (curcol),a
ld a,' '
call putchar
ld a,(curcol)
inc a
ld (curcol),a
call Display
call readPrompt ; Reads user input, stores in buffer
call newline
call parse ; Parses string in buffer
jp loop
; ========================
; Text input routine
; ========================
readPrompt:
ld hl,buffer
push hl
readPrompt_waitKey:
call getk ; Get a key
or a
jr z,readPrompt_waitKey
cp 9 ; Is it Enter?
jp nz,evalKey
pop hl
ld (hl),0
ret ; Then return
evalKey:
call mapGetkToAscii
or a
jp z,readPrompt_waitKey
pop hl
ld (hl),a ; Store character
inc hl ; For later parsing
push hl
call putchar
call Display
ld a,(curcol)
inc a
and 15
ld (curcol),a
jp nz,readPrompt_waitKey
call newline
jp readPrompt_waitKey
; ========================
; Command parser
; ========================
parse:
ld hl,buffer
ld de,clear_str
call stringCompare
jp z,clearScreen
ld hl,buffer
ld de,base_str
call stringCompare
jp z,areBelong
ld hl,unknown_str
call putstring
call newline
ret
clearScreen:
ld hl,$8000
ld (hl),$20
ld de,$8001
ld bc,$7f
ldir
xor a
ld (curcol),a
ld (currow),a
ret
areBelong:
ld hl,belong_str
call putstring
call newline
ret
clear_str:
.db "clear",0
base_str:
.db "all your base",0
belong_str:
.db "are belong to us!",0
unknown_str:
;1234567890123456
.db "Unrecognized command",0
stringCompare: ; From the API
; hl = str1
; de = str2
; Return z = equal, nz = not equal
ld a,(de)
or a
jr z,string_compare_end
xor (hl)
ret nz ; Nonidentical
inc hl
inc de
jr stringCompare
string_compare_end:
or (hl)
ret
; ========================
; Get ascii value from getk
; ========================
mapGetkToAscii:
push hl
dec a
ld hl,keytable
ld c,a
ld b,0
add hl,bc
ld a,(hl)
pop hl
ret
keytable:
.fill 9,0
; start at 10
.db $22 ; "
.db $77 ; w
.db $72 ; r
.db $6d ; m
.db $68 ; h
.fill 2,0
; start at 17
.db $3f ; ?
.db $5b ; theta
.db $76 ; v
.db $71 ; q
.db $6c ; l
.db $67 ; g
.fill 2,0
; start at 25
.db $3a ; :
.db $7a ; z
.db $75 ; u
.db $70 ; p
.db $6b ; k
.db $66 ; f
.db $63 ; c
.db 0
; start at 33
.db $20 ; space
.db $79 ; y
.db $74 ; t
.db $6f ; o
.db $6a ; j
.db $65 ; e
.db $62 ; b
.fill 2,0
; start at 42
.db $78 ; x
.db $73 ; s
.db $6e ; n
.db $69 ; i
.db $64 ; d
.db $61 ; a
.fill 4,0
; ========================
; Jim's stuff :)
; ========================
GetK:
push hl
push de
push bc
ld a,$ff ;
out (1),a ;reset keyport
ld e,$fe ;frist group
ld c,$01 ;key port
ld l,0 ;l holds key pressed
cscloop:
out (c),e ;set keygroup
ld b,8 ;loop, Delay needed when work with key driver
in a,(c) ;read key
cscbit:
inc l ;inc to get key pressed
rra ; if key pressed done
jp nc,donecsc
djnz cscbit ;loop 8
rlc e ;next key group
jp m,cscloop ;if bit 7 set loop
ld l,0 ;if no key pressed 0
donecsc:
ld a,(keymem)
cp l
jr z,norepeat
ld a,l
ld (keymem),a
pop bc
pop de
pop hl
ret
norepeat:
xor a
pop bc
pop de
pop hl
ret
delay:
push bc
ld bc,$10
delayloop:
in f,(c)
jp p,delaydone
djnz delayloop
delaydone:
pop bc
ret
Display:
push af
push ix
WAIT
xor a
out ($10),a
WAIT
ld a,$80
out ($10),a
ld ix,textmem
ld a,$20
col:
WAIT
out ($10),a
push af
ld a,(ix)
call Character
ld a,(ix+16)
call Character
ld a,(ix+16*2)
call Character
ld a,(ix+16*3)
call Character
ld a,(ix+16*4)
call Character
ld a,(ix+16*5)
call Character
ld a,(ix+16*6)
call Character
ld a,(ix+16*7)
call Character
pop af
inc a
inc ix
cp $30
jp nz,col
WAIT
pop ix
pop af
ret
Character:
push af
push hl
push de
push bc
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld de,font
add hl,de
ld b,8
row:
WAIT
ld a,(hl)
rrca
rrca
out ($11),a
inc hl
djnz row
pop bc
pop de
pop hl
pop af
ret
newline:
push af
xor a
ld (curcol),a
ld a,(currow)
inc a
and 7
jr z,shiftline
ld (currow),a
pop af
ret
shiftline:
push hl
push de
push bc
ld hl,$8010
ld de,$8000
ld bc,128-16
ldir
ld hl,$8070
ld (hl),$20
ld de,$8071
ld bc,$F
ldir
call Display
pop bc
pop de
pop hl
pop af
ret
putchar:
push hl
push af
ld a,(currow)
and 7
add a,a
add a,a
add a,a
add a,a
ld l,a
ld a,(curcol)
and 15
or l
ld l,a
ld h,$80
pop af
ld (hl),a
pop hl
ret
putstring:
; pop hl
putstringloop:
ld a,(hl)
inc hl
or a
jp z,donestr
cp $0a
jp nz,nonewline
call newline
jr putstringloop
nonewline:
call putchar
ld a,(curcol)
inc a
and 15
ld (curcol),a
jp nz,putstringloop
call newline
jp putstringloop
donestr:
;call newline
call Display
; jp (hl)
ret
puthex:
push af
push de
ld d,a
rra
rra
rra
rra
or $F0
daa
add a,$A0
adc a,$40
call putchar
ld a,(curcol)
inc a
and 15
ld (curcol),a
ld a,d
or $F0
daa
add a,$A0
adc a,$40
call putchar
ld a,(curcol)
inc a
and 15
ld (curcol),a
call Display
pop de
pop af
ret
#include "font3.asm"