-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_ring0.htll
More file actions
402 lines (355 loc) · 8.65 KB
/
Copy pathrandom_ring0.htll
File metadata and controls
402 lines (355 loc) · 8.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
; =============================================================
; 1. GLOBAL VARIABLE DEFINITIONS
; =============================================================
; Standard LCG - Safe for bare metal
int lcg_seed := 0
int lcg_multiplier := 1664525
int lcg_increment := 1013904223
int lcg_modulus := 999983
int pos_x := 0
int pos_y := 0
int pos_xx := 0
int STR_main_num := 0
int remainder_val := 0
int current_digit := 0
int actual_str_len := 0
int temp_size := 0
arr func_arr
arr STR_temp_buffer
int range_val := 0
int temp_math_val := 0
int random_result := 0
int final_num := 0
arr pressEnterStr
arr pressEscStr
arr input_bufferr
arr prompt
arr cmd_help
arr cmd_exit
; Command Prefixes
arr cmd_min_pre
arr cmd_max_pre
int num := 1
int num2 := 1
int is_match := 0
int l1 := 0
int l2 := 0
int v1 := 0
int v2 := 0
int i := 0
; Parsing Variables
int start_rand_num := 5
int end_rand_num := 20
int temp_parsed_int := 0
int parse_valid := 0
int digit_val := 0
int digit_count := 0
int prefix_match := 0
; Global params for random to avoid stack pressure
int r_min := 0
int r_max := 0
; =============================================================
; 2. UTILITY FUNCTIONS
; =============================================================
func init_constants() {
; Clear buffers first to claim heap space
input_bufferr.clear
STR_temp_buffer.clear
func_arr.clear
arradd prompt [HTLL-Shell]
prompt.add 62 ; ASCII for '>'
prompt.add 32 ; ASCII for ' '
arradd cmd_help help
arradd cmd_exit exit
; "min-rand=" is 9 characters
arradd cmd_min_pre min-rand=
; "max-rand=" is 9 characters
arradd cmd_max_pre max-rand=
arradd pressEnterStr Press Space To Start...
arradd pressEscStr Press Esc To Restart...
}
func check_if_help() {
is_match := 0
input_bufferr.size
l1 := rax
cmd_help.size
l2 := rax
; GUARD: If input isn't exactly the length of 'help', it's not a match.
if (l1 = l2) {
is_match := 1
Loop, l1 {
input_bufferr.index A_Index
v1 := rax
cmd_help.index A_Index
v2 := rax
if (v1 != v2) {
is_match := 0
}
}
}
}
func check_if_exit() {
is_match := 0
input_bufferr.size
l1 := rax
cmd_exit.size
l2 := rax
; GUARD: If input isn't exactly the length of 'exit', it's not a match.
if (l1 = l2) {
is_match := 1
Loop, l1 {
input_bufferr.index A_Index
v1 := rax
cmd_exit.index A_Index
v2 := rax
if (v1 != v2) {
is_match := 0
}
}
}
}
func parse_num_from_input() {
temp_parsed_int := 0
parse_valid := 0
digit_count := 0
input_bufferr.size
l1 := rax
; Guard: Prefix is 9 chars. Must be at least 10 to have a digit.
if (l1 < 10) {
goto end_parse
}
parse_valid := 1
Loop, l1 {
i := A_Index
; Only start looking for digits AFTER the prefix (index 9)
if (i >= 9) {
input_bufferr.index i
digit_val := rax
; Filter to strictly allow 0-9
if (digit_val >= 48) {
if (digit_val <= 57) {
digit_val -= 48
temp_parsed_int *= 10
temp_parsed_int += digit_val
digit_count++
}
}
}
}
; If no digits found, set as invalid
if (digit_count = 0) {
parse_valid := 0
}
togo end_parse
}
func check_min_command() {
prefix_match := 0
input_bufferr.size
l1 := rax
; GUARD: Input must be at least 9 chars long for the prefix "min-rand="
if (l1 >= 9) {
prefix_match := 1
Loop, 9 {
input_bufferr.index A_Index
v1 := rax
cmd_min_pre.index A_Index
v2 := rax
if (v1 != v2) {
prefix_match := 0
}
}
}
}
func check_max_command() {
prefix_match := 0
input_bufferr.size
l1 := rax
; GUARD: Input must be at least 9 chars long for the prefix "max-rand="
if (l1 >= 9) {
prefix_match := 1
Loop, 9 {
input_bufferr.index A_Index
v1 := rax
cmd_max_pre.index A_Index
v2 := rax
if (v1 != v2) {
prefix_match := 0
}
}
}
}
func echo_input() {
print("Echo: ")
input_bufferr.size
if (rax = 0) {
print("(empty)")
}
Loop, rax {
input_bufferr.index A_Index
print_rax_as_char
}
print("")
}
func INT_To_STR() {
if (STR_main_num = 0) {
func_arr.clear
func_arr.add 48 ; '0'
goto end_stoi
}
STR_temp_buffer.clear
remainder_val := STR_main_num
togo str_extraction_loop
current_digit := remainder_val
current_digit %= 10
current_digit += 48
STR_temp_buffer.add current_digit
remainder_val //= 10
if (remainder_val > 0) {
goto str_extraction_loop
}
func_arr.clear
STR_temp_buffer.size
actual_str_len := rax
Loop, actual_str_len {
temp_size := actual_str_len
temp_size--
temp_size -= A_Index
STR_temp_buffer.index temp_size
func_arr.add rax
}
togo end_stoi
}
func generate_random() {
; Safety guard against math errors
if (r_max <= r_min) {
r_max := r_min
r_max++
}
range_val := r_max
range_val -= r_min
range_val++
; Seed mutation
lcg_seed *= lcg_multiplier
lcg_seed += lcg_increment
lcg_seed %= lcg_modulus
random_result := lcg_seed
random_result %= range_val
random_result += r_min
}
; =============================================================
; 3. MAIN PROGRAM EXECUTION
; =============================================================
main
init_constants()
togo start_start
_htll_clear(1)
pos_x := 28
pressEnterStr.size
Loop, rax {
pressEnterStr.index A_Index
_htll_draw_char(pos_x, 12, rax, 15)
pos_x++
}
draw_all()
togo mainWaitLoop
Loop, 20000 {
}
num++
if (num > 10000) {
num := 1
}
num2++
if (num2 > 10004) {
num2 := 500
}
_htll_get_key()
if (rax = 57) {
goto start_shell
}
goto mainWaitLoop
togo start_shell
; Final seed setup from user interaction timing
lcg_seed := num
lcg_seed *= num2
lcg_seed %= lcg_modulus
if (lcg_seed = 0) {
lcg_seed := 1
}
_htll_clear(1)
draw_all()
print("Welcome to HTLL Shell.")
print("Commands: min-rand= NUM, max-rand= NUM, help, exit")
togo shell_loop
input_bufferr.clear
input input_bufferr, prompt
check_if_exit()
if (is_match = 1) {
goto run_generator
}
check_if_help()
if (is_match = 1) {
print("Set range using min-rand= 10 and max-rand= 100")
print("Type 'exit' to start generator.")
goto shell_loop
}
check_min_command()
if (prefix_match = 1) {
parse_num_from_input()
if (parse_valid = 1) {
start_rand_num := temp_parsed_int
print("Minimum set.")
}
goto shell_loop
}
check_max_command()
if (prefix_match = 1) {
parse_num_from_input()
if (parse_valid = 1) {
end_rand_num := temp_parsed_int
print("Maximum set.")
}
goto shell_loop
}
; Only echo if it didn't match any known command
echo_input()
draw_all()
goto shell_loop
togo run_generator
_htll_clear(1)
draw_all()
pos_xx := 1
Loop, 12 {
pos_y := 3
Loop, 20 {
r_min := start_rand_num
r_max := end_rand_num
generate_random()
final_num := random_result
STR_main_num := final_num
INT_To_STR()
pos_x := pos_xx
func_arr.size
Loop, rax {
func_arr.index A_Index
_htll_draw_char(pos_x, pos_y, rax, 15)
pos_x++
}
pos_y++
}
pos_xx += 6
draw_all()
}
pos_x := 1
pressEscStr.size
Loop, rax {
pressEscStr.index A_Index
_htll_draw_char(pos_x, 24, rax, 15)
pos_x++
}
draw_all()
togo main_esc_loop
_htll_get_key()
if (rax = 1) {
goto start_start
}
goto main_esc_loop