From 443f6e1f2a8d83ad9da051cbb960311c5aaaea66 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Thu, 26 Sep 2024 20:16:51 +0300 Subject: [PATCH] Add timeouts to some LY waits --- common/common.s | 1 + common/lib/disable_ppu_safe.s | 6 ++++- common/lib/quit.s | 14 ++++++++-- common/lib/wait_ly_with_timeout.s | 45 +++++++++++++++++++++++++++++++ utils/bootrom_dumper.s | 1 + 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 common/lib/wait_ly_with_timeout.s diff --git a/common/common.s b/common/common.s index 9aab3bb..9b56c2b 100644 --- a/common/common.s +++ b/common/common.s @@ -103,6 +103,7 @@ .include "lib/quit_dump_mem.s" .include "lib/reset_screen.s" .include "lib/serial_send_byte.s" +.include "lib/wait_ly_with_timeout.s" ; --- Cartridge header --- diff --git a/common/lib/disable_ppu_safe.s b/common/lib/disable_ppu_safe.s index 6557ba9..153c2b8 100644 --- a/common/lib/disable_ppu_safe.s +++ b/common/lib/disable_ppu_safe.s @@ -30,7 +30,11 @@ disable_ppu_safe: ld hl, LCDC bit 7, (hl) ret z - wait_ly 144 + + push de + ld a, 144 + call wait_ly_with_timeout res 7, (hl) + pop de ret .ends diff --git a/common/lib/quit.s b/common/lib/quit.s index ee656b0..1d5cf4f 100644 --- a/common/lib/quit.s +++ b/common/lib/quit.s @@ -46,15 +46,25 @@ quit: ret @cb_return: + push de call is_ppu_broken jr c, @report_result enable_ppu - wait_vblank + + ld a, 143 + call wait_ly_with_timeout + jr c, @report_result + ld a, 144 + call wait_ly_with_timeout ; Extra vblank to account for initial (invisible) frame - wait_vblank + ld a, 143 + call wait_ly_with_timeout + ld a, 144 + call wait_ly_with_timeout @report_result: + pop de ld a, d and a jr nz, @failure diff --git a/common/lib/wait_ly_with_timeout.s b/common/lib/wait_ly_with_timeout.s new file mode 100644 index 0000000..ae26cb6 --- /dev/null +++ b/common/lib/wait_ly_with_timeout.s @@ -0,0 +1,45 @@ +; Copyright (C) 2014-2024 Joonas Javanainen +; +; Permission is hereby granted, free of charge, to any person obtaining a copy +; of this software and associated documentation files (the "Software"), to deal +; in the Software without restriction, including without limitation the rights +; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +; copies of the Software, and to permit persons to whom the Software is +; furnished to do so, subject to the following conditions: +; +; The above copyright notice and this permission notice shall be included in +; all copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +; SOFTWARE. + +.ifdef FORCE_SECTIONS +.section "wait_ly_with_timeout" FORCE +.else +.section "wait_ly_with_timeout" +.endif +; Inputs: +; A expected LY value +; Outputs: +; cf 0 if LY value was seen, 1 if the wait timed out +; Preserved: E, HL +wait_ly_with_timeout: + ld d, a + ld bc, $0000 +- ldh a, (