c56555e39273 — Laurens Holst 3 years ago
neonlib: Update to latest.
7 files changed, 43 insertions(+), 66 deletions(-)

M .hgsubstate
M src/Application.asm
M src/CLI.asm
M src/COM.asm
M src/MappedBuffer.asm
M src/MappedBufferLoader.asm
M src/PNG.asm
M .hgsubstate +2 -2
@@ 1,2 1,2 @@ 
-97d4edac8987a95323638f606b03a4c6e9caf5b4 lib/gunzip
-494955e3891fd4ac75d3e9c0d39864e7e7ab0ee5 lib/neonlib
+b673971f8861bbfa929855e7fb68fc048a773632 lib/gunzip
+d0251f469b20f4e741a3dbeee0467e1d0d053ca3 lib/neonlib

          
M src/Application.asm +19 -44
@@ 21,13 21,19 @@ Application: MACRO
 
 ;
 Application_Main:
-	ld hl,DOS_Terminate
-	call System_SetTerminateHandler
+	ld ix,Mapper_instance
+	call Mapper_Construct
+
+	ld hl,Application_MainContinue
+	call System_TryCall
 
-	call DOS_IsDOS2
-	ld hl,Application_dos2RequiredError
-	jp c,System_TerminateWithError
+	ld ix,Mapper_instance
+	call Mapper_Destruct
 
+	call System_Rethrow
+	ret
+
+Application_MainContinue:
 	call Application_CheckStack
 
 	call VDP_InitMirrorsOnVDPUpgrades

          
@@ 35,8 41,6 @@ Application_Main:
 	ld hl,Application_welcome
 	call System_Print
 
-	ld ix,Mapper_instance
-	call Mapper_Construct
 	ld ix,Heap_main
 	call Heap_Construct
 

          
@@ 45,24 49,14 @@ Application_Main:
 
 	ld ix,Application_instance
 	call Application_Construct
-	ld de,Application_Abort
-	call DOS_DefineAbortExitRoutine
-	call Application_EnterMainLoop
-	call Application_Abort
-	ret
 
-; DOS error or abort handler
-Application_Abort:
-	push af
-	push bc
-	ld ix,Mapper_instance
-	call Mapper_RestoreInitialState
-	ld ix,Application_instance
+	push ix
+	ld hl,Application_EnterMainLoop
+	call System_TryCall
+	pop ix
+
 	call Application_Destruct
-	ld ix,Mapper_instance
-	call Mapper_Destruct
-	pop bc
-	pop af
+	call System_Rethrow
 	ret
 
 ; ix = this

          
@@ 156,7 150,7 @@ Application_ParseCLI:
 	ld a,l
 	or h
 	ld hl,Application_usageInstructions
-	jp z,System_TerminateWithError
+	jp z,System_ThrowExceptionWithMessage
 	pop ix
 	ret
 

          
@@ 225,30 219,14 @@ Application_CheckStack:
 	ld hl,-(HEAP + HEAP_SIZE + STACK_SIZE)
 	add hl,sp
 	ld hl,Application_insufficientTPAError
-	jp nc,System_TerminateWithError
+	jp nc,System_ThrowExceptionWithMessage
 	ret
 
-; a = DOS error code
-Application_CheckDOSError:
-	and a
-	ret z
-Application_TerminateWithDOSError:
-	ld b,a
-	ld de,Application_explainBuffer
-	call DOS_ExplainErrorCode
-	ld hl,Application_explainBuffer
-	call System_Print
-	call System_PrintCrLf
-	jp System_TerminateWithError
-
 ;
 	SECTION RAM
 
 Application_instance: Application
 
-Application_explainBuffer:
-	ds 64,0
-
 	ENDS
 
 Application_welcome:

          
@@ 263,9 241,6 @@ Application_dotDotDot:
 Application_showing:
 	db 13,10,"Showing...",13,10,0
 
-Application_dos2RequiredError:
-	db "MSX-DOS 2 is required.",13,10,0
-
 Application_insufficientTPAError:
 	db "Insufficient TPA space.",13,10,0
 

          
M src/CLI.asm +3 -3
@@ 70,7 70,7 @@ CLI_ParseOption: PROC
 	ld a,(de)
 	and 11011111B  ; upper-case
 	ld hl,CLI_unknownOptionError
-	jp System_TerminateWithError
+	jp System_ThrowExceptionWithMessage
 Next:
 	ld a,(de)
 	and a

          
@@ 78,7 78,7 @@ Next:
 	cp " "
 	ret z
 	ld hl,CLI_unknownOptionError
-	jp System_TerminateWithError
+	jp System_ThrowExceptionWithMessage
 	ENDP
 
 ; de = buffer position

          
@@ 87,7 87,7 @@ CLI_ParsePath:
 	ld a,(ix + CLI.path)
 	or (ix + CLI.path + 1)
 	ld hl,CLI_multiplePathsError
-	jp nz,System_TerminateWithError
+	jp nz,System_ThrowExceptionWithMessage
 	ld (ix + CLI.path),e
 	ld (ix + CLI.path + 1),d
 	call DOS_ParsePathname

          
M src/COM.asm +2 -5
@@ 27,11 27,7 @@ RAM: equ RAM_PAGE1
 
 	SECTION TPA
 
-;
-; Program entry point
-;
-COM_Main:
-	jp Application_Main
+	DOS2Runtime Application_Main
 
 	INCLUDE "DOS.asm"
 	INCLUDE "BIOS.asm"

          
@@ 40,6 36,7 @@ COM_Main:
 	INCLUDE "Memory.asm"
 	INCLUDE "Mapper.asm"
 	INCLUDE "Heap.asm"
+	INCLUDE "DOS2Runtime.asm"
 	INCLUDE "Application.asm"
 	INCLUDE "MappedBuffer.asm"
 	INCLUDE "MappedBufferLoader.asm"

          
M src/MappedBuffer.asm +2 -2
@@ 99,7 99,7 @@ MappedBuffer_AllocateSegment:
 	ld a,0
 	call Mapper_instance.Allocate
 	ld hl,MappedBuffer_outOfMemoryError
-	jp c,System_TerminateWithError
+	jp c,System_ThrowExceptionWithMessage
 	ret
 
 ; a = segment number

          
@@ 111,7 111,7 @@ MappedBuffer_AddSegment:
 	ld e,(ix + MappedBuffer.segmentCount)
 	inc e
 	ld hl,MappedBuffer_outOfMemoryError
-	jp z,System_TerminateWithError
+	jp z,System_ThrowExceptionWithMessage
 	ld (ix + MappedBuffer.segmentCount),e
 	dec e
 	ld d,0

          
M src/MappedBufferLoader.asm +4 -4
@@ 27,7 27,7 @@ MappedBufferLoader_Construct:
 	pop de
 	ld a,00000001B  ; read-only
 	call DOS_OpenFileHandle
-	call Application_CheckDOSError
+	call DOS_TerminateIfError
 	ld (ix + MappedBufferLoader.fileHandle),b
 	ret
 

          
@@ 35,7 35,7 @@ MappedBufferLoader_Construct:
 MappedBufferLoader_Destruct:
 	ld b,(ix + MappedBufferLoader.fileHandle)
 	call DOS_CloseFileHandle
-	call Application_CheckDOSError
+	call DOS_TerminateIfError
 	push ix
 	call MappedBufferLoader_GetWriter
 	call Writer_FinishBlock

          
@@ 68,7 68,7 @@ MappedBufferLoader_Load:
 	call DOS_ReadFromFileHandle
 	cp .EOF
 	ret z
-	call Application_CheckDOSError
+	call DOS_TerminateIfError
 	push af
 	push ix
 	call MappedBufferLoader_GetWriter

          
@@ 89,7 89,7 @@ MappedBufferLoader_LoadViaBuffer:
 	call DOS_ReadFromFileHandle
 	cp .EOF
 	ret z
-	call Application_CheckDOSError
+	call DOS_TerminateIfError
 	push af
 	push ix
 	call MappedBufferLoader_GetWriter

          
M src/PNG.asm +11 -6
@@ 473,16 473,21 @@ PNG_Decompress:
 	ld e,ixl
 	ld d,ixh
 	ex (sp),ix  ; sp = this, reader, writer, ix = zlibarchive
-	call ZlibArchive_Extract
+	push ix
+	ld hl,ZlibArchive_Extract
+	call System_TryCall
+	pop ix
+	ex (sp),ix
+	call Mapped32KWriter_Destruct
+	call Mapped32KWriter_class.Delete
+	pop ix
 	call ZlibArchive_Destruct
 	call ZlibArchive_class.Delete
 	pop ix
-	call Mapped32KWriter_Destruct
-	call Mapped32KWriter_class.Delete
-	pop ix
 	call IndirectMappedReader_Destruct
 	call IndirectMappedReader_class.Delete
 	pop ix
+	call System_Rethrow
 	ret
 
 ; ix = this

          
@@ 692,12 697,12 @@ PNG_CheckChunkNameCharacter:
 ; ix = this
 PNG_TerminateWithInvalidError:
 	ld hl,PNG_invalidPNGError
-	jp System_TerminateWithError
+	jp System_ThrowExceptionWithMessage
 
 ; ix = this
 PNG_TerminateWithUnsupportedError:
 	ld hl,PNG_unsupportedError
-	jp System_TerminateWithError
+	jp System_ThrowExceptionWithMessage
 
 ;
 PNG_invalidPNGError: