diff options
author | yenatch <yenatch@gmail.com> | 2017-12-23 17:14:09 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2017-12-23 17:14:09 -0500 |
commit | c51968f0de6b8420c141dde27339e82a42837c5b (patch) | |
tree | 782f2b25f21adacb48fd516694b8a82864fe0b99 /engine/square_root.asm | |
parent | c883ab4d34ecb4890010e808d6b6d533f5d8ad56 (diff) | |
parent | 878092004956418bfd77bfdb9fc9dd7f640f80d2 (diff) |
Merge remote-tracking branch 'origin/master' into master
Diffstat (limited to 'engine/square_root.asm')
-rw-r--r-- | engine/square_root.asm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/engine/square_root.asm b/engine/square_root.asm new file mode 100644 index 000000000..496f66c83 --- /dev/null +++ b/engine/square_root.asm @@ -0,0 +1,30 @@ +GetSquareRoot: ; 13b87 +; Return the square root of de in b. + +; Rather than calculating the result, we take the index of the +; first value in a table of squares that isn't lower than de. + + ld hl, Squares + ld b, 0 +.loop +; Make sure we don't go past the end of the table. + inc b + ld a, b + cp $ff + ret z + +; Iterate over the table until b**2 >= de. + ld a, [hli] + sub e + ld a, [hli] + sbc d + + jr c, .loop + ret + +Squares: ; 13b98 +root set 1 + rept $ff + dw root*root +root set root+1 + endr |