ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
tms9918.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(__msx1__) || defined(__coleco__) || defined(__sc3000__) || defined(__sg1000__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40static RGBi SYSTEM_PALETTE[] = {
41 { 0, 0, 0, 0x00, 0, "TRANSPARENT" },
42 { 0, 0, 0, 0xff, 1, "BLACK" },
43 { 81, 202, 92, 0xff, 2, "GREEN" },
44 { 133, 223, 141, 0xff, 3, "LIGHT_GREEN" },
45 { 107, 103, 240, 0xff, 4, "DARK_BLUE" },
46 { 146, 136, 255, 0xff, 5, "LIGHT_BLUE" },
47 { 212, 100, 113, 0xff, 6, "DARK_RED" },
48 { 102, 219, 239, 0xff, 7, "CYAN" },
49 { 230, 118, 130, 0xff, 8, "RED" },
50 { 255, 151, 164, 0xff, 9, "LIGHT_RED" },
51 { 215, 207, 97, 0xff, 10, "DARK_YELLOW" },
52 { 230, 222, 112, 0xff, 11, "LIGHT_YELLOW" },
53 { 74, 177, 81, 0xff, 12, "DARK_GREEN" },
54 { 200, 121, 198, 0xff, 13, "MAGENTA" },
55 { 204, 204, 204, 0xff, 14, "GRAY" },
56 { 255, 255, 255, 0xff, 15, "WHITE" }
57};
58
59static RGBi * commonPalette;
61
62/****************************************************************************
63 * CODE SECTION
64 ****************************************************************************/
65
67
68 unsigned int minDistance = 0xffff;
69 int colorIndex = 0;
70 for (int j = 0; j < COLOR_COUNT; ++j) {
71 int distance = rgbi_distance(&SYSTEM_PALETTE[j], _color);
72 if ( _color->alpha < 255 ) {
73 if ( rgbi_equals_rgb( &SYSTEM_PALETTE[j], _color ) ) {
74 minDistance = 0;
75 distance = 0;
76 colorIndex = j;
77 }
78 } else {
79 if ( SYSTEM_PALETTE[j].alpha < 255 ) {
80 continue;
81 }
82 if (distance < minDistance) {
83 minDistance = distance;
84 colorIndex = j;
85 }
86 }
87 }
88
89 return &SYSTEM_PALETTE[colorIndex];
90
91}
92
104static void tms9918_image_converter_tile( Environment * _environment, char * _source, char * _dest, int _width, int _depth, int _source_width ) {
105
106 int colorIndexesCount[COLOR_COUNT];
107
108 int colorBackgroundMax = 0;
109 int colorBackground[8];
110 memset( colorBackground, 0, 8 * sizeof( int ) );
111
112 int colorForegroundMax = 0;
113 int colorForeground[8];
114 memset( colorForeground, 0, 8 * sizeof( int ) );
115
116 char * source = _source;
117
118 // Clear the box and colors
119 memset( _dest, 0, 16 );
120
121 // Loop for all the box surface
122 for (int y=0; y<8; ++y) {
123
124 memset(colorIndexesCount, 0, COLOR_COUNT * sizeof( int ) );
125 colorBackgroundMax = 0;
126 colorForegroundMax = 0;
127
128 for (int x=0; x<8; ++x) {
129
130 RGBi rgb;
131
132 memset( &rgb, 0, sizeof( RGBi ) );
133
134 // Take the color of the pixel
135 rgb.red = *source;
136 rgb.green = *(source + 1);
137 rgb.blue = *(source + 2);
138 if ( _depth > 3 ) {
139 rgb.alpha = *(source + 3);
140 } else {
141 rgb.alpha = 255;
142 }
143 if ( rgb.alpha == 0 ) {
144 rgb.red = 0;
145 rgb.green = 0;
146 rgb.blue = 0;
147 }
148
149 RGBi *systemRgb = tms9918_image_nearest_system_color( &rgb );
150
151 ++colorIndexesCount[systemRgb->index];
152
153 source += _depth;
154
155 }
156
157 // printf( "\n" );
158
159 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
160 if ( colorIndexesCount[xx] > colorBackgroundMax ) {
161 colorBackground[y] = xx;
162 colorBackgroundMax = colorIndexesCount[xx];
163 };
164 }
165
166 colorIndexesCount[colorBackground[y]] = 0;
167
168 for( int xx = 0; xx<COLOR_COUNT; ++xx ) {
169 if ( colorIndexesCount[xx] > colorForegroundMax ) {
170 colorForeground[y] = xx;
171 colorForegroundMax = colorIndexesCount[xx];
172 };
173 }
174
175 if ( colorForeground[y] == 0 ) {
176 colorForeground[y] = colorBackground[y];
177 }
178
179 source += _depth * ( _source_width - 8 );
180
181 }
182
183 source = _source;
184
185 for (int y=0; y<8; ++y) {
186 for (int x=0; x<8; ++x) {
187
188 RGBi rgb;
189
190 memset( &rgb, 0, sizeof( RGBi ) );
191
192 rgb.red = *source;
193 rgb.green = *(source + 1);
194 rgb.blue = *(source + 2);
195 if ( _depth > 3 ) {
196 rgb.alpha = *(source + 3);
197 } else {
198 rgb.alpha = 255;
199 }
200 if ( rgb.alpha == 0 ) {
201 rgb.red = 0;
202 rgb.green = 0;
203 rgb.blue = 0;
204 }
205
206 RGBi *systemRgb = tms9918_image_nearest_system_color( &rgb );
207
208 char bitmask = 1 << ( 7 - ((x) & 0x7) );
209
210 if ( systemRgb->index != colorBackground[y] ) {
211 adilinepixel(colorForeground[y]);
212 *( _dest + y ) |= bitmask;
213 // printf("%1.1x", colorForeground[y]);
214 } else {
215 adilinepixel(colorBackground[y]);
216 *( _dest + y ) &= ~bitmask;
217 // printf("%1.1x", colorBackground[y]);
218 }
219
220 source += _depth;
221
222 }
223
224 // printf("\n");
225
226 source += _depth * ( _source_width - 8 );
227
228 }
229
230 // printf("\n\n----\n\n");
231
232 for( int i=0; i<8; ++i ) {
233 *( _dest + 8 + i ) = ( colorForeground[i] << 4 ) | colorBackground[i] ;
234 }
235
236}
237
249static void tms9918_image_converter_tiles( Environment * _environment, char * _source, char * _dest, int _width, int _height, int _depth, int _source_width ) {
250
251 int bitmapSize = ( _width>>3 ) * _height;
252 int colormapSize = ( _width>>3 ) * _height;
253
254 memset( _dest, 0, bitmapSize + colormapSize );
255
256 adilinebeginbitmap("BMD2");
257
258 for( int y=0; y<_height; y+=8 ) {
259 for( int x=0; x<_width; x+=8 ) {
260
261 char * source = _source + ( ( y * _source_width ) + x ) * _depth;
262 char tile[16];
263
264 tms9918_image_converter_tile( _environment, source, tile, _width, _depth, _source_width );
265
266 int offset = ((y>>3) * 8 *( _width >> 3 ) ) + ((x>>3) * 8) + ((y) & 0x07);
267 // x = 8, y = 8
268 // offset = ((8 >> 3) * 8 * (16>>3) ) + ((8>>3) * 8) + ((8) & 7)
269 // offset = (1 * 8 * 2 ) + (1 * 8)
270 // offset = 16 + 8 = 24
271
272 char * destBitmap = _dest + offset;
273 char * destColormap = _dest + bitmapSize + offset;
274 for( int i=0; i<8; ++i ) {
275 *destBitmap = tile[i];
276 *destColormap = tile[i+8];
277 ++destBitmap;
278 ++destColormap;
279 }
280 }
281 }
282
284
285}
286
298Variable * tms9918_collision( Environment * _environment, char * _sprite ) {
299
300 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
301 Variable * result = variable_temporary( _environment, VT_SBYTE, "(collision)" );
302
303 deploy( sprite, src_hw_tms9918_sprites_asm );
304
305 if ( ! _environment->hasGameLoop ) {
306 outline0("CALL SPRITECOL");
307 } else {
308 outline0("CALL SPRITECOLNMI2");
309 }
310
311 outline1("LD (%s), A", result->realName )
312
313 return result;
314
315}
316
328void tms9918_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
329
330 //todo
331
332}
333
343void tms9918_border_color( Environment * _environment, char * _border_color ) {
344
345// #ifdef __coleco__
346// MAKE_LABEL
347// if ( ! _environment->hasGameLoop ) {
348// outline1("JP %sskip", label );
349// outhead1("%s:", label );
350// }
351// #endif
352 outline1("LD E, %2.2x", VDP_RCOLOR );
353 outline0("CALL VDPREGIN" );
354 outline0("AND $F0" );
355 outline0("LD B, A" );
356 outline1("LD E, %2.2x", VDP_RCOLOR );
357 outline1("LD A, (%s)", _border_color );
358 outline0("AND $0F" );
359 outline0("OR B" );
360 outline0("CALL VDPSETREG" );
361// #ifdef __coleco__
362// if ( ! _environment->hasGameLoop ) {
363// outline0("RET" );
364// outhead1("%sskip:", label );
365// outline0("CALL WAIT_VDP_HOOK" );
366// outline1("LD HL, %s", label );
367// outline0("CALL SET_VDP_HOOK0" );
368// outline0("CALL WAIT_VDP_HOOK" );
369// }
370// #endif
371
372}
373
384void tms9918_background_color( Environment * _environment, int _index, int _background_color ) {
385
386 char value[MAX_TEMPORARY_STORAGE]; sprintf( value, "$%2.2x", _background_color );
387
388 tms9918_background_color_vars( _environment, NULL, value );
389
390}
391
402void tms9918_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
403
405
406 cpu_compare_and_branch_8bit_const( _environment, _index, 0, label, 0 );
407
408 tms9918_border_color( _environment, _background_color );
409
410 cpu_label( _environment, label );
411 outline1( "LD A, (%s)", _index );
412 outline0( "LD E, A" );
413 outline0( "LD A, 0" );
414 outline0( "LD D, A" );
415 outline0( "LD HL, PALETTE" );
416 outline0( "ADD HL, DE" );
417 outline1( "LD A, (%s)", _background_color );
418 outline0( "LD (HL), A" );
419
420}
421
432void tms9918_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
433
434 if ( ! _index ) {
435 tms9918_border_color( _environment, _background_color );
436 }
437
438 outline1( "LD A, $%2.2x", _index );
439 outline0( "LD E, A" );
440 outline0( "LD A, 0" );
441 outline0( "LD D, A" );
442 outline0( "LD HL, PALETTE" );
443 outline0( "ADD HL, DE" );
444 outline1( "LD A, (%s)", _background_color );
445 outline0( "LD (HL), A" );
446
447}
448
459void tms9918_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
460
461 outline1( "LD A, (%s)", _index );
462 outline0( "LD E, A" );
463 outline0( "LD A, 0" );
464 outline0( "LD D, A" );
465 outline0( "LD HL, PALETTE" );
466 outline0( "ADD HL, DE" );
467 outline0( "LD A, (HL)" );
468 outline1( "LD (%s), A", _background_color );
469
470}
471
482void tms9918_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
483
484// #ifdef __coleco__
485// MAKE_LABEL
486// if ( ! _environment->hasGameLoop ) {
487// outline1("JP %sskip", label );
488// outhead1("%s:", label );
489// }
490// #endif
491 outline0("LD HL, $1000");
492 outline1("LD E, (%s)", _index );
493 outline0("SLA E");
494 outline0("SLA E");
495 outline0("INC E");
496 outline0("INC E");
497 outline0("INC E");
498 outline0("LD D, 0");
499 outline0("ADD HL, DE");
500 outline0("CALL VDPINCHAR");
501 outline0("AND $F0");
502 outline0("LD B, A");
503 outline1("LD A, (%s)", _common_color );
504 outline0("OR B");
505 outline0("CALL VDPOUTCHAR");
506// #ifdef __coleco__
507// if ( ! _environment->hasGameLoop ) {
508// outline0("RET" );
509// outhead1("%sskip:", label );
510// outline0("CALL WAIT_VDP_HOOK" );
511// outline1("LD HL, %s", label );
512// outline0("CALL SET_VDP_HOOK0" );
513// outline0("CALL WAIT_VDP_HOOK" );
514// }
515// #endif
516
517}
518
534void tms9918_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
535
536}
537
548void tms9918_next_raster( Environment * _environment ) {
549
550}
551
565void tms9918_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
566
567}
568
569void tms9918_bank_select( Environment * _environment, int _bank ) {
570
571}
572
573static int rgbConverterFunction( int _red, int _green, int _blue ) {
574
575 int colorIndex = 0;
576 unsigned int minDistance = 0xffffffff;
577 int j;
578
579 RGBi rgb;
580 rgb.red = _red;
581 rgb.green = _green;
582 rgb.blue = _blue;
583
584 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
585 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &rgb);
586 if (distance < minDistance) {
587 minDistance = distance;
588 colorIndex = j;
589 }
590 }
591
592 return colorIndex;
593
594}
595
596int tms9918_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
597
598 _screen_mode->selected = 1;
599
600 cpu_store_8bit( _environment, "_PEN", _environment->defaultPenColor );
601 cpu_store_8bit( _environment, "_PAPER", _environment->defaultPaperColor );
602
603// #ifdef __coleco__
604
605// MAKE_LABEL
606
607// if ( ! _environment->hasGameLoop ) {
608// outline1("JP %sdone", label );
609// outhead1("%s:", label );
610// }
611
612// #endif
613
614 switch( _screen_mode->id ) {
615 // M1 M2 M3 Display Mode
616 // 0 0 0 Graphics I Mode
617 // 0 0 1 Graphics II Mode
618 // 0 1 0 Multicolor Mode
619 // 1 0 0 Text Mode
621 _environment->fontWidth = 6;
622 _environment->fontHeight = 8;
623 _environment->screenTilesWidth = 40;
624 _environment->screenTilesHeight = 24;
625 _environment->screenTiles = 255;
626 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
627 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
628 _environment->screenColors = 16;
629 _environment->currentModeBW = 0;
630
631 // M3 = 0
632 WVDP_R0( 0x00 );
633 // 1 + = Selects 16K bytes of VRAM.
634 // 2 + = Enables the active display
635 // 4 + = Enables VDP interrupt
636 // 8 + = M1 x 1 = 8
637 // = M2 x 0 = 0
638 // = Reserved Bit (must be set to O)
639 // = Selects Size 1 sprites (16x16 pixels)
640 // = Selects no magnification
641 WVDP_R1( 0xb2 );
642
643 // Register 2 tells the VDP where the starting address of the Name Table is located in VRAM. The
644 // range of its contents is from O-F. The contents of the register form the upper four bits of
645 // the 14-bit VDP address, therefore making the location of the Name Table in VRAM equal to
646 // (Register 2) * 400 (Hex)
647 WVDP_RNAME( 0x06 );
648
649 cpu_store_16bit( _environment, "TEXTADDRESS", 6 * 0x0400 );
650
651 // Register 4 tells the VDP where the starting address of the Pattern Table is located in VRAM.
652 // The range of its contents is from 0-7. The contents of the register form the upper three bits of
653 // the 14 bit VDP address, therefore making the location of the Pattern Table in VRAM equal to
654 // (Register 4) * 800 (Hex).
655 // 5-3
656 // NOTE
657 // Register 4 functions differently when the VDP is in Graphics II Mode. In this
658 // mode the Pattern Table can only be located in one of two places in VRAM, either
659 // Hex 0000 or Hex 2000. If Hex 0000 is where you wish the Pattern Table to
660 // be located, then the MSB in Register 4 has to be a 0. If Hex 2000 is the location
661 // choice for your Pattern Generator Table, then the MSB in Register 4 must be a
662 // 1. In either case, all the LSBs in Register 4 must be set to ls. Therefore, in
663 // Graphics II Mode the only two values that work correctly in Register 4 are Hex
664 // 03 and Hex 07.
665 WVDP_RPATTERN( 0x00 );
666
667 cpu_store_16bit( _environment, "PATTERNADDRESS", 0x0000 );
668
669 WVDP_RSPRITEA( 0xff );
670 WVDP_RSPRITEP( 0xff );
671
672 outline0("CALL TMS9918AUDCCHAR01");
673 outline0("CALL TMS9918SPRITEINIT");
674
675 WVDP_R1( 0xf2 );
676
677 break;
679 _environment->fontWidth = 8;
680 _environment->fontHeight = 8;
681 _environment->screenTilesWidth = 32;
682 _environment->screenTilesHeight = 24;
683 _environment->screenTiles = 255;
684 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
685 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
686 _environment->screenColors = 16;
687 _environment->currentModeBW = 1;
688
689 // M3 = 0
690 WVDP_R0( 0x00 );
691 // 1 + = Selects 16K bytes of VRAM.
692 // 2 + = Enables the active display
693 // 4 + = Enables VDP interrupt
694 // 8 + = M1 x 0 = 0
695 // = M2 x 0 = 0
696 // = Reserved Bit (must be set to O)
697 // = Selects Size 1 sprites (16x16 pixels)
698 // = Selects no magnification
699 WVDP_R1( 0xa2 );
700
701 // Register 2 tells the VDP where the starting address of the Name Table is located in VRAM. The
702 // range of its contents is from O-F. The contents of the register form the upper four bits of
703 // the 14-bit VDP address, therefore making the location of the Name Table in VRAM equal to
704 // (Register 2) * 400 (Hex)
705 WVDP_RNAME( 0x06 );
706
707 cpu_store_16bit( _environment, "TEXTADDRESS", 6 * 0x0400 );
708
709 // Register 3 tells the VDP where the starting address of the Color Table is located in VRAM. The
710 // range of its contents is from O-FF. The contents of the register form the upper eight bits of
711 // the 14-bit VDP address, therefore making the. location of the Color Table in VRAM equal to
712 // (Register 3) * 40 (Hex).
713 // NOTE
714 // Register 3 functions differently when the VDP is in Graphics II Mode. In this
715 // mode the Color Table can only be located ~n one of two places in VRAM, either
716 // Hex 0000 or Hex 2000. If Hex 0000 is where you wish the Color Table to be
717 // located, then the MSB in Register 3 has to be a O. If Hex 2000 is the location
718 // choice for your Color Table, then the MSB in Register 3 must be a 1. In either
719 // case, all the LSBs in Register 3 must be set to ls. Therefore, in Graphics II
720 // Mode the only two values that work correctly in Register 3 are Hex 7F and Hex
721 // FF.
722 WVDP_RCOLORTABLE( 0x12 );
723
724 cpu_store_16bit( _environment, "COLORMAPADDRESS", 0x0480 );
725
726 // Register 4 tells the VDP where the starting address of the Pattern Table is located in VRAM.
727 // The range of its contents is from 0-7. The contents of the register form the upper three bits of
728 // the 14 bit VDP address, therefore making the location of the Pattern Table in VRAM equal to
729 // (Register 4) * 800 (Hex).
730 // 5-3
731 // NOTE
732 // Register 4 functions differently when the VDP is in Graphics II Mode. In this
733 // mode the Pattern Table can only be located in one of two places in VRAM, either
734 // Hex 0000 or Hex 2000. If Hex 0000 is where you wish the Pattern Table to
735 // be located, then the MSB in Register 4 has to be a 0. If Hex 2000 is the location
736 // choice for your Pattern Generator Table, then the MSB in Register 4 must be a
737 // 1. In either case, all the LSBs in Register 4 must be set to ls. Therefore, in
738 // Graphics II Mode the only two values that work correctly in Register 4 are Hex
739 // 03 and Hex 07.
740 WVDP_RPATTERN( 0x0 );
741
742 cpu_store_16bit( _environment, "PATTERNADDRESS", 0x0000 );
743
744 WVDP_RSPRITEA( 0x20 ); // 1000
745 WVDP_RSPRITEP( 0x00 ); // 0000
746
747 cpu_store_16bit( _environment, "SPRITEAADDRESS", 0x1000 );
748 cpu_store_16bit( _environment, "SPRITEADDRESS", 0x0000 );
749
750 outline0("CALL TMS9918AUDCCHAR01");
751 outline0("CALL TMS9918SPRITEINIT");
752
753 WVDP_R1( 0xe2 );
754
755 break;
758 _environment->fontWidth = 8;
759 _environment->fontHeight = 8;
760 _environment->screenTilesWidth = 32;
761 _environment->screenTilesHeight = 24;
762 _environment->screenTiles = 255;
763 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
764 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
765 _environment->screenColors = 16;
766 _environment->currentModeBW = 1;
767
768 // M3 = 1
769 WVDP_R0( 0x02 );
770 // 1 + = Selects 16K bytes of VRAM.
771 // 2 + = Enables the active display
772 // 4 + = Enables VDP interrupt
773 // 8 + = M1 x 0 = 0
774 // = M2 x 0 = 0
775 // = Reserved Bit (must be set to O)
776 // = Selects Size 1 sprites (16x16 pixels)
777 // = Selects no magnification
778 WVDP_R1( 0x80 );
779
780 // Register 2 tells the VDP where the starting address of the Name Table is located in VRAM. The
781 // range of its contents is from O-F. The contents of the register form the upper four bits of
782 // the 14-bit VDP address, therefore making the location of the Name Table in VRAM equal to
783 // (Register 2) * 400 (Hex)
784 WVDP_RNAME( 0x0e );
785
786 cpu_store_16bit( _environment, "TEXTADDRESS", 0x0e * 0x0400 );
787
788 // Register 3 tells the VDP where the starting address of the Color Table is located in VRAM. The
789 // range of its contents is from O-FF. The contents of the register form the upper eight bits of
790 // the 14-bit VDP address, therefore making the. location of the Color Table in VRAM equal to
791 // (Register 3) * 40 (Hex).
792 // NOTE
793 // Register 3 functions differently when the VDP is in Graphics II Mode. In this
794 // mode the Color Table can only be located ~n one of two places in VRAM, either
795 // Hex 0000 or Hex 2000. If Hex 0000 is where you wish the Color Table to be
796 // located, then the MSB in Register 3 has to be a O. If Hex 2000 is the location
797 // choice for your Color Table, then the MSB in Register 3 must be a 1. In either
798 // case, all the LSBs in Register 3 must be set to ls. Therefore, in Graphics II
799 // Mode the only two values that work correctly in Register 3 are Hex 7F and Hex
800 // FF.
801 WVDP_RCOLORTABLE( 0xff );
802
803 cpu_store_16bit( _environment, "COLORMAPADDRESS", 0x2000 );
804
805 // Register 4 tells the VDP where the starting address of the Pattern Table is located in VRAM.
806 // The range of its contents is from 0-7. The contents of the register form the upper three bits of
807 // the 14 bit VDP address, therefore making the location of the Pattern Table in VRAM equal to
808 // (Register 4) * 800 (Hex).
809 // 5-3
810 // NOTE
811 // Register 4 functions differently when the VDP is in Graphics II Mode. In this
812 // mode the Pattern Table can only be located in one of two places in VRAM, either
813 // Hex 0000 or Hex 2000. If Hex 0000 is where you wish the Pattern Table to
814 // be located, then the MSB in Register 4 has to be a 0. If Hex 2000 is the location
815 // choice for your Pattern Generator Table, then the MSB in Register 4 must be a
816 // 1. In either case, all the LSBs in Register 4 must be set to ls. Therefore, in
817 // Graphics II Mode the only two values that work correctly in Register 4 are Hex
818 // 03 and Hex 07.
819 WVDP_RPATTERN( 0x03 );
820
821 cpu_store_16bit( _environment, "PATTERNADDRESS", 0x0000 );
822
823 WVDP_RSPRITEA( 0x76 ); // 1000
824 WVDP_RSPRITEP( 0x03 ); // 0000
825
826 cpu_store_16bit( _environment, "SPRITEAADDRESS", 0x3b00 );
827 cpu_store_16bit( _environment, "SPRITEADDRESS", 0x1800 );
828
829 outline0("CALL TMS9918AUDCCHAR23");
830 outline0("CALL TMS9918SPRITEINIT");
831
832 WVDP_R1( 0xe2 );
833
834 break;
835 }
836
837 _environment->consoleTilesWidth = _environment->screenTilesWidth;
838 _environment->consoleTilesHeight = _environment->screenTilesHeight;
839
840 cpu_store_16bit( _environment, "CLIPX1", 0 );
841 cpu_store_16bit( _environment, "CLIPX2", (_environment->screenWidth-1) );
842 cpu_store_16bit( _environment, "CLIPY1", 0 );
843 cpu_store_16bit( _environment, "CLIPY2", (_environment->screenHeight-1) );
844
845 cpu_store_16bit( _environment, "ORIGINX", 0 );
846 cpu_store_16bit( _environment, "ORIGINY", 0 );
847
848 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
849 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
850 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
851 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
852 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
853 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
854 cpu_store_8bit( _environment, "CURRENTTILESWIDTHX8", _environment->screenTilesWidth * 8 );
855 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
856 cpu_store_8bit( _environment, "FONTWIDTH", _environment->fontWidth );
857 cpu_store_8bit( _environment, "FONTHEIGHT", _environment->fontHeight );
858 cpu_store_8bit( _environment, "CONSOLEX1", 0 );
859 cpu_store_8bit( _environment, "CONSOLEY1", 0 );
860 cpu_store_8bit( _environment, "CONSOLEX2", _environment->consoleTilesWidth-1 );
861 cpu_store_8bit( _environment, "CONSOLEY2", _environment->consoleTilesHeight-1 );
862 cpu_store_8bit( _environment, "CONSOLEW", _environment->consoleTilesWidth );
863 cpu_store_8bit( _environment, "CONSOLEH", _environment->consoleTilesHeight );
864
865 console_calculate( _environment );
866
867// #ifdef __coleco__
868
869// if ( ! _environment->hasGameLoop ) {
870// outline0("RET");
871// outline1("%sdone:", label );
872// outline0("CALL WAIT_VDP_HOOK" );
873// outline1("LD HL, %s", label );
874// outline0("CALL SET_VDP_HOOK0" );
875// outline0("CALL WAIT_VDP_HOOK");
876// }
877
878// #endif
879
880 // printf("tms9918_tilemap_enable() -> screen tiles width %d\n", _environment->screenTilesWidth );
881
882 if (_environment->vestigialConfig.clsImplicit ) {
883 tms9918_cls( _environment );
884 }
885
886}
887
888void console_calculate( Environment * _environment ) {
889
890 int startAddress = 0;
891
892 switch( _environment->currentMode ) {
893 // M1 M2 M3 Display Mode
894 // 0 0 0 Graphics I Mode
895 // 0 0 1 Graphics II Mode
896 // 0 1 0 Multicolor Mode
897 // 1 0 0 Text Mode
900 startAddress = 6 * 0x0400;
901 break;
904 startAddress = 0x0e * 0x0400;
905 break;
906 }
907
908 int consoleSA = startAddress + ( _environment->activeConsole.y1 * _environment->screenTilesWidth ) + _environment->activeConsole.x1;
909 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
910 int consoleHB = _environment->activeConsole.height * 8;
911
912 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
913 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
914 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
915
916}
917
918void console_calculate_vars( Environment * _environment ) {
919
920 _environment->dynamicConsole = 1;
921
922 outline0( "CALL CONSOLECALCULATE" );
923
924}
925
926void tms9918_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
927
928 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
929
930 if ( mode ) {
931 tms9918_screen_mode_enable( _environment, mode );
932
933 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
934 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
935
936 _environment->currentMode = mode->id;
937 _environment->currentTileMode = 0;
938
939 if (_environment->vestigialConfig.clsImplicit ) {
940 tms9918_cls( _environment );
941 }
942
943 } else {
945 }
946}
947
948void tms9918_bitmap_disable( Environment * _environment ) {
949
950 //todo
951
952}
953
954void tms9918_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
955
956 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
957
958 if ( mode ) {
959
960 // printf("tms9918_tilemap_enable() -> %d\n", mode->id );
961
962 tms9918_screen_mode_enable( _environment, mode );
963
964 _environment->currentMode = mode->id;
965 _environment->currentTileMode = 1;
966
967 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
968 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
969
970 if (_environment->vestigialConfig.clsImplicit ) {
971 tms9918_cls( _environment );
972 }
973
974 } else {
975 // printf("tms9918_tilemap_enable() -> -1\n" );
977 }
978
979}
980
981void tms9918_bitmap_at( Environment * _environment, char * _address ) {
982
983}
984
985void tms9918_colormap_at( Environment * _environment, char * _address ) {
986
987}
988
989void tms9918_textmap_at( Environment * _environment, char * _address ) {
990
991}
992
993void tms9918_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
994
995 deploy( tms9918vars, src_hw_tms9918_vars_asm);
996 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
997 deploy( plot, src_hw_tms9918_plot_asm );
998
999 if ( _c ) {
1000 outline1("LD A, #$%2.2x", ( *_c & 0xff ) );
1001 } else {
1002 Variable * c = variable_retrieve( _environment, "PEN" );
1003 outline1("LD A, (%s)", c->realName );
1004 }
1005 outline0("LD (PLOTCPE), A");
1006 outline1("LD A, $%2.2x", ( _y & 0xff ) );
1007 outline0("LD D, A");
1008 outline1("LD A, $%2.2x", ( _x & 0xff ) );
1009 outline0("LD E, A");
1010 outline1("LD A, $%2.2x", ( ( _x >> 8 ) & 0xff ) );
1011 outline0("LD IXH, A");
1012 outline0("LD A, 1");
1013 if ( ! _environment->hasGameLoop ) {
1014 outline0("CALL PLOT");
1015 } else {
1016 outline0("CALL PLOTNMI2");
1017 }
1018
1019}
1020
1021void tms9918_pset_vars( Environment * _environment, char *_x, char *_y, char *_c ) {
1022
1023 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
1024 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
1025 Variable * c;
1026
1027 if ( _c ) {
1028 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
1029 } else {
1030 c = variable_retrieve( _environment, "PEN" );
1031 }
1032
1033 deploy( tms9918vars, src_hw_tms9918_vars_asm);
1034 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1035 deploy( plot, src_hw_tms9918_plot_asm );
1036
1037 outline1("LD A, (%s)", c->realName );
1038 outline0("LD (PLOTCPE), A");
1039 outline1("LD A, (%s)", y->realName );
1040 outline0("LD D, A");
1041 outline1("LD A, (%s)", x->realName );
1042 outline0("LD E, A");
1043 outline1("LD A, (%s)", address_displacement(_environment, x->realName, "1") );
1044 outline0("LD IXH, A");
1045 outline0("LD A, 1");
1046 if ( ! _environment->hasGameLoop ) {
1047 outline0("CALL PLOT");
1048 } else {
1049 outline0("CALL PLOTNMI2");
1050 }
1051
1052}
1053
1054void tms9918_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
1055
1056 Variable * x = variable_retrieve( _environment, _x );
1057 Variable * y = variable_retrieve( _environment, _y );
1058 Variable * result = variable_retrieve( _environment, _result );
1059
1060 deploy( tms9918vars, src_hw_tms9918_vars_asm);
1061 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1062 deploy( plot, src_hw_tms9918_plot_asm );
1063
1064 outline1("LD A, (%s)", y->realName );
1065 outline0("LD D, A");
1066 outline1("LD A, (%s)", x->realName );
1067 outline0("LD E, A");
1068 outline1("LD A, (%s)", address_displacement( _environment, x->realName, "1" ) );
1069 outline0("LD IXH, A");
1070 outline0("LD A, 3");
1071 if ( ! _environment->hasGameLoop ) {
1072 outline0("CALL PLOT");
1073 } else {
1074 outline0("CALL PLOTNMI2");
1075 }
1076 outline1("LD (%s), A", result->realName);
1077
1078}
1079
1080void tms9918_screen_on( Environment * _environment ) {
1081
1082// #ifdef __coleco__
1083// MAKE_LABEL
1084// if ( ! _environment->hasGameLoop ) {
1085// outline1("JP %sskip", label );
1086// outhead1("%s:", label );
1087// }
1088// #endif
1089 outline1("LD E, %2.2x", VDP_R1 );
1090 outline0("CALL VDPREGIN" );
1091 outline0("OR $40" );
1092 outline0("CALL VDPSETREG" );
1093// #ifdef __coleco__
1094// if ( ! _environment->hasGameLoop ) {
1095// outline0("RET" );
1096// outhead1("%sskip:", label );
1097// outline0("CALL WAIT_VDP_HOOK" );
1098// outline1("LD HL, %s", label );
1099// outline0("CALL SET_VDP_HOOK0" );
1100// outline0("CALL WAIT_VDP_HOOK" );
1101// }
1102// #endif
1103
1104}
1105
1106void tms9918_screen_off( Environment * _environment ) {
1107
1108// #ifdef __coleco__
1109// MAKE_LABEL
1110// if ( ! _environment->hasGameLoop ) {
1111// outline1("JP %sskip", label );
1112// outhead1("%s:", label );
1113// }
1114// #endif
1115 outline1("LD E, %2.2x", VDP_R1 );
1116 outline0("CALL VDPREGIN" );
1117 outline0("AND $BF" );
1118 outline0("CALL VDPSETREG" );
1119// #ifdef __coleco__
1120// if ( ! _environment->hasGameLoop ) {
1121// outline0("RET" );
1122// outhead1("%sskip:", label );
1123// outline0("CALL WAIT_VDP_HOOK" );
1124// outline1("LD HL, %s", label );
1125// outline0("CALL SET_VDP_HOOK0" );
1126// outline0("CALL WAIT_VDP_HOOK" );
1127// }
1128// #endif
1129
1130}
1131
1132void tms9918_screen_rows( Environment * _environment, char * _rows ) {
1133
1134}
1135
1136void tms9918_screen_columns( Environment * _environment, char * _columns ) {
1137
1138}
1139
1140void tms9918_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
1141
1142 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1143 Variable * address = variable_retrieve_or_define( _environment, _address, VT_BYTE, 0 );
1144
1145 deploy( sprite, src_hw_tms9918_sprites_asm );
1146
1147 outline1("LD A, (%s)", sprite->realName );
1148 outline0("LD B, A");
1149 outline1("LD A, (%s)", address->realName );
1150 if ( ! _environment->hasGameLoop ) {
1151 outline0("CALL SPRITEDATASET");
1152 } else {
1153 outline0("CALL SPRITEDATASETNMI2");
1154 }
1155
1156}
1157
1158void tms9918_sprite_data_from( Environment * _environment, char * _sprite, char * _image ) {
1159
1160 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1161 Variable * image = variable_retrieve_or_define( _environment, _image, VT_IMAGE, 0 );
1162
1163 deploy( sprite, src_hw_tms9918_sprites_asm );
1164
1165 outline1("LD A, (%s)", sprite->realName );
1166 outline0("LD B, A");
1167 outline1("LD HL, %s", image->realName );
1168 if ( ! _environment->hasGameLoop ) {
1169 outline0("CALL SPRITEDATAFROM");
1170 } else {
1171 outline0("CALL SPRITEDATAFROMNMI2");
1172 }
1173
1174}
1175
1176void tms9918_sprite_enable( Environment * _environment, char * _sprite ) {
1177
1178 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1179
1180 deploy( sprite, src_hw_tms9918_sprites_asm );
1181
1182 outline1("LD A, (%s)", sprite->realName );
1183 outline0("LD B, A");
1184 if ( ! _environment->hasGameLoop ) {
1185 outline0("CALL SPRITEENABLE");
1186 } else {
1187 outline0("CALL SPRITEENABLENMI2");
1188 }
1189
1190}
1191
1192void tms9918_sprite_disable( Environment * _environment, char * _sprite ) {
1193
1194 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1195
1196 deploy( sprite, src_hw_tms9918_sprites_asm );
1197
1198 outline1("LD A, (%s)", sprite->realName );
1199 outline0("LD B, A");
1200 if ( ! _environment->hasGameLoop ) {
1201 outline0("CALL SPRITEDISABLE");
1202 } else {
1203 outline0("CALL SPRITEDISABLENMI2");
1204 }
1205
1206}
1207
1208void tms9918_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
1209
1210 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1211 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
1212 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
1213
1214 deploy( sprite, src_hw_tms9918_sprites_asm );
1215
1216 outline1("LD A, (%s)", sprite->realName );
1217 outline0("LD B, A");
1218 outline1("LD A, (%s)", x->realName );
1219 outline0("LD H, A");
1220 outline1("LD A, (%s)", y->realName );
1221 outline0("LD L, A");
1222 if ( ! _environment->hasGameLoop ) {
1223 outline0("CALL SPRITEAT");
1224 } else {
1225 outline0("CALL SPRITEATNMI2");
1226 }
1227
1228}
1229
1230void tms9918_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
1231
1232 _sprite = NULL;
1233
1234 deploy( sprite, src_hw_tms9918_sprites_asm );
1235
1236 if ( ! _environment->hasGameLoop ) {
1237 outline0("CALL SPRITEEXPAND");
1238 } else {
1239 outline0("CALL SPRITEEXPANDNMI2");
1240 }
1241
1242}
1243
1244void tms9918_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
1245
1246 _sprite = NULL;
1247
1248 deploy( sprite, src_hw_tms9918_sprites_asm );
1249
1250 if ( ! _environment->hasGameLoop ) {
1251 outline0("CALL SPRITEEXPAND");
1252 } else {
1253 outline0("CALL SPRITEEXPANDNMI2");
1254 }
1255
1256}
1257
1258void tms9918_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
1259
1260 _sprite = NULL;
1261
1262 deploy( sprite, src_hw_tms9918_sprites_asm );
1263
1264 if ( ! _environment->hasGameLoop ) {
1265 outline0("CALL SPRITECOMPRESS");
1266 } else {
1267 outline0("CALL SPRITECOMPRESSNMI2");
1268 }
1269
1270}
1271
1272void tms9918_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
1273
1274 _sprite = NULL;
1275
1276 deploy( sprite, src_hw_tms9918_sprites_asm );
1277
1278 if ( ! _environment->hasGameLoop ) {
1279 outline0("CALL SPRITECOMPRESS");
1280 } else {
1281 outline0("CALL SPRITECOMPRESSNMI2");
1282 }
1283
1284}
1285
1286void tms9918_sprite_multicolor( Environment * _environment, char * _sprite ) {
1287
1288}
1289
1290void tms9918_sprite_monocolor( Environment * _environment, char * _sprite ) {
1291
1292}
1293
1294void tms9918_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
1295
1296 Variable * sprite = variable_retrieve_or_define( _environment, _sprite, VT_BYTE, 0 );
1297 Variable * color = variable_retrieve_or_define( _environment, _color, VT_COLOR, COLOR_WHITE );
1298
1299 deploy( sprite, src_hw_tms9918_sprites_asm );
1300
1301 outline1("LD A, (%s)", sprite->realName );
1302 outline0("LD B, A");
1303 outline1("LD A, (%s)", color->realName );
1304 outline0("LD C, A");
1305 if ( ! _environment->hasGameLoop ) {
1306 outline0("CALL SPRITECOLOR");
1307 } else {
1308 outline0("CALL SPRITECOLORNMI2");
1309 }
1310
1311}
1312
1313void tms9918_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
1314
1315}
1316
1317void tms9918_tiles_at( Environment * _environment, char * _address ) {
1318
1319}
1320
1321void tms9918_vertical_scroll( Environment * _environment, char * _displacement ) {
1322
1323}
1324
1325void tms9918_horizontal_scroll( Environment * _environment, char * _displacement ) {
1326
1327}
1328
1329void tms9918_busy_wait( Environment * _environment, char * _timing ) {
1330
1332
1333 outline1("LD C, (%s)", _timing);
1334 outline0("CALL VDPREGIN");
1335 outhead1("%sfirst:", label );
1336 outline0("CALL VDPREGIN");
1337 outline0("AND $01");
1338 outline1("JP Z, %sfirst", label);
1339 outline0("DEC C");
1340 outline1("JP NZ, %sfirst", label);
1341
1342}
1343
1344void tms9918_get_width( Environment * _environment, char *_result ) {
1345
1346 outline0("LD HL, (CURRENTWIDTH)" );
1347 outline1("LD (%s), HL", _result );
1348
1349}
1350
1351void tms9918_tiles_get( Environment * _environment, char *_result ) {
1352
1353 outline0("LD A, (CURRENTTILES)" );
1354 outline1("LD (%s), A", _result );
1355
1356}
1357
1358void tms9918_get_height( Environment * _environment, char *_result ) {
1359
1360 outline0("LD HL, (CURRENTHEIGHT)" );
1361 outline1("LD (%s), HL", _result );
1362
1363}
1364
1365void tms9918_cls( Environment * _environment ) {
1366
1367 if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1368 deploy( clsGraphic, src_hw_tms9918_cls_graphic_asm );
1369 if ( ! _environment->hasGameLoop ) {
1370 outline0("CALL CLSG");
1371 } else {
1372 outline0("CALL CLSGNMI2");
1373 }
1374 } else {
1375 deploy( clsText, src_hw_tms9918_cls_text_asm );
1376 if ( ! _environment->hasGameLoop ) {
1377 outline0("CALL CLST");
1378 } else {
1379 outline0("CALL CLSTNMI2");
1380 }
1381 }
1382
1383}
1384
1385void tms9918_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
1386
1387 if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1388 deploy( clsBox, src_hw_tms9918_cls_box_asm );
1389 outline1("LD A, (%s)", _x1 );
1390 outline0("LD E, A" );
1391 outline1("LD A, (%s)", _y1 );
1392 outline0("LD D, A" );
1393 outline1("LD A, (%s)", _w);
1394 outline0("LD C, A");
1395 outline1("LD A, (%s)", _h);
1396 outline0("LD B, A");
1397 outline0("CALL CLSBOX");
1398
1399 } else {
1400
1401 }
1402
1403}
1404
1405void tms9918_scroll_text( Environment * _environment, int _direction, int _overlap ) {
1406
1407 if ( _direction > 0 ) {
1408 deploy( vScrollTextDown, src_hw_tms9918_vscroll_text_down_asm );
1409 if ( ! _environment->hasGameLoop ) {
1410 outline0("CALL VSCROLLTDOWN");
1411 } else {
1412 outline0("CALL VSCROLLTDOWNNMI2");
1413 }
1414 } else {
1415 deploy( vScrollTextUp, src_hw_tms9918_vscroll_text_up_asm );
1416 if ( ! _environment->hasGameLoop ) {
1417 outline0("CALL VSCROLLTUP");
1418 } else {
1419 outline0("CALL VSCROLLTUPNMI2");
1420 }
1421 }
1422
1423}
1424
1425void tms9918_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
1426
1427 deploy( tms9918vars, src_hw_tms9918_vars_asm);
1428 deploy( vScrollTextUp, src_hw_tms9918_vscroll_text_up_asm );
1429
1430 outline1("LD DE, (%s)", _text);
1431 outline1("LD A, (%s)", _text_size);
1432 outline0("LD C, A");
1433
1434 if ( _raw ) {
1435
1436 if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1437 deploy( clsGraphic, src_hw_tms9918_cls_graphic_asm );
1438 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1439 deploy( textEncodedAt, src_hw_tms9918_text_asm );
1440 deploy( textEncodedAtGraphicRaw, src_hw_tms9918_text_at_graphic_raw_asm );
1441 if ( ! _environment->hasGameLoop ) {
1442 outline0("CALL TEXTATBITMAPMODERAW");
1443 } else {
1444 outline0("CALL TEXTATBITMAPMODENMI2RAW");
1445 }
1446 } else {
1447 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1448 deploy( clsText, src_hw_tms9918_cls_text_asm );
1449 #if defined(__sc3000__) || defined(__sg1000__) || defined(__msx1__) || defined(__coleco__)
1450 deploy( textEncodedAt, src_hw_tms9918_text_asm );
1451 #endif
1452 deploy( textEncodedAtTextRaw, src_hw_tms9918_text_at_text_raw_asm );
1453 if ( ! _environment->hasGameLoop ) {
1454 outline0("CALL TEXTATTILEMODERAW");
1455 } else {
1456 outline0("CALL TEXTATTILEMODENMI2RAW");
1457 }
1458 }
1459
1460 } else {
1461
1462 if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1463 deploy( clsGraphic, src_hw_tms9918_cls_graphic_asm );
1464 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1465 deploy( textEncodedAt, src_hw_tms9918_text_asm );
1466 deploy( textEncodedAtGraphic, src_hw_tms9918_text_at_graphic_asm );
1467 if ( ! _environment->hasGameLoop ) {
1468 outline0("CALL TEXTATBITMAPMODE");
1469 } else {
1470 outline0("CALL TEXTATBITMAPMODENMI2");
1471 }
1472 } else {
1473 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1474 deploy( clsText, src_hw_tms9918_cls_text_asm );
1475 #if defined(__sc3000__) || defined(__sg1000__) || defined(__msx1__) || defined(__coleco__)
1476 deploy( textEncodedAt, src_hw_tms9918_text_asm );
1477 #endif
1478 deploy( textEncodedAtText, src_hw_tms9918_text_at_text_asm );
1479 if ( ! _environment->hasGameLoop ) {
1480 outline0("CALL TEXTATTILEMODE");
1481 } else {
1482 outline0("CALL TEXTATTILEMODENMI2");
1483 }
1484 }
1485
1486
1487 }
1488
1489}
1490
1491void tms9918_initialization( Environment * _environment ) {
1492
1493 deploy( tms9918vars, src_hw_tms9918_vars_asm );
1494 deploy_preferred( tms9918startup, src_hw_tms9918_startup_asm );
1495
1496 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 256 );
1497 variable_global( _environment, "CURRENTWIDTH" );
1498 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 192 );
1499 variable_global( _environment, "CURRENTHEIGHT" );
1500 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
1501 variable_global( _environment, "CURRENTTILES" );
1502 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 40 );
1503 variable_global( _environment, "CURRENTTILESWIDTH" );
1504 variable_import( _environment, "CURRENTTILESWIDTHX8", VT_WORD, 320 );
1505 variable_global( _environment, "CURRENTTILESWIDTHX8" );
1506 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 24 );
1507 variable_global( _environment, "CURRENTTILESHEIGHT" );
1508 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
1509 variable_global( _environment, "FONTWIDTH" );
1510 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
1511 variable_global( _environment, "FONTHEIGHT" );
1512 variable_import( _environment, "SPRITEADDRESS", VT_ADDRESS, 0x3b00 );
1513 variable_global( _environment, "SPRITEADDRESS" );
1514 variable_import( _environment, "SPRITEAADDRESS", VT_ADDRESS, 0x1800 );
1515 variable_global( _environment, "SPRITEAADDRESS" );
1516 variable_import( _environment, "TEXTADDRESS", VT_ADDRESS, 0x0e * 0x0400 );
1517 variable_global( _environment, "TEXTADDRESS" );
1518 variable_import( _environment, "COLORMAPADDRESS", VT_ADDRESS, 0x2000 );
1519 variable_global( _environment, "COLORMAPADDRESS" );
1520 variable_import( _environment, "PATTERNADDRESS", VT_ADDRESS, 0x0000 );
1521 variable_global( _environment, "PATTERNADDRESS" );
1522 Variable * palette = variable_import( _environment, "PALETTE", VT_BUFFER, 16 );
1523 variable_global( _environment, "PALETTE" );
1524 // palette->readonly = 1;
1525
1526 char defaultPalette[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
1527 variable_store_buffer( _environment, "PALETTE", &defaultPalette[0], 16, 0 );
1528
1529 SCREEN_MODE_DEFINE( TILEMAP_MODE_STANDARD, 0, 40, 24, 20, 6, 8, "Text Mode" );
1530 SCREEN_MODE_DEFINE( BITMAP_MODE_GRAPHIC2, 0, 32, 24, 16, 8, 8, "Graphic II" );
1531 SCREEN_MODE_DEFINE( TILEMAP_MODE_GRAPHIC1, 0, 32, 24, 16, 8, 8, "Graphic I" );
1532
1533 SCREEN_MODE_DEFINE( BITMAP_MODE_GRAPHIC2, 1, 256, 192, 16, 8, 8, "Graphic II" );
1534 SCREEN_MODE_DEFINE( BITMAP_MODE_MULTICOLOR, 1, 256, 192, 16, 8, 8, "Multicolor" );
1535
1536 outline0("CALL TMS9918STARTUP");
1537
1538 variable_import( _environment, "XGR", VT_POSITION, 0 );
1539 variable_global( _environment, "XGR" );
1540 variable_import( _environment, "YGR", VT_POSITION, 0 );
1541 variable_global( _environment, "YGR" );
1542 variable_import( _environment, "LINE", VT_WORD, (unsigned short)(0xffff) );
1543 variable_global( _environment, "LINE" );
1544
1545 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
1546 variable_global( _environment, "CLIPX1" );
1547 variable_import( _environment, "CLIPX2", VT_POSITION, 255 );
1548 variable_global( _environment, "CLIPX2" );
1549 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
1550 variable_global( _environment, "CLIPY1" );
1551 variable_import( _environment, "CLIPY2", VT_POSITION, 191 );
1552 variable_global( _environment, "CLIPY2" );
1553
1554 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
1555 variable_global( _environment, "ORIGINX" );
1556 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
1557 variable_global( _environment, "ORIGINY" );
1558
1559 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
1560 variable_global( _environment, "RESOLUTIONX" );
1561 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
1562 variable_global( _environment, "RESOLUTIONY" );
1563
1564 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
1565 variable_global( _environment, "TABCOUNT" );
1566
1567 variable_import( _environment, "CLINEX", VT_BYTE, 0 );
1568 variable_global( _environment, "CLINEX" );
1569
1570 variable_import( _environment, "CLINEY", VT_BYTE, 0 );
1571 variable_global( _environment, "CLINEY" );
1572
1573 variable_import( _environment, "PLOTCPE", VT_BYTE, 0 );
1574 variable_global( _environment, "PLOTCPE" );
1575
1576 variable_import( _environment, "TABSTODRAW", VT_BYTE, 0 );
1577 variable_global( _environment, "TABSTODRAW" );
1578
1579 variable_import( _environment, "CURRENTMODE", VT_BYTE, 2 );
1580 variable_global( _environment, "CURRENTMODE" );
1581 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
1582 variable_global( _environment, "CURRENTTILEMODE" );
1583
1584 variable_import( _environment, "SPRITECOUNT", VT_SPRITE, 0 );
1585 variable_global( _environment, "SPRITECOUNT" );
1586
1587 variable_import( _environment, "TILEX", VT_BYTE, 0 );
1588 variable_global( _environment, "TILEX" );
1589 variable_import( _environment, "TILEY", VT_BYTE, 0 );
1590 variable_global( _environment, "TILEY" );
1591 variable_import( _environment, "TILEX2", VT_BYTE, 0 );
1592 variable_global( _environment, "TILEX2" );
1593 variable_import( _environment, "TILET", VT_BYTE, 0 );
1594 variable_global( _environment, "TILET" );
1595 variable_import( _environment, "TILEW", VT_BYTE, 0 );
1596 variable_global( _environment, "TILEW" );
1597 variable_import( _environment, "TILEH", VT_BYTE, 0 );
1598 variable_global( _environment, "TILEH" );
1599 variable_import( _environment, "TILEW2", VT_BYTE, 0 );
1600 variable_global( _environment, "TILEW2" );
1601 variable_import( _environment, "TILEH2", VT_BYTE, 0 );
1602 variable_global( _environment, "TILEH2" );
1603 variable_import( _environment, "TILEA", VT_BYTE, 0 );
1604 variable_global( _environment, "TILEA" );
1605 variable_import( _environment, "TILEO", VT_WORD, 0 );
1606 variable_global( _environment, "TILEO" );
1607
1608 variable_import( _environment, "XSCROLLPOS", VT_BYTE, 0 );
1609 variable_global( _environment, "XSCROLLPOS" );
1610 variable_import( _environment, "YSCROLLPOS", VT_BYTE, 0 );
1611 variable_global( _environment, "YSCROLLPOS" );
1612 variable_import( _environment, "XSCROLL", VT_BYTE, 0 );
1613 variable_global( _environment, "XSCROLL" );
1614 variable_import( _environment, "YSCROLL", VT_BYTE, 0 );
1615 variable_global( _environment, "YSCROLL" );
1616 variable_import( _environment, "DIRECTION", VT_BYTE, 0 );
1617 variable_global( _environment, "DIRECTION" );
1618
1619 variable_import( _environment, "ONSCROLLUP", VT_BUFFER, 3 );
1620 variable_global( _environment, "ONSCROLLUP" );
1621
1622 variable_import( _environment, "ONSCROLLDOWN", VT_BUFFER, 3 );
1623 variable_global( _environment, "ONSCROLLDOWN" );
1624
1625 variable_import( _environment, "ONSCROLLLEFT", VT_BUFFER, 3 );
1626 variable_global( _environment, "ONSCROLLLEFT" );
1627
1628 variable_import( _environment, "ONSCROLLRIGHT", VT_BUFFER, 3 );
1629 variable_global( _environment, "ONSCROLLRIGHT" );
1630
1631 variable_import( _environment, "IMAGEF", VT_BYTE, 0 );
1632 variable_global( _environment, "IMAGEF" );
1633
1634 variable_import( _environment, "IMAGET", VT_BYTE, 0 );
1635 variable_global( _environment, "IMAGET" );
1636
1637 variable_import( _environment, "IMAGEY", VT_BYTE, 0 );
1638 variable_global( _environment, "IMAGEY" );
1639
1640 variable_import( _environment, "BLITIMAGEBLITTINGADDR", VT_ADDRESS, 0 );
1641 variable_global( _environment, "BLITIMAGEBLITTINGADDR" );
1642 variable_import( _environment, "BLITTMPPTR", VT_ADDRESS, 0 );
1643 variable_global( _environment, "BLITTMPPTR" );
1644 variable_import( _environment, "BLITTMPPTR2", VT_ADDRESS, 0 );
1645 variable_global( _environment, "BLITTMPPTR2" );
1646
1647 // #if __coleco__
1648 // variable_import( _environment, "VDP_HOOK", VT_BUFFER, 10 );
1649 // variable_global( _environment, "VDP_HOOK" );
1650 // #endif
1651
1652 variable_import( _environment, "VBLFLAG", VT_BYTE, 0 );
1653 variable_global( _environment, "VBLFLAG" );
1654 variable_import( _environment, "VDPINUSE", VT_BYTE, 0 );
1655 variable_global( _environment, "VDPINUSE" );
1656
1657 variable_import( _environment, "SLICEX", VT_POSITION, 0 );
1658 variable_global( _environment, "SLICEX" );
1659 variable_import( _environment, "SLICEY", VT_POSITION, 0 );
1660 variable_global( _environment, "SLICEY" );
1661 variable_import( _environment, "SLICEDTARGET", VT_POSITION, 0 );
1662 variable_global( _environment, "SLICEDTARGET" );
1663
1664 variable_import( _environment, "CONSOLESA", VT_ADDRESS, 0x0 );
1665 variable_global( _environment, "CONSOLESA" );
1666 variable_import( _environment, "CONSOLEHB", VT_BYTE, 0x0 );
1667 variable_global( _environment, "CONSOLEHB" );
1668 variable_import( _environment, "CONSOLEWB", VT_BYTE, 0x0 );
1669 variable_global( _environment, "CONSOLEWB" );
1670
1671 tms9918_tilemap_enable( _environment, 40, 24, 1, 8, 8 );
1672
1673 font_descriptors_init( _environment, 0 );
1674
1675 console_calculate( _environment );
1676
1677 _environment->currentRgbConverterFunction = rgbConverterFunction;
1678 _environment->screenShades = 16;
1679
1680 outline0("CALL TMS9918AFTERINIT");
1681
1682}
1683
1684void tms9918_finalization( Environment * _environment ) {
1685
1686 if ( _environment->vestigialConfig.clsImplicit ) {
1687 deploy( clsText, src_hw_tms9918_cls_text_asm );
1688 }
1689
1690 CopperList * copperList = _environment->copperList;
1691 if ( copperList ) {
1692 while(copperList) {
1693 outhead1("COPPERACTIVATE%s:", copperList->name ? copperList->name : "" );
1694 outline0("RET");
1695 copperList = copperList->next;
1696 }
1697 }
1698
1699}
1700
1701void tms9918_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
1702
1703 deploy( textHScroll, src_hw_tms9918_hscroll_text_asm );
1704
1705 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1706 outline1("LD A, $%2.2x", ( _direction & 0xff ) );
1707 outline1("LD B, (%s)", y->realName );
1708 if ( ! _environment->hasGameLoop ) {
1709 outline0("CALL HSCROLLLT");
1710 } else {
1711 outline0("CALL HSCROLLLTNMI2");
1712 }
1713
1714}
1715
1716void tms9918_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
1717
1718 deploy( textHScroll, src_hw_tms9918_hscroll_text_asm );
1719
1720 outline1("LD A, $%2.2x", ( _direction & 0xff ) );
1721 if ( ! _environment->hasGameLoop ) {
1722 outline0("CALL HSCROLLST");
1723 } else {
1724 outline0("CALL HSCROLLSTNMI2");
1725 }
1726
1727}
1728
1729void tms9918_back( Environment * _environment ) {
1730
1731 deploy( back, src_hw_tms9918_back_asm );
1732
1733 if ( ! _environment->hasGameLoop ) {
1734 outline0("CALL BACK");
1735 } else {
1736 outline0("CALL BACKNMI2");
1737 }
1738
1739}
1740
1741void tms9918_cline( Environment * _environment, char * _characters ) {
1742
1743 deploy( tms9918vars, src_hw_tms9918_vars_asm);
1744
1745 Variable * x = variable_retrieve( _environment, "XCURSYS" );
1746 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1747
1748 outline1("LD A, (%s)", x->realName );
1749 outline0("LD (CLINEX), A" );
1750 outline1("LD A, (%s)", y->realName );
1751 outline0("LD (CLINEY), A");
1752
1753 if ( _characters ) {
1754 outline1("LD A, (%s)", _characters);
1755 outline0("LD C, A");
1756 } else {
1757 outline0("LD A, 0");
1758 outline0("LD C, A");
1759 }
1760
1761 if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1762 deploy( textClineGraphic, src_hw_tms9918_cline_graphic_asm );
1763 if ( ! _environment->hasGameLoop ) {
1764 outline0("CALL CLINEG");
1765 } else {
1766 outline0("CALL CLINEGGMI2");
1767 }
1768 } else {
1769 deploy( textCline, src_hw_tms9918_cline_text_asm );
1770 if ( ! _environment->hasGameLoop ) {
1771 outline0("CALL CLINE");
1772 } else {
1773 outline0("CALL CLINENMI2");
1774 }
1775 }
1776
1777}
1778
1779int tms9918_image_size( Environment * _environment, int _width, int _height, int _mode ) {
1780
1781 switch( _mode ) {
1782
1784
1785 return 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height ) );
1786
1790 break;
1791 }
1792
1793 return 0;
1794
1795}
1796
1797static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1798
1799 switch( _mode ) {
1800
1802
1803 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height ) ) ) * _frames;
1804
1808 break;
1809 }
1810
1811 return 0;
1812
1813}
1814
1815static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1816
1817 switch( _mode ) {
1818
1820
1821 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height ) ) ) * _frames ) * _sequences;
1822
1826 break;
1827 }
1828
1829 return 0;
1830
1831}
1832
1833static Variable * tms9918_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 ) {
1834
1835 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1836
1837 // ignored on bitmap mode
1838 (void)!_transparent_color;
1839
1840 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
1841
1842 if ( _environment->freeImageWidth ) {
1843 if ( _width % 8 ) {
1844 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1845 }
1846 if ( _frame_width % 8 ) {
1847 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1848 }
1849 }
1850
1851 if ( _environment->freeImageHeight ) {
1852 if ( _height % 8 ) {
1853 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
1854 }
1855 if ( _frame_height % 8 ) {
1856 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
1857 }
1858 }
1859
1860 RGBi * palette = malloc_palette( MAX_PALETTE );
1861
1862 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1863
1864 if (paletteColorCount > 16) {
1865 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1866 }
1867
1868 // printf("X PALETTE (%dx%d):\n", _frame_width, _frame_height );
1869 // for( int i=0; i<paletteColorCount; ++i ) {
1870 // printf(" (%2.2d) = %2.2x%2.2x%2.2x%2.2x (%s)\n", i, palette[i].alpha, palette[i].red, palette[i].green, palette[i].blue, palette[i].description );
1871 // }
1872
1873 int i, j, k;
1874
1875 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1876 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1877 lastUsedSlotInCommonPalette = paletteColorCount;
1878 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1879
1880 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE) / sizeof(RGBi)), SYSTEM_PALETTE );
1881
1882 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1884 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1885
1886 int bufferSize = tms9918_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_GRAPHIC2 );
1887
1888 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_GRAPHIC2 );
1889
1890 char * buffer = malloc ( bufferSize );
1891 memset( buffer, 0, bufferSize );
1892
1893 // Position of the pixel in the original image
1894 int image_x, image_y;
1895
1896 // Position of the pixel, in terms of tiles
1897 int tile_x, tile_y;
1898
1899 // Position of the pixel, in terms of offset and bitmask
1900 int offset, offsetc, bitmask;
1901
1902 // Color of the pixel to convert
1903 RGBi rgb;
1904
1905 *(buffer) = (_frame_width & 0xff);
1906 *(buffer+1) = (_frame_width >> 8 ) & 0xff;
1907 *(buffer+2) = _frame_height;
1908
1909 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1910
1911 tms9918_image_converter_tiles( _environment, _source, buffer+3, _frame_width, _frame_height, _depth, _width );
1912
1913 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1914
1915 return result;
1916
1917}
1918
1919Variable * tms9918_sprite_converter( Environment * _environment, char * _source, int _width, int _height, int _depth, RGBi * _color, int _slot_x, int _slot_y ) {
1920
1921 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
1922
1923 RGBi palette[MAX_PALETTE];
1924
1925 int colorUsed = tms9918_palette_extract( _environment, _source, _width, _height, _depth, 0 /* flags */, &palette[0] );
1926
1927 if ( ! _color ) {
1928
1929 if (colorUsed > 2) {
1931 }
1932
1933 }
1934
1935 // int colorUsed = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, 1 /* sorted */);
1936
1937 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1938 result->originalColors = colorUsed;
1939
1940 // int i, j, k;
1941
1942 // for( i=0; i<colorUsed; ++i ) {
1943 // int minDistance = 0xffff;
1944 // int colorIndex = 0;
1945 // for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
1946 // int distance = rgbi_distance(&SYSTEM_PALETTE[j], &palette[i]);
1947 // if (distance < minDistance) {
1948 // for( k=0; k<i; ++k ) {
1949 // if ( palette[k].index == SYSTEM_PALETTE[j].index ) {
1950 // break;
1951 // }
1952 // }
1953 // if ( k>=i ) {
1954 // minDistance = distance;
1955 // colorIndex = j;
1956 // }
1957 // }
1958 // }
1959 // palette[i].index = SYSTEM_PALETTE[colorIndex].index;
1960 // strcopy( palette[i].description, SYSTEM_PALETTE[colorIndex].description );
1961 // }
1962
1963 memcpy( result->originalPalette, palette, MAX_PALETTE * sizeof( RGBi ) );
1964
1965 int bufferSize = ( ( _width >> 3 ) * _height ) + 1;
1966
1967 char * buffer = malloc ( bufferSize );
1968 memset( buffer, 0, bufferSize );
1969
1970 // Position of the pixel in the original image
1971 int image_x, image_y;
1972
1973 // Position of the pixel, in terms of tiles
1974 int tile_x, tile_y;
1975
1976 // Position of the pixel, in terms of offset and bitmask
1977 int offset, bitmask;
1978
1979 int i = 0;
1980
1981 // Color of the pixel to convert
1982 RGBi rgb;
1983
1984 int spriteWidth = 16;
1985 int spriteHeight = 16;
1986
1987 char * source = _source + ( ( _slot_y * spriteHeight * spriteWidth ) + _slot_x * spriteWidth ) * _depth;
1988
1989 // Loop for all the source surface.
1990 for (image_y = 0; image_y < spriteHeight; ++image_y) {
1991 if ( ( image_y + ( _slot_y * spriteHeight ) ) == _height ) {
1992 // printf( "Y" );
1993 break;
1994 }
1995 for (image_x = _slot_x * spriteWidth; image_x < ( _slot_x * spriteWidth ) + spriteWidth; ++image_x) {
1996 if ( ( image_x + ( _slot_x * spriteWidth ) ) == _width ) {
1997 // printf( "X" );
1998 break;
1999 }
2000
2001 // Take the color of the pixel
2002 rgb.red = *source;
2003 rgb.green = *(source + 1);
2004 rgb.blue = *(source + 2);
2005 if ( _depth > 3 ) {
2006 rgb.alpha = *(source + 3);
2007 } else {
2008 rgb.alpha = 255;
2009 }
2010
2011 // Calculate the relative tile
2012
2013 // Calculate the offset starting from the tile surface area
2014 // and the bit to set.
2015 offset = image_y * ( _width >> 4 ) + ( ( image_x & 0x07 ) >> 3 );
2016 if ( image_x > 7 ) {
2017 offset += 16;
2018 }
2019
2020 if ( rgb.alpha < 255 ) {
2021 i = 0;
2022 } else {
2023
2024 if ( ! _color ) {
2025 int minDistance = 0xffff;
2026 RGBi * color = NULL;
2027 int i = 0;
2028 for( int k=0; k<colorUsed; ++k ) {
2029 int distance = rgbi_distance( &palette[k], &rgb );
2030 if ( distance < minDistance ) {
2031 minDistance = distance;
2032 color = &palette[k];
2033 i = k;
2034 }
2035 }
2036 // for( i=0; i<colorUsed; ++i ) {
2037 // // 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 );
2038 // if ( rgbi_equals_rgba( &palette[i], color ) ) {
2039 // break;
2040 // }
2041 // }
2042 } else {
2043 int minDistance = 0xffff;
2044 RGBi * color = NULL;
2045 for( int k=0; k<colorUsed; ++k ) {
2046 if ( palette[k].alpha < 255 ) continue;
2047 int distance = rgbi_distance( &palette[k], &rgb );
2048 if ( distance < minDistance ) {
2049 minDistance = distance;
2050 color = &palette[k];
2051 }
2052 }
2053 if ( rgbi_equals_rgba( _color, color ) ) {
2054 i = 1;
2055 } else {
2056 i = 0;
2057 }
2058 }
2059
2060 }
2061
2062 int colorIndex = i;
2063
2064 bitmask = ( colorIndex == 0 ? 0 : 1 ) << (7 - ((image_x & 0x7)));
2065 *(buffer + offset) |= bitmask;
2066
2067 source += _depth;
2068
2069 }
2070
2071 source += _depth * ( _width - image_x );
2072
2073 }
2074
2075 // printf("\n" );
2076 // printf("\n" );
2077
2078 if ( _color ) {
2079 *(buffer + ( ( _width >> 3 ) * _height )) = _color->index;
2080 } else {
2081 *(buffer + ( ( _width >> 3 ) * _height )) = palette[1].index;
2082 }
2083
2084 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2085
2086 result->readonly = 1;
2087
2088 return result;
2089
2090}
2091
2092Variable * tms9918_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 ) {
2093
2094 switch( _mode ) {
2095
2097
2098 return tms9918_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2099
2100 break;
2101 }
2102
2104
2105 return tms9918_new_image( _environment, 8, 8, BITMAP_MODE_GRAPHIC2 );
2106
2107}
2108
2109static void tms9918_load_image_address_to_other_register( Environment * _environment, char * _register, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2110
2111 outline1("LD HL, %s", _source );
2112 if ( _sequence ) {
2113
2114 outline0("LD DE, $0003" );
2115 outline0("ADD HL, DE" );
2116 if ( strlen(_sequence) == 0 ) {
2117
2118 } else {
2119 outline0("PUSH HL" );
2120 outline1("LD A, (%s)", _sequence );
2121 outline0("LD L, A" );
2122 outline0("LD H, 0" );
2123 outline0("ADD HL, HL" );
2124 outline0("LD DE, HL" );
2125 outline1("LD HL, OFFSETS%4.4x", _frame_size * _frame_count );
2126 outline0("ADD HL, DE" );
2127 outline0("LD A, (HL)" );
2128 outline0("LD E, A" );
2129 outline0("INC HL" );
2130 outline0("LD A, (HL)" );
2131 outline0("LD D, A" );
2132 outline0("POP HL" );
2133 outline0("ADD HL, DE" );
2134 }
2135
2136 if ( _frame ) {
2137 if ( strlen(_frame) == 0 ) {
2138
2139 } else {
2140 outline0("PUSH HL" );
2141 outline1("LD A, (%s)", _frame );
2142 outline0("LD L, A" );
2143 outline0("LD H, 0" );
2144 outline0("ADD HL, HL" );
2145 outline0("LD DE, HL" );
2146 outline1("LD HL, OFFSETS%4.4x", _frame_size * _frame_count );
2147 outline0("ADD HL, DE" );
2148 outline0("LD A, (HL)" );
2149 outline0("LD E, A" );
2150 outline0("INC HL" );
2151 outline0("LD A, (HL)" );
2152 outline0("LD D, A" );
2153 outline0("POP HL" );
2154 outline0("ADD HL, DE" );
2155 }
2156 }
2157
2158 } else {
2159
2160 if ( _frame ) {
2161 outline0("LD DE, $0003" );
2162 outline0("ADD HL, DE" );
2163 if ( strlen(_frame) == 0 ) {
2164
2165 } else {
2166 outline0("PUSH HL" );
2167 outline1("LD A, (%s)", _frame );
2168 outline0("LD L, A" );
2169 outline0("LD H, 0" );
2170 outline0("ADD HL, HL" );
2171 outline0("LD DE, HL" );
2172 outline1("LD HL, OFFSETS%4.4x", _frame_size );
2173 outline0("ADD HL, DE" );
2174 outline0("LD A, (HL)" );
2175 outline0("LD E, A" );
2176 outline0("INC HL" );
2177 outline0("LD A, (HL)" );
2178 outline0("LD D, A" );
2179 outline0("POP HL" );
2180 outline0("ADD HL, DE" );
2181 }
2182 }
2183
2184 }
2185
2186 if ( _register ) {
2187 outline1("LD (%s), HL", _register );
2188 }
2189
2190}
2191
2192static void tms9918_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2193
2194 if ( _source->isAddress ) {
2195 outline1("LD HL, (%s)", _source->realName );
2196 } else {
2197 outline1("LD HL, %s", _source->realName );
2198 }
2199
2200 if ( _frame_size ) {
2201
2202 if ( !_sequence && !_frame ) {
2203 } else {
2204 if ( _sequence ) {
2205 outline0("LD DE, $0003" );
2206 outline0("ADD HL, DE" );
2207 if ( strlen(_sequence) == 0 ) {
2208
2209 } else {
2210 outline1("LD A, (%s)", _sequence );
2211 outline0("PUSH HL" );
2212 outline0("POP IX" );
2213 outline1("CALL %soffsetsequence", _source->realName );
2214 }
2215 if ( _frame ) {
2216 if ( strlen(_frame) == 0 ) {
2217
2218 } else {
2219 outline1("LD A, (%s)", _frame );
2220 outline0("PUSH HL" );
2221 outline0("POP IX" );
2222 outline1("CALL %soffsetframe", _source->realName );
2223 }
2224 }
2225
2226 } else {
2227
2228 if ( _frame ) {
2229 outline0("LD DE, $0003" );
2230 outline0("ADD HL, DE" );
2231 if ( strlen(_frame) == 0 ) {
2232
2233 } else {
2234 outline0("PUSH HL" );
2235 outline0("POP IX" );
2236 outline1("LD A, (%s)", _frame );
2237 outline1("CALL %soffsetframe", _source->realName );
2238 }
2239 }
2240
2241 }
2242
2243 }
2244
2245 }
2246
2247 if ( _register ) {
2248 outline1("LD (%s), HL", _register );
2249 }
2250
2251}
2252
2253
2254void tms9918_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 ) {
2255
2256 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2257 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2258 deploy( blitimage, src_hw_tms9918_blit_image_asm );
2259
2260 if ( _source_count > 2 ) {
2262 }
2263
2265
2266 outline1("LD HL, %s", _blit );
2267 outline0("LD (BLITIMAGEBLITTINGADDR), HL");
2268
2269 outhead1("blitimage%s:", label);
2270 if ( _source_count > 0 ) {
2271 Resource resource;
2272 resource.realName = strdup( _sources[0] );
2273 resource.type = VT_IMAGE;
2274 resource.isAddress = 0;
2275 tms9918_load_image_address_to_register( _environment, "BLITTMPPTR", &resource, _sequence, _frame, _frame_size, _frame_count );
2276 } else {
2277 outline0( "LD HL, 0" );
2278 outline0( "LD (BLITTMPPTR), HL" );
2279 }
2280
2281 if ( _source_count > 1 ) {
2282 Resource resource;
2283 resource.realName = strdup( _sources[0] );
2284 resource.type = VT_IMAGE;
2285 resource.isAddress = 0;
2286 tms9918_load_image_address_to_register( _environment, "BLITTMPPTR2", &resource, _sequence, _frame, _frame_size, _frame_count );
2287 } else {
2288 outline0( "LD HL, 0" );
2289 outline0( "LD (BLITTMPPTR2), HL" );
2290 }
2291
2292 outline1("LD A, (%s)", _x );
2293 outline0("LD E, A" );
2294 outline1("LD A, (%s)", _y );
2295 outline0("LD D, A" );
2296
2297 outline0("PUSH HL" );
2298 outline1("LD HL, %4.4x", _flags );
2299 outline0("LD A, L" );
2300 outline0("LD (IMAGEF), A" );
2301 outline0("LD A, H" );
2302 outline0("LD (IMAGET), A" );
2303 outline0("POP HL" );
2304
2305 if ( ! _environment->hasGameLoop ) {
2306 outline0("CALL BLITIMAGE");
2307 } else {
2308 outline0("CALL BLITIMAGENMI2");
2309 }
2310
2311}
2312
2313void tms9918_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
2314
2315 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2316 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2317 deploy( putimage, src_hw_tms9918_put_image_asm );
2318
2320
2321 outhead1("putimage%s:", label);
2322
2323 tms9918_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2324
2325 outline1("LD A, (%s)", _x );
2326 outline0("LD E, A" );
2327 outline1("LD A, (%s)", _y );
2328 outline0("LD D, A" );
2329 outline1("LD A, (%s)", _flags );
2330 outline0("LD (IMAGEF), A" );
2331 outline1("LD A, (%s)", address_displacement(_environment, _flags, "1") );
2332 outline0("LD (IMAGET), A" );
2333
2334 if ( ! _environment->hasGameLoop ) {
2335 outline0("CALL PUTIMAGE");
2336 } else {
2337 outline0("CALL PUTIMAGENMI2");
2338 }
2339
2340}
2341
2342void tms9918_wait_vbl( Environment * _environment ) {
2343
2344 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2345 deploy( vbl, src_hw_tms9918_vbl_asm);
2346
2347 outline0("JSR VBL");
2348
2349}
2350
2351Variable * tms9918_new_image( Environment * _environment, int _width, int _height, int _mode ) {
2352
2353 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2354
2355 int size = tms9918_image_size( _environment, _width, _height, _mode );
2356
2357 if ( ! size ) {
2359 }
2360
2361 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
2362
2363 char * buffer = malloc ( size );
2364 memset( buffer, 0, size );
2365
2366 *(buffer) = (_width & 0xff);
2367 *(buffer+1) = (_width>>8) & 0xff;
2368 *(buffer+2) = _height;
2369
2370 result->valueBuffer = buffer;
2371 result->size = size;
2372
2373 return result;
2374
2375}
2376
2377Variable * tms9918_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2378
2379 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2380
2381 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2382 int frameSize = tms9918_image_size( _environment, _width, _height, _mode );
2383
2384 if ( ! size ) {
2386 }
2387
2388 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
2389
2390 char * buffer = malloc ( size );
2391 memset( buffer, 0, size );
2392
2393 *(buffer) = _frames;
2394 *(buffer+1) = ( _width & 0xff );
2395 *(buffer+2) = ( _width >> 8 ) & 0xff;
2396 for( int i=0; i<_frames; ++i ) {
2397 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2398 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2399 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2400 }
2401
2402 result->valueBuffer = buffer;
2403 result->frameSize = frameSize;
2404 result->size = size;
2405 result->frameCount = _frames;
2406
2407 return result;
2408
2409}
2410
2411Variable * tms9918_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2412
2413 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2414
2415 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
2416 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2417 int frameSize = tms9918_image_size( _environment, _width, _height, _mode );
2418
2419 if ( ! size ) {
2421 }
2422
2423 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
2424
2425 char * buffer = malloc ( size2 );
2426 memset( buffer, 0, size2 );
2427
2428 *(buffer) = _frames;
2429 *(buffer+1) = _width;
2430 *(buffer+2) = _sequences;
2431 for( int i=0; i<(_frames*_sequences); ++i ) {
2432 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2433 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2434 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2435 }
2436
2437 result->valueBuffer = buffer;
2438 result->frameSize = frameSize;
2439 result->size = size2;
2440 result->frameCount = _frames;
2441
2442 return result;
2443
2444}
2445
2446void tms9918_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
2447
2448 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2449 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2450 deploy( getimage, src_hw_tms9918_get_image_asm );
2451
2453
2454 tms9918_load_image_address_to_other_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2455
2456 outline1("LD A, (%s)", _x );
2457 outline0("LD E, A" );
2458 outline1("LD A, (%s)", _y );
2459 outline0("LD D, A" );
2460 outline1("LD A, $%2.2x", _palette );
2461 outline0("LD IXH, A" );
2462
2463 if ( ! _environment->hasGameLoop ) {
2464 outline0("CALL GETIMAGE");
2465 } else {
2466 outline0("CALL GETIMAGENMI2");
2467 }
2468
2469}
2470
2471
2472void tms9918_scroll( Environment * _environment, int _dx, int _dy ) {
2473
2474 deploy( vic2vars, src_hw_tms9918_vars_asm);
2475 deploy( scroll, src_hw_tms9918_scroll_asm);
2476 deploy( textHScroll, src_hw_tms9918_hscroll_text_asm );
2477 deploy( vScrollTextDown, src_hw_tms9918_vscroll_text_down_asm );
2478 deploy( vScrollTextUp, src_hw_tms9918_vscroll_text_up_asm );
2479
2480 outline1("LD A, $%2.2x", (unsigned char)(_dx&0xff) );
2481 outline0("LD B, A" );
2482 outline1("LD A, $%2.2x", (unsigned char)(_dy&0xff) );
2483 outline0("LD C, A" );
2484 outline0("CALL SCROLL");
2485
2486}
2487
2488void tms9918_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
2489
2490 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2491 deploy( tiles, src_hw_tms9918_tiles_asm );
2492
2493 outline1("LD A, (%s)", _tile );
2494 outline0("LD (TILET), A" );
2495 outline1("LD A, (%s)", _x );
2496 outline0("LD (TILEX), A" );
2497 outline1("LD A, (%s)", _y );
2498 outline0("LD (TILEY), A" );
2499 outline0("LD A, 1" );
2500 outline0("LD (TILEW), A" );
2501 outline0("LD (TILEH), A" );
2502 outline0("LD (TILEW2), A" );
2503 outline0("LD (TILEH2), A" );
2504
2505 if ( ! _environment->hasGameLoop ) {
2506 outline0("CALL PUTTILE");
2507 } else {
2508 outline0("CALL PUTTILENMI2");
2509 }
2510
2511}
2512
2513void tms9918_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
2514
2515 Variable * tile = variable_retrieve( _environment, _tile );
2516 Variable * x = variable_retrieve( _environment, _x );
2517 Variable * y = variable_retrieve( _environment, _y );
2518
2519 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2520 deploy( tiles, src_hw_tms9918_tiles_asm );
2521
2522 int size = ( tile->originalWidth >> 3 ) * ( tile->originalHeight >> 3 );
2523
2524 if ( size ) {
2525 outline1("LD HL, OFFSETS%4.4x", size );
2526 outline0("LD A, L" );
2527 outline0("LD (TILEO), A" );
2528 outline0("LD A, H" );
2529 outline0("LD (TILEO+1), A" );
2530 } else {
2531 outline0("LD A, 0" );
2532 outline0("LD (TILEO), A" );
2533 outline0("LD (TILEO+1), A" );
2534 }
2535
2536 outline1("LD A, (%s)", tile->realName );
2537 outline0("LD (TILET), A" );
2538 outline1("LD A, (%s)", x->realName );
2539 outline0("LD (TILEX), A" );
2540 outline1("LD A, (%s)", y->realName );
2541 outline0("LD (TILEY), A" );
2542 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "1") );
2543 outline0("LD (TILEW), A" );
2544 outline0("LD (TILEW2), A" );
2545 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "2") );
2546 outline0("LD (TILEH), A" );
2547 outline0("LD (TILEH2), A" );
2548 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "3") );
2549 outline0("LD (TILEA), A" );
2550
2551 if ( ! _environment->hasGameLoop ) {
2552 outline0("CALL MOVETILE");
2553 } else {
2554 outline0("CALL MOVETILENMI2");
2555 }
2556
2557}
2558
2559void tms9918_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
2560
2561 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2562 deploy( tiles, src_hw_tms9918_tiles_asm );
2563
2564 outline1("LD A, (%s)", _tile );
2565 outline0("LD (TILET), A" );
2566 outline1("LD A, (%s)", _x );
2567 outline0("LD (TILEX), A" );
2568 outline1("LD A, (%s)", _y );
2569 outline0("LD (TILEY), A" );
2570 outline1("LD A, (%s)", address_displacement(_environment, _tile, "1") );
2571 outline0("LD (TILEW), A" );
2572 if ( _w ) {
2573 outline1("LD A, (%s)", _w );
2574 }
2575 outline0("LD (TILEW2), A" );
2576 outline1("LD A, (%s)", address_displacement(_environment, _tile, "2") );
2577 outline0("LD (TILEH), A" );
2578 if ( _h ) {
2579 outline1("LD A, (%s)", _h );
2580 }
2581 outline0("LD (TILEH2), A" );
2582
2583 if ( ! _environment->hasGameLoop ) {
2584 outline0("CALL PUTTILE");
2585 } else {
2586 outline0("CALL PUTTILENMI2");
2587 }
2588
2589}
2590
2591void tms9918_tile_at( Environment * _environment, char * _x, char * _y, char *_result ) {
2592
2593 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2594 deploy( tiles, src_hw_tms9918_tiles_asm );
2595
2596 outline1("LD A, (%s)", _x );
2597 outline0("LD (TILEX), A" );
2598 outline1("LD A, (%s)", _y );
2599 outline0("LD (TILEY), A" );
2600
2601 if ( ! _environment->hasGameLoop ) {
2602 outline0("CALL TILEAT");
2603 } else {
2604 outline0("CALL TILEATNMI2");
2605 }
2606
2607 outline0("LD A, (TILET)" );
2608 outline1("LD (%s), A", _result );
2609
2610}
2611
2612void tms9918_use_tileset( Environment * _environment, char * _tileset ) {
2613
2614 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2615 deploy( tiles, src_hw_tms9918_tiles_asm );
2616
2617 outline1("LD A, (%s)", _tileset );
2618
2619 if ( ! _environment->hasGameLoop ) {
2620 outline0("CALL USETILESET");
2621 } else {
2622 outline0("CALL USETILESETNMI2");
2623 }
2624
2625}
2626
2628
2629 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
2630
2631 variable_store( _environment, result->name, 0 );
2632
2633 return result;
2634
2635}
2636
2637void tms9918_move_memory_video( Environment * _environment, char * _from, char * _to, char * _size ) {
2638
2639 outline1("LD HL, (%s)", _from );
2640 outline1("LD DE, (%s)", _to );
2641 outline1("LD BC, (%s)", _size );
2642 outline0("CALL VDPWRITE" );
2643
2644}
2645
2646void tms9918_move_video_memory( Environment * _environment, char * _from, char * _to, char * _size ) {
2647
2648 outline1("LD HL, (%s)", _to );
2649 outline1("LD DE, (%s)", _from );
2650 outline1("LD BC, (%s)", _size );
2651 outline0("CALL VDPREAD" );
2652
2653}
2654
2655void tms9918_colors_vars( Environment * _environment, char * _foreground_color, char * _background_color ) {
2656
2657// #ifdef __coleco__
2658// MAKE_LABEL
2659// if ( ! _environment->hasGameLoop ) {
2660// outline1("JP %sskip", label );
2661// outhead1("%s:", label );
2662// }
2663// #endif
2664 outline1("LD E, %2.2x", VDP_RCOLOR );
2665 outline0("CALL VDPREGIN" );
2666 outline1("LD A, (%s)", _foreground_color );
2667 outline0("SLA A" );
2668 outline0("SLA A" );
2669 outline0("SLA A" );
2670 outline0("SLA A" );
2671 outline0("LD B, A" );
2672 outline1("LD A, (%s)", _background_color );
2673 outline0("OR B" );
2674 outline0("CALL VDPSETREG" );
2675// #ifdef __coleco__
2676// if ( ! _environment->hasGameLoop ) {
2677// outline0("RET" );
2678// outhead1("%sskip:", label );
2679// outline0("CALL WAIT_VDP_HOOK" );
2680// outline1("LD HL, %s", label );
2681// outline0("CALL SET_VDP_HOOK0" );
2682// outline0("CALL WAIT_VDP_HOOK" );
2683// }
2684// #endif
2685
2686}
2687
2688void tms9918_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2689
2690}
2691
2692void tms9918_slice_image_copy( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2693
2694 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2695 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm);
2696 deploy( duff, src_hw_z80_duff_asm );
2697 deploy( sliceimagecopy, src_hw_tms9918_slice_image_copy_asm );
2698
2700
2701 Resource resource;
2702 resource.realName = strdup( _image );
2703 resource.type = VT_IMAGE;
2704 tms9918_load_image_address_to_register( _environment, NULL, &resource, _sequence, _frame, _frame_size, _frame_count );
2705
2706 outline1( "LD DE, %s", _destination );
2707
2708 outline0("CALL SLICEIMAGECOPY");
2709
2710}
2711
2712void tms9918_slice_image_extract( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2713
2714 deploy( tms9918vars, src_hw_tms9918_vars_asm);
2715 deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm);
2716 deploy( duff, src_hw_z80_duff_asm );
2717 deploy( sliceimageextract, src_hw_tms9918_slice_image_extract_asm );
2718
2720
2721 Resource resource;
2722 resource.realName = strdup( _image );
2723 resource.type = VT_IMAGE;
2724 tms9918_load_image_address_to_register( _environment, NULL, &resource, _sequence, _frame, _frame_size, _frame_count );
2725
2726 Variable * sliceImageX = variable_retrieve( _environment, _environment->sliceImageX );
2727 Variable * sliceImageY = variable_retrieve( _environment, _environment->sliceImageY );
2728 outline1( "LD DE, (%s)", sliceImageX->realName );
2729 outline0( "LD (SLICEX), DE" );
2730 outline1( "LD DE, (%s)", sliceImageY->realName );
2731 outline0( "LD (SLICEY), DE" );
2732 outline1( "LD DE, %s", _destination );
2733
2734 outline0("CALL SLICEIMAGEEXT");
2735
2736}
2737
2738int tms9918_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
2739
2740 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2741
2742 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
2743
2744 int uniquePaletteCount = 0;
2745
2746 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
2747
2748 return uniquePaletteCount;
2749
2750}
2751
2752void tms9918_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2753
2754 if ( !_sequence && !_frame ) {
2755 outline0("LD HL, 0" );
2756 } else {
2757 outline0("LD HL, 0" );
2758
2759 if ( _sequence ) {
2760 outline0("LD DE, $0003" );
2761 outline0("ADD HL, DE" );
2762 if ( strlen(_sequence) == 0 ) {
2763
2764 } else {
2765 outline1("LD A, (%s)", _sequence );
2766 outline0("PUSH HL" );
2767 outline0("POP IX" );
2768 outline1("CALL fs%4.4Xoffsetsequence", _frame_count * _frame_size );
2769 }
2770 if ( _frame ) {
2771 if ( strlen(_frame) == 0 ) {
2772
2773 } else {
2774 outline1("LD A, (%s)", _frame );
2775 outline0("PUSH HL" );
2776 outline0("POP IX" );
2777 outline1("CALL fs%4.4Xoffsetframe", _frame_size );
2778 }
2779 }
2780
2781 } else {
2782
2783 if ( _frame ) {
2784 outline0("LD DE, $0003" );
2785 outline0("ADD HL, DE" );
2786 if ( strlen(_frame) == 0 ) {
2787
2788 } else {
2789 outline0("PUSH HL" );
2790 outline0("POP IX" );
2791 outline1("LD A, (%s)", _frame );
2792 outline1("CALL fs%4.4Xoffsetframe", _frame_size );
2793 }
2794 }
2795
2796 }
2797
2798 }
2799 outline1("LD (%s), HL", _offset );
2800
2801}
2802
2803void tms9918_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
2804
2805 // deploy( tms9918vars, src_hw_tms9918_vars_asm);
2806 // deploy( tms9918varsGraphic, src_hw_tms9918_vars_graphic_asm );
2807
2808 // MAKE_LABEL
2809
2810 // if ( _direction & FLAG_FLIP_X ) {
2811 // tms9918_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2812 // deploy( flipimagex, src_hw_tms9918_flip_image_x_asm );
2813 // outline0("CALL FLIPIMAGEX");
2814 // }
2815
2816 // if ( _direction & FLAG_FLIP_Y ) {
2817 // ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2818 // deploy( flipimagey, src_hw_tms9918_flip_image_y_asm );
2819 // outline0("CALL FLIPIMAGEY");
2820 // }
2821
2822}
2823
2824void tms9918_screen( Environment * _environment, char * _x, char * _y, char * _c ) {
2825
2826 deploy( screen, src_hw_tms9918_screen_asm);
2827
2828 outline1("LD A, (%s)", _x );
2829 outline0("LD C, A" );
2830 outline1("LD A, (%s)", _y );
2831 outline0("LD B, A" );
2832 outline0("CALL SCREEN" );
2833 outline1("LD (%s), A", _c );
2834
2835}
2836
2837#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_label(Environment *_environment, char *_label)
Definition 6309.c:356
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_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
int lastUsedSlotInCommonPalette
Definition 6847.c:100
#define COLOR_COUNT
Definition 6847.h:72
#define COLOR_WHITE
Definition 6847.h:39
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
int rgbi_equals_rgba(RGBi *_first, RGBi *_second)
int rgbi_equals_rgb(RGBi *_first, RGBi *_second)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * malloc_palette(int _size)
Allocate a palette space.
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.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
void font_descriptors_init(Environment *_environment, int _embedded_present)
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
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
#define BITMAP_MODE_GRAPHIC2
Definition cpc.h:238
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
int width
Definition ugbc.h:2209
int y1
Definition ugbc.h:2206
int x1
Definition ugbc.h:2205
int height
Definition ugbc.h:2210
char * name
Definition ugbc.h:2252
struct _CopperList * next
Definition ugbc.h:2255
int screenTilesWidth
Definition ugbc.h:2880
int screenShades
Definition ugbc.h:2865
int fontHeight
Definition ugbc.h:2905
Console activeConsole
Definition ugbc.h:2910
char * sliceImageX
Definition ugbc.h:3075
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
CopperList * copperList
Definition ugbc.h:3282
int screenColors
Definition ugbc.h:2870
int hasGameLoop
Definition ugbc.h:2646
int dynamicConsole
Definition ugbc.h:3298
int currentModeBW
Definition ugbc.h:2701
int screenHeight
Definition ugbc.h:2860
char * sliceImageY
Definition ugbc.h:3080
int consoleTilesWidth
Definition ugbc.h:2890
int currentTileMode
Definition ugbc.h:2706
int screenTiles
Definition ugbc.h:2875
int freeImageHeight
Definition ugbc.h:3086
int screenWidth
Definition ugbc.h:2855
int defaultPaperColor
Definition ugbc.h:3226
int defaultPenColor
Definition ugbc.h:3225
VestigialConfig vestigialConfig
Definition ugbc.h:2442
unsigned char red
Definition ugbc.h:433
unsigned char green
Definition ugbc.h:434
unsigned char blue
Definition ugbc.h:435
unsigned char alpha
Definition ugbc.h:436
unsigned char index
Definition ugbc.h:437
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
int selected
Definition ugbc.h:1510
unsigned char * valueBuffer
Definition ugbc.h:1061
int size
Definition ugbc.h:1077
int originalHeight
Definition ugbc.h:1148
char * name
Definition ugbc.h:979
int originalColors
Definition ugbc.h:1154
int frameSize
Definition ugbc.h:1134
int readonly
Definition ugbc.h:1195
int frameCount
Definition ugbc.h:1137
int originalWidth
Definition ugbc.h:1145
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
#define BITMAP_MODE_MULTICOLOR
Definition ted.h:77
void tms9918_cline(Environment *_environment, char *_characters)
Definition tms9918.c:1741
void tms9918_finalization(Environment *_environment)
Definition tms9918.c:1684
void tms9918_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition tms9918.c:2752
Variable * tms9918_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition tms9918.c:2377
void tms9918_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition tms9918.c:1140
void tms9918_sprite_multicolor(Environment *_environment, char *_sprite)
Definition tms9918.c:1286
void tms9918_hit(Environment *_environment, char *_sprite_mask, char *_result)
TMS9918: emit code to check for collision
Definition tms9918.c:328
void tms9918_background_color(Environment *_environment, int _index, int _background_color)
TMS9918: emit code to change background color
Definition tms9918.c:384
Variable * tms9918_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition tms9918.c:2411
void tms9918_background_color_vars(Environment *_environment, char *_index, char *_background_color)
TMS9918: emit code to change background color
Definition tms9918.c:402
Variable * tms9918_collision(Environment *_environment, char *_sprite)
TMS9918: emit code to check for collision
Definition tms9918.c:298
Variable * tms9918_sprite_converter(Environment *_environment, char *_source, int _width, int _height, int _depth, RGBi *_color, int _slot_x, int _slot_y)
Definition tms9918.c:1919
void tms9918_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
TMS9918: emit code to retrieve background color
Definition tms9918.c:459
void tms9918_bitmap_disable(Environment *_environment)
Definition tms9918.c:948
void tms9918_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
TMS9918: emit code to change common sprite's color
Definition tms9918.c:482
void tms9918_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition tms9918.c:993
void tms9918_use_tileset(Environment *_environment, char *_tileset)
Definition tms9918.c:2612
void tms9918_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition tms9918.c:1425
void tms9918_screen(Environment *_environment, char *_x, char *_y, char *_c)
Definition tms9918.c:2824
void tms9918_vertical_scroll(Environment *_environment, char *_displacement)
Definition tms9918.c:1321
void tms9918_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition tms9918.c:2446
void tms9918_tiles_at(Environment *_environment, char *_address)
Definition tms9918.c:1317
void tms9918_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition tms9918.c:1701
void tms9918_move_video_memory(Environment *_environment, char *_from, char *_to, char *_size)
Definition tms9918.c:2646
Variable * tms9918_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 tms9918.c:2092
void tms9918_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
TMS9918: emit code to wait for next raster irq at different position
Definition tms9918.c:565
void tms9918_get_width(Environment *_environment, char *_result)
Definition tms9918.c:1344
void tms9918_slice_image_extract(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition tms9918.c:2712
void tms9918_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition tms9918.c:926
void tms9918_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition tms9918.c:1405
void tms9918_border_color(Environment *_environment, char *_border_color)
TMS9918: emit code to change border color
Definition tms9918.c:343
void tms9918_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition tms9918.c:1230
void tms9918_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition tms9918.c:1272
void tms9918_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition tms9918.c:1021
void tms9918_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition tms9918.c:2591
RGBi * tms9918_image_nearest_system_color(RGBi *_color)
Definition tms9918.c:66
void tms9918_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition tms9918.c:2688
void tms9918_get_height(Environment *_environment, char *_result)
Definition tms9918.c:1358
void tms9918_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition tms9918.c:1054
void tms9918_screen_rows(Environment *_environment, char *_rows)
Definition tms9918.c:1132
void tms9918_horizontal_scroll(Environment *_environment, char *_displacement)
Definition tms9918.c:1325
void tms9918_move_memory_video(Environment *_environment, char *_from, char *_to, char *_size)
Definition tms9918.c:2637
void tms9918_tiles_get(Environment *_environment, char *_result)
Definition tms9918.c:1351
void tms9918_bitmap_at(Environment *_environment, char *_address)
Definition tms9918.c:981
void tms9918_cls(Environment *_environment)
Definition tms9918.c:1365
void tms9918_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
TMS9918: emit code to set raster irq
Definition tms9918.c:534
void tms9918_sprite_data_from(Environment *_environment, char *_sprite, char *_image)
Definition tms9918.c:1158
void tms9918_colormap_at(Environment *_environment, char *_address)
Definition tms9918.c:985
void tms9918_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition tms9918.c:1294
void console_calculate_vars(Environment *_environment)
Definition tms9918.c:918
void tms9918_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition tms9918.c:1385
void tms9918_screen_on(Environment *_environment)
Definition tms9918.c:1080
int tms9918_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition tms9918.c:2738
Variable * tms9918_get_raster_line(Environment *_environment)
Definition tms9918.c:2627
void tms9918_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition tms9918.c:2803
void tms9918_bank_select(Environment *_environment, int _bank)
Definition tms9918.c:569
void tms9918_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition tms9918.c:1313
void tms9918_background_color_semivars(Environment *_environment, int _index, char *_background_color)
TMS9918: emit code to change background color
Definition tms9918.c:432
void tms9918_next_raster(Environment *_environment)
TMS9918: emit code to wait for next raster irq
Definition tms9918.c:548
void tms9918_scroll(Environment *_environment, int _dx, int _dy)
Definition tms9918.c:2472
Variable * tms9918_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition tms9918.c:2351
int tms9918_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition tms9918.c:1779
void tms9918_sprite_disable(Environment *_environment, char *_sprite)
Definition tms9918.c:1192
void tms9918_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition tms9918.c:2513
void tms9918_screen_off(Environment *_environment)
Definition tms9918.c:1106
void tms9918_sprite_monocolor(Environment *_environment, char *_sprite)
Definition tms9918.c:1290
void tms9918_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition tms9918.c:2488
void tms9918_screen_columns(Environment *_environment, char *_columns)
Definition tms9918.c:1136
void tms9918_busy_wait(Environment *_environment, char *_timing)
Definition tms9918.c:1329
void tms9918_colors_vars(Environment *_environment, char *_foreground_color, char *_background_color)
Definition tms9918.c:2655
void tms9918_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition tms9918.c:1208
void tms9918_back(Environment *_environment)
Definition tms9918.c:1729
int tms9918_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition tms9918.c:596
void tms9918_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition tms9918.c:1244
void tms9918_slice_image_copy(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition tms9918.c:2692
void tms9918_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition tms9918.c:2313
void tms9918_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 tms9918.c:2254
void tms9918_initialization(Environment *_environment)
Definition tms9918.c:1491
void tms9918_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition tms9918.c:1716
void tms9918_textmap_at(Environment *_environment, char *_address)
Definition tms9918.c:989
void tms9918_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition tms9918.c:954
void tms9918_wait_vbl(Environment *_environment)
Definition tms9918.c:2342
void tms9918_sprite_enable(Environment *_environment, char *_sprite)
Definition tms9918.c:1176
void console_calculate(Environment *_environment)
Definition tms9918.c:888
void tms9918_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition tms9918.c:2559
void tms9918_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition tms9918.c:1258
#define WVDP_RSPRITEA(v)
Definition tms9918.h:55
#define VDP_RCOLOR
Definition tms9918.h:43
#define VDP_R1
Definition tms9918.h:37
#define WVDP_RSPRITEP(v)
Definition tms9918.h:56
#define TILEMAP_MODE_GRAPHIC1
Definition tms9918.h:100
#define WVDP_RPATTERN(v)
Definition tms9918.h:54
#define WVDP_RCOLORTABLE(v)
Definition tms9918.h:53
#define WVDP_R1(v)
Definition tms9918.h:51
#define WVDP_R0(v)
Definition tms9918.h:50
#define WVDP_RNAME(v)
Definition tms9918.h:52
void * malloc(YYSIZE_T)
struct _ScreenMode ScreenMode
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
Definition ugbc.h:3502
struct _Resource Resource
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define adilineendbitmap()
Definition ugbc.h:4241
#define WARNING_SCREEN_MODE(v1)
Definition ugbc.h:3878
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_BUFFER
Definition ugbc.h:477
@ VT_SPRITE
Definition ugbc.h:501
@ VT_SBYTE
Definition ugbc.h:452
@ VT_IMAGES
Definition ugbc.h:495
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_COLOR
Definition ugbc.h:471
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define adiline3(s, a, b, c)
Definition ugbc.h:4197
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#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 outline0(s)
Definition ugbc.h:4252
#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 adilinebeginbitmap(s)
Definition ugbc.h:4231
struct _CopperList CopperList
#define FLAG_EXACT
Definition ugbc.h:4569
#define adilinepixel(p)
Definition ugbc.h:4236
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)
Definition ugbc.h:3540
#define CRITICAL_BLIT_TOO_MUCH_SOURCES()
Definition ugbc.h:3613
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247