Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trim_str: macro
- IF STRSUB("{\1}", 1, 1) == " "
- TMP_STR\@ equs STRSUB("{\1}", 2, STRLEN("{\1}") - 1)
- PURGE \1
- \1 equs "{TMP_STR\@}"
- PURGE TMP_STR\@
- trim_str \1
- ELIF STRSUB("{\1}", STRLEN("{\1}"), 1) == " "
- TMP_STR\@ equs STRSUB("{\1}", 1, STRLEN("{\1}") - 1)
- PURGE \1
- \1 equs "{TMP_STR\@}"
- PURGE TMP_STR\@
- trim_str \1
- ENDC
- endm
- pop_token: macro
- IF DEF(TOKEN)
- PURGE TOKEN
- ENDC
- SPACE_POS equ STRIN("{\1}", " ")
- IF SPACE_POS == 0
- TOKEN equs "{\1}"
- PURGE \1
- \1 equs ""
- ELSE
- TOKEN equs STRSUB("{\1}", 1, SPACE_POS + (-1))
- TMP\@ equs STRSUB("{\1}", SPACE_POS + 1, STRLEN("{\1}") - SPACE_POS)
- PURGE \1
- \1 equs "{TMP\@}"
- PURGE TMP\@
- trim_str \1
- ENDC
- PURGE SPACE_POS
- endm
- count_tokens: macro
- NB_TOKENS = 0
- IF "{\1}" != ""
- \1_copy\@ equs "{\1}"
- trim_str \1_copy\@
- count_tokens_internal \1_copy\@
- ENDC
- endm
- count_tokens_internal: macro
- IF "{\1}" != ""
- NB_TOKENS = NB_TOKENS + 1
- pop_token \1
- count_tokens_internal \1
- ENDC
- endm
- ; cutscene_jump dest [, expr]
- ; Jump to the destination always, or when the expression evaluates to non-zero
- ; TODO: implement RPN evaluator
- cutscene_jump: macro
- db CUTSCENE_JUMP
- IF _NARG > 1
- RPN_STRING equs \2
- trim_str RPN_STRING
- ; RGBDS doesn't have a `while`-like structure
- ; Thus, we need to compute the number of tokens and REPT that
- count_tokens RPN_STRING
- REPT NB_TOKENS
- pop_token RPN_STRING
- ; The single quotes serve as separators and padding
- RPN_OPER = STRIN("+'''-'''!'''&'''|'''^'''<'''<=''==''&&''||''<<''>>''['''", "{TOKEN}'") + 3
- IF RPN_OPER != 3
- ; Operator
- db RPN_OPER / 4
- ELSE
- ; Immediate
- db $81
- dw TOKEN
- ENDC
- ENDR
- PURGE RPN_STRING
- PURGE RPN_OPER
- PURGE TOKEN
- ELSE
- db $81
- dw 1
- ENDC
- db 0
- db LOW(\1)
- db BANK(\1)
- db HIGH(\1)
- endm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement