Skip to content

Commit a281068

Browse files
committed
doesnt work
1 parent e5a0981 commit a281068

File tree

1 file changed

+78
-17
lines changed

1 file changed

+78
-17
lines changed

src/mame/adp/servicetastatur.cpp

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class servicet_state : public driver_device
6060
servicet_state(const machine_config &mconfig, device_type type, const char *tag) :
6161
driver_device(mconfig, type, tag),
6262
m_maincpu(*this, "maincpu"),
63-
m_i2cmem(*this, "i2cmem"),
63+
m_i2cmem(*this, "eeprom"),
6464
m_lcd(*this, "hd44780"),
6565
m_io_keys(*this, "IN%u", 0U)
6666
{ }
@@ -89,7 +89,7 @@ class servicet_state : public driver_device
8989
uint8_t m_port3 = 0xff; // Port 3 output latch
9090
uint8_t m_lcd_data = 0; // LCD data bus
9191

92-
// I2C debugging state
92+
// I2C debugging state
9393
bool m_last_scl = true;
9494
bool m_last_sda = true;
9595
uint32_t m_i2c_bit_count = 0;
@@ -112,19 +112,19 @@ void servicet_state::servicet_io(address_map &map)
112112

113113
static INPUT_PORTS_START( servicet )
114114
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
118118

119119
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
123123

124124
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
128128
INPUT_PORTS_END
129129

130130
void servicet_state::machine_start()
@@ -143,23 +143,79 @@ void servicet_state::machine_reset()
143143

144144
uint8_t servicet_state::port1_r()
145145
{
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;
147182
}
148183

149184
void servicet_state::port1_w(uint8_t data)
150185
{
151186
m_port1 = data;
152-
LOG("Scanning col/row: %02X\n", data);
187+
LOG("Port1 write: %02X (scanning)\n", data);
153188
}
154189

155190
uint8_t servicet_state::port3_r()
156191
{
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;
158202
}
159203

160204
void servicet_state::port3_w(uint8_t data)
161205
{
206+
uint8_t changed = m_port3 ^ data;
162207
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+
}
163219
}
164220

165221
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)
211267
m_lcd->e_w(1);
212268
m_lcd->e_w(0);
213269
}
270+
} else if (offset == 0x4000){
271+
//LOG("GSG write: %02X \n", data, offset);
214272
} else {
215273
LOG("IO write: %02X to %04X\n", data, offset);
216274
}
@@ -227,8 +285,8 @@ void servicet_state::servicet(machine_config &config)
227285
m_maincpu->port_in_cb<3>().set(FUNC(servicet_state::port3_r));
228286
m_maincpu->port_out_cb<3>().set(FUNC(servicet_state::port3_w));
229287

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");
232290

233291
// LCD4002A
234292
screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_LCD));
@@ -250,7 +308,10 @@ void servicet_state::servicet(machine_config &config)
250308

251309
ROM_START( servicet )
252310
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
254315
ROM_END
255316

256317
} // anonymous namespace

0 commit comments

Comments
 (0)