Previous 15994 Revisions Next

r1409 Saturday 15th December, 2007 at 14:12:01 UTC by Dirk Best
[SYM1] Cleaned up keyboard code, changed 74145 to use callbacks.
[src/mess/drivers]sym1.c
[src/mess/machine]74145.c 74145.h sym1.c

src/mess/machine/74145.c
r1408r1409
6363typedef struct _ttl74145_state ttl74145_state;
6464struct _ttl74145_state
6565{
66   /* Pointer to our interface */
67   const ttl74145_interface *intf;
68   
69   /* Decoded number */
6670   UINT16 number;
6771};
6872 
r1408r1409
8286*****************************************************************************/
8387 
8488 
89/* Config */
90void ttl74145_config(int which, const ttl74145_interface *intf)
91{
92   assert_always(mame_get_phase(Machine) == MAME_PHASE_INIT,
93      "Can only call ttl74145_config at init time!");
94   assert_always(which < MAX_74145,
95      "'which' exceeds maximum number of configured 74145s!");
96 
97   /* Assign interface */
98   ttl74145[which].intf = intf;
99   
100   /* Initialize */
101   ttl74145_reset(which);
102}
103 
104 
85105/* Reset */
86106void ttl74145_reset(int which)
87107{
r1408r1409
92112/* Data Write */
93113void ttl74145_write(int which, offs_t offset, UINT8 data)
94114{
95   ttl74145[which].number = bcd_2_dec(data & 0x0f);
115   /* Decode number */
116   UINT16 new_number = bcd_2_dec(data & 0x0f);
117   
118   /* Call output callbacks if the number changed */
119   if (new_number != ttl74145[which].number)
120   {
121      const ttl74145_interface *i = ttl74145[which].intf;
122       
123      if (i->output_line_0) i->output_line_0(new_number == 0);
124      if (i->output_line_1) i->output_line_1(new_number == 1);
125      if (i->output_line_2) i->output_line_2(new_number == 2);
126      if (i->output_line_3) i->output_line_3(new_number == 3);
127      if (i->output_line_4) i->output_line_4(new_number == 4);
128      if (i->output_line_5) i->output_line_5(new_number == 5);
129      if (i->output_line_6) i->output_line_6(new_number == 6);
130      if (i->output_line_7) i->output_line_7(new_number == 7);
131      if (i->output_line_8) i->output_line_8(new_number == 8);
132      if (i->output_line_9) i->output_line_9(new_number == 9);             
133   }
134   
135   /* Update state */
136   ttl74145[which].number = new_number;
96137}
97138 
98139 
99int ttl74145_output_0(int which) { return ttl74145[which].number == 0; }
100int ttl74145_output_1(int which) { return ttl74145[which].number == 1; }
101int ttl74145_output_2(int which) { return ttl74145[which].number == 2; }
102int ttl74145_output_3(int which) { return ttl74145[which].number == 3; }
103int ttl74145_output_4(int which) { return ttl74145[which].number == 4; }
104int ttl74145_output_5(int which) { return ttl74145[which].number == 5; }
105int ttl74145_output_6(int which) { return ttl74145[which].number == 6; }
106int ttl74145_output_7(int which) { return ttl74145[which].number == 7; }
107int ttl74145_output_8(int which) { return ttl74145[which].number == 8; }
108int ttl74145_output_9(int which) { return ttl74145[which].number == 9; }
109 
110 
111140WRITE8_HANDLER( ttl74145_0_w ) { ttl74145_write(0, offset, data); }
141READ16_HANDLER( ttl74145_0_r ) { return ttl74145[0].number; }
src/mess/machine/74145.h
r1408r1409
99 
1010#include "driver.h"
1111 
12/* Interface */
13typedef struct _ttl74145_interface ttl74145_interface;
14struct _ttl74145_interface
15{
16   /* Outputs */
17   void (*output_line_0)(int state);
18   void (*output_line_1)(int state);
19   void (*output_line_2)(int state);
20   void (*output_line_3)(int state);
21   void (*output_line_4)(int state);
22   void (*output_line_5)(int state);
23   void (*output_line_6)(int state);
24   void (*output_line_7)(int state);
25   void (*output_line_8)(int state);
26   void (*output_line_9)(int state);
27};
28 
1229/* Configuration */
30void ttl74145_config(int which, const ttl74145_interface *intf);
1331void ttl74145_reset(int which);
1432 
15/* Output pin states */
16int ttl74145_output_0(int which);
17int ttl74145_output_1(int which);
18int ttl74145_output_2(int which);
19int ttl74145_output_3(int which);
20int ttl74145_output_4(int which);
21int ttl74145_output_5(int which);
22int ttl74145_output_6(int which);
23int ttl74145_output_7(int which);
24int ttl74145_output_8(int which);
25int ttl74145_output_9(int which);
26 
2733/* Standard handlers */
2834WRITE8_HANDLER( ttl74145_0_w );
35READ16_HANDLER( ttl74145_0_r );
2936 
3037#endif /*TTL74145_H_*/
src/mess/machine/sym1.c
r1408r1409
2020#include "sound/speaker.h"
2121
2222
23#define LED_REFRESH_DELAY  ATTOTIME_IN_USEC(70)
24
25
2326static UINT8 riot_port_a, riot_port_b;
24emu_timer *led_update;
27static emu_timer *led_update;
2528
2629
30
2731/******************************************************************************
2832 6532 RIOT
2933******************************************************************************/
3034
3135
32static TIMER_CALLBACK( led_refresh )
36void sym1_74145_output_0_w(int state)
3337{
34   /* update digits depending on the status of the output lines */
35   if (ttl74145_output_0(0)) output_set_digit_value(0, riot_port_a);
36   if (ttl74145_output_1(0)) output_set_digit_value(1, riot_port_a);
37   if (ttl74145_output_2(0)) output_set_digit_value(2, riot_port_a);
38   if (ttl74145_output_3(0)) output_set_digit_value(3, riot_port_a);
39   if (ttl74145_output_4(0)) output_set_digit_value(4, riot_port_a);
40   if (ttl74145_output_5(0)) output_set_digit_value(5, riot_port_a);   
38   if (state) timer_adjust(led_update, LED_REFRESH_DELAY, 0, attotime_never);
4139}
4240
4341
44static void sym1_led_w(void)
42void sym1_74145_output_1_w(int state)
4543{
46   timer_adjust(led_update, ATTOTIME_IN_USEC(70), 0, attotime_never);
44   if (state) timer_adjust(led_update, LED_REFRESH_DELAY, 1, attotime_never);
4745}
4846
4947
50static READ8_HANDLER( sym1_riot_a_r )
48void sym1_74145_output_2_w(int state)
5149{
52   int data = 0xff;
50   if (state) timer_adjust(led_update, LED_REFRESH_DELAY, 2, attotime_never);
51}
5352
54   if (!(riot_port_a & 0x80)) {
55      data &= input_port_0_r(0);
56   }
5753
58   if (!(riot_port_b & 0x01)) {
59      data &= input_port_1_r(1);
60   }
54void sym1_74145_output_3_w(int state)
55{
56   if (state) timer_adjust(led_update, LED_REFRESH_DELAY, 3, attotime_never);
57}
6158
62   if (!(riot_port_b & 0x02)) {
63      data &= input_port_2_r(1);
64   }
6559
66   if (!(riot_port_b & 0x04)) {
67      data &= input_port_3_r(1);
68   }
60void sym1_74145_output_4_w(int state)
61{
62   if (state) timer_adjust(led_update, LED_REFRESH_DELAY, 4, attotime_never);
63}
6964
70   if ( ((riot_port_a ^ 0xff) & (input_port_0_r(0) ^ 0xff)) & 0x3f )
65
66void sym1_74145_output_5_w(int state)
67{
68   if (state) timer_adjust(led_update, LED_REFRESH_DELAY, 5, attotime_never);
69}
70
71
72static TIMER_CALLBACK( led_refresh )
73{
74   output_set_digit_value(param, riot_port_a);
75}
76
77
78/* The speaker is connected to output 6 of the 74145 */
79void sym1_74145_output_6_w(int state)
80{
81   speaker_level_w(0, state);   
82}
83
84
85static READ8_HANDLER( sym1_riot_a_r )
86{
87   int data = 0x7f;
88
89   /* scan keypad rows */
90   if (!(riot_port_a & 0x80)) data &= readinputportbytag("ROW-0");
91   if (!(riot_port_b & 0x01)) data &= readinputportbytag("ROW-1");
92   if (!(riot_port_b & 0x02)) data &= readinputportbytag("ROW-2");
93   if (!(riot_port_b & 0x04)) data &= readinputportbytag("ROW-3");
94
95   /* determine column */
96   if ( ((riot_port_a ^ 0xff) & (readinputportbytag("ROW-0") ^ 0xff)) & 0x7f )
7197      data &= ~0x80;
7298
7399   return data;
r1408r1409
78104{
79105   int data = 0xff;
80106
81   if ( ((riot_port_a ^ 0xff) & (input_port_1_r(0) ^ 0xff)) & 0x3f )
107   /* determine column */
108   if ( ((riot_port_a ^ 0xff) & (readinputportbytag("ROW-1") ^ 0xff)) & 0x7f )
82109      data &= ~1;
83110
84   if ( ((riot_port_a ^ 0xff) & (input_port_2_r(0) ^ 0xff)) & 0x3f )
111   if ( ((riot_port_a ^ 0xff) & (readinputportbytag("ROW-2") ^ 0xff)) & 0x3f )
85112      data &= ~2;
86113
87   if ( ((riot_port_a ^ 0xff) & (input_port_3_r(0) ^ 0xff)) & 0x3f )
114   if ( ((riot_port_a ^ 0xff) & (readinputportbytag("ROW-3") ^ 0xff)) & 0x1f )
88115      data &= ~4;
89116
90117   data &= ~0x80; // else hangs 8b02
r1408r1409
99126
100127   /* save for later use */
101128   riot_port_a = data;
102
103   /* refresh the leds */
104   sym1_led_w();
105129}
106130
107131
r1408r1409
112136   /* save for later use */
113137   riot_port_b = data;
114138
115   /* first 4 output pins are connected to the 74145 */
139   /* first 4 pins are connected to the 74145 */
116140   ttl74145_0_w(0, data & 0x0f);
117   
118   /* speaker is connected to output 6 of the 74145 */
119   speaker_level_w(0, ttl74145_output_6(0));
120
121   /* refresh the leds */
122   sym1_led_w();
123141}
124142
125143
r1408r1409
132150};
133151
134152
153static const ttl74145_interface ttl74145_intf =
154{
155   sym1_74145_output_0_w,  /* connected to DS0 */
156   sym1_74145_output_1_w,  /* connected to DS1 */
157   sym1_74145_output_2_w,  /* connected to DS2 */
158   sym1_74145_output_3_w,  /* connected to DS3 */
159   sym1_74145_output_4_w,  /* connected to DS4 */
160   sym1_74145_output_5_w,  /* connected to DS5 */
161   sym1_74145_output_6_w,  /* connected to the speaker */
162   NULL,                   /* not connected */
163   NULL,                   /* not connected */
164   NULL                    /* not connected */
165};
135166
167
136168/******************************************************************************
137169 6522 VIA
138170******************************************************************************/
r1408r1409
256288   r6532_set_clock(0, OSC_Y1);
257289   r6532_reset(0);
258290   
291   /* configure 74145 */
292   ttl74145_config(0, &ttl74145_intf);
293   
259294   /* allocate a timer to refresh the led display */
260295   led_update = timer_alloc(led_refresh, NULL);
261296}
src/mess/drivers/sym1.c
r1408r1409
5555
5656
5757static INPUT_PORTS_START( sym1 )
58   PORT_START         /* IN0 */
59   PORT_BIT(0x01, 0x01, IPT_KEYBOARD) PORT_NAME("0     USR0") PORT_CODE(KEYCODE_0)
60   PORT_BIT(0x02, 0x02, IPT_KEYBOARD) PORT_NAME("4     USR4") PORT_CODE(KEYCODE_4)
61   PORT_BIT(0x04, 0x04, IPT_KEYBOARD) PORT_NAME("8     JUMP") PORT_CODE(KEYCODE_8)
62   PORT_BIT(0x08, 0x08, IPT_KEYBOARD) PORT_NAME("C     CALC") PORT_CODE(KEYCODE_C)
63   PORT_BIT(0x10, 0x10, IPT_KEYBOARD) PORT_NAME("CR    S DBL") PORT_CODE(KEYCODE_ENTER)
64   PORT_BIT(0x20, 0x20, IPT_KEYBOARD) PORT_NAME("GO    LD P") PORT_CODE(KEYCODE_F3)
65   PORT_BIT(0x40, 0x40, IPT_KEYBOARD) PORT_NAME("LD 2  LD 1") PORT_CODE(KEYCODE_F1)
66   PORT_BIT(0x80, 0x80, IPT_UNUSED )
58   PORT_START_TAG("ROW-0")
59   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("0     USR 0") PORT_CODE(KEYCODE_0)
60   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("4     USR 4") PORT_CODE(KEYCODE_4)
61   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("8     JUMP")  PORT_CODE(KEYCODE_8)
62   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("C     CALC")  PORT_CODE(KEYCODE_C)
63   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("CR    S DBL") PORT_CODE(KEYCODE_ENTER)
64   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("GO    LD P")  PORT_CODE(KEYCODE_F3)
65   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("LD 2  LD 1")  PORT_CODE(KEYCODE_F1)
66   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_UNUSED)
6767
68   PORT_START         /* IN1 */
69   PORT_BIT(0x01, 0x01, IPT_KEYBOARD) PORT_NAME("1     USR1") PORT_CODE(KEYCODE_1)
70   PORT_BIT(0x02, 0x02, IPT_KEYBOARD) PORT_NAME("5     USR5") PORT_CODE(KEYCODE_5)
71   PORT_BIT(0x04, 0x04, IPT_KEYBOARD) PORT_NAME("9     VER") PORT_CODE(KEYCODE_9)
72   PORT_BIT(0x08, 0x08, IPT_KEYBOARD) PORT_NAME("D     DEP") PORT_CODE(KEYCODE_D)
73   PORT_BIT(0x10, 0x10, IPT_KEYBOARD) PORT_NAME("-     +") PORT_CODE(KEYCODE_MINUS)
74   PORT_BIT(0x20, 0x20, IPT_KEYBOARD) PORT_NAME("REG   SAV P") PORT_CODE(KEYCODE_F4)
75   PORT_BIT(0x40, 0x40, IPT_KEYBOARD) PORT_NAME("SAV 2 SAV 1") PORT_CODE(KEYCODE_F2)
76   PORT_BIT(0x80, 0x80, IPT_UNUSED )
68   PORT_START_TAG("ROW-1")
69   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("1     USR 1") PORT_CODE(KEYCODE_1)
70   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("5     USR 5") PORT_CODE(KEYCODE_5)
71   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("9     VER")   PORT_CODE(KEYCODE_9)
72   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("D     DEP")   PORT_CODE(KEYCODE_D)
73   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("-     +")     PORT_CODE(KEYCODE_MINUS)
74   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("REG   SAV P") PORT_CODE(KEYCODE_F4)
75   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("SAV 2 SAV 1") PORT_CODE(KEYCODE_F2)
76   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_UNUSED )
7777
78   PORT_START         /* IN2 */
79   PORT_BIT(0x01, 0x01, IPT_KEYBOARD) PORT_NAME("2     USR2") PORT_CODE(KEYCODE_2)
80   PORT_BIT(0x02, 0x02, IPT_KEYBOARD) PORT_NAME("6     USR6") PORT_CODE(KEYCODE_6)
81   PORT_BIT(0x04, 0x04, IPT_KEYBOARD) PORT_NAME("A     ASCII") PORT_CODE(KEYCODE_A)
82   PORT_BIT(0x08, 0x08, IPT_KEYBOARD) PORT_NAME("E     EXEC") PORT_CODE(KEYCODE_E)
83   PORT_BIT(0x10, 0x10, IPT_KEYBOARD) PORT_NAME("Right Left") PORT_CODE(KEYCODE_RIGHT) PORT_CODE(KEYCODE_LEFT)
84   PORT_BIT(0x20, 0x20, IPT_KEYBOARD) PORT_NAME("MEM   WP") PORT_CODE(KEYCODE_F5)
85   PORT_BIT(0xc0, 0xc0, IPT_UNUSED )
78   PORT_START_TAG("ROW-2")
79   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("2     USR 2") PORT_CODE(KEYCODE_2)
80   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("6     USR 6") PORT_CODE(KEYCODE_6)
81   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("A     ASCII") PORT_CODE(KEYCODE_A)
82   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("E     EXEC")  PORT_CODE(KEYCODE_E)
83   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("\xE2\x86\x92     \xE2\x86\x90") PORT_CODE(KEYCODE_RIGHT) PORT_CODE(KEYCODE_LEFT)
84   PORT_BIT(0x20, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("MEM   WP")    PORT_CODE(KEYCODE_F5)
85   PORT_BIT(0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
8686
87   PORT_START         /* IN3 */
88   PORT_BIT(0x01, 0x01, IPT_KEYBOARD) PORT_NAME("3     USR3") PORT_CODE(KEYCODE_3)
89   PORT_BIT(0x02, 0x02, IPT_KEYBOARD) PORT_NAME("7     USR7") PORT_CODE(KEYCODE_7)
90   PORT_BIT(0x04, 0x04, IPT_KEYBOARD) PORT_NAME("B     B MOV") PORT_CODE(KEYCODE_B)
91   PORT_BIT(0x08, 0x08, IPT_KEYBOARD) PORT_NAME("F     FILL") PORT_CODE(KEYCODE_F)
92   PORT_BIT(0x10, 0x10, IPT_KEYBOARD) PORT_NAME("SHIFT") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT)
93   PORT_BIT(0xe0, 0xe0, IPT_UNUSED )
87   PORT_START_TAG("ROW-3")
88   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("3     USR 3") PORT_CODE(KEYCODE_3)
89   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("7     USR 7") PORT_CODE(KEYCODE_7)
90   PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("B     B MOV") PORT_CODE(KEYCODE_B)
91   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F     FILL")  PORT_CODE(KEYCODE_F)
92   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("SHIFT")       PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT)
93   PORT_BIT(0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
9494
9595   PORT_START         /* IN4 */
96   PORT_BIT(0x80, 0x80, IPT_KEYBOARD) PORT_NAME("DEBUG OFF") PORT_CODE(KEYCODE_F6)
97   PORT_BIT(0x40, 0x40, IPT_KEYBOARD) PORT_NAME("DEBUG ON") PORT_CODE(KEYCODE_F7)
96   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("DEBUG OFF") PORT_CODE(KEYCODE_F6)
97   PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("DEBUG ON")  PORT_CODE(KEYCODE_F7)
9898   
9999   PORT_START_TAG("WP")
100100   PORT_DIPNAME(0x01, 0x01, "6532 RAM WP")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team