section "home/math.asm", rom0 bits_swap:: ld c, $80 ld b, a xor a .loop rrc b jr nc, .skip or c .skip rrc c jr nc, .loop ret ; TODO: There was a more optimal way to do this with max 16 iterations array_index:: ; hl: array base ; c: entry size ; a: index and a ret z ld b, 0 .loop add hl, bc dec a jr nz, .loop ret divide:: ; a: value ; c: divisor ; Returns: ; b: result ; a: remainder ld b, 0 .loop inc b sub c jr nc, .loop dec b add c ret