From c811d5330c224d2d2c6022dc3fbde427fcf61829 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 13 Jul 2019 22:09:17 -0400 Subject: [PATCH] apps/ed: add support for addr ranges --- apps/ed/cmd.asm | 50 ++++++++++++++++++++++++++++++++++++++++-------- apps/ed/main.asm | 18 +++++++++++++++-- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/apps/ed/cmd.asm b/apps/ed/cmd.asm index 0a86045..9d3cc7d 100644 --- a/apps/ed/cmd.asm +++ b/apps/ed/cmd.asm @@ -26,9 +26,41 @@ cmdParse: ld a, (hl) cp 'q' jr z, .quit - ld (CMD_TYPE), a ld ix, CMD_ADDR1 - jp .readAddr + call .readAddr + ret nz + ; Before we check for the existence of a second addr, let's set that + ; second addr to the same value as the first. That's going to be its + ; value if we have to ",". + ld a, (ix) + ld (CMD_ADDR2), a + ld a, (ix+1) + ld (CMD_ADDR2+1), a + ld a, (ix+2) + ld (CMD_ADDR2+2), a + ld a, (hl) + cp ',' + jr nz, .noaddr2 + inc hl + ld ix, CMD_ADDR2 + call .readAddr + ret nz +.noaddr2: + ; We expect HL (rest of the cmdline) to be a null char or an accepted + ; cmd, otherwise it's garbage + ld a, (hl) + or a + jr z, .nullCmd + cp 'p' + jr z, .okCmd + ; unsupported cmd + ret ; Z unset +.nullCmd: + ld a, 'p' +.okCmd: + ld (CMD_TYPE), a + ret ; Z already set + .quit: ; Z already set ld (CMD_TYPE), a @@ -84,14 +116,10 @@ cmdParse: ex de, hl pop hl .end: - ; We expect HL (rest of the cmdline) to be a null char, otherwise it's - ; garbage - ld a, (hl) - or a - ret nz ; we still have to save DE in memory ld (ix+1), e ld (ix+2), d + cp a ; ensure Z ret ; call parseDecimal and set HL to the character following the last digit @@ -106,7 +134,8 @@ cmdParse: jr nc, .loop ; We're at the first non-digit char. Let's save it because we're going ; to temporarily replace it with a null. - ld b, a + ld b, (hl) ; refetch (HL), A has been mucked with in + ; parseDecimalDigit xor a ld (hl), a ; Now, let's go back to the beginning of the string and parse it. @@ -129,6 +158,11 @@ cmdAddr1: ld ix, CMD_ADDR1 ret +; Make (IX) point to addr 2 +cmdAddr2: + ld ix, CMD_ADDR2 + ret + ; Set A to CMD_TYPE cmdType: ld a, (CMD_TYPE) diff --git a/apps/ed/main.asm b/apps/ed/main.asm index 62d92f5..5f3ca6a 100644 --- a/apps/ed/main.asm +++ b/apps/ed/main.asm @@ -96,12 +96,25 @@ edMain: .doPrint: call cmdAddr1 call edResolveAddr + ex de, hl ; DE: addr1 + call cmdAddr2 + call edResolveAddr ld (ED_CURLINE), hl + ex de, hl ; HL: addr1, DE: addr2 + call cpHLDE + jr z, .doPrintLoop ; DE == HL, ok + jr nc, .error ; DE < HL, not good +.doPrintLoop: + push hl call bufGetLine jr nz, .error call printstr call printcrlf - jr .mainLoop + pop hl + call cpHLDE + jr nc, .mainLoop + inc hl + jr .doPrintLoop .error: ld a, '?' call stdioPutC @@ -116,13 +129,14 @@ edResolveAddr: jr z, .relative ; absolute ld l, (ix+1) - ld a, l ld h, (ix+2) ret .relative: ld hl, (ED_CURLINE) + push de ld e, (ix+1) ld d, (ix+2) add hl, de + pop de ret