While I am stuck with many things that unlike OO are really hard to implement, I've added some very basic string support. So, this is a piece of code that sends a command to C64 disk drive:
Code:
package pl.qus.wolin
fun chkin^0xFFC6(lfn: ubyte^CPU.X): bool^CPU.C
fun getin^0xFFE4(): bool^CPU.A
fun readst^0xFFB7(): ubyte^CPU.A
fun clrchn^0xFFCC()
fun setlfs^0xFFBA(lfn: ubyte^CPU.A, device: ubyte^CPU.X, sa: ubyte^CPU.Y)
fun setnam^0xFFBD(fnameLen: ubyte^CPU.A, name: string^CPU.XY)
fun kopen^0xFFC0()
fun openCommandChannel(lfn: ubyte, device: ubyte, command: string) {
setlfs(lfn, device, 15)
setnam(10, command)
kopen()
}
fun main() {
openCommandChannel(15,8,"DUPA")
}
To pseudo asm:
Code:
setup HEADER
setup SPF = 251[ubyte], 40959[uword]
setup SP = 114[ubyte]
setup HEAP = 176[ubyte]
alloc SPF, #0
call __wolin_pl_qus_wolin_main[uword]
endfunction
function __wolin_pl_qus_wolin_openCommandChannel
alloc SPF, #0
save SP
save SPF(3)<pl.qus.wolin.openCommandChannel.lfn>[ubyte]
save SPF(2)<pl.qus.wolin.openCommandChannel.device>[ubyte]
save #15[ubyte]
restore CPU.Y[ubyte]
restore CPU.X[ubyte]
restore CPU.A[ubyte]
call 65466[uword]
restore SP
alloc SPF, #0
save SP
save #10[ubyte]
save SPF(0)<pl.qus.wolin.openCommandChannel.command>[ubyte*]
restore CPU.XY[ubyte*]
restore CPU.A[ubyte]
call 65469[uword]
restore SP
alloc SPF, #0
save SP
call 65472[uword]
restore SP
free SPF<pl.qus.wolin.openCommandChannel.__fnargs>, #4
endfunction
function __wolin_pl_qus_wolin_main
alloc SPF, #4
let SPF(3)[ubyte] = #15[ubyte]
let SPF(2)[ubyte] = #8[ubyte]
let SPF(0)[ubyte*] = #__wolin_lab_stringConst_0[uword]
call __wolin_pl_qus_wolin_openCommandChannel[uword]
endfunction
string __wolin_lab_stringConst_0[uword] = $"DUPA"
And finally to our favorite CPU:
Code:
; setupHEADER
;**********************************************
;*
;* BASIC header
;*
;* compile with:
;* cl65.exe -o assembler.prg -t c64 -C c64-asm.cfg -g -Ln labels.txt assembler.s
;*
;**********************************************
.org 2049
.export LOADADDR = *
Bas10: .word BasEnd
.word 10
.byte 158 ; sys
.byte " 2064"
.byte 0
BasEnd: .word 0
.word 0
;
; setupSPF=251[ubyte],40959[uword]
; prepare function stack
__wolin_spf := 251 ; function stack ptr
__wolin_spf_hi := 251+1 ; function stack ptr
__wolin_spf_top := 40959 ; function stack top
__wolin_spf_top_hi := 40959+1 ; function stack top
lda #<__wolin_spf_top ; set function stack top
sta __wolin_spf
lda #>__wolin_spf_top
sta __wolin_spf+1
; setupSP=114[ubyte]
; prepare program stack
__wolin_sp_top := 114 ; program stack top
__wolin_sp_top_hi := 114+1 ; program stack top
ldx #__wolin_sp_top ; set program stack top
; setupHEAP=176[ubyte]
__wolin_this_ptr := 176
__wolin_this_ptr_hi := 176+1
; allocSPF,#0
; call__wolin_pl_qus_wolin_main[uword]
jsr __wolin_pl_qus_wolin_main
; endfunction
rts
; function__wolin_pl_qus_wolin_openCommandChannel
__wolin_pl_qus_wolin_openCommandChannel:
; allocSPF,#0
; saveSP
txa
pha
; saveSPF(3)<pl.qus.wolin.openCommandChannel.lfn>[ubyte]
ldy #3
lda (__wolin_spf),y
pha
; saveSPF(2)<pl.qus.wolin.openCommandChannel.device>[ubyte]
ldy #2
lda (__wolin_spf),y
pha
; save#15[ubyte]
lda #15
pha
; restoreCPU.Y[ubyte]
pla
tay
; restoreCPU.X[ubyte]
pla
tax
; restoreCPU.A[ubyte]
pla
; call65466[uword]
jsr 65466
; restoreSP
pla
tax
; allocSPF,#0
; saveSP
txa
pha
; save#10[ubyte]
lda #10
pha
; saveSPF(0)<pl.qus.wolin.openCommandChannel.command>[ubyte*]
ldy #0
lda (__wolin_spf),y
pha
iny
lda (__wolin_spf),y
pha
; restoreCPU.XY[ubyte*]
pla
tay
pla
tax
; restoreCPU.A[ubyte]
pla
; call65469[uword]
jsr 65469
; restoreSP
pla
tax
; allocSPF,#0
; saveSP
txa
pha
; call65472[uword]
jsr 65472
; restoreSP
pla
tax
; freeSPF<pl.qus.wolin.openCommandChannel.__fnargs>,#4
clc
lda __wolin_spf
adc #4
sta __wolin_spf
bcc :+
inc __wolin_spf+1
:
; endfunction
rts
; function__wolin_pl_qus_wolin_main
__wolin_pl_qus_wolin_main:
; allocSPF,#4
sec
lda __wolin_spf
sbc #4
sta __wolin_spf
bcs :+
dec __wolin_spf+1
:
; letSPF(3)[ubyte]=#15[ubyte]
ldy #3
lda #15
sta (__wolin_spf),y
; letSPF(2)[ubyte]=#8[ubyte]
ldy #2
lda #8
sta (__wolin_spf),y
; letSPF(0)[ubyte*]=#__wolin_lab_stringConst_0[uword]
lda #<__wolin_lab_stringConst_0
ldy #0
sta (__wolin_spf),y
lda #>__wolin_lab_stringConst_0
iny
sta (__wolin_spf),y
; call__wolin_pl_qus_wolin_openCommandChannel[uword]
jsr __wolin_pl_qus_wolin_openCommandChannel
; endfunction
rts
; string__wolin_lab_stringConst_0[uword]=$"DUPA"
__wolin_lab_stringConst_0:
.str "DUPA"