]> git.sur5r.net Git - cc65/commitdiff
Add two new trampoline test cases
authorLauri Kasanen <cand@gmx.com>
Fri, 19 May 2017 11:20:04 +0000 (14:20 +0300)
committerLauri Kasanen <cand@gmx.com>
Fri, 19 May 2017 11:34:10 +0000 (14:34 +0300)
test/val/trampoline-params.c [new file with mode: 0644]
test/val/trampoline-varargs.c [new file with mode: 0644]

diff --git a/test/val/trampoline-params.c b/test/val/trampoline-params.c
new file mode 100644 (file)
index 0000000..890e43e
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+  !!DESCRIPTION!! wrapped-call pragma w/ many params
+  !!ORIGIN!!      cc65 regression tests
+  !!LICENCE!!     Public Domain
+  !!AUTHOR!!      Lauri Kasanen
+*/
+
+#include <stdarg.h>
+
+static unsigned char flag;
+
+static void trampoline_set() {
+       asm("ldy tmp4");
+       asm("sty %v", flag);
+       asm("jsr callptr4");
+}
+
+#pragma wrapped-call(push, trampoline_set, 4)
+long adder(long in);
+#pragma wrapped-call(pop)
+
+long adder(long in) {
+
+       return in + 7;
+}
+
+int main() {
+
+       flag = 0;
+
+       return adder(70436) == 70436 + 7 && flag == 4 ? 0 : 1;
+}
diff --git a/test/val/trampoline-varargs.c b/test/val/trampoline-varargs.c
new file mode 100644 (file)
index 0000000..5d3377c
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  !!DESCRIPTION!! wrapped-call pragma w/ varags
+  !!ORIGIN!!      cc65 regression tests
+  !!LICENCE!!     Public Domain
+  !!AUTHOR!!      Lauri Kasanen
+*/
+
+#include <stdarg.h>
+
+static unsigned char flag;
+
+static void trampoline_set() {
+       // The Y register is used for variadics - save and restore
+       asm("sty tmp3");
+
+       asm("ldy tmp4");
+       asm("sty %v", flag);
+
+       asm("ldy tmp3");
+       asm("jsr callptr4");
+}
+
+#pragma wrapped-call(push, trampoline_set, 4)
+unsigned adder(unsigned char num, ...);
+#pragma wrapped-call(pop)
+
+unsigned adder(unsigned char num, ...) {
+
+       unsigned char i;
+       unsigned sum = 0;
+       va_list ap;
+       va_start(ap, num);
+
+       for (i = 0; i < num; i++) {
+               sum += va_arg(ap, unsigned);
+       }
+
+       va_end(ap);
+
+       return sum;
+}
+
+int main() {
+
+       flag = 0;
+
+       return adder(3, 0, 5, 500) == 505 && flag == 4 ? 0 : 1;
+}