diff options
author | 2015-08-08 17:48:17 +0200 | |
---|---|---|
committer | 2015-08-17 10:38:35 +0200 | |
commit | a7abd5aaac35af248b46a6ceccef7b704dfba120 (patch) | |
tree | a5063bae72f1bd94414aef74e8f97ba0eb96a78d /src | |
parent | e3b06ea5f3c88641e1ece21b22e517c78b86f1ad (diff) |
hp64k: first step of rs232 emulation
Diffstat (limited to 'src')
-rw-r--r-- | src/mess/drivers/hp64k.c | 141 |
1 files changed, 138 insertions, 3 deletions
diff --git a/src/mess/drivers/hp64k.c b/src/mess/drivers/hp64k.c index 37ad5231b45..fc992e77600 100644 --- a/src/mess/drivers/hp64k.c +++ b/src/mess/drivers/hp64k.c @@ -158,6 +158,8 @@ #include "machine/74123.h" #include "machine/rescap.h" #include "sound/beep.h" +#include "machine/clock.h" +#include "machine/i8251.h" #define BIT_MASK(n) (1U << (n)) @@ -165,6 +167,8 @@ #define BIT_CLR(w , n) ((w) &= ~BIT_MASK(n)) #define BIT_SET(w , n) ((w) |= BIT_MASK(n)) +#define BAUD_RATE_GEN_CLOCK 5068800 + class hp64k_state : public driver_device { public: @@ -212,9 +216,14 @@ public: void hp64k_floppy_wpt_cb(floppy_image_device *floppy , int state); DECLARE_READ16_MEMBER(hp64k_usart_r); + DECLARE_WRITE16_MEMBER(hp64k_usart_w); + DECLARE_WRITE_LINE_MEMBER(hp64k_rxrdy_w); + DECLARE_WRITE_LINE_MEMBER(hp64k_txrdy_w); DECLARE_WRITE16_MEMBER(hp64k_beep_w); TIMER_DEVICE_CALLBACK_MEMBER(hp64k_beeper_off); + + DECLARE_WRITE_LINE_MEMBER(hp64k_baud_clk_w); private: required_device<hp_5061_3011_cpu_device> m_cpu; required_device<i8275_device> m_crtc; @@ -232,6 +241,9 @@ private: required_ioport m_rs232_sw; required_device<beep_device> m_beeper; required_device<timer_device> m_beep_timer; + required_device<clock_device> m_baud_rate; + required_ioport m_s5_sw; + required_device<i8251_device> m_uart; // Character generator const UINT8 *m_chargen; @@ -281,6 +293,11 @@ private: floppy_state_t m_floppy_if_state; floppy_image_device *m_current_floppy; + + // RS232 I/F + bool m_16x_clk; + bool m_baud_clk; + UINT8 m_16x_div; }; static ADDRESS_MAP_START(cpu_mem_map , AS_PROGRAM , 16 , hp64k_state) @@ -300,6 +317,9 @@ static ADDRESS_MAP_START(cpu_io_map , AS_IO , 16 , hp64k_state) // PA = 4, IC = [0..3] // Floppy I/F AM_RANGE(HP_MAKE_IOADDR(4 , 0) , HP_MAKE_IOADDR(4 , 3)) AM_READWRITE(hp64k_flp_r , hp64k_flp_w) + // PA = 5, IC = [0..3] + // Write to USART + AM_RANGE(HP_MAKE_IOADDR(5 , 0) , HP_MAKE_IOADDR(5 , 3)) AM_WRITE(hp64k_usart_w) // PA = 6, IC = [0..3] // Read from USART AM_RANGE(HP_MAKE_IOADDR(6 , 0) , HP_MAKE_IOADDR(6 , 3)) AM_READ(hp64k_usart_r) @@ -334,7 +354,10 @@ hp64k_state::hp64k_state(const machine_config &mconfig, device_type type, const m_rear_panel_sw(*this , "rear_sw"), m_rs232_sw(*this , "rs232_sw"), m_beeper(*this , "beeper"), - m_beep_timer(*this , "beep_timer") + m_beep_timer(*this , "beep_timer"), + m_baud_rate(*this , "baud_rate"), + m_s5_sw(*this , "s5_sw"), + m_uart(*this , "uart") { } @@ -349,6 +372,26 @@ void hp64k_state::video_start() m_chargen = memregion("chargen")->base(); } +// Divisors of K1135 baud rate generator +static unsigned baud_rate_divisors[] = { + 6336, + 4224, + 2880, + 2355, + 2112, + 1056, + 528, + 264, + 176, + 158, + 132, + 88, + 66, + 44, + 33, + 16 +}; + void hp64k_state::machine_reset() { m_crtc_drq = false; @@ -372,6 +415,8 @@ void hp64k_state::machine_reset() m_floppy0_wpt = false; m_floppy1_wpt = false; m_beeper->set_state(0); + m_baud_rate->set_unscaled_clock(BAUD_RATE_GEN_CLOCK / baud_rate_divisors[ (m_s5_sw->read() >> 1) & 0xf ]); + m_16x_clk = (m_rs232_sw->read() & 0x02) != 0; } UINT8 hp64k_state::hp64k_crtc_filter(UINT8 data) @@ -895,9 +940,54 @@ void hp64k_state::hp64k_floppy_wpt_cb(floppy_image_device *floppy , int state) READ16_MEMBER(hp64k_state::hp64k_usart_r) { - // todo + UINT16 tmp; + + if ((offset & 1) == 0) { + tmp = m_uart->status_r(space , 0); + } else { + tmp = m_uart->data_r(space , 0); + } + // bit 8 == bit 7 rear panel switches (modem/terminal) ??? - return m_rs232_sw->read() << 8; + + tmp |= (m_rs232_sw->read() << 8); + + if (BIT(m_rear_panel_sw->read() , 7)) { + BIT_SET(tmp , 8); + } + + return tmp; +} + +WRITE16_MEMBER(hp64k_state::hp64k_usart_w) +{ + if ((offset & 1) == 0) { + m_uart->control_w(space , 0 , (UINT8)(data & 0xff)); + } else { + m_uart->data_w(space , 0 , (UINT8)(data & 0xff)); + } +} + +WRITE_LINE_MEMBER(hp64k_state::hp64k_rxrdy_w) +{ + if (state) { + BIT_SET(m_irl_pending , 6); + } else { + BIT_CLR(m_irl_pending , 6); + } + + hp64k_update_irl(); +} + +WRITE_LINE_MEMBER(hp64k_state::hp64k_txrdy_w) +{ + if (state) { + BIT_SET(m_irl_pending , 5); + } else { + BIT_CLR(m_irl_pending , 5); + } + + hp64k_update_irl(); } WRITE16_MEMBER(hp64k_state::hp64k_beep_w) @@ -914,6 +1004,19 @@ TIMER_DEVICE_CALLBACK_MEMBER(hp64k_state::hp64k_beeper_off) m_beeper->set_state(0); } +WRITE_LINE_MEMBER(hp64k_state::hp64k_baud_clk_w) +{ + if (!m_16x_clk) { + if (state && !m_baud_clk) { + m_16x_div++; + } + m_baud_clk = !!state; + state = BIT(m_16x_div , 3); + } + m_uart->write_txc(state); + m_uart->write_rxc(state); +} + static INPUT_PORTS_START(hp64k) // Keyboard is arranged in a 8 x 16 matrix. Of the 128 possible positions, only 77 are used. // For key arrangement on the matrix, see [1] pg 334 @@ -1129,6 +1232,30 @@ static INPUT_PORTS_START(hp64k) PORT_DIPSETTING(0x00 , "1x") PORT_DIPSETTING(0x02 , "16x") + PORT_START("s5_sw") + PORT_DIPNAME(0x01 , 0x00 , "Duplex") + PORT_DIPLOCATION("S5 IO:!1") + PORT_DIPSETTING(0x00 , "Half duplex") + PORT_DIPSETTING(0x01 , "Full duplex") + PORT_DIPNAME(0x1e , 0x00 , "Baud rate") + PORT_DIPLOCATION("S5 IO:!5,!4,!3,!2") + PORT_DIPSETTING(0x00 , "50") + PORT_DIPSETTING(0x02 , "75") + PORT_DIPSETTING(0x04 , "110") + PORT_DIPSETTING(0x06 , "134.5") + PORT_DIPSETTING(0x08 , "150") + PORT_DIPSETTING(0x0a , "300") + PORT_DIPSETTING(0x0c , "600") + PORT_DIPSETTING(0x0e , "1200") + PORT_DIPSETTING(0x10 , "1800") + PORT_DIPSETTING(0x12 , "2000") + PORT_DIPSETTING(0x14 , "2400") + PORT_DIPSETTING(0x16 , "3600") + PORT_DIPSETTING(0x18 , "4800") + PORT_DIPSETTING(0x1a , "7200") + PORT_DIPSETTING(0x1c , "9600") + PORT_DIPSETTING(0x1e , "19200") + INPUT_PORTS_END static SLOT_INTERFACE_START(hp64k_floppies) @@ -1191,6 +1318,14 @@ static MACHINE_CONFIG_START(hp64k , hp64k_state) MCFG_SOUND_ROUTE(ALL_OUTPUTS , "mono" , 1.00) MCFG_TIMER_DRIVER_ADD("beep_timer" , hp64k_state , hp64k_beeper_off); + + MCFG_DEVICE_ADD("baud_rate" , CLOCK , 0) + MCFG_CLOCK_SIGNAL_HANDLER(WRITELINE(hp64k_state , hp64k_baud_clk_w)); + + MCFG_DEVICE_ADD("uart" , I8251 , 0) + MCFG_I8251_RXRDY_HANDLER(WRITELINE(hp64k_state , hp64k_rxrdy_w)); + MCFG_I8251_TXRDY_HANDLER(WRITELINE(hp64k_state , hp64k_txrdy_w)); + MACHINE_CONFIG_END ROM_START(hp64k) |