What's new

Game Boy

bcrew1375

New member
Mine now plays the intro of Link's Awakening(MBC1 is actually a cinch to implement). Unfortunately, it crashes just before the screen scrolls up to the egg. Oh, heh, I also don't quite have sprites working yet, so there's no boat, or Link, Or Marin :p. I also got the title to Metroid 2 working, and probably some others, but I have no input yet, so I can't go further :p.

Here's some screenies:
 
Last edited:

zenogais

New member
So, what documents are you guys using for this. I think I'm going to start one pretty soon here, just for a fun.
 

aprentice

Moderator
bcrew1375 said:
Mine now plays the intro of Link's Awakening(MBC1 is actually a cinch to implement). Unfortunately, it crashes just before the screen scrolls up to the egg. Oh, heh, I also don't quite have sprites working yet, so there's no boat, or Link, Or Marin :p. I also got the title to Metroid 2 working, and probably some others, but I have no input yet, so I can't go further :p.

Here's some screenies:

I dont have sprites or input either, i guess everyone considers these lower priorities :p

I couldn't find any info on the gb palette, is there any known accurate values for this, or is it kinda like a guess thing?

edit: is everyone using a public cpu core, or am I the only one crazy enough to code my own? :p
 
Last edited:

smcd

Active member
Coding your own is half the fun of it! (actually some of the available cores are not well documented and downright scary looking :p)
 

refraction

PCSX2 Coder
well im starting a GB emu as well, its like were all in a classroom together progressing at the same rate :p

if anyone could provide a GOOD document on the gameboy itd be handy.

Im puzzled tho on how these MBC1 and that works, im guessing the 32k rom games just load straight into memory, but is MBC1 and MBC2 etc direct access to the cart or what?
 

aprentice

Moderator
refraction said:
well im starting a GB emu as well, its like were all in a classroom together progressing at the same rate :p

if anyone could provide a GOOD document on the gameboy itd be handy.

Im puzzled tho on how these MBC1 and that works, im guessing the 32k rom games just load straight into memory, but is MBC1 and MBC2 etc direct access to the cart or what?

mbc is like a memory controller, it controls which banks are "paged" or "switched" in and out since the cpu can only address a limited amount of space. The memory paged can be accessed at 4000-7FFF. I think that should clear everything up :p
 

refraction

PCSX2 Coder
aprentice said:
mbc is like a memory controller, it controls which banks are "paged" or "switched" in and out since the cpu can only address a limited amount of space. The memory paged can be accessed at 4000-7FFF. I think that should clear everything up :p


so basically chunks of memory are copied from the cart into the memory between 4000-7FFF?

and how does the switching work? :p sorry to sound like an ass, but ive not actually started on the fundamentals of the emu yet, just getting the GUI sorted.
 

aprentice

Moderator
refraction said:
so basically chunks of memory are copied from the cart into the memory between 4000-7FFF?

and how does the switching work? :p sorry to sound like an ass, but ive not actually started on the fundamentals of the emu yet, just getting the GUI sorted.

Every rompage is 0x4000 bytes, so when you load the rom you would need to settup a pointer to every page after the complete rom has been loaded into memory. You can get the rom page information from the header.

example:
mem.rompage[3]=(mem.prgrom+(3*0x4000));

this would make page 3 point to 0xC000 of the program rom in memory.

since some roms can have up to 0x7F pages, its a good idea to use a for loop.

I wouldnt worry about mbc1 right away though.
 

bcrew1375

New member
Here's the best documents I've ever seen for the Gameboy. These should contain everything you'll need for basic emulation. As far as the MBC1, if it's on is determined by the ROM header. Basically, if the area from 0x2000 - 0x3FFF is written to, you take the value and use it to choose the ROM bank. Banks 0 and 1 both point to bank 1. So, you can just take the bank number and multiply it by 0x4000(Each bank is 16K). Take that chunk out of the ROM and put it into memory at 0x4000. Make sure you don't actually write the bank value to memory, just evaluate it. That should be all there is to it.
 

refraction

PCSX2 Coder
bcrew1375 said:
No problem :bouncy:. So, do you think you understand MBC1 now?


Kinda, let me say how i think it works and you tell me if im right or wrong.

Different games are different sized, so the data is stored in blocks of data on the card (mbc1, mbc2 etc) the system only has 32k of space for the data from the rom so what it does is pages the data from the memory block into the system depending on which block it needs, then swaps it if it requires a different block of memory.

that sound right to you?
 

bcrew1375

New member
Well, for the most part. I'm not really sure where it stores it, but what does it matter :p. Yes, it essentially swaps in the 16K block that it happens to need at the moment.
 

aprentice

Moderator
Some more screens to revive the thread :p

<images removed>

to bcrew1375:

I implamented dynamic background palette and that fixed the color issues, but a couple games have inverted colors now, i was wondering how you implamented this feature?
 
Last edited:

bcrew1375

New member
The palette is layed out like this:

1 AND 1 = bits 7-6
0 AND 1 = bits 5-4
1 AND 0 = bits 3-2
0 AND 0 = bits 1-0

Hopefully, that is clear :p. If not, I'll try to explain in more detail. Remember though, this is just what I'm using. No guarantees that it's correct :p.

BTW, I've managed to get a single controller button implemented, the Start button. It seems to work for the most part, but I think I'm doing something wrong still. Anyway, I can go in-game on Tetris now. Unfortunately, I don't have sprites, so I have no idea what's going on :p.
 
Last edited:

aprentice

Moderator
bcrew1375 said:
The palette is layed out like this:

1 AND 1 = bits 7-6
0 AND 1 = bits 5-4
1 AND 0 = bits 3-2
0 AND 0 = bits 1-0

dude, your just spitting back at me whats in the docs,
i want to know how you implamented it. The way i did it
gets the colors right in 90% of the games, but games like
mario land 2, the colors are inverted :p

edit: (this is how i do it, so you can point out what im doing wrong) :p

gb_bgpal[0]=palette[(data&0x3)];
gb_bgpal[1]=palette[((data>>2)&0x3)];
gb_bgpal[2]=palette[((data>>4)&0x3)];
gb_bgpal[3]=palette[((data>>6)&0x3)];

edit 2: never mind, the bad colors were just a bug in my interrupt routine, problem magically fixed :p
 
Last edited:

aprentice

Moderator
bcrew1375 said:
Well, that's good to know. Let me know if you get sprites implemented, I'm still working on it :plain:.

rough implamention of sprites, very incomplete, as a matter of fact, this is the only case that it works right in, but since its 3am, i can't do better :p

sml_sprite.gif


On the side note, I haven't figured out how pad (P1) works, does anyone understand this register?
 
Last edited:

Top