diff options
author | 2011-10-04 20:15:30 +0000 | |
---|---|---|
committer | 2011-10-04 20:15:30 +0000 | |
commit | 5fc1b023b416673c8140e9141c1e5508b0b3957b (patch) | |
tree | 0ab09695007b500ce4656ef961d71a786207ba53 /src/emu | |
parent | 56f7f759011eed1a30fc4f6072745b008438b430 (diff) |
Hooked up touch screen to Odeon Twister 2 [Mariusz Wojcieszek]
Diffstat (limited to 'src/emu')
-rw-r--r-- | src/emu/machine/microtch.c | 125 |
1 files changed, 81 insertions, 44 deletions
diff --git a/src/emu/machine/microtch.c b/src/emu/machine/microtch.c index 128dc29c383..c551bc89c0c 100644 --- a/src/emu/machine/microtch.c +++ b/src/emu/machine/microtch.c @@ -14,6 +14,24 @@ #define LOG 0 +enum MICROTOUCH_FORMAT +{ + FORMAT_UNKNOWN, + FORMAT_TABLET, + FORMAT_DECIMAL +}; + +ALLOW_SAVE_TYPE(MICROTOUCH_FORMAT); + +enum MICROTOUCH_MODE +{ + MODE_INACTIVE, + MODE_STREAM, + MODE_POINT +}; + +ALLOW_SAVE_TYPE(MICROTOUCH_MODE); + static struct { UINT8 rx_buffer[16]; @@ -23,10 +41,8 @@ static struct UINT8 tx_buffer_num; UINT8 tx_buffer_ptr; int reset_done; - int format_tablet; - int format_decimal; - int mode_inactive; - int mode_stream; + MICROTOUCH_FORMAT format; + MICROTOUCH_MODE mode; int last_touch_state; int last_x; int last_y; @@ -90,6 +106,33 @@ static void microtouch_send_format_decimal_packet(int x, int y) microtouch.tx_buffer[microtouch.tx_buffer_num++] = 0x0d; } +static void microtouch_send_touch_packet(running_machine &machine) +{ + int tx = input_port_read(machine, "TOUCH_X"); + int ty = input_port_read(machine, "TOUCH_Y"); + + if ( microtouch.touch_callback == NULL || + microtouch.touch_callback( machine, &tx, &ty ) != 0 ) + { + ty = 0x4000 - ty; + + switch( microtouch.format ) + { + case FORMAT_TABLET: + microtouch_send_format_table_packet(0xc8, tx, ty); + break; + case FORMAT_DECIMAL: + microtouch_send_format_decimal_packet(tx, ty); + break; + case FORMAT_UNKNOWN: + break; + } + microtouch.last_touch_state = 1; + microtouch.last_x = tx; + microtouch.last_y = ty; + } +} + static TIMER_CALLBACK(microtouch_timer_callback) { if ( microtouch.tx_buffer_ptr < microtouch.tx_buffer_num ) @@ -103,9 +146,8 @@ static TIMER_CALLBACK(microtouch_timer_callback) } if ( (microtouch.reset_done == 0) || - ((microtouch.format_tablet == 0) && (microtouch.format_decimal == 0)) || - (microtouch.mode_inactive == 1) || - (microtouch.mode_stream == 0) ) + (microtouch.format == FORMAT_UNKNOWN) || + (microtouch.mode != MODE_STREAM)) { return; } @@ -113,39 +155,23 @@ static TIMER_CALLBACK(microtouch_timer_callback) // send format tablet packet if ( input_port_read(machine, "TOUCH") & 0x01 ) { - int tx = input_port_read(machine, "TOUCH_X"); - int ty = input_port_read(machine, "TOUCH_Y"); - - if ( microtouch.touch_callback == NULL || - microtouch.touch_callback( machine, &tx, &ty ) != 0 ) - { - ty = 0x4000 - ty; - - if ( microtouch.format_tablet ) - { - microtouch_send_format_table_packet(0xc8, tx, ty); - } - else if ( microtouch.format_decimal ) - { - microtouch_send_format_decimal_packet(tx, ty); - } - microtouch.last_touch_state = 1; - microtouch.last_x = tx; - microtouch.last_y = ty; - } + microtouch_send_touch_packet(machine); } else { if ( microtouch.last_touch_state == 1 ) { microtouch.last_touch_state = 0; - if ( microtouch.format_tablet ) - { - microtouch_send_format_table_packet(0x88, microtouch.last_x, microtouch.last_y); - } - else if ( microtouch.format_decimal ) + switch( microtouch.format ) { - microtouch_send_format_decimal_packet(microtouch.last_x, microtouch.last_y); + case FORMAT_TABLET: + microtouch_send_format_table_packet(0x88, microtouch.last_x, microtouch.last_y); + break; + case FORMAT_DECIMAL: + microtouch_send_format_decimal_packet(microtouch.last_x, microtouch.last_y); + break; + case FORMAT_UNKNOWN: + break; } } } @@ -162,10 +188,10 @@ void microtouch_init(running_machine &machine, microtouch_tx_func tx_cb, microto microtouch.timer = machine.scheduler().timer_alloc(FUNC(microtouch_timer_callback)); microtouch.timer->adjust(attotime::from_hz(167*5), 0, attotime::from_hz(167*5)); + microtouch.format = FORMAT_UNKNOWN; + microtouch.mode = MODE_INACTIVE; + state_save_register_item(machine, "microtouch", NULL, 0, microtouch.reset_done); - state_save_register_item(machine, "microtouch", NULL, 0, microtouch.format_tablet); - state_save_register_item(machine, "microtouch", NULL, 0, microtouch.mode_inactive); - state_save_register_item(machine, "microtouch", NULL, 0, microtouch.mode_stream); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.last_touch_state); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.last_x); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.last_y); @@ -174,8 +200,8 @@ void microtouch_init(running_machine &machine, microtouch_tx_func tx_cb, microto state_save_register_item_array(machine, "microtouch", NULL, 0, microtouch.tx_buffer); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.tx_buffer_num); state_save_register_item(machine, "microtouch", NULL, 0, microtouch.tx_buffer_ptr); - state_save_register_item(machine, "microtouch", NULL, 0, microtouch.format_decimal); - + state_save_register_item(machine, "microtouch", NULL, 0, microtouch.format); + state_save_register_item(machine, "microtouch", NULL, 0, microtouch.mode); }; @@ -201,12 +227,15 @@ void microtouch_rx(int count, UINT8* data) // check command if ( microtouch_check_command( "MS", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) { - microtouch.mode_stream = 1; - microtouch.mode_inactive = 0; + microtouch.mode = MODE_STREAM; } else if ( microtouch_check_command( "MI", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) { - microtouch.mode_inactive = 1; + microtouch.mode = MODE_INACTIVE; + } + else if ( microtouch_check_command( "MP", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) + { + microtouch.mode = MODE_POINT; } else if ( microtouch_check_command( "R", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) { @@ -215,11 +244,11 @@ void microtouch_rx(int count, UINT8* data) } else if ( microtouch_check_command( "FT", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) { - microtouch.format_tablet = 1; + microtouch.format = FORMAT_TABLET; } else if ( microtouch_check_command( "FD", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) { - microtouch.format_decimal = 1; + microtouch.format = FORMAT_DECIMAL; } else if ( microtouch_check_command("OI", microtouch.rx_buffer_ptr, microtouch.rx_buffer ) ) { @@ -243,9 +272,17 @@ void microtouch_rx(int count, UINT8* data) } }; +static INPUT_CHANGED( microtouch_touch ) +{ + if ( newval && ( microtouch.mode == MODE_POINT ) ) + { + microtouch_send_touch_packet( field.machine() ); + } +} + INPUT_PORTS_START(microtouch) PORT_START("TOUCH") - PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME( "Touch screen" ) + PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME( "Touch screen" ) PORT_CHANGED( microtouch_touch, 0 ) PORT_START("TOUCH_X") PORT_BIT( 0x3fff, 0x2000, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(45) PORT_KEYDELTA(15) PORT_START("TOUCH_Y") |