+++ /dev/null
-| Run-time start off for ccv1 on the Physics 6809
-.globl _edata
-.globl _main
-| Initialize stack
- lds #/1000
- ldx #_edata | clear all of memory
-l2: clr (x)+
- cmpx #/0fff
- bne l2
-| Circumvent EPROM bug
- ldx #/ff3b
- ldb #6
-l1: pshs x
- decb
- bne l1
-| clear everything so that start conds are
-| always same
- clra
- clrb
- tfr a,dp
- tfr d,x
- tfr d,y
- tfr d,u
- jsr _main
- jmp /fc00
--- /dev/null
+| csa09 Small C v1 comparison support
+| All are dyadic except for lneg.
+.globl __eq
+.globl __ne
+.globl __lt
+.globl __le
+.globl __gt
+.globl __ge
+.globl __ult
+.globl __ule
+.globl __ugt
+.globl __uge
+.globl __lneg
+.globl __bool
+
+__eq: cmpd 2,s
+ lbeq true
+ lbra false
+
+__ne: cmpd 2,s
+ lbne true
+ lbra false
+
+__lt: cmpd 2,s
+ bgt true
+ bra false
+
+__le: cmpd 2,s
+ bge true
+ bra false
+
+__gt: cmpd 2,s
+ blt true
+ bra false
+
+__ge: cmpd 2,s
+ ble true
+ bra false
+
+__ult: cmpd 2,s
+ bhi true
+ bra false
+
+__ule: cmpd 2,s
+ bhs true
+ bra false
+
+__ugt: cmpd 2,s
+ blo true
+ bra false
+
+__uge: cmpd 2,s
+ bls true
+ bra false
+
+__lneg: cmpd #0
+ beq ltrue
+ ldd #0
+ rts
+ltrue: ldd #1
+ rts
+
+__bool: bsr __lneg
+ bra __lneg
+
+true: ldd #1
+ ldx ,s
+ leas 4,s
+ jmp ,x
+
+false: clra
+ clrb
+ ldx ,s
+ leas 4,s
+ jmp ,x
+++ /dev/null
-| csa09 Small C v1 comparison support
-| All are dyadic except for lneg.
-.globl eq
-.globl ne
-.globl lt
-.globl le
-.globl gt
-.globl ge
-.globl ult
-.globl ule
-.globl ugt
-.globl uge
-.globl lneg
-.globl bool
-.globl _eend,_edata,_etext
-.globl _Xstktop,_brkend
-
-eq: cmpd 2(s)
- lbeq true
- lbra false
-
-ne: cmpd 2(s)
- lbne true
- lbra false
-
-lt: cmpd 2(s)
- bgt true
- bra false
-
-le: cmpd 2(s)
- bge true
- bra false
-
-gt: cmpd 2(s)
- blt true
- bra false
-
-ge: cmpd 2(s)
- ble true
- bra false
-
-ult: cmpd 2(s)
- bhi true
- bra false
-
-ule: cmpd 2(s)
- bhs true
- bra false
-
-ugt: cmpd 2(s)
- blo true
- bra false
-
-uge: cmpd 2(s)
- bls true
- bra false
-
-lneg: cmpd #0
- beq ltrue
- ldd #0
- rts
-ltrue: ldd #1
- rts
-
-bool: bsr lneg
- bra lneg
-
-true: ldd #1
- ldx (s)
- leas 4(s)
- jmp (x)
-
-false: clra
- clrb
- ldx (s)
- leas 4(s)
- jmp (x)
-_Xstktop: tfr s,d
- rts
-_etext = .
- .bss
-_eend = .
- .data
-_brkend: .wval _eend
-_edata = .
+++ /dev/null
-| Small C v1 exit routine (physics computer)
-.globl _exit
-_exit: jmp /fc00
+++ /dev/null
-| MC6809 Concurrent Euclid fault codes
-ASSERTFAIL = 0
-RANGECHECK = 1
-CASERANGE = 2
-| fault codes for runtime routines
-OUTOFSPACE = 20
-.globl ASSERTFAIL
-.globl RANGECHECK
-.globl CASERANGE
-.globl OUTOFSPACE
+++ /dev/null
-| Small C v1 io (putchar) for physics machine
-.globl _putchar
-_putchar=.
- lda /9000
- bita #2
- beq _putchar
- lda 3(s)
- sta /9001
- cmpa #10.
- bne out
- ldd #13.
- pshs d
- lbsr _putchar
- leas 2(s)
-out: rts
-
-.globl _getchar
-_getchar=.
- lda /9000
- bita #1
- beq _getchar
- ldb /9001
- clra
- andb #/7F
- cmpb #04
- bne noteot
- ldd #-1
-noteot: rts
| if result (from mod) should be negative.
|
|
-.globl mrabs
- left=8.
- right=4.
- sign=3.
-mrabs: clr sign(s)
- ldd left(s)
+.globl __mrabs
+; left=8.
+; right=4.
+; sign=3.
+__mrabs:clr 3,s
+ ldd 8,s
bge tryr
nega
negb
sbca #0
- std left(s)
- inc sign(s)
-tryr: ldd right(s)
+ std 8,s
+ inc 3,s
+tryr: ldd 4,s
bge done
nega
negb
sbca #0
- std right(s)
+ std 4,s
done: rts
| if result (from divide) should be negative.
|
|
-.globl prabs
- left=8.
- right=4.
- sign=3.
-prabs: clr sign(s)
- ldd left(s)
+.globl __prabs
+| left=8.
+| right=4.
+| sign=3.
+__prabs:clr 3,s
+ ldd 8,s
bge tryr
nega
negb
sbca #0
- std left(s)
- inc sign(s)
-tryr: ldd right(s)
+ std 8,s
+ inc 3,s
+tryr: ldd 4,s
bge done
nega
negb
sbca #0
- dec sign(s)
- std right(s)
+ dec 3,s
+ std 4,s
done: rts
--- /dev/null
+| signed divide
+| calling: (left / right)
+| push left
+| ldd right
+| jsr sdiv
+| result in d, arg popped.
+|
+| left=6
+| right=2
+| sign=1
+| count=0
+| return=4
+| CARRY=1
+.globl __sdiv,__div
+.globl __prabs
+__sdiv: leas -4,s
+ std 2,s
+ bne nozero
+ ldd #8 ; SIGFPE
+ pshs d,x ; need a dummy
+ ldx #0
+ ldd #39 ; kill
+ swi ; kill(0,SIGFPE)
+ puls d,x
+ rts
+;
+; FIXME - self signal
+;
+
+nozero: jsr __prabs
+__div: clr 0,s ; prescale divisor
+ inc 0,s
+mscl: inc 0,s
+ aslb
+ rola
+ bpl mscl
+ std 2,s
+ ldd 6,s
+ clr 6,s
+ clr 6+1,s
+div1: subd 2,s ; check subtract
+ bcc div2
+ addd 2,s
+ andcc #~1
+ bra div3
+div2: orcc #1
+div3: rol 6+1,s ; roll in carry
+ rol 6,s
+ lsr 2,s
+ ror 2+1,s
+ dec 0,s
+ bne div1
+ ldd 6,s
+ tst 1,s ; sign fiddle
+ beq nochg
+ nega
+ negb
+ sbca #0
+nochg: std 2,s ; move return addr
+ ldd 4,s
+ std 6,s
+ ldd 2,s
+ leas 6,s
+ rts
+++ /dev/null
-| signed divide
-| calling: (left / right)
-| push left
-| ldd right
-| jsr sdiv
-| result in d, arg popped.
-|
- left=6
- right=2
- sign=1
- count=0
- return=4
- CARRY=1
-.globl sdiv,div,ASSERTFAIL
-.globl prabs
-sdiv: leas -4(s)
- std right(s)
- bne nozero
- swi2
- .byte ASSERTFAIL
-nozero: jsr prabs
-div: clr count(s) | prescale divisor
- inc count(s)
-mscl: inc count(s)
- aslb
- rola
- bpl mscl
- std right(s)
- ldd left(s)
- clr left(s)
- clr left+1 <tel:+1>(s)
-div1: subd right(s) | check subtract
- bcc div2
- addd right(s)
- andcc #~CARRY
- bra div3
-div2: orcc #CARRY
-div3: rol left+1 <tel:+1>(s) | roll in carry
- rol left(s)
- lsr right(s)
- ror right+1 <tel:+1>(s)
- dec count(s)
- bne div1
- ldd left(s)
- tst sign(s) | sign fiddle
- beq nochg
- nega
- negb
- sbca #0
-nochg: std right(s) | move return addr
- ldd return(s)
- std left(s)
- ldd right(s)
- leas 6(s)
- rts
| Shift support for Small C v1 sa09
-.globl asr
-asr: tstb
+.globl __asr
+__asr: tstb
bge okr
negb
- bra asl
+ bra __asl
okr: incb
pshs b
- ldd 3(s)
-asrl: dec (s)
+ ldd 3,s
+asrl: dec ,s
beq return
asra
rorb
bra asrl
-.globl asl
-asl: tstb
+.globl __asl
+__asl: tstb
bge okl
negb
- bra asr
+ bra __asr
okl: incb
pshs b
- ldd 3(s)
-asll: dec (s)
+ ldd 3,s
+asll: dec ,s
beq return
aslb
rola
bra asll
-return: ldx 1(s)
- leas 5(s)
- jmp (x)
+return: ldx 1,s
+ leas 5,s
+ jmp ,x
--- /dev/null
+| signed mod
+| calling: (left / right)
+| push left
+| ldd right
+| jsr smod
+| result in d, arg popped.
+|
+| left=6
+| right=2
+| sign=1
+| count=0
+| return=4
+| CARRY=1
+.globl __smod,__mod,ASSERTFAIL
+.globl __mrabs
+__smod: leas -4,s
+ std 2,s
+ bne nozero
+ ldd #8 ; SIGFPE
+ pshs d,x ; need a dummy
+ ldd #39 ; sigkill
+ swi
+ puls d,x
+ rts
+nozero: jsr __mrabs
+__mod: clr 0,s ; prescale divisor
+ inc 0,s
+mscl: inc 0,s
+ aslb
+ rola
+ bpl mscl
+ std 2,s
+ ldd 6,s
+ clr 6,s
+ clr 6+1,s
+mod1: subd 2,s ; check subtract
+ bcc mod2
+ addd 2,s
+ andcc #~1
+ bra mod3
+mod2: orcc #1
+mod3: rol 6+1,s ; roll in carry
+ rol 6,s
+ lsr 2,s
+ ror 2+1,s
+ dec 0,s
+ bne mod1
+ tst 1,s ; sign fiddle
+ beq nochg
+ nega
+ negb
+ sbca #0
+nochg: std 2,s ; move return addr
+ ldd 4,s
+ std 6,s
+ ldd 2,s
+ leas 6,s
+ rts
+++ /dev/null
-| signed mod
-| calling: (left / right)
-| push left
-| ldd right
-| jsr smod
-| result in d, arg popped.
-|
- left=6
- right=2
- sign=1
- count=0
- return=4
- CARRY=1
-.globl smod,mod,ASSERTFAIL
-.globl mrabs
-smod: leas -4(s)
- std right(s)
- bne nozero
- swi2
- .byte ASSERTFAIL
-nozero: jsr mrabs
-mod: clr count(s) | prescale divisor
- inc count(s)
-mscl: inc count(s)
- aslb
- rola
- bpl mscl
- std right(s)
- ldd left(s)
- clr left(s)
- clr left+1 <tel:+1>(s)
-mod1: subd right(s) | check subtract
- bcc mod2
- addd right(s)
- andcc #~CARRY
- bra mod3
-mod2: orcc #CARRY
-mod3: rol left+1 <tel:+1>(s) | roll in carry
- rol left(s)
- lsr right(s)
- ror right+1 <tel:+1>(s)
- dec count(s)
- bne mod1
- tst sign(s) | sign fiddle
- beq nochg
- nega
- negb
- sbca #0
-nochg: std right(s) | move return addr
- ldd return(s)
- std left(s)
- ldd right(s)
- leas 6(s)
- rts
--- /dev/null
+| signed/unsigned multiply
+| calling (left * right)
+| push left
+| ldd right
+| jsr [u|s]mul (same entry point)
+| result in d, stack is popped
+.globl __smul,__umul
+__smul:
+__umul:
+ pshs d
+ lda 2+2,s
+ mul ; left msb * right lsb
+ pshs b ; save high order
+ ldb -1+3,s ; right lsb
+ lda 3+3,s ; left lsb
+ mul
+ pshs d
+ lda 3+5,s ; left lsb
+ ldb -2+5,s ; right msb
+ beq small ; is zero?
+ mul ; no, gotta do it too
+ tfr b,a
+ clrb
+ addd ,s++ ; partial prod
+ bra big
+small: puls d ; aha! don't need third mul
+big: adda ,s+
+ pshs d
+ ldd 4,s ; rearrange return address
+ std 6,s
+ puls d
+ leas 4,s
+ rts
+++ /dev/null
-| signed/unsigned multiply
-| calling (left * right)
-| push left
-| ldd right
-| jsr [u|s]mul (same entry point)
-| result in d, stack is popped
-.globl smul,umul
-smul=.
-umul: pshs d
- lda 2+2 <tel:+2>(s)
- mul | left msb * right lsb
- pshs b | save high order
- ldb -1+3 <tel:+3>(s) | right lsb
- lda 3+3 <tel:+3>(s) | left lsb
- mul
- pshs d
- lda 3+5 <tel:+5>(s) | left lsb
- ldb -2+5 <tel:+5>(s) | right msb
- beq small | is zero?
- mul | no, gotta do it too
- tfr b,a
- clrb
- addd (s)++ | partial prod
- bra big
-small: puls d | aha! don't need third mul
-big: adda (s)+
- pshs d
- ldd 4(s) | rearrange return address
- std 6(s)
- puls d
- leas 4(s)
- rts