Added support for building targetutils.
This commit is contained in:
7
libsrc/apple2/targetutil/Makefile.inc
Normal file
7
libsrc/apple2/targetutil/Makefile.inc
Normal file
@@ -0,0 +1,7 @@
|
||||
../wrk/$(TARGET)/loader.o: $(SRCDIR)/targetutil/loader.s | ../wrk/$(TARGET)
|
||||
$(ASSEMBLE_recipe)
|
||||
|
||||
../targetutil/loader.system: ../wrk/$(TARGET)/loader.o $(SRCDIR)/targetutil/loader.cfg | ../targetutil
|
||||
$(LD) -o $@ -C $(filter %.cfg,$^) $(filter-out %.cfg,$^)
|
||||
|
||||
$(TARGET): ../targetutil/loader.system
|
||||
17
libsrc/apple2/targetutil/loader.cfg
Normal file
17
libsrc/apple2/targetutil/loader.cfg
Normal file
@@ -0,0 +1,17 @@
|
||||
#################################################################################
|
||||
# #
|
||||
# LOADER.SYSTEM - an Apple][ ProDOS 8 loader for cc65 programs (Oliver Schmidt) #
|
||||
# #
|
||||
#################################################################################
|
||||
|
||||
MEMORY {
|
||||
MEMORY_2000: start = $2000, size = $0200, file = %O;
|
||||
MEMORY_0300: start = $0300, size = $0100;
|
||||
}
|
||||
|
||||
SEGMENTS {
|
||||
CODE_2000: load = MEMORY_2000, type = ro;
|
||||
DATA_2000: load = MEMORY_2000, type = rw;
|
||||
CODE_0300: load = MEMORY_2000, run = MEMORY_0300, type = ro, define = yes;
|
||||
DATA_0300: load = MEMORY_2000, run = MEMORY_0300, type = rw, define = yes;
|
||||
}
|
||||
BIN
libsrc/apple2/targetutil/loader.o
Normal file
BIN
libsrc/apple2/targetutil/loader.o
Normal file
Binary file not shown.
234
libsrc/apple2/targetutil/loader.s
Normal file
234
libsrc/apple2/targetutil/loader.s
Normal file
@@ -0,0 +1,234 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; ;
|
||||
; LOADER.SYSTEM - an Apple][ ProDOS 8 loader for cc65 programs (Oliver Schmidt) ;
|
||||
; ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
A1L := $3C
|
||||
A1H := $3D
|
||||
STACK := $0100
|
||||
BUF := $0200
|
||||
PATHNAME := $0280
|
||||
MLI := $BF00
|
||||
VERSION := $FBB3
|
||||
RDKEY := $FD0C
|
||||
PRBYTE := $FDDA
|
||||
COUT := $FDED
|
||||
|
||||
QUIT_CALL = $65
|
||||
GET_FILE_INFO_CALL = $C4
|
||||
OPEN_CALL = $C8
|
||||
READ_CALL = $CA
|
||||
CLOSE_CALL = $CC
|
||||
FILE_NOT_FOUND_ERR = $46
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
.import __CODE_0300_SIZE__, __DATA_0300_SIZE__
|
||||
.import __CODE_0300_LOAD__, __CODE_0300_RUN__
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
.segment "DATA_2000"
|
||||
|
||||
GET_FILE_INFO_PARAM:
|
||||
.byte $0A ;PARAM_COUNT
|
||||
.addr PATHNAME ;PATHNAME
|
||||
.byte $00 ;ACCESS
|
||||
.byte $00 ;FILE_TYPE
|
||||
FILE_INFO_ADDR: .word $0000 ;AUX_TYPE
|
||||
.byte $00 ;STORAGE_TYPE
|
||||
.word $0000 ;BLOCKS_USED
|
||||
.word $0000 ;MOD_DATE
|
||||
.word $0000 ;MOD_TIME
|
||||
.word $0000 ;CREATE_DATE
|
||||
.word $0000 ;CREATE_TIME
|
||||
|
||||
OPEN_PARAM:
|
||||
.byte $03 ;PARAM_COUNT
|
||||
.addr PATHNAME ;PATHNAME
|
||||
.addr MLI - 1024 ;IO_BUFFER
|
||||
OPEN_REF: .byte $00 ;REF_NUM
|
||||
|
||||
LOADING:
|
||||
.byte $0D
|
||||
.asciiz "Loading "
|
||||
|
||||
ELLIPSES:
|
||||
.byte " ...", $0D, $0D, $00
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
.segment "DATA_0300"
|
||||
|
||||
READ_PARAM:
|
||||
.byte $04 ;PARAM_COUNT
|
||||
READ_REF: .byte $00 ;REF_NUM
|
||||
READ_ADDR: .addr $0000 ;DATA_BUFFER
|
||||
.word $FFFF ;REQUEST_COUNT
|
||||
.word $0000 ;TRANS_COUNT
|
||||
|
||||
CLOSE_PARAM:
|
||||
.byte $01 ;PARAM_COUNT
|
||||
CLOSE_REF: .byte $00 ;REF_NUM
|
||||
|
||||
QUIT_PARAM:
|
||||
.byte $04 ;PARAM_COUNT
|
||||
.byte $00 ;QUIT_TYPE
|
||||
.word $0000 ;RESERVED
|
||||
.byte $00 ;RESERVED
|
||||
.word $0000 ;RESERVED
|
||||
|
||||
FILE_NOT_FOUND:
|
||||
.asciiz "... File Not Found"
|
||||
|
||||
ERROR_NUMBER:
|
||||
.asciiz "... Error $"
|
||||
|
||||
PRESS_ANY_KEY:
|
||||
.asciiz " - Press Any Key "
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
.segment "CODE_2000"
|
||||
|
||||
jmp :+
|
||||
.byte $EE
|
||||
.byte $EE
|
||||
.byte 65
|
||||
STARTUP:.res 65
|
||||
|
||||
; Reset stack
|
||||
: ldx #$FF
|
||||
txs
|
||||
|
||||
; Relocate CODE_0300 and DATA_0300
|
||||
ldx #<(__CODE_0300_SIZE__ + __DATA_0300_SIZE__)
|
||||
: lda __CODE_0300_LOAD__ - 1,x
|
||||
sta __CODE_0300_RUN__ - 1,x
|
||||
dex
|
||||
bne :-
|
||||
|
||||
; Remove ".SYSTEM" from pathname
|
||||
lda PATHNAME
|
||||
sec
|
||||
sbc #.strlen(".SYSTEM")
|
||||
sta PATHNAME
|
||||
|
||||
; Add trailing '\0' to pathname
|
||||
tax
|
||||
lda #$00
|
||||
sta PATHNAME + 1,x
|
||||
|
||||
; Copy ProDOS startup filename and trailing '\0' to stack
|
||||
ldx STARTUP
|
||||
lda #$00
|
||||
beq :++ ; bra
|
||||
: lda STARTUP + 1,x
|
||||
: sta STACK,x
|
||||
dex
|
||||
bpl :--
|
||||
|
||||
; Provide some user feedback
|
||||
lda #<LOADING
|
||||
ldx #>LOADING
|
||||
jsr PRINT
|
||||
lda #<(PATHNAME + 1)
|
||||
ldx #>(PATHNAME + 1)
|
||||
jsr PRINT
|
||||
lda #<ELLIPSES
|
||||
ldx #>ELLIPSES
|
||||
jsr PRINT
|
||||
|
||||
jsr MLI
|
||||
.byte GET_FILE_INFO_CALL
|
||||
.word GET_FILE_INFO_PARAM
|
||||
bcc :+
|
||||
jmp ERROR
|
||||
|
||||
: jsr MLI
|
||||
.byte OPEN_CALL
|
||||
.word OPEN_PARAM
|
||||
bcc :+
|
||||
jmp ERROR
|
||||
|
||||
; Copy file reference number
|
||||
: lda OPEN_REF
|
||||
sta READ_REF
|
||||
sta CLOSE_REF
|
||||
|
||||
; Get load address from aux-type
|
||||
lda FILE_INFO_ADDR
|
||||
ldx FILE_INFO_ADDR + 1
|
||||
sta READ_ADDR
|
||||
stx READ_ADDR + 1
|
||||
|
||||
; It's high time to leave this place
|
||||
jmp __CODE_0300_RUN__
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
.segment "CODE_0300"
|
||||
|
||||
jsr MLI
|
||||
.byte READ_CALL
|
||||
.word READ_PARAM
|
||||
bcs ERROR
|
||||
|
||||
jsr MLI
|
||||
.byte CLOSE_CALL
|
||||
.word CLOSE_PARAM
|
||||
bcs ERROR
|
||||
|
||||
; Copy REM token and startup filename to BASIC input buffer
|
||||
ldx #$00
|
||||
lda #$B2
|
||||
bne :++ ; bra
|
||||
: inx
|
||||
lda a:STACK - 1,x
|
||||
: sta BUF,x
|
||||
bne :--
|
||||
|
||||
; Go for it ...
|
||||
jmp (READ_ADDR)
|
||||
|
||||
PRINT:
|
||||
sta A1L
|
||||
stx A1H
|
||||
ldx VERSION
|
||||
ldy #$00
|
||||
: lda (A1L),y
|
||||
beq :++
|
||||
cpx #$06 ; //e ?
|
||||
beq :+
|
||||
cmp #$60 ; lowercase ?
|
||||
bcc :+
|
||||
and #$5F ; -> uppercase
|
||||
: ora #$80
|
||||
jsr COUT
|
||||
iny
|
||||
bne :-- ; bra
|
||||
: rts
|
||||
|
||||
ERROR:
|
||||
cmp #FILE_NOT_FOUND_ERR
|
||||
bne :+
|
||||
lda #<FILE_NOT_FOUND
|
||||
ldx #>FILE_NOT_FOUND
|
||||
jsr PRINT
|
||||
beq :++ ; bra
|
||||
: pha
|
||||
lda #<ERROR_NUMBER
|
||||
ldx #>ERROR_NUMBER
|
||||
jsr PRINT
|
||||
pla
|
||||
jsr PRBYTE
|
||||
: lda #<PRESS_ANY_KEY
|
||||
ldx #>PRESS_ANY_KEY
|
||||
jsr PRINT
|
||||
jsr RDKEY
|
||||
jsr MLI
|
||||
.byte QUIT_CALL
|
||||
.word QUIT_PARAM
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
80
libsrc/apple2/targetutil/loader.txt
Normal file
80
libsrc/apple2/targetutil/loader.txt
Normal file
@@ -0,0 +1,80 @@
|
||||
LOADER.SYSTEM - an Apple][ ProDOS 8 loader for cc65 programs (Oliver Schmidt)
|
||||
=============================================================================
|
||||
|
||||
|
||||
Background
|
||||
----------
|
||||
|
||||
Apple][ ProDOS 8 system programs (filetype SYS) are always loaded into memory
|
||||
starting at location $2000. This poses the problem of how to make efficient
|
||||
use of the memory in the range $0800-$2000. The usual approach of relocation
|
||||
has two downsides:
|
||||
- Relocating e.g. 30 kB from $2000-$9800 to $0800-$8000 takes a considerable
|
||||
amount of time.
|
||||
- Really large programs just don't fit into memory when loaded starting at
|
||||
location $2000.
|
||||
|
||||
The relocation can be eliminated by loading the major part(s) of the program
|
||||
from disk right to the final location by a rather small system program.
|
||||
|
||||
LOADER.SYSTEM is such a small program. In fact it's so small that it fits into
|
||||
a single block in the ProDOS 8 file system making it a so-called seedling file,
|
||||
which are loaded really fast. LOADER.SYSTEM can load cc65 programs into memory
|
||||
anywhere in the range $0800-$BB00 (44,75 kB).
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Link the cc65 program to the start address $0803 (or any other address) and
|
||||
store it as binary program (filetype BIN). This is in fact no different from
|
||||
a binary program to be run by BASIC.SYSTEM's BRUN command in the usual way.
|
||||
|
||||
If however the cc65 program isn't run by BASIC.SYSTEM but is rather run by
|
||||
LOADER.SYSTEM then it behaves like a system program which means:
|
||||
- It uses memory up to the ProDOS 8 system global page located at $BF00.
|
||||
- It supports the ProDOS 8 startup file mechanism (mapped to argv[1]).
|
||||
- It quits to the ProDOS 8 dispatcher.
|
||||
|
||||
Obviously LOADER.SYSTEM has to be told which cc65 program to run. Unfortunately
|
||||
the ProDOS 8 dispatcher has no notion of system program parameters so the usual
|
||||
approach would have been to make LOADER.SYSTEM bring up yet another menu to
|
||||
select the cc65 program to run.
|
||||
|
||||
But to allow to select the cc65 program directly from the ProDOS 8 dispatcher
|
||||
anyway LOADER.SYSTEM detects the path to the cc65 program from its own path by
|
||||
just removing the '.SYSTEM' from its name. So if you want to run the cc65
|
||||
program MYPROGRAM you'll need a copy of LOADER.SYSTEM in the same directory
|
||||
being renamed to MYPROGRAM.SYSTEM.
|
||||
|
||||
This means you will end up with a copy of LOADER.SYSTEM for every cc65 program
|
||||
to be run by it. But as LOADER.SYSTEM is a ProDOS 8 seedling file using up only
|
||||
a single block in the ProDOS 8 file system this should be no issue.
|
||||
|
||||
|
||||
Build
|
||||
-----
|
||||
|
||||
In case you want to build 'loader.system' from the source code yourself you can
|
||||
do so using the following commands:
|
||||
|
||||
ca65 loader.s
|
||||
ld65 -C loader.cfg -o loader.system loader.o
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
The file 'loader.system' as generated by the cc65 linker with the command above
|
||||
does NOT include the 4-byte address/length header that is generated for Apple][
|
||||
programs by default. This is because ProDOS 8 system programs are always loaded
|
||||
into memory starting at location $2000.
|
||||
|
||||
The recommended way to transfer 'loader.system' from your native file system to
|
||||
a ProDOS 8 file system disk image is to use AppleCommander which is available at
|
||||
http://applecommander.sourceforge.net/
|
||||
|
||||
If you want to put the file 'loader.system' onto a disk image 'mydisk.dsk' as
|
||||
system program MYPROGRAM.SYSTEM you can do so using the following command:
|
||||
|
||||
java -jar ac.jar -p mydisk.dsk MYPROGRAM.SYSTEM sys < loader.system
|
||||
Reference in New Issue
Block a user