Skip to content

Commit

Permalink
ed: add '.' and '$' support
Browse files Browse the repository at this point in the history
  • Loading branch information
Virgil Dupras committed Oct 4, 2019
1 parent 55be698 commit 8db1bdb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apps/ed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 14 additions & 3 deletions apps/ed/cmd.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions apps/ed/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 8db1bdb

Please sign in to comment.