# HG changeset patch # User Laurens Holst # Date 1733263420 -3600 # Tue Dec 03 23:03:40 2024 +0100 # Node ID 88fa75ec754f5af9c147fe9418524d071722045c # Parent 8b931818a05f9ce3242a560ab962956232ad401f neonlib: Decouple reader from buffer and introduce supplier. Providing more flexibility in where the reader sources its data from. diff --git a/.hgsubstate b/.hgsubstate --- a/.hgsubstate +++ b/.hgsubstate @@ -1,1 +1,1 @@ -f5d4ac3a27c5e04578db4551e52ed6f50a111448 lib/neonlib +a1204b887749a07200c9af22d4fbad5137923355 lib/neonlib diff --git a/src/Application.asm b/src/Application.asm --- a/src/Application.asm +++ b/src/Application.asm @@ -2,6 +2,8 @@ ; Top-level application program class ; Application: MACRO + archiveFileHandle: + db 0FFH outputFileHandle: db 0FFH outputSize: @@ -12,8 +14,10 @@ FileInfoBlock cli: CLI - fileReader: - FileReader + fileSupplier: + FileSupplier + bitReader: + BitReader gzipArchive: GzipArchive _size: @@ -61,11 +65,21 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 diff --git a/src/COM.asm b/src/COM.asm --- a/src/COM.asm +++ b/src/COM.asm @@ -40,7 +40,7 @@ INCLUDE "deflate/HuffmanCodes.asm" INCLUDE "Reader.asm" INCLUDE "BitReader.asm" - INCLUDE "FileReader.asm" + INCLUDE "FileSupplier.asm" INCLUDE "CRC32Checker.asm" INCLUDE "CRC32CheckerTest.asm" diff --git a/src/deflate/AlphabetTest.asm b/src/deflate/AlphabetTest.asm --- a/src/deflate/AlphabetTest.asm +++ b/src/deflate/AlphabetTest.asm @@ -105,7 +105,7 @@ 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 @@ ret ENDP +; de <- buffer start +; hl <- buffer size +AlphabetTest_Supplier: + ld de,READBUFFER + ld hl,READBUFFER_SIZE + ret + AlphabetTest_alphabet: Alphabet