[cc65] nested loader

From: Frank Buss <fb1frank-buss.de>
Date: 2014-09-26 13:39:02
I need to implement a relocated program code within a relocated program code. How would I do this with cc65? See below for a simplified example (.rorg means that it appends as usual at the current "*" position, but jumps etc. are compiled, as if "*" and following would be the address specified at .rorg). The program starts at $2000 and all other code should follow without gaps from this address. When the program at $2000 is started, it copies the rest to $8000. After reset, the code from "reset_start" is executed, which copies the rest of the program to $0b00 and then starts this program (yes, sounds strange, but I need this to start a C128 program from C64 mode).

My current solution is to compile the part starting at "cart:" in an extra bin-file, with an extra def-file and two segments, with a "run" address of $0b00 for the segment which starts at "program:", but the same "load" address. Then I use the same concept for the main program and include the bin file with .incbin. This works, but I wonder if it is possible to construct this with only one def file and assembler file.

BTW: I'm using the latest cc65 compiler (V2.14 - Git d75f9c2), no problems so far.

.org $2000
ldx #0
c:  lda cart,x
sta $8000,x
inx
cpx #cart_end-cart
bne c
// reset

cart:
.rorg $8000
.byte id
reset_start: ldx #0
c2: lda program,x
sta $0b00,x
inx
cpx #cart_end-program
bne c2
jmp $0b00

.rorg $0b00
program: inc $d020
jmp x
cart_end:


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Sep 26 13:39:30 2014

This archive was generated by hypermail 2.1.8 : 2014-09-26 13:39:32 CEST