2020-03-24 23:32:54 +00:00
|
|
|
%import c64lib
|
2020-03-14 23:47:21 +00:00
|
|
|
%import c64utils
|
2020-04-08 22:12:50 +00:00
|
|
|
%import c64flt
|
2020-04-03 20:44:10 +00:00
|
|
|
%zeropage basicsafe
|
2020-07-02 19:21:40 +00:00
|
|
|
%option enable_floats
|
2020-03-24 18:37:54 +00:00
|
|
|
|
2020-06-14 00:39:48 +00:00
|
|
|
|
2020-07-03 20:09:44 +00:00
|
|
|
; TODO: fix register argument clobbering when calling asmsubs.
|
|
|
|
; for instance if the first arg goes into Y, and the second in A,
|
|
|
|
; but when calculating the second argument clobbers Y, the first argument gets destroyed.
|
|
|
|
|
2020-03-24 23:32:54 +00:00
|
|
|
main {
|
2020-06-03 23:43:37 +00:00
|
|
|
|
2020-07-02 19:21:40 +00:00
|
|
|
sub start() {
|
2020-07-03 20:09:44 +00:00
|
|
|
function(20, calculate())
|
|
|
|
asmfunction(20, calculate())
|
2020-06-27 14:51:25 +00:00
|
|
|
|
2020-07-03 20:09:44 +00:00
|
|
|
c64.CHROUT('\n')
|
2020-06-27 14:51:25 +00:00
|
|
|
|
2020-07-03 20:09:44 +00:00
|
|
|
if @($0400)==@($0402) and @($0401) == @($0403) {
|
|
|
|
c64scr.print("ok: results are same\n")
|
|
|
|
} else {
|
|
|
|
c64scr.print("error: result differ; arg got clobbered\n")
|
|
|
|
}
|
|
|
|
}
|
2020-06-27 14:51:25 +00:00
|
|
|
|
2020-07-03 20:09:44 +00:00
|
|
|
sub function(ubyte a1, ubyte a2) {
|
|
|
|
; non-asm function passes via stack, this is ok
|
|
|
|
@($0400) = a1
|
|
|
|
@($0401) = a2
|
|
|
|
}
|
2020-07-02 19:21:40 +00:00
|
|
|
|
2020-07-03 20:09:44 +00:00
|
|
|
asmsub asmfunction(ubyte a1 @ Y, ubyte a2 @ A) {
|
|
|
|
; asm-function passes via registers, risk of clobbering
|
|
|
|
%asm {{
|
|
|
|
sty $0402
|
|
|
|
sta $0403
|
|
|
|
}}
|
2020-03-13 01:05:15 +00:00
|
|
|
}
|
2020-06-14 00:39:48 +00:00
|
|
|
|
2020-07-03 20:09:44 +00:00
|
|
|
sub calculate() -> ubyte {
|
|
|
|
Y = 99
|
|
|
|
return Y
|
|
|
|
}
|
2020-03-21 17:39:36 +00:00
|
|
|
}
|
2020-03-24 21:02:50 +00:00
|
|
|
|
2020-03-24 23:32:54 +00:00
|
|
|
|