It is currently Tue Jun 18, 2019 4:32 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 1509 posts ]  Go to page Previous  1 ... 97, 98, 99, 100, 101
Author Message
PostPosted: Mon Jun 03, 2019 8:36 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21441
Location: NE Indiana, USA (NTSC)
If you're calling subroutines in RAM, whether for self-modifying code or for having additional fixed bank space, you have to copy them to RAM before you call them. See "LOAD and RUN addresses" in ld65 Users Guide.

_________________
Pin Eight | Twitter | GitHub | Patreon


Top
 Profile  
 
PostPosted: Wed Jun 05, 2019 1:29 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 1018
Location: cypress, texas
tepples wrote:
If you're calling subroutines in RAM, whether for self-modifying code or for having additional fixed bank space, you have to copy them to RAM before you call them. See "LOAD and RUN addresses" in ld65 Users Guide.
unregistered wrote:
After moving the_function that needs to be in PRG-RAM into an unused bank, and writting a short new-function to copy the_function into an appropriate spot in bank 0 of PRG-RAM and change its jmp correctly, and creating a label to mark that appropriate spot... the game assembles, but reset: still begins with a bunch of zeros. Any idea why?
See my function has already been copied to RAM (for self-modifying code), though I can't see that bc our game never makes it through reset. :) But, thank you tepples for making it clear that subroutines can be called in RAM on the NES! :D I'll visit your link. :) ...maybe the PPU registers are set incorrectly...


Top
 Profile  
 
PostPosted: Wed Jun 05, 2019 2:15 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 1018
Location: cypress, texas
Ah! So my asm6_ has successfully created a faulty .nes file (lots of brks), but when trying to assemble our game with asm6 it quits assembling after pass 1...

tepples, can subroutines be run when they are inside 'Save RAM' $6000-$7000 in MMC1?

The site you linked to must be experiencing problems... I'll try again. :)


edit: sigh, guess I caused my asm6_ to sometimes assemble corrupt binaries. :( tokumaru recommends asm6:
tokumaru, here, wrote:
NESASM and ASM6 are equally simple IMO: both can create a ROM from nothing more than a single ASM file, without configuration files or complex command lines. If you're going for simplicity, you should pick one of these 2. I prefer ASM6because NESASM uses non-standard 6502 syntax for some things and it has been known to fail silently in the past, producing corrupt binaries without reporting any errors (some people say these bugs have been fixed).
I need to fix this sometime. :oops:


Top
 Profile  
 
PostPosted: Wed Jun 05, 2019 3:18 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21441
Location: NE Indiana, USA (NTSC)
I was under the impression that Nintendo's big four FDS-to-cartridge ports (Metroid, Kid Icarus, The Legend of Zelda, and Super Mario Bros. 2: Mario Madness) run code in RAM at $6000. If you have dumped a game with such RAM, you can set an execute breakpoint on $6000-$7FFF to see for yourself.

_________________
Pin Eight | Twitter | GitHub | Patreon


Top
 Profile  
 
PostPosted: Wed Jun 05, 2019 6:08 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11369
Location: Rio de Janeiro - Brazil
Both ASM6 and NESASM have quirks that will cause you to scratch your head sometimes... You just have to keep looking for the cause of the problem so you can get to know your tools better.

It's definitely possible to run code at $6000-$7FFF, but you need to be careful when setting up the addresses for this code. Like tepples said, ca65 has a way for you to define the LOAD address (where the code is stored in ROM) and the RUN address (the PRG-RAM address you'll copy it to), but in ASM6 you have to do this manually, possibly like this:

Code:
  ;(...)

;save ROM address for later
ROMAddress = $

  ;change address to PRG-RAM
  .base $6000

SubroutineStart:

  ;(...)

SubroutineEnd:

  ;restore ROM address, taking the code size into consideration
  .base ROMAddress + (SubroutineEnd - SubroutineStart)

If you don't change the address to PRG-RAM, references to absolute addresses in that subroutine will use the ROM address, which is not where the subroutine be running from. And if you forget to take the subroutine's size into consideration when restoring the ROM address, the final size of the ROM bank will be wrong, resulting in an invalid NES file.


Top
 Profile  
 
PostPosted: Thu Jun 06, 2019 1:08 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 1018
Location: cypress, texas
Ah, so PRG-RAM doesn't work like PRG-ROM? That's pretty obvious, but when setting up PRG-RAM like you showed, tokumaru, the address, changed with .base to PRG-RAM, helps absolute addresses be correct inside that subroutine, but we have to adjust the PRG-ROM address bc that subroutine is also in PRG-ROM? The addresses in the subroutine are pointing to PRG-RAM so the game will never get mixed up and try to run that section of PRG-ROM?

It seems I incorrectly set up the 4 PRG-RAM banks so that they were exactly like the PRG-ROM banks... bank0:
Code:
.base $6000
;seei is transfered here form bank 13
seei_:

.pad $6FF0
-reset_part1:
  sei
  ldx #$FF
  txs ;set the stack pointer
  stx $8000 ;reset the mapper
  jmp reset_part2 ; must be in $C000-$FFED
.word vblank, -reset_part1, irq
and then bank1 through bank3 are then set up the same way (without the seei_ label).

Thank you so much tokumaru! :D Going to try setting it up like you recommended. :)
edit: It seems my code wouldn't work anyways bc RAM never holds anything you want unless you load/store into it from ROM, like booker and you all taught me. :) ENDEDIT.

tepples, your link always worked; rather, I forgot what I had learned earlier that github links don't work on this old computer. :oops:


Top
 Profile  
 
PostPosted: Thu Jun 06, 2019 1:26 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11369
Location: Rio de Janeiro - Brazil
Yeah, the complication comes from the fact that even though the code is supposed to run from RAM (which means that the PC must be set to the correct RAM section so all absolute references are correct), it's still stored in ROM, taking up space there.

I don't know if this is what you're doing, but you can't have that PRG-RAM code stored separately in the NES file, it must be stored within the PRG-ROM space. My example was a generic one that allows PRG-RAM code to be stored anywhere in PRG-ROM, but since you're working with full banks, you could just use the lower part of a PRG-ROM bank for your PRG-RAM stuff and manually .base the address to, say, $D000 ($1000 bytes after $C000) for the rest of the PRG-ROM. That way you won't need all the label math from my example. Either way, PRG-ROM banks should remain the same size as before, and any PRG-RAM code you have must be stored inside them, but with the correct PC value for the address where that code will run from.


Top
 Profile  
 
PostPosted: Mon Jun 10, 2019 4:02 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 1018
Location: cypress, texas
YEAY! PRAISE GOD!! :D My function is successfully running inside PRG-RAM! :) Thank you so much tokumaru! Now to attempt to make it self-modify itself. This is so much fun! :)


Top
 Profile  
 
PostPosted: Thu Jun 13, 2019 4:57 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 1018
Location: cypress, texas
It self-modifies itself successfully! :D Have to reduce the blinking, but one more thing works! PRAISE GOD!! :D

ok, I'll be silent now. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1509 posts ]  Go to page Previous  1 ... 97, 98, 99, 100, 101

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group