-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.asm
137 lines (106 loc) · 1.63 KB
/
math.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
; 32 bits add
; input num1: ax(lo), bx(hi)
; input num2: cx(lo), dx(hi)
; result in ax(lo), bx(hi)
Add32:
php
.call M8
.call RESERVE_STACK_FRAME 04
; 01/02 03/04 -> result
.call M16
; 32 bits add
clc
lda @ax ; num1_lo
adc @cx ; num2_lo
sta 01; result_lo
lda @bx ; num1_hi
adc @dx ; num2_hi
sta 03 ; result_hi
lda 01
sta @ax
lda 03
sta @bx
.call M8
.call RESTORE_STACK_FRAME 04
plp
rts
; 32 bits LSR
; @ax -> input lo / result lo
; @bx -> input hi / result hi
; @cl -> amount to shift
Lsr32:
php
lsr_32_loop:
.call M16
lsr @bx
ror @ax
.call M8
dec @cl
bne @lsr_32_loop
plp
rts
; 32 bits ASL
; @ax -> input lo / result lo
; @bx -> input hi / result hi
; @cl -> amount to shift
Asl32:
php
asl_32_loop:
.call M16
asl @ax
rol @bx
.call M8
dec @cl
bne @asl_32_loop
plp
rts
; angle in A:16
; result in A:16
GetSin:
asl
bit #0100
bne @negative_sin
tax
lda !binrad_sines_lut,x
bra @exit_get_sin
negative_sin:
and #00ff
tax
lda !binrad_sines_lut,x
eor #ffff
inc
exit_get_sin:
rts
; angle in A:16
; result in A:16
GetCos:
clc
adc #0040
and #00ff
jsr @GetSin
rts
; angle in A:16
; result in A:16
GetSinM7:
asl
bit #0100
bne @negative_m7sin
tax
lda !m7_sines_lut,x
bra @exit_get_m7sin
negative_m7sin:
and #00ff
tax
lda !m7_sines_lut,x
eor #ffff
inc
exit_get_m7sin:
rts
; angle in A:16
; result in A:16
GetCosM7:
clc
adc #0040
and #00ff
jsr @GetSinM7
rts