Skip to content

Commit dcf8980

Browse files
ZERICO2005adriweb
authored andcommitted
formatted i48 CRT routines
1 parent 5c31b2f commit dcf8980

22 files changed

+598
-580
lines changed

src/crt/i48add.src

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
section .text
99
public __i48add
1010
__i48add:
11-
add hl, bc
12-
ex de, hl
13-
push bc
14-
lea bc, iy
15-
adc hl, bc
16-
pop bc
17-
ex de, hl
11+
add hl, bc
12+
ex de, hl
13+
push bc
14+
lea bc, iy
15+
adc hl, bc
16+
pop bc
17+
ex de, hl
1818
ret

src/crt/i48add_1.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; Performs 48-bit addition
1+
; Performs 48-bit increment
22
;
33
; Returns:
44
; ude:uhl = ude:uhl + 1

src/crt/i48and.src

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,51 @@
88
section .text
99
public __i48and
1010
__i48and:
11-
push af
11+
push af
1212

1313
; Deal with Upper Byte
14-
push hl
15-
push bc
16-
push de
14+
push hl
15+
push bc
16+
push de
1717
scf
18-
sbc hl, hl
19-
add hl, sp ; uhl = &iyu
20-
push iy
21-
22-
ld de, 3
23-
ld a, (hl) ; a = iyu
24-
add hl, de
25-
and a, (hl) ; a &= deu
26-
ld (hl), a ; deu = a
27-
28-
add hl, de
29-
ld a, (hl) ; a = bcu
30-
add hl, de
31-
and a, (hl) ; a &= hlu
32-
ld (hl), a ; hlu = a
18+
sbc hl, hl
19+
add hl, sp ; uhl = &iyu
20+
push iy
21+
22+
ld de, 3
23+
ld a, (hl) ; a = iyu
24+
add hl, de
25+
and a, (hl) ; a &= deu
26+
ld (hl), a ; deu = a
27+
28+
add hl, de
29+
ld a, (hl) ; a = bcu
30+
add hl, de
31+
and a, (hl) ; a &= hlu
32+
ld (hl), a ; hlu = a
3333

3434
; Load values back into registers and process low and high bytes
35-
pop bc
36-
pop de
35+
pop bc
36+
pop de
3737

38-
ld a, d
39-
and a, b ; = iyh
40-
ld d, a
38+
ld a, d
39+
and a, b ; = iyh
40+
ld d, a
4141

42-
ld a, e
43-
and a, c ; = iyl
44-
ld e, a
42+
ld a, e
43+
and a, c ; = iyl
44+
ld e, a
4545

46-
pop bc
47-
pop hl
46+
pop bc
47+
pop hl
4848

49-
ld a, h
50-
and a, b
51-
ld h, a
49+
ld a, h
50+
and a, b
51+
ld h, a
5252

53-
ld a, l
54-
and a, c
55-
ld l, a
53+
ld a, l
54+
and a, c
55+
ld l, a
5656

57-
pop af
57+
pop af
5858
ret

src/crt/i48bswap.src

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
public __i48bswap
1010
__i48bswap:
1111
; Line up the reversed data on the stack
12-
push hl
13-
ld h, e
14-
ld l, d
15-
ex (sp), hl
16-
ld d, l
17-
ld e, h
18-
push de
19-
push hl
12+
push hl
13+
ld h, e
14+
ld l, d
15+
ex (sp), hl
16+
ld d, l
17+
ld e, h
18+
push de
19+
push hl
2020
; -1: hlu
2121
; -2: e
2222
; -3: d
@@ -28,9 +28,9 @@ __i48bswap:
2828
; -9: l
2929

3030
; Misalign the stack and pop into the correct registers
31-
inc sp
32-
inc sp
33-
pop de
34-
pop hl
35-
inc sp
31+
inc sp
32+
inc sp
33+
pop de
34+
pop hl
35+
inc sp
3636
ret

src/crt/i48cmps.src

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
section .text
1313
public __i48cmps
1414
__i48cmps:
15-
push hl
16-
push de
17-
or a, a
18-
sbc hl, bc ; compare hl to bc
19-
ex de, hl ; hl = de
20-
lea de, iy ; de = iy
21-
sbc hl, de ; compare de to iy
22-
pop de
23-
pop hl
15+
push hl
16+
push de
17+
or a, a
18+
sbc hl, bc ; compare hl to bc
19+
ex de, hl ; hl = de
20+
lea de, iy ; de = iy
21+
sbc hl, de ; compare de to iy
22+
pop de
23+
pop hl
2424
ret
25-

src/crt/i48cmpu.src

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
section .text
1313
public __i48cmpu
1414
__i48cmpu:
15-
push hl
16-
or a, a
17-
lea hl, iy
18-
sbc hl, de ; subtract IY - DE, which is the other way around
19-
ccf ; complement carry
20-
pop hl
21-
ret nz
22-
or a, a
23-
sbc hl, bc ; subtract the low parts the normal way
24-
add hl, bc ; causes the same carry, preserves Z
25-
ret ; don't complement carry
15+
push hl
16+
or a, a
17+
lea hl, iy
18+
sbc hl, de ; subtract IY - DE, which is the other way around
19+
ccf ; complement carry
20+
pop hl
21+
ret nz
22+
or a, a
23+
sbc hl, bc ; subtract the low parts the normal way
24+
add hl, bc ; causes the same carry, preserves Z
25+
; don't complement carry
26+
ret

src/crt/i48cmpzero.src

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
section .text
99
public __i48cmpzero
1010
__i48cmpzero:
11-
;check msb's == 0
12-
ex de, hl
13-
add hl, de
14-
or a, a
15-
sbc hl, de ; z set if de = 0, s set if de is negative (z also reset)
16-
ex de, hl
17-
ret nz
18-
;check lsb's == 0
19-
;in this path, de = 0 and carry is reset
20-
sbc hl, de
21-
ret p
22-
;special case if bit 23 is set
23-
inc e ; reset z and s flags
24-
dec de
25-
ret
11+
; check msb's == 0
12+
ex de, hl
13+
add hl, de
14+
or a, a
15+
sbc hl, de ; z set if de = 0, s set if de is negative (z also reset)
16+
ex de, hl
17+
ret nz
18+
; check lsb's == 0
19+
; in this path, de = 0 and carry is reset
20+
sbc hl, de
21+
ret p
22+
; special case if bit 23 is set
23+
inc e ; reset z and s flags
24+
dec de
25+
ret

src/crt/i48divs.src

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
1+
; Performs 48-bit signed division
2+
;
3+
; Returns:
4+
; ude:uhl = ude:uhl / uiy:ubc
5+
16
assume adl=1
27

38
section .text
49
public __i48divs
5-
; Result in ude:uhl
610
__i48divs:
7-
push af
8-
push iy
9-
push bc
11+
push af
12+
push iy
13+
push bc
1014

1115
; divisor sign check
12-
push hl
13-
lea hl, iy
14-
add hl, hl
15-
sbc a, a
16-
call c, __uiyubcNeg
16+
push hl
17+
lea hl, iy
18+
add hl, hl
19+
sbc a, a
20+
call c, __uiyubcNeg
1721

1822
; dividend sign check
19-
ld hl, $800000
20-
add hl, de
21-
pop hl
23+
ld hl, $800000
24+
add hl, de
25+
pop hl
2226
rla
2327
rrca
24-
call c, __i48neg
28+
call c, __i48neg
2529

26-
call __i48dvrmu
30+
call __i48dvrmu
2731

2832
; negate quotient if exactly one of the dividend and divisor is negative
29-
add a, a
30-
call pe, __i48neg
33+
add a, a
34+
call pe, __i48neg
3135

32-
pop bc
33-
pop iy
34-
pop af
36+
pop bc
37+
pop iy
38+
pop af
3539
ret
3640

3741
extern __i48dvrmu
3842
extern __i48neg
39-
extern __uiyubcNeg
43+
extern __uiyubcNeg

src/crt/i48divu.src

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
; Performs 48-bit unsigned division
2+
;
3+
; Returns:
4+
; ude:uhl = ude:uhl / uiy:ubc
5+
16
assume adl=1
27

38
section .text
49
public __i48divu
5-
6-
; Result in ude:uhl
710
__i48divu:
8-
push iy
9-
push bc
11+
push iy
12+
push bc
1013

11-
call __i48dvrmu
14+
call __i48dvrmu
1215

13-
pop bc
14-
pop iy
16+
pop bc
17+
pop iy
1518
ret
1619

17-
extern __i48dvrmu
20+
extern __i48dvrmu

0 commit comments

Comments
 (0)