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


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

Re: Assemble HelloWorld with Ca65

Newsgroups comp.sys.apple2.programmer
Date 2016-01-16 09:51 -0800
References <eba160ff-162f-4300-97f0-2ad2bb9617d4@i7g2000prf.googlegroups.com>
Message-ID <272508d0-abe8-42c6-95ea-af1e41b30618@googlegroups.com> (permalink)
Subject Re: Assemble HelloWorld with Ca65
From michael.pohoreski@gmail.com

Show all headers | View raw


Necro'ing in case anyone comes from searching "Ye Old Internet"

- - - 8< barebones.s - - -
           COUT = $FDED

.macro ASC text
    .repeat .strlen(text), I
    .byte   .strat(text, I) | $80
    .endrep
.endmacro
            __MAIN = $1000       ; Apple DOS 3.3 binary file 4 byte prefix header
            .word __MAIN         ; 2 byte BLAOD address
            .word __END - __MAIN ; 2 byte BLOAD size
            .org  __MAIN         ; .org must come after header else offsets are wrong
            LDX    #0
            LDA    MSG,X    ; load initial char
PRINTCHAR:  JSR    COUT
            INX
            LDA    MSG,X
            BNE    PRINTCHAR
            RTS
MSG:
            ASC "Hello world, Apple!"
            .byte $00
__END:
- - - 8< barebones.s - - -

You'll need a linker script that doesn't include all the C library cruft, and makes all RAM available.

- - - 8< apple2linkbin.cfg - - -
MEMORY {
     RAM:    start = $0, size = $10000, file = %O;
}
SEGMENTS {
     CODE:     load = RAM,    type = rw;
     DATA:     load = RAM,    type = rw;
     BSS:      load = RAM,    type = rw;
}
- - - 8< - - -


ca65 --cpu 65c02 -o barebones.o barebones.s
ld65 -C apple2linkbin.cfg -o barebones.bin barebones.o

Then use a2tools to copy onto a .DSK image in "raw" format:

a2rm barebones.DSK BAREBONES
a2in -r b barebones.DSK BAREBONES barebones.bin


You can simple this by moving this boiler plate to a file called: dos33.h

- - - 8< dos33.h - - -
            .word __MAIN         ; 2 byte BLAOD address
            .word __END - __MAIN ; 2 byte BLOAD size
            .org  __MAIN         ; .org must come after header else offsets are wrong
- - - 8< dos33.h - - -

Then your main program is simplified:

            __MAIN = $1000
            .include "dos33.h"   ; Apple DOS 3.3 binary file 4 byte prefix header

More details and files at my fork of the repo:
https://github.com/Michaelangel007/cc65

P.S.
Someone *really* needs to update that ancient cc65 docs with a *working* link to AppleWin
http://www.cc65.org/snapshot-doc/intro-6.html

Remove: Available at http://applewin.berlios.de/:
Replace: Available at https://github.com/AppleWin/AppleWin


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


Thread

Re: Assemble HelloWorld with Ca65 michael.pohoreski@gmail.com - 2016-01-16 09:51 -0800
  Re: Assemble HelloWorld with Ca65 ol.sc@web.de (Oliver Schmidt) - 2016-01-19 19:26 +0000

csiph-web