From 8730e2ff9a44f9efe8020d6a1118b57651d68750 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Tue, 13 Mar 2018 07:48:34 -0700 Subject: [PATCH] Update test cases and portable VM --- src/samplesrc/test.pla | 14 +++++++++----- src/vmsrc/apple/plvm802.s | 2 +- src/vmsrc/plvm.c | 7 +++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/samplesrc/test.pla b/src/samplesrc/test.pla index 224760a..a8a1c26 100755 --- a/src/samplesrc/test.pla +++ b/src/samplesrc/test.pla @@ -85,7 +85,7 @@ def vals123#3 return 1, 2, 3 end export def main(range)#0 - byte a, b, c + word a, b, c word lambda a = 10 @@ -127,10 +127,14 @@ export def main(range)#0 drop, b, drop = vals123 drop, drop, c = vals123 puts("a, b, c = "); puti(a); puts(", "); puti(b); puts(", "); puti(c); putln - puts(" 8 % 3 = "); puti(8%3); putln - puts(" 8 % -3 = "); puti(8%-3); putln - puts("-8 % 3 = "); puti(-8%3); putln - puts("-8 % -3 = "); puti(-8%-3); putln + puts(" 7 / 3 = "); puti(7/3); puts(" ; 7 % 3 = "); puti(7%3); putln + puts(" 7 / -3 = "); puti(7/-3); puts("; 7 % -3 = "); puti(7%-3); putln + puts("-7 / 3 = "); puti(-7/3); puts("; -7 % 3 = "); puti(-7%3); putln + puts("-7 / -3 = "); puti(-7/-3); puts(" ; -7 % -3 = "); puti(-7%-3); putln + a,b=divmod(7,3); puts("divmod( 7, 3) = "); puti(a); puts(", "); puti(b); putln + a,b=divmod(7,-3); puts("divmod( 7,-3) = "); puti(a); puts(", "); puti(b); putln + a,b=divmod(-7,3); puts("divmod(-7, 3) = "); puti(a); puts(", "); puti(b); putln + a,b=divmod(-7,-3);puts("divmod(-7,-3) = "); puti(a); puts(", "); puti(b); putln end def dummy(zz)#2 diff --git a/src/vmsrc/apple/plvm802.s b/src/vmsrc/apple/plvm802.s index 7702cb1..18fca79 100644 --- a/src/vmsrc/apple/plvm802.s +++ b/src/vmsrc/apple/plvm802.s @@ -544,12 +544,12 @@ _DIV STY IPY LDY #$11 ; #BITS+1 LDX #$00 LDA NOS+2,S ; WE JSR'ED HERE SO OFFSET ACCORDINGLY + BEQ _DIVEX BPL + LDX #$81 EOR #$FFFF INC + STA TMP ; NOS,S - BEQ _DIVEX LDA TOS+2,S BPL + INX diff --git a/src/vmsrc/plvm.c b/src/vmsrc/plvm.c index 5395c44..5379d9b 100755 --- a/src/vmsrc/plvm.c +++ b/src/vmsrc/plvm.c @@ -455,6 +455,7 @@ void interp(code *ip); void call(uword pc) { unsigned int i, s; + int a, b; char c, sz[64]; if (show_state) @@ -508,6 +509,12 @@ void call(uword pc) mem_data[0x1FF] = i; PUSH(0x1FF); break; + case 24: // LIBRARY CMDSYS::DIVMOD + a = POP; + b = POP; + PUSH(b / a); + PUSH(b % a); + break; default: printf("\nUnimplemented call code:$%02X\n", mem_data[pc - 1]); exit(1);