aboutsummaryrefslogtreecommitdiff
path: root/inv.inc
blob: 45f8d336c022724b066e71547861a6b7dd359ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
; 20221210 bkw:
; Convert characters to inverse video (set bit 7). Actually, toggles
; bit 7 (passing it inverse video characters turn them into normal ones).

; Based on scrcode macro from cc65's atari.mac. Probably this should
; ship with cc65...

; Helper macro that converts and outputs one character
.macro _inv char
  .if char > $ff
    .error "inverse: Character constant out of range"
  .else
    .byte char .bitxor $80
  .endif
.endmacro

.macro  inverse 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
                        _inv        {.strat (arg1, i)}
                .endrepeat

        ; Check for a number
        .elseif .match (.left (1, {arg1}), 0)

                ; Just output the number
                _inv        arg1

        ; Check for a character
        .elseif .match (.left (1, {arg1}), 'a')

                ; Just output the character
                _inv        arg1

        ; Anything else is an error
        .else

                .error  "inv: invalid argument type"

        .endif

        ; Call the macro recursively with the remaining args
        inverse arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
.endmacro