I'm trying to segment my C code into two distinct memory areas, one which will be flashed to a ROM chip and another which will end up somewhere else. Here is what I have in sbc.cfg
(I was originally following the custom target tutorial):
MEMORY {
ZP: start = $0, size = $100, type = rw, define = yes;
RAM: start = $200, size = $34FF, define = yes;
FIRM: start = $4000, size = $3000, file = "%O-FIRM.bin", fill = yes;
ROM: start = $8000, size = $8000, file = "%O-ROM.bin", fill = yes;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp, define = yes;
DATA: load = ROM, type = rw, define = yes, run = RAM;
BSS: load = RAM, type = bss, define = yes;
HEAP: load = RAM, type = bss, optional = yes;
STARTUP: load = ROM, type = ro;
ONCE: load = ROM, type = ro, optional = yes;
CODE: load = ROM, type = ro;
CODE2: load = FIRM, type = ro;
RODATA: load = ROM, type = ro;
VECTORS: load = ROM, type = ro, start = $FFFA;
}
# ...
Of special interest are the FIRM
and ROM
memory areas and the CODE
and CODE2
segments which are loaded into them respectively. Given that I said the memory areas begin at $4000
and $8000
, I was expecting to see the instructions written to file starting there, but ld65
actually appears to have put it at the top of each file:
neil@Neil-Legion:~/cc65-customizing-demo$ hexdump build/6502-ROM.bin
0000000 0e8d 8e02 020f 158d 8e02 0216 b988 ffff
0000010 1f8d 8802 ffb9 8dff 021e 218c 2002 ffff
0000020 ffa0 e8d0 a260 9aff a9d8 85ff a902 8536
0000030 2003 80c5 9820 2080 8041 7f20 2080 808c
0000040 a000 f000 a907 a241 4c80 0200 4060 bada
0000050 e848 bde8 0100 1029 03d0 fa68 4c40 8063
0000060 cb58 db60 0085 0186 00a0 00b2 008d c810
0000070 00b1 f8d0 0da9 008d a910 8d0a 1000 2060
0000080 4000 0220 5840 0420 7840 f680 00a0 07f0
0000090 41a9 80a2 004c 6002 00a9 0a85 80a9 0b85
00000a0 00a9 0c85 02a9 0d85 daa2 ffa9 1285 00a0
00000b0 f0e8 b10d 910a c80c f6d0 0be6 0de6 f0d0
00000c0 12e6 efd0 a960 8525 a90a 8502 a90b a800
00000d0 00a2 0af0 0a91 d0c8 e6fb ca0b f6d0 00c0
00000e0 05f0 0a91 d0c8 60f7 0000 0000 0000 0000
00000f0 0000 0000 0000 0000 0000 0000 0000 0000
*
0007ff0 0000 0000 0000 0000 0000 804d 8025 804e
0008000
neil@Neil-Legion:~/cc65-customizing-demo$ hexdump build/6502-FIRM.bin
0000000 60ea 60ea 60ea 0000 0000 0000 0000 0000
0000010 0000 0000 0000 0000 0000 0000 0000 0000
*
0003000
neil@Neil-Legion:~/cc65-customizing-demo$
It's entirely possible I'm misunderstanding the .cfg
options here, but this seems to be what worked here too, so I'm confused. I'm also quite new to microprocessor programming, so I'm not exactly sure what to try next. I tried the start
segment attribute as mentioned in the docs here, but this didn't change anything.