summaryrefslogtreecommitdiff
path: root/MassCalc
diff options
context:
space:
mode:
Diffstat (limited to 'MassCalc')
-rw-r--r--MassCalc/.DS_Storebin0 -> 6148 bytes
-rw-r--r--MassCalc/bin/MassCalc.8xpbin0 -> 8831 bytes
-rw-r--r--MassCalc/bin/MassCalc.binbin0 -> 8755 bytes
-rwxr-xr-xMassCalc/makefile20
-rw-r--r--MassCalc/obj/icon.src9
-rw-r--r--MassCalc/obj/main.c.src408
-rw-r--r--MassCalc/src/main.c130
7 files changed, 567 insertions, 0 deletions
diff --git a/MassCalc/.DS_Store b/MassCalc/.DS_Store
new file mode 100644
index 0000000..0c36b57
--- /dev/null
+++ b/MassCalc/.DS_Store
Binary files differ
diff --git a/MassCalc/bin/MassCalc.8xp b/MassCalc/bin/MassCalc.8xp
new file mode 100644
index 0000000..c01251f
--- /dev/null
+++ b/MassCalc/bin/MassCalc.8xp
Binary files differ
diff --git a/MassCalc/bin/MassCalc.bin b/MassCalc/bin/MassCalc.bin
new file mode 100644
index 0000000..f26c5b0
--- /dev/null
+++ b/MassCalc/bin/MassCalc.bin
Binary files differ
diff --git a/MassCalc/makefile b/MassCalc/makefile
new file mode 100755
index 0000000..e65825e
--- /dev/null
+++ b/MassCalc/makefile
@@ -0,0 +1,20 @@
+# ----------------------------
+# Makefile Options
+# ----------------------------
+
+NAME ?= MassCalc
+ICON ?= icon.png
+DESCRIPTION ?= "Mass Converter"
+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/MassCalc/obj/icon.src b/MassCalc/obj/icon.src
new file mode 100644
index 0000000..f4ece96
--- /dev/null
+++ b/MassCalc/obj/icon.src
@@ -0,0 +1,9 @@
+ section .icon
+
+ jp ___prgm_init
+ db $02
+
+ public ___description
+___description:
+ db "Mass Converter", 0
+___prgm_init:
diff --git a/MassCalc/obj/main.c.src b/MassCalc/obj/main.c.src
new file mode 100644
index 0000000..b2182e4
--- /dev/null
+++ b/MassCalc/obj/main.c.src
@@ -0,0 +1,408 @@
+ section .text,"ax",@progbits
+ assume adl = 1
+ section .text,"ax",@progbits
+ public _main
+_main:
+BB0_1:
+ ld iy, -3145600
+ call _os_ClrLCD
+ call _os_HomeUp
+ call _os_DrawStatusBar
+ ld hl, L_.str
+ push hl
+ call _printf_
+ pop hl
+ call _os_GetKey
+ ld e, l
+ ld d, h
+ ld.sis bc, 149
+ or a, a
+ sbc.sis hl, bc
+ jq z, BB0_4
+ or a, a
+ sbc hl, hl
+ ld l, e
+ ld h, d
+ push hl
+ call _output
+ pop hl
+BB0_3:
+ call _os_GetCSC
+ or a, a
+ jq z, BB0_3
+ jq BB0_1
+BB0_4:
+ or a, a
+ sbc hl, hl
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _output
+_output:
+ call __frameset0
+ ld iy, -3145600
+ call _os_ClrLCD
+ call _os_HomeUp
+ call _os_DrawStatusBar
+ ld de, 143
+ ld hl, (ix + 6)
+ or a, a
+ sbc hl, de
+ push hl
+ pop de
+ ld bc, 6
+ or a, a
+ sbc hl, bc
+ jq c, BB1_3
+ ld hl, L_.str.7
+ push hl
+ call _printf_
+ pop hl
+ ld bc, 0
+ ld e, 0
+ jq BB1_2
+BB1_3:
+ ld hl, LJTI1_0
+ add hl, de
+ add hl, de
+ add hl, de
+ ld hl, (hl)
+ jp (hl)
+BB1_4:
+ ld hl, L_.str.1
+ push hl
+ call _printf_
+ pop hl
+ call _getInput
+ push hl
+ pop bc
+ ld a, e
+ ld hl, -1913901
+ ld e, 67
+ jq BB1_5
+BB1_7:
+ ld hl, L_.str.2
+ push hl
+ call _printf_
+ pop hl
+ call _getInput
+ push hl
+ pop bc
+ ld a, e
+ ld hl, -1913901
+ ld e, 67
+ call __fdiv
+ jq BB1_6
+BB1_8:
+ ld hl, L_.str.3
+ push hl
+ call _printf_
+ pop hl
+ call _getInput
+ push de
+ push hl
+ call _ozToG
+ jq BB1_9
+BB1_10:
+ ld hl, L_.str.4
+ push hl
+ call _printf_
+ pop hl
+ call _getInput
+ push de
+ push hl
+ call _gToOz
+BB1_9:
+ push hl
+ pop bc
+ pop hl
+ pop hl
+ jq BB1_2
+BB1_11:
+ ld hl, L_.str.5
+ push hl
+ call _printf_
+ pop hl
+ call _getInput
+ push hl
+ pop bc
+ ld a, e
+ ld hl, -8388608
+ ld e, 65
+ jq BB1_5
+BB1_12:
+ ld hl, L_.str.6
+ push hl
+ call _printf_
+ pop hl
+ call _getInput
+ push hl
+ pop bc
+ ld a, e
+ ld hl, -8388608
+ ld e, 61
+BB1_5:
+ call __fmul
+BB1_6:
+ ld e, a
+BB1_2:
+ push de
+ push bc
+ ld hl, L_.str.8
+ push hl
+ call _printf_
+ ld sp, ix
+ pop ix
+ ret
+ section .text,"ax",@progbits
+ section .rodata,"a",@progbits
+lJTI1_0:
+ private LJTI1_0
+LJTI1_0:
+ dl BB1_4
+ dl BB1_7
+ dl BB1_8
+ dl BB1_10
+ dl BB1_11
+ dl BB1_12
+
+ section .text,"ax",@progbits
+ public _lbsToG
+_lbsToG:
+ call __frameset0
+ ld bc, (ix + 6)
+ ld a, (ix + 9)
+ ld hl, -1913901
+ ld e, 67
+ call __fmul
+ push bc
+ pop hl
+ ld e, a
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _getInput
+_getInput:
+ ld hl, -29
+ call __frameset
+ ld hl, L_.str.9
+ xor a, a
+ ld (ix + -26), a
+ lea de, ix + -22
+ ld (ix + -29), de
+ push hl
+ call _printf_
+ pop hl
+BB3_1:
+ call _os_GetKey
+ ld a, l
+ sub a, -116
+ cp a, 2
+ jq nc, BB3_2
+ dec l
+ jq BB3_4
+BB3_2:
+ ld a, l
+ cp a, 5
+ jq z, BB3_5
+BB3_4:
+ ld a, l
+ add a, -94
+ ld de, 0
+ ld c, (ix + -26)
+ ld e, c
+ ld hl, (ix + -29)
+ add hl, de
+ ld (hl), a
+ inc c
+ ld (ix + -26), c
+ ld l, a
+ rlc l
+ sbc hl, hl
+ ld l, a
+ push hl
+ ld hl, L_.str.10
+ push hl
+ call _printf_
+ pop hl
+ pop hl
+ jq BB3_1
+BB3_5:
+ ld de, 0
+ ld a, (ix + -26)
+ ld e, a
+ ld bc, (ix + -29)
+ push bc
+ pop hl
+ add hl, de
+ ld (hl), 0
+ pea ix + -25
+ push bc
+ call _strtod
+ ld sp, ix
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _gToLbs
+_gToLbs:
+ call __frameset0
+ ld bc, (ix + 6)
+ ld a, (ix + 9)
+ ld hl, -1913901
+ ld e, 67
+ call __fdiv
+ push bc
+ pop hl
+ ld e, a
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _ozToG
+_ozToG:
+ call __frameset0
+ ld bc, (ix + 6)
+ ld a, (ix + 9)
+ ld hl, -8388608
+ ld e, 61
+ ld iy, -1913901
+ ld d, 67
+ call __fmul
+ lea hl, iy + 0
+ ld e, d
+ call __fmul
+ push bc
+ pop hl
+ ld e, a
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _gToOz
+_gToOz:
+ call __frameset0
+ ld bc, (ix + 6)
+ ld a, (ix + 9)
+ ld hl, -1913901
+ ld e, 67
+ ld iy, -8388608
+ ld d, 65
+ call __fdiv
+ lea hl, iy + 0
+ ld e, d
+ call __fmul
+ push bc
+ pop hl
+ ld e, a
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _lbsToOz
+_lbsToOz:
+ call __frameset0
+ ld bc, (ix + 6)
+ ld a, (ix + 9)
+ ld hl, -8388608
+ ld e, 65
+ call __fmul
+ push bc
+ pop hl
+ ld e, a
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .text,"ax",@progbits
+ public _ozToLbs
+_ozToLbs:
+ call __frameset0
+ ld bc, (ix + 6)
+ ld a, (ix + 9)
+ ld hl, -8388608
+ ld e, 61
+ call __fmul
+ push bc
+ pop hl
+ ld e, a
+ pop ix
+ ret
+ section .text,"ax",@progbits
+
+ section .rodata,"a",@progbits
+ private L_.str
+L_.str:
+ db "MassCalc",012o,"Select:",012o,"1. Pounds to Grams",012o,"2. Grams to Pounds",012o,"3. Ounces to Grams",012o,"4. Grams to Ounces",012o,"5. Pounds to Ounces",012o,"6. Ounces to Pounds",012o,"7. Exit",000o
+
+ section .rodata,"a",@progbits
+ private L_.str.1
+L_.str.1:
+ db "Pounds to Grams",012o,000o
+
+ section .rodata,"a",@progbits
+ private L_.str.2
+L_.str.2:
+ db "Grams to Pounds",012o,000o
+
+ section .rodata,"a",@progbits
+ private L_.str.3
+L_.str.3:
+ db "Ounces to Grams",012o,000o
+
+ section .rodata,"a",@progbits
+ private L_.str.4
+L_.str.4:
+ db "Grams to Ounces",012o,000o
+
+ section .rodata,"a",@progbits
+ private L_.str.5
+L_.str.5:
+ db "Pounds to Ounces",012o,000o
+
+ section .rodata,"a",@progbits
+ private L_.str.6
+L_.str.6:
+ db "Ounces to Pounds",012o,000o
+
+ section .rodata,"a",@progbits
+ private L_.str.7
+L_.str.7:
+ db "Invalid",000o
+
+ section .rodata,"a",@progbits
+ private L_.str.8
+L_.str.8:
+ db "",012o,"Output: %f",000o
+
+ section .rodata,"a",@progbits
+ private L_.str.9
+L_.str.9:
+ db "Input: ",000o
+
+ section .rodata,"a",@progbits
+ private L_.str.10
+L_.str.10:
+ db "%c",000o
+
+ ident "clang version 12.0.0 (https://github.com/jacobly0/llvm-project 170be88120e3aa88c20eea5615ba76b8f1d6c647)"
+ extern __Unwind_SjLj_Register
+ extern __frameset
+ extern _printf_
+ extern _os_ClrLCD
+ extern _os_DrawStatusBar
+ extern _os_GetKey
+ extern __fmul
+ extern __Unwind_SjLj_Unregister
+ extern __fdiv
+ extern _strtod
+ extern _os_GetCSC
+ extern __frameset0
+ extern _os_HomeUp
diff --git a/MassCalc/src/main.c b/MassCalc/src/main.c
new file mode 100644
index 0000000..dd4f952
--- /dev/null
+++ b/MassCalc/src/main.c
@@ -0,0 +1,130 @@
+#include <tice.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define EnterKey 5
+#define maxline 22
+
+double lbsToG(double lbs);
+double gToLbs(double gram);
+double ozToG(double oz);
+double gToOz(double gram);
+double ozToLbs(double oz);
+double lbsToOz(double lbs);
+double getInput(void);
+void output(int operation);
+
+int main(void)
+{
+ while(true) {
+ os_ClrHome();
+
+ printf("MassCalc\nSelect:\n1. Pounds to Grams\n2. Grams to Pounds\n3. Ounces to Grams\n4. Grams to Ounces\n5. Pounds to Ounces\n6. Ounces to Pounds\n7. Exit");
+ uint16_t key = os_GetKey();
+
+ if(key == 149)
+ break;
+
+ output(key);
+ /* Waits for a key press */
+ while (!os_GetCSC());
+ }
+ return 0;
+}
+
+void output(int operation)
+{
+ os_ClrHome();
+ double value = 0.0;
+ switch(operation) {
+ case 143:
+ printf("Pounds to Grams\n");
+ value = lbsToG(getInput());
+ break;
+ case 144:
+ printf("Grams to Pounds\n");
+ value = gToLbs(getInput());
+ break;
+ case 145:
+ printf("Ounces to Grams\n");
+ value = ozToG(getInput());
+ break;
+ case 146:
+ printf("Grams to Ounces\n");
+ value = gToOz(getInput());
+ break;
+ case 147:
+ printf("Pounds to Ounces\n");
+ value = lbsToOz(getInput());
+ break;
+ case 148:
+ printf("Ounces to Pounds\n");
+ value = ozToLbs(getInput());
+ break;
+ default: printf("Invalid");
+ }
+ printf("\nOutput: %f", value);
+}
+
+double getInput(void)
+{
+ uint8_t key, i = 0;
+ char number[maxline];
+ char *eptr;
+ double value = 0.0;
+
+ printf("Input: ");
+ while((key = os_GetKey()) != EnterKey) {
+ if(key == 141 || key == 140)
+ key--;
+ number[i] = (key - 142) + '0';
+ printf("%c", number[i++]);
+ }
+ number[i] = '\0';
+ value = strtod(number, &eptr);
+ return value;
+}
+
+double lbsToG(double lbs)
+{
+ double gram = 0;
+ gram = lbs * 453.59237;
+ return gram;
+}
+
+double gToLbs(double gram)
+{
+ double lbs = 0;
+ lbs = gram / 453.59237;
+ return lbs;
+}
+
+double ozToG(double oz)
+{
+ double gram = 0;
+ gram = lbsToG(ozToLbs(oz));
+ return gram;
+}
+
+double gToOz(double gram)
+{
+ double oz = 0;
+ oz = lbsToOz(gToLbs(gram));
+ return oz;
+}
+
+double lbsToOz(double lbs)
+{
+ double oz = 0;
+ oz = lbs * 16;
+ return oz;
+}
+
+double ozToLbs(double oz)
+{
+ double lbs = 0;
+ lbs = oz / 16;
+ return lbs;
+}
+