summaryrefslogtreecommitdiff
path: root/rng
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 /rng
initial commit
Diffstat (limited to 'rng')
-rw-r--r--rng/.DS_Storebin0 -> 6148 bytes
-rw-r--r--rng/bin/RNG.8xpbin0 -> 8875 bytes
-rw-r--r--rng/bin/RNG.binbin0 -> 8799 bytes
-rwxr-xr-xrng/makefile20
-rw-r--r--rng/obj/icon.src9
-rw-r--r--rng/obj/rng.c.src202
-rw-r--r--rng/src/rng.c52
7 files changed, 283 insertions, 0 deletions
diff --git a/rng/.DS_Store b/rng/.DS_Store
new file mode 100644
index 0000000..0c36b57
--- /dev/null
+++ b/rng/.DS_Store
Binary files differ
diff --git a/rng/bin/RNG.8xp b/rng/bin/RNG.8xp
new file mode 100644
index 0000000..9c86c58
--- /dev/null
+++ b/rng/bin/RNG.8xp
Binary files differ
diff --git a/rng/bin/RNG.bin b/rng/bin/RNG.bin
new file mode 100644
index 0000000..73c3a0e
--- /dev/null
+++ b/rng/bin/RNG.bin
Binary files differ
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;
+}