PDA

View Full Version : 6502



Kevin19
July 14th, 2004, 16:55
I encountered a sort of dilemma

I almost am done emulating the CPU and now i got the pull all flags off the stack

And i actually divided the flags into a series of variables other than one byte

And pushing 8 variables of int type onto the stack is going to mess it all up

So i thought of this idea and i just wanted to confirm and consult it with you people

I thought maybe i could parse it into a char type variable the all 8 integers
and then put it as one chunk up

and when i pull it i will do the same thing only reversely And segment it again into the 8 int variables

what do you people think

Azimer
July 14th, 2004, 17:53
That is called packing and unpacking. Consider the price of this method as opposed to using a bit manipulation method in the emulated operations.

Kevin19
July 14th, 2004, 19:52
I am almost done about 92% of the instructions i have already implemented

And this packing and unpacking method whatever you called it might be the soultion to my problem

Because changing now the setup of the functions is going to be very amateur
and cumbersome

smcd
July 14th, 2004, 20:31
You are using separate variables as opposed to a single one, and toggling bits? :yucky:

aprentice
July 14th, 2004, 20:42
Bit manipulation used correctly would probably be more efficient that the method you currently use, as well as more cleaner.

Kevin19
July 14th, 2004, 20:59
I do not mean to be rude but in order to use the approach You just suggested
I will have to alter more than 80 functions
I did not want to say it the first time Because i did not want to sound impolite
But your suggestion just does not sound very inviting

zenogais
July 14th, 2004, 21:04
I do not mean to be rude but in order to use the approach You just suggested
I will have to alter more than 80 functions
I did not want to say it the first time Because i did not want to sound impolite
But your suggestion just does not sound very inviting

Well are you talking about casting the integers to type char?

i.e.


char* largeSetOfIntegers = (char*)&myInteger1


Because I'm not exactly clear on what you mean by parsing out the values, do you mean finding the MSB that is set and then converting into the appropriate number of chars based on that or something. Sorry, I just need a llittle more explaining, maybe a code example.

Doomulation
July 14th, 2004, 21:05
You don't absolutely HAVE to. It's your choice really...
Since you've already used the second way I'd (if I were you of course) NOT do it :whistling

Kevin19
July 14th, 2004, 22:09
It took me approximately 2 days to finish coding my first emulator which was the CHIP8

and this 6502 emulator i seem to be working on for almost a week now

And i am only in the range of after reestimation 80 percent to 95 percent done

And in addition to this amount of time i am working on it which is quite a bit I think i would hate to think of revising it because of one little error

That is why i asked for your opinion on this People

And that is why i also said that i do not want to be rude

Because his idea a bit irked me to think of this revision

zenogais
July 15th, 2004, 00:38
From what I've read it would appear that the processor for the 6502 has 7 1-bit flags stored in the status register. The stack appears to have to ability to push and pop values 8-bits long. All you would have to do is cast the flags integer value to a value of char* and then push that onto your stack, a relatively simple operation.



int statusRegister;
void push(char cPushValue);
...
push( (*(char*)statusRegister) );
..or..
push( (char)statusRegister&0xFF );

Kevin19
July 15th, 2004, 01:43
Hah Hah Hah

aprentice
July 15th, 2004, 03:35
It took me 3 hours to emulate the 6502 using bit manupulation and jump tables, the 6502 is super easy to emulate. (I'm not working on an nes emu though, i did this core over 2 years ago).

Also Kevin, you attitude sucks, and with that attitude, i don't expect you to get far. If you do not wish to accept anyones suggestions because "I must do everything my own way from scratch completely on my own", then stop asking us for advice because your posts seem utterly pointless. This is an observation from every thread you created, not just this one :P We cannot help you if you do not want to be helped, rule of the thumb. And drop that "I dont mean to be rude" crap, its annoying :P

smcd
July 15th, 2004, 03:49
Or if he wants to do it on his own with suggestions, ask BEFORE doing the damn project, instead of waiting until he did it his way and then refusing to go back and change anything.

Kevin19
July 15th, 2004, 09:30
Cannot argue with that

You are right

Azimer
July 15th, 2004, 10:03
Before all the clutter happen, I simply made a suggestion for an alternative. If well defined #define's were used (assuming C code) than you would have only needed to change a small bit of code. But that is not the case so my suggestion is invalid unless you care to do a major revision. You seem to know what you need to do, and I suggest you go ahead and do it. No furthur discussion is needed. You asked for our opinion and you received it. Good luck.

Kevin19
July 15th, 2004, 12:23
Well Thank you
But yes i already chose the packing unpacking whatever you called it

void PHP()
{
int empty=0;
char P=0;
P=(P<<0)|Negative;
P=(P<<1)|Overflow;
P=(P<<1)|empty;
P=(P<<1)|BreakPoint;
P=(P<<1)|Decimal;
P=(P<<1)|IRQDisable;
P=(P<<1)|Zero;
P=(P<<1)|Carry;
Memory[SP--]=P;
}

void PLP()
{
int empty=0;
char P=Memory[++SP];
Negative=(P&0x80)>>7;
Overflow=(P&0x40)>>6;
empty=(P&0x20)>>5;
BreakPoint=(P&0x10)>>4;
Decimal=(P&0x8)>>3;
IRQDisable=(P&0x4)>>2;
Zero=(P&0x2)>>1;
Carry=(P&0x1)>>0;
}

anyway goodnight
I am going to sleep now

zenogais
July 15th, 2004, 19:38
void PHP()
{
int empty=0;
char P=0;
P=(P<<0)|Negative;
P=(P<<1)|Overflow;
P=(P<<1)|empty;
P=(P<<1)|BreakPoint;
P=(P<<1)|Decimal;
P=(P<<1)|IRQDisable;
P=(P<<1)|Zero;
P=(P<<1)|Carry;
Memory[SP--]=P;
}


This is my suggestion, you aren't likely to take it :yucky: but this piece of code looks messed up. The problem is that you are shifting over the value of P and or'ing it with the next flag, which is just plain wrong, I believe this is what you should've done:



void PHP()
{
int empty=0;
char P=0;
P|=(Negative<<0);
P|=(Overflow<<1);
P|=(empty<<2);
P|=(BreakPoint<<3);
P|=(Decimal<<4);
P|=(IRQDisable<<5);
P|=(Zero<<6);
P|=(Carry<<7);
Memory[SP--]=P;
}

bjz
July 15th, 2004, 20:46
Before all the clutter happen, I simply made a suggestion for an alternative. If well defined #define's were used (assuming C code) than you would have only needed to change a small bit of code. But that is not the case so my suggestion is invalid unless you care to do a major revision. You seem to know what you need to do, and I suggest you go ahead and do it. No furthur discussion is needed. You asked for our opinion and you received it. Good luck.

http://xenge.emulation64.com/shotdown.gif

:party:

Kevin19
July 16th, 2004, 14:43
Thank you for your suggestion but my code seems to work swell
Instead of putting effort into revising it into a looker

I think i am going to take this effort and get done with the CPU

A it was very late when i came up with it after a long series of failing attempts
B If i wanted any of my code to look good I would have to change half of the program and that is just a tremendous time consumer do not you agree

I am sorry if i am attacking you
I am a bit tipsy right now after a spin of the cheapest vodka in town
I am going to sleep now Goodnight everyone

Doomulation
July 16th, 2004, 18:53
Well, doesn't that teach you not to get drunk? ;)

smcd
July 16th, 2004, 20:33
I must agree, Kevin19's code doesn't look like it does anything functional in the above post (PHP function especially).

Kevin19
July 16th, 2004, 22:13
I must say you do not sound like a programmer with much experience
if you cannot instinctively analyze a code in your mind and pass a judgement on it whether it is working or not

But then again i would not want to say anything bashing

and doomulation the only thing that last night taught me

is not to get a cheap vodka
You know getting drunk can make a person really happy but not with the inappropriate booze last night i punched out all my stomach
i vomited all over myself and swam in my own vomit
do you have any idea what it feels to swim in your own stomach contents and actually enjoy it

zenogais
July 16th, 2004, 22:20
I wasn't making an argument about the aesthetic value of the code, I was saying that its just plain wrong and your emulator will fail because of it, but hey its not my emulator ;)

Kevin19
July 16th, 2004, 22:35
I beg your pardon
But i have already tested the code and it seemed to work beautifully
But i am not bringing anything new into your attention
Because i have already said that i did and yet you bother have your response

By the way i would have put one of those faces too but unfortunately i do not have enough time to switch to the advance mode

Kevin19
July 16th, 2004, 22:42
Yes out of request or lack of attention to my previous sentence which saliently indicated you that i have tested out my code and that it worked swell and yet you bothered to reply again

I have checked my code again and yours too and yours and mine shows the number 3 when the first 2 bits are set and yours seem to be showing the number -64

zenogais
July 16th, 2004, 22:56
Yes out of request or lack of attention to my previous sentence which saliently indicated you that i have tested out my code and that it worked swell and yet you bothered to reply again

I have checked my code again and yours too and yours and mine shows the number 3 when the first 2 bits are set and yours seem to be showing the number -64

That indicates to me that you are using signed integers, meaning that the twos complement bit gets set, but its not the value anyhow, its the bit placements. So spitting out three doesn't really indicate anything except that the flags in bits 0 and 1 would be set. In this case that would appear to be the negative and overflow flags.

Kevin19
July 16th, 2004, 23:01
spitting out three actually indicates the bits placement in the byte so i think it is pretty much the ultimate indicator that we have unless we used something lower than this language

and the fact that the number is signed and unsigned does not really change anything i checked it out both ways and it seems to do the same thing

I do not want to be ungrateful of your help
but please put your code to test before you post it
It might mislead the unwise to great mistakes

zenogais
July 16th, 2004, 23:34
spitting out three actually indicates the bits placement in the byte so i think it is pretty much the ultimate indicator that we have unless we used something lower than this language

and the fact that the number is signed and unsigned does not really change anything i checked it out both ways and it seems to do the same thing

I do not want to be ungrateful of your help
but please put your code to test before you post it
It might mislead the unwise to great mistakes

Most of that post was just a repeat of what I said, also, that code was tested. The problem with your code is that you're only writing to two bits of the entire byte. Meaning that the values of your flags register could only be 0, 1, 2, or 3. My code works as I have tested it, but here's a suggestion for testing yours. Try setting your flagss to something like this:

Negative = 1
Overflow = 1
BreakPoint = 1
Zero = 0

and then try reading out the values for each flag:



Negative = (P>>0)&0x1; //< Should work fine.
Overflow = (P>>1)&0x1; //< Whoops, error!.
BreakPoint = (P>>4)&0x1; //< Whoops, error!
Zero = (P>>6)&0x1; //< Works fine.


I think you'll see that performing tests similar to that should show whose code truly works and whose doesn't. I'm not trying to start a flame war, merely I'm trying to help you fix a bug, so please just test my advice and answer truthfully. I've already tested your code and it failed.

refraction
July 16th, 2004, 23:34
spitting out three actually indicates the bits placement in the byte so i think it is pretty much the ultimate indicator that we have unless we used something lower than this language

and the fact that the number is signed and unsigned does not really change anything i checked it out both ways and it seems to do the same thing

I do not want to be ungrateful of your help
but please put your code to test before you post it
It might mislead the unwise to great mistakes

his code worked fine for me, and i checked it over, theres nothing wrong with his code.

Kevin19
July 16th, 2004, 23:48
Yes his code did it work well except for it was in the wrong order

and i really did not want to bother to revise mine and yes i checked mine over and over again and it seemed to work swell

RipNLa
July 17th, 2004, 09:10
Although I've been reading the board I haven't posted since the main Chip8 thread, but man, reading Kevin19's posts are aggravating. I agree with the mod that didn't like his attitude. And before I get told to just not read his threads, I just want to say that I read them for the tidbits of good info I get from guys like Zenogais. Alrighty, thats all. Everyone can resume posting and programming now.

Kevin19
July 17th, 2004, 12:31
You are right i do have an attitude problem
And if that is what you think of me
Then i will just say that i apologize and resign

Goodbye

refraction
July 17th, 2004, 19:26
You are right i do have an attitude problem
And if that is what you think of me
Then i will just say that i apologize and resign

Goodbye


i think the problem is you dont accept where your wrong. this is my interpretation of how the convosation goes

Kevin19: hmm something isnt working properly with this x part
someone: Ah the problem is with this bit of your code
Kevin19: no its not, my code is perfectly fine.

Kevin19
July 17th, 2004, 20:33
I am sorry but that is really not my problem

I can admit when i am wrong for instance when i admitted that zenogais code was alright except for the right order part which i think is what misled him to think my code was wrong

When i checked it for over more than 4 times and the bits seemed to be right in place

I can admit when i am wrong and i can admit when someone else is not

But I think this is going to be my last message on this forum so please do not even bother to reply

I admit that i have been a pain in the ass But i can at least admit it
And if that is what you people feel about me
Then i guess goodbye everyone

Have a nice life

refraction
July 17th, 2004, 20:35
*gets out the violin* have fun coding.