Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joystick data on the VIA doesn't consider DDR bits #84

Open
Yazwh0 opened this issue Apr 8, 2023 · 3 comments
Open

Joystick data on the VIA doesn't consider DDR bits #84

Yazwh0 opened this issue Apr 8, 2023 · 3 comments

Comments

@Yazwh0
Copy link

Yazwh0 commented Apr 8, 2023

The bits for the joysticks do not check the DDR bits at all, unlike the i2c bits.

		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;
			}
@DragWx
Copy link
Contributor

DragWx commented Apr 16, 2023

This is tricky because port A of the VIA is different from port B, in that it will give you the logic levels seen on the pins regardless of DDR. (For comparison, port B will always read the programmatic setting of output pins and not the physical level at the pin itself)

Hypothetically, if you connected a joystick that drives the pins more strongly than the 65C22's output drive, you'd see the joystick data no matter whether the pins were configured as inputs or outputs.

I don't know how likely that is, but it implies programmers might not be able to rely on a particular behavior here, and more weirdly, that the emulator is currently simulating a situation which is still actually possible. :P

(I got this info from page 9 of the W65C22 datasheet)

@mooinglemur
Copy link
Contributor

Which emulator behavior would cause the least confusion in the majority of cases? The joystick_scan routine always sets the direction. The emulator does check to see whether the clock and latch are configured as outputs.

If the emulator checked the direction of the data pins, then it would potentially be different than hardware behavior, possibly most of the time.
If the emulator remains as is, it might cause a developer who forgets to set the direction to be convinced that it's behaving correctly when set as outputs, and there may be some controllers that are too weak to overcome how the lines are being driven by the VIA.

@DragWx
Copy link
Contributor

DragWx commented Jul 23, 2023

I think first of all, make sure the documentation for the VIA makes the difference between Port A and Port B clear, and advise that developers must set the correct direction when manually reading the joysticks vs. using the kernal routine to do so, otherwise, the behavior is undefined.

Second, it might help to know what happens on real hardware. If the joysticks work most commonly, or they stop working most commonly, that might be what the emulator should do. If we wanted to provide a strict, "make sure my stuff works on real hardware" environment, then I'd say to make the joysticks stop reading back when the direction is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants