comparison blastem.c @ 358:9498cfa7f7c8

Make Z80 writes to VDP/PSG not potentially crash the emulator
author Mike Pavone <pavone@retrodev.com>
date Fri, 24 May 2013 00:41:54 -0700
parents fa7ea48be9a9
children b7c3facee762
comparison
equal deleted inserted replaced
357:fa7ea48be9a9 358:9498cfa7f7c8
337 } 337 }
338 338
339 z80_context * z80_vdp_port_write(uint16_t vdp_port, z80_context * context, uint8_t value) 339 z80_context * z80_vdp_port_write(uint16_t vdp_port, z80_context * context, uint8_t value)
340 { 340 {
341 genesis_context * gen = context->system; 341 genesis_context * gen = context->system;
342 vdp_port_write_b(vdp_port, gen->m68k, value); 342 if (vdp_port & 0xE0) {
343 printf("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port);
344 exit(1);
345 }
346 if (vdp_port < 0x10) {
347 //These probably won't currently interact well with the 68K accessing the VDP
348 vdp_run_context(gen->vdp, context->current_cycle * MCLKS_PER_Z80);
349 if (vdp_port < 4) {
350 vdp_data_port_write(gen->vdp, value << 8 | value);
351 } else if (vdp_port < 8) {
352 vdp_control_port_write(gen->vdp, value << 8 | value);
353 } else {
354 printf("Illegal write to HV Counter port %X\n", vdp_port);
355 exit(1);
356 }
357 } else if (vdp_port < 0x18) {
358 psg_run(gen->psg, (context->current_cycle * MCLKS_PER_Z80) / MCLKS_PER_PSG);
359 psg_write(gen->psg, value);
360 } else {
361 //TODO: Implement undocumented test register(s)
362 }
343 return context; 363 return context;
344 } 364 }
345 365
346 uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context) 366 uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context)
347 { 367 {