ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
cpc.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#include "../ugbc.h"
36#include <math.h>
37
38static RGBi SYSTEM_PALETTE[] = {
39 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK", 0x14 },
40 { 0x00, 0x00, 0x80, 0xff, 1, "BLUE", 0x04 },
41 { 0x00, 0x00, 0xff, 0xff, 2, "LIGHT BLUE", 0x15 },
42 { 0x80, 0x00, 0x00, 0xff, 3, "RED", 0x1c },
43 { 0x80, 0x00, 0x80, 0xff, 4, "MAGENTA", 0x18 },
44 { 0x80, 0x00, 0xff, 0xff, 5, "MAUVE", 0x1d },
45 { 0xff, 0x00, 0x00, 0xff, 6, "LIGHT RED", 0x0c },
46 { 0xff, 0x00, 0x80, 0xff, 7, "PURPLE", 0x08 },
47 { 0xff, 0x00, 0xff, 0xff, 8, "LIGHT MAGENTA", 0x0d },
48 { 0x00, 0x80, 0x00, 0xff, 9, "GREEN", 0x16 },
49 { 0x00, 0x80, 0x80, 0xff, 10, "CYAN", 0x06 },
50 { 0x00, 0x80, 0xff, 0xff, 11, "DARK CYAN", 0x17 },
51 { 0x80, 0x80, 0x00, 0xff, 12, "YELLOW", 0x1e },
52 { 0x80, 0x80, 0x80, 0xff, 13, "WHITE", 0x00 },
53 { 0x80, 0x80, 0xff, 0xff, 14, "PASTEL BLUE", 0x5f },
54 { 0xff, 0x80, 0x00, 0xff, 15, "ORANGE", 0x0e },
55 { 0xff, 0x80, 0x80, 0xff, 16, "PINK", 0x07 },
56 { 0xff, 0x80, 0xff, 0xff, 17, "PASTEL MAGENTA", 0x0f },
57 { 0x00, 0xff, 0x00, 0xff, 18, "LIGHT GREEN", 0x12 },
58 { 0x00, 0xff, 0x80, 0xff, 19, "SEA GREEN", 0x02 },
59 { 0x00, 0xff, 0xff, 0xff, 20, "LIGHT CYAN", 0x13 },
60 { 0x80, 0xff, 0x00, 0xff, 21, "LIME", 0x1a },
61 { 0x80, 0xff, 0x80, 0xff, 22, "PASTEL GREEN", 0x19 },
62 { 0x80, 0xff, 0xff, 0xff, 23, "PASTEL CYAN", 0x1b },
63 { 0xff, 0xff, 0x00, 0xff, 24, "LIGHT YELLOW", 0x0a },
64 { 0xff, 0xff, 0x80, 0xff, 25, "PASTEL YELLOW", 0x03 },
65 { 0xff, 0xff, 0xff, 0xff, 26, "LIGHT WHITE", 0x0b },
66};
67
68static int plotVBase[] = {
69 0xC000, 0xC800, 0xD000, 0xD800, 0xE000, 0xE800, 0xF000, 0xF800,
70 0xC050, 0xC850, 0xD050, 0xD850, 0xE050, 0xE850, 0xF050, 0xF850,
71 0xC0A0, 0xC8A0, 0xD0A0, 0xD8A0, 0xE0A0, 0xE8A0, 0xF0A0, 0xF8A0,
72 0xC0F0, 0xC8F0, 0xD0F0, 0xD8F0, 0xE0F0, 0xE8F0, 0xF0F0, 0xF8F0,
73 0xC140, 0xC940, 0xD140, 0xD940, 0xE140, 0xE940, 0xF140, 0xF940,
74 0xC190, 0xC990, 0xD190, 0xD990, 0xE190, 0xE990, 0xF190, 0xF990,
75 0xC1E0, 0xC9E0, 0xD1E0, 0xD9E0, 0xE1E0, 0xE9E0, 0xF1E0, 0xF9E0,
76 0xC230, 0xCA30, 0xD230, 0xDA30, 0xE230, 0xEA30, 0xF230, 0xFA30,
77 0xC280, 0xCA80, 0xD280, 0xDA80, 0xE280, 0xEA80, 0xF280, 0xFA80,
78 0xC2D0, 0xCAD0, 0xD2D0, 0xDAD0, 0xE2D0, 0xEAD0, 0xF2D0, 0xFAD0,
79 0xC320, 0xCB20, 0xD320, 0xDB20, 0xE320, 0xEB20, 0xF320, 0xFB20,
80 0xC370, 0xCB70, 0xD370, 0xDB70, 0xE370, 0xEB70, 0xF370, 0xFB70,
81 0xC3C0, 0xCBC0, 0xD3C0, 0xDBC0, 0xE3C0, 0xEBC0, 0xF3C0, 0xFBC0,
82 0xC410, 0xCC10, 0xD410, 0xDC10, 0xE410, 0xEC10, 0xF410, 0xFC10,
83 0xC460, 0xCC60, 0xD460, 0xDC60, 0xE460, 0xEC60, 0xF460, 0xFC60,
84 0xC4B0, 0xCCB0, 0xD4B0, 0xDCB0, 0xE4B0, 0xECB0, 0xF4B0, 0xFCB0,
85 0xC500, 0xCD00, 0xD500, 0xDD00, 0xE500, 0xED00, 0xF500, 0xFD00,
86 0xC550, 0xCD50, 0xD550, 0xDD50, 0xE550, 0xED50, 0xF550, 0xFD50,
87 0xC5A0, 0xCDA0, 0xD5A0, 0xDDA0, 0xE5A0, 0xEDA0, 0xF5A0, 0xFDA0,
88 0xC5F0, 0xCDF0, 0xD5F0, 0xDDF0, 0xE5F0, 0xEDF0, 0xF5F0, 0xFDF0,
89 0xC640, 0xCE40, 0xD640, 0xDE40, 0xE640, 0xEE40, 0xF640, 0xFE40,
90 0xC690, 0xCE90, 0xD690, 0xDE90, 0xE690, 0xEE90, 0xF690, 0xFE90,
91 0xC6E0, 0xCEE0, 0xD6E0, 0xDEE0, 0xE6E0, 0xEEE0, 0xF6E0, 0xFEE0,
92 0xC730, 0xCF30, 0xD730, 0xDF30, 0xE730, 0xEF30, 0xF730, 0xFF30,
93 0xC780, 0xCF80, 0xD780, 0xDF80, 0xE780, 0xEF80, 0xF780, 0xFF80
94};
95
96/****************************************************************************
97 * CODE SECTION
98 ****************************************************************************/
99
100#ifdef __cpc__
101
102static RGBi * commonPalette;
103static int lastUsedSlotInCommonPalette = 0;
104
105void cpc_inkey( Environment * _environment, char * _key ) {
106
107 _environment->bitmaskNeeded = 1;
108
109 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm);
110
111 outline0("CALL INKEY");
112 outline1("LD (%s), A", _key);
113
114}
115
116void cpc_wait_key( Environment * _environment, int _release ) {
117
118 _environment->bitmaskNeeded = 1;
119
120 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
121
122 if ( _release ) {
123 outline0("CALL WAITKEYRELEASE");
124 } else {
125 outline0("CALL WAITKEY");
126 }
127
128}
129
130
131void cpc_wait_key_or_fire( Environment * _environment, int _port, int _release ) {
132
133 _environment->bitmaskNeeded = 1;
134
135 deploy( joystick, src_hw_cpc_joystick_asm );
136 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
137 deploy( wait_key_or_fire, src_hw_cpc_wait_key_or_fire_asm );
138
139 if ( _port == -1 ) {
140 outline0("CALL WAITKEYFIRE");
141 } else {
142 outline1("LD A, %2.2x", _port);
143 outline0("CALL WAITKEYFIREA");
144 }
145
146}
147
148void cpc_wait_key_or_fire_semivar( Environment * _environment, char * _port, int _release ) {
149
150 _environment->bitmaskNeeded = 1;
151
152 deploy( joystick, src_hw_cpc_joystick_asm );
153 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
154 deploy( wait_key_or_fire, src_hw_cpc_wait_key_or_fire_asm );
155
156 if ( ! _port ) {
157 outline0("CALL WAITKEYFIRE");
158 } else {
159 outline1("LD A, (%s)", _port);
160 outline0("CALL WAITKEYFIREA");
161 }
162
163}
164
165void cpc_wait_fire( Environment * _environment, int _port, int _release ) {
166
167 _environment->bitmaskNeeded = 1;
168
169 deploy( joystick, src_hw_cpc_joystick_asm );
170 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
171
172 switch( _port ) {
173 case -1:
174 outline0("CALL WAITFIRE");
175 break;
176 case 0:
177 outline0("CALL WAITFIRE0");
178 break;
179 case 1:
180 outline0("CALL WAITFIRE1");
181 break;
182 }
183
184}
185
186void cpc_wait_fire_semivar( Environment * _environment, char * _port, int _release ) {
187
188 _environment->bitmaskNeeded = 1;
189
190 deploy( joystick, src_hw_cpc_joystick_asm );
191
192 if ( ! _port ) {
193 outline0("CALL WAITFIRE");
194 } else {
195 outline1("LD A, (%s)", _port);
196 outline0("CALL WAITFIREA");
197 }
198
199}
200
201void cpc_key_state( Environment * _environment, char *_scancode, char * _result ) {
202
203 _environment->bitmaskNeeded = 1;
204
206
207 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
208
209 outline1("LD A, (%s)", _scancode);
210 outline0("CALL KEYSTATE");
211 cpu_ctoa( _environment );
212 outline1("LD (%s), A", _result);
213
214}
215
216void cpc_scancode( Environment * _environment, char * _result ) {
217
219
220 _environment->bitmaskNeeded = 1;
221
222 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm);
223
224 outline0("CALL SCANCODE");
225 if ( _environment->vestigialConfig.rchack_falling_balls_1163 ) {
226 outline0("CP $FF");
227 outline1("JR NZ, %s", label );
228 outline0("XOR $FF");
229 outhead1("%s:", label );
230 }
231 outline1("LD (%s), A", _result );
232
233}
234
235void cpc_asciicode( Environment * _environment, char * _result ) {
236
237 _environment->bitmaskNeeded = 1;
238
239 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm);
240
241 outline0("CALL ASCIICODE");
242 outline1("LD (%s), A", _result );
243
244}
245
246void cpc_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
247
248 _environment->bitmaskNeeded = 1;
249
251
252 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
253
254 outline1("LD A, (%s)", _scancode);
255 outline0("CALL KEYPRESSED");
256 cpu_ctoa( _environment );
257 outline1("LD (%s), A", _result);
258
259}
260
261void cpc_scanshift( Environment * _environment, char * _shifts ) {
262
263}
264
265void cpc_keyshift( Environment * _environment, char * _shifts ) {
266
267 _environment->bitmaskNeeded = 1;
268
269 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
270
271 outline0("CALL KEYSHIFT" );
272 outline1("LD (%s), A", _shifts );
273
274}
275
276void cpc_clear_key( Environment * _environment ) {
277
278 _environment->bitmaskNeeded = 1;
279
280 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
281
282 outline0("CALL CLEARKEY" );
283
284}
285
286void cpc_joy_vars( Environment * _environment, char * _port, char * _value ) {
287
288 _environment->bitmaskNeeded = 1;
289
290 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
291 deploy( joystick, src_hw_cpc_joystick_asm );
292
294
295 if ( _environment->keyboardConfig.sync ) {
296 outline0("CALL SCANCODERAW" );
297 }
298 outline1("LD A, (%s)", _port);
299 outline0("CP 0");
300 outline1("JR NZ, %spt1", label );
301 if ( _environment->joystickConfig.sync ) {
302 outline0("CALL JOYSTICKREAD0" );
303 } else {
304 outline0("LD A, (JOYSTICK0)" );
305 }
306 if ( _environment->joystickConfig.values ) {
307 outline0("CALL JOYSTICKTSB" );
308 }
309 outline1("LD (%s), A", _value);
310 outline1("JR %sptx", label );
311 outhead1("%spt1:", label);
312 if ( _environment->joystickConfig.sync ) {
313 outline0("CALL JOYSTICKREAD1" );
314 } else {
315 outline0("LD A, (JOYSTICK1)" );
316 }
317 if ( _environment->joystickConfig.values ) {
318 outline0("CALL JOYSTICKTSB" );
319 }
320 outline1("LD (%s), A", _value);
321 outline1("JR %sptx", label );
322 outhead1("%sptx:", label);
323
324}
325
326void cpc_joy( Environment * _environment, int _port, char * _value ) {
327
328 _environment->bitmaskNeeded = 1;
329
330 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm );
331 deploy( joystick, src_hw_cpc_joystick_asm );
332 if ( _environment->keyboardConfig.sync ) {
333 outline0("CALL SCANCODERAW" );
334 }
335 switch ( _port ) {
336 case 0:
337 if ( _environment->joystickConfig.sync ) {
338 outline0("CALL JOYSTICKREAD0" );
339 } else {
340 outline0("LD A, (JOYSTICK0)" );
341 }
342 break;
343 case 1:
344 if ( _environment->joystickConfig.sync ) {
345 outline0("CALL JOYSTICKREAD0" );
346 } else {
347 outline0("LD A, (JOYSTICK0)" );
348 }
349 break;
350 }
351 if ( _environment->joystickConfig.values ) {
352 outline0("CALL JOYSTICKTSB" );
353 }
354 outline1("LD (%s), A", _value);
355
356}
357
358/****************************************************************************
359 * CODE SECTION
360 ****************************************************************************/
361
373Variable * cpc_collision( Environment * _environment, char * _sprite ) {
374
375 Variable * result = variable_temporary( _environment, VT_SBYTE, "(collision)" );
376
377 return result;
378
379}
380
392void cpc_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
393
394}
395
405void cpc_border_color( Environment * _environment, char * _border_color ) {
406
407 outline0("LD BC,$7F10");
408 outline0("OUT (C), C");
409 outline1("LD A, (%s)", _border_color);
410 outline0("LD (PALETTEB), A");
411 outline0("AND $1f");
412 outline0("OR A, 0x40");
413 outline0("OUT (C), A");
414
415}
416
427void cpc_background_color( Environment * _environment, int _index, int _background_color ) {
428
429 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
430 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
431
432 outline1("LD A, 0x%2.2x", ( _index & 0x0f ));
433 outline0("LD IXH, A");
434 outline1("LD A, 0x%2.2x", ( _background_color & 0x0f ));
435 outline0("LD IXL, A");
436 outline0("LD A, 1");
437 outline0("LD IYL, A");
438 outline0("CALL CPCUPDATEPALETTE");
439
440}
441
452void cpc_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
453
454 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
455 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
456
457 outline1("LD A, (%s)", _index);
458 outline0("LD IXH, A");
459 outline1("LD A, (%s)", _background_color);
460 outline0("LD IXL, A");
461 outline0("LD A, 1");
462 outline0("LD IYL, A");
463 outline0("CALL CPCUPDATEPALETTE");
464
465}
466
477void cpc_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
478
479 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
480 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
481
483
484 outline1("%sbackgroundcolor:", label );
485 outline1("LD A, 0x%2.2x", ( _index & 0x0f ));
486 outline0("LD IXH, A");
487 outline1("LD A, (%s)", _background_color);
488 outline0("LD IXL, A");
489 outline0("LD A, 1");
490 outline0("LD IYL, A");
491 outline0("CALL CPCUPDATEPALETTE");
492
493}
494
505void cpc_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
506
507 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
508 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
509
510 outline1("LD A, (%s)", _index);
511 outline0("LD IXH, A");
512 outline0("CALL CPCGETPALETTE");
513 outline0("LD A, IXL");
514 outline1("LD (%s), A", _background_color);
515
516}
517
528void cpc_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
529
530}
531
547void cpc_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
548
549}
550
561void cpc_next_raster( Environment * _environment ) {
562
563}
564
578void cpc_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
579
580}
581
582void cpc_bank_select( Environment * _environment, int _bank ) {
583
584}
585
586static int rgbConverterFunction( int _red, int _green, int _blue ) {
587
588 int colorIndex = 0;
589 unsigned int minDistance = 0xffffffff;
590 int j;
591
592 RGBi rgb;
593 rgb.red = _red;
594 rgb.green = _green;
595 rgb.blue = _blue;
596
597 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
598 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &rgb);
599 if (distance < minDistance) {
600 minDistance = distance;
601 colorIndex = SYSTEM_PALETTE[j].hardwareIndex;
602 }
603 }
604
605 return colorIndex;
606
607}
608
609void console_calculate( Environment * _environment ) {
610
611 int consoleSA = plotVBase[ ( _environment->activeConsole.y1 * 8 ) ] + ( _environment->activeConsole.x1 * _environment->currentModeBW ) ;
612 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
613 int consoleHB = _environment->activeConsole.height * 8;
614
615 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
616 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
617 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
618
619}
620
621void console_calculate_vars( Environment * _environment ) {
622
623 _environment->dynamicConsole = 1;
624
625 outline0( "CALL CONSOLECALCULATE" );
626
627}
628
629int cpc_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
630
631 _screen_mode->selected = 1;
632
633 cpu_store_8bit( _environment, "_PEN", _environment->defaultPenColor );
634 cpu_store_8bit( _environment, "_PAPER", _environment->defaultPaperColor );
635
636 _environment->fontWidth = 8;
637 _environment->fontHeight = 8;
638
639 switch( _screen_mode->id ) {
640
641 // "Mode 0" 160×200 pixels with 16 colors
643 _environment->screenTilesWidth = 20;
644 _environment->screenTilesHeight = 25;
645 _environment->screenTiles = 255;
646 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
647 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
648 _environment->screenColors = 16;
649 _environment->currentModeBW = 4;
650 CPC_GA_MASK( 0xc3, 0x80 );
651 break;
652 // "Mode 1" 320×200 pixels with 4 colors
654 _environment->screenTilesWidth = 40;
655 _environment->screenTilesHeight = 25;
656 _environment->screenTiles = 255;
657 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
658 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
659 _environment->screenColors = 4;
660 _environment->currentModeBW = 2;
661 CPC_GA_MASK( 0xc3, 0x81 );
662 break;
663 // "Mode 2" 640×200 pixels with 2 colors
665 _environment->screenTilesWidth = 80;
666 _environment->screenTilesHeight = 25;
667 _environment->screenTiles = 255;
668 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
669 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
670 _environment->screenColors = 2;
671 _environment->currentModeBW = 1;
672 CPC_GA_MASK( 0xc3, 0x82 );
673 break;
674 // "Mode 3" 160×200 pixels with 4 colors (2bpp) (this is not an official mode, but rather a side-effect of the hardware)
676 _environment->screenTilesWidth = 20;
677 _environment->screenTilesHeight = 25;
678 _environment->screenTiles = 255;
679 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
680 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
681 _environment->screenColors = 4;
682 _environment->currentModeBW = 2;
683 CPC_GA_MASK( 0xc3, 0x83 );
684 break;
685 }
686
687 _environment->consoleTilesWidth = _environment->screenTilesWidth;
688 _environment->consoleTilesHeight = _environment->screenTilesHeight;
689
690 cpu_store_16bit( _environment, "CLIPX1", 0 );
691 cpu_store_16bit( _environment, "CLIPX2", (_environment->screenWidth-1) );
692 cpu_store_16bit( _environment, "CLIPY1", 0 );
693 cpu_store_16bit( _environment, "CLIPY2", (_environment->screenHeight-1) );
694
695 cpu_store_16bit( _environment, "ORIGINX", 0 );
696 cpu_store_16bit( _environment, "ORIGINY", 0 );
697
698 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
699 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
700 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
701 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
702 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
703 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
704 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
705 cpu_store_8bit( _environment, "FONTWIDTH", _environment->fontWidth );
706 cpu_store_8bit( _environment, "FONTHEIGHT", _environment->fontHeight );
707 cpu_store_8bit( _environment, "PALETTELIMIT", _environment->screenColors );
708
709 console_init( _environment );
710
711 if (_environment->vestigialConfig.clsImplicit ) {
712 cpc_cls( _environment );
713 }
714
715}
716
717void cpc_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
718
719 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
720
721 if ( mode ) {
722 cpc_screen_mode_enable( _environment, mode );
723
724 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
725 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
726
727 _environment->currentMode = mode->id;
728 _environment->currentTileMode = 0;
729
730 if (_environment->vestigialConfig.clsImplicit ) {
731 cpc_cls( _environment );
732 }
733
734 } else {
736 }
737}
738
739void cpc_bitmap_disable( Environment * _environment ) {
740
741}
742
743void cpc_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
744
745 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
746
747 if ( mode ) {
748
749 cpc_screen_mode_enable( _environment, mode );
750
751 _environment->currentMode = mode->id;
752 _environment->currentTileMode = 1;
753
754 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
755 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
756
757 if (_environment->vestigialConfig.clsImplicit ) {
758 cpc_cls( _environment );
759 }
760
761 } else {
762 // printf("cpc_tilemap_enable() -> -1\n" );
764 }
765
766}
767
768void cpc_bitmap_at( Environment * _environment, char * _address ) {
769
770}
771
772void cpc_colormap_at( Environment * _environment, char * _address ) {
773
774}
775
776void cpc_textmap_at( Environment * _environment, char * _address ) {
777
778}
779
780void cpc_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
781
782 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
783 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
784 deploy( plot, src_hw_cpc_plot_asm );
785
786 outline1("LD A, 0x%2.2x", ( _y & 0xff ) );
787 outline0("LD D, A");
788 outline1("LD A, 0x%2.2x", ( _x & 0xff ) );
789 outline0("LD E, A");
790 outline1("LD A, 0x%2.2x", ( ( _x >> 8 ) & 0xff ) );
791 outline0("LD IXL, A");
792 if ( _c ) {
793 outline1("LD A, $%2.2x", ( *_c & 0Xff ) );
794 } else {
795 Variable * c = variable_retrieve( _environment, "PEN" );
796 outline1("LD A, (%s)", c->realName );
797 }
798 outline0("LD (PLOTCPE), A");
799 outline0("LD A, 1");
800 outline0("CALL PLOT");
801
802}
803
804void cpc_pset_vars( Environment * _environment, char *_x, char *_y, char *_c ) {
805
806 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
807 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
808 Variable * c;
809
810 if ( _c ) {
811 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
812 } else {
813 c = variable_retrieve( _environment, "PEN" );
814 }
815
816 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
817 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
818 deploy( plot, src_hw_cpc_plot_asm );
819
820 outline1("LD A, (%s)", y->realName );
821 outline0("LD D, A");
822 outline1("LD A, (%s)", x->realName );
823 outline0("LD E, A");
824 outline1("LD A, (%s)", c->realName );
825 outline0("LD (PLOTCPE), A");
826 if ( VT_BITWIDTH( x->type ) > 8 ) {
827 outline1("LD A, (%s)", address_displacement(_environment, x->realName, "1") );
828 } else {
829 outline0("LD A, 0" );
830 }
831 outline0("LD IXL, A");
832 outline0("LD A, 1");
833 outline0("CALL PLOT");
834
835}
836
837void cpc_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
838
839 Variable * x = variable_retrieve( _environment, _x );
840 Variable * y = variable_retrieve( _environment, _y );
841 Variable * result = variable_retrieve( _environment, _result );
842
843 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
844 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
845 deploy( plot, src_hw_cpc_plot_asm );
846
847 outline1("LD A, (%s)", y->realName );
848 outline0("LD D, A");
849 outline1("LD A, (%s)", x->realName );
850 outline0("LD E, A");
851 if ( VT_BITWIDTH( x->type ) > 8 ) {
852 outline1("LD A, (%s)", address_displacement(_environment, x->realName, "1") );
853 } else {
854 outline0("LD A, 0" );
855 }
856 outline0("LD IXL, A");
857 outline0("LD A, 3");
858 outline0("CALL PLOT");
859 outline1("LD (%s), A", result->realName);
860
861}
862
863void cpc_screen_on( Environment * _environment ) {
864
865}
866
867void cpc_screen_off( Environment * _environment ) {
868
869}
870
871void cpc_screen_rows( Environment * _environment, char * _rows ) {
872
873}
874
875void cpc_screen_columns( Environment * _environment, char * _columns ) {
876
877}
878
879void cpc_sprite_data_from( Environment * _environment, char * _sprite, char * _address ) {
880
881}
882
883void cpc_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
884
885}
886
887void cpc_sprite_enable( Environment * _environment, char * _sprite ) {
888
889}
890
891void cpc_sprite_disable( Environment * _environment, char * _sprite ) {
892
893}
894
895void cpc_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
896
897}
898
899void cpc_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
900
901}
902
903void cpc_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
904
905}
906
907void cpc_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
908
909}
910
911void cpc_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
912
913}
914
915void cpc_sprite_multicolor( Environment * _environment, char * _sprite ) {
916
917}
918
919void cpc_sprite_monocolor( Environment * _environment, char * _sprite ) {
920
921}
922
923void cpc_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
924
925}
926
927void cpc_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
928
929}
930
931void cpc_tiles_at( Environment * _environment, char * _address ) {
932
933}
934
935void cpc_vertical_scroll( Environment * _environment, char * _displacement ) {
936
937}
938
939void cpc_horizontal_scroll( Environment * _environment, char * _displacement ) {
940
941}
942
943void cpc_busy_wait( Environment * _environment, char * _timing ) {
944
946
947 outline1("LD A, (%s)", _timing);
948 outline0("LD D, A");
949 outline0("LD B, 0xf5");
950 outline1("%swait", label );
951 outline0("IN A, (C)");
952 outline0("RRA");
953 outline1("JP NC, %swait", label);
954 outline0("DEC D");
955 outline1("JP NZ, %swait", label);
956
957}
958
959void cpc_get_width( Environment * _environment, char *_result ) {
960
961 outline0("LD HL, (CURRENTWIDTH)" );
962 outline1("LD (%s), HL", _result );
963
964}
965
966void cpc_tiles_get( Environment * _environment, char *_result ) {
967
968 outline0("LD A, (CURRENTTILES)" );
969 outline1("LD (%s), A", _result );
970
971}
972
973void cpc_get_height( Environment * _environment, char *_result ) {
974
975 outline0("LD HL, (CURRENTHEIGHT)" );
976 outline1("LD (%s), HL", _result );
977
978}
979
980void cpc_cls( Environment * _environment ) {
981
982 deploy( clsGraphic, src_hw_cpc_cls_graphic_asm );
983 outline0("CALL CLSG");
984
985}
986
987void cpc_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
988
989 deploy( clsBox, src_hw_cpc_cls_box_asm );
990
991 outline1("LD A, (%s)", _x1);
992 outline0("LD E, A");
993 outline1("LD A, (%s)", address_displacement( _environment, _x1, "1" ) );
994 outline0("LD IXH, A");
995
996 outline1("LD A, (%s)", _y1);
997 outline0("LD D, A");
998
999 outline1("LD A, (%s)", _x1);
1000 outline0("LD E, A");
1001 outline1("LD A, (%s)", address_displacement( _environment, _x1, "1" ) );
1002 outline0("LD IXH, A");
1003
1004 outline1("LD A, (%s)", _w);
1005 outline0("LD C, A");
1006 outline1("LD A, (%s)", _h);
1007 outline0("LD B, A");
1008 outline0("CALL CLSBOX");
1009
1010}
1011
1012void cpc_scroll_text( Environment * _environment, int _direction, int _overlap ) {
1013
1014 if ( _direction > 0 ) {
1015 deploy_preferred( vScrollTextDown, src_hw_cpc_vscroll_text_down_asm );
1016 outline1("LD IYL, $%2.2x", (unsigned char)(_overlap&0xff) );
1017 outline0("CALL VSCROLLTDOWN");
1018 } else {
1019 deploy_preferred( vScrollTextUp, src_hw_cpc_vscroll_text_up_asm );
1020 outline1("LD IYL, $%2.2x", (unsigned char)(_overlap&0xff) );
1021 outline0("CALL VSCROLLTUP");
1022 }
1023
1024}
1025
1026void cpc_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
1027
1028 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
1029 deploy_preferred( vScrollTextUp, src_hw_cpc_vscroll_text_up_asm );
1030
1031 outline1("LD DE, (%s)", _text);
1032 outline1("LD A, (%s)", _text_size);
1033 outline0("LD C, A");
1034
1035 deploy( clsGraphic, src_hw_cpc_cls_graphic_asm );
1036 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
1037 // deploy( textEncodedAt, src_hw_cpc_text_at_asm );
1038 deploy( textEncodedAtGraphic, src_hw_cpc_text_at_graphic_asm );
1039 outline0("CALL TEXTATBITMAPMODE");
1040
1041}
1042
1043void cpc_initialization( Environment * _environment ) {
1044
1045 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 160 );
1046 variable_global( _environment, "CURRENTWIDTH" );
1047 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 200 );
1048 variable_global( _environment, "CURRENTHEIGHT" );
1049 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
1050 variable_global( _environment, "CURRENTTILES" );
1051 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 20 );
1052 variable_global( _environment, "CURRENTTILESWIDTH" );
1053 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 25 );
1054 variable_global( _environment, "CURRENTTILESHEIGHT" );
1055 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
1056 variable_global( _environment, "FONTWIDTH" );
1057 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
1058 variable_global( _environment, "FONTHEIGHT" );
1059 variable_import( _environment, "PALETTELIMIT", VT_BYTE, 16 );
1060 variable_global( _environment, "PALETTELIMIT" );
1061
1062 SCREEN_MODE_DEFINE( BITMAP_MODE_GRAPHIC0, 1, 160, 200, 16, 8, 8, "Graphic Mode 0" );
1063 SCREEN_MODE_DEFINE( BITMAP_MODE_GRAPHIC1, 1, 320, 200, 4, 8, 8, "Graphic Mode 1" );
1064 SCREEN_MODE_DEFINE( BITMAP_MODE_GRAPHIC2, 1, 640, 200, 2, 8, 8, "Graphic Mode 2" );
1065 SCREEN_MODE_DEFINE( BITMAP_MODE_GRAPHIC3, 1, 160, 200, 4, 8, 8, "Graphic Mode 3" );
1066
1067 outline0("CALL CPCVIDEOSTARTUP");
1068
1069 variable_import( _environment, "XGR", VT_POSITION, 0 );
1070 variable_global( _environment, "XGR" );
1071 variable_import( _environment, "YGR", VT_POSITION, 0 );
1072 variable_global( _environment, "YGR" );
1073 variable_import( _environment, "LINE", VT_WORD, (unsigned short)(0xffff) );
1074 variable_global( _environment, "LINE" );
1075
1076 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
1077 variable_global( _environment, "CLIPX1" );
1078 variable_import( _environment, "CLIPX2", VT_POSITION, 255 );
1079 variable_global( _environment, "CLIPX2" );
1080 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
1081 variable_global( _environment, "CLIPY1" );
1082 variable_import( _environment, "CLIPY2", VT_POSITION, 191 );
1083 variable_global( _environment, "CLIPY2" );
1084
1085 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
1086 variable_global( _environment, "ORIGINX" );
1087 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
1088 variable_global( _environment, "ORIGINY" );
1089
1090 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
1091 variable_global( _environment, "RESOLUTIONX" );
1092 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
1093 variable_global( _environment, "RESOLUTIONY" );
1094
1095 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
1096 variable_global( _environment, "TABCOUNT" );
1097
1098 variable_import( _environment, "CLINEX", VT_BYTE, 0 );
1099 variable_global( _environment, "CLINEX" );
1100
1101 variable_import( _environment, "CLINEY", VT_BYTE, 0 );
1102 variable_global( _environment, "CLINEY" );
1103
1104 variable_import( _environment, "TABSTODRAW", VT_BYTE, 0 );
1105 variable_global( _environment, "TABSTODRAW" );
1106
1107 variable_import( _environment, "CURRENTMODE", VT_BYTE, 2 );
1108 variable_global( _environment, "CURRENTMODE" );
1109 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
1110 variable_global( _environment, "CURRENTTILEMODE" );
1111
1112 variable_import( _environment, "SPRITECOUNT", VT_SPRITE, 0 );
1113 variable_global( _environment, "SPRITECOUNT" );
1114
1115 variable_import( _environment, "TILEX", VT_BYTE, 0 );
1116 variable_global( _environment, "TILEX" );
1117 variable_import( _environment, "TILEY", VT_BYTE, 0 );
1118 variable_global( _environment, "TILEY" );
1119 variable_import( _environment, "TILEX2", VT_BYTE, 0 );
1120 variable_global( _environment, "TILEX2" );
1121 variable_import( _environment, "TILET", VT_BYTE, 0 );
1122 variable_global( _environment, "TILET" );
1123 variable_import( _environment, "TILEW", VT_BYTE, 0 );
1124 variable_global( _environment, "TILEW" );
1125 variable_import( _environment, "TILEH", VT_BYTE, 0 );
1126 variable_global( _environment, "TILEH" );
1127 variable_import( _environment, "TILEW2", VT_BYTE, 0 );
1128 variable_global( _environment, "TILEW2" );
1129 variable_import( _environment, "TILEH2", VT_BYTE, 0 );
1130 variable_global( _environment, "TILEH2" );
1131 variable_import( _environment, "TILEA", VT_BYTE, 0 );
1132 variable_global( _environment, "TILEA" );
1133 variable_import( _environment, "TILEO", VT_WORD, 0 );
1134 variable_global( _environment, "TILEO" );
1135
1136 variable_import( _environment, "XSCROLLPOS", VT_BYTE, 0 );
1137 variable_global( _environment, "XSCROLLPOS" );
1138 variable_import( _environment, "YSCROLLPOS", VT_BYTE, 0 );
1139 variable_global( _environment, "YSCROLLPOS" );
1140 variable_import( _environment, "XSCROLL", VT_BYTE, 0 );
1141 variable_global( _environment, "XSCROLL" );
1142 variable_import( _environment, "YSCROLL", VT_BYTE, 0 );
1143 variable_global( _environment, "YSCROLL" );
1144 variable_import( _environment, "DIRECTION", VT_BYTE, 0 );
1145 variable_global( _environment, "DIRECTION" );
1146
1147 variable_import( _environment, "ONSCROLLUP", VT_BUFFER, 3 );
1148 variable_global( _environment, "ONSCROLLUP" );
1149
1150 variable_import( _environment, "ONSCROLLDOWN", VT_BUFFER, 3 );
1151 variable_global( _environment, "ONSCROLLDOWN" );
1152
1153 variable_import( _environment, "ONSCROLLLEFT", VT_BUFFER, 3 );
1154 variable_global( _environment, "ONSCROLLLEFT" );
1155
1156 variable_import( _environment, "ONSCROLLRIGHT", VT_BUFFER, 3 );
1157 variable_global( _environment, "ONSCROLLRIGHT" );
1158
1159 variable_import( _environment, "IMAGEF", VT_BYTE, 0 );
1160 variable_global( _environment, "IMAGEF" );
1161 variable_import( _environment, "IMAGET", VT_BYTE, 0 );
1162 variable_global( _environment, "IMAGET" );
1163
1164 variable_import( _environment, "CPCTIMER", VT_WORD, 0 );
1165 variable_global( _environment, "CPCTIMER" );
1166 variable_import( _environment, "CPCTIMER2", VT_BYTE, 6 );
1167 variable_global( _environment, "CPCTIMER2" );
1168
1169 variable_import( _environment, "EVERYCOUNTER", VT_BYTE, 0 );
1170 variable_global( _environment, "EVERYCOUNTER" );
1171 variable_import( _environment, "EVERYTIMING", VT_BYTE, 0 );
1172 variable_global( _environment, "EVERYTIMING" );
1173
1174 variable_import( _environment, "IMAGEY", VT_BYTE, 0 );
1175 variable_global( _environment, "IMAGEY" );
1176
1177 variable_import( _environment, "SLICEX", VT_POSITION, 0 );
1178 variable_global( _environment, "SLICEX" );
1179 variable_import( _environment, "SLICEY", VT_POSITION, 0 );
1180 variable_global( _environment, "SLICEY" );
1181 variable_import( _environment, "SLICEDTARGET", VT_POSITION, 0 );
1182 variable_global( _environment, "SLICEDTARGET" );
1183 variable_import( _environment, "GAVALUE", VT_BYTE, 0xfc );
1184 variable_global( _environment, "GAVALUE" );
1185
1186 variable_import( _environment, "XCURSYS", VT_SBYTE, 0 );
1187 variable_global( _environment, "XCURSYS" );
1188 variable_import( _environment, "YCURSYS", VT_SBYTE, 0 );
1189 variable_global( _environment, "YCURSYS" );
1190
1191 variable_import( _environment, "CONSOLESA", VT_ADDRESS, 0x0 );
1192 variable_global( _environment, "CONSOLESA" );
1193 variable_import( _environment, "CONSOLEHB", VT_BYTE, 0x0 );
1194 variable_global( _environment, "CONSOLEHB" );
1195 variable_import( _environment, "CONSOLEWB", VT_BYTE, 0x0 );
1196 variable_global( _environment, "CONSOLEWB" );
1197
1198 variable_import( _environment, "PENT", VT_BYTE, 0x0 );
1199 variable_global( _environment, "PENT" );
1200 variable_import( _environment, "PAPERT", VT_BYTE, 0x0 );
1201 variable_global( _environment, "PAPERT" );
1202
1203 cpc_screen_mode_enable( _environment, find_screen_mode_by_id( _environment, BITMAP_MODE_DEFAULT ) );
1204
1205 console_init( _environment );
1206
1207 font_descriptors_init( _environment, 0 );
1208
1209 _environment->fontWidth = 8;
1210 _environment->fontHeight = 8;
1211 _environment->screenTilesWidth = 80;
1212 _environment->screenTilesHeight = 25;
1213 _environment->screenTiles = 255;
1214 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
1215 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
1216 _environment->currentModeBW = 1;
1217 _environment->currentRgbConverterFunction = rgbConverterFunction;
1218 _environment->screenShades = 16;
1219 _environment->screenColors = 2;
1220 _environment->currentModeBW = 1;
1221
1222}
1223
1224void cpc_finalization( Environment * _environment ) {
1225
1226 if ( ! _environment->vestigialConfig.rchack_pick_the_star_1163 ) {
1227 outhead0("PALETTE:");
1228 int defaultPalette[] = {
1229 4, 10, 19, 12,
1230 11, 20, 21, 13,
1231 6, 30, 31, 7,
1232 18, 25, 10, 7
1233 };
1234
1235 if ( ! commonPalette ) {
1236 out0("DB ");
1237 for( int i=0; i<15; ++i ) {
1238 out1("%d,", defaultPalette[i] );
1239 }
1240 outline1("%d", defaultPalette[15] );
1241 } else {
1242 out0("DB ");
1243 for( int i=0; i<lastUsedSlotInCommonPalette; ++i ) {
1244 out1("%d,", commonPalette[i].hardwareIndex );
1245 }
1246 for( int i=lastUsedSlotInCommonPalette; i<16; ++i ) {
1247 out1("%d,", defaultPalette[i] );
1248 }
1249 outline0("0");
1250 }
1251 }
1252
1253 if ( _environment->vestigialConfig.clsImplicit ) {
1254 deploy( clsGraphic, src_hw_cpc_cls_graphic_asm );
1255 }
1256
1257 CopperList * copperList = _environment->copperList;
1258 if ( copperList ) {
1259 while(copperList) {
1260 outhead1("COPPERACTIVATE%s:", copperList->name ? copperList->name : "" );
1261 outline0("RET");
1262 copperList = copperList->next;
1263 }
1264 }
1265
1266}
1267
1268void cpc_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
1269
1270 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
1271 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
1272 deploy( textHScrollLine, src_hw_cpc_hscroll_line_asm );
1273
1274 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1275 outline1("LD A, (%s)", y->realName );
1276 outline0("LD B, A");
1277 outline1("LD A, 0x%2.2x", (unsigned char)(_direction));
1278 outline1("LD IYL, 0x%2.2x", (unsigned char)(_overlap));
1279 outline0("CALL HSCROLLLINE");
1280
1281}
1282
1283void cpc_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
1284
1285 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
1286 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
1287 deploy( textHScrollScreen, src_hw_cpc_hscroll_screen_asm );
1288
1289 outline1("LD A, 0x%2.2x", (unsigned char)(_direction));
1290 outline1("LD IYL, 0x%2.2x", (unsigned char)(_overlap));
1291 outline0("CALL HSCROLLSCREEN");
1292
1293}
1294
1295void cpc_back( Environment * _environment ) {
1296
1297}
1298
1299void cpc_cline( Environment * _environment, char * _characters ) {
1300
1301 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
1302 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
1303 deploy( textCline, src_hw_cpc_cline_asm );
1304
1305 if ( _characters ) {
1306 outline1("LD A, (%s)", _characters);
1307 } else {
1308 outline0("LD A, 0");
1309 }
1310 outline0("CALL CLINE");
1311
1312}
1313
1314int cpc_image_size( Environment * _environment, int _width, int _height, int _mode ) {
1315
1316 switch( _mode ) {
1317
1319
1320 return 3 + ( ( _width >> 1 ) * _height ) + 16;
1321
1324
1325 return 3 + ( ( _width >> 2 ) * _height ) + 4;
1326
1328
1329 return 3 + ( ( _width >> 3 ) * _height ) + 2;
1330 }
1331
1332 return 0;
1333
1334}
1335
1336static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1337
1338 switch( _mode ) {
1339
1341
1342 return 3 + ( 3 + ( ( _width >> 1 ) * _height ) + 16 ) * _frames;
1343
1346
1347 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) + 4 ) * _frames;
1348
1350
1351 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + 2 ) * _frames;
1352 }
1353
1354 return 0;
1355
1356}
1357
1358static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1359
1360 switch( _mode ) {
1361
1363
1364 return 3 + ( ( 3 + ( ( _width >> 1 ) * _height ) + 16 ) * _frames ) * _sequences;
1365
1368
1369 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) + 4 ) * _frames ) * _sequences;
1370
1372
1373 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + 2 ) * _frames ) * _sequences;
1374 }
1375
1376 return 0;
1377
1378}
1379
1380static Variable * cpc_image_converter_bitmap_mode_hires( 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 ) {
1381
1382 // ignored on bitmap mode
1383 (void)!_transparent_color;
1384
1385 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
1386
1387 if ( _environment->freeImageWidth ) {
1388 if ( _width % 8 ) {
1389 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1390 }
1391 if ( _frame_width % 8 ) {
1392 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1393 }
1394 }
1395
1396 RGBi * palette = malloc_palette( MAX_PALETTE );
1397
1398 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1399
1400 if (paletteColorCount > 2) {
1401 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1402 }
1403
1404 int i, j, k;
1405
1406 if ( ! commonPalette ) {
1407
1408 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1409 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1410
1411 if ( _transparent_color & 0x0f0000 ) {
1412 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1413 }
1414 if ( _transparent_color & 0xf00000 ) {
1415 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 2 );
1416 paletteColorCount = 2;
1417 }
1418
1419 lastUsedSlotInCommonPalette = paletteColorCount;
1420 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1421
1422 } else {
1423
1424 RGBi * newPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1425 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
1426 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1427
1428 int mergedCommonPalette = 0;
1429
1430 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1431
1432 if ( _transparent_color & 0x0f0000 ) {
1433 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
1434 }
1435 if ( _transparent_color & 0xf00000 ) {
1436 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 2 );
1437 mergedCommonPalette = 2;
1438 }
1439
1440 lastUsedSlotInCommonPalette = mergedCommonPalette;
1441 if ( lastUsedSlotInCommonPalette > 2 ) {
1443 }
1444 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1445
1446 }
1447
1448 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1450 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1451
1452 int bufferSize = cpc_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_GRAPHIC2 );
1453
1454 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_GRAPHIC2 );
1455
1456 adilinebeginbitmap("BMD");
1457
1458 char * buffer = malloc ( bufferSize );
1459
1460 // Position of the pixel in the original image
1461 int image_x, image_y;
1462
1463 // Position of the pixel, in terms of tiles
1464 int tile_x, tile_y;
1465
1466 // Position of the pixel, in terms of offset and bitmask
1467 int offset, bitmask;
1468
1469 int colorIndex;
1470
1471 // Color of the pixel to convert
1472 RGBi rgb;
1473
1474 *(buffer) = (_frame_width & 0xff);
1475 *(buffer+1) = ( _frame_width >> 8 ) & 0xff;
1476 *(buffer+2) = _frame_height;
1477
1478 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1479
1480 // Loop for all the source surface.
1481 for (image_y = 0; image_y < _frame_height; ++image_y) {
1482 for (image_x = 0; image_x < _frame_width; ++image_x) {
1483
1484 // Take the color of the pixel
1485 rgb.red = *_source;
1486 rgb.green = *(_source + 1);
1487 rgb.blue = *(_source + 2);
1488 if ( _depth > 3 ) {
1489 rgb.alpha = *(_source + 3);
1490 } else {
1491 rgb.alpha = 255;
1492 }
1493 if ( rgb.alpha == 0 ) {
1494 rgb.red = 0;
1495 rgb.green = 0;
1496 rgb.blue = 0;
1497 }
1498
1499 if ( rgb.alpha < 255 ) {
1500 colorIndex = 0;
1501 } else {
1502 int minDistance = 9999;
1503 for( int i=(_transparent_color)?1:0; i<lastUsedSlotInCommonPalette; ++i ) {
1504 int distance = rgbi_distance(&commonPalette[i], &rgb );
1505 if ( distance < minDistance ) {
1506 minDistance = distance;
1507 colorIndex = i;
1508 }
1509 }
1510 }
1511
1512 adilinepixel(colorIndex);
1513
1514 // Calculate the offset starting from the tile surface area
1515 // and the bit to set.
1516 offset = (image_y *( _frame_width >> 3 ) ) + (image_x >> 3 );
1517 bitmask = 1 << ( 7 - (image_x & 0x7) );
1518
1519 if ( colorIndex == 1 ) {
1520 *( buffer + offset + 3) |= bitmask;
1521 } else {
1522 *( buffer + offset + 3) &= ~bitmask;
1523 }
1524
1525 _source += _depth;
1526
1527 }
1528
1529 _source += ( _width - _frame_width ) * _depth;
1530
1531 }
1532
1534
1535 int hwIndex;
1536
1537 if ( lastUsedSlotInCommonPalette > 1 ) {
1538 hwIndex = commonPalette[1].hardwareIndex;
1539 } else {
1540 hwIndex = 0xff;
1541 }
1542 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) + 1 ) = hwIndex;
1543
1544 if ( lastUsedSlotInCommonPalette > 1 ) {
1545 hwIndex = commonPalette[0].hardwareIndex;
1546 } else {
1547 hwIndex = 0xff;
1548 }
1549 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) ) = hwIndex;
1550
1551 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1552
1553 return result;
1554
1555}
1556
1557static Variable * cpc_image_converter_multicolor_mode_midres( 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 ) {
1558
1559 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
1560
1561 if ( _environment->freeImageWidth ) {
1562 if ( _width % 4 ) {
1563 _width = ( ( ( _width - 1 ) / 4 ) - 1 ) * 4;
1564 }
1565 if ( _frame_width % 4 ) {
1566 _frame_width = ( ( ( _frame_width - 1 ) / 4 ) - 1 ) * 4;
1567 }
1568 }
1569
1570 RGBi * palette = malloc_palette( MAX_PALETTE );
1571
1572 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1573
1574 if (paletteColorCount > 4) {
1575 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1576 }
1577
1578 int i, j, k;
1579
1580 if ( ! commonPalette ) {
1581
1582 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1583 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1584 if ( _transparent_color & 0x0f0000 ) {
1585 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1586 }
1587 if ( _transparent_color & 0xf00000 ) {
1588 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 4 );
1589 paletteColorCount = 4;
1590 }
1591 lastUsedSlotInCommonPalette = paletteColorCount;
1592 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1593
1594 } else {
1595
1596 RGBi * newPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1597 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
1598 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1599
1600 int mergedCommonPalette = 0;
1601
1602 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1603
1604 if ( _transparent_color & 0x0f0000 ) {
1605 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1606 }
1607 if ( _transparent_color & 0xf00000 ) {
1608 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 4 );
1609 mergedCommonPalette = 4;
1610 }
1611
1612 lastUsedSlotInCommonPalette = mergedCommonPalette;
1613 if ( lastUsedSlotInCommonPalette > 4 ) {
1615 }
1616 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1617
1618 }
1619
1620 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1622 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1623
1624 int bufferSize = cpc_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_GRAPHIC1 );
1625
1626 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_GRAPHIC1 );
1627
1628 adilinebeginbitmap("BMD");
1629
1630 char * buffer = malloc ( bufferSize );
1631 memset( buffer, 0, bufferSize );
1632
1633 // Position of the pixel in the original image
1634 int image_x, image_y;
1635
1636 // Position of the pixel, in terms of tiles
1637 int tile_x, tile_y;
1638
1639 // Position of the pixel, in terms of offset and bitmask
1640 int offset, offsetc, bitmask;
1641
1642 // Color of the pixel to convert
1643 RGBi rgb;
1644
1645 *(buffer) = (_frame_width & 0xff);
1646 *(buffer+1) = (_frame_width >> 8 ) & 0xff;
1647 *(buffer+2) = _frame_height;
1648
1649 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1650
1651 // Loop for all the source surface.
1652 for (image_y = 0; image_y < _frame_height; ++image_y) {
1653 for (image_x = 0; image_x < _frame_width; ++image_x) {
1654
1655 // Take the color of the pixel
1656 rgb.red = *_source;
1657 rgb.green = *(_source + 1);
1658 rgb.blue = *(_source + 2);
1659 if ( _depth > 3 ) {
1660 rgb.alpha = *(_source + 3);
1661 } else {
1662 rgb.alpha = 255;
1663 }
1664 if ( rgb.alpha == 0 ) {
1665 rgb.red = 0;
1666 rgb.green = 0;
1667 rgb.blue = 0;
1668 }
1669
1670 // Calculate the offset starting from the tile surface area
1671 // and the bit to set.
1672 offset = (image_y * ( _frame_width >> 2 ) ) + (image_x>>2);
1673
1674 int colorIndex = 0;
1675
1676 if ( rgb.alpha < 255 ) {
1677 colorIndex = 0;
1678 } else {
1679 int minDistance = 9999;
1680 for( int i=(_transparent_color)?1:0; i<lastUsedSlotInCommonPalette; ++i ) {
1681 int distance = rgbi_distance(&commonPalette[i], &rgb );
1682 if ( distance < minDistance ) {
1683 minDistance = distance;
1684 colorIndex = i;
1685 }
1686 }
1687 }
1688
1689 adilinepixel(colorIndex);
1690
1691 bitmask = ( ( colorIndex & 0x2 ) >> 1 ) << (3 - ((image_x & 0x3)));
1692 bitmask |= ( ( ( colorIndex & 0x1 ) ) << 4 ) << (3 - ((image_x & 0x3)));
1693
1694 *(buffer + 3 + offset) |= bitmask;
1695
1696 _source += _depth;
1697
1698 }
1699
1700 _source += ( _width - _frame_width ) * _depth;
1701
1702 }
1703
1705
1706 int hwIndex = 0;
1707 if ( lastUsedSlotInCommonPalette > 0 ) {
1708 hwIndex = commonPalette[0].hardwareIndex;
1709 } else {
1710 hwIndex = 0xff;
1711 }
1712 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) )= hwIndex;
1713
1714 if ( lastUsedSlotInCommonPalette > 1 ) {
1715 hwIndex = commonPalette[1].hardwareIndex;
1716 } else {
1717 hwIndex = 0xff;
1718 }
1719 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 1 ) = hwIndex;
1720
1721 if ( lastUsedSlotInCommonPalette > 2 ) {
1722 hwIndex = commonPalette[2].hardwareIndex;
1723 } else {
1724 hwIndex = 0xff;
1725 }
1726 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 2 ) = hwIndex;
1727
1728 if ( lastUsedSlotInCommonPalette > 3 ) {
1729 hwIndex = commonPalette[3].hardwareIndex;
1730 } else {
1731 hwIndex = 0xff;
1732 }
1733 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 3 ) = hwIndex;
1734
1735 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1736
1737 return result;
1738
1739}
1740
1741static Variable * cpc_image_converter_multicolor_mode_lores( 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 ) {
1742
1743 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
1744
1745 if ( _environment->freeImageWidth ) {
1746 if ( _width % 2 ) {
1747 _width = ( ( ( _width - 1 ) / 2) - 1 ) * 2;
1748 }
1749 if ( _frame_width % 2 ) {
1750 _frame_width = ( ( ( _frame_width - 1 ) / 2 ) - 1 ) * 2;
1751 }
1752 }
1753
1754 RGBi * palette = malloc_palette( MAX_PALETTE );
1755
1756 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1757
1758 if (paletteColorCount > 16) {
1759 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1760 }
1761
1762 int i, j, k;
1763
1764 if ( ! commonPalette ) {
1765
1766 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1767 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1768
1769 if ( _transparent_color & 0x0f0000 ) {
1770 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
1771 }
1772 if ( _transparent_color & 0xf00000 ) {
1773 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 16 );
1774 paletteColorCount = 16;
1775 }
1776
1777 lastUsedSlotInCommonPalette = paletteColorCount;
1778 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1779
1780 } else {
1781
1782 RGBi * newPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
1783
1784 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
1785
1786 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
1787
1788 int mergedCommonPalette = 0;
1789
1790 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
1791
1792 if ( _transparent_color & 0x0f0000 ) {
1793 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
1794 }
1795 if ( _transparent_color & 0xf00000 ) {
1796 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 16 );
1797 mergedCommonPalette = 16;
1798 }
1799
1800 lastUsedSlotInCommonPalette = mergedCommonPalette;
1801 if ( lastUsedSlotInCommonPalette > 16 ) {
1803 }
1804 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
1805
1806 }
1807
1808 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1810 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1811
1812 int bufferSize = cpc_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_GRAPHIC0 );
1813
1814 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_GRAPHIC0 );
1815
1816 adilinebeginbitmap("BMD");
1817
1818 char * buffer = malloc ( bufferSize );
1819 memset( buffer, 0, bufferSize );
1820
1821 // Position of the pixel in the original image
1822 int image_x, image_y;
1823
1824 // Position of the pixel, in terms of tiles
1825 int tile_x, tile_y;
1826
1827 // Position of the pixel, in terms of offset and bitmask
1828 int offset, offsetc, bitmask;
1829
1830 // Color of the pixel to convert
1831 RGBi rgb;
1832
1833 *(buffer) = (_frame_width & 0xff);
1834 *(buffer+1) = (_frame_width >> 8 ) & 0xff;
1835 *(buffer+2) = _frame_height;
1836
1837 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1838
1839 // Loop for all the source surface.
1840 for (image_y = 0; image_y < _frame_height; ++image_y) {
1841 for (image_x = 0; image_x < _frame_width; ++image_x) {
1842
1843 // Take the color of the pixel
1844 rgb.red = *_source;
1845 rgb.green = *(_source + 1);
1846 rgb.blue = *(_source + 2);
1847 if ( _depth > 3 ) {
1848 rgb.alpha = *(_source + 3);
1849 } else {
1850 rgb.alpha = 255;
1851 }
1852 if ( rgb.alpha == 0 ) {
1853 rgb.red = 0;
1854 rgb.green = 0;
1855 rgb.blue = 0;
1856 }
1857
1858 // Calculate the offset starting from the tile surface area
1859 // and the bit to set.
1860 offset = (image_y * ( _frame_width >> 1 ) ) + (image_x>>1);
1861
1862 int colorIndex = 0;
1863
1864 if ( rgb.alpha < 255 ) {
1865 colorIndex = 0;
1866 } else {
1867 int minDistance = 9999;
1868 for( int i=(_transparent_color)?1:0; i<lastUsedSlotInCommonPalette; ++i ) {
1869 int distance = rgbi_distance(&commonPalette[i], &rgb );
1870 if ( distance < minDistance ) {
1871 minDistance = distance;
1872 colorIndex = i;
1873 }
1874 }
1875 }
1876
1877 adilinepixel(colorIndex);
1878
1879 bitmask = ( ( colorIndex & 0x8 ) >> 3 ) << (1 - ((image_x & 0x1)));
1880 bitmask |= ( ( ( colorIndex & 0x2 ) ) << 1 ) << (1 - ((image_x & 0x1)));
1881 bitmask |= ( ( ( colorIndex & 0x4 ) ) << 2 ) << (1 - ((image_x & 0x1)));
1882 bitmask |= ( ( ( colorIndex & 0x1 ) ) << 6 ) << (1 - ((image_x & 0x1)));
1883
1884 *(buffer + 3 + offset) |= bitmask;
1885
1886 _source += _depth;
1887
1888 }
1889
1890 _source += ( _width - _frame_width ) * _depth;
1891
1892 }
1893
1895
1896 for( int i=0; i<16; ++i ) {
1897 int hwIndex = 0xff;
1898 if ( lastUsedSlotInCommonPalette > ( i ) ) {
1899 hwIndex = commonPalette[i].hardwareIndex;
1900 }
1901 *(buffer + 3 + ( ( _frame_width >> 1 ) * _frame_height ) + i ) = hwIndex;
1902 }
1903
1904 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1905
1906 return result;
1907
1908}
1909
1910Variable * cpc_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 ) {
1911
1912 switch( _mode ) {
1913
1915
1916 return cpc_image_converter_bitmap_mode_hires( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1917
1919
1920 return cpc_image_converter_multicolor_mode_midres( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1921
1924
1925 return cpc_image_converter_multicolor_mode_lores( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1926
1927 }
1928
1929 return cpc_new_image( _environment, 8, 8, _mode );
1930
1931}
1932
1933static void cpc_load_image_address_to_hl( Environment * _environment, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
1934
1935 outline1("LD HL, %s", _source );
1936 if ( _sequence ) {
1937
1938 outline0("LD DE, 0x0003" );
1939 outline0("ADD HL, DE" );
1940 if ( strlen(_sequence) == 0 ) {
1941
1942 } else {
1943 outline0("PUSH HL" );
1944 outline1("LD A, (%s)", _sequence );
1945 outline0("LD L, A" );
1946 outline0("LD H, 0" );
1947 outline0("ADD HL, HL" );
1948 outline0("LD DE, HL" );
1949 outline1("LD HL, OFFSETS%4.4x", _frame_size * _frame_count );
1950 outline0("ADD HL, DE" );
1951 outline0("LD A, (HL)" );
1952 outline0("LD E, A" );
1953 outline0("INC HL" );
1954 outline0("LD A, (HL)" );
1955 outline0("LD D, A" );
1956 outline0("POP HL" );
1957 outline0("ADD HL, DE" );
1958 }
1959
1960 if ( _frame ) {
1961 if ( strlen(_frame) == 0 ) {
1962
1963 } else {
1964 outline0("PUSH HL" );
1965 outline1("LD A, (%s)", _frame );
1966 outline0("LD L, A" );
1967 outline0("LD H, 0" );
1968 outline0("ADD HL, HL" );
1969 outline0("LD DE, HL" );
1970 outline1("LD HL, OFFSETS%4.4x", _frame_size );
1971 outline0("ADD HL, DE" );
1972 outline0("LD A, (HL)" );
1973 outline0("LD E, A" );
1974 outline0("INC HL" );
1975 outline0("LD A, (HL)" );
1976 outline0("LD D, A" );
1977 outline0("POP HL" );
1978 outline0("ADD HL, DE" );
1979 }
1980 }
1981
1982 } else {
1983
1984 if ( _frame ) {
1985 outline0("LD DE, 0x0003" );
1986 outline0("ADD HL, DE" );
1987 if ( strlen(_frame) == 0 ) {
1988
1989 } else {
1990 outline0("PUSH HL" );
1991 outline1("LD A, (%s)", _frame );
1992 outline0("LD L, A" );
1993 outline0("LD H, 0" );
1994 outline0("ADD HL, HL" );
1995 outline0("LD DE, HL" );
1996 outline1("LD HL, OFFSETS%4.4x", _frame_size );
1997 outline0("ADD HL, DE" );
1998 outline0("LD A, (HL)" );
1999 outline0("LD E, A" );
2000 outline0("INC HL" );
2001 outline0("LD A, (HL)" );
2002 outline0("LD D, A" );
2003 outline0("POP HL" );
2004 outline0("ADD HL, DE" );
2005 }
2006 }
2007
2008 }
2009
2010}
2011
2012static void cpc_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2013
2014 if ( !_sequence && !_frame ) {
2015 if ( _source->isAddress ) {
2016 outline1("LD HL, (%s)", _source->realName );
2017 } else {
2018 outline1("LD HL, %s", _source->realName );
2019 }
2020 } else {
2021 if ( _source->isAddress ) {
2022 outline1("LD HL, (%s)", _source->realName );
2023 } else {
2024 outline1("LD HL, %s", _source->realName );
2025 }
2026
2027 if ( _sequence ) {
2028 outline0("LD DE, $0003" );
2029 outline0("ADD HL, DE" );
2030 if ( strlen(_sequence) == 0 ) {
2031
2032 } else {
2033 outline1("LD A, (%s)", _sequence );
2034 outline0("PUSH HL" );
2035 outline0("POP IX" );
2036 if ( _frame_size ) {
2037 outline1("CALL fs%4.4xoffsetsequence", _frame_size * _frame_count );
2038 } else {
2039 outline1("CALL %soffsetsequence", _source->realName );
2040 }
2041 }
2042 if ( _frame ) {
2043 if ( strlen(_frame) == 0 ) {
2044
2045 } else {
2046 outline1("LD A, (%s)", _frame );
2047 outline0("PUSH HL" );
2048 outline0("POP IX" );
2049 if ( _frame_size ) {
2050 outline1("CALL fs%4.4xoffsetframe", _frame_size );
2051 } else {
2052 outline1("CALL %soffsetframe", _source->realName );
2053 }
2054
2055 }
2056 }
2057
2058 } else {
2059
2060 if ( _frame ) {
2061 outline0("LD DE, $0003" );
2062 outline0("ADD HL, DE" );
2063 if ( strlen(_frame) == 0 ) {
2064
2065 } else {
2066 outline0("PUSH HL" );
2067 outline0("POP IX" );
2068 outline1("LD A, (%s)", _frame );
2069 if ( _frame_size ) {
2070 outline1("CALL fs%4.4xoffsetframe", _frame_size );
2071 } else {
2072 outline1("CALL %soffsetframe", _source->realName );
2073 }
2074 }
2075 }
2076
2077 }
2078
2079 }
2080 if ( _register ) {
2081 outline1("LD (%s), HL", _register );
2082 }
2083
2084}
2085
2086void cpc_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
2087
2088 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2089 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2090 deploy( putimage, src_hw_cpc_put_image_asm );
2091
2093
2094 if ( _frame_size ) {
2095 cpc_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2096 }
2097
2098 outline1("LD A, (%s)", _x );
2099 outline0("LD E, A" );
2100 outline1("LD A, (%s)", address_displacement(_environment, _x, "1") );
2101 outline0("LD IXL, A" );
2102 outline1("LD A, (%s)", _y );
2103 outline0("LD D, A" );
2104 outline0("PUSH HL" );
2105 outline1("LD HL, %s", _flags );
2106 outline0("LD A, L" );
2107 outline0("LD (IMAGEF), A" );
2108 outline0("LD A, H" );
2109 outline0("LD (IMAGET), A" );
2110 outline0("POP HL" );
2111
2112 outline0("CALL PUTIMAGE");
2113
2114}
2115
2116void cpc_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 ) {
2117
2118 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2119 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2120 deploy( blitimage, src_hw_cpc_blit_image_asm );
2121
2122 if ( _source_count > 2 ) {
2124 }
2125
2127
2128 outhead1("blitimage%s:", label);
2129 if ( _source_count > 0 ) {
2130 Resource resource;
2131 resource.realName = strdup( _sources[0] );
2132 resource.type = VT_IMAGE;
2133 resource.isAddress = 0;
2134 cpc_load_image_address_to_register( _environment, NULL, &resource, _sequence, _frame, _frame_size, _frame_count );
2135 } else {
2136 outline0( "LD HL, 0" );
2137 }
2138
2139 outline0("DI");
2140 outline0("EXX");
2141 outline0("EI");
2142
2143 if ( _source_count > 1 ) {
2144 Resource resource;
2145 resource.realName = strdup( _sources[0] );
2146 resource.type = VT_IMAGE;
2147 resource.isAddress = 0;
2148 cpc_load_image_address_to_register( _environment, NULL, &resource, _sequence, _frame, _frame_size, _frame_count );
2149 } else {
2150 outline0( "LD HL, 0" );
2151 }
2152
2153 outline1("LD DE, %s", _blit );
2154
2155 outline0("DI");
2156 outline0("EXX");
2157 outline0("EI");
2158
2159 outline1("LD A, (%s)", _x );
2160 outline0("LD E, A" );
2161 outline1("LD A, (%s)", address_displacement(_environment, _x, "1") );
2162 outline0("LD IXL, A" );
2163 outline1("LD A, (%s)", _y );
2164 outline0("LD D, A" );
2165 outline1("LD A, 0x%2.2x", (_flags & 0Xff) );
2166 outline0("LD (IMAGEF), A" );
2167 outline1("LD A, 0x%2.2x", ((_flags>>8) & 0Xff) );
2168 outline0("LD (IMAGET), A" );
2169
2170 outline0("CALL BLITIMAGE");
2171
2172}
2173
2174void cpc_wait_vbl( Environment * _environment, char * _raster_line ) {
2175
2176 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2177 deploy( vbl, src_hw_cpc_vbl_asm);
2178
2179 if ( _raster_line ) {
2180 Variable * raster_line = variable_retrieve_or_define( _environment, _raster_line, VT_BYTE, 255 );
2181 outline0("LD HL, 0x1000" );
2182 outline1("LD A, (%s)", raster_line->realName );
2183 outline0("LD E, A" );
2184 outline0("LD D, 0" );
2185 outline0("SLA E" );
2186 outline0("RL D" );
2187 outline0("SLA E" );
2188 outline0("RL D" );
2189 outline0("SLA E" );
2190 outline0("RL D" );
2191 outline0("SLA E" );
2192 outline0("RL D" );
2193 outline0("SLA E" );
2194 outline0("RL D" );
2195 outline0("SLA E" );
2196 outline0("RL D" );
2197 outline0("ADD HL, DE" );
2198 outline0("LD DE, HL" );
2199 } else {
2200 outline0("LD DE, 0x1000" );
2201 }
2202 outline0("CALL WAITVBL");
2203
2204}
2205
2206Variable * cpc_new_image( Environment * _environment, int _width, int _height, int _mode ) {
2207
2208 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2209
2210 int size = cpc_image_size( _environment, _width, _height, _mode );
2211
2212 if ( ! size ) {
2214 }
2215
2216 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
2217
2218 char * buffer = malloc ( size );
2219 memset( buffer, 0, size );
2220
2221 *(buffer) = ( _width & 0xff );
2222 *(buffer+1) = ( ( _width >> 8 ) & 0xff );
2223 *(buffer+2) = _height;
2224
2225 result->valueBuffer = buffer;
2226 result->size = size;
2227
2228 return result;
2229
2230}
2231
2232Variable * cpc_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2233
2234 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2235
2236 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2237 int frameSize = cpc_image_size( _environment, _width, _height, _mode );
2238
2239 if ( ! size ) {
2241 }
2242
2243 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
2244
2245 char * buffer = malloc ( size );
2246 memset( buffer, 0, size );
2247
2248 *(buffer) = _frames;
2249 *(buffer+1) = ( _width & 0xff );
2250 *(buffer+2) = ( _width >> 8 ) & 0xff;
2251 for( int i=0; i<_frames; ++i ) {
2252 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2253 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2254 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2255 }
2256
2257 result->valueBuffer = buffer;
2258 result->frameSize = frameSize;
2259 result->size = size;
2260 result->frameCount = _frames;
2261
2262 return result;
2263
2264}
2265
2266Variable * cpc_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2267
2268 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2269
2270 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
2271 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
2272 int frameSize = cpc_image_size( _environment, _width, _height, _mode );
2273
2274 if ( ! size ) {
2276 }
2277
2278 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
2279
2280 char * buffer = malloc ( size2 );
2281 memset( buffer, 0, size2 );
2282
2283 *(buffer) = _frames;
2284 *(buffer+1) = _width;
2285 *(buffer+2) = _sequences;
2286 for( int i=0; i<(_frames*_sequences); ++i ) {
2287 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
2288 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
2289 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
2290 }
2291
2292 result->valueBuffer = buffer;
2293 result->frameSize = frameSize;
2294 result->size = size2;
2295 result->frameCount = _frames;
2296
2297 return result;
2298
2299}
2300
2301void cpc_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
2302
2303 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2304 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2305 deploy( getimage, src_hw_cpc_get_image_asm );
2306
2308
2309 cpc_load_image_address_to_hl( _environment, _image, _sequence, _frame, _frame_size, _frame_count );
2310
2311 outline1("LD A, (%s)", _x );
2312 outline0("LD IYL, A" );
2313 outline1("LD A, (%s)", address_displacement(_environment, _x, "1") );
2314 outline0("LD IYH, A" );
2315 outline1("LD A, (%s)", _y );
2316 outline0("LD D, A" );
2317 outline1("LD A, 0x%2.2x", _palette );
2318 outline0("LD IXH, A" );
2319
2320 outline0("CALL GETIMAGE");
2321
2322}
2323
2324void cpc_scroll( Environment * _environment, int _dx, int _dy ) {
2325
2326 deploy( vic2vars, src_hw_cpc_vars_asm);
2327 deploy( scroll, src_hw_cpc_scroll_asm);
2328 deploy( textHScrollLine, src_hw_cpc_hscroll_line_asm );
2329 deploy( textHScrollScreen, src_hw_cpc_hscroll_screen_asm );
2330 deploy_preferred( vScrollTextDown, src_hw_cpc_vscroll_text_down_asm );
2331 deploy_preferred( vScrollTextUp, src_hw_cpc_vscroll_text_up_asm );
2332
2333 outline1("LD A, 0x%2.2x", (unsigned char)(_dx&0xff) );
2334 outline0("LD B, A" );
2335 outline1("LD A, 0x%2.2x", (unsigned char)(_dy&0xff) );
2336 outline0("LD C, A" );
2337 outline0("CALL SCROLL");
2338
2339}
2340
2341void cpc_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
2342
2343 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2344 deploy( tiles, src_hw_cpc_tiles_asm );
2345
2346 outline1("LD A, (%s)", _tile );
2347 outline0("LD (TILET), A" );
2348 outline1("LD A, (%s)", _x );
2349 outline0("LD (TILEX), A" );
2350 outline1("LD A, (%s)", _y );
2351 outline0("LD (TILEY), A" );
2352 outline0("LD A, 1" );
2353 outline0("LD (TILEW), A" );
2354 outline0("LD (TILEH), A" );
2355 outline0("LD (TILEW2), A" );
2356 outline0("LD (TILEH2), A" );
2357
2358 outline0("CALL PUTTILE");
2359
2360}
2361
2362void cpc_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
2363
2364 Variable * tile = variable_retrieve( _environment, _tile );
2365 Variable * x = variable_retrieve( _environment, _x );
2366 Variable * y = variable_retrieve( _environment, _y );
2367
2368 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2369 deploy( tiles, src_hw_cpc_tiles_asm );
2370
2371 int size = ( tile->originalWidth >> 3 ) * ( tile->originalHeight >> 3 );
2372
2373 if ( size ) {
2374 outline1("LD HL, OFFSETS%4.4x", size );
2375 outline0("LD A, L" );
2376 outline0("LD (TILEO), A" );
2377 outline0("LD A, H" );
2378 outline0("LD (TILEO+1), A" );
2379 } else {
2380 outline0("LD A, 0" );
2381 outline0("LD (TILEO), A" );
2382 outline0("LD (TILEO+1), A" );
2383 }
2384
2385 outline1("LD A, (%s)", tile->realName );
2386 outline0("LD (TILET), A" );
2387 outline1("LD A, (%s)", x->realName );
2388 outline0("LD (TILEX), A" );
2389 outline1("LD A, (%s)", y->realName );
2390 outline0("LD (TILEY), A" );
2391 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "1") );
2392 outline0("LD (TILEW), A" );
2393 outline0("LD (TILEW2), A" );
2394 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "2") );
2395 outline0("LD (TILEH), A" );
2396 outline0("LD (TILEH2), A" );
2397 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "3") );
2398 outline0("LD (TILEA), A" );
2399
2400 outline0("CALL MOVETILE");
2401
2402}
2403
2404void cpc_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
2405
2406 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2407 deploy( tiles, src_hw_cpc_tiles_asm );
2408
2409 outline1("LD A, (%s)", _tile );
2410 outline0("LD (TILET), A" );
2411 outline1("LD A, (%s)", _x );
2412 outline0("LD (TILEX), A" );
2413 outline1("LD A, (%s)", _y );
2414 outline0("LD (TILEY), A" );
2415 outline1("LD A, (%s)", address_displacement(_environment, _tile, "1") );
2416 outline0("LD (TILEW), A" );
2417 if ( _w ) {
2418 outline1("LD A, (%s)", _w );
2419 }
2420 outline0("LD (TILEW2), A" );
2421 outline1("LD A, (%s)", address_displacement(_environment, _tile, "2") );
2422 outline0("LD (TILEH), A" );
2423 if ( _h ) {
2424 outline1("LD A, (%s)", _h );
2425 }
2426 outline0("LD (TILEH2), A" );
2427
2428 outline0("CALL PUTTILE");
2429
2430}
2431
2432void cpc_tile_at( Environment * _environment, char * _x, char * _y, char *_result ) {
2433
2434 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2435 deploy( tiles, src_hw_cpc_tiles_asm );
2436
2437 outline1("LD A, (%s)", _x );
2438 outline0("LD (TILEX), A" );
2439 outline1("LD A, (%s)", _y );
2440 outline0("LD (TILEY), A" );
2441
2442 outline0("CALL TILEAT");
2443
2444 outline0("LD A, (TILET)" );
2445 outline1("LD (%s), A", _result );
2446
2447}
2448
2449void cpc_use_tileset( Environment * _environment, char * _tileset ) {
2450
2451 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2452 deploy( tiles, src_hw_cpc_tiles_asm );
2453
2454 outline1("LD A, (%s)", _tileset );
2455
2456 outline0("CALL USETILESET");
2457
2458}
2459
2461
2462 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
2463
2464 variable_store( _environment, result->name, 0 );
2465
2466 return result;
2467
2468}
2469
2470void cpc_move_memory_video( Environment * _environment, char * _from, char * _to, char * _size ) {
2471
2472}
2473
2474void cpc_move_video_memory( Environment * _environment, char * _from, char * _to, char * _size ) {
2475
2476}
2477
2478void cpc_colors_vars( Environment * _environment, char * _foreground_color, char * _background_color ) {
2479
2480}
2481
2482void cpc_slice_image_copy( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2483
2484 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2485 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2486 deploy( duff, src_hw_z80_duff_asm );
2487 deploy( sliceimagecopy, src_hw_cpc_slice_image_copy_asm );
2488
2490
2491 Resource resource;
2492 resource.realName = strdup( _image );
2493 resource.type = VT_IMAGE;
2494 cpc_load_image_address_to_register( _environment, "HL", &resource, _sequence, _frame, _frame_size, _frame_count );
2495
2496 outline1( "LD DE, %s", _destination );
2497
2498 outline0("CALL SLICEIMAGECOPY");
2499
2500}
2501
2502void cpc_slice_image_extract( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2503
2504 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2505 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2506 deploy( duff, src_hw_z80_duff_asm );
2507 deploy( sliceimageextract, src_hw_cpc_slice_image_extract_asm );
2508
2510
2511 Resource resource;
2512 resource.realName = strdup( _image );
2513 resource.type = VT_IMAGE;
2514 cpc_load_image_address_to_register( _environment, "HL", &resource, _sequence, _frame, _frame_size, _frame_count );
2515
2516 Variable * sliceImageX = variable_retrieve( _environment, _environment->sliceImageX );
2517 Variable * sliceImageY = variable_retrieve( _environment, _environment->sliceImageY );
2518 outline1( "LD DE, (%s)", sliceImageX->realName );
2519 outline0( "LD (SLICEX), DE" );
2520 outline1( "LD DE, (%s)", sliceImageY->realName );
2521 outline0( "LD (SLICEY), DE" );
2522 outline1( "LD DE, %s", _destination );
2523
2524 outline0("CALL SLICEIMAGEEXT");
2525
2526}
2527
2528void cpc_sys_call( Environment * _environment, int _destination ) {
2529
2530 _environment->sysCallUsed = 1;
2531
2532 outline0("PUSH HL" );
2533 outline0("LD HL, SYSCALL0" );
2534 outline0("INC HL" );
2535 outline1("LD (HL), 0x%2.2x", (_destination & 0xff ) );
2536 outline0("INC HL" );
2537 outline1("LD (HL), 0x%2.2x", ((_destination>>8) & 0xff ) );
2538 outline0("POP HL" );
2539 outline0("CALL SYSCALL");
2540
2541}
2542
2543int cpc_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
2544
2545 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2546
2547 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
2548
2549 int uniquePaletteCount = 0;
2550
2551 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
2552
2553 return uniquePaletteCount;
2554
2555}
2556
2557void cpc_timer_set_status_on( Environment * _environment, char * _timer ) {
2558
2559 deploy( timer, src_hw_z80_timer_asm);
2560
2561 if ( _timer ) {
2562 outline1("LD A, (%s)", _timer );
2563 outline0("LD B, A" );
2564 } else {
2565 outline0("LD B, 0" );
2566 }
2567 outline0("LD A, 1" );
2568 outline0("LD C, A" );
2569 outline0("CALL TIMERSETSTATUS" );
2570
2571}
2572
2573void cpc_timer_set_status_off( Environment * _environment, char * _timer ) {
2574
2575 deploy( timer, src_hw_z80_timer_asm);
2576
2577 if ( _timer ) {
2578 outline1("LD A, (%s)", _timer );
2579 outline0("LD B, A" );
2580 } else {
2581 outline0("LD B, 0" );
2582 }
2583 outline0("LD A, 0" );
2584 outline0("LD C, A" );
2585 outline0("CALL TIMERSETSTATUS" );
2586
2587
2588}
2589
2590void cpc_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
2591
2592 deploy( timer, src_hw_z80_timer_asm);
2593
2594 if ( _counter ) {
2595 outline1("LD A, (%s)", _counter );
2596 outline0("LD IXL, A" );
2597 outline1("LD A, (%s)", address_displacement( _environment, _counter, "1" ) );
2598 outline0("LD IXH, A" );
2599 } else {
2600 outline0("LD IX, 0" );
2601 }
2602 if ( _timer ) {
2603 outline1("LD A, (%s)", _timer );
2604 outline0("LD B, A" );
2605 } else {
2606 outline0("LD B, 0" );
2607 }
2608 outline0("CALL TIMERSETCOUNTER" );
2609
2610}
2611
2612void cpc_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
2613
2614 deploy( timer, src_hw_z80_timer_asm);
2615
2616 if ( _init ) {
2617 outline1("LD A, (%s)", _init );
2618 outline0("LD IXL, A" );
2619 outline1("LD A, (%s)", address_displacement( _environment, _init, "1" ) );
2620 outline0("LD IXH, A" );
2621 } else {
2622 outline0("LD IX, 0" );
2623 }
2624 if ( _timer ) {
2625 outline1("LD A, (%s)", _timer );
2626 outline0("LD B, A" );
2627 } else {
2628 outline0("LD B, 0" );
2629 }
2630 outline0("CALL TIMERSETINIT" );
2631
2632}
2633
2634void cpc_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
2635
2636 deploy( timer, src_hw_z80_timer_asm);
2637
2638 if ( _address ) {
2639 outline1("LD HL, %s", _address );
2640 outline0("LD A, L" );
2641 outline0("LD IXL, A" );
2642 outline0("LD A, H" );
2643 outline0("LD IXH, A" );
2644 } else {
2645 outline0("LD IX, 0" );
2646 }
2647 if ( _timer ) {
2648 outline1("LD A, (%s)", _timer );
2649 outline0("LD B, A" );
2650 } else {
2651 outline0("LD B, 0" );
2652 }
2653 outline0("CALL TIMERSETADDRESS" );
2654
2655}
2656
2657void cpc_dload( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
2658
2659 deploy_preferred( dload, src_hw_cpc_dload_asm );
2660
2662
2663 Variable * filename = variable_retrieve( _environment, _filename );
2664 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
2665 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
2666
2667 Variable * address = NULL;
2668 if ( _address ) {
2669 address = variable_retrieve( _environment, _address );
2670 }
2671 Variable * size = NULL;
2672 if ( _size ) {
2673 size = variable_retrieve( _environment, _size );
2674 }
2675 Variable * offset = NULL;
2676 if ( _offset ) {
2677 offset = variable_retrieve( _environment, _offset );
2678 }
2679
2680 switch( filename->type ) {
2681 case VT_STRING:
2682 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
2683 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
2684 cpu_inc_16bit( _environment, tnaddress->realName );
2685 break;
2686 case VT_DSTRING:
2687 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
2688 break;
2689 }
2690
2691 outline1("LD HL, (%s)", tnaddress->realName);
2692 outline1("LD A, (%s)", tnsize->realName);
2693 outline0("LD B, A");
2694
2695 if ( address ) {
2696
2697 outline1("LD DE, (%s)", address->realName);
2698
2699 }
2700
2701 outline0("CALL CPCDLOAD");
2702
2703}
2704
2705void cpc_dsave( Environment * _environment, char * _filename, char * _offset, char * _address, char * _size ) {
2706
2707 deploy_preferred( dsave, src_hw_cpc_dsave_asm );
2708
2710
2711 Variable * filename = variable_retrieve( _environment, _filename );
2712 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
2713 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
2714
2715 Variable * address = NULL;
2716 if ( _address ) {
2717 address = variable_retrieve( _environment, _address );
2718 }
2719 Variable * size = NULL;
2720 if ( _size ) {
2721 size = variable_retrieve( _environment, _size );
2722 }
2723 Variable * offset = NULL;
2724 if ( _offset ) {
2725 offset = variable_retrieve( _environment, _offset );
2726 }
2727
2728 switch( filename->type ) {
2729 case VT_STRING:
2730 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
2731 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
2732 cpu_inc_16bit( _environment, tnaddress->realName );
2733 break;
2734 case VT_DSTRING:
2735 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
2736 break;
2737 }
2738
2739 outline1("LD HL, (%s)", tnaddress->realName);
2740 outline1("LD A, (%s)", tnsize->realName);
2741 outline0("LD B, A");
2742
2743 if ( address ) {
2744
2745 outline1("LD DE, (%s)", address->realName);
2746
2747 }
2748
2749 if ( size ) {
2750
2751 outline1("LD IX, (%s)", size->realName);
2752
2753 }
2754
2755 outline0("CALL CPCDSAVE");
2756
2757}
2758
2759void cpc_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2760
2761 if ( !_sequence && !_frame ) {
2762 outline0("LD HL, 0" );
2763 } else {
2764 outline0("LD HL, 0" );
2765
2766 if ( _sequence ) {
2767 outline0("LD DE, 0x0003" );
2768 outline0("ADD HL, DE" );
2769 if ( strlen(_sequence) == 0 ) {
2770
2771 } else {
2772 outline1("LD A, (%s)", _sequence );
2773 outline0("PUSH HL" );
2774 outline0("POP IX" );
2775 outline1("CALL OFFSETS%4.4X", _frame_count * _frame_size );
2776 }
2777 if ( _frame ) {
2778 if ( strlen(_frame) == 0 ) {
2779
2780 } else {
2781 outline1("LD A, (%s)", _frame );
2782 outline0("PUSH HL" );
2783 outline0("POP IX" );
2784 outline1("CALL OFFSETS%4.4X", _frame_size );
2785 }
2786 }
2787
2788 } else {
2789
2790 if ( _frame ) {
2791 outline0("LD DE, 0x0003" );
2792 outline0("ADD HL, DE" );
2793 if ( strlen(_frame) == 0 ) {
2794
2795 } else {
2796 outline0("PUSH HL" );
2797 outline0("POP IX" );
2798 outline1("LD A, (%s)", _frame );
2799 outline1("CALL OFFSETS%4.4X", _frame_size );
2800 }
2801 }
2802
2803 }
2804
2805 }
2806 outline1("LD (%s), HL", _offset );
2807
2808}
2809
2810void cpc_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
2811
2812 // deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2813 // deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2814
2815 // MAKE_LABEL
2816
2817 // if ( _direction & FLAG_FLIP_X ) {
2818 // cpc_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2819 // deploy( flipimagex, src_hw_cpc_flip_image_x_asm );
2820 // outline0("CALL FLIPIMAGEX");
2821 // }
2822
2823 // if ( _direction & FLAG_FLIP_Y ) {
2824 // ef936x_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
2825 // deploy( flipimagey, src_hw_cpc_flip_image_y_asm );
2826 // outline0("CALL FLIPIMAGEY");
2827 // }
2828
2829}
2830
2831
2832void cpc_put_key( Environment * _environment, char *_string, char * _size ) {
2833
2834 _environment->bitmaskNeeded = 1;
2835
2836 deploy_deferred( keyboard, src_hw_cpc_keyboard_asm);
2837
2838 outline1("LD HL, (%s)", _string );
2839 outline1("LD A, (%s)", _size );
2840 outline0("LD C, A" );
2841 outline0("CALL PUTKEY" );
2842
2843}
2844
2845void cpc_fade( Environment * _environment, char * _ticks ) {
2846
2847 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2848 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2849 deploy( fade, src_hw_cpc_fade_asm );
2850
2851 outline0( "DI" );
2852 outline0( "LD A, 0" );
2853 outline0( "LD (FADESTEP), A" );
2854 outline1( "LD HL, (%s)", _ticks );
2855 outline0( "LD (FADEDURATION), HL" );
2856 outline0( "LD (FADERESETDURATION), HL" );
2857 outline0( "EI" );
2858
2859}
2860
2861void cpc_flash_begin( Environment * _environment, char * _index, char * _register ) {
2862
2863 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2864 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2865 deploy( flash, src_hw_cpc_flash_asm );
2866
2867 outline0("CALL FLASHBEGIN");
2868 if ( _register ) {
2869 outline1("LD A, (%s)", _index );
2870 outline1("LD B, (%s)", _register );
2871 outline0("LD E, A" );
2872 outline0("LD D, 0" );
2873 outline0("LD HL, FLASHREGISTERADDRESSES" );
2874 outline0("ADD HL, DE" );
2875 outline0("ADD HL, DE" );
2876 outline0("LD A, (HL)" );
2877 outline0("LD E, A" );
2878 outline0("INC HL" );
2879 outline0("LD A, (HL)" );
2880 outline0("LD D, A" );
2881 outline0("LD (HL), B" );
2882 }
2883
2884}
2885
2886void cpc_flash_register( Environment * _environment, char * _index, char * _timer, char * _color ) {
2887
2888 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2889 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2890 deploy( flash, src_hw_cpc_flash_asm );
2891
2892 outline1("LD A, (%s)", _color );
2893 outline0("LD C, A" );
2894 outline1("LD A, (%s)", _timer );
2895 outline0("LD B, A" );
2896 outline1("LD A, (%s)", _index );
2897 outline0("CALL FLASHREGISTER");
2898
2899}
2900
2901void cpc_flash_end( Environment * _environment ) {
2902
2903 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2904 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2905 deploy( flash, src_hw_cpc_flash_asm );
2906
2907 outline0("CALL FLASHEND");
2908
2909}
2910
2911void cpc_flash_off( Environment * _environment, char * _index ) {
2912
2913 deploy_preferred( cpcvars, src_hw_cpc_vars_asm);
2914 deploy_preferred( cpcvarsGraphic, src_hw_cpc_vars_graphic_asm );
2915 deploy( flash, src_hw_cpc_flash_asm );
2916
2917 outline1("LD A, (%s)", _index);
2918 outline0("CALL FLASHOFF");
2919
2920}
2921
2922void cpc_chain( Environment * _environment, char * _filename ) {
2923
2924 deploy_preferred( dload, src_hw_cpc_dload_asm );
2925 deploy_preferred( dload, src_hw_cpc_chain_asm );
2926
2928
2929 Variable * filename = variable_retrieve( _environment, _filename );
2930 Variable * tnaddress = variable_temporary( _environment, VT_ADDRESS, "(address of target_name)");
2931 Variable * tnsize = variable_temporary( _environment, VT_BYTE, "(size of target_name)");
2932
2933 switch( filename->type ) {
2934 case VT_STRING:
2935 cpu_move_8bit( _environment, filename->realName, tnsize->realName );
2936 cpu_addressof_16bit( _environment, filename->realName, tnaddress->realName );
2937 cpu_inc_16bit( _environment, tnaddress->realName );
2938 break;
2939 case VT_DSTRING:
2940 cpu_dsdescriptor( _environment, filename->realName, tnaddress->realName, tnsize->realName );
2941 break;
2942 }
2943
2944 outline1("LD HL, (%s)", tnaddress->realName);
2945 outline1("LD A, (%s)", tnsize->realName);
2946 outline0("LD B, A");
2947
2948 outline0("CALL CHAIN");
2949
2950}
2951
2952#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_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
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_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
void cpu_ctoa(Environment *_environment)
Definition 6309.c:279
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6309.c:5977
int lastUsedSlotInCommonPalette
Definition 6847.c:100
#define BITMAP_MODE_DEFAULT
Definition 6847.h:95
Variable * variable_retrieve(Environment *_environment, char *_name)
ScreenMode * find_screen_mode_by_id(Environment *_environment, int _id)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
RGBi * palette_merge(RGBi *_palette1, int _palette1_size, RGBi *_palette2, int _palette2_size, int *_size)
Make a "palette merge".
void image_converter_asserts_free_height(Environment *_environment, int _width, int _height, int _offset_x, int _offset_y, int *_frame_width, int *_frame_height, int _modulo_x)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * palette_promote_color_as_background(int _index, RGBi *_source, int _source_size)
Promote an index color in a palette.
RGBi * malloc_palette(int _size)
Allocate a palette space.
void variable_global(Environment *_environment, char *_pattern)
ScreenMode * find_screen_mode_by_suggestion(Environment *_environment, int _bitmap, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
RGBi * palette_promote_color_as_foreground(int _index, RGBi *_source, int _source_size, int _max_size)
Promote an index color in a palette.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
void font_descriptors_init(Environment *_environment, int _embedded_present)
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
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 dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_bank, char *_size)
Emit code for DLOAD(...).
Definition dload.c:60
void dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Emit code for DLOAD(...).
Definition dsave.c:58
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
void wait_key_or_fire(Environment *_environment, int _port, int _release)
void flash(Environment *_environment, char *_index, char *_register)
Definition flash.c:44
void console_init(Environment *_environment)
Definition console.c:41
void cpc_horizontal_scroll(Environment *_environment, char *_displacement)
Definition cpc.c:939
void cpc_background_color_semivars(Environment *_environment, int _index, char *_background_color)
cpc: emit code to change background color
Definition cpc.c:477
void cpc_asciicode(Environment *_environment, char *_result)
Definition cpc.c:235
void cpc_tiles_get(Environment *_environment, char *_result)
Definition cpc.c:966
Variable * cpc_get_raster_line(Environment *_environment)
Definition cpc.c:2460
void cpc_wait_key(Environment *_environment, int _release)
Definition cpc.c:116
void cpc_key_state(Environment *_environment, char *_scancode, char *_result)
Definition cpc.c:201
void cpc_flash_off(Environment *_environment, char *_index)
Definition cpc.c:2911
void cpc_screen_rows(Environment *_environment, char *_rows)
Definition cpc.c:871
void cpc_chain(Environment *_environment, char *_filename)
Definition cpc.c:2922
Variable * cpc_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition cpc.c:2266
void cpc_sys_call(Environment *_environment, int _destination)
Definition cpc.c:2528
void cpc_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition cpc.c:2301
void cpc_bank_select(Environment *_environment, int _bank)
Definition cpc.c:582
void cpc_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
cpc: emit code to change common sprite's color
Definition cpc.c:528
void cpc_use_tileset(Environment *_environment, char *_tileset)
Definition cpc.c:2449
void cpc_cline(Environment *_environment, char *_characters)
Definition cpc.c:1299
void cpc_joy(Environment *_environment, int _port, char *_value)
Definition cpc.c:326
void cpc_wait_fire(Environment *_environment, int _port, int _release)
Definition cpc.c:165
void cpc_tiles_at(Environment *_environment, char *_address)
Definition cpc.c:931
void cpc_screen_off(Environment *_environment)
Definition cpc.c:867
void cpc_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition cpc.c:903
void cpc_flash_register(Environment *_environment, char *_index, char *_timer, char *_color)
Definition cpc.c:2886
void cpc_colors_vars(Environment *_environment, char *_foreground_color, char *_background_color)
Definition cpc.c:2478
void cpc_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition cpc.c:907
void cpc_back(Environment *_environment)
Definition cpc.c:1295
void cpc_background_color(Environment *_environment, int _index, int _background_color)
cpc: emit code to change background color
Definition cpc.c:427
void cpc_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition cpc.c:1012
void cpc_busy_wait(Environment *_environment, char *_timing)
Definition cpc.c:943
void cpc_scroll(Environment *_environment, int _dx, int _dy)
Definition cpc.c:2324
void cpc_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition cpc.c:837
void cpc_wait_key_or_fire(Environment *_environment, int _port, int _release)
Definition cpc.c:131
void cpc_hit(Environment *_environment, char *_sprite_mask, char *_result)
cpc: emit code to check for collision
Definition cpc.c:392
void cpc_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition cpc.c:717
void cpc_sprite_disable(Environment *_environment, char *_sprite)
Definition cpc.c:891
Variable * cpc_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition cpc.c:2206
void cpc_colormap_at(Environment *_environment, char *_address)
Definition cpc.c:772
void cpc_flash_end(Environment *_environment)
Definition cpc.c:2901
void cpc_initialization(Environment *_environment)
Definition cpc.c:1043
void cpc_wait_key_or_fire_semivar(Environment *_environment, char *_port, int _release)
Definition cpc.c:148
void cpc_scanshift(Environment *_environment, char *_shifts)
Definition cpc.c:261
void cpc_key_pressed(Environment *_environment, char *_scancode, char *_result)
Definition cpc.c:246
void cpc_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition cpc.c:743
void cpc_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition cpc.c:804
void cpc_keyshift(Environment *_environment, char *_shifts)
Definition cpc.c:265
void cpc_dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition cpc.c:2705
void cpc_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition cpc.c:2341
void cpc_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition cpc.c:2362
void cpc_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition cpc.c:2432
void cpc_move_memory_video(Environment *_environment, char *_from, char *_to, char *_size)
Definition cpc.c:2470
void cpc_wait_fire_semivar(Environment *_environment, char *_port, int _release)
Definition cpc.c:186
Variable * cpc_collision(Environment *_environment, char *_sprite)
cpc: emit code to check for collision
Definition cpc.c:373
void cpc_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
cpc: emit code to set raster irq
Definition cpc.c:547
void cpc_screen_on(Environment *_environment)
Definition cpc.c:863
void cpc_bitmap_disable(Environment *_environment)
Definition cpc.c:739
void cpc_scancode(Environment *_environment, char *_result)
Definition cpc.c:216
void cpc_get_width(Environment *_environment, char *_result)
Definition cpc.c:959
void cpc_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition cpc.c:2590
void cpc_sprite_monocolor(Environment *_environment, char *_sprite)
Definition cpc.c:919
void cpc_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition cpc.c:911
void cpc_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition cpc.c:780
void cpc_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 cpc.c:2116
void cpc_slice_image_extract(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition cpc.c:2502
void cpc_next_raster(Environment *_environment)
cpc: emit code to wait for next raster irq
Definition cpc.c:561
void cpc_timer_set_status_on(Environment *_environment, char *_timer)
Definition cpc.c:2557
void cpc_clear_key(Environment *_environment)
Definition cpc.c:276
void cpc_get_height(Environment *_environment, char *_result)
Definition cpc.c:973
Variable * cpc_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition cpc.c:2232
void cpc_flash_begin(Environment *_environment, char *_index, char *_register)
Definition cpc.c:2861
void cpc_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition cpc.c:2612
void cpc_cls(Environment *_environment)
Definition cpc.c:980
void console_calculate_vars(Environment *_environment)
Definition cpc.c:621
void cpc_move_video_memory(Environment *_environment, char *_from, char *_to, char *_size)
Definition cpc.c:2474
void cpc_sprite_data_from(Environment *_environment, char *_sprite, char *_address)
Definition cpc.c:879
void cpc_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition cpc.c:899
void cpc_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition cpc.c:987
void cpc_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition cpc.c:895
void cpc_wait_vbl(Environment *_environment, char *_raster_line)
Definition cpc.c:2174
void cpc_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition cpc.c:927
void cpc_textmap_at(Environment *_environment, char *_address)
Definition cpc.c:776
void cpc_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition cpc.c:2634
void cpc_joy_vars(Environment *_environment, char *_port, char *_value)
Definition cpc.c:286
int cpc_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition cpc.c:629
void cpc_timer_set_status_off(Environment *_environment, char *_timer)
Definition cpc.c:2573
Variable * cpc_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 cpc.c:1910
void cpc_sprite_multicolor(Environment *_environment, char *_sprite)
Definition cpc.c:915
void cpc_dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Definition cpc.c:2657
void cpc_put_key(Environment *_environment, char *_string, char *_size)
Definition cpc.c:2832
int cpc_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition cpc.c:1314
void cpc_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition cpc.c:2810
void cpc_border_color(Environment *_environment, char *_border_color)
cpc: emit code to change border color
Definition cpc.c:405
void cpc_inkey(Environment *_environment, char *_key)
Definition cpc.c:105
void cpc_slice_image_copy(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition cpc.c:2482
void cpc_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition cpc.c:2086
void cpc_vertical_scroll(Environment *_environment, char *_displacement)
Definition cpc.c:935
void cpc_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
cpc: emit code to wait for next raster irq at different position
Definition cpc.c:578
void cpc_fade(Environment *_environment, char *_ticks)
Definition cpc.c:2845
void cpc_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition cpc.c:883
void cpc_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition cpc.c:2404
void cpc_bitmap_at(Environment *_environment, char *_address)
Definition cpc.c:768
void cpc_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition cpc.c:1268
void cpc_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
cpc: emit code to retrieve background color
Definition cpc.c:505
void cpc_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition cpc.c:1283
void cpc_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition cpc.c:1026
void cpc_sprite_enable(Environment *_environment, char *_sprite)
Definition cpc.c:887
void cpc_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition cpc.c:2759
void console_calculate(Environment *_environment)
Definition cpc.c:609
void cpc_background_color_vars(Environment *_environment, char *_index, char *_background_color)
cpc: emit code to change background color
Definition cpc.c:452
void cpc_screen_columns(Environment *_environment, char *_columns)
Definition cpc.c:875
int cpc_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition cpc.c:2543
void cpc_finalization(Environment *_environment)
Definition cpc.c:1224
void cpc_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition cpc.c:923
#define BITMAP_MODE_GRAPHIC3
Definition cpc.h:239
#define BITMAP_MODE_GRAPHIC2
Definition cpc.h:238
#define CPC_GA_MASK(mask, value)
Definition cpc.h:281
#define BITMAP_MODE_GRAPHIC1
Definition cpc.h:237
#define BITMAP_MODE_GRAPHIC0
Definition cpc.h:236
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
JoystickConfig joystickConfig
Definition ugbc.h:2437
int screenTilesHeight
Definition ugbc.h:2885
int consoleTilesHeight
Definition ugbc.h:2895
RgbConverterFunction currentRgbConverterFunction
Definition ugbc.h:2711
int fontWidth
Definition ugbc.h:2900
int bitmaskNeeded
Definition ugbc.h:2659
CopperList * copperList
Definition ugbc.h:3282
int screenColors
Definition ugbc.h:2870
int sysCallUsed
Definition ugbc.h:3162
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
KeyboardConfig keyboardConfig
Definition ugbc.h:2435
int currentTileMode
Definition ugbc.h:2706
int screenTiles
Definition ugbc.h:2875
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
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
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
int originalWidth
Definition ugbc.h:1145
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char rchack_falling_balls_1163
Definition ugbc.h:2052
char rchack_pick_the_star_1163
Definition ugbc.h:2041
char clsImplicit
Definition ugbc.h:2008
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 adilineendbitmap()
Definition ugbc.h:4241
#define WARNING_SCREEN_MODE(v1)
Definition ugbc.h:3878
struct _Variable Variable
Structure of a single variable.
#define deploy_deferred(s, e)
Definition ugbc.h:4302
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_STRING
Definition ugbc.h:474
@ 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_DSTRING
Definition ugbc.h:483
@ 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 outhead0(s)
Definition ugbc.h:4246
#define out0(s)
Definition ugbc.h:4259
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
Definition ugbc.h:1516
#define MAX_PALETTE
Definition ugbc.h:568
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
Definition ugbc.h:3688
#define outline0(s)
Definition ugbc.h:4252
#define out1(s, a)
Definition ugbc.h:4260
#define outline1(s, a)
Definition ugbc.h:4253
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define VT_BITWIDTH(t)
Definition ugbc.h:595
#define adilinebeginbitmap(s)
Definition ugbc.h:4231
struct _CopperList CopperList
#define 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