diff --git a/scripts/emuwasm.js b/scripts/emuwasm.js index fad6af1..a90bc5a 100755 --- a/scripts/emuwasm.js +++ b/scripts/emuwasm.js @@ -429,8 +429,6 @@ const instructions = [ ], [ "LDZ2", - // Used to be (#T2^! (i32.load16_u (local.get $t))). - // Since LDZ2 does not wrap, this was ok, but performance is the same (and this is more consistent with LDZ) ` (local.set $t (#T)) (#set 1 1) @@ -439,8 +437,6 @@ const instructions = [ ], [ "STZ2", - // Used to be (i32.store16 (local.get $t) (local.get $n)) - // Since STZ2 does not wrap, this was ok, but peformance is actually worse. ` (local.set $t (#T)) (local.set $n (#N)) @@ -877,7 +873,7 @@ function generate() { // zero-page (not wrapping) [ "poke2z", - `(i32.store8 #1 #2) (i32.store8 (i32.add #1 (i32.const 1)) #3)`, + `(i32.store8 #1 #2) (i32.store8 (i32.and (i32.add #1 (i32.const 1)) (i32.const 0xff)) #3)`, ], ]; for (const [regname, regidx] of [ @@ -912,7 +908,7 @@ function generate() { reg + "2 Testing that zero-page is not wrapping ) + > Testing that zero-page is wrapping ) #1234 #ff STZ2 - #ff LDZ #0100 LDA ADD #46 EQU + #00ff LDA #0000 LDA ADD #46 EQU ;Dict/zp-wrap test-part - ( Part 10 - > Testing that device page is wrapping - > TODO ) + ( Part 10 + > Testing that device page is wrapping ) + + #1234 #ff DEO2 + #ff DEI #00 DEI ADD #46 EQU + ;Dict/dev-wrap test-part + #0000 DEO #00ff DEO ( end ) @@ -105,7 +109,7 @@ BRK ( name ) "Opctest 0a ( details ) "A 20 "Testing 20 "Program 0a ( author ) "By 20 "Devine 20 "Lu 20 "Linvega 0a - ( date ) "31 20 "Oct 20 "2023 $2 + ( date ) "1 20 "Nov 20 "2023 $2 @test-part ( f name* -- ) pstr ?{ @@ -277,12 +281,12 @@ JMP2r &g #8000 #0200 MUL2 [ #0000 ] EQU2 JMP2r &h #2222 #0003 MUL2 [ #6666 ] EQU2 JMP2r @op-div ;Dict/div !set - &a #10 #02 DIV [ #08 ] EQU JMP2r + &a #10 #06 DIV [ #02 ] EQU JMP2r &b #20 #20 DIV [ #01 ] EQU JMP2r &c #34 #01 DIV [ #34 ] EQU JMP2r &d #02 #ef DIV [ #00 ] EQU JMP2r &e #02 #00 DIV [ #00 ] EQU JMP2r - &f #1000 #0040 DIV2 [ #0040 ] EQU2 JMP2r + &f #03e8 #0006 DIV2 [ #00a6 ] EQU2 JMP2r &g #abcd #1234 DIV2 [ #0009 ] EQU2 JMP2r &h #8000 #0200 DIV2 [ #0040 ] EQU2 JMP2r &i #2222 #0003 DIV2 [ #0b60 ] EQU2 JMP2r @@ -420,6 +424,7 @@ JMP2r &stack-wrap "Stack-wrap $1 &ram-wrap "RAM-wrap $1 &zp-wrap "Zeropage-wrap $1 + &dev-wrap "Devices-wrap $1 &result "Result: $1 &passed 20 "passed! 0a $1 &missed "Opcode 20 "Failed 20 "-- 20 $1 diff --git a/src/tests/suite.js b/src/tests/suite.js index fead74e..46d748a 100644 --- a/src/tests/suite.js +++ b/src/tests/suite.js @@ -300,7 +300,7 @@ function loadTests() { deo(port, value); }, dei(port) { - throw new Error("not implemented"); + return uxn.dev[port]; }, }); }); @@ -454,12 +454,12 @@ function loadTests() { expect(wst()).to.eql([0xab, 0xcd]); }); - it("should not wrap around zero page", () => { + it("should wrap around zero page", () => { uxn.load([LIT, 0xff, LDZ2]); uxn.ram[0xff] = 0xab; uxn.ram[0x00] = 0xcd; uxn.eval(PROGRAM_OFFSET); - expect(wst()).to.eql([0xab, 0x80]); + expect(wst()).to.eql([0xab, 0xcd]); }); }); diff --git a/src/uxn.wat b/src/uxn.wat index 99579e4..bf56646 100644 --- a/src/uxn.wat +++ b/src/uxn.wat @@ -400,7 +400,7 @@ (local.set $t (i32.load8_u offset=0x10000 (local.get $wstp))) (local.set $wstp (i32.and (i32.add (local.get $wstp) (i32.const 255)) (i32.const 0xff))) (i32.store8 offset=0x10000 (i32.and (i32.add (local.get $wstp) (i32.const 1)) (i32.const 0xff)) (i32.load8_u (local.get $t))) - (i32.store8 offset=0x10000 (local.get $wstp) (i32.load8_u (i32.add (local.get $t) (i32.const 1)))) + (i32.store8 offset=0x10000 (local.get $wstp) (i32.load8_u (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)))) (br $loop) );; STZ2 @@ -409,7 +409,7 @@ (local.set $l (i32.load8_u offset=0x10000 (i32.and (i32.add (local.get $wstp) (i32.const 2)) (i32.const 0xff)))) (local.set $wstp (i32.and (i32.add (local.get $wstp) (i32.const 3)) (i32.const 0xff))) (i32.store8 (local.get $t) (local.get $l)) - (i32.store8 (i32.add (local.get $t) (i32.const 1)) (local.get $n)) + (i32.store8 (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)) (local.get $n)) (br $loop) );; LDR2 @@ -867,7 +867,7 @@ (local.set $t (i32.load8_u offset=0x10100 (local.get $rstp))) (local.set $rstp (i32.and (i32.add (local.get $rstp) (i32.const 255)) (i32.const 0xff))) (i32.store8 offset=0x10100 (i32.and (i32.add (local.get $rstp) (i32.const 1)) (i32.const 0xff)) (i32.load8_u (local.get $t))) - (i32.store8 offset=0x10100 (local.get $rstp) (i32.load8_u (i32.add (local.get $t) (i32.const 1)))) + (i32.store8 offset=0x10100 (local.get $rstp) (i32.load8_u (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)))) (br $loop) );; STZ2r @@ -876,7 +876,7 @@ (local.set $l (i32.load8_u offset=0x10100 (i32.and (i32.add (local.get $rstp) (i32.const 2)) (i32.const 0xff)))) (local.set $rstp (i32.and (i32.add (local.get $rstp) (i32.const 3)) (i32.const 0xff))) (i32.store8 (local.get $t) (local.get $l)) - (i32.store8 (i32.add (local.get $t) (i32.const 1)) (local.get $n)) + (i32.store8 (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)) (local.get $n)) (br $loop) );; LDR2r @@ -1331,7 +1331,7 @@ (local.set $t (i32.load8_u offset=0x10000 (local.get $wstp))) (local.set $wstp (i32.and (i32.add (local.get $wstp) (i32.const 254)) (i32.const 0xff))) (i32.store8 offset=0x10000 (i32.and (i32.add (local.get $wstp) (i32.const 1)) (i32.const 0xff)) (i32.load8_u (local.get $t))) - (i32.store8 offset=0x10000 (local.get $wstp) (i32.load8_u (i32.add (local.get $t) (i32.const 1)))) + (i32.store8 offset=0x10000 (local.get $wstp) (i32.load8_u (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)))) (br $loop) );; STZ2k @@ -1339,7 +1339,7 @@ (local.set $n (i32.load8_u offset=0x10000 (i32.and (i32.add (local.get $wstp) (i32.const 1)) (i32.const 0xff)))) (local.set $l (i32.load8_u offset=0x10000 (i32.and (i32.add (local.get $wstp) (i32.const 2)) (i32.const 0xff)))) (i32.store8 (local.get $t) (local.get $l)) - (i32.store8 (i32.add (local.get $t) (i32.const 1)) (local.get $n)) + (i32.store8 (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)) (local.get $n)) (br $loop) );; LDR2k @@ -1792,7 +1792,7 @@ (local.set $t (i32.load8_u offset=0x10100 (local.get $rstp))) (local.set $rstp (i32.and (i32.add (local.get $rstp) (i32.const 254)) (i32.const 0xff))) (i32.store8 offset=0x10100 (i32.and (i32.add (local.get $rstp) (i32.const 1)) (i32.const 0xff)) (i32.load8_u (local.get $t))) - (i32.store8 offset=0x10100 (local.get $rstp) (i32.load8_u (i32.add (local.get $t) (i32.const 1)))) + (i32.store8 offset=0x10100 (local.get $rstp) (i32.load8_u (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)))) (br $loop) );; STZ2kr @@ -1800,7 +1800,7 @@ (local.set $n (i32.load8_u offset=0x10100 (i32.and (i32.add (local.get $rstp) (i32.const 1)) (i32.const 0xff)))) (local.set $l (i32.load8_u offset=0x10100 (i32.and (i32.add (local.get $rstp) (i32.const 2)) (i32.const 0xff)))) (i32.store8 (local.get $t) (local.get $l)) - (i32.store8 (i32.add (local.get $t) (i32.const 1)) (local.get $n)) + (i32.store8 (i32.and (i32.add (local.get $t) (i32.const 1)) (i32.const 0xff)) (local.get $n)) (br $loop) );; LDR2kr