Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext Thread*Show in Threaded Mode


Subjectnewbie CPU emulator questions new Reply to this message
Posted byMr_edward
Posted on05/11/04 02:41 PM



Hello

I am trying to figure out how an CPU emulator works. Iam trying to write a simple 6502 emulator programmed in c. atm iam trying to load an compile 6502 binary file into an array but i cant get it to work :(. I've tried messing around with the code sniplets in Dan Boris emulator tuturial. I have only been learning c for a little while so it could be my code. anyways iam wondering if anybody can help me out? here is my code : -

#include

int main()
{

int memory[0x001f];int i;


FILE *fp;


fp=fopen("LOADTEST.NES","rb");

if (!fp) {
printf("Error loading game.rom\n");
return 1;
}

read(&memory[0x0000],1,0x001F,fp);

fclose(fp);


for(i=0; i < 0x001f; i++)
{
printf("The value at %x is %x\n",i, memory[i]);

}


return 0;
}


what i have tried to do is load loadtest.nes into an array then read it out using an for next loop.

Every time it reads the array it comes up with werid hex numbers that are not in the rom?

Sorry for such a silly question but iam quite curious to find out how it works :D

Thanks in advance :)




SubjectRe: newbie CPU emulator questions new Reply to this message
Posted byBart T.
Posted on05/11/04 03:42 PM



> int memory[0x001f];

Try "unsigned char" instead of "int" and see if that helps.


----
Bart


SubjectRe: newbie CPU emulator questions Reply to this message
Posted byMr_edward
Posted on05/12/04 05:57 PM



> > int memory[0x001f];
>
> Try "unsigned char" instead of "int" and see if that helps.
>

thanks for your help but it still reads out funny values? :(
>
> ----
> Bart
>



SubjectRe: newbie CPU emulator questions new Reply to this message
Posted byfinaldave
Posted on05/13/04 05:31 PM



> > > int memory[0x001f];
> >
> > Try "unsigned char" instead of "int" and see if that helps.
> >
>
> thanks for your help but it still reads out funny values? :(

What funny values does it read?


By the way, try fread instead of read


> >
> > ----
> > Bart
> >
>


You learn something old everyday...



SubjectRe: newbie CPU emulator questions new Reply to this message
Posted byMr_edward
Posted on05/14/04 04:17 PM



> > > > int memory[0x001f];
> > >
> > > Try "unsigned char" instead of "int" and see if that helps.
> > >
> >
> > thanks for your help but it still reads out funny values? :(
>
> What funny values does it read?
>
>
> By the way, try fread instead of read
>
>
> > >
> > > ----
> > > Bart
> > >
> >
>
>
> You learn something old everyday...
>

yeah thanks that works fine :D it reads in the right values now instead of different values :)


Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode