mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 05:28:06 +11:00
ed: read initial contents in bufInit
This commit is contained in:
parent
797cbdcc95
commit
5669884508
@ -7,43 +7,47 @@
|
|||||||
;
|
;
|
||||||
; Maximum number of lines allowed in the buffer.
|
; Maximum number of lines allowed in the buffer.
|
||||||
.equ BUF_MAXLINES 0x800
|
.equ BUF_MAXLINES 0x800
|
||||||
|
; Size of our scratchpad
|
||||||
|
.equ BUF_PADMAXLEN 0x1000
|
||||||
|
|
||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
; Number of lines currently in the buffer
|
; Number of lines currently in the buffer
|
||||||
.equ BUF_LINECNT BUF_RAMSTART
|
.equ BUF_LINECNT BUF_RAMSTART
|
||||||
; List of words pointing to scratchpad offsets
|
; List of words pointing to scratchpad offsets
|
||||||
.equ BUF_LINES BUF_LINECNT+2
|
.equ BUF_LINES BUF_LINECNT+2
|
||||||
.equ BUF_RAMEND BUF_LINES+BUF_MAXLINES*2
|
; size of file we read in bufInit. That offset is the beginning of our
|
||||||
|
; in-memory scratchpad.
|
||||||
|
.equ BUF_FSIZE BUF_LINES+BUF_MAXLINES*2
|
||||||
|
; The in-memory scratchpad
|
||||||
|
.equ BUF_PADLEN BUF_FSIZE+2
|
||||||
|
.equ BUF_PAD BUF_PADLEN+2
|
||||||
|
|
||||||
|
.equ BUF_RAMEND BUF_PAD+BUF_PADMAXLEN
|
||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
|
|
||||||
|
; On initialization, we read the whole contents of target blkdev and add lines
|
||||||
|
; as we go.
|
||||||
bufInit:
|
bufInit:
|
||||||
xor a
|
ld hl, 0
|
||||||
ld (BUF_LINECNT), a
|
ld (BUF_PADLEN), hl
|
||||||
ret
|
ld ix, BUF_LINES
|
||||||
|
ld bc, 0 ; line count
|
||||||
; Add a new line with offset HL to the buffer
|
.loop:
|
||||||
bufAddLine:
|
call blkTell ; --> HL
|
||||||
push de
|
call blkGetC
|
||||||
push hl
|
jr nz, .loopend
|
||||||
ld hl, BUF_LINES
|
ld (ix), l
|
||||||
ld de, (BUF_LINECNT)
|
inc ix
|
||||||
add hl, de
|
ld (ix), h
|
||||||
add hl, de ; twice, because two bytes per line
|
inc ix
|
||||||
; HL now points to the specified line offset in memory
|
inc bc
|
||||||
pop de ; what used to be in HL ends up in DE
|
call ioGetLine
|
||||||
; line offset popped back in HL
|
jr .loop
|
||||||
ld (hl), e
|
.loopend:
|
||||||
inc hl
|
; HL currently has the result of the last blkTell
|
||||||
ld (hl), d
|
ld (BUF_FSIZE), hl
|
||||||
; increase line count
|
ld (BUF_LINECNT), bc
|
||||||
ld hl, (BUF_LINECNT)
|
|
||||||
inc hl
|
|
||||||
ld (BUF_LINECNT), hl
|
|
||||||
; our initial HL is in DE. Before we pop DE back, let's swap these
|
|
||||||
; two so that all registers are preserved.
|
|
||||||
ex de, hl
|
|
||||||
pop de
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; transform line index HL into its corresponding memory address in BUF_LINES
|
; transform line index HL into its corresponding memory address in BUF_LINES
|
||||||
|
@ -54,14 +54,7 @@ edMain:
|
|||||||
ld hl, 0
|
ld hl, 0
|
||||||
ld (ED_CURLINE), hl
|
ld (ED_CURLINE), hl
|
||||||
|
|
||||||
; Fill line buffer
|
call bufInit
|
||||||
.fillLoop:
|
|
||||||
call blkTell ; --> HL
|
|
||||||
call blkGetC
|
|
||||||
jr nz, .mainLoop
|
|
||||||
call bufAddLine
|
|
||||||
call ioGetLine
|
|
||||||
jr .fillLoop
|
|
||||||
|
|
||||||
.mainLoop:
|
.mainLoop:
|
||||||
ld a, ':'
|
ld a, ':'
|
||||||
|
Loading…
Reference in New Issue
Block a user