|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #include "sprite.h"
1.1.1.4 root 8: #include "mpu.h"
1.1 root 9: #include <sys/time.h>
10:
1.1.1.5 ! root 11: std::unique_ptr<SpriteDevice> gSprite;
! 12:
1.1 root 13: SpriteDevice::SpriteDevice()
14: {
15: logname = "sprite";
16: devname = "Sprite";
17: devaddr = baseaddr;
18: devlen = 0x010000;
19:
1.1.1.2 root 20: mem.reset(new uint8[4 * 8192]);
1.1 root 21: }
22:
23: SpriteDevice::~SpriteDevice()
24: {
25: }
26:
27: uint64
28: SpriteDevice::Read8(uint32 addr)
29: {
30: if (addr >= 0xeb8000) {
31: return mem[HB(addr - 0xeb8000)];
32: }
33: PANIC("not impl");
34: }
35:
36: uint64
37: SpriteDevice::Read16(uint32 addr)
38: {
1.1.1.4 root 39: // スプライトの Read はレジスタ、VRAM とも 17 ウェイト。
40: // InsideOut p.135
41: gMPU->AddCycle(17);
42:
1.1 root 43: if (addr >= 0xeb8000) {
44: return *(uint16 *)&mem[addr - 0xeb8000];
45: }
46: if (addr < 0xeb0400) {
47: int n = (addr - 0xeb0000) / 8;
48: switch (addr % 8) {
49: case 0:
50: return reg.sprite[n].xpos;
51: case 2:
52: return reg.sprite[n].ypos;
53: case 4:
54: return reg.sprite[n].col;
55: case 6:
56: return reg.sprite[n].prw;
57: }
58: }
59: if (0xeb0800 <= addr && addr < 0xeb0812) {
60: switch (addr) {
61: case 0xeb0800:
62: return reg.bg0x;
63: case 0xeb0802:
64: return reg.bg0y;
65: case 0xeb0804:
66: return reg.bg1x;
67: case 0xeb0806:
68: return reg.bg1y;
69: case 0xeb0808:
70: return reg.bgctrl;
71: case 0xeb080a:
72: return reg.htotal;
73: case 0xeb080c:
74: return reg.hdisp;
75: case 0xeb080e:
76: return reg.vdisp;
77: case 0xeb0810:
78: return reg.res;
79: }
80: }
81:
82: return (uint64)-1;
83: }
84:
85: uint64
86: SpriteDevice::Write8(uint32 addr, uint32 data)
87: {
88: if (addr >= 0xeb8000) {
1.1.1.4 root 89: // スプライト VRAM への書き込み (InsideOut p.135)
90: gMPU->AddCycle(18);
1.1 root 91: mem[HB(addr - 0xeb8000)] = data;
92: return 0;
93: }
1.1.1.4 root 94:
95: // スプライトレジスタへの書き込み (InsideOut p.135)
96: gMPU->AddCycle(20);
97:
1.1 root 98: PANIC("not impl");
99: }
100:
101: uint64
102: SpriteDevice::Write16(uint32 addr, uint32 data)
103: {
104: putlog(2, "Write16 $%06x <- $%04x", addr, data);
105: if (addr >= 0xeb8000) {
106: *(uint16 *)&mem[addr - 0xeb8000] = data;
107: return 0;
108: }
109: if (addr < 0xeb0400) {
110: int n = (addr - 0xeb0000) / 8;
111: switch (addr % 8) {
112: case 0:
113: reg.sprite[n].xpos = data & 0x3ff;
114: break;
115: case 2:
116: reg.sprite[n].ypos = data & 0x3ff;
117: break;
118: case 4:
119: reg.sprite[n].col = data & 0xcfff;
120: break;
121: case 6:
122: reg.sprite[n].prw = data & 0x3;
123: break;
124: }
125: return 0;
126: }
127: if (0xeb0800 <= addr && addr < 0xeb0812) {
128: switch (addr) {
129: case 0xeb0800:
130: reg.bg0x = data & 0x3ff;
131: break;
132: case 0xeb0802:
133: reg.bg0y = data & 0x3ff;
134: break;
135: case 0xeb0804:
136: reg.bg1x = data & 0x3ff;
137: break;
138: case 0xeb0806:
139: reg.bg1y = data & 0x3ff;
140: break;
141: case 0xeb0808:
142: reg.bgctrl = data & 0x23f;
143: break;
144: case 0xeb080a:
145: reg.htotal = data & 0xff;
146: break;
147: case 0xeb080c:
148: reg.hdisp = data & 0x3f;
149: break;
150: case 0xeb080e:
151: reg.vdisp = data & 0xff;
152: break;
153: case 0xeb0810:
154: reg.res = data & 0x1f;
155: break;
156: }
157: return 0;
158: }
159:
160: return (uint64)-1;
161: }
162:
163: uint64
164: SpriteDevice::Peek8(uint32 addr)
165: {
166: if (addr >= 0xeb8000) {
167: return mem[HB(addr - 0xeb8000)];
168: }
169: if (addr < 0xeb0400) {
170: int n = (addr - 0xeb0000) / 8;
171: switch (addr % 8) {
172: case 0:
173: return reg.sprite[n].xpos;
174: case 2:
175: return reg.sprite[n].ypos;
176: case 4:
177: return reg.sprite[n].col;
178: case 6:
179: return reg.sprite[n].prw;
180: }
181: }
182: if (0xeb0800 <= addr && addr < 0xeb0812) {
183: switch (addr) {
184: case 0xeb0800:
185: return reg.bg0x;
186: case 0xeb0802:
187: return reg.bg0y;
188: case 0xeb0804:
189: return reg.bg1x;
190: case 0xeb0806:
191: return reg.bg1y;
192: case 0xeb0808:
193: return reg.bgctrl;
194: case 0xeb080a:
195: return reg.htotal;
196: case 0xeb080c:
197: return reg.hdisp;
198: case 0xeb080e:
199: return reg.vdisp;
200: case 0xeb0810:
201: return reg.res;
202: }
203: }
204:
205: return (uint64)-1;
206: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.