neonlib: Decouple reader from buffer and introduce supplier.

Providing more flexibility in where the reader sources its data from.
4 files changed, 54 insertions(+), 28 deletions(-)

M .hgsubstate
M src/Application.asm
M src/COM.asm
M src/deflate/AlphabetTest.asm
M .hgsubstate +1 -1
@@ 1,1 1,1 @@ 
-f5d4ac3a27c5e04578db4551e52ed6f50a111448 lib/neonlib
+a1204b887749a07200c9af22d4fbad5137923355 lib/neonlib

          
M src/Application.asm +44 -25
@@ 2,6 2,8 @@ 
 ; Top-level application program class
 ;
 Application: MACRO
+	archiveFileHandle:
+		db 0FFH
 	outputFileHandle:
 		db 0FFH
 	outputSize:

          
@@ 12,8 14,10 @@ Application: MACRO
 		FileInfoBlock
 	cli:
 		CLI
-	fileReader:
-		FileReader
+	fileSupplier:
+		FileSupplier
+	bitReader:
+		BitReader
 	gzipArchive:
 		GzipArchive
 	_size:

          
@@ 61,11 65,21 @@ Application_GetCLI:
 	ret
 
 ; ix = this
-; ix <- file reader
+; ix <- file supplier
 ; Modifies: f
-Application_GetFileReader:
+Application_GetFileSupplier:
 	push de
-	ld de,Application.fileReader
+	ld de,Application.fileSupplier
+	add ix,de
+	pop de
+	ret
+
+; ix = this
+; ix <- bit reader
+; Modifies: f
+Application_GetBitReader:
+	push de
+	ld de,Application.bitReader
 	add ix,de
 	pop de
 	ret

          
@@ 142,10 156,9 @@ InflateLoop:
 	call DOS_ConsoleStatus  ; allow ctrl-c
 	pop af
 	jr nz,InflateLoop
-	push ix
-	call Application_GetFileReader
-	call FileReader_Destruct
-	pop ix
+	ld b,(ix + Application.archiveFileHandle)
+	call DOS_CloseFileHandle
+	call DOS_TerminateIfError
 	ld b,(ix + Application.outputFileHandle)
 	call DOS_CloseFileHandle
 	call DOS_TerminateIfError

          
@@ 171,10 184,9 @@ InflateLoop:
 	call GzipArchive_Inflate
 	jr nz,InflateLoop
 	pop ix
-	push ix
-	call Application_GetFileReader
-	call FileReader_Destruct
-	pop ix
+	ld b,(ix + Application.archiveFileHandle)
+	call DOS_CloseFileHandle
+	call DOS_TerminateIfError
 	jr Application_InflateTest
 	ENDP
 

          
@@ 311,11 323,21 @@ Application_CreateFileReader:
 	ld hl,Application.archiveFIB
 	add hl,de
 	ex de,hl
-	ld hl,READBUFFER
-	ld bc,READBUFFER_SIZE
+	ld a,00000001B  ; read only
+	call DOS_OpenFileHandle
+	call DOS_TerminateIfError
+	ld (ix + Application.archiveFileHandle),b
+	ld de,READBUFFER
+	ld hl,READBUFFER_SIZE
 	push ix
-	call Application_GetFileReader
-	call FileReader_Construct
+	call Application_GetFileSupplier
+	call FileSupplier_Construct
+	ld e,ixl
+	ld d,ixh
+	pop ix
+	push ix
+	call Application_GetBitReader
+	call BitReader_Construct
 	ld e,ixl
 	ld d,ixh
 	pop ix

          
@@ 336,13 358,10 @@ Application_CreateFileWriter:
 	ld (ix + Application.outputFileHandle),b
 	ret
 
-; de = file reader
 ; ix = this
-; Modifies: af, bc, de, hl, iy
+; Modifies: af, bc, de, hl
 Application_ReadOutputSize:
-	ld iyl,e
-	ld iyh,d
-	ld b,(iy + FileReader.fileHandle)
+	ld b,(ix + Application.archiveFileHandle)
 	call DOS_GetFileHandlePointer
 	call DOS_TerminateIfError
 	push de

          
@@ 350,7 369,7 @@ Application_ReadOutputSize:
 	ld a,2
 	ld hl,-4 & 0FFFFH
 	ld de,-4 >> 16
-	ld b,(iy + FileReader.fileHandle)
+	ld b,(ix + Application.archiveFileHandle)
 	call DOS_MoveFileHandlePointer
 	call DOS_TerminateIfError
 	ld e,ixl

          
@@ 359,12 378,12 @@ Application_ReadOutputSize:
 	add hl,de
 	ex de,hl
 	ld hl,4
-	ld b,(iy + FileReader.fileHandle)
+	ld b,(ix + Application.archiveFileHandle)
 	call DOS_ReadFromFileHandle
 	call DOS_TerminateIfError
 	pop hl
 	pop de
-	ld b,(iy + FileReader.fileHandle)
+	ld b,(ix + Application.archiveFileHandle)
 	call DOS_SetFileHandlePointer
 	jp DOS_TerminateIfError
 

          
M src/COM.asm +1 -1
@@ 40,7 40,7 @@ TPA_TOP:
 	INCLUDE "deflate/HuffmanCodes.asm"
 	INCLUDE "Reader.asm"
 	INCLUDE "BitReader.asm"
-	INCLUDE "FileReader.asm"
+	INCLUDE "FileSupplier.asm"
 	INCLUDE "CRC32Checker.asm"
 	INCLUDE "CRC32CheckerTest.asm"
 

          
M src/deflate/AlphabetTest.asm +8 -1
@@ 105,7 105,7 @@ AlphabetTest_TestTreeBuilding: PROC
 	ldir
 	ld hl,READBUFFER
 	ld bc,READBUFFER_SIZE
-	ld de,Reader_DefaultFiller
+	ld de,AlphabetTest_Supplier
 	ld ix,AlphabetTest_reader
 	call BitReader_Construct
 

          
@@ 128,6 128,13 @@ Loop:
 	ret
 	ENDP
 
+; de <- buffer start
+; hl <- buffer size
+AlphabetTest_Supplier:
+	ld de,READBUFFER
+	ld hl,READBUFFER_SIZE
+	ret
+
 AlphabetTest_alphabet:
 	Alphabet