35#if defined(__c128zz__)
40static RGBi SYSTEM_PALETTE[] = {
41 { 0x00, 0x00, 0x00, 0xff, 0,
"BLACK" },
42 { 0xff, 0xff, 0xff, 0xff, 1,
"WHITE" },
43 { 0x80, 0x00, 0x00, 0xff, 2,
"RED" },
44 { 0xaa, 0xff, 0xe6, 0xff, 3,
"CYAN" },
45 { 0xcc, 0x44, 0xcc, 0xff, 4,
"VIOLET" },
46 { 0x00, 0xcc, 0x55, 0xff, 5,
"GREEN" },
47 { 0x00, 0x00, 0xaa, 0xff, 6,
"BLUE" },
48 { 0xee, 0xee, 0x77, 0xff, 7,
"YELLOW" },
49 { 0xa1, 0x68, 0x3c, 0xff, 8,
"ORANGE" },
50 { 0xdd, 0x88, 0x65, 0xff, 9,
"BROWN" },
51 { 0xff, 0x77, 0x77, 0xff, 10,
"LIGHT_RED" },
52 { 0x33, 0x33, 0x33, 0xff, 11,
"DARK_GREY" },
53 { 0x77, 0x77, 0x77, 0xff, 12,
"GREY" },
54 { 0xaa, 0xff, 0x66, 0xff, 13,
"LIGHT GREEN" },
55 { 0x00, 0x88, 0xff, 0xff, 14,
"LIGHT BLUE" },
56 { 0xbb, 0xbb, 0xbb, 0xff, 15,
"LIGHT GREY" }
59static RGBi * commonPalette;
66RGBi * vic2z_image_nearest_system_color(
RGBi * _color ) {
68 unsigned int minDistance = 0xffff;
78 return &SYSTEM_PALETTE[colorIndex];
93static void vic2z_image_converter_tile(
Environment * _environment,
char * _source,
char * _dest,
int _width,
int _depth,
int _source_width ) {
96 memset(colorIndexesCount, 0,
COLOR_COUNT *
sizeof(
int ) );
102 memset( _dest, 0, 9 );
105 for (
int y=0; y<8; ++y) {
106 for (
int x=0; x<8; ++x) {
110 memset( &rgb, 0,
sizeof(
RGBi ) );
117 rgb.
alpha = *(_source + 3);
121 if ( rgb.
alpha == 0 ) {
127 if ( rgb.
alpha < 255 ) {
130 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
131 ++colorIndexesCount[systemRgb->
index];
138 source += _depth * ( _source_width - 8 );
142 int colorBackground = 0;
143 int colorBackgroundMax = 0;
144 int colorForeground = 0;
145 int colorForegroundMax = 0;
147 if ( colorIndexesCount[xx] > colorBackgroundMax ) {
148 colorBackground = xx;
149 colorBackgroundMax = colorIndexesCount[xx];
153 colorIndexesCount[colorBackground] = 0;
156 if ( colorIndexesCount[xx] > colorForegroundMax ) {
157 colorForeground = xx;
158 colorForegroundMax = colorIndexesCount[xx];
163 if ( colorForeground == 0 ) {
164 colorForeground = colorBackground;
171 if ( colorForeground == colorBackground ) {
172 colorForeground = ( colorBackground == 0 ) ? 1 : 0;
177 for (
int y=0; y<8; ++y) {
178 for (
int x=0; x<8; ++x) {
182 memset( &rgb, 0,
sizeof(
RGBi ) );
188 rgb.
alpha = *(_source + 3);
192 if ( rgb.
alpha == 0 ) {
198 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
200 char bitmask = 1 << ( 7 - ((x) & 0x7) );
202 if ( rgb.
alpha < 255 ) {
203 *( _dest + y ) &= ~bitmask;
206 if ( systemRgb->
index != colorBackground ) {
208 *( _dest + y ) |= bitmask;
212 *( _dest + y ) &= ~bitmask;
221 source += _depth * ( _source_width - 8 );
225 *( _dest + 8 ) = ( colorForeground << 4 ) | colorBackground ;
240static void vic2z_image_converter_tiles(
Environment * _environment,
char * _source,
char * _dest,
int _width,
int _height,
int _depth,
int _source_width ) {
242 int bitmapSize = ( _width>>3 ) * _height;
243 int colormapSize = ( _width>>3 ) * (_height>>3);
245 memset( _dest, 0, bitmapSize + colormapSize );
249 for(
int y=0; y<_height; y+=8 ) {
250 for(
int x=0; x<_width; x+=8 ) {
252 char *
source = _source + ( ( y * _source_width ) + x ) * _depth;
255 vic2z_image_converter_tile( _environment,
source, tile, _width, _depth, _source_width );
257 int offset = ((y>>3) * 8 *( _width >> 3 ) ) + ((x>>3) * 8) + ((y) & 0x07);
263 char * destBitmap = _dest +
offset;
264 char * destColormap = _dest + bitmapSize + ( ( ( y >> 3 ) * ( _width >> 3 ) ) + ( x >> 3 ) );
265 for(
int i=0; i<8; ++i ) {
266 *destBitmap = tile[i];
270 *destColormap = tile[8];
291static void vic2z_image_converter_tile_multicolor(
Environment * _environment,
char * _source,
char * _dest,
int _width,
int _depth,
int _background,
int _source_width ) {
294 memset(colorIndexesCount, 0,
COLOR_COUNT *
sizeof(
int ) );
300 memset( _dest, 0, 10 );
303 for (
int y=0; y<8; ++y) {
304 for (
int x=0; x<4; ++x) {
308 memset( &rgb, 0,
sizeof(
RGBi ) );
315 rgb.
alpha = *(_source + 3);
319 if ( rgb.
alpha == 0 ) {
325 if ( rgb.
alpha < 255 ) {
329 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
331 ++colorIndexesCount[systemRgb->
index];
339 source += _depth * ( _source_width - 4 );
347 colorIndexesCount[_background] = 0;
350 int colorFirstMax = 0;
352 int colorSecondMax = 0;
354 int colorThirdMax = 0;
357 if ( colorIndexesCount[xx] > colorFirstMax ) {
359 colorFirstMax = colorIndexesCount[xx];
363 colorIndexesCount[colorFirst] = 0;
366 if ( colorIndexesCount[xx] > colorSecondMax ) {
368 colorSecondMax = colorIndexesCount[xx];
372 colorIndexesCount[colorSecond] = 0;
375 if ( colorIndexesCount[xx] > colorThirdMax ) {
377 colorThirdMax = colorIndexesCount[xx];
381 colorIndexesCount[colorThird] = 0;
385 for (
int y=0; y<8; ++y) {
386 for (
int x=0; x<4; ++x) {
390 memset( &rgb, 0,
sizeof(
RGBi ) );
396 rgb.
alpha = *(_source + 3);
400 if ( rgb.
alpha == 0 ) {
408 if ( rgb.
alpha < 255 ) {
413 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
415 if ( systemRgb->
index == colorFirst ) {
418 }
else if ( systemRgb->
index == colorSecond ) {
421 }
else if ( systemRgb->
index == colorThird ) {
430 char bitmask = colorIndex << (6 - ((x & 0x3) * 2));
432 *(_dest + y) |= bitmask;
438 source += _depth * ( _source_width - 4 );
442 *( _dest + 8 ) = ( colorFirst << 4 ) | colorSecond ;
443 *( _dest + 9 ) = ( _background << 4 ) | colorThird;
460static void vic2z_image_converter_tiles_multicolor(
Environment * _environment,
char * _source,
char * _dest,
int _width,
int _height,
int _depth,
int _source_width,
int _background ) {
462 int bitmapSize = ( _width>>2 ) * _height;
463 int colormap1Size = ( _width>>2 ) * (_height>>3);
464 int colormap2Size = ( _width>>2 ) * (_height>>3);
466 memset( _dest, 0, bitmapSize + colormap1Size + colormap2Size );
470 for(
int y=0; y<_height; y+=8 ) {
471 for(
int x=0; x<_width; x+=4 ) {
473 char *
source = _source + ( ( y * _source_width ) + x ) * _depth;
476 vic2z_image_converter_tile_multicolor( _environment,
source, tile, _width, _depth, _background, _source_width );
478 int offset = ((y>>3) * 8 *( _width >> 2 ) ) + ((x>>2) * 8) + ((y) & 0x07);
480 char * destBitmap = _dest +
offset;
481 char * destColormap1 = _dest + bitmapSize + ( ( ( y >> 3 ) * ( _width >> 2 ) ) + ( x >> 2 ) );
482 char * destColormap2 = _dest + bitmapSize + colormap1Size + ( ( ( y >> 3 ) * ( _width >> 2 ) ) + ( x >> 2 ) );
483 for(
int i=0; i<8; ++i ) {
484 *destBitmap = tile[i];
487 *destColormap1 = tile[8];
488 *destColormap2 = tile[9];
588 outline1(
"LDA #$%2.2x", _background_color );
590 outline1(
"STA $d021+%d", ( _index & 0x03 ) );
608 outline1(
"LDA %s", _background_color );
628 outline1(
"LDA %s", _background_color );
650 outline1(
"STA %s", _background_color );
786 outline1(
"ORA #%2.2x", ( ~_bank ) & 0x03 );
790static int rgbConverterFunction(
int _red,
int _green,
int _blue ) {
793 unsigned int minDistance = 0xffffffff;
801 for (j = 0; j <
sizeof(SYSTEM_PALETTE)/
sizeof(
RGBi); ++j) {
822 switch( _screen_mode->
id ) {
1112 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1113 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1117 outline1(
"LDA #$%2.2x", ( *_c & 0xff ) );
1123 outline1(
"LDA %2.2x", (_x & 0xff ) );
1125 outline1(
"LDA %2.2x", ( ( _x >> 8 ) & 0xff ) );
1127 outline1(
"LDA %2.2x", ( _y & 0xff ) );
1140 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1141 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1166 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1167 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1251 deploy( sprite, src_hw_vic2z_sprites_asm );
1266 deploy( sprite, src_hw_vic2z_sprites_asm );
1279 deploy( sprite, src_hw_vic2z_sprites_asm );
1294 deploy( sprite, src_hw_vic2z_sprites_asm );
1312 deploy( sprite, src_hw_vic2z_sprites_asm );
1323 deploy( sprite, src_hw_vic2z_sprites_asm );
1334 deploy( sprite, src_hw_vic2z_sprites_asm );
1345 deploy( sprite, src_hw_vic2z_sprites_asm );
1356 deploy( sprite, src_hw_vic2z_sprites_asm );
1367 deploy( sprite, src_hw_vic2z_sprites_asm );
1379 deploy( sprite, src_hw_vic2z_sprites_asm );
1392 deploy( sprite, src_hw_vic2z_sprites_asm );
1420 outline1(
"ORA %s", _displacement );
1429 outline1(
"ORA %s", _displacement );
1489 deploy( clsGraphic, src_hw_vic2z_cls_graphic_asm );
1492 deploy( clsText, src_hw_vic2z_cls_text_asm );
1504 if ( _direction > 0 ) {
1505 deploy( vScrollTextDown, src_hw_vic2z_vscroll_text_down_asm );
1508 deploy( vScrollTextUp, src_hw_vic2z_vscroll_text_up_asm );
1516 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1517 deploy( vScrollTextUp, src_hw_vic2z_vscroll_text_up_asm );
1518 deploy( textEncodedAt, src_hw_vic2z_text_at_asm );
1528 deploy( clsGraphic, src_hw_vic2z_cls_graphic_asm );
1529 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1530 deploy_deferred( textEncodedAtGraphic, src_hw_vic2z_text_at_graphic_asm );
1533 deploy( clsText, src_hw_vic2z_cls_text_asm );
1542 deploy( vic2zvars, src_hw_vic2z_vars_asm );
1543 deploy( vic2zstartup, src_hw_vic2z_startup_asm );
1633static RGBi * multicolorSpritePalette[2];
1639 if ( multicolorSpritePalette[0] ) {
1640 outline1(
"LDA #$%2.2x", multicolorSpritePalette[0]->index );
1644 if ( multicolorSpritePalette[1] ) {
1645 outline1(
"LDA #$%2.2x", multicolorSpritePalette[1]->index );
1655 deploy( textHScroll, src_hw_vic2z_hscroll_text_asm );
1658 outline1(
"LDA #$%2.2x", ( _direction & 0xff ) );
1669 deploy( textHScroll, src_hw_vic2z_hscroll_text_asm );
1671 outline1(
"LDA #$%2.2x", ( _direction & 0xff ) );
1687 deploy( textCline, src_hw_vic2z_cline_asm );
1691 if ( _characters ) {
1705static int calculate_image_size(
Environment * _environment,
int _width,
int _height,
int _mode ) {
1711 return 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) );
1715 return 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1;
1757static int calculate_images_size(
Environment * _environment,
int _frames,
int _width,
int _height,
int _mode ) {
1763 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) * _frames;
1767 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1 ) * _frames;
1809static int calculate_sequence_size(
Environment * _environment,
int _sequences,
int _frames,
int _width,
int _height,
int _mode ) {
1815 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) * _frames ) * _sequences;
1819 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1 ) * _frames ) * _sequences;
1861static Variable * vic2z_image_converter_bitmap_mode_standard(
Environment * _environment,
char * _source,
int _width,
int _height,
int _depth,
int _offset_x,
int _offset_y,
int _frame_width,
int _frame_height,
int _transparent_color,
int _flags ) {
1863 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
1867 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1869 if ( _frame_width % 8 ) {
1870 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1875 if ( _height % 8 ) {
1876 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
1878 if ( _frame_height % 8 ) {
1879 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
1887 if (paletteColorCount > 16) {
1893 commonPalette =
palette_match( palette, paletteColorCount, SYSTEM_PALETTE,
sizeof(SYSTEM_PALETTE) /
sizeof(
RGBi) );
1904 int bufferSize = calculate_image_size( _environment, _frame_width, _frame_height,
BITMAP_MODE_STANDARD );
1910 char * buffer =
malloc ( bufferSize );
1911 memset( buffer, 0, bufferSize );
1914 int image_x, image_y;
1925 *(buffer) = ( _frame_width & 0xff );
1926 *(buffer+1) = ( (_frame_width>>8) & 0xff );
1927 *(buffer+2) = _frame_height;
1929 _source += ( ( _offset_y * _width ) + _offset_x ) * 3;
1931 vic2z_image_converter_tiles( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width );
1943static Variable * vic2z_image_converter_multicolor_mode_standard(
Environment * _environment,
char * _source,
int _width,
int _height,
int _depth,
int _offset_x,
int _offset_y,
int _frame_width,
int _frame_height,
int _transparent_color,
int _flags ) {
1945 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1947 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
1951 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1953 if ( _frame_width % 8 ) {
1954 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1959 if ( _height % 8 ) {
1960 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
1962 if ( _frame_height % 8 ) {
1963 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
1971 if (paletteColorCount > 16) {
1977 commonPalette =
palette_match( palette, paletteColorCount, SYSTEM_PALETTE,
sizeof(SYSTEM_PALETTE) /
sizeof(
RGBi) );
1988 int bufferSize = calculate_image_size( _environment, _frame_width, _frame_height,
BITMAP_MODE_MULTICOLOR );
1992 char * buffer =
malloc ( bufferSize );
1993 memset( buffer, 0, bufferSize );
1996 int image_x, image_y;
2002 int offset, offsetc, bitmask;
2007 *(buffer) = ( _frame_width & 0xff );
2008 *(buffer+1) = ( _frame_width >> 8 ) & 0xff;
2009 *(buffer+2) = _frame_height;
2011 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2013 vic2z_image_converter_tiles_multicolor( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width, palette[0].index );
2021static Variable * vic2z_image_converter_tilemap_mode_standard(
Environment * _environment,
char * _source,
int _width,
int _height,
int _depth,
int _offset_x,
int _offset_y,
int _frame_width,
int _frame_height,
int _transparent_color,
int _flags ) {
2023 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
2027 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2029 if ( _frame_width % 8 ) {
2030 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2035 if ( _height % 8 ) {
2036 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
2038 if ( _frame_height % 8 ) {
2039 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
2043 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2054 for( i=0; i<colorUsed; ++i ) {
2055 int minDistance = 0xffff;
2057 for (j = 0; j <
sizeof(SYSTEM_PALETTE)/
sizeof(
RGBi); ++j) {
2062 for( k=0; k<i; ++k ) {
2063 if ( palette[k].index == SYSTEM_PALETTE[j].index ) {
2075 palette[i].
index = SYSTEM_PALETTE[colorIndex].index;
2076 strcopy( palette[i].description, SYSTEM_PALETTE[colorIndex].description );
2084 if ( colorUsed == 2 ) {
2085 bufferSize = 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) + 1;
2087 bufferSize = 3 + 2* ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) );
2092 char * buffer =
malloc ( bufferSize );
2093 memset( buffer, 0, bufferSize );
2096 int image_x, image_y;
2107 *(buffer) = _frame_width;
2108 *(buffer+1) = _frame_height;
2110 if ( colorUsed > 2 ) {
2118 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2122 for( cy=0; cy<(_frame_height >> 3);++cy) {
2123 for( cx=0; cx<(_frame_width >> 3);++cx) {
2125 char *
source = _source + ( ( cy * 8 * _width ) + cx * 8 ) * _depth;
2128 memset(&tileData,0,
sizeof(
TileData));
2130 int mostFrequentColor[16];
2131 memset(&mostFrequentColor[0],0,
sizeof(
int)*16);
2136 for (image_y = 0; image_y < 8; ++image_y) {
2137 for (image_x = 0; image_x < 8; ++image_x) {
2144 rgb.
alpha = *(_source + 3);
2149 if ( rgb.
alpha < 255 ) {
2150 colorIndex = palette[0].
index;
2153 int minDistance = 9999;
2154 for(
int i=0; i<colorUsed; ++i ) {
2158 colorIndex = palette[i].
index;
2170 offset = (image_y & 0x07);
2171 bitmask = 1 << ( 7 - (image_x & 0x7) );
2173 if (colorUsed == 2 ) {
2175 tileData.data[
offset] &= ~bitmask;
2178 tileData.data[
offset] |= bitmask;
2183 mostFrequentColor[colorIndex]++;
2184 tileData.data[
offset] &= ~bitmask;
2187 tileData.data[
offset] |= bitmask;
2196 source += _depth * ( _width - 8 );
2229 *(buffer + 3 + (cy * ( _frame_width >> 3 ) ) + cx ) = tile;
2230 if ( colorUsed > 2 ) {
2231 int mostFrequentColorIndex = 1;
2232 int mostFrequentColorCount = 0;
2233 for(i=0;i<colorUsed;++i) {
2234 if ( mostFrequentColorCount < mostFrequentColor[palette[i].index] ) {
2235 mostFrequentColorCount = mostFrequentColor[palette[i].
index];
2236 mostFrequentColorIndex = palette[i].index;
2240 *(buffer + 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) + (cy * ( _frame_width >> 3 ) ) + cx ) = ( ( mostFrequentColorIndex & 0x07 ) );
2249 if ( colorUsed <= 2 ) {
2250 *(buffer + 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) ) = palette[0].index == 0 ? palette[1].index : palette[0].index;
2262Variable *
vic2z_image_converter(
Environment * _environment,
char * _data,
int _width,
int _height,
int _depth,
int _offset_x,
int _offset_y,
int _frame_width,
int _frame_height,
int _mode,
int _transparent_color,
int _flags ) {
2268 return vic2z_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2272 return vic2z_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2305 return vic2z_image_converter_tilemap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2326 if (colorUsed > 4) {
2330 if (colorUsed > 2) {
2342 for( i=0; i<colorUsed; ++i ) {
2343 int minDistance = 0xffff;
2345 for (j = 0; j <
sizeof(SYSTEM_PALETTE)/
sizeof(
RGBi); ++j) {
2350 for( k=0; k<i; ++k ) {
2351 if ( palette[k].index == SYSTEM_PALETTE[j].index ) {
2363 palette[i].
index = SYSTEM_PALETTE[colorIndex].index;
2364 strcopy( palette[i].description, SYSTEM_PALETTE[colorIndex].description );
2375 if ( palette[0].index == SYSTEM_PALETTE[0].index ) {
2381 rgbi_move( &SYSTEM_PALETTE[0], &palette[0] );
2393 if ( !multicolorSpritePalette[0] ) {
2395 multicolorSpritePalette[0] =
malloc(
sizeof(
RGBi ) );
2396 memset( multicolorSpritePalette[0], 0,
sizeof(
RGBi ) );
2397 rgbi_move( &palette[1], multicolorSpritePalette[0] );
2402 if ( !multicolorSpritePalette[1] ) {
2404 multicolorSpritePalette[1] =
malloc(
sizeof(
RGBi ) );
2405 memset( multicolorSpritePalette[1], 0,
sizeof(
RGBi ) );
2406 rgbi_move( &palette[2], multicolorSpritePalette[1] );
2412 rgbi_move( &SYSTEM_PALETTE[0], &temporaryPalette[0] );
2414 for(
int i=1; i<colorUsed; ++i ) {
2417 rgbi_move( &palette[i], &temporaryPalette[1] );
2418 }
else if (
rgbi_equals_rgba( &palette[i], multicolorSpritePalette[1] ) ) {
2420 rgbi_move( &palette[i], &temporaryPalette[3] );
2423 rgbi_move( &palette[i], &temporaryPalette[2] );
2427 rgbi_move( &temporaryPalette[0], &palette[0] );
2429 rgbi_move( &temporaryPalette[1], &palette[1] );
2431 rgbi_move( &temporaryPalette[2], &palette[2] );
2433 rgbi_move( &temporaryPalette[3], &palette[3] );
2440 int bufferSize = 64;
2444 char * buffer =
malloc ( bufferSize );
2445 memset( buffer, 0, bufferSize );
2448 int image_x, image_y;
2457 for (image_y = 0; image_y < _height; ++image_y) {
2458 if ( image_y == 21 ) {
2461 for (image_x = 0; image_x < _width; ++image_x) {
2464 if ( image_x == 12 ) {
2468 if ( image_x == 24 ) {
2475 rgb.
green = *(_source + 1);
2476 rgb.
blue = *(_source + 2);
2478 rgb.
alpha = *(_source + 3);
2483 if ( rgb.
alpha < 255 ) {
2488 for( i=0; i<colorUsed; ++i ) {
2508 offset = ( image_y * 3 ) + (image_x >> 2);
2509 bitmask = i << (6 - ((image_x & 0x3) * 2));
2512 *( buffer +
offset) |= bitmask;
2515 *( buffer +
offset) &= ~bitmask;
2523 offset = ( image_y * 3 ) + (image_x >> 3);
2524 bitmask = 1 << ( 7 - (image_x & 0x7) );
2527 *( buffer +
offset) |= bitmask;
2530 *( buffer +
offset) &= ~bitmask;
2541 _source += 3 * ( _width - image_x );
2548 *(buffer+63) = _color->
index;
2551 *(buffer+63) = palette[3].index;
2553 *(buffer+63) = palette[1].index;
2567void vic2z_put_image(
Environment * _environment,
char * _image,
char * _x,
char * _y,
char * _frame,
char * _sequence,
int _frame_size,
int _frame_count,
char * _flags ) {
2569 deploy( vic2zvars, src_hw_vic2z_vars_asm);
2570 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2571 deploy( putimage, src_hw_vic2z_put_image_asm );
2590 if ( strlen(_sequence) == 0 ) {
2593 outline1(
"LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
2595 outline1(
"LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
2611 if ( strlen(_frame) == 0 ) {
2614 outline1(
"LDA #<OFFSETS%4.4x", _frame_size );
2616 outline1(
"LDA #>OFFSETS%4.4x", _frame_size );
2642 if ( strlen(_frame) == 0 ) {
2645 outline1(
"LDA #<OFFSETS%4.4x", _frame_size );
2647 outline1(
"LDA #>OFFSETS%4.4x", _frame_size );
2681static void vic2_load_image_address_to_other_register(
Environment * _environment,
char * _register,
char * _source,
char * _sequence,
char * _frame,
int _frame_size,
int _frame_count ) {
2697 if ( strlen(_sequence) == 0 ) {
2700 outline1(
"LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
2702 outline1(
"LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
2718 if ( strlen(_frame) == 0 ) {
2721 outline1(
"LDA #<OFFSETS%4.4x", _frame_size );
2723 outline1(
"LDA #>OFFSETS%4.4x", _frame_size );
2749 if ( strlen(_frame) == 0 ) {
2752 outline1(
"LDA #<OFFSETS%4.4x", _frame_size );
2754 outline1(
"LDA #>OFFSETS%4.4x", _frame_size );
2774static void vic2z_load_image_address_to_register(
Environment * _environment,
char * _register,
char * _source,
char * _sequence,
char * _frame,
int _frame_size,
int _frame_count ) {
2790 if ( strlen(_sequence) == 0 ) {
2793 outline1(
"LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
2795 outline1(
"LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
2811 if ( strlen(_frame) == 0 ) {
2814 outline1(
"LDA #<OFFSETS%4.4x", _frame_size );
2816 outline1(
"LDA #>OFFSETS%4.4x", _frame_size );
2842 if ( strlen(_frame) == 0 ) {
2845 outline1(
"LDA #<OFFSETS%4.4x", _frame_size );
2847 outline1(
"LDA #>OFFSETS%4.4x", _frame_size );
2867void vic2z_blit_image(
Environment * _environment,
char * _sources[],
int _source_count,
char * _blit,
char * _x,
char * _y,
char * _frame,
char * _sequence,
int _frame_size,
int _frame_count,
int _flags ) {
2869 deploy( vic2zvars, src_hw_vic2z_vars_asm);
2870 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2871 deploy( blitimage, src_hw_vic2z_blit_image_asm );
2873 if ( _source_count > 2 ) {
2882 outline0(
"STA BLITIMAGEBLITADDR" );
2884 outline0(
"STA BLITIMAGEBLITADDR+1" );
2886 if ( _source_count > 0 ) {
2887 vic2z_load_image_address_to_register( _environment,
"BLITTMPPTR", _sources[0], _sequence, _frame, _frame_size, _frame_count );
2894 if ( _source_count > 1 ) {
2895 vic2z_load_image_address_to_register( _environment,
"BLITTMPPTR2", _sources[1], _sequence, _frame, _frame_size, _frame_count );
2912 outline1(
"LDA #$%2.2x", ( _flags & 0xff ) );
2914 outline1(
"LDA #$%2.2x", ( (_flags>>8) & 0xff ) );
2923 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2924 deploy( vbl, src_hw_vic2z_vbl_asm);
2932 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2934 int size = calculate_image_size( _environment, _width, _height, _mode );
2943 memset( buffer, 0,
size );
2945 *(buffer) = (_width & 0xff);
2946 *(buffer+1) = (_width>>8) & 0xff;
2947 *(buffer+2) = _height;
2958 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2960 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2961 int frameSize = calculate_image_size( _environment, _width, _height, _mode );
2970 memset( buffer, 0,
size );
2972 *(buffer) = _frames;
2973 *(buffer+1) = ( _width & 0xff );
2974 *(buffer+2) = ( _width >> 8 ) & 0xff;
2975 for(
int i=0; i<_frames; ++i ) {
2976 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2977 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2978 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2992 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2994 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
2995 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2996 int frameSize = calculate_image_size( _environment, _width, _height, _mode );
3004 char * buffer =
malloc ( size2 );
3005 memset( buffer, 0, size2 );
3007 *(buffer) = _frames;
3008 *(buffer+1) = _width;
3009 *(buffer+2) = _sequences;
3010 for(
int i=0; i<(_frames*_sequences); ++i ) {
3011 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
3012 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
3013 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
3025void vic2z_get_image(
Environment * _environment,
char * _image,
char * _x,
char * _y,
char * _frame,
char * _sequence,
int _frame_size,
int _frame_count,
int _palette ) {
3027 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3028 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
3029 deploy( getimage, src_hw_vic2z_get_image_asm );
3033 vic2_load_image_address_to_other_register( _environment,
"TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3043 outline1(
"LDA #$%2.2x", _palette );
3052 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3054 deploy( textHScroll, src_hw_vic2z_hscroll_text_asm );
3055 deploy( vScrollTextDown, src_hw_vic2z_vscroll_text_down_asm );
3056 deploy( vScrollTextUp, src_hw_vic2z_vscroll_text_up_asm );
3058 outline1(
"LDA #$%2.2x", (
unsigned char)(_dx&0xff) );
3060 outline1(
"LDA #$%2.2x", (
unsigned char)(_dy&0xff) );
3068 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3069 deploy( tiles, src_hw_vic2z_tiles_asm );
3093 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3094 deploy( tiles, src_hw_vic2z_tiles_asm );
3130 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3131 deploy( tiles, src_hw_vic2z_tiles_asm );
3158 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3159 deploy( tiles, src_hw_vic2z_tiles_asm );
3175 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3176 deploy( tiles, src_hw_vic2z_tiles_asm );
3200void vic2z_slice_image(
Environment * _environment,
char * _image,
char * _frame,
char * _sequence,
int _frame_size,
int _frame_count,
char * _destination ) {
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
void cpu_beq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
int lastUsedSlotInCommonPalette
#define BITMAP_MODE_STANDARD
int calculate_nearest_tile(TileDescriptor *_tile, TileDescriptors *_tiles)
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
int rgbi_equals_rgba(RGBi *_first, RGBi *_second)
TileDescriptor * calculate_tile_descriptor(TileData *_tileData)
TileDescriptors * precalculate_tile_descriptors_for_font(char *_fontData, int _fontSize)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * malloc_palette(int _size)
Allocate a palette space.
void rgbi_move(RGBi *_source, RGBi *_destination)
int calculate_exact_tile(TileDescriptor *_tile, TileDescriptors *_tiles)
void variable_global(Environment *_environment, char *_pattern)
ScreenMode * find_screen_mode_by_suggestion(Environment *_environment, int _bitmap, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
void font_descriptors_init(Environment *_environment, int _embedded_present)
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
void image_converter_asserts(Environment *_environment, int _width, int _height, int _offset_x, int _offset_y, int *_frame_width, int *_frame_height, int _modulo_x, int _modulo_y)
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Variable * variable_store_buffer(Environment *_environment, char *_destination, unsigned char *_buffer, int _size, int _at)
void back(Environment *_environment, char *_color)
Emit ASM code to fill background color.
void color(Environment *_environment, int _index, int _shade)
Emit ASM code for instruction COLOR [int], [int].
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
#define TILEMAP_MODE_STANDARD
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
unsigned int data_font_alpha_bin_len
unsigned char data_font_alpha_bin[]
RgbConverterFunction currentRgbConverterFunction
TileDescriptors * descriptors
VestigialConfig vestigialConfig
TileDescriptor * descriptor[512]
unsigned char * valueBuffer
RGBi originalPalette[MAX_PALETTE]
#define TILEMAP_MODE_MULTICOLOR
#define TILEMAP_MODE_EXTENDED
#define BITMAP_MODE_MULTICOLOR
struct _ScreenMode ScreenMode
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define adilineendbitmap()
#define WARNING_SCREEN_MODE(v1)
struct _Variable Variable
Structure of a single variable.
#define SPRITE_FLAG_MULTICOLOR
#define deploy_deferred(s, e)
struct _Environment Environment
Structure of compilation environment.
#define adiline3(s, a, b, c)
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
#define CRITICAL_SCREEN_UNSUPPORTED(v)
struct _TileDescriptor TileDescriptor
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
#define adilinepalette(s, c, p)
#define adilinebeginbitmap(s)
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)
#define CRITICAL_BLIT_TOO_MUCH_SOURCES()
struct _TileData TileData
char * strcopy(char *_dest, char *_source)
#define BITMAP_MODE_IAFLI
#define BITMAP_MODE_NUIFLI
#define BITMAP_MODE_MEGATEXT
#define BITMAP_MODE_TRIFLI
#define BITMAP_MODE_MUIFLI
#define BITMAP_MODE_MUCSUH
#define BITMAP_MODE_XIFLI
#define BITMAP_MODE_ASSLACE
#define BITMAP_MODE_SHIFLI
#define BITMAP_MODE_MUFLI
#define BITMAP_MODE_AIFLI
#define BITMAP_MODE_MUCSUFLI
#define BITMAP_MODE_SHFLI
#define BITMAP_MODE_NUFLI
#define BITMAP_MODE_MRFLI
#define BITMAP_MODE_MUCSU
#define BITMAP_MODE_SHIFXL
#define BITMAP_MODE_UIFLI
void vic2z_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
void vic2z_sprite_disable(Environment *_environment, char *_sprite)
void vic2z_screen_off(Environment *_environment)
void vic2z_wait_vbl(Environment *_environment)
void vic2z_hscroll_line(Environment *_environment, int _direction, int _overlap)
void vic2z_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
void vic2z_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
void vic2z_sprite_enable(Environment *_environment, char *_sprite)
void vic2z_put_tiles(Environment *_environment, char *_image, char *_x, char *_y, char *_w, char *_h)
void vic2z_screen_rows(Environment *_environment, char *_rows)
int vic2z_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
void vic2z_put_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
void vic2z_vertical_scroll(Environment *_environment, char *_displacement)
void vic2z_tiles_at(Environment *_environment, char *_address)
void vic2z_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Variable * vic2z_new_image(Environment *_environment, int _width, int _height, int _mode)
void vic2z_sprite_multicolor(Environment *_environment, char *_sprite)
Variable * vic2z_image_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _mode, int _transparent_color, int _flags)
void vic2z_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
Variable * vic2z_get_raster_line(Environment *_environment)
void vic2z_scroll_text(Environment *_environment, int _direction, int _overlap)
void vic2z_scroll(Environment *_environment, int _dx, int _dy)
void vic2z_sprite_color(Environment *_environment, char *_sprite, char *_color)
void vic2z_get_height(Environment *_environment, char *_result)
void vic2z_hit(Environment *_environment, char *_sprite_mask, char *_result)
void vic2z_use_tileset(Environment *_environment, char *_tileset)
void vic2z_busy_wait(Environment *_environment, char *_timing)
void vic2z_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
void vic2z_bitmap_disable(Environment *_environment)
void vic2z_colormap_at(Environment *_environment, char *_address)
void vic2z_textmap_at(Environment *_environment, char *_address)
void vic2z_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
void vic2z_background_color_vars(Environment *_environment, char *_index, char *_background_color)
void vic2z_screen_columns(Environment *_environment, char *_columns)
void vic2z_sprite_expand_vertical(Environment *_environment, char *_sprite)
void vic2z_next_raster(Environment *_environment)
void vic2z_sprite_compress_vertical(Environment *_environment, char *_sprite)
void vic2z_bank_select(Environment *_environment, int _bank)
void vic2z_sprite_data_from(Environment *_environment, char *_sprite, char *_address)
void vic2z_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
void vic2z_background_color(Environment *_environment, int _index, int _background_color)
void vic2z_pset_int(Environment *_environment, int _x, int _y, int *_c)
void vic2z_blit_image(Environment *_environment, char *_sources[], int _source_count, char *_blit, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _flags)
Variable * vic2z_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Variable * vic2z_collision(Environment *_environment, char *_sprite)
void vic2z_initialization(Environment *_environment)
void vic2z_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
void vic2z_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
void vic2z_horizontal_scroll(Environment *_environment, char *_displacement)
void vic2z_tiles_get(Environment *_environment, char *_result)
void vic2z_bitmap_at(Environment *_environment, char *_address)
void vic2z_finalization(Environment *_environment)
void vic2z_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Variable * vic2z_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
void vic2z_get_width(Environment *_environment, char *_result)
void vic2z_screen_on(Environment *_environment)
void vic2z_background_color_semivars(Environment *_environment, int _index, char *_background_color)
void vic2z_hscroll_screen(Environment *_environment, int _direction, int _overlap)
void vic2z_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Variable * vic2z_sprite_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, RGBi *_color, int _flags)
void vic2z_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
void vic2z_border_color(Environment *_environment, char *_border_color)
void vic2z_sprite_compress_horizontal(Environment *_environment, char *_sprite)
void vic2z_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
void vic2z_back(Environment *_environment)
void vic2z_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
void vic2z_text(Environment *_environment, char *_text, char *_text_size, int _raw)
void vic2z_move_tiles(Environment *_environment, char *_image, char *_x, char *_y)
void vic2z_sprite_monocolor(Environment *_environment, char *_sprite)
void vic2z_cline(Environment *_environment, char *_characters)
void vic2z_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
void vic2z_cls(Environment *_environment)
void vic2z_put_tile(Environment *_environment, char *_image, char *_x, char *_y)