What's new

6502

Kevin19

New member
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

Emulator Developer
Moderator
That is called packing and unpacking. Consider the price of this method as opposed to using a bit manipulation method in the emulated operations.
 
OP
K

Kevin19

New member
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

Active member
You are using separate variables as opposed to a single one, and toggling bits? :yucky:
 

aprentice

Moderator
Bit manipulation used correctly would probably be more efficient that the method you currently use, as well as more cleaner.
 
OP
K

Kevin19

New member
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

New member
Kevin19 said:
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.
Code:
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

?????????????????????????
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
 
OP
K

Kevin19

New member
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

New member
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.

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

aprentice

Moderator
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

Active member
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.
 

Azimer

Emulator Developer
Moderator
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.
 
OP
K

Kevin19

New member
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

New member
Kevin19 said:
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:

Code:
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

New member
Azimer said:
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.

shotdown.gif


:party:
 
OP
K

Kevin19

New member
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
 

Top