summaryrefslogtreecommitdiff
path: root/FibFinder
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@simplelittledream.com>2021-08-18 17:31:19 -0400
committerJacob McDonnell <jacob@simplelittledream.com>2021-08-18 17:31:19 -0400
commit9a6959b2700ec54392fb2ffb145bacae66fc2269 (patch)
tree34704cfbbb55e349ab91c09138911f2906e90988 /FibFinder
initial commit
Diffstat (limited to 'FibFinder')
-rw-r--r--FibFinder/.DS_Storebin0 -> 6148 bytes
-rw-r--r--FibFinder/bin/FibFinder.8xpbin0 -> 8171 bytes
-rw-r--r--FibFinder/bin/FibFinder.binbin0 -> 8095 bytes
-rwxr-xr-xFibFinder/makefile20
-rw-r--r--FibFinder/obj/fib.c.src202
-rw-r--r--FibFinder/obj/icon.src9
-rw-r--r--FibFinder/src/fib.c46
7 files changed, 277 insertions, 0 deletions
diff --git a/FibFinder/.DS_Store b/FibFinder/.DS_Store
new file mode 100644
index 0000000..0c36b57
--- /dev/null
+++ b/FibFinder/.DS_Store
Binary files differ
diff --git a/FibFinder/bin/FibFinder.8xp b/FibFinder/bin/FibFinder.8xp
new file mode 100644
index 0000000..6adf03c
--- /dev/null
+++ b/FibFinder/bin/FibFinder.8xp
Binary files differ
diff --git a/FibFinder/bin/FibFinder.bin b/FibFinder/bin/FibFinder.bin
new file mode 100644
index 0000000..1354e0b
--- /dev/null
+++ b/FibFinder/bin/FibFinder.bin
Binary files differ
diff --git a/FibFinder/makefile b/FibFinder/makefile
new file mode 100755
index 0000000..8537a95
--- /dev/null
+++ b/FibFinder/makefile
@@ -0,0 +1,20 @@
+# ----------------------------
+# Makefile Options
+# ----------------------------
+
+NAME ?= FibFinder
+ICON ?= icon.png
+DESCRIPTION ?= "Fibonacci Number Finder"
+COMPRESSED ?= NO
+ARCHIVED ?= NO
+
+CFLAGS ?= -Wall -Wextra -Oz
+CXXFLAGS ?= -Wall -Wextra -Oz
+
+# ----------------------------
+
+ifndef CEDEV
+$(error CEDEV environment path variable is not set)
+endif
+
+include $(CEDEV)/meta/makefile.mk
diff --git a/FibFinder/obj/fib.c.src b/FibFinder/obj/fib.c.src
new file mode 100644
index 0000000..8823860
--- /dev/null
+++ b/FibFinder/obj/fib.c.src
@@ -0,0 +1,202 @@
+ section .text,"ax",@progbits
+ assume adl = 1
+ section .text,"ax",@progbits
+ public _main
+_main:
+ ld hl, -60
+ call __frameset
+ lea hl, ix + -50
+ ld (ix + -60), hl
+BB0_1:
+ ld iy, -3145600
+ call _os_ClrLCD
+ call _os_HomeUp
+ call _os_DrawStatusBar
+ ld hl, L_.str
+ push hl
+ call _printf_
+ pop hl
+ ld.sis hl, 0
+ ld (ix + -57), l
+ ld (ix + -56), h
+BB0_2:
+ call _os_GetKey
+ ld c, l
+ ld b, h
+ ld.sis de, 5
+ or a, a
+ sbc.sis hl, de
+ ld (ix + -55), c
+ ld (ix + -54), b
+ jq z, BB0_5
+ ld l, c
+ ld h, b
+ ld.sis de, 9
+ or a, a
+ sbc.sis hl, de
+ jq z, BB0_7
+ ld l, (ix + -55)
+ ld h, (ix + -54)
+ ld a, l
+ add a, -94
+ ld c, (ix + -57)
+ ld b, (ix + -56)
+ ld e, b
+ ld l, e
+ ld iyl, e
+ rlc l
+ sbc hl, hl
+ push hl
+ pop de
+ ld d, iyl
+ ld e, c
+ ld hl, (ix + -60)
+ add hl, de
+ ld (hl), a
+ inc.sis bc
+ ld (ix + -57), c
+ ld (ix + -56), b
+ ld l, a
+ rlc l
+ sbc hl, hl
+ ld l, a
+ push hl
+ ld hl, L_.str.1
+ push hl
+ call _printf_
+ pop hl
+ pop hl
+ jq BB0_2
+BB0_5:
+ ld hl, 10
+ push hl
+ pea ix + -53
+ ld hl, (ix + -60)
+ push hl
+ call _strtol
+ pop bc
+ pop bc
+ pop bc
+ push de
+ push hl
+ call _fib
+ pop de
+ pop de
+ push hl
+ ld hl, L_.str.2
+ push hl
+ call _printf_
+ pop hl
+ pop hl
+BB0_6:
+ call _os_GetCSC
+ or a, a
+ jq z, BB0_6
+BB0_7:
+ ld l, (ix + -55)
+ ld h, (ix + -54)
+ ld.sis de, 5
+ or a, a
+ sbc.sis hl, de
+ jq z, BB0_1
+ or a, a
+ sbc hl, hl
+ ld sp, ix
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _fib
+_fib:
+ ld hl, -10
+ call __frameset
+ ld hl, (ix + 6)
+ ld a, (ix + 9)
+ ld (ix + -1), a
+ ld de, 1
+ ld (ix + -4), de
+ xor a, a
+ ld bc, 0
+BB1_1:
+ push hl
+ pop iy
+ ld d, (ix + -1)
+ ld e, d
+ call __lcmpzero
+ jq z, BB1_6
+ ld (ix + -7), bc
+ lea hl, iy + 0
+ ld e, d
+ ld bc, 1
+ call __lcmpu
+ jq z, BB1_4
+ ld (ix + -10), iy
+ lea hl, iy + 0
+ ld e, d
+ ld bc, -1
+ ld a, -1
+ call __ladd
+ ld (ix + -1), d
+ push de
+ push hl
+ call _fib
+ push hl
+ pop iy
+ pop hl
+ pop hl
+ ld hl, (ix + -10)
+ ld e, (ix + -1)
+ ld bc, -2
+ ld a, -1
+ call __ladd
+ ld (ix + -1), e
+ ld de, (ix + -7)
+ add iy, de
+ xor a, a
+ lea bc, iy + 0
+ jq BB1_1
+BB1_6:
+ or a, a
+ sbc hl, hl
+ ld (ix + -4), hl
+ jq BB1_5
+BB1_4:
+ ld bc, (ix + -7)
+BB1_5:
+ ld hl, (ix + -4)
+ add hl, bc
+ ld sp, ix
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .rodata,"a",@progbits
+ private L_.str
+L_.str:
+ db "FibFinder",012o,"Press Clear to exit",012o,"Input: ",000o
+
+ section .rodata,"a",@progbits
+ private L_.str.1
+L_.str.1:
+ db "%c",000o
+
+ section .rodata,"a",@progbits
+ private L_.str.2
+L_.str.2:
+ db "",012o,"Output: %d",000o
+
+ ident "clang version 12.0.0 (https://github.com/jacobly0/llvm-project 170be88120e3aa88c20eea5615ba76b8f1d6c647)"
+ extern __Unwind_SjLj_Register
+ extern __Unwind_SjLj_Unregister
+ extern __frameset
+ extern __lcmpzero
+ extern _printf_
+ extern _strtol
+ extern _os_GetCSC
+ extern _os_ClrLCD
+ extern __lcmpu
+ extern _os_DrawStatusBar
+ extern _os_HomeUp
+ extern _os_GetKey
+ extern __ladd
diff --git a/FibFinder/obj/icon.src b/FibFinder/obj/icon.src
new file mode 100644
index 0000000..06a2ac6
--- /dev/null
+++ b/FibFinder/obj/icon.src
@@ -0,0 +1,9 @@
+ section .icon
+
+ jp ___prgm_init
+ db $02
+
+ public ___description
+___description:
+ db "Fibonacci Number Finder", 0
+___prgm_init:
diff --git a/FibFinder/src/fib.c b/FibFinder/src/fib.c
new file mode 100644
index 0000000..d5badb4
--- /dev/null
+++ b/FibFinder/src/fib.c
@@ -0,0 +1,46 @@
+#include <tice.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define EnterKey 5
+#define maxline 50
+#define ExitKey 9
+
+int fib(long num);
+
+int main(void)
+{
+ while(true) {
+ os_ClrHome();
+
+ char number[maxline];
+ char *ptr;
+
+ printf("FibFinder\nPress Clear to exit\nInput: ");
+ int16_t key, i = 0;
+ long output = -1;
+
+ while((key = os_GetKey()) != EnterKey) {
+ if(key == ExitKey)
+ return 0;
+ number[i] = (key - 142) + '0';
+ printf("%c", number[i++]);
+ }
+
+ output = strtol(number, &ptr, 10);
+ printf("\nOutput: %d", fib(output));
+
+ while(!os_GetCSC());
+ }
+ return 0;
+}
+
+int fib(long num)
+{
+ if(num==0)
+ return 0;
+ else if(num==1)
+ return 1;
+ else
+ return fib(num-1) + fib(num-2);
+}