-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaths.asm
80 lines (77 loc) · 2.7 KB
/
Maths.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;****************************************************************************************************************
; Devides the number in HL (Dividend) by the number in C (Divisor). It returns HL as the result of HL/C with the remainder in A
;
; Entry Registers:
; HL = Dividend
; C = Divisor
; Used Registers:
; A, C, HL
; Returned Registers:
; HL = Quotient
; A = Remainder
;****************************************************************************************************************
dvd_HL_C
xor a ; Clear A
REPT 16
add hl, hl
rla
cp c
jr c, $ + 4
sub c
inc l
ENDM
ret
;****************************************************************************************************************
; Multiplies the unsigned number in H (Multiplier) with the unsigned number in E (Multipland)
;
; Entry Registers:
; H = Multiplier
; E = Multipland
; Used Registers:
; A, C, HL
; Returned Registers:
; HL = Result
;****************************************************************************************************************
mult_H_E
sla h ; optimised 1st iteration
jr nc, $ + 3
ld l, e
REPT 7
add hl, hl ; unroll 7 times
jr nc, $ + 3 ; ...
add hl, de ; ...
ENDM
ret
;****************************************************************************************************************
; Generate a random number
;
; Entry Registers:
; NONE
; Used Registers:
; A, D, E, H, L
; Returned Registers:
; NONE
;****************************************************************************************************************
genRndmNmbr ld hl, rndmNmbr1
ld e, (hl)
inc l
ld d, (hl)
inc l
ld a, r
xor (hl)
xor e
xor d
rlca
rlca
rlca
srl e
srl d
ld (hl), d
dec l
ld (hl), e
dec l
ld (hl), a
ret
rndmNmbr1 db 0xaa ; Holds a random number calculated each frame
rndmNmbr2 db 0x55 ; Holds a random number calculated each frame
rndmNmbr3 db 0xf0 ; Holds a random number calculated each frame