-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_s.S
3531 lines (2932 loc) · 82.5 KB
/
video_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
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
/************************************************************************
* video_s.S
* Video emulation routines (assembler part)
*
************************************************************************
*
* Phoinix,
* Nintendo Gameboy(TM) emulator for the Palm OS(R) Computing Platform
*
* (c)2000-2007 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: video_s.S,v $
* Revision 1.15 2007/02/25 13:15:08 bodowenzel
* No interrupt when writing into STAT
* Check for LYC on line 144 (Vsync) added
*
* Revision 1.14 2007/02/14 15:23:45 bodowenzel
* Frame counting like before gives better info display
* Writing into LYC should not generate an interrupt
*
* Revision 1.13 2007/02/11 17:14:53 bodowenzel
* Correct counting of video frames
* Correct handling of opcode HALT
*
* Revision 1.12 2007/01/08 13:46:56 bodowenzel
* Hsync interrupts only in line 0 to 143
*
* Revision 1.11 2007/01/05 14:17:33 bodowenzel
* LYC=0 interrupt now on first line
*
* Revision 1.10 2006/10/23 15:39:27 bodowenzel
* Clearing the screen at STOP corrected
*
* Revision 1.9 2005/02/17 19:42:35 bodowenzel
* Added pace control
*
* Revision 1.8 2005/01/30 19:34:39 bodowenzel
* Shortened long error message
*
* Revision 1.7 2004/12/28 13:58:40 bodowenzel
* Split up all C-Code to multi-segmented
* Support for devices without direct screen access
*
* Revision 1.6 2004/01/11 19:07:14 bodowenzel
* Corrected copyright
*
* Revision 1.5 2003/04/19 13:17:36 bodowenzel
* Now all calls are jbsr xxx(%pc)
* Screen copy for OS5 via WinDrawBitmap()
*
* Revision 1.4 2002/10/19 08:08:11 bodowenzel
* History cleanup, Javadoc-style header
*
* Revision 1.3 2001/12/30 18:47:11 bodowenzel
* CVS keyword Log was faulty
*
* Revision 1.2 2001/12/28 18:36:49 bodowenzel
* VideoCopyScreen() now after rendering all lines
* Thumbnail taken from VideoBuffer
*
* Revision 1.1.1.1 2001/12/16 13:39:34 bodowenzel
* Import
*
************************************************************************
* Pre-CVS History (developed as PalmBoy):
*
* 2001-09-16 Bodo Wenzel Saving states now possible
* 2001-07-26 Bodo Wenzel Changed syntax to CPP + GAS, joined with
* parts of gray.asm
*
* emuvideo.asm:
* 2001-02-18 Bodo Wenzel Window bug removed,
* bug with visibility of objects found,
* interrupts for hsync implemented
* 2000-11-18 Bodo Wenzel Support of color devices
* 2000-10-23 Bodo Wenzel Interrupts and timer
* 2000-09-17 Bodo Wenzel Now nearly full screen emulation
* 2000-09-10 Bodo Wenzel Got from runmode.asm
*
* gray.asm:
* 2001-02-10 Bodo Wenzel Support for grayhack: no register writes
* 2000-11-19 Bodo Wenzel Clean-up of support for color devices
* 2000-11-01 Till Harbaum Added support for the Palm IIIc and friends
* 2000-09-13 Bodo Wenzel Now nearly full screen emulation
* 2000-07-26 Bodo Wenzel Longer off time while mode switching
* 2000-05-05 Bodo Wenzel Got from full source v.0.4
************************************************************************
*/
/* === Notes ============================================================
*
* > Unlike documented for the real part, this emulation never shows
* 153/0 in the last line to the CPU, but 255.
* > For speeding up the timings for LCD status modes 2 and 3 are
* shortened.
* real: 152 gap 153/0 line 0 line ... 143 vsync 144 gap ...
* emu: 152 gap 255 line 0 line ... 143 vsync 144 gap ...
* i_ly: -10 gap 143 line 142 line ... -1 vsync -2 gap ...
* stat: 1 1 2/3/0 ... 2/3/0 1 ...
*
* > Unlike the real part the interrupts are just sampled at vsync (for
* vsync and joypad) and at the end of each line (for LYC, timer, hsync,
* and serial[currently not emulated]).
* > The display is built by different functions, each called for just one
* line. In general every line function uses preconverted patterns and
* masks. There are counters to manage the wrapping at borders, too.
* > The objects are drawn at last.
* > If data is written into video relevant memory, conversion takes place
* immediate. Since memory contents change not as often as screen output
* is made, this saves time.
*/
/* === Includes ======================================================= */
#include "video.h"
#include "gbemu.h"
/* === Constants ====================================================== */
#define screenYMax (videoScreenHeight-1) /* last line index */
#define opsPerLine (videoClksPerLine/6)
/* Calculated as clocks per line divided by 6 clocks average per opcode.
* This determines greatly the emulation speed!
*/
#define widthInBytes (videoScreenWidth/8*videoBitsPerPixel)
/* === Global and static variables ==================================== */
.comm VideoLyPrv,2 /* private line counters */
.lcomm VideoWyPrv,2
.lcomm VideoLineFunction,4 /* addr of next render function */
.lcomm VideoBgCount1,2 /* counter for loops, sum is 19 */
.lcomm VideoBgCount2,2
.lcomm VideoBgWiCount1,2 /* if <0: no wrap before window */
.lcomm VideoBgWiCount2,2 /* if <0: only window */
.lcomm VideoBgWiCount3,2 /* if <0: window not visible */
.lcomm VideoBufferCurPtr,4 /* pointer into display buffer */
.comm VideoBgWiColorH,4 /* addresses of color functions */
.comm VideoBgWiColorL,4
.comm VideoBgWiTileLow,4 /* pointer for tiles 0x00..0x7f */
.comm VideoBgWiTileHigh,4 /* pointer for tiles 0x80..0xff */
.lcomm VideoBgWiMask,widthInBytes /* mask buffer one line */
.comm VideoBgScxPixel,2 /* prehandled scroll */
.lcomm VideoBgScxTile,2
.lcomm VideoBgMapStart,4 /* pointer into background */
.lcomm VideoBgMapOffset,2
.lcomm VideoBgTilePtr,4 /* pointer to converted tiles */
.lcomm VideoBgTileMax,4
.comm VideoWiWxPixel,2 /* prehandled scroll */
.lcomm VideoWiWxMask,2
.lcomm VideoWiMapStart,4 /* pointer into window */
.lcomm VideoWiMapOffset,2
.lcomm VideoWiTilePtr,4 /* pointer to converted tiles */
.lcomm VideoWiTileMax,4
.lcomm VideoObYOffset,2 /* offset into offset table */
.comm VideoObColor0H,4 /* addresses of color functions */
.comm VideoObColor0L,4
.comm VideoObColor1H,4
.comm VideoObColor1L,4
.comm VideoObCount,2 /* prehandled height */
.comm VideoObTilemask,2
.lcomm VideoIntMaskVsync,1 /* mask for vsync int */
.lcomm VideoIntMaskStat,1 /* mask for STAT int */
.lcomm VideoIntMaskSV,1 /* mask for STAT, vsync */
.lcomm VideoIntMaskSH,1 /* mask for STAT, hsync */
.lcomm VideoIntLycReload,1 /* counter for STAT, LYC */
.lcomm VideoIntLycCount,1
/* === Placing the code =============================================== */
.section emulator,"x"
/* === Function for user polling ====================================== */
.globl VideoUserPoll
VideoUserPoll:
/* This function is called after the last screen line. The function
* returns to the caller of the emulator if the emulation quits.
*/
#define vupRegs %d3/%a0/%a1
movem.l vupRegs,-(%sp)
/* - - copy screen if frame doesn't have to be skipped - - - - - - - - */
move.w [email protected](%a5),%d0
jne VupNoCopy /* skip frame? */
jbsr VideoCopyScreen(%pc) /* show last rendered screen */
VupNoCopy:
add.w #1,[email protected](%a5)
/* - - poll for user and system requests - - - - - - - - - - - - - - - */
jbsr EmulationUserPoll(%pc)
tst.b %d0
jeq VupGoon /* continue emulation */
movem.l (%sp)+,vupRegs
lea 0x76*0x0100(%a4),%a2
lea gbemuOpSize(%a2),%a3
move.l (%sp)+,%d0
cmp.l %a2,%d0
jcs VupQuit
cmp.l %a3,%d0 /* check for opcode $76 (HALT) */
jcc VupQuit
subq.w #1,%a0 /* correct PC to repeat it */
VupQuit:
moveq #gbemuRetUserStop,%d0 /* return to emulation caller */
rts
VupGoon:
/* - - check for joypad interrupt - - - - - - - - - - - - - - - - - - */
move.l [email protected](%a5),%a0
move.b (%a0),%d0
not.b %d0
and.b [email protected](%a5),%d0
sne %d1
and.b #0x10,%d1
or.b %d1,[email protected](%a5)
move.b (%a0),[email protected](%a5)
/* - - MBC3 work (count RTC) - - - - - - - - - - - - - - - - - - - - - */
jbsr MemoryMbc3RtcWork(%pc)
/* - - start a new screen - - - - - - - - - - - - - - - - - - - - - - */
move.w #screenYMax-1-(videoScreenHeight),[email protected](%a5)
lea LineGap(%pc),%a2
move.l %a2,2+indexToAddress(gbemuJmpLcdLine)
/* - - return to emulation - - - - - - - - - - - - - - - - - - - - - - */
move.w #opsPerLine-1,%d6
add.w #videoClksPerLine,[email protected](%a5)
move.w [email protected](%a5),%d0
add.w %d0,[email protected](%a5)
jcc VupTExit
move.b [email protected](%a5),%d0
VupTLoop:
add.b %d0,[email protected](%a5)
jcs VupTLoop
bset #2,[email protected](%a5)
VupTExit:
subq.b #1,[email protected](%a5)
jcc VupLycExit
btst #6,[email protected](%a5)
jeq VupLycExit
move.b [email protected](%a5),%d0
or.b %d0,[email protected](%a5)
VupLycExit:
move.b [email protected](%a5),%d0
and.b [email protected](%a5),%d0
or.b [email protected](%a5),%d0
or.b %d0,[email protected](%a5)
movem.l (%sp)+,vupRegs
jmp indexToAddress(gbemuCodeCheckInt)
/* === Timer support ================================================== */
.globl VideoIoWrTac
VideoIoWrTac:
move.b %d0,[email protected](%a5)
and.w #7,%d0 /* set delta value */
add.w %d0,%d0
lea ViwtTable(%pc),%a3
move.w (%a3,%d0.w),[email protected](%a5)
jmp (%a6)
ViwtTable:
.short 0,0,0,0 /* timer stopped */
.short videoClksPerLine/4 /* timer running */
.short videoClksPerLine*16
.short videoClksPerLine*4
.short videoClksPerLine
/* === Functions for screen rendering ================================= */
.globl VideoClearBuffer
VideoClearBuffer:
/* Can be called from emulation and C-code:
* d0.w (scratch)
* d1 (scratch)
* Call this function with memory protection disabled!
*/
move.l %a2,-(%sp)
move.l [email protected](%a5),%a2
move.w #videoScreenHeight-1,%d0
moveq #0,%d1
VcbLoop:
#if videoScreenWidth != 160
#error "Please adjust function VideoClearBuffer!"
#endif
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
move.l %d1,(%a2)+
dbra %d0,VcbLoop
move.l (%sp)+,%a2
rts
/* -------------------------------------------------------------------- */
.globl VideoCopyScreenByDirectAccess
VideoCopyScreenByDirectAccess:
/* Can be called from emulation and C-code:
* d0.w (scratch)
* d1.w (scratch)
* d2 (scratch)
* Call this function with memory protection disabled!
*/
#if videoScreenWidth != 160
#error "Please adjust function VideoCopyScreenByDirectAccess!"
#endif
#define vcpsRegs %d3-%d7/%a0-%a4/%a6
#define vcpsCopyRegs %d2-%d7/%a2-%a4/%a6 /* 10 registers !!! */
movem.l vcpsRegs,-(%sp)
move.l [email protected](%a5),%a0
move.l [email protected](%a5),%a1
move.w #videoScreenHeight-1,%d0
move.w [email protected](%a5),%d1
VcpsLoop:
movem.l (%a0)+,vcpsCopyRegs
movem.l vcpsCopyRegs,(%a1)
add.w %d1,%a1
dbra %d0,VcpsLoop
movem.l (%sp)+,vcpsRegs
rts
/* -------------------------------------------------------------------- */
LineGap:
move.w [email protected](%a5),%d0
subq.w #1,%d0
cmp.w #screenYMax-1-153,%d0
jeq LgNewPic /* vsync finished? */
move.w %d0,[email protected](%a5)
jra LineGapQuitReturn
/* - - start a new picture, no need to check for on/off - - - - - - - - */
LgNewPic:
move.w #screenYMax-1+1,[email protected](%a5)
move.b [email protected](%a5),%d6
add.w %d6,%d6
add.w %d6,%d6
move.b %d6,-(%sp)
and.w #(videoMapWrap-1)*videoMapWrap,%d6
add.w [email protected](%a5),%d6
add.w %d6,%d6
move.w %d6,[email protected](%a5)
move.w (%sp)+,%d6
and.w #7*0x100*4,%d6
move.l [email protected](%a5),%a3
lea 8*0x100*4(%a3),%a2
add.w %d6,%a3
move.l %a3,[email protected](%a5)
move.l %a2,[email protected](%a5) /* set up for background */
moveq #0,%d1
move.w %d1,[email protected](%a5)
move.b [email protected](%a5),%d1
move.w %d1,[email protected](%a5)
move.l [email protected](%a5),%a3
lea 8*0x100*4(%a3),%a2
move.l %a3,[email protected](%a5)
move.l %a2,[email protected](%a5) /* set up for window */
clr.w [email protected](%a5) /* set up for objects */
move.l [email protected](%a5),[email protected](%a5)
move.l [email protected](%a5),2+indexToAddress(gbemuJmpLcdLine)
/* - - return to emulation - - - - - - - - - - - - - - - - - - - - - - */
move.w #opsPerLine-1,%d6
add.w #videoClksPerLine,[email protected](%a5)
move.w [email protected](%a5),%d0
add.w %d0,[email protected](%a5)
jcc LgTExit
move.b [email protected](%a5),%d0
LgTLoop:
add.b %d0,[email protected](%a5)
jcs LgTLoop
bset #2,[email protected](%a5)
LgTExit:
move.b [email protected](%a5),[email protected](%a5)
jmp indexToAddress(gbemuCodeCheckInt)
/* -------------------------------------------------------------------- */
LineNone:
/* a2 pointer into palm display
*/
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
move.l [email protected](%a5),%a2
moveq #widthInBytes/4/2-1,%d0
moveq #0,%d1
/* - - erase line - - - - - - - - - - - - - - - - - - - - - - - - - - - */
LnLoop:
move.l %d1,(%a2)+
move.l %d1,(%a2)+
dbra %d0,LnLoop
/* - - update pointer - - - - - - - - - - - - - - - - - - - - - - - - - */
move.l %a2,[email protected](%a5)
/* falls through to LineQuit */
/* -------------------------------------------------------------------- */
LineQuit:
subq.w #1,[email protected](%a5)
jcc LineQuitReturn /* rendering not finished? */
lea VideoUserPoll(%pc),%a2
move.l %a2,2+indexToAddress(gbemuJmpLcdLine)
/* falls through to LineQuitReturn */
/* -------------------------------------------------------------------- */
LineQuitReturn:
move.b [email protected](%a5),%d0
and.b [email protected](%a5),%d0
or.b %d0,[email protected](%a5)
LineGapQuitReturn:
move.w #opsPerLine-1,%d6
add.w #videoClksPerLine,[email protected](%a5)
move.w [email protected](%a5),%d0
add.w %d0,[email protected](%a5)
jcc LqrTExit
move.b [email protected](%a5),%d0
LqrTLoop:
add.b %d0,[email protected](%a5)
jcs LqrTLoop
bset #2,[email protected](%a5)
LqrTExit:
subq.b #1,[email protected](%a5)
jcc LqrLycExit
btst #6,[email protected](%a5)
jeq LqrLycExit
move.b [email protected](%a5),%d0
or.b %d0,[email protected](%a5)
LqrLycExit:
jmp indexToAddress(gbemuCodeCheckInt)
/* -------------------------------------------------------------------- */
LineOb:
/* a0 pointer into palm display incl. offset
* a2 pointer into palm display
* a3 pointer to pixel line in object
* a6 pointer VideoObFirst
*/
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
move.l %a0,-(%sp)
move.l [email protected](%a5),%a2
moveq #widthInBytes/4/2-1,%d0
moveq #0,%d1
/* - - erase line - - - - - - - - - - - - - - - - - - - - - - - - - - - */
LoLoop:
move.l %d1,(%a2)+
move.l %d1,(%a2)+
dbra %d0,LoLoop
/* - - update offsets and pointers - - - - - - - - - - - - - - - - - - */
move.l %a2,[email protected](%a5)
/* - - objects behind background/window - - - - - - - - - - - - - - - - */
lea -widthInBytes(%a2),%a2
move.l [email protected](%a5),%a6
move.w [email protected](%a5),%d0
move.w (%a6,%d0.w),%d1
jmi LoBgQuit /* no objects behind bg./wi.? */
LoBgLoop:
lea (%a6,%d1.w),%a3
move.w (%a3)+,%d1
lea (%a2,%d1.w),%a0
move.l (%a3)+,%d2
and.l %d2,(%a0)
move.l (%a3)+,%d2
or.l %d2,(%a0) /* insert object */
move.w (%a3),%d1
jpl LoBgLoop /* more objects? */
LoBgQuit:
/* - - objects in front of background/window - - - - - - - - - - - - - */
addq.w #2,%d0
move.w (%a6,%d0.w),%d1
jmi LoFgQuit /* no obj's in front of bg./wi.? */
LoFgLoop:
lea (%a6,%d1.w),%a3
move.w (%a3)+,%d1
lea (%a2,%d1.w),%a0
move.l (%a3)+,%d2
and.l %d2,(%a0)
move.l (%a3)+,%d2
or.l %d2,(%a0) /* insert object */
move.w (%a3),%d1
jpl LoFgLoop /* more objects? */
LoFgQuit:
addq.w #2,%d0
move.w %d0,[email protected](%a5)
move.l (%sp)+,%a0
jra LineQuit
/* -------------------------------------------------------------------- */
LineBgCh:
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
move.w [email protected](%a5),%d0
dbmi %d0,LbcBg /* window not reached? */
move.w %d0,[email protected](%a5)
lea LineBgWi(%pc),%a2
move.l %a2,2+indexToAddress(gbemuJmpLcdLine)
jmp (%a2) /* now render with window */
LbcBg:
move.w %d0,[email protected](%a5)
/* falls through to LineBg */
/* -------------------------------------------------------------------- */
LineBg:
/* a0 pointer to left tile pattern
* a1 pointer to right tile pattern
* a2 pointer into palm display
* a3 pointer to pixel line base
* a6 pointer to actual tile number in background
*/
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
move.l %a0,-(%sp)
move.l %a1,-(%sp)
move.l [email protected](%a5),%a2
move.l [email protected](%a5),%a3
move.l [email protected](%a5),%a6
add.w [email protected](%a5),%a6
move.w (%a6)+,%d1
lea 2(%a3,%d1.w),%a0 /* ptr to "old" right pattern */
move.w [email protected](%a5),%d0
move.w [email protected](%a5),%d2
jmi LbLoop2 /* no line wrap? */
jra LbNext1
/* - - render until wrap - - - - - - - - - - - - - - - - - - - - - - - */
LbLoop1:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
LbNext1:
dbra %d2,LbLoop1
lea -videoMapWrap*2(%a6),%a6 /* wrap pointer */
/* - - render until finished - - - - - - - - - - - - - - - - - - - - - */
LbLoop2:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
dbra %d0,LbLoop2
/* - - update pointers - - - - - - - - - - - - - - - - - - - - - - - - */
move.l %a2,[email protected](%a5)
lea 0x100*4(%a3),%a3
cmp.l [email protected](%a5),%a3
jcs LbExit /* not last pixel line? */
lea -8*0x100*4(%a3),%a3
moveq #videoMapWrap*2,%d0
add.w [email protected](%a5),%d0
cmp.w #videoMapWrap*videoMapWrap*2,%d0
jcs LbNewline /* no vertical wrap? */
sub.w #videoMapWrap*videoMapWrap*2,%d0
LbNewline:
move.w %d0,[email protected](%a5)
LbExit:
move.l %a3,[email protected](%a5)
move.l (%sp)+,%a1
move.l (%sp)+,%a0
jra LineQuit
/* -------------------------------------------------------------------- */
LineBgWi:
/* a0 pointer to left tile pattern
* a1 pointer to right tile pattern
* a2 pointer into palm display
* a3 pointer to pixel line base
* a6 pointer to actual tile number in background
*/
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
move.l %a0,-(%sp)
move.l %a1,-(%sp)
move.l [email protected](%a5),%a2
move.l [email protected](%a5),%a3
move.w [email protected](%a5),%d0
jmi LbwWi /* only window? */
move.l [email protected](%a5),%a6
add.w [email protected](%a5),%a6
move.w (%a6)+,%d1
lea 2(%a3,%d1.w),%a0 /* ptr to "old" right pattern */
move.w [email protected](%a5),%d2
jmi LbwLoop2 /* no wrap before window? */
jra LbwNext1
/* - - render until wrap - - - - - - - - - - - - - - - - - - - - - - - */
LbwLoop1:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
LbwNext1:
dbra %d2,LbwLoop1
lea -videoMapWrap*2(%a6),%a6 /* wrap pointer */
/* - - render until window - - - - - - - - - - - - - - - - - - - - - - */
LbwLoop2:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
dbra %d0,LbwLoop2
/* - - update background pointers - - - - - - - - - - - - - - - - - - - */
lea 0x100*4(%a3),%a3
cmp.l [email protected](%a5),%a3
jcs LbwBgExit /* not last pixel line? */
lea -8*0x100*4(%a3),%a3
moveq #videoMapWrap*2,%d0
add.w [email protected](%a5),%d0
cmp.w #videoMapWrap*videoMapWrap*2,%d0
jcs LbwBgNewline /* no vertical wrap? */
sub.w #videoMapWrap*videoMapWrap*2,%d0
LbwBgNewline:
move.w %d0,[email protected](%a5)
LbwBgExit:
move.l %a3,[email protected](%a5)
/* - - render window after background - - - - - - - - - - - - - - - - - */
move.l [email protected](%a5),%a3
move.w [email protected](%a5),%d0
jmi LbwExit /* window not visible? */
move.l [email protected](%a5),%a6
add.w [email protected](%a5),%a6
move.w [email protected](%a5),%d2
and.w %d2,-(%a2)
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to first pattern */
move.w (%a0)+,%d1
or.w %d1,(%a2)+ /* store first pattern */
jra LbwNext3
/* - - render window only, but first update background pointers - - - - */
LbwWi:
lea 0x100*4(%a3),%a3
cmp.l [email protected](%a5),%a3
jcs LbwWiBgExit /* not last pixel line? */
lea -8*0x100*4(%a3),%a3
moveq #videoMapWrap*2,%d0
add.w [email protected](%a5),%d0
cmp.w #videoMapWrap*videoMapWrap*2,%d0
jcs LbwWiBgNewline /* no vertical wrap? */
sub.w #videoMapWrap*videoMapWrap*2,%d0
LbwWiBgNewline:
move.w %d0,[email protected](%a5)
LbwWiBgExit:
move.l %a3,[email protected](%a5)
move.l [email protected](%a5),%a3
move.l [email protected](%a5),%a6
add.w [email protected](%a5),%a6
move.w (%a6)+,%d1
lea 2(%a3,%d1.w),%a0 /* ptr to "old" right pattern */
move.w [email protected](%a5),%d0
/* - - render until finished - - - - - - - - - - - - - - - - - - - - - */
LbwLoop3:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
LbwNext3:
dbra %d0,LbwLoop3
/* - - update picture and window pointers - - - - - - - - - - - - - - - */
LbwExit:
move.l %a2,[email protected](%a5)
lea 0x100*4(%a3),%a3
cmp.l [email protected](%a5),%a3
jcs LbwWiExit /* not last pixel line? */
lea -8*0x100*4(%a3),%a3
add.w #videoMapWrap*2,[email protected](%a5)
LbwWiExit:
move.l %a3,[email protected](%a5)
move.l (%sp)+,%a1
move.l (%sp)+,%a0
jra LineQuit
/* -------------------------------------------------------------------- */
LineBgChOb:
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
move.w [email protected](%a5),%d0
dbmi %d0,LbcoBg /* window not reached? */
move.w %d0,[email protected](%a5)
lea LineBgWiOb(%pc),%a2
move.l %a2,2+indexToAddress(gbemuJmpLcdLine)
jmp (%a2) /* now render with window */
LbcoBg:
move.w %d0,[email protected](%a5)
/* falls through to LineBgOb */
/* -------------------------------------------------------------------- */
LineBgOb:
#define lboRegs %a0/%a1/%a4
/* a0 pointer to left tile pattern / palm display incl. offset
* a1 pointer to right tile pattern
* a2 pointer into palm display
* a3 pointer pixel line base / to pixel line in object
* a4 pointer to mask
* a6 pointer to actual tile number in background / VideoObFirst
*/
move.w [email protected](%a5),%d0
jne LineQuit /* skip frame? */
movem.l lboRegs,-(%sp)
move.l [email protected](%a5),%a2
move.l [email protected](%a5),%a3
move.l [email protected](%a5),%a6
add.w [email protected](%a5),%a6
move.w (%a6)+,%d1
lea 2(%a3,%d1.w),%a0 /* ptr to "old" right pattern */
move.l [email protected](%a5),%a1
move.w [email protected](%a5),%d1
move.w (%a1,%d1.w),%d1
jpl LboMasking /* objects behind bg./wi.? */
move.w [email protected](%a5),%d0
move.w [email protected](%a5),%d2
jmi LboLoop2 /* no line wrap? */
jra LboNext1
/* - - render until wrap - - - - - - - - - - - - - - - - - - - - - - - */
LboLoop1:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
LboNext1:
dbra %d2,LboLoop1
lea -videoMapWrap*2(%a6),%a6 /* wrap pointer */
/* - - render until finished - - - - - - - - - - - - - - - - - - - - - */
LboLoop2:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
dbra %d0,LboLoop2
/* - - update pointers - - - - - - - - - - - - - - - - - - - - - - - - */
move.l %a2,[email protected](%a5)
lea 0x100*4(%a3),%a3
cmp.l [email protected](%a5),%a3
jcs LboExit /* not last pixel line? */
lea -8*0x100*4(%a3),%a3
moveq #videoMapWrap*2,%d0
add.w [email protected](%a5),%d0
cmp.w #videoMapWrap*videoMapWrap*2,%d0
jcs LboNewline /* no vertical wrap? */
sub.w #videoMapWrap*videoMapWrap*2,%d0
LboNewline:
move.w %d0,[email protected](%a5)
LboExit:
move.l %a3,[email protected](%a5)
/* - - prepare for objects - - - - - - - - - - - - - - - - - - - - - - */
lea -widthInBytes(%a2),%a2
move.l [email protected](%a5),%a6
jra LboForeground
/* - - render and save mask for this line - - - - - - - - - - - - - - - */
LboMasking:
lea [email protected](%a5),%a4
move.w [email protected](%a5),%d0
move.w [email protected](%a5),%d2
jmi LboMLoop2 /* no line wrap? */
jra LboMNext1
/* - - render until wrap - - - - - - - - - - - - - - - - - - - - - - - */
LboMLoop1:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w 8*0x100*4(%a1),%d1
or.w 8*0x100*4(%a0),%d1
move.w %d1,(%a4)+ /* store mask */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
LboMNext1:
dbra %d2,LboMLoop1
lea -videoMapWrap*2(%a6),%a6 /* wrap pointer */
/* - - render until finished - - - - - - - - - - - - - - - - - - - - - */
LboMLoop2:
move.l %a0,%a1 /* right becomes left */
move.w (%a6)+,%d1
lea (%a3,%d1.w),%a0 /* pointer to right pattern */
move.w 8*0x100*4(%a1),%d1
or.w 8*0x100*4(%a0),%d1
move.w %d1,(%a4)+ /* store mask */
move.w (%a1)+,%d1
or.w (%a0)+,%d1
move.w %d1,(%a2)+ /* join patterns */
dbra %d0,LboMLoop2
/* - - update pointers - - - - - - - - - - - - - - - - - - - - - - - - */
move.l %a2,[email protected](%a5)
lea 0x100*4(%a3),%a3
cmp.l [email protected](%a5),%a3
jcs LboMExit /* not last pixel line? */
lea -8*0x100*4(%a3),%a3
moveq #videoMapWrap*2,%d0
add.w [email protected](%a5),%d0
cmp.w #videoMapWrap*videoMapWrap*2,%d0
jcs LboMNewline /* no vertical wrap? */
sub.w #videoMapWrap*videoMapWrap*2,%d0
LboMNewline:
move.w %d0,[email protected](%a5)
LboMExit:
move.l %a3,[email protected](%a5)
/* - - objects behind background/window - - - - - - - - - - - - - - - - */
moveq #widthInBytes,%d1
sub.w %d1,%a2
sub.w %d1,%a4
move.l [email protected](%a5),%a6