Maybe a bit late but here is my solution the the problem in dreamass format:
Code:
#ifndef bin
#segdef "crtheader" , $0000-$0040
#segdef "chippacket" , $0040-$0050
#segdef "cbmheader" , $8000-$8009
#segdef "cartcode" , $8009-$A000, fillup, force
#outfile "loader.crt", "crtheader", "chippacket", "cbmheader", "cartcode"
#else
#segdef "cbmheader" , $8000-$8009
#segdef "cartcode" , $8009-$A000, fillup, force
#outfile "loader.bin", "cbmheader", "cartcode"
#endif
#ifndef bin
.segment "crtheader"
.text "c64 cartridge " ;3 spaces are required!!!
.byte $00,$00 ;header length
.byte $00,$40 ;header length
.word $0001 ;version
.word $0000 ;crt type
.byte $00 ;exrom line
.byte $01 ;game line
.byte $00,$00,$00,$00,$00,$00 ;unused
.text "crt first file loader " ;must be 32 bytes
.byte 0
.segment "chippacket"
.text "chip"
.byte $00,$00,$20,$10 ;chip length
.byte $00,$00 ;chip type = ROM
.byte $00,$00 ;bank = normal cartridge
.byte $80,$00 ;address
.byte $20,$00 ;length
#endif
.segment "cbmheader"
* = $8000
cartheader:
.word hardstart ;$09, $08
.word warmstart ;$09, $08
.byte $c3, $c2, $cd, $38, $30
.segment "cartcode"
hardstart:
stx $d016 ;enable VIC take a look at kernal $fCef
jsr $fda3 ;init i/o
jsr $fd50 ;init system constants
jsr $fd15 ;restore kernal vectors
jsr $ff5b ;CINT - init vic and screen editor
warmstart:
;basic reset
jsr $e453
jsr $e3bf
jsr $e422
ldx #$fb
txs
loader:
lda $d011
and #%11101111 ;blank screen
sta $d011
ldx #$00
rel lda mcode, x
sta $0400, x
inx
bne rel
jmp $0400
mcode:
.pseudopc $0400
sei
lda #$37
sta $01
cli
lda #fname_end-fname
ldx #<fname
ldy #>fname
jsr $ffbd ; call SETNAM
lda #$01
ldx $ba ; last used device number
bne skip
ldx #$08 ; default to device 8
skip: ldy #$01 ; not $01 means: load to address stored in file
jsr $ffba ; call SETLFS
lda #$00 ; $00 means: load to memory (not verify)
jsr $ffd5 ; call LOAD
jmp $0960 ;default exomizer entry point
error:
jmp *
fname: .text "*"
fname_end:
.realpc
end:
I use it to run prgs crunched with exomizer. There is no real error handling and the entrypoint of loaded program is hardcoded but it is trivial to change the code to your needs. Also using $0400 might not be the best idea - stack can be better in some cases. Actually as long as you are using 8kb crt from $8000 you can safely use kernal calls anyway so there is no need to relocate loader code. Treat it as a very poor example for further reference.