From 6dbbfa837d29294e47a651bf1d8095061cfec283 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 13 Jul 2019 11:53:30 -0400 Subject: [PATCH] apps/ed: add (dummy) line number processing Starting to feel interactive... --- apps/ed/glue.asm | 1 + apps/ed/main.asm | 21 +++++++++++++++++- apps/lib/README.md | 1 + apps/lib/parse.asm | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ apps/zasm/glue.asm | 1 + apps/zasm/parse.asm | 58 ------------------------------------------------ 6 files changed, 86 insertions(+), 59 deletions(-) create mode 100644 apps/lib/README.md create mode 100644 apps/lib/parse.asm diff --git a/apps/ed/glue.asm b/apps/ed/glue.asm index 9ba9bec..c8256ba 100644 --- a/apps/ed/glue.asm +++ b/apps/ed/glue.asm @@ -4,6 +4,7 @@ jp edMain +#include "lib/parse.asm" .equ IO_RAMSTART USER_RAMSTART #include "ed/io.asm" #include "ed/main.asm" diff --git a/apps/ed/main.asm b/apps/ed/main.asm index 2b3862c..b20b511 100644 --- a/apps/ed/main.asm +++ b/apps/ed/main.asm @@ -35,6 +35,11 @@ ; to it. It repeatedly presents a prompt, waits for a command, execute the ; command. 'q' to quit. ; +; Enter a number to print this line's number. For ed, we break with Collapse +; OS's tradition of using hex representation. It would be needlessly confusing +; when combined with commands (p, c, d, a, i). All numbers in ed are +; represented in decimals. +; ; *** Requirements *** ; BLOCKDEV_SIZE ; blkGetC @@ -43,6 +48,7 @@ ; printcrlf ; stdioReadC ; stdioGetLine +; unsetZ edMain: ; Dummy test. Read first line of file @@ -70,9 +76,22 @@ edLoop: ; Sets Z if we need to quit .processLine: - call printstr ld a, (hl) cp 'q' ret z + call parseDecimal + jr z, .processNumber + ; nothing + jr .processEnd +.processNumber: + ; number is in IX + ; Because we don't have a line buffer yet, let's simply print seek + ; offsets. + push ix \ pop hl + call ioGetLine + call printstr + call printcrlf + ; continue to end +.processEnd: call printcrlf jp unsetZ diff --git a/apps/lib/README.md b/apps/lib/README.md new file mode 100644 index 0000000..1791b33 --- /dev/null +++ b/apps/lib/README.md @@ -0,0 +1 @@ +Common code used by more than one app, but not by the kernel. diff --git a/apps/lib/parse.asm b/apps/lib/parse.asm new file mode 100644 index 0000000..f828ad9 --- /dev/null +++ b/apps/lib/parse.asm @@ -0,0 +1,63 @@ +; *** Requirements *** +; unsetZ +; +; *** Code *** + +; Parse the decimal char at A and extract it's 0-9 numerical value. Put the +; result in A. +; +; On success, the carry flag is reset. On error, it is set. +parseDecimalDigit: + ; First, let's see if we have an easy 0-9 case + cp '0' + ret c ; if < '0', we have a problem + sub '0' ; our value now is valid if it's < 10 + cp 10 ; on success, C is set, which is the opposite + ; of what we want + ccf ; invert C flag + ret + +; Parse string at (HL) as a decimal value and return value in IX under the +; same conditions as parseLiteral. +parseDecimal: + push hl + push de + push bc + + ld ix, 0 +.loop: + ld a, (hl) + or a + jr z, .end ; success! + call parseDecimalDigit + jr c, .error + + ; Now, let's add A to IX. First, multiply by 10. + push ix \ pop de + add ix, ix ; x2 + jr c, .error + add ix, ix ; x4 + jr c, .error + add ix, ix ; x8 + jr c, .error + add ix, de ; x9 + jr c, .error + add ix, de ; x10 + jr c, .error + ld d, 0 + ld e, a + add ix, de + jr c, .error + + inc hl + jr .loop + +.error: + call unsetZ +.end: + pop bc + pop de + pop hl + ret + + diff --git a/apps/zasm/glue.asm b/apps/zasm/glue.asm index dac44b5..e7a9fd1 100644 --- a/apps/zasm/glue.asm +++ b/apps/zasm/glue.asm @@ -58,6 +58,7 @@ jp zasmMain #include "zasm/io.asm" .equ TOK_RAMSTART IO_RAMEND #include "zasm/tok.asm" +#include "lib/parse.asm" #include "zasm/parse.asm" #include "zasm/expr.asm" #include "zasm/instr.asm" diff --git a/apps/zasm/parse.asm b/apps/zasm/parse.asm index af8858a..fe6e4a7 100644 --- a/apps/zasm/parse.asm +++ b/apps/zasm/parse.asm @@ -1,61 +1,3 @@ -; Parse the decimal char at A and extract it's 0-9 numerical value. Put the -; result in A. -; -; On success, the carry flag is reset. On error, it is set. -parseDecimalDigit: - ; First, let's see if we have an easy 0-9 case - cp '0' - ret c ; if < '0', we have a problem - sub '0' ; our value now is valid if it's < 10 - cp 10 ; on success, C is set, which is the opposite - ; of what we want - ccf ; invert C flag - ret - -; Parse string at (HL) as a decimal value and return value in IX under the -; same conditions as parseLiteral. -parseDecimal: - push hl - push de - push bc - - ld ix, 0 -.loop: - ld a, (hl) - or a - jr z, .end ; success! - call parseDecimalDigit - jr c, .error - - ; Now, let's add A to IX. First, multiply by 10. - push ix \ pop de - add ix, ix ; x2 - jr c, .error - add ix, ix ; x4 - jr c, .error - add ix, ix ; x8 - jr c, .error - add ix, de ; x9 - jr c, .error - add ix, de ; x10 - jr c, .error - ld d, 0 - ld e, a - add ix, de - jr c, .error - - inc hl - jr .loop - -.error: - call unsetZ -.end: - pop bc - pop de - pop hl - ret - - ; Parse string at (HL) as a hexadecimal value and return value in IX under the ; same conditions as parseLiteral. parseHexadecimal: