diff --git a/apps/lib/expr.asm b/apps/lib/expr.asm index 57eb33d..3a17a43 100644 --- a/apps/lib/expr.asm +++ b/apps/lib/expr.asm @@ -26,6 +26,18 @@ parseExpr: pop de ret +; Same as parseExpr, but preserves IX and puts result in DE. This is a +; transitionary routine and will replace parseExpr when everyone has jumped +; ship. +parseExprDE: + push ix + push hl + call _parseExpr + push ix \ pop de + pop hl + pop ix + ret + _parseExpr: ld de, exprTbl .loop: diff --git a/tools/emul/runbin/runbin.c b/tools/emul/runbin/runbin.c index 2de5bb4..2c5456c 100644 --- a/tools/emul/runbin/runbin.c +++ b/tools/emul/runbin/runbin.c @@ -6,9 +6,15 @@ * until it halts. The return code is the value of the register A at halt time. */ +static void iowr_stderr(uint8_t val) +{ + fputc(val, stderr); +} + int main() { Machine *m = emul_init(); + m->iowr[0] = iowr_stderr; // read stdin in mem int i = 0; int c = getchar(); @@ -22,6 +28,7 @@ int main() return 1; } emul_loop(); + if (m->cpu.R1.wr.HL) return m->cpu.R1.br.A; } diff --git a/tools/tests/unit/runtests.sh b/tools/tests/unit/runtests.sh index 78566c8..c3f0519 100755 --- a/tools/tests/unit/runtests.sh +++ b/tools/tests/unit/runtests.sh @@ -11,7 +11,7 @@ APPS="${BASE}/apps" chk() { echo "Running test $1" - if ! ${ZASM} "${KERNEL}" "${APPS}" < $1 | ${RUNBIN}; then + if ! ${ZASM} "${KERNEL}" "${APPS}" common.asm < $1 | ${RUNBIN}; then echo "failed with code ${PIPESTATUS[1]}" exit 1 fi @@ -22,7 +22,7 @@ if [ ! -z $1 ]; then exit 0 fi -for fn in *.asm; do +for fn in test_*.asm; do chk "${fn}" done diff --git a/tools/tests/unit/test_basic_parse.asm b/tools/tests/unit/test_basic_parse.asm index 6949da5..3c667d1 100644 --- a/tools/tests/unit/test_basic_parse.asm +++ b/tools/tests/unit/test_basic_parse.asm @@ -1,5 +1,6 @@ jp test +.inc "ascii.h" .inc "core.asm" .inc "str.asm" .inc "lib/util.asm" @@ -8,6 +9,9 @@ jp test .equ EXPR_PARSE parseLiteral .inc "lib/expr.asm" .inc "basic/parse.asm" +.inc "lib/fmt.asm" +.inc "stdio.asm" +.inc "common.asm" test: ld sp, 0xffff @@ -55,21 +59,21 @@ testParseThruth: .true: call parseTruth - jp nz, fail + call assertZ or a - jp z, fail + call assertNZ jp nexttest .false: call parseTruth - jp nz, fail + call assertZ or a - jp nz, fail + call assertZ jp nexttest .error: call parseTruth - jp z, fail + call assertNZ jp nexttest .t1: .db "42", 0 @@ -88,17 +92,4 @@ testParseThruth: .f6: .db "2<=1", 0 .e1: .db "foo", 0 -testNum: .db 1 - -nexttest: - ld a, (testNum) - inc a - ld (testNum), a - ret - -fail: - ld a, (testNum) - halt - -; used as RAM -sandbox: +STDIO_RAMSTART: diff --git a/tools/tests/unit/test_core.asm b/tools/tests/unit/test_core.asm index 71e67de..1ae3b06 100644 --- a/tools/tests/unit/test_core.asm +++ b/tools/tests/unit/test_core.asm @@ -5,8 +5,14 @@ jp test +.inc "ascii.h" +.inc "core.asm" +.inc "lib/ari.asm" +.inc "lib/fmt.asm" +.inc "stdio.asm" +.inc "common.asm" + dummyLabel: -testNum: .db 1 .equ dummyLabel 0x42 @@ -37,37 +43,25 @@ test: call nexttest ; Test that .equ can override label - ld a, 0x42 + ld de, 0x42 ld hl, dummyLabel - cp l - jp nz, fail + call assertEQW call nexttest ; test that "@" is updated by a .org directive ld hl, AFTER_ORG ld de, 0x1234 - or a ; clear carry - sbc hl, de - jp nz, fail + call assertEQW call nexttest ; test that AND affects the Z flag ld a, 0x69 and 0x80 - jp nz, fail + call assertZ call nexttest ; success xor a halt -nexttest: - ld a, (testNum) - inc a - ld (testNum), a - ret - -fail: - ld a, (testNum) - halt - +STDIO_RAMSTART: diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index e52ab25..260d42a 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -9,10 +9,12 @@ jp test +.inc "ascii.h" .inc "core.asm" .inc "str.asm" .inc "lib/util.asm" .inc "lib/ari.asm" +.inc "lib/fmt.asm" .inc "zasm/util.asm" .inc "zasm/const.asm" .inc "lib/parse.asm" @@ -21,6 +23,9 @@ jp test .inc "zasm/symbol.asm" .equ EXPR_PARSE parseNumberOrSymbol .inc "lib/expr.asm" +.equ STDIO_RAMSTART SYM_RAMEND +.inc "stdio.asm" +.inc "common.asm" ; Pretend that we aren't in first pass zasmIsFirstPass: @@ -29,8 +34,6 @@ zasmIsFirstPass: zasmGetPC: ret -testNum: .db 1 - s1: .db "2+2", 0 s2: .db "0x4001+0x22", 0 s3: .db "FOO+BAR", 0 @@ -44,29 +47,22 @@ sBAR: .db "BAR", 0 test: ld sp, 0xffff + ; New-style tests + ;call testParseExpr + ; Old-style tests, not touching them now. ld hl, s1 - call parseExpr - jp nz, fail - push ix \ pop hl - ld a, h - or a - jp nz, fail - ld a, l - cp 4 - jp nz, fail + call parseExprDE + call assertZ + ld hl, 4 + call assertEQW call nexttest ld hl, s2 - call parseExpr - jp nz, fail - push ix \ pop hl - ld a, h - cp 0x40 - jp nz, fail - ld a, l - cp 0x23 - jp nz, fail + call parseExprDE + call assertZ + ld hl, 0x4023 + call assertEQW call nexttest ; before the next test, let's set up FOO and BAR symbols @@ -81,55 +77,33 @@ test: jp nz, fail ld hl, s3 - call parseExpr - jp nz, fail - push ix \ pop hl - ld a, h - cp 0x40 - jp nz, fail - ld a, l - cp 0x20 - jp nz, fail + call parseExprDE + call assertZ + ld hl, 0x4020 + call assertEQW call nexttest ld hl, s4 - call parseExpr - jp nz, fail - push ix \ pop hl - ld a, h - or a - jp nz, fail - ld a, l - cp 0x60 - jp nz, fail + call parseExprDE + call assertZ + ld hl, 0x60 + call assertEQW call nexttest ld hl, s5 - call parseExpr - jp nz, fail - push ix \ pop hl - ld a, h - cp 0x3f - jp nz, fail - ld a, l - cp 0xfd - jp nz, fail + call parseExprDE + call assertZ + ld hl, 0x3ffd + call assertEQW call nexttest ld hl, s6 - call parseExpr - jp nz, fail - push ix \ pop hl - ld a, h - cp 0x40 - jp nz, fail - ld a, l - cp 0x80 - jp nz, fail + call parseExprDE + call assertZ + ld hl, 0x4080 + call assertEQW call nexttest - ; New-style tests - call testParseExpr ; success xor a halt @@ -151,20 +125,18 @@ testParseExpr: call .testEQ ld iy, .t8 call .testEQ + ld iy, .t9 + call .testEQ ret .testEQ: push iy \ pop hl inc hl \ inc hl - call parseExpr - jp nz, fail - push ix \ pop de - ld a, e - cp (iy) - jp nz, fail - ld a, d - cp (iy+1) - jp nz, fail + call parseExprDE + call assertZ + ld l, (iy) + ld h, (iy+1) + call assertEQW jp nexttest .t1: @@ -191,13 +163,6 @@ testParseExpr: .t8: .dw 0xffff .db "-1", 0 - -nexttest: - ld a, (testNum) - inc a - ld (testNum), a - ret - -fail: - ld a, (testNum) - halt +.t9: + .dw 10 + .db "2*3+4", 0