What's new

Game Boy

refraction

PCSX2 Coder
bcrew1375 said:
I second that, if you've never done anything emulation related, you have no idea what you're getting yourself into. I tried doing a Gameboy emulator first, there were alot of concepts I simply couldn't grasp until I did a Chip-8 emu. If you understand assembly, registers, the stack, input/output ports, cycle counting, and the way the CPU handles instructions, then go for it.


not forgetting interrupts, DMA transfers and timers :p
 

bcrew1375

New member
Thought I was forgetting something, but it was late :p. Interrupts and timers yes, but DMA transfer is nothing more than a for loop or a memcpy for most people :p.
 

refraction

PCSX2 Coder
bcrew1375 said:
Thought I was forgetting something, but it was late :p. Interrupts and timers yes, but DMA transfer is nothing more than a for loop or a memcpy for most people :p.


yeh i think thats all ive done lol, if im not mistaken the DMA register stores the first 8bits of the 16bit address yes? example if it stores 0x01 the address starts at 0x0100 (or 0x100 however you wanna write it)
 

bcrew1375

New member
Yep, that's right. Just copy it from that address to 0xFE00. BTW, I found a really dumb bug in my code :p. In some cases, when switching MBC1 models, the correct rom bank wasn't copied in :plain:. Unfortunately, it seemed to do squat for compatibility.
 

aprentice

Moderator
bcrew1375 said:
Yep, that's right. Just copy it from that address to 0xFE00. BTW, I found a really dumb bug in my code :p. In some cases, when switching MBC1 models, the correct rom bank wasn't copied in :plain:. Unfortunately, it seemed to do squat for compatibility.

so is mario land 2 running for you yet? :p
 

bcrew1375

New member
Nope, like I said, it seemed to do squat for compatibility :plain:. Mario Land 2 seems to jump into the rom bank space at one point when there is nothing but 0's in it. I was hoping the bug I mentioned was the cause of this, but nope :(.
 

aprentice

Moderator
bcrew1375 said:
Nope, like I said, it seemed to do squat for compatibility :plain:. Mario Land 2 seems to jump into the rom bank space at one point when there is nothing but 0's in it. I was hoping the bug I mentioned was the cause of this, but nope :(.

So what DarkStalker mentioned didn't fix it for you?
 

bcrew1375

New member
Nope, I had already been doing that, if you mean allowing the interrupt when the display is disabled. I don't even make it past the title screen. It's fine until I press start.
 

aprentice

Moderator
bcrew1375 said:
Nope, I had already been doing that, if you mean allowing the interrupt when the display is disabled. I don't even make it past the title screen. It's fine until I press start.

oh okay, I had the same exact problem and it fixed it for me. Have you checked through every single opcode with a fine needle?

Too bad that there isnt a diagnostic rom that does this :p
 

bcrew1375

New member
No, but I plan to. Hehe, I was thinking the same thing about the diagnostics rom until I realized it wouldn't run if the opcodes weren't correct anyways :p.

Hehe, found a really, REALLY dumb bug. Because of some certain variables, I was denying rom bank switches in ROMS with MBC3, MBC4, and MBC5. That of course doesn't fix Mario Land 2. I also found another bug in Earthworm Jim. When you first start the game, Jim instantly dies, and the stage restarts.
 
Last edited:

ShizZy

Emulator Developer
Thanks for the advise bcrew and refraction, this really is a much bigger project than I had initially expected. Though so far, I havn't ran into anything which has slowed me down too much. I spent every waking minute this weekend coding my emulator, and I have the basic core completed. I have about 95% of the opcodes included, and about half of them have basic functionality (mostly a lot of the basic arithmetic and logical functions).

For some reason though, it's crashing on me when I try to load the ROM... I'm willing to bet it's some minescule little error in my code that's throwing everything off. I'm going to pick at it tonight, hopefully I'll have something to show for it in a few days :p
 

ShizZy

Emulator Developer
After mangling my code and such, here's where I spotted the bug... What I did was log the Opcodes for Link's Awakening (original, not the DX version). Here is what it spit out...

The first 6 Opcodes are as follows, with the functions I call...
Opcode = 0 NOP
Opcode = c3 Non-conditional JP
Opcode = cd Non-conditional CALL
Opcode = f0 LD register A with 0xFF00 + 8bit immediate value
Opcode = e0 LD 8bit immediate value + the value at 0xFF00 into register A
Opcode = cb

Following this, the following three opcodes were spit out in what seems to be an infinite loop...
Opcode = f0 (same as above)
Opcode = fe CP an 8bit immediate value with register A
Opcode = 20 (same as above)

Now, I used bcrew's source and edited his logging function to spit the op codes as well. The same first 6 ops are loaded, followed by the f0 - fe - 20 loop. But, what appears to be about a thousand opcodes in (I didn't count :p), it hits op E6. I don't think I ever get to this one, but if I do - I'd call an AND 8bit immediate value to register A.

Any one have any thoughts? Am I doing something blatantely wrong here?
 

bcrew1375

New member
ShizZie said:
After mangling my code and such, here's where I spotted the bug... What I did was log the Opcodes for Link's Awakening (original, not the DX version). Here is what it spit out...

The first 6 Opcodes are as follows, with the functions I call...
Opcode = 0 NOP
Opcode = c3 Non-conditional JP
Opcode = cd Non-conditional CALL
Opcode = f0 LD register A with 0xFF00 + 8bit immediate value
Opcode = e0 LD 8bit immediate value + the value at 0xFF00 into register A
Opcode = cb

Following this, the following three opcodes were spit out in what seems to be an infinite loop...
Opcode = f0 (same as above)
Opcode = fe CP an 8bit immediate value with register A
Opcode = 20 (same as above)

Now, I used bcrew's source and edited his logging function to spit the op codes as well. The same first 6 ops are loaded, followed by the f0 - fe - 20 loop. But, what appears to be about a thousand opcodes in (I didn't count :p), it hits op E6. I don't think I ever get to this one, but if I do - I'd call an AND 8bit immediate value to register A.

Any one have any thoughts? Am I doing something blatantely wrong here?

I had that same problem when I was starting out. The infinite loop is caused because you are not incrementing the LY register at 0xFF44. You need to increment it approx. every 456 clock cycles(114 machine cycles). Reset it to 0 when it passes 153. Do that, and you should make it through that loop.

Also, my old source has two small bugs in it you might want to fix. First is the SRL command function, change "if (*reg & BIT_1)" to "if (*reg & BIT_0)" Second, in the WriteMemory function, goto the if for addresses 0x4000 to 0x5FFF and move the code that says "Switch in the current ROM bank" above the if statement. I'll probably repost the fixed source in a while. I've changed a few things since then, but I don't know if it's caused any new bugs.
 
Last edited:

ShizZy

Emulator Developer
Big thanks bcrew. I'll check that out when I get home - hopefully it'll fix my problem. I also seemed to not be handling the v-bank interrupt properly, but I think that error should be fixed now.
 

ShizZy

Emulator Developer
Hmmm.. I'm incrementing it now. Problem is, I'm still getting that ugly crash that occurs when an infinite loop cycles improperly. It shouldn't crash like that regardless of the LY increment though, enless maybe it wasn't calling the v-bank interrupt. But I can't see how it isn't. Maybe I'm not looking hard enough :blush: Very frustrating.
 

bcrew1375

New member
ShizZie said:
Hmmm.. I'm incrementing it now. Problem is, I'm still getting that ugly crash that occurs when an infinite loop cycles improperly. It shouldn't crash like that regardless of the LY increment though, enless maybe it wasn't calling the v-bank interrupt. But I can't see how it isn't. Maybe I'm not looking hard enough :blush: Very frustrating.

Is it the same loop, or a different one? Can you post the log again? Oh, and you do realize that you are supposed to call the interrupts, not the program?
 

ChaosBlade

My Heart Chose.. Revenge.
Wow. Thats basicly what i have to say after reading this whole thread :p
I havent read any of the GB docs yet (care to tell me which ones you're mostly using ? id like to weed out some useless ones before i might even consider starting a gb emu project) and based on what ive read in this thread, I think i might wait a bit before taking the step from something supremely simple as the chip8 to something immensly complex (in my eyes right now BEFORE reading ANY gb hardware\inner-working material) as the gameboy.

Since i dont believe in jumping in blindly (translating the docs to code really) before i understand, i guess ill wait. One other request i have is, if someone can shortly expline how to deal with timing (considering a PC is far more capable then the gb's cpu), and a few general tips could help aswell.

Thanks in advance :) (wheh, long post.)

(General Note to other people: i do believe i have adaqute programming skills, and ive coded up my chip8emu 95% on my own with little help from others, so im positive i understand it completely.)
 

Top