-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathF18A_update.a99
1786 lines (1607 loc) · 50.8 KB
/
F18A_update.a99
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
* F18A In-System Updater
* TI-99/4A with CF7
*
* @author Matthew Hagerty
* @author Rasmus (lastname?)
* @date July 2014
* @version 1.6.2
*
* To update the updater:
* Run CRC.jar on .bin bitstream
* Copy CRC data into this file
* Compile to TIDisk as F18AUPD
* Convert .bin bitstream to TI-File (tools->convert PC to TI file) F18ABIN, INT/FIX, 128, Binary
* Copy F18ABIN to CF7 disk image
* Copy F18AUPD to CF7 disk image
* Copy CF7 disk image to CFcard
*
* When done beta testing, run in Classic99 to get the CHKSUM value and uncomment
* the checksum test for final distribution.
*
* Checksum values for each revision:
* 9B68 V1.5 Release
* 58AD V1.63 Stable - new NT2, prior to blitter update
* CEBE V1.64 Stable
* 6623 V1.65 Stable
* D555 V1.66 Stable
* E475 V1.67 Stable
* 4F34 V1.68 Stable
* 56A4 V1.69 Stable
* D7AE V1.691 Stable
* 12FF V1.692 Stable
* 40CC V1.6 Release
* A3B5 V1.7 Release
* F981 V1.8 Release
DEF START
REF DSRLNK,KSCAN
* Configuration
* See also section at end of file
FILE1S EQU 166 * Size of file 1 (KB)
FILE2S EQU 46 * Size of file 2 (KB)
BLKSIZ EQU 2 * Read block size (KB)
FRMVER EQU >0108 * Firmware version
GPUPRG EQU >3000 * GPU program start
* Constants
PGITOT EQU FILE1S+FILE2S/BLKSIZ
PGIW EQU 8*30 * Progress indicator width (pixels)
VDPRD EQU >8800 * VDP read data
VDPSTA EQU >8802 * VDP status
VDPWD EQU >8C00 * VDP write data
VDPWA EQU >8C02 * VDP set read/write address
KEYDEV EQU >8374 * Keyboard device
KEY EQU >8375 * Key pressed
STATUS EQU >837C * Key status
FNPNTR EQU >8356 * File name pointer
* VDP Memory Map
NAMETB EQU >0000 * Name table
COLRTB EQU >0380 * Color table
PTRNTB EQU >0800 * Pattern table
SPRATB EQU >0300 * Sprite attribute table
SPRPTB EQU >0800 * Sprite pattern table
PAB EQU >0F00 * Peripheral address block
PABBUF EQU >1000 * File data buffer
* GPU Equates
CSON EQU >03A0 * SPI chip select enable
CSOFF EQU >03C0 * SPI chip select disable
CMD_RD EQU >0B00 * Fast Read
CMD_RS EQU >0500 * Read Status Register
CMD_WE EQU >0600 * Write Enable
CMD_PP EQU >0200 * Page Program
CMD_SE EQU >D800 * Sector Erase
* Start address of host-side code
AORG >A000
CHKSUM DATA >F981 * Use emulator to determine value once code is finalized.
START LIMI 0
LWPI >8300
* Checksum the code to help ensure it loaded from disk
* without error.
LI R0,START
CLR R1
LI R2,CPUEND-START/2
CSUM01 A *R0+,R1
DEC R2
JNE CSUM01
LI R0,GSTART
LI R2,GPUEND-GSTART/2
CSUM02 A *R0+,R1
DEC R2
JNE CSUM02
* Checksum test disabled during updates.
C R1,@CHKSUM
JNE QUIT
LWPI WRKSP
LI R10,STACK
* Boot tracking
BL @BOOTTR
* Detect F18A
BL @F18ADT
* Graphics mode
BL @GMODE
* Check for F18A
MOV @F18A,R0
JNE MAIN1
* Diplay error if not present
LI R0,11*32+7+NAMETB * Position
LI R1,F18ERR * Source address
LI R2,17 * Length
BL @VMBW
JMP ENDIT
* Copy GPU code to VDP RAM
MAIN1 LI R0,GPUPRG
LI R1,GPUPRG
LI R2,GPUEND-GPUPRG
BL @VMBW
* Display the checksum
LI R0,0*32+0+NAMETB * Display the checksum at screen location 0
MOV @CHKSUM,R1
BL @HEXDMP
* Check that all files are present
LI R0,FILEN1 * Bit stream file
LI R2,FILEL1
BL @CKFILE
MOV R0,R0 * Check for error
JNE ENDIT
LI R0,FILEN2 * Extra data file
LI R2,FILEL2
BL @CKFILE
MOV R0,R0 * Check for error
JNE ENDIT
* Display initial information
BL @DSPINF
MOV R0,R0 * Check for quit
JNE QUIT
* Initialize progress indicator
BL @INIPGI
* Display power message
LI R0,8*32+1+NAMETB
LI R1,POWER
LI R2,29
BL @VMBW
* Call GPU initialize routine
BL @STSCLR
LI R0,GPUINI
BL @DO_GPU
* Read bit stream file
BL @RDBIT
MOV R0,R0 * Check for error
JNE ENDIT
* Read extra data file
BL @RDEXT
MOV R0,R0 * Check for error
JNE ENDIT
* Call GPU finalization routine
LI R0,GPUUPD
BL @DO_GPU
BL @VERIFY
MOV R0,R0 * R0 == >0000 if successful
JNE MAIN1 * Recopy GPU code to reset initial data variables
* Call GPU clean up routine
LI R0,GPUCLN
BL @DO_GPU
* Display completed messages
LI R0,8*32+NAMETB * Clear area
LI R1,>2000
LI R2,64
BL @VSMW
LI R0,8*32+4+NAMETB
LI R1,UPDCOM
LI R2,23
BL @VMBW
LI R0,9*32+4+NAMETB
LI R1,PRESSA
LI R2,23
BL @VMBW
* Wait for keypress
ENDIT CLR @KEYDEV
ENDLP BLWP @KSCAN
MOV @STATUS,R0
JEQ ENDLP
* Quit
QUIT LWPI >83E0
LIMI 2
BLWP @>0000
*// MAIN
**
* Display R1 as a hex number at screen location in R0
* Destroys R2
*
HEX TEXT '0123456789ABCDEF'
HEXDMP
MOV R11,R2 * Save return address
BL @VWAD
MOV R2,R11 * Restore return address
MOV R1,R2
ANDI R2,>F000 * Isolate the first digit
SRL R2,12 * Convert to a number
MOVB @HEX(R2),@VDPWD * Convert to ASCII and write to the screen
MOV R1,R2
ANDI R2,>0F00
SRL R2,8
MOVB @HEX(R2),@VDPWD
MOV R1,R2
ANDI R2,>00F0
SRL R2,4
MOVB @HEX(R2),@VDPWD
MOV R1,R2
ANDI R2,>000F
MOVB @HEX(R2),@VDPWD
B *R11
*// HEXDMP
**
* Call a GPU routine and wait for it to complete
* R0 = address of GPU routine in VRAM
*
DO_GPU
MOV R11,*R10+ * Push return address onto the stack
MOV R0,R1 * Save R0
SRL R0,8 * Move MSB to LSB
AI R0,>3600 * VR36 = MSB of GPU address
BL @VWTR
ANDI R1,>00FF
AI R1,>3700 * VR37 = LSB of GPU address
MOV R1,R0
BL @VWTR
* Wait for the GPU to finish and go idle.
LI R0,>0F02 * Set the status port to read SR2
BL @VWTR
DO_IDL MOVB @VDPSTA,R1
JLT DO_IDL * MSbit = '1' while GPU is running. Makes the byte a negative value
LI R0,>0F00 * Set status port to read SR0
BL @VWTR
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// DO_GPU
*********************************************************************
*
* Display initial information
*
DSPINF MOV R11,*R10+ * Push return address onto the stack
* Display info
LI R0,2*32+6+NAMETB
LI R1,F18UPD
LI R2,20
BL @VMBW
LI R0,8*32+NAMETB
LI R1,>2000
LI R2,64
BL @VSMW
LI R0,8*32+7+NAMETB
LI R1,PRESSP
LI R2,18
BL @VMBW
LI R0,9*32+10+NAMETB
LI R1,PRESSQ
LI R2,12
BL @VMBW
* Display version numbers
LI R0,4*32+8+NAMETB
LI R1,YVRLBL
LI R2,14
BL @VMBW
MOV @F18VER,R0
BL @DSPVER
LI R0,5*32+8+NAMETB
LI R1,VERLBL
LI R2,14
BL @VMBW
LI R0,FRMVER
BL @DSPVER
* Check keys
CLR @KEYDEV
DSPIN1 BLWP @KSCAN
CB @P,@KEY
JEQ DSPIN3
CB @Q,@KEY
JEQ DSPIN2
JMP DSPIN1
* Quit
DSPIN2 SETO R0 * Signal quit
JMP DSPIN4
* Clear info
DSPIN3 BL @DSPCLR
CLR R0 * Signal continue
* Return
DSPIN4 DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// DSPINF
**
* Clears lines 8 to 13
*
DSPCLR
MOV R11,*R10+ * Push return address onto the stack
LI R0,8*32+NAMETB
LI R1,>2000
LI R2,192
BL @VSMW
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// DSPCLR
**
* Clears lines 14 to 20
*
STSCLR
MOV R11,*R10+ * Push return address onto the stack
LI R0,14*32+NAMETB
LI R1,>2000
LI R2,224
BL @VSMW
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// STSCLR
*********************************************************************
*
* Display version No
*
* RO contains primary version number in MSB
* and secondary version number in LSB
*
DSPVER MOV R0,R1
AI R1,>3000 * Add ASCII code for 0
MOVB R1,@VDPWD
LI R1,>2E00 * Full stop
MOVB R1,@VDPWD
MOV R0,R1 * LSB
SWPB R1
AI R1,>3000
MOVB R1,@VDPWD
B *R11
*// DPSVER
*********************************************************************
*
* Read bit stream file
*
RDBIT MOV R11,*R10+ * Push return address onto the stack
* Setup variables and callback
LI R0,1 * File number
MOV R0,@FILENO
CLR @BLKNO
LI R0,FL1CRC * CRC table
MOV R0,@CRCTBL
LI R0,FILE1S/BLKSIZ * Number of blocks to read
MOV R0,@BLKCNT
LI R0,CALLBK * Callback adress from RDFILE
MOV R0,@FILECB
LI R0,FILEN1 * File name
LI R2,FILEL1 * File name length
* Call the file reading routine
BL @RDFILE
* Return
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// RDBIT
*********************************************************************
*
* Read extra data file
*
RDEXT MOV R11,*R10+ * Push return address onto the stack
* Setup variables and callback
LI R0,2 * File number
MOV R0,@FILENO
CLR @BLKNO
LI R0,FL2CRC * CRC table
MOV R0,@CRCTBL
LI R0,FILE2S/BLKSIZ * Number of blocks to read
MOV R0,@BLKCNT
LI R0,CALLBK * Callback adress from RDFILE
MOV R0,@FILECB
LI R0,FILEN2 * File name
LI R2,FILEL2 * File name length
* Call the file reading routine
BL @RDFILE
* Return
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// RDEXT
*********************************************************************
*
* Callback routine after block is read
*
CALLBK MOV R11,*R10+ * Push return address onto the stack
* Update progress indicator
INC @PGICNT
BL @UPDPGI
* Setup parameters for GPU routine
LI R0,GPUFNO * File number
LI R1,FILENO
LI R2,2
BL @VMBW
LI R0,GPUBNO * Block number
LI R1,BLKNO
LI R2,2
BL @VMBW
LI R0,GPUCRC * CRC checksum
MOV @BLKNO,R1
SLA R1,1 * Convert to word offset
A @CRCTBL,R1
LI R2,2
BL @VMBW
LI R0,GPURES * Clear result
CLR R1
LI R2,2
BL @VSMW
* Call GPU routine
LI R0,GPUCPY/256+>3600 * High byte
BL @VWTR
LI R0,GPUCPY
ANDI R0,>00FF
AI R0,>3700 * Low byte
BL @VWTR
* Wait for GPU completion
CALLB1 CLR R1
LI R0,GPURES+1
BL @VSBR
MOV R1,R1
JEQ CALLB1
CI R1,>0100 * Check for success
JEQ CALLB2
* Display error message
LI R0,11*32+9+NAMETB * Position
LI R1,CRCERR * Source address
LI R2,9 * Length
BL @VMBW
SETO R0
JMP CALLB3
CALLB2 CLR R0
* Update block number
CALLB3 INC @BLKNO
* Return
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// CALLBK
**
* Verify the data written to the final SPI sectors.
* Similar to the call-back function but does not
* need to read the data files from disk, only passes
* the file no, block no, and CRC to the GPU verify routine.
*
* Returns >0000 if successful, otherwise >FFFF
*
VERIFY
MOV R11,*R10+ * Push return address onto the stack
BL @INIPGI
* Setup file 1
LI R0,1
MOV R0,@FILENO
LI R0,GPUFNO * File number
LI R1,FILENO
LI R2,2
BL @VMBW
CLR @BLKNO * Start at block 0
LI R0,FL2CRC-FL1CRC
SRA R0,1 * Get the number of CRC values for the file
MOV R0,@BLKCNT
LI R0,FL1CRC * CRC table
MOV R0,@CRCTBL
BL @VFYFIL
MOV R0,R0 * R0 == >0000 if successful
JNE VERRET
* Setup file 2
LI R0,2
MOV R0,@FILENO
LI R0,GPUFNO * File number
LI R1,FILENO
LI R2,2
BL @VMBW
CLR @BLKNO * Start at block 0
LI R0,FLCRCE-FL2CRC
SRA R0,1 * Get the number of CRC values for the file
MOV R0,@BLKCNT
LI R0,FL2CRC * CRC table
MOV R0,@CRCTBL
BL @VFYFIL
* Return
VERRET
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// VERIFY
**
* Drives the CRC error value and block count to the GPU verify routine
* that will CRC check the block from the flash.
*
VFYFIL
MOV R11,*R10+ * Push return address onto the stack
* Update progress indicator
VRFY05
INC @PGICNT
BL @UPDPGI
LI R0,GPUBNO * Block number
LI R1,BLKNO
LI R2,2
BL @VMBW
LI R0,GPUCRC * CRC checksum
MOV @CRCTBL,R1
LI R2,2
BL @VMBW
LI R0,GPURES * Clear result
CLR R1
LI R2,2
BL @VSMW
* Call GPU routine
LI R0,GPUVFY/256+>3600 * High byte
BL @VWTR
LI R0,GPUVFY
ANDI R0,>00FF
AI R0,>3700 * Low byte
BL @VWTR
* Wait for GPU completion
VRFY20 CLR R1
LI R0,GPURES+1 * Get the LSB of the return value
BL @VSBR
MOV R1,R1
JEQ VRFY20
CI R1,>0100 * 1 == success
JNE VFYERR
INC @BLKNO * Update block number
INCT @CRCTBL * Next CRC value
DEC @BLKCNT * Count the block
JNE VRFY05
CLR R0 * Return R0 = >0000
JMP VFYRET
* Display error message
VFYERR
BL @DSPCLR
LI R0,11*32+0+NAMETB
LI R1,TVFY01
LI R2,64 * Two lines of text, 32 bytes each
BL @VMBW
SETO R0 * Return R0 = >FFFF
* Return
VFYRET
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// VFYFIL
*********************************************************************
*
* Read file
*
* R0: Address of file name
* R2: Length of file name
* @RECCNT contains number of records to read
* @FILECB contains address of routine to call when a record is read
*
RDFILE MOV R11,*R10+ * Push return address onto the stack
MOV R2,R1
AI R1,5
MOV R1,@FILENL * Set file name length
LI R1,FILENM
SETFNM MOVB *R0+,*R1+ * Set the file name
DEC R2
JNE SETFNM
LI R0,>2000 * Pad with spaces
SETFN1 CI R1,PABDTE
JEQ SETFN2
MOVB R0,*R1+
JMP SETFN1
* Copy PAB data into VDP RAM
SETFN2 LI R0,PAB
LI R1,PABDAT
LI R2,PABDTE-PABDAT
BL @VMBW
* Open
LI R0,PAB+9 * Pointer to name length
MOV R0,@FNPNTR * Store in >8356
BLWP @DSRLNK * Open file
DATA 8
* Check for errors
LI R0,PAB+1 * Get status byte
BL @VSBR
ANDI R1,>E000 * Mask off error code
JNE FERROR
MOVB @STATUS,R0
COC @COND,R0 * Check for device error
JEQ FERROR * This doesn't seem to be working
* Read
LI R0,PAB
LI R1,>0200 * READ op-code
BL @VSBW * Change op-code to READ
BLKLP LI R0,BLKSIZ*8 * 8 records of 128 bytes per KB
MOV R0,@RECCNT
LI R0,PABBUF * Setup destination address
MOV R0,@DSTADR
CLR R1
LI R2,BLKSIZ*1024
BL @VSMW * Clear VDP buffer
RECLP LI R0,PAB+2 * Write destination to PAB
LI R1,DSTADR
LI R2,2
BL @VMBW
LI R0,PAB+9 * Pointer to name length
MOV R0,@FNPNTR * Store in >8356
BLWP @DSRLNK * Read record from file
DATA 8
* Check for errors
LI R0,PAB+1 * Get status byte
BL @VSBR
ANDI R1,>E000 * Mask off error code
JNE FERROR
MOVB @STATUS,R0
COC @COND,R0 * Check for device error
JEQ FERROR * This doesn't seem to be working
LI R0,PAB+5 * Get bytes read
CLR R1
BL @VSBR
CI R1,>8000 * Check if 128 bytes read
JNE FERROR
* Update destination address
MOV @DSTADR,R0
AI R0,128
MOV R0,@DSTADR
* Inner loop
DEC @RECCNT
JNE RECLP
* Call callback routine
MOV @FILECB,R0
BL *R0
MOV R0,R0 * Check for error
JNE RDFEND
* Outer loop
DEC @BLKCNT
JNE BLKLP
* Close
LI R0,PAB
LI R1,>0100 * CLOSE op-code
BL @VSBW * Change op-code to READ
LI R0,PAB+9 * Pointer to name length
MOV R0,@FNPNTR * Store in >8356
BLWP @DSRLNK * Close file
DATA 8
* Signal success
CLR R0
JMP RDFEND
* File error
FERROR SRL R1,5 * Move error code bits into place in MSB
CI R1,>0500 * Error code 5 = end of file
JNE FERR1
C @ONE,@BLKCNT * Check if we're at the last block
JNE FERR1
* Call callback routine one last time
MOV @FILECB,R0
BL *R0
MOV R0,R0 * Check for error
JNE RDFEND
* Signal success
CLR R0
JMP RDFEND
FERR1 AI R1,>3000 * Add ASCII code for 0
MOVB R1,@FILERR+11
* Display error
LI R0,10*32+10+NAMETB * Position
LI R1,FILERR * Source address
LI R2,12 * Length
BL @VMBW
* Signal error
SETO R0
* Return
RDFEND DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// RDFILE
*********************************************************************
*
* Check for file existence
*
* R0: Address of file name
* R2: Length of file name
*
CKFILE MOV R11,*R10+ * Push return address onto the stack
MOV R2,R1
AI R1,5
MOV R1,@FILENL * Set file name length
LI R1,FILENM
CKFIL1 MOVB *R0+,*R1+ * Set the file name
DEC R2
JNE CKFIL1
LI R0,>2000 * Pad with spaces
CKFIL2 CI R1,PABDTE
JEQ CKFIL3
MOVB R0,*R1+
JMP CKFIL2
* Copy PAB data into VDP RAM
CKFIL3 LI R0,PAB
LI R1,PABDAT
LI R2,PABDTE-PABDAT
BL @VMBW
* Open
LI R0,PAB+9 * Pointer to name length
MOV R0,@FNPNTR * Store in >8356
BLWP @DSRLNK * Open file
DATA 8
* Check for errors
LI R0,PAB+1 * Get status byte
BL @VSBR
ANDI R1,>E000 * Mask off error code
JNE CKFIL4
* Close
LI R0,PAB
LI R1,>0100 * CLOSE op-code
BL @VSBW * Change op-code to READ
LI R0,PAB+9 * Pointer to name length
MOV R0,@FNPNTR * Store in >8356
BLWP @DSRLNK * Close file
DATA 8
* Signal success
CLR R0
JMP CKFIL6
* File error
CKFIL4 SRL R1,5 * Move error code bits into place in MSB
MOV R1,R3 * Save it
AI R1,>3000 * Add ASCII code for 0
MOVB R1,@FILERR+11 * Copy into error message
* Display error
LI R0,10*32+10+NAMETB * Position
LI R1,FILERR * Source address
LI R2,12 * Length
BL @VMBW
CI R3,>0700 * Check for file not found
JNE CKFIL5
LI R0,12*32+2+NAMETB * Position
LI R1,FNFERR * Source address
LI R2,15 * Length
BL @VMBW
LI R0,12*32+17+NAMETB * Position
LI R1,FILEDV
MOV @FILENL,R2 * Length
BL @VMBW
* Signal error
CKFIL5 SETO R0
* Return
CKFIL6 DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// CKFILE
*********************************************************************
*
* Boot tracking
*
* Code adapted from:
* 1.7. The Art Of Assembly Part 7. Why A Duck?
* By Bruce Harrison 1991
*
* THE SECTION HERE AT LABEL OPEN PERFORMS "BOOT TRACKING"
* THAT IS, IT TELLS OUR PROGRAM WHICH DRIVE IT WAS LOADED FROM
*
BOOTTR MOV @>83D0,R12 * GET THE CRU BASE IN R12
MOV @>83D2,R1 * GET THE ROM ADDRESS FOR DEVICE
SBO 0 * ENABLE THE ROM
AI R1,4 * ADDING FOUR PUTS US AT THE LENGTH BYTE
MOVB *R1+,R2 * PLACE THAT IN R2 AND INCREMENT R1
SRL R2,8 * RIGHT JUSTIFY LENGTH IN R2
LI R3,FILEDV * POINT TO TEXT BUFFER
BOOTT1 MOVB *R1+,*R3+ * MOV ONE BYTE FROM ROM TO TEXT BUFFER
DEC R2 * FINISHED?
JNE BOOTT1 * NO, DO ANOTHER BYTE
SBZ 0 * DISABLE THE ROM
B *R11 * RETURN
*// BOOTTR
*********************************************************************
*
* Initialize progress indicator
*
INIPGI MOV R11,*R10+ * Push return address onto the stack
CLR @PGICNT * Clear counter
LI R0,21*32+NAMETB
LI R1,PGIDAT
LI R2,96
BL @VMBW
* Return
DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// INIPGI
*********************************************************************
*
* Update progress indicator
*
* Progress is controlled by @PGICNT (0 - (PGITOT-1))
*
UPDPGI MOV R11,*R10+ * Push return address onto the stack
LI R3,PGIW * Width of progress indicator
MPY @PGICNT,R3 * Multiply by progress counter
LI R0,PGITOT
DIV R0,R3 * Divide by total number of blocks
LI R0,22*32+1+NAMETB
BL @VWAD
* Full patterns
LI R1,>0700 * Full pattern
MOV R3,R2
SRA R2,3 * Calculate number of full patterns
JEQ UPDPG1
UPDPG0 MOVB R1,@VDPWD * Write full patterns to VDP
DEC R2
JNE UPDPG0
* Partial pattern
UPDPG1 MOV R3,R1
ANDI R1,>0007 * Mod 8
JEQ UPDPG2
DEC R1
SWPB R1
MOVB R1,@VDPWD * Write partial pattern to VDP
SETO R1 * Signal partial pattern
* Empty patterns
UPDPG2 SRA R3,3 * Calculate number of empty patterns
LI R2,30
S R3,R2 * 30 - full patterns
MOV R1,R1
JEQ UPDPG3
DEC R2 * -1 if there is a partial pattern
UPDPG3 MOV R2,R2
JEQ UPDPG5
LI R1,>2000 * Space
UPDPG4 MOVB R1,@VDPWD * Write space to VDP
DEC R2
JNE UPDPG4
* Return
UPDPG5 DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// INIPGI
*********************************************************************
*
* Detect F18A
*
F18ADT MOV R11,*R10+ * Push return address onto the stack
* F18A Unlock
LI R0,>391C * VR1/57, value 00011100
BL @VWTR * Write once
BL @VWTR * Write twice, unlock
LI R0,>01E0 * VR1, value 11100000, a real sane setting
BL @VWTR * Write reg
* Copy GPU code to VRAM
LI R0,GPUPRG
LI R1,GPUDT
LI R2,GPUDTE-GPUDT
BL @VMBW
* Set the GPU PC which also triggers it
LI R0,GPUPRG/256+>3600 * High byte
BL @VWTR
LI R0,>3700 * Low byte
BL @VWTR
* Compare the result in GPUPRG
LI R0,GPUPRG
BL @VRAD
MOVB @VDPRD,R0
JEQ F18AOK
CLR @F18A
JMP F18ADE
F18AOK SETO @F18A
* Get the version number
LI R0,>0F0E * Choose version status reg
BL @VWTR
CLR R0
MOVB @VDPSTA,R0
MOV R0,R1
ANDI R0,>F000
SRL R0,4 * MSB - major version no
ANDI R1,>0F00
SRL R1,8
SOC R1,R0 * LSB - minor version no
MOV R0,@F18VER
LI R0,>0F00 * Choose ordinary status reg
BL @VWTR
F18ADE DECT R10 * Pop return address off the stack
MOV *R10,R11
B *R11
*// F18ADT
GPUDT CLR @GPUPRG
IDLE
GPUDTE
*********************************************************************
*
* Setup graphics mode
*
GMODE MOV R11,*R10+ * Push return address onto the stack
LI R0,>0000 * Reg 0: Graphics mode I,
BL @VWTR * external video off
LI R0,>01C2 * Reg 1: 16K, display on, no interrupt,
BL @VWTR * size = 1, mag = 0.
LI R0,>0200 * Reg 2: Name table
BL @VWTR * NAMETB = >1800 (>06 * >400), >300 bytes
LI R0,>030E * Reg 3: Color Table
BL @VWTR * COLRTB = >0380 (>0E * >40), >20 bytes
LI R0,>0401 * Reg 4: Pattern Table
BL @VWTR * PTRNTB = >0800 (>01 * >800), >800 bytes
LI R0,>0506 * Reg 5: Sprite Attribute Table
BL @VWTR * SPRATB = >0300 (>06 * >80), >80 bytes
LI R0,>0601 * Reg 6: Sprite Pattern Table
BL @VWTR * SPRPTB = >0800 (>01 * >800), >800 bytes
LI R0,>07F4 * Reg 7: Text-mode color and backdrop color
BL @VWTR * Blue backdrop
* Put a copy of Reg 1 at >83D4
LI R0,>C200
MOVB R0,@>83D4
* Disable sprites
LI R0,SPRATB
LI R1,>D000
BL @VSBW
* Initialize color table
LI R0,COLRTB
LI R1,CLRSET
LI R2,>20 * 32 bytes
BL @VMBW
* Clear name table
LI R0,NAMETB
LI R1,>2000 * Space