mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 15:08:05 +11:00
ed: Add 'w' command
This commit is contained in:
parent
f6479486f2
commit
01031a780a
@ -39,7 +39,8 @@ range is out of bounds.
|
|||||||
* `(addrs)d`: Delete lines specified in `addrs` range.
|
* `(addrs)d`: Delete lines specified in `addrs` range.
|
||||||
* `(addr)a`: Appends a line after `addr`.
|
* `(addr)a`: Appends a line after `addr`.
|
||||||
* `(addr)i`: Insert a line before `addr`.
|
* `(addr)i`: Insert a line before `addr`.
|
||||||
* `q`: quit `ed`
|
* `w`: write to file. For now, `q` is implied in `w`.
|
||||||
|
* `q`: quit `ed` without writing to file.
|
||||||
|
|
||||||
### Current line
|
### Current line
|
||||||
|
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
cmdParse:
|
cmdParse:
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
cp 'q'
|
cp 'q'
|
||||||
jr z, .quit
|
jr z, .simpleCmd
|
||||||
|
cp 'w'
|
||||||
|
jr z, .simpleCmd
|
||||||
ld ix, CMD_ADDR1
|
ld ix, CMD_ADDR1
|
||||||
call .readAddr
|
call .readAddr
|
||||||
ret nz
|
ret nz
|
||||||
@ -67,7 +69,7 @@ cmdParse:
|
|||||||
ld (CMD_TYPE), a
|
ld (CMD_TYPE), a
|
||||||
ret ; Z already set
|
ret ; Z already set
|
||||||
|
|
||||||
.quit:
|
.simpleCmd:
|
||||||
; Z already set
|
; Z already set
|
||||||
ld (CMD_TYPE), a
|
ld (CMD_TYPE), a
|
||||||
ret
|
ret
|
||||||
|
@ -32,7 +32,7 @@ ioInit:
|
|||||||
ld ix, IO_FILE_HDL
|
ld ix, IO_FILE_HDL
|
||||||
jp fsPutC
|
jp fsPutC
|
||||||
.blkdev:
|
.blkdev:
|
||||||
.dw .fsGetC, unsetZ
|
.dw .fsGetC, .fsPutC
|
||||||
|
|
||||||
ioGetC:
|
ioGetC:
|
||||||
push ix
|
push ix
|
||||||
@ -61,3 +61,33 @@ ioTell:
|
|||||||
call _blkTell
|
call _blkTell
|
||||||
pop ix
|
pop ix
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
ioSetSize:
|
||||||
|
push ix
|
||||||
|
ld ix, IO_FILE_HDL
|
||||||
|
call fsSetSize
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Write string (HL) in current file. Ends line with LF.
|
||||||
|
ioPutLine:
|
||||||
|
push hl
|
||||||
|
.loop:
|
||||||
|
ld a, (hl)
|
||||||
|
or a
|
||||||
|
jr z, .loopend ; null, we're finished
|
||||||
|
call ioPutC
|
||||||
|
jr nz, .error
|
||||||
|
inc hl
|
||||||
|
jr .loop
|
||||||
|
.loopend:
|
||||||
|
; Wrote the whole line, write ending LF
|
||||||
|
ld a, 0x0a
|
||||||
|
call ioPutC
|
||||||
|
jr z, .end ; success
|
||||||
|
; continue to error
|
||||||
|
.error:
|
||||||
|
call unsetZ
|
||||||
|
.end:
|
||||||
|
pop hl
|
||||||
|
ret
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
; fsOpen
|
; fsOpen
|
||||||
; fsGetC
|
; fsGetC
|
||||||
; fsPutC
|
; fsPutC
|
||||||
|
; fsSetSize
|
||||||
; intoHL
|
; intoHL
|
||||||
; printstr
|
; printstr
|
||||||
; printcrlf
|
; printcrlf
|
||||||
@ -69,6 +70,8 @@ edMain:
|
|||||||
ld a, (CMD_TYPE)
|
ld a, (CMD_TYPE)
|
||||||
cp 'q'
|
cp 'q'
|
||||||
jr z, .doQuit
|
jr z, .doQuit
|
||||||
|
cp 'w'
|
||||||
|
jr z, .doWrite
|
||||||
; The rest of the commands need an address
|
; The rest of the commands need an address
|
||||||
call edReadAddrs
|
call edReadAddrs
|
||||||
jr nz, .error
|
jr nz, .error
|
||||||
@ -85,6 +88,26 @@ edMain:
|
|||||||
xor a
|
xor a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
.doWrite:
|
||||||
|
ld a, 3 ; seek beginning
|
||||||
|
call ioSeek
|
||||||
|
ld de, 0 ; cur line
|
||||||
|
.writeLoop:
|
||||||
|
push de \ pop hl
|
||||||
|
call bufGetLine ; --> buffer in (HL)
|
||||||
|
jr nz, .writeEnd
|
||||||
|
call ioPutLine
|
||||||
|
jr nz, .error
|
||||||
|
inc de
|
||||||
|
jr .writeLoop
|
||||||
|
.writeEnd:
|
||||||
|
; Set new file size
|
||||||
|
call ioTell
|
||||||
|
call ioSetSize
|
||||||
|
; for now, writing implies quitting
|
||||||
|
; TODO: reload buffer
|
||||||
|
xor a
|
||||||
|
ret
|
||||||
.doDel:
|
.doDel:
|
||||||
; bufDelLines expects an exclusive upper bound, which is why we inc DE.
|
; bufDelLines expects an exclusive upper bound, which is why we inc DE.
|
||||||
inc de
|
inc de
|
||||||
@ -114,12 +137,12 @@ edMain:
|
|||||||
jr .doPrint
|
jr .doPrint
|
||||||
.doPrintEnd:
|
.doPrintEnd:
|
||||||
ld (ED_CURLINE), hl
|
ld (ED_CURLINE), hl
|
||||||
jr .mainLoop
|
jp .mainLoop
|
||||||
.error:
|
.error:
|
||||||
ld a, '?'
|
ld a, '?'
|
||||||
call stdioPutC
|
call stdioPutC
|
||||||
call printcrlf
|
call printcrlf
|
||||||
jr .mainLoop
|
jp .mainLoop
|
||||||
|
|
||||||
|
|
||||||
; Transform an address "cmd" in IX into an absolute address in HL.
|
; Transform an address "cmd" in IX into an absolute address in HL.
|
||||||
|
@ -425,7 +425,6 @@ fsPlaceH:
|
|||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Advance file handle in (IX) by one byte
|
|
||||||
; Sets Z according to whether HL is within bounds for file handle at (IX), that
|
; Sets Z according to whether HL is within bounds for file handle at (IX), that
|
||||||
; is, if it is smaller than file size.
|
; is, if it is smaller than file size.
|
||||||
fsWithinBounds:
|
fsWithinBounds:
|
||||||
@ -441,24 +440,20 @@ fsWithinBounds:
|
|||||||
.outOfBounds:
|
.outOfBounds:
|
||||||
jp unsetZ ; returns
|
jp unsetZ ; returns
|
||||||
|
|
||||||
; Adjust, if needed, file size of handle (IX) to HL+1.
|
; Set size of file handle (IX) to value in HL.
|
||||||
; This adjustment only happens if this makes file size grow.
|
; This writes directly in handle's metadata.
|
||||||
fsAdjustBounds:
|
fsSetSize:
|
||||||
call fsWithinBounds
|
push hl ; --> lvl 1
|
||||||
ret z
|
|
||||||
; Not within bounds? let's increase them
|
|
||||||
push hl
|
|
||||||
ld hl, 0
|
ld hl, 0
|
||||||
call fsPlaceH ; fs blkdev is now at beginning of content
|
call fsPlaceH ; fs blkdev is now at beginning of content
|
||||||
; we need the blkdev to be on filesize's offset
|
; we need the blkdev to be on filesize's offset
|
||||||
ld hl, FS_METASIZE-FS_META_FSIZE_OFFSET
|
ld hl, FS_METASIZE-FS_META_FSIZE_OFFSET
|
||||||
ld a, BLOCKDEV_SEEK_BACKWARD
|
ld a, BLOCKDEV_SEEK_BACKWARD
|
||||||
call fsblkSeek
|
call fsblkSeek
|
||||||
pop hl
|
pop hl ; <-- lvl 1
|
||||||
; blkdev is at the right spot, HL is back to its original value, let's
|
; blkdev is at the right spot, HL is back to its original value, let's
|
||||||
; write it.
|
; write it both in the metadata block and in its file handle's cache.
|
||||||
push hl
|
push hl ; --> lvl 1
|
||||||
inc hl ; We write HL+1, remember
|
|
||||||
; now let's write our new filesize both in blkdev and in file handle's
|
; now let's write our new filesize both in blkdev and in file handle's
|
||||||
; cache.
|
; cache.
|
||||||
ld a, l
|
ld a, l
|
||||||
@ -467,7 +462,7 @@ fsAdjustBounds:
|
|||||||
ld a, h
|
ld a, h
|
||||||
ld (ix+5), a
|
ld (ix+5), a
|
||||||
call fsblkPutC
|
call fsblkPutC
|
||||||
pop hl
|
pop hl ; <-- lvl 1
|
||||||
xor a ; ensure Z
|
xor a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -488,7 +483,7 @@ fsGetC:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Write byte A in handle (IX) and advance the handle's position.
|
; Write byte A in handle (IX) at position HL.
|
||||||
; Z is set on success, unset if handle is at the end of the file.
|
; Z is set on success, unset if handle is at the end of the file.
|
||||||
; TODO: detect end of block alloc
|
; TODO: detect end of block alloc
|
||||||
fsPutC:
|
fsPutC:
|
||||||
@ -496,7 +491,11 @@ fsPutC:
|
|||||||
call fsPlaceH
|
call fsPlaceH
|
||||||
call fsblkPutC
|
call fsblkPutC
|
||||||
pop hl
|
pop hl
|
||||||
jp fsAdjustBounds ; returns
|
; if HL is out of bounds, increase bounds
|
||||||
|
call fsWithinBounds
|
||||||
|
ret z
|
||||||
|
inc hl ; our filesize is now HL+1
|
||||||
|
jp fsSetSize
|
||||||
|
|
||||||
; Mount the fs subsystem upon the currently selected blockdev at current offset.
|
; Mount the fs subsystem upon the currently selected blockdev at current offset.
|
||||||
; Verify is block is valid and error out if its not, mounting nothing.
|
; Verify is block is valid and error out if its not, mounting nothing.
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
jp fsOpen
|
jp fsOpen
|
||||||
jp fsGetC
|
jp fsGetC
|
||||||
jp fsPutC
|
jp fsPutC
|
||||||
|
jp fsSetSize
|
||||||
jp cpHLDE
|
jp cpHLDE
|
||||||
jp parseArgs
|
jp parseArgs
|
||||||
jp printstr
|
jp printstr
|
||||||
|
@ -21,13 +21,14 @@
|
|||||||
.equ fsOpen 0x2d
|
.equ fsOpen 0x2d
|
||||||
.equ fsGetC 0x30
|
.equ fsGetC 0x30
|
||||||
.equ fsPutC 0x33
|
.equ fsPutC 0x33
|
||||||
.equ cpHLDE 0x36
|
.equ fsSetSize 0x36
|
||||||
.equ parseArgs 0x39
|
.equ cpHLDE 0x39
|
||||||
.equ printstr 0x3c
|
.equ parseArgs 0x3c
|
||||||
.equ _blkGetC 0x3f
|
.equ printstr 0x3f
|
||||||
.equ _blkPutC 0x42
|
.equ _blkGetC 0x42
|
||||||
.equ _blkSeek 0x45
|
.equ _blkPutC 0x45
|
||||||
.equ _blkTell 0x48
|
.equ _blkSeek 0x48
|
||||||
.equ printcrlf 0x4b
|
.equ _blkTell 0x4b
|
||||||
.equ stdioPutC 0x4e
|
.equ printcrlf 0x4e
|
||||||
.equ stdioReadLine 0x51
|
.equ stdioPutC 0x51
|
||||||
|
.equ stdioReadLine 0x54
|
||||||
|
Loading…
Reference in New Issue
Block a user