ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
vic2z.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(__c128zz__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40static RGBi SYSTEM_PALETTE[] = {
41 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK" },
42 { 0xff, 0xff, 0xff, 0xff, 1, "WHITE" },
43 { 0x80, 0x00, 0x00, 0xff, 2, "RED" },
44 { 0xaa, 0xff, 0xe6, 0xff, 3, "CYAN" },
45 { 0xcc, 0x44, 0xcc, 0xff, 4, "VIOLET" },
46 { 0x00, 0xcc, 0x55, 0xff, 5, "GREEN" },
47 { 0x00, 0x00, 0xaa, 0xff, 6, "BLUE" },
48 { 0xee, 0xee, 0x77, 0xff, 7, "YELLOW" },
49 { 0xa1, 0x68, 0x3c, 0xff, 8, "ORANGE" },
50 { 0xdd, 0x88, 0x65, 0xff, 9, "BROWN" },
51 { 0xff, 0x77, 0x77, 0xff, 10, "LIGHT_RED" },
52 { 0x33, 0x33, 0x33, 0xff, 11, "DARK_GREY" },
53 { 0x77, 0x77, 0x77, 0xff, 12, "GREY" },
54 { 0xaa, 0xff, 0x66, 0xff, 13, "LIGHT GREEN" },
55 { 0x00, 0x88, 0xff, 0xff, 14, "LIGHT BLUE" },
56 { 0xbb, 0xbb, 0xbb, 0xff, 15, "LIGHT GREY" }
57};
58
59static RGBi * commonPalette;
61
62/****************************************************************************
63 * CODE SECTION
64 ****************************************************************************/
65
66RGBi * vic2z_image_nearest_system_color( RGBi * _color ) {
67
68 unsigned int minDistance = 0xffff;
69 int colorIndex = 0;
70 for (int j = 0; j < COLOR_COUNT; ++j) {
71 int distance = rgbi_distance(&SYSTEM_PALETTE[j], _color);
72 if (distance < minDistance) {
73 minDistance = distance;
74 colorIndex = j;
75 }
76 }
77
78 return &SYSTEM_PALETTE[colorIndex];
79
80}
81
93static void vic2z_image_converter_tile( Environment * _environment, char * _source, char * _dest, int _width, int _depth, int _source_width ) {
94
95 int colorIndexesCount[COLOR_COUNT];
96 memset(colorIndexesCount, 0, COLOR_COUNT * sizeof( int ) );
97 int trans = 0;
98
99 char * source = _source;
100
101 // Clear the box and colors
102 memset( _dest, 0, 9 );
103
104 // Loop for all the box surface
105 for (int y=0; y<8; ++y) {
106 for (int x=0; x<8; ++x) {
107
108 RGBi rgb;
109
110 memset( &rgb, 0, sizeof( RGBi ) );
111
112 // Take the color of the pixel
113 rgb.red = *source;
114 rgb.green = *(source + 1);
115 rgb.blue = *(source + 2);
116 if ( _depth > 3 ) {
117 rgb.alpha = *(_source + 3);
118 } else {
119 rgb.alpha = 255;
120 }
121 if ( rgb.alpha == 0 ) {
122 rgb.red = 0;
123 rgb.green = 0;
124 rgb.blue = 0;
125 }
126
127 if ( rgb.alpha < 255 ) {
128 trans = 1;
129 } else {
130 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
131 ++colorIndexesCount[systemRgb->index];
132 }
133
134 source += _depth;
135
136 }
137
138 source += _depth * ( _source_width - 8 );
139
140 }
141
142 int colorBackground = 0;
143 int colorBackgroundMax = 0;
144 int colorForeground = 0;
145 int colorForegroundMax = 0;
146 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
147 if ( colorIndexesCount[xx] > colorBackgroundMax ) {
148 colorBackground = xx;
149 colorBackgroundMax = colorIndexesCount[xx];
150 };
151 }
152
153 colorIndexesCount[colorBackground] = 0;
154
155 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
156 if ( colorIndexesCount[xx] > colorForegroundMax ) {
157 colorForeground = xx;
158 colorForegroundMax = colorIndexesCount[xx];
159 };
160 }
161
162 if ( trans ) {
163 if ( colorForeground == 0 ) {
164 colorForeground = colorBackground;
165 colorBackground = 0;
166 } else {
167 colorBackground = 0;
168 }
169 }
170
171 if ( colorForeground == colorBackground ) {
172 colorForeground = ( colorBackground == 0 ) ? 1 : 0;
173 }
174
175 source = _source;
176
177 for (int y=0; y<8; ++y) {
178 for (int x=0; x<8; ++x) {
179
180 RGBi rgb;
181
182 memset( &rgb, 0, sizeof( RGBi ) );
183
184 rgb.red = *source;
185 rgb.green = *(source + 1);
186 rgb.blue = *(source + 2);
187 if ( _depth > 3 ) {
188 rgb.alpha = *(_source + 3);
189 } else {
190 rgb.alpha = 255;
191 }
192 if ( rgb.alpha == 0 ) {
193 rgb.red = 0;
194 rgb.green = 0;
195 rgb.blue = 0;
196 }
197
198 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
199
200 char bitmask = 1 << ( 7 - ((x) & 0x7) );
201
202 if ( rgb.alpha < 255 ) {
203 *( _dest + y ) &= ~bitmask;
204 adilinepixel(colorBackground);
205 } else {
206 if ( systemRgb->index != colorBackground ) {
207 adilinepixel(colorForeground);
208 *( _dest + y ) |= bitmask;
209 // printf("*");
210 } else {
211 adilinepixel(colorBackground);
212 *( _dest + y ) &= ~bitmask;
213 // printf(" ");
214 }
215 }
216
217 source += _depth;
218
219 }
220
221 source += _depth * ( _source_width - 8 );
222
223 }
224
225 *( _dest + 8 ) = ( colorForeground << 4 ) | colorBackground ;
226
227}
228
240static void vic2z_image_converter_tiles( Environment * _environment, char * _source, char * _dest, int _width, int _height, int _depth, int _source_width ) {
241
242 int bitmapSize = ( _width>>3 ) * _height;
243 int colormapSize = ( _width>>3 ) * (_height>>3);
244
245 memset( _dest, 0, bitmapSize + colormapSize );
246
247 adilinebeginbitmap("BMD2");
248
249 for( int y=0; y<_height; y+=8 ) {
250 for( int x=0; x<_width; x+=8 ) {
251
252 char * source = _source + ( ( y * _source_width ) + x ) * _depth;
253 char tile[9];
254
255 vic2z_image_converter_tile( _environment, source, tile, _width, _depth, _source_width );
256
257 int offset = ((y>>3) * 8 *( _width >> 3 ) ) + ((x>>3) * 8) + ((y) & 0x07);
258 // x = 8, y = 8
259 // offset = ((8 >> 3) * 8 * (16>>3) ) + ((8>>3) * 8) + ((8) & 7)
260 // offset = (1 * 8 * 2 ) + (1 * 8)
261 // offset = 16 + 8 = 24
262
263 char * destBitmap = _dest + offset;
264 char * destColormap = _dest + bitmapSize + ( ( ( y >> 3 ) * ( _width >> 3 ) ) + ( x >> 3 ) );
265 for( int i=0; i<8; ++i ) {
266 *destBitmap = tile[i];
267 ++destBitmap;
268 }
269 // printf("tile at %d,%d color = %2.2x\n", x, y, tile[8] );
270 *destColormap = tile[8];
271 }
272 }
273
275
276}
277
291static void vic2z_image_converter_tile_multicolor( Environment * _environment, char * _source, char * _dest, int _width, int _depth, int _background, int _source_width ) {
292
293 int colorIndexesCount[COLOR_COUNT];
294 memset(colorIndexesCount, 0, COLOR_COUNT * sizeof( int ) );
295 int trans = 0;
296
297 char * source = _source;
298
299 // Clear the box and colors
300 memset( _dest, 0, 10 );
301
302 // Loop for all the box surface
303 for (int y=0; y<8; ++y) {
304 for (int x=0; x<4; ++x) {
305
306 RGBi rgb;
307
308 memset( &rgb, 0, sizeof( RGBi ) );
309
310 // Take the color of the pixel
311 rgb.red = *source;
312 rgb.green = *(source + 1);
313 rgb.blue = *(source + 2);
314 if ( _depth > 3 ) {
315 rgb.alpha = *(_source + 3);
316 } else {
317 rgb.alpha = 255;
318 }
319 if ( rgb.alpha == 0 ) {
320 rgb.red = 0;
321 rgb.green = 0;
322 rgb.blue = 0;
323 }
324
325 if ( rgb.alpha < 255 ) {
326 trans = 1;
327 } else {
328
329 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
330
331 ++colorIndexesCount[systemRgb->index];
332
333 }
334
335 source += _depth;
336
337 }
338
339 source += _depth * ( _source_width - 4 );
340
341 }
342
343 if ( trans ) {
344 _background = 0;
345 }
346
347 colorIndexesCount[_background] = 0;
348
349 int colorFirst = 0;
350 int colorFirstMax = 0;
351 int colorSecond = 0;
352 int colorSecondMax = 0;
353 int colorThird = 0;
354 int colorThirdMax = 0;
355
356 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
357 if ( colorIndexesCount[xx] > colorFirstMax ) {
358 colorFirst = xx;
359 colorFirstMax = colorIndexesCount[xx];
360 };
361 }
362
363 colorIndexesCount[colorFirst] = 0;
364
365 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
366 if ( colorIndexesCount[xx] > colorSecondMax ) {
367 colorSecond = xx;
368 colorSecondMax = colorIndexesCount[xx];
369 };
370 }
371
372 colorIndexesCount[colorSecond] = 0;
373
374 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
375 if ( colorIndexesCount[xx] > colorThirdMax ) {
376 colorThird = xx;
377 colorThirdMax = colorIndexesCount[xx];
378 };
379 }
380
381 colorIndexesCount[colorThird] = 0;
382
383 source = _source;
384
385 for (int y=0; y<8; ++y) {
386 for (int x=0; x<4; ++x) {
387
388 RGBi rgb;
389
390 memset( &rgb, 0, sizeof( RGBi ) );
391
392 rgb.red = *source;
393 rgb.green = *(source + 1);
394 rgb.blue = *(source + 2);
395 if ( _depth > 3 ) {
396 rgb.alpha = *(_source + 3);
397 } else {
398 rgb.alpha = 255;
399 }
400 if ( rgb.alpha == 0 ) {
401 rgb.red = 0;
402 rgb.green = 0;
403 rgb.blue = 0;
404 }
405
406 char colorIndex = 0;
407
408 if ( rgb.alpha < 255 ) {
409 adilinepixel(_background);
410 colorIndex = 0;
411 } else {
412
413 RGBi *systemRgb = vic2z_image_nearest_system_color( &rgb );
414
415 if ( systemRgb->index == colorFirst ) {
416 adilinepixel(colorFirst);
417 colorIndex = 1;
418 } else if ( systemRgb->index == colorSecond ) {
419 adilinepixel(colorSecond);
420 colorIndex = 2;
421 } else if ( systemRgb->index == colorThird ) {
422 adilinepixel(colorThird);
423 colorIndex = 3;
424 } else {
425 adilinepixel(_background);
426 }
427
428 }
429
430 char bitmask = colorIndex << (6 - ((x & 0x3) * 2));
431
432 *(_dest + y) |= bitmask;
433
434 source += _depth;
435
436 }
437
438 source += _depth * ( _source_width - 4 );
439
440 }
441
442 *( _dest + 8 ) = ( colorFirst << 4 ) | colorSecond ;
443 *( _dest + 9 ) = ( _background << 4 ) | colorThird;
444
445}
446
460static void vic2z_image_converter_tiles_multicolor( Environment * _environment, char * _source, char * _dest, int _width, int _height, int _depth, int _source_width, int _background ) {
461
462 int bitmapSize = ( _width>>2 ) * _height;
463 int colormap1Size = ( _width>>2 ) * (_height>>3);
464 int colormap2Size = ( _width>>2 ) * (_height>>3);
465
466 memset( _dest, 0, bitmapSize + colormap1Size + colormap2Size );
467
468 adilinebeginbitmap("BMD4");
469
470 for( int y=0; y<_height; y+=8 ) {
471 for( int x=0; x<_width; x+=4 ) {
472
473 char * source = _source + ( ( y * _source_width ) + x ) * _depth;
474 char tile[10];
475
476 vic2z_image_converter_tile_multicolor( _environment, source, tile, _width, _depth, _background, _source_width );
477
478 int offset = ((y>>3) * 8 *( _width >> 2 ) ) + ((x>>2) * 8) + ((y) & 0x07);
479
480 char * destBitmap = _dest + offset;
481 char * destColormap1 = _dest + bitmapSize + ( ( ( y >> 3 ) * ( _width >> 2 ) ) + ( x >> 2 ) );
482 char * destColormap2 = _dest + bitmapSize + colormap1Size + ( ( ( y >> 3 ) * ( _width >> 2 ) ) + ( x >> 2 ) );
483 for( int i=0; i<8; ++i ) {
484 *destBitmap = tile[i];
485 ++destBitmap;
486 }
487 *destColormap1 = tile[8];
488 *destColormap2 = tile[9];
489 }
490 }
491
493
494}
495
507Variable * vic2z_collision( Environment * _environment, char * _sprite ) {
508
509 // _environment->bitmaskNeeded = 1;
510
511 // deploy( sprite, src_hw_vic2z_sprites_asm );
512
513 // Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_SPRITE, 0 );
514 // Variable * result = variable_temporary( _environment, VT_BYTE, "(collision result)");
515
516 // MAKE_LABEL
517
518 // outline1("LDA %s", sprite->realName);
519 // outline0("STA MATHPTR3");
520 // outline0("JSR SPRITECOL");
521 // outline1("STA %s", result->realName);
522
523 // return result;
524
525}
526
538void vic2z_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
539
540 // Generate unique label for ASM code.
542
543 // Check for collision using VIC-II registers
544 outline0("LDA $D01F");
545 outline1("AND %s", _sprite_mask);
546 cpu_beq(_environment, label);
547
548 outline0("LDA #$1");
549 outline1("STA %s", _result);
550 outline1("JMP %s_2", label);
551
552 outhead1("%s:", label);
553 outline0("LDA #0");
554 outline1("STA %s", _result);
555 outhead1("%s_2:", label);
556
557}
558
568void vic2z_border_color( Environment * _environment, char * _border_color ) {
569
570 outline1("LDA %s", _border_color );
571 outline0("AND #$0f" );
572 outline0("STA $D020");
573
574}
575
586void vic2z_background_color( Environment * _environment, int _index, int _background_color ) {
587
588 outline1("LDA #$%2.2x", _background_color );
589 outline0("AND #$0f" );
590 outline1("STA $d021+%d", ( _index & 0x03 ) );
591}
592
603void vic2z_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
604
605 outline1("LDA %s", _index);
606 outline0("AND #$03");
607 outline0("TAX");
608 outline1("LDA %s", _background_color );
609 outline0("AND #$0f" );
610 outline0("STA $d021,X");
611}
612
623void vic2z_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
624
625 outline1("LDA #$%2.2x", _index);
626 outline0("AND #$03");
627 outline0("TAX");
628 outline1("LDA %s", _background_color );
629 outline0("AND #$0f" );
630 outline0("STA $d021,X");
631}
632
643void vic2z_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
644
645 outline1("LDA %s", _index);
646 outline0("AND #$03");
647 outline0("TAX");
648 outline0("LDA $d021,X");
649 outline0("AND #$0f" );
650 outline1("STA %s", _background_color );
651}
652
663void vic2z_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
664
665 outline1("LDA %s", _index);
666 outline0("AND #$03");
667 outline0("TAX");
668 outline1("LDA %s", _common_color );
669 outline0("AND #$0f" );
670 outline0("STA $D025,X" );
671
672}
673
689void vic2z_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
690
692
693 // outline0("LDA #%01111111"); // switch off CIA-1
694 // outline0("STA $DC0D");
695 outline0("AND $D011");
696 outline0("STA $D011");
697 outline0("LDA $DC0D"); // acknowledge CIA-1
698 outline0("LDA $DD0D"); // acknowledge CIA-2
699 outline1("LDA #<%s", _label);
700 outline0("STA $0314");
701 outline1("LDA #>%s", _label);
702 outline0("STA $0315");
703 outline0("LDA #%00000001"); // enable raster interrupt signals from VIC
704 outline0("STA $D01A");
705 outline1("LDA %s", _positionlo );
706 outline0("STA $D012");
707 outline1("LDA %s", _positionhi );
708 outline0("AND #%00000001" );
709 cpu_beq(_environment, label);
710 outline0("LDA $D011" );
711 outline0("AND #%01111111" );
712 outline0("ORA #%10000000" );
713 outline0("STA $D011");
714 outline1("JMP %s_2", label );
715 outhead1("%s:", label );
716 outline0("LDA $D011" );
717 outline0("AND #%01111111" );
718 outline0("STA $D011");
719 outhead1("%s_2:", label );
720 outline0("CLI");
721
722}
723
734void vic2z_next_raster( Environment * _environment ) {
735
736 outline0("ASL $D019");
737 outline0("JMP IRQSVC2");
738
739}
740
754void vic2z_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
755
757
758 outline1("LDA %s", _positionlo);
759 outline0("STA $D012");
760 outline1("LDA %s", _positionhi );
761 outline0("AND #%00000001" );
762 cpu_beq(_environment, label);
763 outline0("LDA $D011" );
764 outline0("AND #%01111111" );
765 outline0("ORA #%10000000" );
766 outline0("STA $D011");
767 outline1("JMP %s_2", label );
768 outhead1("%s:", label );
769 outline0("LDA $D011" );
770 outline0("AND #%01111111" );
771 outline0("STA $D011");
772 outhead1("%s_2:", label );
773 outline1("LDA #<%s", _label);
774 outline0("STA $0314");
775 outline1("LDA #>%s", _label);
776 outline0("STA $0315");
777
778 vic2z_next_raster( _environment );
779
780}
781
782void vic2z_bank_select( Environment * _environment, int _bank ) {
783
784 outline0("LDA $DD00" );
785 outline0("AND #%11111100");
786 outline1("ORA #%2.2x", ( ~_bank ) & 0x03 );
787 outline0("STA $DD00" );
788}
789
790static int rgbConverterFunction( int _red, int _green, int _blue ) {
791
792 int colorIndex = 0;
793 unsigned int minDistance = 0xffffffff;
794 int j;
795
796 RGBi rgb;
797 rgb.red = _red;
798 rgb.green = _green;
799 rgb.blue = _blue;
800
801 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
802 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &rgb);
803 if (distance < minDistance) {
804 minDistance = distance;
805 colorIndex = j;
806 }
807 }
808
809 return colorIndex;
810
811}
812
813int vic2z_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
814
815 _screen_mode->selected = 1;
816
817 Variable * colormapAddress = variable_retrieve( _environment, "COLORMAPADDRESS" );
818
819 _environment->fontWidth = 8;
820 _environment->fontHeight = 8;
821 _environment->screenTiles = 255;
822 switch( _screen_mode->id ) {
824 _environment->screenWidth = 320;
825 _environment->screenHeight = 200;
826 _environment->screenColors = 16;
827 _environment->currentModeBW = 1;
828 // This fix is necessary to set the starting address of the bitmap
829 // to $A000 (which is an address available on C=64).
830 outline0("LDA $D018" );
831 outline0("AND #%11110111");
832 outline0("ORA #%00001000" );
833 outline0("STA $D018" );
834
835 // Let's enable monocolor graphics!
836 outline0("LDA $D011" );
837 outline0("ORA #%00100000");
838 outline0("STA $D011" );
839 outline0("LDA $D016" );
840 outline0("AND #%11101111");
841 outline0("STA $D016" );
842
843 cpu_store_16bit( _environment, colormapAddress->realName, 0x8400 );
844
845 cpu_store_8bit( _environment, "_PEN", 0X01 );
846 cpu_store_8bit( _environment, "_PAPER", 0x00 );
847 cpu_store_16bit( _environment, "CLIPX1", 0 );
848 cpu_store_16bit( _environment, "CLIPX2", 319 );
849 cpu_store_16bit( _environment, "CLIPY1", 0 );
850 cpu_store_16bit( _environment, "CLIPY2", 199 );
851
852 break;
854 _environment->fontWidth = 4;
855 _environment->screenWidth = 160;
856 _environment->screenHeight = 200;
857 _environment->screenColors = 16;
858 _environment->currentModeBW = 2;
859 // This fix is necessary to set the starting address of the bitmap
860 // to $A000 (which is an address available on C=64) instead of the
861 // address $8000.
862 outline0("LDA $D018" );
863 outline0("AND #%11110111");
864 outline0("ORA #%00001000" );
865 outline0("STA $D018" );
866
867 // Let's enable multicolor graphics!
868 outline0("LDA $D011" );
869 outline0("ORA #%00100000");
870 outline0("STA $D011" );
871 outline0("LDA $D016" );
872 outline0("ORA #%00010000");
873 outline0("STA $D016" );
874
875 cpu_store_16bit( _environment, colormapAddress->realName, 0x8400 );
876
877 cpu_store_8bit( _environment, "_PEN", 0X01 );
878 cpu_store_8bit( _environment, "_PAPER", 0x00 );
879
880 cpu_store_16bit( _environment, "CLIPX1", 0 );
881 cpu_store_16bit( _environment, "CLIPX2", 159 );
882 cpu_store_16bit( _environment, "CLIPY1", 0 );
883 cpu_store_16bit( _environment, "CLIPY2", 199 );
884
885 break;
887 _environment->screenWidth = 320;
888 _environment->screenHeight = 200;
889 _environment->screenColors = 16;
890 _environment->currentModeBW = 0;
891 // Let's disable graphics!
892 outline0("LDA $D011" );
893 outline0("AND #%11011111");
894 outline0("STA $D011" );
895 outline0("LDA $D016" );
896 outline0("AND #%11101111");
897 outline0("STA $D016" );
898
899 // This fix is necessary to reset the lookup for rom character.
900 // outline0("LDA $D018" );
901 // outline0("AND #%11110111");
902 // outline0("STA $D018" );
903
904 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
905
906 cpu_store_8bit( _environment, "_PEN", 0x01 );
907 cpu_store_8bit( _environment, "_PAPER", 0x00 );
908
909 cpu_store_16bit( _environment, "CLIPX1", 0 );
910 cpu_store_16bit( _environment, "CLIPX2", 39 );
911 cpu_store_16bit( _environment, "CLIPY1", 0 );
912 cpu_store_16bit( _environment, "CLIPY2", 24 );
913
914 break;
916 _environment->screenWidth = 320;
917 _environment->screenHeight = 200;
918 _environment->screenColors = 16;
919 _environment->currentModeBW = 0;
920 // Let's disable graphics!
921 outline0("LDA $D011" );
922 outline0("AND #%11011111");
923 outline0("STA $D011" );
924 outline0("LDA $D016" );
925 outline0("ORA #%00010000");
926 outline0("STA $D016" );
927
928 // This fix is necessary to reset the lookup for rom character.
929 outline0("LDA $D018" );
930 outline0("AND #%11110111");
931 outline0("STA $D018" );
932
933 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
934
935 cpu_store_8bit( _environment, "_PEN", 0x01 );
936 cpu_store_8bit( _environment, "_PAPER", 0x00 );
937 cpu_store_16bit( _environment, "CLIPX1", 0 );
938 cpu_store_16bit( _environment, "CLIPX2", 39 );
939 cpu_store_16bit( _environment, "CLIPY1", 0 );
940 cpu_store_16bit( _environment, "CLIPY2", 24 );
941
942 break;
944 _environment->screenWidth = 320;
945 _environment->screenHeight = 200;
946 _environment->screenColors = 16;
947 _environment->currentModeBW = 0;
948 // Let's disable graphics!
949 outline0("LDA $D011" );
950 outline0("AND #%11011111");
951 outline0("ORA #%01000000");
952 outline0("STA $D011" );
953 outline0("LDA $D016" );
954 outline0("AND #%11101111");
955 outline0("STA $D016" );
956
957 // This fix is necessary to reset the lookup for rom character.
958 outline0("LDA $D018" );
959 outline0("AND #%11110111");
960 outline0("STA $D018" );
961
962 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
963
964 cpu_store_8bit( _environment, "_PEN", 0x01 );
965 cpu_store_8bit( _environment, "_PAPER", 0x00 );
966 cpu_store_16bit( _environment, "CLIPX1", 0 );
967 cpu_store_16bit( _environment, "CLIPX2", 39 );
968 cpu_store_16bit( _environment, "CLIPY1", 0 );
969 cpu_store_16bit( _environment, "CLIPY2", 24 );
970
971 break;
972 default:
973 CRITICAL_SCREEN_UNSUPPORTED( _screen_mode->id );
974 }
975
976 cpu_store_16bit( _environment, "ORIGINX", 0 );
977 cpu_store_16bit( _environment, "ORIGINY", 0 );
978
979 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
980 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
981 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
982 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
983 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
984 _environment->screenTilesWidth = 40;
985 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
986 _environment->screenTilesHeight = 25;
987 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
988 cpu_store_8bit( _environment, "FONTWIDTH", _environment->fontWidth );
989 cpu_store_8bit( _environment, "FONTHEIGHT", _environment->fontHeight );
990
991 if (_environment->vestigialConfig.clsImplicit ) {
992 vic2z_cls( _environment );
993 }
994
995}
996
997void vic2z_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
998
999 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
1000
1001 if ( mode ) {
1002 vic2z_screen_mode_enable( _environment, mode );
1003
1004 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
1005 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
1006
1007 _environment->currentMode = mode->id;
1008 _environment->currentTileMode = 0;
1009 } else {
1010 WARNING_SCREEN_MODE( -1 );
1011 }
1012}
1013
1014void vic2z_bitmap_disable( Environment * _environment ) {
1015
1016 Variable * colormapAddress = variable_retrieve( _environment, "COLORMAPADDRESS" );
1017
1018 // Let's disable graphics!
1019 outline0("LDA $D011" );
1020 outline0("AND #%11011111");
1021 outline0("STA $D011" );
1022 outline0("LDA $D016" );
1023 outline0("AND #%11101111");
1024 outline0("STA $D016" );
1025
1026 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
1027
1028}
1029
1030void vic2z_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
1031
1032 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
1033
1034 if ( mode ) {
1035 vic2z_screen_mode_enable( _environment, mode );
1036
1037 _environment->currentMode = mode->id;
1038 _environment->currentTileMode = 1;
1039
1040 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
1041 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
1042
1043 } else {
1044 WARNING_SCREEN_MODE( -1 );
1045 }
1046
1047}
1048
1049void vic2z_bitmap_at( Environment * _environment, char * _address ) {
1050
1051 outline1("LDA %s", _address );
1052 outline0("LSR");
1053 outline0("LSR");
1054 outline0("LSR");
1055 outline0("LSR");
1056 outline0("LSR");
1057 outline0("LSR");
1058 outline0("AND #%00000001");
1059 outline0("ASL" );
1060 outline0("ASL" );
1061 outline0("ASL" );
1062 outline0("STA TMPPTR" );
1063 outline0("LDA $D018" );
1064 outline0("AND #%11110111");
1065 outline0("ORA TMPPTR" );
1066 outline0("STA $D018" );
1067
1068}
1069
1070void vic2z_colormap_at( Environment * _environment, char * _address ) {
1071
1072 // Create a unique variabled for ASM code.
1074
1075 // Let's check if we are in ECM mode.
1076 outline0("LDA $D011");
1077 outline0("BIT #%00100000");
1078 cpu_beq(_environment, label);
1079
1080 // Change the colormap address that is the text address.
1081 vic2z_textmap_at( _environment, _address );
1082
1083 // If not, we are unable to change the colormap address.
1084 outline1("%s:", label);
1085
1086
1087}
1088
1089void vic2z_textmap_at( Environment * _environment, char * _address ) {
1090
1091 // Create a unique variabled for ASM code.
1093
1094 outline1("LDA %s", _address );
1095 outline0("LSR");
1096 outline0("LSR");
1097 outline0("AND #$0f");
1098 outline0("ASL");
1099 outline0("ASL");
1100 outline0("ASL");
1101 outline0("ASL");
1102 outline0("STA TMPPTR");
1103 outline0("LDA $D018");
1104 outline0("AND #%00001111");
1105 outline0("ORA TMPPTR" );
1106 outline0("STA $D018");
1107
1108}
1109
1110void vic2z_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
1111
1112 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1113 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1114 deploy( plot, src_hw_vic2z_plot_asm );
1115
1116 if ( _c ) {
1117 outline1("LDA #$%2.2x", ( *_c & 0xff ) );
1118 } else {
1119 Variable * c = variable_retrieve( _environment, "PEN" );
1120 outline1("LDA %s", c->realName );
1121 }
1122 outline0("STA PLOTCPE");
1123 outline1("LDA %2.2x", (_x & 0xff ) );
1124 outline0("STA PLOTX");
1125 outline1("LDA %2.2x", ( ( _x >> 8 ) & 0xff ) );
1126 outline0("STA PLOTX+1");
1127 outline1("LDA %2.2x", ( _y & 0xff ) );
1128 outline0("STA PLOTY");
1129 outline0("LDA #1");
1130 outline0("STA PLOTM");
1131 outline0("JSR PLOT");
1132
1133}
1134
1135void vic2z_pset_vars( Environment * _environment, char *_x, char *_y, char *_c ) {
1136
1137 Variable * x = variable_retrieve( _environment, _x );
1138 Variable * y = variable_retrieve( _environment, _y );
1139
1140 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1141 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1142 deploy( plot, src_hw_vic2z_plot_asm );
1143
1144 outline1("LDA %s", x->realName );
1145 outline0("STA PLOTX");
1146 if ( VT_BITWIDTH( x->type ) > 8 ) {
1147 outline1("LDA %s+1", x->realName );
1148 } else {
1149 outline0("LDA #0");
1150 }
1151 outline0("STA PLOTX+1");
1152 outline1("LDA %s", y->realName );
1153 outline0("STA PLOTY");
1154 outline0("LDA #1");
1155 outline0("STA PLOTM");
1156 outline0("JSR PLOT");
1157
1158}
1159
1160void vic2z_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
1161
1162 Variable * x = variable_retrieve( _environment, _x );
1163 Variable * y = variable_retrieve( _environment, _y );
1164 Variable * result = variable_retrieve( _environment, _result );
1165
1166 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1167 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1168 deploy( plot, src_hw_vic2z_plot_asm );
1169
1170 outline1("LDA %s", x->realName );
1171 outline0("STA PLOTX");
1172 outline1("LDA %s+1", x->realName );
1173 outline0("STA PLOTX+1");
1174 outline1("LDA %s", y->realName );
1175 outline0("STA PLOTY");
1176 outline0("LDA #3");
1177 outline0("STA PLOTM");
1178 outline0("JSR PLOT");
1179 outline0("LDA PLOTM");
1180 outline1("STA %s", result->realName);
1181
1182}
1183
1184void vic2z_screen_on( Environment * _environment ) {
1185
1186 outline0("LDA $D011" );
1187 outline0("ORA #%00010000");
1188 outline0("STA $D011" );
1189
1190}
1191
1192void vic2z_screen_off( Environment * _environment ) {
1193
1194 outline0("LDA $D011" );
1195 outline0("AND #%11101111");
1196 outline0("STA $D011" );
1197
1198}
1199
1200void vic2z_screen_rows( Environment * _environment, char * _rows ) {
1201
1203
1204 outline1("LDA %s", _rows);
1205 outline0("CMP #24");
1206 outline1("BEQ %s", label);
1207 outline0("LDA $D011" );
1208 outline0("ORA #%00001000");
1209 outline0("STA $D011" );
1210 outline1("JMP %s_2", label);
1211 outhead1("%s:", label );
1212 outline0("LDA $D011" );
1213 outline0("AND #%11110111");
1214 outline0("STA $D011" );
1215 outline1("JMP %s_2", label);
1216 outhead1("%s_2:", label );
1217
1218}
1219
1220void vic2z_screen_columns( Environment * _environment, char * _columns ) {
1221
1223
1224 outline1("LDA %s", _columns);
1225 outline0("CMP #38");
1226 outline1("BEQ %s", label);
1227 outline0("LDA $D016" );
1228 outline0("ORA #%00001000");
1229 outline0("STA $D016" );
1230 outline1("JMP %s_2", label);
1231 outhead1("%s:", label );
1232 outline0("LDA $D016" );
1233 outline0("AND #%11110111");
1234 outline0("STA $D016" );
1235 outline1("JMP %s_2", label);
1236 outhead1("%s_2:", label );
1237
1238}
1239
1240void vic2z_sprite_data_set( Environment * _environment, char * _sprite, char * _image ) {
1241
1242}
1243
1244void vic2z_sprite_data_from( Environment * _environment, char * _sprite, char * _image ) {
1245
1246 _environment->bitmaskNeeded = 1;
1247
1248 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1249 Variable * image = variable_retrieve_or_define( _environment, _image, VT_IMAGE, 0 );
1250
1251 deploy( sprite, src_hw_vic2z_sprites_asm );
1252
1253 outline1("LDA #<%s", image->realName );
1254 outline0("STA MATHPTR1" );
1255 outline1("LDA #>%s", image->realName );
1256 outline0("STA MATHPTR2" );
1257 outline1("LDY %s", sprite->realName );
1258 outline0("JSR SPRITEDATAFROM" );
1259
1260}
1261
1262void vic2z_sprite_enable( Environment * _environment, char * _sprite ) {
1263
1264 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1265
1266 deploy( sprite, src_hw_vic2z_sprites_asm );
1267
1268 _environment->bitmaskNeeded = 1;
1269
1270 outline1("LDY %s", sprite->realName );
1271 outline0("JSR SPRITEENABLE" );
1272
1273}
1274
1275void vic2z_sprite_disable( Environment * _environment, char * _sprite ) {
1276
1277 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1278
1279 deploy( sprite, src_hw_vic2z_sprites_asm );
1280
1281 _environment->bitmaskNeeded = 1;
1282
1283 outline1("LDY %s", sprite->realName );
1284 outline0("JSR SPRITEDISABLE" );
1285
1286}
1287
1288void vic2z_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
1289
1290 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1291 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
1292 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
1293
1294 deploy( sprite, src_hw_vic2z_sprites_asm );
1295
1296 _environment->bitmaskNeeded = 1;
1297
1298 outline1("LDA %s", x->realName );
1299 outline0("STA MATHPTR0" );
1300 outline1("LDA %s+1", x->realName );
1301 outline0("STA MATHPTR1" );
1302 outline1("LDX %s", y->realName );
1303 outline1("LDY %s", sprite->realName );
1304 outline0("JSR SPRITEAT" );
1305
1306}
1307
1308void vic2z_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
1309
1310 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1311
1312 deploy( sprite, src_hw_vic2z_sprites_asm );
1313
1314 outline1("LDY %s", sprite->realName );
1315 outline0("JSR SPRITEEXPAND" );
1316
1317}
1318
1319void vic2z_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
1320
1321 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1322
1323 deploy( sprite, src_hw_vic2z_sprites_asm );
1324
1325 outline1("LDY %s", sprite->realName );
1326 outline0("JSR SPRITEEXPAND" );
1327
1328}
1329
1330void vic2z_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
1331
1332 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1333
1334 deploy( sprite, src_hw_vic2z_sprites_asm );
1335
1336 outline1("LDY %s", sprite->realName );
1337 outline0("JSR SPRITECOMPRESS" );
1338
1339}
1340
1341void vic2z_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
1342
1343 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1344
1345 deploy( sprite, src_hw_vic2z_sprites_asm );
1346
1347 outline1("LDY %s", sprite->realName );
1348 outline0("JSR SPRITECOMPRESS" );
1349
1350}
1351
1352void vic2z_sprite_multicolor( Environment * _environment, char * _sprite ) {
1353
1354 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1355
1356 deploy( sprite, src_hw_vic2z_sprites_asm );
1357
1358 outline1("LDY %s", sprite->realName );
1359 outline0("JSR SPRITEMULTICOLOR" );
1360
1361}
1362
1363void vic2z_sprite_monocolor( Environment * _environment, char * _sprite ) {
1364
1365 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1366
1367 deploy( sprite, src_hw_vic2z_sprites_asm );
1368
1369 outline1("LDY %s", sprite->realName );
1370 outline0("JSR SPRITEMONOCOLOR" );
1371
1372}
1373
1374void vic2z_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
1375
1376 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1377 Variable * color = variable_retrieve_or_define( _environment, _color, VT_COLOR, COLOR_WHITE );
1378
1379 deploy( sprite, src_hw_vic2z_sprites_asm );
1380
1381 outline1("LDA %s", color->realName );
1382 outline1("LDY %s", sprite->realName );
1383 outline0("JSR SPRITECOLOR" );
1384
1385}
1386
1387void vic2z_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
1388
1389 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1390 Variable * priority = variable_retrieve_or_define( _environment, _priority, VT_BYTE, 0 );
1391
1392 deploy( sprite, src_hw_vic2z_sprites_asm );
1393
1394 outline1("LDA %s", priority->realName );
1395 outline1("LDY %s", sprite->realName );
1396 outline0("JSR SPRITEPRIORITY" );
1397
1398}
1399
1400void vic2z_tiles_at( Environment * _environment, char * _address ) {
1401
1402 outline1("LDA %s", _address);
1403 outline0("LSR");
1404 outline0("LSR");
1405 outline0("LSR");
1406 outline0("AND #$07");
1407 outline0("ASL");
1408 outline0("STA TMPPTR");
1409 outline0("LDA $D018");
1410 outline0("AND #%00001111");
1411 outline0("ORA TMPPTR");
1412 outline0("STA $D018");
1413
1414}
1415
1416void vic2z_vertical_scroll( Environment * _environment, char * _displacement, int _overlap ) {
1417
1418 outline0("LDA $D011" );
1419 outline0("AND #%11111000");
1420 outline1("ORA %s", _displacement );
1421 outline0("STA $D011" );
1422
1423}
1424
1425void vic2z_horizontal_scroll( Environment * _environment, char * _displacement, int _overlap ) {
1426
1427 outline0("LDA $D016" );
1428 outline0("AND #%11111000");
1429 outline1("ORA %s", _displacement );
1430 outline0("STA $D016" );
1431
1432}
1433
1434void vic2z_busy_wait( Environment * _environment, char * _timing ) {
1435
1437
1438 outline1("LDA %s", _timing );
1439 outline0("STA TMPPTR");
1440 outline1("LDA %s+1", _timing );
1441 outline0("STA TMPPTR+1");
1442 outhead1("%sfirst:", label );
1443 outline0("LDA $01");
1444 outhead1("%ssecond:", label );
1445 outline0("CMP $D012");
1446 outline1("BNE %ssecond", label);
1447 outhead1("%sthird:", label );
1448 outline0("CMP $D012");
1449 outline1("BEQ %sthird", label);
1450 outline0("DEC TMPPTR");
1451 outline0("LDA TMPPTR");
1452 outline0("CMP #$FF");
1453 outline1("BNE %sfirst", label);
1454 outline0("DEC TMPPTR+1");
1455 outline0("LDA TMPPTR+1");
1456 outline0("CMP #$FF");
1457 outline1("BNE %sfirst", label);
1458
1459}
1460
1461void vic2z_get_width( Environment * _environment, char *_result ) {
1462
1463 outline0("LDA CURRENTWIDTH" );
1464 outline1("STA %s", _result );
1465 outline0("LDA CURRENTWIDTH+1" );
1466 outline1("STA %s+1", _result );
1467
1468}
1469
1470void vic2z_tiles_get( Environment * _environment, char *_result ) {
1471
1472 outline0("LDA CURRENTTILES" );
1473 outline1("STA %s", _result );
1474
1475}
1476
1477void vic2z_get_height( Environment * _environment, char *_result ) {
1478
1479 outline0("LDA CURRENTHEIGHT" );
1480 outline1("STA %s", _result );
1481 outline0("LDA CURRENTHEIGHT+1" );
1482 outline1("STA %s+1", _result );
1483
1484}
1485
1486void vic2z_cls( Environment * _environment ) {
1487
1488 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
1489 deploy( clsGraphic, src_hw_vic2z_cls_graphic_asm );
1490 outline0("JSR CLSG");
1491 } else {
1492 deploy( clsText, src_hw_vic2z_cls_text_asm );
1493 outline0("JSR CLST");
1494 }
1495
1496}
1497
1498void vic2z_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
1499
1500}
1501
1502void vic2z_scroll_text( Environment * _environment, int _direction ) {
1503
1504 if ( _direction > 0 ) {
1505 deploy( vScrollTextDown, src_hw_vic2z_vscroll_text_down_asm );
1506 outline0("JSR VSCROLLTDOWN");
1507 } else {
1508 deploy( vScrollTextUp, src_hw_vic2z_vscroll_text_up_asm );
1509 outline0("JSR VSCROLLTUP");
1510 }
1511
1512}
1513
1514void vic2z_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
1515
1516 deploy( vic2zvars, src_hw_vic2z_vars_asm);
1517 deploy( vScrollTextUp, src_hw_vic2z_vscroll_text_up_asm );
1518 deploy( textEncodedAt, src_hw_vic2z_text_at_asm );
1519
1520 outline1("LDA %s", _text);
1521 outline0("STA TEXTPTR" );
1522 outline1("LDA %s+1", _text);
1523 outline0("STA TEXTPTR+1" );
1524 outline1("LDA %s", _text_size);
1525 outline0("STA TEXTSIZE" );
1526
1527 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
1528 deploy( clsGraphic, src_hw_vic2z_cls_graphic_asm );
1529 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1530 deploy_deferred( textEncodedAtGraphic, src_hw_vic2z_text_at_graphic_asm );
1531 outline0("JSR TEXTATBITMAPMODE");
1532 } else {
1533 deploy( clsText, src_hw_vic2z_cls_text_asm );
1534 deploy_deferred( textEncodedAtText, src_hw_vic2z_text_at_text_asm );
1535 outline0("JSR TEXTATTILEMODE");
1536 }
1537
1538}
1539
1540void vic2z_initialization( Environment * _environment ) {
1541
1542 deploy( vic2zvars, src_hw_vic2z_vars_asm );
1543 deploy( vic2zstartup, src_hw_vic2z_startup_asm );
1544
1545 variable_import( _environment, "CURRENTMODE", VT_BYTE, 0 );
1546 variable_global( _environment, "CURRENTMODE" );
1547 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
1548 variable_global( _environment, "CURRENTTILEMODE" );
1549
1550 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 320 );
1551 variable_global( _environment, "CURRENTWIDTH" );
1552 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 200 );
1553 variable_global( _environment, "CURRENTHEIGHT" );
1554 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
1555 variable_global( _environment, "CURRENTTILES" );
1556 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 40 );
1557 variable_global( _environment, "CURRENTTILESWIDTH" );
1558 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 25 );
1559 variable_global( _environment, "CURRENTTILESHEIGHT" );
1560 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
1561 variable_global( _environment, "FONTWIDTH" );
1562 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
1563 variable_global( _environment, "FONTHEIGHT" );
1564
1565 SCREEN_MODE_DEFINE( BITMAP_MODE_STANDARD, 1, 320, 200, 2, 8, 8, "Standard Bitmap Mode" );
1566 SCREEN_MODE_DEFINE( BITMAP_MODE_MULTICOLOR, 1, 160, 200, 4, 8, 8, "Multicolor Bitmap Mode" );
1567 SCREEN_MODE_DEFINE( TILEMAP_MODE_STANDARD, 0, 40, 25, 2, 8, 8, "Standard Character Mode" );
1568 SCREEN_MODE_DEFINE( TILEMAP_MODE_MULTICOLOR, 0, 40, 25, 16, 8, 8, "Multicolor Character Mode" );
1569 SCREEN_MODE_DEFINE( TILEMAP_MODE_EXTENDED, 0, 40, 25, 20, 8, 8, "Extended Multicolor Character Mode" );
1570
1571 outline0("JSR VIC2ZSTARTUP");
1572
1573 variable_import( _environment, "XGR", VT_POSITION, 0 );
1574 variable_global( _environment, "XGR" );
1575 variable_import( _environment, "YGR", VT_POSITION, 0 );
1576 variable_global( _environment, "YGR" );
1577 variable_import( _environment, "LINE", VT_WORD, (unsigned short) (0xffff) );
1578 variable_global( _environment, "LINE" );
1579 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
1580 variable_global( _environment, "TABCOUNT" );
1581
1582 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
1583 variable_global( _environment, "CLIPX1" );
1584 variable_import( _environment, "CLIPX2", VT_POSITION, 319 );
1585 variable_global( _environment, "CLIPX2" );
1586 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
1587 variable_global( _environment, "CLIPY1" );
1588 variable_import( _environment, "CLIPY2", VT_POSITION, 199 );
1589 variable_global( _environment, "CLIPY2" );
1590
1591 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
1592 variable_global( _environment, "ORIGINX" );
1593 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
1594 variable_global( _environment, "ORIGINY" );
1595
1596 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
1597 variable_global( _environment, "RESOLUTIONX" );
1598 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
1599 variable_global( _environment, "RESOLUTIONY" );
1600
1601 variable_import( _environment, "XSCROLLPOS", VT_BYTE, 4 );
1602 variable_global( _environment, "XSCROLLPOS" );
1603 variable_import( _environment, "YSCROLLPOS", VT_BYTE, 4 );
1604 variable_global( _environment, "YSCROLLPOS" );
1605 variable_import( _environment, "XSCROLL", VT_BYTE, 0 );
1606 variable_global( _environment, "XSCROLL" );
1607 variable_import( _environment, "YSCROLL", VT_BYTE, 0 );
1608 variable_global( _environment, "YSCROLL" );
1609
1610 variable_import( _environment, "SPRITECOUNT", VT_SPRITE, 0 );
1611 variable_global( _environment, "SPRITECOUNT" );
1612
1613 _environment->fontWidth = 8;
1614 _environment->fontHeight = 8;
1615 _environment->screenTilesWidth = 40;
1616 _environment->screenTilesHeight = 25;
1617 _environment->screenWidth = _environment->screenTilesWidth * 8;
1618 _environment->screenHeight = _environment->screenTilesHeight * 8;
1619
1620 font_descriptors_init( _environment, 1 );
1621
1622 _environment->currentRgbConverterFunction = rgbConverterFunction;
1623 _environment->screenShades = 16;
1624
1625 outline0("JSR VIC2ZFINALIZATION");
1626
1627 if (_environment->vestigialConfig.clsImplicit ) {
1628 vic2z_cls( _environment );
1629 }
1630
1631}
1632
1633static RGBi * multicolorSpritePalette[2];
1634
1635void vic2z_finalization( Environment * _environment ) {
1636
1637 outhead0("VIC2ZFINALIZATION:");
1638
1639 if ( multicolorSpritePalette[0] ) {
1640 outline1("LDA #$%2.2x", multicolorSpritePalette[0]->index );
1641 outline0("STA $D025" );
1642 }
1643
1644 if ( multicolorSpritePalette[1] ) {
1645 outline1("LDA #$%2.2x", multicolorSpritePalette[1]->index );
1646 outline0("STA $D026" );
1647 }
1648
1649 outline0("RTS");
1650
1651}
1652
1653void vic2z_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
1654
1655 deploy( textHScroll, src_hw_vic2z_hscroll_text_asm );
1656
1657 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1658 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1659 outline0("STA DIRECTION" );
1660 outline1("LDA %s", y->realName );
1661 outline0("STA CLINEY");
1662
1663 outline0("JSR HSCROLLLT");
1664
1665}
1666
1667void vic2z_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
1668
1669 deploy( textHScroll, src_hw_vic2z_hscroll_text_asm );
1670
1671 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1672 outline0("STA DIRECTION" );
1673
1674 outline0("JSR HSCROLLST");
1675}
1676
1677void vic2z_back( Environment * _environment ) {
1678
1679 deploy( back, src_hw_vic2z_back_asm );
1680
1681 outline0("JSR BACK");
1682
1683}
1684
1685void vic2z_cline( Environment * _environment, char * _characters ) {
1686
1687 deploy( textCline, src_hw_vic2z_cline_asm );
1688 Variable * x = variable_retrieve( _environment, "XCURSYS" );
1689 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1690
1691 if ( _characters ) {
1692 outline1("LDA %s", _characters);
1693 } else {
1694 outline0("LDA #0");
1695 }
1696 outline0("STA CHARACTERS");
1697 outline1("LDA %s", x->realName );
1698 outline0("STA CLINEX" );
1699 outline1("LDA %s", y->realName );
1700 outline0("STA CLINEY");
1701 outline0("JSR CLINE");
1702
1703}
1704
1705static int calculate_image_size( Environment * _environment, int _width, int _height, int _mode ) {
1706
1707 switch( _mode ) {
1708
1710
1711 return 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) );
1712
1714
1715 return 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1;
1716
1717 case BITMAP_MODE_AH:
1718 case BITMAP_MODE_AIFLI:
1720 case BITMAP_MODE_ECI:
1721 case BITMAP_MODE_IAFLI:
1722 case BITMAP_MODE_IH:
1723 case BITMAP_MODE_MRFLI:
1725 case BITMAP_MODE_MUCSUH:
1726 case BITMAP_MODE_MUFLI:
1727 case BITMAP_MODE_MUIFLI:
1728 case BITMAP_MODE_NUFLI:
1729 case BITMAP_MODE_NUIFLI:
1730 case BITMAP_MODE_SH:
1731 case BITMAP_MODE_SHFLI:
1732 case BITMAP_MODE_SHI:
1733 case BITMAP_MODE_SHIFLI:
1734 case BITMAP_MODE_SHIFXL:
1735 case BITMAP_MODE_UFLI:
1736 case BITMAP_MODE_UIFLI:
1737 case BITMAP_MODE_TRIFLI:
1738 case BITMAP_MODE_XFLI:
1739 case BITMAP_MODE_XIFLI:
1740 case BITMAP_MODE_FLI:
1741 case BITMAP_MODE_HCB:
1742 case BITMAP_MODE_IFLI:
1743 case BITMAP_MODE_MUCSU:
1744 case BITMAP_MODE_MCI:
1746 case BITMAP_MODE_PRS:
1750 break;
1751 }
1752
1753 return 0;
1754
1755}
1756
1757static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1758
1759 switch( _mode ) {
1760
1762
1763 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) * _frames;
1764
1766
1767 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1 ) * _frames;
1768
1769 case BITMAP_MODE_AH:
1770 case BITMAP_MODE_AIFLI:
1772 case BITMAP_MODE_ECI:
1773 case BITMAP_MODE_IAFLI:
1774 case BITMAP_MODE_IH:
1775 case BITMAP_MODE_MRFLI:
1777 case BITMAP_MODE_MUCSUH:
1778 case BITMAP_MODE_MUFLI:
1779 case BITMAP_MODE_MUIFLI:
1780 case BITMAP_MODE_NUFLI:
1781 case BITMAP_MODE_NUIFLI:
1782 case BITMAP_MODE_SH:
1783 case BITMAP_MODE_SHFLI:
1784 case BITMAP_MODE_SHI:
1785 case BITMAP_MODE_SHIFLI:
1786 case BITMAP_MODE_SHIFXL:
1787 case BITMAP_MODE_UFLI:
1788 case BITMAP_MODE_UIFLI:
1789 case BITMAP_MODE_TRIFLI:
1790 case BITMAP_MODE_XFLI:
1791 case BITMAP_MODE_XIFLI:
1792 case BITMAP_MODE_FLI:
1793 case BITMAP_MODE_HCB:
1794 case BITMAP_MODE_IFLI:
1795 case BITMAP_MODE_MUCSU:
1796 case BITMAP_MODE_MCI:
1798 case BITMAP_MODE_PRS:
1802 break;
1803 }
1804
1805 return 0;
1806
1807}
1808
1809static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1810
1811 switch( _mode ) {
1812
1814
1815 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) * _frames ) * _sequences;
1816
1818
1819 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1 ) * _frames ) * _sequences;
1820
1821 case BITMAP_MODE_AH:
1822 case BITMAP_MODE_AIFLI:
1824 case BITMAP_MODE_ECI:
1825 case BITMAP_MODE_IAFLI:
1826 case BITMAP_MODE_IH:
1827 case BITMAP_MODE_MRFLI:
1829 case BITMAP_MODE_MUCSUH:
1830 case BITMAP_MODE_MUFLI:
1831 case BITMAP_MODE_MUIFLI:
1832 case BITMAP_MODE_NUFLI:
1833 case BITMAP_MODE_NUIFLI:
1834 case BITMAP_MODE_SH:
1835 case BITMAP_MODE_SHFLI:
1836 case BITMAP_MODE_SHI:
1837 case BITMAP_MODE_SHIFLI:
1838 case BITMAP_MODE_SHIFXL:
1839 case BITMAP_MODE_UFLI:
1840 case BITMAP_MODE_UIFLI:
1841 case BITMAP_MODE_TRIFLI:
1842 case BITMAP_MODE_XFLI:
1843 case BITMAP_MODE_XIFLI:
1844 case BITMAP_MODE_FLI:
1845 case BITMAP_MODE_HCB:
1846 case BITMAP_MODE_IFLI:
1847 case BITMAP_MODE_MUCSU:
1848 case BITMAP_MODE_MCI:
1850 case BITMAP_MODE_PRS:
1854 break;
1855 }
1856
1857 return 0;
1858
1859}
1860
1861static Variable * vic2z_image_converter_bitmap_mode_standard( Environment * _environment, char * _source, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _transparent_color, int _flags ) {
1862
1863 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
1864
1865 if ( _environment->freeImageWidth ) {
1866 if ( _width % 8 ) {
1867 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1868 }
1869 if ( _frame_width % 8 ) {
1870 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1871 }
1872 }
1873
1874 if ( _environment->freeImageHeight ) {
1875 if ( _height % 8 ) {
1876 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
1877 }
1878 if ( _frame_height % 8 ) {
1879 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
1880 }
1881 }
1882
1883 RGBi * palette = malloc_palette( MAX_PALETTE );
1884
1885 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1886
1887 if (paletteColorCount > 16) {
1888 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1889 }
1890
1891 int i, j, k;
1892
1893 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1894 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1895 lastUsedSlotInCommonPalette = paletteColorCount;
1896 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1897
1898 adilinepalette( "CPMS:%ld", sizeof(SYSTEM_PALETTE) / sizeof(RGBi), SYSTEM_PALETTE );
1899
1900 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1902 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1903
1904 int bufferSize = calculate_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_STANDARD );
1905
1906 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_STANDARD );
1907
1908 // printf("bufferSize = %d\n", bufferSize );
1909
1910 char * buffer = malloc ( bufferSize );
1911 memset( buffer, 0, bufferSize );
1912
1913 // Position of the pixel in the original image
1914 int image_x, image_y;
1915
1916 // Position of the pixel, in terms of tiles
1917 int tile_x, tile_y;
1918
1919 // Position of the pixel, in terms of offset and bitmask
1920 int offset, bitmask;
1921
1922 // Color of the pixel to convert
1923 RGBi rgb;
1924
1925 *(buffer) = ( _frame_width & 0xff );
1926 *(buffer+1) = ( (_frame_width>>8) & 0xff );
1927 *(buffer+2) = _frame_height;
1928
1929 _source += ( ( _offset_y * _width ) + _offset_x ) * 3;
1930
1931 vic2z_image_converter_tiles( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width );
1932
1933 // printf("----\n");
1934
1935 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1936
1937 // printf("----\n");
1938
1939 return result;
1940
1941}
1942
1943static Variable * vic2z_image_converter_multicolor_mode_standard( Environment * _environment, char * _source, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _transparent_color, int _flags ) {
1944
1945 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
1946
1947 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
1948
1949 if ( _environment->freeImageWidth ) {
1950 if ( _width % 8 ) {
1951 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1952 }
1953 if ( _frame_width % 8 ) {
1954 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1955 }
1956 }
1957
1958 if ( _environment->freeImageHeight ) {
1959 if ( _height % 8 ) {
1960 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
1961 }
1962 if ( _frame_height % 8 ) {
1963 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
1964 }
1965 }
1966
1967 RGBi * palette = malloc_palette( MAX_PALETTE );
1968
1969 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1970
1971 if (paletteColorCount > 16) {
1972 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1973 }
1974
1975 int i, j, k;
1976
1977 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1978 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1979 lastUsedSlotInCommonPalette = paletteColorCount;
1980 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1981
1982 adilinepalette( "CPMS:%ld", sizeof(SYSTEM_PALETTE) / sizeof(RGBi), SYSTEM_PALETTE );
1983
1984 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1986 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1987
1988 int bufferSize = calculate_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_MULTICOLOR );
1989
1990 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_MULTICOLOR );
1991
1992 char * buffer = malloc ( bufferSize );
1993 memset( buffer, 0, bufferSize );
1994
1995 // Position of the pixel in the original image
1996 int image_x, image_y;
1997
1998 // Position of the pixel, in terms of tiles
1999 int tile_x, tile_y;
2000
2001 // Position of the pixel, in terms of offset and bitmask
2002 int offset, offsetc, bitmask;
2003
2004 // Color of the pixel to convert
2005 RGBi rgb;
2006
2007 *(buffer) = ( _frame_width & 0xff );
2008 *(buffer+1) = ( _frame_width >> 8 ) & 0xff;
2009 *(buffer+2) = _frame_height;
2010
2011 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2012
2013 vic2z_image_converter_tiles_multicolor( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width, palette[0].index );
2014
2015 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2016
2017 return result;
2018
2019}
2020
2021static Variable * vic2z_image_converter_tilemap_mode_standard( Environment * _environment, char * _source, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _transparent_color, int _flags ) {
2022
2023 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
2024
2025 if ( _environment->freeImageWidth ) {
2026 if ( _width % 8 ) {
2027 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2028 }
2029 if ( _frame_width % 8 ) {
2030 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2031 }
2032 }
2033
2034 if ( _environment->freeImageHeight ) {
2035 if ( _height % 8 ) {
2036 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
2037 }
2038 if ( _frame_height % 8 ) {
2039 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
2040 }
2041 }
2042
2043 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2044
2045 RGBi palette[MAX_PALETTE];
2046
2047 int colorUsed = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, 1 /* sorted */ );
2048
2049 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2050 result->originalColors = colorUsed;
2051
2052 int i, j, k;
2053
2054 for( i=0; i<colorUsed; ++i ) {
2055 int minDistance = 0xffff;
2056 int colorIndex = 0;
2057 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
2058 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &palette[i]);
2059 // printf("%d <-> %d [%d] = %d [min = %d]\n", i, j, SYSTEM_PALETTE[j].index, distance, minDistance );
2060 if (distance < minDistance) {
2061 // printf(" candidated...\n" );
2062 for( k=0; k<i; ++k ) {
2063 if ( palette[k].index == SYSTEM_PALETTE[j].index ) {
2064 // printf(" ...used!\n" );
2065 break;
2066 }
2067 }
2068 if ( k>=i ) {
2069 // printf(" ...ok! (%d)\n", SYSTEM_PALETTE[j].index );
2070 minDistance = distance;
2071 colorIndex = j;
2072 }
2073 }
2074 }
2075 palette[i].index = SYSTEM_PALETTE[colorIndex].index;
2076 strcopy( palette[i].description, SYSTEM_PALETTE[colorIndex].description );
2077 // printf("%d) %d %2.2x%2.2x%2.2x\n", i, palette[i].index, palette[i].red, palette[i].green, palette[i].blue);
2078 }
2079
2080 memcpy( result->originalPalette, palette, MAX_PALETTE * sizeof( RGBi ) );
2081
2082 int bufferSize;
2083
2084 if ( colorUsed == 2 ) {
2085 bufferSize = 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) + 1;
2086 } else {
2087 bufferSize = 3 + 2* ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) );
2088 }
2089
2090 // printf("bufferSize = %d\n", bufferSize );
2091
2092 char * buffer = malloc ( bufferSize );
2093 memset( buffer, 0, bufferSize );
2094
2095 // Position of the pixel in the original image
2096 int image_x, image_y;
2097
2098 // Position of the pixel, in terms of tiles
2099 int tile_x, tile_y;
2100
2101 // Position of the pixel, in terms of offset and bitmask
2102 int offset, bitmask;
2103
2104 // Color of the pixel to convert
2105 RGBi rgb;
2106
2107 *(buffer) = _frame_width;
2108 *(buffer+1) = _frame_height;
2109
2110 if ( colorUsed > 2 ) {
2111 *(buffer+2) = 1;
2112 } else {
2113 *(buffer+2) = 0;
2114 }
2115
2116 int cx=0,cy=0;
2117
2118 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2119
2120 // commonTileDescriptors = precalculate_tile_descriptors_for_font( data_fontvic1_bin );
2121
2122 for( cy=0; cy<(_frame_height >> 3);++cy) {
2123 for( cx=0; cx<(_frame_width >> 3);++cx) {
2124
2125 char *source = _source + ( ( cy * 8 * _width ) + cx * 8 ) * _depth;
2126
2127 TileData tileData;
2128 memset(&tileData,0,sizeof(TileData));
2129
2130 int mostFrequentColor[16];
2131 memset(&mostFrequentColor[0],0,sizeof(int)*16);
2132
2133 int colorIndex = 0;
2134
2135 // Loop for all the source surface.
2136 for (image_y = 0; image_y < 8; ++image_y) {
2137 for (image_x = 0; image_x < 8; ++image_x) {
2138
2139 // Take the color of the pixel
2140 rgb.red = *source;
2141 rgb.green = *(source + 1);
2142 rgb.blue = *(source + 2);
2143 if ( _depth > 3 ) {
2144 rgb.alpha = *(_source + 3);
2145 } else {
2146 rgb.alpha = 255;
2147 }
2148
2149 if ( rgb.alpha < 255 ) {
2150 colorIndex = palette[0].index;
2151 } else {
2152
2153 int minDistance = 9999;
2154 for( int i=0; i<colorUsed; ++i ) {
2155 int distance = rgbi_distance(&palette[i], &rgb );
2156 if ( distance < minDistance ) {
2157 minDistance = distance;
2158 colorIndex = palette[i].index;
2159 }
2160 }
2161
2162 }
2163
2164 // printf("%d", i );
2165
2166 // Calculate the relative tile
2167
2168 // Calculate the offset starting from the tile surface area
2169 // and the bit to set.
2170 offset = (image_y & 0x07);
2171 bitmask = 1 << ( 7 - (image_x & 0x7) );
2172
2173 if (colorUsed == 2 ) {
2174 if ( colorIndex ) {
2175 tileData.data[offset] &= ~bitmask;
2176 // printf("%1.1x", colorIndex );
2177 } else {
2178 tileData.data[offset] |= bitmask;
2179 // printf("%1.1x", colorIndex );
2180 }
2181 } else {
2182 if ( colorIndex ) {
2183 mostFrequentColor[colorIndex]++;
2184 tileData.data[offset] &= ~bitmask;
2185 // printf("%1.1x", colorIndex );
2186 } else {
2187 tileData.data[offset] |= bitmask;
2188 // printf("%1.1x", colorIndex );
2189 }
2190 }
2191
2192 source += _depth;
2193
2194 }
2195
2196 source += _depth * ( _width - 8 );
2197
2198 // printf("\n" );
2199
2200 }
2201
2202 // printf("\n" );
2203
2204 TileDescriptor * t = calculate_tile_descriptor( &tileData );
2205
2206 if ( ! _environment->descriptors ) {
2208 _environment->descriptors->first = 0;
2209 _environment->descriptors->firstFree = ( (data_font_alpha_bin_len / 8) );
2210 _environment->descriptors->lastFree = 255;
2211 _environment->descriptors->count = _environment->descriptors->firstFree;
2212 }
2213
2214 int tile = calculate_exact_tile( t, _environment->descriptors );
2215
2216 if ( tile == -1 ) {
2217 if ( _environment->descriptors->count < 128 ) {
2218 tile = 0x5e + (_environment->descriptors->count++);
2219 _environment->descriptors->descriptor[tile] = t;
2220 memcpy( &_environment->descriptors->data[tile], &tileData, sizeof( TileData ) );
2221 } else {
2222 tile = calculate_nearest_tile( t, _environment->descriptors );
2223 }
2224 // printf("*** tile = %d\n", tile );
2225 } else {
2226 // printf(" tile = %d\n", tile );
2227 }
2228
2229 *(buffer + 3 + (cy * ( _frame_width >> 3 ) ) + cx ) = tile;
2230 if ( colorUsed > 2 ) {
2231 int mostFrequentColorIndex = 1;
2232 int mostFrequentColorCount = 0;
2233 for(i=0;i<colorUsed;++i) {
2234 if ( mostFrequentColorCount < mostFrequentColor[palette[i].index] ) {
2235 mostFrequentColorCount = mostFrequentColor[palette[i].index];
2236 mostFrequentColorIndex = palette[i].index;
2237 }
2238 }
2239 // printf( "c = %1.1x\n", mostFrequentColorIndex );
2240 *(buffer + 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) + (cy * ( _frame_width >> 3 ) ) + cx ) = ( ( mostFrequentColorIndex & 0x07 ) );
2241 }
2242
2243 // printf("\ntile: %2.2x\n", tile );
2244
2245 }
2246 // printf("\n");
2247 }
2248
2249 if ( colorUsed <= 2 ) {
2250 *(buffer + 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) ) = palette[0].index == 0 ? palette[1].index : palette[0].index;
2251 }
2252 // printf("----\n");
2253
2254 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2255
2256 // printf("----\n");
2257
2258 return result;
2259
2260}
2261
2262Variable * vic2z_image_converter( Environment * _environment, char * _data, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _mode, int _transparent_color, int _flags ) {
2263
2264 switch( _mode ) {
2265
2267
2268 return vic2z_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2269
2271
2272 return vic2z_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2273
2274 case BITMAP_MODE_AH:
2275 case BITMAP_MODE_AIFLI:
2277 case BITMAP_MODE_ECI:
2278 case BITMAP_MODE_IAFLI:
2279 case BITMAP_MODE_IH:
2280 case BITMAP_MODE_MRFLI:
2282 case BITMAP_MODE_MUCSUH:
2283 case BITMAP_MODE_MUFLI:
2284 case BITMAP_MODE_MUIFLI:
2285 case BITMAP_MODE_NUFLI:
2286 case BITMAP_MODE_NUIFLI:
2287 case BITMAP_MODE_SH:
2288 case BITMAP_MODE_SHFLI:
2289 case BITMAP_MODE_SHI:
2290 case BITMAP_MODE_SHIFLI:
2291 case BITMAP_MODE_SHIFXL:
2292 case BITMAP_MODE_UFLI:
2293 case BITMAP_MODE_UIFLI:
2294 case BITMAP_MODE_TRIFLI:
2295 case BITMAP_MODE_XFLI:
2296 case BITMAP_MODE_XIFLI:
2297 case BITMAP_MODE_FLI:
2298 case BITMAP_MODE_HCB:
2299 case BITMAP_MODE_IFLI:
2300 case BITMAP_MODE_MUCSU:
2301 case BITMAP_MODE_MCI:
2303 case BITMAP_MODE_PRS:
2305 return vic2z_image_converter_tilemap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2308 break;
2309 }
2310
2312
2313 return vic2z_new_image( _environment, 8, 8, BITMAP_MODE_STANDARD );
2314
2315}
2316
2317Variable * vic2z_sprite_converter( Environment * _environment, char * _source, int _width, int _height, int _depth, RGBi * _color, int _flags ) {
2318
2319 RGBi palette[MAX_PALETTE];
2320
2321 int colorUsed = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, 1 /* sorted */ );
2322
2323 if ( ! _color ) {
2324
2325 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
2326 if (colorUsed > 4) {
2328 }
2329 } else {
2330 if (colorUsed > 2) {
2332 }
2333 }
2334
2335 }
2336
2337 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2338 result->originalColors = colorUsed;
2339
2340 int i, j, k;
2341
2342 for( i=0; i<colorUsed; ++i ) {
2343 int minDistance = 0xffff;
2344 int colorIndex = 0;
2345 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
2346 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &palette[i]);
2347 // printf("%d <-> %d [%d] = %d [min = %d]\n", i, j, SYSTEM_PALETTE[j].index, distance, minDistance );
2348 if (distance < minDistance) {
2349 // printf(" candidated...\n" );
2350 for( k=0; k<i; ++k ) {
2351 if ( palette[k].index == SYSTEM_PALETTE[j].index ) {
2352 // printf(" ...used!\n" );
2353 break;
2354 }
2355 }
2356 if ( k>=i ) {
2357 // printf(" ...ok! (%d)\n", SYSTEM_PALETTE[j].index );
2358 minDistance = distance;
2359 colorIndex = j;
2360 }
2361 }
2362 }
2363 palette[i].index = SYSTEM_PALETTE[colorIndex].index;
2364 strcopy( palette[i].description, SYSTEM_PALETTE[colorIndex].description );
2365 // printf("%d) %d %2.2x%2.2x%2.2x\n", i, palette[i].index, palette[i].red, palette[i].green, palette[i].blue);
2366 }
2367
2368 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
2369
2370 // printf("PALETTE 0: %d\n", palette[0].index );
2371 // printf("PALETTE 1: %d %2.2x%2.2x%2.2x\n", palette[1].index, palette[1].red, palette[1].green, palette[1].blue );
2372 // printf("PALETTE 2: %d\n", palette[2].index );
2373 // printf("PALETTE 3: %d\n", palette[3].index );
2374
2375 if ( palette[0].index == SYSTEM_PALETTE[0].index ) {
2376
2377 } else {
2378 rgbi_move( &palette[2], &palette[3] );
2379 rgbi_move( &palette[1], &palette[2] );
2380 rgbi_move( &palette[0], &palette[1] );
2381 rgbi_move( &SYSTEM_PALETTE[0], &palette[0] );
2382 }
2383
2384 // printf("PALETTE 0: %d\n", palette[0].index );
2385 // printf("PALETTE 1: %d %2.2x%2.2x%2.2x\n", palette[1].index, palette[1].red, palette[1].green, palette[1].blue );
2386 // printf("PALETTE 2: %d\n", palette[2].index );
2387 // printf("PALETTE 3: %d\n", palette[3].index );
2388
2389 // printf("Color used = %d\n", colorUsed);
2390
2391 // printf("Decoding multicolor sprite color #0\n");
2392
2393 if ( !multicolorSpritePalette[0] ) {
2394 // printf("Initializing with color 1 (%d)\n", palette[1].index );
2395 multicolorSpritePalette[0] = malloc( sizeof( RGBi ) );
2396 memset( multicolorSpritePalette[0], 0, sizeof( RGBi ) );
2397 rgbi_move( &palette[1], multicolorSpritePalette[0] );
2398 }
2399
2400 // printf("Decoding multicolor sprite color #1\n");
2401
2402 if ( !multicolorSpritePalette[1] ) {
2403 // printf("Initializing with color 2 (%d)\n", palette[2].index );
2404 multicolorSpritePalette[1] = malloc( sizeof( RGBi ) );
2405 memset( multicolorSpritePalette[1], 0, sizeof( RGBi ) );
2406 rgbi_move( &palette[2], multicolorSpritePalette[1] );
2407 }
2408
2409 RGBi temporaryPalette[MAX_PALETTE];
2410 memset( temporaryPalette, 0, sizeof( RGBi ) * MAX_PALETTE );
2411
2412 rgbi_move( &SYSTEM_PALETTE[0], &temporaryPalette[0] );
2413
2414 for( int i=1; i<colorUsed; ++i ) {
2415 if ( rgbi_equals_rgba( &palette[i], multicolorSpritePalette[0] ) ) {
2416 // printf("%d) Color #%d == sprite palette 0\n", i, palette[i].index );
2417 rgbi_move( &palette[i], &temporaryPalette[1] );
2418 } else if ( rgbi_equals_rgba( &palette[i], multicolorSpritePalette[1] ) ) {
2419 // printf("%d) Color #%d == sprite palette 1\n", i, palette[i].index );
2420 rgbi_move( &palette[i], &temporaryPalette[3] );
2421 } else {
2422 // printf("%d) Color #%d == sprite custom\n", i, palette[i].index );
2423 rgbi_move( &palette[i], &temporaryPalette[2] );
2424 }
2425 }
2426
2427 rgbi_move( &temporaryPalette[0], &palette[0] );
2428 // printf("PALETTE 0: %d\n", palette[0].index );
2429 rgbi_move( &temporaryPalette[1], &palette[1] );
2430 // printf("PALETTE 1: %d\n", palette[1].index );
2431 rgbi_move( &temporaryPalette[2], &palette[2] );
2432 // printf("PALETTE 2: %d\n", palette[2].index );
2433 rgbi_move( &temporaryPalette[3], &palette[3] );
2434 // printf("PALETTE 3: %d\n", palette[3].index );
2435
2436 }
2437
2438 memcpy( result->originalPalette, palette, MAX_PALETTE * sizeof( RGBi ) );
2439
2440 int bufferSize = 64;
2441
2442 // printf("bufferSize = %d\n", bufferSize );
2443
2444 char * buffer = malloc ( bufferSize );
2445 memset( buffer, 0, bufferSize );
2446
2447 // Position of the pixel in the original image
2448 int image_x, image_y;
2449
2450 // Position of the pixel, in terms of offset and bitmask
2451 int offset, bitmask;
2452
2453 // Color of the pixel to convert
2454 RGBi rgb;
2455
2456 // Loop for all the source surface.
2457 for (image_y = 0; image_y < _height; ++image_y) {
2458 if ( image_y == 21 ) {
2459 break;
2460 }
2461 for (image_x = 0; image_x < _width; ++image_x) {
2462
2463 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
2464 if ( image_x == 12 ) {
2465 break;
2466 }
2467 } else {
2468 if ( image_x == 24 ) {
2469 break;
2470 }
2471 }
2472
2473 // Take the color of the pixel
2474 rgb.red = *_source;
2475 rgb.green = *(_source + 1);
2476 rgb.blue = *(_source + 2);
2477 if ( _depth > 3 ) {
2478 rgb.alpha = *(_source + 3);
2479 } else {
2480 rgb.alpha = 255;
2481 }
2482
2483 if ( rgb.alpha < 255 ) {
2484 i = 0;
2485 } else {
2486
2487 if ( ! _color ) {
2488 for( i=0; i<colorUsed; ++i ) {
2489 // printf( "%d) %2.2x%2.2x%2.2x == %2.2x%2.2x%2.2x\n", i, palette[i].red, palette[i].green, palette[i].blue, rgb.red, rgb.green, rgb.blue );
2490 if ( rgbi_equals_rgba( &palette[i], &rgb ) ) {
2491 break;
2492 }
2493 }
2494 } else {
2495 if ( rgbi_equals_rgba( _color, &rgb ) ) {
2496 i = 1;
2497 } else {
2498 i = 0;
2499 }
2500 }
2501
2502 }
2503
2504 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
2505
2506 // Calculate the offset starting from the tile surface area
2507 // and the bit to set.
2508 offset = ( image_y * 3 ) + (image_x >> 2);
2509 bitmask = i << (6 - ((image_x & 0x3) * 2));
2510
2511 if ( i > 0 ) {
2512 *( buffer + offset) |= bitmask;
2513 // printf("%1.1x", i );
2514 } else {
2515 *( buffer + offset) &= ~bitmask;
2516 // printf("%1.1x", i );
2517 }
2518
2519 } else {
2520
2521 // Calculate the offset starting from the tile surface area
2522 // and the bit to set.
2523 offset = ( image_y * 3 ) + (image_x >> 3);
2524 bitmask = 1 << ( 7 - (image_x & 0x7) );
2525
2526 if ( i == 1 ) {
2527 *( buffer + offset) |= bitmask;
2528 // printf("*");
2529 } else {
2530 *( buffer + offset) &= ~bitmask;
2531 // printf(" ");
2532 }
2533
2534 }
2535
2536 _source += 3;
2537
2538 }
2539
2540 // printf("\n");
2541 _source += 3 * ( _width - image_x );
2542
2543 // printf("\n" );
2544
2545 }
2546
2547 if ( _color ) {
2548 *(buffer+63) = _color->index;
2549 } else {
2550 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
2551 *(buffer+63) = palette[3].index;
2552 } else {
2553 *(buffer+63) = palette[1].index;
2554 }
2555 }
2556
2557 // printf("\n----\n");
2558
2559 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2560
2561 // printf("----\n");
2562
2563 return result;
2564
2565}
2566
2567void vic2z_put_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
2568
2569 deploy( vic2zvars, src_hw_vic2z_vars_asm);
2570 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2571 deploy( putimage, src_hw_vic2z_put_image_asm );
2572
2574
2575 outhead1("putimage%s:", label);
2576 outline1("LDA #<%s", _image );
2577 outline0("STA TMPPTR" );
2578 outline1("LDA #>%s", _image );
2579 outline0("STA TMPPTR+1" );
2580
2581 if ( _sequence ) {
2582
2583 outline0("CLC" );
2584 outline0("LDA TMPPTR" );
2585 outline0("ADC #3" );
2586 outline0("STA TMPPTR" );
2587 outline0("LDA TMPPTR+1" );
2588 outline0("ADC #0" );
2589 outline0("STA TMPPTR+1" );
2590 if ( strlen(_sequence) == 0 ) {
2591
2592 } else {
2593 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
2594 outline0("STA TMPPTR2" );
2595 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
2596 outline0("STA TMPPTR2+1" );
2597 outline0("CLC" );
2598 outline1("LDA %s", _sequence );
2599 outline0("ASL" );
2600 outline0("TAY" );
2601 outline0("LDA TMPPTR" );
2602 outline0("ADC (TMPPTR2), Y" );
2603 outline0("STA TMPPTR" );
2604 outline0("INY" );
2605 outline0("LDA TMPPTR+1" );
2606 outline0("ADC (TMPPTR2), Y" );
2607 outline0("STA TMPPTR+1" );
2608 }
2609
2610 if ( _frame ) {
2611 if ( strlen(_frame) == 0 ) {
2612
2613 } else {
2614 outline1("LDA #<OFFSETS%4.4x", _frame_size );
2615 outline0("STA TMPPTR2" );
2616 outline1("LDA #>OFFSETS%4.4x", _frame_size );
2617 outline0("STA TMPPTR2+1" );
2618 outline0("CLC" );
2619 outline1("LDA %s", _frame );
2620 outline0("ASL" );
2621 outline0("TAY" );
2622 outline0("LDA TMPPTR" );
2623 outline0("ADC (TMPPTR2), Y" );
2624 outline0("STA TMPPTR" );
2625 outline0("INY" );
2626 outline0("LDA TMPPTR+1" );
2627 outline0("ADC (TMPPTR2), Y" );
2628 outline0("STA TMPPTR+1" );
2629 }
2630 }
2631
2632 } else {
2633
2634 if ( _frame ) {
2635 outline0("CLC" );
2636 outline0("LDA TMPPTR" );
2637 outline0("ADC #3" );
2638 outline0("STA TMPPTR" );
2639 outline0("LDA TMPPTR+1" );
2640 outline0("ADC #0" );
2641 outline0("STA TMPPTR+1" );
2642 if ( strlen(_frame) == 0 ) {
2643
2644 } else {
2645 outline1("LDA #<OFFSETS%4.4x", _frame_size );
2646 outline0("STA TMPPTR2" );
2647 outline1("LDA #>OFFSETS%4.4x", _frame_size );
2648 outline0("STA TMPPTR2+1" );
2649 outline0("CLC" );
2650 outline1("LDA %s", _frame );
2651 outline0("ASL" );
2652 outline0("TAY" );
2653 outline0("LDA TMPPTR" );
2654 outline0("ADC (TMPPTR2), Y" );
2655 outline0("STA TMPPTR" );
2656 outline0("INY" );
2657 outline0("LDA TMPPTR+1" );
2658 outline0("ADC (TMPPTR2), Y" );
2659 outline0("STA TMPPTR+1" );
2660 }
2661 }
2662
2663 }
2664 outline1("LDA %s", _x );
2665 outline0("STA IMAGEX" );
2666 outline1("LDA %s+1", _x );
2667 outline0("STA IMAGEX+1" );
2668 outline1("LDA %s", _y );
2669 outline0("STA IMAGEY" );
2670 outline1("LDA %s+1", _y );
2671 outline0("STA IMAGEY+1" );
2672 outline1("LDA %s", _flags );
2673 outline0("STA IMAGEF" );
2674 outline1("LDA %s", address_displacement( _environment, _flags, "1" ) );
2675 outline0("STA IMAGET" );
2676
2677 outline0("JSR PUTIMAGE");
2678
2679}
2680
2681static void vic2_load_image_address_to_other_register( Environment * _environment, char * _register, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2682
2683 outline1("LDA #<%s", _source );
2684 outline1("STA %s", _register );
2685 outline1("LDA #>%s", _source );
2686 outline1("STA %s", address_displacement(_environment, _register, "1") );
2687
2688 if ( _sequence ) {
2689
2690 outline0("CLC" );
2691 outline1("LDA %s", _register );
2692 outline0("ADC #3" );
2693 outline1("STA %s", _register );
2694 outline1("LDA %s", address_displacement(_environment, _register, "1") );
2695 outline0("ADC #0" );
2696 outline1("STA %s", address_displacement(_environment, _register, "1") );
2697 if ( strlen(_sequence) == 0 ) {
2698
2699 } else {
2700 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
2701 outline0("STA MATHPTR0" );
2702 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
2703 outline0("STA MATHPTR1" );
2704 outline0("CLC" );
2705 outline1("LDA %s", _sequence );
2706 outline0("ASL" );
2707 outline0("TAY" );
2708 outline1("LDA %s", _register );
2709 outline0("ADC (MATHPTR0), Y" );
2710 outline1("STA %s", _register );
2711 outline0("INY" );
2712 outline1("LDA %s", address_displacement(_environment, _register, "1") );
2713 outline0("ADC (MATHPTR0), Y" );
2714 outline1("STA %s", address_displacement(_environment, _register, "1") );
2715 }
2716
2717 if ( _frame ) {
2718 if ( strlen(_frame) == 0 ) {
2719
2720 } else {
2721 outline1("LDA #<OFFSETS%4.4x", _frame_size );
2722 outline0("STA MATHPTR0" );
2723 outline1("LDA #>OFFSETS%4.4x", _frame_size );
2724 outline0("STA MATHPTR1" );
2725 outline0("CLC" );
2726 outline1("LDA %s", _frame );
2727 outline0("ASL" );
2728 outline0("TAY" );
2729 outline1("LDA %s", _register );
2730 outline0("ADC (MATHPTR0), Y" );
2731 outline1("STA %s", _register );
2732 outline0("INY" );
2733 outline1("LDA %s", address_displacement(_environment, _register, "1") );
2734 outline0("ADC (MATHPTR0), Y" );
2735 outline1("STA %s", address_displacement(_environment, _register, "1") );
2736 }
2737 }
2738
2739 } else {
2740
2741 if ( _frame ) {
2742 outline0("CLC" );
2743 outline1("LDA %s", _register );
2744 outline0("ADC #3" );
2745 outline1("STA %s", _register );
2746 outline1("LDA %s", address_displacement(_environment, _register, "1") );
2747 outline0("ADC #0" );
2748 outline1("STA %s", address_displacement(_environment, _register, "1") );
2749 if ( strlen(_frame) == 0 ) {
2750
2751 } else {
2752 outline1("LDA #<OFFSETS%4.4x", _frame_size );
2753 outline0("STA MATHPTR0" );
2754 outline1("LDA #>OFFSETS%4.4x", _frame_size );
2755 outline0("STA MATHPTR0+1" );
2756 outline0("CLC" );
2757 outline1("LDA %s", _frame );
2758 outline0("ASL" );
2759 outline0("TAY" );
2760 outline1("LDA %s", _register );
2761 outline0("ADC (MATHPTR0), Y" );
2762 outline1("STA %s", _register );
2763 outline0("INY" );
2764 outline1("LDA %s", address_displacement(_environment, _register, "1") );
2765 outline0("ADC (MATHPTR0), Y" );
2766 outline1("STA %s", address_displacement(_environment, _register, "1") );
2767 }
2768 }
2769
2770 }
2771
2772}
2773
2774static void vic2z_load_image_address_to_register( Environment * _environment, char * _register, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2775
2776 outline1("LDA #<%s", _source );
2777 outline1("STA %s", _register );
2778 outline1("LDA #>%s", _source );
2779 outline1("STA %s+1", _register );
2780
2781 if ( _sequence ) {
2782
2783 outline0("CLC" );
2784 outline1("LDA %s", _register );
2785 outline0("ADC #3" );
2786 outline1("STA %s", _register );
2787 outline1("LDA %s+1", _register );
2788 outline0("ADC #0" );
2789 outline1("STA %s+1", _register );
2790 if ( strlen(_sequence) == 0 ) {
2791
2792 } else {
2793 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
2794 outline0("STA MATHPTR0" );
2795 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
2796 outline0("STA MATHPTR0+1" );
2797 outline0("CLC" );
2798 outline1("LDA %s", _sequence );
2799 outline0("ASL" );
2800 outline0("TAY" );
2801 outline1("LDA %s", _register );
2802 outline0("ADC (MATHPTR0), Y" );
2803 outline1("STA %s", _register );
2804 outline0("INY" );
2805 outline1("LDA %s+1", _register );
2806 outline0("ADC (MATHPTR0+1), Y" );
2807 outline1("STA %s+1", _register );
2808 }
2809
2810 if ( _frame ) {
2811 if ( strlen(_frame) == 0 ) {
2812
2813 } else {
2814 outline1("LDA #<OFFSETS%4.4x", _frame_size );
2815 outline0("STA MATHPTR0" );
2816 outline1("LDA #>OFFSETS%4.4x", _frame_size );
2817 outline0("STA MATHPTR0+1" );
2818 outline0("CLC" );
2819 outline1("LDA %s", _frame );
2820 outline0("ASL" );
2821 outline0("TAY" );
2822 outline1("LDA %s", _register );
2823 outline0("ADC (MATHPTR0), Y" );
2824 outline1("STA %s", _register );
2825 outline0("INY" );
2826 outline1("LDA %s+1", _register );
2827 outline0("ADC (MATHPTR0), Y" );
2828 outline1("STA %s+1", _register );
2829 }
2830 }
2831
2832 } else {
2833
2834 if ( _frame ) {
2835 outline0("CLC" );
2836 outline1("LDA %s", _register );
2837 outline0("ADC #3" );
2838 outline1("STA %s", _register );
2839 outline1("LDA %s+1", _register );
2840 outline0("ADC #0" );
2841 outline1("STA %s+1", _register );
2842 if ( strlen(_frame) == 0 ) {
2843
2844 } else {
2845 outline1("LDA #<OFFSETS%4.4x", _frame_size );
2846 outline0("STA MATHPTR0" );
2847 outline1("LDA #>OFFSETS%4.4x", _frame_size );
2848 outline0("STA MATHPTR0+1" );
2849 outline0("CLC" );
2850 outline1("LDA %s", _frame );
2851 outline0("ASL" );
2852 outline0("TAY" );
2853 outline1("LDA %s", _register );
2854 outline0("ADC (MATHPTR0), Y" );
2855 outline1("STA %s", _register );
2856 outline0("INY" );
2857 outline1("LDA %s+1", _register );
2858 outline0("ADC (MATHPTR0), Y" );
2859 outline1("STA %s+1", _register );
2860 }
2861 }
2862
2863 }
2864
2865}
2866
2867void vic2z_blit_image( Environment * _environment, char * _sources[], int _source_count, char * _blit, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _flags ) {
2868
2869 deploy( vic2zvars, src_hw_vic2z_vars_asm);
2870 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2871 deploy( blitimage, src_hw_vic2z_blit_image_asm );
2872
2873 if ( _source_count > 2 ) {
2875 }
2876
2878
2879 outhead1("blitimage%s:", label);
2880
2881 outline1("LDA #<%s", _blit );
2882 outline0("STA BLITIMAGEBLITADDR" );
2883 outline1("LDA #>%s", _blit );
2884 outline0("STA BLITIMAGEBLITADDR+1" );
2885
2886 if ( _source_count > 0 ) {
2887 vic2z_load_image_address_to_register( _environment, "BLITTMPPTR", _sources[0], _sequence, _frame, _frame_size, _frame_count );
2888 } else {
2889 outline0( "LDA #$0" );
2890 outline0( "STA BLITTMPPTR" );
2891 outline0( "STA BLITTMPPTR+1" );
2892 }
2893
2894 if ( _source_count > 1 ) {
2895 vic2z_load_image_address_to_register( _environment, "BLITTMPPTR2", _sources[1], _sequence, _frame, _frame_size, _frame_count );
2896 } else {
2897 outline0( "LDA #$0" );
2898 outline0( "STA BLITTMPPTR2" );
2899 outline0( "STA BLITTMPPTR2+1" );
2900 }
2901
2902 outhead1("putimage%s:", label);
2903
2904 outline1("LDA %s", _x );
2905 outline0("STA IMAGEX" );
2906 outline1("LDA %s+1", _x );
2907 outline0("STA IMAGEX+1" );
2908 outline1("LDA %s", _y );
2909 outline0("STA IMAGEY" );
2910 outline1("LDA %s+1", _y );
2911 outline0("STA IMAGEY+1" );
2912 outline1("LDA #$%2.2x", ( _flags & 0xff ) );
2913 outline0("STA IMAGEF" );
2914 outline1("LDA #$%2.2x", ( (_flags>>8) & 0xff ) );
2915 outline0("STA IMAGET" );
2916
2917 outline0("JSR BLITIMAGE");
2918
2919}
2920
2921void vic2z_wait_vbl( Environment * _environment ) {
2922
2923 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2924 deploy( vbl, src_hw_vic2z_vbl_asm);
2925
2926 outline0("JSR VBL");
2927
2928}
2929
2930Variable * vic2z_new_image( Environment * _environment, int _width, int _height, int _mode ) {
2931
2932 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2933
2934 int size = calculate_image_size( _environment, _width, _height, _mode );
2935
2936 if ( ! size ) {
2938 }
2939
2940 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
2941
2942 char * buffer = malloc ( size );
2943 memset( buffer, 0, size );
2944
2945 *(buffer) = (_width & 0xff);
2946 *(buffer+1) = (_width>>8) & 0xff;
2947 *(buffer+2) = _height;
2948
2949 result->valueBuffer = buffer;
2950 result->size = size;
2951
2952 return result;
2953
2954}
2955
2956Variable * vic2z_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2957
2958 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2959
2960 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2961 int frameSize = calculate_image_size( _environment, _width, _height, _mode );
2962
2963 if ( ! size ) {
2965 }
2966
2967 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
2968
2969 char * buffer = malloc ( size );
2970 memset( buffer, 0, size );
2971
2972 *(buffer) = _frames;
2973 *(buffer+1) = ( _width & 0xff );
2974 *(buffer+2) = ( _width >> 8 ) & 0xff;
2975 for( int i=0; i<_frames; ++i ) {
2976 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2977 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2978 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2979 }
2980
2981 result->valueBuffer = buffer;
2982 result->frameSize = frameSize;
2983 result->size = size;
2984 result->frameCount = _frames;
2985
2986 return result;
2987
2988}
2989
2990Variable * vic2z_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2991
2992 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
2993
2994 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
2995 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2996 int frameSize = calculate_image_size( _environment, _width, _height, _mode );
2997
2998 if ( ! size ) {
3000 }
3001
3002 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
3003
3004 char * buffer = malloc ( size2 );
3005 memset( buffer, 0, size2 );
3006
3007 *(buffer) = _frames;
3008 *(buffer+1) = _width;
3009 *(buffer+2) = _sequences;
3010 for( int i=0; i<(_frames*_sequences); ++i ) {
3011 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
3012 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
3013 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
3014 }
3015
3016 result->valueBuffer = buffer;
3017 result->frameSize = frameSize;
3018 result->size = size;
3019 result->frameCount = _frames;
3020
3021 return result;
3022
3023}
3024
3025void vic2z_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
3026
3027 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3028 deploy( vic2zvarsGraphic, src_hw_vic2z_vars_graphic_asm );
3029 deploy( getimage, src_hw_vic2z_get_image_asm );
3030
3032
3033 vic2_load_image_address_to_other_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3034
3035 outline1("LDA %s", _x );
3036 outline0("STA IMAGEX" );
3037 outline1("LDA %s+1", _x );
3038 outline0("STA IMAGEX+1" );
3039 outline1("LDA %s", _y );
3040 outline0("STA IMAGEY" );
3041 outline1("LDA %s+1", _y );
3042 outline0("STA IMAGEY+1" );
3043 outline1("LDA #$%2.2x", _palette );
3044 outline0("STA IMAGET" );
3045
3046 outline0("JSR GETIMAGE");
3047
3048}
3049
3050void vic2z_scroll( Environment * _environment, int _dx, int _dy ) {
3051
3052 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3053 deploy( scroll, src_hw_vic2z_scroll_asm);
3054 deploy( textHScroll, src_hw_vic2z_hscroll_text_asm );
3055 deploy( vScrollTextDown, src_hw_vic2z_vscroll_text_down_asm );
3056 deploy( vScrollTextUp, src_hw_vic2z_vscroll_text_up_asm );
3057
3058 outline1("LDA #$%2.2x", (unsigned char)(_dx&0xff) );
3059 outline0("STA MATHPTR0" );
3060 outline1("LDA #$%2.2x", (unsigned char)(_dy&0xff) );
3061 outline0("STA MATHPTR1" );
3062 outline0("JSR SCROLL");
3063
3064}
3065
3066void vic2z_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
3067
3068 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3069 deploy( tiles, src_hw_vic2z_tiles_asm );
3070
3071 outline1("LDA %s", _tile );
3072 outline0("STA TILET" );
3073 outline1("LDA %s", _x );
3074 outline0("STA TILEX" );
3075 outline1("LDA %s", _y );
3076 outline0("STA TILEY" );
3077 outline0("LDA #1" );
3078 outline0("STA TILEW" );
3079 outline0("STA TILEH" );
3080 outline0("STA TILEW2" );
3081 outline0("STA TILEH2" );
3082
3083 outline0("JSR PUTTILE");
3084
3085}
3086
3087void vic2z_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
3088
3089 Variable * tile = variable_retrieve( _environment, _tile );
3090 Variable * x = variable_retrieve( _environment, _x );
3091 Variable * y = variable_retrieve( _environment, _y );
3092
3093 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3094 deploy( tiles, src_hw_vic2z_tiles_asm );
3095
3096 outline1("LDA %s", tile->realName );
3097 outline0("STA TILET" );
3098 outline1("LDA %s", x->realName );
3099 outline0("STA TILEX" );
3100 outline1("LDA %s", y->realName );
3101 outline0("STA TILEY" );
3102 outline1("LDA %s+1", tile->realName );
3103 outline0("STA TILEW" );
3104 outline0("STA TILEW2" );
3105 outline1("LDA %s+2", tile->realName );
3106 outline0("STA TILEH" );
3107 outline0("STA TILEH2" );
3108 outline1("LDA %s+3", tile->realName );
3109 outline0("STA TILEA" );
3110
3111 int size = ( tile->originalWidth >> 3 ) * ( tile->originalHeight >> 3 );
3112
3113 if ( size ) {
3114 outline1("LDA #<OFFSETS%4.4x", size );
3115 outline0("STA TMPPTR2" );
3116 outline1("LDA #>OFFSETS%4.4x", size );
3117 outline0("STA TMPPTR2+1" );
3118 } else {
3119 outline0("LDA #0" );
3120 outline0("STA TMPPTR2" );
3121 outline0("STA TMPPTR2+1" );
3122 }
3123
3124 outline0("JSR MOVETILE");
3125
3126}
3127
3128void vic2z_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
3129
3130 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3131 deploy( tiles, src_hw_vic2z_tiles_asm );
3132
3133 outline1("LDA %s", _tile );
3134 outline0("STA TILET" );
3135 outline1("LDA %s", _x );
3136 outline0("STA TILEX" );
3137 outline1("LDA %s", _y );
3138 outline0("STA TILEY" );
3139 outline1("LDA %s+1", _tile );
3140 outline0("STA TILEW" );
3141 if ( _w ) {
3142 outline1("LDA %s", _w );
3143 }
3144 outline0("STA TILEW2" );
3145 outline1("LDA %s+2", _tile );
3146 outline0("STA TILEH" );
3147 if ( _h ) {
3148 outline1("LDA %s", _h );
3149 }
3150 outline0("STA TILEH2" );
3151
3152 outline0("JSR PUTTILE");
3153
3154}
3155
3156void vic2z_tile_at( Environment * _environment, char * _x, char * _y, char * _result ) {
3157
3158 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3159 deploy( tiles, src_hw_vic2z_tiles_asm );
3160
3161 outline1("LDA %s", _x );
3162 outline0("STA TILEX" );
3163 outline1("LDA %s", _y );
3164 outline0("STA TILEY" );
3165
3166 outline0("JSR TILEAT");
3167
3168 outline0("LDA TILET" );
3169 outline1("STA %s", _result );
3170
3171}
3172
3173void vic2z_use_tileset( Environment * _environment, char * _tileset ) {
3174
3175 deploy( vic2zvars, src_hw_vic2z_vars_asm);
3176 deploy( tiles, src_hw_vic2z_tiles_asm );
3177
3178 outline1("LDA %s", _tileset );
3179
3180 outline0("JSR USETILESET");
3181
3182}
3183
3184Variable * vic2z_get_raster_line( Environment * _environment ) {
3185
3186 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
3187
3188 outline0( "LDA $D012" );
3189 outline1( "STA %s", result->realName );
3190 outline0( "LDA $D011" );
3191 outline0( "ROL" );
3192 outline0( "ROL" );
3193 outline0( "AND #$01" );
3194 outline1( "STA %s+1", result->realName );
3195
3196 return result;
3197
3198}
3199
3200void vic2z_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
3201
3202}
3203
3204
3205#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
void cpu_beq(Environment *_environment, char *_label)
CPU 6309: emit code to make long conditional jump
Definition 6309.c:308
int lastUsedSlotInCommonPalette
Definition 6847.c:100
#define COLOR_COUNT
Definition 6847.h:72
#define BITMAP_MODE_STANDARD
Definition 6847.h:96
#define COLOR_WHITE
Definition 6847.h:39
int calculate_nearest_tile(TileDescriptor *_tile, TileDescriptors *_tiles)
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
int rgbi_equals_rgba(RGBi *_first, RGBi *_second)
TileDescriptor * calculate_tile_descriptor(TileData *_tileData)
TileDescriptors * precalculate_tile_descriptors_for_font(char *_fontData, int _fontSize)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * malloc_palette(int _size)
Allocate a palette space.
void rgbi_move(RGBi *_source, RGBi *_destination)
int calculate_exact_tile(TileDescriptor *_tile, TileDescriptors *_tiles)
void variable_global(Environment *_environment, char *_pattern)
ScreenMode * find_screen_mode_by_suggestion(Environment *_environment, int _bitmap, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
void font_descriptors_init(Environment *_environment, int _embedded_present)
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
void image_converter_asserts(Environment *_environment, int _width, int _height, int _offset_x, int _offset_y, int *_frame_width, int *_frame_height, int _modulo_x, int _modulo_y)
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Variable * variable_store_buffer(Environment *_environment, char *_destination, unsigned char *_buffer, int _size, int _at)
int size
Definition _optimizer.c:678
int offset
Definition _optimizer.c:681
void back(Environment *_environment, char *_color)
Emit ASM code to fill background color.
Definition back.c:53
void color(Environment *_environment, int _index, int _shade)
Emit ASM code for instruction COLOR [int], [int].
Definition color.c:59
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
void scroll(Environment *_environment, int _dx, int _dy)
Definition scroll.c:41
#define TILEMAP_MODE_STANDARD
Definition cga.h:80
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
unsigned int data_font_alpha_bin_len
Definition font_alpha.c:89
unsigned char data_font_alpha_bin[]
Definition font_alpha.c:1
int screenTilesWidth
Definition ugbc.h:2880
int screenShades
Definition ugbc.h:2865
int fontHeight
Definition ugbc.h:2905
int freeImageWidth
Definition ugbc.h:3088
int currentMode
Definition ugbc.h:2696
int screenTilesHeight
Definition ugbc.h:2885
RgbConverterFunction currentRgbConverterFunction
Definition ugbc.h:2711
int fontWidth
Definition ugbc.h:2900
int bitmaskNeeded
Definition ugbc.h:2659
int screenColors
Definition ugbc.h:2870
int currentModeBW
Definition ugbc.h:2701
int screenHeight
Definition ugbc.h:2860
int currentTileMode
Definition ugbc.h:2706
TileDescriptors * descriptors
Definition ugbc.h:2939
int screenTiles
Definition ugbc.h:2875
int freeImageHeight
Definition ugbc.h:3086
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
unsigned char index
Definition ugbc.h:437
int selected
Definition ugbc.h:1510
TileData data[512]
Definition ugbc.h:2153
TileDescriptor * descriptor[512]
Definition ugbc.h:2152
unsigned char * valueBuffer
Definition ugbc.h:1061
int size
Definition ugbc.h:1077
int originalHeight
Definition ugbc.h:1148
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 originalWidth
Definition ugbc.h:1145
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
#define TILEMAP_MODE_MULTICOLOR
Definition ted.h:82
#define TILEMAP_MODE_EXTENDED
Definition ted.h:83
#define BITMAP_MODE_MULTICOLOR
Definition ted.h:77
void * malloc(YYSIZE_T)
struct _ScreenMode ScreenMode
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
Definition ugbc.h:3502
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 SPRITE_FLAG_MULTICOLOR
Definition ugbc.h:4559
#define deploy_deferred(s, e)
Definition ugbc.h:4302
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_SPRITE
Definition ugbc.h:501
@ 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
#define outhead0(s)
Definition ugbc.h:4246
#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
struct _TileDescriptor TileDescriptor
#define outline1(s, a)
Definition ugbc.h:4253
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
Definition ugbc.h:3880
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define VT_BITWIDTH(t)
Definition ugbc.h:595
#define adilinebeginbitmap(s)
Definition ugbc.h:4231
#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
struct _TileData TileData
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247
char * strcopy(char *_dest, char *_source)
#define BITMAP_MODE_IH
Definition vdc.h:84
#define BITMAP_MODE_IAFLI
Definition vdc.h:83
#define BITMAP_MODE_NUIFLI
Definition vdc.h:91
#define BITMAP_MODE_MEGATEXT
Definition vdc.h:107
#define BITMAP_MODE_TRIFLI
Definition vdc.h:99
#define BITMAP_MODE_MUIFLI
Definition vdc.h:89
#define BITMAP_MODE_MUCSUH
Definition vdc.h:87
#define BITMAP_MODE_XIFLI
Definition vdc.h:101
#define BITMAP_MODE_SH
Definition vdc.h:92
#define BITMAP_MODE_IFLI
Definition vdc.h:104
#define BITMAP_MODE_ECI
Definition vdc.h:82
#define BITMAP_MODE_UFLI
Definition vdc.h:97
#define BITMAP_MODE_ASSLACE
Definition vdc.h:81
#define BITMAP_MODE_SHIFLI
Definition vdc.h:95
#define BITMAP_MODE_MUFLI
Definition vdc.h:88
#define BITMAP_MODE_AIFLI
Definition vdc.h:80
#define BITMAP_MODE_MCI
Definition vdc.h:106
#define BITMAP_MODE_MUCSUFLI
Definition vdc.h:86
#define BITMAP_MODE_SHFLI
Definition vdc.h:93
#define BITMAP_MODE_HCB
Definition vdc.h:103
#define BITMAP_MODE_NUFLI
Definition vdc.h:90
#define BITMAP_MODE_MRFLI
Definition vdc.h:85
#define BITMAP_MODE_FLI
Definition vdc.h:102
#define BITMAP_MODE_MUCSU
Definition vdc.h:105
#define BITMAP_MODE_SHIFXL
Definition vdc.h:96
#define BITMAP_MODE_UIFLI
Definition vdc.h:98
#define BITMAP_MODE_PRS
Definition vdc.h:108
#define BITMAP_MODE_SHI
Definition vdc.h:94
#define BITMAP_MODE_AH
Definition vdc.h:79
#define BITMAP_MODE_XFLI
Definition vdc.h:100
void vic2z_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
void vic2z_sprite_disable(Environment *_environment, char *_sprite)
void vic2z_screen_off(Environment *_environment)
void vic2z_wait_vbl(Environment *_environment)
void vic2z_hscroll_line(Environment *_environment, int _direction, int _overlap)
void vic2z_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
void vic2z_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
void vic2z_sprite_enable(Environment *_environment, char *_sprite)
void vic2z_put_tiles(Environment *_environment, char *_image, char *_x, char *_y, char *_w, char *_h)
void vic2z_screen_rows(Environment *_environment, char *_rows)
int vic2z_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
void vic2z_put_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
void vic2z_vertical_scroll(Environment *_environment, char *_displacement)
void vic2z_tiles_at(Environment *_environment, char *_address)
void vic2z_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Variable * vic2z_new_image(Environment *_environment, int _width, int _height, int _mode)
void vic2z_sprite_multicolor(Environment *_environment, char *_sprite)
Variable * vic2z_image_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _mode, int _transparent_color, int _flags)
void vic2z_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
Variable * vic2z_get_raster_line(Environment *_environment)
void vic2z_scroll_text(Environment *_environment, int _direction, int _overlap)
void vic2z_scroll(Environment *_environment, int _dx, int _dy)
void vic2z_sprite_color(Environment *_environment, char *_sprite, char *_color)
void vic2z_get_height(Environment *_environment, char *_result)
void vic2z_hit(Environment *_environment, char *_sprite_mask, char *_result)
void vic2z_use_tileset(Environment *_environment, char *_tileset)
void vic2z_busy_wait(Environment *_environment, char *_timing)
void vic2z_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
void vic2z_bitmap_disable(Environment *_environment)
void vic2z_colormap_at(Environment *_environment, char *_address)
void vic2z_textmap_at(Environment *_environment, char *_address)
void vic2z_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
void vic2z_background_color_vars(Environment *_environment, char *_index, char *_background_color)
void vic2z_screen_columns(Environment *_environment, char *_columns)
void vic2z_sprite_expand_vertical(Environment *_environment, char *_sprite)
void vic2z_next_raster(Environment *_environment)
void vic2z_sprite_compress_vertical(Environment *_environment, char *_sprite)
void vic2z_bank_select(Environment *_environment, int _bank)
void vic2z_sprite_data_from(Environment *_environment, char *_sprite, char *_address)
void vic2z_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
void vic2z_background_color(Environment *_environment, int _index, int _background_color)
void vic2z_pset_int(Environment *_environment, int _x, int _y, int *_c)
void vic2z_blit_image(Environment *_environment, char *_sources[], int _source_count, char *_blit, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _flags)
Variable * vic2z_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Variable * vic2z_collision(Environment *_environment, char *_sprite)
void vic2z_initialization(Environment *_environment)
void vic2z_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
void vic2z_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
void vic2z_horizontal_scroll(Environment *_environment, char *_displacement)
void vic2z_tiles_get(Environment *_environment, char *_result)
void vic2z_bitmap_at(Environment *_environment, char *_address)
void vic2z_finalization(Environment *_environment)
void vic2z_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Variable * vic2z_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
void vic2z_get_width(Environment *_environment, char *_result)
void vic2z_screen_on(Environment *_environment)
void vic2z_background_color_semivars(Environment *_environment, int _index, char *_background_color)
void vic2z_hscroll_screen(Environment *_environment, int _direction, int _overlap)
void vic2z_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Variable * vic2z_sprite_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, RGBi *_color, int _flags)
void vic2z_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
void vic2z_border_color(Environment *_environment, char *_border_color)
void vic2z_sprite_compress_horizontal(Environment *_environment, char *_sprite)
void vic2z_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
void vic2z_back(Environment *_environment)
void vic2z_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
void vic2z_text(Environment *_environment, char *_text, char *_text_size, int _raw)
void vic2z_move_tiles(Environment *_environment, char *_image, char *_x, char *_y)
void vic2z_sprite_monocolor(Environment *_environment, char *_sprite)
void vic2z_cline(Environment *_environment, char *_characters)
void vic2z_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
void vic2z_cls(Environment *_environment)
void vic2z_put_tile(Environment *_environment, char *_image, char *_x, char *_y)