-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUTILS.ASM
executable file
·636 lines (568 loc) · 8.41 KB
/
UTILS.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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
;Source by Six of Style (Oliver VieBrooks)
;http://style64.org http://thedarkside.ath.cx mailto:six@darklordsofchaos.com
;
;Last Updated 8/24/2005
getanykey
PRINT 13,146,5,"pRESS aNY kEY tO cONTINUE",13
gak0
jsr GETIN
beq gak0
rts
px dc.b $00
py dc.b $00
pa dc.b $00
prns
sta pa
stx px
sty py
jsr CLRCHN
pla
sta addr$+1
pla
sta addr$+2
loop$ inc addr$+1
bne addr$
inc addr$+2
addr$ lda $aaaa
beq out$
jsr CHROUT
jmp loop$
out$ lda addr$+2
pha
lda addr$+1
pha
lda pa
ldx px
ldy py
rts
;print null terminated string found at x:a
pnts
sta pnts_0+1
stx pnts_0+2
;jsr CLRCHN
ldx #$00
pnts_0 lda $ffff,x
beq pntsx
tay
txa
pha
tya
jsr CHROUT
pla
inx
bne pnts_0
pntsx
rts
;Duplicate PRNS used from IRQ to avoid crossover
ipx dc.b $00
ipy dc.b $00
ipa dc.b $00
iprns
sta ipa
stx ipx
sty ipy
jsr CLRCHN
pla
sta iaddr$+1
pla
sta iaddr$+2
iloop$ inc iaddr$+1
bne iaddr$
inc iaddr$+2
iaddr$ lda $aaaa
beq iout$
jsr CHROUT
jmp iloop$
iout$ lda iaddr$+2
pha
lda iaddr$+1
pha
lda ipa
ldx ipx
ldy ipy
rts
as0 dc.b $00,$00
as1 dc.b $00,$00
res dc.b $00,$00
add16 ;adds two 16-bit numbers (as0 + as1), returns 16-bit result in x:a
clc
lda as0
adc as1
pha
lda as0+$01
adc as1+$01
tax
pla
rts
sub16 ;subtracts two 16-bit numbers (as0-as1), returns 16-bit result in x:a
sec
lda as0
sbc as1
pha
lda as0+$01
sbc as1+$01
tax
pla
rts
copybytes ; takes y bytes at x:a and transfers it to address in as0 (lo:hi)
stx copybytes1+$02
sta copybytes1+$01
sty copybytes2+$01
lda as0
sta as2+$01
lda as0+$01
sta as2+$02
ldx #$00
copybytes1
lda $ffff,x
as2 sta $ffff,x
iny
inx
copybytes2
cpx #$ff
bne copybytes1
rts
CPY_LEN dc.b $00,$00
copyblock ;src=CPY_SRC, dst=CPY_DST, len in x:a
stx CPY_LEN+1
sta CPY_LEN
ldy #$00
ldx CPY_LEN+1
beq CPY_FRAG
CPY_PAGE
lda (CPY_SRC),y
sta (CPY_DST),y
iny
bne CPY_PAGE
inc CPY_SRC+1
inc CPY_DST+1
dex
bne CPY_PAGE
CPY_FRAG
cpy CPY_LEN+0
beq CPY_DONE
lda (CPY_SRC),Y
sta (CPY_DST),Y
iny
bne CPY_FRAG
CPY_DONE
rts
;Input a string and store it in x:a, terminated with a null byte.
;max # of chars in y returns num of chars entered in y, carry set if run/stop
ICOUNT dc.b $00
INPUT
stx INPUT_PTR+1
sta INPUT_PTR
sty INPUT_1+1
lda #$00
sta INPUT_Y
INPUT_G
jsr STOP
beq INPUT_3
jsr GETIN
beq INPUT_G
ldy INPUT_Y
cmp #160
bcs INPUT_G
cmp #$0d
beq INPUT_2
INPUT_0 sta (INPUT_PTR),y
jsr $ffd2
inc INPUT_Y
lda INPUT_Y
INPUT_1 cmp #$ff
bne INPUT_G
INPUT_2
lda #$00
sta (INPUT_PTR),y
clc
rts
INPUT_3
sec
rts
; print hex char $ of number in a
hexx dc.b $00,$00
hexstr
stx hexx
pha
and #$f0
clc
lsr
lsr
lsr
lsr
tax
lda hexstring,x
jsr $ffd2
pla
and #$0f
tax
lda hexstring,x
jsr $ffd2
ldx hexx
rts
acc
dc.b $00,$00
aux
dc.b $00,$00
ext
dc.b $00,$00
decstr
STA acc
STX acc+1
STY aux ;Base
LDX #00
STX aux+1
decstrLOOP
JSR DIV16
INX
LDA ext
PHA
LDA acc
ORA acc+1
BNE decstrLOOP ;Divide until result=0
decstrPOOP PLA
ORA #$30 ;Convert to chr$
CMP #$3A
BCC decstrPLOP
ADC #$06 ;$3A->A $3B->B etc.
decstrPLOP JSR $FFD2
DEX
BNE decstrPOOP
RTS
DIV16
LDA #0
STA ext+1
LDY #$10
div16LOOP
ASL acc
ROL acc+1
ROL
ROL ext+1
PHA
CMP aux
LDA ext+1
SBC aux+1
BCC div16DIV2
STA ext+1
PLA
SBC aux
PHA
INC acc
div16DIV2 PLA
DEY
BNE div16LOOP
STA ext
RTS
;
;Prints the mac address indicated by the six bytes at (x:a)
;destroys a,x, preserves y
;
printmac
sty macprinty
stx macprl+$02
sta macprl+$01
ldy #$00
macprl
lda $FFFF,y
jsr hexstr
cpy #$05
beq macpr2
jsr prns
dc.b "-",0
macpr2 iny
cpy #$06
bne macprl
ldy macprinty
rts
macprinty dc.b $00
printipy dc.b $00
printip ;Address in x:a, preserves y
sty printipy
sta pipadr+$01
stx pipadr+$02
ldy #$00
printiploop
tya
pha
pipadr lda $FFFF,y
ldx #$00
ldy #$0a
jsr decstr
pla
tay
pha
cpy #$03
beq printiploop2
jsr prns
dc.b ".",0
printiploop2
pla
tay
iny
cpy #$04
bne printiploop
ldy printipy
rts
;Thank you, Steve Judd
printnum
sta acc
stx acc+1
sty aux
ldx #$00
stx aux+1
pn_l jsr DIV16
inx
lda ext
pha
lda acc
ora acc+1
bne pn_l
pn_l2 pla
ora #$30
cmp #$3a
bcc pn_l3
adc #$06
pn_l3 jsr CHROUT
dex
bne pn_l2
rts
yesno ;returns 0 in a for no, 1 in a for yes, 2 for "quit"
PRINT "(y/n/q)"
yn1 jsr GETIN
beq yn1
cmp #89 ;y
beq yesnoyes
cmp #217;Y
beq yesnoyes
cmp #78;n
beq yesnono
cmp #206;N
beq yesnono
cmp #81;q
beq yesnoquit
cmp #209;Q
beq yesnoquit
jmp yn1
yesnoyes
lda #$01
rts
yesnono
lda #$00
rts
yesnoquit
lda #$02
rts
gotmac dc.b $00,$00,$00,$00,$00,$00
getmac
PRINT 13,"mac[0]: "
jsr gethex
sta gotmac
PRINT 13,"mac[1]: "
jsr gethex
sta gotmac+1
PRINT 13,"mac[2]: "
jsr gethex
sta gotmac+2
PRINT 13,"mac[3]: "
jsr gethex
sta gotmac+3
PRINT 13,"mac[4]: "
jsr gethex
sta gotmac+4
PRINT 13,"mac[5]: "
jsr gethex
sta gotmac+5
rts
ghr dc.b $00
gethex
jsr gethexdig
txa
asl
asl
asl
asl
sta ghr
jsr gethexdig
txa
ora ghr
rts
gotip
dc.b $00,$00,$00,$00
getip
PRINT 13,"ip[0]: "
jsr getnum
sta gotip
PRINT 13,"ip[1]: "
jsr getnum
sta gotip+$01
PRINT 13,"ip[2]: "
jsr getnum
sta gotip+$02
PRINT 13,"ip[3]: "
jsr getnum
sta gotip+$03
rts
gny dc.b $00
getnum ;max 3 digits
lda #$00
sta gns
sta gns+$01
sta gns+$02
ldy #$00
gn0 sty gny
jsr getdigit ;returns dec value in a
ldy gny
cmp #$0d ;abort on return
beq gn1
sta gns,y
iny
cpy #$03
beq gn3
jmp gn0
gn1
lda gny
beq gnx
lda gny
cmp #$01 ;1 digit entered
bne gn2
lda gns
rts
gn2
lda gns ;mul gns+1 * 10 and store in gnr+1
asl ;*2
sta gnr
asl ;*4 ;again multiply by 2 (*4)
asl ;*8 ;again multiply by 2 (*8)
clc
adc gnr
sta gnr
lda gnr
clc
adc gns+1
rts
gn3
lda gns ;mul gns*100 and store in gnr
asl ;*2 (*4 + *32 + *64)
asl ;*4
sta gnr
asl ;*8
asl ;*16
asl ;*32
pha
clc
adc gnr
sta gnr
pla
asl ;*64
clc
adc gnr
sta gnr
lda gns+1 ;mul gns+1 * 10 and store in gnr+1
asl ;*2
sta gnr+1
asl ;*4 ;again multiply by 2 (*4)
asl ;*8 ;again multiply by 2 (*8)
clc
adc gnr+1
sta gnr+1
lda gnr
clc
adc gnr+1
clc
adc gns+2
gnx
rts
gns dc.b $00,$00,$00
gnr dc.b $00,$00
getdigit ;returns digit in a,value in x
jsr GETIN
beq getdigit
cmp #$0d
beq gd2
ldx #$00
gd0
cmp numstr,x
beq gd1
inx
cpx #$0b
beq getdigit
jmp gd0
gd1
pha
jsr $ffd2
pla
sec
sbc #$30
gd2
rts
gethexdig ;returns hex digit in a,value in x
jsr GETIN
beq gethexdig
cmp #$0d
beq ghd2
ldx #$00
ghd0
cmp hexstring,x
beq ghd1
inx
cpx #$10
beq gethexdig
jmp ghd0
ghd1
pha
jsr $ffd2
pla
sec
sbc #$30
ghd2
rts
ipm dc.b $00,$00,$00,$00
IPMTemp dc.b $00
;IF CARD_IP AND CARD_MASK = DEST_IP AND CARD_MASK THEN LOCAL
IPMASK ; expects pointer to IP in x:a,
; returns carry clear if local,
; carry set if not.
sta IPM0+1
stx IPM0+2
ldy #$00
IPM0
lda $FFFF,y
and CARD_MASK,y
; sta $0500,y
sta IPMTemp
lda CARD_IP,y
and CARD_MASK,y
cmp IPMTemp
bne IPM_NL
iny
cpy #$04
bne IPM0
clc
rts
IPM_NL
sec
rts
numstr dc.b "0123456789"
hexstring
dc.b "0123456789ABCDEF"
pet2asc ;petscii char in a returns ascii char in a
;if a > 64 AND a <91 THEN a = a + 32
;if a > 96 AND a <123 THEN a = a - 32
cmp #97
blt pet2asc0
;it's greater than 96
cmp #123
bge pet2ascx
sec
sbc #$20
rts
pet2asc0
cmp #65
blt pet2ascx
cmp #91
bge pet2ascx
clc
adc #$20
pet2ascx
rts