2019-04-23 12:54:23 +10:00
|
|
|
; *** REQUIREMENTS ***
|
2019-11-16 07:37:49 +11:00
|
|
|
; blkSelPtr
|
|
|
|
; blkSel
|
|
|
|
; blkSeek
|
|
|
|
; blkTell
|
2019-04-23 12:54:23 +10:00
|
|
|
|
|
|
|
blkBselCmd:
|
|
|
|
.db "bsel", 0b001, 0, 0
|
|
|
|
ld a, (hl) ; argument supplied
|
2019-05-11 08:20:43 +10:00
|
|
|
push de
|
2019-11-16 07:37:49 +11:00
|
|
|
call blkSelPtr
|
2019-04-23 12:54:23 +10:00
|
|
|
call blkSel
|
2019-05-11 08:20:43 +10:00
|
|
|
pop de
|
2019-11-16 07:37:49 +11:00
|
|
|
jr nz, .error
|
2019-04-23 12:54:23 +10:00
|
|
|
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
|
2019-05-31 04:54:28 +10:00
|
|
|
ld de, 0 ; DE is used for seek > 64K which we don't support
|
2019-04-23 12:54:23 +10:00
|
|
|
call blkSeek
|
|
|
|
call blkTell
|
|
|
|
ld a, h
|
|
|
|
call printHex
|
|
|
|
ld a, l
|
|
|
|
call printHex
|
|
|
|
call printcrlf
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2019-06-17 22:19:03 +10:00
|
|
|
; 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.
|
2019-06-03 01:18:06 +10:00
|
|
|
;
|
|
|
|
; Returns a SHELL_ERR_IO_ERROR only if we couldn't read any byte (if the first
|
2019-10-31 07:59:35 +11:00
|
|
|
; call to GetB failed)
|
2019-06-03 00:50:18 +10:00
|
|
|
;
|
|
|
|
; 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)
|
2019-10-31 07:59:35 +11:00
|
|
|
call blkGetB
|
2019-06-03 00:50:18 +10:00
|
|
|
jr nz, .ioError
|
2019-10-31 07:59:35 +11:00
|
|
|
jr .intoLoop ; we'v already called blkGetB. don't call it
|
2019-06-17 23:54:30 +10:00
|
|
|
; again.
|
2019-06-03 01:18:06 +10:00
|
|
|
.loop:
|
2019-10-31 07:59:35 +11:00
|
|
|
call blkGetB
|
2019-06-17 23:54:30 +10:00
|
|
|
.intoLoop:
|
2019-06-03 00:50:18 +10:00
|
|
|
ld (hl), a
|
|
|
|
inc hl
|
2019-06-03 01:18:06 +10:00
|
|
|
jr nz, .loopend
|
2019-06-03 00:50:18 +10:00
|
|
|
djnz .loop
|
2019-06-03 01:18:06 +10:00
|
|
|
.loopend:
|
2019-06-03 00:50:18 +10:00
|
|
|
; success
|
|
|
|
xor a
|
|
|
|
jr .end
|
|
|
|
.ioError:
|
|
|
|
ld a, SHELL_ERR_IO_ERROR
|
|
|
|
.end:
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2019-06-17 22:19:03 +10:00
|
|
|
; 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
|
2019-10-31 07:59:35 +11:00
|
|
|
; chars to blkPutB. Raises error if not all bytes could be written.
|
2019-06-03 00:50:18 +10:00
|
|
|
;
|
|
|
|
; 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
|
2019-10-31 07:59:35 +11:00
|
|
|
call blkPutB
|
2019-06-06 06:13:15 +10:00
|
|
|
jr nz, .ioError
|
2019-06-03 00:50:18 +10:00
|
|
|
djnz .loop
|
2019-06-06 06:13:15 +10:00
|
|
|
.loopend:
|
|
|
|
; success
|
|
|
|
xor a
|
|
|
|
jr .end
|
|
|
|
.ioError:
|
|
|
|
ld a, SHELL_ERR_IO_ERROR
|
2019-06-03 00:50:18 +10:00
|
|
|
.end:
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|