Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Project:
- ; hl is Z, de is Y, bc is X
- ; assume hl is stricly positive
- ; 265 bytes, +-600 TStates depending the input
- add hl, hl
- ; return if neg
- ret c
- ld a, h
- or a
- jr z, _scale_up
- _scale_down_loop:
- srl a
- rr l
- sra d
- rr e
- sra b
- rr c
- or a
- jp nz, _scale_down_loop
- _scale_up:
- ; l, e, c are significant
- ld a, l
- or a
- ret z
- cp 98
- jp z, _no_bissect
- jr nc, _scale_done
- _scale_up_loop:
- sla e
- sla c
- add a, a
- cp 98
- jp c, _scale_up_loop
- _scale_done:
- rra
- ld l, a
- ; l=Z, e=X, c=Y
- xor a
- ; set a to 0 and reset carry flag
- ld h, a
- ld d, a
- ld b, a
- ; first optimized iters (h,d,b are 0)
- gBissectFirstIter:
- ld a, l
- rra
- cp 49
- ; calculate midpoint and classify
- jr nc, $+16
- ; store to h
- ld h, a
- ld a, e
- inc a
- sra a
- ld d, a
- ld a, c
- inc a
- sra a
- ld b, a
- jp $+10
- ; store it to l
- ld l, a
- inc e
- sra e
- inc c
- sra c
- ; the bissection macro, unrolled to gain speed (and because we need all register)
- #macro gBissectIter()
- ld a, l
- add a, h
- rra
- cp 49
- ; calculate midpoint and classify
- jr nc, $+18
- ; store to h
- ld h, a
- ld a, e
- inc a
- add a, d
- sra a
- ld d, a
- ld a, c
- inc a
- add a, b
- sra a
- ld b, a
- jp $+16
- ; store it to l
- ld l, a
- ld a, e
- inc a
- add a, d
- sra a
- ld e, a
- ld a, c
- inc a
- add a, b
- sra a
- ld c, a
- #endmacro
- ; 4 more iters to match precision
- gBissectIter()
- gBissectIter()
- gBissectIter()
- gBissectIter()
- ; finish:
- ld a, e
- add a, d
- ; note : rra works because both d and e are either positive (no carry) or negative (carry set)
- rra
- adc a, 48
- ; or whatever
- ld (gScreenX), a
- ld a, c
- add a, b
- rra
- ld c, a
- ld a, 32
- sbc a, c
- ld (gScreenY), a
- ret
- _no_bissect:
- ld a, e
- add a, 48
- ld (gScreenX), a
- ld a, 32
- sub c
- ld (gScreenY), a
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement