dmsc/fastbasic

Compile Cartridge ROM configuration

Opened this issue · 3 comments

I am working on compiling a program and seeing if it is possible to make a program run from a 16k cartridge instead of RAM. I have started a CFG file. I am not sure if I am not missing anything.

FEATURES {
STARTADDRESS: default = $8000;
}
SYMBOLS {
EXEHDR: type = import;
STARTADDRESS: type = export, value = %S;
}
MEMORY {
ZP: file = "", define = yes, start = $0094, size = $0040;
ROM: file = "", define = yes, start = $8000, size = $2000, type = ro, fill = yes, fillval = $ff;
RAM: file = "", define = yes, start = $0400, size = STARTADDRESS - ROM, define = yes;
CARTSTART: file = %O, start = $BFEA, size = $0002;
CARTLEFT: file = %O, start = $BFFC, size = $0001;
CARTBOOT: file = %O, start = $BFFD, size = $0001; fill = yes, fillval = $59;
CARTENTRY: file = %O, start = $BFFE, size = $0002;
VECTORS: start = $BFFA, size = 6, type= ro, file = %O;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp, optional = yes;
EXEHDR: load = HEADER, type = ro, optional = yes;
MAINHDR: load = MAINHDR, type = ro, optional = yes;
JUMPTAB: load = MAIN, type = ro, define = yes, align = $100;
RUNTIME: load = MAIN, type = rw, define = yes;
CODE: load = MAIN, type = rw, define = yes;
DATA: load = RAM, type = rw optional = yes, define = yes;
BSS: load = RAM, type = bss, optional = yes, define = yes;
HEAP: load = RAM, type = bss, optional = yes
IHEADER: load = IHEADER, type = ro;
INTERP: load = INTERP, type = rw;
AUTOSTRT: load = TRAILER, type = ro, optional = yes;
CARTSTART: load = CARTSTART, type = ro;
CARTLEFT: load = CARTLEFT, type = ro;
CARTBOOT: load = CARTBOOT, type = ro;
CARTENTRY: load = CARTENTRY, type = ro;
}

dmsc commented

Hi!

I am working on compiling a program and seeing if it is possible to make a program run from a 16k cartridge instead of RAM. I have started a CFG file. I am not sure if I am not missing anything.

This needs a little extra work.

Normally, Fastbasic uses self-modifying-code in a few places to make the code faster, so the code can't be placed in ROM. But there is a compilation option to use alternative code that disables this, so you need to recompile the interpreter.

As I had not tested that option in a while, I just reviewed all the interpreter and found three places which still tried to write to the code, so I just fixed that.

This means:

  • You need the last (unreleased) version from github.
  • You need to compile the code using:
  make ASMFLAGS="--asm-define NO_SMCODE"
  • You need to alter the linker file.

Here there is another little issue: Fastbasic uses code in zeropage and initialized DATA.

This means you need to provide two special sections:

  • A section to place the "INTERP" segment in ROM, and at runtime copy it to RAM.
  • A section to place the "RT_DATA" segment in TOM, and again at runtime copy it to RAM.

I added a "fastbiasc-cart.cfg" file with those sections, and the support code to build the cartridge image in commit b8d7ff6 , now the full instructions to compile for a cartridge image (on Linux or other Unix) are:

  git clone https://github.com/dmsc/fastbasic/
  cd fastbasic
  make ASMFLAGS="--asm-define NO_SMCODE"
  build/compiler/fb myProgram.bas -C:build/compiler/fastbasic-cart.cfg

Have Fun!

I also have a ML routine called deflate which decompresses data blocks from Cartridge ROM into RAM. I could just use a portion of cartridge ROM for fonts, data tables, and some ML routines.

dmsc commented

Hi!

I also have a ML routine called deflate which decompresses data blocks from Cartridge ROM into RAM. I could just use a portion of cartridge ROM for fonts, data tables, and some ML routines.

Did you try using the new CART support?

Also I recently added a copy of the CC65 tools to the repo, so you don't need CC65 to use the compiler.

Have Fun!