Summary Files Commits Branches @commit @diff @stats
path: root / catalan / math.a65
diff options
context:
space:
mode:
1 files changed, 29 insertions, 0 deletions
-rw-r--r--catalan/math.a6529
diff --git a/catalan/math.a65 b/catalan/math.a65
index 434fd8d..7bd850a 100644
--- a/catalan/math.a65
+++ b/catalan/math.a65
@@ -66,5 +66,34 @@ arg .byt 0
subtrahend .byt 0
.)
+; a %= moda_arg
+moda .(
+ ldx arg ; x = arg
+ cpx #1 ; if (x <= 1)
+ bcc r_zero ; return 0
+ beq r_zero
+
+ ora #0 ; Update flags, so they're accurate with the accumulator value
+ beq return ; if (a == 0) return a
+
+ cmp arg ; if (a < arg)
+ bcc return ; return a
+ ldx #0 ; x = 0
+
+loop sec ; do carry = 1
+ sbc arg ; a -= arg + !carry
+ inx ; ++x
+ cmp arg ; while (a >= arg)
+ bcs loop
+
+return rts
+
+r_zero lda #0
+ rts
+
++moda_arg
+arg .byt 0
+.)
+
#endif /* CATALAN_MATH */
// vim: noet ts=9 sw=0 lcs=tab\:\ \