1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-31 07:38:06 +11:00
collapseos/apps/shell/blkdev.asm
Virgil Dupras 019d05f64c Make the shell a userspace app
That's my mega-commit you've all been waiting for.

The code for the shell share more routines with userspace apps than with kernel
units, because, well, its behavior is that of a userspace app, not a device
driver.

This created a weird situation with libraries and jump tables. Some routine
belonging to the `kernel/` directory felt weird there.

And then comes `apps/basic`, which will likely share even more code with the
shell. I was seeing myself creating huge jump tables to reuse code from the
shell. It didn't feel right.

Moreover, we'll probably want basic-like apps to optionnally replace the shell.

So here I am with this huge change in the project structure. I didn't test all
recipes on hardware yet, I will do later. I might have broken some...

But now, the structure feels better and the line between what belongs to
`kernel` and what belongs to `apps` feels clearer.
2019-11-15 15:37:49 -05:00

119 lines
2.0 KiB
NASM

; *** REQUIREMENTS ***
; blkSelPtr
; blkSel
; blkSeek
; blkTell
blkBselCmd:
.db "bsel", 0b001, 0, 0
ld a, (hl) ; argument supplied
push de
call blkSelPtr
call blkSel
pop de
jr nz, .error
xor a
ret
.error:
ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS
ret
blkSeekCmd:
.db "seek", 0b001, 0b011, 0b001
; First, the mode
ld a, (hl)
inc hl
push af ; save mode for later
; HL points to two bytes that contain out address. Seek expects HL
; to directly contain that address.
ld a, (hl)
ex af, af'
inc hl
ld a, (hl)
ld l, a
ex af, af'
ld h, a
pop af ; bring mode back
ld de, 0 ; DE is used for seek > 64K which we don't support
call blkSeek
call blkTell
ld a, h
call printHex
ld a, l
call printHex
call printcrlf
xor a
ret
; Load the specified number of bytes (max 0x100, 0 means 0x100) from IO and
; write them in the current memory pointer (which doesn't change). If the
; blkdev hits end of stream before we reach our specified number of bytes, we
; stop loading.
;
; Returns a SHELL_ERR_IO_ERROR only if we couldn't read any byte (if the first
; call to GetB failed)
;
; Example: load 42
blkLoadCmd:
.db "load", 0b001, 0, 0
blkLoad:
push bc
push hl
ld a, (hl)
ld b, a
ld hl, (SHELL_MEM_PTR)
call blkGetB
jr nz, .ioError
jr .intoLoop ; we'v already called blkGetB. don't call it
; again.
.loop:
call blkGetB
.intoLoop:
ld (hl), a
inc hl
jr nz, .loopend
djnz .loop
.loopend:
; success
xor a
jr .end
.ioError:
ld a, SHELL_ERR_IO_ERROR
.end:
pop hl
pop bc
ret
; Load the specified number of bytes (max 0x100, 0 means 0x100) from the current
; memory pointer and write them to I/O. Memory pointer doesn't move. This puts
; chars to blkPutB. Raises error if not all bytes could be written.
;
; Example: save 42
blkSaveCmd:
.db "save", 0b001, 0, 0
blkSave:
push bc
push hl
ld a, (hl)
ld b, a
ld hl, (SHELL_MEM_PTR)
.loop:
ld a, (hl)
inc hl
call blkPutB
jr nz, .ioError
djnz .loop
.loopend:
; success
xor a
jr .end
.ioError:
ld a, SHELL_ERR_IO_ERROR
.end:
pop hl
pop bc
ret