--- /dev/null
+; Convert characters to screen codes
+
+; Helper macro that converts and outputs one character
+.macro _scrcode char
+ .if (char >= 0) .and (char <= 31)
+ .byte (char + 64)
+ .elseif (char >= 32) .and (char <= 95)
+ .byte (char - 32)
+ .elseif (char >= 96) .and (char <= 127)
+ .byte char
+ .elseif (char >= 128) .and (char <= 159)
+ .byte (char + 64)
+ .elseif (char >= 160) .and (char <= 223)
+ .byte (char - 32)
+ .elseif (char >= 224) .and (char <= 255)
+ .byte char
+ .else
+ .error "scrcode: Character constant out of range"
+ .endif
+.endmacro
+
+.macro scrcode arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
+
+ ; Bail out if next argument is empty
+ .if .blank (arg1)
+ .exitmacro
+ .endif
+
+ ; Check for a string
+ .if .match ({arg1}, "")
+
+ ; Walk over all string chars
+ .repeat .strlen (arg1), i
+ _scrcode {.strat (arg1, i)}
+ .endrepeat
+
+ ; Check for a number
+ .elseif .match (.left (1, {arg1}), 0)
+
+ ; Just output the number
+ _scrcode arg1
+
+ ; Check for a character
+ .elseif .match (.left (1, {arg1}), 'a')
+
+ ; Just output the character
+ _scrcode arg1
+
+ ; Anything else is an error
+ .else
+
+ .error "scrcode: invalid argument type"
+
+ .endif
+
+ ; Call the macro recursively with the remaining args
+ scrcode arg2, arg3, arg4, arg5, arg6, arg7, arg8
+.endmacro
+
; Convert characters to screen codes
-.macro scrcode str
- .repeat .strlen(str), i
- .if (.strat(str, i) >= '@' .and .strat(str, i) <= 'z')
- .byte .strat(str, i) - '@'
- .elseif (.strat(str, i) >= 'A' .and .strat(str, i) <= 'Z')
- .byte .strat(str, i) - 'A' + 65
- .elseif (.strat(str, i) = '[')
- .byte 27
- .elseif (.strat(str, i) = ']')
- .byte 29
- .elseif (.strat(str, i) = '^')
- .byte 30
- .elseif (.strat(str, i) = '_')
- .byte 31
- .else
- .byte .strat(str, i)
- .endif
- .endrepeat
+
+; Helper macro that converts and outputs one character
+.macro _scrcode char
+ .if (char >= '@' .and char <= 'z')
+ .byte (char - '@')
+ .elseif (char >= 'A' .and char <= 'Z')
+ .byte (char - 'A' + 65)
+ .elseif (char = '[')
+ .byte 27
+ .elseif (char = ']')
+ .byte 29
+ .elseif (char = '^')
+ .byte 30
+ .elseif (char = '_')
+ .byte 31
+ .elseif (char < 256)
+ .byte char
+ .else
+ .error "scrcode: Character constant out of range"
+ .endif
.endmacro
+.macro scrcode arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
+
+ ; Bail out if next argument is empty
+ .if .blank (arg1)
+ .exitmacro
+ .endif
+
+ ; Check for a string
+ .if .match ({arg1}, "")
+
+ ; Walk over all string chars
+ .repeat .strlen (arg1), i
+ _scrcode {.strat (arg1, i)}
+ .endrepeat
+
+ ; Check for a number
+ .elseif .match (.left (1, {arg1}), 0)
+
+ ; Just output the number
+ _scrcode arg1
+
+ ; Check for a character
+ .elseif .match (.left (1, {arg1}), 'a')
+
+ ; Just output the character
+ _scrcode arg1
+
+ ; Anything else is an error
+ .else
+
+ .error "scrcode: invalid argument type"
+
+ .endif
+
+ ; Call the macro recursively with the remaining args
+ scrcode arg2, arg3, arg4, arg5, arg6, arg7, arg8
+.endmacro
+