mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2025-02-11 15:32:38 +00:00
Implement lldiv and imaxdiv functions.
These do 64-bit division and return a struct with the quotient and remainder.
This commit is contained in:
parent
d1d0358e4b
commit
b072f5d042
34
stdlib.asm
34
stdlib.asm
@ -534,6 +534,40 @@ lb1 lla addr,div_t return the result
|
|||||||
div_t ds 8
|
div_t ds 8
|
||||||
end
|
end
|
||||||
|
|
||||||
|
****************************************************************
|
||||||
|
*
|
||||||
|
* lldiv_t lldiv(long long n, long long d)
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* n - numerator
|
||||||
|
* d - denominator
|
||||||
|
*
|
||||||
|
* Outputs:
|
||||||
|
* lldiv_t - contains result & remainder
|
||||||
|
*
|
||||||
|
****************************************************************
|
||||||
|
*
|
||||||
|
lldiv start
|
||||||
|
imaxdiv entry
|
||||||
|
addr equ 1
|
||||||
|
|
||||||
|
csubroutine (8:n,8:d),4
|
||||||
|
phb use local addressing
|
||||||
|
phk
|
||||||
|
plb
|
||||||
|
ph8 n do the divide
|
||||||
|
ph8 d
|
||||||
|
jsl ~CDIV8
|
||||||
|
pl8 lldiv_t
|
||||||
|
pl8 lldiv_t+8
|
||||||
|
lla addr,lldiv_t return the result
|
||||||
|
plb
|
||||||
|
|
||||||
|
creturn 4:addr
|
||||||
|
|
||||||
|
lldiv_t ds 16
|
||||||
|
end
|
||||||
|
|
||||||
****************************************************************
|
****************************************************************
|
||||||
*
|
*
|
||||||
* void qsort(base, count, size, compar)
|
* void qsort(base, count, size, compar)
|
||||||
|
104
stdlib.macros
104
stdlib.macros
@ -585,3 +585,107 @@
|
|||||||
DC I4'&DCB'
|
DC I4'&DCB'
|
||||||
~RESTM
|
~RESTM
|
||||||
MEND
|
MEND
|
||||||
|
macro
|
||||||
|
&l ph8 &n1
|
||||||
|
lclc &c
|
||||||
|
&l anop
|
||||||
|
&c amid &n1,1,1
|
||||||
|
aif s:longa=1,.a
|
||||||
|
rep #%00100000
|
||||||
|
.a
|
||||||
|
aif "&c"="#",.d
|
||||||
|
aif "&c"="[",.b
|
||||||
|
aif "&c"<>"{",.c
|
||||||
|
&c amid &n1,l:&n1,1
|
||||||
|
aif "&c"<>"}",.g
|
||||||
|
&n1 amid &n1,2,l:&n1-2
|
||||||
|
&n1 setc (&n1)
|
||||||
|
.b
|
||||||
|
ldy #6
|
||||||
|
~&SYSCNT lda &n1,y
|
||||||
|
pha
|
||||||
|
dey
|
||||||
|
dey
|
||||||
|
bpl ~&SYSCNT
|
||||||
|
ago .e
|
||||||
|
.c
|
||||||
|
ldx #6
|
||||||
|
~&SYSCNT lda &n1,x
|
||||||
|
pha
|
||||||
|
dex
|
||||||
|
dex
|
||||||
|
bpl ~&SYSCNT
|
||||||
|
ago .e
|
||||||
|
.d
|
||||||
|
&n1 amid &n1,2,l:&n1-1
|
||||||
|
bra ~b&SYSCNT
|
||||||
|
~a&SYSCNT dc i8"&n1"
|
||||||
|
~b&SYSCNT ldx #6
|
||||||
|
~c&SYSCNT lda ~a&SYSCNT,x
|
||||||
|
pha
|
||||||
|
dex
|
||||||
|
dex
|
||||||
|
bpl ~c&SYSCNT
|
||||||
|
.e
|
||||||
|
aif s:longa=1,.f
|
||||||
|
sep #%00100000
|
||||||
|
.f
|
||||||
|
mexit
|
||||||
|
.g
|
||||||
|
mnote "Missing closing '}'",16
|
||||||
|
mend
|
||||||
|
macro
|
||||||
|
&l pl8 &n1
|
||||||
|
lclc &c
|
||||||
|
&l anop
|
||||||
|
aif s:longa=1,.a
|
||||||
|
rep #%00100000
|
||||||
|
.a
|
||||||
|
&c amid &n1,1,1
|
||||||
|
aif "&c"<>"{",.b
|
||||||
|
&c amid &n1,l:&n1,1
|
||||||
|
aif "&c"<>"}",.f
|
||||||
|
&n1 amid &n1,2,l:&n1-2
|
||||||
|
pla
|
||||||
|
sta (&n1)
|
||||||
|
ldy #2
|
||||||
|
pla
|
||||||
|
sta (&n1),y
|
||||||
|
ldy #4
|
||||||
|
pla
|
||||||
|
sta (&n1),y
|
||||||
|
ldy #6
|
||||||
|
pla
|
||||||
|
sta (&n1),y
|
||||||
|
ago .d
|
||||||
|
.b
|
||||||
|
aif "&c"<>"[",.c
|
||||||
|
pla
|
||||||
|
sta &n1
|
||||||
|
ldy #2
|
||||||
|
pla
|
||||||
|
sta &n1,y
|
||||||
|
ldy #4
|
||||||
|
pla
|
||||||
|
sta &n1,y
|
||||||
|
ldy #6
|
||||||
|
pla
|
||||||
|
sta &n1,y
|
||||||
|
ago .d
|
||||||
|
.c
|
||||||
|
pla
|
||||||
|
sta &n1
|
||||||
|
pla
|
||||||
|
sta &n1+2
|
||||||
|
pla
|
||||||
|
sta &n1+4
|
||||||
|
pla
|
||||||
|
sta &n1+6
|
||||||
|
.d
|
||||||
|
aif s:longa=1,.e
|
||||||
|
sep #%00100000
|
||||||
|
.e
|
||||||
|
mexit
|
||||||
|
.f
|
||||||
|
mnote "Missing closing '}'",16
|
||||||
|
mend
|
||||||
|
Loading…
x
Reference in New Issue
Block a user