-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvbasic_prologue.asm
2375 lines (2208 loc) · 39.4 KB
/
cvbasic_prologue.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
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
;
; CVBasic prologue (BASIC compiler for Colecovision)
;
; by Oscar Toledo G.
; https://nanochess.org/
;
; Creation date: Feb/27/2024.
; Revision date: Feb/29/2024. Turns off sound. Now it reads the controllers.
; Added 16-bit multiply, division, modulo, and abs.
; Added random generator. Added sound routines.
; Revision date: Mar/03/2024. Removed fname directive to use gasm80.
; Revision date: Mar/05/2024. Added support for Sega SG1000.
; Revision date: Mar/06/2024. Added ENASCR, DISSCR, and CPYBLK.
; Revision date: Mar/08/2024. Added modes 0, 1 and 2.
; Revision date: Mar/12/2024. Added support for MSX.
; Revision date: Mar/14/2024. Added _sgn16.
; Revision date: Mar/15/2024. Added upper 16k enable for MSX.
; Revision date: Apr/11/2024. Added support for formatting numbers. Added
; support for Super Game Module.
; Revision date: Apr/13/2024. Saved bytes in SG-1000 ROMs. Faster LDIRVM.
; Shorter mode setting subroutines.
; Revision date: Apr/26/2024. Interruption handler saves current bank.
; Revision date: Apr/27/2024. Music player now supports bank switching.
;
VDP: equ $98+$26*COLECO+$26*SG1000
JOYSEL: equ $c0
KEYSEL: equ $80
PSG: equ $ff-$80*SG1000
JOY1: equ $fc-$20*SG1000
JOY2: equ $ff-$22*SG1000
BASE_RAM: equ $e000-$7000*COLECO-$2000*SG1000+$0c00*SGM
STACK: equ $f000-$7c00*COLECO-$2c00*SG1000+$0c00*SGM
if COLECO
org $8000
db $55,$aa
dw 0
dw 0
dw 0
dw 0
dw START
jp 0 ; rst $08
jp 0 ; rst $10
jp 0 ; rst $18
jp 0 ; rst $20
jp 0 ; rst $28
jp 0 ; rst $30
jp 0 ; rst $38
jp nmi_handler
endif
if SG1000
org $0000
di
im 1
jp START
db $ff,$ff
jp 0
db $ff,$ff,$ff,$ff,$ff
jp 0
db $ff,$ff,$ff,$ff,$ff
jp 0
db $ff,$ff,$ff,$ff,$ff
jp 0
db $ff,$ff,$ff,$ff,$ff
jp 0
db $ff,$ff,$ff,$ff,$ff
jp 0
db $ff,$ff,$ff,$ff,$ff
jp nmi_handler ; It should be called int_handler.
endif
if MSX
ORG $4000
db "AB"
dw START
dw $0000
dw $0000
dw $0000
dw $0000
endif
WRTVDP:
ld a,b
out (VDP+1),a
ld a,c
or $80
out (VDP+1),a
ret
SETWRT:
ld a,l
out (VDP+1),a
ld a,h
or $40
out (VDP+1),a
ret
SETRD:
ld a,l
out (VDP+1),a
ld a,h
and $3f
out (VDP+1),a
ret
WRTVRM:
push af
call SETWRT
pop af
out (VDP),a
ret
if SG1000
db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
; Located at $0066
ei ; NMI handler (pause button)
retn
endif
RDVRM:
push af
call SETRD
pop af
ex (sp),hl
ex (sp),hl
in a,(VDP)
ret
FILVRM:
push af
call SETWRT
.1: pop af
out (VDP),a
push af
dec bc
ld a,b
or c
jp nz,.1
pop af
ret
LDIRVM:
EX DE,HL
CALL SETWRT
EX DE,HL
DEC BC
INC C
LD A,B
LD B,C
INC A
LD C,VDP
.1:
if SG1000
NOP ; SG1000 is faster (reported by SiRioKD)
endif
OUTI
JP NZ,.1
DEC A
JP NZ,.1
RET
LDIRVM3:
call .1
call .1
.1: push hl
push de
push bc
call LDIRVM
pop bc
pop de
ld a,d
add a,8
ld d,a
pop hl
ret
DISSCR:
call nmi_off
ld bc,$a201
call WRTVDP
jp nmi_on
ENASCR:
call nmi_off
ld bc,$e201
call WRTVDP
jp nmi_on
CPYBLK:
pop hl
ex af,af'
pop af
ld b,a
pop af
ld c,a
pop de
ex (sp),hl
call nmi_off
.1: push bc
push hl
push de
ld b,0
call LDIRVM
pop hl
ld bc,$0020
add hl,bc
ex de,hl
pop hl
ex af,af'
ld c,a
ld b,0
add hl,bc
ex af,af'
pop bc
djnz .1
jp nmi_on
nmi_off:
if COLECO
push hl
ld hl,mode
set 0,(hl)
pop hl
endif
if SG1000+MSX
di
endif
ret
nmi_on:
if COLECO
push af
push hl
ld hl,mode
res 0,(hl)
nop
bit 1,(hl)
jp nz,nmi_handler.0
pop hl
pop af
endif
if SG1000+MSX
ei
endif
ret
if COLECO
keypad_table:
db $0f,$08,$04,$05,$0c,$07,$0a,$02
db $0d,$0b,$00,$09,$03,$01,$06,$0f
endif
if SG1000
;--------------------------------------------------------------------
; SG-1000 / SC-3000 1-player Joystick/Keyboard routines
;--------------------------------------------------------------------
; SG-1000 with keyboard and SC-3000 returns data from joystick
; merged with data from keyboard as Sega standard.
;
; Bits
; Format: | 5 | 4 | 3 | 2 | 1 | 0 |
; | Trig R | Trig L | Right | Left | Down | Up |
; | Ins/Del | Home/Clr | Cursor Right | Cursor Left | Cursor Down | Cursor Up |
;
; INPUT:
; HL = INPUT DATA ADDRESS
;
; OUTPUT:
; A = joy/key bits (0 = pressed, 1 = not pressed)
;
;--------------------------------------------------------------------
SG1000_PPI_PLAYER_1_READ:
ld a, 7 ; Select Row 7
out ($de), a
in a, ($de) ; Readback the value
cp 7 ; if keyboard not present => A = $FF
jr z, .readKeybAndJoy ; Keyboard present
in a, (JOY1) ; Read Joystick
;or $C0
ret
; Keyboard routine
; This routine read joystick and merge the obtained data with corresponding keyboard keys (Cursors + Home/Clr + Ins/Del) that simulate the joystick .
;
.readKeybAndJoy:
in a, ($dc) ; Read Joystick
;or $C0
ld c, a
ld a, $04
out ($de), a
in a, ($dc)
bit 5, a ; Key Cursor Down => Joy Down
jp nz, .nocursordown
res 1, c
.nocursordown:
ld a, $05
out ($de), a
in a, ($dc)
bit 5, a ; Key Cursor Left => Joy Left
jp nz, .nocursorleft
res 2, c
.nocursorleft:
ld a, $06
out ($de), a
in a, ($dc)
bit 5, a ; Key Cursor Right => Joy Right
jp nz, .nocursorright
res 3, c
.nocursorright:
bit 6, a ; Key Cursor Up => Joy Up
jp nz, .nocursorup
res 0, c
.nocursorup:
ld a, $02
out ($de), a
in a, ($dc)
bit 4, a ; Key Home/Clr => Joy Fire 1 (Trig L)
jp nz, .nokeyHomeClr
res 4, c
.nokeyHomeClr:
ld a, $03
out ($de), a
in a, ($dc)
bit 4, a ; Key Ins/Del => Joy Fire 2 (Trig R)
jp nz, .nokeyInsDel
res 5, c
.nokeyInsDel:
ld a, c
ret
endif
cls:
ld hl,$1800
ld (cursor),hl
ld bc,$0300
ld a,$20
call nmi_off
call FILVRM
jp nmi_on
print_string:
ld c,a
ld b,0
ld de,(cursor)
ld a,d
and $03
or $18
ld d,a
push de
push bc
call nmi_off
call LDIRVM
call nmi_on
pop bc
pop hl
add hl,bc
ld (cursor),hl
ret
print_number:
ld b,0
call nmi_off
print_number5:
ld de,10000
call print_digit
print_number4:
ld de,1000
call print_digit
print_number3:
ld de,100
call print_digit
print_number2:
ld de,10
call print_digit
print_number1:
ld de,1
ld b,e
call print_digit
jp nmi_on
print_digit:
ld a,$2f
or a
.2: inc a
sbc hl,de
jp nc,.2
add hl,de
cp $30
jr nz,.3
ld a,b
or a
ret z
dec a
jr z,.4
ld a,c
jr .5
.4:
ld a,$30
.3: ld b,1
.5: push hl
ld hl,(cursor)
ex af,af'
ld a,h
and $03
or $18
ld h,a
ex af,af'
call WRTVRM
inc hl
ld (cursor),hl
pop hl
ret
define_sprite:
ex de,hl
ld l,a
ld h,0
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
add hl,hl ; x16
add hl,hl ; x32
ld c,l
ld b,h
pop af
pop hl
push af
add hl,hl ; x2
add hl,hl ; x4
ld h,$07
add hl,hl ; x8
add hl,hl ; x16
add hl,hl ; x32
ex de,hl
call nmi_off
call LDIRVM
jp nmi_on
define_char:
ex de,hl
ld l,a
ld h,0
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
ld c,l
ld b,h
pop af
pop hl
push af
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
ex de,hl
call nmi_off
ld a,(mode)
and 4
jr nz,.1
call LDIRVM3
jp nmi_on
.1: call LDIRVM
jp nmi_on
define_color:
ex de,hl
ld l,a
ld h,0
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
ld c,l
ld b,h
pop af
pop hl
push af
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
ex de,hl
set 5,d
call nmi_off
call LDIRVM3
jp nmi_on
update_sprite:
pop bc
ld (sprite_data+3),a
pop af
ld (sprite_data+2),a
pop af
ld (sprite_data+1),a
pop af
ld (sprite_data),a
pop af
push bc
ld de,sprites
add a,a
add a,a
ld e,a
ld hl,sprite_data
ld bc,4
ldir
ret
; Fast 16-bit multiplication.
_mul16:
ld b,h
ld c,l
ld a,16
ld hl,0
.1:
srl d
rr e
jr nc,.2
add hl,bc
.2: sla c
rl b
dec a
jp nz,.1
ret
; Fast 16-bit division.
_div16:
ld b,h
ld c,l
ld hl,0
ld a,16
.1:
rl c
rl b
adc hl,hl
sbc hl,de
jp nc,.2
add hl,de
.2:
ccf
dec a
jp nz,.1
rl c
rl b
ld h,b
ld l,c
ret
; Fast 16-bit modulo.
_mod16:
ld b,h
ld c,l
ld hl,0
ld a,16
.1:
rl c
rl b
adc hl,hl
sbc hl,de
jp nc,.2
add hl,de
.2:
ccf
dec a
jp nz,.1
ret
_abs16:
bit 7,h
ret z
ld a,h
cpl
ld h,a
ld a,l
cpl
ld l,a
inc hl
ret
_sgn16:
ld a,h
or l
ret z
bit 7,h
ld hl,$ffff
ret nz
inc hl
inc hl
ret
; Random number generator.
; From my game Mecha Eight.
random:
ld hl,(lfsr)
ld a,h
or l
jr nz,.0
ld hl,$7811
.0: ld a,h
and $80
ld b,a
ld a,h
and $02
rrca
rrca
xor b
ld b,a
ld a,h
and $01
rrca
xor b
ld b,a
ld a,l
and $20
rlca
rlca
xor b
rlca
rr h
rr l
ld (lfsr),hl
ret
sn76489_freq:
if COLECO+SG1000
ld b,a
ld a,l
and $0f
or b
out (PSG),a
add hl,hl
add hl,hl
add hl,hl
add hl,hl
ld a,h
and $3f
out (PSG),a
endif
ret
sn76489_vol:
if COLECO+SG1000
cpl
and $0f
or b
out (PSG),a
endif
ret
sn76489_control:
if COLECO+SG1000
and $0f
or $e0
out (PSG),a
endif
ret
ay3_reg:
if COLECO
push af
ld a,b
out ($50),a
pop af
out ($51),a
ret
endif
if SG1000
ret
endif
if MSX
ld e,a
ld a,b
jp WRTPSG
endif
ay3_freq:
if COLECO
out ($50),a
push af
ld a,l
out ($51),a
pop af
inc a
out ($50),a
push af
ld a,h
and $0f
out ($51),a
pop af
ret
endif
if SG1000
ret
endif
if MSX
ld e,l
call WRTPSG
ld e,h
inc a
jp WRTPSG
endif
if SG1000
; Required for SG1000 as it doesn't have a BIOS
;
; My personal font for TMS9928.
;
; Patterned after the TMS9928 programming manual 6x8 letters
; with better lowercase letters, also I made a proper
; AT sign.
;
font_bitmaps:
db $00,$00,$00,$00,$00,$00,$00,$00 ; $20 space
db $20,$20,$20,$20,$20,$00,$20,$00 ; $21 !
db $50,$50,$50,$00,$00,$00,$00,$00 ; $22 "
db $50,$50,$f8,$50,$f8,$50,$50,$00 ; $23 #
db $20,$78,$a0,$70,$28,$f0,$20,$00 ; $24 $
db $c0,$c8,$10,$20,$40,$98,$18,$00 ; $25 %
db $40,$a0,$40,$a0,$a8,$90,$68,$00 ; $26 &
db $60,$20,$40,$00,$00,$00,$00,$00 ; $27 '
db $10,$20,$40,$40,$40,$20,$10,$00 ; $28 (
db $40,$20,$10,$10,$10,$20,$40,$00 ; $29 )
db $00,$a8,$70,$20,$70,$a8,$00,$00 ; $2a *
db $00,$20,$20,$f8,$20,$20,$00,$00 ; $2b +
db $00,$00,$00,$00,$00,$60,$20,$40 ; $2c ,
db $00,$00,$00,$fc,$00,$00,$00,$00 ; $2d -
db $00,$00,$00,$00,$00,$00,$60,$00 ; $2e .
db $00,$08,$10,$20,$40,$80,$00,$00 ; $2f /
db $70,$88,$98,$a8,$c8,$88,$70,$00 ; $30 0
db $20,$60,$20,$20,$20,$20,$f8,$00 ; $31 1
db $70,$88,$08,$10,$60,$80,$f8,$00 ; $32 2
db $70,$88,$08,$30,$08,$88,$70,$00 ; $33 3
db $30,$50,$90,$90,$f8,$10,$10,$00 ; $34 4
db $f8,$80,$f0,$08,$08,$08,$f0,$00 ; $35 5
db $30,$40,$80,$f0,$88,$88,$70,$00 ; $36 6
db $f8,$08,$10,$20,$20,$20,$20,$00 ; $37 7
db $70,$88,$88,$70,$88,$88,$70,$00 ; $38 8
db $70,$88,$88,$78,$08,$10,$60,$00 ; $39 9
db $00,$00,$00,$60,$00,$60,$00,$00 ; $3a :
db $00,$00,$00,$60,$00,$60,$20,$40 ; $3b ;
db $10,$20,$40,$80,$40,$20,$10,$00 ; $3c <
db $00,$00,$f8,$00,$f8,$00,$00,$00 ; $3d =
db $08,$04,$02,$01,$02,$04,$08,$00 ; $3e >
db $70,$88,$08,$10,$20,$00,$20,$00 ; $3f ?
db $70,$88,$98,$a8,$98,$80,$70,$00 ; $40 @
db $20,$50,$88,$88,$f8,$88,$88,$00 ; $41 A
db $f0,$88,$88,$f0,$88,$88,$f0,$00 ; $42 B
db $70,$88,$80,$80,$80,$88,$70,$00 ; $43 C
db $f0,$88,$88,$88,$88,$88,$f0,$00 ; $44 D
db $f8,$80,$80,$f0,$80,$80,$f8,$00 ; $45 E
db $f8,$80,$80,$f0,$80,$80,$80,$00 ; $46 F
db $70,$88,$80,$b8,$88,$88,$70,$00 ; $47 G
db $88,$88,$88,$f8,$88,$88,$88,$00 ; $48 H
db $70,$20,$20,$20,$20,$20,$70,$00 ; $49 I
db $08,$08,$08,$08,$88,$88,$70,$00 ; $4A J
db $88,$90,$a0,$c0,$a0,$90,$88,$00 ; $4B K
db $80,$80,$80,$80,$80,$80,$f8,$00 ; $4C L
db $88,$d8,$a8,$a8,$88,$88,$88,$00 ; $4D M
db $88,$c8,$c8,$a8,$98,$98,$88,$00 ; $4E N
db $70,$88,$88,$88,$88,$88,$70,$00 ; $4F O
db $f0,$88,$88,$f0,$80,$80,$80,$00 ; $50 P
db $70,$88,$88,$88,$88,$a8,$90,$68 ; $51 Q
db $f0,$88,$88,$f0,$a0,$90,$88,$00 ; $52 R
db $70,$88,$80,$70,$08,$88,$70,$00 ; $53 S
db $f8,$20,$20,$20,$20,$20,$20,$00 ; $54 T
db $88,$88,$88,$88,$88,$88,$70,$00 ; $55 U
db $88,$88,$88,$88,$50,$50,$20,$00 ; $56 V
db $88,$88,$88,$a8,$a8,$d8,$88,$00 ; $57 W
db $88,$88,$50,$20,$50,$88,$88,$00 ; $58 X
db $88,$88,$88,$70,$20,$20,$20,$00 ; $59 Y
db $f8,$08,$10,$20,$40,$80,$f8,$00 ; $5A Z
db $78,$60,$60,$60,$60,$60,$78,$00 ; $5B [
db $00,$80,$40,$20,$10,$08,$00,$00 ; $5C \
db $F0,$30,$30,$30,$30,$30,$F0,$00 ; $5D ]
db $20,$50,$88,$00,$00,$00,$00,$00 ; $5E
db $00,$00,$00,$00,$00,$00,$f8,$00 ; $5F _
db $40,$20,$10,$00,$00,$00,$00,$00 ; $60
db $00,$00,$68,$98,$88,$98,$68,$00 ; $61 a
db $80,$80,$f0,$88,$88,$88,$f0,$00 ; $62 b
db $00,$00,$78,$80,$80,$80,$78,$00 ; $63 c
db $08,$08,$68,$98,$88,$98,$68,$00 ; $64 d
db $00,$00,$70,$88,$f8,$80,$70,$00 ; $65 e
db $30,$48,$40,$e0,$40,$40,$40,$00 ; $66 f
db $00,$00,$78,$88,$88,$78,$08,$70 ; $67 g
db $80,$80,$f0,$88,$88,$88,$88,$00 ; $68 h
db $20,$00,$60,$20,$20,$20,$70,$00 ; $69 i
db $08,$00,$18,$08,$88,$88,$70,$00 ; $6a j
db $80,$80,$88,$90,$e0,$90,$88,$00 ; $6b k
db $60,$20,$20,$20,$20,$20,$70,$00 ; $6c l
db $00,$00,$d0,$a8,$a8,$a8,$a8,$00 ; $6d m
db $00,$00,$b0,$c8,$88,$88,$88,$00 ; $6e n
db $00,$00,$70,$88,$88,$88,$70,$00 ; $6f o
db $00,$00,$f0,$88,$88,$88,$f0,$80 ; $70 p
db $00,$00,$78,$88,$88,$88,$78,$08 ; $71 q
db $00,$00,$b8,$c0,$80,$80,$80,$00 ; $72 r
db $00,$00,$78,$80,$70,$08,$f0,$00 ; $73 s
db $20,$20,$f8,$20,$20,$20,$20,$00 ; $74 t
db $00,$00,$88,$88,$88,$98,$68,$00 ; $75 u
db $00,$00,$88,$88,$88,$50,$20,$00 ; $76 v
db $00,$00,$88,$a8,$a8,$a8,$50,$00 ; $77 w
db $00,$00,$88,$50,$20,$50,$88,$00 ; $78 x
db $00,$00,$88,$88,$98,$68,$08,$70 ; $79 y
db $00,$00,$f8,$10,$20,$40,$f8,$00 ; $7a z
db $18,$20,$20,$40,$20,$20,$18,$00 ; $7b {
db $20,$20,$20,$20,$20,$20,$20,$00 ; $7c |
db $c0,$20,$20,$10,$20,$20,$c0,$00 ; $7d }
db $00,$00,$40,$a8,$10,$00,$00,$00 ; $7e
db $70,$70,$20,$f8,$20,$70,$50,$00 ; $7f
endif
vdp_generic_mode:
call nmi_off
call WRTVDP
ld bc,$a201
call WRTVDP
ld bc,$0602 ; $1800 for pattern table.
call WRTVDP
ld b,d
ld c,$03 ; for color table.
call WRTVDP
ld b,e
ld c,$04 ; for bitmap table.
call WRTVDP
ld bc,$3605 ; $1b00 for sprite attribute table.
call WRTVDP
ld bc,$0706 ; $3800 for sprites bitmaps.
call WRTVDP
ld bc,$0107
jp WRTVDP
mode_0:
ld hl,mode
res 2,(hl)
ld bc,$0200
ld de,$ff03 ; $2000 for color table, $0000 for bitmaps.
call vdp_generic_mode
if COLECO
ld hl,($006c)
ld de,-128
add hl,de
endif
if SG1000
ld hl,font_bitmaps
endif
if MSX
ld hl,($0004)
inc h
endif
ld de,$0100
ld bc,$0300
call LDIRVM3
call nmi_on
call nmi_off
ld hl,$2000
ld bc,$1800
ld a,$f0
call FILVRM
call nmi_on
call cls
vdp_generic_sprites:
call nmi_off
ld hl,$1b00
ld bc,$0080
ld a,$d1
call FILVRM
ld hl,sprites
ld de,sprites+1
ld bc,127
ld (hl),$d1
ldir
call nmi_on
call nmi_off
ld bc,$e201 ; Enable screen and interrupts.
call WRTVDP
jp nmi_on
mode_1:
ld hl,mode
res 2,(hl)
ld bc,$0200
ld de,$ff03 ; $2000 for color table, $0000 for bitmaps.
call vdp_generic_mode
ld hl,$0000
ld bc,$1800
xor a
call FILVRM
call nmi_on
call nmi_off
ld hl,$2000
ld bc,$1800
ld a,$f0
call FILVRM
call nmi_on
ld hl,$1800
.1: call nmi_off
ld b,32
.2: ld a,l
call WRTVRM
inc hl
djnz .2
call nmi_on
ld a,h
cp $1b
jp nz,.1
jp vdp_generic_sprites
mode_2:
ld hl,mode
set 2,(hl)
ld bc,$0000
ld de,$8000 ; $2000 for color table, $0000 for bitmaps.
call vdp_generic_mode
if COLECO
ld hl,($006c)
ld de,-128
add hl,de
endif
if SG1000
ld hl,font_bitmaps
endif
if MSX
ld hl,($0004)
inc h
endif
ld de,$0100
ld bc,$0300
call LDIRVM
call nmi_on
call nmi_off
ld hl,$2000
ld bc,$0020
ld a,$f0
call FILVRM
call nmi_on
call cls
jp vdp_generic_sprites
if MSX
ENASLT: EQU $0024 ; Select slot (H=Addr, A=Slot)
RSLREG: EQU $0138 ; Read slot status in A
;
; Get slot mapping
; B = 16K bank (0 for $0000, 1 for $4000, 2 for $8000, 3 for $c000)
; A = Current slot selection status (CALL RSLREG)
;
get_slot_mapping:
call rotate_slot
ld c,a
add a,$C1 ; EXPTBL
ld l,a
ld h,$FC
ld a,(hl)
and $80 ; Get expanded flag
or c
ld c,a
inc hl
inc hl
inc hl
inc hl
ld a,(hl) ; SLTTBL
call rotate_slot
rlca
rlca
or c ; A contains bit 7 = Marks expanded
; bit 6 - 4 = Doesn't care
; bit 3 - 2 = Secondary mapper
; bit 1 - 0 = Primary mapper
ret
rotate_slot:
push bc
dec b
inc b
jr z,.1
.0: rrca
rrca
djnz .0
.1: and 3