-
Notifications
You must be signed in to change notification settings - Fork 1
/
WSVideo.s
2648 lines (2466 loc) · 80.5 KB
/
WSVideo.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
//
// WSVideo.s
// Bandai WonderSwan Video emulation for GBA/NDS.
//
// Created by Fredrik Ahlström on 2006-07-23.
// Copyright © 2006-2024 Fredrik Ahlström. All rights reserved.
//
#ifdef __arm__
#ifdef GBA
#include "../Shared/gba_asm.h"
#elif NDS
#include "../Shared/nds_asm.h"
#endif
#include "Sphinx.i"
#include "../ARMV30MZ/ARMV30MZ.i"
.global wsVideoInit
.global wsVideoReset
.global wsvSetCartMap
.global wsvSetIOPortOut
.global wsvDoScanline
.global wsvRead
.global wsvRead16
.global wsvWrite
.global wsvWrite16
.global sphinxSaveState
.global sphinxLoadState
.global sphinxGetStateSize
.global copyScrollValues
.global wsvConvertTileMaps
.global wsvConvertSprites
.global wsvRefW
.global wsvGetInterruptVector
.global wsvSetInterruptExternal
.global wsvPushVolumeButton
.global wsvSetHeadphones
.global wsvSetLowBattery
.global wsvSetSerialByteIn
.syntax unified
.arm
#ifdef GBA
.section .ewram, "ax", %progbits ;@ For the GBA
#else
.section .text ;@ For anything else
#endif
.align 2
;@----------------------------------------------------------------------------
wsVideoInit: ;@ Only need to be called once
;@----------------------------------------------------------------------------
ldr r0,=CHR_DECODE ;@ Destination 0x400
mov r1,#0xffffff00 ;@ Build chr decode tbl
chrLutLoop:
movs r2,r1,lsl#31
movne r2,#0x10000000
orrcs r2,r2,#0x01000000
tst r1,r1,lsl#29
orrmi r2,r2,#0x00100000
orrcs r2,r2,#0x00010000
tst r1,r1,lsl#27
orrmi r2,r2,#0x00001000
orrcs r2,r2,#0x00000100
tst r1,r1,lsl#25
orrmi r2,r2,#0x00000010
orrcs r2,r2,#0x00000001
str r2,[r0],#4
adds r1,r1,#1
bne chrLutLoop
bx lr
;@----------------------------------------------------------------------------
wsVideoReset: ;@ r0=ram+LUTs, r1=machine, r2=IrqFunc
;@----------------------------------------------------------------------------
stmfd sp!,{r0-r3,lr}
mov r0,spxptr
ldr r1,=sphinxSize/4
bl memclr_ ;@ Clear Sphinx state
ldr r2,=lineStateTable
ldr r1,[r2],#4
mov r0,#-1
stmia spxptr,{r0-r2} ;@ Reset scanline, nextChange & lineState
str r0,[spxptr,#serialRXCounter]
str r0,[spxptr,#serialTXCounter]
ldmfd sp!,{r0-r3}
str r0,[spxptr,#gfxRAM]
add r0,r0,#0xFE00
str r0,[spxptr,#paletteRAM]
ldr r0,=DISP_BUFF
str r0,[spxptr,#dispBuff]
ldr r0,=WINDOW_BUFF
str r0,[spxptr,#windowBuff]
ldr r0,=SCROLL_BUFF
str r0,[spxptr,#scrollBuff]
strb r1,[spxptr,#wsvMachine]
cmp r1,#HW_WONDERSWAN
cmpne r1,#HW_POCKETCHALLENGEV2
moveq r0,#SOC_ASWAN
movne r0,#SOC_SPHINX
cmp r1,#HW_SWANCRYSTAL
moveq r0,#SOC_SPHINX2
strb r0,[spxptr,#wsvSOC]
cmp r2,#0
adreq r2,dummyIrqFunc
str r2,[spxptr,#irqFunction]
adr r3,dummyIrqFunc
str r3,[spxptr,#rxFunction]
str r3,[spxptr,#txFunction]
;@ r0=SOC
bl wsvInitIOMap
ldmfd sp!,{lr}
b wsvRegistersReset
dummyIrqFunc:
bx lr
;@----------------------------------------------------------------------------
wsvSetPowerOff:
;@----------------------------------------------------------------------------
stmfd sp!,{lr}
mov r0,#0
ldr r1,=powerIsOn
strb r0,[r1]
bl wsvRegistersReset
ldrb r0,[spxptr,#wsvSystemCtrl3]
orr r0,r0,#1
strb r0,[spxptr,#wsvSystemCtrl3]
bl setMuteSoundChip
bl wsvUpdateIcons
ldmfd sp!,{pc}
;@----------------------------------------------------------------------------
wsvInitIOMap: ;@ r0=SOC
;@----------------------------------------------------------------------------
stmfd sp!,{r4,r5,lr}
ldr r1,=defaultInTable
ldr r2,=defaultOutTable
ldr r3,=ioInTable
ldr r4,=ioOutTable
mov r5,#0xC0
ioTblLoop:
subs r5,r5,#1
ldr lr,[r1,r5,lsl#2]
str lr,[r3,r5,lsl#2]
ldr lr,[r2,r5,lsl#2]
str lr,[r4,r5,lsl#2]
bhi ioTblLoop
cmp r0,#SOC_SPHINX2
ldmfdeq sp!,{r4,r5,pc}
ldr r1,=wsvUnmappedR
ldr r2,=wsvUnmappedW
cmp r0,#SOC_ASWAN
moveq r5,#0x40
movne r5,#0x70 ;@ SPHINX
ioASLoop:
str r1,[r3,r5,lsl#2]
str r2,[r4,r5,lsl#2]
add r5,r5,#1
cmp r5,#0x78
bne ioASLoop
ldmfd sp!,{r4,r5,pc}
;@----------------------------------------------------------------------------
wsvSetIOMode: ;@ r0=color mode, 0=mono !0=color.
;@ Should only be called on SPHINX/SPHINX2
;@----------------------------------------------------------------------------
stmfd sp!,{r4,r5,lr}
ldr r3,=ioInTable
ldr r4,=ioOutTable
mov r5,#0x40
cmp r0,#0
beq modeMono
ldr r1,=defaultInTable
ldr r2,=defaultOutTable
ioMode1Loop:
ldr lr,[r1,r5,lsl#2]
str lr,[r3,r5,lsl#2]
ldr lr,[r2,r5,lsl#2]
str lr,[r4,r5,lsl#2]
add r5,r5,#1
cmp r5,#0x6C
bne ioMode1Loop
ldmfd sp!,{r4,r5,pc}
modeMono:
ldr r1,=wsvUnmappedR
ldr r2,=wsvUnmappedW
ioMode0Loop:
cmp r5,#0x60 ;@ Skip 0x60 since it's used to switch back to color mode.
strne r1,[r3,r5,lsl#2]
strne r2,[r4,r5,lsl#2]
add r5,r5,#1
cmp r5,#0x6C
bne ioMode0Loop
ldmfd sp!,{r4,r5,pc}
;@----------------------------------------------------------------------------
wsvSetCartMap: ;@ r0=inTable, r1=outTable
;@----------------------------------------------------------------------------
stmfd sp!,{r4,lr}
ldr r2,=cartInTable
ldr r3,=cartOutTable
mov r4,#0x40
cartTblLoop:
ldr lr,[r0],#4
str lr,[r2],#4
ldr lr,[r1],#4
str lr,[r3],#4
subs r4,r4,#1
bhi cartTblLoop
ldmfd sp!,{r4,lr}
bx lr
;@----------------------------------------------------------------------------
wsvSetIOPortOut: ;@ r0=port, r1=function
;@----------------------------------------------------------------------------
ldr r2,=ioOutTable
str r1,[r2,r0,lsl#2]
bx lr
;@----------------------------------------------------------------------------
_debugIOUnmappedR:
;@----------------------------------------------------------------------------
ldr r3,=debugIOUnmappedR
bx r3
;@----------------------------------------------------------------------------
_debugIOUnimplR:
;@----------------------------------------------------------------------------
ldr r3,=debugIOUnimplR
bx r3
;@----------------------------------------------------------------------------
_debugIOUnmappedW:
;@----------------------------------------------------------------------------
ldr r3,=debugIOUnmappedW
bx r3
;@----------------------------------------------------------------------------
handleSerialOutW:
;@----------------------------------------------------------------------------
ldr r3,[spxptr,#txFunction]
bx r3
;@----------------------------------------------------------------------------
callSerialInEmpty:
;@----------------------------------------------------------------------------
stmfd sp!,{spxptr,lr}
ldr r3,[spxptr,#rxFunction]
mov lr,pc
bx r3
ldmfd sp!,{spxptr,pc}
;@----------------------------------------------------------------------------
memCopy:
;@----------------------------------------------------------------------------
ldr r3,=memcpy
;@----------------------------------------------------------------------------
thumbCallR3:
;@----------------------------------------------------------------------------
bx r3
;@----------------------------------------------------------------------------
wsvRegistersReset: ;@ in r3=SOC
;@----------------------------------------------------------------------------
adr r1,IO_Default
// cmp r3,#SOC_SPHINX
// adreq r1,WSC_IO_Default
// adrhi r1,SC_IO_Default
mov r2,#0x100
add r0,spxptr,#wsvRegs
stmfd sp!,{spxptr,lr}
bl memCopy
ldmfd sp!,{spxptr,lr}
ldrb r1,[spxptr,#wsvSOC]
cmp r1,#SOC_ASWAN
mov r0,#0x84
movne r0,#0x86
strb r0,[spxptr,#wsvSystemCtrl1]
mov r0,#LCD_ICON_TIME_VALUE
strb r0,[spxptr,#wsvCartIconTimer]
mov r0,#0x02
movne r0,#0x03
strb r0,[spxptr,#wsvHWVolume]
cmpne r1,#SOC_SPHINX2
mov r0,#0x90
movne r0,#0x9F
strb r0,[spxptr,#wsvColor01]
cmp r1,#SOC_SPHINX2
mov r0,#0
moveq r0,#0x80
strb r0,[spxptr,#wsvSystemCtrl3]
ldrb r0,[spxptr,#wsvTotalLines]
b wsvRefW
;@----------------------------------------------------------------------------
IO_Default:
.byte 0x00, 0x00, 0x9d, 0xbb, 0x00, 0x00, 0x00, 0x26, 0xfe, 0xde, 0xf9, 0xfb, 0xdb, 0xd7, 0x7f, 0xf5
.byte 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x9e, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x99, 0xfd, 0xb7, 0xdf
.byte 0x30, 0x57, 0x75, 0x76, 0x15, 0x73, 0x77, 0x77, 0x20, 0x75, 0x50, 0x36, 0x70, 0x67, 0x50, 0x77
.byte 0x57, 0x54, 0x75, 0x77, 0x75, 0x17, 0x37, 0x73, 0x50, 0x57, 0x60, 0x77, 0x70, 0x77, 0x10, 0x73
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00
.byte 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0xdb, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x42, 0x00, 0x83, 0x00
// Cartridge
.byte 0x2f, 0x3f, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1
.byte 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1
.byte 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1
.byte 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1
;@----------------------------------------------------------------------------
sphinxSaveState: ;@ In r0=destination, r1=spxptr. Out r0=state size.
.type sphinxSaveState STT_FUNC
;@----------------------------------------------------------------------------
stmfd sp!,{lr}
add r1,r1,#sphinxState
mov r2,#sphinxStateSize
bl memCopy
ldmfd sp!,{lr}
mov r0,#sphinxStateSize
bx lr
;@----------------------------------------------------------------------------
sphinxLoadState: ;@ In r0=spxptr, r1=source. Out r0=state size.
.type sphinxLoadState STT_FUNC
;@----------------------------------------------------------------------------
stmfd sp!,{r4,r5,lr}
mov r5,r0 ;@ Store spxptr (r0)
mov r4,r1 ;@ Store source
add r0,r5,#sphinxState
mov r2,#sphinxStateSize
bl memCopy
mov spxptr,r5
ldr r0,[spxptr,#nextLineChange]
ldr r2,=lineStateTable
fixStateTableLoop:
ldr r1,[r2],#8
cmp r1,r0
bne fixStateTableLoop
ldr r1,[r2,#-4]!
ldr r1,[spxptr,#lineState]
bl clearDirtyTiles
mov spxptr,r5
bl drawFrameGfx
bl reBankSwitchAll
ldrb r1,[spxptr,#wsvSystemCtrl1]
tst r1,#1 ;@ Boot rom locked?
movne r0,#0 ;@ Remove boot rom overlay
blne setBootRomOverlay
ldmfd sp!,{r4,r5,lr}
;@----------------------------------------------------------------------------
sphinxGetStateSize: ;@ Out r0=state size.
.type sphinxGetStateSize STT_FUNC
;@----------------------------------------------------------------------------
mov r0,#sphinxStateSize
bx lr
.pool
;@----------------------------------------------------------------------------
wsvRead16: ;@ I/O read word (0x00-0xFF)
;@----------------------------------------------------------------------------
tst r0,r0,lsr#1 ;@ Odd address?
cmpcc r0,#0xC0 ;@ Cart?
subcs v30cyc,v30cyc,#1*CYCLE ;@ Eat an extra cpu cycle
stmfd sp!,{r4,r5,lr}
mov r4,r0
bl wsvRead
mov r5,r0
add r0,r4,#1
bl wsvRead
orr r0,r5,r0,lsl#8
ldmfd sp!,{r4,r5,pc}
;@----------------------------------------------------------------------------
wsvReadHigh: ;@ I/O read (0x0100-0xFFFF)
;@----------------------------------------------------------------------------
mov r1,r0,lsl#23
cmp r1,#0xB8<<23
bcs wsvUnmappedR
stmfd sp!,{r0,spxptr,lr}
bl _debugIOUnmappedR
ldmfd sp!,{r0,spxptr,lr}
and r0,r0,#0xFF
;@----------------------------------------------------------------------------
wsvRead: ;@ I/O read (0x00-0xBF)
;@----------------------------------------------------------------------------
cmp r0,#0x100
ldrmi pc,[pc,r0,lsl#2]
b wsvReadHigh
ioInTable:
.space 0xC0*4
;@----------------------------------------------------------------------------
;@Cartridge ;@ I/O read cart (0xC0-0xFF)
;@----------------------------------------------------------------------------
cartInTable:
.space 0x40*4
;@----------------------------------------------------------------------------
wsvUnmappedR:
;@----------------------------------------------------------------------------
mov r11,r11 ;@ No$GBA breakpoint
stmfd sp!,{spxptr,lr}
bl _debugIOUnmappedR
ldmfd sp!,{spxptr,lr}
ldrb r0,[spxptr,#wsvVideoMode]
tst r0,#0x80 ;@ Color mode?
moveq r0,#0x90
movne r0,#0x00
bx lr
;@----------------------------------------------------------------------------
wsvZeroR:
;@----------------------------------------------------------------------------
stmfd sp!,{lr}
bl _debugIOUnmappedR
ldmfd sp!,{lr}
mov r0,#0x00
bx lr
;@----------------------------------------------------------------------------
wsvUnknownR:
;@----------------------------------------------------------------------------
ldr r2,=0x826EBAD0
;@----------------------------------------------------------------------------
wsvImportantR:
mov r11,r11 ;@ No$GBA breakpoint
add r2,spxptr,#wsvRegs
ldrb r1,[r2,r0]
stmfd sp!,{r1,spxptr,lr}
bl _debugIOUnimplR
ldmfd sp!,{r0,spxptr,pc}
;@----------------------------------------------------------------------------
wsvRegR:
add r2,spxptr,#wsvRegs
ldrb r0,[r2,r0]
bx lr
.pool
;@----------------------------------------------------------------------------
wsvVCountR: ;@ 0x03
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#scanline]
bx lr
;@----------------------------------------------------------------------------
wsvLCDVolumeR: ;@ 0x1A
;@----------------------------------------------------------------------------
ldr r1,[spxptr,#enabledLCDIcons]
and r0,r1,LCD_ICON_SLEEP ;@ #1
tst r1,#LCD_ICON_TIME
bxeq lr
tst r1,LCD_ICON_HEADPHONE
orrne r0,r0,#0x02
orreq r0,r0,#0x10
tst r1,#LCD_ICON_VOL1
orrne r0,r0,#0x08
tst r1,#LCD_ICON_VOL2
orrne r0,r0,#0x04
bx lr
;@----------------------------------------------------------------------------
wsvSndDMASrc0R: ;@ 0x4A, only WSC.
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#sndDmaSource]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMASrc1R: ;@ 0x4B, only WSC.
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#sndDmaSource+1]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMASrc2R: ;@ 0x4C, only WSC.
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#sndDmaSource+2]
and r0,r0,#0x0F
bx lr
;@----------------------------------------------------------------------------
wsvSndDMALen0R: ;@ 0x4E, only WSC.
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#sndDmaLength]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMALen1R: ;@ 0x4F, only WSC.
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#sndDmaLength+1]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMALen2R: ;@ 0x50, only WSC.
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#sndDmaLength+2]
bx lr
;@----------------------------------------------------------------------------
wsvHyperChanCtrlR: ;@ 0x6B, only WSC
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#wsvHyperVCtrl+1]
and r0,r0,#0x6F
bx lr
;@----------------------------------------------------------------------------
wsvGetInterruptVector: ;@ return vector in r0
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvInterruptBaseR: ;@ 0xB0
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvInterruptStatus]
#ifdef GBA
mov r1,r1,lsl#24
mov r0,#7
intVecLoop:
movs r1,r1,lsl#1
bcs intFound
subs r0,r0,#1
bne intVecLoop
intFound:
#else
clz r0,r1
rsbs r0,r0,#31
movmi r0,#0
#endif
ldrb r1,[spxptr,#wsvInterruptBase]
orr r0,r0,r1
bx lr
;@----------------------------------------------------------------------------
wsvComByteR: ;@ 0xB1
;@----------------------------------------------------------------------------
stmfd sp!,{lr}
mov r0,#SERRX_IRQ_F ;@ #3 = Serial receive
bl wsvClearInterruptPins
bl callSerialInEmpty
mov r0,#0
strb r0,[spxptr,#wsvSerialBufFull]
ldrb r0,[spxptr,#wsvByteReceived]
ldmfd sp!,{pc}
;@----------------------------------------------------------------------------
wsvSerialStatusR: ;@ 0xB3
;@----------------------------------------------------------------------------
ldrb r0,[spxptr,#wsvSerialStatus]
ldr r1,[spxptr,#serialTXCounter]
cmp r1,#0 ;@ Send complete?
orrmi r0,r0,#4
ldrb r1,[spxptr,#wsvSerialBufFull]
cmp r1,#0 ;@ Receive buffer full?
orrne r0,r0,#1
bx lr
;@----------------------------------------------------------------------------
wsvWriteHigh: ;@ I/O write (0x0100-0xFFFF)
;@----------------------------------------------------------------------------
mov r2,r1,lsl#23
cmp r2,#0xB8<<23
bcs wsvUnmappedW
stmfd sp!,{r0,r1,spxptr,lr}
bl _debugIOUnmappedW
ldmfd sp!,{r0,r1,spxptr,lr}
and r1,r1,#0xFF
b wsvWrite
;@----------------------------------------------------------------------------
wsvWrite16: ;@ I/O write word (0x00-0xFF)
;@----------------------------------------------------------------------------
tst r1,r1,lsr#1 ;@ Odd address?
cmpcc r1,#0xC0 ;@ Cart?
subcs v30cyc,v30cyc,#1*CYCLE ;@ Eat an extra cpu cycle
stmfd sp!,{r0,r1,lr}
and r0,r0,#0xFF
bl wsvWrite
ldmfd sp!,{r0,r1,lr}
mov r0,r0,lsr#8
add r1,r1,#1
;@----------------------------------------------------------------------------
wsvWrite: ;@ I/O write (0x00-0xBF)
;@----------------------------------------------------------------------------
cmp r1,#0x100
ldrmi pc,[pc,r1,lsl#2]
b wsvWriteHigh
ioOutTable:
.space 0xC0*4
;@----------------------------------------------------------------------------
;@Cartridge ;@ I/O write cart (0xC0-0xFF)
;@----------------------------------------------------------------------------
cartOutTable:
.space 0x40*4
;@----------------------------------------------------------------------------
wsvUnknownW:
;@----------------------------------------------------------------------------
wsvImportantW:
;@----------------------------------------------------------------------------
mov r11,r11 ;@ No$GBA breakpoint
add r2,spxptr,#wsvRegs
strb r0,[r2,r1]
stmfd sp!,{spxptr,lr}
bl debugIOUnimplW
ldmfd sp!,{spxptr,pc}
;@----------------------------------------------------------------------------
wsvReadOnlyW:
;@----------------------------------------------------------------------------
wsvUnmappedW:
;@----------------------------------------------------------------------------
b _debugIOUnmappedW
;@----------------------------------------------------------------------------
wsvRegW:
add r2,spxptr,#wsvRegs
strb r0,[r2,r1]
;@----------------------------------------------------------------------------
wsvZeroW:
;@----------------------------------------------------------------------------
bx lr
;@----------------------------------------------------------------------------
wsvDisplayCtrlW: ;@ 0x00, Display Control
;@----------------------------------------------------------------------------
ldrb r2,[spxptr,#wsvDispCtrl]
and r0,r0,#0x3F
strb r0,[spxptr,#wsvDispCtrl]
dispCnt:
ldr r1,[spxptr,#scanline] ;@ r1=scanline
add r1,r1,#1
cmp r1,#145
movhi r1,#145
ldr r0,[spxptr,#dispLine]
subs r0,r1,r0
strhi r1,[spxptr,#dispLine]
ldr r3,[spxptr,#dispBuff]
add r1,r3,r1
sy1:
strbhi r2,[r1,#-1]! ;@ Fill backwards from scanline to lastline
subs r0,r0,#1
bhi sy1
bx lr
;@----------------------------------------------------------------------------
wsvSpriteTblAdrW: ;@ 0x04, Sprite Table Address
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvVideoMode]
tst r1,#0x80 ;@ Color mode?
andne r0,r0,#0x3F
andeq r0,r0,#0x1F
strb r0,[spxptr,#wsvSprTblAdr]
bx lr
;@----------------------------------------------------------------------------
wsvSpriteFirstW: ;@ 0x05, First Sprite
;@----------------------------------------------------------------------------
and r0,r0,#0x7F
strb r0,[spxptr,#wsvSpriteFirst]
bx lr
;@----------------------------------------------------------------------------
wsvMapAdrW: ;@ 0x07 Map table address
;@----------------------------------------------------------------------------
#ifdef __ARM_ARCH_5TE__
ldrd r2,r3,[spxptr,#wsvBgScrollBak]
#else
ldr r2,[spxptr,#wsvBgScrollBak]
ldr r3,[spxptr,#wsvFgScrollBak]
#endif
ldrb r1,[spxptr,#wsvVideoMode]
tst r1,#0x80 ;@ Color mode?
andeq r0,r0,#0x77
strb r0,[spxptr,#wsvMapTblAdr]
strb r0,[spxptr,#wsvBgScrollBak+1]
b scrollCnt
;@----------------------------------------------------------------------------
wsvFgWinX0W: ;@ 0x08, Foreground Window X start register
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvFgWinY0W: ;@ 0x09, Foreground Window Y start register
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvFgWinX1W: ;@ 0x0A, Foreground Window X end register
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvFgWinY1W: ;@ 0x0B, Foreground Window Y end register
;@----------------------------------------------------------------------------
ldr r2,[spxptr,#wsvFgWinXPos]
add r1,r1,#wsvRegs
strb r0,[spxptr,r1]
windowCnt:
ldr r1,[spxptr,#scanline] ;@ r1=scanline
add r1,r1,#1
cmp r1,#145
movhi r1,#145
ldr r0,[spxptr,#windowLine]
subs r0,r1,r0
strhi r1,[spxptr,#windowLine]
ldr r3,[spxptr,#windowBuff]
add r1,r3,r1,lsl#2
sy3:
stmdbhi r1!,{r2} ;@ Fill backwards from scanline to lastline
subs r0,r0,#1
bhi sy3
bx lr
;@----------------------------------------------------------------------------
wsvBgScrXW: ;@ 0x10, Background Horizontal Scroll register
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvBgScrYW: ;@ 0x11, Background Vertical Scroll register
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvFgScrXW: ;@ 0x12, Foreground Horizontal Scroll register
;@----------------------------------------------------------------------------
;@----------------------------------------------------------------------------
wsvFgScrYW: ;@ 0x13, Foreground Vertical Scroll register
;@----------------------------------------------------------------------------
#ifdef __ARM_ARCH_5TE__
ldrd r2,r3,[spxptr,#wsvBgScrollBak]
#else
ldr r2,[spxptr,#wsvBgScrollBak]
ldr r3,[spxptr,#wsvFgScrollBak]
#endif
add r1,r1,#wsvRegs
strb r0,[spxptr,r1]
add r1,r1,#(wsvBgScrollBak/2) - wsvBgXScroll
strb r0,[spxptr,r1,lsl#1]
scrollCnt:
stmfd sp!,{lr}
ldr r1,[spxptr,#scanline] ;@ r1=scanline
add r1,r1,#1
cmp r1,#145
movhi r1,#145
ldr r0,[spxptr,#scrollLine]
subs r0,r1,r0
strhi r1,[spxptr,#scrollLine]
ldr lr,[spxptr,#scrollBuff]
add r1,lr,r1,lsl#3
sy4:
stmdbhi r1!,{r2,r3} ;@ Fill backwards from scanline to lastline
subs r0,r0,#1
bhi sy4
ldmfd sp!,{pc}
;@----------------------------------------------------------------------------
wsvLCDIconW: ;@ 0x15, Enable/disable LCD icons
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvLCDIcons]
ands r0,r0,#6
bxeq lr
cmp r0,#2
movne r0,#0
strb r0,[spxptr,#wsvOrientation]
bx lr
;@----------------------------------------------------------------------------
wsvRefW: ;@ 0x16, Last scan line.
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvTotalLines]
cmp r0,#0x9E
movmi r0,#0x9E
cmp r0,#0xC8
movpl r0,#0xC8
add r0,r0,#1
str r0,lineStateLastLine
b setScreenRefresh
;@----------------------------------------------------------------------------
wsvLCDVolumeW: ;@ 0x1A
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvLCDControl]
and r0,r0,#1
orr r1,r1,#1
eor r1,r1,r0
strb r1,[spxptr,#wsvLCDControl]
bx lr
;@----------------------------------------------------------------------------
wsvDMASourceW: ;@ 0x40, only WSC.
;@----------------------------------------------------------------------------
bic r0,r0,#0x01
strb r0,[spxptr,#wsvDMASource]
bx lr
;@----------------------------------------------------------------------------
wsvDMASourceHW: ;@ 0x42, only WSC.
;@----------------------------------------------------------------------------
and r0,r0,#0x0F
strb r0,[spxptr,#wsvDMASource+2]
bx lr
;@----------------------------------------------------------------------------
wsvDMADestW: ;@ 0x44, only WSC.
;@----------------------------------------------------------------------------
bic r0,r0,#0x01
strb r0,[spxptr,#wsvDMADest]
bx lr
;@----------------------------------------------------------------------------
wsvDMALengthW: ;@ 0x46, only WSC.
;@----------------------------------------------------------------------------
bic r0,r0,#0x01
strb r0,[spxptr,#wsvDMALength]
bx lr
;@----------------------------------------------------------------------------
wsvDMACtrlW: ;@ 0x48, only WSC, word transfer. steals 5+2*word cycles.
;@----------------------------------------------------------------------------
and r0,r0,#0xC0
strb r0,[spxptr,#wsvDMACtrl]
tst r0,#0x80 ;@ Start?
bxeq lr
stmfd sp!,{r4-r8,lr}
#ifdef __ARM_ARCH_5TE__
ldrd r4,r5,[spxptr,#wsvDMASource]
#else
ldr r4,[spxptr,#wsvDMASource]
ldr r5,[spxptr,#wsvDMADest] ;@ r5=destination
#endif
movs r6,r5,lsr#16 ;@ r6=length
beq dmaEnd
mov r4,r4,lsl#12
mov r5,r5,lsl#16
sub v30cyc,v30cyc,#5*CYCLE
sub v30cyc,v30cyc,r6,lsl#CYC_SHIFT
and r7,r0,#0x40 ;@ Inc/dec
rsb r7,r7,#0x20
mov r8,spxptr
dmaLoop:
mov r0,r4
bl dmaReadMem20W
mov r1,r0
mov r0,r5,lsr#4
bl dmaWriteMem20W
add r4,r4,r7,lsl#8
add r5,r5,r7,lsl#12
subs r6,r6,#2
bne dmaLoop
mov spxptr,r8
mov r4,r4,lsr#12
mov r5,r5,lsr#16
#ifdef __ARM_ARCH_5TE__
strd r4,r5,[spxptr,#wsvDMASource]
#else
str r4,[spxptr,#wsvDMASource]
str r5,[spxptr,#wsvDMADest] ;@ Store dest plus clear length
#endif
rsb r7,r7,#0x20
strb r7,[spxptr,#wsvDMACtrl]
dmaEnd:
ldmfd sp!,{r4-r8,lr}
bx lr
;@----------------------------------------------------------------------------
wsvSndDMASrc0W: ;@ 0x4A, only WSC.
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvSndDMASrcL]
strb r0,[spxptr,#sndDmaSource]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMASrc1W: ;@ 0x4B, only WSC.
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvSndDMASrcL+1]
strb r0,[spxptr,#sndDmaSource+1]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMASrc2W: ;@ 0x4C, only WSC.
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvSndDMASrcH]
strb r0,[spxptr,#sndDmaSource+2]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMALen0W: ;@ 0x4E, only WSC.
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvSndDMALenL]
strb r0,[spxptr,#sndDmaLength]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMALen1W: ;@ 0x4F, only WSC.
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvSndDMALenL+1]
strb r0,[spxptr,#sndDmaLength+1]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMALen2W: ;@ 0x50, only WSC.
;@----------------------------------------------------------------------------
and r0,r0,#0x0F
strb r0,[spxptr,#wsvSndDMALenH]
strb r0,[spxptr,#sndDmaLength+2]
bx lr
;@----------------------------------------------------------------------------
wsvSndDMACtrlW: ;@ 0x52, only WSC. steals 7n cycles.
;@----------------------------------------------------------------------------
and r0,r0,#0xDF
strb r0,[spxptr,#wsvSndDMACtrl]
bx lr
;@----------------------------------------------------------------------------
wsvVideoModeW: ;@ 0x60, Video mode, WSColor
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvVideoMode]
strb r0,[spxptr,#wsvVideoMode]
eor r1,r1,r0
tst r1,#0x80 ;@ Color mode changed?
bxeq lr
and r0,r0,#0x80
stmfd sp!,{lr}
bl wsvSetIOMode
ldmfd sp!,{lr}
b intEepromSetSize
;@----------------------------------------------------------------------------
wsvSysCtrl3W: ;@ 0x62, only WSC
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvSystemCtrl3]
ands r0,r0,#1 ;@ Power Off bit.
orr r0,r0,r1 ;@ OR SwanCrystal flag (bit 7).
strb r0,[spxptr,#wsvSystemCtrl3]
bxeq lr
b wsvSetPowerOff
;@----------------------------------------------------------------------------
wsvHyperCtrlW: ;@ 0x6A, only WSC
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvHyperVCtrl]
bx lr
;@----------------------------------------------------------------------------
wsvHyperChanCtrlW: ;@ 0x6B, only WSC
;@----------------------------------------------------------------------------
strb r0,[spxptr,#wsvHyperVCtrl+1]
tst r0,#0x10 ;@ Reset Left/Right?
bx lr
;@----------------------------------------------------------------------------
wsvFreqLW: ;@ 0x80,0x82,0x84,0x86 Sound frequency low
;@----------------------------------------------------------------------------
add r2,spxptr,#wsvRegs
strb r0,[r2,r1]
and r1,r1,#6
add r2,spxptr,#pcm1CurrentAddr
strb r0,[r2,r1,lsl#1]
bx lr
;@----------------------------------------------------------------------------
wsvFreqHW: ;@ 0x81,0x83,0x85,0x87 Sound frequency high
;@----------------------------------------------------------------------------
and r0,r0,#7 ;@ Only low 3 bits
add r2,spxptr,#wsvRegs
strb r0,[r2,r1]
orr r0,r0,#8
and r1,r1,#6
add r2,spxptr,r1,lsl#1
strb r0,[r2,#pcm1CurrentAddr+1]
bx lr
;@----------------------------------------------------------------------------
wsvCh1VolumeW: ;@ 0x88 Sound Channel 1 Volume
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvSound1Vol]
teq r1,r0
bxeq lr
strb r0,[spxptr,#wsvSound1Vol] ;@ Each nibble is L & R
b setCh1Volume
;@----------------------------------------------------------------------------
wsvCh2VolumeW: ;@ 0x89 Sound Channel 2 Volume
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvSound2Vol]
teq r1,r0
bxeq lr
strb r0,[spxptr,#wsvSound2Vol] ;@ Each nibble is L & R
b setCh2Volume
;@----------------------------------------------------------------------------
wsvCh3VolumeW: ;@ 0x8A Sound Channel 3 Volume
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvSound3Vol]
teq r1,r0
bxeq lr
strb r0,[spxptr,#wsvSound3Vol] ;@ Each nibble is L & R
b setCh3Volume
;@----------------------------------------------------------------------------
wsvCh4VolumeW: ;@ 0x8B Sound Channel 4 Volume
;@----------------------------------------------------------------------------
ldrb r1,[spxptr,#wsvSound4Vol]
teq r1,r0
bxeq lr
strb r0,[spxptr,#wsvSound4Vol] ;@ Each nibble is L & R
b setCh4Volume
;@----------------------------------------------------------------------------
wsvSweepTimeW: ;@ 0x8D Sound sweep time
;@----------------------------------------------------------------------------
and r0,r0,#0x1F ;@ Only low 5 bits
strb r0,[spxptr,#wsvSweepTime]
add r0,r0,#1
sub r0,r0,r0,lsl#26
str r0,[spxptr,#sweep3CurrentAddr]
bx lr
;@----------------------------------------------------------------------------
wsvNoiseCtrlW: ;@ 0x8E Noise Control
;@----------------------------------------------------------------------------
and r1,r0,#0x17 ;@ Only keep enable & tap bits
strb r1,[spxptr,#wsvNoiseCtrl]
ldr r1,[spxptr,#noise4CurrentAddr]
mov r1,r1,lsr#12 ;@ Clear taps
tst r0,#0x08 ;@ Reset?
andne r1,r1,#0x4 ;@ Keep Ch4 noise on/off
tst r0,#0x10 ;@ Enable calculation?
biceq r1,r1,#0x8
orrne r1,r1,#0x8
and r0,r0,#7 ;@ Which taps?
adr r2,noiseTaps