davidgiven / cowgol

A self-hosted Ada-inspired programming language for very small systems.
BSD 2-Clause "Simplified" License
241 stars 20 forks source link

Add Commodore 64 target #115

Closed matozoid closed 3 years ago

matozoid commented 3 years ago

That would be cool! I'm absolutely fine cross-compiling from linux.

I tried getting the BBC target to work with the following makefile:

COWGOLDIR=../cowgol
FE=$(COWGOLDIR)/bin/cowfe-6502.lx386.lx386.exe
BE=$(COWGOLDIR)/bin/cowbe-6502.lx386.lx386.exe
LINKER=$(COWGOLDIR)/bin/cowlink-bbcti.lx386.lx386.exe

%.cob: %.cow
    $(FE) -I$(COWGOLDIR)/ -I$(COWGOLDIR)/rt/ -I$(COWGOLDIR)/rt/bbcti/ $< $@

%.coo: %.cob
    $(BE) $< $@

%.s: %.coo
    $(LINKER) $< -o $@

all: test.s

clean:
    rm *.cob
    rm *.coo
    rm *.s

but that gave me link errors. I guess the standard library isn't done for that target yet?

davidgiven commented 3 years ago

There is one! Er, somewhere. Possibly I haven't merged it yet. Sadly the C64 can't actually run the compiler itself, but simple programs work. Here's the frontend starting but not finding a source file.

image

...although I don't like that 1AKb string much (this may have been taken prior to some bugfixes). This is running under cshell, which is a very simple CP/M-like shell for running programs off disk with scripts and command-line arguments; see https://github.com/davidgiven/cshell; but the programs are also perfectly ordinary Basic-stub machine code programs which can be loaded and run. Unfortunately the C64 OS and DOS are both thoroughly cursed, which makes working with files no fun at all, but Cowgol certainly works.

Re the BBC version: you have explicitly tell it where the libraries are. For a BBC Tube machine, you want .obj/rt/bbc/cowgol.coo. Also, you're using the wrong linker above; you want cowlink-bbct, not bbcti (that's the byte-coded Forth-like interpreter linker).

Update: Yes, I haven't merged it. It's in the c64 branch if you're interested, but there are a few broken bits.

matozoid commented 3 years ago

Alright, I've got it to generate a prg! Thanks for the help :-) I turned it into a hello world thing and stored it here if others want to do the same: https://github.com/matozoid/cowgol-hellow-world-linux-c64/

davidgiven commented 3 years ago

Looks good --- thanks for wanting to use this! Let me know if you run into any problems. (I'll try and get the branch merged soon.)