commanderx16 / x16-emulator

Emulator for the Commander X16 8-bit computer
383 stars 60 forks source link

When reading from PRA ($f001\$f00f) the data direction register should be considered for all bits. #450

Open Yazwh0 opened 1 year ago

Yazwh0 commented 1 year ago

It only looks like it's considered for the I2C bits, not the joystick data.

In via.c:

case 1: // PA
case 15:
    i2c_step();
    if (!debug) via_clear_pra_irqs(&via[0]);
    if (via[0].registers[11] & 1) {
        // CA1 is currently not connected to anything (?)
        return 0;
    } else {
        return (~via[0].registers[3] & i2c_port.data_out) |                 //I2C Data: PA0=1 if DDR bit is 0 (input) and data_out is 1; usage of data_out and data_in is a bit confusing...
            (via[0].registers[3] & i2c_port.data_in) |                      //I2C Data: PA0=1 if DDR bit is 1 (output) and data_in is 1
            (~via[0].registers[3] & I2C_CLK_MASK ) |                        //I2C Clock: PA1=1 if DDR bit is 0 (input), simulating an input pull-up
            (via[0].registers[3] & i2c_port.clk_in) |                       //I2C Clock: PA1=1 if DDR bit is 1 (output) and clk_in is 1, simulating a pin driven by the VIA 
            Joystick_data;
    }