/
tuberom.s
1740 lines (1409 loc) · 45.4 KB
/
tuberom.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
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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##include "macros.s"
##ifdef CPU_OPC7
EQU BASE, 0x00000
EQU CODE, 0x00200
EQU TUBE, 0xFFEF8
EQU MOS, 0x000C8
EQU WORK, 0x00100
EQU END_MARKER, 0x80000000 # makes the end of each command -ve
##else
##ifdef CPU_OPC6
EQU BASE, 0xE000
EQU CODE, 0xF800
EQU TUBE, 0xFEF8
EQU MOS, 0xFFC8
EQU WORK, 0x0000
EQU END_MARKER, 0x8000 # makes the end of each command -ve
##else
EQU BASE, 0xE000
EQU CODE, 0xF000
EQU TUBE, 0xFEF8
EQU MOS, 0xFFC8
EQU WORK, 0x0000
EQU END_MARKER, 0x8000 # makes the end of each command -ve
##endif
##endif
# These are passed in directly from the makefile
EQU MEM_BOT, _MEM_BOT_
EQU MEM_TOP, _MEM_TOP_
EQU STACK, _STACK_
EQU r1status, TUBE
EQU r1data, TUBE + 1
EQU r2status, TUBE + 2
EQU r2data, TUBE + 3
EQU r3status, TUBE + 4
EQU r3data, TUBE + 5
EQU r4status, TUBE + 6
EQU r4data, TUBE + 7
EQU NUM_VECTORS, 27 # number of vectors in DefaultVectors table
# -----------------------------------------------------------------------------
# Memory from 0x0000 to 0x00FF is reserved for system use
# -----------------------------------------------------------------------------
# 0x0000 = OPC5/6 Reset address
# 0x0002 = OPC5/6 IRQ0 address
# 0x0004 = OPC6 IRQ1 address
EQU USERV, WORK + 0x0010
EQU BRKV, WORK + 0x0011
EQU IRQ1V, WORK + 0x0012
EQU IRQ2V, WORK + 0x0013
EQU CLIV, WORK + 0x0014
EQU BYTEV, WORK + 0x0015
EQU WORDV, WORK + 0x0016
EQU WRCHV, WORK + 0x0017
EQU RDCHV, WORK + 0x0018
EQU FILEV, WORK + 0x0019
EQU ARGSV, WORK + 0x001A
EQU BGETV, WORK + 0x001B
EQU BPUTV, WORK + 0x001C
EQU GBPBV, WORK + 0x001D
EQU FINDV, WORK + 0x001E
EQU FSCV, WORK + 0x001F
EQU EVNTV, WORK + 0x0020
EQU UPTV, WORK + 0x0021 # not implemented
EQU NETV, WORK + 0x0022 # not implemented
EQU VDUV, WORK + 0x0023 # not implemented
EQU KEYV, WORK + 0x0024 # not implemented
EQU INSV, WORK + 0x0025 # not implemented
EQU REMV, WORK + 0x0026 # not implemented
EQU CNPV, WORK + 0x0027 # not implemented
EQU IND1V, WORK + 0x0028 # not implemented
EQU IND2V, WORK + 0x0029 # not implemented
EQU IND3V, WORK + 0x002A # not implemented
EQU ERRBUF, WORK + 0x0030
EQU INPBUF, WORK + 0x0030
EQU INPEND, WORK + 0x00F6
EQU ADDR, WORK + 0x00F6 # tube execution address
EQU TMP_R1, WORK + 0x00FC # tmp store for R1 during IRQ
EQU LAST_ERR, WORK + 0x00FD # last error
EQU ESCAPE_FLAG, WORK + 0x00FF # escape flag
MACRO ERROR (_address_)
mov r1, r0, _address_
SWI0 ()
ENDMACRO
# -----------------------------------------------------------------------------
# 8K Rom Start
# -----------------------------------------------------------------------------
// These end up at 0x0000 and get used by the Real Co Pro
ORG BASE
mov pc, r0, ResetHandler
ORG BASE + 2
mov pc, r0, InterruptHandler
ORG CODE
##include "lib_printstring.s"
##include "lib_printhex.s"
##include "lib_printdec.s"
##include "lib_readhex.s"
##include "lib_srec.s"
##include "lib_dumpmem.s"
##include "lib_disassemble.s"
ResetHandler:
mov r14, r0, STACK # setup the stack
mov r2, r0, NUM_VECTORS - 1 # copy the vectors
InitVecLoop:
ld r1, r2, DefaultVectors
sto r1, r2, USERV
sub r2, r0, 1
pl.mov pc, r0, InitVecLoop
EI () # enable interrupts
mov r1, r0, BannerMessage # send the reset message
JSR (print_string)
mov r1, r0 # send the terminator
JSR (OSWRCH)
JSR (WaitByteR2) # wait for the response and ignore
CmdPrompt:
CmdOSLoop:
mov r1, r0, 0x2a
JSR (OSWRCH)
mov r1, r0
mov r2, r0, osword0_param_block
JSR (OSWORD)
c.mov pc, r0, CmdOSEscape
mov r1, r0, INPBUF
JSR (OS_CLI)
mov pc, r0, CmdOSLoop
CmdOSEscape:
mov r1, r0, 0x7e
JSR (OSBYTE)
ERROR (EscapeError)
# --------------------------------------------------------------
# MOS interface
# --------------------------------------------------------------
NullReturn:
RTS ()
# --------------------------------------------------------------
Unsupported:
RTS ()
# --------------------------------------------------------------
ErrorHandler:
mov r14, r0, STACK # Clear the stack
JSR (OSNEWL)
ld r1, r0, LAST_ERR # Address of the last error: <error num> <err string> <00>
add r1, r0, 1 # Skip over error num
JSR (print_string) # Print error string
JSR (OSNEWL)
mov pc, r0, CmdPrompt # Jump to command prompt
# --------------------------------------------------------------
osARGS:
# TODO
RTS ()
# --------------------------------------------------------------
osBGET:
# TODO
RTS ()
# --------------------------------------------------------------
osBPUT:
# TODO
RTS ()
# --------------------------------------------------------------
# OSBYTE - Byte MOS functions
# ===========================
# On entry, r1, r2, r3=OSBYTE parameters
# On exit, r1 preserved
# If r1<$80, r2=returned value
# If r1>$7F, r2, r3, Carry=returned values
#
osBYTE:
PUSH (r13)
cmp r1, r0, 0x80 # Jump for long OSBYTEs
c.mov pc, r0, ByteHigh
#
# Tube data $04 X A -- X
#
PUSH (r1)
mov r1, r0, 0x04 # Send command &04 - OSBYTELO
JSR (SendByteR2)
mov r1, r2
JSR (SendByteR2) # Send single parameter
POP (r1)
PUSH (r1)
JSR (SendByteR2) # Send function
JSR (WaitByteR2) # Get return value
mov r2, r1
POP (r1)
POP (r13)
RTS ()
ByteHigh:
cmp r1, r0, 0x82 # Read memory high word
z.mov pc, r0, Byte82
cmp r1, r0, 0x83 # Read bottom of memory
z.mov pc, r0, Byte83
cmp r1, r0, 0x84 # Read top of memory
z.mov pc, r0, Byte84
#
# Tube data $06 X Y A -- Cy Y X
#
PUSH (r1)
mov r1, r0, 0x06
JSR (SendByteR2) # Send command &06 - OSBYTEHI
mov r2, r1
JSR (SendByteR2) # Send parameter 1
mov r3, r1
JSR (SendByteR2) # Send parameter 2
POP (r1)
PUSH (r1)
JSR (SendByteR2) # Send function
# cmp r1, r0, 0x8e # If select language, check to enter code
# z.mov pc, r0, CheckAck
cmp r1, r0, 0x9d # Fast return with Fast BPUT
z.mov pc, r0, FastReturn
JSR (WaitByteR2) # Get carry - from bit 7
add r1, r0, -0x80
JSR (WaitByteR2) # Get high byte
mov r3, r1
JSR (WaitByteR2) # Get low byte
mov r2, r1
FastReturn:
POP (r1) # restore original r1
POP (r13)
RTS ()
Byte84: # Read top of memory
mov r1, r0, MEM_TOP
POP (r13)
RTS ()
Byte83: # Read bottom of memory
mov r1, r0, MEM_BOT
POP (r13)
RTS ()
Byte82: # Return &0000 as memory high word
mov r1, r0
POP (r13)
RTS ()
# --------------------------------------------------------------
# OSCLI - Send command line to host
# =================================
# On entry, r1=>command string
#
# Tube data &02 string &0D -- &7F or &80
#
osCLI:
PUSH (r13)
PUSH (r2)
PUSH (r1) # save the string pointer
JSR (cmdLocal) # try to handle the command locally
cmp r1, r0 # was command handled locally? (r1 = 0)
z.mov pc, r0, dontEnterCode # yes, then nothing more to do
POP (r1) # restore the string pointer
PUSH (r1) # save the string pointer
mov r2, r1
mov r1, r0, 0x02 # Send command &02 - OSCLI
JSR (SendByteR2)
JSR (SendStringR2) # Send string pointed to by r2
osCLI_Ack:
JSR (WaitByteR2)
cmp r1, r0, 0x80
nc.mov pc, r0, dontEnterCode
POP (r1)
PUSH (r1)
JSR (prep_env)
JSR (enterCode)
dontEnterCode:
POP (r1)
POP (r2)
POP (r13)
RTS ()
enterCode:
ld pc, r0, ADDR
# Find the start of the command string
#
# Lots of ways a file can be run:
# * filename params
# * / filename params
# *R. filename params
# *RU. filename params
# *RUN filename params
#
#
# In general you want:
# - skip leading space or * characters
# - skip any form of *RUN, followed by trailing spaces
# - leave the environment point at the first character of filename
prep_env:
PUSH (r13)
DEC (r1, 1)
prep_env_1: # skip leading space or * characters
INC (r1, 1)
JSR (skip_spaces)
cmp r2, r0, 0x2A # *
z.mov pc, r0, prep_env_1
cmp r2, r0, 0x2F # /
z.mov pc, r0, prep_env_4
mov r2, r0, run_string - 1
mov r3, r1, -1
prep_env_2: # skip a possibly abbreviated RUN
INC (r2, 1)
ld r4, r2 # Read R U N <0>
z.mov pc, r0, prep_env_3
INC (r3, 1)
ld r5, r3
cmp r5, r0, 0x2E # .
z.mov pc, r0, prep_env_3
and r5, r0, 0xDF # force upper case
cmp r4, r5 # match against R U N
nz.mov pc, r0, prep_env_5
mov pc, r0, prep_env_2 # loop back for more characters
prep_env_3:
mov r1, r3
prep_env_4:
INC (r1, 1)
prep_env_5:
JSR (skip_spaces)
POP (r13)
RTS ()
run_string:
STRING "RUN"
WORD 0
# --------------------------------------------------------------
# Local Command Processor
#
# On Entry:
# - r1 points to the user command
#
# On Exit:
# - r1 == 0 if command successfully processed locally
# - r1 != 0 if command should be
#
# Register usage:
# r1 points to start of user command
# r2 points within command table
# r3 points within user command
# r4 is current character in command table
# r5 is current character in user command
cmdLocal:
PUSH (r2)
PUSH (r3)
PUSH (r4)
PUSH (r5)
PUSH (r13)
sub r1, r0, 1
cmdLoop0:
add r1, r0, 1
JSR (skip_spaces) # skip leading spaces
cmp r2, r0, ord('*') # also skip leading *
z.mov pc, r0, cmdLoop0
mov r2, r0, cmdTable-1 # initialize command table pointer (to char before)
cmdLoop1:
mov r3, r1, -1 # initialize user command pointer (to char before)
cmdLoop2:
add r2, r0, 1 # increment command table pointer
add r3, r0, 1 # increment user command pointer
ld r5, r3 # read next character from user command
or r5, r0, 0x20 # convert to lower case
ld r4, r2 # read next character from command table
mi.mov pc, r0, cmdCheck # if an address, then we are done matching
cmp r5, r4 # compare the characters
z.mov pc, r0, cmdLoop2 # if a match, loop back for more
sub r2, r0, 1
cmdLoop3: # skip to the end of the command in the table
add r2, r0, 1
ld r4, r2
pl.mov pc, r0, cmdLoop3
cmp r5, r0, ord('.') # was the mis-match a '.'
nz.mov pc, r0, cmdLoop1 # no, then start again with next command
add r3, r0, 1 # increment user command pointer past the '.'
cmdExec:
mov r1, r3 # r1 = the command pointer to the params
mov r2, r4 # r2 = the execution address
JSR (cmdExecR2)
cmdExit:
POP (r13)
POP (r5)
POP (r4)
POP (r3)
POP (r2)
RTS ()
# Additional code to make the match non-greedy
# e.g. *MEMORY should not match against the MEM command
# also exclude *MEM.
cmdCheck:
cmp r5, r0, ord('.') # check the first non-matching user char against '.'
z.mov pc, r0, cmdReject # if == '.' then reject the command
cmp r5, r0, ord('a') # check the first non-matching user char against 'a'
nc.mov pc, r0, cmdExec # if < 'a' then execute the local command
cmp r5, r0, ord('z')+1 # check the first non-matching user char against 'z'
c.mov pc, r0, cmdExec # if >= 'z'+1 then execute the local command
cmdReject:
mov r1, r0, 1 # flag command as not handled here then return
mov pc, r0, cmdExit # allowing the command to be handled elsewhere
# --------------------------------------------------------------
cmdGo:
PUSH (r13)
JSR (read_hex)
JSR (cmdExecR2)
mov r1, r0
POP (r13)
RTS ()
# --------------------------------------------------------------
cmdMem:
PUSH (r13)
JSR (read_hex)
mov r1, r2
JSR (dump_mem)
mov r1, r0
POP (r13)
RTS ()
# --------------------------------------------------------------
cmdDis:
PUSH (r13)
JSR (read_hex)
mov r3, r0, 16
dis_loop:
mov r1, r2
JSR (disassemble)
mov r2, r1
JSR (OSNEWL)
DEC (r3, 1)
nz.mov pc, r0, dis_loop
mov r1, r0
POP (r13)
RTS ()
# --------------------------------------------------------------
cmdHelp:
PUSH (r13)
mov r1, r0, msgHelp
JSR (print_string)
mov r1, r0, 1
POP (r13)
RTS ()
msgHelp:
CPU_STRING()
STRING " 0.55"
WORD 10, 13, 0
# --------------------------------------------------------------
cmdTest:
PUSH (r13)
JSR (read_hex)
# Save param
PUSH (r2)
# Set TIME to using OSWORD 2
mov r1, r0, 0x02
mov r2, r0, osword_pblock
sto r0, r2
sto r0, r2, 1
sto r0, r2, 2 # only necessary when word size is 16 bits
JSR (OSWORD)
# Restore param
POP (r1)
PUSH (r1)
# Print param
JSR (print_hex_word_spc)
JSR (print_dec_word)
JSR (OSNEWL)
# Restore param
POP (r1)
# Do some real work
JSR (pi_calc)
JSR (OSNEWL)
# Read TIME using OSWORD 1
mov r1, r0, 0x01
mov r2, r0, osword_pblock
JSR (OSWORD)
# Print the LS word in decomal
ld r1, r0, osword_pblock
JSR (print_dec_word)
JSR (OSNEWL)
mov r1, r0
POP (r13)
RTS ()
osword_pblock:
WORD 0
WORD 0
WORD 0
# -------------------------------------------------------
# Pi Test Program
#
# On entry, r1 is the number of digits
# -------------------------------------------------------
EQU p, 0x1000
pi_calc:
PUSH (r13)
# r1 = ndigits
# psize calculated dynamicaly as = 1 + ndigits * 10 / 3
PUSH (r1) # push ndigits
mov r11, r0, 10
JSR (mul)
mov r11, r1
mov r1, r0, 3
JSR (div) # r11 / r1 => quotient in r11, remainder in r1
mov r2, r11, 1
PUSH (r2) # push psize
JSR (init) # ndigits in r2
POP (r3) # pop psize
POP (r2) # pop ndigits
#mov r2, r0, ndigits # ldx #359
#mov r3, r0, psize # ldy #1193
mov r7, r2, -1 # r7 = ndigits - 1
l1:
mov r6, r3 # phy
mov r4, r1 # pha
mov r5, r2 # phx
mov r11, r0 # stz q
mov r1, r3 # tya
mov r2, r1 # tax
l2:
mov r1, r2 # txa
JSR (mul)
mov r9, r1 # sta s
mov r1, r0, 10 # lda #10
mov r11, r1 # sta q
ld r1, r2, p-1 # lda p-1,x
JSR (mul)
# clc
add r1, r9 # adc s
mov r11, r1 # sta q
mov r1, r2 # txa
add r1, r1 # asl
mov r1, r1, -1 # dec
JSR (div)
sto r1, r2, p-1 # sta p-1,x
mov r2, r2, -1 # dex
nz.mov pc, r0, l2 # bne l2
mov r1, r0, 10 # lda #10
JSR (div)
sto r1, r0, p # sta p
mov r2, r5 # plx
mov r1, r4 # pla
mov r3, r11 # ldy q
cmp r3, r0, 10 # cpy #10
nc.mov pc, r0, l3 # bcc l3
mov r3, r0 # ldy #0
mov r1, r1, 1 # inc
l3:
cmp r2, r7 # cpx #358
nc.mov pc, r0, l4 # bcc l4
nz.mov pc, r0, l5 # bne l5
JSR (OSWRCH)
mov r1, r0, 46 # lda #46
l4:
JSR (OSWRCH)
l5:
mov r1, r3 # tya
xor r1, r0, 48 # eor #48
mov r3, r6 # ply
cmp r2, r7 # cpx #358
c.mov pc, r0, l6 # bcs l6
# dey
# dey
mov r3, r3, -3 # dey by 3
l6:
mov r2, r2, -1 # dex
nz.mov pc, r0, l1 # bne l1
JSR (OSWRCH)
mov r0, r0, 3142 # RTS()
POP (r13)
RTS ()
init:
mov r1, r0, 2 # lda #2
#mov r2, r0, psize # was ldx #1192
i1:
sto r1, r2, p-1 # was sta p,x
mov r2, r2, -1 # dex
nz.mov pc, r0, i1 # bne instead of bpl i1
RTS ()
mul: # uses y as loop counter
mov r10, r1 # sta r
mov r3, r0, WORD_SIZE # ldy #16
m1:
add r1, r1 # asl
add r11, r11 # asl q
nc.mov pc, r0, m2 # bcc m2
# clc
add r1, r10 # adc r
m2:
mov r3, r3, -1 # dey
nz.mov pc, r0, m1 # bne m1
RTS()
div: # uses y as loop counter
mov r10, r1 # sta r
mov r3, r0, WORD_SIZE # ldy #16
mov r1, r0, 0 # lda #0
add r11, r11 # asl q
d1:
ROL (r1, r1) # rol
cmp r1, r10 # cmp r
nc.mov pc, r0, d2 # bcc d2
sub r1, r10 # sbc r
d2:
ROL (r11, r11) # rol q
mov r3, r3, -1 # dey
nz.mov pc, r0, d1 # bne d1
RTS ()
# ---------------------------------------------------------
cmdSrec:
PUSH (r13)
JSR (srec_load)
cmp r1, r0, 1
z.mov pc, r0, CmdOSEscape
cmp r1, r0, 2
z.mov pc, r0, cmdSrecChecksumError
cmp r1, r0
nz.mov pc, r0, cmdSrecBadFormatError
POP (r13)
RTS ()
cmdSrecChecksumError:
ERROR (checksumError)
checksumError:
WORD 17 # TODO assign proper error code
STRING "Checksum Mismatch"
WORD 0x00
cmdSrecBadFormatError:
ERROR (badFormatError)
badFormatError:
WORD 17 # TODO assign proper error code
STRING "Bad Format"
WORD 0x00
# ---------------------------------------------------------
cmdEnd:
mov r1, r0, 1
RTS ()
# --------------------------------------------------------------
cmdExecR2:
mov pc, r2
# --------------------------------------------------------------
cmdTable:
STRING "."
WORD cmdEnd | END_MARKER
STRING "go"
WORD cmdGo | END_MARKER
STRING "mem"
WORD cmdMem | END_MARKER
STRING "dis"
WORD cmdDis | END_MARKER
STRING "help"
WORD cmdHelp | END_MARKER
STRING "test"
WORD cmdTest | END_MARKER
STRING "srec"
WORD cmdSrec | END_MARKER
WORD cmdEnd | END_MARKER
# --------------------------------------------------------------
osFILE:
# TODO
RTS ()
# --------------------------------------------------------------
osFIND:
# TODO
RTS ()
# --------------------------------------------------------------
osGBPB:
# TODO
RTS ()
# --------------------------------------------------------------
# On entry:
# r1 is the osword number
# r2 points to the paramater block in memory
osWORD:
cmp r1, r0
z.mov pc, r0, RDLINE
PUSH (r13)
PUSH (r1) # save calling param (osword number)
PUSH (r2) # save calling param (block)
PUSH (r3) # r3 used as a scratch register
PUSH (r4) # r4 used as a scratch register
mov r3, r1
mov r4, r2
mov r1, r0, 8
JSR (SendByteR2) # Send command &08 - OSWORD
mov r1, r3
JSR (SendByteR2) # Send osword number
cmp r3, r0, 0x15 # Compute index into length table
c.mov r3, r0 # >= OSWORD 0x15, use slot 0
ld r1, r3, word_in_len
JSR (SendByteR2) # Send request block length
ld r1, r3, word_in_len
mov r2, r4
JSR (SendBlockR2) # Send request block
ld r1, r3, word_out_len
JSR (SendByteR2) # Send response block length
ld r1, r3, word_out_len
mov r2, r4
JSR (ReceiveBlockR2) # Receive response block
POP (r4)
POP (r3)
POP (r2)
POP (r1)
POP (r13)
RTS ()
# Send a defined size block to tube FIFO R2
# r1 is the length
# r2 is the block address
# The complexity here is the block needs to be send backwards!
SendBlockR2:
PUSH (r13)
PUSH (r3)
PUSH (r4)
mov r4, r1, -1 # r4 = block length - 1
mi.mov pc, r0, SendBlockDone
##ifdef CPU_OPC7
mov r1, r4 # calculate address of word containing last byte
lsr r1, r1
lsr r1, r1
add r2, r1
ld r3, r2 # load the first word from memory
mov r1, r4
and r1, r0, 3 # word out the byte alignment of the last byte in the block (first byte to send)
z.mov pc, r0, SendBlockB0
cmp r1, r0, 1
z.mov pc, r0, SendBlockB1
cmp r1, r0, 2
z.mov pc, r0, SendBlockB2
SendBlockB3:
bperm r1, r3, 0x4443
JSR (SendByteR2) # send byte 3
DEC (r4, 1)
mi.mov pc, r0, SendBlockDone
SendBlockB2:
bperm r1, r3, 0x4442
JSR (SendByteR2) # send byte 2
DEC (r4, 1)
mi.mov pc, r0, SendBlockDone
SendBlockB1:
bperm r1, r3, 0x4441
JSR (SendByteR2) # send byte 1
DEC (r4, 1)
mi.mov pc, r0, SendBlockDone
SendBlockB0:
bperm r1, r3, 0x4440
JSR (SendByteR2) # send byte 0
DEC (r4, 1)
mi.mov pc, r0, SendBlockDone
DEC (r2, 1)
ld r3, r2 # load the next word from memory
mov pc, r0, SendBlockB3
##else
mov r1, r4 # calculate address of word containing last byte
LSR (r1, r1)
add r2, r1
ld r3, r2 # load the first word from memory
mov r1, r4
and r1, r0, 1 # word out the byte alignment of the last byte in the block (first byte to send)
z.mov pc, r0, SendBlockB0
SendBlockB1:
bswp r1, r3
JSR (SendByteR2) # send byte 1
DEC (r4, 1)
mi.mov pc, r0, SendBlockDone
SendBlockB0:
JSR (SendByteR2) # send byte 0
DEC (r4, 1)
mi.mov pc, r0, SendBlockDone
DEC (r2, 1)
ld r3, r2 # load the next word from memory
mov pc, r0, SendBlockB1
##endif
SendBlockDone:
POP (r4)
POP (r3)
POP (r13)
RTS ()
# Receive a defined size block from tube FIFO R2
# r1 is the length
# r2 is the block address
ReceiveBlockR2:
PUSH (r13)
PUSH (r3)
PUSH (r4)
mov r4, r1, -1 # r4 = block length - 1
mi.mov pc, r0, ReceiveBlockDone
##ifdef CPU_OPC7
mov r1, r4 # calculate address of word containing last byte
lsr r1, r1
lsr r1, r1
add r2, r1
mov r3, r0 # clear the receive word
mov r1, r4
and r1, r0, 3 # word out the byte alignment of the last byte in the block (first byte to send)
z.mov pc, r0, ReceiveBlockB0
cmp r1, r0, 1
z.mov pc, r0, ReceiveBlockB1
cmp r1, r0, 2
z.mov pc, r0, ReceiveBlockB2
ReceiveBlockB3:
JSR (WaitByteR2) # receive byte 3
bperm r1, r1, 0x0444
or r3, r1
DEC (r4, 1)
mi.mov pc, r0, ReceiveBlockWrite
ReceiveBlockB2:
JSR (WaitByteR2) # receive byte 2
bperm r1, r1, 0x4044
or r3, r1
DEC (r4, 1)
ReceiveBlockB1:
mi.mov pc, r0, ReceiveBlockWrite
JSR (WaitByteR2) # receive byte 1
bperm r1, r1, 0x4404
or r3, r1
DEC (r4, 1)
ReceiveBlockB0:
mi.mov pc, r0, ReceiveBlockWrite
JSR (WaitByteR2) # receive byte 0
bperm r1, r1, 0x4440 # this instruction could probably be skipped
or r3, r1
ReceiveBlockWrite:
sto r3, r2
mov r3, r0
DEC (r2, 1)
DEC (r4, 1)
pl.mov pc, r0, ReceiveBlockB3
##else
mov r1, r4 # calculate address of word containing last byte
LSR (r1, r1)
add r2, r1
mov r3, r0 # clear the receive word
mov r1, r4
and r1, r0, 1 # word out the byte alignment of the last byte in the block (first byte to send)
z.mov pc, r0, ReceiveBlockB0
ReceiveBlockB1:
mi.mov pc, r0, ReceiveBlockWrite
JSR (WaitByteR2) # receive byte 1
bswp r1, r1
or r3, r1
DEC (r4, 1)
ReceiveBlockB0:
mi.mov pc, r0, ReceiveBlockWrite
JSR (WaitByteR2) # receive byte 0
or r3, r1
ReceiveBlockWrite:
sto r3, r2
mov r3, r0
DEC (r2, 1)
DEC (r4, 1)
pl.mov pc, r0, ReceiveBlockB1
##endif
ReceiveBlockDone:
POP (r4)