]> git.sur5r.net Git - cc65/blob - src/ca65/macpack/cbm.mac
Finished implemenation of commands to delete macros. Added the new commands to
[cc65] / src / ca65 / macpack / cbm.mac
1 ; Convert characters to screen codes
2
3 ; Helper macro that converts and outputs one character
4 .macro _scrcode char
5         .if (char >= '@' .and char <= 'z')
6                 .byte   (char - '@')
7         .elseif (char >= 'A' .and char <= 'Z')
8                 .byte   (char - 'A' + 65)
9         .elseif (char = '[')
10                 .byte   27
11         .elseif (char = ']')
12                 .byte   29
13         .elseif (char = '^')
14                 .byte   30
15         .elseif (char = '_')
16                 .byte   31
17         .elseif (char < 256)
18                 .byte   char
19         .else
20                 .error  "scrcode: Character constant out of range"
21         .endif
22 .endmacro
23
24 .macro  scrcode arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
25
26         ; Bail out if next argument is empty
27         .if     .blank (arg1)
28                 .exitmacro
29         .endif
30
31         ; Check for a string
32         .if     .match ({arg1}, "")
33
34                 ; Walk over all string chars
35                 .repeat .strlen (arg1), i
36                         _scrcode        {.strat (arg1, i)}
37                 .endrepeat
38
39         ; Check for a number
40         .elseif .match (.left (1, {arg1}), 0)
41
42                 ; Just output the number
43                 _scrcode        arg1
44
45         ; Check for a character
46         .elseif .match (.left (1, {arg1}), 'a')
47
48                 ; Just output the character
49                 _scrcode        arg1
50
51         ; Anything else is an error
52         .else
53
54                 .error  "scrcode: invalid argument type"
55
56         .endif
57
58         ; Call the macro recursively with the remaining args
59         scrcode arg2, arg3, arg4, arg5, arg6, arg7, arg8
60 .endmacro
61
62