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 - On Topic Stuff

Reply to topic
Author Message
Consolemu
  • Guest
Reply with quote
On Topic Stuff
Post Posted: Sun May 14, 2000 6:34 pm
For my debugger, I would like to merge the cartridge data into the main address space. My problem is, how exactly do I do it? I found a way to work around stack by adding 0x100 plus the SP's value to correctly emulate that during push and pop. I don't know how to do that with rom though. I really tried to read and understand memcpy and some of the other functions but I couldn't find one that was like...
memory(destination,count,location,size)

Is there some other function or method for copying memory to a set position? I would like to copy 1 4K bank or page to 0x8000.

Chris :o)
 
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Post Posted: Sun May 14, 2000 8:07 pm
Quote
> For my debugger, I would like to merge the cartridge data into the main address space. My problem is, how exactly do I do it? I found a way to work around stack by adding 0x100 plus the SP's value to correctly emulate that during push and pop. I don't know how to do that with rom though. I really tried to read and understand memcpy and some of the other functions but I couldn't find one that was like...
> memory(destination,count,location,size)

Don't know if it's me, but I don't understand a word of what you are talking about.

Quote
> Is there some other function or method for copying memory to a set position? I would like to copy 1 4K bank or page to 0x8000.

memcpy ?
  View user's profile Send private message Visit poster's website
Consolemu
  • Guest
Reply with quote
Post Posted: Sun May 14, 2000 8:39 pm
The 6502 has a 16-bit address space. So it's entire memory is 0x10000 or 0xFFFF long. So, in order to emulate that I must do this...

memory = (BYTE *) malloc(0xFFFF);

Are we clear on this? The memory is laid out like this, I think...

0x0000 | 0x00FF > Zero Page
0x0100 | 0x01FF > Stack
0x0200 | 0x02FF > RAM (I think)
0x0300 | 0x7FFF > Misc Crap
0x8000 | 0xFFFF > Program Code

Almost every game, when it's reset or the system is started it's vector points to 0x8000. What I need to do is copy one 4K bank to 0x8000. If I can get the program code into 0x8000 then the emulation can continue. Without the program code, it's just a chain of 0's.

I already have the program code saved to one memory pointer called ROM. I need to merge ROM into Memory at offset 0x8000.

Chris :o)
 
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Post Posted: Sun May 14, 2000 8:43 pm
Quote
> For my debugger, I would like to merge the cartridge data into the main address space. My problem is, how exactly do I do it? I found a way to work around stack by adding 0x100 plus the SP's value to correctly emulate that during push and pop. I don't know how to do that with rom though. I really tried to read and understand memcpy and some of the other functions but I couldn't find one that was like...
> memory(destination,count,location,size)

> Is there some other function or method for copying memory to a set position? I would like to copy 1 4K bank or page to 0x8000.

You must be doing 6502 and NES stuff. :)
You'd do something like this:

char mem[65536]; // the virtual address space
char some_rom[16384]; // 16k of ROM, just for the heck of it

// copy 4k of rom to address 8000h
memcpy(mem + 0x8000, some_rom, 4096);

Another identical way to do it:

// copy 4k of rom to address 8000h
memcpy(&mem[0x8000], some_rom, 4096);

IMO, you should use arrays of pointers to handle bankswitching:

// array of pointers to map 16 4k chunks
char *read_map[16];

// read memory from the virtual address space
int read_mem(int address)
{
return(read_map[(address >> 12) & 0x0F][(address & 0x0FFF)]);
}

You could assign each pointer to a ROM page like so:

read_map[0x0E] = some_rom[page * 4096];

This way, reads from E000-EFFF would return data from
'some_rom', at whatever 4k offset was specified. It's much
faster than using memcpy which can be very slow, depending
on the implementation.

Hope this is related to what you're working on. :))



  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Post Posted: Sun May 14, 2000 9:49 pm
Handling these kind of stuff is done via your read/write handlers.
When the program try to read from 8000h+x, return the byte at ROM[8000h+x]
That's it.
  View user's profile Send private message Visit poster's website
Consolemu
  • Guest
Reply with quote
Beautiful!
Post Posted: Sun May 14, 2000 10:42 pm
That's exactly what I was looking for. All I needed to do is add the offset to the pointer. Go figure, eh?

Thanks! This is something that's really going to help me with a lot of projects in the future.

Chris :o)
 
Consolemu
  • Guest
Reply with quote
Cool
Post Posted: Sun May 14, 2000 10:47 pm
Quote
> Handling these kind of stuff is done via your read/write handlers.
> When the program try to read from 8000h+x, return the byte at ROM[8000h+x]
> That's it.

I get what you're saying now. But, I kinda like Charles' method a little better. I really want to keep everything encapsulated in that address space; like the real system would do it. So that way there's no confusion on my part or somehow by the emulation later on down the line.

Thanks for the help,

Chris :o)
 
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Re: Cool
Post Posted: Mon May 15, 2000 5:16 am
Quote
> I get what you're saying now. But, I kinda like Charles' method a little better. I really want to keep everything encapsulated in that address space; like the real system would do it. So that way there's no confusion on my part or somehow by the emulation later on down the line.

Sure, if you don't care about bankswitching speed issues.
  View user's profile Send private message Visit poster's website
Johannes
  • Guest
Reply with quote
Re: On Topic Stuff (not really)
Post Posted: Mon May 15, 2000 7:04 am
Quote
> 0x0000 | 0x00FF > Zero Page
> 0x0100 | 0x01FF > Stack
> 0x0200 | 0x02FF > RAM (I think)
> 0x0300 | 0x7FFF > Misc Crap
> 0x8000 | 0xFFFF > Program Code

Almost correct but the NES has 2KB of RAM (=0x800 bytes).
It should end at 0x07FF.

Quote
> Almost every game, when it's reset or the system is started it's vector points to 0x8000. What I need to do is copy one 4K bank to 0x8000. If I can get the program code into 0x8000 then the emulation can continue. Without the program code, it's just a chain of 0's.

You'd be better off copying 32KB to 0x8000 (two 16KB banks),
or 16KB to 0x8000 and 0xC000 if the rom only has one bank.
Which two 16KB banks you should be using depends on the mapper,
but usually it's the first one and the last one.
But then, (as you already know by now) you shouldn't be copying
anything :)

/Johannes
 
Reply to topic



Back to the top of this page

Back to SMS Power!