6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 7:50 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jan 31, 2024 11:59 pm 
Offline

Joined: Sun Sep 24, 2023 3:45 pm
Posts: 47
Hi all. I’m working on my Bad Apple! video decoder and have this version just about finished up.
One of the last things I wanted was a self contained ROM that boots right up to the demo.
The problem is that I have a little bit of self modifying code so I want to move some to RAM and I don't quite know what the correct way is to deal with this.
I know how to move data from ROM to RAM, but how do I deal with it from the source side?

IE, I can do a:
Code:
  .org $500
  .. source code ..

assemble, then on my ROM file do something like
Code:
 .org $5000
 .. source code ..
 .org $6000
 include file.bin

but I was wondering if there was a way to keep everything in the same source file?
Is there a 'Assemble To' command that I can't seem to figure out?
Maybe something like:
Code:
 .org $6000
 .. source code..
.RelocateLoop ;routine to move code
 LDA RelocateCode,x
 STA $500,x
 inx
 bne .RelocateLoop

RelocateCode:  ; location in output is after above code
 .assembleto $500  ; but the code uses $500 as base address
.Top ; location $500
.. source code ..
jmp .Top ;IE jmp $500
.Bottom
endassembleto


I can’t quite seem to find what I’m looking for from the source code management side.
Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 01, 2024 1:50 am 
Offline

Joined: Sun Feb 22, 2004 9:01 pm
Posts: 104
Relocated or copied? If it's some code you copy elsewhere to execute, if it's small enough, I usually just embed the difference into the code. Eg:

LDX #codeend-code-1
.initlp
LDA code,X:STA &100,X:DEX:BPL initlp
CALL &100
...
.code ; this code will be copied to &100 onwards
LDA &F4:PHA
LDA #0:JSR romsel-code+&100 ; dest address will be at &100+(distance from code to romsel)
JSR sidecall:PLA
.romsel ; this point will be at &100+(distance from code to here)
STA &F4:STA &FE30:RTS
.codeend

If it's more complicated than that, I think the thing you are looking for your assembler to support is "REPHASE".

org &8000
...
LDX #codeend-code-1
.initlp
LDA code,X:STA &100,X:DEX:BPL initlp
CALL &100
...
phase &100 ; this will be stored here but targetted at &100
.code ; this code will be copied to &100 onwards
LDA &F4:PHA
LDA #0:JSR romsel ; dest address will be at &100+(distance from code to romsel)
JSR sidecall:PLA
.romsel ; this point will be at &100+(distance from code to here)
STA &F4:STA &FE30:RTS
.codeend
dephase ; we now return to storing at &8000+whatever onwards

_________________
--
JGH - http://mdfs.net


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 01, 2024 12:46 pm 
Offline

Joined: Thu Apr 23, 2020 5:04 pm
Posts: 50
NormalLuser wrote:
there was a way to keep everything in the same source file?
Is there a 'Assemble To' command that I can't seem to figure out?

I don't know what assembler you are using, but with vasm this can be done using rorg/rend directives:

Code:
 Source: "x.s"
                                     1:  .org $6000
                                     2: ; .. source code..
                                     3: test1
00:6000 4C0060                       4:  jmp test1
                                     5: .RelocateLoop ;routine to move code
00:6003 BD0C60                       6:  LDA RelocateCode,x
00:6006 9D0005                       7:  STA $500,x
00:6009 E8                           8:  inx
00:600A D0F7                         9:  bne .RelocateLoop
                                    10:
                                    11: RelocateCode:  ; location in output is after above code
                                    12: ; .assembleto $500  ; but the code uses $500 as base address
                                    13:  .rorg $500
                                    14: Top ; location $500
                                    15: ;.. source code ..
00:0500 4C0005                      16:  jmp Top ;IE jmp $500
                                    17: .Bottom
                                    18:  .rend
                                    19: ;endassembleto
                                    20: test2
00:600F 4C0F60                      21:  jmp test2
                                    22:


Symbols by name:
RelocateCode                     A:600C
Top                              A:0500
test1                            A:6000
test2                            A:600F

> hexdump -C x.out
00000000  4c 00 60 bd 0c 60 9d 00  05 e8 d0 f7 4c 00 05 4c  |L.`..`......L..L|
00000010  0f 60



Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 01, 2024 11:39 pm 
Offline

Joined: Sun Sep 24, 2023 3:45 pm
Posts: 47
Thanks guys!
.rorg $1234 and .rend is exactly what I needed.
Don't know how I missed that in the vasm manual.
Worked great!


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 26, 2024 8:45 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1042
Location: near Heidelberg, Germany
In xa65 you can just do a
*=1234
to redefine the PC at any time.

And even use
*=
to enter relocatable mode if using -R to create relocatable o65 files (relocatable at load time)

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users 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: