What's new

Game Boy

TJA

New member
Hi all,
Well after almost 8 mounths without touching my emu, I finally finished uni and have a job lined up that doesn't start till next month. Therefore I have plenty of free time at the moment. Anyway, I have a question. I'm ready to implement some graphics for my emu but I'm unsure when I should be updating the display, do I update it straight after writing to video memory, any help on this and inplementing gameboy graphics in general would be appreciated.

Cheers, TJA.
 

ShizZy

Emulator Developer
huarifaifa - sounds great.

TJA - every 114 machine cycles, or 456 clock cycles, you draw one of the 144 screen lines - if I recall correctly. After that there is a vblank period for 10 scanlines.
 

huarifaifa

New member
I'm ready to implement some graphics for my emu but I'm unsure when I should be updating the display

As ShizZy said. Draw each line every 114 machine cycles on your offscreen bitmap, and then blit it on screen during the V-Blank period, ie. something like:

Code:
while LCD Enabled do

  for LY = 0 to 143 do
     // OAM
     LCD Mode = 2
     wait 20 cycles

     // Transfer
     LCD Mode = 3
     wait 43 cycles

     // draw line using the current LCD registers (LY, LCDC, STAT, SCX, etc.)
     drawLine(LY, LCDC, STAT, ...)

     // H-Blank
     LCD Mode = 0
     wait 51 cycles
  end for

  // show the offscreen bitmap on screen
  showFrame()

  // V-Blank
  LCD Mode = 1
  for LY = 144 to 153 do
     wait 114 cycles
  end for

end while

It's usually implemented as a state machine (unless your programming language supports continuations :).

There's some "weirdness" in the line 153 not shown here, and some games (like Prehistorik Man, Parodius, etc.) that need a more accurate way to draw each line, but most games should run fine.
 
Last edited:

TJA

New member
Thanks, huarifaifa and shizzy. I understand this now thanks to your posts and examining the tech docs I have. Hopfully I shall have this implemented by the end of tommorrow, or if not the end of the weekend ( looking a my code I found some other things I need to implement first ).
Anyway wish me luck hopefully I should have a screenshot to show off sometime next week.

Cheers, TJA.
 

TJA

New member
Hey guys I’ve implemented the start of my graphics, but are now stumped.

Here is the code I’m currently working on:

void draw_win()
{
unsigned char *tile_map, *tile_data;

if( LCDC&0x40) // select Windows tile map display
tile_map = &RAM[0x9C00];
else
tile_map = &RAM[0x9800];

if ( WX > 166 ) // makes sure window is visable
return;

if ( LY >= WY ) // only draw if LCD y position up to or equal the window position
{
what do I do now???
}
}
//draw line using the current LCD registers (LY, LCDC, STAT, SCX, etc.)
void h_blank()
{
//if (LCDC&0x01) draw_back();
if (LCDC&0x20) draw_win();
//if (LCDC&0x02) draw_obj();
}

It seems the document I have do not have enough detail to implement this from them.
For instance how do I know which pattern in the tile data table to draw?

Any help would be appreciated.

Cheers, TJA.
 

huarifaifa

New member
TJA said:
It seems the document I have do not have enough detail to implement this from them.
For instance how do I know which pattern in the tile data table to draw?
Cheers, TJA.

Check out the Pan Docs:

http://www.work.de/nocash/pandocs.htm#vramtiledata

It's (almost) all explained there.

The tile data for BG and WIN starts at address 0x8000 or 0x8800, ie:

Code:
  if(LCDC&0x10)
    tile_data = &RAM[0x8000];
  else
    tile_data = &RAM[0x8800];

The format of the 8x8 / 8x16 tiles is explained in the Pan Docs.

Carlos
 

TJA

New member
Thanks huarifaifa, I already had this document but had forgot about it, this should help alot, hopefully I will have some graphics displaying by next week, little busy at the moment as I are moving to a different city in a couple of weeks to start my new job.

TJA.
 

Helius

Capsule Corp.
Hi all!!

After writing a Chip8 emulator for J2ME devices (http://www.emutalk.net/showpost.php?p=336235&postcount=697) I decided to start a GameBoy emulator using C#.

I have spent a month on and off to code all CPU opcodes and now I have finally completed it. Still buggy opcodes but it can load some games like Dr Mario to the splash screen.

A lot of work to do now, interrupts, io ports, input... but things are getting more interesting :)

Keep up the good work guys.
 

hap

New member
Looks and sounds good! But playing games on it was annoying:
- The window is SO small (add a window zoom option, eg. mario xxx.gb -4 quadruples the window size, or a fullscreen option even, but that's a bit harder to implement).
- Buttons are placed wrongly, B should be to the left of A, Select to the left of Start (Select/Start shouldn't on top of eachother).
 

huarifaifa

New member
> Looks and sounds good! But playing games on it was annoying:

Thanks!

> The window is SO small [...]

The Java version has the window size doubled (320x288). I'll check out if there's an easy way to scale the window in the C++ version (which uses SDL).

> Buttons are placed wrongly, B should be to the left of A, [...]

Yes, I "naturally" defined that layout (I'm left-handed) without knowing the actual button placement in a real GameBoy. I will change that to make it "not wrong." :)

Carlos
 

EdgEy

New member
After looking at this topic for a while I decided to start coding a GB emulator.. so far I just have most of the core done (interrupt related opcodes aren't done).. nothing else really. this screenshot is me just dumping areas of ram to the screen ..
 

EdgEy

New member
Thanks ShiZzY :)

Unknown bugs are stopping me from running a lot of games

Tetris... doesn't seem to write tiles to vram or anything, but i have gotten a few demos to work (Big scroller works exactly the same as in VBA, landscape demo works, Merry Christmas demo works with a few bugs - neither have sprites yet)

:bouncy:
 

Danny

Programmer | Moderator
wow this thread hasnt seen activity in a while. Now that my chip8 emu is almost done im looking to port a gameboy emu.

bcbrew i noted that you used sdl in your emulator...

i wondered if i could have your latest source so i can port it to the psp?

or if anyone else has a early working emulator that would be great too :)

cheers
 
Last edited:

hap

New member
or write one from scratch :)

1: You get to know the Gameboy ins and outs better: much easier to fix imperfections and bugs.
2: It's a lot more fun!
 

Danny

Programmer | Moderator
or write one from scratch :)

1: You get to know the Gameboy ins and outs better: much easier to fix imperfections and bugs.
2: It's a lot more fun!

yeah not a bad idea hap ;)

Do you think i would be able for the challenge of making a gameboy emu from scratch after only porting a chip8 emu?

if so il start ;)

i assume writing the cpu core is the first thing to start with
 
Last edited:

cloudy

New member
GB emu opcodes question

Hey all,

I just need confirmation about how the gameboy opcodes work. All opcodes are 1 byte in size and the immediate data can be between 0 and 2 bytes correct?

So when i read the gb game into a byte array, i take it i should read the opcode first and the read the next index in the array as the immediate value (assuming of course that the opcodes immediate data is 1 byte).

So for instance the opcode 06 loads 1 byte of immediate data into register B.

So if for example i hexedited the gb game and seen the instruction 06AA. I would then load the value AA into register B?

So for example is this correct (psudo code):

Code:
opcode = byteMemory[instructionPointer] ;

switch(opcode)
{
 case 06: 
   register[REG_B] = byteMemory[instructionPointer+1];
   instructionPointer += 2;  // is this correct? for a load opcode anyway     
}

Thanks for any help

Edit:

Whats the deal with opcode 7F?

You have to Load RegisterA into RegisterA... whats the point?
 
Last edited:

Top