src/mess/drivers/scv.c
| r7722 | r7723 | |
| 16 | 16 | static READ8_HANDLER( scv_portb_r ); |
| 17 | 17 | static READ8_HANDLER( scv_portc_r ); |
| 18 | 18 | static WRITE8_HANDLER( scv_portc_w ); |
| 19 | static WRITE8_HANDLER( scv_cart_ram_w ); |
| 19 | 20 | |
| 20 | 21 | |
| 22 | class scv_state |
| 23 | { |
| 24 | public: |
| 25 | static void *alloc(running_machine &machine) { return auto_alloc_clear(&machine, scv_state(machine)); } |
| 26 | |
| 27 | scv_state(running_machine &machine) { } |
| 28 | |
| 29 | UINT8 *vram; |
| 30 | UINT8 porta; |
| 31 | UINT8 portc; |
| 32 | emu_timer *vb_timer; |
| 33 | UINT8 *cart_rom; |
| 34 | UINT32 cart_rom_size; |
| 35 | UINT8 *cart_ram; |
| 36 | UINT32 cart_ram_size; |
| 37 | }; |
| 38 | |
| 39 | |
| 21 | 40 | static UINT8 *scv_vram; |
| 22 | | static UINT8 scv_porta; |
| 23 | | static UINT8 scv_portc; |
| 24 | | static emu_timer *scv_vb_timer; |
| 25 | 41 | |
| 26 | 42 | |
| 27 | 43 | static ADDRESS_MAP_START( scv_mem, ADDRESS_SPACE_PROGRAM, 8 ) |
| r7722 | r7723 | |
| 31 | 47 | |
| 32 | 48 | AM_RANGE( 0x3600, 0x3600 ) AM_DEVWRITE( "upd1771c", upd1771_w ) |
| 33 | 49 | |
| 34 | | AM_RANGE( 0x8000, 0xff7f ) AM_ROM AM_REGION("cart", 0) |
| 50 | AM_RANGE( 0x8000, 0x9fff ) AM_ROMBANK("bank0") |
| 51 | AM_RANGE( 0xa000, 0xbfff ) AM_ROMBANK("bank1") |
| 52 | AM_RANGE( 0xc000, 0xdfff ) AM_ROMBANK("bank2") |
| 53 | AM_RANGE( 0xe000, 0xff7f ) AM_READ_BANK("bank3") AM_WRITE( scv_cart_ram_w ) |
| 35 | 54 | AM_RANGE( 0xff80, 0xffff ) AM_RAM /* upd7801 internal RAM */ |
| 36 | 55 | ADDRESS_MAP_END |
| 37 | 56 | |
| r7722 | r7723 | |
| 129 | 148 | INPUT_PORTS_END |
| 130 | 149 | |
| 131 | 150 | |
| 151 | static WRITE8_HANDLER( scv_cart_ram_w ) |
| 152 | { |
| 153 | scv_state *state = (scv_state *)space->machine->driver_data; |
| 154 | |
| 155 | /* Check if cartridge ram is available and enabled */ |
| 156 | if ( state->cart_ram && state->cart_ram_size && ( state->portc & 0x20 ) ) |
| 157 | { |
| 158 | state->cart_ram[offset] = data; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | |
| 132 | 163 | static WRITE8_HANDLER( scv_porta_w ) |
| 133 | 164 | { |
| 134 | | scv_porta = data; |
| 165 | scv_state *state = (scv_state *)space->machine->driver_data; |
| 166 | |
| 167 | state->porta = data; |
| 135 | 168 | } |
| 136 | 169 | |
| 137 | 170 | |
| 138 | 171 | static READ8_HANDLER( scv_portb_r ) |
| 139 | 172 | { |
| 173 | scv_state *state = (scv_state *)space->machine->driver_data; |
| 140 | 174 | UINT8 data = 0xff; |
| 141 | 175 | |
| 142 | | if ( ! ( scv_porta & 0x01 ) ) |
| 176 | if ( ! ( state->porta & 0x01 ) ) |
| 143 | 177 | data &= input_port_read( space->machine, "PA0" ); |
| 144 | 178 | |
| 145 | | if ( ! ( scv_porta & 0x02 ) ) |
| 179 | if ( ! ( state->porta & 0x02 ) ) |
| 146 | 180 | data &= input_port_read( space->machine, "PA1" ); |
| 147 | 181 | |
| 148 | | if ( ! ( scv_porta & 0x04 ) ) |
| 182 | if ( ! ( state->porta & 0x04 ) ) |
| 149 | 183 | data &= input_port_read( space->machine, "PA2" ); |
| 150 | 184 | |
| 151 | | if ( ! ( scv_porta & 0x08 ) ) |
| 185 | if ( ! ( state->porta & 0x08 ) ) |
| 152 | 186 | data &= input_port_read( space->machine, "PA3" ); |
| 153 | 187 | |
| 154 | | if ( ! ( scv_porta & 0x10 ) ) |
| 188 | if ( ! ( state->porta & 0x10 ) ) |
| 155 | 189 | data &= input_port_read( space->machine, "PA4" ); |
| 156 | 190 | |
| 157 | | if ( ! ( scv_porta & 0x20 ) ) |
| 191 | if ( ! ( state->porta & 0x20 ) ) |
| 158 | 192 | data &= input_port_read( space->machine, "PA5" ); |
| 159 | 193 | |
| 160 | | if ( ! ( scv_porta & 0x40 ) ) |
| 194 | if ( ! ( state->porta & 0x40 ) ) |
| 161 | 195 | data &= input_port_read( space->machine, "PA6" ); |
| 162 | 196 | |
| 163 | | if ( ! ( scv_porta & 0x80 ) ) |
| 197 | if ( ! ( state->porta & 0x80 ) ) |
| 164 | 198 | data &= input_port_read( space->machine, "PA7" ); |
| 165 | 199 | |
| 166 | 200 | return data; |
| r7722 | r7723 | |
| 169 | 203 | |
| 170 | 204 | static READ8_HANDLER( scv_portc_r ) |
| 171 | 205 | { |
| 172 | | UINT8 data = 0xff; |
| 206 | scv_state *state = (scv_state *)space->machine->driver_data; |
| 207 | UINT8 data = state->portc; |
| 173 | 208 | |
| 174 | 209 | data = ( data & 0xfe ) | ( input_port_read( space->machine, "PC0" ) & 0x01 ); |
| 175 | 210 | |
| r7722 | r7723 | |
| 177 | 212 | } |
| 178 | 213 | |
| 179 | 214 | |
| 215 | static void scv_set_banks( running_machine *machine ) |
| 216 | { |
| 217 | scv_state *state = (scv_state *)machine->driver_data; |
| 218 | |
| 219 | switch( state->cart_rom_size ) |
| 220 | { |
| 221 | case 0x2000: |
| 222 | memory_set_bankptr( machine, "bank0", state->cart_rom ); |
| 223 | memory_set_bankptr( machine, "bank1", state->cart_rom ); |
| 224 | memory_set_bankptr( machine, "bank2", state->cart_rom ); |
| 225 | memory_set_bankptr( machine, "bank3", state->cart_rom ); |
| 226 | break; |
| 227 | case 0x4000: |
| 228 | memory_set_bankptr( machine, "bank0", state->cart_rom ); |
| 229 | memory_set_bankptr( machine, "bank1", state->cart_rom + 0x2000 ); |
| 230 | memory_set_bankptr( machine, "bank2", state->cart_rom ); |
| 231 | memory_set_bankptr( machine, "bank3", state->cart_rom + 0x2000 ); |
| 232 | break; |
| 233 | case 0x8000: |
| 234 | memory_set_bankptr( machine, "bank0", state->cart_rom ); |
| 235 | memory_set_bankptr( machine, "bank1", state->cart_rom + 0x2000 ); |
| 236 | memory_set_bankptr( machine, "bank2", state->cart_rom + 0x4000 ); |
| 237 | memory_set_bankptr( machine, "bank3", state->cart_rom + 0x6000 ); |
| 238 | break; |
| 239 | case 0x10000: |
| 240 | case 0x20000: |
| 241 | memory_set_bankptr( machine, "bank0", state->cart_rom + ( ( state->portc & 0x20 ) ? 0x8000 : 0 ) ); |
| 242 | memory_set_bankptr( machine, "bank1", state->cart_rom + ( ( state->portc & 0x20 ) ? 0xa000 : 0x2000 ) ); |
| 243 | memory_set_bankptr( machine, "bank2", state->cart_rom + ( ( state->portc & 0x20 ) ? 0xc000 : 0x4000 ) ); |
| 244 | memory_set_bankptr( machine, "bank3", state->cart_rom + ( ( state->portc & 0x20 ) ? 0xe000 : 0x6000 ) ); |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | /* Check if cartridge RAM is available and should be enabled */ |
| 249 | if ( state->cart_ram && state->cart_ram_size && ( state->portc & 0x20 ) ) |
| 250 | { |
| 251 | memory_set_bankptr( machine, "bank3", state->cart_ram ); |
| 252 | } |
| 253 | |
| 254 | } |
| 255 | |
| 256 | |
| 180 | 257 | static WRITE8_HANDLER( scv_portc_w ) |
| 181 | 258 | { |
| 182 | | scv_portc = data; |
| 259 | scv_state *state = (scv_state *)space->machine->driver_data; |
| 260 | |
| 261 | logerror("%04x: scv_portc_w: data = 0x%02x\n", cpu_get_pc(devtag_get_device(space->machine, "maincpu")), data ); |
| 262 | state->portc = data; |
| 263 | |
| 264 | scv_set_banks( space->machine ); |
| 183 | 265 | } |
| 184 | 266 | |
| 185 | 267 | |
| 268 | static DEVICE_START( scv_cart ) |
| 269 | { |
| 270 | scv_state *state = (scv_state *)device->machine->driver_data; |
| 271 | |
| 272 | state->cart_rom = memory_region( device->machine, "cart" ); |
| 273 | state->cart_rom_size = memory_region_length( device->machine, "cart" ); |
| 274 | state->cart_ram = NULL; |
| 275 | state->cart_ram_size = 0; |
| 276 | |
| 277 | scv_set_banks( device->machine ); |
| 278 | } |
| 279 | |
| 280 | |
| 186 | 281 | static DEVICE_IMAGE_LOAD( scv_cart ) |
| 187 | 282 | { |
| 283 | scv_state *state = (scv_state *)image->machine->driver_data; |
| 188 | 284 | |
| 189 | | UINT8 *cart = memory_region( image->machine, "cart" ); |
| 190 | | int size = image_length( image ); |
| 285 | if ( image_software_entry(image) == NULL ) |
| 286 | { |
| 287 | UINT8 *cart = memory_region( image->machine, "cart" ); |
| 288 | int size = image_length( image ); |
| 191 | 289 | |
| 192 | | if ( size > 0x8000 ) |
| 193 | | { |
| 194 | | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size" ); |
| 195 | | return INIT_FAIL; |
| 290 | if ( size > memory_region_length( image->machine, "cart" ) ) |
| 291 | { |
| 292 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size" ); |
| 293 | return INIT_FAIL; |
| 294 | } |
| 295 | |
| 296 | if ( image_fread( image, cart, size ) != size ) |
| 297 | { |
| 298 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" ); |
| 299 | return INIT_FAIL; |
| 300 | } |
| 301 | |
| 302 | state->cart_rom = cart; |
| 303 | state->cart_rom_size = size; |
| 304 | state->cart_ram = NULL; |
| 305 | state->cart_ram_size = 0; |
| 196 | 306 | } |
| 197 | | |
| 198 | | if ( image_fread( image, cart, size ) != size ) |
| 307 | else |
| 199 | 308 | { |
| 200 | | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" ); |
| 201 | | return INIT_FAIL; |
| 309 | state->cart_rom = image_get_software_region( image, "rom" ); |
| 310 | state->cart_rom_size = image_get_software_region_length( image, "rom" ); |
| 311 | state->cart_ram = image_get_software_region( image, "ram" ); |
| 312 | state->cart_ram_size = image_get_software_region_length( image, "ram" ); |
| 202 | 313 | } |
| 203 | 314 | |
| 315 | scv_set_banks( image->machine ); |
| 316 | |
| 204 | 317 | return INIT_PASS; |
| 205 | 318 | } |
| 206 | 319 | |
| r7722 | r7723 | |
| 229 | 342 | |
| 230 | 343 | static TIMER_CALLBACK( scv_vb_callback ) |
| 231 | 344 | { |
| 345 | scv_state *state = (scv_state *)machine->driver_data; |
| 232 | 346 | int vpos = video_screen_get_vpos(machine->primary_screen); |
| 233 | 347 | |
| 234 | 348 | switch( vpos ) |
| r7722 | r7723 | |
| 241 | 355 | break; |
| 242 | 356 | } |
| 243 | 357 | |
| 244 | | timer_adjust_oneshot( scv_vb_timer, video_screen_get_time_until_pos( machine->primary_screen, ( vpos + 1 ) % 262, 0 ), 0 ); |
| 358 | timer_adjust_oneshot( state->vb_timer, video_screen_get_time_until_pos( machine->primary_screen, ( vpos + 1 ) % 262, 0 ), 0 ); |
| 245 | 359 | } |
| 246 | 360 | |
| 247 | 361 | |
| r7722 | r7723 | |
| 535 | 649 | |
| 536 | 650 | static MACHINE_START( scv ) |
| 537 | 651 | { |
| 538 | | scv_vb_timer = timer_alloc( machine, scv_vb_callback, NULL ); |
| 652 | scv_state *state = (scv_state *)machine->driver_data; |
| 653 | |
| 654 | state->vb_timer = timer_alloc( machine, scv_vb_callback, NULL ); |
| 539 | 655 | } |
| 540 | 656 | |
| 541 | 657 | |
| 542 | 658 | static MACHINE_RESET( scv ) |
| 543 | 659 | { |
| 544 | | timer_adjust_oneshot( scv_vb_timer, video_screen_get_time_until_pos( machine->primary_screen, 0, 0 ), 0 ); |
| 660 | scv_state *state = (scv_state *)machine->driver_data; |
| 661 | |
| 662 | timer_adjust_oneshot( state->vb_timer, video_screen_get_time_until_pos( machine->primary_screen, 0, 0 ), 0 ); |
| 545 | 663 | } |
| 546 | 664 | |
| 547 | 665 | |
| r7722 | r7723 | |
| 569 | 687 | |
| 570 | 688 | |
| 571 | 689 | static MACHINE_DRIVER_START( scv ) |
| 690 | MDRV_DRIVER_DATA( scv_state ) |
| 691 | |
| 572 | 692 | MDRV_CPU_ADD( "maincpu", UPD7801, XTAL_4MHz ) |
| 573 | 693 | MDRV_CPU_PROGRAM_MAP( scv_mem ) |
| 574 | 694 | MDRV_CPU_IO_MAP( scv_io ) |
| r7722 | r7723 | |
| 597 | 717 | MDRV_CARTSLOT_ADD( "cart" ) |
| 598 | 718 | MDRV_CARTSLOT_EXTENSION_LIST( "bin" ) |
| 599 | 719 | MDRV_CARTSLOT_NOT_MANDATORY |
| 720 | MDRV_CARTSLOT_INTERFACE("scv_cart") |
| 721 | MDRV_CARTSLOT_START( scv_cart ) |
| 600 | 722 | MDRV_CARTSLOT_LOAD( scv_cart ) |
| 723 | |
| 724 | /* Software lists */ |
| 725 | MDRV_SOFTWARE_LIST_ADD("scv") |
| 601 | 726 | MACHINE_DRIVER_END |
| 602 | 727 | |
| 603 | 728 | |
| 604 | 729 | static MACHINE_DRIVER_START( scv_pal ) |
| 730 | MDRV_DRIVER_DATA( scv_state ) |
| 731 | |
| 605 | 732 | MDRV_CPU_ADD( "maincpu", UPD7801, 3780000 ) |
| 606 | 733 | MDRV_CPU_PROGRAM_MAP( scv_mem ) |
| 607 | 734 | MDRV_CPU_IO_MAP( scv_io ) |
| r7722 | r7723 | |
| 630 | 757 | MDRV_CARTSLOT_ADD( "cart" ) |
| 631 | 758 | MDRV_CARTSLOT_EXTENSION_LIST( "bin" ) |
| 632 | 759 | MDRV_CARTSLOT_NOT_MANDATORY |
| 760 | MDRV_CARTSLOT_INTERFACE("scv_cart") |
| 761 | MDRV_CARTSLOT_START( scv_cart ) |
| 633 | 762 | MDRV_CARTSLOT_LOAD( scv_cart ) |
| 763 | |
| 764 | /* Software lists */ |
| 765 | MDRV_SOFTWARE_LIST_ADD("scv") |
| 634 | 766 | MACHINE_DRIVER_END |
| 635 | 767 | |
| 636 | 768 | |
| r7722 | r7723 | |
| 641 | 773 | ROM_REGION( 0x400, "charrom", 0 ) |
| 642 | 774 | ROM_LOAD( "epochtv.chr", 0, 0x400, BAD_DUMP CRC(db521533) SHA1(40b4e44838c35191f115437a14f200f052e71509) ) |
| 643 | 775 | |
| 644 | | ROM_REGION( 0x8000, "cart", ROMREGION_ERASEFF ) |
| 776 | ROM_REGION( 0x20000, "cart", ROMREGION_ERASEFF ) |
| 645 | 777 | ROM_END |
| 646 | 778 | |
| 647 | 779 | |
| r7722 | r7723 | |
| 651 | 783 | ROM_REGION( 0x400, "charrom", 0 ) |
| 652 | 784 | ROM_LOAD( "epochtv.chr", 0, 0x400, BAD_DUMP CRC(db521533) SHA1(40b4e44838c35191f115437a14f200f052e71509) ) |
| 653 | 785 | |
| 654 | | ROM_REGION( 0x8000, "cart", ROMREGION_ERASEFF ) |
| 786 | ROM_REGION( 0x20000, "cart", ROMREGION_ERASEFF ) |
| 655 | 787 | ROM_END |
| 656 | 788 | |
| 657 | 789 | |