1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:08:05 +11:00

ed: add '.' and '$' support

This commit is contained in:
Virgil Dupras 2019-10-04 13:49:33 -04:00
parent 55be698f61
commit 8db1bdb245
3 changed files with 25 additions and 5 deletions

View File

@ -63,3 +63,7 @@ Addresses can be expressed relatively to the current line with `+` and `-`.
lines before current line and ending 2 lines after it`.
`+` alone means `+1`, `-` means `-1`.
`.` means current line. It can usually be ommitted. `p` is the same as `.p`.
`$` means the last line of the buffer.

View File

@ -7,8 +7,7 @@
.equ ABSOLUTE 0
; handles +, - and ".". For +, easy. For -, addr is negative. For ., it's 0.
.equ RELATIVE 1
.equ BOF 2
.equ EOF 3
.equ EOF 2
; *** Variables ***
@ -86,6 +85,10 @@ cmdParse:
jr z, .plusOrMinus
cp '-'
jr z, .plusOrMinus
cp '.'
jr z, .dot
cp '$'
jr z, .eof
call parseDecimalDigit
jr c, .notHandled
; straight number
@ -95,14 +98,22 @@ cmdParse:
ret nz
dec de ; from 1-based to 0-base
jr .end
.dot:
inc hl ; advance cmd cursor
; the rest is the same as .notHandled
.notHandled:
; something else. Something we don't handle. Our addr is therefore "."
; something else. It's probably our command. Our addr is therefore "."
ld a, RELATIVE
ld (ix), a
xor a ; sets Z
ld (ix+1), a
ld (ix+2), a
ret
.eof:
inc hl ; advance cmd cursor
ld a, EOF
ld (ix), a
ret ; Z set during earlier CP
.plusOrMinus:
push af ; preserve that + or -
ld a, RELATIVE

View File

@ -14,8 +14,7 @@
; That's on a resourceful UNIX system.
;
; That doubly linked list on the z80 would use 7 bytes per line (prev, next,
; offset, len), which is a bit much. Moreover, there's that whole "scratchpad
; being loaded in memory" thing that's a bit iffy.
; offset, len), which is a bit much.
;
; We sacrifice speed for memory usage by making that linked list into a simple
; array of pointers to line contents in scratchpad. This means that we
@ -159,6 +158,8 @@ edResolveAddr:
ld a, (ix)
cp RELATIVE
jr z, .relative
cp EOF
jr z, .eof
; absolute
ld l, (ix+1)
ld h, (ix+2)
@ -171,6 +172,10 @@ edResolveAddr:
add hl, de
pop de
ret
.eof:
ld hl, (BUF_LINECNT)
dec hl
ret
; Read absolute addr1 in HL and addr2 in DE. Also, check bounds and set Z if
; both addresses are within bounds, unset if not.