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