mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 18:10:55 +11:00
Compare commits
No commits in common. "ab578159b725de12eb3a2981d66e1dd106dc0b23" and "33c480a5dd7ae49310ff40b500118639b19fdb1d" have entirely different histories.
ab578159b7
...
33c480a5dd
@ -59,11 +59,8 @@ instrNames:
|
||||
.db "BST", 0
|
||||
.db "SBRC", 0
|
||||
.db "SBRS", 0
|
||||
.equ I_RCALL 42
|
||||
.db "RCALL", 0
|
||||
.db "RJMP", 0
|
||||
; no arg (from here, instrUpMasks2)
|
||||
.equ I_BREAK 44
|
||||
.equ I_BREAK 42
|
||||
.db "BREAK", 0
|
||||
.db "CLC", 0
|
||||
.db "CLH", 0
|
||||
@ -91,7 +88,7 @@ instrNames:
|
||||
.db "SLEEP", 0
|
||||
.db "WDR", 0
|
||||
; Rd(5)
|
||||
.equ I_ASR 70
|
||||
.equ I_ASR 68
|
||||
.db "ASR", 0
|
||||
.db "COM", 0
|
||||
.db "DEC", 0
|
||||
@ -140,9 +137,6 @@ instrUpMasks1:
|
||||
.db 0b11111010 ; BST
|
||||
.db 0b11111100 ; SBRC
|
||||
.db 0b11111110 ; SBRS
|
||||
; k(12): XXXXkkkk kkkkkkkk
|
||||
.db 0b11010000 ; RCALL
|
||||
.db 0b11000000 ; RJMP
|
||||
|
||||
; 16-bit constant masks associated with each instruction. In the same order as
|
||||
; in instrNames
|
||||
@ -237,35 +231,33 @@ parseInstruction:
|
||||
jr c, .spitRd5Rr5
|
||||
cp I_BLD
|
||||
jr c, .spitRdK8
|
||||
cp I_RCALL
|
||||
jr c, .spitRdBit
|
||||
cp I_BREAK
|
||||
jr c, .spitK12
|
||||
jr c, .spitRdBit
|
||||
cp I_ASR
|
||||
jr c, .spitNoArg
|
||||
; spitRd5
|
||||
ld ix, argSpecs ; 'R', 0
|
||||
call _parseArgs
|
||||
ld a, h
|
||||
call .readR5
|
||||
ret nz
|
||||
call .placeRd
|
||||
; continue to .spitNoArg
|
||||
.spitNoArg:
|
||||
call .getUp2
|
||||
jp .spit
|
||||
jr .spit
|
||||
|
||||
.spitRd5Rr5:
|
||||
ld ix, argSpecs+2 ; 'R', 'R'
|
||||
call _parseArgs
|
||||
call .readR5
|
||||
ret nz
|
||||
ld a, h
|
||||
call .placeRd
|
||||
ld a, l
|
||||
call readComma
|
||||
call .readR5
|
||||
ret nz
|
||||
push af ; --> lvl 1
|
||||
; let's start with the 4 lower bits
|
||||
and 0xf
|
||||
or c
|
||||
; We now have our LSB in A. Let's spit it now.
|
||||
call ioPutB
|
||||
ld a, l
|
||||
pop af ; <-- lvl 1
|
||||
; and now that last high bit, currently bit 4, which must become bit 1
|
||||
and 0b00010000
|
||||
rra \ rra \ rra
|
||||
@ -276,18 +268,24 @@ parseInstruction:
|
||||
jr .spitMSB
|
||||
|
||||
.spitRdK8:
|
||||
ld ix, argSpecs+6 ; 'r', 8
|
||||
call _parseArgs
|
||||
call .readR4
|
||||
ret nz
|
||||
ld a, h ; Rd
|
||||
call .placeRd
|
||||
ld a, l ; K
|
||||
call readComma
|
||||
call readWord
|
||||
call parseExpr
|
||||
ret nz
|
||||
ld a, c
|
||||
ld a, 0xff
|
||||
call .IX2A
|
||||
ret nz
|
||||
push af ; --> lvl 1
|
||||
; let's start with the 4 lower bits
|
||||
and 0xf
|
||||
or c
|
||||
; We now have our LSB in A. Let's spit it now.
|
||||
call ioPutB
|
||||
ld a, l
|
||||
pop af ; <-- lvl 1
|
||||
; and now those high 4 bits
|
||||
and 0xf0
|
||||
rra \ rra \ rra \ rra
|
||||
@ -296,47 +294,18 @@ parseInstruction:
|
||||
jr .spitMSB
|
||||
|
||||
.spitRdBit:
|
||||
ld ix, argSpecs+8 ; 'R', 'b'
|
||||
call _parseArgs
|
||||
call .readR5
|
||||
ret nz
|
||||
ld a, h
|
||||
call .placeRd
|
||||
or l
|
||||
call readComma
|
||||
ret nz
|
||||
call .readBit
|
||||
ret nz
|
||||
; LSB is in A and is ready to go
|
||||
call ioPutB
|
||||
call .getUp1
|
||||
jr .spitMSB
|
||||
|
||||
.spitK12:
|
||||
; Let's deal with the upcode constant before we destroy DE below
|
||||
call .getUp1
|
||||
ld b, (hl)
|
||||
call readWord
|
||||
call parseExpr
|
||||
ret nz
|
||||
push ix \ pop hl
|
||||
; We're doing the same dance as in _readk7. See comments there.
|
||||
ld de, 0xfff
|
||||
add hl, de
|
||||
jp c, unsetZ ; Carry? number is way too high.
|
||||
ex de, hl
|
||||
call zasmGetPC ; --> HL
|
||||
inc hl \ inc hl
|
||||
ex de, hl
|
||||
sbc hl, de
|
||||
jp c, unsetZ ; Carry? error
|
||||
ld de, 0xfff
|
||||
sbc hl, de
|
||||
; We're within bounds! Now, divide by 2
|
||||
ld a, l
|
||||
rr h \ rra
|
||||
; LSB in A, spit
|
||||
call ioPutB
|
||||
ld a, h
|
||||
and 0xf
|
||||
or b
|
||||
jp ioPutB
|
||||
|
||||
.spit:
|
||||
; LSB is spit *before* MSB
|
||||
inc hl
|
||||
@ -369,24 +338,39 @@ parseInstruction:
|
||||
inc b
|
||||
.skip1:
|
||||
and 0b111
|
||||
ld c, a ; can't store in H now, (HL) is used
|
||||
ld ix, argSpecs+4 ; 7, 0
|
||||
call _parseArgs
|
||||
ret nz
|
||||
; ok, now we can
|
||||
ld l, h ; k in L
|
||||
ld h, c ; bit in H
|
||||
ld c, a
|
||||
.spitBR2:
|
||||
; bit in H, k in L.
|
||||
; Our value in L is the number of relative *bytes*. The value we put
|
||||
; there is the number of words. Therefore, relevant bits are 7:1
|
||||
call readWord
|
||||
ret nz
|
||||
call parseExpr
|
||||
ret nz
|
||||
; 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)
|
||||
push ix \ pop hl
|
||||
ld de, 0x7f
|
||||
add hl, de ; Carry cleared
|
||||
ex de, hl
|
||||
call zasmGetPC ; --> HL
|
||||
; The relative value is actually not relative to current PC, but to
|
||||
; PC after the execution of this branching op. Increase HL by 2.
|
||||
inc hl \ inc hl
|
||||
ex de, hl
|
||||
sbc hl, de
|
||||
jp c, unsetZ ; Carry? error
|
||||
ld de, 0x7f
|
||||
sbc hl, de
|
||||
; We're within bounds! However, our value in L is the number of
|
||||
; relative *bytes*. The value we put there is the number of words.
|
||||
; Thefore, relevant bits are 7:1
|
||||
ld a, l
|
||||
sla a \ rl b
|
||||
sla a \ rl b
|
||||
and 0b11111000
|
||||
; k is now shifted by 3, two of those bits being in B. Let's OR A and
|
||||
; H and we have our LSB ready to go.
|
||||
or h
|
||||
; C and we have our LSB ready to go.
|
||||
or c
|
||||
call ioPutB
|
||||
; Good! MSB now. B is already good to go.
|
||||
ld a, b
|
||||
@ -396,10 +380,10 @@ parseInstruction:
|
||||
; upcode becomes 0b111101
|
||||
inc b
|
||||
.rdBRBS:
|
||||
ld ix, argSpecs+10 ; bit + k(7)
|
||||
call _parseArgs
|
||||
call .readBit
|
||||
ret nz
|
||||
call readComma
|
||||
ret nz
|
||||
; bit in H, k in L.
|
||||
jr .spitBR2
|
||||
|
||||
; local routines
|
||||
@ -426,141 +410,8 @@ parseInstruction:
|
||||
ld hl, instrUpMasks2
|
||||
jp addHL
|
||||
|
||||
; Argspecs: two bytes describing the arguments that are accepted. Possible
|
||||
; values:
|
||||
;
|
||||
; 0 - None
|
||||
; 7 - a k(7) address, relative to PC, *in bytes* (divide by 2 before writing)
|
||||
; 8 - a K(8) value
|
||||
; 'a' - A 5-bit I/O port value
|
||||
; 'A' - A 6-bit I/O port value
|
||||
; 'b' - a 0-7 bit value
|
||||
; 'R' - an r5 value: r0-r31
|
||||
; 'r' - an r4 value: r16-r31
|
||||
;
|
||||
; All arguments accept expressions, even 'r' ones: in 'r' args, we start by
|
||||
; looking if the arg starts with 'r' or 'R'. If yes, it's a simple 'rXX' value,
|
||||
; if not, we try parsing it as an expression and validate that it falls in the
|
||||
; correct 0-31 or 16-31 range
|
||||
argSpecs:
|
||||
.db 'R', 0 ; Rd(5)
|
||||
.db 'R', 'R' ; Rd(5) + Rr(5)
|
||||
.db 7, 0 ; k(7)
|
||||
.db 'r', 8 ; Rd(4) + K(8)
|
||||
.db 'R', 'b' ; Rd(5) + bit
|
||||
.db 'b', 7 ; bit + k(7)
|
||||
|
||||
; Parse arguments in (HL) according to specs in IX
|
||||
; Puts the results in HL (which is not needed anymore after the parsing).
|
||||
; First arg in H, second in L.
|
||||
; This routine is not used in all cases, some ops don't fit this pattern well
|
||||
; and thus parse their args themselves.
|
||||
; Z for success.
|
||||
_parseArgs:
|
||||
; For the duration of the routine, our final value will be in DE, and
|
||||
; then placed in HL at the end.
|
||||
push de
|
||||
call readWord
|
||||
jr nz, .end
|
||||
ld a, (ix)
|
||||
call .parse
|
||||
jr nz, .end
|
||||
ld d, a
|
||||
ld a, (ix+1)
|
||||
or a
|
||||
jr z, .end ; no arg
|
||||
call readComma
|
||||
jr nz, .end
|
||||
call readWord
|
||||
jr nz, .end
|
||||
ld a, (ix+1)
|
||||
call .parse
|
||||
jr nz, .end
|
||||
; we're done with (HL) now
|
||||
ld l, a
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
ld h, d
|
||||
pop de
|
||||
ret
|
||||
|
||||
; Parse a single arg specified in A and returns its value in A
|
||||
; Z for success
|
||||
.parse:
|
||||
cp 'R'
|
||||
jr z, _readR5
|
||||
cp 'r'
|
||||
jr z, _readR4
|
||||
cp 'b'
|
||||
jr z, _readBit
|
||||
cp 7
|
||||
jr z, _readk7
|
||||
cp 8
|
||||
jr z, _readK8
|
||||
ret ; something's wrong
|
||||
|
||||
_readBit:
|
||||
push ix
|
||||
call parseExpr
|
||||
ld a, 7
|
||||
call _IX2A
|
||||
jr nz, .end
|
||||
or c
|
||||
ld c, a
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop ix
|
||||
ret
|
||||
|
||||
_readk7:
|
||||
push hl
|
||||
push de
|
||||
push ix
|
||||
call parseExpr
|
||||
jr nz, .end
|
||||
; 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)
|
||||
push ix \ pop hl
|
||||
ld de, 0x7f
|
||||
add hl, de ; Carry cleared
|
||||
ex de, hl
|
||||
call zasmGetPC ; --> HL
|
||||
; The relative value is actually not relative to current PC, but to
|
||||
; PC after the execution of this branching op. Increase HL by 2.
|
||||
inc hl \ inc hl
|
||||
ex de, hl
|
||||
sbc hl, de
|
||||
jp c, .err ; Carry? error
|
||||
ld de, 0x7f
|
||||
sbc hl, de
|
||||
; We're within bounds! However, our value in L is the number of
|
||||
; relative *bytes*.
|
||||
ld a, l
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop ix
|
||||
pop de
|
||||
pop hl
|
||||
ret
|
||||
.err:
|
||||
call unsetZ
|
||||
jr .end
|
||||
|
||||
_readK8:
|
||||
push ix
|
||||
call parseExpr
|
||||
jr nz, .end
|
||||
ld a, 0xff
|
||||
call _IX2A
|
||||
.end:
|
||||
pop ix
|
||||
ret
|
||||
|
||||
_readR4:
|
||||
call _readR5
|
||||
.readR4:
|
||||
call .readR5
|
||||
ret nz
|
||||
; has to be in the 16-31 range
|
||||
sub 0x10
|
||||
@ -570,25 +421,34 @@ _readR4:
|
||||
|
||||
; read a rXX argument and return register number in A.
|
||||
; Set Z for success.
|
||||
_readR5:
|
||||
push ix
|
||||
.readR5:
|
||||
call readWord
|
||||
ld a, (hl)
|
||||
call upcase
|
||||
cp 'R'
|
||||
jr nz, .end ; not a register
|
||||
ret nz ; not a register
|
||||
inc hl
|
||||
call parseDecimal
|
||||
jr nz, .end
|
||||
ret nz
|
||||
ld a, 31
|
||||
call _IX2A
|
||||
.end:
|
||||
pop ix
|
||||
jr .IX2A
|
||||
|
||||
.readBit:
|
||||
call readWord
|
||||
ret nz
|
||||
call parseExpr
|
||||
ld a, 7
|
||||
call .IX2A
|
||||
ret nz
|
||||
or c
|
||||
ld c, a
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
||||
; Put IX's LSB into A and, additionally, ensure that the new value is <=
|
||||
; than what was previously in A.
|
||||
; Z for success.
|
||||
_IX2A:
|
||||
.IX2A:
|
||||
push ix \ pop hl
|
||||
cp l
|
||||
jp c, unsetZ ; A < L
|
||||
@ -598,5 +458,3 @@ _IX2A:
|
||||
ld a, l
|
||||
; Z set from "or a"
|
||||
ret
|
||||
|
||||
|
||||
|
@ -80,10 +80,8 @@ ioGetB:
|
||||
call ioInInclude
|
||||
jr z, .normalmode
|
||||
; We're in "include mode", read from FS
|
||||
push ix ; --> lvl 1
|
||||
ld ix, IO_INCLUDE_BLK
|
||||
call _blkGetB
|
||||
pop ix ; <-- lvl 1
|
||||
jr nz, .includeEOF
|
||||
cp 0x0a ; newline
|
||||
ret nz ; not newline? nothing to do
|
||||
@ -113,11 +111,9 @@ ioGetB:
|
||||
; continue on to "normal" reading. We don't want to return our zero
|
||||
.normalmode:
|
||||
; normal mode, read from IN stream
|
||||
push ix ; --> lvl 1
|
||||
ld ix, IO_IN_BLK
|
||||
call _blkGetB
|
||||
pop ix ; <-- lvl 1
|
||||
cp LF ; newline
|
||||
cp 0x0a ; newline
|
||||
ret nz ; not newline? return
|
||||
; inc current lineno
|
||||
push hl
|
||||
@ -134,6 +130,10 @@ ioGetB:
|
||||
pop af
|
||||
ret
|
||||
|
||||
_callIX:
|
||||
jp (ix)
|
||||
ret
|
||||
|
||||
; Put back non-zero character A into the "ioGetB stack". The next ioGetB call,
|
||||
; instead of reading from IO_IN_BLK, will return that character. That's the
|
||||
; easiest way I found to handle the readWord/gotoNextLine problem.
|
||||
|
@ -155,7 +155,8 @@ readComma:
|
||||
cp ','
|
||||
ret z
|
||||
call ioPutBack
|
||||
jp unsetZ
|
||||
call unsetZ
|
||||
ret
|
||||
|
||||
; Read ioGetB until we reach the beginning of next line, skipping comments if
|
||||
; necessary. This skips all whitespace, \n, \r, comments until we reach the
|
||||
|
@ -9,6 +9,3 @@ bar:
|
||||
brbs 6, foo
|
||||
ori r22, 0x34+4
|
||||
sbrs r1, 3
|
||||
rjmp foo
|
||||
rcall baz
|
||||
baz:
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user