comparison sms.c @ 2195:40290a923886

Implement Game Gear start button and region register
author Michael Pavone <pavone@retrodev.com>
date Sun, 21 Aug 2022 22:56:32 -0700
parents 01ff005b08f6
children 2648081f3100
comparison
equal deleted inserted replaced
2194:01ff005b08f6 2195:40290a923886
193 break; 193 break;
194 } 194 }
195 return 1; 195 return 1;
196 } 196 }
197 197
198 static uint8_t gg_io_read(uint32_t location, void *vcontext)
199 {
200 z80_context *z80 = vcontext;
201 sms_context *sms = z80->system;
202 if (!location) {
203 return sms->start_button_region;
204 } else {
205 //TODO: implement link port
206 return 0xFF;
207 }
208 }
209
210 static void *gg_io_write(uint32_t location, void *vcontext, uint8_t value)
211 {
212 //TODO: implement link port
213 return vcontext;
214 }
215
216 static uint8_t psg_pan_read(uint32_t location, void *vcontext)
217 {
218 //TODO: implement PSG pan
219 return 0xFF;
220 }
221
222 static void *psg_pan_write(uint32_t location, void *vcontext, uint8_t value)
223 {
224 //TODO: implement PSG pan
225 return vcontext;
226 }
198 static memmap_chunk io_map[] = { 227 static memmap_chunk io_map[] = {
199 {0x00, 0x40, 0xFF, .write_8 = memory_io_write}, 228 {0x00, 0x40, 0xFF, .write_8 = memory_io_write},
229 {0x40, 0x80, 0xFF, .read_8 = hv_read, .write_8 = sms_psg_write},
230 {0x80, 0xC0, 0xFF, .read_8 = vdp_read, .write_8 = vdp_write},
231 {0xC0, 0x100,0xFF, .read_8 = io_read}
232 };
233
234 static memmap_chunk io_gg[] = {
235 {0x00, 0x07, 0xFF, .read_8 = gg_io_read, .write_8 = gg_io_write},
236 {0x07, 0x08, 0xFF, .read_8 = psg_pan_read, .write_8 = psg_pan_write},
237 {0x08, 0x40, 0xFF, .write_8 = memory_io_write},
200 {0x40, 0x80, 0xFF, .read_8 = hv_read, .write_8 = sms_psg_write}, 238 {0x40, 0x80, 0xFF, .read_8 = hv_read, .write_8 = sms_psg_write},
201 {0x80, 0xC0, 0xFF, .read_8 = vdp_read, .write_8 = vdp_write}, 239 {0x80, 0xC0, 0xFF, .read_8 = vdp_read, .write_8 = vdp_write},
202 {0xC0, 0x100,0xFF, .read_8 = io_read} 240 {0xC0, 0x100,0xFF, .read_8 = io_read}
203 }; 241 };
204 242
541 sms_context *sms = (sms_context *)system; 579 sms_context *sms = (sms_context *)system;
542 if (gamepad_num == GAMEPAD_MAIN_UNIT) { 580 if (gamepad_num == GAMEPAD_MAIN_UNIT) {
543 if (button == MAIN_UNIT_PAUSE) { 581 if (button == MAIN_UNIT_PAUSE) {
544 vdp_pbc_pause(sms->vdp); 582 vdp_pbc_pause(sms->vdp);
545 } 583 }
584 } else if (sms->vdp->type == VDP_GAMEGEAR && gamepad_num == 1 && button == BUTTON_START) {
585 sms->start_button_region &= 0x7F;
546 } else { 586 } else {
547 io_gamepad_down(&sms->io, gamepad_num, button); 587 io_gamepad_down(&sms->io, gamepad_num, button);
548 } 588 }
549 } 589 }
550 590
551 static void gamepad_up(system_header *system, uint8_t gamepad_num, uint8_t button) 591 static void gamepad_up(system_header *system, uint8_t gamepad_num, uint8_t button)
552 { 592 {
553 sms_context *sms = (sms_context *)system; 593 sms_context *sms = (sms_context *)system;
554 io_gamepad_up(&sms->io, gamepad_num, button); 594 if (sms->vdp->type == VDP_GAMEGEAR && gamepad_num == 1 && button == BUTTON_START) {
595 sms->start_button_region |= 0x80;
596 } else {
597 io_gamepad_up(&sms->io, gamepad_num, button);
598 }
555 } 599 }
556 600
557 static void mouse_down(system_header *system, uint8_t mouse_num, uint8_t button) 601 static void mouse_down(system_header *system, uint8_t mouse_num, uint8_t button)
558 { 602 {
559 sms_context *sms = (sms_context *)system; 603 sms_context *sms = (sms_context *)system;
624 memory_map[1] = (memmap_chunk){0xC000, 0x10000, sizeof(sms->ram)-1, 0, 0, .flags = MMAP_READ|MMAP_WRITE|MMAP_CODE, .buffer = sms->ram}; 668 memory_map[1] = (memmap_chunk){0xC000, 0x10000, sizeof(sms->ram)-1, 0, 0, .flags = MMAP_READ|MMAP_WRITE|MMAP_CODE, .buffer = sms->ram};
625 }; 669 };
626 sms->header.info.map = malloc(sizeof(memmap_chunk) * sms->header.info.map_chunks); 670 sms->header.info.map = malloc(sizeof(memmap_chunk) * sms->header.info.map_chunks);
627 memcpy(sms->header.info.map, memory_map, sizeof(memmap_chunk) * sms->header.info.map_chunks); 671 memcpy(sms->header.info.map, memory_map, sizeof(memmap_chunk) * sms->header.info.map_chunks);
628 z80_options *zopts = malloc(sizeof(z80_options)); 672 z80_options *zopts = malloc(sizeof(z80_options));
629 init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_map, 4, 15, 0xFF); 673 uint8_t vdp_type = strcasecmp(media->extension, "gg") ? VDP_GENESIS : VDP_GAMEGEAR;
674 if (vdp_type == VDP_GAMEGEAR) {
675 init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_gg, 6, 15, 0xFF);
676 sms->start_button_region = 0xC0;
677 } else {
678 init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_map, 4, 15, 0xFF);
679 }
630 sms->z80 = init_z80_context(zopts); 680 sms->z80 = init_z80_context(zopts);
631 sms->z80->system = sms; 681 sms->z80->system = sms;
632 sms->z80->Z80_OPTS->gen.debug_cmd_handler = debug_commands; 682 sms->z80->Z80_OPTS->gen.debug_cmd_handler = debug_commands;
633 683
634 sms->rom = media->buffer; 684 sms->rom = media->buffer;
648 sms->psg = malloc(sizeof(psg_context)); 698 sms->psg = malloc(sizeof(psg_context));
649 psg_init(sms->psg, sms->master_clock, 15*16); 699 psg_init(sms->psg, sms->master_clock, 15*16);
650 700
651 set_gain_config(sms); 701 set_gain_config(sms);
652 702
653 sms->vdp = init_vdp_context(0, 0, strcasecmp(media->extension, "gg") ? VDP_GENESIS : VDP_GAMEGEAR); 703 sms->vdp = init_vdp_context(0, 0, vdp_type);
654 sms->vdp->system = &sms->header; 704 sms->vdp->system = &sms->header;
655 705
656 sms->header.info.save_type = SAVE_NONE; 706 sms->header.info.save_type = SAVE_NONE;
657 sms->header.info.name = strdup(media->name); 707 sms->header.info.name = strdup(media->name);
658 708