@@ -130,6 +130,7 @@ class BackendUXN : CompilerBackend {
130130 override long MaxInt () => 0xFFFF ;
131131
132132 override string DefaultHeader () => "
133+ |00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
133134 |10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
134135 " ;
135136
@@ -216,6 +217,7 @@ class BackendUXN : CompilerBackend {
216217 }
217218
218219 override void Init () {
220+ WarnNoInfo(" This backend is slightly broken. Don't use implement or printf" );
219221 output ~= " |0 @vsp $2 @arraySrc $2 @arrayDest $2\n " ;
220222 output ~= " |100\n " ;
221223 output ~= " @on-reset\n " ;
@@ -264,6 +266,13 @@ class BackendUXN : CompilerBackend {
264266 }
265267 }
266268
269+ output ~= " @memcpy 01\n " ;
270+ output ~= " &length 0000\n " ;
271+ output ~= " &srcBank 0000\n " ;
272+ output ~= " &srcAddr 0000\n " ;
273+ output ~= " &dstBank 0000\n " ;
274+ output ~= " &dstAddr 0000\n " ;
275+
267276 // pad for the stack
268277 output ~= " |e0000\n " ;
269278 }
@@ -1104,15 +1113,14 @@ class BackendUXN : CompilerBackend {
11041113 output ~= format(" #ffff ;global_%s STA2\n " , Sanitise(" _cal_exception" ));
11051114
11061115 // copy exception message
1107- // TODO: make this less bloat
1108- foreach (i ; 0 .. 3 ) {
1109- output ~= " DUP2 LDA2\n " ;
1110- output ~= format(
1111- " ;global_%s #%.2x ADD2 STA2\n " , Sanitise(" _cal_exception" ), i + 2
1112- );
1113- output ~= " #0002 ADD2\n " ;
1114- }
1115- output ~= " POP2\n " ;
1116+ output ~= " #0006 ;memcpy/length STA2\n " ;
1117+ output ~= " #0000 ;memcpy/srcBank STA2\n " ;
1118+ output ~= " ;memcpy/srcAddr STA2\n " ;
1119+ output ~= " #0000 ;memcpy/dstBank STA2\n " ;
1120+ output ~= format(
1121+ " ;global_%s INC2 INC2 ;memcpy/dstAddr STA2\n " , Sanitise(" _cal_exception" )
1122+ );
1123+ output ~= " ;memcpy .System/expansion DEO2\n " ;
11161124
11171125 CompileReturn(node);
11181126 }
0 commit comments