Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Memory Access Problems

Reply to topic
Author Message
Chris
  • Guest
Reply with quote
Memory Access Problems
Post Posted: Mon Nov 08, 1999 4:57 am
Why does C have to be so damn ubelieveable sometimes!? It seems like everytime I try to do
modular programming in C with the passing of parameters and variables and all, I run into more
complicated problems. Ahh well, here's my new problem.

I created a function simply called Emulate and it passes 2 parameters: CPU and ROM. Like this:

void Emulate(CPU *b80,unsigned char *rom);

The b80 is properly dereferenced but there's some major problems with rom. Oh yeah,
in my main program I declared 'CPU Z80' and 'unsigned char *ROM' and those are the variables that
I'm using to pass through to Emulate. Like this:

Emulate(&Z80,&ROM);

Now, everything in the function works just fine, CPU and variable assignment wise, but there's a big
problem with ROM. Under Emulate, all of the data that was originally stored in ROM is being
ignored and the function is accessing a whole different area of memory. So basically, it's
emulating the wrong block of memory and I can't figure out why. For debugging purposes,
instead of using functions and passing parameters, I did the emulation loop inside of the
'main()' portion of the program and it worked just fine. And yes, I am properly reading the
ROM file data into the allocated block of memory because I check the values via hex editor
and they matched up.

Please help,

Chris :o)
 
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Post Posted: Mon Nov 08, 1999 5:21 am

Quote
> Emulate(&Z80,&ROM);

The statement '&ROM' means you are getting the address of the
pointer named 'ROM', not the address of the data the pointer
points to. You can do this instead:

Emulate(&Z80, ROM); *or* Emulate(&Z80, &ROM[0]);

If you want to know what this looks like visually, try this:

char *rom;
:
rom = malloc(0x8000);
printf("%08X %08X %08X
", rom, &rom, &rom[0]);

You'll notice that the 1st and 3rd references to the rom
pointer will correctly give the address of the memory block
returned by malloc, where the 2nd one is just the address
of the pointer itself.

Yes, pointers are very difficult to get a grip on. :)
  View user's profile Send private message Visit poster's website
Chris
  • Guest
Reply with quote
Thanks
Post Posted: Tue Nov 09, 1999 1:47 am
It's amazing how one little character can effect the entire program.

Chris :o)
 
Reply to topic



Back to the top of this page

Back to SMS Power!