662ffc64f996 — Laurens Holst 3 years ago
VBlankHandler: Prevent buffer overruns.

The previous commit’s measure was not sufficient to prevent buffer overruns, it
seems that the standard ISR itself (and the interslot call to it) takes too long
to process MIDI interrupts in time. So we resort to implementing a minimal
VBlank interrupt handler, replacing the BIOS one.

Oddly enough this is not reproducible in openMSX…
3 files changed, 60 insertions(+), 0 deletions(-)

M src/Application.asm
M src/COM.asm
A => src/VBlankHandler.asm
M src/Application.asm +17 -0
@@ 4,6 4,8 @@ 
 Application: MACRO
 	cli:
 		CLI
+	vblankHandler:
+		VBlankHandler
 	synthesizer:
 		Synthesizer
 	size:

          
@@ 64,6 66,10 @@ Application_Construct:
 	call CLI_Construct
 	pop ix
 	push ix
+	call Application_GetVBlankHandler
+	call VBlankHandler_Construct
+	pop ix
+	push ix
 	call Application_GetSynthesizer
 	call Synthesizer_Construct
 	pop ix

          
@@ 77,6 83,10 @@ Application_Destruct:
 	call Synthesizer_Destruct
 	pop ix
 	push ix
+	call Application_GetVBlankHandler
+	call VBlankHandler_Destruct
+	pop ix
+	push ix
 	call Application_GetCLI
 	call CLI_Destruct
 	pop ix

          
@@ 90,6 100,13 @@ Application_GetCLI:
 	ret
 
 ; ix = this
+; ix <- vblank handler
+Application_GetVBlankHandler:
+	ld de,Application.vblankHandler
+	add ix,de
+	ret
+
+; ix = this
 ; ix <- synthesizer
 Application_GetSynthesizer:
 	ld de,Application.synthesizer

          
M src/COM.asm +1 -0
@@ 42,6 42,7 @@ COM_Main:
 	INCLUDE "Application.asm"
 	INCLUDE "CLI.asm"
 	INCLUDE "Hook.asm"
+	INCLUDE "VBlankHandler.asm"
 	INCLUDE "MidiIn.asm"
 	INCLUDE "MSXMidi.asm"
 	INCLUDE "MSXMusic.asm"

          
A => src/VBlankHandler.asm +42 -0
@@ 0,0 1,42 @@ 
+;
+; Minimal VBlank interrupt handler
+;
+VBlankHandler: MACRO
+	hook:
+		Hook 38H, Entry, OldHook
+	Entry:
+		push af
+		in a,(99H)
+		rlca
+		jr nc,NotVBlank
+		push hl
+		ld hl,(JIFFY)
+		inc hl
+		ld (JIFFY),hl
+		pop hl
+		pop af
+		ei
+		ret
+	NotVBlank:
+		pop af
+	OldHook:
+		ds 5
+	ENDM
+
+; ix = this
+VBlankHandler_Construct:
+	push ix
+	ld de,VBlankHandler.hook
+	add ix,de
+	call Hook_Install
+	pop ix
+	ret
+
+; ix = this
+VBlankHandler_Destruct:
+	push ix
+	ld de,VBlankHandler.hook
+	add ix,de
+	call Hook_Uninstall
+	pop ix
+	ret