-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_s.S
812 lines (681 loc) · 20.2 KB
/
memory_s.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
/************************************************************************
* memory_s.S
* Memory emulation routines (assembler part)
*
************************************************************************
*
* Phoinix,
* Nintendo Gameboy(TM) emulator for the Palm OS(R) Computing Platform
*
* (c)2000-2004 Bodo Wenzel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
************************************************************************
* History:
*
* $Log: memory_s.S,v $
* Revision 1.4 2004/12/28 13:56:35 bodowenzel
* Split up all C-Code to multi-segmented
*
* Revision 1.3 2002/10/19 08:08:11 bodowenzel
* History cleanup, Javadoc-style header
*
* Revision 1.2 2001/12/30 18:47:11 bodowenzel
* CVS keyword Log was faulty
*
* Revision 1.1.1.1 2001/12/16 13:38:21 bodowenzel
* Import
*
************************************************************************
* Pre-CVS History (developed as PalmBoy):
*
* 2001-09-16 Bodo Wenzel Saving states now possible
* 2001-07-25 Bodo Wenzel Changed syntax to CPP + GAS
* 2001-02-24 Bodo Wenzel Support of more cartridges
* 2000-11-15 Bodo Wenzel Support of color devices
* 2000-10-19 Bodo Wenzel Interrupts and timer
* 2000-09-17 Bodo Wenzel Now nearly full screen emulation
* 2000-09-10 Bodo Wenzel Got from runmode.asm
************************************************************************
*/
/* === Includes ======================================================= */
#include "memory.h"
#include "video.h"
#include "gbemu.h"
/* === Placing the code =============================================== */
.section emulator,"x"
/* === Functions for memory bank control ============================== */
.globl MemoryMbcDummy
MemoryMbcDummy: /* Dummy ROM write */
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryMbc1RomSelect
MemoryMbc1RomSelect: /* 4/32 mode */
and.w #0x1f,%d0 /* 32 banks (512 KB) */
add.w %d0,%d0
add.w %d0,%d0
move.w %d0,[email protected](%a5)
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc1RomSelectL
MemoryMbc1RomSelectL: /* 16/8 mode */
and.w #0x1f,%d0 /* 128 banks (2 MB) */
add.w %d0,%d0
add.w %d0,%d0
move.w %d0,[email protected](%a5)
move.w [email protected](%a5),%d1
lsl.w #5,%d1
add.w %d1,%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc1RomSelectH
MemoryMbc1RomSelectH: /* 16/8 mode */
and.w #0x03,%d0 /* 128 banks (2 MB) */
add.w %d0,%d0
add.w %d0,%d0
move.w %d0,[email protected](%a5)
lsl.w #5,%d0
add.w [email protected](%a5),%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc1RamSelect
MemoryMbc1RamSelect: /* 4/32 mode */
and.w #0x03,%d0 /* 4 banks (32 KB) */
add.w %d0,%d0
add.w %d0,%d0
move.w %d0,[email protected](%a5)
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRamCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc1ModeSelect
MemoryMbc1ModeSelect:
move.b %d0,[email protected](%a5)
btst #0,%d0
jeq MM1MS168
move.w [email protected](%a5),%d0 /* 32 banks (512 KB) */
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
move.w [email protected](%a5),%d0 /* 4 banks (32 KB) */
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
lea MemoryMbc1RomSelect(%pc),%a3
move.l %a3,2+indexToAddress(gbemuJmpRomSelectL)
move.l %a3,2+indexToAddress(gbemuJmpRomSelectH)
lea MemoryMbc1RamSelect(%pc),%a3
move.l %a3,2+indexToAddress(gbemuJmpRamSelect)
jmp indexToAddress(gbemuCodeSpRomCorrect)
MM1MS168:
move.w [email protected](%a5),%d0
lsl.w #5,%d0 /* 128 banks (2 MB) */
add.w [email protected](%a5),%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
move.l [email protected](%a5),[email protected](%a5)
lea MemoryMbc1RomSelectL(%pc),%a3
move.l %a3,2+indexToAddress(gbemuJmpRomSelectL)
move.l %a3,2+indexToAddress(gbemuJmpRomSelectH)
lea MemoryMbc1RomSelectH(%pc),%a3
move.l %a3,2+indexToAddress(gbemuJmpRamSelect)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc2RomSelect
MemoryMbc2RomSelect:
and.w #0x0f,%d0 /* 16 banks (256 KB) */
add.w %d0,%d0
add.w %d0,%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc3RomSelect
MemoryMbc3RomSelect:
and.w #0x7f,%d0 /* 128 banks (2 MB) */
add.w %d0,%d0
add.w %d0,%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc3RamSelect
MemoryMbc3RamSelect:
move.b %d0,[email protected](%a5)
btst #3,%d0
jne MM3RtcSelect
and.w #0x03,%d0 /* 4 banks (32 KB) */
add.w %d0,%d0
add.w %d0,%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
move.l 6+indexToAddress(gbemuJmpRamRdExt),2+indexToAddress(gbemuJmpRamRdExt)
move.l 6+indexToAddress(gbemuJmpRamWrExt),2+indexToAddress(gbemuJmpRamWrExt)
jmp indexToAddress(gbemuCodeSpRamCorrect)
MM3RtcSelect:
lea [email protected](%a5),%a3
and.w #0x07,%d0
add.w %d0,%a3
move.l %a3,[email protected](%a5)
lea MemoryMbc3RtcRd(%pc),%a3
move.l %a3,2+indexToAddress(gbemuJmpRamRdExt)
lea MemoryMbc3RtcWr(%pc),%a3
move.l %a3,2+indexToAddress(gbemuJmpRamWrExt)
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryMbc3RtcRd
MemoryMbc3RtcRd:
move.l [email protected](%a5),%a3
move.l %a3,%a2
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryMbc3RtcWr
MemoryMbc3RtcWr:
move.l [email protected](%a5),%a3
lea [email protected](%a5),%a2
sub.l %a2,%a3
lea [email protected](%a5),%a2
move.b %d0,(%a2,%a3.w)
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryMbc3RtcLatch
MemoryMbc3RtcLatch:
btst #0,%d0
jeq MM3RLQuit
lea [email protected](%a5),%a2
lea [email protected](%a5),%a3
move.b (%a2)+,(%a3)+
move.b (%a2)+,(%a3)+
move.b (%a2)+,(%a3)+
move.b (%a2)+,(%a3)+
move.b (%a2)+,(%a3)+
MM3RLQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryMbc3RtcWork
MemoryMbc3RtcWork:
lea [email protected](%a5),%a2
btst #6,4(%a2)
jne MM3RWQuit /* rtc stopped? */
subq.b #1,[email protected](%a5)
jcc MM3RWQuit
move.b #videoFramesPerSec-1,[email protected](%a5)
addq.b #1,(%a2)
cmp.b #60,(%a2)
jne MM3RWQuit
clr.b (%a2)+
addq.b #1,(%a2)
cmp.b #60,(%a2)
jne MM3RWQuit
clr.b (%a2)+
addq.b #1,(%a2)
cmp.b #24,(%a2)
jne MM3RWQuit
clr.b (%a2)+
addq.b #1,(%a2)+
jcc MM3RWQuit
bchg #0,(%a2)
jeq MM3RWQuit
bset #7,(%a2) /* count values */
MM3RWQuit:
rts
/* -------------------------------------------------------------------- */
.globl MemoryMbc5RomSelect
MemoryMbc5RomSelect:
and.w #0xff,%d0 /* only 256 banks (4 MB) */
add.w %d0,%d0
add.w %d0,%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRomCorrect)
/* -------------------------------------------------------------------- */
.globl MemoryMbc5RamSelect
MemoryMbc5RamSelect:
and.w #0x03,%d0 /* only 4 banks (32 KB) */
add.w %d0,%d0
add.w %d0,%d0
lea [email protected](%a5),%a3
move.l (%a3,%d0.w),[email protected](%a5)
jmp indexToAddress(gbemuCodeSpRamCorrect)
/* === Functions accessing external memory ============================ */
.globl MemoryRamRdExtNone
MemoryRamRdExtNone:
move.l [email protected](%a5),%a2
lea -1(%a0),%a3
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamWrExtNone
MemoryRamWrExtNone:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamRdExtMbc2
MemoryRamRdExtMbc2:
move.l [email protected](%a5),%a2
and.w #0xa1ff,%d1
lea (%a2,%d1.w),%a3
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamWrExtMbc2
MemoryRamWrExtMbc2:
move.l [email protected](%a5),%a2
and.w #0xa1ff,%d1
and.b #0x0f,%d0
move.b %d0,(%a2,%d1.w)
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamRdExt2K
MemoryRamRdExt2K:
move.l [email protected](%a5),%a2
and.w #0xa7ff,%d1
lea (%a2,%d1.w),%a3
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamWrExt2K
MemoryRamWrExt2K:
move.l [email protected](%a5),%a2
and.w #0xa7ff,%d1
move.b %d0,(%a2,%d1.w)
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamRdExt8K
MemoryRamRdExt8K:
move.l [email protected](%a5),%a2
lea (%a2,%d1.w),%a3
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamWrExt8K
MemoryRamWrExt8K:
move.l [email protected](%a5),%a2
move.b %d0,(%a2,%d1.w)
jmp (%a6)
/* === Functions accessing internal memory ============================ */
.globl MemoryRamNone
MemoryRamNone:
move.b %d0,(%a2,%d1.w)
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamTileBg
MemoryRamTileBg:
cmp.b (%a2,%d1.w),%d0
jeq MrtbQuit /* no change? */
move.w %d3,-(%sp)
move.b %d0,(%a2,%d1.w) /* store pattern in tile table */
MrtbStart:
and.w #0xfffe,%d1
lea (%a2,%d1.w),%a3
ror.w #4,%d1
move.w %d1,%d0
and.w #0xff,%d1
move.w %d1,%d3
ror.w #3,%d0
and.w #7*0x100*4,%d0
add.w %d1,%d1
add.w %d1,%d1
add.w %d1,%d0 /* prepare some values */
MrtbCheck:
move.w [email protected](%a5),%d2
move.l [email protected](%a5),%a2
cmp.b (%a2,%d3.w),%d2
jne MrtbExit /* tile not used? */
move.l [email protected](%a5),%a2
add.w %d0,%a2
move.l %a0,-(%sp)
moveq #0,%d0
moveq #0,%d1
move.l [email protected](%a5),%a0
jsr (%a0)
swap %d0
move.l [email protected](%a5),%a0
jsr (%a0)
add.l %d0,%d0
lea VideoGrayCopyTable(%pc),%a0
move.w (%a0,%d0.w),%d1
add.w %d1,%d1
swap %d0
or.w (%a0,%d0.w),%d1
lsl.l %d2,%d1
move.l %d1,(%a2)
moveq #0,%d1
move.b (%a3)+,%d1
or.b (%a3),%d1
add.w %d1,%d1
move.w (%a0,%d1.w),%d1
move.w %d1,%d0
add.w %d0,%d0
or.w %d0,%d1
lsl.l %d2,%d1
move.l %d1,8*0x100*4(%a2)
move.l (%sp)+,%a0 /* convert one line */
MrtbExit:
move.w (%sp)+,%d3
MrtbQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamTileBgWi
MemoryRamTileBgWi:
cmp.b (%a2,%d1.w),%d0
jeq MrtbQuit /* no change? */
move.w %d3,-(%sp)
move.b %d0,(%a2,%d1.w) /* store pattern in tile table */
MrtbwStart:
and.w #0xfffe,%d1
lea (%a2,%d1.w),%a3
ror.w #4,%d1
move.w %d1,%d0
and.w #0xff,%d1
move.w %d1,%d3
ror.w #3,%d0
and.w #7*0x100*4,%d0
add.w %d1,%d1
add.w %d1,%d1
add.w %d1,%d0 /* prepare some values */
move.w [email protected](%a5),%d2
move.l [email protected](%a5),%a2
cmp.b (%a2,%d3.w),%d2
jne MrtbwQuit /* tile not used in window? */
move.l [email protected](%a5),%a2
add.w %d0,%a2
move.l %a0,-(%sp)
move.w %d0,-(%sp)
moveq #0,%d0
moveq #0,%d1
move.l [email protected](%a5),%a0
jsr (%a0)
swap %d0
move.l [email protected](%a5),%a0
jsr (%a0)
add.l %d0,%d0
lea VideoGrayCopyTable(%pc),%a0
move.w (%a0,%d0.w),%d1
add.w %d1,%d1
swap %d0
or.w (%a0,%d0.w),%d1
lsl.l %d2,%d1
move.l %d1,(%a2)
moveq #0,%d1
move.b (%a3),%d1
or.b 1(%a3),%d1
add.w %d1,%d1
move.w (%a0,%d1.w),%d1
move.w %d1,%d0
add.w %d0,%d0
or.w %d0,%d1
lsl.l %d2,%d1
move.l %d1,8*0x100*4(%a2)
move.w (%sp)+,%d0
move.l (%sp)+,%a0 /* convert one line (wi) */
MrtbwQuit:
jra MrtbCheck /* now check for background */
/* -------------------------------------------------------------------- */
.globl MemoryRamTileOb
MemoryRamTileOb:
cmp.b (%a2,%d1.w),%d0
jeq MrtoQuit /* no change? */
move.b %d0,(%a2,%d1.w) /* store pattern in tile table */
move.w %d3,-(%sp)
jbsr VideoObTileCheck(%pc)
move.w (%sp)+,%d3
MrtoQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamTileBgOb
MemoryRamTileBgOb:
cmp.b (%a2,%d1.w),%d0
jeq MrtoQuit /* no change? */
move.b %d0,(%a2,%d1.w) /* store pattern in tile table */
move.w %d3,-(%sp)
jbsr VideoObTileCheck(%pc)
jra MrtbStart
/* -------------------------------------------------------------------- */
.globl MemoryRamTileBgWiOb
MemoryRamTileBgWiOb:
cmp.b (%a2,%d1.w),%d0
jeq MrtoQuit /* no change? */
move.b %d0,(%a2,%d1.w) /* store pattern in tile table */
move.w %d3,-(%sp)
jbsr VideoObTileCheck(%pc)
jra MrtbwStart
/* -------------------------------------------------------------------- */
.globl MemoryRamMapNone
MemoryRamMapNone:
cmp.b (%a2,%d1.w),%d0
jeq MrmnQuit /* no change? */
move.b %d0,(%a2,%d1.w) /* store tile number in map */
add.w %d1,%d1
and.w #2*videoMapWrap*videoMapWrap*2-1,%d1
move.l [email protected](%a5),%a2
moveq #0,%d2
move.b %d0,%d2
add.w %d2,%d2
add.w %d2,%d2
move.w %d2,(%a2,%d1.w) /* store precalculated index */
MrmnQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamMapBg
MemoryRamMapBg:
cmp.b (%a2,%d1.w),%d0
jeq MrmbQuit /* no change? */
move.b %d0,(%a2,%d1.w) /* store tile number in map */
add.w %d1,%d1
and.w #2*videoMapWrap*videoMapWrap*2-1,%d1
move.l [email protected](%a5),%a2
moveq #0,%d2
move.b %d0,%d2
move.w %d2,%d0
add.w %d2,%d2
add.w %d2,%d2
move.w %d2,(%a2,%d1.w) /* store precalculated index */
move.w %d2,%d1
move.w [email protected](%a5),%d2
move.l [email protected](%a5),%a2
cmp.b (%a2,%d0.w),%d2
jeq MrmbQuit /* already converted? */
move.b %d2,(%a2,%d0.w)
move.l [email protected](%a5),%a3
tst.b %d0
jpl MrmbTileOK
move.l [email protected](%a5),%a3
MrmbTileOK:
move.l [email protected](%a5),%a2
add.w %d1,%a2
add.w %d1,%d1
add.w %d1,%d1
add.w %d1,%a3
movem.l %d3/%a0-%a1/%a4,-(%sp)
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
lea VideoGrayCopyTable(%pc),%a4
jbsr VideoConvertBgWi(%pc)
movem.l (%sp)+,%d3/%a0-%a1/%a4
MrmbQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamMapWi
MemoryRamMapWi:
cmp.b (%a2,%d1.w),%d0
jeq MrmwQuit /* no change? */
move.b %d0,(%a2,%d1.w) /* store tile number in map */
add.w %d1,%d1
and.w #2*videoMapWrap*videoMapWrap*2-1,%d1
move.l [email protected](%a5),%a2
moveq #0,%d2
move.b %d0,%d2
move.w %d2,%d0
add.w %d2,%d2
add.w %d2,%d2
move.w %d2,(%a2,%d1.w) /* store precalculated index */
move.w %d2,%d1
move.w [email protected](%a5),%d2
move.l [email protected](%a5),%a2
cmp.b (%a2,%d0.w),%d2
jeq MrmwQuit /* already converted? */
move.b %d2,(%a2,%d0.w)
move.l [email protected](%a5),%a3
tst.b %d0
jpl MrmwTileOK
move.l [email protected](%a5),%a3
MrmwTileOK:
move.l [email protected](%a5),%a2
add.w %d1,%a2
add.w %d1,%d1
add.w %d1,%d1
add.w %d1,%a3
movem.l %d3/%a0-%a1/%a4,-(%sp)
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
lea VideoGrayCopyTable(%pc),%a4
jbsr VideoConvertBgWi(%pc)
movem.l (%sp)+,%d3/%a0-%a1/%a4
MrmwQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamMapBgWi
MemoryRamMapBgWi:
cmp.b (%a2,%d1.w),%d0
jeq MrmbwWiQuit /* no change? */
move.l [email protected](%a5),%a3
move.b %d0,(%a2,%d1.w) /* store tile number in map */
jpl MrmbwTileOK
move.l [email protected](%a5),%a3
MrmbwTileOK:
add.w %d1,%d1
and.w #2*videoMapWrap*videoMapWrap*2-1,%d1
move.l [email protected](%a5),%a2
moveq #0,%d2
move.b %d0,%d2
move.w %d2,%d0
add.w %d2,%d2
add.w %d2,%d2
move.w %d2,(%a2,%d1.w) /* store precalculated index */
move.w %d0,-(%sp)
move.w %d2,%d1
add.w %d2,%d2
add.w %d2,%d2
add.w %d2,%a3 /* prepare some values */
move.w [email protected](%a5),%d2
move.l [email protected](%a5),%a2
cmp.b (%a2,%d0.w),%d2
jeq MrmbwBgQuit /* already converted? */
move.b %d2,(%a2,%d0.w)
move.l [email protected](%a5),%a2
add.w %d1,%a2
movem.l %d3/%a0-%a1/%a4,-(%sp)
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
lea VideoGrayCopyTable(%pc),%a4
jbsr VideoConvertBgWi(%pc) /* convert for background */
lea -8*2(%a3),%a3
movem.l (%sp)+,%d3/%a0-%a1/%a4
MrmbwBgQuit:
move.w (%sp)+,%d0
move.w [email protected](%a5),%d2
move.l [email protected](%a5),%a2
cmp.b (%a2,%d0.w),%d2
jeq MrmbwWiQuit /* already converted? */
move.b %d2,(%a2,%d0.w)
add.w %d0,%d0
add.w %d0,%d0
move.l [email protected](%a5),%a2
add.w %d0,%a2
movem.l %d3/%a0-%a1/%a4,-(%sp)
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
lea VideoGrayCopyTable(%pc),%a4
jbsr VideoConvertBgWi(%pc) /* convert for window */
movem.l (%sp)+,%d3/%a0-%a1/%a4
MrmbwWiQuit:
jmp (%a6)
/* -------------------------------------------------------------------- */
.globl MemoryRamOam
MemoryRamOam:
pea (%a6) /* save return address */
moveq #0xfc-0x100,%d2
and.w %d1,%d2
lea (%a2,%d2.w),%a3
move.l (%a3),%d2
move.b %d0,(%a2,%d1.w) /* store byte in memory */
move.l (%a3),%d0
cmp.b #40<<2,%d1
jcc MroeQuit /* object # too big? */
/* fall through to MemoryRamOamEntry */
/* -------------------------------------------------------------------- */
.globl MemoryRamOamEntry
MemoryRamOamEntry:
#define mroeRegs %d3-%d5/%a0/%a1/%a4
/* d0.l new value (already stored)
* d1.b offset into oam
* d2.l old value
* a2 (scratch)
* a3 pointer into oam
* a6 (scratch)
*/
eor.l %d0,%d2
jeq MroeQuit /* no change? */
movem.l mroeRegs,-(%sp)
/* - - check changes in y or x - - - - - - - - - - - - - - - - - - - - */
move.l #0xffff7f,%d5
and.l %d2,%d5 /* save changes in x/tile/flags */
move.l [email protected](%a5),%a6
move.w #0x00fc,%d0
and.w %d1,%d0
lsl.w #4-1,%d0
move.w %d0,%d1
lsl.w #3,%d0
sub.w %d1,%d0
add.w #videoScreenHeight*2*2,%d0
lea (%a6,%d0.w),%a2 /* prepare some values */
eor.w %d5,%d2
jne MroeXYLink
swap %d2
tst.w %d2
jeq MroeXYQuit /* no change? */
MroeXYLink:
jbsr VideoObLink(%pc) /* re-link object */
MroeXYQuit:
/* - - check changes in x, tile #, or flags - - - - - - - - - - - - - - */
tst.l %d5
jeq MroeXTFQuit /* no change? */
move.w (%a3)+,%d4
move.w [email protected](%a5),%d3
and.b (%a3)+,%d3
move.b (%a3)+,%d0
lsl.w #3+1,%d3
move.l [email protected](%a5),%a3
lea 0x8000-0x10000(%a3),%a3
add.w %d3,%a3
move.w [email protected](%a5),%d3
moveq #0x10,%d2
and.b %d0,%d2
jne MroeXTFObp1
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
jra MroeXTFConv
MroeXTFObp1:
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
MroeXTFConv:
lea VideoGrayCopyTable(%pc),%a4
jbsr VideoConvertOb(%pc)
MroeXTFQuit:
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
movem.l (%sp)+,mroeRegs
MroeQuit:
rts
/* === The end ======================================================== */