What's new

Game Boy

aprentice

Moderator
glVertex3f said:
I am so sorry for posting again..
(If you want I'll start my own thread if im disrupting progress)

I just want to make sure I am doing this right before I continue
(No, this isnt something im gonna do on every op-code)

Code:
void ADC_A_HL()
{
	
	unsigned char carry_flag = ((gbReg.F & gbReg.CF) >> 4)
	unsigned char temp_value = gbMemory[gbReg.HL];
	
	gbReg.A += (temp_value + carry_flag);
	
	if(gbReg.A == 0)  SetFlag(gbReg.ZF, 7);
	if(gbReg.A > 15)  SetFlag(gbReg.HF, 5);
	if(gbReg.A > 255) SetFlag(gbReg.CF, 4);
	
	ResetFlag(gbReg.NF, 6);
	
}

gbReg.CF is 0x10, and the SetFlag functions, the first argument is the Flag to be set and the second argument is the bit number.

Now, if this is wrong, I appologize again.. I just need to be pointed in the right direction :eek:

The whole opcode is wrong, back to the drawing board for you :p
We could tell you the correct code, but then we wouldn't be helping you, so read the docs one more time more carefully and give it another shot :p And half carry is the carry from bit 3 to 4 by definition, so look into that.
 
Last edited:

glVertex3f

Crap Cracker
Well, as far as the set flag function I was doing this

Code:
void GBmemory::SetFlag(unsigned char bit_num, unsigned char bit_shift)
{
	
	if(((gbReg.F & bit_num) >> bit_shift) != 1)
		gbReg.F += bit_num;
		
}

And yes I guess I obviously need to read the docs much more thoroughly as it sounds like I missed a whole lot.

But it was 2AM :p
 

bcrew1375

New member
aprentice, could you post that document that has the BCD information in it. It might have some other information I've been looking for :p.
 

glVertex3f

Crap Cracker
Ugh, ive been looking over my code only to fild that it was in a mess.

I guess thats what I get for programming while half awake (I have to quit doing that).

Here is my code, I cant really just post the ADC (HL) opcode by itself and have it make sense.

If any of you have the time, (and the heart) :p, Please give it a once over and make sure im actually getting this.

And bcrew, why do I need to modulate the registers?

Also note, to those of you who helped with my ChipAte (nearly all of you), I think you should be able to see a great difference in my coding style. To me it seems more "neat" and organized and overall moe readable.
 
Last edited:

zenogais

New member
Really you need to just code and stop asking people to walk you along in coding emulators. The gameboy is loads more complex than the Chip8, and if you're not understanding whats going on you should do some research or try something simpler.
 

aprentice

Moderator
zenogais said:
Really you need to just code and stop asking people to walk you along in coding emulators. The gameboy is loads more complex than the Chip8, and if you're not understanding whats going on you should do some research or try something simpler.

I have to agree with Zenogias on this. I think the real problem here is not his lack of understanding of the gameboy, its the lack of solid programming skills, which is required to take on a task such as the gameboy. Lack of understanding of how bits work is a major set back as well. I think glVertex should first enhance his programming skills, and start with simple programs instead of jumping into the complex world of emulators as a beginners program. I know he will just ignore this advice just like he has ignored many other peoples advice, though.
 

refraction

PCSX2 Coder
my programming isnt spectacular, i dont know a lot about the gameboy (at the moment but that document is really helping) but im still gonna have a shot at it, im sure i will understand the system better the more of it i emulate, or attempt :)

i was the same with chip8, kinda didnt understand it at first, but the more i made of the system, i realised how it worked and understood the system better.
 

glVertex3f

Crap Cracker
Look, the only reason I was asking is to make sure I had the basic concept of what the DOCS were saying. I mean wouldnt you hate to program all of the opcodes when all along you were just missunderstanding what the docs were saying?

I'll admit I had alot of trouble with Chip8, and I know I wouldnt have been able to do it if it werent for all the help. But now I understand the concepts of emulation and I am confident in my programmming skills. You just have no idea how much the chip8 emulator has taught me. It caused me to look deeper into my language and understand ten times that of wich I knew before.

But i hope that if you look at my code (what little there is), you will see that I am serious about this and I am looking forward to the things that this emulator will teach me.

I understand that for most people, programming an emulator shouldnt be a place to learn, but I know I can do it.

I will try to continue and do as much as I possibly can without asking for help.
 

aprentice

Moderator
glVertex3f said:
I mean wouldnt you hate to program all of the opcodes when all along you were just missunderstanding what the docs were saying?

The stuff your asking for help has nothing to do with emulation, its purely bit math, which you should already understand before you touch emulation. I would like to help you, but not with learning the concepts of programming, that is your responsibility. If you have a question with something EMULATION related, then by all means ask, everyone here has a question or two, and its understandable. I will not answer any C++ related questions.

PS: I'm not trying to sound rude, but the attitude in gl's post slightly ticked me off...
 

glVertex3f

Crap Cracker
I am really sorry, I honestly didnt write that post with any kind of negative attitude.

I guess I am merely confuse because I dont understand what you mean. I have a ver good understanding of bit math, and my main question was actually dealing with what the docs were saying. I guess I should have made this clearer in the beginning.

See my main problems were things like not understanding what
(HL)
meant, I know HL is a 16 bit register, I just at first thought that I added the VALUE of HL (+ carry) to the A register. I didnt know that the parentheses around the HL meant a memory location.

Anyway, it was things like that that were throwing me off. Nothing C++ related at all.

And the bit of code I posted (not the attachment) is code I wrote at 2am while I was half asleep, so excuse that bit :p

Now, if the code in the atachment is still way off, then I guess I am very wrong and there is something I am missing greatly, but I will never know what if you dont tell me.

I am very sorry if I have been sounding rude. I, in no way, meant to sound rude at all.
And thanks aprentice for not getting rude, you have very great patience :)

OH OH EDIT EDIT:

I know I have this

ADC_A_HL()
ADC_A_CONST8()
ADC_A_REG8()

when all i need is

ADC(unsigned char value)

I just wanted to let you know that that was one of those 2am things.
:whistling

lol no wonder you guys got ticked off at me (I ticked myself off)

I believe this should be right for the ADC opcode

Code:
void GBcpu::ADC(unsigned char value)
{
	
	unsigned char carry_flag = ((REG_F & CF_MASK) > 0) ? 1 : 0;
	unsigned char temp = (value + carry_flag);
	
	if(REG_A + temp == 0)   SetFlag(ZF_MASK);
	
	ResetFlag(NF_MASK);
	
	if((REG_A + temp) > 0xF)  SetFlag(HF_MASK);
	if((REG_A + temp) > 0xFF) SetFlag(CF_MASK);
	
	REG_A += temp;
	
}
:blush:
 
Last edited:

bcrew1375

New member
It looks like it MIGHT work, assuming you are correctly assigning values to the flags. Post the code again once you've done alot more work.
 

glVertex3f

Crap Cracker
I have just about all the opcodes programmed (whether they are right or not)
I was wondering about a few things.

the opcodes that have conditions, how do you tell what the conditions is?

also, I was wondering about the stack, I cant seem to find anywhere in the docs that have the size of it. Im not sure how much memory to allocate for it. (I assume it would either be a 0xFFFF or just simply use tha already allocated memory).

And without telling me how to do it, What exactly does the DAA opcode do?
 

bcrew1375

New member
The condition is hard-coded into the opcode. The stack uses the Gameboy's internal memory. The DAA(Decimal Adjust A) instruction is meant to convert the A register into its proper packed-BCD representation.
 

aprentice

Moderator
Heres the DAA code everyones been asking for, it runs right out of the box :p
PHP:
 void op0x27() //DAA
{
   if(regF&0x40) //Negative Flag Set
   {
      if((regA&0x0F)>0x09 || regF&0x20)
     {
        regA-=0x06; //Half borrow: (0-1) = (0xF-0x6) = 9
        if((regA&0xF0)==0xF0) regF|=0x10; else regF&=~0x10;
     }

     if((regA&0xF0)>0x90 || regF&0x10) regA-=0x60;
   }
   else
   {
       if((regA&0x0F)>9 || regF&0x20)
       {
           regA+=0x06; //Half carry: (9+1) = (0xA+0x6) = 10
           if((regA&0xF0)==0) regF|=0x10; else regF&=~0x10;
        }

        if((regA&0xF0)>0x90 || regF&0x10) regA+=0x60;
    }

    if(regA==0) regF|=0x80; else regF&=~0x80;
}

I read up in BCD and I also had a peak on how other emus do it and tried to get an understanding of how it works. I didnt use any macros in this code so everyone should be able to use it without any mods.

I finally broke some walls that I ran into and the games that run that werent playable before are now :p Apparently it was a bug in my interrupt system that had me boggled, but now solved :p Also, I completely redid timing, although that didnt really have any major visible effects.
 
Last edited:

aprentice

Moderator
Got tired of hardcore debugging of my bug infested emulator, so i added gameboy color support, which is very raw and prilimary at the moment, to take a small break from bug fixing :p

No commercial games run except a few menus in tetris dx. Second screen is from a gameboy color demo game called jet pack dx :p

gbc_tetrisdx01.gif

gbc_demo_jetpakdx.gif


edit: I didnt add this in the past 3 hours, i actually did it a few days ago (havent touched the emu in the past few days) and fixed a few bugs to make it start working. Just wanted to make it clear so people don't think its a cinch to add, although its not too hard, it just takes a lot of figuring out :p
 
Last edited:

bcrew1375

New member
Man, no offense, but that code is a pain to look at :p. I tried it, I'm still getting incorrect values, but not as bad as my implementation. Maybe I'm setting some flags wrong :/. I'm still trying to understand how this works.

Edit: Congratulations on the GBC support :p.
 

aprentice

Moderator
bcrew1375 said:
I tried it, I'm still getting incorrect values, but not as bad as my implementation. Maybe I'm setting some flags wrong :/.

Which games you testing the DAA code on?
And setting flags wrong could cause incorrect values since the F flag plays a major role in getting the right numbers
 

Top