trunk/src/emu/bus/a2bus/mouse.c
| r0 | r31959 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | mouse.c |
| 4 | |
| 5 | Implemention of the Apple II Mouse Card |
| 6 | |
| 7 | Apple II Mouse Interface PCB |
| 8 | Apple 1983 |
| 9 | |
| 10 | This is a mouse interface for the Apple II |
| 11 | |
| 12 | PCB Layout |
| 13 | ---------- |
| 14 | apple computer |
| 15 | MOUSE INTERFACE |
| 16 | 670-0030-C (C) 1983 |
| 17 | Printed on back side - MOUSE INTERFACE 820-0104-B (C) 1983 APPLE COMPUTER |
| 18 | |-----------------------------------| |
| 19 | | PAL16R4 6821 | |
| 20 | | | |
| 21 | | J1 | |
| 22 | | 74SC245 | |
| 23 | | 68705P3 8516 | |
| 24 | | 74LS74 X1 X2 | |
| 25 | |-------------------| |-| |
| 26 | |-------------| |
| 27 | |
| 28 | Notes: |
| 29 | J1 - 9 pin flat cable with female DB9 connector |
| 30 | 68705P3 - Motorola MC68705P3 microcontroller (DIP28) labelled '341-0269 (C) APPLE' |
| 31 | PCB printed '(C) APPLE 1983 341-0269 or 342-0285' |
| 32 | 8516 - Fujitsu MB8516 2k x8-bit EPROM (DIP24) labelled '341-0270-C (C) APPLE 1983' |
| 33 | PCB printed '(C) APPLE 1983 342-0270' |
| 34 | PAL16R4 - MMI PAL16R4ACN (DIP20) marked '341-0268-A' |
| 35 | PCB printed '(C) APPLE 1983 342-0268' |
| 36 | 6821 - AMI 6821 Peripheral Interface Adapter (DIP40) |
| 37 | X1/X2 - Jumper pads. X1 is open, X2 is closed. |
| 38 | |
| 39 | |
| 40 | Hookup notes: |
| 41 | PIA port A connects to 68705 port A in its entirety (bi-directional) |
| 42 | PIA PB4-PB7 connects to 68705 PC0-3 (bi-directional) |
| 43 | PIA PB0 is 'sync latch' |
| 44 | PIA PB1 is A8 on the EPROM |
| 45 | PIA PB2 is A9 on the EPROM |
| 46 | PIA PB3 is A10 on the EPROM |
| 47 | |
| 48 | 68705 PB0 is mouse X1 |
| 49 | 68705 PB1 is mouse X0 |
| 50 | 68705 PB2 is mouse Y0 |
| 51 | 68705 PB3 is mouse Y1 |
| 52 | 68705 PB4 and 5 are N/C |
| 53 | 68705 PB6 is IRQ for the slot |
| 54 | 68705 PB7 is the mouse button |
| 55 | |
| 56 | 68705 is clocked at 2M |
| 57 | PIA is clocked at 1M |
| 58 | |
| 59 | See the schematic at: |
| 60 | http://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Interface%20Cards/Digitizers/Apple%20Mouse%20Interface%20Card/Schematics/ |
| 61 | |
| 62 | *********************************************************************/ |
| 63 | |
| 64 | #include "mouse.h" |
| 65 | |
| 66 | /*************************************************************************** |
| 67 | PARAMETERS |
| 68 | ***************************************************************************/ |
| 69 | |
| 70 | //************************************************************************** |
| 71 | // GLOBAL VARIABLES |
| 72 | //************************************************************************** |
| 73 | |
| 74 | const device_type A2BUS_MOUSE = &device_creator<a2bus_mouse_device>; |
| 75 | |
| 76 | #define MOUSE_ROM_REGION "a2mse_rom" |
| 77 | #define MOUSE_PIA_TAG "a2mse_pia" |
| 78 | #define MOUSE_MCU_TAG "a2mse_mcu" |
| 79 | #define MOUSE_MCU_ROM "a2mse_mcurom" |
| 80 | |
| 81 | #define MOUSE_BUTTON_TAG "a2mse_button" |
| 82 | #define MOUSE_XAXIS_TAG "a2mse_x" |
| 83 | #define MOUSE_YAXIS_TAG "a2mse_y" |
| 84 | |
| 85 | #define TIMER_68705 0 |
| 86 | #define TIMER_QUADRATURE 1 |
| 87 | |
| 88 | static ADDRESS_MAP_START( mcu_mem, AS_PROGRAM, 8, a2bus_mouse_device ) |
| 89 | ADDRESS_MAP_GLOBAL_MASK(0x7ff) |
| 90 | AM_RANGE(0x0000, 0x0000) AM_READWRITE(mcu_port_a_r, mcu_port_a_w) |
| 91 | AM_RANGE(0x0001, 0x0001) AM_READWRITE(mcu_port_b_r, mcu_port_b_w) |
| 92 | AM_RANGE(0x0002, 0x0002) AM_READWRITE(mcu_port_c_r, mcu_port_c_w) |
| 93 | AM_RANGE(0x0004, 0x0004) AM_WRITE(mcu_ddr_a_w) |
| 94 | AM_RANGE(0x0005, 0x0005) AM_WRITE(mcu_ddr_b_w) |
| 95 | AM_RANGE(0x0006, 0x0006) AM_WRITE(mcu_ddr_c_w) |
| 96 | AM_RANGE(0x0008, 0x0009) AM_READWRITE(mcu_timer_r, mcu_timer_w) |
| 97 | AM_RANGE(0x0010, 0x007f) AM_RAM |
| 98 | AM_RANGE(0x0080, 0x07ff) AM_ROM AM_REGION(MOUSE_MCU_ROM, 0x80) |
| 99 | ADDRESS_MAP_END |
| 100 | |
| 101 | MACHINE_CONFIG_FRAGMENT( mouse ) |
| 102 | MCFG_CPU_ADD(MOUSE_MCU_TAG, M68705, 2043600) |
| 103 | MCFG_CPU_PROGRAM_MAP(mcu_mem) |
| 104 | |
| 105 | MCFG_DEVICE_ADD(MOUSE_PIA_TAG, PIA6821, 1021800) |
| 106 | MCFG_PIA_READPA_HANDLER(READ8(a2bus_mouse_device, pia_in_a)) |
| 107 | MCFG_PIA_READPB_HANDLER(READ8(a2bus_mouse_device, pia_in_b)) |
| 108 | MCFG_PIA_WRITEPA_HANDLER(WRITE8(a2bus_mouse_device, pia_out_a)) |
| 109 | MCFG_PIA_WRITEPB_HANDLER(WRITE8(a2bus_mouse_device, pia_out_b)) |
| 110 | MCFG_PIA_IRQA_HANDLER(WRITELINE(a2bus_mouse_device, pia_irqa_w)) |
| 111 | MCFG_PIA_IRQB_HANDLER(WRITELINE(a2bus_mouse_device, pia_irqb_w)) |
| 112 | MACHINE_CONFIG_END |
| 113 | |
| 114 | ROM_START( mouse ) |
| 115 | ROM_REGION(0x800, MOUSE_ROM_REGION, 0) |
| 116 | ROM_LOAD( "341-0270-c.4b", 0x000000, 0x000800, CRC(0bcd1e8e) SHA1(3a9d881a8a8d30f55b9719aceebbcf717f829d6f) ) |
| 117 | |
| 118 | ROM_REGION(0x800, MOUSE_MCU_ROM, 0) |
| 119 | ROM_LOAD( "341-0269.2b", 0x000000, 0x000800, CRC(94067f16) SHA1(3a2baa6648efe4456d3ec3721216e57c64f7acfc) ) |
| 120 | |
| 121 | ROM_REGION(0xc00, "pal", 0) |
| 122 | ROM_LOAD( "mmi_pal16r4a(jedec).2a", 0x000000, 0x000b04, CRC(1d620ee5) SHA1(5aa9a515c919ff7a18878649cac5d44f0c2abf28) ) |
| 123 | ROM_LOAD( "mmi_pal16r4a(binary).2a", 0x000000, 0x000100, CRC(1da5c745) SHA1(ba267b69a2fda2a2348b140979ece562411bb37b) ) |
| 124 | ROM_END |
| 125 | |
| 126 | static INPUT_PORTS_START( mouse ) |
| 127 | PORT_START(MOUSE_BUTTON_TAG) /* Mouse - button */ |
| 128 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Mouse Button") PORT_CODE(MOUSECODE_BUTTON1) |
| 129 | |
| 130 | PORT_START(MOUSE_XAXIS_TAG) /* Mouse - X AXIS */ |
| 131 | PORT_BIT( 0xff, 0x00, IPT_MOUSE_X) PORT_SENSITIVITY(40) PORT_KEYDELTA(0) PORT_PLAYER(1) |
| 132 | |
| 133 | PORT_START(MOUSE_YAXIS_TAG) /* Mouse - Y AXIS */ |
| 134 | PORT_BIT( 0xff, 0x00, IPT_MOUSE_Y) PORT_SENSITIVITY(40) PORT_KEYDELTA(0) PORT_PLAYER(1) |
| 135 | INPUT_PORTS_END |
| 136 | |
| 137 | /*************************************************************************** |
| 138 | FUNCTION PROTOTYPES |
| 139 | ***************************************************************************/ |
| 140 | |
| 141 | //------------------------------------------------- |
| 142 | // input_ports - device-specific input ports |
| 143 | //------------------------------------------------- |
| 144 | |
| 145 | ioport_constructor a2bus_mouse_device::device_input_ports() const |
| 146 | { |
| 147 | return INPUT_PORTS_NAME( mouse ); |
| 148 | } |
| 149 | |
| 150 | //------------------------------------------------- |
| 151 | // machine_config_additions - device-specific |
| 152 | // machine configurations |
| 153 | //------------------------------------------------- |
| 154 | |
| 155 | machine_config_constructor a2bus_mouse_device::device_mconfig_additions() const |
| 156 | { |
| 157 | return MACHINE_CONFIG_NAME( mouse ); |
| 158 | } |
| 159 | |
| 160 | //------------------------------------------------- |
| 161 | // rom_region - device-specific ROM region |
| 162 | //------------------------------------------------- |
| 163 | |
| 164 | const rom_entry *a2bus_mouse_device::device_rom_region() const |
| 165 | { |
| 166 | return ROM_NAME( mouse ); |
| 167 | } |
| 168 | |
| 169 | //************************************************************************** |
| 170 | // LIVE DEVICE |
| 171 | //************************************************************************** |
| 172 | |
| 173 | a2bus_mouse_device::a2bus_mouse_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) : |
| 174 | device_t(mconfig, type, name, tag, owner, clock, shortname, source), |
| 175 | device_a2bus_card_interface(mconfig, *this), |
| 176 | m_pia(*this, MOUSE_PIA_TAG), |
| 177 | m_mcu(*this, MOUSE_MCU_TAG), |
| 178 | m_mouseb(*this, MOUSE_BUTTON_TAG), |
| 179 | m_mousex(*this, MOUSE_XAXIS_TAG), |
| 180 | m_mousey(*this, MOUSE_YAXIS_TAG) |
| 181 | { |
| 182 | m_started = false; |
| 183 | m_rom_bank = 0; |
| 184 | } |
| 185 | |
| 186 | a2bus_mouse_device::a2bus_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 187 | device_t(mconfig, A2BUS_MOUSE, "Apple II Mouse Card", tag, owner, clock, "a2mouse", __FILE__), |
| 188 | device_a2bus_card_interface(mconfig, *this), |
| 189 | m_pia(*this, MOUSE_PIA_TAG), |
| 190 | m_mcu(*this, MOUSE_MCU_TAG), |
| 191 | m_mouseb(*this, MOUSE_BUTTON_TAG), |
| 192 | m_mousex(*this, MOUSE_XAXIS_TAG), |
| 193 | m_mousey(*this, MOUSE_YAXIS_TAG) |
| 194 | { |
| 195 | m_started = false; |
| 196 | m_rom_bank = 0; |
| 197 | } |
| 198 | |
| 199 | //------------------------------------------------- |
| 200 | // device_start - device-specific startup |
| 201 | //------------------------------------------------- |
| 202 | |
| 203 | void a2bus_mouse_device::device_start() |
| 204 | { |
| 205 | // set_a2bus_device makes m_slot valid |
| 206 | set_a2bus_device(); |
| 207 | |
| 208 | astring tempstring; |
| 209 | m_rom = device().machine().root_device().memregion(this->subtag(tempstring, MOUSE_ROM_REGION))->base(); |
| 210 | |
| 211 | // allocate two timers: one for the 68705, one for the quadrature magic |
| 212 | m_timer = timer_alloc(TIMER_68705, NULL); |
| 213 | m_read_timer = timer_alloc(TIMER_QUADRATURE, NULL); |
| 214 | m_timer->adjust(attotime::never, TIMER_68705); |
| 215 | m_read_timer->adjust(attotime::never, TIMER_QUADRATURE); |
| 216 | |
| 217 | // get 68705P3 mask option byte |
| 218 | m_mask_option = m_rom[0x784]; |
| 219 | |
| 220 | // register save state variables |
| 221 | save_item(NAME(m_ddr_a)); |
| 222 | save_item(NAME(m_ddr_b)); |
| 223 | save_item(NAME(m_ddr_c)); |
| 224 | save_item(NAME(m_port_a_out)); |
| 225 | save_item(NAME(m_port_b_out)); |
| 226 | save_item(NAME(m_port_c_out)); |
| 227 | save_item(NAME(m_port_a_in)); |
| 228 | save_item(NAME(m_port_b_in)); |
| 229 | save_item(NAME(m_port_c_in)); |
| 230 | save_item(NAME(m_timer_cnt)); |
| 231 | save_item(NAME(m_timer_ctl)); |
| 232 | save_item(NAME(last_mx)); |
| 233 | save_item(NAME(last_my)); |
| 234 | save_item(NAME(count_x)); |
| 235 | save_item(NAME(count_y)); |
| 236 | } |
| 237 | |
| 238 | void a2bus_mouse_device::device_reset() |
| 239 | { |
| 240 | m_started = true; |
| 241 | m_rom_bank = 0; |
| 242 | last_mx = last_my = count_x = count_y = 0; |
| 243 | m_timer_cnt = 0xff; |
| 244 | m_timer_ctl = 0x40; // disable interrupt, everything else clear |
| 245 | m_port_a_in = 0; |
| 246 | m_port_b_in = 0x80; |
| 247 | m_port_c_in = 0; |
| 248 | |
| 249 | // are we emulating the mask part with a semi-programmable timer? |
| 250 | if (m_mask_option & 0x40) |
| 251 | { |
| 252 | m_timer_ctl |= m_mask_option & 0x17; |
| 253 | } |
| 254 | |
| 255 | m_read_timer->adjust(attotime::from_hz(600.0), TIMER_QUADRATURE, attotime::from_hz(600.0)); |
| 256 | } |
| 257 | |
| 258 | /*------------------------------------------------- |
| 259 | read_c0nx - called for reads from this card's c0nx space |
| 260 | -------------------------------------------------*/ |
| 261 | |
| 262 | UINT8 a2bus_mouse_device::read_c0nx(address_space &space, UINT8 offset) |
| 263 | { |
| 264 | return m_pia->read(space, offset & 3); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | /*------------------------------------------------- |
| 269 | write_c0nx - called for writes to this card's c0nx space |
| 270 | -------------------------------------------------*/ |
| 271 | |
| 272 | void a2bus_mouse_device::write_c0nx(address_space &space, UINT8 offset, UINT8 data) |
| 273 | { |
| 274 | m_pia->write(space, offset & 3, data); |
| 275 | } |
| 276 | |
| 277 | /*------------------------------------------------- |
| 278 | read_cnxx - called for reads from this card's cnxx space |
| 279 | -------------------------------------------------*/ |
| 280 | |
| 281 | UINT8 a2bus_mouse_device::read_cnxx(address_space &space, UINT8 offset) |
| 282 | { |
| 283 | return m_rom[offset+m_rom_bank]; |
| 284 | } |
| 285 | |
| 286 | READ8_MEMBER(a2bus_mouse_device::pia_in_a) |
| 287 | { |
| 288 | return m_port_a_out; |
| 289 | } |
| 290 | |
| 291 | READ8_MEMBER(a2bus_mouse_device::pia_in_b) |
| 292 | { |
| 293 | return (m_port_c_out << 4); |
| 294 | } |
| 295 | |
| 296 | WRITE8_MEMBER(a2bus_mouse_device::pia_out_a) |
| 297 | { |
| 298 | m_port_a_in = data; |
| 299 | } |
| 300 | |
| 301 | WRITE8_MEMBER(a2bus_mouse_device::pia_out_b) |
| 302 | { |
| 303 | m_port_c_in &= 0xf0; |
| 304 | m_port_c_in |= ((data >> 4) & 0xf); |
| 305 | |
| 306 | m_rom_bank = (data & 0xe) << 7; |
| 307 | } |
| 308 | |
| 309 | WRITE_LINE_MEMBER(a2bus_mouse_device::pia_irqa_w) |
| 310 | { |
| 311 | } |
| 312 | |
| 313 | WRITE_LINE_MEMBER(a2bus_mouse_device::pia_irqb_w) |
| 314 | { |
| 315 | } |
| 316 | |
| 317 | READ8_MEMBER(a2bus_mouse_device::mcu_port_a_r) |
| 318 | { |
| 319 | return (m_port_a_out & m_ddr_a) | (m_port_a_in & ~m_ddr_a); |
| 320 | } |
| 321 | |
| 322 | WRITE8_MEMBER(a2bus_mouse_device::mcu_port_a_w) |
| 323 | { |
| 324 | m_port_a_out = data; |
| 325 | } |
| 326 | |
| 327 | WRITE8_MEMBER(a2bus_mouse_device::mcu_ddr_a_w) |
| 328 | { |
| 329 | m_ddr_a = data; |
| 330 | } |
| 331 | |
| 332 | READ8_MEMBER(a2bus_mouse_device::mcu_port_b_r) |
| 333 | { |
| 334 | UINT8 b_in = m_port_b_in; |
| 335 | |
| 336 | // clear the gates, leave everything else alone between pulses |
| 337 | m_port_b_in &= 0x85; |
| 338 | |
| 339 | return (m_port_b_out & m_ddr_b) | (b_in & ~m_ddr_b); |
| 340 | } |
| 341 | |
| 342 | WRITE8_MEMBER(a2bus_mouse_device::mcu_port_b_w) |
| 343 | { |
| 344 | m_port_b_out = data; |
| 345 | |
| 346 | if (!(data & 0x40)) |
| 347 | { |
| 348 | raise_slot_irq(); |
| 349 | } |
| 350 | else |
| 351 | { |
| 352 | lower_slot_irq(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | WRITE8_MEMBER(a2bus_mouse_device::mcu_ddr_b_w) |
| 357 | { |
| 358 | m_ddr_b = data; |
| 359 | } |
| 360 | |
| 361 | READ8_MEMBER(a2bus_mouse_device::mcu_port_c_r) |
| 362 | { |
| 363 | return (m_port_c_out & m_ddr_c) | (m_port_c_in & ~m_ddr_c); |
| 364 | } |
| 365 | |
| 366 | WRITE8_MEMBER(a2bus_mouse_device::mcu_port_c_w) |
| 367 | { |
| 368 | m_port_c_out = data; |
| 369 | } |
| 370 | |
| 371 | WRITE8_MEMBER(a2bus_mouse_device::mcu_ddr_c_w) |
| 372 | { |
| 373 | m_ddr_c = data; |
| 374 | } |
| 375 | |
| 376 | READ8_MEMBER(a2bus_mouse_device::mcu_timer_r) |
| 377 | { |
| 378 | if (offset == 1) |
| 379 | { |
| 380 | return m_timer_ctl; |
| 381 | } |
| 382 | |
| 383 | return m_timer_cnt; |
| 384 | } |
| 385 | |
| 386 | WRITE8_MEMBER(a2bus_mouse_device::mcu_timer_w) |
| 387 | { |
| 388 | static const int prescale[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; |
| 389 | bool recalc = false; |
| 390 | |
| 391 | // offset 0 = timer data (counts down) |
| 392 | if (offset == 0) |
| 393 | { |
| 394 | m_timer_cnt = data; |
| 395 | recalc = true; |
| 396 | } |
| 397 | // offset 1 = timer control: b7 = IRQ, b6 = IRQ mask (1=suppress), |
| 398 | // b5 = input select (0=CPU clk, 1=ext), |
| 399 | // b4 = enable external timer input, |
| 400 | // b3 = clear, b2-b0 = scaler (1/2/4/8/16/32/64/128) |
| 401 | else |
| 402 | { |
| 403 | // clearing the interrupt? |
| 404 | if ((m_timer_ctl & 0x80) && !(data & 0x80)) |
| 405 | { |
| 406 | m_mcu->set_input_line(M68705_INT_TIMER, CLEAR_LINE); |
| 407 | } |
| 408 | |
| 409 | if (m_mask_option & 0x40) |
| 410 | { |
| 411 | m_timer_ctl &= 0x3f; |
| 412 | m_timer_ctl |= (data & 0xc0); |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | // if any parameters that affect the timer changed, recalc now |
| 417 | if ((data & 0x3f) != (m_timer_ctl & 0x3f)) |
| 418 | { |
| 419 | recalc = true; |
| 420 | } |
| 421 | |
| 422 | // if prescaler reset, recalc |
| 423 | if (data & 0x8) |
| 424 | { |
| 425 | recalc = true; |
| 426 | } |
| 427 | |
| 428 | m_timer_ctl = data; |
| 429 | } |
| 430 | |
| 431 | } |
| 432 | |
| 433 | if (recalc) |
| 434 | { |
| 435 | // recalculate the timer now |
| 436 | UINT32 m_ticks = 2043600 / 4; |
| 437 | m_ticks /= prescale[m_timer_ctl & 7]; |
| 438 | m_ticks /= (int)(m_timer_cnt + 1); |
| 439 | m_timer->adjust(attotime::from_hz((double)m_ticks), TIMER_68705, attotime::from_hz((double)m_ticks)); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | X0 = direction, 0 = left, 1 = right |
| 445 | X1 = gate, must go 0/1 for each pixel moved |
| 446 | Y0 = direction, 0 = up, 1 = down |
| 447 | Y1 = gate, must go 0/1 for each pixel moved |
| 448 | |
| 449 | The direction must stay constant for a given train of gate pulses or the MCU will get confused. |
| 450 | */ |
| 451 | void a2bus_mouse_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 452 | { |
| 453 | if (id == TIMER_68705) // 68705's built-in timer |
| 454 | { |
| 455 | m_timer_ctl |= 0x80; // indicate timer expired |
| 456 | if (!(m_timer_ctl & 0x40)) // if interrupt not suppressed, fire! |
| 457 | { |
| 458 | m_mcu->set_input_line(M68705_INT_TIMER, ASSERT_LINE); |
| 459 | } |
| 460 | } |
| 461 | else if (id == TIMER_QUADRATURE) |
| 462 | { |
| 463 | int new_mx, new_my; |
| 464 | m_port_b_in = 0x80; |
| 465 | |
| 466 | // update button now |
| 467 | if (m_mouseb->read()) m_port_b_in &= ~0x80; |
| 468 | |
| 469 | // read the axes |
| 470 | new_mx = m_mousex->read(); |
| 471 | new_my = m_mousey->read(); |
| 472 | |
| 473 | // did X change? |
| 474 | if (new_mx != last_mx) |
| 475 | { |
| 476 | int diff = new_mx - last_mx; |
| 477 | |
| 478 | /* check for wrap */ |
| 479 | if (diff > 0x80) |
| 480 | diff = 0x100-diff; |
| 481 | if (diff < -0x80) |
| 482 | diff = -0x100-diff; |
| 483 | |
| 484 | count_x += diff; |
| 485 | last_mx = new_mx; |
| 486 | } |
| 487 | |
| 488 | // did Y change? |
| 489 | if (new_my != last_my) |
| 490 | { |
| 491 | int diff = new_my - last_my; |
| 492 | |
| 493 | /* check for wrap */ |
| 494 | if (diff > 0x80) |
| 495 | diff = 0x100-diff; |
| 496 | if (diff < -0x80) |
| 497 | diff = -0x100-diff; |
| 498 | |
| 499 | count_y += diff; |
| 500 | last_my = new_my; |
| 501 | } |
| 502 | |
| 503 | if (count_x) |
| 504 | { |
| 505 | if (count_x < 0) |
| 506 | { |
| 507 | count_x++; |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | count_x--; |
| 512 | m_port_b_in |= 0x01; // X1 |
| 513 | } |
| 514 | m_port_b_in |= 0x02; // X0 |
| 515 | } |
| 516 | else if (count_y) |
| 517 | { |
| 518 | if (count_y < 0) |
| 519 | { |
| 520 | count_y++; |
| 521 | } |
| 522 | else |
| 523 | { |
| 524 | count_y--; |
| 525 | m_port_b_in |= 0x04; // Y0 |
| 526 | } |
| 527 | m_port_b_in |= 0x08; // Y1 |
| 528 | } |
| 529 | } |
| 530 | } |
trunk/src/emu/bus/a2bus/mouse.h
| r0 | r31959 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | mouse.h |
| 4 | |
| 5 | Implemention of the Apple II Mouse Card |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | #ifndef __A2BUS_MOUSE__ |
| 10 | #define __A2BUS_MOUSE__ |
| 11 | |
| 12 | #include "emu.h" |
| 13 | #include "a2bus.h" |
| 14 | #include "machine/6821pia.h" |
| 15 | #include "cpu/m6805/m6805.h" |
| 16 | |
| 17 | //************************************************************************** |
| 18 | // TYPE DEFINITIONS |
| 19 | //************************************************************************** |
| 20 | |
| 21 | class a2bus_mouse_device: |
| 22 | public device_t, |
| 23 | public device_a2bus_card_interface |
| 24 | { |
| 25 | public: |
| 26 | // construction/destruction |
| 27 | a2bus_mouse_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); |
| 28 | a2bus_mouse_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 29 | |
| 30 | // optional information overrides |
| 31 | virtual machine_config_constructor device_mconfig_additions() const; |
| 32 | virtual const rom_entry *device_rom_region() const; |
| 33 | virtual ioport_constructor device_input_ports() const; |
| 34 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 35 | |
| 36 | DECLARE_READ8_MEMBER(pia_in_a); |
| 37 | DECLARE_READ8_MEMBER(pia_in_b); |
| 38 | DECLARE_WRITE8_MEMBER(pia_out_a); |
| 39 | DECLARE_WRITE8_MEMBER(pia_out_b); |
| 40 | DECLARE_WRITE_LINE_MEMBER(pia_irqa_w); |
| 41 | DECLARE_WRITE_LINE_MEMBER(pia_irqb_w); |
| 42 | |
| 43 | DECLARE_READ8_MEMBER(mcu_port_a_r); |
| 44 | DECLARE_READ8_MEMBER(mcu_port_b_r); |
| 45 | DECLARE_READ8_MEMBER(mcu_port_c_r); |
| 46 | DECLARE_WRITE8_MEMBER(mcu_port_a_w); |
| 47 | DECLARE_WRITE8_MEMBER(mcu_port_b_w); |
| 48 | DECLARE_WRITE8_MEMBER(mcu_port_c_w); |
| 49 | DECLARE_WRITE8_MEMBER(mcu_ddr_a_w); |
| 50 | DECLARE_WRITE8_MEMBER(mcu_ddr_b_w); |
| 51 | DECLARE_WRITE8_MEMBER(mcu_ddr_c_w); |
| 52 | DECLARE_READ8_MEMBER(mcu_timer_r); |
| 53 | DECLARE_WRITE8_MEMBER(mcu_timer_w); |
| 54 | |
| 55 | protected: |
| 56 | virtual void device_start(); |
| 57 | virtual void device_reset(); |
| 58 | |
| 59 | // overrides of standard a2bus slot functions |
| 60 | virtual UINT8 read_c0nx(address_space &space, UINT8 offset); |
| 61 | virtual void write_c0nx(address_space &space, UINT8 offset, UINT8 data); |
| 62 | virtual UINT8 read_cnxx(address_space &space, UINT8 offset); |
| 63 | |
| 64 | required_device<pia6821_device> m_pia; |
| 65 | required_device<m68705_device> m_mcu; |
| 66 | required_ioport m_mouseb, m_mousex, m_mousey; |
| 67 | |
| 68 | private: |
| 69 | UINT8 *m_rom; |
| 70 | bool m_started; |
| 71 | int m_rom_bank; |
| 72 | UINT8 m_ddr_a; |
| 73 | UINT8 m_ddr_b; |
| 74 | UINT8 m_ddr_c; |
| 75 | UINT8 m_port_a_out; |
| 76 | UINT8 m_port_b_out; |
| 77 | UINT8 m_port_c_out; |
| 78 | UINT8 m_port_a_in; |
| 79 | UINT8 m_port_b_in; |
| 80 | UINT8 m_port_c_in; |
| 81 | UINT8 m_timer_cnt; |
| 82 | UINT8 m_timer_ctl; |
| 83 | UINT8 m_mask_option; |
| 84 | int last_mx, last_my, count_x, count_y; |
| 85 | emu_timer *m_timer, *m_read_timer; |
| 86 | }; |
| 87 | |
| 88 | // device type definition |
| 89 | extern const device_type A2BUS_MOUSE; |
| 90 | |
| 91 | #endif /* __A2BUS_MOUSE__ */ |