zasm: have .fill generate an error on overflow

Can possibly avoid a lot of debugging pain.
This commit is contained in:
Virgil Dupras 2019-11-13 22:24:58 -05:00
parent 8d46895dd3
commit 82995eb346
3 changed files with 22 additions and 11 deletions

View File

@ -130,6 +130,11 @@ allowed. An included file cannot have an `.inc` directive.
offset. For example, if we want to place an instruction exactly at
byte 0x38, we would precede it with `.fill 0x38-$`.
The maximum value possible for `.fill` is `0xd000`. We do this to
avoid "overshoot" errors, that is, error where `$` is greater than
the offset you're trying to reach in an expression like `.fill X-$`
(such an expression overflows to `0xffff`).
**.org**: Sets the Program Counter to the value of the argument, an expression.
For example, a label being defined right after a `.org 0x400`, would
have a value of `0x400`. Does not do any filling. You have to do that

View File

@ -201,8 +201,11 @@ handleFIL:
jr nz, .badfmt
call parseExpr
jr nz, .badarg
push bc
push bc ; --> lvl 1
push ix \ pop bc
ld a, b
cp 0xd0
jr nc, .overflow
.loop:
ld a, b
or c
@ -214,19 +217,21 @@ handleFIL:
jr .loop
.loopend:
cp a ; ensure Z
pop bc
pop bc ; <-- lvl 1
ret
.ioError:
ld a, SHELL_ERR_IO_ERROR
jr .error
jp unsetZ
.badfmt:
ld a, ERR_BAD_FMT
jr .error
jp unsetZ
.badarg:
ld a, ERR_BAD_ARG
.error:
call unsetZ
ret
jp unsetZ
.overflow:
pop bc ; <-- lvl 1
ld a, ERR_OVFL
jp unsetZ
handleOUT:
push hl

View File

@ -54,6 +54,7 @@ chkerr ".inc" 19
chkerr ".inc foo" 19
chkerr "ld a, 0x100" 20
chkerr ".db 0x100" 20
chkerr $'nop \ nop \ nop\n.fill 2-$' 20
chkerr ".inc \"doesnotexist\"" 21
chkerr "foo:\\foo:" 22
chkoom