When it LY/LYC Coincidence checked?

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

When it LY/LYC Coincidence checked?

Post by zerowalker »

As title says.

I would imagine they being checked each LY increment,
but what happens when the actual flag to check is set, does a check occur at that moment, or will it wait till the next LY increment?
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: When it LY/LYC Coincidence checked?

Post by Shonumi »

zerowalker wrote:but what happens when the actual flag to check is set, does a check occur at that moment, or will it wait till the next LY increment?
When you write a new value to LYC, this forces an immediate comparison between LY and LYC. You can use this to manually fire a STAT interrupt via LYC. The game Sagaia does this, but other than that it's a very rare edge case even among commercial titles.
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: When it LY/LYC Coincidence checked?

Post by zerowalker »

Ah, but what if you write to LY so it resets?

And also when is the comparison done otherwise, is it done at the end of HBlank?
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: When it LY/LYC Coincidence checked?

Post by Shonumi »

zerowalker wrote:Ah, but what if you write to LY so it resets?
I think this is another famous example of how poor Game Boy documentation can be. That bit of info is from Pan Docs, which is incorrect. Any writes to LY while the LCD is enabled are ignored. When the LCD is disabled, LY is forcibly set to 0, and since it's read-only, the value never changes. A long time ago, I think someone may have written to LY while the LCD was disabled, then read the value of LY, and assumed all writes reset the counter. Admittedly, I haven't yet fixed that part in my own emulator; still using the outdated Pan Docs in my source code. I'll change it, eventually.

And also when is the comparison done otherwise, is it done at the end of HBlank?
For anything related to Game Boy timing, I'd highly recommend AntonioND's The Cycle Accurate Game Boy Docs. According to him, LY is incremented/compared after each 456 cycles necessary to process a line. For most displayable lines, that means after the last line's HBlank, when entering Mode 2. If I recall correctly, there's some funny stuff happening on Line 0, so read up on that (Kirby's Dream Land 2's intro relies on that behavior).
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: When it LY/LYC Coincidence checked?

Post by zerowalker »

Yeah it sucks that random stuff are inaccurate, and as i don't know how to test the stuff myself i have to rely on documentation from others.

Would probably get a gameboy for the purpose of testing the behaviours, but i would probably need other hardware as well to do proper tets rather than just looking at the screen,
and i am not confident i have the skills for that.

Will read the link you gave, pretty sure i had that one before but couldn't find it again.
I actually just got Kirby's Dream Land 2 to start to the Title Screen,
the start of the game is messed up (so is Bomberman), basically garbage, but when the actual intro starts it seems kinda fine.
Dream Land 2 only has one bug (on the intro) and that is that the top line is bugged, so this would be line 0, so it's probably what you are talking about.
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: When it LY/LYC Coincidence checked?

Post by Shonumi »

GB documentation is a mess. Stuff is scattered all over the place in different resources. And on top of that, we're still learning new things even today. Just look at gekkio, endrift, or LIJI32's work. I've been tackling lots of crazy accessories as well (Barcode Taisen Bargidun, the Barcode Boy, the Full Changer). I'm just now finishing up my research into the DMG-07, the 4-player adapter. There's like zero info on it; no one's bothered to touch it despite all these years.

Anyway, as for testing stuff on real hardware, definitely grab yourself a couple of Game Boys and a flashcart of some sort. GBCs or GBAs are cheap enough. DMGs in actual good condition are a bit pricier (like $5 or $10 USD more on eBay) probably because they're older and less common, and popular with hardware modders. I personally have an EMS 64M Smart Card or whatever its technically called. EverDrives are just too expensive for my needs, and BennVenn's ElCheapo's have been "Sold Out" forever. If you want to go the really cheap route, you can buy fake GB carts online (usually with the words "GAME" in the molding instead of "GAME BOY"). These are generally reflashable if you have a cart reader/writer.

Writing tests isn't so bad though. If you know your way around GBZ80 assembly and have an idea of what parts of the hardware you want to examine, it's usually trial and error until you come up with some results :D
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: When it LY/LYC Coincidence checked?

Post by zerowalker »

Yeah learning more and more about that,
first when i started my GB Emulation just for fun (never doen ANY emulation before) and got much help and explanation how things worked.
But as i went deeper i noticed that it was lacking and something were kinda controversial.

So i think it would help to do tests myself, even if i know i am not in the league of others, it's still fun right;P

Will try to get a hold of a GameBoy, i have the originals myself but i really don't wana touch those.

Btw why would i want several GameBoys, one expects them to break?

Will look up on the Flash Card, i think as long as it's at least MBC3 then it's fine, as that's the common one (i think) and could help do tests.
Though MBC5 also exists, not sure how common that one is as that's then (newest?).
I mean one would want to be able to have something that can test the weird quirks right?

EDIT:

Oh and also about you researching the 4 player thing.
One would really think that these things (especially a multi player thing) would have been researched by now.
So for what it's worth, i hope you learn something from it and it's not Too much a pain haha;P

Didn't even know GB had multiplayer (except i noticed SGB apparently have it, which i think is to blame for those games not even accepting any input for me).
Can't imagine where 4 players would be of use on a Gameboy, how it would even process that external information.
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: When it LY/LYC Coincidence checked?

Post by Shonumi »

zerowalker wrote:Btw why would i want several GameBoys, one expects them to break?
You'll need at least two if you want to do hardware tests on multiplayer stuff (standard 2-player stuff e.g. Pokemon battles/trading). It's not necessary, but yes, having a backup is always a good idea. Game Boys are pretty durable and fixable, but I myself somehow ended up having 8 (1 DMG, 2 Pockets, 2 GBCs, 1 AGB-001, 1 AGS-001, and 1 AGS-101).
zerowalker wrote: I mean one would want to be able to have something that can test the weird quirks right?
Anything that's MBC1, MBC3, or MBC5 is good enough for testing. Most flashcarts are programmable, so whatever ROM you put inside will determine what kind of MBC it simulates (it checks the header). I generally stick to 32KB MBC1 ROM + RAM + Battery. Test ROMs are generally very, very small, and I like to save any results to the cart RAM so I can analyze things in a hex editor later. I have a cart reader, so I can pull up the save file as a binary. If you don't have a cart reader, you'll have to come up with visual "PASS/FAIL" graphics and print things to the screen like blargg's tests.
zerowalker wrote:Can't imagine where 4 players would be of use on a Gameboy, how it would even process that external information.
If you're interested, I write a bunch of articles about emulation, so once I finish implementing the DMG-07 4 Player Adapter in my emulator, I'll post a very detailed explanation about how it works. Without going into much detail, the DMG-07 basically pings the status of all connected Game Boys and broadcasts that to each. So each Game Boy knows which one is connected and which player it is (e.g. Player 1, Player 2, Player 3, or Player 4). Player 1 acts as master, all other Game Boys are slaves. Player 1 starts the synchronization process, and then each Game Boy basically takes turns sending data over the link cables (starts with Player 1, ends with Player 4, repeats). The DMG-07 is responsible for broadcasting the data to each Game Boy, so anything Player 1 sends, Players 2, 3, and 4 also receive. Anything Player 2 sends, Players 1, 3, and 4 receive, and so on.

It's really fascinating, but it ended up being used by like only a dozen or so games. By the mid-1990s, it had been totally forgetten. 4-player support was an afterthought for the original Game Boy, while the Game Boy Advance handled it like a professional ;)
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: When it LY/LYC Coincidence checked?

Post by zerowalker »

Ah well obviously i would need more than one for any kind of link tests, pretty hard otherwise xd

Confused when you say you can put a ROM on the flashcart, and later you say if you don't have a flashcart reader you need to print visual statuses.
How would i even get the ROM to the flashcart without a flashcart reader, isn't that what you use to R/W to it;o?

Checking your articles a bit, impressive, not just the research but also how you write it.
Admire when people are able to write in a while that's clear. I am completely horrible with these stuff, i can barely understand what i myself writes at times;p

As for the 4 Player thing, really interesting.
So it's based on player 1 and then acts like a serial connection, going to one by one until the last one?
Or wait, ehm that can't be right as it would only make sense when player 1 sends information.
Or is it prioritized, meaning player 3 sends to 1, 2 then 4 etc?
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: When it LY/LYC Coincidence checked?

Post by Shonumi »

zerowalker wrote: Confused when you say you can put a ROM on the flashcart, and later you say if you don't have a flashcart reader you need to print visual statuses.
How would i even get the ROM to the flashcart without a flashcart reader, isn't that what you use to R/W to it;o?
Well, for me, I use Linux. There are tools for writing ROMs to my EMS 64M Smart Card, but no tools for reading the saves. So when I first started, all my tests had to use visual cues, since I couldn't read anything I saved to RAM. I got a cart reader/writer (BennVenn's Joey Squinson Gen 2) and that allowed me to read save files from my flash cart. Better flashcarts with better tools simply use SD cards, so there's no issue there. :)
zerowalker wrote: As for the 4 Player thing, really interesting.
So it's based on player 1 and then acts like a serial connection, going to one by one until the last one?
Or wait, ehm that can't be right as it would only make sense when player 1 sends information.
Or is it prioritized, meaning player 3 sends to 1, 2 then 4 etc?
The DMG-07 has a multiplexer built into it, meaning input from one Game Boy can be duplicated to others simultaneously. Player 1 sends out 4 bytes before letting Players 2, 3, and 4 send 4 bytes as well. Each time a Game Boy sends something, all the other Game Boys receive it. But only when a Game Boy sends something during it's turn will it be broadcast to the other Game Boys. For example, if Player 2 tried sending data when it's Player 3 or Player 4's turn to send data, Player 2 gets completely ignored. So...

Player 1 sends 4 bytes, all other Game Boys receive sent bytes
Player 2 sends 4 bytes, all other Game Boys receive sent bytes
Player 3 sends 4 bytes, all other Game Boys receive sent bytes
Player 4 sends 4 bytes, all other Game Boys receive sent bytes
Repeat endlessly

But now we are getting a bit off-topic I guess :P
zerowalker
Posts: 68
Joined: Tue May 17, 2016 10:15 pm

Re: When it LY/LYC Coincidence checked?

Post by zerowalker »

Ah, would have thought something that could write would automatically be able to read as well, that explains it.

Seems quite hard to find these flashcarts, except some super expensive ones, not even Reader/Writers, perhaps i am searching wrong:S


Ah okay, thought it was some kind of serial connection where each gameboy sent to the next one, till all had it.
But if it's a multiplexer then i kinda get how it works out, thanks:D
Post Reply