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

"MAD EFFECT #2" demo doesn't work correctly #711

Closed
Archange427 opened this issue Oct 29, 2019 · 15 comments
Closed

"MAD EFFECT #2" demo doesn't work correctly #711

Archange427 opened this issue Oct 29, 2019 · 15 comments
Labels
bug
Milestone

Comments

@Archange427
Copy link

@Archange427 Archange427 commented Oct 29, 2019

MAD EFFECT 2
http://fr3nch.t0uch.free.fr/MAD2/MAD2.html

OK several issues with this one:

  • tearing while displaying scrolling parts.
    Related with #680
    Issue seems to be fixed with: https://github.com/AppleWin/AppleWin/tree/GH680-Video-Tearing
    (waiting to be merged with the main branch)
    note: YT video was done using a modified APPLEWIN 1.29.4.0 including GH680 fix.
  • timing issues requiring a special version for emulators that compensates for missing cycles.
    Related with #699
    Not exactly the same code used to synchronize but probably same issue.
    note: I used a modified "v2" version here.
  • weird music issue. Some notes at the launch of the demo seem to be "stretched". Issue noticed since CHIP release. But this time I used a totally different player, actually an "old" YM player.
    Since I did not notice this issue at the time, I think it was introduced during a regression. I do not know yet which one.
@Archange427 Archange427 changed the title "MAD EFFECT #2" demo doesn't work correctly bug "MAD EFFECT #2" demo doesn't work correctly Oct 29, 2019
@tomcw tomcw added the bug label Oct 29, 2019
@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Oct 29, 2019

weird music issue. Some notes at the launch of the demo seem to be "stretched".
I think it was introduced during a regression

If it possible (and if you have time) can you try some older AppleWin's to try to determine when this weird music issue started?

@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Oct 29, 2019

I had just planned to do these tests!
Result:
1.28.6.0 => OK
1.28.7.0 => KO!

@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 3, 2019

re. weird music issue
@Archange427 - which demo or music disk are you using to test the 1.28.6 vs 1.28.7 versions?

@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Nov 3, 2019

I used MAD EFFECT 2
(it works at 60Hz).

@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 3, 2019

re. weird music issue
This sounds fixed in the above commit (eb59c52).

The problem was that:

  • 6522 TIMER1 interrupt was enabled, but T1C and T1L = 0x0000 (ie. T1L wasn't configured yet).
  • From 1.28.7.0 onwards (after I added support for the TIMER1 N+2 count), then the interrupt would occur after 0x10003 cycles.
    • FTR, it occurred 3 times before T1L was set to 0x4284 (ie. NTSC)
  • But during MB_Update(), the interval returned by MB_GetFramePeriod() was 0, meaning that no new sound samples (nNumSamples=0) were written to the DirectSound playback buffer.
  • So the "write" cursor remained static for 3x 0x10003 cycles ~= 0.2s.
  • After the correct T1L interval was set, then because the write cursor was so far behind the play cursor, the adaptive nNumSamplesError would ramp up, inorder to compensate, meaning sped-up emulation until the write cursor was within tolerance of the play cursor again.
  • And sped-up emulation = sped-up music

Interestingly at 1.28.6.0, the T1L=0x0000 interval meant that TIMER1 underflow occurred every opcode!

  • so every opcode there was a call to MB_Update()!
  • MB_GetFramePeriod() was still returning 0
  • but the adaptive nNumSamplesError was able to compensate at a much finer granularity, so was able to keep the write cursor tracking the play cursor.
@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Nov 4, 2019

Good news. Thanks.

@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 16, 2019

@Archange427 - I've merged in a fix for the MADEF & MAD2 demos.
It's not quite 100% (but very close!): in MADEF there is a bit of flicker on the Space Invader Ghost (left edge). Any ideas about this?

@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Nov 17, 2019

@Archange427 - I've merged in a fix for the MADEF & MAD2 demos.
It's not quite 100% (but very close!): in MADEF there is a bit of flicker on the Space Invader Ghost (left edge). Any ideas about this?

OK. I see.

First, very good job Tom!

Yes, it looks like there is still a issue.
Actually, it is present with all the pictures (not only the Ghost one).
More visible with Ghost, because the bottom left edge is white (black with all others).

So I build a new "special" version of MAD EFFECT for 1.29.50.
This time, I needed to decrease ONE cycle (before I had to add 6!) to get a full working version:
MADEF_12950.zip

So, this time AppleWin uses one cycle "too much" somewhere...

original line 307 (in main.a of MAD EFFECT) was:
NOP : NOP : NOP : NOP : LDA $EA ; +11
It is now with "special" version:
NOP : NOP : NOP : NOP : NOP ; +10

@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 17, 2019

Thanks for the new (special) MADEF build.

So, this time AppleWin uses one cycle "too much" somewhere...

Yes, so on entry to INT_ROUT ($D200), it's 1 cycle late, so with this AppleWin (and with the official MADEF.DSK) the LDA $C019 always reads $80 (never $00).

The INT is caused by the 6522 timer. It's counting the correct interval (N+2) as OMT demo is stable. But perhaps it's triggering 1 cycle late? I'll have to check this.

@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 17, 2019

But perhaps it's triggering 1 cycle late? I'll have to check this.

Yes... if I revert the 6522 underflow code back to underflowing from 0x0001 -> 0x0000, then the official MADEF.DSK now works fine.

I don't quite understand, as this old "underflow at 0x0001->0x0000" was done to support a count of 0x0000 meaning 0x10000... which I've shown (on real hardware) isn't the case.

Basically it's a subtle 6522 timer emulation issue. But I'm very close!

@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Nov 17, 2019

Perhaps your fix just compensates another problem and it is not the real cause.
When the STY $C405 occurs, do you immediately start counting down?

@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Nov 17, 2019

Btw, I still have so much trouble following this kind of issues because of the difference between the theoretical count of the cycles and AppleWin's behavior because of the execution (read / write) of all the opcodes at cycle 1!
I'm on my knees here and I'm begging an implementation of the opcodes cycles accuracy! :)

@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 17, 2019

But perhaps it's triggering 1 cycle late? I'll have to check this.

It was this. Fix now committed to master branch.

@Archange427

This comment has been minimized.

Copy link
Author

@Archange427 Archange427 commented Nov 17, 2019

Well done Tom!
I'm really happy to finally see that MAD EFFECT 1 and 2 are working properly on an emulator.

A new milestone was reached in the Apple II emulation IMHO.

@tomcw tomcw added this to the 1.29.6 milestone Nov 18, 2019
@tomcw

This comment has been minimized.

Copy link
Contributor

@tomcw tomcw commented Nov 18, 2019

Yes, I'm relieved that both MAD EFFECT 1 and 2 demos are now working correctly! Thanks for your help with this.

Closing as fixed in AppleWin 1.29.6.0 here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.