-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Apple IIe MouseCard/screen emulation is wrong #13598
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
Comments
Hi Colin, The Technical Notes mention that the mouse card can generate either 50 or 60 Hz interrupts via a setting, but they don't say the interrupt is synced to the actual vertical blank anywhere that I'm seeing. I'm not even sure how that would work, as there are no video-related signals on slot 4 where the mouse typically was installed. I guess it's possible that the 6502 firmware polls $C019 on a IIe and tries to sync it that way, but first we need to determine if the interrupts are really synced on a IIe (or II Plus, for that matter). -RB |
The card polls $C019 on the IIe, or vapor-lock on the II+, as a best-effort
starting point. It really is trying to sync.
…On Wed, 16 Apr 2025 at 18:05, R. Belmont ***@***.***> wrote:
Hi Colin,
The Technical Notes mention that the mouse card can generate either 50 or
60 Hz interrupts via a setting, but they don't say the interrupt is synced
to the actual vertical blank anywhere that I'm seeing. I'm not even sure
how that would work, as there are no video-related signals on slot 4 where
the mouse typically was installed.
I guess it's possible that the 6502 firmware polls $C019 on a IIe and
tries to sync it that way, but first we need to determine if the interrupts
are really synced on a IIe (or II Plus, for that matter).
-RB
—
Reply to this email directly, view it on GitHub
<#13598 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWSFM3ZVQWBHLGRCEGA6C32Z344BAVCNFSM6AAAAAB3JLL3TOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJRGM3TSMRVHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
*rb6502* left a comment (mamedev/mame#13598)
<#13598 (comment)>
Hi Colin,
The Technical Notes mention that the mouse card can generate either 50 or
60 Hz interrupts via a setting, but they don't say the interrupt is synced
to the actual vertical blank anywhere that I'm seeing. I'm not even sure
how that would work, as there are no video-related signals on slot 4 where
the mouse typically was installed.
I guess it's possible that the 6502 firmware polls $C019 on a IIe and
tries to sync it that way, but first we need to determine if the interrupts
are really synced on a IIe (or II Plus, for that matter).
-RB
—
Reply to this email directly, view it on GitHub
<#13598 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWSFM3ZVQWBHLGRCEGA6C32Z344BAVCNFSM6AAAAAB3JLL3TOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMJRGM3TSMRVHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
If it does that, then it should just work in MAME. |
And yet, it doesn't. I have questioned my sanity over that, and I have questioned Apple engineer's sanity. I made schematics with theories: I have sent the binary that you saw running under MAME in the video linked in the issue and I got, so far, two different persons telling me "I do not see any flickering and yes it drawn clearly.", "I don't see any flickering at 60Hz, also the puck moves SO SMOOTHLY". Which is why I think something is wrong with MAME, and would love some help figuring it out. I have a theory but I don't really want to go on a multiple-evenings-long sidequest blindly, one of them is this comment in apple2e.cpp:
I also see nothing related to the screen in This does not seem to take into account the stretched cycle. Could it be a lead? Thanks in advance. |
Maybe another lead, MAME outputs warnings from the a2bus/mouse PIA:
|
Finally, but this proves about nothing as these are also not the real hardware, AppleWin and Virtual][ don't show this behaviour and my code does not flicker when ran by thoses emulators. |
We don't emulate the stretched cycle, but we don't emulate it for either the CPU or the video generation so vapor lock and CPU/video cycle sync work. AppleWin and V][ make no attempts to emulate the actual mouse card hardware so that's not useful data, as you surmised. |
Oh, and CB2 on the PIA is not connected, as per the schematic on A2DP. |
Try setting the 68705 clock to 1021800 in mouse.cpp. That seems to make the cursor smoother in Apple II Desktop, and the schematic shows both the microcontroller and the PIA are connected to the slot's phase 0 so I'm not sure why it was double that before. |
Thanks. I tried that, and it doesn't really help. Does this log give you any idea ? Right after the "RD VBLBAR 80" is when, I suppose, the firmware should tell the PIA that should tell the MCU to reset its timer? Thanks in advance! |
Adding a bit more log in m6805_timer::update, I see no timer reset either at the end of the VBL polling. I suppose that's at least part of the problem ?
Edit: Sorry, there's one just ten lines after, it goes back to 255. |
I'm going to have to read up on how the timer works on the 68705, but it probably auto-repeats if you don't do anything. |
The 68705 timer is working. We’ve got lots of nasty test cases for it. The Zorba keyboard and Xain’d Sleena MCU were particularly nasty to get right. It isn’t free-running like the 68HC05 timers. |
That’s correct, it triggers an interrupt when it passes zero and continues to count down, wrapping around to 255. This allows the software to determine how long it was from when the timer triggered to when it the interrupt is serviced. This is important for things that use it to generate asynchronous serial timings (like the Zorba keyboard does), etc. |
OK, after looking at the schematics, I noticed the 6821’s CB1 is tied high, but we haven’t hooked this up in MAME. It’s worth giving that a shot just to eliminate it as a possibility. Try setting it in void a2bus_mouse_device::device_start()
{
// register save state variables
save_item(NAME(m_port_a_in));
save_item(NAME(m_port_b_in));
save_item(NAME(m_last));
save_item(NAME(m_count));
m_pia->cb1_w(1); // tied high via 10k resistor
} |
Hi! |
Schematic here shows the MCU being driven from the Q3 2MHz asymmetrical clock (card edge pin 37) via the 16R4 PAL. Is the firmware we have from a different card? |
Would help to actually link to the schematic: https://archive.org/details/APPLE_050-0101-A-1of1 |
8ab7404 may help with timing issues. |
Hi Vas, Thanks for looking into this. I've cherry-picked the commit, but it doesn't help: https://www.youtube.com/watch?v=GTbesntgicQ If it may help to test, my code is now released at https://www.colino.net/wordpress/wp-content/uploads/shufflepuck-beta-1-960a89c4.po
That would explain things... :-) |
Very naive question, is the 6821 PIA and the 6520 the same thing? (You can tell I'm out of my depth here) https://www.applefritter.com/content/apple-mouse-card-pia-chip |
The 6821 is supposed to be 100% compatible from a software point of view. The main difference is that it’s manufactured using a newer semiconductor process. The electrical characteristics are a bit different, but it shouldn’t matter for emulation purposes. |
I did a decode of the PAL and see the SYNCLATCH is an output that goes to the PIA PB0, maybe its looking for this somehow to sync up? Equations: /o12(LS245) = /i8(DEVSEL) + these appear not connected to anything
/rf17(SYNCLATCH) := i4(D0) /o18(2MHZCLOCK) = /i3(Q3) /o19(feedback to pin 1 clock input for rf17) = i2(IOSTR) + |
So SYNCLATCH is just a passthrough of the A2 bus D0 line and 2MHZCLOCK is Q3 inverted? |
AppleWin doesn't do anything special with SYNCLATCH that I can see, it should always return 0 there. This is very confusing. |
My understanding of the logic is that it will clock the value of D0 into SYNCLATCH only when IOSTR is low. When IOSTR is high, the clock input will be stuck at high regardless of the Q3 signal, so effectively disabling the clocking for SYNCLATCH. What its doing this for seems a mystery still. |
I'm absolutely out of my depth here. A thing that I have noticed is that if I let time pass, the flickering changes place while my sprites don't: https://www.youtube.com/watch?v=cBB4_vKQtCA (that code's image at https://colino.net/tmp/shflpuck-mame-test.po if needed). That makes me think that there might be a very small difference in the VBL frequency versus the mouseCard's IRQ frequency? Another video showing the flickering on the Cafe screen, at 0:54, 2:05 and 3:14. https://www.youtube.com/watch?v=ADV8-4yEa50 The pointer is a 14x11, 33 bytes sprite that can't ever be out of budget to draw. It takes about 888 cycles for the IRQ to be processed, 1034 cycles to clear the pointer, 1667 to draw it, so it's supposed to be done 1ms before the beam is even back at the top. |
The Apple MouseCard is supposed to fire interrupts synced on VBL (cf https://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Interface%20Cards/Digitizers/Apple%20Mouse%20Interface%20Card/Documentation/Apple%20II%20Mouse%20Technical%20Notes.pdf for example).
However, doing so flickers a lot when using the mouse interrupt as VBL detection, even when it should not:
https://www.youtube.com/watch?v=NJsZvI407XI
On the contrary, emulating a IIc or IIgs never flickers, even when the drawing is too slow to stay ahead of the beam.
None of those situations are ideal and make debugging more complicated than it should be. I workaround the issue by using the $C019 softswitch on IIe, but that's not great.
I would love to help fix it, but have so far no idea where to look for what to fix.
Thanks!
The text was updated successfully, but these errors were encountered: