It is currently Thu Apr 27, 2017 11:43 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Hblank on line 153?
PostPosted: Mon Jan 18, 2016 6:10 pm 
Offline

Joined: Mon Jan 18, 2016 5:36 pm
Posts: 23
Hey!

First of all I must say I'm flattered to see people actually invested time in properly emulating my GBVideoPlayer. :) (You should have contacted me though! I could have helped!)

Second, the source code of the OAM interrupt in the player (It's incorrectly labeled as HBlank, sorry!) states the problem:
Code:
    ; Not sure how or why, but this routine gets called 145 times
    ; per frame instead of 144. The addional call is not rLY=144.
    ; Until I figure out which LY value is being used twice (or,
    ; which LY value greater than 144 is being used), we skip the
    ; last line so HL won't go out of sync with frame starts.

    ldh a, [rLY] ; 3
    xor $8F ; 2

    jr z, SkipLine ; 2 (If false)


When I released the player, I haven't investigated this issue that much, after I start writing my own Gameboy Color emulator (Will release it sooner or later :P) I decided to investigate further. And yes, my own player gave me a pretty much hard time when writing the emulator.

I discovered that the extra interrupt only occurs for OAM interrupts, but that extra "line" is neither 153, nor is it 144 (as stated in the comment). BGB emulates this hardware bug incorrectly, an interrupt being fired for LY=144. This was EXTREMELY confusing to figure that out, since I used BGB to debug my player when I was making it.

I wrote a simple test ROM that had an OAM interrupt that simply added 1 to an array cell, with LY as an index (i.e. array[rLY]++). I ran the test on my GBC and found out that the extra interrupt occurs for LY=151.

This can also be verified by modifying GBVideo Player by changing $8F in the above code snippet. Setting anything higher that 143, except 151, will break it on a real Gameboy. 144 will work on BGB, but not on a real Gameboy, and 153 will work on higan, but not on a real Gameboy. Also, any value greater than 143 will work on an emulator that does not emulate this bug in the first place.

And while we're at it, my local "build" has a double resolution, which will later get another 50% increase. I attached a comparison as a teaser, I hope the coming soon updates won't break any of your emulators! :P


Attachments:
gbvideoplayer2.png
gbvideoplayer2.png [ 88.37 KiB | Viewed 924 times ]
Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Mon Jan 18, 2016 11:20 pm 
Offline

Joined: Sun Jan 26, 2014 9:31 am
Posts: 237
Hello LIJI, great to have you join us! :D

Could you double check your results on whether the 145th OAM-STAT interrupt happens on Line 151? I only ask because I modified my tests to try to replicate it. The source code and the binary are attached for review. What I did was use Register B as a counter for OAM interrupts, and HL pointing to Cart RAM to write the results of the current LY value. The program waits until the start of a new VBlank (manually testing if LY == 144), then it spins, waiting for OAM-STAT interrupts. Every OAM-STAT interrupt, B is incremented, and the current value of LY is stored in Cart RAM. It technically starts waiting for OAM-STAT interrupts somewhere on line 144, so it should catch any OAM-STAT interrupts that occur from 145-153, then from 0-144. Essentially, I believe I'm testing for OAM-STATS on every line. The results of the Cart RAM show 0x0 through 0x90 (Lines 0 through 144).

I tested it on my GBC, and the save attached (just rename it from .txt to .sav or something) is the dump from my test. Could you share your test here as well, and perhaps take a look at my code? I'm pretty sure I'm doing this correctly, but I want to reconcile getting different results than you.


Attachments:
oam_count_v4_save.txt [8 KiB]
Downloaded 44 times
oam_count_v4.gb [32 KiB]
Downloaded 34 times
oam_count_v4.txt [4.65 KiB]
Downloaded 31 times
Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Tue Jan 19, 2016 2:02 am 
Offline

Joined: Mon Mar 27, 2006 5:23 pm
Posts: 1274
> Second, the source code of the OAM interrupt in the player (It's incorrectly labeled as HBlank, sorry!) states the problem:

The comment definitely helped a whole lot. But it sounds like we still don't have the exact behavior down 100% just yet, but Shonumi seems to be closing in on it :D

Right now, it looks like my interrupt system is shot. Altered Space is doing something really weird with IRQs that I don't yet understand. And the exact way they trigger is really poorly explained (like everything else on the DMG ...) So my emulator's probably not the best place to test things, but ... oh well.

> the extra interrupt occurs for LY=151

Given this contradicts Shonumi's research ... I wonder if it varies per Game Boy, or if perhaps yours is an odd exception that's acting slightly erratic?

I've also heard another person state they couldn't run your GBVideoPlayer on their real hardware with a flashcart.

Maybe Game Boys are all full of micro-variations like this. Wouldn't that be a treat? :P

> And while we're at it, my local "build" has a double resolution, which will later get another 50% increase. I attached a comparison as a teaser, I hope the coming soon updates won't break any of your emulators! :P

Looking forward to seeing how you do it! :D

And by the way, I'm considering extending my MBC3 support to allow full 16-bit bank selection, which would give you 1GiB of storage. It's a silly, stupid thing, but maybe that could be useful for you in some way? Obviously won't work on real hardware, of course.


Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Tue Jan 19, 2016 4:37 am 
Offline

Joined: Mon Jan 18, 2016 5:36 pm
Posts: 23
Weird, Shonumi's test ROM passes on my Gameboy, yet fails on emulator, meaning I haven't got it either. :P

I uploaded the test ROM I used to get that 151 timing. It's different than what I remembered but it's still pretty much the same: It logs every OAM interrupt by it's LY value into an array, "restarting" every HBlank. On my Gameboy Color and on my own emulator, the output starts with 97 (151) and continues with "00, 01, 02, 03...". It does not display the entire array, because that would take too much CPU and break the timing.

BGB's handling of this is quite weird: When in CGB mode, the output does not start with 97; it starts with 00 and continues. Debugging easily shows the extra interrupt happens on LY=144 - incorrect. In DMG mode however, it's the same as the correct CGB output. However, I don't have a DMG to verify if this behavior is correct.

As for higan, I can't get the ROM to even run on it — for some reason it makes icarus crash both on OS X and my Windows VM.

Edit: This is really weird, I managed to get it to run on higan, and it actually displays the correct result, even though it should have been 99 in higan. Got to do more tests!


Attachments:
hblank_test.png
hblank_test.png [ 81.12 KiB | Viewed 878 times ]
hblank_test.asm [2.67 KiB]
Downloaded 42 times
hblank_test.gb [16 KiB]
Downloaded 49 times
Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Tue Jan 19, 2016 8:17 am 
Offline

Joined: Sun Jan 26, 2014 9:31 am
Posts: 237
> Maybe Game Boys are all full of micro-variations like this. Wouldn't that be a treat? :P

Like some of the audio quirks? That would be wonderful! :D not really

Anyway, I thought about this, so I added a new check to my test. It now verifies each LY value at the start of every OAM-STAT interrupt before writing it to Cart RAM. It expects it to be 0 through 0x90 incrementing by one. If it encounters any other value, it now displays an "NN" screen. So this gives us the results on-screen in addition to the saved RAM. If any Game Boy models deviate from the GBC, we should be able to tell with this new "NN" screen, since it will mess up the expected pattern of LYs.

I was a spoiled kid, so I have quite a few GB models to work with: MGB-001, CGB-001, AGB-001, AGS-001, and a Game Boy Player for the Gamecube. Tested on everything but the GBP, but the results were the same. They passed this new test, so as long as this test is written correctly, it means this behavior should be consistent, OAM-STATs on Lines 0 - 144.

@LIJI - I'll take a look at your test more in-depth in a bit. Tuesdays + Wednesdays are the busiest days of my week, however, so I might not finish up till later. Thanks for sharing though, and keep up the awesome work on the GB Video Player! :)

EDIT - FWIW, I can replicate your results with your test ROM on my GBC, first value is 0x97. I'll dig into the assembly tonight if I get time.


Attachments:
oam_count_v5.txt [5.62 KiB]
Downloaded 43 times
oam_count_v5.gb [32 KiB]
Downloaded 50 times
Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Tue Jan 19, 2016 1:11 pm 
Offline

Joined: Fri Oct 16, 2015 6:18 am
Posts: 32
I tested oam_count_v5.gb with all handheld devices I own (listed here here) and the test passed on all of them. Can't test SGB/SGB2 at the moment, but I'm 99.99% sure the test will pass on them as well.


Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Thu Feb 11, 2016 6:06 pm 
Offline
User avatar

Joined: Sun May 27, 2012 8:43 pm
Posts: 1214
Just curious... are you the same LIJI from the Clickteam / TDC forums?


Top
 Profile  
 
 Post subject: Re: Hblank on line 153?
PostPosted: Fri Feb 12, 2016 12:18 am 
Offline

Joined: Mon Jan 18, 2016 5:36 pm
Posts: 23
mikejmoffitt wrote:
Just curious... are you the same LIJI from the Clickteam / TDC forums?

Yes. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group