| 1 |
;ACME 0.97 |
| 2 |
|
| 3 |
!ifdef lib_cbm_multicolor_a !eof |
| 4 |
lib_cbm_multicolor_a = 1 |
| 5 |
|
| 6 |
; this file contains macros to convert strings into bit patterns. |
| 7 |
; the idea is to use four different characters to indicate the four |
| 8 |
; different bit patterns of multicolor graphics, so mc sprites can be |
| 9 |
; "drawn" in the source code even though ACME does not support any |
| 10 |
; four-based number system. see the end of this file for an example. |
| 11 |
|
| 12 |
; macro to set "digit" characters |
| 13 |
; example: |
| 14 |
; +mc_set " .o#" |
| 15 |
!macro mc_set .s { |
| 16 |
!if is_number(.s) or is_list(.s) { |
| 17 |
!error "Argument to +mc_set must be a string." |
| 18 |
} else if len(.s) != 4 { |
| 19 |
!error "Argument to +mc_set must be four characters." |
| 20 |
} else { |
| 21 |
!set multicolor_alphabet = .s |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
; macro to convert string to number |
| 26 |
!macro mc_value ~.result, .in, .len { |
| 27 |
!ifndef multicolor_alphabet { |
| 28 |
!error "Called +mc_value before calling +mc_set." |
| 29 |
} else if is_number(.in) or is_list(.in) { |
| 30 |
!error "Argument to +mc_value must be a string." |
| 31 |
} else if len(.in) != .len { |
| 32 |
!error "Argument to +mc_value must have ", .len, " characters." |
| 33 |
} else { |
| 34 |
!set .result = 0 |
| 35 |
!for .idx, 0, (.len / 2) - 1 { |
| 36 |
!set .char = .in[2 * .idx] ; get first of pair |
| 37 |
!if .char != .in[2 * .idx + 1] { ; compare to second |
| 38 |
!error "Characters in argument to +mc_value must be given in pairs." |
| 39 |
} else { |
| 40 |
!if .char = multicolor_alphabet[0] { |
| 41 |
!set .result = (.result << 2) |
| 42 |
} else if .char = multicolor_alphabet[1] { |
| 43 |
!set .result = (.result << 2) + 1 |
| 44 |
} else if .char = multicolor_alphabet[2] { |
| 45 |
!set .result = (.result << 2) + 2 |
| 46 |
} else if .char = multicolor_alphabet[3] { |
| 47 |
!set .result = (.result << 2) + 3 |
| 48 |
} else { |
| 49 |
!error "Characters in argument to +mc_value must be from alphabet set via +mc_set." |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
; macro for a multicolor byte (for charsets) |
| 57 |
!macro mc_8 .in { |
| 58 |
+mc_value ~.result, .in, 8 |
| 59 |
!by .result |
| 60 |
} |
| 61 |
|
| 62 |
; macro for a multicolor sprite line |
| 63 |
!macro mc_be24 .in { |
| 64 |
+mc_value ~.result, .in, 24 |
| 65 |
!be24 .result |
| 66 |
} |
| 67 |
|
| 68 |
!eof |
| 69 |
; Here's an example on how to use this: |
| 70 |
!to "mc-sprites.prg", cbm |
| 71 |
*=$e00 |
| 72 |
+mc_set " .o#" ; set four characters |
| 73 |
; and now use those four characters to "paint" the sprite: |
| 74 |
+mc_be24 " " |
| 75 |
+mc_be24 ".. .." |
| 76 |
+mc_be24 ".... ...." |
| 77 |
+mc_be24 "...... ##....## ......" |
| 78 |
+mc_be24 " .................... " |
| 79 |
+mc_be24 " .................... " |
| 80 |
+mc_be24 " ................ " |
| 81 |
+mc_be24 " ######........###### " |
| 82 |
+mc_be24 " ..oo####....####oo.. " |
| 83 |
+mc_be24 "##..oo ######## oo..##" |
| 84 |
+mc_be24 "....oo oo....oo oo...." |
| 85 |
+mc_be24 "......oooo....oooo......" |
| 86 |
+mc_be24 "........................" |
| 87 |
+mc_be24 "......oooo....oooo......" |
| 88 |
+mc_be24 "....oooooooooooooooo...." |
| 89 |
+mc_be24 ".... oooooooooooo ...." |
| 90 |
+mc_be24 ".. ####oooooooo#### .." |
| 91 |
+mc_be24 ".. ######oooo###### .." |
| 92 |
+mc_be24 " ###### #### " |
| 93 |
+mc_be24 " ###### ## " |
| 94 |
+mc_be24 " " |