1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-24 01:58:06 +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`. lines before current line and ending 2 lines after it`.
`+` alone means `+1`, `-` means `-1`. `+` 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 .equ ABSOLUTE 0
; handles +, - and ".". For +, easy. For -, addr is negative. For ., it's 0. ; handles +, - and ".". For +, easy. For -, addr is negative. For ., it's 0.
.equ RELATIVE 1 .equ RELATIVE 1
.equ BOF 2 .equ EOF 2
.equ EOF 3
; *** Variables *** ; *** Variables ***
@ -86,6 +85,10 @@ cmdParse:
jr z, .plusOrMinus jr z, .plusOrMinus
cp '-' cp '-'
jr z, .plusOrMinus jr z, .plusOrMinus
cp '.'
jr z, .dot
cp '$'
jr z, .eof
call parseDecimalDigit call parseDecimalDigit
jr c, .notHandled jr c, .notHandled
; straight number ; straight number
@ -95,14 +98,22 @@ cmdParse:
ret nz ret nz
dec de ; from 1-based to 0-base dec de ; from 1-based to 0-base
jr .end jr .end
.dot:
inc hl ; advance cmd cursor
; the rest is the same as .notHandled
.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 a, RELATIVE
ld (ix), a ld (ix), a
xor a ; sets Z xor a ; sets Z
ld (ix+1), a ld (ix+1), a
ld (ix+2), a ld (ix+2), a
ret ret
.eof:
inc hl ; advance cmd cursor
ld a, EOF
ld (ix), a
ret ; Z set during earlier CP
.plusOrMinus: .plusOrMinus:
push af ; preserve that + or - push af ; preserve that + or -
ld a, RELATIVE ld a, RELATIVE

View File

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