git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit bab52712cfc1c1d38dd4cb26dec7c596b6b65486
parent a51b4e04ccd781699217a74f05b3ea3dac932ed0
Author: Toxa <untoxa@mail.ru>
Date:   Tue, 13 Jan 2026 19:23:54 +0300

GB: a few minor optimizations to the integer division routines

Diffstat:
Mgbdk-lib/libc/asm/sm83/div.s21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/gbdk-lib/libc/asm/sm83/div.s b/gbdk-lib/libc/asm/sm83/div.s @@ -260,8 +260,7 @@ signexte: ld d,a ret .exit: - pop af - pop af + add sp, #4 ret .divu8:: @@ -275,13 +274,8 @@ signexte: ;; Check for division by zero ld a,e or d - jr NZ,.divide ; Branch if divisor is non-zero - ld bc,#0x00 ; Divide by zero error - ld d,b - ld e,c - scf ; Set carry, invalid result - ret -.divide: + jr Z,.error ; Branch if divisor is zero + ld l,c ; L = low byte of dividend/quotient ld h,b ; H = high byte of dividend/quotient ld bc,#0x00 ; BC = remainder @@ -319,13 +313,14 @@ signexte: or a ; restore (clear) the carry flag jr NZ,.dvloop jr .nodrop + .drop: pop af ; faster and smaller than 2x inc sp pop af ; recover # bits remaining, carry flag destroyed dec a scf ; restore (set) the carry flag jr NZ,.dvloop - jr .nodrop + .nodrop: ;; Shift last carry bit into quotient ld d,b ; DE = remainder @@ -337,3 +332,9 @@ signexte: or a ; Clear carry, valid result ret +.error: + ld bc,#0x00 ; Divide by zero error + ld d,b + ld e,c + scf ; Set carry, invalid result + ret

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.