diff options
| -rw-r--r-- | Dice/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | Dice/bin/Dice.8xp | bin | 0 -> 8831 bytes | |||
| -rw-r--r-- | Dice/bin/Dice.bin | bin | 0 -> 8755 bytes | |||
| -rwxr-xr-x | Dice/makefile | 20 | ||||
| -rw-r--r-- | Dice/obj/dice.c.src | 180 | ||||
| -rw-r--r-- | Dice/obj/icon.src | 9 | ||||
| -rw-r--r-- | Dice/src/dice.c | 55 | ||||
| -rw-r--r-- | FibFinder/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | FibFinder/bin/FibFinder.8xp | bin | 0 -> 8171 bytes | |||
| -rw-r--r-- | FibFinder/bin/FibFinder.bin | bin | 0 -> 8095 bytes | |||
| -rwxr-xr-x | FibFinder/makefile | 20 | ||||
| -rw-r--r-- | FibFinder/obj/fib.c.src | 202 | ||||
| -rw-r--r-- | FibFinder/obj/icon.src | 9 | ||||
| -rw-r--r-- | FibFinder/src/fib.c | 46 | ||||
| -rw-r--r-- | MassCalc/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | MassCalc/bin/MassCalc.8xp | bin | 0 -> 8831 bytes | |||
| -rw-r--r-- | MassCalc/bin/MassCalc.bin | bin | 0 -> 8755 bytes | |||
| -rwxr-xr-x | MassCalc/makefile | 20 | ||||
| -rw-r--r-- | MassCalc/obj/icon.src | 9 | ||||
| -rw-r--r-- | MassCalc/obj/main.c.src | 408 | ||||
| -rw-r--r-- | MassCalc/src/main.c | 130 | ||||
| -rw-r--r-- | TempCalc/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | TempCalc/bin/TempCalc.8xp | bin | 0 -> 8825 bytes | |||
| -rw-r--r-- | TempCalc/bin/TempCalc.bin | bin | 0 -> 8749 bytes | |||
| -rwxr-xr-x | TempCalc/makefile | 20 | ||||
| -rw-r--r-- | TempCalc/obj/icon.src | 9 | ||||
| -rw-r--r-- | TempCalc/obj/main.c.src | 348 | ||||
| -rw-r--r-- | TempCalc/src/main.c | 106 | ||||
| -rw-r--r-- | coin/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | coin/bin/Coin.8xp | bin | 0 -> 8041 bytes | |||
| -rw-r--r-- | coin/bin/Coin.bin | bin | 0 -> 7965 bytes | |||
| -rwxr-xr-x | coin/makefile | 20 | ||||
| -rw-r--r-- | coin/obj/coin.c.src | 94 | ||||
| -rw-r--r-- | coin/obj/icon.src | 9 | ||||
| -rw-r--r-- | coin/src/coin.c | 41 | ||||
| -rwxr-xr-x | makefile | 13 | ||||
| -rw-r--r-- | rng/.DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | rng/bin/RNG.8xp | bin | 0 -> 8875 bytes | |||
| -rw-r--r-- | rng/bin/RNG.bin | bin | 0 -> 8799 bytes | |||
| -rwxr-xr-x | rng/makefile | 20 | ||||
| -rw-r--r-- | rng/obj/icon.src | 9 | ||||
| -rw-r--r-- | rng/obj/rng.c.src | 202 | ||||
| -rw-r--r-- | rng/src/rng.c | 52 |
43 files changed, 2051 insertions, 0 deletions
diff --git a/Dice/.DS_Store b/Dice/.DS_Store Binary files differnew file mode 100644 index 0000000..0c36b57 --- /dev/null +++ b/Dice/.DS_Store diff --git a/Dice/bin/Dice.8xp b/Dice/bin/Dice.8xp Binary files differnew file mode 100644 index 0000000..774dc72 --- /dev/null +++ b/Dice/bin/Dice.8xp diff --git a/Dice/bin/Dice.bin b/Dice/bin/Dice.bin Binary files differnew file mode 100644 index 0000000..8fccb59 --- /dev/null +++ b/Dice/bin/Dice.bin diff --git a/Dice/makefile b/Dice/makefile new file mode 100755 index 0000000..77bdc07 --- /dev/null +++ b/Dice/makefile @@ -0,0 +1,20 @@ +# ---------------------------- +# Makefile Options +# ---------------------------- + +NAME ?= Dice +ICON ?= icon.png +DESCRIPTION ?= "Dice Roller" +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/Dice/obj/dice.c.src b/Dice/obj/dice.c.src new file mode 100644 index 0000000..82bfd3c --- /dev/null +++ b/Dice/obj/dice.c.src @@ -0,0 +1,180 @@ + 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 _getInput + push hl + call _diceRoll + push hl + pop de + pop hl + push de + pop hl + ld bc, -1 + or a, a + sbc hl, bc + jq z, BB0_4 + push de + ld hl, L_.str.1 + push hl + call _printf_ + pop hl + 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 _diceRoll +_diceRoll: + ld hl, -4 + call __frameset + ld hl, (ix + 6) + ld de, -1 + or a, a + sbc hl, de + jq nz, BB1_2 + ld hl, -1 + jq BB1_3 +BB1_2: + pea ix + -4 + call _time + pop de + push hl + call _srand + pop hl + call _rand + ld bc, (ix + 6) + call __irems + inc hl +BB1_3: + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .text,"ax",@progbits + public _getInput +_getInput: + ld hl, -30 + call __frameset + ld.sis hl, 0 + ld (ix + -30), l + ld (ix + -29), h + lea hl, ix + -22 + ld (ix + -28), hl +BB2_1: + call _os_GetKey + ld e, l + ld d, h + ld.sis bc, 5 + or a, a + sbc.sis hl, bc + jq z, BB2_4 + ld l, e + ld h, d + ld.sis bc, 9 + or a, a + sbc.sis hl, bc + jq z, BB2_5 + ld a, e + add a, -94 + ld c, (ix + -30) + ld b, (ix + -29) + 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 + -28) + add hl, de + ld (hl), a + inc.sis bc + ld (ix + -30), c + ld (ix + -29), b + ld l, a + rlc l + sbc hl, hl + ld l, a + push hl + ld hl, L_.str.2 + push hl + call _printf_ + pop hl + pop hl + jq BB2_1 +BB2_4: + ld hl, 10 + push hl + pea ix + -25 + ld hl, (ix + -28) + push hl + call _strtol + pop de + pop de + pop de + ld c, 8 + call __ishl + call __ishrs + jq BB2_6 +BB2_5: + ld hl, -1 +BB2_6: + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .rodata,"a",@progbits + private L_.str +L_.str: + db "Dice Roll",012o,"Press Clear to exit",012o,"How many sides?",012o,"Input: ",000o + + section .rodata,"a",@progbits + private L_.str.1 +L_.str.1: + db "",012o,"Output: %d",000o + + section .rodata,"a",@progbits + private L_.str.2 +L_.str.2: + db "%c",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 _srand + extern __irems + extern _printf_ + extern _rand + extern _strtol + extern _os_GetCSC + extern _os_ClrLCD + extern _os_DrawStatusBar + extern _os_HomeUp + extern _time + extern _os_GetKey + extern __ishrs + extern __ishl diff --git a/Dice/obj/icon.src b/Dice/obj/icon.src new file mode 100644 index 0000000..24ec1cb --- /dev/null +++ b/Dice/obj/icon.src @@ -0,0 +1,9 @@ + section .icon + + jp ___prgm_init + db $02 + + public ___description +___description: + db "Dice Roller", 0 +___prgm_init: diff --git a/Dice/src/dice.c b/Dice/src/dice.c new file mode 100644 index 0000000..5aee7b9 --- /dev/null +++ b/Dice/src/dice.c @@ -0,0 +1,55 @@ +#include <tice.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define EnterKey 5 +#define maxline 22 +#define ExitKey 9 +#define ExitCode -1 + +int diceRoll(int sides); +int getInput(void); + +int main(void) +{ + while (true) { + os_ClrHome(); + + printf("Dice Roll\nPress Clear to exit\nHow many sides?\nInput: "); + + int ans = diceRoll(getInput()); + + if (ans == ExitCode) + break; + + printf("\nOutput: %d", ans); + + while (!os_GetCSC()); + } + return 0; +} + +int diceRoll(int sides) +{ + if (sides == ExitCode) + return ExitCode; + time_t t; + srand((unsigned) time(&t)); + return (rand() % sides) + 1; +} + +int getInput(void) +{ + char number[maxline]; + char *ptr; + int16_t key, i = 0, output; + while((key = os_GetKey()) != EnterKey) { + if(key == ExitKey) + return ExitCode; + number[i] = (key - 142) + '0'; + printf("%c", number[i++]); + } + output = strtol(number, &ptr, 10); + return output; +} diff --git a/FibFinder/.DS_Store b/FibFinder/.DS_Store Binary files differnew file mode 100644 index 0000000..0c36b57 --- /dev/null +++ b/FibFinder/.DS_Store diff --git a/FibFinder/bin/FibFinder.8xp b/FibFinder/bin/FibFinder.8xp Binary files differnew file mode 100644 index 0000000..6adf03c --- /dev/null +++ b/FibFinder/bin/FibFinder.8xp diff --git a/FibFinder/bin/FibFinder.bin b/FibFinder/bin/FibFinder.bin Binary files differnew file mode 100644 index 0000000..1354e0b --- /dev/null +++ b/FibFinder/bin/FibFinder.bin 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); +} diff --git a/MassCalc/.DS_Store b/MassCalc/.DS_Store Binary files differnew file mode 100644 index 0000000..0c36b57 --- /dev/null +++ b/MassCalc/.DS_Store diff --git a/MassCalc/bin/MassCalc.8xp b/MassCalc/bin/MassCalc.8xp Binary files differnew file mode 100644 index 0000000..c01251f --- /dev/null +++ b/MassCalc/bin/MassCalc.8xp diff --git a/MassCalc/bin/MassCalc.bin b/MassCalc/bin/MassCalc.bin Binary files differnew file mode 100644 index 0000000..f26c5b0 --- /dev/null +++ b/MassCalc/bin/MassCalc.bin 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; +} + diff --git a/TempCalc/.DS_Store b/TempCalc/.DS_Store Binary files differnew file mode 100644 index 0000000..0c36b57 --- /dev/null +++ b/TempCalc/.DS_Store diff --git a/TempCalc/bin/TempCalc.8xp b/TempCalc/bin/TempCalc.8xp Binary files differnew file mode 100644 index 0000000..a16814c --- /dev/null +++ b/TempCalc/bin/TempCalc.8xp diff --git a/TempCalc/bin/TempCalc.bin b/TempCalc/bin/TempCalc.bin Binary files differnew file mode 100644 index 0000000..f0cb013 --- /dev/null +++ b/TempCalc/bin/TempCalc.bin diff --git a/TempCalc/makefile b/TempCalc/makefile new file mode 100755 index 0000000..cfd1ae5 --- /dev/null +++ b/TempCalc/makefile @@ -0,0 +1,20 @@ +# ---------------------------- +# Makefile Options +# ---------------------------- + +NAME ?= TempCalc +ICON ?= icon.png +DESCRIPTION ?= "Temperature 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/TempCalc/obj/icon.src b/TempCalc/obj/icon.src new file mode 100644 index 0000000..a0a6924 --- /dev/null +++ b/TempCalc/obj/icon.src @@ -0,0 +1,9 @@ + section .icon + + jp ___prgm_init + db $02 + + public ___description +___description: + db "Temperature Converter", 0 +___prgm_init: diff --git a/TempCalc/obj/main.c.src b/TempCalc/obj/main.c.src new file mode 100644 index 0000000..936f4f7 --- /dev/null +++ b/TempCalc/obj/main.c.src @@ -0,0 +1,348 @@ + 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, 147 + 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: + ld iy, -3145600 + call _os_ClrLCD + call _os_HomeUp + call _os_DrawStatusBar + 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, 4 + or a, a + sbc hl, bc + jq c, BB1_2 + ld hl, L_.str.5 + push hl + call _printf_ + pop hl + ld hl, L_.str.6 + ld bc, 0 + ld e, 0 + jq BB1_8 +BB1_2: + ld hl, LJTI1_0 + add hl, de + add hl, de + add hl, de + ld hl, (hl) + jp (hl) +BB1_3: + ld hl, L_.str.1 + push hl + call _printf_ + pop hl + call _getInput + push de + push hl + call _fToC + jq BB1_7 +BB1_4: + ld hl, L_.str.3 + push hl + call _printf_ + pop hl + call _getInput + push de + push hl + call _fToK + jq BB1_7 +BB1_5: + ld hl, L_.str.4 + push hl + call _printf_ + pop hl + call _getInput + push de + push hl + call _kToF + jq BB1_7 +BB1_6: + ld hl, L_.str.2 + push hl + call _printf_ + pop hl + call _getInput + push de + push hl + call _cToF +BB1_7: + push hl + pop bc + pop hl + pop hl + ld hl, L_.str.6 +BB1_8: + push de + push bc + 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_3 + dl BB1_6 + dl BB1_4 + dl BB1_5 + + section .text,"ax",@progbits + public _fToC +_fToC: + call __frameset0 + ld bc, (ix + 6) + ld a, (ix + 9) + or a, a + sbc hl, hl + ld e, -62 + ld iy, 932068 + ld d, 63 + call __fadd + 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 _getInput +_getInput: + ld hl, -29 + call __frameset + ld hl, L_.str.7 + 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.8 + 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 _cToF +_cToF: + call __frameset0 + ld bc, (ix + 6) + ld a, (ix + 9) + ld hl, -1677722 + ld e, 63 + ld iy, 0 + ld d, 66 + call __fmul + lea hl, iy + 0 + ld e, d + call __fadd + push bc + pop hl + ld e, a + pop ix + ret + section .text,"ax",@progbits + + section .text,"ax",@progbits + public _fToK +_fToK: + call __frameset0 + ld hl, (ix + 6) + ld a, (ix + 9) + ld e, a + push de + push hl + call _fToC + push hl + pop bc + ld a, e + pop hl + pop hl + ld hl, -7831552 + ld e, 67 + call __fadd + push bc + pop hl + ld e, a + pop ix + ret + section .text,"ax",@progbits + + section .text,"ax",@progbits + public _kToF +_kToF: + call __frameset0 + ld bc, (ix + 6) + ld a, (ix + 9) + ld hl, -7831552 + ld e, -61 + call __fadd + ld l, a + push hl + push bc + call _cToF + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .rodata,"a",@progbits + private L_.str +L_.str: + db "TempCalc",012o,"Select:",012o,"1. Fahrenheit to Celsius",012o,"2. Celsius to Fahrenheit",012o,"3. Fahrenheit to Kelvin",012o,"4. Kelvin to Fahrenheit",012o,"5. Exit",000o + + section .rodata,"a",@progbits + private L_.str.1 +L_.str.1: + db "Fahrenheit to Celsius",012o,000o + + section .rodata,"a",@progbits + private L_.str.2 +L_.str.2: + db "Celsius to Fahrenheit ",012o,000o + + section .rodata,"a",@progbits + private L_.str.3 +L_.str.3: + db "Fahrenheit to Kelvin",012o,000o + + section .rodata,"a",@progbits + private L_.str.4 +L_.str.4: + db "Kelvin to Fahrenheit ",012o,000o + + section .rodata,"a",@progbits + private L_.str.5 +L_.str.5: + db "Invalid",000o + + section .rodata,"a",@progbits + private L_.str.6 +L_.str.6: + db "",012o,"Output: %f",000o + + section .rodata,"a",@progbits + private L_.str.7 +L_.str.7: + db "Input: ",000o + + section .rodata,"a",@progbits + private L_.str.8 +L_.str.8: + db "%c",000o + + ident "clang version 12.0.0 (https://github.com/jacobly0/llvm-project 170be88120e3aa88c20eea5615ba76b8f1d6c647)" + extern __Unwind_SjLj_Register + extern __frameset + extern __fadd + extern _printf_ + extern _os_ClrLCD + extern _os_DrawStatusBar + extern _os_GetKey + extern __fmul + extern __Unwind_SjLj_Unregister + extern _strtod + extern _os_GetCSC + extern __frameset0 + extern _os_HomeUp diff --git a/TempCalc/src/main.c b/TempCalc/src/main.c new file mode 100644 index 0000000..ff44eca --- /dev/null +++ b/TempCalc/src/main.c @@ -0,0 +1,106 @@ +#include <tice.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define EnterKey 5 +#define maxline 22 + +double fToC(double fahr); +double cToF(double cel); +double fToK(double fahr); +double kToF(double kel); +double getInput(void); +void output(int operation); + +int main(void) +{ + while(true) { + os_ClrHome(); + + printf("TempCalc\nSelect:\n1. Fahrenheit to Celsius\n2. Celsius to Fahrenheit\n3. Fahrenheit to Kelvin\n4. Kelvin to Fahrenheit\n5. Exit"); + uint16_t key = os_GetKey(); + + if(key == 147) + break; + + output(key); + /* Waits for a key press */ + while (!os_GetCSC()); + } + os_ClrHome(); + return 0; +} + +void output(int operation) +{ + os_ClrHome(); + double value = 0.0; + switch(operation) { + case 143: + printf("Fahrenheit to Celsius\n"); + value = fToC(getInput()); + break; + case 144: + printf("Celsius to Fahrenheit \n"); + value = cToF(getInput()); + break; + case 145: + printf("Fahrenheit to Kelvin\n"); + value = fToK(getInput()); + break; + case 146: + printf("Kelvin to Fahrenheit \n"); + value = kToF(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 fToC(double fahr) +{ + double cel = 0; + cel = (5.0 / 9.0) * (fahr - 32.0); + return cel; +} + +double fToK(double fahr) +{ + double kel = 0; + kel = fToC(fahr) + 273; + return kel; +} + +double cToF(double cel) +{ + double fahr = 0; + fahr = (cel * (9.0 / 5.0)) + 32.0; + return fahr; +} + +double kToF(double kel) +{ + double fahr = 0; + fahr = cToF(kel - 273); + return fahr; +} diff --git a/coin/.DS_Store b/coin/.DS_Store Binary files differnew file mode 100644 index 0000000..0c36b57 --- /dev/null +++ b/coin/.DS_Store diff --git a/coin/bin/Coin.8xp b/coin/bin/Coin.8xp Binary files differnew file mode 100644 index 0000000..ce45ea6 --- /dev/null +++ b/coin/bin/Coin.8xp diff --git a/coin/bin/Coin.bin b/coin/bin/Coin.bin Binary files differnew file mode 100644 index 0000000..c318c72 --- /dev/null +++ b/coin/bin/Coin.bin diff --git a/coin/makefile b/coin/makefile new file mode 100755 index 0000000..fe76d81 --- /dev/null +++ b/coin/makefile @@ -0,0 +1,20 @@ +# ---------------------------- +# Makefile Options +# ---------------------------- + +NAME ?= Coin +ICON ?= icon.png +DESCRIPTION ?= "Coin Flip" +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/coin/obj/coin.c.src b/coin/obj/coin.c.src new file mode 100644 index 0000000..b2a3cc3 --- /dev/null +++ b/coin/obj/coin.c.src @@ -0,0 +1,94 @@ + 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.sis de, 9 + or a, a + sbc.sis hl, de + jq z, BB0_8 + call _coinFlip + add hl, bc + or a, a + sbc hl, bc + ld de, L_.str.1 + jq z, BB0_5 + ld de, 1 + or a, a + sbc hl, de + jq nz, BB0_6 + ld de, L_.str.2 +BB0_5: + push de + call _printf_ + pop hl +BB0_6: +BB0_7: + call _os_GetCSC + or a, a + jq z, BB0_7 + jq BB0_1 +BB0_8: + or a, a + sbc hl, hl + ret + section .text,"ax",@progbits + + section .text,"ax",@progbits + public _coinFlip +_coinFlip: + ld hl, -4 + call __frameset + pea ix + -4 + call _time + pop de + push hl + call _srand + pop hl + call _rand + ld bc, 2 + call __irems + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .rodata,"a",@progbits + private L_.str +L_.str: + db "Coin Flip",012o,"Press Enter to Flip",012o,"Press Clear to exit",012o,000o + + section .rodata,"a",@progbits + private L_.str.1 +L_.str.1: + db "Heads",000o + + section .rodata,"a",@progbits + private L_.str.2 +L_.str.2: + db "Tails",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 _srand + extern __irems + extern _printf_ + extern _rand + extern _os_GetCSC + extern _os_ClrLCD + extern _os_DrawStatusBar + extern _os_HomeUp + extern _time + extern _os_GetKey diff --git a/coin/obj/icon.src b/coin/obj/icon.src new file mode 100644 index 0000000..5b3aaab --- /dev/null +++ b/coin/obj/icon.src @@ -0,0 +1,9 @@ + section .icon + + jp ___prgm_init + db $02 + + public ___description +___description: + db "Coin Flip", 0 +___prgm_init: diff --git a/coin/src/coin.c b/coin/src/coin.c new file mode 100644 index 0000000..8c71534 --- /dev/null +++ b/coin/src/coin.c @@ -0,0 +1,41 @@ +#include <tice.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define EnterKey 5 +#define ExitKey 9 + +int coinFlip(void); + +int main() +{ + + while (true) { + os_ClrHome(); + + printf("Coin Flip\nPress Enter to Flip\nPress Clear to exit\n"); + + int key = os_GetKey(); + + if (key == ExitKey) + break; + int coin = coinFlip(); + if (coin == 0) + printf("Heads"); + else if (coin == 1) + printf("Tails"); + + while (!os_GetCSC()); + } + + return 0; +} + +int coinFlip(void) +{ + time_t t; + + srand((unsigned) time(&t)); + return (rand() % 2); +} diff --git a/makefile b/makefile new file mode 100755 index 0000000..db266b5 --- /dev/null +++ b/makefile @@ -0,0 +1,13 @@ +#----------------------------------------------- +# This makefile builds all the example projects +#----------------------------------------------- + +DIRS = $(wildcard */makefile) + +all clean gfx .PHONY: $(DIRS) + +$(DIRS): + $(MAKE) -C $(dir $@) $(MAKECMDGOALS) + +.PHONY: all clean gfx + diff --git a/rng/.DS_Store b/rng/.DS_Store Binary files differnew file mode 100644 index 0000000..0c36b57 --- /dev/null +++ b/rng/.DS_Store diff --git a/rng/bin/RNG.8xp b/rng/bin/RNG.8xp Binary files differnew file mode 100644 index 0000000..9c86c58 --- /dev/null +++ b/rng/bin/RNG.8xp diff --git a/rng/bin/RNG.bin b/rng/bin/RNG.bin Binary files differnew file mode 100644 index 0000000..73c3a0e --- /dev/null +++ b/rng/bin/RNG.bin diff --git a/rng/makefile b/rng/makefile new file mode 100755 index 0000000..4f245cc --- /dev/null +++ b/rng/makefile @@ -0,0 +1,20 @@ +# ---------------------------- +# Makefile Options +# ---------------------------- + +NAME ?= RNG +ICON ?= icon.png +DESCRIPTION ?= "Random Number Generator" +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/rng/obj/icon.src b/rng/obj/icon.src new file mode 100644 index 0000000..27bbc45 --- /dev/null +++ b/rng/obj/icon.src @@ -0,0 +1,9 @@ + section .icon + + jp ___prgm_init + db $02 + + public ___description +___description: + db "Random Number Generator", 0 +___prgm_init: diff --git a/rng/obj/rng.c.src b/rng/obj/rng.c.src new file mode 100644 index 0000000..90a1789 --- /dev/null +++ b/rng/obj/rng.c.src @@ -0,0 +1,202 @@ + section .text,"ax",@progbits + assume adl = 1 + section .text,"ax",@progbits + public _main +_main: + ld hl, -3 + call __frameset +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 _getInput + push hl + pop bc + ld de, -1 + or a, a + sbc hl, de + jq z, BB0_5 + ld hl, L_.str.1 + push hl + ld (ix + -3), bc + call _printf_ + pop hl + call _getInput + push hl + pop de + ld bc, -1 + or a, a + sbc hl, bc + ld hl, (ix + -3) + jq z, BB0_5 + push de + push hl + call _rng + pop de + pop de + push hl + ld hl, L_.str.2 + push hl + call _printf_ + pop hl + pop hl +BB0_4: + call _os_GetCSC + or a, a + jq z, BB0_4 + jq BB0_1 +BB0_5: + or a, a + sbc hl, hl + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .text,"ax",@progbits + public _getInput +_getInput: + ld hl, -30 + call __frameset + ld.sis hl, 0 + ld (ix + -30), l + ld (ix + -29), h + lea hl, ix + -22 + ld (ix + -28), hl +BB1_1: + call _os_GetKey + ld e, l + ld d, h + ld.sis bc, 5 + or a, a + sbc.sis hl, bc + jq z, BB1_4 + ld l, e + ld h, d + ld.sis bc, 9 + or a, a + sbc.sis hl, bc + jq z, BB1_5 + ld a, e + add a, -94 + ld c, (ix + -30) + ld b, (ix + -29) + 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 + -28) + add hl, de + ld (hl), a + inc.sis bc + ld (ix + -30), c + ld (ix + -29), b + ld l, a + rlc l + sbc hl, hl + ld l, a + push hl + ld hl, L_.str.3 + push hl + call _printf_ + pop hl + pop hl + jq BB1_1 +BB1_4: + ld hl, 10 + push hl + pea ix + -25 + ld hl, (ix + -28) + push hl + call _strtol + pop de + pop de + pop de + ld c, 8 + call __ishl + call __ishrs + jq BB1_6 +BB1_5: + ld hl, -1 +BB1_6: + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .text,"ax",@progbits + public _rng +_rng: + ld hl, -4 + call __frameset + pea ix + -4 + call _time + pop de + push hl + call _srand + pop hl + call _rand + push hl + pop de + ld hl, (ix + 9) + ld bc, (ix + 6) + or a, a + sbc hl, bc + push hl + pop bc + ex de, hl + call __irems + ld de, (ix + 6) + add hl, de + ld sp, ix + pop ix + ret + section .text,"ax",@progbits + + section .rodata,"a",@progbits + private L_.str +L_.str: + db "Random Number",012o,"Press Clear to exit",012o,"Minimun: ",000o + + section .rodata,"a",@progbits + private L_.str.1 +L_.str.1: + db "",012o,"Maximum: ",000o + + section .rodata,"a",@progbits + private L_.str.2 +L_.str.2: + db "",012o,"%d",000o + + section .rodata,"a",@progbits + private L_.str.3 +L_.str.3: + db "%c",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 _srand + extern __irems + extern _printf_ + extern _strtol + extern _rand + extern _os_GetCSC + extern _os_ClrLCD + extern _os_DrawStatusBar + extern _os_HomeUp + extern __ishl + extern _os_GetKey + extern __ishrs + extern _time diff --git a/rng/src/rng.c b/rng/src/rng.c new file mode 100644 index 0000000..4243268 --- /dev/null +++ b/rng/src/rng.c @@ -0,0 +1,52 @@ +#include <tice.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define EnterKey 5 +#define maxline 22 +#define ExitKey 9 +#define ExitCode -1 + +int rng(int min, int max); +int getInput(void); + +int main(void) +{ + while (true) { + os_ClrHome(); + + int min, max; + printf("Random Number\nPress Clear to exit\nMinimun: "); + if ((min = getInput()) == ExitCode) + break; + printf("\nMaximum: "); + if ((max = getInput()) == ExitCode) + break; + printf("\n%d", rng(min, max)); + + while (!os_GetCSC()); + } +} + +int getInput(void) +{ + char number[maxline]; + char *ptr; + int16_t key, i = 0, output; + while((key = os_GetKey()) != EnterKey) { + if(key == ExitKey) + return ExitCode; + number[i] = (key - 142) + '0'; + printf("%c", number[i++]); + } + output = strtol(number, &ptr, 10); + return output; +} + +int rng(int min, int max) +{ + time_t t; + srand((unsigned) time(&t)); + return (rand() % (max - min)) + min; +} |
