src/mess/machine/thomson.c
| r2781 | r2782 | |
| 378 | 378 | |
| 379 | 379 | static READ8_HANDLER ( to7_timer_port_in ) |
| 380 | 380 | { |
| 381 | | int lightpen = (input_port_read_indexed(machine, THOM_INPUT_LIGHTPEN + 2 ) & 1) ? 2 : 0; |
| 381 | int lightpen = (input_port_read(machine, "lightpen_button") & 1) ? 2 : 0; |
| 382 | 382 | int cass = to7_get_cassette() ? 0x80 : 0; |
| 383 | 383 | return lightpen | cass; |
| 384 | 384 | } |
| r2781 | r2782 | |
| 474 | 474 | int keyline = pia_get_output_b( THOM_PIA_SYS ); |
| 475 | 475 | UINT8 val = 0xff; |
| 476 | 476 | int i; |
| 477 | char tag[12]; |
| 478 | |
| 477 | 479 | for ( i = 0; i < 8; i++ ) |
| 478 | 480 | { |
| 479 | 481 | if ( ! (keyline & (1 << i)) ) |
| 480 | | val &= input_port_read_indexed(machine, THOM_INPUT_KEYBOARD + i ); |
| 482 | { |
| 483 | sprintf(tag, "keyboard_%d", i); |
| 484 | val &= input_port_read(machine, tag); |
| 485 | } |
| 481 | 486 | } |
| 482 | 487 | return val; |
| 483 | 488 | } |
| r2781 | r2782 | |
| 769 | 774 | |
| 770 | 775 | READ8_HANDLER ( to7_modem_mea8000_r ) |
| 771 | 776 | { |
| 772 | | if ( input_port_read_indexed(machine, THOM_INPUT_MCONFIG ) & 1 ) |
| 777 | if ( input_port_read(machine, "mconfig") & 1 ) |
| 773 | 778 | return mea8000_r( machine, offset ); |
| 774 | 779 | else |
| 775 | 780 | { |
| r2781 | r2782 | |
| 785 | 790 | |
| 786 | 791 | WRITE8_HANDLER ( to7_modem_mea8000_w ) |
| 787 | 792 | { |
| 788 | | if ( input_port_read_indexed(machine, THOM_INPUT_MCONFIG ) & 1 ) |
| 793 | if ( input_port_read(machine, "mconfig") & 1 ) |
| 789 | 794 | mea8000_w( machine, offset, data ); |
| 790 | 795 | else |
| 791 | 796 | { |
| r2781 | r2782 | |
| 833 | 838 | static UINT8 to7_get_mouse_signal( void ) |
| 834 | 839 | { |
| 835 | 840 | UINT8 xa, xb, ya, yb; |
| 836 | | UINT16 dx = input_port_read_indexed(Machine, THOM_INPUT_GAME + 2 ); /* x axis */ |
| 837 | | UINT16 dy = input_port_read_indexed(Machine, THOM_INPUT_GAME + 3 ); /* y axis */ |
| 841 | UINT16 dx = input_port_read(Machine, "mouse_x"); /* x axis */ |
| 842 | UINT16 dy = input_port_read(Machine, "mouse_y"); /* y axis */ |
| 838 | 843 | xa = ((dx + 1) & 3) <= 1; |
| 839 | 844 | xb = (dx & 3) <= 1; |
| 840 | 845 | ya = ((dy + 1) & 3) <= 1; |
| r2781 | r2782 | |
| 854 | 859 | static READ8_HANDLER ( to7_game_porta_in ) |
| 855 | 860 | { |
| 856 | 861 | UINT8 data; |
| 857 | | if ( input_port_read_indexed(machine, THOM_INPUT_CONFIG ) & 1 ) |
| 862 | if ( input_port_read(machine, "config") & 1 ) |
| 858 | 863 | { |
| 859 | 864 | /* mouse */ |
| 860 | 865 | data = to7_get_mouse_signal() & 0x0c; /* XB, YB */ |
| 861 | | data |= input_port_read_indexed(machine, THOM_INPUT_GAME + 4 ) & 3; /* buttons */ |
| 866 | data |= input_port_read(machine, "mouse_button") & 3; /* buttons */ |
| 862 | 867 | } |
| 863 | 868 | else |
| 864 | 869 | { |
| 865 | 870 | /* joystick */ |
| 866 | | data = input_port_read_indexed(machine, THOM_INPUT_GAME ); |
| 871 | data = input_port_read(machine, "game_port_directions"); |
| 867 | 872 | /* bit 0=0 => P1 up bit 4=0 => P2 up |
| 868 | 873 | bit 1=0 => P1 down bit 5=0 => P2 down |
| 869 | 874 | bit 2=0 => P1 left bit 6=0 => P2 left |
| r2781 | r2782 | |
| 895 | 900 | static READ8_HANDLER ( to7_game_portb_in ) |
| 896 | 901 | { |
| 897 | 902 | UINT8 data; |
| 898 | | if ( input_port_read_indexed(machine, THOM_INPUT_CONFIG ) & 1 ) |
| 903 | if ( input_port_read(machine, "config") & 1 ) |
| 899 | 904 | { |
| 900 | 905 | /* mouse */ |
| 901 | 906 | UINT8 mouse = to7_get_mouse_signal(); |
| r2781 | r2782 | |
| 912 | 917 | /* bits 2-3: action buttons B (0=pressed) */ |
| 913 | 918 | /* bits 4-5: unused (ouput) */ |
| 914 | 919 | /* bits 0-1: unknown! */ |
| 915 | | data = input_port_read_indexed(machine, THOM_INPUT_GAME + 1 ); |
| 920 | data = input_port_read(machine, "game_port_buttons"); |
| 916 | 921 | } |
| 917 | 922 | return data; |
| 918 | 923 | } |
| r2781 | r2782 | |
| 949 | 954 | /* this should be called periodically */ |
| 950 | 955 | static TIMER_CALLBACK(to7_game_update_cb) |
| 951 | 956 | { |
| 952 | | if ( input_port_read_indexed(machine, THOM_INPUT_CONFIG ) & 1 ) |
| 957 | if ( input_port_read(machine, "config") & 1 ) |
| 953 | 958 | { |
| 954 | 959 | /* mouse */ |
| 955 | 960 | UINT8 mouse = to7_get_mouse_signal(); |
| r2781 | r2782 | |
| 959 | 964 | else |
| 960 | 965 | { |
| 961 | 966 | /* joystick */ |
| 962 | | UINT8 in = input_port_read_indexed(machine, THOM_INPUT_GAME ); |
| 967 | UINT8 in = input_port_read(machine, "game_port_buttons"); |
| 963 | 968 | pia_set_input_cb2( THOM_PIA_GAME, (in & 0x80) ? 1 : 0 ); /* P2 action A */ |
| 964 | 969 | pia_set_input_ca2( THOM_PIA_GAME, (in & 0x40) ? 1 : 0 ); /* P1 action A */ |
| 965 | 970 | pia_set_input_cb1( THOM_PIA_GAME, (in & 0x08) ? 1 : 0 ); /* P2 action B */ |
| r2781 | r2782 | |
| 1364 | 1369 | static READ8_HANDLER ( to770_sys_porta_in ) |
| 1365 | 1370 | { |
| 1366 | 1371 | /* keyboard */ |
| 1372 | char tag[12]; |
| 1367 | 1373 | int keyline = pia_get_output_b( THOM_PIA_SYS ) & 7; |
| 1368 | | return input_port_read_indexed(machine, THOM_INPUT_KEYBOARD + 7 - keyline ); |
| 1374 | |
| 1375 | sprintf(tag, "keyboard_%d", 7 - keyline); |
| 1376 | return input_port_read(machine, tag); |
| 1369 | 1377 | } |
| 1370 | 1378 | |
| 1371 | 1379 | |
| r2781 | r2782 | |
| 1646 | 1654 | { |
| 1647 | 1655 | return |
| 1648 | 1656 | (mo5_get_cassette() ? 0x80 : 0) | /* bit 7: cassette input */ |
| 1649 | | ((input_port_read_indexed(machine, THOM_INPUT_LIGHTPEN + 2 ) & 1) ? 0x20 : 0) |
| 1657 | ((input_port_read(machine, "lightpen_button") & 1) ? 0x20 : 0) |
| 1650 | 1658 | /* bit 5: lightpen button */; |
| 1651 | 1659 | } |
| 1652 | 1660 | |
| r2781 | r2782 | |
| 1664 | 1672 | UINT8 portb = pia_get_output_b( THOM_PIA_SYS ); |
| 1665 | 1673 | int col = (portb >> 1) & 7; /* key column */ |
| 1666 | 1674 | int lin = 7 - ((portb >> 4) & 7); /* key line */ |
| 1667 | | return ( input_port_read_indexed(machine, THOM_INPUT_KEYBOARD+lin ) & (1 << col) ) ? 0x80 : 0; |
| 1675 | char tag[12]; |
| 1676 | |
| 1677 | sprintf(tag, "keyboard_%d", lin); |
| 1678 | return ( input_port_read(machine, tag) & (1 << col) ) ? 0x80 : 0; |
| 1668 | 1679 | } |
| 1669 | 1680 | |
| 1670 | 1681 | |
| r2781 | r2782 | |
| 2324 | 2335 | static int to9_kbd_ktest ( void ) |
| 2325 | 2336 | { |
| 2326 | 2337 | int line, bit; |
| 2338 | UINT8 port; |
| 2339 | char tag[12]; |
| 2327 | 2340 | |
| 2328 | 2341 | for ( line = 0; line < 10; line++ ) |
| 2329 | 2342 | { |
| 2330 | | UINT8 port = input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + line ); |
| 2343 | sprintf(tag, "keyboard_%d", line); |
| 2344 | port = input_port_read(Machine, tag); |
| 2331 | 2345 | |
| 2332 | 2346 | if ( line == 7 || line == 9 ) |
| 2333 | 2347 | port |= 1; /* shift & control */ |
| r2781 | r2782 | |
| 2552 | 2566 | /* returns the ASCII code for the key, or 0 for no key */ |
| 2553 | 2567 | static int to9_kbd_get_key( void ) |
| 2554 | 2568 | { |
| 2555 | | int control = ! (input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + 7 ) & 1); |
| 2556 | | int shift = ! (input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + 9 ) & 1); |
| 2569 | int control = ! (input_port_read(Machine, "keyboard_7") & 1); |
| 2570 | int shift = ! (input_port_read(Machine, "keyboard_9") & 1); |
| 2557 | 2571 | int key = -1, line, bit; |
| 2572 | UINT8 port; |
| 2573 | char tag[12]; |
| 2558 | 2574 | |
| 2559 | 2575 | for ( line = 0; line < 10; line++ ) |
| 2560 | 2576 | { |
| 2561 | | UINT8 port = input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + line ); |
| 2577 | sprintf(tag, "keyboard_%d", line); |
| 2578 | port = input_port_read(Machine, tag); |
| 2562 | 2579 | |
| 2563 | 2580 | if ( line == 7 || line == 9 ) |
| 2564 | 2581 | port |= 1; /* shift & control */ |
| r2781 | r2782 | |
| 2649 | 2666 | |
| 2650 | 2667 | case 1: /* x axis */ |
| 2651 | 2668 | { |
| 2652 | | int newx = input_port_read_indexed(machine, THOM_INPUT_GAME + 2 ); |
| 2669 | int newx = input_port_read(machine, "mouse_x"); |
| 2653 | 2670 | UINT8 data = ( (newx - to9_mouse_x) & 0xf ) - 8; |
| 2654 | 2671 | to9_kbd_send( data, 1 ); |
| 2655 | 2672 | to9_mouse_x = newx; |
| r2781 | r2782 | |
| 2658 | 2675 | |
| 2659 | 2676 | case 2: /* y axis */ |
| 2660 | 2677 | { |
| 2661 | | int newy = input_port_read_indexed(machine, THOM_INPUT_GAME + 3 ); |
| 2678 | int newy = input_port_read(machine, "mouse_y"); |
| 2662 | 2679 | UINT8 data = ( (newy - to9_mouse_y) & 0xf ) - 8; |
| 2663 | 2680 | to9_kbd_send( data, 1 ); |
| 2664 | 2681 | to9_mouse_y = newy; |
| r2781 | r2782 | |
| 2667 | 2684 | |
| 2668 | 2685 | case 3: /* axis overflow & buttons */ |
| 2669 | 2686 | { |
| 2670 | | int b = input_port_read_indexed(machine, THOM_INPUT_GAME + 4 ); |
| 2687 | int b = input_port_read(machine, "mouse_button"); |
| 2671 | 2688 | UINT8 data = 0; |
| 2672 | 2689 | if ( b & 1 ) data |= 1; |
| 2673 | 2690 | if ( b & 2 ) data |= 4; |
| r2781 | r2782 | |
| 2961 | 2978 | static int to8_kbd_ktest ( void ) |
| 2962 | 2979 | { |
| 2963 | 2980 | int line, bit; |
| 2981 | UINT8 port; |
| 2982 | char tag[12]; |
| 2964 | 2983 | |
| 2965 | | if ( input_port_read_indexed(Machine, THOM_INPUT_CONFIG ) & 2 ) |
| 2984 | if ( input_port_read(Machine, "config") & 2 ) |
| 2966 | 2985 | return 0; /* disabled */ |
| 2967 | 2986 | |
| 2968 | 2987 | for ( line = 0; line < 10; line++ ) |
| 2969 | 2988 | { |
| 2970 | | UINT8 port = input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + line ); |
| 2989 | sprintf(tag, "keyboard_%d", line); |
| 2990 | port = input_port_read(Machine, tag); |
| 2971 | 2991 | |
| 2972 | 2992 | if ( line == 7 || line == 9 ) |
| 2973 | 2993 | port |= 1; /* shift & control */ |
| r2781 | r2782 | |
| 2987 | 3007 | /* keyboard scan & return keycode (or -1) */ |
| 2988 | 3008 | static int to8_kbd_get_key( void ) |
| 2989 | 3009 | { |
| 2990 | | int control = (input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + 7 ) & 1) ? 0 : 0x100; |
| 2991 | | int shift = (input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + 9 ) & 1) ? 0 : 0x080; |
| 3010 | int control = (input_port_read(Machine, "keyboard_7") & 1) ? 0 : 0x100; |
| 3011 | int shift = (input_port_read(Machine, "keyboard_9") & 1) ? 0 : 0x080; |
| 2992 | 3012 | int key = -1, line, bit; |
| 2993 | | |
| 2994 | | if ( input_port_read_indexed(Machine, THOM_INPUT_CONFIG ) & 2 ) |
| 3013 | UINT8 port; |
| 3014 | char tag[12]; |
| 3015 | |
| 3016 | if ( input_port_read(Machine, "config") & 2 ) |
| 2995 | 3017 | return -1; /* disabled */ |
| 2996 | 3018 | |
| 2997 | 3019 | for ( line = 0; line < 10; line++ ) |
| 2998 | 3020 | { |
| 2999 | | UINT8 port = input_port_read_indexed(Machine, THOM_INPUT_KEYBOARD + line ); |
| 3021 | sprintf(tag, "keyboard_%d", line); |
| 3022 | port = input_port_read(Machine, tag); |
| 3000 | 3023 | |
| 3001 | 3024 | if ( line == 7 || line == 9 ) |
| 3002 | 3025 | port |= 1; /* shift & control */ |
| r2781 | r2782 | |
| 3712 | 3735 | |
| 3713 | 3736 | static READ8_HANDLER ( to8_timer_port_in ) |
| 3714 | 3737 | { |
| 3715 | | int lightpen = (input_port_read_indexed(machine, THOM_INPUT_LIGHTPEN + 2 ) & 1) ? 2 : 0; |
| 3738 | int lightpen = (input_port_read(machine, "lightpen_button") & 1) ? 2 : 0; |
| 3716 | 3739 | int cass = to7_get_cassette() ? 0x80 : 0; |
| 3717 | 3740 | int dtr = (centronics_read_handshake( 0 ) & CENTRONICS_NOT_BUSY) ? 0 : 0x40; |
| 3718 | 3741 | int lock = to8_kbd_caps ? 0 : 8; /* undocumented! */ |
| r2781 | r2782 | |
| 3908 | 3931 | |
| 3909 | 3932 | static READ8_HANDLER ( to9p_timer_port_in ) |
| 3910 | 3933 | { |
| 3911 | | int lightpen = (input_port_read_indexed(machine, THOM_INPUT_LIGHTPEN + 2 ) & 1) ? 2 : 0; |
| 3934 | int lightpen = (input_port_read(machine, "lightpen_button") & 1) ? 2 : 0; |
| 3912 | 3935 | int cass = to7_get_cassette() ? 0x80 : 0; |
| 3913 | 3936 | int dtr = (centronics_read_handshake( 0 ) & CENTRONICS_NOT_BUSY) ? 0 : 0x40; |
| 3914 | 3937 | return lightpen | cass | dtr; |
| r2781 | r2782 | |
| 4248 | 4271 | static TIMER_CALLBACK(mo6_game_update_cb) |
| 4249 | 4272 | { |
| 4250 | 4273 | /* unlike the TO8, CB1 & CB2 are not connected to buttons */ |
| 4251 | | if ( input_port_read_indexed(machine, THOM_INPUT_CONFIG ) & 1 ) |
| 4274 | if ( input_port_read(machine, "config") & 1 ) |
| 4252 | 4275 | { |
| 4253 | 4276 | UINT8 mouse = to7_get_mouse_signal(); |
| 4254 | 4277 | pia_set_input_ca1( THOM_PIA_GAME, mouse & 1 ); /* XA */ |
| r2781 | r2782 | |
| 4257 | 4280 | else |
| 4258 | 4281 | { |
| 4259 | 4282 | /* joystick */ |
| 4260 | | UINT8 in = input_port_read_indexed(machine, THOM_INPUT_GAME ); |
| 4283 | UINT8 in = input_port_read(machine, "game_port_buttons"); |
| 4261 | 4284 | pia_set_input_ca1( THOM_PIA_GAME, in & 0x04 ); /* P1 action B */ |
| 4262 | 4285 | pia_set_input_ca2( THOM_PIA_GAME, in & 0x40 ); /* P1 action A */ |
| 4263 | 4286 | } |
| r2781 | r2782 | |
| 4297 | 4320 | return |
| 4298 | 4321 | (mo5_get_cassette() ? 0x80 : 0) | /* bit 7: cassette input */ |
| 4299 | 4322 | 8 | /* bit 3: kbd-line float up to 1 */ |
| 4300 | | ((input_port_read_indexed(machine, THOM_INPUT_LIGHTPEN + 2 ) & 1) ? 2 : 0); |
| 4323 | ((input_port_read(machine, "lightpen_button") & 1) ? 2 : 0); |
| 4301 | 4324 | /* bit 1: lightpen button */; |
| 4302 | 4325 | } |
| 4303 | 4326 | |
| r2781 | r2782 | |
| 4310 | 4333 | UINT8 portb = pia_get_output_b( THOM_PIA_SYS ); |
| 4311 | 4334 | int col = (portb >> 4) & 7; /* B bits 4-6: kbd column */ |
| 4312 | 4335 | int lin = (portb >> 1) & 7; /* B bits 1-3: kbd line */ |
| 4336 | char tag[12]; |
| 4313 | 4337 | |
| 4314 | 4338 | if ( ! (porta & 8) ) |
| 4315 | 4339 | lin = 8; /* A bit 3: 9-th kbd line select */ |
| 4316 | 4340 | |
| 4341 | sprintf(tag, "keyboard_%d", lin); |
| 4317 | 4342 | return |
| 4318 | | ( input_port_read_indexed(machine, THOM_INPUT_KEYBOARD + lin ) & (1 << col) ) |
| 4319 | | ? 0x80 : 0; /* bit 7: key up */ |
| 4343 | ( input_port_read(machine, tag) & (1 << col) ) ? 0x80 : 0; |
| 4344 | /* bit 7: key up */ |
| 4320 | 4345 | } |
| 4321 | 4346 | |
| 4322 | 4347 | |
| r2781 | r2782 | |
| 4732 | 4757 | UINT8 portb = pia_get_output_b( THOM_PIA_SYS ); |
| 4733 | 4758 | int col = (portb >> 4) & 7; /* B bits 4-6: kbd column */ |
| 4734 | 4759 | int lin = (portb >> 1) & 7; /* B bits 1-3: kbd line */ |
| 4760 | char tag[12]; |
| 4761 | |
| 4762 | sprintf(tag, "keyboard_%d", lin); |
| 4735 | 4763 | return |
| 4736 | | ( input_port_read_indexed(machine, THOM_INPUT_KEYBOARD + lin ) & (1 << col) ) |
| 4737 | | ? 0x80 : 0; /* bit 7: key up */ |
| 4764 | ( input_port_read(machine, tag) & (1 << col) ) ? 0x80 : 0; |
| 4765 | /* bit 7: key up */ |
| 4738 | 4766 | } |
| 4739 | 4767 | |
| 4740 | 4768 | |