Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #2128

cc65: ca65 + ld65 without all the library crap for "pure" assembly programs

Newsgroups comp.sys.apple2.programmer
Date 2016-01-15 21:26 -0800
Message-ID <dec2c6fc-3c74-40e8-a655-fca8451d9a1b@googlegroups.com> (permalink)
Subject cc65: ca65 + ld65 without all the library crap for "pure" assembly programs
From michael.pohoreski@gmail.com

Show all headers | View raw


aka: "ca65 for stand-alone Apple assembly projects"

Since all the cool kids are using cross-assemblers these days I figured I would get with the times and stop hand-assembling everything.  (Hey it was good enough for Woz and Integer Basic! :)

I've put together a demo and bash shell script to automate these steps:
https://github.com/Michaelangel007/cc65/tree/master/apple2

What src2dsk.sh does:

* assemble a barebones.s file, producing barebones.o
* link it, producing barebones.bin
* use a2tools to copy it onto a DOS 3.3 disk, called BAREBONES

This lets you use cc65 without all the C library crap!  Here are the steps involved that others might find interesting:

1. I used a dead simple linker script called: apple2bin.cfg

- - - 8< - - -
MEMORY {
     RAM:    start = $1000, size = $8E00, file = %O;
}
SEGMENTS {
     CODE:     load = RAM,    type = ro;
     DATA:     load = RAM,    type = rw;
     BSS:      load = RAM,    type = rw;
}
- - - 8< - - -

2.  Since we're not using any of the cc65 libraries, ld65 won't generate the 4-byte header for us. We need to do this manually, but this is trivial.  Stick this at the top of your .s file to generate the 4-byte header for DOS 3.3

- - - 8< - - -
            ; 4 byte header for DOS 3.3 files
            .word $1000     ; define 2 bytes, must match org
            .word __END__ - * ; define 2 bytes, total size in bytes

            .org  $1000     ; .org must come after header else offsets are wrong

... your code ...

__END__:
- - - 8< - - -

3. Runs the assembler with:

    ca65 --cpu 65c02 -o foo.o foo.s

4. Runs the linker with:

    ld65 -C apple2bin.cfg -o foo.bin foo.o

5. We can verify the binary is truely barbones!

    hexdump -C barebones.bin

00000000  00 10 1d 00 a2 00 bd 11  10 09 80 20 ed fd e8 bd  |........... ....|
00000010  11 10 d0 f5 60 48 65 6c  6c 6f 2c 20 77 6f 72 6c  |....`Hello, worl|
00000020  64 21 00                                          |d!.|
00000023


6. I used a2tools to copy the foo.bin onto foo.dsk with the filename FOO.  I used awk to capitalize the filename, a2rm to delete the old binary off the .DSK, and a2in to "instal"" the new binary onto the .DKS.

    A2FILE=`echo "${1}" | awk '{print toupper($0)}'`
    a2rm      ${1}.DSK ${A2FILE}
    a2in -r b ${1}.DSK ${A2FILE} ${BIN} 

7. You'll need to mount the (updated) disk in your favorite emulator but you're good to go !

I ran into one cc65 bug with version ca65 V2.15.  Apparently the macro to is broken when setting the high bit -- it doesn't update the last 4 bytes of the string.  I wasted enough time automating the whole assemble+link+copy that I didn't feel like tracking down what was broken with ca65.

Anyways, all the stuff is in my repo:

* apple2bin.cfg
* barebones.dsk
* barebones.s
* src2dsk.sh

https://github.com/Michaelangel007/cc65/tree/master/apple2

Enjoy!

Michael




Back to comp.sys.apple2.programmer | Previous | NextNext in thread | Find similar


Thread

cc65: ca65 + ld65 without all the library crap for "pure" assembly programs michael.pohoreski@gmail.com - 2016-01-15 21:26 -0800
  Re: cc65: ca65 + ld65 without all the library crap for "pure" assembly programs michael.pohoreski@gmail.com - 2016-01-16 09:24 -0800
  Re: cc65: ca65 + ld65 without all the library crap for "pure" assembly programs michael.pohoreski@gmail.com - 2016-01-16 16:13 -0800
  Re: cc65: ca65 + ld65 without all the library crap for "pure" assembly programs ol.sc@web.de (Oliver Schmidt) - 2016-01-19 19:36 +0000
    Re: cc65: ca65 + ld65 without all the library crap for "pure" assembly programs michael.pohoreski@gmail.com - 2016-01-19 22:54 -0800
      Re: cc65: ca65 + ld65 without all the library crap for "pure" assembly programs michael.pohoreski@gmail.com - 2016-01-20 07:21 -0800

csiph-web