]> git.sur5r.net Git - cc65/blob - asminc/cbm.mac
Refactorred a CBM screen-code macro, so that we can use it as an operand.
[cc65] / asminc / cbm.mac
1 ; Convert characters to screen codes
2
3 ; Macro that converts one character.
4 ; scrbyte() can be used as an instruction operand
5 .define scrbyte(code)   (<(.strat ("h@dbdlhh", code >> 5) << 4) ^ code)
6
7 ; Helper macro that stores one character
8 .macro _scrcode char
9         .if (char < 256)
10                 .byte   scrbyte {char}
11         .else
12                 .error  "scrcode: Character constant out of range"
13         .endif
14 .endmacro
15
16 .macro  scrcode arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
17
18         ; Bail out if next argument is empty
19         .if     .blank ({arg1})
20                 .exitmacro
21         .endif
22
23         ; Check for a string
24         .if     .match ({arg1}, "")
25
26                 ; Walk over all string chars
27                 .repeat .strlen (arg1), i
28                         _scrcode        {.strat (arg1, i)}
29                 .endrepeat
30
31         ; Check for a number
32         .elseif .match (.left (1, {arg1}), 0)
33
34                 ; Just output the number
35                 _scrcode        arg1
36
37         ; Check for a character
38         .elseif .match (.left (1, {arg1}), 'a')
39
40                 ; Just output the character
41                 _scrcode        arg1
42
43         ; Anything else is an error
44         .else
45                 .error  "scrcode: invalid argument type"
46         .endif
47
48         ; Call the macro recursively with the remaining args
49         scrcode arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
50 .endmacro