diff options
author | 2012-08-21 10:41:19 +0000 | |
---|---|---|
committer | 2012-08-21 10:41:19 +0000 | |
commit | 7285b359d259b2ae0fdf85096571c386ec8c991a (patch) | |
tree | a027aff57f1a255f9ec6cfd3b68cabe4b6683998 /src/mess/machine/galaxy.c | |
parent | 67c425e90757876a6716b7867df30c0149912e74 (diff) |
Merge of MESS sources (no whatsnew)
Diffstat (limited to 'src/mess/machine/galaxy.c')
-rw-r--r-- | src/mess/machine/galaxy.c | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/src/mess/machine/galaxy.c b/src/mess/machine/galaxy.c new file mode 100644 index 00000000000..57392644ec6 --- /dev/null +++ b/src/mess/machine/galaxy.c @@ -0,0 +1,214 @@ +/*************************************************************************** + + machine.c + + Functions to emulate general aspects of the machine (RAM, ROM, interrupts, + I/O ports) + +***************************************************************************/ + +#include "emu.h" +#include "cpu/z80/z80.h" +#include "includes/galaxy.h" +#include "imagedev/cassette.h" +#include "machine/ram.h" + +/*************************************************************************** + I/O devices +***************************************************************************/ + +READ8_MEMBER(galaxy_state::galaxy_keyboard_r) +{ + static const char *const keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7" }; + + if (offset == 0) + { + double level = (machine().device<cassette_image_device>(CASSETTE_TAG)->input()); + return (level > 0) ? 0xfe : 0xff; + } + else + { + return ioport(keynames[(offset>>3) & 0x07])->read() & (0x01<<(offset & 0x07)) ? 0xfe : 0xff; + } +} + +WRITE8_MEMBER(galaxy_state::galaxy_latch_w) +{ + double val = (((data >>6) & 1 ) + ((data >> 2) & 1) - 1) * 32000; + m_latch_value = data; + machine().device<cassette_image_device>(CASSETTE_TAG)->output(val); +} + + + +/*************************************************************************** + Interrupts +***************************************************************************/ + +INTERRUPT_GEN( galaxy_interrupt ) +{ + device_set_input_line(device, 0, HOLD_LINE); +} + +static IRQ_CALLBACK ( galaxy_irq_callback ) +{ + galaxy_state *state = device->machine().driver_data<galaxy_state>(); + galaxy_set_timer(device->machine()); + state->m_interrupts_enabled = TRUE; + return 0xff; +} + +/*************************************************************************** + Snapshot files (GAL) +***************************************************************************/ + +#define GALAXY_SNAPSHOT_V1_SIZE 8268 +#define GALAXY_SNAPSHOT_V2_SIZE 8244 + +static void galaxy_setup_snapshot (running_machine &machine, const UINT8 * data, UINT32 size) +{ + device_t *cpu = machine.device("maincpu"); + + switch (size) + { + case GALAXY_SNAPSHOT_V1_SIZE: + cpu_set_reg(cpu, Z80_AF, data[0x00] | data[0x01] << 8); + cpu_set_reg(cpu, Z80_BC, data[0x04] | data[0x05] << 8); + cpu_set_reg(cpu, Z80_DE, data[0x08] | data[0x09] << 8); + cpu_set_reg(cpu, Z80_HL, data[0x0c] | data[0x0d] << 8); + cpu_set_reg(cpu, Z80_IX, data[0x10] | data[0x11] << 8); + cpu_set_reg(cpu, Z80_IY, data[0x14] | data[0x15] << 8); + cpu_set_reg(cpu, Z80_PC, data[0x18] | data[0x19] << 8); + cpu_set_reg(cpu, Z80_SP, data[0x1c] | data[0x1d] << 8); + cpu_set_reg(cpu, Z80_AF2, data[0x20] | data[0x21] << 8); + cpu_set_reg(cpu, Z80_BC2, data[0x24] | data[0x25] << 8); + cpu_set_reg(cpu, Z80_DE2, data[0x28] | data[0x29] << 8); + cpu_set_reg(cpu, Z80_HL2, data[0x2c] | data[0x2d] << 8); + cpu_set_reg(cpu, Z80_IFF1, data[0x30]); + cpu_set_reg(cpu, Z80_IFF2, data[0x34]); + cpu_set_reg(cpu, Z80_HALT, data[0x38]); + cpu_set_reg(cpu, Z80_IM, data[0x3c]); + cpu_set_reg(cpu, Z80_I, data[0x40]); + cpu_set_reg(cpu, Z80_R, (data[0x44] & 0x7f) | (data[0x48] & 0x80)); + + memcpy (machine.device<ram_device>(RAM_TAG)->pointer(), data + 0x084c, (machine.device<ram_device>(RAM_TAG)->size() < 0x1800) ? machine.device<ram_device>(RAM_TAG)->size() : 0x1800); + + break; + case GALAXY_SNAPSHOT_V2_SIZE: + cpu_set_reg(cpu, Z80_AF, data[0x00] | data[0x01] << 8); + cpu_set_reg(cpu, Z80_BC, data[0x02] | data[0x03] << 8); + cpu_set_reg(cpu, Z80_DE, data[0x04] | data[0x05] << 8); + cpu_set_reg(cpu, Z80_HL, data[0x06] | data[0x07] << 8); + cpu_set_reg(cpu, Z80_IX, data[0x08] | data[0x09] << 8); + cpu_set_reg(cpu, Z80_IY, data[0x0a] | data[0x0b] << 8); + cpu_set_reg(cpu, Z80_PC, data[0x0c] | data[0x0d] << 8); + cpu_set_reg(cpu, Z80_SP, data[0x0e] | data[0x0f] << 8); + cpu_set_reg(cpu, Z80_AF2, data[0x10] | data[0x11] << 8); + cpu_set_reg(cpu, Z80_BC2, data[0x12] | data[0x13] << 8); + cpu_set_reg(cpu, Z80_DE2, data[0x14] | data[0x15] << 8); + cpu_set_reg(cpu, Z80_HL2, data[0x16] | data[0x17] << 8); + + cpu_set_reg(cpu, Z80_IFF1, data[0x18] & 0x01); + cpu_set_reg(cpu, Z80_IFF2, (UINT64)0); + + cpu_set_reg(cpu, Z80_HALT, (UINT64)0); + + cpu_set_reg(cpu, Z80_IM, (data[0x18] >> 1) & 0x03); + + cpu_set_reg(cpu, Z80_I, data[0x19]); + cpu_set_reg(cpu, Z80_R, data[0x1a]); + + memcpy (machine.device<ram_device>(RAM_TAG)->pointer(), data + 0x0834, (machine.device<ram_device>(RAM_TAG)->size() < 0x1800) ? machine.device<ram_device>(RAM_TAG)->size() : 0x1800); + + break; + } + + device_set_input_line(cpu, INPUT_LINE_NMI, CLEAR_LINE); + device_set_input_line(cpu, INPUT_LINE_IRQ0, CLEAR_LINE); +} + +SNAPSHOT_LOAD( galaxy ) +{ + UINT8* snapshot_data; + + switch (snapshot_size) + { + case GALAXY_SNAPSHOT_V1_SIZE: + case GALAXY_SNAPSHOT_V2_SIZE: + snapshot_data = auto_alloc_array(image.device().machine(), UINT8, snapshot_size); + break; + default: + return IMAGE_INIT_FAIL; + } + + image.fread( snapshot_data, snapshot_size); + + galaxy_setup_snapshot(image.device().machine(), snapshot_data, snapshot_size); + + return IMAGE_INIT_PASS; +} + + +/*************************************************************************** + Driver Initialization +***************************************************************************/ + +DRIVER_INIT_MEMBER(galaxy_state,galaxy) +{ + address_space *space = machine().device("maincpu")->memory().space(AS_PROGRAM); + space->install_readwrite_bank( 0x2800, 0x2800 + machine().device<ram_device>(RAM_TAG)->size() - 1, "bank1"); + membank("bank1")->set_base(machine().device<ram_device>(RAM_TAG)->pointer()); + + if (machine().device<ram_device>(RAM_TAG)->size() < (6 + 48) * 1024) + { + space->nop_readwrite( 0x2800 + machine().device<ram_device>(RAM_TAG)->size(), 0xffff); + } +} + +/*************************************************************************** + Machine Initialization +***************************************************************************/ + +MACHINE_RESET( galaxy ) +{ + galaxy_state *state = machine.driver_data<galaxy_state>(); + address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM); + + /* ROM 2 enable/disable */ + if (machine.root_device().ioport("ROM2")->read()) { + space->install_read_bank(0x1000, 0x1fff, "bank10"); + } else { + space->nop_read(0x1000, 0x1fff); + } + space->nop_write(0x1000, 0x1fff); + + if (machine.root_device().ioport("ROM2")->read()) + state->membank("bank10")->set_base(machine.root_device().memregion("maincpu")->base() + 0x1000); + + device_set_irq_callback(machine.device("maincpu"), galaxy_irq_callback); + state->m_interrupts_enabled = TRUE; +} + +DRIVER_INIT_MEMBER(galaxy_state,galaxyp) +{ + DRIVER_INIT_CALL(galaxy); +} + +MACHINE_RESET( galaxyp ) +{ + galaxy_state *state = machine.driver_data<galaxy_state>(); + UINT8 *ROM = machine.root_device().memregion("maincpu")->base(); + address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM); + + device_set_irq_callback(machine.device("maincpu"), galaxy_irq_callback); + + ROM[0x0037] = 0x29; + ROM[0x03f9] = 0xcd; + ROM[0x03fa] = 0x00; + ROM[0x03fb] = 0xe0; + + space->install_read_bank(0xe000, 0xefff, "bank11"); + space->nop_write(0xe000, 0xefff); + state->membank("bank11")->set_base(state->memregion("maincpu")->base() + 0xe000); + state->m_interrupts_enabled = TRUE; +} |