ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
ef936x.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSì COM'è", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#if defined(__pc128op__) || defined(__mo5__) || defined(__to8__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40#if defined(__pc128op__)
41
42 static RGBi SYSTEM_PALETTE[] = {
43 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK", 0 },
44 { 0xff, 0xff, 0xff, 0xff, 1, "WHITE", 1 },
45 { 0x88, 0x00, 0x00, 0xff, 2, "RED", 2 },
46 { 0xaa, 0xff, 0xe6, 0xff, 3, "CYAN", 3 },
47 { 0xcc, 0x44, 0xcc, 0xff, 4, "VIOLET", 4 },
48 { 0x00, 0xcc, 0x55, 0xff, 5, "GREEN", 5 },
49 { 0x00, 0x00, 0xaa, 0xff, 6, "BLUE", 6 },
50 { 0xee, 0xee, 0x77, 0xff, 7, "YELLOW", 7 },
51 { 0xa1, 0x68, 0x3c, 0xff, 8, "ORANGE", 8 },
52 { 0xdd, 0x88, 0x65, 0xff, 9, "BROWN", 9 },
53 { 0xff, 0x77, 0x77, 0xff, 10, "LIGHT RED", 10 },
54 { 0x33, 0x33, 0x33, 0xff, 11, "DARK GREY", 11 },
55 { 0x77, 0x77, 0x77, 0xff, 12, "GREY", 12 },
56 { 0xaa, 0xff, 0x66, 0xff, 13, "LIGHT GREEN", 13 },
57 { 0x00, 0x88, 0xff, 0xff, 14, "LIGHT BLUE", 14 },
58 { 0xbb, 0xbb, 0xbb, 0xff, 15, "LIGHT GREY", 15 }
59 };
60
61#elif defined(__mo5__)
62
63 static RGBi SYSTEM_PALETTE[] = {
64 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK", 0 },
65 { 0x88, 0x00, 0x00, 0xff, 1, "RED", 1 },
66 { 0x00, 0xcc, 0x55, 0xff, 2, "GREEN", 2 },
67 { 0xee, 0xee, 0x77, 0xff, 3, "YELLOW", 3 },
68 { 0x00, 0x00, 0xaa, 0xff, 4, "BLUE", 4 },
69 { 0xcc, 0x44, 0xcc, 0xff, 5, "VIOLET", 5 },
70 { 0xaa, 0xff, 0xe6, 0xff, 6, "CYAN", 6 },
71 { 0xff, 0xff, 0xff, 0xff, 7, "WHITE", 7 },
72 { 0x77, 0x77, 0x77, 0xff, 8, "GREY", 8 },
73 { 0xff, 0x77, 0x77, 0xff, 9, "OLD ROSE", 9 },
74 { 0xaa, 0xff, 0x66, 0xff, 10, "LIGHT GREEN", 10 },
75 { 0xdd, 0x88, 0x65, 0xff, 11, "SAND", 11 },
76 { 0x00, 0x88, 0xff, 0xff, 12, "SKY BLUE", 12 },
77 { 0xec, 0x54, 0xe4, 0xff, 13, "LIGHT MAGENTA", 13 },
78 { 0xee, 0xff, 0xff, 0xff, 14, "CYAN", 14 },
79 { 0xa1, 0x68, 0x3c, 0xff, 15, "ORANGE", 15 }
80 };
81
82#elif defined(__to8__)
83
84 static RGBi SYSTEM_PALETTE[] = {
85 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK", 0 },
86 { 0xff, 0xff, 0xff, 0xff, 1, "WHITE", 1 },
87 { 0x88, 0x00, 0x00, 0xff, 2, "RED", 2 },
88 { 0xaa, 0xff, 0xe6, 0xff, 3, "CYAN", 3 },
89 { 0xcc, 0x44, 0xcc, 0xff, 4, "VIOLET", 4 },
90 { 0x00, 0xcc, 0x55, 0xff, 5, "GREEN", 5 },
91 { 0x00, 0x00, 0xaa, 0xff, 6, "BLUE", 6 },
92 { 0xee, 0xee, 0x77, 0xff, 7, "YELLOW", 7 },
93 { 0xa1, 0x68, 0x3c, 0xff, 8, "ORANGE", 8 },
94 { 0xdd, 0x88, 0x65, 0xff, 9, "BROWN", 9 },
95 { 0xff, 0x77, 0x77, 0xff, 10, "LIGHT RED", 10 },
96 { 0x33, 0x33, 0x33, 0xff, 11, "DARK GREY", 11 },
97 { 0x77, 0x77, 0x77, 0xff, 12, "GREY", 12 },
98 { 0xaa, 0xff, 0x66, 0xff, 13, "LIGHT GREEN", 13 },
99 { 0x00, 0x88, 0xff, 0xff, 14, "LIGHT BLUE", 14 },
100 { 0xbb, 0xbb, 0xbb, 0xff, 15, "LIGHT GREY", 15 }
101 };
102
103#endif
104
105static RGBi * commonPalette;
107
108/****************************************************************************
109 * CODE SECTION
110 ****************************************************************************/
111
112extern char DATATYPE_AS_STRING[][16];
113
114static int rgbConverterFunction( int _red, int _green, int _blue ) {
115
116 int value = ( ( ( _blue >> 4 ) & 0x0f ) << 8 ) |
117 ( ( ( _green >> 4 ) & 0x0f ) << 4 ) |
118 ( ( ( _red >> 4 ) & 0x0f ) );
119
120 return value;
121
122}
123
124static void rgbConverterFunctionInverse( int _value, unsigned char* _red, unsigned char* _green, unsigned char* _blue ) {
125
126 *_red = (unsigned char)( _value & 0xf ) << 4;
127 *_green = (unsigned char)( _value & 0xf0 );
128 *_blue = (unsigned char)( _value & 0xf00 ) >> 4;
129
130}
131
143void ef936x_collision( Environment * _environment, char * _sprite_mask, char * _result ) {
144
145}
146
158void ef936x_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
159
160}
161
171void ef936x_border_color( Environment * _environment, char * _border_color ) {
172
173}
174
185void ef936x_background_color( Environment * _environment, int _index, int _background_color ) {
186
187 outline1("LDB #$%2.2x", ( _index & 0x0f ) * 2 );
188 outline0("STB BASE_SEGMENT+$DB" );
189 outline1("LDD #$%4.4x", _background_color );
190 outline1("STD SHADOWPALETTE+$%2.2x", ( _index & 0x0f ) * 2 );
191 outline0("STB BASE_SEGMENT+$DA" );
192 outline0("STA BASE_SEGMENT+$DA" );
193
194 rgbConverterFunctionInverse( _background_color, &SYSTEM_PALETTE[_index].red, &SYSTEM_PALETTE[_index].green, &SYSTEM_PALETTE[_index].blue );
195
196 // printf("SYSTEM_PALETTE[_index].index = %d\n", _index );
197 // printf("SYSTEM_PALETTE[_index].red = %2.2x\n", SYSTEM_PALETTE[_index].red );
198 // printf("SYSTEM_PALETTE[_index].green = %2.2x\n", SYSTEM_PALETTE[_index].green );
199 // printf("SYSTEM_PALETTE[_index].blue = %2.2x\n", SYSTEM_PALETTE[_index].blue );
200 // printf("\n" );
201
202 SYSTEM_PALETTE[_index].index = _index;
203 strcopy( SYSTEM_PALETTE[_index].description, "custom" );
204 SYSTEM_PALETTE[_index].used = 0;
205 SYSTEM_PALETTE[_index].count = 0;
206
207}
208
219void ef936x_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
220
221 outline1("LDB %s", _index );
222 outline0("LSLB" );
223 outline0("STB BASE_SEGMENT+$DB" );
224 outline1("LDD %s", _background_color );
225 outline0("STB BASE_SEGMENT+$DA" );
226 outline0("STA BASE_SEGMENT+$DA" );
227 outline0("LDX #SHADOWPALETTE" );
228 outline1("LDB %s", _index );
229 outline0("LSLB" );
230 outline0("ABX" );
231 outline1("LDD %s", _background_color );
232 outline0("STD B,X" );
233
234}
235
246void ef936x_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
247
248 outline1("LDB #$%2.2x", (( _index & 0x0f ) *2) );
249 outline0("STB BASE_SEGMENT+$DB" );
250 outline1("LDD %s", _background_color );
251 outline0("STB BASE_SEGMENT+$DA" );
252 outline0("STA BASE_SEGMENT+$DA" );
253 outline1("STD SHADOWPALETTE+$%2.2x", ( _index & 0x0f ) * 2 );
254
255}
256
267void ef936x_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
268
269 outline1("LDB %s", _index );
270 outline0("ASLB" );
271 outline0("LDX #SHADOWPALETTE" );
272 outline0("LDD B,X" );
273 outline1("STD %s", _background_color );
274
275}
276
287void ef936x_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
288
289}
290
306void ef936x_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
307
308}
309
320void ef936x_next_raster( Environment * _environment ) {
321
322}
323
337void ef936x_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
338
339}
340
341void ef936x_bank_select( Environment * _environment, int _bank ) {
342
343}
344
345void console_calculate( Environment * _environment ) {
346
347 #if defined(__to8__)
348 int consoleSA = 0x4000;
349 #else
350 int consoleSA = 0x0000;
351 #endif
352 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
353 int consoleHB = _environment->activeConsole.height * 8;
354
355 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
356 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
357 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
358
359}
360
361void console_calculate_vars( Environment * _environment ) {
362
363 _environment->dynamicConsole = 1;
364
365 outline0( "JSR CONSOLECALCULATE" );
366
367}
368
369int ef936x_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
370
371 _screen_mode->selected = 1;
372
373 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm );
374
375 _environment->fontWidth = 8;
376 _environment->fontHeight = 8;
377 _environment->screenTiles = 255;
378 switch( _screen_mode->id ) {
380 _environment->screenWidth = 320;
381 _environment->screenHeight = 200;
382 _environment->screenTilesWidth = 40;
383 _environment->screenTilesHeight = 25;
384 _environment->screenColors = 16;
385 _environment->currentModeBW = 4;
386 #if defined(__to8__)
387 outline0("LDA #%00100000");
388 #else
389 outline0("LDA #%00000000");
390 #endif
391 outline0("STA BASE_SEGMENT+$DC");
392 break;
394 _environment->screenWidth = 640;
395 _environment->screenHeight = 200;
396 _environment->screenTilesWidth = 80;
397 _environment->screenTilesHeight = 25;
398 _environment->screenColors = 4;
399 _environment->currentModeBW = 2;
400 outline0("LDA #%00101010");
401 outline0("STA BASE_SEGMENT+$DC");
402 break;
404 _environment->screenWidth = 320;
405 _environment->screenHeight = 200;
406 _environment->screenTilesWidth = 40;
407 _environment->screenTilesHeight = 25;
408 _environment->screenColors = 4;
409 _environment->currentModeBW = 2;
410 outline0("LDA #%00100001");
411 outline0("STA BASE_SEGMENT+$DC");
412 break;
414 _environment->screenWidth = 160;
415 _environment->screenHeight = 200;
416 _environment->screenTilesWidth = 20;
417 _environment->screenTilesHeight = 25;
418 _environment->screenColors = 16;
419 _environment->currentModeBW = 4;
420 outline0("LDA #%01111011");
421 outline0("STA BASE_SEGMENT+$DC");
422 break;
423 case BITMAP_MODE_PAGE:
424 _environment->screenWidth = 320;
425 _environment->screenHeight = 200;
426 _environment->screenTilesWidth = 40;
427 _environment->screenTilesHeight = 25;
428 _environment->screenColors = 4;
429 _environment->currentModeBW = 2;
430 outline0("LDA #%00100100");
431 outline0("STA BASE_SEGMENT+$DC");
432 break;
433 default:
434 CRITICAL_SCREEN_UNSUPPORTED( _screen_mode->id );
435 }
436
437 _environment->consoleTilesWidth = _environment->screenTilesWidth;
438 _environment->consoleTilesHeight = _environment->screenTilesHeight;
439
440 cpu_store_16bit( _environment, "CLIPX1", 0 );
441 cpu_store_16bit( _environment, "CLIPX2", _environment->screenWidth-1 );
442 cpu_store_16bit( _environment, "CLIPY1", 0 );
443 cpu_store_16bit( _environment, "CLIPY2", _environment->screenHeight-1 );
444
445 cpu_store_16bit( _environment, "ORIGINX", 0 );
446 cpu_store_16bit( _environment, "ORIGINY", 0 );
447
448 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
449 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
450 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
451 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
452 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
453 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
454 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
455
456 console_init( _environment );
457
458 if (_environment->vestigialConfig.clsImplicit ) {
459 ef936x_cls( _environment );
460 }
461
462}
463
464void ef936x_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
465
466 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
467
468 if ( mode ) {
469 ef936x_screen_mode_enable( _environment, mode );
470 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
471 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
472 _environment->currentMode = mode->id;
473 _environment->currentTileMode = 0;
474 } else {
476 }
477
478}
479
480void ef936x_bitmap_disable( Environment * _environment ) {
481
482}
483
484void ef936x_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
485
486 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
487
488 if ( mode ) {
489 ef936x_screen_mode_enable( _environment, mode );
490 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
491 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
492 _environment->currentMode = mode->id;
493 _environment->currentTileMode = 1;
494 } else {
496 }
497
498}
499
500void ef936x_bitmap_at( Environment * _environment, char * _address ) {
501
502}
503
504void ef936x_colormap_at( Environment * _environment, char * _address ) {
505
506}
507
508void ef936x_textmap_at( Environment * _environment, char * _address ) {
509
510}
511
512void ef936x_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
513
514 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm );
515 deploy( plot, src_hw_ef936x_plot_asm );
516
517 outline0("LDA #1");
518 outline1("LDX %4.4x", (_x & 0xffff ) );
519 outline1("LDU %4.4x", ( _y & 0xffff ) );
520 if ( _c ) {
521 outline1("LDB #$%2.2x", ( *_c & 0Xff ) );
522 } else {
523 Variable * c = variable_retrieve( _environment, "PEN" );
524 outline1("LDB %s", c->realName );
525 }
526 outline0("STB <PLOTCPE" );
527 outline0("JSR PLOT");
528}
529
530void ef936x_pset_vars( Environment * _environment, char *_x, char *_y, char * _c ) {
531
532 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
533 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
534 Variable * c;
535
536 if ( _c ) {
537 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
538 } else {
539 c = variable_retrieve( _environment, "PEN" );
540 }
541
542 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm );
543 deploy( plot, src_hw_ef936x_plot_asm );
544
545 outline0("LDA #1");
546 outline1("LDX %s", x->realName );
547 outline1("LDU %s", y->realName );
548 outline1("LDB %s", c->realName );
549 outline0("STB <PLOTCPE" );
550 outline0("JSR PLOT");
551
552}
553
554void ef936x_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
555
556 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
557 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
558 Variable * result = variable_retrieve_or_define( _environment, _result, VT_BYTE, 0 );
559
560 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm );
561 deploy( plot, src_hw_ef936x_plot_asm );
562
563 outline0("LDA #3");
564 outline1("LDX %s", x->realName );
565 outline1("LDU %s", y->realName );
566 outline0("JSR PLOT");
567 outline1("STB %s", result->realName );
568
569}
570
571void ef936x_screen_on( Environment * _environment ) {
572
573}
574
575void ef936x_screen_off( Environment * _environment ) {
576
577}
578
579void ef936x_screen_rows( Environment * _environment, char * _rows ) {
580
581}
582
583void ef936x_screen_columns( Environment * _environment, char * _columns ) {
584
585}
586
587void ef936x_sprite_data_from( Environment * _environment, char * _sprite, char * _address ) {
588
589}
590
591void ef936x_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
592
593}
594
595void ef936x_sprite_enable( Environment * _environment, char * _sprite ) {
596
597}
598
599void ef936x_sprite_disable( Environment * _environment, char * _sprite ) {
600
601}
602
603void ef936x_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
604
605}
606
607void ef936x_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
608
609}
610
611void ef936x_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
612
613}
614
615void ef936x_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
616
617}
618
619void ef936x_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
620
621}
622
623void ef936x_sprite_multicolor( Environment * _environment, char * _sprite ) {
624
625}
626
627void ef936x_sprite_monocolor( Environment * _environment, char * _sprite ) {
628
629}
630
631void ef936x_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
632
633}
634
635void ef936x_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
636
637}
638
639void ef936x_tiles_at( Environment * _environment, char * _address ) {
640
641}
642
643void ef936x_vertical_scroll( Environment * _environment, char * _displacement ) {
644
645}
646
647void ef936x_horizontal_scroll( Environment * _environment, char * _displacement ) {
648
649}
650
651void ef936x_get_width( Environment * _environment, char *_result ) {
652
653 outline0("LDD CURRENTWIDTH" );
654 outline1("STD %s", _result );
655
656}
657
658void ef936x_tiles_get( Environment * _environment, char *_result ) {
659
660 outline0("LDB CURRENTTILES" );
661 outline1("STB %s", _result );
662
663}
664
665void ef936x_get_height( Environment * _environment, char *_result ) {
666
667 outline0("LDD CURRENTHEIGHT" );
668 outline1("STD %s", _result );
669
670}
671
672void ef936x_cls( Environment * _environment ) {
673
674 deploy_preferred( clsGraphic, src_hw_ef936x_cls_asm );
675
676 outline0("JSR CLS");
677
678}
679
680void ef936x_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
681
682 deploy_preferred( clsBox, src_hw_ef936x_cls_box_asm );
683 outline1("LDD %s", _x1 );
684 outline0("STD <IMAGEX" );
685 outline1("LDD %s", _y1 );
686 outline0("STD <IMAGEY" );
687 outline1("LDD %s", _w );
688 outline0("STD <IMAGEW" );
689 outline1("LDA %s", _h );
690 outline0("STA <IMAGEH" );
691 outline0("JSR CLSBOX");
692
693}
694
695void ef936x_scroll_text( Environment * _environment, int _direction, int _overlap ) {
696
697 deploy( vScrollText, src_hw_ef936x_vscroll_text_asm );
698
699 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
700 outline0("STA <DIRECTION" );
701
702 outline0("JSR VSCROLLT");
703
704}
705
706void ef936x_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
707
708 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm);
709 deploy( vScrollText, src_hw_ef936x_vscroll_text_asm );
710 deploy_preferred( clsGraphic, src_hw_ef936x_cls_asm );
711
712 if( ! _environment->descriptors ) {
713 font_descriptors_init( _environment, 0 );
714 }
715
716 outline1("LDY %s", _text);
717 outline0("STY <TEXTPTR" );
718 outline1("LDA %s", _text_size);
719 outline0("STA <TEXTSIZE" );
720
721 if ( _raw ) {
722 deploy_preferred( textEncodedAtGraphicRaw, src_hw_ef936x_text_at_raw_asm );
723 outline0("JSR TEXTATRAW");
724 } else {
725 deploy_preferred( textEncodedAtGraphic, src_hw_ef936x_text_at_asm );
726 outline0("JSR TEXTAT");
727 }
728
729}
730
731void ef936x_initialization( Environment * _environment ) {
732
733 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm );
734 deploy_preferred( ef936xstartup, src_hw_ef936x_startup_asm );
735
736 variable_import( _environment, "CURRENTMODE", VT_BYTE, 0 );
737 variable_global( _environment, "CURRENTMODE" );
738 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
739 variable_global( _environment, "CURRENTTILEMODE" );
740
741 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 320 );
742 variable_global( _environment, "CURRENTWIDTH" );
743 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 200 );
744 variable_global( _environment, "CURRENTHEIGHT" );
745 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
746 variable_global( _environment, "CURRENTTILES" );
747 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 40 );
748 variable_global( _environment, "CURRENTTILESWIDTH" );
749 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 25 );
750 variable_global( _environment, "CURRENTTILESHEIGHT" );
751 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
752 variable_global( _environment, "FONTWIDTH" );
753 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
754 variable_global( _environment, "FONTHEIGHT" );
755
756#if !defined(__mo5__)
757 SCREEN_MODE_DEFINE( BITMAP_MODE_BITMAP_16, 1, 160, 200, 16, 8, 8, "BITMAP MODE BITMAP 16" );
758#endif
759 SCREEN_MODE_DEFINE( BITMAP_MODE_40_COLUMN, 1, 320, 200, 15, 8, 8, "BITMAP MODE 40 COLUMN" );
760#if !defined(__mo5__)
761 SCREEN_MODE_DEFINE( BITMAP_MODE_BITMAP_4, 1, 320, 200, 4, 8, 8, "BITMAP MODE BITMAP 4" );
762#endif
763 // SCREEN_MODE_DEFINE( BITMAP_MODE_80_COLUMN, 1, 640, 200, 2, 8, 8, "BITMAP MODE 80 COLUMN" );
764 // SCREEN_MODE_DEFINE( BITMAP_MODE_PAGE, 1, 320, 200, 4, 8, 8, "BITMAP MODE PAGE" );
765
766 outline0("JSR EF936XSTARTUP");
767
768 variable_import( _environment, "XGR", VT_POSITION, 0 );
769 variable_global( _environment, "XGR" );
770 variable_import( _environment, "YGR", VT_POSITION, 0 );
771 variable_global( _environment, "YGR" );
772 variable_import( _environment, "LINE", VT_WORD, (unsigned short)(0xffff) );
773 variable_global( _environment, "LINE" );
774 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
775 variable_global( _environment, "TABCOUNT" );
776
777 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
778 variable_global( _environment, "CLIPX1" );
779 variable_import( _environment, "CLIPX2", VT_POSITION, 319 );
780 variable_global( _environment, "CLIPX2" );
781 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
782 variable_global( _environment, "CLIPY1" );
783 variable_import( _environment, "CLIPY2", VT_POSITION, 199 );
784 variable_global( _environment, "CLIPY2" );
785
786 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
787 variable_global( _environment, "ORIGINX" );
788 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
789 variable_global( _environment, "ORIGINY" );
790
791 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
792 variable_global( _environment, "RESOLUTIONX" );
793 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
794 variable_global( _environment, "RESOLUTIONY" );
795
796 // ef936x_cls( _environment );
797
798 _environment->fontWidth = 8;
799 _environment->fontHeight = 8;
800 _environment->screenTilesWidth = 40;
801 _environment->screenTilesHeight = 25;
802 _environment->consoleTilesWidth = 40;
803 _environment->consoleTilesHeight = 25;
804 _environment->screenTiles = 255;
805 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
806 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
807 _environment->screenShades = 16;
808 _environment->screenColors = 16;
809 _environment->currentModeBW = 1;
810 _environment->currentRgbConverterFunction = rgbConverterFunction;
811
812 cpu_store_16bit( _environment, "CLIPX1", 0 );
813 cpu_store_16bit( _environment, "CLIPX2", _environment->screenWidth-1 );
814 cpu_store_16bit( _environment, "CLIPY1", 0 );
815 cpu_store_16bit( _environment, "CLIPY2", _environment->screenHeight-1 );
816
817 cpu_store_16bit( _environment, "ORIGINX", 0 );
818 cpu_store_16bit( _environment, "ORIGINY", 0 );
819
820 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
821 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
822 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
823 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
824
825 font_descriptors_init( _environment, 1 );
826
827 _environment->currentRgbConverterFunction = rgbConverterFunction;
828 _environment->screenShades = 4096;
829
830 screen_mode( _environment, 0 );
831
832 reset_screen_mode_selected( _environment );
833
834}
835
836extern RGBi * commonPalette;
837
838// Converts a PC color to a thomson color for ef936
839// considering its very high gamma value.
840// Author: Samuel Devulder
841static int pc_to_ef936x(int _pc_color) {
842 // if(1) return (_pc_color>>4)&15;
843 double pc_color = _pc_color/255.0;
844 double ef936_color = 15*pow(pc_color, 1.67);
845 return 0x0F & (int)(ef936_color + 0.5);
846}
847
848// Calculate gamma value for each component.
849// Author: Dino Florenzi
850static unsigned short df_gamma(unsigned char c)
851{
852 int i,col=0;
853 int ef_vals[16]={0,60,90,110,130,148,165,180,193,205,215,225,230,235,240,255};
854 for (i=0;i<15;i++)
855 {
856 if((c>=ef_vals[i])&&(c<ef_vals[i+1])) return i;
857 }
858 return 15;
859}
860
861void ef936x_finalization( Environment * _environment ) {
862
863 int i;
864
865 outhead0("COMMONPALETTE");
866 out0(" fdb ");
867
868 RGBi * palette;
869
870 if ( commonPalette ) {
871 palette = commonPalette;
872 } else {
873 palette = SYSTEM_PALETTE;
874 }
875
876#if defined( __to8__ ) || defined( __mo5__ )
877 if ( _environment->currentMode < 3 ) {
878
879 RGBi * transposedPalette = malloc_palette( 16 );
880 rgbi_move( &palette[0], &transposedPalette[8] );
881 rgbi_move( &palette[1], &transposedPalette[10] );
882 rgbi_move( &palette[2], &transposedPalette[12] );
883 rgbi_move( &palette[3], &transposedPalette[14] );
884
885 rgbi_move( &palette[4], &transposedPalette[0] );
886 rgbi_move( &palette[5], &transposedPalette[2] );
887 rgbi_move( &palette[6], &transposedPalette[4] );
888 rgbi_move( &palette[7], &transposedPalette[6] );
889
890 palette = transposedPalette;
891 }
892#endif
893
894 for( i=0; i<15; ++i ) {
895 switch( _environment->gammaCorrection ) {
897 out4( "$%1.1x%1.1x%1.1x%1.1x, ",
898 0,
899 ( EF936X_COMPONENT_BITMASK * 0x10 ) | ( ( palette[i].blue >> 4 ) & 0x0f ) ,
900 ( ( palette[i].green >> 4 ) & 0x0f ) ,
901 ( ( palette[i].red >> 4 ) & 0x0f )
902 );
903 break;
905 out4( "$%1.1x%1.1x%1.1x%1.1x, ",
906 0,
907 ( EF936X_COMPONENT_BITMASK * 0x10 ) | ( pc_to_ef936x( palette[i].blue >> 4 ) & 0x0f ) ,
908 ( pc_to_ef936x( palette[i].green >> 4 ) & 0x0f ) ,
909 ( pc_to_ef936x( palette[i].red >> 4 ) & 0x0f )
910 );
911 break;
913 out4( "$%1.1x%1.1x%1.1x%1.1x, ",
914 0,
915 ( EF936X_COMPONENT_BITMASK * 0x10 ) | ( df_gamma( palette[i].blue >> 4 ) & 0x0f ) ,
916 ( df_gamma( palette[i].green >> 4 ) & 0x0f ) ,
917 ( df_gamma( palette[i].red >> 4 ) & 0x0f )
918 );
919 break;
920 }
921 }
922 outline4("$%1.1x%1.1x%1.1x%1.1x", 0, EF936X_COMPONENT_BITMASK * 0x10 | ( ( palette[15].blue >> 4 ) & 0x0f ) , ( ( palette[15].green >> 4 ) & 0x0f ) , ( ( palette[15].red >> 4 ) & 0x0f ) );
923
924 if ( _environment->vestigialConfig.clsImplicit ) {
925 deploy_preferred( clsGraphic, src_hw_ef936x_cls_asm );
926
927 }
928
929 CopperList * copperList = _environment->copperList;
930 if ( copperList ) {
931 while(copperList) {
932 outhead1("COPPERACTIVATE%s", copperList->name ? copperList->name : "" );
933 outline0("RTS");
934 copperList = copperList->next;
935 }
936 }
937}
938
939void ef936x_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
940
941 deploy( textHScroll, src_hw_ef936x_hscroll_text_asm );
942
943 Variable * y = variable_retrieve( _environment, "YCURSYS" );
944 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
945 outline0("STA <DIRECTION" );
946 outline1("LDA %s", y->realName );
947 outline0("STA <CLINEY");
948
949 outline0("JSR HSCROLLLT");
950
951}
952
953void ef936x_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
954
955 deploy( textHScroll, src_hw_ef936x_hscroll_text_asm );
956
957 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
958 outline0("STA <DIRECTION" );
959
960 outline0("JSR HSCROLLST");
961
962}
963
964void ef936x_back( Environment * _environment ) {
965
966}
967
968void ef936x_cline( Environment * _environment, char * _characters ) {
969
970 deploy( textCline, src_hw_ef936x_cline_asm );
971 Variable * x = variable_retrieve( _environment, "XCURSYS" );
972 Variable * y = variable_retrieve( _environment, "YCURSYS" );
973
974 if ( _characters ) {
975 outline1("LDA %s", _characters);
976 } else {
977 outline0("LDA #0");
978 }
979 outline0("STA <CHARACTERS");
980 outline1("LDA %s", x->realName );
981 outline0("STA <CLINEX" );
982 outline1("LDA %s", y->realName );
983 outline0("STA <CLINEY");
984 outline0("JSR CLINEG");
985
986}
987
988int ef936x_image_size( Environment * _environment, int _width, int _height, int _mode ) {
989
990 switch( _mode ) {
992 return 3 + 2 * ( ( _width >> 3 ) * _height );
994 return 3 + 2 * ( ( _width >> 3 ) * _height ) /*+ 8*/;
997 return 3 + 2 * ( ( _width >> 2 ) * _height ) /*+ 32*/;
998 case BITMAP_MODE_PAGE:
999 // WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE( _mode );
1000 break;
1001 }
1002
1003 return 0;
1004
1005}
1006
1007static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1008
1009 switch( _mode ) {
1011 return 3 + ( 3 + 2 * ( ( _width >> 3 ) * _height ) ) * _frames;
1013 return 3 + ( 3 + 2 * ( ( _width >> 3 ) * _height ) /*+ 8*/ ) * _frames;
1016 return 3 + ( 3 + 2 * ( ( _width >> 2 ) * _height ) /*+ 32*/ ) * _frames;
1017 case BITMAP_MODE_PAGE:
1018 // WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE( _mode );
1019 break;
1020 }
1021
1022 return 0;
1023
1024}
1025
1026static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1027
1028 switch( _mode ) {
1030 return 3 + ( ( 3 + 2 * ( ( _width >> 3 ) * _height ) ) * _frames ) * _sequences;
1032 return 3 + ( ( 3 + 2 * ( ( _width >> 3 ) * _height ) /*+ 8*/ ) * _frames ) * _sequences;
1035 return 3 + ( ( 3 + 2 * ( ( _width >> 2 ) * _height ) /*+ 32*/ ) * _frames ) * _sequences;
1036 case BITMAP_MODE_PAGE:
1037 // WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE( _mode );
1038 break;
1039 }
1040
1041 return 0;
1042
1043}
1044
1045static Variable * ef936x_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 ) {
1046
1047 // ignored on bitmap mode
1048 (void)!_transparent_color;
1049
1050 image_converter_asserts_free( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height );
1051
1052 RGBi * palette = malloc_palette( MAX_PALETTE );
1053
1054 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1055
1056 if (paletteColorCount > 2) {
1057 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1058 }
1059
1060 int i, j, k;
1061
1062 if ( ! commonPalette ) {
1063
1064 commonPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1065 commonPalette = palette_remove_duplicates( palette, paletteColorCount, &paletteColorCount );
1066
1067 if ( _transparent_color & 0x0f0000 ) {
1068 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1069 }
1070 if ( _transparent_color & 0xf00000 ) {
1071 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 2 );
1072 paletteColorCount = 2;
1073 }
1074
1075 lastUsedSlotInCommonPalette = paletteColorCount;
1076 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1077
1078 } else {
1079
1080 commonPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1081 RGBi * newPalette = palette_remove_duplicates( palette, paletteColorCount, &paletteColorCount );
1082 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1083
1084 int mergedCommonPalette = 0;
1085
1086 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1087
1088 if ( _transparent_color & 0x0f0000 ) {
1089 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
1090 }
1091 if ( _transparent_color & 0xf00000 ) {
1092 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 16 );
1093 mergedCommonPalette = 2;
1094 }
1095
1096 lastUsedSlotInCommonPalette = mergedCommonPalette;
1097 if ( lastUsedSlotInCommonPalette > 2 ) {
1099 }
1100 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1101
1102 }
1103
1104 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1106 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1107
1108 int bufferSize = ef936x_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_DEFAULT );;
1109 // printf("bufferSize = %d\n", bufferSize );
1110
1111 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_DEFAULT );
1112
1113 adilinebeginbitmap("BMD");
1114
1115 char * buffer = malloc ( bufferSize );
1116 memset( buffer, 0, bufferSize );
1117
1118 // Position of the pixel in the original image
1119 int image_x, image_y;
1120
1121 // Position of the pixel, in terms of tiles
1122 int tile_x, tile_y;
1123
1124 // Position of the pixel, in terms of offset and bitmask
1125 int offset, bitmask;
1126
1127 // Color of the pixel to convert
1128 RGBi rgb;
1129
1130 *(buffer) = (_frame_width >> 8 ) & 0xff;
1131 *(buffer+1) = (_frame_width ) & 0xff;
1132 *(buffer+2) = _frame_height;
1133
1134 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1135
1136 // Loop for all the source surface.
1137 for (image_y = 0; image_y < _frame_height; ++image_y) {
1138 for (image_x = 0; image_x < _frame_width; ++image_x) {
1139
1140 // Take the color of the pixel
1141 rgb.red = *_source;
1142 rgb.green = *(_source + 1);
1143 rgb.blue = *(_source + 2);
1144 if ( _depth > 3 ) {
1145 rgb.alpha = *(_source + 3);
1146 } else {
1147 rgb.alpha = 255;
1148 }
1149 if ( rgb.alpha == 0 ) {
1150 rgb.red = 0;
1151 rgb.green = 0;
1152 rgb.blue = 0;
1153 }
1154
1155 int colorIndex = 0;
1156 int firstIndex = 0;
1157 if ( _transparent_color & 0x0f0000 ) {
1158 firstIndex = 1;
1159 }
1160
1161 if ( rgb.alpha < 255 ) {
1162 colorIndex = 0;
1163 } else {
1164 unsigned int minDistance = 0xffff;
1165 for( i=firstIndex; i<lastUsedSlotInCommonPalette; ++i ) {
1166 if ( commonPalette[i].alpha < 255 ) continue;
1167 unsigned int distance = rgbi_distance(&commonPalette[i], &rgb);
1168 if ( minDistance > distance ) {
1169 minDistance = distance;
1170 colorIndex = i;
1171 }
1172 }
1173 }
1174
1175 adilinepixel(colorIndex);
1176
1177 // printf("%d", i );
1178
1179 // Calculate the offset starting from the tile surface area
1180 // and the bit to set.
1181 offset = ( image_y * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
1182 bitmask = 1 << ( 7 - (image_x & 0x7) );
1183
1184 if ( i == 1 ) {
1185 *( buffer + offset + 3) |= bitmask;
1186 // printf("*");
1187 } else {
1188 *( buffer + offset + 3) &= ~bitmask;
1189 // printf(" ");
1190 }
1191
1192 _source += _depth;
1193
1194 }
1195
1196 _source += ( _width - _frame_width ) * _depth;
1197
1198 // printf("\n" );
1199
1200 }
1201
1203
1204 // printf("----\n");
1205
1206 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1207
1208 // printf("----\n");
1209
1210 return result;
1211
1212}
1213
1214static Variable * ef936x_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 ) {
1215
1216 image_converter_asserts_free( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height );
1217
1218#if defined( __mo5__ )
1219
1220 RGBi * palette = &SYSTEM_PALETTE[0];
1221 int paletteColorCount = 16;
1222 commonPalette = &SYSTEM_PALETTE[0];
1224
1225#else
1226
1227 RGBi * palette = malloc_palette( MAX_PALETTE );
1228
1229 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1230
1231 if (paletteColorCount > 16) {
1232 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1233 }
1234
1235 int i, j, k;
1236
1237 if ( ! commonPalette ) {
1238
1239 commonPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1240 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1241
1242 if ( ( _transparent_color & 0x0f0000 ) || ( _transparent_color & 0xf00000 ) ) {
1243 commonPalette = palette_shift( commonPalette, (paletteColorCount == MAX_PALETTE) ? (MAX_PALETTE-1) : (paletteColorCount), 1 );
1244 }
1245
1246 if ( _transparent_color & 0x0f0000 ) {
1247 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1248 }
1249 if ( _transparent_color & 0xf00000 ) {
1250 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 4 );
1251 paletteColorCount = 16;
1252 }
1253
1254 lastUsedSlotInCommonPalette = paletteColorCount;
1255 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1256
1257 } else {
1258
1259 RGBi * newPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1260 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
1261 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1262
1263 int mergedCommonPalette = 0;
1264
1265 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1266
1267 if ( _transparent_color & 0x0f0000 ) {
1268 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
1269 }
1270 if ( _transparent_color & 0xf00000 ) {
1271 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 16 );
1272 mergedCommonPalette = 16;
1273 }
1274
1275 lastUsedSlotInCommonPalette = mergedCommonPalette;
1276 if ( lastUsedSlotInCommonPalette > 16 ) {
1278 }
1279 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1280
1281 }
1282
1283#endif
1284
1285 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1287 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1288
1289 int bufferSize = ef936x_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_40_COLUMN );
1290
1291 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_40_COLUMN );
1292
1293 adilinebeginbitmap("BMD");
1294
1295 char * buffer = malloc ( bufferSize );
1296 memset( buffer, 0, bufferSize );
1297
1298 // Position of the pixel in the original image
1299 int image_x, image_y;
1300
1301 // Position of the pixel, in terms of tiles
1302 int tile_x, tile_y;
1303
1304 // Position of the pixel, in terms of offset and bitmask
1305 int offset, offsetc, bitmask;
1306
1307 // Color of the pixel to convert
1308 RGBi rgb;
1309
1310 *(buffer) = (_frame_width >> 8 ) & 0xff;
1311 *(buffer+1) = ( _frame_width ) & 0xff;
1312 *(buffer+2) = _frame_height;
1313
1314 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1315
1316 // Loop for all the source surface.
1317 for (image_y = 0; image_y < _frame_height; ++image_y) {
1318 for (image_x = 0; image_x < _frame_width; image_x+=8) {
1319 int colorIndexes[8];
1320 memset( colorIndexes, 0, 8*sizeof( int ) );
1321 int trans = 0;
1322
1323 for( int xx = 0; xx<8; ++xx ) {
1324 // Take the color of the pixel
1325 rgb.red = *_source;
1326 rgb.green = *(_source + 1);
1327 rgb.blue = *(_source + 2);
1328 if ( _depth > 3 ) {
1329 rgb.alpha = *(_source + 3);
1330 } else {
1331 rgb.alpha = 255;
1332 }
1333 if ( rgb.alpha == 0 ) {
1334 rgb.red = 0;
1335 rgb.green = 0;
1336 rgb.blue = 0;
1337 }
1338
1339 int firstIndex = 0;
1340 if ( _transparent_color & 0x0f0000 ) {
1341 firstIndex = 1;
1342 }
1343
1344 if ( rgb.alpha < 255 ) {
1345 colorIndexes[xx] = 0;
1346 } else {
1347 int minDistance = 9999;
1348 for( int i=firstIndex; i<lastUsedSlotInCommonPalette; ++i ) {
1349 if ( commonPalette[i].alpha < 255 ) continue;
1350 int distance = rgbi_distance(&commonPalette[i], &rgb );
1351 if ( distance < minDistance ) {
1352 minDistance = distance;
1353 colorIndexes[xx] = i;
1354 }
1355 }
1356 }
1357
1358 _source += _depth;
1359
1360 }
1361
1362 int colorIndexesCount[16];
1363 memset( colorIndexesCount, 0, 16*sizeof( int ) );
1364
1365 for( int xx = 0; xx<8; ++xx ) {
1366 ++colorIndexesCount[colorIndexes[xx]];
1367 }
1368
1369 int colorBackground = 0;
1370 int colorBackgroundMax = 0;
1371 int colorForeground = 0;
1372 int colorForegroundMax = 0;
1373
1374 if ( trans ) {
1375
1376 } else {
1377 for( int xx = 0; xx<16; ++xx ) {
1378 if ( colorIndexesCount[xx] > colorBackgroundMax ) {
1379 colorBackground = xx;
1380 colorBackgroundMax = colorIndexesCount[xx];
1381 };
1382 }
1383
1384 }
1385
1386 colorIndexesCount[colorBackground] = 0;
1387
1388 for( int xx = 0; xx<16; ++xx ) {
1389 if ( colorIndexesCount[xx] > colorForegroundMax ) {
1390 colorForeground = xx;
1391 colorForegroundMax = colorIndexesCount[xx];
1392 };
1393 }
1394
1395 if ( colorForeground == colorBackground ) {
1396 colorForeground = ( colorBackground == 0 ) ? 1 : 0;
1397 }
1398
1399 for( int xx = 0; xx<8; ++xx ) {
1400 offset = ( image_y * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
1401 bitmask = 1 << ( 7 - ((image_x+xx) & 0x7) );
1402
1403 if ( colorIndexes[xx] != colorBackground ) {
1404 adilinepixel(colorForeground);
1405 *( buffer + offset + 3) |= bitmask;
1406 } else {
1407 adilinepixel(colorBackground);
1408 *( buffer + offset + 3) &= ~bitmask;
1409 }
1410
1411 offset = ( image_y * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
1412
1413 bitmask = colorForeground << 4 | ( colorBackground );
1414 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) + offset) = bitmask;
1415
1416 }
1417 }
1418
1419 _source += ( _width - _frame_width ) * _depth;
1420
1421 }
1422
1424
1425 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1426
1427 return result;
1428
1429}
1430
1431static Variable * ef936x_image_converter_multicolor_mode4( 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 ) {
1432
1433 image_converter_asserts_free( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height );
1434
1435#if defined( __mo5__ )
1436
1437 RGBi * palette = &SYSTEM_PALETTE[0];
1438 int paletteColorCount = 16;
1439 commonPalette = &SYSTEM_PALETTE[0];
1441
1442 int i;
1443
1444#else
1445
1446 RGBi * palette = malloc_palette( MAX_PALETTE );
1447
1448 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1449
1450 if (paletteColorCount > 4) {
1451 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1452 }
1453
1454 int i, j, k;
1455
1456 if ( ! commonPalette ) {
1457
1458 commonPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1459 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1460
1461 if ( ( _transparent_color & 0x0f0000 ) || ( _transparent_color & 0xf00000 ) ) {
1462 commonPalette = palette_shift( commonPalette, (paletteColorCount == MAX_PALETTE) ? (MAX_PALETTE-1) : (paletteColorCount), 1 );
1463 }
1464
1465 if ( _transparent_color & 0x0f0000 ) {
1466 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1467 }
1468 if ( _transparent_color & 0xf00000 ) {
1469 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 16 );
1470 paletteColorCount = 4;
1471 }
1472
1473 lastUsedSlotInCommonPalette = paletteColorCount;
1474 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1475
1476 } else {
1477
1478 RGBi * newPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1479 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
1480 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1481
1482 int mergedCommonPalette = 0;
1483
1484 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1485
1486 if ( _transparent_color & 0x0f0000 ) {
1487 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
1488 }
1489 if ( _transparent_color & 0xf00000 ) {
1490 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 16 );
1491 mergedCommonPalette = 4;
1492 }
1493
1494 lastUsedSlotInCommonPalette = mergedCommonPalette;
1495 if ( lastUsedSlotInCommonPalette > 4 ) {
1497 }
1498 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1499
1500 }
1501
1502#endif
1503
1504 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1506 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1507
1508 int bufferSize = ef936x_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_BITMAP_4 );
1509
1510 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_BITMAP_4 );
1511
1512 adilinebeginbitmap("BMD");
1513
1514 char * buffer = malloc ( bufferSize );
1515 memset( buffer, 0, bufferSize );
1516
1517 // Position of the pixel in the original image
1518 int image_x, image_y;
1519
1520 // Position of the pixel, in terms of tiles
1521 int tile_x, tile_y;
1522
1523 // Position of the pixel, in terms of offset and bitmask
1524 int offset, offsetc, bitmask;
1525
1526 // Color of the pixel to convert
1527 RGBi rgb;
1528
1529 *(buffer) = ( _frame_width >> 8 ) & 0xff;
1530 *(buffer+1) = ( _frame_width ) & 0xff;
1531 *(buffer+2) = _frame_height;
1532
1533 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1534
1535 // Loop for all the source surface.
1536 for (image_y = 0; image_y < _frame_height; ++image_y) {
1537 for (image_x = 0; image_x < _frame_width; ++image_x) {
1538
1539 // Take the color of the pixel
1540 rgb.red = *_source;
1541 rgb.green = *(_source + 1);
1542 rgb.blue = *(_source + 2);
1543 if ( _depth > 3 ) {
1544 rgb.alpha = *(_source + 3 );
1545 } else {
1546 rgb.alpha= 255;
1547 }
1548 if ( rgb.alpha == 0 ) {
1549 rgb.red = 0;
1550 rgb.green = 0;
1551 rgb.blue = 0;
1552 }
1553
1554 unsigned int minDistance = 0xffff;
1555 int colorIndex = 0;
1556 int firstIndex = 0;
1557 if ( _transparent_color & 0x0f0000 ) {
1558 firstIndex = 1;
1559 }
1560
1561 colorIndex = 0;
1562
1563 if ( rgb.alpha < 255 ) {
1564
1565 } else {
1566 for( i=firstIndex; i<lastUsedSlotInCommonPalette; ++i ) {
1567 if ( commonPalette[i].alpha < 255 ) continue;
1568 unsigned int distance = rgbi_distance(&commonPalette[i], &rgb);
1569 if ( minDistance > distance ) {
1570 minDistance = distance;
1571 colorIndex = i;
1572 }
1573 }
1574 }
1575 // printf( "%1.1x", colorIndex );
1576
1577 adilinepixel(colorIndex);
1578
1579 bitmask = 1 << ( 7 - (image_x & 0x7) );
1580
1581 *(buffer + 3 + ( image_x >> 3 ) + ( ( _frame_width >> 3 ) * image_y ) ) |= ( ( colorIndex & 0x02 ) == 0x02 ) ? bitmask : 0;
1582 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) + ( ( image_x >> 3 ) + ( _frame_width >> 3 ) * image_y ) ) |= ( ( colorIndex & 0x01 ) == 0x01 ) ? bitmask : 0;
1583
1584 _source += _depth;
1585
1586 }
1587
1588 _source += ( _width - _frame_width ) * _depth;
1589
1590 // printf("\n" );
1591 }
1592
1594
1595 // RGBi * color = &SYSTEM_PALETTE[commonPalette[0].index];
1596 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 1 ) = ( color->green & 0xf0 ) | ( ( color->red & 0xf0 ) >> 4 );
1597 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) ) = ( ( color->blue & 0xf0 ) >> 4 );
1598
1599 // color = &SYSTEM_PALETTE[commonPalette[1].index];
1600 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 3 ) = ( color->green & 0xf0 ) | ( ( color->red & 0xf0 ) >> 4 );
1601 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 2 ) = ( ( color->blue & 0xf0 ) >> 4 );
1602
1603 // color = &SYSTEM_PALETTE[commonPalette[2].index];
1604 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 5 ) = ( color->green & 0xf0 ) | ( ( color->red & 0xf0 ) >> 4 );
1605 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 4 ) = ( ( color->blue & 0xf0 ) >> 4 );
1606
1607 // color = &SYSTEM_PALETTE[commonPalette[3].index];
1608 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 7 ) = ( color->green & 0xf0 ) | ( ( color->red & 0xf0 ) >> 4 );
1609 // *(buffer + 2 + 2 * ( ( _width >> 3 ) * _height ) + 6 ) = ( ( color->blue & 0xf0 ) >> 4 );
1610
1611 // for(i=0; i<4; ++i ) {
1612 // printf( "%1.1x = %2.2x\n", i, palette[i].index );
1613 // }
1614
1615 // printf("\n" );
1616 // printf("\n" );
1617
1618 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1619
1620 return result;
1621
1622}
1623
1624static Variable * ef936x_image_converter_multicolor_mode16( 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 ) {
1625
1626 image_converter_asserts_free( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height );
1627
1628#if defined( __mo5__ )
1629
1630 RGBi * palette = &SYSTEM_PALETTE[0];
1631 int paletteColorCount = 16;
1632 commonPalette = &SYSTEM_PALETTE[0];
1634
1635 int i;
1636
1637#else
1638
1639 RGBi * palette = malloc_palette( MAX_PALETTE );
1640
1641 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1642
1643 if (paletteColorCount > 16) {
1644 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1645 }
1646
1647 int i, j, k;
1648
1649 if ( ! commonPalette ) {
1650
1651 commonPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1652 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1653 if ( ( _transparent_color & 0x0f0000 ) || ( _transparent_color & 0xf00000 ) ) {
1654 commonPalette = palette_shift( commonPalette, (paletteColorCount == MAX_PALETTE) ? (MAX_PALETTE-1) : (paletteColorCount), 1 );
1655 }
1656
1657 if ( _transparent_color & 0x0f0000 ) {
1658 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1659 }
1660
1661 if ( _transparent_color & 0xf00000 ) {
1662 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 16 );
1663 paletteColorCount = 16;
1664 }
1665
1666 lastUsedSlotInCommonPalette = paletteColorCount;
1667 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1668
1669 } else {
1670
1671 RGBi * newPalette = palette_match_hardware_index( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1672
1673 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
1674
1675 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1676
1677 int mergedCommonPalette = 0;
1678
1679 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1680
1681 if ( _transparent_color & 0x0f0000 ) {
1682 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
1683 }
1684
1685 if ( _transparent_color & 0xf00000 ) {
1686 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 16 );
1687 mergedCommonPalette = 16;
1688 }
1689
1690 lastUsedSlotInCommonPalette = mergedCommonPalette;
1691 if ( lastUsedSlotInCommonPalette > 16 ) {
1693 }
1694 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1695
1696 }
1697
1698#endif
1699
1700 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1702 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1703
1704 int bufferSize = ef936x_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_BITMAP_16 );
1705
1706 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_BITMAP_4 );
1707
1708 adilinebeginbitmap("BMD");
1709
1710 char * buffer = malloc ( bufferSize );
1711 memset( buffer, 0, bufferSize );
1712
1713 // Position of the pixel in the original image
1714 int image_x, image_y;
1715
1716 // Position of the pixel, in terms of tiles
1717 int tile_x, tile_y;
1718
1719 // Position of the pixel, in terms of offset and bitmask
1720 int offset, offsetc, bitmask;
1721
1722 // Color of the pixel to convert
1723 RGBi rgb;
1724
1725 *(buffer) = ( _frame_width >> 8 ) & 0xff;
1726 *(buffer+1) = ( _frame_width ) & 0xff;
1727 *(buffer+2) = _frame_height;
1728
1729 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1730
1731 // Loop for all the source surface.
1732 for (image_y = 0; image_y < _frame_height; ++image_y) {
1733 for (image_x = 0; image_x < _frame_width; ++image_x) {
1734
1735 // Take the color of the pixel
1736 rgb.red = *_source;
1737 rgb.green = *(_source + 1);
1738 rgb.blue = *(_source + 2);
1739 if ( _depth > 3 ) {
1740 rgb.alpha = *(_source + 3);
1741 } else {
1742 rgb.alpha = 255;
1743 }
1744 if ( rgb.alpha == 0 ) {
1745 rgb.red = 0;
1746 rgb.green = 0;
1747 rgb.blue = 0;
1748 }
1749
1750 int minDistance = 0xffff;
1751 int colorIndex = 0;
1752 int firstIndex = 0;
1753 if ( _transparent_color & 0x0f0000 ) {
1754 firstIndex = 1;
1755 }
1756
1757 colorIndex = 0;
1758
1759 if ( rgb.alpha < 255 ) {
1760
1761 } else {
1762 for( i=firstIndex; i<lastUsedSlotInCommonPalette; ++i ) {
1763 if ( commonPalette[i].alpha < 255 ) continue;
1764 int distance = rgbi_distance(&commonPalette[i], &rgb);
1765 if ( minDistance > distance ) {
1766 minDistance = distance;
1767 colorIndex = i;
1768 }
1769 }
1770 }
1771
1772 // printf( "%1.1x", colorIndex );
1773
1774 bitmask = colorIndex << ( 4 * ( 1 - (image_x & 0x1) ) );
1775
1776 adilinepixel(colorIndex);
1777
1778 // printf( "%2.2x", bitmask );
1779
1780 if ( ( ( image_x & 0x03 ) < 0x02 ) ) {
1781 *(buffer + 3 + ( image_x >> 2 ) + ( ( _frame_width >> 2 ) * image_y ) ) |= bitmask;
1782 } else {
1783 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + ( ( image_x >> 2 ) + ( _frame_width >> 2 ) * image_y ) ) |= bitmask;
1784 }
1785
1786 _source += _depth;
1787
1788 }
1789
1790 _source += ( _width - _frame_width ) * _depth;
1791
1792 // printf("\n" );
1793 }
1794
1796
1797 // for (i=0; i<16; ++i ) {
1798 // RGBi * color = &SYSTEM_PALETTE[commonPalette[i].index];
1799 // *(buffer + 2 + 2 * ( ( _width >> 2 ) * _height ) + 2*i + 1 ) = ( color->green & 0xf0 ) | ( ( color->red & 0xf0 ) >> 4 );
1800 // *(buffer + 2 + 2 * ( ( _width >> 2 ) * _height ) + 2*i ) = ( ( color->blue & 0xf0 ) >> 4 );
1801 // }
1802
1803 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1804
1805 return result;
1806
1807}
1808
1809Variable * ef936x_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 ) {
1810
1811 switch( _mode ) {
1813 return ef936x_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1815 return ef936x_image_converter_multicolor_mode4( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1818 return ef936x_image_converter_multicolor_mode16( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1819 case BITMAP_MODE_PAGE:
1820 // WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE( _mode );
1821 break;
1822 }
1823
1824 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1825
1826 return result;
1827
1828}
1829
1830static void ef936x_load_image_address_to_y( Environment * _environment, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
1831
1832 if ( !_sequence && !_frame ) {
1833 outline1("LDY #%s", _source );
1834 } else {
1835
1836 outline1("LDY #%s", _source );
1837
1838 if ( _sequence ) {
1839 outline0("LEAY 3,y" );
1840 if ( strlen(_sequence) == 0 ) {
1841 } else {
1842 outline1("LDB %s", _sequence );
1843 outline1("JSR fs%4.4xoffsetsequence", _frame_count * _frame_size );
1844 }
1845 if ( _frame ) {
1846 if ( strlen(_frame) == 0 ) {
1847 } else {
1848 outline1("LDB %s", _frame );
1849 outline1("JSR fs%4.4xoffsetframe", _frame_size );
1850 }
1851 }
1852 } else {
1853 if ( _frame ) {
1854 outline0("LEAY 3,y" );
1855 if ( strlen(_frame) == 0 ) {
1856 } else {
1857 outline1("LDB %s", _frame );
1858 outline1("JSR fs%4.4xoffsetframe", _frame_size );
1859 }
1860 }
1861 }
1862
1863 }
1864
1865}
1866
1867static void ef936x_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
1868
1869 if ( !_sequence && !_frame ) {
1870 if ( _source->isAddress ) {
1871 outline1("LDY %s", _source->realName );
1872 } else {
1873 outline1("LDY #%s", _source->realName );
1874 }
1875 } else {
1876
1877 if ( _source->isAddress ) {
1878 outline1("LDY %s", _source->realName );
1879 } else {
1880 outline1("LDY #%s", _source->realName );
1881 }
1882
1883 if ( _sequence ) {
1884 outline0("LEAY 3,y" );
1885 if ( strlen(_sequence) == 0 ) {
1886 } else {
1887
1888 Variable * sequence = variable_retrieve( _environment, _sequence );
1889 outline1("LDB %s", sequence->realName );
1890 outline1("JSR %soffsetsequence", _source->realName );
1891 }
1892 if ( _frame ) {
1893 if ( strlen(_frame) == 0 ) {
1894 } else {
1895 Variable * frame = variable_retrieve( _environment, _frame );
1896 outline1("LDB %s", frame->realName );
1897 outline1("JSR %soffsetframe", _source->realName );
1898 }
1899 }
1900 } else {
1901 if ( _frame ) {
1902 outline0("LEAY 3,y" );
1903 if ( strlen(_frame) == 0 ) {
1904 } else {
1905 Variable * frame = variable_retrieve( _environment, _frame );
1906 outline1("LDB %s", frame->realName );
1907 outline1("JSR %soffsetframe", _source->realName );
1908 }
1909 }
1910 }
1911
1912 }
1913
1914 if ( _register ) {
1915 outline1("STY %s", _register );
1916 }
1917
1918}
1919
1920void ef936x_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
1921
1922 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm);
1923 deploy_preferred( putimage, src_hw_ef936x_put_image_asm );
1924
1925 if ( _frame_size ) {
1926 ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
1927 }
1928
1929 Variable * x = variable_retrieve( _environment, _x );
1930 Variable * y = variable_retrieve( _environment, _y );
1931
1932 switch( VT_BITWIDTH( x->type ) ) {
1933 case 32:
1934 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 ) {
1935 if ( x->initializedByConstant ) {
1936 outline1("LDB #$%2.2x", (unsigned char)(x->value&0xff) );
1937 } else {
1938 outline1("LDB %s+3", x->realName );
1939 }
1940 outline0("STB <(IMAGEX+1)" );
1941 } else {
1942 if ( x->initializedByConstant ) {
1943 outline1("LDD #$%4.4x", (unsigned int)(x->value&0xffff) );
1944 } else {
1945 outline1("LDD %s+2", x->realName );
1946 }
1947 outline0("STD <IMAGEX" );
1948 }
1949 break;
1950 case 16:
1951 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 ) {
1952 if ( x->initializedByConstant ) {
1953 outline1("LDB #$%2.2x", (unsigned char)(x->value&0xff) );
1954 } else {
1955 outline1("LDB %s+1", x->realName );
1956 }
1957 outline0("STB <(IMAGEX+1)" );
1958 } else {
1959 if ( x->initializedByConstant ) {
1960 outline1("LDD #$%4.4x", (unsigned int)(x->value&0xffff) );
1961 } else {
1962 outline1("LDD %s", x->realName );
1963 }
1964 outline0("STD <IMAGEX" );
1965 }
1966 break;
1967 case 8:
1968 if ( x->initializedByConstant ) {
1969 outline1("LDB #$%2.2x", (unsigned char)(x->value&0xff) );
1970 } else {
1971 outline1("LDB %s", x->realName );
1972 }
1973 outline0("STB <(IMAGEX+1)" );
1974 break;
1975 default:
1977 }
1978
1979 switch( VT_BITWIDTH( y->type ) ) {
1980 case 32:
1981 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 ) {
1982 if ( x->initializedByConstant ) {
1983 outline1("LDB #$%2.2x", (unsigned char)(y->value&0xff) );
1984 } else {
1985 outline1("LDB %s+3", y->realName );
1986 }
1987 outline0("STB <(IMAGEY+1)" );
1988 } else {
1989 if ( x->initializedByConstant ) {
1990 outline1("LDD #$%4.4x", (unsigned int)(y->value&0xffff) );
1991 } else {
1992 outline1("LDD %s+2", y->realName );
1993 }
1994 outline0("STD <IMAGEY" );
1995 }
1996 break;
1997 case 16:
1998 if ( y->initializedByConstant ) {
1999 outline1("LDB #$%2.4x", y->value );
2000 } else {
2001 outline1("LDB %s+1", y->realName );
2002 }
2003 outline0("STB <(IMAGEY+1)" );
2004 break;
2005 case 8:
2006 if ( y->initializedByConstant ) {
2007 outline1("LDB #$%2.2x", y->value );
2008 } else {
2009 outline1("LDB %s", y->realName );
2010 }
2011 outline0("STB <(IMAGEY+1)" );
2012 break;
2013 default:
2015 }
2016
2017 if( _flags && ( _environment->transparencyUsed || strcmp( _flags, "#PUTIMAGEFLAGS0000" ) ) != 0 ) {
2018 _environment->transparencyUsed = 1;
2019 outline1("LDD %s", _flags );
2020 outline0("STD <IMAGET" );
2021 } else {
2022 outline0("CLR <IMAGEF" );
2023 }
2024
2025 outline0("JSR PUTIMAGE");
2026
2027}
2028
2029Variable * ef936x_new_image( Environment * _environment, int _width, int _height, int _mode ) {
2030
2031 int size = ef936x_image_size( _environment, _width, _height, _mode );
2032
2033 if ( ! size ) {
2035 }
2036
2037 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
2038
2039 char * buffer = malloc ( size );
2040 memset( buffer, 0, size );
2041
2042 *(buffer) = ( _width >> 8 ) & 0xff;
2043 *(buffer+1) = ( _width & 0xff );
2044 *(buffer+2) = _height;
2045
2046 result->valueBuffer = buffer;
2047 result->size = size;
2048
2049 return result;
2050
2051}
2052
2053Variable * ef936x_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2054
2055 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2056 int frameSize = ef936x_image_size( _environment, _width, _height, _mode );
2057
2058 if ( ! size ) {
2060 }
2061
2062 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
2063
2064 char * buffer = malloc ( size );
2065 memset( buffer, 0, size );
2066
2067 *(buffer) = _frames;
2068 *(buffer+1) = ( _width >> 8 ) & 0xff;
2069 *(buffer+2) = ( _width & 0xff );
2070 for( int i=0; i<_frames; ++i ) {
2071 *(buffer+3+(i*frameSize)) = ( ( _width >> 8 ) & 0xff );
2072 *(buffer+3+(i*frameSize)+1) = ( _width & 0xff );
2073 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2074 }
2075
2076 result->valueBuffer = buffer;
2077 result->frameSize = frameSize;
2078 result->size = size;
2079 result->frameCount = _frames;
2080
2081 return result;
2082
2083}
2084
2085Variable * ef936x_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2086
2087 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
2088 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2089 int frameSize = ef936x_image_size( _environment, _width, _height, _mode );
2090
2091 if ( ! size ) {
2093 }
2094
2095 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
2096
2097 char * buffer = malloc ( size2 );
2098 memset( buffer, 0, size2 );
2099
2100 *(buffer) = _frames;
2101 *(buffer+1) = _width;
2102 *(buffer+2) = _sequences;
2103 for( int i=0; i<(_frames*_sequences); ++i ) {
2104 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2105 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2106 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2107 }
2108
2109 result->valueBuffer = buffer;
2110 result->frameSize = frameSize;
2111 result->size = size;
2112 result->frameCount = _frames;
2113
2114 return result;
2115
2116}
2117
2118void ef936x_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
2119
2120 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm);
2121 deploy_preferred( getimage, src_hw_ef936x_get_image_asm );
2122
2123 ef936x_load_image_address_to_y( _environment, _image, _sequence, _frame, _frame_size, _frame_count );
2124
2125 Variable * x = variable_retrieve( _environment, _x );
2126 Variable * y = variable_retrieve( _environment, _y );
2127
2128 switch( VT_BITWIDTH( x->type ) ) {
2129 case 16:
2130 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 ) {
2131 if ( x->initializedByConstant ) {
2132 outline1("LDB #$%2.2x", (unsigned char)(x->value&0xff) );
2133 } else {
2134 outline1("LDB %s+1", x->realName );
2135 }
2136 outline0("STB <(IMAGEX+1)" );
2137 } else {
2138 if ( x->initializedByConstant ) {
2139 outline1("LDD #$%4.4x", (unsigned int)(x->value&0xffff) );
2140 } else {
2141 outline1("LDD %s", x->realName );
2142 }
2143 outline0("STD <IMAGEX" );
2144 }
2145 break;
2146 case 8:
2147 if ( x->initializedByConstant ) {
2148 outline1("LDB #$%2.2x", (unsigned char)(x->value&0xff) );
2149 } else {
2150 outline1("LDB %s", x->realName );
2151 }
2152 outline0("STB <(IMAGEX+1)" );
2153 break;
2154 default:
2156 }
2157
2158 switch( VT_BITWIDTH( y->type ) ) {
2159 case 16:
2160 if ( y->initializedByConstant ) {
2161 outline1("LDB #$%2.42", y->value );
2162 } else {
2163 outline1("LDB %s+1", y->realName );
2164 }
2165 outline0("STB <(IMAGEY+1)" );
2166 break;
2167 case 8:
2168 if ( y->initializedByConstant ) {
2169 outline1("LDB #$%2.2x", y->value );
2170 } else {
2171 outline1("LDB %s", y->realName );
2172 }
2173 outline0("STB <(IMAGEY+1)" );
2174 break;
2175 default:
2177 }
2178
2179 outline1("LDA #$%2.2x", _palette );
2180 outline0("STA <IMAGET" );
2181
2182 outline0("JSR GETIMAGE");
2183
2184}
2185
2186void ef936x_scroll( Environment * _environment, int _dx, int _dy ) {
2187
2188 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm);
2189 deploy( scroll, src_hw_ef936x_scroll_asm);
2190 deploy( textHScroll, src_hw_ef936x_hscroll_text_asm );
2191 deploy( vScrollText, src_hw_ef936x_vscroll_text_asm );
2192
2193 outline1("LDA #$%2.2x", (unsigned char)(_dx&0xff) );
2194 outline0("STA <MATHPTR0" );
2195 outline1("LDA #$%2.2x", (unsigned char)(_dy&0xff) );
2196 outline0("STA <MATHPTR1" );
2197 outline0("JSR SCROLL");
2198
2199
2200}
2201
2202void ef936x_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
2203
2204}
2205
2206void ef936x_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
2207
2208}
2209
2210void ef936x_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
2211
2212
2213}
2214
2215void ef936x_tile_at( Environment * _environment, char * _x, char * _y, char * _result ) {
2216
2217}
2218
2219void ef936x_use_tileset( Environment * _environment, char * _tileset ) {
2220
2221}
2222
2224
2225 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
2226
2227 variable_store( _environment, result->name, 0 );
2228
2229 return result;
2230
2231}
2232
2233void ef936x_calculate_sequence_frame_offset_regy( Environment * _environment, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2234
2235 if ( _sequence ) {
2236 outline0("LEAY 3, Y" );
2237 if ( strlen(_sequence) == 0 ) {
2238 } else {
2239
2240 Variable * sequence = variable_retrieve( _environment, _sequence );
2241
2242 if ( sequence->initializedByConstant ) {
2243 outline1("LDB #$%2.2x", sequence->value );
2244 } else {
2245 outline1("LDB %s", sequence->realName );
2246 }
2247
2248 outline1("JSR fs%4.4xoffsetsequence", _frame_count * _frame_size );
2249 }
2250 if ( _frame ) {
2251 if ( strlen(_frame) == 0 ) {
2252 } else {
2253
2254 Variable * frame = variable_retrieve( _environment, _frame );
2255
2256 if ( frame->initializedByConstant ) {
2257 outline1("LDB #$%2.2x", frame->value );
2258 } else {
2259 outline1("LDB %s", frame->realName );
2260 }
2261
2262 outline1("JSR fs%4.4xoffsetframe", _frame_size );
2263 }
2264 }
2265 } else {
2266 if ( _frame ) {
2267 outline0("LEAY 3, Y" );
2268 if ( strlen(_frame) == 0 ) {
2269 } else {
2270 Variable * frame = variable_retrieve( _environment, _frame );
2271
2272 if ( frame->initializedByConstant ) {
2273 outline1("LDB #$%2.2x", frame->value );
2274 } else {
2275 outline1("LDB %s", frame->realName );
2276 }
2277
2278 outline1("JSR fs%4.4xoffsetframe", _frame_size );
2279 }
2280 }
2281 }
2282
2283}
2284
2285void ef936x_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2286
2287 if ( _sequence ) {
2288 outline0("LDY #$3" );
2289 if ( strlen(_sequence) == 0 ) {
2290 } else {
2291
2292 outline1("LDB %s", _sequence );
2293 outline1("JSR fs%4.4xoffsetsequence", _frame_count * _frame_size );
2294 }
2295 if ( _frame ) {
2296 if ( strlen(_frame) == 0 ) {
2297 } else {
2298 outline1("LDB %s", _frame );
2299 outline1("JSR fs%4.4xoffsetframe", _frame_size );
2300 }
2301 }
2302 } else {
2303 if ( _frame ) {
2304 outline0("LDY #$3" );
2305 if ( strlen(_frame) == 0 ) {
2306 } else {
2307 outline1("LDB %s", _frame );
2308 outline1("JSR fs%4.4xoffsetframe", _frame_size );
2309 }
2310 } else {
2311 outline0("LDY #$0" );
2312 }
2313 }
2314
2315 if ( _offset ) {
2316 outline1("STY %s", _offset );
2317 }
2318
2319}
2320
2321void ef936x_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 ) {
2322
2323 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm);
2324 deploy( blitimage, src_hw_ef936x_blit_image_asm );
2325
2326 if ( _source_count > 2 ) {
2328 }
2329
2331
2332 outhead1("blitimage%s", label);
2333
2334 outline1("LDY #%s", _blit );
2335 outline0("STY BLITIMAGEBLITADDR" );
2336
2337 if ( _source_count > 0 ) {
2338 Resource resource;
2339 resource.realName = strdup( _sources[0] );
2340 resource.type = VT_IMAGE;
2341 ef936x_load_image_address_to_register( _environment, "BLITTMPPTR", &resource, _sequence, _frame, _frame_size, _frame_count );
2342 } else {
2343 outline0( "LDY #0" );
2344 outline0( "STY BLITTMPPTR" );
2345 }
2346
2347 if ( _source_count > 1 ) {
2348 Resource resource;
2349 resource.realName = strdup( _sources[1] );
2350 resource.type = VT_IMAGE;
2351 ef936x_load_image_address_to_register( _environment, "BLITTMPPTR2", &resource, _sequence, _frame, _frame_size, _frame_count );
2352 } else {
2353 outline0( "LDY #0" );
2354 outline0( "STY BLITTMPPTR2" );
2355 }
2356
2357 outline1("LDD %s", _x );
2358 outline0("STD <IMAGEX" );
2359 outline1("LDD %s", _y );
2360 outline0("STD <IMAGEY" );
2361
2362 outline1("LDA #$%2.2x", ( _flags & 0xff ) );
2363 outline0("STA <IMAGEF" );
2364 outline1("LDA #$%2.2x", ( (_flags>>8) & 0xff ) );
2365 outline0("STA <IMAGET" );
2366
2367 outline0("JSR BLITIMAGE");
2368
2369}
2370
2371void ef936x_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2372
2373}
2374
2375int ef936x_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
2376
2377 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2378
2379 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
2380
2381 int uniquePaletteCount = 0;
2382
2383 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
2384
2385 return uniquePaletteCount;
2386
2387}
2388
2389void ef936x_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
2390
2391 deploy_preferred( ef936xvars, src_hw_ef936x_vars_asm);
2392
2393 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0001" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
2394 ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2395 deploy( flipimagex, src_hw_ef936x_flip_image_x_asm );
2396 if ( _image->isAddress && _image->bankNumber != -1 ) {
2397 outline0("ORCC #$50");
2398 bank_set( _environment, _image->bankNumber );
2399 }
2400 outline0("JSR FLIPIMAGEX");
2401 if ( _image->isAddress && _image->bankNumber != -1 ) {
2402 bank_set( _environment, 0x07 );
2403 outline0("ANDCC #$AF");
2404 }
2405 } else {
2406
2408
2409 ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2410 deploy( flipimagex, src_hw_ef936x_flip_image_x_asm );
2411 outline1("LDA %s", _direction );
2412 outline1("ANDA #$%2.2x", FLAG_FLIP_X );
2413 outline1("BEQ %s", label );
2414 if ( _image->isAddress && _image->bankNumber != -1 ) {
2415 outline0("ORCC #$50");
2416 bank_set( _environment, _image->bankNumber );
2417 }
2418 outline0("JSR FLIPIMAGEX");
2419 if ( _image->isAddress && _image->bankNumber != -1 ) {
2420 bank_set( _environment, 0x07 );
2421 outline0("ANDCC #$AF");
2422 }
2423 outhead1("%s", label );
2424
2425 }
2426
2427 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0002" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
2428 ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2429 deploy( flipimagey, src_hw_ef936x_flip_image_y_asm );
2430 if ( _image->isAddress && _image->bankNumber != -1 ) {
2431 outline0("ORCC #$50");
2432 bank_set( _environment, _image->bankNumber );
2433 }
2434 outline0("JSR FLIPIMAGEY");
2435 if ( _image->isAddress && _image->bankNumber != -1 ) {
2436 bank_set( _environment, 0x07 );
2437 outline0("ANDCC #$AF");
2438 }
2439 } else {
2440
2442
2443 ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2444 deploy( flipimagey, src_hw_ef936x_flip_image_y_asm );
2445 outline1("LDA %s", _direction );
2446 outline1("ANDA #$%2.2x", FLAG_FLIP_Y );
2447 outline1("BEQ %s", label );
2448 if ( _image->isAddress && _image->bankNumber != -1 ) {
2449 outline0("ORCC #$50");
2450 bank_set( _environment, _image->bankNumber );
2451 }
2452 outline0("JSR FLIPIMAGEY");
2453 if ( _image->isAddress && _image->bankNumber != -1 ) {
2454 bank_set( _environment, 0x07 );
2455 outline0("ANDCC #$AF");
2456 }
2457 outhead1("%s", label );
2458
2459 }
2460
2461}
2462
2463void ef936x_fade_out( Environment * _environment, char * _period ) {
2464
2465 deploy( fade, src_hw_ef936x_fade_asm );
2466
2467 if ( _period ) {
2468 outline1( "LDD %s", _period );
2469 } else {
2470 outline0( "LDD #4" );
2471 }
2472 outline0( "STD FADEOUTPERIOD+1" );
2473 outline0("JSR FADEOUT");
2474
2475}
2476
2477void ef936x_fade_in( Environment * _environment, char * _period ) {
2478
2479 deploy( fade, src_hw_ef936x_fade_asm );
2480
2481 if ( _period ) {
2482 outline1( "LDD %s", _period );
2483 } else {
2484 outline0( "LDD #4" );
2485 }
2486 outline0( "STD FADEINPERIOD+1" );
2487 outline0("JSR FADEIN");
2488
2489}
2490
2491void ef936x_fade_in_color( Environment * _environment, int _index, int _background_color ) {
2492
2493 outline1("LDD #$%4.4x", _background_color );
2494 outline1("STD COMMONPALETTE+$%2.2x", ( _index & 0x0f ) * 2 );
2495
2496}
2497
2498void ef936x_fade_in_color_vars( Environment * _environment, char * _index, char * _background_color ) {
2499
2500 outline0("LDX #COMMONPALETTE" );
2501 outline1("LDB %s", _index );
2502 outline0("LSLB" );
2503 outline0("ABX" );
2504 outline1("LDD %s", _background_color );
2505 outline0("STD ,X" );
2506
2507}
2508
2509void ef936x_fade_in_color_semivars( Environment * _environment, int _index, char * _background_color ) {
2510
2511 outline1("LDD %s", _background_color );
2512 outline1("STD COMMONPALETTE+$%2.2x", ( _index & 0x0f ) * 2 );
2513
2514}
2515
2516#endif
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
int lastUsedSlotInCommonPalette
Definition 6847.c:100
#define BITMAP_MODE_DEFAULT
Definition 6847.h:95
Variable * variable_retrieve(Environment *_environment, char *_name)
RGBi * palette_match_hardware_index(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
int reset_screen_mode_selected(Environment *_environment)
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.
RGBi * palette_shift(RGBi *_source, int _source_size, int _offset)
Shift colors in palette.
RGBi * palette_merge(RGBi *_palette1, int _palette1_size, RGBi *_palette2, int _palette2_size, int *_size)
Make a "palette merge".
void image_converter_asserts_free(Environment *_environment, int _width, int _height, int _offset_x, int _offset_y, int *_frame_width, int *_frame_height)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * palette_promote_color_as_background(int _index, RGBi *_source, int _source_size)
Promote an index color in a palette.
RGBi * malloc_palette(int _size)
Allocate a palette space.
void rgbi_move(RGBi *_source, RGBi *_destination)
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_promote_color_as_foreground(int _index, RGBi *_source, int _source_size, int _max_size)
Promote an index color in a palette.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
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".
Variable * variable_store_buffer(Environment *_environment, char *_destination, unsigned char *_buffer, int _size, int _at)
int size
Definition _optimizer.c:678
int offset
Definition _optimizer.c:681
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
void screen_mode(Environment *_environment, int _mode)
Emit ASM code for SCREEN [mode].
void scroll(Environment *_environment, int _dx, int _dy)
Definition scroll.c:41
void bank_set(Environment *_environment, int _bank)
Emit ASM code for instruction BANK ....
Definition bank_set.c:72
void console_init(Environment *_environment)
Definition console.c:41
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
int ef936x_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition ef936x.c:2375
void ef936x_sprite_multicolor(Environment *_environment, char *_sprite)
Definition ef936x.c:623
void ef936x_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition ef936x.c:1920
void ef936x_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition ef936x.c:530
void ef936x_textmap_at(Environment *_environment, char *_address)
Definition ef936x.c:508
void ef936x_background_color_semivars(Environment *_environment, int _index, char *_background_color)
VIC-II: emit code to change background color
Definition ef936x.c:246
void ef936x_screen_on(Environment *_environment)
Definition ef936x.c:571
void ef936x_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition ef936x.c:2285
void ef936x_sprite_data_from(Environment *_environment, char *_sprite, char *_address)
Definition ef936x.c:587
void ef936x_sprite_monocolor(Environment *_environment, char *_sprite)
Definition ef936x.c:627
void ef936x_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition ef936x.c:2202
void ef936x_fade_in(Environment *_environment, char *_period)
Definition ef936x.c:2477
void ef936x_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition ef936x.c:484
void ef936x_vertical_scroll(Environment *_environment, char *_displacement)
Definition ef936x.c:643
void ef936x_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition ef936x.c:635
void ef936x_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)
Definition ef936x.c:2321
void ef936x_bitmap_at(Environment *_environment, char *_address)
Definition ef936x.c:500
Variable * ef936x_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition ef936x.c:2085
void ef936x_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition ef936x.c:2210
void ef936x_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition ef936x.c:953
void ef936x_calculate_sequence_frame_offset_regy(Environment *_environment, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition ef936x.c:2233
void ef936x_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition ef936x.c:2389
void ef936x_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition ef936x.c:607
void ef936x_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
VIC-II: emit code to wait for next raster irq at different position
Definition ef936x.c:337
int ef936x_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition ef936x.c:988
void ef936x_cline(Environment *_environment, char *_characters)
Definition ef936x.c:968
void ef936x_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition ef936x.c:2215
void ef936x_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition ef936x.c:939
void ef936x_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition ef936x.c:680
Variable * ef936x_get_raster_line(Environment *_environment)
Definition ef936x.c:2223
int ef936x_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition ef936x.c:369
void ef936x_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
VIC-II: emit code to set raster irq
Definition ef936x.c:306
void ef936x_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition ef936x.c:512
void ef936x_fade_in_color_vars(Environment *_environment, char *_index, char *_background_color)
Definition ef936x.c:2498
void ef936x_fade_in_color(Environment *_environment, int _index, int _background_color)
Definition ef936x.c:2491
void ef936x_sprite_enable(Environment *_environment, char *_sprite)
Definition ef936x.c:595
void ef936x_get_height(Environment *_environment, char *_result)
Definition ef936x.c:665
void ef936x_tiles_get(Environment *_environment, char *_result)
Definition ef936x.c:658
void ef936x_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition ef936x.c:2206
void ef936x_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition ef936x.c:2371
Variable * ef936x_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition ef936x.c:2053
void ef936x_background_color(Environment *_environment, int _index, int _background_color)
VIC-II: emit code to change background color
Definition ef936x.c:185
void ef936x_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition ef936x.c:554
void ef936x_bitmap_disable(Environment *_environment)
Definition ef936x.c:480
void ef936x_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition ef936x.c:603
void ef936x_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
VIC-II: emit code to change common sprite's color
Definition ef936x.c:287
void ef936x_hit(Environment *_environment, char *_sprite_mask, char *_result)
VIC-II: emit code to check for collision
Definition ef936x.c:158
void ef936x_initialization(Environment *_environment)
Definition ef936x.c:731
void ef936x_fade_out(Environment *_environment, char *_period)
Definition ef936x.c:2463
void ef936x_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition ef936x.c:591
void ef936x_screen_rows(Environment *_environment, char *_rows)
Definition ef936x.c:579
Variable * ef936x_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition ef936x.c:2029
void ef936x_use_tileset(Environment *_environment, char *_tileset)
Definition ef936x.c:2219
void console_calculate_vars(Environment *_environment)
Definition ef936x.c:361
void ef936x_collision(Environment *_environment, char *_sprite_mask, char *_result)
VIC-II: emit code to check for collision
Definition ef936x.c:143
void ef936x_tiles_at(Environment *_environment, char *_address)
Definition ef936x.c:639
void ef936x_next_raster(Environment *_environment)
VIC-II: emit code to wait for next raster irq
Definition ef936x.c:320
void ef936x_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition ef936x.c:706
void ef936x_colormap_at(Environment *_environment, char *_address)
Definition ef936x.c:504
void ef936x_finalization(Environment *_environment)
Definition ef936x.c:861
void ef936x_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition ef936x.c:611
void ef936x_sprite_disable(Environment *_environment, char *_sprite)
Definition ef936x.c:599
void ef936x_screen_off(Environment *_environment)
Definition ef936x.c:575
void ef936x_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
VIC-II: emit code to change background color
Definition ef936x.c:267
void ef936x_horizontal_scroll(Environment *_environment, char *_displacement)
Definition ef936x.c:647
void ef936x_screen_columns(Environment *_environment, char *_columns)
Definition ef936x.c:583
void ef936x_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition ef936x.c:464
void ef936x_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition ef936x.c:631
void ef936x_background_color_vars(Environment *_environment, char *_index, char *_background_color)
VIC-II: emit code to change background color
Definition ef936x.c:219
void ef936x_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition ef936x.c:619
void ef936x_back(Environment *_environment)
Definition ef936x.c:964
void ef936x_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition ef936x.c:2118
void ef936x_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition ef936x.c:615
void ef936x_fade_in_color_semivars(Environment *_environment, int _index, char *_background_color)
Definition ef936x.c:2509
void ef936x_cls(Environment *_environment)
Definition ef936x.c:672
void ef936x_get_width(Environment *_environment, char *_result)
Definition ef936x.c:651
void ef936x_bank_select(Environment *_environment, int _bank)
Definition ef936x.c:341
void ef936x_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition ef936x.c:695
Variable * ef936x_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)
Definition ef936x.c:1809
void console_calculate(Environment *_environment)
Definition ef936x.c:345
void ef936x_scroll(Environment *_environment, int _dx, int _dy)
Definition ef936x.c:2186
void ef936x_border_color(Environment *_environment, char *_border_color)
VIC-II: emit code to change border color
Definition ef936x.c:171
#define BITMAP_MODE_BITMAP_16
Definition ef936x.h:122
#define BITMAP_MODE_PAGE
Definition ef936x.h:123
#define BITMAP_MODE_80_COLUMN
Definition ef936x.h:120
#define BITMAP_MODE_40_COLUMN
Definition ef936x.h:119
#define BITMAP_MODE_BITMAP_4
Definition ef936x.h:121
#define EF936X_COMPONENT_BITMASK
Definition mo5.h:165
int width
Definition ugbc.h:2209
int height
Definition ugbc.h:2210
char * name
Definition ugbc.h:2252
struct _CopperList * next
Definition ugbc.h:2255
int screenTilesWidth
Definition ugbc.h:2880
int screenShades
Definition ugbc.h:2865
int fontHeight
Definition ugbc.h:2905
Console activeConsole
Definition ugbc.h:2910
int currentMode
Definition ugbc.h:2696
int screenTilesHeight
Definition ugbc.h:2885
int consoleTilesHeight
Definition ugbc.h:2895
RgbConverterFunction currentRgbConverterFunction
Definition ugbc.h:2711
int fontWidth
Definition ugbc.h:2900
CopperList * copperList
Definition ugbc.h:3282
int screenColors
Definition ugbc.h:2870
int dynamicConsole
Definition ugbc.h:3298
int currentModeBW
Definition ugbc.h:2701
int screenHeight
Definition ugbc.h:2860
int consoleTilesWidth
Definition ugbc.h:2890
int transparencyUsed
Definition ugbc.h:3259
int currentTileMode
Definition ugbc.h:2706
TileDescriptors * descriptors
Definition ugbc.h:2939
GammaCorrection gammaCorrection
Definition ugbc.h:3000
int screenTiles
Definition ugbc.h:2875
int screenWidth
Definition ugbc.h:2855
VestigialConfig vestigialConfig
Definition ugbc.h:2442
unsigned char red
Definition ugbc.h:433
unsigned char green
Definition ugbc.h:434
unsigned char blue
Definition ugbc.h:435
unsigned char alpha
Definition ugbc.h:436
int bankNumber
Definition ugbc.h:556
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
int selected
Definition ugbc.h:1510
unsigned char * valueBuffer
Definition ugbc.h:1061
int size
Definition ugbc.h:1077
char * name
Definition ugbc.h:979
int originalColors
Definition ugbc.h:1154
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
int value
Definition ugbc.h:1025
int initializedByConstant
Definition ugbc.h:1036
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
void * malloc(YYSIZE_T)
struct _ScreenMode ScreenMode
#define out4(s, a, b, c, d)
Definition ugbc.h:4263
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
Definition ugbc.h:3502
struct _Resource Resource
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define adilineendbitmap()
Definition ugbc.h:4241
#define WARNING_SCREEN_MODE(v1)
Definition ugbc.h:3878
struct _Variable Variable
Structure of a single variable.
#define CRITICAL_PUT_IMAGE_X_UNSUPPORTED(v, t)
Definition ugbc.h:3760
struct _Environment Environment
Structure of compilation environment.
#define FLAG_FLIP_X
Definition ugbc.h:4553
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_SBYTE
Definition ugbc.h:452
@ VT_IMAGES
Definition ugbc.h:495
@ VT_COLOR
Definition ugbc.h:471
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define adiline3(s, a, b, c)
Definition ugbc.h:4197
@ GAMMA_CORRECTION_TYPE2
Definition ugbc.h:324
@ GAMMA_CORRECTION_NONE
Definition ugbc.h:318
@ GAMMA_CORRECTION_TYPE1
Definition ugbc.h:321
#define CRITICAL_PUT_IMAGE_Y_UNSUPPORTED(v, t)
Definition ugbc.h:3761
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#define outhead0(s)
Definition ugbc.h:4246
#define out0(s)
Definition ugbc.h:4259
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
Definition ugbc.h:1516
#define MAX_PALETTE
Definition ugbc.h:568
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
Definition ugbc.h:3688
#define CRITICAL_SCREEN_UNSUPPORTED(v)
Definition ugbc.h:3496
#define outline0(s)
Definition ugbc.h:4252
#define FLAG_FLIP_Y
Definition ugbc.h:4554
#define outline1(s, a)
Definition ugbc.h:4253
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define VT_BITWIDTH(t)
Definition ugbc.h:595
#define adilinebeginbitmap(s)
Definition ugbc.h:4231
struct _CopperList CopperList
#define outline4(s, a, b, c, d)
Definition ugbc.h:4256
#define FLAG_EXACT
Definition ugbc.h:4569
#define adilinepixel(p)
Definition ugbc.h:4236
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)
Definition ugbc.h:3540
#define CRITICAL_BLIT_TOO_MUCH_SOURCES()
Definition ugbc.h:3613
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247
char DATATYPE_AS_STRING[][16]
char * strcopy(char *_dest, char *_source)