@@ -60,7 +60,7 @@ class servicet_state : public driver_device
60
60
servicet_state (const machine_config &mconfig, device_type type, const char *tag) :
61
61
driver_device (mconfig, type, tag),
62
62
m_maincpu (*this , " maincpu" ),
63
- m_i2cmem (*this , " i2cmem " ),
63
+ m_i2cmem (*this , " eeprom " ),
64
64
m_lcd (*this , " hd44780" ),
65
65
m_io_keys (*this , " IN%u" , 0U )
66
66
{ }
@@ -89,7 +89,7 @@ class servicet_state : public driver_device
89
89
uint8_t m_port3 = 0xff ; // Port 3 output latch
90
90
uint8_t m_lcd_data = 0 ; // LCD data bus
91
91
92
- // I2C debugging state
92
+ // I2C debugging state
93
93
bool m_last_scl = true ;
94
94
bool m_last_sda = true ;
95
95
uint32_t m_i2c_bit_count = 0 ;
@@ -112,19 +112,19 @@ void servicet_state::servicet_io(address_map &map)
112
112
113
113
static INPUT_PORTS_START ( servicet )
114
114
PORT_START(" IN0" ) // Column 0 (P1.0 = 0)
115
- PORT_BIT( 0x10 , IP_ACTIVE_LOW , IPT_KEYPAD) PORT_NAME(" OK" ) PORT_CODE(KEYCODE_ENTER) // Row 0
116
- PORT_BIT( 0x20 , IP_ACTIVE_LOW , IPT_KEYPAD) PORT_NAME(" F4" ) PORT_CODE(KEYCODE_F4) // Row 1
117
- PORT_BIT( 0x40 , IP_ACTIVE_LOW , IPT_JOYSTICK_UP) PORT_4WAY // Row 2
115
+ PORT_BIT( 0x10 , IP_ACTIVE_HIGH , IPT_KEYPAD) PORT_NAME(" OK" ) PORT_CODE(KEYCODE_ENTER) // Row 0
116
+ PORT_BIT( 0x20 , IP_ACTIVE_HIGH , IPT_KEYPAD) PORT_NAME(" F4" ) PORT_CODE(KEYCODE_F4) // Row 1
117
+ PORT_BIT( 0x40 , IP_ACTIVE_HIGH , IPT_JOYSTICK_UP) PORT_4WAY // Row 2
118
118
119
119
PORT_START(" IN1" ) // Column 1 (P1.1 = 0)
120
- PORT_BIT( 0x10 , IP_ACTIVE_LOW , IPT_JOYSTICK_LEFT) PORT_4WAY // Row 0
121
- PORT_BIT( 0x20 , IP_ACTIVE_LOW , IPT_JOYSTICK_RIGHT) PORT_4WAY // Row 1
122
- PORT_BIT( 0x40 , IP_ACTIVE_LOW , IPT_JOYSTICK_DOWN) PORT_4WAY // Row 2
120
+ PORT_BIT( 0x10 , IP_ACTIVE_HIGH , IPT_JOYSTICK_LEFT) PORT_4WAY // Row 0
121
+ PORT_BIT( 0x20 , IP_ACTIVE_HIGH , IPT_JOYSTICK_RIGHT) PORT_4WAY // Row 1
122
+ PORT_BIT( 0x40 , IP_ACTIVE_HIGH , IPT_JOYSTICK_DOWN) PORT_4WAY // Row 2
123
123
124
124
PORT_START(" IN2" ) // Column 2 (P1.2 = 0)
125
- PORT_BIT( 0x10 , IP_ACTIVE_LOW , IPT_KEYPAD) PORT_NAME(" F3" ) PORT_CODE(KEYCODE_F3) // Row 0
126
- PORT_BIT( 0x20 , IP_ACTIVE_LOW , IPT_KEYPAD) PORT_NAME(" F1" ) PORT_CODE(KEYCODE_F1) // Row 1
127
- PORT_BIT( 0x40 , IP_ACTIVE_LOW , IPT_KEYPAD) PORT_NAME(" F2" ) PORT_CODE(KEYCODE_F2) // Row 2
125
+ PORT_BIT( 0x10 , IP_ACTIVE_HIGH , IPT_KEYPAD) PORT_NAME(" F3" ) PORT_CODE(KEYCODE_F3) // Row 0
126
+ PORT_BIT( 0x20 , IP_ACTIVE_HIGH , IPT_KEYPAD) PORT_NAME(" F1" ) PORT_CODE(KEYCODE_F1) // Row 1
127
+ PORT_BIT( 0x40 , IP_ACTIVE_HIGH , IPT_KEYPAD) PORT_NAME(" F2" ) PORT_CODE(KEYCODE_F2) // Row 2
128
128
INPUT_PORTS_END
129
129
130
130
void servicet_state::machine_start()
@@ -143,23 +143,79 @@ void servicet_state::machine_reset()
143
143
144
144
uint8_t servicet_state::port1_r ()
145
145
{
146
- return m_port1;
146
+ uint8_t data = m_port1; // Start with what was written to port1
147
+
148
+ // Handle key matrix scanning - bidirectional
149
+ // CPU drives lines HIGH and checks if connected lines are also HIGH = button pressed
150
+
151
+ // Column-to-Row scanning: When columns (P1.0-P1.2) are driven HIGH
152
+ for (int col = 0 ; col < 3 ; col++)
153
+ {
154
+ if (m_port1 & (1 << col)) // Column is driven HIGH
155
+ {
156
+ uint8_t keys = m_io_keys[col]->read ();
157
+ // If a key is pressed, the corresponding row line will also be HIGH
158
+ // Apply pressed keys to the row bits (bits 4, 5, 6)
159
+ data |= (keys & 0x70 ); // Mask to only row bits (4,5,6)
160
+ }
161
+ }
162
+
163
+ // Row-to-Column scanning: When rows (P1.4-P1.6) are driven HIGH
164
+ for (int row = 0 ; row < 3 ; row++)
165
+ {
166
+ if (m_port1 & (1 << (row + 4 ))) // Row is driven HIGH (bits 4,5,6)
167
+ {
168
+ // Check all columns for this row
169
+ for (int col = 0 ; col < 3 ; col++)
170
+ {
171
+ uint8_t keys = m_io_keys[col]->read ();
172
+ if (keys & (1 << (row + 4 ))) // Key pressed in this row
173
+ {
174
+ data |= (1 << col); // Set corresponding column bit HIGH
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ LOG (" Port1 read: out=%02X, in=%02X\n " , m_port1, data);
181
+ return data;
147
182
}
148
183
149
184
void servicet_state::port1_w (uint8_t data)
150
185
{
151
186
m_port1 = data;
152
- LOG (" Scanning col/row : %02X\n " , data);
187
+ LOG (" Port1 write : %02X (scanning) \n " , data);
153
188
}
154
189
155
190
uint8_t servicet_state::port3_r ()
156
191
{
157
- return m_port3;
192
+ uint8_t data = m_port3;
193
+
194
+ // Read SDA line from I2C EEPROM
195
+ bool sda_state = m_i2cmem->read_sda ();
196
+ if (sda_state)
197
+ data |= PORT_3_SDA;
198
+ else
199
+ data &= ~PORT_3_SDA;
200
+ LOG (" Port3 read: %02X \n " , data);
201
+ return data;
158
202
}
159
203
160
204
void servicet_state::port3_w (uint8_t data)
161
205
{
206
+ uint8_t changed = m_port3 ^ data;
162
207
m_port3 = data;
208
+
209
+ // Handle I2C signals to EEPROM
210
+ if (changed & (PORT_3_SDA | PORT_3_SCL))
211
+ {
212
+ bool scl = (data & PORT_3_SCL) != 0 ;
213
+ bool sda = (data & PORT_3_SDA) != 0 ;
214
+
215
+ // Update I2C EEPROM signals
216
+ m_i2cmem->write_scl (scl);
217
+ m_i2cmem->write_sda (sda);
218
+ }
163
219
}
164
220
165
221
uint8_t servicet_state::lcd_bus_r (offs_t offset)
@@ -211,6 +267,8 @@ void servicet_state::lcd_bus_w(offs_t offset, uint8_t data)
211
267
m_lcd->e_w (1 );
212
268
m_lcd->e_w (0 );
213
269
}
270
+ } else if (offset == 0x4000 ){
271
+ // LOG("GSG write: %02X \n", data, offset);
214
272
} else {
215
273
LOG (" IO write: %02X to %04X\n " , data, offset);
216
274
}
@@ -227,8 +285,8 @@ void servicet_state::servicet(machine_config &config)
227
285
m_maincpu->port_in_cb <3 >().set (FUNC (servicet_state::port3_r));
228
286
m_maincpu->port_out_cb <3 >().set (FUNC (servicet_state::port3_w));
229
287
230
- // I2C EEPROM: 24C16 (2KB)
231
- I2C_24C16 (config, m_i2cmem );
288
+ // I2C EEPROM: 24C16 (2KB) - connected to P3.4 (SDA) and P3.5 (SCL)
289
+ I2C_24C16 (config, " eeprom " );
232
290
233
291
// LCD4002A
234
292
screen_device &screen (SCREEN (config, " screen" , SCREEN_TYPE_LCD));
@@ -250,7 +308,10 @@ void servicet_state::servicet(machine_config &config)
250
308
251
309
ROM_START ( servicet )
252
310
ROM_REGION ( 0x8000 , " maincpu" , 0 )
253
- ROM_LOAD ( " Service-Tastatur V3.3 EPROM.bin" , 0x0000 , 0x8000 , CRC(8eb161c4) SHA1(d44f3b38e75e1095487893d8b30c4e3212c1a143) )
311
+ ROM_LOAD ( " service_tastatur_v3.3.u3" , 0x0000 , 0x8000 , CRC(8eb161c4) SHA1(d44f3b38e75e1095487893d8b30c4e3212c1a143) )
312
+
313
+ ROM_REGION (0x800 , " eeprom" , 0 )
314
+ ROM_LOAD (" 24cs16.u15" , 0x000 , 0x800 , CRC(ac5f7095) SHA1(8cce7046b122346ddc2400e03405794e0d919413)) // Atmel 24CS16
254
315
ROM_END
255
316
256
317
} // anonymous namespace
0 commit comments