From 6a32b2438d3cfacc3aa95274bc52e97b1ce206ee Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 17 May 2018 12:10:24 +1000 Subject: nc: clean up a little, or a lot (nw) --- src/mame/drivers/nc.cpp | 296 +++++++++++++++++++++++------------------------- src/mame/includes/nc.h | 125 +++++++++++++------- src/mame/video/nc.cpp | 73 ++++-------- 3 files changed, 251 insertions(+), 243 deletions(-) diff --git a/src/mame/drivers/nc.cpp b/src/mame/drivers/nc.cpp index 9d4fca3f82d..12bc9a93002 100644 --- a/src/mame/drivers/nc.cpp +++ b/src/mame/drivers/nc.cpp @@ -99,20 +99,21 @@ #include "includes/nc.h" #include "cpu/z80/z80.h" -#include "machine/mc146818.h" /* for NC200 real time clock */ -#include "machine/rp5c01.h" /* for NC100 real time clock */ -#include "machine/upd765.h" /* for NC200 disk drive interface */ -#include "formats/pc_dsk.h" /* for NC200 disk image */ +#include "machine/mc146818.h" // for NC200 real time clock +#include "machine/rp5c01.h" // for NC100 real time clock +#include "machine/upd765.h" // for NC200 disk drive interface +#include "formats/pc_dsk.h" // for NC200 disk image #include "rendlay.h" #include "screen.h" #include "speaker.h" +#define LOG_GENERAL (1U << 0) +#define LOG_DEBUG (1U << 1) -#define VERBOSE 0 -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) +//#define VERBOSE (LOG_GENERAL | LOG_DEBUG) +#include "logmacro.h" -#define NC200_DEBUG 1 -#define LOG_DEBUG(x) do { if (NC200_DEBUG) logerror x; } while (0) +#define LOGDEBUG(...) LOGMASKED(LOG_DEBUG, __VA_ARGS__) /* the serial clock is generated by the nc hardware and connected to the i8251 @@ -277,7 +278,7 @@ void nc_state::nc_update_interrupts() TIMER_CALLBACK_MEMBER(nc_state::nc_keyboard_timer_callback) { - LOG(("keyboard int\n")); + LOG("keyboard int\n"); /* set int */ m_irq_status |= (1<<3); @@ -324,7 +325,7 @@ void nc_state::nc_refresh_memory_bank_config(int bank) membank(bank1)->set_base(ptr); space.nop_write((bank * 0x4000), (bank * 0x4000) + 0x3fff); - LOG(("BANK %d: ROM %d\n",bank,mem_bank)); + LOG("BANK %d: ROM %d\n",bank,mem_bank); } break; @@ -338,7 +339,7 @@ void nc_state::nc_refresh_memory_bank_config(int bank) membank(bank5)->set_base(ptr); space.install_write_bank((bank * 0x4000), (bank * 0x4000) + 0x3fff, nc_bankhandler_w[bank]); - LOG(("BANK %d: RAM\n",bank)); + LOG("BANK %d: RAM\n",bank); } break; @@ -366,7 +367,7 @@ void nc_state::nc_refresh_memory_bank_config(int bank) space.nop_write((bank * 0x4000), (bank * 0x4000) + 0x3fff); } - LOG(("BANK %d: CARD-RAM\n",bank)); + LOG("BANK %d: CARD-RAM\n",bank); } else { @@ -403,20 +404,16 @@ TIMER_DEVICE_CALLBACK_MEMBER(nc_state::dummy_timer_callback) { /* on NC100 on/off button causes a nmi, on nc200 on/off button causes an int */ - switch (m_type) + switch (m_nc_type) { - case NC_TYPE_1xx: - { - LOG(("nmi triggered\n")); - m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE); - } + case NC_TYPE_1xx: + LOG("nmi triggered\n"); + m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE); break; - case NC_TYPE_200: - { - m_irq_status |= (1 << 4); - nc_update_interrupts(); - } + case NC_TYPE_200: + m_irq_status |= (1 << 4); + nc_update_interrupts(); break; } } @@ -434,7 +431,7 @@ TIMER_DEVICE_CALLBACK_MEMBER(nc_state::dummy_timer_callback) -void nc_state::nc_common_init_machine() +void nc_state::machine_reset() { /* setup reset state */ m_display_memory_start = 0; @@ -485,7 +482,7 @@ READ8_MEMBER(nc_state::nc_memory_management_r) WRITE8_MEMBER(nc_state::nc_memory_management_w) { - LOG(("Memory management W: %02x %02x\n",offset,data)); + LOG("Memory management W: %02x %02x\n",offset,data); m_memory_config[offset] = data; nc_refresh_memory_config(); @@ -493,8 +490,8 @@ WRITE8_MEMBER(nc_state::nc_memory_management_w) WRITE8_MEMBER(nc_state::nc_irq_mask_w) { - LOG(("irq mask w: %02x\n", data)); - LOG_DEBUG(("irq mask nc200 w: %02x\n",data & ((1<<4) | (1<<5) | (1<<6) | (1<<7)))); + LOG("irq mask w: %02x\n", data); + LOGDEBUG("irq mask nc200 w: %02x\n",data & ((1<<4) | (1<<5) | (1<<6) | (1<<7))); /* writing mask clears ints that are to be masked? */ m_irq_mask = data; @@ -504,22 +501,8 @@ WRITE8_MEMBER(nc_state::nc_irq_mask_w) WRITE8_MEMBER(nc_state::nc_irq_status_w) { - LOG(("irq status w: %02x\n", data)); - data = data^0x0ff; - - if (m_type == NC_TYPE_200) - { - /* Russell Marks confirms that on the NC200, the key scan interrupt must be explicitly - cleared. It is not automatically cleared when reading 0x0b9 */ - if ((data & (1<<3))!=0) - { - /* set timer to occur again */ - m_keyboard_timer->reset(attotime::from_msec(10)); - - nc_update_interrupts(); - } - } - + LOG("irq status w: %02x\n", data); + data = data ^ 0x0ff; /* writing to status will clear int, will this re-start the key-scan? */ #if 0 @@ -539,6 +522,24 @@ WRITE8_MEMBER(nc_state::nc_irq_status_w) nc_update_interrupts(); } +WRITE8_MEMBER(nc200_state::nc200_irq_status_w) +{ + LOG("irq status w: %02x\n", data); + data = data ^ 0x0ff; + + /* Russell Marks confirms that on the NC200, the key scan interrupt must be explicitly + cleared. It is not automatically cleared when reading 0x0b9 */ + if ((data & (1<<3))!=0) + { + /* set timer to occur again */ + m_keyboard_timer->reset(attotime::from_msec(10)); + + nc_update_interrupts(); + } + + nc_irq_status_w(space, offset, data, mem_mask); +} + READ8_MEMBER(nc_state::nc_irq_status_r) { return ~((m_irq_status & (~m_irq_latch_mask)) | m_irq_latch); @@ -600,7 +601,7 @@ void nc_state::nc_sound_update(int channel) WRITE8_MEMBER(nc_state::nc_sound_w) { - LOG(("sound w: %04x %02x\n", offset, data)); + LOG("sound w: %04x %02x\n", offset, data); switch (offset) { @@ -705,11 +706,11 @@ WRITE8_MEMBER(nc_state::nc100_display_memory_start_w) /* bit 3-0: not used */ m_display_memory_start = (data & 0x0f0)<<(12-4); - LOG(("disp memory w: %04x\n", (int) m_display_memory_start)); + LOG("disp memory w: %04x\n", m_display_memory_start); } -WRITE8_MEMBER(nc_state::nc100_uart_control_w) +WRITE8_MEMBER(nc100_state::nc100_uart_control_w) { nc_uart_control_w(space, offset,data); @@ -723,12 +724,12 @@ WRITE8_MEMBER(nc_state::nc100_uart_control_w) } -WRITE_LINE_MEMBER(nc_state::nc100_tc8521_alarm_callback) +WRITE_LINE_MEMBER(nc100_state::nc100_tc8521_alarm_callback) { // TODO } -WRITE_LINE_MEMBER(nc_state::nc100_txrdy_callback) +WRITE_LINE_MEMBER(nc100_state::nc100_txrdy_callback) { m_irq_latch &= ~(1 << 1); @@ -745,7 +746,7 @@ WRITE_LINE_MEMBER(nc_state::nc100_txrdy_callback) nc_update_interrupts(); } -WRITE_LINE_MEMBER(nc_state::nc100_rxrdy_callback) +WRITE_LINE_MEMBER(nc100_state::nc100_rxrdy_callback) { m_irq_latch &= ~(1<<0); @@ -761,7 +762,7 @@ WRITE_LINE_MEMBER(nc_state::nc100_rxrdy_callback) nc_update_interrupts(); } -WRITE_LINE_MEMBER(nc_state::write_nc100_centronics_ack) +WRITE_LINE_MEMBER(nc100_state::write_nc100_centronics_ack) { m_centronics_ack = state; @@ -779,7 +780,7 @@ WRITE_LINE_MEMBER(nc_state::write_centronics_busy) m_centronics_busy = state; } -void nc_state::machine_reset() +void nc100_state::machine_reset() { /* 256k of rom */ m_membank_rom_mask = 0x0f; @@ -788,42 +789,24 @@ void nc_state::machine_reset() m_membank_card_ram_mask = 0x03f; - nc_common_init_machine(); + nc_state::machine_reset(); /* serial */ m_irq_latch_mask = (1<<0) | (1<<1); } -void nc_state::machine_start() -{ - m_type = NC_TYPE_1xx; - - std::string region_tag; - m_card_ram = memregion(region_tag.assign(m_card->tag()).append(GENERIC_ROM_REGION_TAG).c_str()); - if (m_card_ram) - m_card_size = m_card_ram->bytes(); - else - m_card_size = 0; - /* keyboard timer */ - m_keyboard_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(nc_state::nc_keyboard_timer_callback),this)); - m_keyboard_timer->adjust(attotime::from_msec(10)); - - m_nvram->set_base(m_ram->pointer(), m_ram->size()); -} - - -WRITE8_MEMBER(nc_state::nc100_poweroff_control_w) +WRITE8_MEMBER(nc100_state::nc100_poweroff_control_w) { /* bits 7-1: not used */ /* bit 0: 1 = no effect, 0 = power off */ m_poweroff_control = data; - LOG(("nc poweroff control: %02x\n",data)); + LOG("nc poweroff control: %02x\n",data); } /* nc100 version of card/battery status */ -READ8_MEMBER(nc_state::nc100_card_battery_status_r) +READ8_MEMBER(nc100_state::nc100_card_battery_status_r) { int nc_card_battery_status = 0x0fc; @@ -851,29 +834,29 @@ READ8_MEMBER(nc_state::nc100_card_battery_status_r) return nc_card_battery_status; } -WRITE8_MEMBER(nc_state::nc100_memory_card_wait_state_w) +WRITE8_MEMBER(nc100_state::nc100_memory_card_wait_state_w) { - LOG(("nc100 memory card wait state: %02x\n",data)); + LOG("nc100 memory card wait state: %02x\n",data); } -void nc_state::nc100_io(address_map &map) +void nc100_state::nc100_io(address_map &map) { map.global_mask(0xff); map.unmap_value_high(); - map(0x00, 0x0f).w(this, FUNC(nc_state::nc100_display_memory_start_w)); - map(0x10, 0x13).rw(this, FUNC(nc_state::nc_memory_management_r), FUNC(nc_state::nc_memory_management_w)); - map(0x20, 0x20).w(this, FUNC(nc_state::nc100_memory_card_wait_state_w)); - map(0x30, 0x30).w(this, FUNC(nc_state::nc100_uart_control_w)); + map(0x00, 0x0f).w(this, FUNC(nc100_state::nc100_display_memory_start_w)); + map(0x10, 0x13).rw(this, FUNC(nc100_state::nc_memory_management_r), FUNC(nc100_state::nc_memory_management_w)); + map(0x20, 0x20).w(this, FUNC(nc100_state::nc100_memory_card_wait_state_w)); + map(0x30, 0x30).w(this, FUNC(nc100_state::nc100_uart_control_w)); map(0x40, 0x40).w("cent_data_out", FUNC(output_latch_device::write)); - map(0x50, 0x53).w(this, FUNC(nc_state::nc_sound_w)); - map(0x60, 0x60).w(this, FUNC(nc_state::nc_irq_mask_w)); - map(0x70, 0x70).w(this, FUNC(nc_state::nc100_poweroff_control_w)); - map(0x90, 0x90).rw(this, FUNC(nc_state::nc_irq_status_r), FUNC(nc_state::nc_irq_status_w)); - map(0x91, 0x9f).r(this, FUNC(nc_state::nc_irq_status_r)); - map(0xa0, 0xaf).r(this, FUNC(nc_state::nc100_card_battery_status_r)); - map(0xb0, 0xb9).r(this, FUNC(nc_state::nc_key_data_in_r)); + map(0x50, 0x53).w(this, FUNC(nc100_state::nc_sound_w)); + map(0x60, 0x60).w(this, FUNC(nc100_state::nc_irq_mask_w)); + map(0x70, 0x70).w(this, FUNC(nc100_state::nc100_poweroff_control_w)); + map(0x90, 0x90).rw(this, FUNC(nc100_state::nc_irq_status_r), FUNC(nc100_state::nc_irq_status_w)); + map(0x91, 0x9f).r(this, FUNC(nc100_state::nc_irq_status_r)); + map(0xa0, 0xaf).r(this, FUNC(nc100_state::nc100_card_battery_status_r)); + map(0xb0, 0xb9).r(this, FUNC(nc100_state::nc_key_data_in_r)); map(0xc0, 0xc0).rw(m_uart, FUNC(i8251_device::data_r), FUNC(i8251_device::data_w)); map(0xc1, 0xc1).rw(m_uart, FUNC(i8251_device::status_r), FUNC(i8251_device::control_w)); map(0xd0, 0xdf).rw("rtc", FUNC(tc8521_device::read), FUNC(tc8521_device::write)); @@ -1014,7 +997,7 @@ void nc_state::nc150_init_machine() m_membank_card_ram_mask = 0x03f; - nc_common_init_machine(machine); + nc_state::machine_reset(); } #endif @@ -1024,7 +1007,7 @@ void nc_state::nc150_init_machine() /* NC200 hardware */ #ifdef UNUSED_FUNCTION -WRITE8_MEMBER(nc_state::nc200_display_memory_start_w) +WRITE8_MEMBER(nc200_state::nc200_display_memory_start_w) { /* bit 7: A15 */ /* bit 6: A14 */ @@ -1032,12 +1015,12 @@ WRITE8_MEMBER(nc_state::nc200_display_memory_start_w) /* bit 4-0: not used */ m_display_memory_start = (data & 0x0e0)<<(12-4); - LOG(("disp memory w: %04x\n", (int) m_display_memory_start)); + LOG("disp memory w: %04x\n", m_display_memory_start); } #endif -WRITE_LINE_MEMBER(nc_state::write_nc200_centronics_ack) +WRITE_LINE_MEMBER(nc200_state::write_nc200_centronics_ack) { if (state) m_irq_status |= 0x01; @@ -1051,7 +1034,7 @@ WRITE_LINE_MEMBER(nc_state::write_nc200_centronics_ack) /* assumption. nc200 uses the same uart chip. The rxrdy and txrdy are combined together with a or to generate a single interrupt */ -void nc_state::nc200_refresh_uart_interrupt() +void nc200_state::nc200_refresh_uart_interrupt() { m_irq_latch &=~(1<<2); @@ -1066,7 +1049,7 @@ void nc_state::nc200_refresh_uart_interrupt() nc_update_interrupts(); } -WRITE_LINE_MEMBER(nc_state::nc200_txrdy_callback) +WRITE_LINE_MEMBER(nc200_state::nc200_txrdy_callback) { // m_nc200_uart_interrupt_irq &=~(1<<0); // @@ -1078,7 +1061,7 @@ WRITE_LINE_MEMBER(nc_state::nc200_txrdy_callback) // nc200_refresh_uart_interrupt(); } -WRITE_LINE_MEMBER(nc_state::nc200_rxrdy_callback) +WRITE_LINE_MEMBER(nc200_state::nc200_rxrdy_callback) { m_nc200_uart_interrupt_irq &=~(1<<1); @@ -1090,7 +1073,7 @@ WRITE_LINE_MEMBER(nc_state::nc200_rxrdy_callback) nc200_refresh_uart_interrupt(); } -WRITE_LINE_MEMBER( nc_state::nc200_fdc_interrupt ) +WRITE_LINE_MEMBER(nc200_state::nc200_fdc_interrupt) { #if 0 m_irq_latch &=~(1<<5); @@ -1113,14 +1096,14 @@ WRITE_LINE_MEMBER( nc_state::nc200_fdc_interrupt ) #ifdef UNUSED_FUNCTION void nc_state::nc200_floppy_drive_index_callback(int drive_id) { - LOG_DEBUG(("nc200 index pulse\n")); + LOGDEBUG("nc200 index pulse\n"); // m_irq_status |= (1<<4); // nc_update_interrupts(Machine); } #endif -MACHINE_RESET_MEMBER(nc_state, nc200) +void nc200_state::machine_reset() { /* 512k of rom */ m_membank_rom_mask = 0x1f; @@ -1129,7 +1112,7 @@ MACHINE_RESET_MEMBER(nc_state, nc200) m_membank_card_ram_mask = 0x03f; - nc_common_init_machine(); + nc_state::machine_reset(); m_nc200_uart_interrupt_irq = 0; @@ -1139,10 +1122,8 @@ MACHINE_RESET_MEMBER(nc_state, nc200) nc200_video_set_backlight(0); } -MACHINE_START_MEMBER(nc_state, nc200) +void nc_state::machine_start() { - m_type = NC_TYPE_200; - std::string region_tag; m_card_ram = memregion(region_tag.assign(m_card->tag()).append(GENERIC_ROM_REGION_TAG).c_str()); if (m_card_ram) @@ -1172,7 +1153,7 @@ NC200: /* nc200 version of card/battery status */ -READ8_MEMBER(nc_state::nc200_card_battery_status_r) +READ8_MEMBER(nc200_state::nc200_card_battery_status_r) { int nc_card_battery_status = 0x0ff; @@ -1205,7 +1186,7 @@ READ8_MEMBER(nc_state::nc200_card_battery_status_r) bit 0: Parallel interface BUSY */ -READ8_MEMBER(nc_state::nc200_printer_status_r) +READ8_MEMBER(nc200_state::nc200_printer_status_r) { uint8_t result = 0; @@ -1215,7 +1196,7 @@ READ8_MEMBER(nc_state::nc200_printer_status_r) } -WRITE8_MEMBER(nc_state::nc200_uart_control_w) +WRITE8_MEMBER(nc200_state::nc200_uart_control_w) { /* int reset_fdc = (m_uart_control^data) & (1<<5); */ @@ -1229,7 +1210,7 @@ WRITE8_MEMBER(nc_state::nc200_uart_control_w) } /* bit 5 is used in disk interface */ - LOG_DEBUG(("bit 5: PC: %04x %02x\n", m_maincpu->pc(), data & (1 << 5))); + LOGDEBUG("bit 5: PC: %04x %02x\n", m_maincpu->pc(), data & (1 << 5)); } @@ -1245,10 +1226,10 @@ WRITE8_MEMBER(nc_state::nc200_uart_control_w) /* bit 1: disk motor?? */ /* bit 0: UPD765 Terminal Count input */ -WRITE8_MEMBER(nc_state::nc200_memory_card_wait_state_w) +WRITE8_MEMBER(nc200_state::nc200_memory_card_wait_state_w) { upd765a_device *fdc = machine().device("upd765"); - LOG_DEBUG(("nc200 memory card wait state: PC: %04x %02x\n", m_maincpu->pc(), data)); + LOGDEBUG("nc200 memory card wait state: PC: %04x %02x\n", m_maincpu->pc(), data); #if 0 floppy_drive_set_motor_state(0, 1); floppy_drive_set_ready_state(0, 1, 1); @@ -1259,28 +1240,28 @@ WRITE8_MEMBER(nc_state::nc200_memory_card_wait_state_w) /* bit 2: backlight: 1=off, 0=on */ /* bit 1 cleared to zero in disk code */ /* bit 0 seems to be the same as nc100 */ -WRITE8_MEMBER(nc_state::nc200_poweroff_control_w) +WRITE8_MEMBER(nc200_state::nc200_poweroff_control_w) { - LOG_DEBUG(("nc200 power off: PC: %04x %02x\n", m_maincpu->pc(), data)); + LOGDEBUG("nc200 power off: PC: %04x %02x\n", m_maincpu->pc(), data); nc200_video_set_backlight(((data ^ (1 << 2)) >> 2) & 0x01); } -void nc_state::nc200_io(address_map &map) +void nc200_state::nc200_io(address_map &map) { map.global_mask(0xff); - map(0x00, 0x0f).w(this, FUNC(nc_state::nc100_display_memory_start_w)); - map(0x10, 0x13).rw(this, FUNC(nc_state::nc_memory_management_r), FUNC(nc_state::nc_memory_management_w)); - map(0x20, 0x20).w(this, FUNC(nc_state::nc200_memory_card_wait_state_w)); - map(0x30, 0x30).w(this, FUNC(nc_state::nc200_uart_control_w)); + map(0x00, 0x0f).w(this, FUNC(nc200_state::nc100_display_memory_start_w)); + map(0x10, 0x13).rw(this, FUNC(nc200_state::nc_memory_management_r), FUNC(nc200_state::nc_memory_management_w)); + map(0x20, 0x20).w(this, FUNC(nc200_state::nc200_memory_card_wait_state_w)); + map(0x30, 0x30).w(this, FUNC(nc200_state::nc200_uart_control_w)); map(0x40, 0x40).w("cent_data_out", FUNC(output_latch_device::write)); - map(0x50, 0x53).w(this, FUNC(nc_state::nc_sound_w)); - map(0x60, 0x60).w(this, FUNC(nc_state::nc_irq_mask_w)); - map(0x70, 0x70).w(this, FUNC(nc_state::nc200_poweroff_control_w)); - map(0x80, 0x80).r(this, FUNC(nc_state::nc200_printer_status_r)); - map(0x90, 0x90).rw(this, FUNC(nc_state::nc_irq_status_r), FUNC(nc_state::nc_irq_status_w)); - map(0xa0, 0xa0).r(this, FUNC(nc_state::nc200_card_battery_status_r)); - map(0xb0, 0xb9).r(this, FUNC(nc_state::nc_key_data_in_r)); + map(0x50, 0x53).w(this, FUNC(nc200_state::nc_sound_w)); + map(0x60, 0x60).w(this, FUNC(nc200_state::nc_irq_mask_w)); + map(0x70, 0x70).w(this, FUNC(nc200_state::nc200_poweroff_control_w)); + map(0x80, 0x80).r(this, FUNC(nc200_state::nc200_printer_status_r)); + map(0x90, 0x90).rw(this, FUNC(nc200_state::nc_irq_status_r), FUNC(nc200_state::nc200_irq_status_w)); + map(0xa0, 0xa0).r(this, FUNC(nc200_state::nc200_card_battery_status_r)); + map(0xb0, 0xb9).r(this, FUNC(nc200_state::nc_key_data_in_r)); map(0xc0, 0xc0).rw(m_uart, FUNC(i8251_device::data_r), FUNC(i8251_device::data_w)); map(0xc1, 0xc1).rw(m_uart, FUNC(i8251_device::status_r), FUNC(i8251_device::control_w)); map(0xd0, 0xd1).rw("mc", FUNC(mc146818_device::read), FUNC(mc146818_device::write)); @@ -1399,20 +1380,16 @@ INPUT_PORTS_END /**********************************************************************************************************/ -MACHINE_CONFIG_START(nc_state::nc100) +MACHINE_CONFIG_START(nc_state::nc_base) /* basic machine hardware */ MCFG_DEVICE_ADD("maincpu", Z80, /*6000000*/ 4606000) /* Russell Marks says this is more accurate */ MCFG_DEVICE_PROGRAM_MAP(nc_map) - MCFG_DEVICE_IO_MAP(nc100_io) MCFG_QUANTUM_TIME(attotime::from_hz(60)) /* video hardware */ MCFG_SCREEN_ADD("screen", LCD) MCFG_SCREEN_REFRESH_RATE(50) MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ - MCFG_SCREEN_SIZE(480, 64) - MCFG_SCREEN_VISIBLE_AREA(0, 480-1, 0, 64-1) - MCFG_SCREEN_UPDATE_DRIVER(nc_state, screen_update_nc) MCFG_SCREEN_PALETTE("palette") MCFG_PALETTE_ADD("palette", NC_NUM_COLOURS) @@ -1429,23 +1406,16 @@ MACHINE_CONFIG_START(nc_state::nc100) /* printer */ MCFG_CENTRONICS_ADD("centronics", centronics_devices, "printer") - MCFG_CENTRONICS_ACK_HANDLER(WRITELINE(*this, nc_state, write_nc100_centronics_ack)) MCFG_CENTRONICS_BUSY_HANDLER(WRITELINE(*this, nc_state, write_centronics_busy)) MCFG_CENTRONICS_OUTPUT_LATCH_ADD("cent_data_out", "centronics") /* uart */ MCFG_DEVICE_ADD("uart", I8251, 0) - MCFG_I8251_RXRDY_HANDLER(WRITELINE(*this, nc_state,nc100_rxrdy_callback)) - MCFG_I8251_TXRDY_HANDLER(WRITELINE(*this, nc_state,nc100_txrdy_callback)) MCFG_DEVICE_ADD("uart_clock", CLOCK, 19200) MCFG_CLOCK_SIGNAL_HANDLER(WRITELINE(*this, nc_state, write_uart_clock)) - /* rtc */ - MCFG_DEVICE_ADD("rtc", TC8521, XTAL(32'768)) - MCFG_RP5C01_OUT_ALARM_CB(WRITELINE(*this, nc_state, nc100_tc8521_alarm_callback)) - /* cartridge */ MCFG_GENERIC_CARTSLOT_ADD("cardslot", generic_plain_slot, nullptr) MCFG_GENERIC_LOAD(nc_state, nc_pcmcia_card) @@ -1460,6 +1430,32 @@ MACHINE_CONFIG_START(nc_state::nc100) MCFG_TIMER_DRIVER_ADD_PERIODIC("dummy_timer", nc_state, dummy_timer_callback, attotime::from_hz(50)) MACHINE_CONFIG_END +MACHINE_CONFIG_START(nc100_state::nc100) + nc_base(config); + + MCFG_DEVICE_MODIFY("maincpu") + MCFG_DEVICE_IO_MAP(nc100_io) + + /* video hardware */ + MCFG_SCREEN_MODIFY("screen") + MCFG_SCREEN_SIZE(480, 64) + MCFG_SCREEN_VISIBLE_AREA(0, 480-1, 0, 64-1) + MCFG_SCREEN_UPDATE_DRIVER(nc100_state, screen_update_nc100) + + /* printer */ + MCFG_DEVICE_MODIFY("centronics") + MCFG_CENTRONICS_ACK_HANDLER(WRITELINE(*this, nc100_state, write_nc100_centronics_ack)) + + /* uart */ + MCFG_DEVICE_MODIFY("uart") + MCFG_I8251_RXRDY_HANDLER(WRITELINE(*this, nc100_state, nc100_rxrdy_callback)) + MCFG_I8251_TXRDY_HANDLER(WRITELINE(*this, nc100_state, nc100_txrdy_callback)) + + /* rtc */ + MCFG_DEVICE_ADD("rtc", TC8521, XTAL(32'768)) + MCFG_RP5C01_OUT_ALARM_CB(WRITELINE(*this, nc100_state, nc100_tc8521_alarm_callback)) +MACHINE_CONFIG_END + static const floppy_format_type ibmpc_floppy_formats[] = { FLOPPY_PC_FORMAT, FLOPPY_MFI_FORMAT, @@ -1471,38 +1467,33 @@ static void ibmpc_floppies(device_slot_interface &device) device.option_add("525dd", FLOPPY_525_DD); } -MACHINE_CONFIG_START(nc_state::nc200) - nc100(config); +MACHINE_CONFIG_START(nc200_state::nc200) + nc_base(config); - MCFG_DEVICE_MODIFY( "maincpu" ) + MCFG_DEVICE_MODIFY("maincpu") MCFG_DEVICE_IO_MAP(nc200_io) - MCFG_MACHINE_START_OVERRIDE(nc_state, nc200) - MCFG_MACHINE_RESET_OVERRIDE(nc_state, nc200) - /* video hardware */ MCFG_SCREEN_MODIFY("screen") MCFG_SCREEN_SIZE(NC200_SCREEN_WIDTH, NC200_SCREEN_HEIGHT) MCFG_SCREEN_VISIBLE_AREA(0, NC200_SCREEN_WIDTH-1, 0, NC200_SCREEN_HEIGHT-1) + MCFG_SCREEN_UPDATE_DRIVER(nc200_state, screen_update_nc200) MCFG_PALETTE_MODIFY("palette") MCFG_PALETTE_ENTRIES(NC200_NUM_COLOURS) - MCFG_PALETTE_INIT_OWNER(nc_state, nc) + MCFG_PALETTE_INIT_OWNER(nc200_state, nc) /* printer */ MCFG_DEVICE_MODIFY("centronics") - MCFG_CENTRONICS_ACK_HANDLER(WRITELINE(*this, nc_state, write_nc200_centronics_ack)) + MCFG_CENTRONICS_ACK_HANDLER(WRITELINE(*this, nc200_state, write_nc200_centronics_ack)) /* uart */ MCFG_DEVICE_MODIFY("uart") - MCFG_I8251_RXRDY_HANDLER(WRITELINE(*this, nc_state,nc200_rxrdy_callback)) - MCFG_I8251_TXRDY_HANDLER(WRITELINE(*this, nc_state,nc200_txrdy_callback)) - - /* no rtc */ - MCFG_DEVICE_REMOVE("rtc") + MCFG_I8251_RXRDY_HANDLER(WRITELINE(*this, nc200_state, nc200_rxrdy_callback)) + MCFG_I8251_TXRDY_HANDLER(WRITELINE(*this, nc200_state, nc200_txrdy_callback)) MCFG_UPD765A_ADD("upd765", true, true) - MCFG_UPD765_INTRQ_CALLBACK(WRITELINE(*this, nc_state, nc200_fdc_interrupt)) + MCFG_UPD765_INTRQ_CALLBACK(WRITELINE(*this, nc200_state, nc200_fdc_interrupt)) MCFG_FLOPPY_DRIVE_ADD("upd765:0", ibmpc_floppies, "525dd", ibmpc_floppy_formats) MCFG_FLOPPY_DRIVE_ADD("upd765:1", ibmpc_floppies, "525dd", ibmpc_floppy_formats) @@ -1511,7 +1502,6 @@ MACHINE_CONFIG_START(nc_state::nc200) /* internal ram */ MCFG_RAM_MODIFY(RAM_TAG) MCFG_RAM_DEFAULT_SIZE("128K") - MACHINE_CONFIG_END @@ -1554,8 +1544,8 @@ ROM_START(nc200) ROM_LOAD("nc200.rom", 0x010000, 0x080000, CRC(bb8180e7) SHA1(fb5c93b0a3e199202c6a12548d2617f7a09bae47)) ROM_END -/* YEAR NAME PARENT COMPAT MACHINE INPUT CLASS INIT COMPANY FULLNAME FLAGS */ -COMP( 1992, nc100, 0, 0, nc100, nc100, nc_state, init_nc, "Amstrad plc", "NC100", 0 ) -COMP( 1992, dw225, nc100, 0, nc100, nc100, nc_state, init_nc, "NTS Computer Systems", "DreamWriter 225", 0 ) -COMP( 1992, nc150, nc100, 0, nc100, nc100, nc_state, init_nc, "Amstrad plc", "NC150", 0 ) -COMP( 1993, nc200, 0, 0, nc200, nc200, nc_state, init_nc, "Amstrad plc", "NC200", MACHINE_NOT_WORKING ) // boot hangs while checking the MC146818 UIP (update in progress) bit +// YEAR NAME PARENT COMPAT MACHINE INPUT CLASS INIT COMPANY FULLNAME FLAGS +COMP( 1992, nc100, 0, 0, nc100, nc100, nc100_state, init_nc, "Amstrad plc", "NC100", 0 ) +COMP( 1992, dw225, nc100, 0, nc100, nc100, nc100_state, init_nc, "NTS Computer Systems", "DreamWriter 225", 0 ) +COMP( 1992, nc150, nc100, 0, nc100, nc100, nc100_state, init_nc, "Amstrad plc", "NC150", 0 ) +COMP( 1993, nc200, 0, 0, nc200, nc200, nc200_state, init_nc, "Amstrad plc", "NC200", MACHINE_NOT_WORKING ) // boot hangs while checking the MC146818 UIP (update in progress) bit diff --git a/src/mame/includes/nc.h b/src/mame/includes/nc.h index 39c51be1b2d..985bb7aec0b 100644 --- a/src/mame/includes/nc.h +++ b/src/mame/includes/nc.h @@ -30,17 +30,16 @@ #define NC200_NUM_COLOURS 4 -enum -{ - NC_TYPE_1xx, /* nc100/nc150 */ - NC_TYPE_200 /* nc200 */ -}; - - class nc_state : public driver_device { public: - nc_state(const machine_config &mconfig, device_type type, const char *tag) : + enum nc_type + { + NC_TYPE_1xx, // nc100/nc150 + NC_TYPE_200 // nc200 + }; + + nc_state(const machine_config &mconfig, device_type type, const char *tag, nc_type variant) : driver_device(mconfig, type, tag), m_maincpu(*this, "maincpu"), m_ram(*this, RAM_TAG), @@ -50,7 +49,8 @@ public: m_card(*this, "cardslot"), m_uart(*this, "uart"), m_uart_clock(*this, "uart_clock"), - m_nvram(*this, "nvram") + m_nvram(*this, "nvram"), + m_nc_type(variant) { } @@ -63,57 +63,34 @@ public: DECLARE_WRITE8_MEMBER(nc_sound_w); DECLARE_WRITE8_MEMBER(nc_uart_control_w); DECLARE_WRITE8_MEMBER(nc100_display_memory_start_w); - DECLARE_WRITE8_MEMBER(nc100_uart_control_w); - DECLARE_WRITE8_MEMBER(nc100_poweroff_control_w); - DECLARE_READ8_MEMBER(nc100_card_battery_status_r); - DECLARE_WRITE8_MEMBER(nc100_memory_card_wait_state_w); - DECLARE_READ8_MEMBER(nc200_card_battery_status_r); - DECLARE_READ8_MEMBER(nc200_printer_status_r); - DECLARE_WRITE8_MEMBER(nc200_uart_control_w); - DECLARE_WRITE8_MEMBER(nc200_memory_card_wait_state_w); - DECLARE_WRITE8_MEMBER(nc200_poweroff_control_w); DECLARE_PALETTE_INIT(nc); - DECLARE_MACHINE_START(nc200); - DECLARE_MACHINE_RESET(nc200); - uint32_t screen_update_nc(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); TIMER_CALLBACK_MEMBER(nc_keyboard_timer_callback); TIMER_DEVICE_CALLBACK_MEMBER(dummy_timer_callback); - DECLARE_WRITE_LINE_MEMBER(nc100_tc8521_alarm_callback); - DECLARE_WRITE_LINE_MEMBER(nc100_txrdy_callback); - DECLARE_WRITE_LINE_MEMBER(nc100_rxrdy_callback); DECLARE_WRITE_LINE_MEMBER(write_uart_clock); - DECLARE_WRITE_LINE_MEMBER(write_nc100_centronics_ack); - DECLARE_WRITE_LINE_MEMBER(write_nc200_centronics_ack); DECLARE_WRITE_LINE_MEMBER(write_centronics_busy); - DECLARE_WRITE_LINE_MEMBER(nc200_txrdy_callback); - DECLARE_WRITE_LINE_MEMBER(nc200_rxrdy_callback); - DECLARE_WRITE_LINE_MEMBER(nc200_fdc_interrupt); void init_nc(); DECLARE_DEVICE_IMAGE_LOAD_MEMBER( nc_pcmcia_card ); DECLARE_DEVICE_IMAGE_UNLOAD_MEMBER( nc_pcmcia_card ); - void nc200(machine_config &config); - void nc100(machine_config &config); - void nc100_io(address_map &map); - void nc200_io(address_map &map); - void nc_map(address_map &map); protected: virtual void machine_start() override; virtual void machine_reset() override; virtual void video_start() override; + void nc_base(machine_config &config); + void nc_map(address_map &map); + + uint32_t screen_update_nc(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int height, int width, int const (&pens)[2]); + void nc_update_interrupts(); + private: - void nc200_video_set_backlight(int state); int card_calculate_mask(int size); void set_card_present_state(int state); - void nc_update_interrupts(); void nc_refresh_memory_bank_config(int bank); void nc_refresh_memory_config(); - void nc_common_init_machine(); void nc_sound_update(int channel); - void nc200_refresh_uart_interrupt(); public: // HACK FOR MC6845 required_device m_maincpu; @@ -140,17 +117,83 @@ public: // HACK FOR MC6845 int m_sound_channel_periods[2]; int m_previous_inputport_10_state; int m_previous_alarm_state; - uint8_t m_nc200_uart_interrupt_irq; memory_region *m_card_ram; int m_membank_card_ram_mask; int m_card_size; unsigned long m_display_memory_start; - uint8_t m_type; - int m_nc200_backlight; + const nc_type m_nc_type; int m_centronics_ack; int m_centronics_busy; }; +class nc100_state : public nc_state +{ +public: + nc100_state(const machine_config &mconfig, device_type type, const char *tag) : + nc_state(mconfig, type, tag, NC_TYPE_1xx) + { + } + + void nc100(machine_config &config); + +protected: + DECLARE_WRITE8_MEMBER(nc100_uart_control_w); + DECLARE_WRITE8_MEMBER(nc100_poweroff_control_w); + DECLARE_READ8_MEMBER(nc100_card_battery_status_r); + DECLARE_WRITE8_MEMBER(nc100_memory_card_wait_state_w); + + DECLARE_WRITE_LINE_MEMBER(nc100_tc8521_alarm_callback); + DECLARE_WRITE_LINE_MEMBER(nc100_txrdy_callback); + DECLARE_WRITE_LINE_MEMBER(nc100_rxrdy_callback); + DECLARE_WRITE_LINE_MEMBER(write_nc100_centronics_ack); + + virtual void machine_reset() override; + + void nc100_io(address_map &map); + + uint32_t screen_update_nc100(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); +}; + + + +class nc200_state : public nc_state +{ +public: + nc200_state(const machine_config &mconfig, device_type type, const char *tag) : + nc_state(mconfig, type, tag, NC_TYPE_200) + { + } + + void nc200(machine_config &config); + +protected: + DECLARE_WRITE8_MEMBER(nc200_irq_status_w); + DECLARE_READ8_MEMBER(nc200_card_battery_status_r); + DECLARE_READ8_MEMBER(nc200_printer_status_r); + DECLARE_WRITE8_MEMBER(nc200_uart_control_w); + DECLARE_WRITE8_MEMBER(nc200_memory_card_wait_state_w); + DECLARE_WRITE8_MEMBER(nc200_poweroff_control_w); + + DECLARE_WRITE_LINE_MEMBER(write_nc200_centronics_ack); + DECLARE_WRITE_LINE_MEMBER(nc200_txrdy_callback); + DECLARE_WRITE_LINE_MEMBER(nc200_rxrdy_callback); + DECLARE_WRITE_LINE_MEMBER(nc200_fdc_interrupt); + + virtual void machine_reset() override; + + uint32_t screen_update_nc200(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + + void nc200_io(address_map &map); + +private: + void nc200_video_set_backlight(int state); + void nc200_refresh_uart_interrupt(); + + uint8_t m_nc200_uart_interrupt_irq; + int m_nc200_backlight; +}; + + #endif // MAME_INCLUDES_NC_H diff --git a/src/mame/video/nc.cpp b/src/mame/video/nc.cpp index 97d2811d736..6298bdf2ecb 100644 --- a/src/mame/video/nc.cpp +++ b/src/mame/video/nc.cpp @@ -45,7 +45,7 @@ PALETTE_INIT_MEMBER(nc_state, nc) } -void nc_state::nc200_video_set_backlight(int state) +void nc200_state::nc200_video_set_backlight(int state) { m_nc200_backlight = state; } @@ -56,65 +56,40 @@ void nc_state::nc200_video_set_backlight(int state) Do NOT call osd_update_display() from this function, it will be called by the main emulation engine. ***************************************************************************/ -uint32_t nc_state::screen_update_nc(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +uint32_t nc_state::screen_update_nc(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int height, int width, int const (&pens)[2]) { - int y; - int b; - int x; - int height, width; - int pens[2]; - - if (m_type==NC_TYPE_200) - { - height = NC200_SCREEN_HEIGHT; - width = NC200_SCREEN_WIDTH; - - if (m_nc200_backlight) - { - pens[0] = 2; - pens[1] = 3; - } - else - { - pens[0] = 0; - pens[1] = 1; - } - } - else - { - height = NC_SCREEN_HEIGHT; - width = NC_SCREEN_WIDTH; - pens[0] = 2; - pens[1] = 3; - } - - - for (y=0; ypointer()) + m_display_memory_start + (y<<6); + char const *line_ptr = ((char const *)m_ram->pointer()) + m_display_memory_start + (y<<6); - x = 0; - for (by=0; by>3; by++) + for (int x = 0, by = 0; by < (width >> 3); by++) { - int px; - unsigned char byte; - - byte = line_ptr[0]; + unsigned char byte = line_ptr[0]; - px = x; - for (b=0; b<8; b++) + for (int b = 0; b < 8; b++) { - bitmap.pix16(y, px) = pens[(byte>>7) & 0x01]; + bitmap.pix16(y, x) = pens[(byte>>7) & 0x01]; byte = byte<<1; - px++; + x++; } - x = px; - - line_ptr = line_ptr+1; + line_ptr++; } } return 0; } + + +uint32_t nc100_state::screen_update_nc100(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +{ + int const pens[]{ 2, 3 }; + return screen_update_nc(screen, bitmap, cliprect, NC_SCREEN_HEIGHT, NC_SCREEN_WIDTH, pens); +} + + +uint32_t nc200_state::screen_update_nc200(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +{ + int const pens[]{ m_nc200_backlight ? 2 : 0, m_nc200_backlight ? 3 : 1 }; + return screen_update_nc(screen, bitmap, cliprect, NC200_SCREEN_HEIGHT, NC200_SCREEN_WIDTH, pens); +} -- cgit v1.2.3