Another example of 'auto namespacing' is when you put a label before a macro execution.
.macro equalCharPack(filename, screenAdr, charsetAdr) { .var charMap = Hashtable() .var charNo = 0 .var screenData = List() .var charsetData = List() .var pic = LoadPicture(filename) .for (var charY=0; charY<25; charY++) { .for (var charX=0; charX<40; charX++) { .var currentCharBytes = List() .var key = "" .for (var i=0; i<8; i++) { .var byteVal = pic.getSinglecolorByte(charX, charY*8 + i) .eval key = key + toHexString(byteVal) + "," .eval currentCharBytes.add(byteVal) } .var currentChar = charMap.get(key) .if (currentChar == null) { .eval currentChar = charNo .eval charMap.put(key, charNo) .eval charNo++ .for (var i=0; i<8; i++) { .eval charsetData.add(currentCharBytes.get(i)) } } .eval screenData.add(currentChar) } } .pc = screenAdr "screen" .fill screenData.size(), screenData.get(i) .pc = charsetAdr "charset" .fill charsetData.size(), charsetData.get(i) } :equalCharPack("pic.png", $2800, $2000)
// Graphics should fit in 8x8 Single collor / 4 x 8 Multi collor blocks .var PictureSizeX = pic.width/8 .var PictureSizeY = pic.height/8 .for (var charY=0; charY<PictureSizeY; charY++) { .for (var charX=0; charX<PictureSizeX; charX++) {
.struct RGB {r,g,b} .var s_palette = List().add( RGB(0,0,0), // black 0 RGB(255,255,255), // white 1 RGB(104,55,43), // red 2 RGB(131,240,220), // cyan 3 RGB(111,61,134), // purple 4 RGB(89,205,54), // green 5 RGB(65,55,205), // blue 6 RGB(184,199,111), // yellow 7 RGB(209,127,48), // orange 8 RGB(67,57,0), // brown 9 RGB(154,103,89), // light_red 10 RGB(91,91,91), // dark_gray 11 RGB(142,142,142), // gray 12 RGB(157,255,157), // light_green 13 RGB(117,161,236), // light_blue 14 RGB(193,193,193) // light_gray 15 ); .function colorDistance(c1,c2) { .var cr = c1.r-c2.r .var cg = c1.g-c2.g .var cb = c1.b-c2.b .return sqrt([cr*cr] + [cg*cg] + [cb*cb]) } .function getClosestColorIndex(rgb) { .return getClosestColorIndex( rgb, s_palette ) } .function getClosestColorIndex(rgb, palette) { .var distance = colorDistance(rgb, palette.get(0)) .var closestColorIndex = 0 .for (var index = 1; index < palette.size(); index++) { .var d = colorDistance(rgb, palette.get(index)) .if (d < distance) { .eval distance = d .eval closestColorIndex = index } } .return closestColorIndex }