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