1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-26 03:48:07 +11:00

Compare commits

..

No commits in common. "cca3157c66456ca8bd7bec57673f6a871e8d5701" and "9fb1467ee53f458131f5f04b3c135afc48c6887f" have entirely different histories.

11 changed files with 27 additions and 353 deletions

View File

@ -152,11 +152,4 @@ allowed. An included file cannot have an `.inc` directive.
in the argument in the currently active filesystem and outputs its
contents directly.
## Undocumented instructions
`zasm` doesn't support undocumented instructions such as the ones that involve
using `IX` and `IY` as 8-bit registers. We used to support them, but because
this makes our code incompatible with Z80-compatible CPUs such as the Z180, we
prefer to avoid these in our code.
[libz80]: https://github.com/ggambetta/libz80

View File

@ -109,7 +109,7 @@ getInstID:
ret
; Parse the string at (HL) and check if it starts with IX+, IY+, IX- or IY-.
; Sets Z if yes, unset if no. On success, A contains either '+' or '-'.
; Sets Z if yes, unset if no.
parseIXY:
push hl
ld a, (hl)
@ -180,15 +180,13 @@ parseArg:
ld a, 'N'
jr .end
.withParens:
ld b, 0 ; make sure it doesn't hold '-'
ld c, 'M' ; C holds the argspec type until we reach
; .numberInParens
; We have parens. First, let's see if we have a (IX+d) type of arg.
call parseIXY
jr nz, .parseNumberInParens ; not I{X,Y}. just parse number.
; We have IX+/IY+/IX-/IY-.
; A contains either '+' or '-'. Save it for later, in B.
ld b, a
; note: the "-" part isn't supported yet.
inc hl ; (HL) now points to X or Y
ld a, (hl)
call upcase
@ -204,22 +202,6 @@ parseArg:
call .maybeParseExpr
jr nz, .nomatch
; 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, .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.
; HL isn't needed anymore and can be destroyed.
push ix \ pop hl
ld a, l
neg
ld l, a
push hl \ pop ix
.dontNegateIX:
ld a, c ; M, x, or y
jr .end
.nomatch:

View File

@ -110,14 +110,12 @@ symRegister:
; Is our new name going to make us go out of bounds?
push hl ; --> lvl 2
push de ; --> lvl 3
ld d, 0
ld e, c
add hl, de ; if carry set here, sbc will carry too
ld e, (ix+2) ; DE --> pointer to record list, which is also
ld d, (ix+3) ; the end of names pool
; DE --> names end
sbc hl, de ; compares hl and de destructively
ld a, c
call addHL
call cpHLDE
pop de ; <-- lvl 3
pop hl ; <-- lvl 2
jr nc, .outOfMemory ; HL >= DE
@ -192,15 +190,9 @@ _symFind:
jr z, .end ; match! Z already set, IY and HL placed.
.skip:
; ok, next!
push de ; --> lvl 1
ld de, 0x0003
add iy, de ; faster and shorter than three inc's
ld e, (iy-3) ; offset is also compulsory, so no extra bytes used
; (iy-3) holds the name length of the string just processed
add hl, de ; advance HL by (iy-3) characters
pop de ; <-- lvl 1
ld a, (iy) ; name len again
call addHL ; advance HL by A chars
inc iy \ inc iy \ inc iy
djnz .loop
; end of the chain, nothing found
.nothing:

View File

@ -53,25 +53,28 @@ intoIX:
ret
; add the value of A into HL
; affects carry flag according to the 16-bit addition, Z, S and P untouched.
addHL:
push de
ld d, 0
ld e, a
add hl, de
pop de
push af
add a, l
jr nc, .end ; no carry? skip inc
inc h
.end:
ld l, a
pop af
ret
; subtract the value of A from HL
; affects flags according to the 16-bit subtraction.
subHL:
push de
ld d, 0
ld e, a
or a ;reset carry flag
sbc hl, de ;There is no 'sub hl, de', so we must use sbc
pop de
push af
; To avoid having to swap L and A, we sub "backwards", that is, we add
; a NEGated value. This means that the carry flag is inverted
neg
add a, l
jr c, .end ; if carry, no carry. :)
dec h
.end:
ld l, a
pop af
ret
; Compare HL with DE and sets Z and C in the same way as a regular cp X where

Binary file not shown.

Binary file not shown.

View File

@ -48,22 +48,14 @@ ADD IY, IY
ADD IY, SP
ADD A, (IX)
ADD A, (IX+1)
ADD A, (IX-1)
ADD A, (IX+10)
ADD A, (IX-10)
ADD A, (IX+100)
ADD A, (IX-100)
ADD A, (IX+127)
ADD A, (IX-127)
ADD A, (IY)
ADD A, (IY+1)
ADD A, (IY-1)
ADD A, (IY+10)
ADD A, (IY-10)
ADD A, (IY+100)
ADD A, (IY-100)
ADD A, (IY+127)
ADD A, (IY-127)
AND (HL)
AND B
AND C
@ -81,78 +73,46 @@ AND 32
AND 64
AND 128
AND (IX+1)
AND (IX-1)
AND (IX+10)
AND (IX-10)
AND (IX+100)
AND (IX-100)
AND (IX+127)
AND (IX-127)
AND (IY+1)
AND (IY-1)
AND (IY+10)
AND (IY-10)
AND (IY+100)
AND (IY-100)
AND (IY+127)
AND (IY-127)
BIT 1, (HL)
BIT 2, (HL)
BIT 4, (HL)
BIT 1, (IX)
BIT 1, (IX+1)
BIT 1, (IX-1)
BIT 1, (IX+10)
BIT 1, (IX-10)
BIT 1, (IX+100)
BIT 1, (IX-100)
BIT 1, (IX+127)
BIT 1, (IX-127)
BIT 2, (IX)
BIT 2, (IX+1)
BIT 2, (IX-1)
BIT 2, (IX+10)
BIT 2, (IX-10)
BIT 2, (IX+100)
BIT 2, (IX-100)
BIT 2, (IX+127)
BIT 2, (IX-127)
BIT 4, (IX)
BIT 4, (IX+1)
BIT 4, (IX-1)
BIT 4, (IX+10)
BIT 4, (IX-10)
BIT 4, (IX+100)
BIT 4, (IX-100)
BIT 4, (IX+127)
BIT 4, (IX-127)
BIT 1, (IY)
BIT 1, (IY+1)
BIT 1, (IY-1)
BIT 1, (IY+10)
BIT 1, (IY-10)
BIT 1, (IY+100)
BIT 1, (IY-100)
BIT 1, (IY+127)
BIT 1, (IY-127)
BIT 2, (IY)
BIT 2, (IY+1)
BIT 2, (IY-1)
BIT 2, (IY+10)
BIT 2, (IY-10)
BIT 2, (IY+100)
BIT 2, (IY-100)
BIT 2, (IY+127)
BIT 2, (IY-127)
BIT 4, (IY)
BIT 4, (IY+1)
BIT 4, (IY-1)
BIT 4, (IY+10)
BIT 4, (IY-10)
BIT 4, (IY+100)
BIT 4, (IY-100)
BIT 4, (IY+127)
BIT 4, (IY-127)
BIT 1, B
BIT 1, C
BIT 1, D
@ -337,22 +297,14 @@ CP 64
CP 128
CP (IX)
CP (IX+1)
CP (IX-1)
CP (IX+10)
CP (IX-10)
CP (IX+100)
CP (IX-100)
CP (IX+127)
CP (IX-127)
CP (IY)
CP (IY+1)
CP (IY-1)
CP (IY+10)
CP (IY-10)
CP (IY+100)
CP (IY-100)
CP (IY+127)
CP (IY-127)
CPD
CPDR
CPI
@ -363,23 +315,15 @@ DEC (HL)
DEC IX
DEC (IX)
DEC (IX+1)
DEC (IX-1)
DEC (IX+10)
DEC (IX-10)
DEC (IX+100)
DEC (IX-100)
DEC (IX+127)
DEC (IX-127)
DEC IY
DEC (IY)
DEC (IY+1)
DEC (IY-1)
DEC (IY+10)
DEC (IY-10)
DEC (IY+100)
DEC (IY-100)
DEC (IY+127)
DEC (IY-127)
DEC B
DEC C
DEC D
@ -436,23 +380,15 @@ INC (HL)
INC IX
INC (IX)
INC (IX+1)
INC (IX-1)
INC (IX+10)
INC (IX-10)
INC (IX+100)
INC (IX-100)
INC (IX+127)
INC (IX-127)
INC IY
INC (IY)
INC (IY+1)
INC (IY-1)
INC (IY+10)
INC (IY-10)
INC (IY+100)
INC (IY-100)
INC (IY+127)
INC (IY-127)
INC B
INC C
INC D
@ -1189,14 +1125,6 @@ LD (IX+1), 16
LD (IX+1), 32
LD (IX+1), 64
LD (IX+1), 128
LD (IX-1), 1
LD (IX-1), 2
LD (IX-1), 4
LD (IX-1), 8
LD (IX-1), 16
LD (IX-1), 32
LD (IX-1), 64
LD (IX-1), 128
LD (IX+10), 1
LD (IX+10), 2
LD (IX+10), 4
@ -1205,14 +1133,6 @@ LD (IX+10), 16
LD (IX+10), 32
LD (IX+10), 64
LD (IX+10), 128
LD (IX-10), 1
LD (IX-10), 2
LD (IX-10), 4
LD (IX-10), 8
LD (IX-10), 16
LD (IX-10), 32
LD (IX-10), 64
LD (IX-10), 128
LD (IX+100), 1
LD (IX+100), 2
LD (IX+100), 4
@ -1221,14 +1141,6 @@ LD (IX+100), 16
LD (IX+100), 32
LD (IX+100), 64
LD (IX+100), 128
LD (IX-100), 1
LD (IX-100), 2
LD (IX-100), 4
LD (IX-100), 8
LD (IX-100), 16
LD (IX-100), 32
LD (IX-100), 64
LD (IX-100), 128
LD (IX+127), 1
LD (IX+127), 2
LD (IX+127), 4
@ -1237,14 +1149,6 @@ LD (IX+127), 16
LD (IX+127), 32
LD (IX+127), 64
LD (IX+127), 128
LD (IX-127), 1
LD (IX-127), 2
LD (IX-127), 4
LD (IX-127), 8
LD (IX-127), 16
LD (IX-127), 32
LD (IX-127), 64
LD (IX-127), 128
LD (IY), 1
LD (IY), 2
LD (IY), 4
@ -1261,14 +1165,6 @@ LD (IY+1), 16
LD (IY+1), 32
LD (IY+1), 64
LD (IY+1), 128
LD (IY-1), 1
LD (IY-1), 2
LD (IY-1), 4
LD (IY-1), 8
LD (IY-1), 16
LD (IY-1), 32
LD (IY-1), 64
LD (IY-1), 128
LD (IY+10), 1
LD (IY+10), 2
LD (IY+10), 4
@ -1277,14 +1173,6 @@ LD (IY+10), 16
LD (IY+10), 32
LD (IY+10), 64
LD (IY+10), 128
LD (IY-10), 1
LD (IY-10), 2
LD (IY-10), 4
LD (IY-10), 8
LD (IY-10), 16
LD (IY-10), 32
LD (IY-10), 64
LD (IY-10), 128
LD (IY+100), 1
LD (IY+100), 2
LD (IY+100), 4
@ -1293,14 +1181,6 @@ LD (IY+100), 16
LD (IY+100), 32
LD (IY+100), 64
LD (IY+100), 128
LD (IY-100), 1
LD (IY-100), 2
LD (IY-100), 4
LD (IY-100), 8
LD (IY-100), 16
LD (IY-100), 32
LD (IY-100), 64
LD (IY-100), 128
LD (IY+127), 1
LD (IY+127), 2
LD (IY+127), 4
@ -1309,14 +1189,6 @@ LD (IY+127), 16
LD (IY+127), 32
LD (IY+127), 64
LD (IY+127), 128
LD (IY-127), 1
LD (IY-127), 2
LD (IY-127), 4
LD (IY-127), 8
LD (IY-127), 16
LD (IY-127), 32
LD (IY-127), 64
LD (IY-127), 128
LD (IX), B
LD (IX), C
LD (IX), D
@ -1331,13 +1203,6 @@ LD (IX+1), E
LD (IX+1), H
LD (IX+1), L
LD (IX+1), A
LD (IX-1), B
LD (IX-1), C
LD (IX-1), D
LD (IX-1), E
LD (IX-1), H
LD (IX-1), L
LD (IX-1), A
LD (IX+10), B
LD (IX+10), C
LD (IX+10), D
@ -1345,13 +1210,6 @@ LD (IX+10), E
LD (IX+10), H
LD (IX+10), L
LD (IX+10), A
LD (IX-10), B
LD (IX-10), C
LD (IX-10), D
LD (IX-10), E
LD (IX-10), H
LD (IX-10), L
LD (IX-10), A
LD (IX+100), B
LD (IX+100), C
LD (IX+100), D
@ -1359,13 +1217,6 @@ LD (IX+100), E
LD (IX+100), H
LD (IX+100), L
LD (IX+100), A
LD (IX-100), B
LD (IX-100), C
LD (IX-100), D
LD (IX-100), E
LD (IX-100), H
LD (IX-100), L
LD (IX-100), A
LD (IX+127), B
LD (IX+127), C
LD (IX+127), D
@ -1373,13 +1224,6 @@ LD (IX+127), E
LD (IX+127), H
LD (IX+127), L
LD (IX+127), A
LD (IX-127), B
LD (IX-127), C
LD (IX-127), D
LD (IX-127), E
LD (IX-127), H
LD (IX-127), L
LD (IX-127), A
LD (IY), B
LD (IY), C
LD (IY), D
@ -1394,13 +1238,6 @@ LD (IY+1), E
LD (IY+1), H
LD (IY+1), L
LD (IY+1), A
LD (IY-1), B
LD (IY-1), C
LD (IY-1), D
LD (IY-1), E
LD (IY-1), H
LD (IY-1), L
LD (IY-1), A
LD (IY+10), B
LD (IY+10), C
LD (IY+10), D
@ -1408,13 +1245,6 @@ LD (IY+10), E
LD (IY+10), H
LD (IY+10), L
LD (IY+10), A
LD (IY-10), B
LD (IY-10), C
LD (IY-10), D
LD (IY-10), E
LD (IY-10), H
LD (IY-10), L
LD (IY-10), A
LD (IY+100), B
LD (IY+100), C
LD (IY+100), D
@ -1422,13 +1252,6 @@ LD (IY+100), E
LD (IY+100), H
LD (IY+100), L
LD (IY+100), A
LD (IY-100), B
LD (IY-100), C
LD (IY-100), D
LD (IY-100), E
LD (IY-100), H
LD (IY-100), L
LD (IY-100), A
LD (IY+127), B
LD (IY+127), C
LD (IY+127), D
@ -1436,139 +1259,76 @@ LD (IY+127), E
LD (IY+127), H
LD (IY+127), L
LD (IY+127), A
LD (IY-127), B
LD (IY-127), C
LD (IY-127), D
LD (IY-127), E
LD (IY-127), H
LD (IY-127), L
LD (IY-127), A
LD B, (IX)
LD B, (IX+1)
LD B, (IX-1)
LD B, (IX+10)
LD B, (IX-10)
LD B, (IX+100)
LD B, (IX-100)
LD B, (IX+127)
LD B, (IX-127)
LD C, (IX)
LD C, (IX+1)
LD C, (IX-1)
LD C, (IX+10)
LD C, (IX-10)
LD C, (IX+100)
LD C, (IX-100)
LD C, (IX+127)
LD C, (IX-127)
LD D, (IX)
LD D, (IX+1)
LD D, (IX-1)
LD D, (IX+10)
LD D, (IX-10)
LD D, (IX+100)
LD D, (IX-100)
LD D, (IX+127)
LD D, (IX-127)
LD E, (IX)
LD E, (IX+1)
LD E, (IX-1)
LD E, (IX+10)
LD E, (IX-10)
LD E, (IX+100)
LD E, (IX-100)
LD E, (IX+127)
LD E, (IX-127)
LD H, (IX)
LD H, (IX+1)
LD H, (IX-1)
LD H, (IX+10)
LD H, (IX-10)
LD H, (IX+100)
LD H, (IX-100)
LD H, (IX+127)
LD H, (IX-127)
LD L, (IX)
LD L, (IX+1)
LD L, (IX-1)
LD L, (IX+10)
LD L, (IX-10)
LD L, (IX+100)
LD L, (IX-100)
LD L, (IX+127)
LD L, (IX-127)
LD A, (IX)
LD A, (IX+1)
LD A, (IX-1)
LD A, (IX+10)
LD A, (IX-10)
LD A, (IX+100)
LD A, (IX-100)
LD A, (IX+127)
LD A, (IX-127)
LD B, (IY)
LD B, (IY+1)
LD B, (IY-1)
LD B, (IY+10)
LD B, (IY-10)
LD B, (IY+100)
LD B, (IY-100)
LD B, (IY+127)
LD B, (IY-127)
LD C, (IY)
LD C, (IY+1)
LD C, (IY-1)
LD C, (IY+10)
LD C, (IY-10)
LD C, (IY+100)
LD C, (IY-100)
LD C, (IY+127)
LD C, (IY-127)
LD D, (IY)
LD D, (IY+1)
LD D, (IY-1)
LD D, (IY+10)
LD D, (IY-10)
LD D, (IY+100)
LD D, (IY-100)
LD D, (IY+127)
LD D, (IY-127)
LD E, (IY)
LD E, (IY+1)
LD E, (IY-1)
LD E, (IY+10)
LD E, (IY-10)
LD E, (IY+100)
LD E, (IY-100)
LD E, (IY+127)
LD E, (IY-127)
LD H, (IY)
LD H, (IY+1)
LD H, (IY-1)
LD H, (IY+10)
LD H, (IY-10)
LD H, (IY+100)
LD H, (IY-100)
LD H, (IY+127)
LD H, (IY-127)
LD L, (IY)
LD L, (IY+1)
LD L, (IY-1)
LD L, (IY+10)
LD L, (IY-10)
LD L, (IY+100)
LD L, (IY-100)
LD L, (IY+127)
LD L, (IY-127)
LD A, (IY)
LD A, (IY+1)
LD A, (IY-1)
LD A, (IY+10)
LD A, (IY-10)
LD A, (IY+100)
LD A, (IY-100)
LD A, (IY+127)
LD A, (IY-127)
LDD
LDDR
LDI
@ -1593,22 +1353,14 @@ OR 64
OR 128
OR (IX)
OR (IX+1)
OR (IX-1)
OR (IX+10)
OR (IX-10)
OR (IX+100)
OR (IX-100)
OR (IX+127)
OR (IX-127)
OR (IY)
OR (IY+1)
OR (IY-1)
OR (IY+10)
OR (IY-10)
OR (IY+100)
OR (IY-100)
OR (IY+127)
OR (IY-127)
OTDR
OTIR
OUT (1), A
@ -1643,58 +1395,34 @@ RES 2, (HL)
RES 4, (HL)
RES 1, (IX)
RES 1, (IX+1)
RES 1, (IX-1)
RES 1, (IX+10)
RES 1, (IX-10)
RES 1, (IX+100)
RES 1, (IX-100)
RES 1, (IX+127)
RES 1, (IX-127)
RES 2, (IX)
RES 2, (IX+1)
RES 2, (IX-1)
RES 2, (IX+10)
RES 2, (IX-10)
RES 2, (IX+100)
RES 2, (IX-100)
RES 2, (IX+127)
RES 2, (IX-127)
RES 4, (IX)
RES 4, (IX+1)
RES 4, (IX-1)
RES 4, (IX+10)
RES 4, (IX-10)
RES 4, (IX+100)
RES 4, (IX-100)
RES 4, (IX+127)
RES 4, (IX-127)
RES 1, (IY)
RES 1, (IY+1)
RES 1, (IY-1)
RES 1, (IY+10)
RES 1, (IY-10)
RES 1, (IY+100)
RES 1, (IY-100)
RES 1, (IY+127)
RES 1, (IY-127)
RES 2, (IY)
RES 2, (IY+1)
RES 2, (IY-1)
RES 2, (IY+10)
RES 2, (IY-10)
RES 2, (IY+100)
RES 2, (IY-100)
RES 2, (IY+127)
RES 2, (IY-127)
RES 4, (IY)
RES 4, (IY+1)
RES 4, (IY-1)
RES 4, (IY+10)
RES 4, (IY-10)
RES 4, (IY+100)
RES 4, (IY-100)
RES 4, (IY+127)
RES 4, (IY-127)
RES 1, B
RES 1, C
RES 1, D
@ -1777,58 +1505,34 @@ SET 2, (HL)
SET 4, (HL)
SET 1, (IX)
SET 1, (IX+1)
SET 1, (IX-1)
SET 1, (IX+10)
SET 1, (IX-10)
SET 1, (IX+100)
SET 1, (IX-100)
SET 1, (IX+127)
SET 1, (IX-127)
SET 2, (IX)
SET 2, (IX+1)
SET 2, (IX-1)
SET 2, (IX+10)
SET 2, (IX-10)
SET 2, (IX+100)
SET 2, (IX-100)
SET 2, (IX+127)
SET 2, (IX-127)
SET 4, (IX)
SET 4, (IX+1)
SET 4, (IX-1)
SET 4, (IX+10)
SET 4, (IX-10)
SET 4, (IX+100)
SET 4, (IX-100)
SET 4, (IX+127)
SET 4, (IX-127)
SET 1, (IY)
SET 1, (IY+1)
SET 1, (IY-1)
SET 1, (IY+10)
SET 1, (IY-10)
SET 1, (IY+100)
SET 1, (IY-100)
SET 1, (IY+127)
SET 1, (IY-127)
SET 2, (IY)
SET 2, (IY+1)
SET 2, (IY-1)
SET 2, (IY+10)
SET 2, (IY-10)
SET 2, (IY+100)
SET 2, (IY-100)
SET 2, (IY+127)
SET 2, (IY-127)
SET 4, (IY)
SET 4, (IY+1)
SET 4, (IY-1)
SET 4, (IY+10)
SET 4, (IY-10)
SET 4, (IY+100)
SET 4, (IY-100)
SET 4, (IY+127)
SET 4, (IY-127)
SET 1, B
SET 1, C
SET 1, D

View File

@ -103,7 +103,7 @@ def genargs(argspec):
argspec = argspec.upper()
for n in [1, 10, 100, 127]:
result.append(f"(I{argspec}+{n})")
result.append(f"(I{argspec}-{n})")
# TODO: support minus
return result
if argspec in argspecTbl:
return [argspecTbl[argspec]]

View File

@ -17,7 +17,7 @@ label2: .dw 0x42
ld ix, 1234
ld iy, 2345
ld (ix+1), l
ld l, (ix-1)
ld l, (ix+1)
ld hl, 0x100
.equ baz 0x20
; accept space before comma

Binary file not shown.