Jump exection code to RAM

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
squall926
Posts: 21
Joined: Wed Jan 03, 2018 3:50 pm

Jump exection code to RAM

Post by squall926 » Mon Feb 10, 2020 3:15 pm

Hello!
How can load a code in internal ram and jump execution to this on snes, more precise pvsneslib? No tried code this but no idea how.

Thanks for attention!!!

User avatar
Memblers
Site Admin
Posts: 3786
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Jump exection code to RAM

Post by Memblers » Mon Feb 10, 2020 4:23 pm

I've zero experience with the tcc compiler, but I looked through tcc-doc.html out of curiosity. It doesn't explicitly say you can do that. But I did see where it said: "ind contains the current position in the code section". I have no idea what that actually means or implies. Is that "ind" something you can set manually, or is that read-only? Can you make a new section and change "ind"? If there's a relevant attribute for the section, I didn't see it in the doc..

I know with cc65, (or ld65 specifically) when you make a segment, you can specify load and run attributes if you need them to be different. Then your program would need to copy it from the load address to the run address, the compiler doesn't do this for you.

squall926
Posts: 21
Joined: Wed Jan 03, 2018 3:50 pm

Re: Jump exection code to RAM

Post by squall926 » Wed Feb 12, 2020 5:45 pm

I do a function point in c, Tha's work after copy the function to ram. But sometimes crash. I think ill need do in asm.
In pvsneslib

nocash
Posts: 1137
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: Jump exection code to RAM

Post by nocash » Wed Feb 12, 2020 6:35 pm

But why? Using code in RAM only makes sense if you were using self-modifying code (which is unlikely in C), or if you want to artifically slowdown a fast ROM cartridge to slow RAM timings (makes no sense at all), or when removing the ROM cartridge.

tepples
Posts: 21843
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Jump exection code to RAM

Post by tepples » Wed Feb 12, 2020 6:46 pm

Or when making a Super Game Boy native mode game (like Space Invaders). Or when making a multicart menu (similar to removing the cartridge).

Something I plan to do this year, and something I've done.

squall926
Posts: 21
Joined: Wed Jan 03, 2018 3:50 pm

Re: Jump exection code to RAM

Post by squall926 » Thu Feb 13, 2020 12:41 pm

I got a cart with 4MB sram and a slow mcu(avr128).
So when i need program the memory i block access on chips, and menu crash and after finish i do hw reset.
I want copy a block code to internal ram and jump to it, so this way the menu keep work, and if possible, keep updating the bus with info about writting progress(this part is easy), i'm no a good programmer asm, tried in C using function point, crash.
the code need check cart rom area who return b10000000 so MSB is done or no and others bits 128 write status.
Good, this is the ideia. :beer:


Ahhh! C is because pvsneslib make snes a lot more easy!

Thanks for attention :D

nocash
Posts: 1137
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: Jump exection code to RAM

Post by nocash » Thu Feb 13, 2020 8:25 pm

Technically it is trivial, and more so because it can be tested in snes debuggers.
The main problem would be to figure out how to tweak your assembler or compiler to assign ram addresses for relocated code/data. And of course, knowing how to memcopy code from rom to ram.
And some good understanding of all related memory addresses, including function & subfunction addresses, data addresses for variables and stack, and exception vectors.

Post Reply