It is currently Wed Nov 22, 2017 12:42 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Program code in WRAM
PostPosted: Sat Sep 16, 2017 3:46 am 
Online
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1463
I like my code to remain in the fixed bank because I think switching the bank is too risky and too much of a hazzle. That's why I attempt to use the switchable banks only for data.

But now that my game uses MMC1 with battery save, I thought of a way to extend the available room for code should it ever become too small:

Would it be possible to use the otherwise unused space in WRAM for code?
You store the code that doesn't fit into the fixed bank anymore somewhere into another bank. And at program startup, you copy that code from the other bank into WRAM. Now you have up to 8 KB (minus the stuff you need for savestates) as additional always available program code.

Would this be possible?

The only problem that I see is: The WRAM has different addresses than the switchable bank. How do you organize your source code, so that you can still call these functions normally?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 3:58 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10117
Location: Rio de Janeiro - Brazil
Yes, you can do this. You just have to assemble the code with an origin of $6000, even though it will be mapped somewhere else in ROM when you're copying it to RAM.

In ca65 you could probably create a memory section with start = $6000, size = $2000 and one or more segments that use it. Then, at run time, you'd switch to the bank that contains that chunk and copy it to WRAM. From then on you can use the code in WRAM as you would any code in ROM.


Last edited by tokumaru on Sat Sep 16, 2017 4:07 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:02 am 
Online
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1463
But how do I do this in practice, namely in cc65?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:10 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10117
Location: Rio de Janeiro - Brazil
Edited my post. I'm not sure about C code, but what I wrote is what I'd do for assembly.


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:23 am 
Online
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1463
I know how to create the stuff in the cfg file and how to prepare the code in the bank, but I don't know how to make the compiler know the function addresses in WRAM, except for the first function:
Code:
.segment "SWITCHABLE_ROM_BANK"

Function1Rom:
    BLA
    RTS

Function2Rom:
    BLA
    BLA
    RTS

.segment "WRAM_CODE"

Function1:
    ; Do nothing.
    ; After the copy process,
    ; the code from Function1Rom
    ; will be here.

But how do I make the compiler/assembler know the RAM address for function 2?

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:29 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10117
Location: Rio de Janeiro - Brazil
Everything you put in the "WRAM_CODE" segment should use addresses in the $6000-$7FFF area if that segment uses a MEMORY area of start = $6000, size = $2000.


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:37 am 
Online
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1463
So, I assume I have to do something like this?
Code:
Function2 = WRAM_CODE_LOAD + Function2Rom - SWITCHABLE_ROM_BANK_LOAD

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:44 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
Use the LOAD and RUN attributes in your linker configuration file: http://cc65.github.io/doc/ld65.html#ss5.4

Point the LOAD attribute to ROM, and the RUN attribute to WRAM. Then you can use define=yes to get the linker to define symbols which you can use to copy the data from ROM to WRAM.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 4:48 am 
Online
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1463
I didn't know there was a RUN attribute.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 5:02 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10117
Location: Rio de Janeiro - Brazil
Oh crap, I forgot about LOAD and RUN!


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 5:11 am 
Online
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1463
Looks like this is really the most elegant solution. Thanks for that hint.

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 6:17 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7272
Location: Chexbres, VD, Switzerland
As a side note, if you're going to have code sit in WRAM anyway, you might as well compress it so you can save PRG-ROM (in this case, if this can make your game fit in 128 KB PRG-ROM instead of 256 KB PRG-ROM).


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 6:46 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19239
Location: NE Indiana, USA (NTSC)
What codec is effective for 6502 machine code?


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 7:01 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3950
There is Aplib/pucrunch, or huffman.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
 Post subject: Re: Program code in WRAM
PostPosted: Sat Sep 16, 2017 7:09 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7272
Location: Chexbres, VD, Switzerland
I'd bet on Huffman since it could encode frequently used opcodes on few bits. I'm kind of fond of Huffman personally, it compress almost everything well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 9 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