What's new

Game Boy

bcrew1375

New member
aprentice said:
I touched mine last week, put it direct sound code, just havent gone beyond that yet regarding sound, i might give it a go today.. btw, is your emulator generating any good sound since you said your close to getting channel 3 working?

I haven't got any sound out of a game yet, but I'm beginning to understand more and more how Channel 3 works after reading the docs over and over and over. However, I know my sound setup is correct, since I got it to play some raw sound data correctly. Probably the most confusing part is how I am going to adjust the samples to play at the correct speed.
 

zenogais

New member
I've been working on my emulator on and off, just polished off the CPU and debugged it using Executaboy :p , added Interrupt support and I'm now working on drawing. I've been extremely busy working on a webpage for someone, but when I get back to it cross your fingers, hopefully something will show up this time :D.
 

KaioShin

New member
Hi!

I started working on a GB emu too, just last week. I am nowhere near a "showable" state though (Haven't even touched Grafics yet). I am collecting some Demos to test stuff. In this thread you mentionend a Interrupt Demo earlier. I googled for it but could not find it. From some info I found I know its so PD so could someone upload it?

Regards, KaioShin

EDIT: Never Mind, I finally got it (Those creepy "vote 100 times" Rom-Sites should stick to GoodGbx naming convention :saint: ).
 
Last edited:

zenogais

New member
KaioShin: Best of luck to you, and if you have any questions feel free to ask. :) I hope you know what you're getting yourself into. :p
 

ShizZy

Emulator Developer
zenogais said:
KaioShin: Best of luck to you, and if you have any questions feel free to ask. :) I hope you know what you're getting yourself into. :p
It's a blast bro. Enjoy this part while it lasts... the fun comes when you start debugging ^^
 

ShizZy

Emulator Developer
Anyone make any progress? I'm not the only one still working on one, am I? I busted my laptop, and need to buy a new one before I can get back to coding - but mine is still very much allive.
 

HyperHacker

Raving Lunatic
You might be. I was spending all my time on a Pokémon map editor, and then my motherboard fried so I have to wait to get a new one. :(
 

bcrew1375

New member
I've been catching up on video games lately. I plan to get back to mine soon. I'm pretty sure I fully understand Channel 3 now. I just can't figure out how to implement it :/.
 

aprentice

Moderator
bcrew1375 said:
I've been catching up on video games lately. I plan to get back to mine soon. I'm pretty sure I fully understand Channel 3 now. I just can't figure out how to implement it :/.

i dont understand how to play back the WAVE data, i dont think you can just read it into a buffer and play it off the bat, not exactly sure how to approach it..
 

ShizZy

Emulator Developer
Could anyone help me with my STAT code? Trying to get my timings right so the proper modes are set at the right time. Something major is wrong... I've attached my cpu, but here's some basic snippets of the code:

Here's the actual set mode function, stollen from Aprentice (this part works fine, it's the calling of it that is off):
Code:
	#define reqINT(x) IOReg_IF|=x;

	void VIDEO::SetLCDCMode(int mode)
	{
		IOReg_STAT=(IOReg_STAT&0xFC)|mode; //Clear and set bits 0,1
		switch(mode)
		{
			case 0: //HBlank
				if(IOReg_STAT&0x08) reqINT(INT_LCDC);
				break;
			case 1: //VBlank
				if(IOReg_STAT&0x10) reqINT(INT_LCDC);
				break;
			case 2: //OAM
				if(IOReg_STAT&0x20) reqINT(INT_LCDC);
				break;
			case 3: //Transfer
				//if(cpu.hdma&0x80) hdma_hblank();
				break;
		}
	}
Now, here's where I call it. This is in my main CPU loop, shortly after I execute my opcode...
Code:
			/* handle input/output */

			// set STAT mode

			cpu.count_stat+=cpu.cycles;

			if(cpu.count_stat_mode==0 && cpu.count_stat>=CYCLES_OAMTRANSFER){
				vid.VIDEO::SetLCDCMode(MODE_HBLANK);
				cpu.count_stat_mode=1;
				cpu.count_stat=0;
			}else{
				if(cpu.count_stat_mode==1 && cpu.count_stat>=CYCLES_HBLANK){
					vid.VIDEO::SetLCDCMode(CYCLES_TRANSFER);
					cpu.count_stat_mode=2;
					cpu.count_stat=0;
				}else{
					if(cpu.count_stat_mode==2 && cpu.count_stat>=CYCLES_TRANSFER){
						vid.VIDEO::SetLCDCMode(MODE_OAMTRANSFER);
						cpu.count_stat_mode=0;
						cpu.count_stat=0;
					}else{
						if(cpu.count_stat_mode>2 && cpu.count_stat<CYCLES_VBLANK*10){
							cpu.count_stat_mode=0;
							cpu.count_stat=0;
						}
					}
				}
			}

			// main input and output

			if (IOReg_LY < 144){
				vid.VIDEO::DrawScanline();
				
				cpu.count_stat_mode++;
				if(cpu.count_stat_mode==3)
				{
					cpu.count_stat=0;
					vid.VIDEO::SetLCDCMode(MODE_VBLANK);
				}
			}
That's basically it. It's kinna sloppy... bare in mind the first thing I do is set the OAMTRANSFER mode outside of the loop, that's why the first mode set is actually the HBLANK. Anyways, I bugged Aprentice on IRC enough about it, so hopefully you guys will see something wrong. Currently, I don't think it is working. :p Attached my core... STAT stuff is around line 2246. Thanks!

Regards,
 

bjz

New member
I havent looked at the file attatched but... if vid is an instance of VIDEO than you probobly want to call it

vid.SetLCDCMode()

instead of
vid.VIDEO::SetLCDCMode()


But.... like I said I havent looked at your code so I dont know what you have going on.
 

KaioShin

New member
I am currently working on the Stats register too, but I think I can't help you much because I am using another programminglanguage (Delphi). If I get mine working fine I will post the part (unlike the other way around Delphi is very readable for C users). ATM it counts up to 91 and then stops cause I did not yet wrote the part that distinguishes between LY > 144 in Mode 0 or Mode 1 (Was that sentence understandable? I Fear not :saint: ).
what i don't know is what bits 3-5 are for. Are these just additional Statusflags to check the mode by one bit instead of 2 ???
 

KaioShin

New member
One question:

When an Interrupt occurs and the Pc is pushed to the Stack and then a jump is performed, these steps consume clock-cycles, right?
 

ShizZy

Emulator Developer
Yeah... Just call your RST opcode which pushes the program counter onto the stack, and then jumps to the address. That opcode should use about 4 machine cycles (or 16 clock cycles).
 

HyperHacker

Raving Lunatic
Er, the RST addresses only go up to $38, and interrupt vectors start at $40. You could use 'di, call' though, but depending how your system is set up it might be easier to just manually push and modify the PC, disable interrupts and increase the cycle count. Should just mean modifying a few variables.

Also, at http://www.devrs.com/gb, they just dumped the original Gameboy bootROM. Might be fun to add support for that. :p
 
Last edited:

aprentice

Moderator
HyperHacker said:
Also, at http://www.devrs.com/gb, they just dumped the original Gameboy bootROM. Might be fun to add support for that. :p

interesting indeed, even more interesting is getting it to work :p

edit: ok, i got off my lazy ass and just did it myself..

gameboy_bootrom.gif


edit2: here is the emu (boot rom not included), put the bootrom in the same directory as the emu and make sure its named "DMG_ROM.bin". Then load the game and enjoy the show :p
 
Last edited:

KaioShin

New member
Apprentice I tried it with your emu and this is what I get:

BTW: I like this distorted Logo, so I made it my Avatar :)
 
Last edited:

Top