Skip to content

Commit 905a5b9

Browse files
committed
feat: add random.bas library
1 parent 6b33360 commit 905a5b9

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
' ----------------------------------------------------------------
2+
' This file is released under the MIT License
3+
'
4+
' Copyleft (k) 2025
5+
' by Jose Rodriguez-Rosa (a.k.a. Boriel) <http://www.boriel.com>
6+
' ----------------------------------------------------------------
7+
8+
#pragma once
9+
#pragma push(case_insensitive)
10+
#pragma case_insensitive = TRUE
11+
12+
function fastcall randInt() as ULong ' Returns a random ULong
13+
asm
14+
push namespace core
15+
call RAND
16+
pop namespace
17+
end asm
18+
end function
19+
20+
21+
Function fastcall randFixed() as Fixed ' Returns a random Fixed
22+
Asm
23+
push namespace core
24+
call RAND
25+
pop namespace
26+
End Asm
27+
End Function
28+
29+
30+
Function fastcall randomLimit(limit as uByte) as uByte
31+
Asm
32+
push namespace core
33+
PROC
34+
and a
35+
ret z ; Input zero, output zero.
36+
ld b, a ; Save A
37+
ld c,255
38+
1:
39+
rla
40+
jr c, 2f
41+
rr c
42+
jp 1b ; loop back until we find a bit.
43+
2:
44+
push bc
45+
call RAND
46+
pop bc
47+
and c
48+
cp b
49+
ret z
50+
jr nc, 2b
51+
ENDP
52+
pop namespace
53+
End Asm
54+
End Function
55+
56+
#pragma pop(case_insensitive)
57+
#require "random.asm"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
' ----------------------------------------------------------------
2+
' This file is released under the MIT License
3+
'
4+
' Copyleft (k) 2025
5+
' by Jose Rodriguez-Rosa (a.k.a. Boriel) <http://www.boriel.com>
6+
' ----------------------------------------------------------------
7+
8+
#pragma once
9+
#pragma push(case_insensitive)
10+
#pragma case_insensitive = TRUE
11+
12+
function fastcall randInt() as ULong ' Returns a random ULong
13+
asm
14+
push namespace core
15+
call RAND
16+
pop namespace
17+
end asm
18+
end function
19+
20+
21+
Function fastcall randFixed() as Fixed ' Returns a random Fixed
22+
Asm
23+
push namespace core
24+
call RAND
25+
pop namespace
26+
End Asm
27+
End Function
28+
29+
30+
Function fastcall randomLimit(limit as uByte) as uByte
31+
Asm
32+
push namespace core
33+
PROC
34+
and a
35+
ret z ; Input zero, output zero.
36+
ld b, a ; Save A
37+
ld c,255
38+
1:
39+
rla
40+
jr c, 2f
41+
rr c
42+
jp 1b ; loop back until we find a bit.
43+
2:
44+
push bc
45+
call RAND
46+
pop bc
47+
and c
48+
cp b
49+
ret z
50+
jr nc, 2b
51+
ENDP
52+
pop namespace
53+
End Asm
54+
End Function
55+
56+
#pragma pop(case_insensitive)
57+
#require "random.asm"

0 commit comments

Comments
 (0)