prog8/examples/test.p8

48 lines
1.0 KiB
Plaintext
Raw Normal View History

2020-03-24 23:32:54 +00:00
%import c64lib
%import c64utils
%import c64flt
%zeropage basicsafe
2020-07-02 19:21:40 +00:00
%option enable_floats
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-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-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 23:32:54 +00:00