mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 12:18:07 +11:00
apps/ed: add (dummy) line number processing
Starting to feel interactive...
This commit is contained in:
parent
3491c26132
commit
6dbbfa837d
@ -4,6 +4,7 @@
|
||||
|
||||
jp edMain
|
||||
|
||||
#include "lib/parse.asm"
|
||||
.equ IO_RAMSTART USER_RAMSTART
|
||||
#include "ed/io.asm"
|
||||
#include "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
|
||||
|
1
apps/lib/README.md
Normal file
1
apps/lib/README.md
Normal file
@ -0,0 +1 @@
|
||||
Common code used by more than one app, but not by the kernel.
|
63
apps/lib/parse.asm
Normal file
63
apps/lib/parse.asm
Normal file
@ -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
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user