mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 20:20:55 +11:00
Compare commits
No commits in common. "7410891ad1bc1189874404e694fae2ea10f373ab" and "98ca338aba486ab5e33545d2833b7c26d50da73b" have entirely different histories.
7410891ad1
...
98ca338aba
@ -224,6 +224,7 @@ basPRINT:
|
||||
ex de, hl
|
||||
call parseExpr
|
||||
jr nz, .parseError
|
||||
push ix \ pop de
|
||||
ld hl, SCRATCHPAD
|
||||
call fmtDecimalS
|
||||
call printstr
|
||||
@ -253,6 +254,7 @@ basGOTO:
|
||||
ex de, hl
|
||||
call parseExpr
|
||||
ret nz
|
||||
push ix \ pop de
|
||||
call bufFind
|
||||
jr nz, .notFound
|
||||
push ix \ pop de
|
||||
@ -315,7 +317,7 @@ basINPUT:
|
||||
call rdSep
|
||||
call stdioReadLine
|
||||
call parseExpr
|
||||
ld (VAR_TBL), de
|
||||
ld (VAR_TBL), ix
|
||||
call printcrlf
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
@ -42,6 +42,7 @@ parseTruth:
|
||||
.simple:
|
||||
call parseExpr
|
||||
jr nz, .end
|
||||
push ix \ pop de
|
||||
ld a, d
|
||||
or e
|
||||
jr .success
|
||||
@ -131,12 +132,12 @@ parseTruth:
|
||||
; place their corresponding values in HL and DE.
|
||||
.parseLeftRight:
|
||||
; let's start with HL
|
||||
push de ; --> lvl 1
|
||||
call parseExpr
|
||||
pop hl ; <-- lvl 1, orig DE
|
||||
ret nz
|
||||
push de ; --> lvl 1. save HL value in stack.
|
||||
; Now, for DE. (DE) is now in HL
|
||||
call parseExpr ; DE in place
|
||||
pop hl ; <-- lvl 1. restore saved HL
|
||||
push ix ; --> lvl 1. save (HL) value in stack.
|
||||
ex de, hl
|
||||
call parseExpr
|
||||
ret nz
|
||||
push ix \ pop de
|
||||
pop hl ; <-- lvl 1. restore.
|
||||
ret
|
||||
|
@ -85,13 +85,11 @@ rdWord:
|
||||
; Read word from HL in SCRATCHPAD and then intepret that word as an expression.
|
||||
; Put the result in IX.
|
||||
; Z for success.
|
||||
; TODO: put result in DE
|
||||
rdExpr:
|
||||
ld de, SCRATCHPAD
|
||||
call rdWord
|
||||
push hl
|
||||
ex de, hl
|
||||
call parseExpr
|
||||
push de \ pop ix
|
||||
pop hl
|
||||
ret
|
||||
|
@ -52,9 +52,10 @@ varTryAssign:
|
||||
call rdWord
|
||||
ex de, hl
|
||||
; Now, evaluate that expression now in (HL)
|
||||
call parseExpr ; --> number in DE
|
||||
call parseExpr ; --> number in IX
|
||||
jr nz, .exprErr
|
||||
pop af ; <-- lvl 4
|
||||
push ix \ pop de ; send number to DE
|
||||
call varAssign
|
||||
xor a ; ensure Z
|
||||
.end:
|
||||
|
@ -11,18 +11,19 @@
|
||||
;
|
||||
; *** Code ***
|
||||
;
|
||||
|
||||
; Parse expression in string at (HL) and returns the result in DE.
|
||||
; Parse expression in string at (HL) and returns the result in IX.
|
||||
; **This routine mutates (HL).**
|
||||
; We expect (HL) to be disposable: we mutate it to avoid having to make a copy.
|
||||
; Sets Z on success, unset on error.
|
||||
; TODO: the IX output register is a bit awkward. Nearly everywhere, I need
|
||||
; to push \ pop that thing. See if we could return the result in DE
|
||||
; instead.
|
||||
parseExpr:
|
||||
push ix
|
||||
push de
|
||||
push hl
|
||||
call _parseExpr
|
||||
push ix \ pop de
|
||||
pop hl
|
||||
pop ix
|
||||
pop de
|
||||
ret
|
||||
|
||||
_parseExpr:
|
||||
@ -96,29 +97,25 @@ _findAndSplit:
|
||||
; parse expression on the left (HL) and the right (DE) and put the results in
|
||||
; HL (left) and DE (right)
|
||||
_resolveLeftAndRight:
|
||||
ld a, (hl)
|
||||
or a
|
||||
jr z, .noleft
|
||||
; Parse left operand in (HL)
|
||||
push de ; --> lvl 1
|
||||
call parseExpr
|
||||
pop hl ; <-- lvl 1, orig DE
|
||||
ret nz ; return immediately if error
|
||||
.parseright:
|
||||
; Now we have parsed everything to the left and we have its result in
|
||||
; DE. What we need to do now is the same thing on (DE) and then apply
|
||||
; the + operator. Let's save DE somewhere and parse this.
|
||||
push de ; --> lvl 1
|
||||
; right expr in (HL)
|
||||
call parseExpr ; DE is set
|
||||
pop hl ; <-- lvl 1. left value
|
||||
ret ; Z is parseExpr's result
|
||||
.noleft:
|
||||
; special case: is (HL) zero? If yes, it means that our left operand
|
||||
; is empty. consider it as 0
|
||||
ex de, hl ; (DE) goes in (HL) for .parseright
|
||||
ld de, 0
|
||||
jr .parseright
|
||||
ld ix, 0 ; pre-set to 0
|
||||
ld a, (hl)
|
||||
or a
|
||||
jr z, .skip
|
||||
; Parse left operand in (HL)
|
||||
call parseExpr
|
||||
ret nz ; return immediately if error
|
||||
.skip:
|
||||
; Now we have parsed everything to the left and we have its result in
|
||||
; IX. What we need to do now is the same thing on (DE) and then apply
|
||||
; the + operator. Let's save IX somewhere and parse this.
|
||||
ex de, hl ; right expr now in HL
|
||||
push ix ; --> lvl 1
|
||||
call parseExpr
|
||||
pop hl ; <-- lvl 1. left
|
||||
push ix \ pop de ; right
|
||||
ret ; Z is parseExpr's result
|
||||
|
||||
; Routines in here all have the same signature: they take two numbers, DE (left)
|
||||
; and IX (right), apply the operator and put the resulting number in DE.
|
||||
|
@ -643,15 +643,14 @@ _readK8:
|
||||
jr _readExpr
|
||||
|
||||
_readDouble:
|
||||
push de
|
||||
push ix
|
||||
call parseExpr
|
||||
jr nz, .end
|
||||
ld b, d
|
||||
ld c, e
|
||||
push ix \ pop bc
|
||||
; BC is already set. For good measure, let's set A to BC's MSB
|
||||
ld a, b
|
||||
.end:
|
||||
pop de
|
||||
pop ix
|
||||
ret
|
||||
|
||||
_readk7:
|
||||
@ -664,12 +663,13 @@ _readk7:
|
||||
; truncation checks might falsely fail.
|
||||
call zasmIsFirstPass
|
||||
jr z, .end
|
||||
; DE contains an absolute value. Turn this into a -64/+63 relative
|
||||
; IX contains an absolute value. Turn this into a -64/+63 relative
|
||||
; value by subtracting PC from it. However, before we do that, let's
|
||||
; add 0x7f to it, which we'll remove later. This will simplify bounds
|
||||
; checks. (we use 7f instead of 3f because we deal in bytes here, not
|
||||
; in words)
|
||||
ld hl, 0x7f
|
||||
push ix \ pop hl
|
||||
ld de, 0x7f
|
||||
add hl, de ; Carry cleared
|
||||
ex de, hl
|
||||
call zasmGetPC ; --> HL
|
||||
@ -706,7 +706,6 @@ _readR4:
|
||||
; read a rXX argument and return register number in A.
|
||||
; Set Z for success.
|
||||
_readR5:
|
||||
push de
|
||||
push ix
|
||||
ld a, (hl)
|
||||
call upcase
|
||||
@ -715,44 +714,43 @@ _readR5:
|
||||
inc hl
|
||||
call parseDecimal
|
||||
jr nz, .end
|
||||
push ix \ pop de
|
||||
ld a, 31
|
||||
call _DE2A
|
||||
call _IX2A
|
||||
.end:
|
||||
pop ix
|
||||
pop de
|
||||
ret
|
||||
|
||||
; Put DE's LSB into A and, additionally, ensure that the new value is <=
|
||||
; Put IX's LSB into A and, additionally, ensure that the new value is <=
|
||||
; than what was previously in A.
|
||||
; Z for success.
|
||||
_DE2A:
|
||||
cp e
|
||||
jp c, unsetZ ; A < E
|
||||
ld a, d
|
||||
_IX2A:
|
||||
push ix \ pop hl
|
||||
cp l
|
||||
jp c, unsetZ ; A < L
|
||||
ld a, h
|
||||
or a
|
||||
ret nz ; should be zero
|
||||
ld a, e
|
||||
ld a, l
|
||||
; Z set from "or a"
|
||||
ret
|
||||
|
||||
; Read expr and return success only if result in under number given in A
|
||||
; Z for success
|
||||
_readExpr:
|
||||
push de
|
||||
push ix
|
||||
push bc
|
||||
ld b, a
|
||||
call parseExpr
|
||||
jr nz, .end
|
||||
ld a, b
|
||||
call _DE2A
|
||||
call _IX2A
|
||||
jr nz, .end
|
||||
or c
|
||||
ld c, a
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop bc
|
||||
pop de
|
||||
pop ix
|
||||
ret
|
||||
|
||||
; Parse one of the following: X, Y, Z, X+, Y+, Z+, -X, -Y, -Z.
|
||||
|
@ -40,7 +40,6 @@ dirHandlers:
|
||||
.dw handleBIN
|
||||
|
||||
handleDB:
|
||||
push de
|
||||
push hl
|
||||
.loop:
|
||||
call readWord
|
||||
@ -50,19 +49,18 @@ handleDB:
|
||||
jr z, .stringLiteral
|
||||
call parseExpr
|
||||
jr nz, .badarg
|
||||
ld a, d
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
or a ; cp 0
|
||||
jr nz, .overflow ; not zero? overflow
|
||||
ld a, e
|
||||
ld a, l
|
||||
call ioPutB
|
||||
jr nz, .ioError
|
||||
.stopStrLit:
|
||||
call readComma
|
||||
jr z, .loop
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop hl
|
||||
pop de
|
||||
ret
|
||||
.ioError:
|
||||
ld a, SHELL_ERR_IO_ERROR
|
||||
@ -76,8 +74,9 @@ handleDB:
|
||||
.overflow:
|
||||
ld a, ERR_OVFL
|
||||
.error:
|
||||
or a ; unset Z
|
||||
jr .end
|
||||
call unsetZ
|
||||
pop hl
|
||||
ret
|
||||
|
||||
.stringLiteral:
|
||||
ld a, (hl)
|
||||
@ -90,7 +89,6 @@ handleDB:
|
||||
jr .stringLiteral
|
||||
|
||||
handleDW:
|
||||
push de
|
||||
push hl
|
||||
.loop:
|
||||
call readWord
|
||||
@ -98,18 +96,17 @@ handleDW:
|
||||
ld hl, scratchpad
|
||||
call parseExpr
|
||||
jr nz, .badarg
|
||||
ld a, e
|
||||
push ix \ pop hl
|
||||
ld a, l
|
||||
call ioPutB
|
||||
jr nz, .ioError
|
||||
ld a, d
|
||||
ld a, h
|
||||
call ioPutB
|
||||
jr nz, .ioError
|
||||
call readComma
|
||||
jr z, .loop
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop hl
|
||||
pop de
|
||||
ret
|
||||
.ioError:
|
||||
ld a, SHELL_ERR_IO_ERROR
|
||||
@ -120,8 +117,9 @@ handleDW:
|
||||
.badarg:
|
||||
ld a, ERR_BAD_ARG
|
||||
.error:
|
||||
or a ; unset Z
|
||||
jr .end
|
||||
call unsetZ
|
||||
pop hl
|
||||
ret
|
||||
|
||||
handleEQU:
|
||||
call zasmIsLocalPass ; Are we in local pass? Then ignore all .equ.
|
||||
@ -151,6 +149,7 @@ handleEQU:
|
||||
call parseExpr
|
||||
jr nz, .badarg
|
||||
ld hl, DIREC_SCRATCHPAD
|
||||
push ix \ pop de
|
||||
; Save value in "@" special variable
|
||||
ld (DIREC_LASTVAL), de
|
||||
call symRegisterConst ; A and Z set
|
||||
@ -180,17 +179,14 @@ handleEQU:
|
||||
jp readWord
|
||||
|
||||
handleORG:
|
||||
push de
|
||||
call readWord
|
||||
jr nz, .badfmt
|
||||
call parseExpr
|
||||
jr nz, .badarg
|
||||
ex de, hl
|
||||
push ix \ pop hl
|
||||
ld (DIREC_LASTVAL), hl
|
||||
call zasmSetOrg
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop de
|
||||
ret
|
||||
.badfmt:
|
||||
ld a, ERR_BAD_FMT
|
||||
@ -198,28 +194,31 @@ handleORG:
|
||||
.badarg:
|
||||
ld a, ERR_BAD_ARG
|
||||
.error:
|
||||
or a ; unset Z
|
||||
jr .end
|
||||
call unsetZ
|
||||
ret
|
||||
|
||||
handleFIL:
|
||||
call readWord
|
||||
jr nz, .badfmt
|
||||
call parseExpr
|
||||
jr nz, .badarg
|
||||
ld a, d
|
||||
push bc ; --> lvl 1
|
||||
push ix \ pop bc
|
||||
ld a, b
|
||||
cp 0xd0
|
||||
jr nc, .overflow
|
||||
.loop:
|
||||
ld a, d
|
||||
or e
|
||||
ld a, b
|
||||
or c
|
||||
jr z, .loopend
|
||||
xor a
|
||||
call ioPutB
|
||||
jr nz, .ioError
|
||||
dec de
|
||||
dec bc
|
||||
jr .loop
|
||||
.loopend:
|
||||
cp a ; ensure Z
|
||||
pop bc ; <-- lvl 1
|
||||
ret
|
||||
.ioError:
|
||||
ld a, SHELL_ERR_IO_ERROR
|
||||
@ -231,11 +230,11 @@ handleFIL:
|
||||
ld a, ERR_BAD_ARG
|
||||
jp unsetZ
|
||||
.overflow:
|
||||
pop bc ; <-- lvl 1
|
||||
ld a, ERR_OVFL
|
||||
jp unsetZ
|
||||
|
||||
handleOUT:
|
||||
push de
|
||||
push hl
|
||||
; Read our expression
|
||||
call readWord
|
||||
@ -245,9 +244,10 @@ handleOUT:
|
||||
ld hl, scratchpad
|
||||
call parseExpr
|
||||
jr nz, .badarg
|
||||
ld a, d
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
out (ZASM_DEBUG_PORT), a
|
||||
ld a, e
|
||||
ld a, l
|
||||
out (ZASM_DEBUG_PORT), a
|
||||
jr .end
|
||||
.badfmt:
|
||||
@ -256,10 +256,9 @@ handleOUT:
|
||||
.badarg:
|
||||
ld a, ERR_BAD_ARG
|
||||
.error:
|
||||
or a ; unset Z
|
||||
call unsetZ
|
||||
.end:
|
||||
pop hl
|
||||
pop de
|
||||
ret
|
||||
|
||||
handleINC:
|
||||
|
@ -146,7 +146,7 @@ parseIXY:
|
||||
; any argspec (A == 0 means arg is empty). A return value of 0xff means an
|
||||
; error.
|
||||
;
|
||||
; If the parsed argument is a number constant, 'N' is returned and DE contains
|
||||
; If the parsed argument is a number constant, 'N' is returned and IX contains
|
||||
; the value of that constant.
|
||||
parseArg:
|
||||
call strlen
|
||||
@ -154,8 +154,13 @@ parseArg:
|
||||
ret z ; empty string? A already has our result: 0
|
||||
|
||||
push bc
|
||||
push de
|
||||
push hl
|
||||
|
||||
; We always initialize IX to zero so that non-numerical args end up with
|
||||
; a clean zero.
|
||||
ld ix, 0
|
||||
|
||||
ld de, argspecTbl
|
||||
; DE now points the the "argspec char" part of the entry, but what
|
||||
; we're comparing in the loop is the string next to it. Let's offset
|
||||
@ -176,7 +181,7 @@ parseArg:
|
||||
; (HL) has no parens
|
||||
call .maybeParseExpr
|
||||
jr nz, .nomatch
|
||||
; We have a proper number in no parens. Number in DE.
|
||||
; We have a proper number in no parens. Number in IX.
|
||||
ld a, 'N'
|
||||
jr .end
|
||||
.withParens:
|
||||
@ -203,20 +208,23 @@ parseArg:
|
||||
.parseNumberInParens:
|
||||
call .maybeParseExpr
|
||||
jr nz, .nomatch
|
||||
; We have a proper number in parens. Number in DE
|
||||
; is '-' in B? if yes, we need to negate the low part of DE
|
||||
; We have a proper number in parens. Number in IX
|
||||
; is '-' in B? if yes, we need to negate the low part of IX
|
||||
ld a, b
|
||||
cp '-'
|
||||
jr nz, .dontNegateDE
|
||||
; we need to negate the low part of DE
|
||||
jr nz, .dontNegateIX
|
||||
; we need to negate the low part of IX
|
||||
; TODO: when parsing routines properly support unary negative numbers,
|
||||
; We could replace this complicated scheme below with a nice hack where
|
||||
; we start parsing our displacement number at the '+' and '-' char.
|
||||
|
||||
ld a, e
|
||||
; HL isn't needed anymore and can be destroyed.
|
||||
push ix \ pop hl
|
||||
ld a, l
|
||||
neg
|
||||
ld e, a
|
||||
.dontNegateDE:
|
||||
ld l, a
|
||||
push hl \ pop ix
|
||||
.dontNegateIX:
|
||||
ld a, c ; M, x, or y
|
||||
jr .end
|
||||
.nomatch:
|
||||
@ -227,13 +235,9 @@ parseArg:
|
||||
; found the matching argspec row. Our result is one byte left of DE.
|
||||
dec de
|
||||
ld a, (de)
|
||||
|
||||
; When we have non-numerical args, we set DE to zero to have a clean
|
||||
; result.
|
||||
ld de, 0
|
||||
|
||||
.end:
|
||||
pop hl
|
||||
pop de
|
||||
pop bc
|
||||
ret
|
||||
|
||||
@ -243,7 +247,6 @@ parseArg:
|
||||
; harmless, but in some cases it causes false failures. For example,
|
||||
; a "-" operator can cause is to falsely overflow and generate
|
||||
; truncation error.
|
||||
ld de, 0 ; in first pass, return a clean zero
|
||||
call zasmIsFirstPass
|
||||
ret z
|
||||
jp parseExpr
|
||||
@ -814,18 +817,27 @@ spitUpcode:
|
||||
ld (INS_UPCODE+2), a
|
||||
ret
|
||||
|
||||
; Parse argument in (HL) and place it in (IX)
|
||||
; Parse argument in (HL) and place it in (DE)
|
||||
; DE is not preserved
|
||||
; Sets Z on success, reset on error.
|
||||
processArg:
|
||||
call parseArg
|
||||
cp 0xff
|
||||
jr z, .error
|
||||
ld (ix), a
|
||||
; When A is a number, DE is set with the value of that number. Because
|
||||
ld (de), a
|
||||
; When A is a number, IX is set with the value of that number. Because
|
||||
; We don't use the space allocated to store those numbers in any other
|
||||
; occasion, we store DE there unconditonally, LSB first.
|
||||
ld (ix+1), e
|
||||
ld (ix+2), d
|
||||
; occasion, we store IX there unconditonally, LSB first.
|
||||
inc de
|
||||
ex (sp), ix ; (SP) is kept in IX and will be restored
|
||||
ex (sp), hl ; old HL is on (SP)
|
||||
ld a, l
|
||||
ld (de), a
|
||||
inc de
|
||||
ld a, h
|
||||
ld (de), a
|
||||
ex (sp), hl ; restore old HL from (SP)
|
||||
ex (sp), ix ; restore old (SP) from IX
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
.error:
|
||||
@ -848,14 +860,14 @@ parseInstruction:
|
||||
ld (INS_CURARG2), a
|
||||
call readWord
|
||||
jr nz, .nomorearg
|
||||
ld ix, INS_CURARG1
|
||||
ld de, INS_CURARG1
|
||||
call processArg
|
||||
jr nz, .end ; A is set to error, Z is unset
|
||||
call readComma
|
||||
jr nz, .nomorearg
|
||||
call readWord
|
||||
jr nz, .badfmt
|
||||
ld ix, INS_CURARG2
|
||||
ld de, INS_CURARG2
|
||||
call processArg
|
||||
jr nz, .end ; A is set to error, Z is unset
|
||||
.nomorearg:
|
||||
|
@ -6,15 +6,9 @@
|
||||
* 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();
|
||||
@ -28,7 +22,6 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
emul_loop();
|
||||
if (m->cpu.R1.wr.HL)
|
||||
return m->cpu.R1.br.A;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,62 +0,0 @@
|
||||
; *** requirements ***
|
||||
; ascii.h
|
||||
; core
|
||||
; stdio
|
||||
; lib/ari
|
||||
; lib/fmt
|
||||
|
||||
testNum: .db 1
|
||||
|
||||
STDIO_PUTC:
|
||||
out (0), a
|
||||
cp a
|
||||
ret
|
||||
|
||||
STDIO_GETC:
|
||||
jp unsetZ
|
||||
|
||||
assertZ:
|
||||
ret z
|
||||
ld hl, .msg
|
||||
call printstr
|
||||
jp fail
|
||||
.msg:
|
||||
.db "Z not set", CR, LF, 0
|
||||
|
||||
assertNZ:
|
||||
ret nz
|
||||
ld hl, .msg
|
||||
call printstr
|
||||
jp fail
|
||||
.msg:
|
||||
.db "Z set", CR, LF, 0
|
||||
|
||||
; Assert that HL == DE
|
||||
assertEQW:
|
||||
ld a, h
|
||||
cp d
|
||||
jr nz, .fail
|
||||
ld a, l
|
||||
cp e
|
||||
ret z
|
||||
.fail:
|
||||
call printHexPair
|
||||
call printcrlf
|
||||
ex de, hl
|
||||
call printHexPair
|
||||
call printcrlf
|
||||
ld hl, .msg
|
||||
call printstr
|
||||
jp fail
|
||||
.msg:
|
||||
.db "HL != DE", CR, LF, 0
|
||||
|
||||
nexttest:
|
||||
ld a, (testNum)
|
||||
inc a
|
||||
ld (testNum), a
|
||||
ret
|
||||
|
||||
fail:
|
||||
ld a, (testNum)
|
||||
halt
|
@ -11,7 +11,7 @@ APPS="${BASE}/apps"
|
||||
|
||||
chk() {
|
||||
echo "Running test $1"
|
||||
if ! ${ZASM} "${KERNEL}" "${APPS}" common.asm < $1 | ${RUNBIN}; then
|
||||
if ! ${ZASM} "${KERNEL}" "${APPS}" < $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 test_*.asm; do
|
||||
for fn in *.asm; do
|
||||
chk "${fn}"
|
||||
done
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
jp test
|
||||
|
||||
.inc "ascii.h"
|
||||
.inc "core.asm"
|
||||
.inc "str.asm"
|
||||
.inc "lib/util.asm"
|
||||
@ -9,9 +8,6 @@ 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
|
||||
@ -59,21 +55,21 @@ testParseThruth:
|
||||
|
||||
.true:
|
||||
call parseTruth
|
||||
call assertZ
|
||||
jp nz, fail
|
||||
or a
|
||||
call assertNZ
|
||||
jp z, fail
|
||||
jp nexttest
|
||||
|
||||
.false:
|
||||
call parseTruth
|
||||
call assertZ
|
||||
jp nz, fail
|
||||
or a
|
||||
call assertZ
|
||||
jp nz, fail
|
||||
jp nexttest
|
||||
|
||||
.error:
|
||||
call parseTruth
|
||||
call assertNZ
|
||||
jp z, fail
|
||||
jp nexttest
|
||||
|
||||
.t1: .db "42", 0
|
||||
@ -92,4 +88,17 @@ testParseThruth:
|
||||
.f6: .db "2<=1", 0
|
||||
.e1: .db "foo", 0
|
||||
|
||||
STDIO_RAMSTART:
|
||||
testNum: .db 1
|
||||
|
||||
nexttest:
|
||||
ld a, (testNum)
|
||||
inc a
|
||||
ld (testNum), a
|
||||
ret
|
||||
|
||||
fail:
|
||||
ld a, (testNum)
|
||||
halt
|
||||
|
||||
; used as RAM
|
||||
sandbox:
|
||||
|
@ -5,14 +5,8 @@
|
||||
|
||||
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
|
||||
|
||||
@ -43,25 +37,37 @@ test:
|
||||
call nexttest
|
||||
|
||||
; Test that .equ can override label
|
||||
ld de, 0x42
|
||||
ld a, 0x42
|
||||
ld hl, dummyLabel
|
||||
call assertEQW
|
||||
cp l
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
; test that "@" is updated by a .org directive
|
||||
ld hl, AFTER_ORG
|
||||
ld de, 0x1234
|
||||
call assertEQW
|
||||
or a ; clear carry
|
||||
sbc hl, de
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
; test that AND affects the Z flag
|
||||
ld a, 0x69
|
||||
and 0x80
|
||||
call assertZ
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
; success
|
||||
xor a
|
||||
halt
|
||||
|
||||
STDIO_RAMSTART:
|
||||
nexttest:
|
||||
ld a, (testNum)
|
||||
inc a
|
||||
ld (testNum), a
|
||||
ret
|
||||
|
||||
fail:
|
||||
ld a, (testNum)
|
||||
halt
|
||||
|
||||
|
@ -9,12 +9,10 @@
|
||||
|
||||
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"
|
||||
@ -23,9 +21,6 @@ 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:
|
||||
@ -34,6 +29,8 @@ zasmIsFirstPass:
|
||||
zasmGetPC:
|
||||
ret
|
||||
|
||||
testNum: .db 1
|
||||
|
||||
s1: .db "2+2", 0
|
||||
s2: .db "0x4001+0x22", 0
|
||||
s3: .db "FOO+BAR", 0
|
||||
@ -47,22 +44,29 @@ 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
|
||||
call assertZ
|
||||
ld hl, 4
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
or a
|
||||
jp nz, fail
|
||||
ld a, l
|
||||
cp 4
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
ld hl, s2
|
||||
call parseExpr
|
||||
call assertZ
|
||||
ld hl, 0x4023
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
cp 0x40
|
||||
jp nz, fail
|
||||
ld a, l
|
||||
cp 0x23
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
; before the next test, let's set up FOO and BAR symbols
|
||||
@ -78,32 +82,54 @@ test:
|
||||
|
||||
ld hl, s3
|
||||
call parseExpr
|
||||
call assertZ
|
||||
ld hl, 0x4020
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
cp 0x40
|
||||
jp nz, fail
|
||||
ld a, l
|
||||
cp 0x20
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
ld hl, s4
|
||||
call parseExpr
|
||||
call assertZ
|
||||
ld hl, 0x60
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
or a
|
||||
jp nz, fail
|
||||
ld a, l
|
||||
cp 0x60
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
ld hl, s5
|
||||
call parseExpr
|
||||
call assertZ
|
||||
ld hl, 0x3ffd
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
cp 0x3f
|
||||
jp nz, fail
|
||||
ld a, l
|
||||
cp 0xfd
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
ld hl, s6
|
||||
call parseExpr
|
||||
call assertZ
|
||||
ld hl, 0x4080
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop hl
|
||||
ld a, h
|
||||
cp 0x40
|
||||
jp nz, fail
|
||||
ld a, l
|
||||
cp 0x80
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
; New-style tests
|
||||
call testParseExpr
|
||||
; success
|
||||
xor a
|
||||
halt
|
||||
@ -125,18 +151,20 @@ 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
|
||||
call assertZ
|
||||
ld l, (iy)
|
||||
ld h, (iy+1)
|
||||
call assertEQW
|
||||
jp nz, fail
|
||||
push ix \ pop de
|
||||
ld a, e
|
||||
cp (iy)
|
||||
jp nz, fail
|
||||
ld a, d
|
||||
cp (iy+1)
|
||||
jp nz, fail
|
||||
jp nexttest
|
||||
|
||||
.t1:
|
||||
@ -163,6 +191,13 @@ testParseExpr:
|
||||
.t8:
|
||||
.dw 0xffff
|
||||
.db "-1", 0
|
||||
.t9:
|
||||
.dw 10
|
||||
.db "2*3+4", 0
|
||||
|
||||
nexttest:
|
||||
ld a, (testNum)
|
||||
inc a
|
||||
ld (testNum), a
|
||||
ret
|
||||
|
||||
fail:
|
||||
ld a, (testNum)
|
||||
halt
|
||||
|
Loading…
Reference in New Issue
Block a user