35#if defined(__vg5000__)
40static RGBi SYSTEM_PALETTE[] = {
41 { 0x00, 0x00, 0x00, 0xff, 1,
"BLACK" },
42 { 0x00, 0x00, 0x00, 0xff, 0,
"TRANSPARENT" },
43 { 0x00, 0x80, 0x00, 0xff, 2,
"GREEN" },
44 { 0x00, 0xff, 0x00, 0xff, 3,
"LIGHT_GREEN" },
45 { 0x00, 0x00, 0x80, 0xff, 4,
"DARK_BLUE" },
46 { 0x00, 0x00, 0xff, 0xff, 5,
"LIGHT_BLUE" },
47 { 0x80, 0x00, 0x00, 0xff, 6,
"DARK_RED" },
48 { 0x00, 0xff, 0xff, 0xff, 7,
"CYAN" },
49 { 0x80, 0x00, 0x00, 0xff, 8,
"RED" },
50 { 0xff, 0x00, 0x00, 0xff, 9,
"LIGHT_RED" },
51 { 0xff, 0xff, 0x20, 0xff, 10,
"DARK_YELLOW" },
52 { 0xff, 0xff, 0xee, 0xff, 11,
"LIGHT_YELLOW" },
53 { 0x00, 0x40, 0x00, 0xff, 12,
"DARK_GREEN" },
54 { 0xaa, 0x00, 0xaa, 0xff, 13,
"MAGENTA" },
55 { 0xaa, 0xaa, 0xaa, 0xff, 14,
"GRAY" },
56 { 0xff, 0xff, 0xff, 0xff, 15,
"WHITE" }
65 int minDistance = 0xffff;
75 return &SYSTEM_PALETTE[colorIndex];
90static void ef9345_image_converter_tile(
char * _source,
char * _dest,
int _width,
int _depth,
int _source_width ) {
94 int colorBackgroundMax = 0;
95 int colorBackground[8];
96 memset( colorBackground, 0, 8 );
98 int colorForegroundMax = 0;
99 int colorForeground[8];
100 memset( colorForeground, 0, 8 );
105 memset( _dest, 0, 16 );
108 for (
int y=0; y<8; ++y) {
110 memset(colorIndexesCount, 0,
COLOR_COUNT *
sizeof(
int ) );
111 colorBackgroundMax = 0;
112 colorForegroundMax = 0;
114 for (
int x=0; x<8; ++x) {
118 memset( &rgb, 0,
sizeof(
RGBi ) );
127 ++colorIndexesCount[systemRgb->
index];
134 if ( colorIndexesCount[xx] > colorBackgroundMax ) {
135 colorBackground[y] = xx;
136 colorBackgroundMax = colorIndexesCount[xx];
140 colorIndexesCount[colorBackground[y]] = 0;
143 if ( colorIndexesCount[xx] > colorForegroundMax ) {
144 colorForeground[y] = xx;
145 colorForegroundMax = colorIndexesCount[xx];
149 if ( colorForeground[y] == colorBackground[y] ) {
150 colorForeground[y] = ( colorBackground[y] == 0 ) ? 1 : 0;
153 source += _depth * ( _source_width - 8 );
159 for (
int y=0; y<8; ++y) {
160 for (
int x=0; x<8; ++x) {
164 memset( &rgb, 0,
sizeof(
RGBi ) );
172 char bitmask = 1 << ( 7 - ((x) & 0x7) );
174 if ( systemRgb->
index != colorBackground[y] ) {
175 *( _dest + y ) |= bitmask;
178 *( _dest + y ) &= ~bitmask;
186 source += _depth * ( _source_width - 8 );
190 for(
int i=0; i<8; ++i ) {
191 *( _dest + 8 + i ) = ( colorForeground[i] << 4 ) | colorBackground[i] ;
207static void ef9345_image_converter_tiles(
char * _source,
char * _dest,
int _width,
int _height,
int _depth,
int _source_width ) {
209 int bitmapSize = ( _width>>3 ) * _height;
210 int colormapSize = ( _width>>3 ) * _height;
212 memset( _dest, 0, bitmapSize + colormapSize );
214 for(
int y=0; y<_height; y+=8 ) {
215 for(
int x=0; x<_width; x+=8 ) {
217 char *
source = _source + ( ( y * _source_width ) + x ) * _depth;
220 ef9345_image_converter_tile(
source, tile, _width, _depth, _source_width );
222 int offset = ((y>>3) * 8 *( _width >> 3 ) ) + ((x>>3) * 8) + ((y) & 0x07);
228 char * destBitmap = _dest +
offset;
229 char * destColormap = _dest + bitmapSize +
offset;
230 for(
int i=0; i<8; ++i ) {
231 *destBitmap = tile[i];
232 *destColormap = tile[i+8];
409static int rgbConverterFunction(
int _red,
int _green,
int _blue ) {
412 unsigned int minDistance = 0xffffffff;
420 for (j = 0; j <
sizeof(SYSTEM_PALETTE)/
sizeof(
RGBi); ++j) {
463 switch( _screen_mode->
id ) {
683 outline0(
"LD HL, (CURRENTHEIGHT)" );
690 deploy( clsText, src_hw_ef9345_cls_asm );
716 deploy( ef9345vars, src_hw_ef9345_vars_asm);
717 deploy( textEncodedAt, src_hw_ef9345_text_at_asm );
731 deploy( ef9345vars, src_hw_ef9345_vars_asm );
732 deploy( ef9345startup, src_hw_ef9345_startup_asm );
886 deploy( clsText, src_hw_ef9345_cls_asm );
894 copperList = copperList->
next;
928static int calculate_images_size(
Environment * _environment,
int _frames,
int _width,
int _height,
int _mode ) {
940static int calculate_sequence_size(
Environment * _environment,
int _sequences,
int _frames,
int _width,
int _height,
int _mode ) {
1062Variable *
ef9345_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 ) {
1074void ef9345_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 ) {
1093 memset( buffer, 0,
size );
1095 *(buffer) = (_width & 0xff);
1096 *(buffer+1) = (_width>>8) & 0xff;
1097 *(buffer+2) = _height;
1108 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
1118 memset( buffer, 0,
size );
1120 *(buffer) = _frames;
1121 *(buffer+1) = ( _width & 0xff );
1122 *(buffer+2) = ( _width >> 8 ) & 0xff;
1123 for(
int i=0; i<_frames; ++i ) {
1124 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
1125 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
1126 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
1140 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
1141 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
1150 char * buffer =
malloc ( size2 );
1151 memset( buffer, 0, size2 );
1153 *(buffer) = _frames;
1154 *(buffer+1) = _width;
1155 *(buffer+2) = _sequences;
1156 for(
int i=0; i<(_frames*_sequences); ++i ) {
1157 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
1158 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
1159 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
1172void ef9345_get_image(
Environment * _environment,
char * _image,
char * _x,
char * _y,
char * _frame,
char * _sequence,
int _frame_size,
int _frame_count,
int _palette ) {
1225 memcpy( _palette,
palette_match( _palette, paletteColorCount, SYSTEM_PALETTE,
sizeof(SYSTEM_PALETTE) /
sizeof(
RGBi) ), paletteColorCount *
sizeof(
RGBi ) );
1227 int uniquePaletteCount = 0;
1231 return uniquePaletteCount;
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
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
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".
#define TILEMAP_MODE_STANDARD
void console_init(Environment *_environment)
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
void ef9345_textmap_at(Environment *_environment, char *_address)
void ef9345_sprite_compress_vertical(Environment *_environment, char *_sprite)
void ef9345_tiles_at(Environment *_environment, char *_address)
RGBi * ef9345_image_nearest_system_color(RGBi *_color)
void ef9345_screen_columns(Environment *_environment, char *_columns)
void ef9345_sprite_expand_vertical(Environment *_environment, char *_sprite)
void ef9345_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
void ef9345_wait_vbl(Environment *_environment)
void ef9345_bitmap_at(Environment *_environment, char *_address)
void ef9345_busy_wait(Environment *_environment, char *_timing)
void ef9345_border_color(Environment *_environment, char *_border_color)
EF9345: emit code to change border color
void ef9345_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
EF9345: emit code to change common sprite's color
void ef9345_screen_off(Environment *_environment)
void ef9345_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)
void ef9345_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
EF9345: emit code to retrieve background color
void ef9345_background_color_vars(Environment *_environment, char *_index, char *_background_color)
EF9345: emit code to change background color
void ef9345_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
void ef9345_sprite_data_from(Environment *_environment, char *_sprite, char *_image)
int ef9345_image_size(Environment *_environment, int _width, int _height, int _mode)
void ef9345_next_raster(Environment *_environment)
EF9345: emit code to wait for next raster irq
void ef9345_vertical_scroll(Environment *_environment, char *_displacement)
void ef9345_use_tileset(Environment *_environment, char *_tileset)
void ef9345_sprite_color(Environment *_environment, char *_sprite, char *_color)
Variable * ef9345_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
void ef9345_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
EF9345: emit code to wait for next raster irq at different position
void ef9345_sprite_compress_horizontal(Environment *_environment, char *_sprite)
void ef9345_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
void ef9345_text(Environment *_environment, char *_text, char *_text_size, int _raw)
void ef9345_move_video_memory(Environment *_environment, char *_from, char *_to, char *_size)
void ef9345_screen_on(Environment *_environment)
void ef9345_initialization(Environment *_environment)
void ef9345_scroll(Environment *_environment, int _dx, int _dy)
void ef9345_background_color(Environment *_environment, int _index, int _background_color)
EF9345: emit code to change background color
void ef9345_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
void ef9345_bank_select(Environment *_environment, int _bank)
void ef9345_get_height(Environment *_environment, char *_result)
void ef9345_cline(Environment *_environment, char *_characters)
int ef9345_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
void ef9345_pset_int(Environment *_environment, int _x, int _y, int *_c)
void ef9345_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
void ef9345_finalization(Environment *_environment)
void ef9345_colormap_at(Environment *_environment, char *_address)
void ef9345_cls(Environment *_environment)
void ef9345_scroll_text(Environment *_environment, int _direction, int _overlap)
void ef9345_sprite_disable(Environment *_environment, char *_sprite)
void ef9345_sprite_expand_horizontal(Environment *_environment, char *_sprite)
void ef9345_tiles_get(Environment *_environment, char *_result)
void ef9345_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Variable * ef9345_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Variable * ef9345_sprite_converter(Environment *_environment, char *_source, int _width, int _height, int _depth, RGBi *_color)
void ef9345_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
void ef9345_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
void ef9345_sprite_multicolor(Environment *_environment, char *_sprite)
void ef9345_hscroll_line(Environment *_environment, int _direction, int _overlap)
void console_calculate_vars(Environment *_environment)
int ef9345_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
void ef9345_bitmap_disable(Environment *_environment)
void ef9345_sprite_data_set(Environment *_environment, char *_sprite, char *_image)
void ef9345_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
EF9345: emit code to set raster irq
void ef9345_screen_rows(Environment *_environment, char *_rows)
void ef9345_sprite_enable(Environment *_environment, char *_sprite)
Variable * ef9345_get_raster_line(Environment *_environment)
void ef9345_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Variable * ef9345_collision(Environment *_environment, char *_sprite)
EF9345: emit code to check for collision
void ef9345_background_color_semivars(Environment *_environment, int _index, char *_background_color)
EF9345: emit code to change background color
void ef9345_move_memory_video(Environment *_environment, char *_from, char *_to, char *_size)
void ef9345_sprite_monocolor(Environment *_environment, char *_sprite)
void ef9345_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
void ef9345_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
void ef9345_back(Environment *_environment)
void ef9345_get_width(Environment *_environment, char *_result)
Variable * ef9345_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 ef9345_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
void ef9345_hit(Environment *_environment, char *_sprite_mask, char *_result)
EF9345: emit code to check for collision
void console_calculate(Environment *_environment)
void ef9345_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
void ef9345_hscroll_screen(Environment *_environment, int _direction, int _overlap)
void ef9345_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
void ef9345_horizontal_scroll(Environment *_environment, char *_displacement)
Variable * ef9345_new_image(Environment *_environment, int _width, int _height, int _mode)
void ef9345_colors_vars(Environment *_environment, char *_foreground_color, char *_background_color)
struct _CopperList * next
RgbConverterFunction currentRgbConverterFunction
VestigialConfig vestigialConfig
unsigned char * valueBuffer
struct _ScreenMode ScreenMode
struct _Resource Resource
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define WARNING_SCREEN_MODE(v1)
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
struct _CopperList CopperList
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)