Skip to content

Commit 7a82a0b

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
added fallback for llmulu that does not clobber SP.S
1 parent 75225c7 commit 7a82a0b

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

src/crt/llmulu.src

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
__llmulu:
88
; Really slow
99

10+
.if 1
11+
; clobbers SP.S
1012
push ix
1113
push iy
1214
push af
@@ -74,3 +76,76 @@ __llmulu:
7476
pop iy
7577
pop ix
7678
ret
79+
80+
.else
81+
82+
; fallback routine that does not clobber SP.S
83+
push ix
84+
push iy
85+
push af
86+
87+
ld ix, 0
88+
lea iy, ix - 6
89+
add iy, sp ; cf=1
90+
91+
push de
92+
push hl
93+
push bc
94+
95+
lea hl, iy + 18
96+
ld b, 8
97+
.L.push_loop:
98+
push af
99+
ld a, (hl)
100+
inc hl
101+
or a, a ; cf=0
102+
djnz .L.push_loop
103+
104+
sbc hl, hl
105+
ld e, l
106+
ld d, h
107+
108+
.L.byte_loop:
109+
scf
110+
adc a, a
111+
112+
.L.bit_loop:
113+
push af
114+
add ix, ix
115+
adc hl, hl
116+
ex de, hl
117+
adc hl, hl
118+
ex de, hl
119+
pop af
120+
121+
jr nc, .L.add_end
122+
ld bc, (iy)
123+
add ix, bc
124+
ld bc, (iy + 3)
125+
adc hl, bc
126+
ex de, hl
127+
ld bc, (iy - 3)
128+
adc hl, bc
129+
ex de, hl
130+
.L.add_end:
131+
132+
add a, a
133+
jr nz, .L.bit_loop
134+
135+
pop af
136+
jr nc, .L.byte_loop
137+
138+
ld b, d
139+
ld c, e
140+
ex de, hl
141+
lea hl, ix + 0
142+
143+
pop af
144+
pop af
145+
pop af
146+
pop af
147+
pop iy
148+
pop ix
149+
ret
150+
151+
.endif

0 commit comments

Comments
 (0)