forked from jblang/bbcbasic-z80
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.asm
64 lines (54 loc) · 846 Bytes
/
utils.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
PUBLIC DIV_HL_C, MATH_ABS_HL, MATH_POS_HL, MATH_NEG_HL, MATH_CP_HL_DE
; THE FOLLOWING ROUTINE DIVIDES HL BY C AND PLACES THE QUOTIENT IN HL AND THE REMAINDER IN A
; https://wikiti.brandonw.net/index.php?title=Z80_Routines:Math:Division#16.2F16_division
DIV_HL_C:
XOR A
LD B, 16
LOOP:
ADD HL, HL
RLA
JR C, DIV_HL_C1
CP C
JR C, DIV_HL_C2
DIV_HL_C1:
SUB C
INC L
DIV_HL_C2:
DJNZ LOOP
RET
MATH_ABS_HL:
BIT 7, H
RET Z
MATH_POS_HL:
XOR A
SUB L
LD L, A
SBC A, A
SUB H
LD H, A
RET
MATH_NEG_HL:
XOR A
SUB L
LD L,A
SBC A,A
SUB H
LD H,A
RET
; MATH_CP_HL_DE -> test if HL >= DE
; Input HL=A, DE=B
; Output C FLAG RESET IF TRUE
; C FLAG SET IF FALSE
MATH_CP_HL_DE:
LD A, H
XOR D
JP M, MATH_CP_HL_DE2
SBC HL, DE
RET NC
MATH_CP_HL_DE1:
SCF
RET
MATH_CP_HL_DE2:
BIT 7, D
JR Z, MATH_CP_HL_DE1
RET