• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# RGBDS abuse macros, RPL edition

ISSOtm Jan 24th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. trim_str: macro
2.     IF STRSUB("{\1}", 1, 1) == " "
3. TMP_STR\@ equs STRSUB("{\1}", 2, STRLEN("{\1}") - 1)
4.         PURGE \1
5. \1 equs "{TMP_STR\@}"
6.         PURGE TMP_STR\@
7.         trim_str \1
8.     ELIF STRSUB("{\1}", STRLEN("{\1}"), 1) == " "
9. TMP_STR\@ equs STRSUB("{\1}", 1, STRLEN("{\1}") - 1)
10.         PURGE \1
11. \1 equs "{TMP_STR\@}"
12.         PURGE TMP_STR\@
13.         trim_str \1
14.     ENDC
15. endm
16.
17. pop_token: macro
18.     IF DEF(TOKEN)
19.         PURGE TOKEN
20.     ENDC
21.
22. SPACE_POS equ STRIN("{\1}", " ")
23.     IF SPACE_POS == 0
24. TOKEN equs "{\1}"
25.         PURGE \1
26. \1 equs ""
27.     ELSE
28. TOKEN equs STRSUB("{\1}", 1, SPACE_POS + (-1))
29. TMP\@ equs STRSUB("{\1}", SPACE_POS + 1, STRLEN("{\1}") - SPACE_POS)
30.         PURGE \1
31. \1 equs "{TMP\@}"
32.         PURGE TMP\@
33.         trim_str \1
34.     ENDC
35.     PURGE SPACE_POS
36. endm
37.
38. count_tokens: macro
39. NB_TOKENS = 0
40.     IF "{\1}" != ""
41. \1_copy\@ equs "{\1}"
42.         trim_str \1_copy\@
43.         count_tokens_internal \1_copy\@
44.     ENDC
45. endm
46.
47. count_tokens_internal: macro
48.     IF "{\1}" != ""
49. NB_TOKENS = NB_TOKENS + 1
50.         pop_token \1
51.         count_tokens_internal \1
52.     ENDC
53. endm
54.
55. ; cutscene_jump dest [, expr]
56. ; Jump to the destination always, or when the expression evaluates to non-zero
57. ; TODO: implement RPN evaluator
58. cutscene_jump: macro
59.     db CUTSCENE_JUMP
60.     IF _NARG > 1
61. RPN_STRING equs \2
62.         trim_str RPN_STRING
63.         ; RGBDS doesn't have a `while`-like structure
64.         ; Thus, we need to compute the number of tokens and REPT that
65.         count_tokens RPN_STRING
66.         REPT NB_TOKENS
67.             pop_token RPN_STRING
68.             ; The single quotes serve as separators and padding
69. RPN_OPER = STRIN("+'''-'''!'''&'''|'''^'''<'''<=''==''&&''||''<<''>>''['''", "{TOKEN}'") + 3
70.             IF RPN_OPER != 3
71.                 ; Operator
72.                 db RPN_OPER / 4
73.             ELSE
74.                 ; Immediate
75.                 db \$81
76.                 dw TOKEN
77.             ENDC
78.         ENDR
79.         PURGE RPN_STRING
80.         PURGE RPN_OPER
81.         PURGE TOKEN
82.     ELSE
83.         db \$81
84.         dw 1
85.     ENDC
86.     db 0
87.     db LOW(\1)
88.     db BANK(\1)
89.     db HIGH(\1)
90. endm
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?