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