| ... | ... |
@@ -37,7 +37,7 @@ SDL_Renderer *gRenderer; |
| 37 | 37 |
SDL_Texture *gTexture; |
| 38 | 38 |
Uint32 *pixels; |
| 39 | 39 |
|
| 40 |
-Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devctrl; |
|
| 40 |
+Device *devconsole, *devscreen, *devmouse, *devkey, *devsprite, *devcontroller; |
|
| 41 | 41 |
|
| 42 | 42 |
#pragma mark - Helpers |
| 43 | 43 |
|
| ... | ... |
@@ -187,12 +187,6 @@ domouse(SDL_Event *event) |
| 187 | 187 |
} |
| 188 | 188 |
} |
| 189 | 189 |
|
| 190 |
-void |
|
| 191 |
-dokey(SDL_Event *event) |
|
| 192 |
-{
|
|
| 193 |
- (void)event; |
|
| 194 |
-} |
|
| 195 |
- |
|
| 196 | 190 |
void |
| 197 | 191 |
doctrl(SDL_Event *event, int z) |
| 198 | 192 |
{
|
| ... | ... |
@@ -209,18 +203,16 @@ doctrl(SDL_Event *event, int z) |
| 209 | 203 |
case SDLK_LEFT: flag = 0x40; break; |
| 210 | 204 |
case SDLK_RIGHT: flag = 0x80; break; |
| 211 | 205 |
} |
| 212 |
- setflag(&devctrl->mem[0], flag, z); |
|
| 206 |
+ setflag(&devcontroller->mem[0], flag, z); |
|
| 213 | 207 |
} |
| 214 | 208 |
|
| 215 | 209 |
#pragma mark - Devices |
| 216 | 210 |
|
| 217 | 211 |
Uint8 |
| 218 |
-consoler(Device *d, Memory *m, Uint8 b) |
|
| 212 |
+defaultrw(Device *d, Memory *m, Uint8 b) |
|
| 219 | 213 |
{
|
| 220 |
- (void)b; |
|
| 221 |
- (void)d; |
|
| 222 | 214 |
(void)m; |
| 223 |
- return 0; |
|
| 215 |
+ return d->mem[b]; |
|
| 224 | 216 |
} |
| 225 | 217 |
|
| 226 | 218 |
Uint8 |
| ... | ... |
@@ -235,7 +227,7 @@ consolew(Device *d, Memory *m, Uint8 b) |
| 235 | 227 |
} |
| 236 | 228 |
|
| 237 | 229 |
Uint8 |
| 238 |
-ppur(Device *d, Memory *m, Uint8 b) |
|
| 230 |
+screenr(Device *d, Memory *m, Uint8 b) |
|
| 239 | 231 |
{
|
| 240 | 232 |
switch(b) {
|
| 241 | 233 |
case 0: return (WIDTH >> 8) & 0xff; |
| ... | ... |
@@ -243,11 +235,12 @@ ppur(Device *d, Memory *m, Uint8 b) |
| 243 | 235 |
case 2: return (HEIGHT >> 8) & 0xff; |
| 244 | 236 |
case 3: return HEIGHT & 0xff; |
| 245 | 237 |
} |
| 238 |
+ (void)m; |
|
| 246 | 239 |
return d->mem[b]; |
| 247 | 240 |
} |
| 248 | 241 |
|
| 249 | 242 |
Uint8 |
| 250 |
-ppuw(Device *d, Memory *m, Uint8 b) |
|
| 243 |
+screenw(Device *d, Memory *m, Uint8 b) |
|
| 251 | 244 |
{
|
| 252 | 245 |
d->mem[d->len++] = b; |
| 253 | 246 |
if(d->len > 5) {
|
| ... | ... |
@@ -259,17 +252,12 @@ ppuw(Device *d, Memory *m, Uint8 b) |
| 259 | 252 |
redraw(pixels); |
| 260 | 253 |
d->len = 0; |
| 261 | 254 |
} |
| 255 |
+ (void)m; |
|
| 262 | 256 |
return 0; |
| 263 | 257 |
} |
| 264 | 258 |
|
| 265 | 259 |
Uint8 |
| 266 |
-ppusr(Device *d, Memory *m, Uint8 b) |
|
| 267 |
-{
|
|
| 268 |
- return 0; |
|
| 269 |
-} |
|
| 270 |
- |
|
| 271 |
-Uint8 |
|
| 272 |
-ppusw(Device *d, Memory *m, Uint8 b) |
|
| 260 |
+spritew(Device *d, Memory *m, Uint8 b) |
|
| 273 | 261 |
{
|
| 274 | 262 |
d->mem[d->len++] = b; |
| 275 | 263 |
if(d->len > 6) {
|
| ... | ... |
@@ -284,50 +272,6 @@ ppusw(Device *d, Memory *m, Uint8 b) |
| 284 | 272 |
return 0; |
| 285 | 273 |
} |
| 286 | 274 |
|
| 287 |
-Uint8 |
|
| 288 |
-mouser(Device *d, Memory *m, Uint8 b) |
|
| 289 |
-{
|
|
| 290 |
- return d->mem[b]; |
|
| 291 |
-} |
|
| 292 |
- |
|
| 293 |
-Uint8 |
|
| 294 |
-mousew(Device *d, Memory *m, Uint8 b) |
|
| 295 |
-{
|
|
| 296 |
- (void)d; |
|
| 297 |
- (void)b; |
|
| 298 |
- return 0; |
|
| 299 |
-} |
|
| 300 |
- |
|
| 301 |
-Uint8 |
|
| 302 |
-keyr(Device *d, Memory *m, Uint8 b) |
|
| 303 |
-{
|
|
| 304 |
- (void)d; |
|
| 305 |
- (void)b; |
|
| 306 |
- return 0; |
|
| 307 |
-} |
|
| 308 |
- |
|
| 309 |
-Uint8 |
|
| 310 |
-keyw(Device *d, Memory *m, Uint8 b) |
|
| 311 |
-{
|
|
| 312 |
- (void)d; |
|
| 313 |
- (void)b; |
|
| 314 |
- return 0; |
|
| 315 |
-} |
|
| 316 |
- |
|
| 317 |
-Uint8 |
|
| 318 |
-ctrlr(Device *d, Memory *m, Uint8 b) |
|
| 319 |
-{
|
|
| 320 |
- return d->mem[b]; |
|
| 321 |
-} |
|
| 322 |
- |
|
| 323 |
-Uint8 |
|
| 324 |
-ctrlw(Device *d, Memory *m, Uint8 b) |
|
| 325 |
-{
|
|
| 326 |
- (void)d; |
|
| 327 |
- (void)b; |
|
| 328 |
- return 0; |
|
| 329 |
-} |
|
| 330 |
- |
|
| 331 | 275 |
#pragma mark - Generics |
| 332 | 276 |
|
| 333 | 277 |
int |
| ... | ... |
@@ -378,12 +322,12 @@ main(int argc, char **argv) |
| 378 | 322 |
if(!init()) |
| 379 | 323 |
return error("Init", "Failed");
|
| 380 | 324 |
|
| 381 |
- devconsole = portuxn(&u, "console", consoler, consolew); |
|
| 382 |
- devscreen = portuxn(&u, "ppu", ppur, ppuw); |
|
| 383 |
- devmouse = portuxn(&u, "mouse", mouser, mousew); |
|
| 384 |
- devkey = portuxn(&u, "key", keyr, keyw); |
|
| 385 |
- devsprite = portuxn(&u, "ppu-sprite", ppusr, ppusw); |
|
| 386 |
- devctrl = portuxn(&u, "ctrl", ctrlr, ctrlw); |
|
| 325 |
+ devconsole = portuxn(&u, "console", defaultrw, consolew); |
|
| 326 |
+ devscreen = portuxn(&u, "screen", screenr, screenw); |
|
| 327 |
+ devsprite = portuxn(&u, "sprite", defaultrw, spritew); |
|
| 328 |
+ devcontroller = portuxn(&u, "controller", defaultrw, defaultrw); |
|
| 329 |
+ devkey = portuxn(&u, "key", defaultrw, consolew); |
|
| 330 |
+ devmouse = portuxn(&u, "mouse", defaultrw, defaultrw); |
|
| 387 | 331 |
|
| 388 | 332 |
start(&u); |
| 389 | 333 |
|
| ... | ... |
@@ -7,8 +7,8 @@ |
| 7 | 7 |
|
| 8 | 8 |
|0100 @RESET |
| 9 | 9 |
|
| 10 |
- #05 =dev/r ( set dev/read to ctrl ) |
|
| 11 |
- #04 =dev/w ( set dev/write to ppu-sprite ) |
|
| 10 |
+ #03 =dev/r ( set dev/read to controller ) |
|
| 11 |
+ #02 =dev/w ( set dev/write to sprite ) |
|
| 12 | 12 |
#0080 =x #0040 =y ( origin ) |
| 13 | 13 |
#01 ,cursor_icn ~x ~y ,putsprite JSR ( draw sprite ) |
| 14 | 14 |
|