SpriteScreen.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13: package xeij;
14:
15: import java.lang.*;
16: import java.util.*;
17:
18: public class SpriteScreen {
19:
20:
21: public static final int SPR_REG0_BG0_X = 0x00eb0800;
22: public static final int SPR_REG1_BG0_Y = 0x00eb0802;
23: public static final int SPR_REG2_BG1_X = 0x00eb0804;
24: public static final int SPR_REG3_BG1_Y = 0x00eb0806;
25: public static final int SPR_REG4_BG_CTRL = 0x00eb0808;
26:
27:
28:
29:
30:
31: public static final int SPR_REG5_H_FRONT_END = 0x00eb080a;
32: public static final int SPR_REG6_H_BACK_END = 0x00eb080c;
33: public static final int SPR_REG7_V_BACK_END = 0x00eb080e;
34: public static final int SPR_REG8_RESO = 0x00eb0810;
35:
36:
37:
38:
39:
40: public static final int SPR_REG9_BANK_CONTROL = 0x00eb0812;
41: public static final int SPR_REG10_BANK_SELECT = 0x00eb0814;
42:
43:
44:
45: public static int sprReg0Bg0XPort;
46: public static int sprReg0Bg0XMask;
47: public static int sprReg0Bg0XTest;
48: public static int sprReg0Bg0XCurr;
49: public static int sprReg1Bg0YPort;
50: public static int sprReg1Bg0YMask;
51: public static int sprReg1Bg0YTest;
52: public static int sprReg1Bg0YCurr;
53: public static int sprReg2Bg1XPort;
54: public static int sprReg2Bg1XMask;
55: public static int sprReg2Bg1XTest;
56: public static int sprReg2Bg1XCurr;
57: public static int sprReg3Bg1YPort;
58: public static int sprReg3Bg1YMask;
59: public static int sprReg3Bg1YTest;
60: public static int sprReg3Bg1YCurr;
61: public static int sprReg4BgCtrlPort;
62: public static int sprReg4BgCtrlMask;
63: public static int sprReg4BgCtrlTest;
64: public static int sprReg4BgCtrlCurr;
65: public static int sprReg5HFrontEndPort;
66: public static int sprReg5HFrontEndMask;
67: public static int sprReg5HFrontEndTest;
68: public static int sprReg5HFrontEndCurr;
69: public static int sprReg6HBackEndPort;
70: public static int sprReg6HBackEndMask;
71: public static int sprReg6HBackEndTest;
72: public static int sprReg6HBackEndCurr;
73: public static int sprReg7VBackEndPort;
74: public static int sprReg7VBackEndMask;
75: public static int sprReg7VBackEndTest;
76: public static int sprReg7VBackEndCurr;
77: public static int sprReg8ResoPort;
78: public static int sprReg8ResoMask;
79: public static int sprReg8ResoTest;
80: public static int sprReg8ResoCurr;
81:
82:
83: public static final int SPR_SHIFT = 10;
84: public static final int SPR_COUNT = 1 << SPR_SHIFT;
85: public static final short[] sprX = new short[SPR_COUNT];
86: public static final short[] sprY = new short[SPR_COUNT];
87: public static final short[] sprNumPort = new short[SPR_COUNT];
88: public static final short[] sprColPort = new short[SPR_COUNT];
89: public static final byte[] sprPrw = new byte[SPR_COUNT];
90: public static final boolean[] sprH = new boolean[SPR_COUNT];
91: public static final boolean[] sprV = new boolean[SPR_COUNT];
92: public static final int[] sprF = new int[SPR_COUNT];
93:
94:
95:
96:
97:
98:
99:
100: public static final int[] sprRRmap = new int[1039 << (SPR_SHIFT - 5)];
101:
102:
103:
104:
105: public static final int[] sprPatPort = new int[32 * 4096];
106:
107:
108:
109:
110: public static final int[] sprPPmap = new int[4096 << (SPR_SHIFT - 5)];
111:
112:
113: public static final short[] sprTNum = new short[4096 * 4];
114: public static final short[] sprTColPort = new short[4096 * 4];
115: public static final boolean[] sprTH = new boolean[4096 * 4];
116: public static final boolean[] sprTV = new boolean[4096 * 4];
117:
118: public static final boolean SPR_THREE_STEPS = true;
119: public static int[] sprBuffer;
120: public static int[] sprShadowBuffer;
121:
122:
123:
124:
125:
126:
127:
128: public static boolean sprLatched;
129: public static boolean sprActive;
130:
131:
132: public static final boolean SPR_PATTEST_ON = true;
133: public static final int[] sprPatTest = new int[32 * 4096];
134: public static int[] sprPatCurr;
135: public static final short[] sprNumTest = new short[SPR_COUNT];
136: public static short[] sprNumCurr;
137: public static final short[] sprColTest = new short[SPR_COUNT];
138: public static short[] sprColCurr;
139: public static final short[] sprTColTest = new short[4096 * 4];
140: public static short[] sprTColCurr;
141:
142:
143: public static int sprSpritesPerRaster;
144:
145:
146: public static int sprNumberOfSpritesRequest;
147: public static int sprNumberOfSprites;
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: public static boolean sprBankOnRequest;
220: public static boolean sprBankOn;
221: public static int sprBankMode;
222: public static boolean sprBankShifted;
223: public static int sprBankNumber;
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234: public static boolean spr768x512Request;
235: public static boolean spr768x512;
236: public static boolean sprAccessible;
237:
238:
239:
240:
241: public static boolean spr512bg1Request;
242: public static boolean spr512bg1;
243:
244:
245: public static final long SPR_WAIT_PATTERN_DISP_0 = XEiJ.TMR_FREQ * 215L / 1000000000L;
246: public static final long SPR_WAIT_SPRITE_DISP_0 = XEiJ.TMR_FREQ * 275L / 1000000000L;
247: public static final long SPR_WAIT_SPRITE_DISP_1 = XEiJ.TMR_FREQ * 400L / 1000000000L;
248: public static final long SPR_WAIT_PATTERN_DISP_1 = XEiJ.TMR_FREQ * 465L / 1000000000L;
249: public static long sprWaitSprite;
250: public static long sprWaitPattern;
251:
252:
253:
254:
255: public static final boolean SPR_RC_SCROLL_ON = true;
256: public static boolean sprRcScrollRequest;
257: public static boolean sprRcScrollOn;
258: public static final int[] sprRowScroll = new int[64 * 4];
259: public static final int[] sprColScroll = new int[64 * 4];
260:
261:
262:
263: public static void sprInit () {
264: sprReg0Bg0XPort = 0;
265: sprReg0Bg0XMask = 0;
266: sprReg0Bg0XTest = 0;
267: sprReg0Bg0XCurr = 0;
268: sprReg1Bg0YPort = 0;
269: sprReg1Bg0YMask = 0;
270: sprReg1Bg0YTest = 0;
271: sprReg1Bg0YCurr = 0;
272: sprReg2Bg1XPort = 0;
273: sprReg2Bg1XMask = 0;
274: sprReg2Bg1XTest = 0;
275: sprReg2Bg1XCurr = 0;
276: sprReg3Bg1YPort = 0;
277: sprReg3Bg1YMask = 0;
278: sprReg3Bg1YTest = 0;
279: sprReg3Bg1YCurr = 0;
280: sprReg4BgCtrlPort = 0;
281: sprReg4BgCtrlMask = 0;
282: sprReg4BgCtrlTest = 0;
283: sprReg4BgCtrlCurr = 0;
284: sprReg5HFrontEndPort = 0;
285: sprReg5HFrontEndMask = 0;
286: sprReg5HFrontEndTest = 0;
287: sprReg5HFrontEndCurr = 0;
288: sprReg6HBackEndPort = 0;
289: sprReg6HBackEndMask = 0;
290: sprReg6HBackEndTest = 0;
291: sprReg6HBackEndCurr = 0;
292: sprReg7VBackEndPort = 0;
293: sprReg7VBackEndMask = 0;
294: sprReg7VBackEndTest = 0;
295: sprReg7VBackEndCurr = 0;
296: sprReg8ResoPort = 0;
297: sprReg8ResoMask = 0;
298: sprReg8ResoTest = 0;
299: sprReg8ResoCurr = 0;
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315: if (SPR_THREE_STEPS) {
316: sprBuffer = new int[1056 * 3];
317: sprShadowBuffer = new int[1056 * 3];
318: }
319:
320:
321:
322: if (SPR_PATTEST_ON) {
323:
324:
325: Arrays.fill (sprPatTest, 0x00000000);
326: for (int i = 0; i < 4 * 4096; i++) {
327:
328: if ((i & 3) == 0) {
329: sprPatTest[8 * i ] = 0b1111 * 0x11000000;
330: sprPatTest[8 * i + 1] = 0b1111 * 0x10000000;
331: } else if ((i & 3) == 1) {
332: sprPatTest[8 * i ] = 0b1111 * 0x10000000;
333: sprPatTest[8 * i + 1] = 0b1111 * 0x11000000;
334: } else if ((i & 3) == 2) {
335: sprPatTest[8 * i ] = 0b1111 * 0x11000000;
336: sprPatTest[8 * i + 1] = 0b1111 * 0x01000000;
337: } else {
338: sprPatTest[8 * i ] = 0b1111 * 0x01000000;
339: sprPatTest[8 * i + 1] = 0b1111 * 0x11000000;
340: }
341: if (4 <= i) {
342:
343: int t = i >> (2 + 8);
344: if (t != 0) {
345: t = Indicator.IND_ASCII_3X5[(((9 - t) >> 4) & ('A' - '0' - 10)) + '0' + t];
346: sprPatTest[8 * i ] |= 0b1010 * VideoController.VCN_TXP0[((t >> (12 - 4)) & 0b00010000) |
347: ((t >> ( 9 - 3)) & 0b00001000) |
348: ((t >> ( 6 - 2)) & 0b00000100) |
349: ((t >> ( 3 - 1)) & 0b00000010) |
350: ((t >> ( 0 - 0)) & 0b00000001)];
351: sprPatTest[8 * i + 1] |= 0b1010 * VideoController.VCN_TXP0[((t >> (13 - 4)) & 0b00010000) |
352: ((t >> (10 - 3)) & 0b00001000) |
353: ((t >> ( 7 - 2)) & 0b00000100) |
354: ((t >> ( 4 - 1)) & 0b00000010) |
355: ((t >> ( 1 - 0)) & 0b00000001)];
356: sprPatTest[8 * i + 2] |= 0b1010 * VideoController.VCN_TXP0[((t >> (14 - 4)) & 0b00010000) |
357: ((t >> (11 - 3)) & 0b00001000) |
358: ((t >> ( 8 - 2)) & 0b00000100) |
359: ((t >> ( 5 - 1)) & 0b00000010) |
360: ((t >> ( 2 - 0)) & 0b00000001)];
361: }
362:
363: t = (i >> (2 + 4)) & 15;
364: t = Indicator.IND_ASCII_3X5[(((9 - t) >> 4) & ('A' - '0' - 10)) + '0' + t];
365: sprPatTest[8 * i + 3] = 0b1100 * VideoController.VCN_TXP0[(t >> (12 - 5)) & 0b11100000];
366: sprPatTest[8 * i + 4] = 0b1100 * VideoController.VCN_TXP0[(t >> ( 9 - 5)) & 0b11100000];
367: sprPatTest[8 * i + 5] = 0b1100 * VideoController.VCN_TXP0[(t >> ( 6 - 5)) & 0b11100000];
368: sprPatTest[8 * i + 6] = 0b1100 * VideoController.VCN_TXP0[(t << ( 5 - 3)) & 0b11100000];
369: sprPatTest[8 * i + 7] = 0b1100 * VideoController.VCN_TXP0[(t << ( 5 - 0)) & 0b11100000];
370:
371: t = (i >> 2) & 15;
372: t = Indicator.IND_ASCII_3X5[(((9 - t) >> 4) & ('A' - '0' - 10)) + '0' + t];
373: sprPatTest[8 * i + 3] |= 0b1001 * VideoController.VCN_TXP0[(t >> (12 - 1)) & 0b00001110];
374: sprPatTest[8 * i + 4] |= 0b1001 * VideoController.VCN_TXP0[(t >> ( 9 - 1)) & 0b00001110];
375: sprPatTest[8 * i + 5] |= 0b1001 * VideoController.VCN_TXP0[(t >> ( 6 - 1)) & 0b00001110];
376: sprPatTest[8 * i + 6] |= 0b1001 * VideoController.VCN_TXP0[(t >> ( 3 - 1)) & 0b00001110];
377: sprPatTest[8 * i + 7] |= 0b1001 * VideoController.VCN_TXP0[(t << ( 1 - 0)) & 0b00001110];
378: }
379: }
380:
381:
382: for (int i = 0; i < SPR_COUNT; i++) {
383: sprNumTest[i] = (short) i;
384: }
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402: for (int i = 0; i < SPR_COUNT; i++) {
403: sprColTest[i] = (short) ((i < 64 ? 1 + (i >> 4) :
404: i < 128 ? 3 + (i >> 5) :
405: i < 256 ? 5 + (i >> 6) :
406: i < 512 ? 7 + (i >> 7) :
407: 11) << 4);
408: }
409:
410: for (int i = 0; i < 4; i++) {
411: Arrays.fill (sprTColTest,
412: 4096 * i,
413: 4096 * (i + 1),
414: (short) ((12 + i) << 4));
415: }
416: }
417: sprPatCurr = sprPatPort;
418: sprNumCurr = sprNumPort;
419: sprColCurr = sprColPort;
420: sprTColCurr = sprTColPort;
421:
422:
423: sprSpritesPerRaster = Math.max (0, Math.min (1016, Settings.sgsGetInt ("sprras")));
424:
425:
426: {
427: int n = Settings.sgsGetInt ("numspr");
428: n = (n == 128 || n == 256 ? n :
429: n == 504 || n == 1016 ? n + 8 :
430: 128);
431: if (n == 128 && Settings.sgsGetOnOff ("dblspr")) {
432: n = 256;
433: }
434: sprNumberOfSpritesRequest = n;
435: }
436:
437:
438: sprBankOnRequest = Settings.sgsGetOnOff ("sprbank");
439:
440:
441: spr768x512Request = Settings.sgsGetOnOff ("spr768x512");
442:
443:
444: spr512bg1Request = Settings.sgsGetOnOff ("spr512bg1");
445:
446:
447: sprWaitSprite = SPR_WAIT_SPRITE_DISP_0;
448: sprWaitPattern = SPR_WAIT_PATTERN_DISP_0;
449:
450: if (SPR_RC_SCROLL_ON) {
451:
452: sprRcScrollRequest = Settings.sgsGetOnOff ("sprrcscroll");
453:
454:
455: }
456:
457: sprReset ();
458: }
459:
460: public static void sprTini () {
461:
462: Settings.sgsPutInt ("sprras", sprSpritesPerRaster);
463:
464: Settings.sgsPutOnOff ("dblspr", false);
465: Settings.sgsPutInt ("numspr", sprNumberOfSpritesRequest <= 256 ? sprNumberOfSpritesRequest : sprNumberOfSpritesRequest - 8);
466:
467: Settings.sgsPutOnOff ("sprbank", sprBankOnRequest);
468:
469: Settings.sgsPutOnOff ("spr768x512", spr768x512Request);
470:
471: Settings.sgsPutOnOff ("spr512bg1", spr512bg1Request);
472: if (SPR_RC_SCROLL_ON) {
473:
474: Settings.sgsPutOnOff ("sprrcscroll", sprRcScrollRequest);
475: }
476: }
477:
478:
479:
480: public static void sprReset () {
481:
482: sprNumberOfSprites = sprNumberOfSpritesRequest;
483:
484: sprBankOn = sprBankOnRequest;
485: sprBankMode = 0;
486: sprBankShifted = false;
487: sprBankNumber = (0 << 8);
488:
489: spr768x512 = spr768x512Request;
490: sprAccessible = spr768x512;
491:
492: spr512bg1 = spr512bg1Request;
493: if (SPR_RC_SCROLL_ON) {
494:
495: sprRcScrollOn = sprRcScrollRequest;
496: Arrays.fill (sprRowScroll, 0);
497: Arrays.fill (sprColScroll, 0);
498: }
499:
500: Arrays.fill (sprX, (short) 0);
501: Arrays.fill (sprY, (short) 0);
502: Arrays.fill (sprNumPort, (short) 0);
503: Arrays.fill (sprColPort, (short) 0);
504: Arrays.fill (sprPrw, (byte) 0);
505: Arrays.fill (sprH, false);
506: Arrays.fill (sprV, false);
507: Arrays.fill (sprF, 0);
508: Arrays.fill (sprRRmap, 0);
509: Arrays.fill (sprPatPort, 0);
510: Arrays.fill (sprPPmap, 0);
511: Arrays.fill (sprTNum, (short) 0);
512: Arrays.fill (sprTColPort, (short) 0);
513: Arrays.fill (sprTH, false);
514: Arrays.fill (sprTV, false);
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: public static void sprSwap () {
600: int[] t = sprBuffer;
601: sprBuffer = sprShadowBuffer;
602: sprShadowBuffer = t;
603: }
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619: public static void sprStep1 (int src) {
620:
621:
622: Arrays.fill (sprBuffer, 0);
623:
624: src += sprReg7VBackEndCurr - CRTC.crtR06VBackEndCurr;
625: if (src < 0 || 1023 < src) {
626: return;
627: }
628:
629: int hStart = (sprReg6HBackEndCurr - CRTC.crtR02HBackEndCurr - 4) << 3;
630: int width16 = 16 + XEiJ.pnlScreenWidth;
631:
632: int cnt = sprSpritesPerRaster;
633: if (cnt == 0) {
634: return;
635: }
636: for (int i = (16 + src) << (SPR_SHIFT - 5), nn = 0; nn < sprNumberOfSprites; nn += 32) {
637: for (int map = sprRRmap[i++], n = nn; map != 0; map <<= 1, n++) {
638: if (0 <= map) {
639: continue;
640: }
641: int x = hStart + sprX[n];
642: if (x <= 0 || width16 <= x) {
643:
644: if (--cnt == 0) {
645: return;
646: }
647: continue;
648: }
649:
650:
651:
652:
653:
654:
655:
656: int a = (sprNumCurr[n] << 5) + (sprV[n] ? sprY[n] - src - 1 : 16 + src - sprY[n]);
657: int prw = sprPrw[n] << 3;
658: int col = sprColCurr[n] << prw >>> 4;
659: int f = sprF[n];
660: int s, t;
661: if ((t = f | sprPatCurr[a]) != 0) {
662: if (sprH[n]) {
663: if ((s = 15 & t) != 0 && sprBuffer[2112 + 8 + x] >>> prw == 0) {
664: sprBuffer[2112 + 8 + x] = s << prw;
665: sprBuffer[1056 + 8 + x] = col;
666: }
667: if ((s = 15 << 4 & t) != 0 && sprBuffer[2112 + 9 + x] >>> prw == 0) {
668: sprBuffer[2112 + 9 + x] = s >>> 4 << prw;
669: sprBuffer[1056 + 9 + x] = col;
670: }
671: if ((s = 15 << 8 & t) != 0 && sprBuffer[2112 + 10 + x] >>> prw == 0) {
672: sprBuffer[2112 + 10 + x] = s >>> 8 << prw;
673: sprBuffer[1056 + 10 + x] = col;
674: }
675: if ((s = 15 << 12 & t) != 0 && sprBuffer[2112 + 11 + x] >>> prw == 0) {
676: sprBuffer[2112 + 11 + x] = s >>> 12 << prw;
677: sprBuffer[1056 + 11 + x] = col;
678: }
679: if ((s = 15 << 16 & t) != 0 && sprBuffer[2112 + 12 + x] >>> prw == 0) {
680: sprBuffer[2112 + 12 + x] = s >>> 16 << prw;
681: sprBuffer[1056 + 12 + x] = col;
682: }
683: if ((s = 15 << 20 & t) != 0 && sprBuffer[2112 + 13 + x] >>> prw == 0) {
684: sprBuffer[2112 + 13 + x] = s >>> 20 << prw;
685: sprBuffer[1056 + 13 + x] = col;
686: }
687: if ((s = 15 << 24 & t) != 0 && sprBuffer[2112 + 14 + x] >>> prw == 0) {
688: sprBuffer[2112 + 14 + x] = s >>> 24 << prw;
689: sprBuffer[1056 + 14 + x] = col;
690: }
691: if ((s = t >>> 28 ) != 0 && sprBuffer[2112 + 15 + x] >>> prw == 0) {
692: sprBuffer[2112 + 15 + x] = s << prw;
693: sprBuffer[1056 + 15 + x] = col;
694: }
695: } else {
696: if ((s = t >>> 28 ) != 0 && sprBuffer[2112 + x] >>> prw == 0) {
697: sprBuffer[2112 + x] = s << prw;
698: sprBuffer[1056 + x] = col;
699: }
700: if ((s = 15 << 24 & t) != 0 && sprBuffer[2112 + 1 + x] >>> prw == 0) {
701: sprBuffer[2112 + 1 + x] = s >>> 24 << prw;
702: sprBuffer[1056 + 1 + x] = col;
703: }
704: if ((s = 15 << 20 & t) != 0 && sprBuffer[2112 + 2 + x] >>> prw == 0) {
705: sprBuffer[2112 + 2 + x] = s >>> 20 << prw;
706: sprBuffer[1056 + 2 + x] = col;
707: }
708: if ((s = 15 << 16 & t) != 0 && sprBuffer[2112 + 3 + x] >>> prw == 0) {
709: sprBuffer[2112 + 3 + x] = s >>> 16 << prw;
710: sprBuffer[1056 + 3 + x] = col;
711: }
712: if ((s = 15 << 12 & t) != 0 && sprBuffer[2112 + 4 + x] >>> prw == 0) {
713: sprBuffer[2112 + 4 + x] = s >>> 12 << prw;
714: sprBuffer[1056 + 4 + x] = col;
715: }
716: if ((s = 15 << 8 & t) != 0 && sprBuffer[2112 + 5 + x] >>> prw == 0) {
717: sprBuffer[2112 + 5 + x] = s >>> 8 << prw;
718: sprBuffer[1056 + 5 + x] = col;
719: }
720: if ((s = 15 << 4 & t) != 0 && sprBuffer[2112 + 6 + x] >>> prw == 0) {
721: sprBuffer[2112 + 6 + x] = s >>> 4 << prw;
722: sprBuffer[1056 + 6 + x] = col;
723: }
724: if ((s = 15 & t) != 0 && sprBuffer[2112 + 7 + x] >>> prw == 0) {
725: sprBuffer[2112 + 7 + x] = s << prw;
726: sprBuffer[1056 + 7 + x] = col;
727: }
728: }
729: }
730: if ((t = f | sprPatCurr[16 + a]) != 0) {
731: if (sprH[n]) {
732: if ((s = 15 & t) != 0 && sprBuffer[2112 + x] >>> prw == 0) {
733: sprBuffer[2112 + x] = s << prw;
734: sprBuffer[1056 + x] = col;
735: }
736: if ((s = 15 << 4 & t) != 0 && sprBuffer[2112 + 1 + x] >>> prw == 0) {
737: sprBuffer[2112 + 1 + x] = s >>> 4 << prw;
738: sprBuffer[1056 + 1 + x] = col;
739: }
740: if ((s = 15 << 8 & t) != 0 && sprBuffer[2112 + 2 + x] >>> prw == 0) {
741: sprBuffer[2112 + 2 + x] = s >>> 8 << prw;
742: sprBuffer[1056 + 2 + x] = col;
743: }
744: if ((s = 15 << 12 & t) != 0 && sprBuffer[2112 + 3 + x] >>> prw == 0) {
745: sprBuffer[2112 + 3 + x] = s >>> 12 << prw;
746: sprBuffer[1056 + 3 + x] = col;
747: }
748: if ((s = 15 << 16 & t) != 0 && sprBuffer[2112 + 4 + x] >>> prw == 0) {
749: sprBuffer[2112 + 4 + x] = s >>> 16 << prw;
750: sprBuffer[1056 + 4 + x] = col;
751: }
752: if ((s = 15 << 20 & t) != 0 && sprBuffer[2112 + 5 + x] >>> prw == 0) {
753: sprBuffer[2112 + 5 + x] = s >>> 20 << prw;
754: sprBuffer[1056 + 5 + x] = col;
755: }
756: if ((s = 15 << 24 & t) != 0 && sprBuffer[2112 + 6 + x] >>> prw == 0) {
757: sprBuffer[2112 + 6 + x] = s >>> 24 << prw;
758: sprBuffer[1056 + 6 + x] = col;
759: }
760: if ((s = t >>> 28 ) != 0 && sprBuffer[2112 + 7 + x] >>> prw == 0) {
761: sprBuffer[2112 + 7 + x] = s << prw;
762: sprBuffer[1056 + 7 + x] = col;
763: }
764: } else {
765: if ((s = t >>> 28 ) != 0 && sprBuffer[2112 + 8 + x] >>> prw == 0) {
766: sprBuffer[2112 + 8 + x] = s << prw;
767: sprBuffer[1056 + 8 + x] = col;
768: }
769: if ((s = 15 << 24 & t) != 0 && sprBuffer[2112 + 9 + x] >>> prw == 0) {
770: sprBuffer[2112 + 9 + x] = s >>> 24 << prw;
771: sprBuffer[1056 + 9 + x] = col;
772: }
773: if ((s = 15 << 20 & t) != 0 && sprBuffer[2112 + 10 + x] >>> prw == 0) {
774: sprBuffer[2112 + 10 + x] = s >>> 20 << prw;
775: sprBuffer[1056 + 10 + x] = col;
776: }
777: if ((s = 15 << 16 & t) != 0 && sprBuffer[2112 + 11 + x] >>> prw == 0) {
778: sprBuffer[2112 + 11 + x] = s >>> 16 << prw;
779: sprBuffer[1056 + 11 + x] = col;
780: }
781: if ((s = 15 << 12 & t) != 0 && sprBuffer[2112 + 12 + x] >>> prw == 0) {
782: sprBuffer[2112 + 12 + x] = s >>> 12 << prw;
783: sprBuffer[1056 + 12 + x] = col;
784: }
785: if ((s = 15 << 8 & t) != 0 && sprBuffer[2112 + 13 + x] >>> prw == 0) {
786: sprBuffer[2112 + 13 + x] = s >>> 8 << prw;
787: sprBuffer[1056 + 13 + x] = col;
788: }
789: if ((s = 15 << 4 & t) != 0 && sprBuffer[2112 + 14 + x] >>> prw == 0) {
790: sprBuffer[2112 + 14 + x] = s >>> 4 << prw;
791: sprBuffer[1056 + 14 + x] = col;
792: }
793: if ((s = 15 & t) != 0 && sprBuffer[2112 + 15 + x] >>> prw == 0) {
794: sprBuffer[2112 + 15 + x] = s << prw;
795: sprBuffer[1056 + 15 + x] = col;
796: }
797: }
798: }
799: if (--cnt == 0) {
800: return;
801: }
802: }
803: }
804: }
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820: public static void sprStep2 (int src) {
821:
822: src += sprReg7VBackEndCurr - CRTC.crtR06VBackEndCurr;
823: if (src < 0 || 1023 < src) {
824: return;
825: }
826:
827: int hStart = (sprReg6HBackEndCurr - CRTC.crtR02HBackEndCurr - 4) << 3;
828: int width16 = 16 + XEiJ.pnlScreenWidth;
829: if ((sprReg8ResoCurr & 3) == 0) {
830: final short[] tnum = sprTNum, tcol = sprTColCurr;
831: final boolean[] th = sprTH, tv = sprTV;
832: int x, y = 0, sx, sy = 0, y0 = 0;
833:
834:
835: int ofst = (sprReg4BgCtrlCurr << (12 - 1)) & (3 << 12);
836: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
837: y0 = (src + sprReg1Bg0YCurr) & 511;
838: x = 16 + hStart - sprReg0Bg0XCurr - sprRowScroll[y0 >> 3];
839: sx = (((x & 7) - x) >> 3) & 63;
840: x &= 7;
841: } else {
842: x = 16 + hStart - sprReg0Bg0XCurr;
843: y = (src + sprReg1Bg0YCurr) & 511;
844: sx = (((x & 7) - x) >> 3) & 63;
845: sy = ofst + ((y >> 3) << 6);
846: x &= 7;
847: y &= 7;
848: }
849: while (x < width16) {
850: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
851: y = (y0 + sprColScroll[sx]) & 511;
852: sy = ofst + ((y >> 3) << 6);
853: y &= 7;
854: }
855: int t;
856: if ((t = sprPatCurr[tnum[sy + sx] + (tv[sy + sx] ? 7 - y : y)]) != 0) {
857: if (th[sy + sx]) {
858: sprBuffer[2112 + x] |= (t & 15) << 20;
859: sprBuffer[2112 + 1 + x] |= (t >>> 4 & 15) << 20;
860: sprBuffer[2112 + 2 + x] |= (t >>> 8 & 15) << 20;
861: sprBuffer[2112 + 3 + x] |= (t >>> 12 & 15) << 20;
862: sprBuffer[2112 + 4 + x] |= (t >>> 16 & 15) << 20;
863: sprBuffer[2112 + 5 + x] |= (t >>> 20 & 15) << 20;
864: sprBuffer[2112 + 6 + x] |= (t >>> 24 & 15) << 20;
865: sprBuffer[2112 + 7 + x] |= (t >>> 28 ) << 20;
866: } else {
867: sprBuffer[2112 + x] |= (t >>> 28 ) << 20;
868: sprBuffer[2112 + 1 + x] |= (t >>> 24 & 15) << 20;
869: sprBuffer[2112 + 2 + x] |= (t >>> 20 & 15) << 20;
870: sprBuffer[2112 + 3 + x] |= (t >>> 16 & 15) << 20;
871: sprBuffer[2112 + 4 + x] |= (t >>> 12 & 15) << 20;
872: sprBuffer[2112 + 5 + x] |= (t >>> 8 & 15) << 20;
873: sprBuffer[2112 + 6 + x] |= (t >>> 4 & 15) << 20;
874: sprBuffer[2112 + 7 + x] |= (t & 15) << 20;
875: }
876: }
877: if ((t = tcol[sy + sx]) != 0) {
878: t <<= 20 - 4;
879: sprBuffer[1056 + x] |= t;
880: sprBuffer[1056 + 1 + x] |= t;
881: sprBuffer[1056 + 2 + x] |= t;
882: sprBuffer[1056 + 3 + x] |= t;
883: sprBuffer[1056 + 4 + x] |= t;
884: sprBuffer[1056 + 5 + x] |= t;
885: sprBuffer[1056 + 6 + x] |= t;
886: sprBuffer[1056 + 7 + x] |= t;
887: }
888: x += 8;
889: sx = (sx + 1) & 63;
890: }
891:
892:
893: ofst = (sprReg4BgCtrlCurr << (12 - 4)) & (3 << 12);
894: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
895: y0 = (src + sprReg3Bg1YCurr) & 511;
896: x = 16 + hStart - sprReg2Bg1XCurr - sprRowScroll[64 * 1 + (y0 >> 3)];
897: sx = (((x & 7) - x) >> 3) & 63;
898: x &= 7;
899: } else {
900: x = 16 + hStart - sprReg2Bg1XCurr;
901: y = (src + sprReg3Bg1YCurr) & 511;
902: sx = (((x & 7) - x) >> 3) & 63;
903: sy = ofst + ((y >> 3) << 6);
904: x &= 7;
905: y &= 7;
906: }
907: while (x < width16) {
908: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
909: y = (y0 + sprColScroll[64 * 1 + sx]) & 511;
910: sy = ofst + ((y >> 3) << 6);
911: y &= 7;
912: }
913: int t;
914: if ((t = sprPatCurr[tnum[sy + sx] + (tv[sy + sx] ? 7 - y : y)]) != 0) {
915: if (th[sy + sx]) {
916: sprBuffer[2112 + x] |= (t & 15) << 12;
917: sprBuffer[2112 + 1 + x] |= (t >>> 4 & 15) << 12;
918: sprBuffer[2112 + 2 + x] |= (t >>> 8 & 15) << 12;
919: sprBuffer[2112 + 3 + x] |= (t >>> 12 & 15) << 12;
920: sprBuffer[2112 + 4 + x] |= (t >>> 16 & 15) << 12;
921: sprBuffer[2112 + 5 + x] |= (t >>> 20 & 15) << 12;
922: sprBuffer[2112 + 6 + x] |= (t >>> 24 & 15) << 12;
923: sprBuffer[2112 + 7 + x] |= (t >>> 28 ) << 12;
924: } else {
925: sprBuffer[2112 + x] |= (t >>> 28 ) << 12;
926: sprBuffer[2112 + 1 + x] |= (t >>> 24 & 15) << 12;
927: sprBuffer[2112 + 2 + x] |= (t >>> 20 & 15) << 12;
928: sprBuffer[2112 + 3 + x] |= (t >>> 16 & 15) << 12;
929: sprBuffer[2112 + 4 + x] |= (t >>> 12 & 15) << 12;
930: sprBuffer[2112 + 5 + x] |= (t >>> 8 & 15) << 12;
931: sprBuffer[2112 + 6 + x] |= (t >>> 4 & 15) << 12;
932: sprBuffer[2112 + 7 + x] |= (t & 15) << 12;
933: }
934: }
935: if ((t = tcol[sy + sx]) != 0) {
936: t <<= 12 - 4;
937: sprBuffer[1056 + x] |= t;
938: sprBuffer[1056 + 1 + x] |= t;
939: sprBuffer[1056 + 2 + x] |= t;
940: sprBuffer[1056 + 3 + x] |= t;
941: sprBuffer[1056 + 4 + x] |= t;
942: sprBuffer[1056 + 5 + x] |= t;
943: sprBuffer[1056 + 6 + x] |= t;
944: sprBuffer[1056 + 7 + x] |= t;
945: }
946: x += 8;
947: sx = (sx + 1) & 63;
948: }
949: } else {
950: final short[] tnum = sprTNum, tcol = sprTColCurr;
951: final boolean[] th = sprTH, tv = sprTV;
952: int x, y = 0, sx, sy = 0, y0 = 0;
953:
954:
955: int ofst = (sprReg4BgCtrlCurr << (12 - 1)) & (3 << 12);
956: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
957: y0 = (src + sprReg1Bg0YCurr) & 1023;
958: x = 16 + hStart - sprReg0Bg0XCurr - sprRowScroll[y0 >> 4];
959: sx = (((x & 15) - x) >> 4) & 63;
960: x &= 15;
961: } else {
962: x = 16 + hStart - sprReg0Bg0XCurr;
963: y = (src + sprReg1Bg0YCurr) & 1023;
964: sx = (((x & 15) - x) >> 4) & 63;
965: sy = ofst + ((y >> 4) << 6);
966: x &= 15;
967: y &= 15;
968: }
969: while (x < width16) {
970: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
971: y = (y0 + sprColScroll[sx]) & 1023;
972: sy = ofst + ((y >> 4) << 6);
973: y &= 15;
974: }
975: int a = (tnum[sy + sx] << 2) + (tv[sy + sx] ? 15 - y : y);
976: int t;
977: if ((t = sprPatCurr[a]) != 0) {
978: if (th[sy + sx]) {
979: sprBuffer[2112 + 8 + x] |= (t & 15) << 20;
980: sprBuffer[2112 + 9 + x] |= (t >>> 4 & 15) << 20;
981: sprBuffer[2112 + 10 + x] |= (t >>> 8 & 15) << 20;
982: sprBuffer[2112 + 11 + x] |= (t >>> 12 & 15) << 20;
983: sprBuffer[2112 + 12 + x] |= (t >>> 16 & 15) << 20;
984: sprBuffer[2112 + 13 + x] |= (t >>> 20 & 15) << 20;
985: sprBuffer[2112 + 14 + x] |= (t >>> 24 & 15) << 20;
986: sprBuffer[2112 + 15 + x] |= (t >>> 28 ) << 20;
987: } else {
988: sprBuffer[2112 + x] |= (t >>> 28 ) << 20;
989: sprBuffer[2112 + 1 + x] |= (t >>> 24 & 15) << 20;
990: sprBuffer[2112 + 2 + x] |= (t >>> 20 & 15) << 20;
991: sprBuffer[2112 + 3 + x] |= (t >>> 16 & 15) << 20;
992: sprBuffer[2112 + 4 + x] |= (t >>> 12 & 15) << 20;
993: sprBuffer[2112 + 5 + x] |= (t >>> 8 & 15) << 20;
994: sprBuffer[2112 + 6 + x] |= (t >>> 4 & 15) << 20;
995: sprBuffer[2112 + 7 + x] |= (t & 15) << 20;
996: }
997: }
998: if ((t = sprPatCurr[16 + a]) != 0) {
999: if (th[sy + sx]) {
1000: sprBuffer[2112 + x] |= (t & 15) << 20;
1001: sprBuffer[2112 + 1 + x] |= (t >>> 4 & 15) << 20;
1002: sprBuffer[2112 + 2 + x] |= (t >>> 8 & 15) << 20;
1003: sprBuffer[2112 + 3 + x] |= (t >>> 12 & 15) << 20;
1004: sprBuffer[2112 + 4 + x] |= (t >>> 16 & 15) << 20;
1005: sprBuffer[2112 + 5 + x] |= (t >>> 20 & 15) << 20;
1006: sprBuffer[2112 + 6 + x] |= (t >>> 24 & 15) << 20;
1007: sprBuffer[2112 + 7 + x] |= (t >>> 28 ) << 20;
1008: } else {
1009: sprBuffer[2112 + 8 + x] |= (t >>> 28 ) << 20;
1010: sprBuffer[2112 + 9 + x] |= (t >>> 24 & 15) << 20;
1011: sprBuffer[2112 + 10 + x] |= (t >>> 20 & 15) << 20;
1012: sprBuffer[2112 + 11 + x] |= (t >>> 16 & 15) << 20;
1013: sprBuffer[2112 + 12 + x] |= (t >>> 12 & 15) << 20;
1014: sprBuffer[2112 + 13 + x] |= (t >>> 8 & 15) << 20;
1015: sprBuffer[2112 + 14 + x] |= (t >>> 4 & 15) << 20;
1016: sprBuffer[2112 + 15 + x] |= (t & 15) << 20;
1017: }
1018: }
1019: if ((t = tcol[sy + sx]) != 0) {
1020: t <<= 20 - 4;
1021: sprBuffer[1056 + x] |= t;
1022: sprBuffer[1056 + 1 + x] |= t;
1023: sprBuffer[1056 + 2 + x] |= t;
1024: sprBuffer[1056 + 3 + x] |= t;
1025: sprBuffer[1056 + 4 + x] |= t;
1026: sprBuffer[1056 + 5 + x] |= t;
1027: sprBuffer[1056 + 6 + x] |= t;
1028: sprBuffer[1056 + 7 + x] |= t;
1029: sprBuffer[1056 + 8 + x] |= t;
1030: sprBuffer[1056 + 9 + x] |= t;
1031: sprBuffer[1056 + 10 + x] |= t;
1032: sprBuffer[1056 + 11 + x] |= t;
1033: sprBuffer[1056 + 12 + x] |= t;
1034: sprBuffer[1056 + 13 + x] |= t;
1035: sprBuffer[1056 + 14 + x] |= t;
1036: sprBuffer[1056 + 15 + x] |= t;
1037: }
1038: x += 16;
1039: sx = (sx + 1) & 63;
1040: }
1041: if (spr512bg1) {
1042:
1043:
1044: ofst = (sprReg4BgCtrlCurr << (12 - 4)) & (3 << 12);
1045: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
1046: y0 = (src + sprReg3Bg1YCurr) & 1023;
1047: x = 16 + hStart - sprReg2Bg1XCurr - sprRowScroll[64 * 1 + (y0 >> 4)];
1048: sx = (((x & 15) - x) >> 4) & 63;
1049: x &= 15;
1050: } else {
1051: x = 16 + hStart - sprReg2Bg1XCurr;
1052: y = (src + sprReg3Bg1YCurr) & 1023;
1053: sx = (((x & 15) - x) >> 4) & 63;
1054: sy = ofst + ((y >> 4) << 6);
1055: x &= 15;
1056: y &= 15;
1057: }
1058: while (x < width16) {
1059: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
1060: y = (y0 + sprColScroll[64 * 1 + sx]) & 1023;
1061: sy = ofst + ((y >> 4) << 6);
1062: y &= 15;
1063: }
1064: int a = (tnum[sy + sx] << 2) + (tv[sy + sx] ? 15 - y : y);
1065: int t;
1066: if ((t = sprPatCurr[a]) != 0) {
1067: if (th[sy + sx]) {
1068: sprBuffer[2112 + 8 + x] |= (t & 15) << 12;
1069: sprBuffer[2112 + 9 + x] |= (t >>> 4 & 15) << 12;
1070: sprBuffer[2112 + 10 + x] |= (t >>> 8 & 15) << 12;
1071: sprBuffer[2112 + 11 + x] |= (t >>> 12 & 15) << 12;
1072: sprBuffer[2112 + 12 + x] |= (t >>> 16 & 15) << 12;
1073: sprBuffer[2112 + 13 + x] |= (t >>> 20 & 15) << 12;
1074: sprBuffer[2112 + 14 + x] |= (t >>> 24 & 15) << 12;
1075: sprBuffer[2112 + 15 + x] |= (t >>> 28 ) << 12;
1076: } else {
1077: sprBuffer[2112 + x] |= (t >>> 28 ) << 12;
1078: sprBuffer[2112 + 1 + x] |= (t >>> 24 & 15) << 12;
1079: sprBuffer[2112 + 2 + x] |= (t >>> 20 & 15) << 12;
1080: sprBuffer[2112 + 3 + x] |= (t >>> 16 & 15) << 12;
1081: sprBuffer[2112 + 4 + x] |= (t >>> 12 & 15) << 12;
1082: sprBuffer[2112 + 5 + x] |= (t >>> 8 & 15) << 12;
1083: sprBuffer[2112 + 6 + x] |= (t >>> 4 & 15) << 12;
1084: sprBuffer[2112 + 7 + x] |= (t & 15) << 12;
1085: }
1086: }
1087: if ((t = sprPatCurr[16 + a]) != 0) {
1088: if (th[sy + sx]) {
1089: sprBuffer[2112 + x] |= (t & 15) << 12;
1090: sprBuffer[2112 + 1 + x] |= (t >>> 4 & 15) << 12;
1091: sprBuffer[2112 + 2 + x] |= (t >>> 8 & 15) << 12;
1092: sprBuffer[2112 + 3 + x] |= (t >>> 12 & 15) << 12;
1093: sprBuffer[2112 + 4 + x] |= (t >>> 16 & 15) << 12;
1094: sprBuffer[2112 + 5 + x] |= (t >>> 20 & 15) << 12;
1095: sprBuffer[2112 + 6 + x] |= (t >>> 24 & 15) << 12;
1096: sprBuffer[2112 + 7 + x] |= (t >>> 28 ) << 12;
1097: } else {
1098: sprBuffer[2112 + 8 + x] |= (t >>> 28 ) << 12;
1099: sprBuffer[2112 + 9 + x] |= (t >>> 24 & 15) << 12;
1100: sprBuffer[2112 + 10 + x] |= (t >>> 20 & 15) << 12;
1101: sprBuffer[2112 + 11 + x] |= (t >>> 16 & 15) << 12;
1102: sprBuffer[2112 + 12 + x] |= (t >>> 12 & 15) << 12;
1103: sprBuffer[2112 + 13 + x] |= (t >>> 8 & 15) << 12;
1104: sprBuffer[2112 + 14 + x] |= (t >>> 4 & 15) << 12;
1105: sprBuffer[2112 + 15 + x] |= (t & 15) << 12;
1106: }
1107: }
1108: if ((t = tcol[sy + sx]) != 0) {
1109: t <<= 12 - 4;
1110: sprBuffer[1056 + x] |= t;
1111: sprBuffer[1056 + 1 + x] |= t;
1112: sprBuffer[1056 + 2 + x] |= t;
1113: sprBuffer[1056 + 3 + x] |= t;
1114: sprBuffer[1056 + 4 + x] |= t;
1115: sprBuffer[1056 + 5 + x] |= t;
1116: sprBuffer[1056 + 6 + x] |= t;
1117: sprBuffer[1056 + 7 + x] |= t;
1118: sprBuffer[1056 + 8 + x] |= t;
1119: sprBuffer[1056 + 9 + x] |= t;
1120: sprBuffer[1056 + 10 + x] |= t;
1121: sprBuffer[1056 + 11 + x] |= t;
1122: sprBuffer[1056 + 12 + x] |= t;
1123: sprBuffer[1056 + 13 + x] |= t;
1124: sprBuffer[1056 + 14 + x] |= t;
1125: sprBuffer[1056 + 15 + x] |= t;
1126: }
1127: x += 16;
1128: sx = (sx + 1) & 63;
1129: }
1130: }
1131: }
1132: }
1133:
1134:
1135:
1136:
1137:
1138:
1139:
1140:
1141:
1142:
1143:
1144:
1145:
1146:
1147:
1148:
1149:
1150:
1151: public static void sprStep3 () {
1152: int width16 = 16 + XEiJ.pnlScreenWidth;
1153: if (!sprActive ||
1154: (sprReg4BgCtrlCurr & 512) == 0) {
1155: Arrays.fill (sprBuffer, 16, width16, 0);
1156: } else {
1157: int mask = (15 << 24 |
1158: 15 << 16 |
1159: 15 << 8 |
1160: 15 << 20 & -(sprReg4BgCtrlCurr & 1) |
1161: 15 << 12 & -(sprReg4BgCtrlCurr & 8));
1162: for (int x = 16; x < width16; x++) {
1163: int l = sprBuffer[2112 + x];
1164: int h = sprBuffer[1056 + x];
1165: if ((l &= mask) != 0) {
1166: int i = Integer.numberOfLeadingZeros (l) & -4;
1167: sprBuffer[x] = h << i >>> 28 << 4 | l << i >>> 28;
1168: } else if ((h &= mask & (15 << 20 | 15 << 12)) != 0) {
1169: int i = Integer.numberOfTrailingZeros (h) & -4;
1170: sprBuffer[x] = (h >> i & 15) << 4 | l >> i & 15;
1171: } else {
1172: sprBuffer[x] = 0;
1173: }
1174: }
1175: }
1176: }
1177:
1178:
1179:
1180:
1181:
1182: public static int sprReadByte (int a) throws M68kException {
1183: return ((a & 1) == 0 ?
1184: sprReadWord (a) >> 8 :
1185: sprReadWord (a & ~1) & 0x00ff);
1186: }
1187:
1188:
1189:
1190: public static int sprReadWord (int a) throws M68kException {
1191: a &= XEiJ.BUS_MOTHER_MASK;
1192: if (a < 0x00eb0800 || (0x00eb0840 <= a && a < 0x00eb4000)) {
1193:
1194:
1195:
1196:
1197:
1198:
1199: if (!sprAccessible) {
1200: return MemoryMappedDevice.MMD_NUL.mmdRwz (a);
1201: }
1202:
1203: XEiJ.mpuClockTime += sprWaitSprite;
1204: int n = (a - 0x00eb0000) >> 3;
1205: if (sprNumberOfSprites <= n) {
1206: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
1207: if (0x00eb2000 <= a && a < 0x00eb20ff) {
1208: return sprRowScroll[(a >> 1) & (64 * 4 - 1)];
1209: } else if (0x00eb2200 <= a && a < 0x00eb22ff) {
1210: return sprColScroll[(a >> 1) & (64 * 4 - 1)];
1211: }
1212: }
1213: return 0xffff;
1214: }
1215:
1216: switch (a & 6) {
1217: case 0:
1218: return sprX[n];
1219: case 2:
1220: return sprY[n];
1221: case 4:
1222: {
1223: int v = sprV[n] ? 0x8000 : 0;
1224: int h = sprH[n] ? 0x4000 : 0;
1225: int col = sprColPort[n] << 4;
1226: int num = sprNumPort[n];
1227: if (sprBankOn) {
1228: if (sprBankMode == 0) {
1229: return (v | h | col | num);
1230: } else if (sprBankMode == 1) {
1231: return (v | h | (num & 0x0300) << 4 | col | (num & 0x00ff));
1232: } else {
1233: return ((num & 0x0f00) << 4 | col | (num & 0x00ff));
1234: }
1235: } else {
1236: return (v | h | col | num);
1237: }
1238: }
1239: default:
1240: if (sprBankOn &&
1241: sprBankMode == 3) {
1242: return ((sprV[n] ? 0x8000 : 0) |
1243: (sprH[n] ? 0x4000 : 0) |
1244: (sprF[n] & 0x0004) |
1245: sprPrw[n]);
1246: } else {
1247: return ((sprF[n] & 0x0004) |
1248: sprPrw[n]);
1249: }
1250: }
1251: } else if (a < 0x00eb4000) {
1252:
1253:
1254:
1255: switch (a) {
1256: case SPR_REG0_BG0_X:
1257: return sprReg0Bg0XPort;
1258: case SPR_REG1_BG0_Y:
1259: return sprReg1Bg0YPort;
1260: case SPR_REG2_BG1_X:
1261: return sprReg2Bg1XPort;
1262: case SPR_REG3_BG1_Y:
1263: return sprReg3Bg1YPort;
1264: case SPR_REG4_BG_CTRL:
1265: return sprReg4BgCtrlPort;
1266: case SPR_REG5_H_FRONT_END:
1267: return sprReg5HFrontEndPort;
1268: case SPR_REG6_H_BACK_END:
1269: return sprReg6HBackEndPort;
1270: case SPR_REG7_V_BACK_END:
1271: return sprReg7VBackEndPort;
1272: case SPR_REG8_RESO:
1273: return sprReg8ResoPort;
1274: case SPR_REG9_BANK_CONTROL:
1275: if (sprBankOn) {
1276: return sprBankMode << 1 | (sprBankShifted ? 1 : 0);
1277: } else {
1278: return 0xffff;
1279: }
1280: case SPR_REG10_BANK_SELECT:
1281: if (sprBankOn) {
1282: return sprBankNumber;
1283: } else {
1284: return 0xffff;
1285: }
1286: }
1287: return 0xffff;
1288: } else if (a < 0x00eb8000) {
1289:
1290:
1291:
1292:
1293:
1294:
1295: if (sprBankOn &&
1296: sprBankShifted) {
1297: if (!sprAccessible) {
1298: return MemoryMappedDevice.MMD_NUL.mmdRwz (a);
1299: }
1300:
1301: XEiJ.mpuClockTime += sprWaitPattern;
1302:
1303: int p = (a >> 1) & 8191;
1304: int v = sprTV[p] ? 0x8000 : 0;
1305: int h = sprTH[p] ? 0x4000 : 0;
1306: int col = sprTColPort[p] << 4;
1307: int num = sprTNum[p] >> 3;
1308: if (sprBankOn) {
1309: if (sprBankMode == 0) {
1310: return (v | h | col | num);
1311: } else if (sprBankMode == 1) {
1312: return (v | h | (num & 0x0300) << 4 | col | (num & 0x00ff));
1313: } else {
1314: return ((num & 0x0f00) << 4 | col | (num & 0x00ff));
1315: }
1316: } else {
1317: return (v | h | col | num);
1318: }
1319: }
1320: return 0xffff;
1321: } else {
1322:
1323:
1324:
1325:
1326:
1327:
1328: if (!sprAccessible) {
1329: return MemoryMappedDevice.MMD_NUL.mmdRwz (a);
1330: }
1331:
1332: XEiJ.mpuClockTime += sprWaitPattern;
1333: if ((sprReg4BgCtrlPort & 0x0400) != 0) {
1334: return 0xffff;
1335: }
1336:
1337: int i = (a >> 2) & 8191;
1338: if (sprBankOn) {
1339: i += sprBankNumber << 5;
1340: }
1341: return ((a & 2) == 0 ?
1342: sprPatPort[i] >>> 16 :
1343: (char) sprPatPort[i]);
1344: }
1345: }
1346:
1347:
1348:
1349: public static int sprReadLong (int a) throws M68kException {
1350: return (sprReadWord (a) << 16 |
1351: sprReadWord (a + 2));
1352: }
1353:
1354:
1355:
1356:
1357:
1358: public static void sprWriteByte (int a, int d) throws M68kException {
1359: a &= XEiJ.BUS_MOTHER_MASK;
1360: if (a < 0x00eb0800 ||
1361: (sprBankOn && sprBankShifted ? 0x00eb4000 : 0x00eb8000) <= a) {
1362: sprWriteWord (a & ~1, d << 8 | (d & 0x00ff));
1363: } else {
1364: if ((a & 1) == 0) {
1365: sprWriteWord (a, d << 8 | (sprReadWord (a) & 0x00ff));
1366: } else {
1367: sprWriteWord (a & ~1, (sprReadWord (a & ~1) & 0xff00) | (d & 0x00ff));
1368: }
1369: }
1370: }
1371:
1372:
1373:
1374: public static void sprWriteWord (int a, int d) throws M68kException {
1375: a &= XEiJ.BUS_MOTHER_MASK;
1376: if (a < 0x00eb0800 || (0x00eb0840 <= a && a < 0x00eb4000)) {
1377:
1378:
1379:
1380:
1381:
1382:
1383:
1384:
1385: if (!sprAccessible) {
1386: MemoryMappedDevice.MMD_NUL.mmdWw (a, d);
1387: return;
1388: }
1389:
1390: XEiJ.mpuClockTime += sprWaitSprite;
1391: int n = (a - 0x00eb0000) >> 3;
1392: if (sprNumberOfSprites <= n) {
1393: if (SPR_RC_SCROLL_ON && sprRcScrollOn) {
1394: if (0x00eb2000 <= a && a < 0x00eb20ff) {
1395: sprRowScroll[(a >> 1) & (64 * 4 - 1)] = d & 1023;
1396: } else if (0x00eb2200 <= a && a < 0x00eb22ff) {
1397: sprColScroll[(a >> 1) & (64 * 4 - 1)] = d & 1023;
1398: }
1399: }
1400: return;
1401: }
1402:
1403: switch (a & 6) {
1404: case 0:
1405: sprX[n] = (short) (d & 1023);
1406: return;
1407: case 2:
1408: d &= 1023;
1409: if (sprY[n] != d) {
1410: int y = sprY[n];
1411: sprY[n] = (short) d;
1412: if (sprPrw[n] != 0) {
1413: int mask = ~(0x80000000 >>> n);
1414: int i = y << (SPR_SHIFT - 5) | n >> 5;
1415: sprRRmap[i ] &= mask;
1416: sprRRmap[i + ( 1 << (SPR_SHIFT - 5))] &= mask;
1417: sprRRmap[i + ( 2 << (SPR_SHIFT - 5))] &= mask;
1418: sprRRmap[i + ( 3 << (SPR_SHIFT - 5))] &= mask;
1419: sprRRmap[i + ( 4 << (SPR_SHIFT - 5))] &= mask;
1420: sprRRmap[i + ( 5 << (SPR_SHIFT - 5))] &= mask;
1421: sprRRmap[i + ( 6 << (SPR_SHIFT - 5))] &= mask;
1422: sprRRmap[i + ( 7 << (SPR_SHIFT - 5))] &= mask;
1423: sprRRmap[i + ( 8 << (SPR_SHIFT - 5))] &= mask;
1424: sprRRmap[i + ( 9 << (SPR_SHIFT - 5))] &= mask;
1425: sprRRmap[i + (10 << (SPR_SHIFT - 5))] &= mask;
1426: sprRRmap[i + (11 << (SPR_SHIFT - 5))] &= mask;
1427: sprRRmap[i + (12 << (SPR_SHIFT - 5))] &= mask;
1428: sprRRmap[i + (13 << (SPR_SHIFT - 5))] &= mask;
1429: sprRRmap[i + (14 << (SPR_SHIFT - 5))] &= mask;
1430: sprRRmap[i + (15 << (SPR_SHIFT - 5))] &= mask;
1431: mask = ~mask;
1432: i = d << (SPR_SHIFT - 5) | n >> 5;
1433: sprRRmap[i ] |= mask;
1434: sprRRmap[i + ( 1 << (SPR_SHIFT - 5))] |= mask;
1435: sprRRmap[i + ( 2 << (SPR_SHIFT - 5))] |= mask;
1436: sprRRmap[i + ( 3 << (SPR_SHIFT - 5))] |= mask;
1437: sprRRmap[i + ( 4 << (SPR_SHIFT - 5))] |= mask;
1438: sprRRmap[i + ( 5 << (SPR_SHIFT - 5))] |= mask;
1439: sprRRmap[i + ( 6 << (SPR_SHIFT - 5))] |= mask;
1440: sprRRmap[i + ( 7 << (SPR_SHIFT - 5))] |= mask;
1441: sprRRmap[i + ( 8 << (SPR_SHIFT - 5))] |= mask;
1442: sprRRmap[i + ( 9 << (SPR_SHIFT - 5))] |= mask;
1443: sprRRmap[i + (10 << (SPR_SHIFT - 5))] |= mask;
1444: sprRRmap[i + (11 << (SPR_SHIFT - 5))] |= mask;
1445: sprRRmap[i + (12 << (SPR_SHIFT - 5))] |= mask;
1446: sprRRmap[i + (13 << (SPR_SHIFT - 5))] |= mask;
1447: sprRRmap[i + (14 << (SPR_SHIFT - 5))] |= mask;
1448: sprRRmap[i + (15 << (SPR_SHIFT - 5))] |= mask;
1449: }
1450: }
1451: return;
1452: case 4:
1453: {
1454: int preNum = sprNumPort[n];
1455: int col = (d & 0x0f00) >> 4;
1456: int num = (d & 0x00ff);
1457: if (sprBankOn) {
1458: if (sprBankMode <= 1) {
1459: sprV[n] = (d & 0x8000) != 0;
1460: sprH[n] = (d & 0x4000) != 0;
1461: if (sprBankMode == 1) {
1462: num |= (d & 0x3000) >> 4;
1463: }
1464: } else {
1465:
1466: if (sprBankMode == 2) {
1467: sprV[n] = false;
1468: sprH[n] = false;
1469: }
1470: num |= (d & 0xf000) >> 4;
1471: }
1472: } else {
1473: sprV[n] = (d & 0x8000) != 0;
1474: sprH[n] = (d & 0x4000) != 0;
1475: }
1476: sprColPort[n] = (short) col;
1477: sprNumPort[n] = (short) num;
1478: if (sprPrw[n] != 0 && preNum != num) {
1479: int mask = 0x80000000 >>> n;
1480: sprPPmap[preNum << (SPR_SHIFT - 5) | n >> 5] &= ~mask;
1481: sprPPmap[num << (SPR_SHIFT - 5) | n >> 5] |= mask;
1482: }
1483: }
1484: return;
1485: default:
1486: {
1487: if (sprBankOn &&
1488: sprBankMode == 3) {
1489:
1490: sprV[n] = (d & 0x8000) != 0;
1491: sprH[n] = (d & 0x4000) != 0;
1492: }
1493: int prePrw = sprPrw[n];
1494: int prw = (d & 0x0003);
1495: sprPrw[n] = (byte) prw;
1496: if (prePrw == 0 && prw != 0) {
1497: int y = sprY[n];
1498: int mask = 0x80000000 >>> n;
1499: int i = y << (SPR_SHIFT - 5) | n >> 5;
1500: sprRRmap[i ] |= mask;
1501: sprRRmap[i + ( 1 << (SPR_SHIFT - 5))] |= mask;
1502: sprRRmap[i + ( 2 << (SPR_SHIFT - 5))] |= mask;
1503: sprRRmap[i + ( 3 << (SPR_SHIFT - 5))] |= mask;
1504: sprRRmap[i + ( 4 << (SPR_SHIFT - 5))] |= mask;
1505: sprRRmap[i + ( 5 << (SPR_SHIFT - 5))] |= mask;
1506: sprRRmap[i + ( 6 << (SPR_SHIFT - 5))] |= mask;
1507: sprRRmap[i + ( 7 << (SPR_SHIFT - 5))] |= mask;
1508: sprRRmap[i + ( 8 << (SPR_SHIFT - 5))] |= mask;
1509: sprRRmap[i + ( 9 << (SPR_SHIFT - 5))] |= mask;
1510: sprRRmap[i + (10 << (SPR_SHIFT - 5))] |= mask;
1511: sprRRmap[i + (11 << (SPR_SHIFT - 5))] |= mask;
1512: sprRRmap[i + (12 << (SPR_SHIFT - 5))] |= mask;
1513: sprRRmap[i + (13 << (SPR_SHIFT - 5))] |= mask;
1514: sprRRmap[i + (14 << (SPR_SHIFT - 5))] |= mask;
1515: sprRRmap[i + (15 << (SPR_SHIFT - 5))] |= mask;
1516: sprPPmap[sprNumPort[n] << (SPR_SHIFT - 5) | n >> 5] |= mask;
1517: } else if (prePrw != 0 && prw == 0) {
1518: int y = sprY[n];
1519: int mask = ~(0x80000000 >>> n);
1520: int i = y << (SPR_SHIFT - 5) | n >> 5;
1521: sprRRmap[i ] &= mask;
1522: sprRRmap[i + ( 1 << (SPR_SHIFT - 5))] &= mask;
1523: sprRRmap[i + ( 2 << (SPR_SHIFT - 5))] &= mask;
1524: sprRRmap[i + ( 3 << (SPR_SHIFT - 5))] &= mask;
1525: sprRRmap[i + ( 4 << (SPR_SHIFT - 5))] &= mask;
1526: sprRRmap[i + ( 5 << (SPR_SHIFT - 5))] &= mask;
1527: sprRRmap[i + ( 6 << (SPR_SHIFT - 5))] &= mask;
1528: sprRRmap[i + ( 7 << (SPR_SHIFT - 5))] &= mask;
1529: sprRRmap[i + ( 8 << (SPR_SHIFT - 5))] &= mask;
1530: sprRRmap[i + ( 9 << (SPR_SHIFT - 5))] &= mask;
1531: sprRRmap[i + (10 << (SPR_SHIFT - 5))] &= mask;
1532: sprRRmap[i + (11 << (SPR_SHIFT - 5))] &= mask;
1533: sprRRmap[i + (12 << (SPR_SHIFT - 5))] &= mask;
1534: sprRRmap[i + (13 << (SPR_SHIFT - 5))] &= mask;
1535: sprRRmap[i + (14 << (SPR_SHIFT - 5))] &= mask;
1536: sprRRmap[i + (15 << (SPR_SHIFT - 5))] &= mask;
1537: sprPPmap[sprNumPort[n] << (SPR_SHIFT - 5) | n >> 5] &= mask;
1538: }
1539: sprF[n] = (d & 0x0004) != 0 ? -1 : 0;
1540: }
1541: return;
1542: }
1543: } else if (a < 0x00eb4000) {
1544:
1545:
1546:
1547:
1548: switch (a) {
1549: case SPR_REG0_BG0_X:
1550: sprReg0Bg0XPort = (d & 1023);
1551: {
1552: int curr = sprReg0Bg0XMask == 0 ? sprReg0Bg0XPort : sprReg0Bg0XTest;
1553: if (sprReg0Bg0XCurr != curr) {
1554: sprReg0Bg0XCurr = curr;
1555: }
1556: }
1557: return;
1558: case SPR_REG1_BG0_Y:
1559: sprReg1Bg0YPort = (d & 1023);
1560: {
1561: int curr = sprReg1Bg0YMask == 0 ? sprReg1Bg0YPort : sprReg1Bg0YTest;
1562: if (sprReg1Bg0YCurr != curr) {
1563: sprReg1Bg0YCurr = curr;
1564: }
1565: }
1566: return;
1567: case SPR_REG2_BG1_X:
1568: sprReg2Bg1XPort = (d & 1023);
1569: {
1570: int curr = sprReg2Bg1XMask == 0 ? sprReg2Bg1XPort : sprReg2Bg1XTest;
1571: if (sprReg2Bg1XCurr != curr) {
1572: sprReg2Bg1XCurr = curr;
1573: }
1574: }
1575: return;
1576: case SPR_REG3_BG1_Y:
1577: sprReg3Bg1YPort = (d & 1023);
1578: {
1579: int curr = sprReg3Bg1YMask == 0 ? sprReg3Bg1YPort : sprReg3Bg1YTest;
1580: if (sprReg3Bg1YCurr != curr) {
1581: sprReg3Bg1YCurr = curr;
1582: }
1583: }
1584: return;
1585: case SPR_REG4_BG_CTRL:
1586: sprReg4BgCtrlPort = (d & 0x063f);
1587: {
1588: int curr = sprReg4BgCtrlPort & ~sprReg4BgCtrlMask | sprReg4BgCtrlTest & sprReg4BgCtrlMask;
1589: if (sprReg4BgCtrlCurr != curr) {
1590: sprReg4BgCtrlCurr = curr;
1591: if ((sprReg4BgCtrlCurr & 512) == 0) {
1592: sprWaitSprite = SPR_WAIT_SPRITE_DISP_0;
1593: sprWaitPattern = SPR_WAIT_PATTERN_DISP_0;
1594: } else {
1595: sprWaitSprite = SPR_WAIT_SPRITE_DISP_1;
1596: sprWaitPattern = SPR_WAIT_PATTERN_DISP_1;
1597: if (SPR_THREE_STEPS) {
1598: sprLatched = true;
1599: }
1600: }
1601: }
1602: }
1603: return;
1604: case SPR_REG5_H_FRONT_END:
1605: sprReg5HFrontEndPort = (d & 255);
1606: {
1607: int curr = sprReg5HFrontEndMask == 0 ? sprReg5HFrontEndPort : sprReg5HFrontEndTest;
1608: if (sprReg5HFrontEndCurr != curr) {
1609: sprReg5HFrontEndCurr = curr;
1610: }
1611: }
1612: return;
1613: case SPR_REG6_H_BACK_END:
1614: sprReg6HBackEndPort = (d & 63);
1615: {
1616: int curr = sprReg6HBackEndMask == 0 ? sprReg6HBackEndPort : sprReg6HBackEndTest;
1617: if (sprReg6HBackEndCurr != curr) {
1618: sprReg6HBackEndCurr = curr;
1619: }
1620: }
1621: return;
1622: case SPR_REG7_V_BACK_END:
1623: sprReg7VBackEndPort = (d & 255);
1624: {
1625: int curr = sprReg7VBackEndMask == 0 ? sprReg7VBackEndPort : sprReg7VBackEndTest;
1626: if (sprReg7VBackEndCurr != curr) {
1627: sprReg7VBackEndCurr = curr;
1628: }
1629: }
1630: return;
1631: case SPR_REG8_RESO:
1632: sprReg8ResoPort = (d & 31);
1633: {
1634: int curr = sprReg8ResoPort & ~sprReg8ResoMask | sprReg8ResoTest & sprReg8ResoMask;
1635: if (sprReg8ResoCurr != curr) {
1636: sprReg8ResoCurr = curr;
1637: CRTC.crtRestart ();
1638: }
1639: }
1640: return;
1641: case SPR_REG9_BANK_CONTROL:
1642: if (sprBankOn) {
1643: sprBankMode = (d & 6) >> 1;
1644: sprBankShifted = (d & 1) != 0;
1645: }
1646: return;
1647: case SPR_REG10_BANK_SELECT:
1648: if (sprBankOn) {
1649: sprBankNumber = (d & (15 << 8));
1650: }
1651: return;
1652: }
1653: return;
1654: } else if (a < 0x00eb8000) {
1655:
1656:
1657:
1658:
1659:
1660:
1661: if (sprBankOn &&
1662: sprBankShifted) {
1663: if (!sprAccessible) {
1664: MemoryMappedDevice.MMD_NUL.mmdWw (a, d);
1665: return;
1666: }
1667:
1668: XEiJ.mpuClockTime += sprWaitPattern;
1669:
1670: boolean v = (d & 0x8000) != 0;
1671: boolean h = (d & 0x4000) != 0;
1672: int col = (d & 0x0f00) >> 4;
1673: int num = (d & 0x00ff);
1674: if (sprBankMode == 0) {
1675: } else if (sprBankMode == 1) {
1676: num |= (d & 0x3000) >> 4;
1677: } else {
1678: v = false;
1679: h = false;
1680: num |= (d & 0xf000) >> 4;
1681: }
1682: int p = (a >> 1) & 8191;
1683: sprTV[p] = v;
1684: sprTH[p] = h;
1685: sprTColPort[p] = (short) col;
1686: sprTNum[p] = (short) (num << 3);
1687: return;
1688: }
1689: return;
1690: } else if (a < 0x00ebc000) {
1691:
1692:
1693:
1694:
1695:
1696:
1697:
1698:
1699: if (!sprAccessible) {
1700: MemoryMappedDevice.MMD_NUL.mmdWw (a, d);
1701: return;
1702: }
1703:
1704: XEiJ.mpuClockTime += sprWaitPattern;
1705: if ((sprReg4BgCtrlPort & 0x0400) != 0) {
1706: return;
1707: }
1708:
1709: int i = ((a >> 2) & 8191);
1710: if (sprBankOn) {
1711: i += sprBankNumber << 5;
1712: }
1713: sprPatPort[i] = ((a & 2) == 0 ?
1714: d << 16 | (char) sprPatPort[i] :
1715: (sprPatPort[i] & 0xffff0000) | (char) d);
1716: return;
1717: } else {
1718:
1719:
1720:
1721:
1722:
1723:
1724:
1725:
1726:
1727:
1728:
1729: if (!sprAccessible) {
1730: MemoryMappedDevice.MMD_NUL.mmdWw (a, d);
1731: return;
1732: }
1733:
1734: XEiJ.mpuClockTime += sprWaitPattern;
1735: if ((sprReg4BgCtrlPort & 0x0400) != 0) {
1736: return;
1737: }
1738:
1739: int i = ((a >> 2) & 8191);
1740: if (sprBankOn) {
1741: i += sprBankNumber << 5;
1742: }
1743: sprPatPort[i] = ((a & 2) == 0 ?
1744: d << 16 | (char) sprPatPort[i] :
1745: (sprPatPort[i] & 0xffff0000) | (char) d);
1746: if (!sprBankOn ||
1747: (!sprBankShifted && sprBankNumber == (0 << 8))) {
1748:
1749: boolean v = (d & 0x8000) != 0;
1750: boolean h = (d & 0x4000) != 0;
1751: int col = (d & 0x0f00) >> 4;
1752: int num = (d & 0x00ff);
1753: if (sprBankOn) {
1754: if (sprBankMode == 0) {
1755: } else if (sprBankMode == 1) {
1756: num |= (d & 0x3000) >> 4;
1757: } else {
1758: v = false;
1759: h = false;
1760: num |= (d & 0xf000) >> 4;
1761: }
1762: }
1763: int p = (a >> 1) & 8191;
1764: sprTV[p] = v;
1765: sprTH[p] = h;
1766: sprTColPort[p] = (short) col;
1767: sprTNum[p] = (short) (num << 3);
1768: return;
1769: }
1770: return;
1771: }
1772: }
1773:
1774:
1775:
1776: public static void sprWriteLong (int a, int d) throws M68kException {
1777: sprWriteWord (a, d >> 16);
1778: sprWriteWord (a + 2, d);
1779: }
1780:
1781:
1782:
1783: }
1784:
1785:
1786: