ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
vic2.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(__c64__) || defined(__c128__) || defined(__c64reu__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40// Palette from http://www.pepto.de/projects/colorvic/
41
42static RGBi SYSTEM_PALETTE[] = {
43// 0 0 0 0 - black
44 { 0, 0, 0, 0xff, 0, "BLACK" },
45// 255 255 255 1 - white
46 { 255, 255, 255, 0xff, 1, "WHITE" },
47// 104 55 43 2 - red
48 { 104, 55, 43, 0xff, 2, "RED" },
49// 112 164 178 3 - cyan
50 { 112, 164, 178, 0xff, 3, "CYAN" },
51// 111 61 134 4 - purple
52 { 111, 61, 134, 0xff, 4, "PURPLE" },
53// 88 141 67 5 - green
54 { 88, 141, 67, 0xff, 5, "GREEN" },
55// 53 40 121 6 - blue
56 { 53, 40, 121, 0xff, 6, "BLUE" },
57// 184 199 111 7 - yellow
58 { 184, 199, 111, 0xff, 7, "YELLOW" },
59// 111 79 37 8 - orange
60 { 111, 79, 37, 0xff, 8, "ORANGE" },
61// 67 57 0 9 - brown
62 { 67, 57, 0, 0xff, 9, "BROWN" },
63// 154 103 89 10 - light red
64 { 154, 103, 89, 0xff, 10, "LIGHT RED" },
65// 68 68 68 11 - dark grey
66 { 68, 68, 68, 0xff, 11, "DARK GREY" },
67// 108 108 108 12 - grey
68 { 108, 108, 108, 0xff, 12, "GREY" },
69// 154 210 132 13 - light green
70 { 154, 210, 132, 0xff, 13, "LIGHT GREEN" },
71// 108 94 181 14 - light blue
72 { 108, 94, 181, 0xff, 14, "LIGHT BLUE" },
73// 149 149 149 15 - light grey
74 { 149, 149, 149, 0xff, 15, "LIGHT GREY" }
75};
76
77
78static RGBi * commonPalette;
80
81static int plotVBase[] = {
82 (0xa000+(0*320)),(0xa000+(1*320)),(0xa000+(2*320)),(0xa000+(3*320)),
83 (0xa000+(4*320)),(0xa000+(5*320)),(0xa000+(6*320)),(0xa000+(7*320)),
84 (0xa000+(8*320)),(0xa000+(9*320)),(0xa000+(10*320)),(0xa000+(11*320)),
85 (0xa000+(12*320)),(0xa000+(13*320)),(0xa000+(14*320)),(0xa000+(15*320)),
86 (0xa000+(16*320)),(0xa000+(17*320)),(0xa000+(18*320)),(0xa000+(19*320)),
87 (0xa000+(20*320)),(0xa000+(21*320)),(0xa000+(22*320)),(0xa000+(23*320)),
88 (0xa000+(24*320)) };
89
90static int plot8[] = {
91 (0*8),(1*8),(2*8),(3*8),(4*8),(5*8),(6*8),(7*8),(8*8),(9*8),
92 (10*8),(11*8),(12*8),(13*8),(14*8),(15*8),(16*8),(17*8),(18*8),(19*8),
93 (20*8),(21*8),(22*8),(23*8),(24*8),(25*8),(26*8),(27*8),(28*8),(29*8),
94 (30*8),(31*8),(32*8),(33*8),(34*8),(35*8),(36*8),(37*8),(38*8),(39*8)
95};
96
97static int plot4[] = {
98 (0*4),(1*4),(2*4),(3*4),(4*4),(5*4),(6*4),(7*4),(8*4),(9*4),
99 (10*4),(11*4),(12*4),(13*4),(14*4),(15*4),(16*4),(17*4),(18*4),(19*4),
100 (20*4),(21*4),(22*4),(23*4),(24*4),(25*4),(26*4),(27*4),(28*4),(29*4),
101 (30*4),(31*4),(32*4),(33*4),(34*4),(35*4),(36*4),(37*4),(38*4),(39*4),
102 (40*4),(41*4),(42*4),(43*4),(44*4),(45*4),(46*4),(47*4),(48*4),(49*4),
103 (50*4),(51*4),(52*4),(53*4),(54*4),(55*4),(56*4),(57*4),(58*4),(59*4),
104 (60*4),(61*4),(62*4),(63*4),(64*4),(65*4),(66*4),(67*4),(68*4),(69*4),
105 (70*4),(71*4),(72*4),(73*4),(74*4),(75*4),(76*4),(77*4),(78*4),(79*4),
106};
107
108/****************************************************************************
109 * CODE SECTION
110 ****************************************************************************/
111
113
114 unsigned int minDistance = 0xffff;
115 int colorIndex = 0;
116 for (int j = 0; j < COLOR_COUNT; ++j) {
117 int distance = rgbi_distance(&SYSTEM_PALETTE[j], _color);
118 if (distance < minDistance) {
119 minDistance = distance;
120 colorIndex = j;
121 }
122 }
123
124 return &SYSTEM_PALETTE[colorIndex];
125
126}
127
139static void vic2_image_converter_tile( Environment * _environment, char * _source, char * _dest, int _width, int _depth, int _source_width ) {
140
141 int colorIndexesCount[COLOR_COUNT];
142 memset(colorIndexesCount, 0, COLOR_COUNT * sizeof( int ) );
143 int trans = 0;
144
145 char * source = _source;
146
147 // Clear the box and colors
148 memset( _dest, 0, 9 );
149
150 // Loop for all the box surface
151 for (int y=0; y<8; ++y) {
152 for (int x=0; x<8; ++x) {
153
154 RGBi rgb;
155
156 memset( &rgb, 0, sizeof( RGBi ) );
157
158 // Take the color of the pixel
159 rgb.red = *source;
160 rgb.green = *(source + 1);
161 rgb.blue = *(source + 2);
162 if ( _depth > 3 ) {
163 rgb.alpha = *(source + 3);
164 } else {
165 rgb.alpha = 255;
166 }
167 if ( rgb.alpha == 0 ) {
168 rgb.red = 0;
169 rgb.green = 0;
170 rgb.blue = 0;
171 }
172
173 if ( rgb.alpha < 255 ) {
174 trans = 1;
175 } else {
176 RGBi *systemRgb = vic2_image_nearest_system_color( &rgb );
177 ++colorIndexesCount[systemRgb->index];
178 }
179
180 source += _depth;
181
182 }
183
184 source += _depth * ( _source_width - 8 );
185
186 }
187
188 int colorBackground = 0;
189 int colorBackgroundMax = 0;
190 int colorForeground = 0;
191 int colorForegroundMax = 0;
192 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
193 if ( colorIndexesCount[xx] > colorBackgroundMax ) {
194 colorBackground = xx;
195 colorBackgroundMax = colorIndexesCount[xx];
196 };
197 }
198
199 colorIndexesCount[colorBackground] = 0;
200
201 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
202 if ( colorIndexesCount[xx] > colorForegroundMax ) {
203 colorForeground = xx;
204 colorForegroundMax = colorIndexesCount[xx];
205 };
206 }
207
208 if ( trans ) {
209 if ( colorForeground == 0 ) {
210 colorForeground = colorBackground;
211 colorBackground = 0;
212 } else {
213 colorBackground = 0;
214 }
215 }
216
217 if ( colorForeground == colorBackground ) {
218 colorForeground = ( colorBackground == 0 ) ? 1 : 0;
219 }
220
221 source = _source;
222
223 for (int y=0; y<8; ++y) {
224 for (int x=0; x<8; ++x) {
225
226 RGBi rgb;
227
228 memset( &rgb, 0, sizeof( RGBi ) );
229
230 rgb.red = *source;
231 rgb.green = *(source + 1);
232 rgb.blue = *(source + 2);
233 if ( _depth > 3 ) {
234 rgb.alpha = *(source + 3);
235 } else {
236 rgb.alpha = 255;
237 }
238 if ( rgb.alpha == 0 ) {
239 rgb.red = 0;
240 rgb.green = 0;
241 rgb.blue = 0;
242 }
243
244 RGBi *systemRgb = vic2_image_nearest_system_color( &rgb );
245
246 char bitmask = 1 << ( 7 - ((x) & 0x7) );
247
248 if ( rgb.alpha < 255 ) {
249 *( _dest + y ) &= ~bitmask;
250 adilinepixel(colorBackground);
251 } else {
252 if ( systemRgb->index != colorBackground ) {
253 adilinepixel(colorForeground);
254 *( _dest + y ) |= bitmask;
255 } else {
256 adilinepixel(colorBackground);
257 *( _dest + y ) &= ~bitmask;
258 }
259 }
260
261 source += _depth;
262
263 }
264
265 source += _depth * ( _source_width - 8 );
266
267 }
268
269 *( _dest + 8 ) = ( colorForeground << 4 ) | colorBackground ;
270
271}
272
284static void vic2_image_converter_tiles( Environment * _environment, char * _source, char * _dest, int _width, int _height, int _depth, int _source_width ) {
285
286 int bitmapSize = ( _width>>3 ) * _height;
287 int colormapSize = ( _width>>3 ) * (_height>>3);
288
289 memset( _dest, 0, bitmapSize + colormapSize );
290
291 adilinebeginbitmap("BMD2");
292
293 for( int y=0; y<_height; y+=8 ) {
294 for( int x=0; x<_width; x+=8 ) {
295
296 char * source = _source + ( ( y * _source_width ) + x ) * _depth;
297 char tile[9];
298
299 vic2_image_converter_tile( _environment, source, tile, _width, _depth, _source_width );
300
301 int offset = ((y>>3) * 8 *( _width >> 3 ) ) + ((x>>3) * 8) + ((y) & 0x07);
302 // x = 8, y = 8
303 // offset = ((8 >> 3) * 8 * (16>>3) ) + ((8>>3) * 8) + ((8) & 7)
304 // offset = (1 * 8 * 2 ) + (1 * 8)
305 // offset = 16 + 8 = 24
306
307 char * destBitmap = _dest + offset;
308 char * destColormap = _dest + bitmapSize + ( ( ( y >> 3 ) * ( _width >> 3 ) ) + ( x >> 3 ) );
309 for( int i=0; i<8; ++i ) {
310 *destBitmap = tile[i];
311 ++destBitmap;
312 }
313 // printf("tile at %d,%d color = %2.2x\n", x, y, tile[8] );
314 *destColormap = tile[8];
315 }
316 }
317
319
320}
321
335static void vic2_image_converter_tile_multicolor( Environment * _environment, char * _source, char * _dest, int _width, int _depth, int _background, int _source_width ) {
336
337 int colorIndexesCount[COLOR_COUNT];
338 memset(colorIndexesCount, 0, COLOR_COUNT * sizeof( int ) );
339 int trans = 0;
340
341 char * source = _source;
342
343 // Clear the box and colors
344 memset( _dest, 0, 10 );
345
346 // Loop for all the box surface
347 for (int y=0; y<8; ++y) {
348 for (int x=0; x<4; ++x) {
349
350 RGBi rgb;
351
352 memset( &rgb, 0, sizeof( RGBi ) );
353
354 // Take the color of the pixel
355 rgb.red = *source;
356 rgb.green = *(source + 1);
357 rgb.blue = *(source + 2);
358 if ( _depth > 3 ) {
359 rgb.alpha = *(source + 3);
360 } else {
361 rgb.alpha = 255;
362 }
363 if ( rgb.alpha == 0 ) {
364 rgb.red = 0;
365 rgb.green = 0;
366 rgb.blue = 0;
367 }
368
369 if ( rgb.alpha < 255 ) {
370 trans = 1;
371 } else {
372
373 RGBi *systemRgb = vic2_image_nearest_system_color( &rgb );
374
375 ++colorIndexesCount[systemRgb->index];
376
377 }
378
379
380 source += _depth;
381
382 }
383
384 source += _depth * ( _source_width - 4 );
385
386 }
387
388 if ( trans ) {
389 _background = 0;
390 }
391
392 colorIndexesCount[_background] = 0;
393
394 int colorFirst = -1;
395 int colorFirstMax = 0;
396 int colorSecond = -1;
397 int colorSecondMax = 0;
398 int colorThird = -1;
399 int colorThirdMax = 0;
400
401 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
402 if ( colorIndexesCount[xx] > colorFirstMax ) {
403 colorFirst = xx;
404 colorFirstMax = colorIndexesCount[xx];
405 };
406 }
407
408 if ( colorFirst > -1 ) {
409 colorIndexesCount[colorFirst] = 0;
410 }
411
412 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
413 if ( colorIndexesCount[xx] > colorSecondMax ) {
414 colorSecond = xx;
415 colorSecondMax = colorIndexesCount[xx];
416 };
417 }
418
419 if ( colorSecond > -1 ) {
420 colorIndexesCount[colorSecond] = 0;
421 }
422
423 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
424 if ( colorIndexesCount[xx] > colorThirdMax ) {
425 colorThird = xx;
426 colorThirdMax = colorIndexesCount[xx];
427 };
428 }
429
430 if ( colorThird > -1 ) {
431 colorIndexesCount[colorThird] = 0;
432 }
433
434 source = _source;
435
436 for (int y=0; y<8; ++y) {
437 for (int x=0; x<4; ++x) {
438
439 RGBi rgb;
440
441 memset( &rgb, 0, sizeof( RGBi ) );
442
443 rgb.red = *source;
444 rgb.green = *(source + 1);
445 rgb.blue = *(source + 2);
446 if ( _depth > 3 ) {
447 rgb.alpha = *(source + 3);
448 } else {
449 rgb.alpha = 255;
450 }
451 if ( rgb.alpha == 0 ) {
452 rgb.red = 0;
453 rgb.green = 0;
454 rgb.blue = 0;
455 }
456
457 char colorIndex = 0;
458
459 if ( rgb.alpha < 255 ) {
460 adilinepixel(_background);
461 colorIndex = 0;
462 } else {
463
464 RGBi *systemRgb = vic2_image_nearest_system_color( &rgb );
465
466 if ( systemRgb->index == colorFirst ) {
467 adilinepixel(colorFirst);
468 colorIndex = 1;
469 } else if ( systemRgb->index == colorSecond ) {
470 adilinepixel(colorSecond);
471 colorIndex = 2;
472 } else if ( systemRgb->index == colorThird ) {
473 adilinepixel(colorThird);
474 colorIndex = 3;
475 } else {
476 adilinepixel(_background);
477 }
478
479 }
480
481 char bitmask = colorIndex << (6 - ((x & 0x3) * 2));
482
483 *(_dest + y) |= bitmask;
484
485 source += _depth;
486
487 }
488
489 source += _depth * ( _source_width - 4 );
490
491 }
492
493 colorFirst = ( colorFirst == -1 ) ? 0 : colorFirst;
494 colorSecond = ( colorSecond == -1 ) ? 0 : colorSecond;
495 colorThird = ( colorThird == -1 ) ? 0 : colorThird;
496 _background = ( _background == -1 ) ? 0 : _background;
497
498 *( _dest + 8 ) = ( colorFirst << 4 ) | colorSecond ;
499 *( _dest + 9 ) = ( _background << 4 ) | colorThird;
500
501}
502
516static void vic2_image_converter_tiles_multicolor( Environment * _environment, char * _source, char * _dest, int _width, int _height, int _depth, int _source_width, int _background ) {
517
518 int bitmapSize = ( _width>>2 ) * _height;
519 int colormap1Size = ( _width>>2 ) * (_height>>3);
520 int colormap2Size = ( _width>>2 ) * (_height>>3);
521
522 memset( _dest, 0, bitmapSize + colormap1Size + colormap2Size );
523
524 adilinebeginbitmap("BMD4");
525
526 for( int y=0; y<_height; y+=8 ) {
527 for( int x=0; x<_width; x+=4 ) {
528
529 char * source = _source + ( ( y * _source_width ) + x ) * _depth;
530 char tile[10];
531
532 vic2_image_converter_tile_multicolor( _environment, source, tile, _width, _depth, _background, _source_width );
533
534 int offset = ((y>>3) * 8 *( _width >> 2 ) ) + ((x>>2) * 8) + ((y) & 0x07);
535
536 char * destBitmap = _dest + offset;
537 char * destColormap1 = _dest + bitmapSize + ( ( ( y >> 3 ) * ( _width >> 2 ) ) + ( x >> 2 ) );
538 char * destColormap2 = _dest + bitmapSize + colormap1Size + ( ( ( y >> 3 ) * ( _width >> 2 ) ) + ( x >> 2 ) );
539 for( int i=0; i<8; ++i ) {
540 *destBitmap = tile[i];
541 ++destBitmap;
542 }
543 *destColormap1 = tile[8];
544 *destColormap2 = tile[9];
545 }
546 }
547
549
550}
551
563Variable * vic2_collision( Environment * _environment, char * _sprite ) {
564
565 _environment->bitmaskNeeded = 1;
566
567 Variable * result = variable_temporary( _environment, VT_SBYTE, "(collision result)");
568 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_SPRITE, 0 );
569
570 switch ( sprite->type) {
571
572 case VT_BYTE:
573 case VT_SPRITE:
574
576
577 outline1("LDA %s", sprite->realName);
578 outline0("STA MATHPTR3");
579 outline0("JSR SPRITECOL");
580 outline1("STA %s", result->realName);
581
582 case VT_MSPRITE:
583
584 if ( !_environment->deployed.msprite ) {
585 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
586 }
587
589
590 outline1("LDA %s", sprite->realName);
591 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
592 outline0("STA MATHPTR3");
593 outline0("JSR MSPRITECOL");
594 outline1("STA %s", result->realName);
595 break;
596
597 }
598
599
600
601 return result;
602
603}
604
616void vic2_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
617
618 // Generate unique label for ASM code.
620
621 // Check for collision using VIC-II registers
622 outline0("LDA $D01F");
623 outline1("AND %s", _sprite_mask);
624 cpu_beq(_environment, label);
625
626 outline0("LDA #$1");
627 outline1("STA %s", _result);
628 outline1("JMP %s_2", label);
629
630 outhead1("%s:", label);
631 outline0("LDA #0");
632 outline1("STA %s", _result);
633 outhead1("%s_2:", label);
634
635}
636
637void vic2_border_color( Environment * _environment, int _border_color ) {
638
639 outline1("LDA #$%2.2x", _border_color );
640 outline0("STA $D020");
641
642}
643
653void vic2_border_color_vars( Environment * _environment, char * _border_color ) {
654
655 outline1("LDA %s", _border_color );
656 outline0("AND #$0f" );
657 outline0("STA $D020");
658
659}
660
671void vic2_background_color( Environment * _environment, int _index, int _background_color ) {
672
673 outline1("LDA #$%2.2x", ( _background_color & 0x0f ) );
674 outline1("STA $d021+%d", ( _index & 0x03 ) );
675
676 if ( _index == 0 ) {
677 outline0("STA _PAPER" );
678 }
679}
680
691void vic2_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
692
694
695 outline1("LDA %s", _index);
696 outline0("AND #$03");
697 outline1("BNE %s", label);
698 outline1("LDA %s", _background_color );
699 outline0("STA _PAPER");
700 outhead1("%s:", label);
701 outline1("LDA %s", _index);
702 outline0("TAX");
703 outline1("LDA %s", _background_color );
704 outline0("AND #$0f" );
705 outline0("STA $d021,X");
706
707}
708
719void vic2_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
720
721 outline1("LDA #$%2.2x", _index);
722 outline0("AND #$03");
723 outline0("TAX");
724 outline1("LDA %s", _background_color );
725 outline0("AND #$0f" );
726 outline0("STA $d021,X");
727 if ( _index == 0 ) {
728 outline0("STA _PAPER" );
729 }
730
731}
732
743void vic2_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
744
745 outline1("LDA %s", _index);
746 outline0("AND #$03");
747 outline0("TAX");
748 outline0("LDA $d021,X");
749 outline0("AND #$0f" );
750 outline1("STA %s", _background_color );
751}
752
763void vic2_sprite_common_color( Environment * _environment, int _index, int _common_color ) {
764
765 outline1("LDA #$%2.2x", ( _common_color & 0x0f ) );
766 outline1("STA $,X", 0xd025 + ( _index & 0x03 ) );
767
768}
769
780void vic2_sprite_common_color_vars( Environment * _environment, char * _index, char * _common_color ) {
781
782 outline1("LDA %s", _index);
783 outline0("AND #$03");
784 outline0("TAX");
785 outline1("LDA %s", _common_color );
786 outline0("AND #$0f" );
787 outline0("STA $D025,X" );
788
789}
790
806void vic2_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
807
809
810 // outline0("LDA #%01111111"); // switch off CIA-1
811 // outline0("STA $DC0D");
812 outline0("AND $D011");
813 outline0("STA $D011");
814 outline0("LDA $DC0D"); // acknowledge CIA-1
815 outline0("LDA $DD0D"); // acknowledge CIA-2
816 outline1("LDA #<%s", _label);
817 outline0("STA $0314");
818 outline1("LDA #>%s", _label);
819 outline0("STA $0315");
820 outline0("LDA #%00000001"); // enable raster interrupt signals from VIC
821 outline0("STA $D01A");
822 outline1("LDA %s", _positionlo );
823 outline0("STA $D012");
824 outline1("LDA %s", _positionhi );
825 outline0("AND #%00000001" );
826 cpu_beq(_environment, label);
827 outline0("LDA $D011" );
828 outline0("AND #%01111111" );
829 outline0("ORA #%10000000" );
830 outline0("STA $D011");
831 outline1("JMP %s_2", label );
832 outhead1("%s:", label );
833 outline0("LDA $D011" );
834 outline0("AND #%01111111" );
835 outline0("STA $D011");
836 outhead1("%s_2:", label );
837 outline0("CLI");
838
839}
840
851void vic2_next_raster( Environment * _environment ) {
852
853 outline0("ASL $D019");
854 outline0("JMP IRQSVC2");
855
856}
857
871void vic2_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
872
874
875 outline1("LDA %s", _positionlo);
876 outline0("STA $D012");
877 outline1("LDA %s", _positionhi );
878 outline0("AND #%00000001" );
879 cpu_beq(_environment, label);
880 outline0("LDA $D011" );
881 outline0("AND #%01111111" );
882 outline0("ORA #%10000000" );
883 outline0("STA $D011");
884 outline1("JMP %s_2", label );
885 outhead1("%s:", label );
886 outline0("LDA $D011" );
887 outline0("AND #%01111111" );
888 outline0("STA $D011");
889 outhead1("%s_2:", label );
890 outline1("LDA #<%s", _label);
891 outline0("STA $0314");
892 outline1("LDA #>%s", _label);
893 outline0("STA $0315");
894
895 vic2_next_raster( _environment );
896
897}
898
899void vic2_bank_select( Environment * _environment, int _bank ) {
900
901 outline0("LDA $DD00" );
902 outline0("AND #%11111100");
903 outline1("ORA #%2.2x", ( ~_bank ) & 0x03 );
904 outline0("STA $DD00" );
905}
906
907static int rgbConverterFunction( int _red, int _green, int _blue ) {
908
909 int colorIndex = 0;
910 unsigned int minDistance = 0xffffffff;
911 int j;
912
913 RGBi rgb;
914 rgb.red = _red;
915 rgb.green = _green;
916 rgb.blue = _blue;
917
918 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
919 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &rgb);
920 if (distance < minDistance) {
921 minDistance = distance;
922 colorIndex = j;
923 }
924 }
925
926 return colorIndex;
927
928}
929
930int vic2_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
931
932 _screen_mode->selected = 1;
933
934 Variable * colormapAddress = variable_retrieve( _environment, "COLORMAPADDRESS" );
935
936 _environment->fontWidth = 8;
937 _environment->fontHeight = 8;
938 _environment->screenTiles = 255;
939 switch( _screen_mode->id ) {
941 _environment->screenWidth = 320;
942 _environment->screenHeight = 200;
943 _environment->screenColors = 16;
944 _environment->currentModeBW = 1;
945 // This fix is necessary to set the starting address of the bitmap
946 // to $A000 (which is an address available on C=64).
947 // Move the screen address to $8C00 to have
948 // more space for sprites (0011....)
949 outline0("LDA $D018" );
950 outline0("AND #%11110111");
951 outline0("ORA #%00111000" );
952 outline0("STA $D018" );
953#if __c128__
954 outline0("STA $0A2D" );
955#endif
956
957 // Let's enable monocolor graphics!
958 outline0("LDA $D011" );
959 outline0("AND #%01111011");
960 outline0("ORA #%00100000");
961 outline0("STA $D011" );
962 outline0("LDA $D016" );
963 outline0("AND #%11101111");
964 outline0("STA $D016" );
965
966 outline0("LDA #$21" );
967 outline0("STA $D8" );
968
969 cpu_store_16bit( _environment, colormapAddress->realName, 0x8c00 );
970
971 cpu_store_8bit( _environment, "_PEN", 0X01 );
972 cpu_store_8bit( _environment, "_PAPER", 0x00 );
973 cpu_store_16bit( _environment, "CLIPX1", 0 );
974 cpu_store_16bit( _environment, "CLIPX2", 319 );
975 cpu_store_16bit( _environment, "CLIPY1", 0 );
976 cpu_store_16bit( _environment, "CLIPY2", 199 );
977
978 _environment->mspriteMsbokAddress = 0x8ff8;
979
980 break;
982 _environment->fontWidth = 8;
983 _environment->screenWidth = 160;
984 _environment->screenHeight = 200;
985 _environment->screenColors = 16;
986 _environment->currentModeBW = 2;
987 // This fix is necessary to set the starting address of the bitmap
988 // to $A000 (which is an address available on C=64) instead of the
989 // address $8000.
990 // Move the screen address to $8C00 to have
991 // more space for sprites (0011....)
992 outline0("LDA $D018" );
993 outline0("AND #%11110111");
994 outline0("ORA #%00111000" );
995 outline0("STA $D018" );
996#if __c128__
997 outline0("STA $0A2D" );
998#endif
999
1000 // Let's enable multicolor graphics!
1001 outline0("LDA $D011" );
1002 outline0("AND #%01111000");
1003 outline0("ORA #%00101011");
1004 outline0("STA $D011" );
1005 outline0("LDA $D016" );
1006 outline0("ORA #%00010000");
1007 outline0("STA $D016" );
1008
1009 outline0("LDA #$23" );
1010 outline0("STA $d8" );
1011
1012 cpu_store_16bit( _environment, colormapAddress->realName, 0x8c00 );
1013
1014 cpu_store_8bit( _environment, "_PEN", 0X01 );
1015 cpu_store_8bit( _environment, "_PAPER", 0x00 );
1016
1017 cpu_store_16bit( _environment, "CLIPX1", 0 );
1018 cpu_store_16bit( _environment, "CLIPX2", 159 );
1019 cpu_store_16bit( _environment, "CLIPY1", 0 );
1020 cpu_store_16bit( _environment, "CLIPY2", 199 );
1021
1022 _environment->mspriteMsbokAddress = 0x8ff8;
1023
1024 break;
1026 _environment->screenWidth = 320;
1027 _environment->screenHeight = 200;
1028 _environment->screenColors = 16;
1029 _environment->currentModeBW = 0;
1030 // Let's disable graphics!
1031 outline0("LDA $D011" );
1032 outline0("AND #%01011000");
1033 outline0("ORA #%00001011");
1034 outline0("STA $D011" );
1035 outline0("LDA $D016" );
1036 outline0("AND #%11101111");
1037 outline0("STA $D016" );
1038 outline0("LDA $D018" );
1039 outline0("AND #%11110111");
1040 if ( _environment->fontConfig.schema || _environment->descriptors ) {
1041 outline0("ORA #$09");
1042 } else {
1043 outline0("ORA #$07");
1044 }
1045 outline0("STA $D018" );
1046
1047 // // This fix is necessary to reset the lookup for rom character.
1048 // outline0("LDA $D018" );
1049 // outline0("AND #%11110000");
1050 // if ( _environment->fontConfig.schema || _environment->descriptors ) {
1051 // outline0("ORA #$09");
1052 // } else {
1053 // outline0("ORA #$07");
1054 // }
1055 // outline0("STA $D018" );
1056
1057 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
1058
1059 cpu_store_8bit( _environment, "_PEN", 0x01 );
1060 cpu_store_8bit( _environment, "_PAPER", 0x00 );
1061
1062 cpu_store_16bit( _environment, "CLIPX1", 0 );
1063 cpu_store_16bit( _environment, "CLIPX2", 39 );
1064 cpu_store_16bit( _environment, "CLIPY1", 0 );
1065 cpu_store_16bit( _environment, "CLIPY2", 24 );
1066
1067 _environment->mspriteMsbokAddress = 0x83f8;
1068
1069 break;
1071 _environment->screenWidth = 160;
1072 _environment->screenHeight = 200;
1073 _environment->screenColors = 16;
1074 _environment->currentModeBW = 0;
1075 // Let's disable graphics!
1076 outline0("LDA $D011" );
1077 outline0("AND #%01011000");
1078 outline0("ORA #%00001011");
1079 outline0("STA $D011" );
1080 outline0("LDA $D016" );
1081 outline0("ORA #%00010000");
1082 outline0("STA $D016" );
1083 outline0("LDA $D018" );
1084 outline0("AND #%11110111");
1085 if ( _environment->fontConfig.schema || _environment->descriptors ) {
1086 outline0("ORA #$09");
1087 } else {
1088 outline0("ORA #$07");
1089 }
1090 outline0("STA $D018" );
1091
1092 // // This fix is necessary to reset the lookup for rom character.
1093 // outline0("LDA $D018" );
1094 // outline0("AND #%11110000");
1095 // if ( _environment->fontConfig.schema || _environment->descriptors ) {
1096 // outline0("ORA #$09");
1097 // } else {
1098 // outline0("ORA #$07");
1099 // }
1100 // outline0("STA $D018" );
1101
1102 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
1103
1104 cpu_store_8bit( _environment, "_PEN", 0x01 );
1105 cpu_store_8bit( _environment, "_PAPER", 0x00 );
1106 cpu_store_16bit( _environment, "CLIPX1", 0 );
1107 cpu_store_16bit( _environment, "CLIPX2", 39 );
1108 cpu_store_16bit( _environment, "CLIPY1", 0 );
1109 cpu_store_16bit( _environment, "CLIPY2", 24 );
1110
1111 _environment->mspriteMsbokAddress = 0x83f8;
1112
1113 break;
1115 _environment->screenWidth = 160;
1116 _environment->screenHeight = 200;
1117 _environment->screenColors = 16;
1118 _environment->currentModeBW = 0;
1119 // Let's disable graphics!
1120 outline0("LDA $D011" );
1121 outline0("AND #%01011111");
1122 outline0("ORA #%01001011");
1123 outline0("STA $D011" );
1124 outline0("LDA $D016" );
1125 outline0("AND #%11101111");
1126 outline0("STA $D016" );
1127 outline0("AND #%11110111");
1128 if ( _environment->fontConfig.schema || _environment->descriptors ) {
1129 outline0("ORA #$09");
1130 } else {
1131 outline0("ORA #$07");
1132 }
1133 outline0("STA $D018" );
1134
1135 // // This fix is necessary to reset the lookup for rom character.
1136 // outline0("LDA $D018" );
1137 // outline0("AND #%11110000");
1138 // if ( _environment->fontConfig.schema || _environment->descriptors ) {
1139 // outline0("ORA #$09");
1140 // } else {
1141 // outline0("ORA #$07");
1142 // }
1143 // outline0("STA $D018" );
1144
1145 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
1146
1147 cpu_store_8bit( _environment, "_PEN", 0x01 );
1148 cpu_store_8bit( _environment, "_PAPER", 0x00 );
1149 cpu_store_16bit( _environment, "CLIPX1", 0 );
1150 cpu_store_16bit( _environment, "CLIPX2", 39 );
1151 cpu_store_16bit( _environment, "CLIPY1", 0 );
1152 cpu_store_16bit( _environment, "CLIPY2", 24 );
1153
1154 _environment->mspriteMsbokAddress = 0x83f8;
1155
1156 break;
1157 default:
1158 CRITICAL_SCREEN_UNSUPPORTED( _screen_mode->id );
1159 }
1160
1161 _environment->screenTilesWidth = _environment->screenWidth / _environment->fontWidth;
1162 _environment->screenTilesHeight = 25;
1163 _environment->consoleTilesWidth = _environment->screenTilesWidth;
1164 _environment->consoleTilesHeight = _environment->screenTilesHeight;
1165
1166 cpu_store_16bit( _environment, "ORIGINX", 0 );
1167 cpu_store_16bit( _environment, "ORIGINY", 0 );
1168
1169 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
1170 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
1171 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
1172 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
1173 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
1174 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
1175 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
1176 cpu_store_8bit( _environment, "FONTWIDTH", _environment->fontWidth );
1177 cpu_store_8bit( _environment, "FONTHEIGHT", _environment->fontHeight );
1178
1179 console_init( _environment );
1180
1181 outline0( "LDA $D018" );
1182 outline0( "STA OLDD018" );
1183
1184}
1185
1186void console_calculate( Environment * _environment ) {
1187
1188 int consoleSA = 0;
1189 int consoleCA = 0;
1190
1191 switch( _environment->currentMode ) {
1193 consoleSA = plotVBase[_environment->activeConsole.y1*8]+plot8[_environment->activeConsole.x1];
1194 _environment->currentModeBW = 1;
1195 break;
1197 consoleSA = plotVBase[_environment->activeConsole.y1*8]+plot4[_environment->activeConsole.x1];
1198 _environment->currentModeBW = 2;
1199 break;
1203 consoleSA = 0x8400 + (_environment->activeConsole.y1*40)+_environment->activeConsole.x1;
1204 consoleCA = 0xD800 + (_environment->activeConsole.y1*40)+_environment->activeConsole.x1;
1205 _environment->currentModeBW = 1;
1206 break;
1207 default:
1209 }
1210
1211 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
1212 int consoleHB = _environment->activeConsole.height * 8;
1213
1214 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
1215 cpu_store_16bit( _environment, "CONSOLECA", consoleCA );
1216 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
1217 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
1218
1219}
1220
1221void console_calculate_vars( Environment * _environment ) {
1222
1224
1225 _environment->dynamicConsole = 1;
1226
1227 outline0( "JSR CONSOLECALCULATE" );
1228
1229}
1230
1231void vic2_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
1232
1233 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
1234
1235 if ( mode ) {
1236 vic2_screen_mode_enable( _environment, mode );
1237
1238 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
1239 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
1240
1241 _environment->currentMode = mode->id;
1242 _environment->currentTileMode = 0;
1243 } else {
1244 WARNING_SCREEN_MODE( -1 );
1245 }
1246}
1247
1248void vic2_bitmap_disable( Environment * _environment ) {
1249
1250 Variable * colormapAddress = variable_retrieve( _environment, "COLORMAPADDRESS" );
1251
1252 // Let's disable graphics!
1253 outline0("LDA $D011" );
1254 outline0("AND #%01011111");
1255 outline0("STA $D011" );
1256 outline0("LDA $D016" );
1257 outline0("AND #%11101111");
1258 outline0("STA $D016" );
1259
1260 cpu_store_16bit( _environment, colormapAddress->realName, 0xd800 );
1261
1262}
1263
1264void vic2_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
1265
1266 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
1267
1268 if ( mode ) {
1269
1270 vic2_screen_mode_enable( _environment, mode );
1271
1272 _environment->currentMode = mode->id;
1273 _environment->currentTileMode = 1;
1274
1275 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
1276 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
1277
1278 } else {
1279 WARNING_SCREEN_MODE( -1 );
1280 }
1281
1282}
1283
1284void vic2_bitmap_at( Environment * _environment, char * _address ) {
1285
1286 outline1("LDA %s", _address );
1287 outline0("LSR");
1288 outline0("LSR");
1289 outline0("LSR");
1290 outline0("LSR");
1291 outline0("LSR");
1292 outline0("LSR");
1293 outline0("AND #%00000001");
1294 outline0("ASL" );
1295 outline0("ASL" );
1296 outline0("ASL" );
1297 outline0("STA TMPPTR" );
1298 outline0("LDA $D018" );
1299 outline0("AND #%11110111");
1300 outline0("ORA TMPPTR" );
1301 outline0("STA $D018" );
1302
1303}
1304
1305void vic2_colormap_at( Environment * _environment, char * _address ) {
1306
1307 // Create a unique variabled for ASM code.
1309
1310 // Let's check if we are in ECM mode.
1311 outline0("LDA $D011");
1312 outline0("BIT #%00100000");
1313 cpu_beq(_environment, label);
1314
1315 // Change the colormap address that is the text address.
1316 vic2_textmap_at( _environment, _address );
1317
1318 // If not, we are unable to change the colormap address.
1319 outline1("%s:", label);
1320
1321
1322}
1323
1324void vic2_textmap_at( Environment * _environment, char * _address ) {
1325
1326 // Create a unique variabled for ASM code.
1328
1329 outline1("LDA %s", _address );
1330 outline0("LSR");
1331 outline0("LSR");
1332 outline0("AND #$0f");
1333 outline0("ASL");
1334 outline0("ASL");
1335 outline0("ASL");
1336 outline0("ASL");
1337 outline0("STA TMPPTR");
1338 outline0("LDA $D018");
1339 outline0("AND #%00001111");
1340 outline0("ORA TMPPTR" );
1341 outline0("STA $D018");
1342
1343}
1344
1345void vic2_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
1346
1347 deploy( vic2vars, src_hw_vic2_vars_asm);
1348 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
1350
1351 outline1("LDA %2.2x", (_x & 0xff ) );
1352 outline0("STA PLOTX");
1353 outline1("LDA %2.2x", ( ( _x >> 8 ) & 0xff ) );
1354 outline0("STA PLOTX+1");
1355 outline1("LDA %2.2x", ( _y & 0xff ) );
1356 outline0("STA PLOTY");
1357 if ( _c ) {
1358 outline1("LDA #$%2.2x", ( *_c & 0xff ) );
1359 } else {
1360 Variable * c = variable_retrieve( _environment, "PEN" );
1361 outline1("LDA %s", c->realName );
1362 }
1363 outline0("STA PLOTCPE");
1364 outline0("LDA #1");
1365 outline0("STA PLOTM");
1366 outline0("JSR PLOT");
1367
1368}
1369
1370void vic2_pset_vars( Environment * _environment, char *_x, char *_y, char * _c ) {
1371
1372 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
1373 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
1374 Variable * c;
1375
1376 if ( _c ) {
1377 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
1378 } else {
1379 c = variable_retrieve( _environment, "PEN" );
1380 }
1381
1382 deploy( vic2vars, src_hw_vic2_vars_asm);
1383 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
1385
1386 outline1("LDA %s", x->realName );
1387 outline0("STA PLOTX");
1388 if ( VT_BITWIDTH( x->type ) > 8 ) {
1389 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
1390 } else {
1391 outline0("LDA #0");
1392 }
1393 outline0("STA PLOTX+1");
1394 outline1("LDA %s", y->realName );
1395 outline0("STA PLOTY");
1396 outline1("LDA %s", c->realName );
1397 outline0("STA PLOTCPE");
1398 outline0("LDA #1");
1399 outline0("STA PLOTM");
1400 outline0("JSR PLOT");
1401
1402}
1403
1404void vic2_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
1405
1406 Variable * x = variable_retrieve( _environment, _x );
1407 Variable * y = variable_retrieve( _environment, _y );
1408 Variable * result = variable_retrieve( _environment, _result );
1409
1410 deploy( vic2vars, src_hw_vic2_vars_asm);
1411 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
1413
1414 outline1("LDA %s", x->realName );
1415 outline0("STA PLOTX");
1416 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
1417 outline0("STA PLOTX+1");
1418 outline1("LDA %s", y->realName );
1419 outline0("STA PLOTY");
1420 outline0("LDA #3");
1421 outline0("STA PLOTM");
1422 outline0("JSR PLOT");
1423 outline0("LDA PLOTM");
1424 outline1("STA %s", result->realName);
1425
1426}
1427
1428void vic2_screen_on( Environment * _environment ) {
1429
1430 outline0("LDA $D011" );
1431 outline0("ORA #%00010000");
1432 outline0("STA $D011" );
1433
1434}
1435
1436void vic2_screen_off( Environment * _environment ) {
1437
1438 outline0("LDA $D011" );
1439 outline0("AND #%01101111");
1440 outline0("STA $D011" );
1441
1442}
1443
1444void vic2_screen_rows( Environment * _environment, char * _rows ) {
1445
1447
1448 outline1("LDA %s", _rows);
1449 outline0("CMP #24");
1450 outline1("BEQ %s", label);
1451 outline0("LDA $D011" );
1452 outline0("ORA #%00001000");
1453 outline0("STA $D011" );
1454 outline1("JMP %s_2", label);
1455 outhead1("%s:", label );
1456 outline0("LDA $D011" );
1457 outline0("AND #%01110111");
1458 outline0("STA $D011" );
1459 outline1("JMP %s_2", label);
1460 outhead1("%s_2:", label );
1461
1462}
1463
1464void vic2_screen_columns( Environment * _environment, char * _columns ) {
1465
1467
1468 outline1("LDA %s", _columns);
1469 outline0("CMP #38");
1470 outline1("BEQ %s", label);
1471 outline0("LDA $D016" );
1472 outline0("ORA #%00001000");
1473 outline0("STA $D016" );
1474 outline1("JMP %s_2", label);
1475 outhead1("%s:", label );
1476 outline0("LDA $D016" );
1477 outline0("AND #%11110111");
1478 outline0("STA $D016" );
1479 outline1("JMP %s_2", label);
1480 outhead1("%s_2:", label );
1481
1482}
1483
1484void vic2_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
1485
1486 _environment->bitmaskNeeded = 1;
1487
1488 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1489 Variable * address = variable_retrieve_or_define( _environment, _address, VT_BYTE, 0 );
1490
1491 switch ( sprite->type) {
1492
1493 case VT_SPRITE:
1494
1496
1497 outline1("LDA %s", address->realName );
1498 outline1("LDY %s", sprite->realName );
1499 outline0("JSR SPRITEDATASET" );
1500 break;
1501
1502 case VT_MSPRITE:
1503
1504 break;
1505
1506 }
1507
1508
1509}
1510
1511void vic2_sprite_data_from( Environment * _environment, char * _sprite, char * _image ) {
1512
1513 _environment->bitmaskNeeded = 1;
1514
1515 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1516 Variable * image = variable_retrieve_or_define( _environment, _image, VT_IMAGE, 0 );
1517
1518 image->usedImage = 1;
1519
1520 outline1("LDA #<%s", image->realName );
1521 outline0("STA MATHPTR1" );
1522 outline1("LDA #>%s", image->realName );
1523 outline0("STA MATHPTR2" );
1524
1525 switch ( sprite->type) {
1526
1527 case VT_SPRITE:
1528
1530
1531 outline1("LDY %s", sprite->realName );
1532 outline0("JSR SPRITEDATAFROM" );
1533 break;
1534
1535 case VT_MSPRITE:
1536
1537 if ( !_environment->deployed.msprite ) {
1538 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1539 }
1540
1541 deploy( msprite, src_hw_vic2_msprites_asm );
1542
1543 outline1("LDY %s", sprite->realName );
1544 outline0("JSR MSPRITEDATAFROM" );
1545 break;
1546
1547 }
1548
1549}
1550
1551void vic2_sprite_duplicate( Environment * _environment, char * _sprite, char * _original ) {
1552
1553 _environment->bitmaskNeeded = 1;
1554
1555 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1556 Variable * original = variable_retrieve( _environment, _original );
1557
1558 switch ( original->type) {
1559
1560 case VT_SPRITE:
1561
1563
1564 case VT_MSPRITE:
1565
1566 if ( !_environment->deployed.msprite ) {
1567 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1568 }
1569
1570 deploy( msprite, src_hw_vic2_msprites_asm );
1571
1572 outline1("LDA %s", original->realName );
1573 outline0("STA MSPRITEDUPLICATEY0+1" );
1574
1575 outline1("LDA %s", sprite->realName );
1576 outline0("STA MSPRITEDUPLICATEY1+1" );
1577
1578 outline1("LDA %s", original->realName );
1579 outline0("STA MSPRITEDUPLICATEY2+1" );
1580
1581 outline1("LDA %s", sprite->realName );
1582 outline0("STA MSPRITEDUPLICATEY3+1" );
1583
1584 outline1("LDY %s", sprite->realName );
1585 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1586
1587 outline0("JSR MSPRITEDUPLICATE" );
1588 break;
1589
1590 }
1591
1592}
1593
1594void vic2_sprite_enable( Environment * _environment, char * _sprite ) {
1595
1596 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1597
1598 _environment->bitmaskNeeded = 1;
1599
1600 switch ( sprite->type) {
1601
1602 case VT_BYTE:
1603 case VT_SPRITE:
1604
1606
1607 outline1("LDY %s", sprite->realName );
1608 outline0("JSR SPRITEENABLE" );
1609 break;
1610
1611 case VT_MSPRITE:
1612
1613 if ( !_environment->deployed.msprite ) {
1614 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1615 }
1616
1617 deploy( msprite, src_hw_vic2_msprites_asm );
1618
1619 outline1("LDY %s", sprite->realName );
1620 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1621 outline0("JSR MSPRITEENABLE" );
1622 break;
1623
1624 }
1625
1626}
1627
1628void vic2_sprite_disable( Environment * _environment, char * _sprite ) {
1629
1630 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1631
1632 _environment->bitmaskNeeded = 1;
1633
1634 switch ( sprite->type) {
1635
1636 case VT_BYTE:
1637 case VT_SPRITE:
1638
1640
1641 outline1("LDY %s", sprite->realName );
1642 outline0("JSR SPRITEDISABLE" );
1643 break;
1644
1645 case VT_MSPRITE:
1646
1647 if ( !_environment->deployed.msprite ) {
1648 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1649 }
1650
1651 deploy( msprite, src_hw_vic2_msprites_asm );
1652
1653 outline1("LDY %s", sprite->realName );
1654 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1655 outline0("JSR MSPRITEDISABLE" );
1656 break;
1657
1658 }
1659
1660
1661}
1662
1663void vic2_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
1664
1665 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_SPRITE, 0 );
1666 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
1667 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
1668
1669 _environment->bitmaskNeeded = 1;
1670
1671 switch ( sprite->type) {
1672
1673 case VT_BYTE:
1674 case VT_SPRITE:
1675
1677
1678 outline1("LDA %s", x->realName );
1679 outline0("STA MATHPTR0" );
1680 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
1681 outline0("STA MATHPTR1" );
1682 outline0("LSR MATHPTR1" );
1683 outline0("ROR MATHPTR0" );
1684 outline1("LDX %s", y->realName );
1685 outline1("LDY %s", sprite->realName );
1686 outline0("JSR SPRITEAT" );
1687 break;
1688
1689 case VT_MSPRITE:
1690
1691 if ( !_environment->deployed.msprite ) {
1692 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1693 }
1694
1695 deploy( msprite, src_hw_vic2_msprites_asm );
1696
1697 outline1("LDA %s", x->realName );
1698 outline0("STA MATHPTR0" );
1699 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
1700 outline0("STA MATHPTR1" );
1701 outline0("LSR MATHPTR1" );
1702 outline0("ROR MATHPTR0" );
1703 outline1("LDA %s", y->realName );
1704 outline0("STA MATHPTR2" );
1705 outline1("LDY %s", sprite->realName );
1706 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1707 outline0("JSR MSPRITEAT" );
1708 break;
1709
1710 }
1711
1712
1713}
1714
1715void vic2_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
1716
1717 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1718
1719 switch ( sprite->type) {
1720
1721 case VT_BYTE:
1722 case VT_SPRITE:
1723
1725
1726 outline1("LDY %s", sprite->realName );
1727 outline0("JSR SPRITEEXPANDY" );
1728 break;
1729
1730 case VT_MSPRITE:
1731
1732 if ( !_environment->deployed.msprite ) {
1733 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1734 }
1735
1736 deploy( msprite, src_hw_vic2_msprites_asm );
1737
1738 outline1("LDY %s", sprite->realName );
1739 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1740 outline0("JSR MSPRITEEXPANDY" );
1741 break;
1742
1743 }
1744
1745
1746
1747
1748}
1749
1750void vic2_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
1751
1752 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1753
1754 switch ( sprite->type) {
1755
1756 case VT_BYTE:
1757 case VT_SPRITE:
1758
1760
1761 outline1("LDY %s", sprite->realName );
1762 outline0("JSR SPRITEEXPANDX" );
1763 break;
1764
1765 case VT_MSPRITE:
1766
1767 if ( !_environment->deployed.msprite ) {
1768 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1769 }
1770
1771 deploy( msprite, src_hw_vic2_msprites_asm );
1772
1773 outline1("LDY %s", sprite->realName );
1774 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1775 outline0("JSR MSPRITEEXPANDX" );
1776 break;
1777
1778 }
1779
1780}
1781
1782void vic2_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
1783
1784 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1785
1786 switch ( sprite->type) {
1787
1788 case VT_BYTE:
1789 case VT_SPRITE:
1790
1792
1793 outline1("LDY %s", sprite->realName );
1794 outline0("JSR SPRITECOMPRESSY" );
1795 break;
1796
1797 case VT_MSPRITE:
1798
1799 if ( !_environment->deployed.msprite ) {
1800 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1801 }
1802
1803 deploy( msprite, src_hw_vic2_msprites_asm );
1804
1805 outline1("LDY %s", sprite->realName );
1806 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1807 outline0("JSR MSPRITECOMPRESSY" );
1808 break;
1809
1810 }
1811
1812}
1813
1814void vic2_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
1815
1816 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1817
1818 switch ( sprite->type) {
1819
1820 case VT_BYTE:
1821 case VT_SPRITE:
1822
1824
1825 outline1("LDY %s", sprite->realName );
1826 outline0("JSR SPRITECOMPRESSX" );
1827 break;
1828
1829 case VT_MSPRITE:
1830
1831 if ( !_environment->deployed.msprite ) {
1832 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1833 }
1834
1835 deploy( msprite, src_hw_vic2_msprites_asm );
1836
1837 outline1("LDY %s", sprite->realName );
1838 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1839 outline0("JSR MSPRITECOMPRESSX" );
1840 break;
1841
1842 }
1843
1844}
1845
1846void vic2_sprite_multicolor( Environment * _environment, char * _sprite ) {
1847
1848 _environment->bitmaskNeeded = 1;
1849
1850 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1851
1852 switch ( sprite->type) {
1853
1854 case VT_BYTE:
1855 case VT_SPRITE:
1856
1858
1859 outline1("LDY %s", sprite->realName );
1860 outline0("JSR SPRITEMULTICOLOR" );
1861 break;
1862
1863 case VT_MSPRITE:
1864
1865 if ( !_environment->deployed.msprite ) {
1866 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1867 }
1868
1869 deploy( msprite, src_hw_vic2_msprites_asm );
1870
1871 outline1("LDY %s", sprite->realName );
1872 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1873 outline0("JSR MSPRITEMULTICOLOR" );
1874 break;
1875
1876 }
1877
1878
1879}
1880
1881void vic2_sprite_monocolor( Environment * _environment, char * _sprite ) {
1882
1883 _environment->bitmaskNeeded = 1;
1884
1885 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1886
1887 switch ( sprite->type) {
1888
1889 case VT_BYTE:
1890 case VT_SPRITE:
1891
1893
1894 outline1("LDY %s", sprite->realName );
1895 outline0("JSR SPRITEMONOCOLOR" );
1896 break;
1897
1898 case VT_MSPRITE:
1899
1900 if ( !_environment->deployed.msprite ) {
1901 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1902 }
1903
1904 deploy( msprite, src_hw_vic2_msprites_asm );
1905
1906 outline1("LDY %s", sprite->realName );
1907 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1908 outline0("JSR MSPRITEMONOCOLOR" );
1909 break;
1910
1911 }
1912
1913}
1914
1915void vic2_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
1916
1917 _environment->bitmaskNeeded = 1;
1918
1919 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1920 Variable * color = variable_retrieve_or_define( _environment, _color, VT_COLOR, COLOR_WHITE );
1921
1922 switch ( sprite->type) {
1923
1924 case VT_BYTE:
1925 case VT_SPRITE:
1926
1928
1929 outline1("LDA %s", color->realName );
1930 outline1("LDY %s", sprite->realName );
1931 outline0("JSR SPRITECOLOR" );
1932 break;
1933
1934 case VT_MSPRITE:
1935
1936 if ( !_environment->deployed.msprite ) {
1937 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1938 }
1939
1940 deploy( msprite, src_hw_vic2_msprites_asm );
1941
1942 outline1("LDA %s", color->realName );
1943 outline1("LDY %s", sprite->realName );
1944 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1945 outline0("JSR MSPRITECOLOR" );
1946 break;
1947
1948 }
1949
1950
1951}
1952
1953void vic2_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
1954
1955 _environment->bitmaskNeeded = 1;
1956
1957 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1958 Variable * priority = variable_retrieve_or_define( _environment, _priority, VT_BYTE, 0 );
1959
1960 switch ( sprite->type) {
1961
1962 case VT_BYTE:
1963 case VT_SPRITE:
1964
1966
1967 outline1("LDA %s", priority->realName );
1968 outline1("LDY %s", sprite->realName );
1969 outline0("JSR SPRITEPRIORITY" );
1970 break;
1971
1972 case VT_MSPRITE:
1973
1974 if ( !_environment->deployed.msprite ) {
1975 cpu_store_16bit( _environment, "MSPRITESMANAGER2MSBOKADDRESS+1", _environment->mspriteMsbokAddress );
1976 }
1977
1978 deploy( msprite, src_hw_vic2_msprites_asm );
1979
1980 outline1("LDA %s", priority->realName );
1981 outline1("LDY %s", sprite->realName );
1982 outline1("LDX %s", address_displacement( _environment, sprite->realName, "1" ) );
1983 outline0("JSR MSPRITEPRIORITY" );
1984 break;
1985
1986 }
1987
1988
1989}
1990
1991void vic2_tiles_at( Environment * _environment, char * _address ) {
1992
1993 outline1("LDA %s", _address);
1994 outline0("LSR");
1995 outline0("LSR");
1996 outline0("LSR");
1997 outline0("AND #$07");
1998 outline0("ASL");
1999 outline0("STA TMPPTR");
2000 outline0("LDA $D018");
2001 outline0("AND #%00001111");
2002 outline0("ORA TMPPTR");
2003 outline0("STA $D018");
2004
2005}
2006
2007void vic2_vertical_scroll( Environment * _environment, char * _displacement ) {
2008
2009 outline0("LDA $D011" );
2010 outline0("AND #%01111000");
2011 outline1("ORA %s", _displacement );
2012 outline0("STA $D011" );
2013
2014}
2015
2016void vic2_horizontal_scroll( Environment * _environment, char * _displacement ) {
2017
2018 outline0("LDA $D016" );
2019 outline0("AND #%11111000");
2020 outline1("ORA %s", _displacement );
2021 outline0("STA $D016" );
2022
2023}
2024
2025void vic2_busy_wait( Environment * _environment, char * _timing ) {
2026
2028
2029 outline1("LDA %s", _timing );
2030 outline0("STA TMPPTR");
2031 outline1("LDA %s", address_displacement(_environment, _timing, "1") );
2032 outline0("STA TMPPTR+1");
2033 outhead1("%sfirst:", label );
2034 outline0("LDA $D011");
2035 outline0("AND #$80");
2036 outline1("BEQ %ssecond", label);
2037 outhead1("%ssecond:", label );
2038 outline0("LDA $D011");
2039 outline0("AND #$80");
2040 outline1("BNE %ssecond", label);
2041 outhead1("%sthird:", label );
2042 outline0("LDA $D011");
2043 outline0("AND #$80");
2044 outline1("BEQ %sthird", label);
2045 outhead1("%sfourth:", label );
2046 outline0("LDA $D011");
2047 outline0("AND #$80");
2048 outline1("BNE %sfourth", label);
2049 outline0("DEC TMPPTR");
2050 outline0("LDA TMPPTR");
2051 outline0("CMP #$FF");
2052 outline1("BNE %sfirst", label);
2053 outline0("DEC TMPPTR+1");
2054 outline0("LDA TMPPTR+1");
2055 outline0("CMP #$FF");
2056 outline1("BNE %sfirst", label);
2057
2058}
2059
2060void vic2_get_width( Environment * _environment, char *_result ) {
2061
2062 outline0("LDA CURRENTWIDTH" );
2063 outline1("STA %s", _result );
2064 outline0("LDA CURRENTWIDTH+1" );
2065 outline1("STA %s", address_displacement(_environment, _result, "1") );
2066
2067}
2068
2069void vic2_tiles_get( Environment * _environment, char *_result ) {
2070
2071 outline0("LDA CURRENTTILES" );
2072 outline1("STA %s", _result );
2073
2074}
2075
2076void vic2_get_height( Environment * _environment, char *_result ) {
2077
2078 outline0("LDA CURRENTHEIGHT" );
2079 outline1("STA %s", _result );
2080 outline0("LDA CURRENTHEIGHT+1" );
2081 outline1("STA %s", address_displacement(_environment, _result, "1") );
2082
2083}
2084
2085void vic2_cls( Environment * _environment ) {
2086
2087 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
2089 outline0("JSR CLSG");
2090 } else {
2092 outline0("JSR CLST");
2093 }
2094
2095}
2096
2097void vic2_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
2098
2099 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
2100 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
2102
2103 outline1("LDA %s", _x1);
2104 outline0("STA IMAGEX");
2105 outline1("LDA %s", address_displacement( _environment, _x1, "1" ) );
2106 outline0("STA IMAGEX+1");
2107 outline1("LDA %s", _y1);
2108 outline0("STA IMAGEY");
2109 outline1("LDA %s",_w );
2110 outline0("STA IMAGEW");
2111 outline1("LDA %s", address_displacement( _environment, _w, "1" ) );
2112 outline0("STA IMAGEW+1");
2113 outline1("LDA %s", _h);
2114 outline0("STA IMAGEH");
2115 outline0("JSR CLSBOX");
2116 } else {
2117
2118 }
2119
2120}
2121
2122void vic2_scroll_text( Environment * _environment, int _direction, int _overlap ) {
2123
2124 if ( _environment->currentMode == 0 || _environment->currentMode == 1 ) {
2125 if ( _direction > 0 ) {
2127 outline1("LDA $%2.2x", (unsigned char)(_overlap&0xff) )
2128 outline0("STA PORT");
2129 outline0("JSR VSCROLLTDOWN");
2130 } else {
2132 outline1("LDA $%2.2x", (unsigned char)(_overlap&0xff) )
2133 outline0("STA PORT");
2134 outline0("JSR VSCROLLTUP");
2135 }
2136 }
2137
2138}
2139
2140void vic2_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
2141
2142 deploy( vic2vars, src_hw_vic2_vars_asm);
2143 deploy( textEncodedAt, src_hw_vic2_text_at_asm );
2144
2145 outline1("LDA %s", _text);
2146 outline0("STA TEXTPTR" );
2147 outline1("LDA %s", address_displacement(_environment, _text, "1"));
2148 outline0("STA TEXTPTR+1" );
2149 outline1("LDA %s", _text_size);
2150 outline0("STA TEXTSIZE" );
2151
2152 if ( _raw ) {
2153 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
2155 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
2156 deploy_deferred( textEncodedAtGraphicRaw, src_hw_vic2_text_at_graphic_raw_asm );
2157 outline0("JSR TEXTATBITMAPMODERAW");
2158 } else {
2159 deploy( clsText, src_hw_vic2_cls_text_asm );
2161 deploy_deferred( textEncodedAtTextRaw, src_hw_vic2_text_at_text_raw_asm );
2162 outline0("JSR TEXTATTILEMODERAW");
2163 }
2164 } else {
2165 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
2167 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
2168 deploy_deferred( textEncodedAtGraphic, src_hw_vic2_text_at_graphic_asm );
2169 outline0("JSR TEXTATBITMAPMODE");
2170 } else {
2171 deploy( clsText, src_hw_vic2_cls_text_asm );
2173 deploy_deferred( textEncodedAtText, src_hw_vic2_text_at_text_asm );
2174 outline0("JSR TEXTATTILEMODE");
2175 }
2176 }
2177
2178}
2179
2180void vic2_initialization( Environment * _environment ) {
2181
2184
2185 variable_import( _environment, "CURRENTMODE", VT_BYTE, 0 );
2186 variable_global( _environment, "CURRENTMODE" );
2187 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
2188 variable_global( _environment, "CURRENTTILEMODE" );
2189
2190 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 320 );
2191 variable_global( _environment, "CURRENTWIDTH" );
2192 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 200 );
2193 variable_global( _environment, "CURRENTHEIGHT" );
2194 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
2195 variable_global( _environment, "CURRENTTILES" );
2196 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 40 );
2197 variable_global( _environment, "CURRENTTILESWIDTH" );
2198 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 25 );
2199 variable_global( _environment, "CURRENTTILESHEIGHT" );
2200 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
2201 variable_global( _environment, "FONTWIDTH" );
2202 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
2203 variable_global( _environment, "FONTHEIGHT" );
2204
2205 if ( !_environment->vestigialConfig.rchack_4gravity_1164 ) {
2206 SCREEN_MODE_DEFINE( BITMAP_MODE_STANDARD, 1, 320, 200, 2, 8, 8, "Standard Bitmap Mode" );
2207 }
2208 SCREEN_MODE_DEFINE( BITMAP_MODE_MULTICOLOR, 1, 160, 200, 4, 8, 8, "Multicolor Bitmap Mode" );
2209 SCREEN_MODE_DEFINE( TILEMAP_MODE_STANDARD, 0, 40, 25, 16, 8, 8, "Standard Character Mode" );
2210 SCREEN_MODE_DEFINE( TILEMAP_MODE_MULTICOLOR, 0, 40, 25, 32, 8, 8, "Multicolor Character Mode" );
2211 SCREEN_MODE_DEFINE( TILEMAP_MODE_EXTENDED, 0, 40, 25, 20, 8, 8, "Extended Multicolor Character Mode" );
2212
2213 outline0("JSR VIC2STARTUP");
2214
2215 variable_import( _environment, "XGR", VT_POSITION, 0 );
2216 variable_global( _environment, "XGR" );
2217 variable_import( _environment, "YGR", VT_POSITION, 0 );
2218 variable_global( _environment, "YGR" );
2219 variable_import( _environment, "LINE", VT_WORD, (unsigned short) (0xffff) );
2220 variable_global( _environment, "LINE" );
2221 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
2222 variable_global( _environment, "TABCOUNT" );
2223
2224 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
2225 variable_global( _environment, "CLIPX1" );
2226 variable_import( _environment, "CLIPX2", VT_POSITION, 319 );
2227 variable_global( _environment, "CLIPX2" );
2228 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
2229 variable_global( _environment, "CLIPY1" );
2230 variable_import( _environment, "CLIPY2", VT_POSITION, 199 );
2231 variable_global( _environment, "CLIPY2" );
2232
2233 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
2234 variable_global( _environment, "ORIGINX" );
2235 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
2236 variable_global( _environment, "ORIGINY" );
2237
2238 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
2239 variable_global( _environment, "RESOLUTIONX" );
2240 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
2241 variable_global( _environment, "RESOLUTIONY" );
2242
2243 variable_import( _environment, "XSCROLLPOS", VT_BYTE, 4 );
2244 variable_global( _environment, "XSCROLLPOS" );
2245 variable_import( _environment, "YSCROLLPOS", VT_BYTE, 4 );
2246 variable_global( _environment, "YSCROLLPOS" );
2247 variable_import( _environment, "XSCROLL", VT_BYTE, 0 );
2248 variable_global( _environment, "XSCROLL" );
2249 variable_import( _environment, "YSCROLL", VT_BYTE, 0 );
2250 variable_global( _environment, "YSCROLL" );
2251
2252 variable_import( _environment, "SPRITECOUNT", VT_SPRITE, 0 );
2253 variable_global( _environment, "SPRITECOUNT" );
2254
2255 _environment->fontWidth = 8;
2256 _environment->fontHeight = 8;
2257 _environment->screenTilesWidth = 40;
2258 _environment->screenTilesHeight = 25;
2259 _environment->screenWidth = _environment->screenTilesWidth * 8;
2260 _environment->screenHeight = _environment->screenTilesHeight * 8;
2261
2262 console_init( _environment );
2263
2264 font_descriptors_init( _environment, 1 );
2265
2266 _environment->currentRgbConverterFunction = rgbConverterFunction;
2267 _environment->screenShades = 16;
2268 _environment->screenColors = 16;
2269
2270 outline0("JSR VIC2FINALIZATION");
2271
2272 vic2_tilemap_enable( _environment, 40, 25, 16, 8, 8 );
2273
2274 reset_screen_mode_selected( _environment );
2275
2276 if (_environment->vestigialConfig.clsImplicit ) {
2277 vic2_cls( _environment );
2278 }
2279}
2280
2281static RGBi * multicolorSpritePalette[2];
2282
2283void vic2_finalization( Environment * _environment ) {
2284
2285 outhead0("VIC2FINALIZATION:");
2286
2287 if ( multicolorSpritePalette[0] ) {
2288 outline1("LDA #$%2.2x", multicolorSpritePalette[0]->index );
2289 outline0("STA $D025" );
2290 }
2291
2292 if ( multicolorSpritePalette[1] ) {
2293 outline1("LDA #$%2.2x", multicolorSpritePalette[1]->index );
2294 outline0("STA $D026" );
2295 }
2296
2297 // This fix is necessary to reset the lookup for rom character.
2298 outline0("LDA $D018" );
2299 outline0("AND #%11110000");
2300 if ( _environment->fontConfig.schema || _environment->descriptors ) {
2301 outline0("ORA #$09");
2302 } else {
2303 outline0("ORA #$07");
2304 }
2305 outline0("STA $D018" );
2306
2307 outline0("RTS");
2308
2309 if ( _environment->copperList ) {
2310 int anon = 0;
2311 CopperList * copperList = _environment->copperList;
2312 while( copperList ) {
2313 if ( !copperList->name ) {
2314 anon = 1;
2315 }
2316 CopperInstruction * actual = copperList->first;
2317 int currentLine = 0;
2318 outhead1("COPPERLIST%s0000:", copperList->name ? copperList->name : "" );
2319 while( actual ) {
2320 switch( actual->operation ) {
2321 case COP_NOP:
2322 outline0("NOP");
2323 break;
2324 case COP_WAIT:
2325 if ( actual->param1 > 0 ) {
2326 if ( actual->param1 > currentLine ) {
2327 outline1("LDA #$%2.2x", (unsigned char)( actual->param1 & 0xff ) );
2328 outline0("STA $D012" );
2329 if ( ( actual->param1 >> 8 ) & 0x01 ) {
2330 outline0("LDA $D011" );
2331 outline0("ORA #$80" );
2332 } else {
2333 outline0("LDA $D011" );
2334 outline0("AND #$7F" );
2335 }
2336 outline0("STA $D011" );
2337 outline2("LDA #<COPPERLIST%s%4.4x", copperList->name ? copperList->name : "", actual->param1 );
2338 outline0("STA COPPERLISTJUMP+1" );
2339 outline2("LDA #>COPPERLIST%s%4.4x", copperList->name ? copperList->name : "", actual->param1 );
2340 outline0("STA COPPERLISTJUMP+2" );
2341 outline0("RTS");
2342 outhead2("COPPERLIST%s%4.4x:", copperList->name ? copperList->name : "", actual->param1 );
2343 currentLine = actual->param1;
2344 }
2345 }
2346 break;
2347 case COP_MOVE_DWORD:
2348 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff )+3 );
2349 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+3 );
2350 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff )+2 );
2351 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+2 );
2352 case COP_MOVE_WORD:
2353 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff )+1 );
2354 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+1 );
2355 case COP_MOVE_BYTE:
2356 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff ) );
2357 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff ) );
2358 break;
2359 case COP_STORE_DWORD:
2360 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 >> 24 ) & 0xff ) );
2361 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+3 );
2362 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 >> 16 ) & 0xff ) );
2363 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+2 );
2364 case COP_STORE_WORD:
2365 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 >> 8 ) & 0xff ) );
2366 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+1 );
2367 case COP_STORE_BYTE:
2368 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 ) & 0xff ) );
2369 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff ) );
2370 break;
2371 case COP_COLOR:
2372 vic2_background_color( _environment, actual->param1, actual->param2 );
2373 break;
2375 vic2_background_color( _environment, 0, actual->param1 );
2376 break;
2377 case COP_COLOR_BORDER:
2378 vic2_border_color( _environment, actual->param1 );
2379 break;
2380 }
2381 actual = actual->next;
2382 }
2383 outhead1("COPPERACTIVATE%s:", copperList->name ? copperList->name : "" );
2384 outline0("LDA #$0" );
2385 outline0("STA $D012" );
2386 outline0("LDA $D011" );
2387 outline0("AND #$7F" );
2388 outline0("STA $D011" );
2389 outline1("LDA #<COPPERLIST%s0000", copperList->name ? copperList->name : "" );
2390 outline0("STA COPPERLISTJUMP+1" );
2391 outline1("LDA #>COPPERLIST%s0000", copperList->name ? copperList->name : "" );
2392 outline0("STA COPPERLISTJUMP+2" );
2393 outline0("RTS");
2394 copperList = copperList->next;
2395 }
2396 if ( ! anon ) {
2397 outhead0("COPPERLIST0000:" );
2398 outline0("RTS");
2399 }
2400 }
2401
2402}
2403
2404void vic2_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
2405
2407
2408 Variable * y = variable_retrieve( _environment, "YCURSYS" );
2409 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
2410 outline0("STA DIRECTION" );
2411 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
2412 outline0("STA PORT" );
2413 outline1("LDA %s", y->realName );
2414 outline0("STA CLINEY");
2415 outline0("JSR HSCROLLLT");
2416
2417}
2418
2419void vic2_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
2420
2422
2423 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
2424 outline0("STA DIRECTION" );
2425 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
2426 outline0("STA PORT" );
2427 outline0("JSR HSCROLLST");
2428
2429}
2430
2431void vic2_back( Environment * _environment ) {
2432
2434
2435 outline0("JSR BACK");
2436
2437}
2438
2439void vic2_cline( Environment * _environment, char * _characters ) {
2440
2441 Variable * x = variable_retrieve( _environment, "XCURSYS" );
2442 Variable * y = variable_retrieve( _environment, "YCURSYS" );
2443
2444 if ( _characters ) {
2445 outline1("LDA %s", _characters);
2446 } else {
2447 outline0("LDA #0");
2448 }
2449 outline0("STA CHARACTERS");
2450 outline1("LDA %s", x->realName );
2451 outline0("STA CLINEX" );
2452 outline1("LDA %s", y->realName );
2453 outline0("STA CLINEY");
2454
2455 if ( _environment->currentMode == 2 || _environment->currentMode == 3 ) {
2456 deploy( textClineGraphic, src_hw_vic2_cline_graphic_asm );
2457 outline0("JSR CLINEG");
2458 } else {
2459 deploy( textCline, src_hw_vic2_cline_text_asm );
2460 outline0("JSR CLINE");
2461 }
2462
2463}
2464
2465int vic2_image_size( Environment * _environment, int _width, int _height, int _mode ) {
2466
2467 switch( _mode ) {
2468
2470
2471 return 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) );
2472
2474
2475 return 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1;
2476
2477 case BITMAP_MODE_AH:
2478 case BITMAP_MODE_AIFLI:
2480 case BITMAP_MODE_ECI:
2481 case BITMAP_MODE_IAFLI:
2482 case BITMAP_MODE_IH:
2483 case BITMAP_MODE_MRFLI:
2485 case BITMAP_MODE_MUCSUH:
2486 case BITMAP_MODE_MUFLI:
2487 case BITMAP_MODE_MUIFLI:
2488 case BITMAP_MODE_NUFLI:
2489 case BITMAP_MODE_NUIFLI:
2490 case BITMAP_MODE_SH:
2491 case BITMAP_MODE_SHFLI:
2492 case BITMAP_MODE_SHI:
2493 case BITMAP_MODE_SHIFLI:
2494 case BITMAP_MODE_SHIFXL:
2495 case BITMAP_MODE_UFLI:
2496 case BITMAP_MODE_UIFLI:
2497 case BITMAP_MODE_TRIFLI:
2498 case BITMAP_MODE_XFLI:
2499 case BITMAP_MODE_XIFLI:
2500 case BITMAP_MODE_FLI:
2501 case BITMAP_MODE_HCB:
2502 case BITMAP_MODE_IFLI:
2503 case BITMAP_MODE_MUCSU:
2504 case BITMAP_MODE_MCI:
2506 case BITMAP_MODE_PRS:
2510 break;
2511 }
2512
2513 return 0;
2514
2515}
2516
2517static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2518
2519 switch( _mode ) {
2520
2522
2523 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) ) * _frames;
2524
2526
2527 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1 ) * _frames;
2528
2529 case BITMAP_MODE_AH:
2530 case BITMAP_MODE_AIFLI:
2532 case BITMAP_MODE_ECI:
2533 case BITMAP_MODE_IAFLI:
2534 case BITMAP_MODE_IH:
2535 case BITMAP_MODE_MRFLI:
2537 case BITMAP_MODE_MUCSUH:
2538 case BITMAP_MODE_MUFLI:
2539 case BITMAP_MODE_MUIFLI:
2540 case BITMAP_MODE_NUFLI:
2541 case BITMAP_MODE_NUIFLI:
2542 case BITMAP_MODE_SH:
2543 case BITMAP_MODE_SHFLI:
2544 case BITMAP_MODE_SHI:
2545 case BITMAP_MODE_SHIFLI:
2546 case BITMAP_MODE_SHIFXL:
2547 case BITMAP_MODE_UFLI:
2548 case BITMAP_MODE_UIFLI:
2549 case BITMAP_MODE_TRIFLI:
2550 case BITMAP_MODE_XFLI:
2551 case BITMAP_MODE_XIFLI:
2552 case BITMAP_MODE_FLI:
2553 case BITMAP_MODE_HCB:
2554 case BITMAP_MODE_IFLI:
2555 case BITMAP_MODE_MUCSU:
2556 case BITMAP_MODE_MCI:
2558 case BITMAP_MODE_PRS:
2562 break;
2563 }
2564
2565 return 0;
2566
2567}
2568
2569static int calculate_sequences_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2570
2571 switch( _mode ) {
2572
2574
2575 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) ) * _frames ) * _sequences;
2576
2578
2579 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) + 2 * ( ( _width >> 2 ) * ( _height >> 3 ) ) + 1 ) * _frames ) * _sequences;
2580
2581 case BITMAP_MODE_AH:
2582 case BITMAP_MODE_AIFLI:
2584 case BITMAP_MODE_ECI:
2585 case BITMAP_MODE_IAFLI:
2586 case BITMAP_MODE_IH:
2587 case BITMAP_MODE_MRFLI:
2589 case BITMAP_MODE_MUCSUH:
2590 case BITMAP_MODE_MUFLI:
2591 case BITMAP_MODE_MUIFLI:
2592 case BITMAP_MODE_NUFLI:
2593 case BITMAP_MODE_NUIFLI:
2594 case BITMAP_MODE_SH:
2595 case BITMAP_MODE_SHFLI:
2596 case BITMAP_MODE_SHI:
2597 case BITMAP_MODE_SHIFLI:
2598 case BITMAP_MODE_SHIFXL:
2599 case BITMAP_MODE_UFLI:
2600 case BITMAP_MODE_UIFLI:
2601 case BITMAP_MODE_TRIFLI:
2602 case BITMAP_MODE_XFLI:
2603 case BITMAP_MODE_XIFLI:
2604 case BITMAP_MODE_FLI:
2605 case BITMAP_MODE_HCB:
2606 case BITMAP_MODE_IFLI:
2607 case BITMAP_MODE_MUCSU:
2608 case BITMAP_MODE_MCI:
2610 case BITMAP_MODE_PRS:
2614 break;
2615 }
2616
2617 return 0;
2618
2619}
2620
2621static Variable * vic2_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 ) {
2622
2623 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
2624
2625 if ( _environment->freeImageWidth ) {
2626 if ( _width % 8 ) {
2627 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2628 }
2629 if ( _frame_width % 8 ) {
2630 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2631 }
2632 }
2633
2634 if ( _environment->freeImageHeight ) {
2635 if ( _height % 8 ) {
2636 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
2637 }
2638 if ( _frame_height % 8 ) {
2639 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
2640 }
2641 }
2642
2643 RGBi * palette = malloc_palette( MAX_PALETTE );
2644
2645 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2646
2647 if (paletteColorCount > 16) {
2648 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
2649 }
2650
2651 int i, j, k;
2652
2653 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2654 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
2655 lastUsedSlotInCommonPalette = paletteColorCount;
2656 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
2657
2658 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE) / sizeof(RGBi)), SYSTEM_PALETTE );
2659
2660 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2662 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
2663
2664 int bufferSize = vic2_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_STANDARD );
2665
2666 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_STANDARD );
2667
2668 // printf("bufferSize = %d\n", bufferSize );
2669
2670 char * buffer = malloc ( bufferSize );
2671 memset( buffer, 0, bufferSize );
2672
2673 // Position of the pixel in the original image
2674 int image_x, image_y;
2675
2676 // Position of the pixel, in terms of tiles
2677 int tile_x, tile_y;
2678
2679 // Position of the pixel, in terms of offset and bitmask
2680 int offset, bitmask;
2681
2682 // Color of the pixel to convert
2683 RGBi rgb;
2684
2685 *(buffer) = ( _frame_width & 0xff );
2686 *(buffer+1) = ( (_frame_width>>8) & 0xff );
2687 *(buffer+2) = _frame_height;
2688
2689 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2690
2691 vic2_image_converter_tiles( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width );
2692
2693 // printf("----\n");
2694
2695 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2696
2697 // printf("----\n");
2698
2699 return result;
2700
2701}
2702
2703static Variable * vic2_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 ) {
2704
2705 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
2706
2707 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
2708
2709 if ( _environment->freeImageWidth ) {
2710 if ( _width % 8 ) {
2711 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2712 }
2713 if ( _frame_width % 8 ) {
2714 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2715 }
2716 }
2717
2718 if ( _environment->freeImageHeight ) {
2719 if ( _height % 8 ) {
2720 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
2721 }
2722 if ( _frame_height % 8 ) {
2723 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
2724 }
2725 }
2726
2727 RGBi * palette = malloc_palette( MAX_PALETTE );
2728
2729 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2730
2731 if (paletteColorCount > 16) {
2732 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
2733 }
2734
2735 int i, j, k;
2736
2737 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2738 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
2739 lastUsedSlotInCommonPalette = paletteColorCount;
2740 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
2741
2742 adilinepalette( "CPMS:%d", (int) (sizeof(SYSTEM_PALETTE) / sizeof(RGBi)), SYSTEM_PALETTE );
2743
2744 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2746 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
2747
2748 int bufferSize = vic2_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_MULTICOLOR );
2749
2750 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_MULTICOLOR );
2751
2752 char * buffer = malloc ( bufferSize );
2753 memset( buffer, 0, bufferSize );
2754
2755 // Position of the pixel in the original image
2756 int image_x, image_y;
2757
2758 // Position of the pixel, in terms of tiles
2759 int tile_x, tile_y;
2760
2761 // Position of the pixel, in terms of offset and bitmask
2762 int offset, offsetc, bitmask;
2763
2764 // Color of the pixel to convert
2765 RGBi rgb;
2766
2767 *(buffer) = ( _frame_width & 0xff );
2768 *(buffer+1) = ( _frame_width >> 8 ) & 0xff;
2769 *(buffer+2) = _frame_height;
2770
2771 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2772
2773 int colorBackground = 0;
2774
2775 if ( (_flags & FLAG_EXACT) == 0 ) {
2776 int colorCount[16];
2777 memset(colorCount, 0, 16 * sizeof( int ) );
2778 char * tmpSource = _source;
2779 for( int y = 0; y < _frame_height; ++y ) {
2780 for( int x = 0; x < _frame_width; ++x ) {
2781 RGBi rgb;
2782 rgb.red = *tmpSource;
2783 rgb.green = *(tmpSource + 1);
2784 rgb.blue = *(tmpSource + 2);
2785 if ( _depth > 3 ) {
2786 rgb.alpha = *(tmpSource + 3);
2787 } else {
2788 rgb.alpha = 255;
2789 }
2790 if ( rgb.alpha == 0 ) {
2791 rgb.red = 0;
2792 rgb.green = 0;
2793 rgb.blue = 0;
2794 }
2795 RGBi * systemColor = vic2_image_nearest_system_color( &rgb );
2796 ++colorCount[systemColor->index];
2797
2798 tmpSource += _depth;
2799 }
2800
2801 tmpSource += _depth * ( _width - _frame_width );
2802 }
2803
2804 int colorBackgroundMax = 0;
2805 for( int i=0; i<16; ++i ) {
2806 if ( colorBackgroundMax < colorCount[i] ) {
2807 colorBackground = i;
2808 colorBackgroundMax = colorCount[i];
2809 }
2810 }
2811
2812 } else {
2813 char * tmpSource = _source;
2814 RGBi rgb;
2815 rgb.red = *tmpSource;
2816 rgb.green = *(tmpSource + 1);
2817 rgb.blue = *(tmpSource + 2);
2818 if ( _depth > 3 ) {
2819 rgb.alpha = *(tmpSource + 3);
2820 } else {
2821 rgb.alpha = 255;
2822 }
2823 if ( rgb.alpha == 0 ) {
2824 rgb.red = 0;
2825 rgb.green = 0;
2826 rgb.blue = 0;
2827 }
2828 RGBi * systemColor = vic2_image_nearest_system_color( &rgb );
2829 colorBackground = rgb.index;
2830 }
2831
2832 vic2_image_converter_tiles_multicolor( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width, colorBackground );
2833
2834 *(buffer+bufferSize-1) = colorBackground;
2835
2836 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2837
2838 return result;
2839
2840}
2841
2842static Variable * vic2_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 ) {
2843
2844 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
2845
2846 if ( _environment->freeImageWidth ) {
2847 if ( _width % 8 ) {
2848 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2849 }
2850 if ( _frame_width % 8 ) {
2851 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2852 }
2853 }
2854
2855 if ( _environment->freeImageHeight ) {
2856 if ( _height % 8 ) {
2857 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
2858 }
2859 if ( _frame_height % 8 ) {
2860 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
2861 }
2862 }
2863
2864 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
2865
2866 RGBi palette[MAX_PALETTE];
2867
2868 int colorUsed = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, (_flags & FLAG_EXACT) /* sorted */ );
2869
2870 commonPalette = palette_match( palette, colorUsed, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2871 commonPalette = palette_remove_duplicates( commonPalette, colorUsed, &colorUsed );
2872 adilinepalette( "CPM1:%d", colorUsed, commonPalette );
2873
2874 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE) / sizeof(RGBi)), SYSTEM_PALETTE );
2875
2876 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2877 result->originalColors = colorUsed;
2878 memcpy( result->originalPalette, commonPalette, colorUsed * sizeof( RGBi ) );
2879
2880 int bufferSize;
2881
2882 if ( colorUsed == 2 ) {
2883 bufferSize = 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) + 1;
2884 } else {
2885 bufferSize = 3 + 2* ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) );
2886 }
2887
2888 // printf("bufferSize = %d\n", bufferSize );
2889
2890 char * buffer = malloc ( bufferSize );
2891 memset( buffer, 0, bufferSize );
2892
2893 // Position of the pixel in the original image
2894 int image_x, image_y;
2895
2896 // Position of the pixel, in terms of tiles
2897 int tile_x, tile_y;
2898
2899 // Position of the pixel, in terms of offset and bitmask
2900 int offset, bitmask;
2901
2902 // Color of the pixel to convert
2903 RGBi rgb;
2904
2905 *(buffer) = _frame_width;
2906 *(buffer+1) = _frame_height;
2907
2908 if ( colorUsed > 2 ) {
2909 *(buffer+2) = 1;
2910 } else {
2911 *(buffer+2) = 0;
2912 }
2913
2914 int cx=0,cy=0;
2915
2916 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2917
2918 // commonTileDescriptors = precalculate_tile_descriptors_for_font( data_fontvic1_bin );
2919
2920 for( cy=0; cy<(_frame_height >> 3);++cy) {
2921 for( cx=0; cx<(_frame_width >> 3);++cx) {
2922
2923 char *source = _source + ( ( cy * 8 * _width ) + cx * 8 ) * _depth;
2924
2925 TileData tileData;
2926 memset(&tileData,0,sizeof(TileData));
2927
2928 int mostFrequentColor[16];
2929 memset(&mostFrequentColor[0],0,sizeof(int)*16);
2930
2931 int colorIndex = 0;
2932
2933 // Loop for all the source surface.
2934 for (image_y = 0; image_y < 8; ++image_y) {
2935 for (image_x = 0; image_x < 8; ++image_x) {
2936
2937 // Take the color of the pixel
2938 rgb.red = *source;
2939 rgb.green = *(source + 1);
2940 rgb.blue = *(source + 2);
2941 if ( _depth > 3 ) {
2942 rgb.alpha = *(_source + 3);
2943 } else {
2944 rgb.alpha = 255;
2945 }
2946
2947 if ( rgb.alpha < 255 ) {
2948 colorIndex = commonPalette[0].index;
2949 } else {
2950
2951 int minDistance = 9999;
2952 for( int i=0; i<colorUsed; ++i ) {
2953 int distance = rgbi_distance(&commonPalette[i], &rgb );
2954 if ( distance < minDistance ) {
2955 minDistance = distance;
2956 colorIndex = commonPalette[i].index;
2957 }
2958 }
2959
2960 }
2961
2962 mostFrequentColor[colorIndex]++;
2963
2964 // printf("%d", i );
2965
2966 // Calculate the relative tile
2967
2968 // Calculate the offset starting from the tile surface area
2969 // and the bit to set.
2970 offset = (image_y & 0x07);
2971 bitmask = 1 << ( 7 - (image_x & 0x7) );
2972
2973 if ( !colorIndex ) {
2974 tileData.data[offset] &= ~bitmask;
2975 // printf("%1.1x", colorIndex );
2976 } else {
2977 tileData.data[offset] |= bitmask;
2978 // printf("%1.1x", colorIndex );
2979 }
2980
2981 source += _depth;
2982
2983 }
2984
2985 source += _depth * ( _width - 8 );
2986
2987 // printf("\n" );
2988
2989 }
2990
2991 // printf("\n" );
2992
2993 TileDescriptor * t = calculate_tile_descriptor( &tileData );
2994
2995 if ( ! _environment->descriptors ) {
2997 _environment->descriptors->first = 0;
2998 _environment->descriptors->firstFree = ( (data_font_alpha_bin_len / 8) );
2999 _environment->descriptors->lastFree = 255;
3000 _environment->descriptors->count = _environment->descriptors->firstFree;
3001 }
3002
3003 int tile = calculate_exact_tile( t, _environment->descriptors );
3004
3005 if ( tile == -1 ) {
3006 if ( _environment->descriptors->count < 256 ) {
3007 tile = (_environment->descriptors->count++);
3008 _environment->descriptors->descriptor[tile] = t;
3009 memcpy( &_environment->descriptors->data[tile], &tileData, sizeof( TileData ) );
3010 // printf("*** tile = %d\n", tile );
3011 } else {
3012 tile = calculate_nearest_tile( t, _environment->descriptors );
3013 // printf("--- tile = %d\n", tile );
3014 }
3015 } else {
3016 // printf(" tile = %d\n", tile );
3017 }
3018
3019 // printf(" colorUsed = %d\n", colorUsed );
3020 int mostFrequentColorIndex = 1;
3021 int mostFrequentColorCount = 0;
3022 for(int i=0;i<colorUsed;++i) {
3023 if ( mostFrequentColorCount < mostFrequentColor[commonPalette[i].index] ) {
3024 mostFrequentColorCount = mostFrequentColor[commonPalette[i].index];
3025 mostFrequentColorIndex = commonPalette[i].index;
3026 }
3027 }
3028
3029 *(buffer + 3 + (cy * ( _frame_width >> 3 ) ) + cx ) = tile;
3030 if ( colorUsed > 2 ) {
3031 *(buffer + 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) + (cy * ( _frame_width >> 3 ) ) + cx ) = ( ( mostFrequentColorIndex & 0x07 ) );
3032 }
3033
3034 // printf("\ntile: %2.2x\n", tile );
3035
3036 }
3037 // printf("\n");
3038 }
3039
3040 if ( colorUsed <= 2 ) {
3041 *(buffer + 3 + ( ( _frame_width >> 3 ) * ( _frame_height >> 3 ) ) ) = commonPalette[0].index == 0 ? commonPalette[1].index : commonPalette[0].index;
3042 }
3043 // printf("----\n");
3044
3045 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
3046
3047 // printf("----\n");
3048
3049 return result;
3050
3051}
3052
3053static Variable * vic2_image_converter_tilemap_mode_multicolor( 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 ) {
3054
3055 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
3056
3057 if ( _environment->freeImageWidth ) {
3058 if ( _width % 8 ) {
3059 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
3060 }
3061 if ( _frame_width % 8 ) {
3062 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
3063 }
3064 }
3065
3066 if ( _environment->freeImageHeight ) {
3067 if ( _height % 8 ) {
3068 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
3069 }
3070 if ( _frame_height % 8 ) {
3071 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
3072 }
3073 }
3074
3075 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
3076
3077 RGBi palette[MAX_PALETTE];
3078
3079 int colorUsed = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, (_flags & FLAG_EXACT) /* sorted */ );
3080
3081 commonPalette = palette_match( palette, colorUsed, SYSTEM_PALETTE, ( sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ) / 2 );
3082 commonPalette = palette_remove_duplicates( commonPalette, colorUsed, &colorUsed );
3083 adilinepalette( "CPM1:%d", colorUsed, commonPalette );
3084
3085 adilinepalette( "CPMS:%d", (int)(( sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ) / 2), SYSTEM_PALETTE );
3086
3087 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
3088 result->originalColors = colorUsed;
3089 memcpy( result->originalPalette, commonPalette, colorUsed * sizeof( RGBi ) );
3090
3091 int bufferSize;
3092
3093 bufferSize = 3 + 2* ( ( _frame_width >> 2 ) * ( _frame_height >> 3 ) ) + 2;
3094
3095 // printf("bufferSize = %d\n", bufferSize );
3096
3097 char * buffer = malloc ( bufferSize );
3098 memset( buffer, 0, bufferSize );
3099
3100 // Position of the pixel in the original image
3101 int image_x, image_y;
3102
3103 // Position of the pixel, in terms of tiles
3104 int tile_x, tile_y;
3105
3106 // Position of the pixel, in terms of offset and bitmask
3107 int offset, bitmask;
3108
3109 // Color of the pixel to convert
3110 RGBi rgb;
3111
3112 *(buffer) = _frame_width;
3113 *(buffer+1) = _frame_height;
3114 *(buffer+2) = 0;
3115
3116 int cx=0,cy=0;
3117
3118 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
3119
3120 // commonTileDescriptors = precalculate_tile_descriptors_for_font( data_fontvic1_bin );
3121
3122 for( cy=0; cy<(_frame_height >> 3);++cy) {
3123 for( cx=0; cx<(_frame_width >> 2);++cx) {
3124
3125 char *source = _source + ( ( cy * 8 * _width ) + cx * 4 ) * _depth;
3126
3127 TileData tileData;
3128 memset(&tileData,0,sizeof(TileData));
3129
3130 int mostFrequentColor[16];
3131 memset(&mostFrequentColor[0],0,sizeof(int)*16);
3132
3133 int colorIndex = 0;
3134
3135 // Loop for all the source surface.
3136 for (image_y = 0; image_y < 8; ++image_y) {
3137 for (image_x = 0; image_x < 4; ++image_x) {
3138
3139 // Take the color of the pixel
3140 rgb.red = *source;
3141 rgb.green = *(source + 1);
3142 rgb.blue = *(source + 2);
3143 if ( _depth > 3 ) {
3144 rgb.alpha = *(_source + 3);
3145 } else {
3146 rgb.alpha = 255;
3147 }
3148
3149 colorIndex = 0;
3150 if ( rgb.alpha < 255 ) {
3151 colorIndex = commonPalette[0].index;
3152 } else {
3153
3154 int minDistance = 9999;
3155 for( int i=0; i<colorUsed; ++i ) {
3156 int distance = rgbi_distance(&commonPalette[i], &rgb );
3157 if ( distance < minDistance ) {
3158 minDistance = distance;
3159 colorIndex = commonPalette[i].index;
3160 }
3161 }
3162
3163 }
3164
3165 mostFrequentColor[colorIndex]++;
3166
3167 // printf("%d", i );
3168
3169 // Calculate the relative tile
3170
3171 // Calculate the offset starting from the tile surface area
3172 // and the bit to set.
3173 offset = (image_y & 0x07);
3174 bitmask = 1 << ( 6 - (2*(image_x & 0x3)) );
3175
3176 if ( colorIndex == 0 ) {
3177 tileData.data[offset] &= ~(3*bitmask);
3178 } else if ( colorIndex == commonPalette[1].index ) {
3179 tileData.data[offset] |= bitmask;
3180 } else if ( colorIndex == commonPalette[2].index ) {
3181 tileData.data[offset] |= 2*bitmask;
3182 } else {
3183 if ( !colorIndex ) {
3184 tileData.data[offset] &= ~(3*bitmask);
3185 } else {
3186 tileData.data[offset] |= (3*bitmask);
3187 }
3188 }
3189 // printf("%1.1x", colorIndex );
3190
3191 source += _depth;
3192
3193 }
3194
3195 source += _depth * ( _width - 4 );
3196
3197 // printf("\n" );
3198
3199 }
3200
3201 // printf("\n" );
3202
3203 TileDescriptor * t = calculate_tile_descriptor( &tileData );
3204
3205 if ( ! _environment->descriptors ) {
3207 _environment->descriptors->first = 0;
3208 _environment->descriptors->firstFree = ( (data_font_alpha_bin_len / 8) );
3209 _environment->descriptors->lastFree = 255;
3210 _environment->descriptors->count = _environment->descriptors->firstFree;
3211 }
3212
3213 int tile = calculate_exact_tile( t, _environment->descriptors );
3214
3215 if ( tile == -1 ) {
3216 if ( _environment->descriptors->count < 256 ) {
3217 tile = (_environment->descriptors->count++);
3218 _environment->descriptors->descriptor[tile] = t;
3219 memcpy( &_environment->descriptors->data[tile], &tileData, sizeof( TileData ) );
3220 // printf("*** tile = %d\n", tile );
3221 } else {
3222 tile = calculate_nearest_tile( t, _environment->descriptors );
3223 // printf("--- tile = %d\n", tile );
3224 }
3225 } else {
3226 // printf(" tile = %d\n", tile );
3227 }
3228
3229 // printf(" colorUsed = %d\n", colorUsed );
3230 int mostFrequentColorIndex = 1;
3231 int mostFrequentColorCount = 0;
3232 for(int i=3;i<colorUsed;++i) {
3233 if ( mostFrequentColorCount < mostFrequentColor[commonPalette[i].index] ) {
3234 mostFrequentColorCount = mostFrequentColor[commonPalette[i].index];
3235 mostFrequentColorIndex = commonPalette[i].index;
3236 }
3237 }
3238
3239 *(buffer + 3 + (cy * ( _frame_width >> 3 ) ) + cx ) = tile;
3240 *(buffer + 3 + ( ( _frame_width >> 2 ) * ( _frame_height >> 3 ) ) + (cy * ( _frame_width >> 2 ) ) + cx ) = 0x8 | ( ( mostFrequentColorIndex & 0x03 ) );
3241
3242 // printf("\ntile: %2.2x\n", tile );
3243
3244 }
3245 // printf("\n");
3246 }
3247
3248 *(buffer + 3 + 2* ( ( _frame_width >> 2 ) * ( _frame_height >> 3 ) ) ) = commonPalette[0].index;
3249 *(buffer + 3 + 2* ( ( _frame_width >> 2 ) * ( _frame_height >> 3 ) ) + 1 ) = commonPalette[1].index;
3250 *(buffer + 3 + 2* ( ( _frame_width >> 2 ) * ( _frame_height >> 3 ) ) + 2 ) = commonPalette[2].index;
3251
3252 // printf("----\n");
3253
3254 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
3255
3256 // printf("----\n");
3257
3258 return result;
3259
3260}
3261
3262Variable * vic2_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 ) {
3263
3264 switch( _mode ) {
3265
3267
3268 return vic2_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
3269
3271
3272 return vic2_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
3273
3274 case BITMAP_MODE_AH:
3275 case BITMAP_MODE_AIFLI:
3277 case BITMAP_MODE_ECI:
3278 case BITMAP_MODE_IAFLI:
3279 case BITMAP_MODE_IH:
3280 case BITMAP_MODE_MRFLI:
3282 case BITMAP_MODE_MUCSUH:
3283 case BITMAP_MODE_MUFLI:
3284 case BITMAP_MODE_MUIFLI:
3285 case BITMAP_MODE_NUFLI:
3286 case BITMAP_MODE_NUIFLI:
3287 case BITMAP_MODE_SH:
3288 case BITMAP_MODE_SHFLI:
3289 case BITMAP_MODE_SHI:
3290 case BITMAP_MODE_SHIFLI:
3291 case BITMAP_MODE_SHIFXL:
3292 case BITMAP_MODE_UFLI:
3293 case BITMAP_MODE_UIFLI:
3294 case BITMAP_MODE_TRIFLI:
3295 case BITMAP_MODE_XFLI:
3296 case BITMAP_MODE_XIFLI:
3297 case BITMAP_MODE_FLI:
3298 case BITMAP_MODE_HCB:
3299 case BITMAP_MODE_IFLI:
3300 case BITMAP_MODE_MUCSU:
3301 case BITMAP_MODE_MCI:
3303 case BITMAP_MODE_PRS:
3305 return vic2_image_converter_tilemap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
3307 return vic2_image_converter_tilemap_mode_multicolor( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
3309 break;
3310 }
3311
3313
3314 return vic2_new_image( _environment, 8, 8, BITMAP_MODE_STANDARD );
3315
3316}
3317
3318Variable * vic2_sprite_converter( Environment * _environment, char * _source, int _width, int _height, int _depth, RGBi * _color, int _flags, int _slot_x, int _slot_y ) {
3319
3320 RGBi palette[MAX_PALETTE];
3321
3322 int colorUsed = vic2_palette_extract( _environment, _source, _width, _height, _depth, _flags, &palette[0] );
3323
3324// int colorUsed = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, 1 /* sorted */ );
3325
3326 int spriteWidth = 0;
3327 int spriteHeight = 0;
3328
3329 if ( ! _color ) {
3330
3331 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
3332 if (colorUsed > 4) {
3334 }
3335 } else {
3336 if (colorUsed > 2) {
3338 }
3339 }
3340
3341 }
3342
3343 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
3344 spriteWidth = 12;
3345 spriteHeight = 21;
3346 } else {
3347 spriteWidth = 24;
3348 spriteHeight = 21;
3349 }
3350
3351 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
3352 result->originalColors = colorUsed;
3353
3354 int i, j, k;
3355
3356 // for( i=0; i<colorUsed; ++i ) {
3357 // int minDistance = 0xffff;
3358 // int colorIndex = 0;
3359 // for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
3360 // int distance = rgbi_distance(&SYSTEM_PALETTE[j], &palette[i]);
3361 // // printf("%d <-> %d [%d] = %d [min = %d]\n", i, j, SYSTEM_PALETTE[j].index, distance, minDistance );
3362 // if (distance < minDistance) {
3363 // // printf(" candidated...\n" );
3364 // for( k=0; k<i; ++k ) {
3365 // if ( palette[k].index == SYSTEM_PALETTE[j].index ) {
3366 // // printf(" ...used!\n" );
3367 // break;
3368 // }
3369 // }
3370 // if ( k>=i ) {
3371 // // printf(" ...ok! (%d)\n", SYSTEM_PALETTE[j].index );
3372 // minDistance = distance;
3373 // colorIndex = j;
3374 // }
3375 // }
3376 // }
3377 // palette[i].index = SYSTEM_PALETTE[colorIndex].index;
3378 // strcopy( palette[i].description, SYSTEM_PALETTE[colorIndex].description );
3379 // // printf("%d) %d %2.2x%2.2x%2.2x\n", i, palette[i].index, palette[i].red, palette[i].green, palette[i].blue);
3380 // }
3381
3382 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
3383
3384 // printf("PALETTE 0: %d\n", palette[0].index );
3385 // printf("PALETTE 1: %d %2.2x%2.2x%2.2x\n", palette[1].index, palette[1].red, palette[1].green, palette[1].blue );
3386 // printf("PALETTE 2: %d\n", palette[2].index );
3387 // printf("PALETTE 3: %d\n", palette[3].index );
3388
3389 if ( palette[0].index == SYSTEM_PALETTE[0].index ) {
3390
3391 } else {
3392 rgbi_move( &palette[2], &palette[3] );
3393 rgbi_move( &palette[1], &palette[2] );
3394 rgbi_move( &palette[0], &palette[1] );
3395 rgbi_move( &SYSTEM_PALETTE[0], &palette[0] );
3396 }
3397
3398 // printf("PALETTE 0: %d\n", palette[0].index );
3399 // printf("PALETTE 1: %d %2.2x%2.2x%2.2x\n", palette[1].index, palette[1].red, palette[1].green, palette[1].blue );
3400 // printf("PALETTE 2: %d\n", palette[2].index );
3401 // printf("PALETTE 3: %d\n", palette[3].index );
3402
3403 // printf("Color used = %d\n", colorUsed);
3404
3405 // printf("Decoding multicolor sprite color #0\n");
3406
3407 if ( !multicolorSpritePalette[0] ) {
3408 // printf("Initializing with color 1 (%d)\n", palette[1].index );
3409 multicolorSpritePalette[0] = malloc( sizeof( RGBi ) );
3410 memset( multicolorSpritePalette[0], 0, sizeof( RGBi ) );
3411 rgbi_move( &palette[1], multicolorSpritePalette[0] );
3412 }
3413
3414 // printf("Decoding multicolor sprite color #1\n");
3415
3416 if ( !multicolorSpritePalette[1] ) {
3417 // printf("Initializing with color 2 (%d)\n", palette[2].index );
3418 multicolorSpritePalette[1] = malloc( sizeof( RGBi ) );
3419 memset( multicolorSpritePalette[1], 0, sizeof( RGBi ) );
3420 rgbi_move( &palette[2], multicolorSpritePalette[1] );
3421 }
3422
3423 RGBi temporaryPalette[MAX_PALETTE];
3424 memset( temporaryPalette, 0, sizeof( RGBi ) * MAX_PALETTE );
3425
3426 rgbi_move( &SYSTEM_PALETTE[0], &temporaryPalette[0] );
3427
3428 for( int i=1; i<colorUsed; ++i ) {
3429 if ( rgbi_equals_rgba( &palette[i], multicolorSpritePalette[0] ) ) {
3430 // printf("%d) Color #%d == sprite palette 0\n", i, palette[i].index );
3431 rgbi_move( &palette[i], &temporaryPalette[1] );
3432 } else if ( rgbi_equals_rgba( &palette[i], multicolorSpritePalette[1] ) ) {
3433 // printf("%d) Color #%d == sprite palette 1\n", i, palette[i].index );
3434 rgbi_move( &palette[i], &temporaryPalette[3] );
3435 } else {
3436 // printf("%d) Color #%d == sprite custom\n", i, palette[i].index );
3437 rgbi_move( &palette[i], &temporaryPalette[2] );
3438 }
3439 }
3440
3441 rgbi_move( &temporaryPalette[0], &palette[0] );
3442 // printf("PALETTE 0: %d\n", palette[0].index );
3443 rgbi_move( &temporaryPalette[1], &palette[1] );
3444 // printf("PALETTE 1: %d\n", palette[1].index );
3445 rgbi_move( &temporaryPalette[2], &palette[2] );
3446 // printf("PALETTE 2: %d\n", palette[2].index );
3447 rgbi_move( &temporaryPalette[3], &palette[3] );
3448 // printf("PALETTE 3: %d\n", palette[3].index );
3449
3450 }
3451
3452 memcpy( result->originalPalette, palette, MAX_PALETTE * sizeof( RGBi ) );
3453
3454 int bufferSize = 64;
3455
3456 // printf("bufferSize = %d\n", bufferSize );
3457
3458 char * buffer = malloc ( bufferSize );
3459 memset( buffer, 0, bufferSize );
3460
3461 // Position of the pixel in the original image
3462 int image_x, image_y;
3463
3464 // Position of the pixel, in terms of offset and bitmask
3465 int offset, bitmask;
3466
3467 // Color of the pixel to convert
3468 RGBi rgb;
3469
3470 char * source = _source + ( ( _slot_y * spriteHeight * _width ) + _slot_x * spriteWidth ) * _depth;
3471
3472 // printf("\n");
3473
3474 // Loop for all the source surface.
3475 for (image_y = 0; image_y < spriteHeight; ++image_y) {
3476 if ( ( image_y + ( _slot_y * spriteHeight ) ) == _height ) {
3477 // printf( "Y" );
3478 break;
3479 }
3480 for (image_x = 0; image_x < spriteWidth; ++image_x) {
3481 if ( ( image_x + ( _slot_x * spriteWidth ) ) == _width ) {
3482 // printf( "X" );
3483 break;
3484 }
3485
3486 // Take the color of the pixel
3487 rgb.red = *source;
3488 rgb.green = *(source + 1);
3489 rgb.blue = *(source + 2);
3490 if ( _depth > 3 ) {
3491 rgb.alpha = *(source + 3);
3492 } else {
3493 rgb.alpha = 255;
3494 }
3495
3496 if ( rgb.alpha < 255 ) {
3497 i = 0;
3498 } else {
3499
3500 if ( ! _color ) {
3501 int minDistance = 0xffff;
3502 RGBi * color = NULL;
3503 i = 0;
3504 for( int k=0; k<colorUsed; ++k ) {
3505 int distance = rgbi_distance( &palette[k], &rgb );
3506 if ( distance < minDistance ) {
3507 minDistance = distance;
3508 color = &palette[k];
3509 i = k;
3510 }
3511 }
3512 // for( i=0; i<colorUsed; ++i ) {
3513 // // 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 );
3514 // if ( rgbi_equals_rgba( &palette[i], color ) ) {
3515 // break;
3516 // }
3517 // }
3518 } else {
3519 int minDistance = 0xffff;
3520 RGBi * color = NULL;
3521 for( int k=0; k<colorUsed; ++k ) {
3522 int distance = rgbi_distance( &palette[k], &rgb );
3523 if ( distance < minDistance ) {
3524 minDistance = distance;
3525 color = &palette[k];
3526 }
3527 }
3528 if ( rgbi_equals_rgba( _color, color ) ) {
3529 i = 1;
3530 } else {
3531 i = 0;
3532 }
3533 }
3534
3535 }
3536
3537 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
3538
3539 // Calculate the offset starting from the tile surface area
3540 // and the bit to set.
3541 offset = ( image_y * 3 ) + (image_x >> 2);
3542 bitmask = i << (6 - ((image_x & 0x3) * 2));
3543
3544 if ( i > 0 ) {
3545 *( buffer + offset) |= bitmask;
3546 // printf("%1.1x", i );
3547 } else {
3548 *( buffer + offset) &= ~bitmask;
3549 // printf("%1.1x", i );
3550 }
3551
3552 } else {
3553
3554 // Calculate the offset starting from the tile surface area
3555 // and the bit to set.
3556 offset = ( image_y * 3 ) + (image_x >> 3);
3557 bitmask = 1 << ( 7 - (image_x & 0x7) );
3558
3559 if ( i == 1 ) {
3560 *( buffer + offset) |= bitmask;
3561 // printf("*");
3562 } else {
3563 *( buffer + offset) &= ~bitmask;
3564 // printf(" ");
3565 }
3566
3567 }
3568
3569 source += _depth;
3570
3571 }
3572
3573 // printf("\n");
3574 if ( ( image_x + ( _slot_x * spriteWidth ) ) == _width ) {
3575 source += _depth * (_width - image_x );
3576 } else {
3577 source += _depth * ( _width - spriteWidth );
3578 }
3579
3580 // printf("\n" );
3581
3582 }
3583
3584 if ( _color ) {
3585 *(buffer+63) = _color->index;
3586 } else {
3587 if ( _flags & SPRITE_FLAG_MULTICOLOR ) {
3588 *(buffer+63) = palette[3].index;
3589 } else {
3590 *(buffer+63) = palette[1].index;
3591 }
3592 }
3593
3594 // printf("\n----\n");
3595
3596 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
3597
3598 // printf("----\n");
3599
3600 return result;
3601
3602}
3603
3604static void vic2_load_image_address_to_other_register( Environment * _environment, char * _register, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
3605
3606 outline1("LDA #<%s", _source );
3607 outline1("STA %s", _register );
3608 outline1("LDA #>%s", _source );
3609 outline1("STA %s", address_displacement(_environment, _register, "1") );
3610#ifdef __c64reu__
3611 outline0("LDA #0" );
3612 outline0("STA BANKPTR" );
3613 outline0("STA BANKUSE" );
3614#endif
3615#ifdef __c128__
3616 outline0("STA RLEUSE" );
3617#endif
3618
3619 if ( _sequence ) {
3620
3621 outline0("CLC" );
3622 outline1("LDA %s", _register );
3623 outline0("ADC #3" );
3624 outline1("STA %s", _register );
3625 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3626 outline0("ADC #0" );
3627 outline1("STA %s", address_displacement(_environment, _register, "1") );
3628 if ( strlen(_sequence) == 0 ) {
3629
3630 } else {
3631 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
3632 outline0("STA MATHPTR0" );
3633 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
3634 outline0("STA MATHPTR1" );
3635 outline0("CLC" );
3636 outline1("LDA %s", _sequence );
3637 outline0("ASL" );
3638 outline0("TAY" );
3639 outline1("LDA %s", _register );
3640 outline0("ADC (MATHPTR0), Y" );
3641 outline1("STA %s", _register );
3642 outline0("INY" );
3643 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3644 outline0("ADC (MATHPTR0), Y" );
3645 outline1("STA %s", address_displacement(_environment, _register, "1") );
3646 }
3647
3648 if ( _frame ) {
3649 if ( strlen(_frame) == 0 ) {
3650
3651 } else {
3652 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3653 outline0("STA MATHPTR0" );
3654 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3655 outline0("STA MATHPTR1" );
3656 outline0("CLC" );
3657 outline1("LDA %s", _frame );
3658 outline0("ASL" );
3659 outline0("TAY" );
3660 outline1("LDA %s", _register );
3661 outline0("ADC (MATHPTR0), Y" );
3662 outline1("STA %s", _register );
3663 outline0("INY" );
3664 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3665 outline0("ADC (MATHPTR0), Y" );
3666 outline1("STA %s", address_displacement(_environment, _register, "1") );
3667 }
3668 }
3669
3670 } else {
3671
3672 if ( _frame ) {
3673 outline0("CLC" );
3674 outline1("LDA %s", _register );
3675 outline0("ADC #3" );
3676 outline1("STA %s", _register );
3677 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3678 outline0("ADC #0" );
3679 outline1("STA %s", address_displacement(_environment, _register, "1") );
3680 if ( strlen(_frame) == 0 ) {
3681
3682 } else {
3683 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3684 outline0("STA MATHPTR0" );
3685 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3686 outline0("STA MATHPTR0+1" );
3687 outline0("CLC" );
3688 outline1("LDA %s", _frame );
3689 outline0("ASL" );
3690 outline0("TAY" );
3691 outline1("LDA %s", _register );
3692 outline0("ADC (MATHPTR0), Y" );
3693 outline1("STA %s", _register );
3694 outline0("INY" );
3695 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3696 outline0("ADC (MATHPTR0), Y" );
3697 outline1("STA %s", address_displacement(_environment, _register, "1") );
3698 }
3699 }
3700
3701 }
3702
3703}
3704
3705static void vic2_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
3706
3707 if ( !_sequence && !_frame ) {
3708 if ( _source->isAddress ) {
3709 outline1("LDA %s", _source->realName );
3710 outline1("STA %s", _register );
3711 outline1("LDA %s", address_displacement(_environment, _source->realName, "1") );
3712 outline1("STA %s", address_displacement(_environment, _register, "1") );
3713#ifdef __c64reu__
3714 if ( _source->bankNumber != -1 ) {
3715 outline1("LDA #$%2.2x", _source->bankNumber );
3716 outline0("STA BANKPTR" );
3717 outline0("LDA #$FF" );
3718 outline0("STA BANKUSE" );
3719 } else {
3720 outline0("LDA #0" );
3721 outline0("STA BANKPTR" );
3722 outline0("STA BANKUSE" );
3723 }
3724#endif
3725
3726#ifdef __c128__
3727 if ( _source->compression == CMP_RLE ) {
3728 outline0("LDA #1" );
3729 outline0("STA RLEUSE" );
3730 } else {
3731 outline0("LDA #0" );
3732 outline0("STA RLEUSE" );
3733 }
3734#endif
3735
3736 } else {
3737 outline1("LDA #<%s", _source->realName );
3738 outline1("STA %s", _register );
3739 outline1("LDA #>%s", _source->realName );
3740 outline1("STA %s", address_displacement(_environment, _register, "1") );
3741#ifdef __c64reu__
3742 outline0("LDA #0" );
3743 outline0("STA BANKPTR" );
3744 outline0("STA BANKUSE" );
3745#endif
3746#ifdef __c128__
3747 if ( _source->compression == CMP_RLE ) {
3748 outline0("LDA #1" );
3749 outline0("STA RLEUSE" );
3750 } else {
3751 outline0("LDA #0" );
3752 outline0("STA RLEUSE" );
3753 }
3754#endif
3755
3756 }
3757 } else {
3758 if ( _source->isAddress ) {
3759 outline1("LDA %s", _source->realName );
3760 outline0("STA TMPPTR" );
3761 outline1("LDA %s", address_displacement(_environment, _source->realName, "1") );
3762 outline0("STA TMPPTR+1" );
3763
3764#ifdef __c64reu__
3765 if ( _source->bankNumber != -1 ) {
3766 outline1("LDA #$%2.2x", _source->bankNumber );
3767 outline0("STA BANKPTR" );
3768 outline0("LDA #$FF" );
3769 outline0("STA BANKUSE" );
3770 } else {
3771 outline0("LDA #0" );
3772 outline0("STA BANKPTR" );
3773 outline0("STA BANKUSE" );
3774 }
3775#endif
3776#ifdef __c128__
3777 if ( _source->compression == CMP_RLE ) {
3778 outline0("LDA #1" );
3779 outline0("STA RLEUSE" );
3780 } else {
3781 outline0("LDA #0" );
3782 outline0("STA RLEUSE" );
3783 }
3784#endif
3785
3786 } else {
3787 outline1("LDA #<%s", _source->realName );
3788 outline0("STA TMPPTR" );
3789 outline1("LDA #>%s", _source->realName );
3790 outline0("STA TMPPTR+1" );
3791#ifdef __c64reu__
3792 outline0("LDA #0" );
3793 outline0("STA BANKPTR" );
3794 outline0("STA BANKUSE" );
3795#endif
3796#ifdef __c128__
3797 if ( _source->compression == CMP_RLE ) {
3798 outline0("LDA #1" );
3799 outline0("STA RLEUSE" );
3800 } else {
3801 outline0("LDA #0" );
3802 outline0("STA RLEUSE" );
3803 }
3804#endif
3805 }
3806
3807 if ( _sequence ) {
3808 outline0("CLC" );
3809 outline0("LDA TMPPTR" );
3810 outline0("ADC #3" );
3811 outline0("STA TMPPTR" );
3812 outline0("LDA TMPPTR+1" );
3813 outline0("ADC #0" );
3814 outline0("STA TMPPTR+1" );
3815
3816 if ( strlen(_sequence) == 0 ) {
3817
3818 } else {
3819 outline1("LDA %s", _sequence );
3820 outline0("STA MATHPTR0" );
3821 outline1("JSR %soffsetsequence", _source->realName );
3822 }
3823 if ( _frame ) {
3824 if ( strlen(_frame) == 0 ) {
3825
3826 } else {
3827 outline1("LDA %s", _frame );
3828 outline0("STA MATHPTR0" );
3829 outline1("JSR %soffsetframe", _source->realName );
3830 }
3831 }
3832
3833 } else {
3834
3835 if ( _frame ) {
3836 outline0("CLC" );
3837 outline0("LDA TMPPTR" );
3838 outline0("ADC #3" );
3839 outline0("STA TMPPTR" );
3840 outline0("LDA TMPPTR+1" );
3841 outline0("ADC #0" );
3842 outline0("STA TMPPTR+1" );
3843 if ( strlen(_frame) == 0 ) {
3844
3845 } else {
3846 outline1("LDA %s", _frame );
3847 outline0("STA MATHPTR0" );
3848 outline1("JSR %soffsetframe", _source->realName );
3849 }
3850 }
3851
3852 }
3853
3854 if ( _source->isAddress ) {
3855 outline0("LDA TMPPTR" );
3856 outline1("STA %s", _register );
3857 outline0("LDA TMPPTR+1" );
3858 outline1("STA %s", address_displacement(_environment, _register, "1") );
3859 } else {
3860 outline0("LDA TMPPTR" );
3861 outline1("STA %s", _register );
3862 outline0("LDA TMPPTR+1" );
3863 outline1("STA %s", address_displacement(_environment, _register, "1") );
3864 }
3865
3866 }
3867
3868}
3869
3870
3871void vic2_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
3872
3873 Variable * x = variable_retrieve( _environment, _x );
3874 Variable * y = variable_retrieve( _environment, _y );
3875
3876 deploy( vic2vars, src_hw_vic2_vars_asm);
3877 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
3879 deploy( putimage, src_hw_vic2_put_image_asm );
3880#ifdef __c64reu__
3883#endif
3884
3885#ifdef __c128__
3886 if ( _environment->enableRle ) {
3887 deploy( putimageramrle, src_hw_vic2_put_image_ram_rle_asm );
3888 }
3889#endif
3890
3892
3893 if ( _frame_size ) {
3894 vic2_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3895 }
3896
3897 if ( x->initializedByConstant ) {
3898 outline1("LDA #$%2.2x", (x->value&0xff) );
3899 } else {
3900 outline1("LDA %s", x->realName );
3901 }
3902 outline0("STA IMAGEX" );
3903 if ( x->initializedByConstant ) {
3904 outline1("LDA #$%2.2x", ((x->value>>8)&0xff) );
3905 } else {
3906 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
3907 }
3908 outline0("STA IMAGEX+1" );
3909 if ( y->initializedByConstant ) {
3910 outline1("LDA #$%2.2x", (y->value&0xff) );
3911 } else {
3912 outline1("LDA %s", y->realName );
3913 }
3914 outline0("STA IMAGEY" );
3915 if ( strchr( _flags, '#' ) ) {
3916 outline1("LDA #((%s)&255)", _flags+1 );
3917 outline0("STA IMAGEF" );
3918 outline1("LDA #(((%s)>>8)&255)", _flags+1 );
3919 outline0("STA IMAGET" );
3920 } else {
3921 outline1("LDA %s", _flags );
3922 outline0("STA IMAGEF" );
3923 outline1("LDA %s", address_displacement(_environment, _flags, "1") );
3924 outline0("STA IMAGET" );
3925 }
3926
3927 outline0("JSR PUTIMAGE");
3928
3929}
3930
3931void vic2_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
3932
3933 outline0("LDA #0");
3934 outline1("STA %s", _offset );
3935 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3936
3937 if ( _sequence ) {
3938
3939 outline0("CLC" );
3940 outline1("LDA %s", _offset );
3941 outline0("ADC #3" );
3942 outline1("STA %s", _offset );
3943 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3944 outline0("ADC #0" );
3945 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3946 if ( strlen(_sequence) == 0 ) {
3947
3948 } else {
3949 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
3950 outline0("STA MATHPTR0" );
3951 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
3952 outline0("STA MATHPTR1" );
3953 outline0("CLC" );
3954 outline1("LDA %s", _sequence );
3955 outline0("ASL" );
3956 outline0("TAY" );
3957 outline1("LDA %s", _offset );
3958 outline0("ADC (MATHPTR0), Y" );
3959 outline1("STA %s", _offset );
3960 outline0("INY" );
3961 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3962 outline0("ADC (MATHPTR0), Y" );
3963 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3964 }
3965
3966 if ( _frame ) {
3967 if ( strlen(_frame) == 0 ) {
3968
3969 } else {
3970 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3971 outline0("STA MATHPTR0" );
3972 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3973 outline0("STA MATHPTR1" );
3974 outline0("CLC" );
3975 outline1("LDA %s", _frame );
3976 outline0("ASL" );
3977 outline0("TAY" );
3978 outline1("LDA %s", _offset );
3979 outline0("ADC (MATHPTR0), Y" );
3980 outline1("STA %s", _offset );
3981 outline0("INY" );
3982 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3983 outline0("ADC (MATHPTR0), Y" );
3984 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3985 }
3986 }
3987
3988 } else {
3989
3990 if ( _frame ) {
3991 outline0("CLC" );
3992 outline1("LDA %s", _offset );
3993 outline0("ADC #3" );
3994 outline1("STA %s", _offset );
3995 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3996 outline0("ADC #0" );
3997 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3998 if ( strlen(_frame) == 0 ) {
3999
4000 } else {
4001 outline1("LDA #<OFFSETS%4.4x", _frame_size );
4002 outline0("STA MATHPTR0" );
4003 outline1("LDA #>OFFSETS%4.4x", _frame_size );
4004 outline0("STA MATHPTR0+1" );
4005 outline0("CLC" );
4006 outline1("LDA %s", _frame );
4007 outline0("ASL" );
4008 outline0("TAY" );
4009 outline1("LDA %s", _offset );
4010 outline0("ADC (MATHPTR0), Y" );
4011 outline1("STA %s", _offset );
4012 outline0("INY" );
4013 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
4014 outline0("ADC (MATHPTR0), Y" );
4015 outline1("STA %s", address_displacement(_environment, _offset, "1") );
4016 }
4017 }
4018
4019 }
4020
4021}
4022
4023void vic2_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 ) {
4024
4025 deploy( vic2vars, src_hw_vic2_vars_asm);
4026 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4027 deploy( blitimage, src_hw_vic2_blit_image_asm );
4028
4029 if ( _source_count > 2 ) {
4031 }
4032
4034
4035 outhead1("blitimage%s:", label);
4036
4037 outline1("LDA #<%s", _blit );
4038 outline0("STA BLITIMAGEBLITADDR+1" );
4039 outline1("LDA #>%s", _blit );
4040 outline0("STA BLITIMAGEBLITADDR+2" );
4041
4042 if ( _source_count > 0 ) {
4043 Resource resource;
4044 resource.realName = strdup( _sources[0] );
4045 resource.type = VT_IMAGE;
4046 resource.isAddress = 0;
4047 vic2_load_image_address_to_register( _environment, "BLITTMPPTR", &resource, _sequence, _frame, _frame_size, _frame_count );
4048 } else {
4049 outline0( "LDA #$0" );
4050 outline0( "STA BLITTMPPTR" );
4051 outline0( "STA BLITTMPPTR+1" );
4052 }
4053
4054 if ( _source_count > 1 ) {
4055 Resource resource;
4056 resource.realName = strdup( _sources[1] );
4057 resource.type = VT_IMAGE;
4058 resource.isAddress = 0;
4059 vic2_load_image_address_to_register( _environment, "BLITTMPPTR2", &resource, _sequence, _frame, _frame_size, _frame_count );
4060 } else {
4061 outline0( "LDA #$0" );
4062 outline0( "STA BLITTMPPTR2" );
4063 outline0( "STA BLITTMPPTR2+1" );
4064 }
4065
4066 outhead1("putimage%s:", label);
4067
4068 outline1("LDA %s", _x );
4069 outline0("STA IMAGEX" );
4070 outline1("LDA %s", address_displacement(_environment, _x, "1") );
4071 outline0("STA IMAGEX+1" );
4072 outline1("LDA %s", _y );
4073 outline0("STA IMAGEY" );
4074 outline1("LDA %s", address_displacement(_environment, _y, "1") );
4075 outline0("STA IMAGEY+1" );
4076 outline1("LDA #$%2.2x", ( _flags & 0xff ) );
4077 outline0("STA IMAGEF" );
4078 outline1("LDA #$%2.2x", ( (_flags>>8) & 0xff ) );
4079 outline0("STA IMAGET" );
4080
4081 outline0("JSR BLITIMAGE");
4082
4083}
4084
4085void vic2_wait_vbl( Environment * _environment, char * _raster_line ) {
4086
4087 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4089
4090 if ( ! _raster_line ) {
4091 outline0("JSR VBL");
4092 } else {
4093 Variable * raster_line = variable_retrieve_or_define( _environment, _raster_line, VT_BYTE, 255 );
4094 outline1("LDA %s", raster_line->realName);
4095 outline0("JSR VBLLINE");
4096 }
4097
4098}
4099
4100Variable * vic2_new_image( Environment * _environment, int _width, int _height, int _mode ) {
4101
4102 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4103
4104 int size = vic2_image_size( _environment, _width, _height, _mode );
4105
4106 if ( ! size ) {
4108 }
4109
4110 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
4111
4112 char * buffer = malloc ( size );
4113 memset( buffer, 0, size );
4114
4115 *(buffer) = (_width & 0xff);
4116 *(buffer+1) = (_width>>8) & 0xff;
4117 *(buffer+2) = _height;
4118
4119 result->valueBuffer = buffer;
4120 result->size = size;
4121
4122 return result;
4123
4124}
4125
4126Variable * vic2_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
4127
4128 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4129
4130 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
4131 int frameSize = vic2_image_size( _environment, _width, _height, _mode );
4132
4133 if ( ! size ) {
4135 }
4136
4137 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
4138
4139 char * buffer = malloc ( size );
4140 memset( buffer, 0, size );
4141
4142 *(buffer) = _frames;
4143 *(buffer+1) = ( _width & 0xff );
4144 *(buffer+2) = ( _width >> 8 ) & 0xff;
4145 for( int i=0; i<_frames; ++i ) {
4146 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
4147 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
4148 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
4149 }
4150
4151 result->valueBuffer = buffer;
4152 result->frameSize = frameSize;
4153 result->size = size;
4154 result->frameCount = _frames;
4155
4156 return result;
4157
4158}
4159
4160Variable * vic2_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
4161
4162 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4163
4164 int size2 = calculate_sequences_size( _environment, _sequences, _frames, _width, _height, _mode );
4165 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
4166 int frameSize = vic2_image_size( _environment, _width, _height, _mode );
4167
4168 if ( ! size ) {
4170 }
4171
4172 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
4173
4174 char * buffer = malloc ( size2 );
4175 memset( buffer, 0, size2 );
4176
4177 *(buffer) = _frames;
4178 *(buffer+1) = _width;
4179 *(buffer+2) = _sequences;
4180 for( int i=0; i<(_frames * _sequences); ++i ) {
4181 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
4182 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
4183 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
4184 }
4185
4186 result->valueBuffer = buffer;
4187 result->frameSize = frameSize;
4188 result->size = size2;
4189 result->frameCount = _frames;
4190
4191 return result;
4192
4193}
4194
4195void vic2_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
4196
4197 deploy( vic2vars, src_hw_vic2_vars_asm);
4198 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4199 deploy( getimage, src_hw_vic2_get_image_asm );
4200
4202
4203 vic2_load_image_address_to_other_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
4204
4205 outline1("LDA %s", _x );
4206 outline0("STA IMAGEX" );
4207 outline1("LDA %s", address_displacement(_environment, _x, "1") );
4208 outline0("STA IMAGEX+1" );
4209 outline1("LDA %s", _y );
4210 outline0("STA IMAGEY" );
4211 outline1("LDA %s", address_displacement(_environment, _y, "1") );
4212 outline0("STA IMAGEY+1" );
4213 outline1("LDA #$%2.2x", _palette );
4214 outline0("STA IMAGET" );
4215
4216 outline0("JSR GETIMAGE");
4217
4218}
4219
4220void vic2_scroll( Environment * _environment, int _dx, int _dy ) {
4221
4222 deploy( vic2vars, src_hw_vic2_vars_asm);
4227
4228 outline1("LDA #$%2.2x", (unsigned char)(_dx&0xff) );
4229 outline0("STA MATHPTR0" );
4230 outline1("LDA #$%2.2x", (unsigned char)(_dy&0xff) );
4231 outline0("STA MATHPTR1" );
4232 outline0("JSR SCROLL");
4233
4234}
4235
4236void vic2_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
4237
4238 deploy( vic2vars, src_hw_vic2_vars_asm);
4239 deploy( tiles, src_hw_vic2_tiles_asm );
4240
4241 outline1("LDA %s", _tile );
4242 outline0("STA TILET" );
4243 outline1("LDA %s", _x );
4244 outline0("STA TILEX" );
4245 outline1("LDA %s", _y );
4246 outline0("STA TILEY" );
4247 outline0("LDA #1" );
4248 outline0("STA TILEW" );
4249 outline0("STA TILEH" );
4250 outline0("STA TILEW2" );
4251 outline0("STA TILEH2" );
4252
4253 outline0("JSR PUTTILE");
4254
4255}
4256
4257void vic2_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
4258
4259 Variable * tile = variable_retrieve( _environment, _tile );
4260 Variable * x = variable_retrieve( _environment, _x );
4261 Variable * y = variable_retrieve( _environment, _y );
4262
4263 deploy( vic2vars, src_hw_vic2_vars_asm);
4264 deploy( tiles, src_hw_vic2_tiles_asm );
4265
4266 outline1("LDA %s", tile->realName );
4267 outline0("STA TILET" );
4268 outline1("LDA %s", x->realName );
4269 outline0("STA TILEX" );
4270 outline1("LDA %s", y->realName );
4271 outline0("STA TILEY" );
4272 outline1("LDA %s", address_displacement(_environment, tile->realName, "1") );
4273 outline0("STA TILEW" );
4274 outline0("STA TILEW2" );
4275 outline1("LDA %s", address_displacement(_environment, tile->realName, "2") );
4276 outline0("STA TILEH" );
4277 outline0("STA TILEH2" );
4278 outline1("LDA %s", address_displacement(_environment, tile->realName, "3") );
4279 outline0("STA TILEA" );
4280
4281 int size = ( tile->originalWidth >> 3 ) * ( tile->originalHeight >> 3 );
4282
4283 if ( size ) {
4284 outline1("LDA #<OFFSETS%4.4x", size );
4285 outline0("STA TMPPTR2" );
4286 outline1("LDA #>OFFSETS%4.4x", size );
4287 outline0("STA TMPPTR2+1" );
4288 } else {
4289 outline0("LDA #0" );
4290 outline0("STA TMPPTR2" );
4291 outline0("STA TMPPTR2+1" );
4292 }
4293
4294 outline0("JSR MOVETILE");
4295
4296}
4297
4298void vic2_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
4299
4300 deploy( vic2vars, src_hw_vic2_vars_asm);
4301 deploy( tiles, src_hw_vic2_tiles_asm );
4302
4303 outline1("LDA %s", _tile );
4304 outline0("STA TILET" );
4305 outline1("LDA %s", _x );
4306 outline0("STA TILEX" );
4307 outline1("LDA %s", _y );
4308 outline0("STA TILEY" );
4309 outline1("LDA %s", address_displacement(_environment, _tile, "1") );
4310 outline0("STA TILEW" );
4311 if ( _w ) {
4312 outline1("LDA %s", _w );
4313 }
4314 outline0("STA TILEW2" );
4315 outline1("LDA %s", address_displacement(_environment, _tile, "2") );
4316 outline0("STA TILEH" );
4317 if ( _h ) {
4318 outline1("LDA %s", _h );
4319 }
4320 outline0("STA TILEH2" );
4321
4322 outline0("JSR PUTTILE");
4323
4324}
4325
4326void vic2_tile_at( Environment * _environment, char * _x, char * _y, char * _result ) {
4327
4328 deploy( vic2vars, src_hw_vic2_vars_asm);
4329 deploy( tiles, src_hw_vic2_tiles_asm );
4330
4331 outline1("LDA %s", _x );
4332 outline0("STA TILEX" );
4333 outline1("LDA %s", _y );
4334 outline0("STA TILEY" );
4335
4336 outline0("JSR TILEAT");
4337
4338 outline0("LDA TILET" );
4339 outline1("STA %s", _result );
4340
4341}
4342
4343void vic2_use_tileset( Environment * _environment, char * _tileset ) {
4344
4345 deploy( vic2vars, src_hw_vic2_vars_asm);
4346 deploy( tiles, src_hw_vic2_tiles_asm );
4347
4348 outline1("LDA %s", _tileset );
4349
4350 outline0("JSR USETILESET");
4351
4352}
4353
4355
4356 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
4357
4358 outline0( "LDA $D012" );
4359 outline1( "STA %s", result->realName );
4360 outline0( "LDA $D011" );
4361 outline0( "ROL" );
4362 outline0( "ROL" );
4363 outline0( "AND #$01" );
4364 outline1( "STA %s", address_displacement(_environment, result->realName, "1") );
4365
4366 return result;
4367
4368}
4369
4370void vic2_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
4371
4372}
4373
4374int vic2_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
4375
4376 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
4377
4378 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
4379
4380 int uniquePaletteCount = 0;
4381
4382 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
4383
4384 return uniquePaletteCount;
4385
4386}
4387
4388void vic2_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
4389
4390 deploy( vic2vars, src_hw_vic2_vars_asm);
4391 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4392
4393 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0001" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
4394 vic2_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
4395 deploy( flipimagex, src_hw_vic2_flip_image_x_asm );
4396 outline0("JSR FLIPIMAGEX");
4397 } else {
4398
4400
4401 vic2_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
4402 deploy( flipimagex, src_hw_vic2_flip_image_x_asm );
4403 outline1("LDA %s", _direction );
4404 outline1("AND #$%2.2x", FLAG_FLIP_X );
4405 outline1("BEQ %s", label );
4406 outline0("JSR FLIPIMAGEX");
4407 outhead1("%s:", label );
4408
4409 }
4410
4411 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0002" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
4412 vic2_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
4413 deploy( flipimagey, src_hw_vic2_flip_image_y_asm );
4414 outline0("JSR FLIPIMAGEY");
4415 } else {
4416
4418
4419 vic2_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
4420 deploy( flipimagey, src_hw_vic2_flip_image_y_asm );
4421 outline1("LDA %s", _direction );
4422 outline1("AND #$%2.2x", FLAG_FLIP_Y );
4423 outline1("BEQ %s", label );
4424 outline0("JSR FLIPIMAGEY");
4425 outhead1("%s:", label );
4426
4427 }
4428
4429
4430}
4431
4432void vic2_fade( Environment * _environment, char * _ticks ) {
4433
4434 deploy( vic2vars, src_hw_vic2_vars_asm);
4435 deploy( vic2varsGraphic, src_hw_vic2_vars_graphic_asm );
4437
4438 outline0( "SEI" );
4439 outline0( "LDA #0" );
4440 outline0( "STA FADESTEP" );
4441 outline1( "LDA %s", _ticks );
4442 outline0( "STA FADEDURATION" );
4443 outline0( "STA FADERESETDURATION" );
4444 outline1( "LDA %s", address_displacement( _environment, _ticks, "1" ) );
4445 outline0( "STA FADEDURATION+1" );
4446 outline0( "STA FADERESETDURATION+1" );
4447 outline0( "CLI" );
4448
4449}
4450
4451void vic2_screen( Environment * _environment, char * _x, char * _y, char * _c ) {
4452
4453 deploy( vic2vars, src_hw_vic2_vars_asm);
4455
4456 outline1( "LDA %s", _x );
4457 outline0( "STA MATHPTR1" );
4458 outline1( "LDA %s", _y );
4459 outline0( "STA MATHPTR0" );
4460 outline0( "JSR SCREEN" );
4461 outline1( "STA %s", _c );
4462
4463}
4464
4465void vic2_flash_begin( Environment * _environment, char * _index, char * _register ) {
4466
4468
4469 outline0("JSR FLASHBEGIN");
4470 if ( _register ) {
4471 outline1("LDA %s", _index );
4472 outline0("ASL" );
4473 outline0("TAX" );
4474 outline0("LDA FLASHREGISTERADDRESSES, X" );
4475 outline0("STA TMPPTR" );
4476 outline0("INX" );
4477 outline0("LDA FLASHREGISTERADDRESSES, X" );
4478 outline0("STA TMPPTR+1" );
4479 outline0("LDY #0" );
4480 outline1("LDA %s", _register );
4481 outline0("STA (TMPPTR), Y" );
4482 outline0("INY" );
4483 outline1("LDA %s", address_displacement( _environment, _register, "+1" ) );
4484 outline0("STA (TMPPTR), Y" );
4485 }
4486
4487}
4488
4489void vic2_flash_register( Environment * _environment, char * _index, char * _timer, char * _color ) {
4490
4492
4493 outline1("LDX %s", _index );
4494 outline1("LDY %s", _color );
4495 outline1("LDA %s", _timer );
4496 outline0("JSR FLASHREGISTER");
4497
4498}
4499
4500void vic2_flash_end( Environment * _environment ) {
4501
4503
4504 outline0("JSR FLASHEND");
4505
4506}
4507
4508void vic2_flash_off( Environment * _environment, char * _index ) {
4509
4511
4512 outline1("LDX %s", _index );
4513 outline0("JSR FLASHOFF");
4514
4515}
4516
4517#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_math_mul_8bit_to_16bit(Environment *_environment, char *_source, char *_destination, char *_other, int _signed)
CPU 6309: emit code to multiply two 8bit values in a 16 bit register
Definition 6309.c:1088
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
unsigned char src_hw_6502_cpu_math_mul_8bit_to_16bit_asm[]
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)
int reset_screen_mode_selected(Environment *_environment)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
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
void flash(Environment *_environment, char *_index, char *_register)
Definition flash.c:44
void console(Environment *_environment, int _x1, int _y1, int _x2, int _y2)
Emit code for CONSOLE.
Definition console.c:118
void console_init(Environment *_environment)
Definition console.c:41
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
unsigned int data_font_alpha_bin_len
Definition font_alpha.c:89
unsigned char data_font_alpha_bin[]
Definition font_alpha.c:1
unsigned char src_hw_vic2_put_image_reu_asm[]
unsigned char src_hw_vic2_vscroll_text_up_asm[]
unsigned char src_hw_vic2_vars_asm[]
unsigned char src_hw_vic2_hscroll_text_asm[]
unsigned char src_hw_vic2_fade_asm[]
unsigned char src_hw_vic2_put_image_ram_rle_asm[]
unsigned char src_hw_vic2_put_image_asm[]
unsigned char src_hw_vic2_blit_image_asm[]
unsigned char src_hw_vic2_screen_asm[]
unsigned char src_hw_vic2_text_at_graphic_asm[]
unsigned char src_hw_vic2_back_asm[]
unsigned char src_hw_vic2_msprites_asm[]
unsigned char src_hw_vic2_vars_graphic_asm[]
unsigned char src_hw_vic2_plot_asm[]
unsigned char src_hw_vic2_put_image_ram_asm[]
unsigned char src_hw_vic2_text_at_text_raw_asm[]
unsigned char src_hw_vic2_vscroll_text_down_asm[]
unsigned char src_hw_vic2_cline_graphic_asm[]
unsigned char src_hw_vic2_tiles_asm[]
unsigned char src_hw_vic2_text_at_text_asm[]
unsigned char src_hw_vic2_cls_graphic_asm[]
unsigned char src_hw_vic2_get_image_asm[]
unsigned char src_hw_vic2_console_asm[]
unsigned char src_hw_vic2_sprites_asm[]
unsigned char src_hw_vic2_cline_text_asm[]
unsigned char src_hw_vic2_startup_asm[]
unsigned char src_hw_vic2_flip_image_x_asm[]
unsigned char src_hw_vic2_flash_asm[]
unsigned char src_hw_vic2_text_at_asm[]
unsigned char src_hw_vic2_cls_box_asm[]
unsigned char src_hw_vic2_cls_text_asm[]
unsigned char src_hw_vic2_vbl_asm[]
unsigned char src_hw_vic2_flip_image_y_asm[]
unsigned char src_hw_vic2_text_at_graphic_raw_asm[]
unsigned char src_hw_vic2_scroll_asm[]
int width
Definition ugbc.h:2209
int y1
Definition ugbc.h:2206
int x1
Definition ugbc.h:2205
int height
Definition ugbc.h:2210
CopperOperation operation
Definition ugbc.h:2243
struct _CopperInstruction * next
Definition ugbc.h:2246
char * name
Definition ugbc.h:2252
struct _CopperInstruction * first
Definition ugbc.h:2254
struct _CopperList * next
Definition ugbc.h:2255
int msprite
Definition ugbc.h:1727
int screenTilesWidth
Definition ugbc.h:2880
int screenShades
Definition ugbc.h:2865
int fontHeight
Definition ugbc.h:2905
Console activeConsole
Definition ugbc.h:2910
int freeImageWidth
Definition ugbc.h:3088
int currentMode
Definition ugbc.h:2696
int screenTilesHeight
Definition ugbc.h:2885
int consoleTilesHeight
Definition ugbc.h:2895
RgbConverterFunction currentRgbConverterFunction
Definition ugbc.h:2711
int fontWidth
Definition ugbc.h:2900
int bitmaskNeeded
Definition ugbc.h:2659
int enableRle
Definition ugbc.h:2561
CopperList * copperList
Definition ugbc.h:3282
int screenColors
Definition ugbc.h:2870
int dynamicConsole
Definition ugbc.h:3298
FontConfig fontConfig
Definition ugbc.h:2415
int currentModeBW
Definition ugbc.h:2701
int screenHeight
Definition ugbc.h:2860
int consoleTilesWidth
Definition ugbc.h:2890
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
Deployed deployed
Definition ugbc.h:2921
int mspriteMsbokAddress
Definition ugbc.h:2563
VestigialConfig vestigialConfig
Definition ugbc.h:2442
int schema
Definition ugbc.h:2063
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 compression
Definition ugbc.h:558
int bankNumber
Definition ugbc.h:556
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
int selected
Definition ugbc.h:1510
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 usedImage
Definition ugbc.h:1220
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
int value
Definition ugbc.h:1025
int initializedByConstant
Definition ugbc.h:1036
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char rchack_4gravity_1164
Definition ugbc.h:2047
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 _Resource Resource
@ COP_NOP
Definition ugbc.h:2223
@ COP_WAIT
Definition ugbc.h:2225
@ COP_STORE_DWORD
Definition ugbc.h:2229
@ COP_COLOR_BORDER
Definition ugbc.h:2235
@ COP_MOVE_BYTE
Definition ugbc.h:2231
@ COP_MOVE_WORD
Definition ugbc.h:2232
@ COP_STORE_WORD
Definition ugbc.h:2228
@ COP_COLOR
Definition ugbc.h:2237
@ COP_STORE_BYTE
Definition ugbc.h:2227
@ COP_MOVE_DWORD
Definition ugbc.h:2233
@ COP_COLOR_BACKGROUND
Definition ugbc.h:2236
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 outline2(s, a, b)
Definition ugbc.h:4254
#define SPRITE_FLAG_MULTICOLOR
Definition ugbc.h:4559
#define deploy_deferred(s, e)
Definition ugbc.h:4302
struct _Environment Environment
Structure of compilation environment.
#define FLAG_FLIP_X
Definition ugbc.h:4553
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_MSPRITE
Definition ugbc.h:531
@ 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
@ CMP_RLE
Definition ugbc.h:113
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#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
#define outhead2(s, a, b)
Definition ugbc.h:4248
struct _TileDescriptor TileDescriptor
#define CRITICAL_CANNOT_DUPLICATE_NOT_MPSRITE(n)
Definition ugbc.h:3785
#define FLAG_FLIP_Y
Definition ugbc.h:4554
#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 deploy_embedded(s, e)
Definition ugbc.h:4339
struct _CopperList CopperList
#define FLAG_EXACT
Definition ugbc.h:4569
struct _CopperInstruction CopperInstruction
#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
#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 vic2_bitmap_disable(Environment *_environment)
Definition vic2.c:1248
void vic2_tiles_get(Environment *_environment, char *_result)
Definition vic2.c:2069
void vic2_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition vic2.c:4257
void vic2_colormap_at(Environment *_environment, char *_address)
Definition vic2.c:1305
void vic2_sprite_duplicate(Environment *_environment, char *_sprite, char *_original)
Definition vic2.c:1551
void vic2_blit_image(Environment *_environment, char *_sources[], int _source_count, char *_blit, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _flags)
Definition vic2.c:4023
void vic2_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition vic2.c:1814
void vic2_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition vic2.c:1370
void vic2_finalization(Environment *_environment)
Definition vic2.c:2283
void vic2_background_color_semivars(Environment *_environment, int _index, char *_background_color)
VIC-II: emit code to change background color
Definition vic2.c:719
void vic2_sprite_enable(Environment *_environment, char *_sprite)
Definition vic2.c:1594
void vic2_wait_vbl(Environment *_environment, char *_raster_line)
Definition vic2.c:4085
void vic2_sprite_common_color_vars(Environment *_environment, char *_index, char *_common_color)
VIC-II: emit code to change common sprite's color
Definition vic2.c:780
void vic2_sprite_monocolor(Environment *_environment, char *_sprite)
Definition vic2.c:1881
Variable * vic2_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition vic2.c:4126
void vic2_busy_wait(Environment *_environment, char *_timing)
Definition vic2.c:2025
void vic2_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition vic2.c:4298
void vic2_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition vic2.c:4388
void vic2_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition vic2.c:2419
void vic2_back(Environment *_environment)
Definition vic2.c:2431
void vic2_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition vic2.c:2404
void vic2_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition vic2.c:1484
void vic2_bank_select(Environment *_environment, int _bank)
Definition vic2.c:899
void vic2_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition vic2.c:1782
int vic2_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition vic2.c:930
void vic2_fade(Environment *_environment, char *_ticks)
Definition vic2.c:4432
void vic2_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition vic2.c:4370
void vic2_initialization(Environment *_environment)
Definition vic2.c:2180
void vic2_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition vic2.c:2140
void vic2_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
VIC-II: emit code to set raster irq
Definition vic2.c:806
void vic2_bitmap_at(Environment *_environment, char *_address)
Definition vic2.c:1284
int vic2_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition vic2.c:4374
void vic2_tiles_at(Environment *_environment, char *_address)
Definition vic2.c:1991
Variable * vic2_collision(Environment *_environment, char *_sprite)
VIC-II: emit code to check for collision
Definition vic2.c:563
void vic2_next_raster(Environment *_environment)
VIC-II: emit code to wait for next raster irq
Definition vic2.c:851
void vic2_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition vic2.c:3931
void vic2_screen_rows(Environment *_environment, char *_rows)
Definition vic2.c:1444
void vic2_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition vic2.c:3871
void vic2_screen(Environment *_environment, char *_x, char *_y, char *_c)
Definition vic2.c:4451
void vic2_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition vic2.c:2097
Variable * vic2_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition vic2.c:4160
void vic2_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition vic2.c:4195
void vic2_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition vic2.c:1915
void vic2_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition vic2.c:1231
void vic2_get_width(Environment *_environment, char *_result)
Definition vic2.c:2060
Variable * vic2_image_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _mode, int _transparent_color, int _flags)
Definition vic2.c:3262
void vic2_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition vic2.c:1345
void vic2_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
VIC-II: emit code to wait for next raster irq at different position
Definition vic2.c:871
void vic2_screen_off(Environment *_environment)
Definition vic2.c:1436
void vic2_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition vic2.c:1715
void vic2_scroll(Environment *_environment, int _dx, int _dy)
Definition vic2.c:4220
void vic2_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition vic2.c:2122
int vic2_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition vic2.c:2465
RGBi * vic2_image_nearest_system_color(RGBi *_color)
Definition vic2.c:112
Variable * vic2_get_raster_line(Environment *_environment)
Definition vic2.c:4354
void vic2_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition vic2.c:1663
void vic2_flash_begin(Environment *_environment, char *_index, char *_register)
Definition vic2.c:4465
void vic2_get_height(Environment *_environment, char *_result)
Definition vic2.c:2076
void vic2_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition vic2.c:1264
void vic2_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition vic2.c:1404
Variable * vic2_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition vic2.c:4100
void vic2_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
VIC-II: emit code to retrieve background color
Definition vic2.c:743
void vic2_sprite_common_color(Environment *_environment, int _index, int _common_color)
VIC-II: emit code to change common sprite's color
Definition vic2.c:763
void vic2_cline(Environment *_environment, char *_characters)
Definition vic2.c:2439
void vic2_cls(Environment *_environment)
Definition vic2.c:2085
void console_calculate_vars(Environment *_environment)
Definition vic2.c:1221
void vic2_flash_register(Environment *_environment, char *_index, char *_timer, char *_color)
Definition vic2.c:4489
void vic2_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition vic2.c:1953
void vic2_sprite_multicolor(Environment *_environment, char *_sprite)
Definition vic2.c:1846
void vic2_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition vic2.c:4326
void vic2_use_tileset(Environment *_environment, char *_tileset)
Definition vic2.c:4343
void vic2_border_color(Environment *_environment, int _border_color)
Definition vic2.c:637
void vic2_screen_columns(Environment *_environment, char *_columns)
Definition vic2.c:1464
Variable * vic2_sprite_converter(Environment *_environment, char *_source, int _width, int _height, int _depth, RGBi *_color, int _flags, int _slot_x, int _slot_y)
Definition vic2.c:3318
void vic2_textmap_at(Environment *_environment, char *_address)
Definition vic2.c:1324
void vic2_sprite_data_from(Environment *_environment, char *_sprite, char *_image)
Definition vic2.c:1511
void vic2_flash_end(Environment *_environment)
Definition vic2.c:4500
void vic2_screen_on(Environment *_environment)
Definition vic2.c:1428
void vic2_background_color(Environment *_environment, int _index, int _background_color)
VIC-II: emit code to change background color
Definition vic2.c:671
void vic2_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition vic2.c:4236
void vic2_vertical_scroll(Environment *_environment, char *_displacement)
Definition vic2.c:2007
void vic2_hit(Environment *_environment, char *_sprite_mask, char *_result)
VIC-II: emit code to check for collision
Definition vic2.c:616
void vic2_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition vic2.c:1750
void vic2_border_color_vars(Environment *_environment, char *_border_color)
VIC-II: emit code to change border color
Definition vic2.c:653
void vic2_background_color_vars(Environment *_environment, char *_index, char *_background_color)
VIC-II: emit code to change background color
Definition vic2.c:691
void vic2_sprite_disable(Environment *_environment, char *_sprite)
Definition vic2.c:1628
void vic2_flash_off(Environment *_environment, char *_index)
Definition vic2.c:4508
void vic2_horizontal_scroll(Environment *_environment, char *_displacement)
Definition vic2.c:2016
void console_calculate(Environment *_environment)
Definition vic2.c:1186