Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/crt/i48add.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
.assume adl=1

.section .text

.global __i48add
.type __i48add, @function

.global __i48addu_overflow
.type __i48addu_overflow, @function

.global __i48subs_overflow
.type __i48subs_overflow, @function

__i48addu_overflow:
; returned flags:
; NC : no unsigned overflow
; C : unsigned overflow occured
__i48adds_overflow:
; returned flags:
; PO : no signed overflow
; PE : signed overflow occured
__i48add:
; CC: 11 bytes | 12F + 6R + 3W + 1
add hl, bc
Expand Down
22 changes: 22 additions & 0 deletions src/crt/i48adds_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.assume adl=1

.section .text

.global __i48adds_sat
.type __i48adds_sat, @function

__i48adds_sat:
; signed saturated addition
; UDE:UHL = UDE:UHL + UIY:UBC
call __i48adds_overflow
ret po
ex de, hl
add hl, hl
sbc hl, hl
ld de, $800000
ret nc ; negative underflow
; positive overflow
dec de
ret

.extern __i48adds_overflow
18 changes: 18 additions & 0 deletions src/crt/i48addu_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.assume adl=1

.section .text

.global __i48addu_sat
.type __i48addu_sat, @function

__i48addu_sat:
; unsigned saturated addition
; UDE:UHL = UDE:UHL + UIY:UBC
call __i48addu_overflow
ret nc
sbc hl, hl
ex de, hl
sbc hl, hl
ret

.extern __i48addu_overflow
15 changes: 15 additions & 0 deletions src/crt/i48sub.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
.assume adl=1

.section .text

.global __i48sub
.type __i48sub, @function

.global __i48subu_overflow
.type __i48subu_overflow, @function

.global __i48subs_overflow
.type __i48subs_overflow, @function

__i48subu_overflow:
; returned flags:
; NC : no unsigned overflow
; C : unsigned overflow occured
__i48subs_overflow:
; returned flags:
; PO : no signed overflow
; PE : signed overflow occured
__i48sub:
; CC: 13 bytes | 14F + 6R + 3W + 1
or a, a
Expand Down
22 changes: 22 additions & 0 deletions src/crt/i48subs_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.assume adl=1

.section .text

.global __i48subs_sat
.type __i48subs_sat, @function

__i48subs_sat:
; signed saturated subtraction
; UDE:UHL = UDE:UHL - UIY:UBC
call __i48subs_overflow
ret po
ex de, hl
add hl, hl
sbc hl, hl
ld de, $800000
ret nc ; negative underflow
; positive overflow
dec de
ret

.extern __i48subs_overflow
19 changes: 19 additions & 0 deletions src/crt/i48subu_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.assume adl=1

.section .text

.global __i48subu_sat
.type __i48subu_sat, @function

__i48subu_sat:
; unsigned saturated subtraction
; UDE:UHL = UDE:UHL - UIY:UBC
call __i48subu_overflow
ret nc
or a, a
sbc hl, hl
ex de, hl
sbc hl, hl
ret

.extern __i48subu_overflow
18 changes: 18 additions & 0 deletions src/crt/iadds_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.assume adl=1

.section .text

.global __iadds_sat
.type __iadds_sat, @function

__iadds_sat:
; signed saturated addition
; UHL = UHL + UBC
or a, a
adc hl, bc
ret po
ld hl, $7FFFFF
ret m ; positive overflow
; negative underflow
inc hl
ret
14 changes: 14 additions & 0 deletions src/crt/iaddu_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.assume adl=1

.section .text

.global __iaddu_sat
.type __iaddu_sat, @function

__iaddu_sat:
; unsigned saturated addition
; UHL = UHL + UBC
add hl, bc
ret nc
sbc hl, hl
ret
18 changes: 18 additions & 0 deletions src/crt/isubs_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.assume adl=1

.section .text

.global __isubs_sat
.type __isubs_sat, @function

__isubs_sat:
; signed saturated subtraction
; HL = HL - BC
or a, a
sbc hl, bc
ret po
ld hl, $800000
ret p ; negative underflow
; positive overflow
inc hl
ret
16 changes: 16 additions & 0 deletions src/crt/isubu_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.assume adl=1

.section .text

.global __isubu_sat
.type __isubu_sat, @function

__isubu_sat:
; unsigned saturated subtraction
; UHL = UHL - UBC
or a, a
sbc hl, bc
ret nc
or a, a
sbc hl, hl
ret
24 changes: 24 additions & 0 deletions src/crt/ladd_overflow.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.assume adl=1

.section .text

.global __laddu_overflow
.type __laddu_overflow, @function

.global __ladds_overflow
.type __ladds_overflow, @function

__laddu_overflow:
; NC : no unsigned overflow
; C : unsigned overflow occured
__ladds_overflow:
; PO : no signed overflow
; PE : signed overflow occured
push bc
add hl, bc
ld c, a
adc a, e
ld e, a
ld a, c
pop bc
ret
21 changes: 21 additions & 0 deletions src/crt/ladds_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.assume adl=1

.section .text

.global __ladds_sat
.type __ladds_sat, @function

__ladds_sat:
; signed saturated addition
; E:UHL = E:UHL + A:UBC
call __ladds_overflow
ret po
sla e
sbc hl, hl
ld e, $80
ret nc ; negative underflow
; positive overflow
dec e
ret

.extern __ladds_overflow
17 changes: 17 additions & 0 deletions src/crt/laddu_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.assume adl=1

.section .text

.global __laddu_sat
.type __laddu_sat, @function

__laddu_sat:
; unsigned saturated addition
; E:UHL = E:UHL + A:UBC
call __laddu_overflow
ret nc
sbc hl, hl
ld e, l
ret

.extern __laddu_overflow
34 changes: 34 additions & 0 deletions src/crt/lladd_overflow.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.assume adl=1

.section .text

.global __lladdu_overflow
.type __lladdu_overflow, @function

.global __lladds_overflow
.type __lladds_overflow, @function

__lladdu_overflow:
; NC : no unsigned overflow
; C : unsigned overflow occured
__lladds_overflow:
; PO : no signed overflow
; PE : signed overflow
push iy
ld iy, 0
add iy, sp
push bc
ld bc, (iy + 6)
add hl, bc
ex de, hl
ld bc, (iy + 9)
adc hl, bc
ex de, hl
ex (sp), hl
ld bc, (iy + 12)
adc.s hl, bc
ld c, l
ld b, h
pop hl
pop iy
ret
24 changes: 24 additions & 0 deletions src/crt/lladds_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.assume adl=1

.section .text

.global __lladds_sat
.type __lladds_sat, @function

__lladds_sat:
; signed saturated addition
; BC:UDE:UHL = BC:UDE:UHL + (SP)
call __lladds_overflow
ret po
sla b
sbc hl, hl
ex de, hl
sbc hl, hl
ld c, l
ld b, $80
ret nc ; negative underflow
; positive overflow
dec b
ret

.extern __lladds_overflow
20 changes: 20 additions & 0 deletions src/crt/lladdu_sat.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.assume adl=1

.section .text

.global __lladdu_sat
.type __lladdu_sat, @function

__lladdu_sat:
; unsigned saturated addition
; BC:UDE:UHL = BC:UDE:UHL + (SP)
call __lladdu_overflow
ret nc
sbc hl, hl
ex de, hl
sbc hl, hl
ld b, l
ld c, l
ret

.extern __lladdu_overflow
34 changes: 34 additions & 0 deletions src/crt/llsub_overflow.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.assume adl=1

.section .text

.global __lladdu_overflow
.type __lladdu_overflow, @function

.global __lladds_overflow
.type __lladds_overflow, @function

__lladdu_overflow:
; NC : no unsigned overflow
; C : unsigned overflow occured
__lladds_overflow:
; PO : no signed overflow
; PE : signed overflow occured
push iy
ld iy, 0
add iy, sp
push bc
ld bc, (iy + 6)
sbc hl, bc
ex de, hl
ld bc, (iy + 9)
sbc hl, bc
ex de, hl
ex (sp), hl
ld bc, (iy + 12)
sbc.s hl, bc
ld c, l
ld b, h
pop hl
pop iy
ret
Loading