comparison io.c @ 2661:462e43f54abf

Properly emulate extra TH transitions due to direction changes for 6-button controllers. Breaks Golden Axe II input the same as hardware with a 6-button controller
author Michael Pavone <pavone@retrodev.com>
date Wed, 05 Mar 2025 22:20:20 -0800
parents 25e40370e0e4
children
comparison
equal deleted inserted replaced
2660:9a5e627c1b1f 2661:462e43f54abf
557 for (int i = 0; i < 8; i++) 557 for (int i = 0; i < 8; i++)
558 { 558 {
559 if (!(port->control & 1 << i)) { 559 if (!(port->control & 1 << i)) {
560 if (port->slow_rise_start[i] != CYCLE_NEVER) { 560 if (port->slow_rise_start[i] != CYCLE_NEVER) {
561 if (current_cycle - port->slow_rise_start[i] >= slow_rise_delay) { 561 if (current_cycle - port->slow_rise_start[i] >= slow_rise_delay) {
562 port->slow_rise_start[i] = CYCLE_NEVER;
562 output |= 1 << i; 563 output |= 1 << i;
563 } 564 }
564 } else { 565 } else {
565 output |= 1 << i; 566 output |= 1 << i;
566 } 567 }
1258 1259
1259 void io_control_write(io_port *port, uint8_t value, uint32_t current_cycle) 1260 void io_control_write(io_port *port, uint8_t value, uint32_t current_cycle)
1260 { 1261 {
1261 uint8_t changes = value ^ port->control; 1262 uint8_t changes = value ^ port->control;
1262 if (changes) { 1263 if (changes) {
1264 uint8_t old_output;
1265 if (port->device_type == IO_GAMEPAD6) {
1266 //slow IO rise could have caused a TH transition
1267 if (port->slow_rise_start[6] != CYCLE_NEVER && current_cycle - port->slow_rise_start[6] >= SLOW_RISE_DEVICE) {
1268 uint32_t rise_cycle = port->slow_rise_start[6] + SLOW_RISE_DEVICE;
1269 if (rise_cycle >= port->device.pad.timeout_cycle) {
1270 port->device.pad.th_counter = 0;
1271 }
1272
1273 port->device.pad.th_counter++;
1274 port->device.pad.timeout_cycle = rise_cycle + TH_TIMEOUT;
1275 }
1276 old_output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE);
1277 }
1263 for (int i = 0; i < 8; i++) 1278 for (int i = 0; i < 8; i++)
1264 { 1279 {
1265 if (!(value & 1 << i) && !(port->output & 1 << i)) { 1280 if (!(value & 1 << i) && !(port->output & 1 << i)) {
1266 //port switched from output to input and the output value was 0 1281 //port switched from output to input and the output value was 0
1267 //since there is a weak pull-up on input pins, this will lead 1282 //since there is a weak pull-up on input pins, this will lead
1270 } else { 1285 } else {
1271 port->slow_rise_start[i] = CYCLE_NEVER; 1286 port->slow_rise_start[i] = CYCLE_NEVER;
1272 } 1287 }
1273 } 1288 }
1274 port->control = value; 1289 port->control = value;
1290 if (port->device_type == IO_GAMEPAD6) {
1291 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE);
1292 if (TH & (old_output ^ output)) {
1293 if (current_cycle >= port->device.pad.timeout_cycle) {
1294 port->device.pad.th_counter = 0;
1295 }
1296 if ((output & TH)) {
1297 port->device.pad.th_counter++;
1298 }
1299 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT;
1300 }
1301 }
1275 } 1302 }
1276 } 1303 }
1277 1304
1278 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle) 1305 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle)
1279 { 1306 {
1307 if (port->device_type == IO_GAMEPAD6) {
1308 //slow IO rise could have caused a TH transition
1309 if (port->slow_rise_start[6] != CYCLE_NEVER && current_cycle - port->slow_rise_start[6] >= SLOW_RISE_DEVICE) {
1310 uint32_t rise_cycle = port->slow_rise_start[6] + SLOW_RISE_DEVICE;
1311 if (rise_cycle >= port->device.pad.timeout_cycle) {
1312 port->device.pad.th_counter = 0;
1313 }
1314
1315 port->device.pad.th_counter++;
1316 port->device.pad.timeout_cycle = rise_cycle + TH_TIMEOUT;
1317 }
1318 }
1280 uint8_t old_output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); 1319 uint8_t old_output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE);
1281 port->output = value; 1320 port->output = value;
1282 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE); 1321 uint8_t output = get_output_value(port, current_cycle, SLOW_RISE_DEVICE);
1283 switch (port->device_type) 1322 switch (port->device_type)
1284 { 1323 {