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