ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
zx.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", 0 },
40 { 0x00, 0x00, 0xff, 0xff, 1, "BLUE", 1 },
41 { 0x88, 0x00, 0x00, 0xff, 2, "RED", 2 },
42 { 0xff, 0x00, 0xff, 0xff, 3, "MAGENTA", 3 },
43 { 0x00, 0xff, 0x00, 0xff, 4, "GREEN", 4 },
44 { 0xaa, 0xff, 0xe6, 0xff, 5, "CYAN", 5 },
45 { 0xee, 0xee, 0x77, 0xff, 6, "YELLOW", 6 },
46 { 0xff, 0xff, 0xff, 0xff, 7, "WHITE", 7 }
47};
48
49static RGBi * commonPalette;
50static int lastUsedSlotInCommonPalette = 0;
51
52static int RowsAddress[] = {
53 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176,
54 16416, 16672, 16928, 17184, 17440, 17696, 17952, 18208,
55 16448, 16704, 16960, 17216, 17472, 17728, 17984, 18240,
56 16480, 16736, 16992, 17248, 17504, 17760, 18016, 18272,
57 16512, 16768, 17024, 17280, 17536, 17792, 18048, 18304,
58 16544, 16800, 17056, 17312, 17568, 17824, 18080, 18336,
59 16576, 16832, 17088, 17344, 17600, 17856, 18112, 18368,
60 16608, 16864, 17120, 17376, 17632, 17888, 18144, 18400,
61 18432, 18688, 18944, 19200, 19456, 19712, 19968, 20244,
62 18464, 18720, 18976, 19232, 19488, 19744, 20000, 20266,
63 18496, 18752, 19008, 19264, 19520, 19776, 20032, 20288,
64 18528, 18784, 19040, 19296, 19552, 19808, 20064, 20320,
65 18560, 18816, 19072, 19328, 19584, 19840, 20096, 20352,
66 18592, 18848, 19104, 19360, 19616, 19872, 20128, 20384,
67 18624, 18880, 19136, 19392, 19648, 19904, 20160, 20416,
68 18656, 18912, 19168, 19424, 19680, 19936, 20192, 20448,
69 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272,
70 20512, 20768, 21024, 21280, 21536, 21792, 22048, 22304,
71 20544, 20800, 21056, 21312, 21568, 21824, 22080, 22336,
72 20576, 20832, 21088, 21344, 21600, 21856, 22112, 22368,
73 20608, 20864, 21120, 21376, 21632, 21888, 22144, 22400,
74 20640, 20896, 21152, 21408, 21664, 21920, 22176, 22432,
75 20672, 20928, 21184, 21440, 21696, 21952, 22208, 22464,
76 20704, 20960, 21216, 21472, 21728, 21984, 22240, 22496
77};
78
79/****************************************************************************
80 * CODE SECTION
81 ****************************************************************************/
82
83#ifdef __zx__
84
85int zx_image_size( Environment * _environment, int _width, int _height, int _mode ) {
86
87 switch( _mode ) {
88
91 return 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) );
92
93 }
94
95 return 0;
96
97}
98
99static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
100
101 switch( _mode ) {
102
105 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) ) * _frames;
106
107 }
108
109 return 0;
110
111}
112
113static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
114
115 switch( _mode ) {
116
119 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + ( ( _width >> 3 ) * ( _height >> 3 ) ) ) * _frames ) * _sequences;
120
121 }
122
123 return 0;
124
125}
126
127void zx_color_border( Environment * _environment, char * _color ) {
128
129 char port[MAX_TEMPORARY_STORAGE]; sprintf(port, "$%2.2x", PORT_COLOR_BORDER);
130
131 cpu_port_out( _environment, port, _color );
132
133}
134
135void zx_vscroll( Environment * _environment, int _displacement, int _overlap ) {
136
137 outline1("LD A, $%2.2x", ( _displacement & 0xff ) );
138 outline1("LD IXL, $%2.2x", ( _overlap & 0xff ) );
139
140 deploy_preferred( vars,src_hw_zx_vars_asm);
141 deploy( vScroll,src_hw_zx_vscroll_asm );
142
143 outline0("CALL VSCROLL");
144
145}
146
147void zx_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
148
149 deploy_preferred( vars,src_hw_zx_vars_asm);
150 deploy( vScroll, src_hw_zx_vscroll_asm );
151 deploy( textEncodedAt, src_hw_zx_text_at_asm );
152 deploy( cls, src_hw_zx_cls_asm );
153
154 //cpu_move_8bit( _environment, _tab, "TABCOUNT");
155
156 outline1("LD A, (%s)", _text_size );
157 outline0("LD C, A");
158 outline0("LD B, 0");
159 outline1("LD HL, (%s)", _text );
160
161 if ( _raw ) {
162 deploy( textEncodedAtTextRaw, src_hw_zx_text_at_text_raw_asm );
163 outline0("CALL TEXTATRAW");
164 } else {
165 deploy( textEncodedAtText, src_hw_zx_text_at_text_asm );
166 outline0("CALL TEXTAT");
167 }
168
169}
170
171void zx_cls( Environment * _environment, char * _pen, char * _paper ) {
172
173 deploy_preferred( vars,src_hw_zx_vars_asm);
174 deploy( cls, src_hw_zx_cls_asm );
175
176 if ( _pen ) {
177 cpu_move_8bit( _environment, _pen, "_PEN");
178 }
179 if ( _paper ) {
180 cpu_move_8bit( _environment, _paper, "_PAPER");
181 }
182
183 outline0("CALL CLS");
184
185}
186
187void zx_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
188
189 deploy( clsBox, src_hw_zx_cls_box_asm );
190
191 outline1("LD A, (%s)", _x1 );
192 outline0("LD (IMAGEX), A" );
193 outline1("LD A, (%s)", _y1 );
194 outline0("LD (IMAGEY), A" );
195 outline1("LD HL, (%s)", _w);
196 outline0("LD (IMAGEW), A" );
197 outline1("LD A, (%s)", _h );
198 outline0("LD (IMAGEH), A" );
199 outline0("CALL CLSBOX");
200
201}
202
203void zx_inkey( Environment * _environment, char * _key ) {
204
205 _environment->bitmaskNeeded = 1;
206
207 deploy( keyboard, src_hw_zx_keyboard_asm);
208
209 outline0("CALL INKEY");
210 outline1("LD (%s), A", _key);
211
212}
213
214void zx_wait_key( Environment * _environment, int _release ) {
215
216 _environment->bitmaskNeeded = 1;
217
218 deploy( keyboard, src_hw_zx_keyboard_asm );
219
220 if ( _release ) {
221 outline0("CALL WAITKEYRELEASE");
222 } else {
223 outline0("CALL WAITKEY");
224 }
225
226}
227
228void zx_wait_key_or_fire( Environment * _environment, int _port, int _release ) {
229
230 zx_wait_key( _environment, _release );
231
232}
233
234void zx_wait_key_or_fire_semivar( Environment * _environment, char * _port, int _release ) {
235
236 zx_wait_key( _environment, _release );
237
238}
239
240void zx_wait_fire( Environment * _environment, int _port, int _release ) {
241
242 if ( _environment->joystickConfig.notEmulated ) {
243
244 } else {
245
246 _environment->bitmaskNeeded = 1;
247
248 deploy( keyboard, src_hw_zx_keyboard_asm );
249 deploy( joystick, src_hw_zx_joystick_asm );
250
251 outline1("LD A, $%2.2x", (unsigned char)(_release&0xff) );
252 outline0("LD B, A" );
253 if ( _port == -1 ) {
254 outline0("CALL WAITFIRE");
255 } else {
256 outline1("LD A, $%2.2x", (unsigned char)(_port&0xff) );
257 outline0("CALL WAITFIREX");
258 }
259 }
260
261}
262
263void zx_wait_fire_semivar( Environment * _environment, char * _port, int _release ) {
264
265 if ( _environment->joystickConfig.notEmulated ) {
266
267 } else {
268
269 _environment->bitmaskNeeded = 1;
270
271 deploy( keyboard, src_hw_zx_keyboard_asm );
272 deploy( joystick, src_hw_zx_joystick_asm );
273
274 if ( !_port ) {
275 outline0("CALL WAITFIRE");
276 } else {
277 outline1("LD A, (%s)", _port );
278 outline0("CALL WAITFIREX");
279 }
280 }
281
282}
283
284void zx_joystick_semivars( Environment * _environment, char * _joystick, char * _result ) {
285
286 if ( _environment->joystickConfig.notEmulated ) {
287 cpu_store_8bit( _environment, _result, 0 );
288 } else {
289
290 _environment->bitmaskNeeded = 1;
291
292 deploy( keyboard, src_hw_zx_keyboard_asm );
293 deploy( joystick, src_hw_zx_joystick_asm );
294
295 outline1("LD A, (%s)", _joystick);
296 outline0("CALL JOYSTICK");
297 outline1("LD (%s), A", _result);
298
299 }
300
301}
302
303void zx_joystick( Environment * _environment, int _joystick, char * _result ) {
304
305 if ( _environment->joystickConfig.notEmulated ) {
306 cpu_store_8bit( _environment, _result, 0 );
307 } else {
308
309 _environment->bitmaskNeeded = 1;
310
311 deploy( keyboard, src_hw_zx_keyboard_asm );
312 deploy( joystick, src_hw_zx_joystick_asm );
313
314 outline1("LD A, #$%2.2x", _joystick);
315 outline0("CALL JOYSTICK");
316 outline1("LD (%s), A", _result);
317
318 }
319
320}
321
322void zx_key_state( Environment * _environment, char *_scancode, char * _result ) {
323
324 _environment->bitmaskNeeded = 1;
325
327
328 deploy( keyboard, src_hw_zx_keyboard_asm );
329
330 outline1("LD A, (%s)", _scancode);
331 outline0("CALL KEYSTATE");
332 cpu_ctoa( _environment );
333 outline1("LD (%s), A", _result);
334
335}
336
337void zx_scancode( Environment * _environment, char * _result ) {
338
339 _environment->bitmaskNeeded = 1;
340
341 deploy( keyboard, src_hw_zx_keyboard_asm);
342
343 outline0("CALL SCANCODE");
344 outline1("LD (%s), A", _result );
345
346}
347
348void zx_asciicode( Environment * _environment, char * _result ) {
349
350 _environment->bitmaskNeeded = 1;
351
352 deploy( keyboard, src_hw_zx_keyboard_asm);
353
354 outline0("CALL ASCIICODE");
355 outline1("LD A, (%s)", _result );
356
357}
358
359void zx_key_pressed( Environment * _environment, char *_scancode, char * _result ) {
360
361 _environment->bitmaskNeeded = 1;
362
364
365 deploy( keyboard, src_hw_zx_keyboard_asm );
366
367 outline1("LD A, (%s)", _scancode);
368 outline0("CALL KEYPRESSED");
369 cpu_ctoa( _environment );
370 outline1("LD (%s), A", _result);
371
372}
373
374void zx_scanshift( Environment * _environment, char * _shifts ) {
375
376 zx_keyshift( _environment, _shifts );
377
378}
379
380void zx_keyshift( Environment * _environment, char * _shifts ) {
381
382 _environment->bitmaskNeeded = 1;
383
384 deploy( keyboard, src_hw_zx_keyboard_asm );
385
386 outline0("CALL KEYSHIFT" );
387 outline1("LD (%s), A", _shifts );
388
389}
390
391void zx_clear_key( Environment * _environment ) {
392
393 _environment->bitmaskNeeded = 1;
394
395 deploy( keyboard, src_hw_zx_keyboard_asm );
396
397 outline0("CALL CLEARKEY" );
398
399}
400
401static int rgbConverterFunction( int _red, int _green, int _blue ) {
402
403 int colorIndex = 0;
404 int j = 0;
405 unsigned int minDistance = 0xffffffff;
406
407 RGBi rgb;
408 rgb.red = _red;
409 rgb.green = _green;
410 rgb.blue = _blue;
411
412 for (j = 0; j < sizeof(SYSTEM_PALETTE)/sizeof(RGBi); ++j) {
413 int distance = rgbi_distance(&SYSTEM_PALETTE[j], &rgb);
414 if (distance < minDistance) {
415 minDistance = distance;
416 colorIndex = j;
417 }
418 }
419
420 return colorIndex;
421
422}
423
424void zx_initialization( Environment * _environment ) {
425
426 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 256);
427 variable_global( _environment, "CURRENTWIDTH" );
428 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 192 );
429 variable_global( _environment, "CURRENTHEIGHT" );
430 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
431 variable_global( _environment, "CURRENTTILES" );
432 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 32 );
433 variable_global( _environment, "CURRENTTILESWIDTH" );
434 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 24 );
435 variable_global( _environment, "CURRENTTILESHEIGHT" );
436 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
437 variable_global( _environment, "FONTWIDTH" );
438 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
439 variable_global( _environment, "FONTHEIGHT" );
440
441 SCREEN_MODE_DEFINE( BITMAP_MODE_STANDARD, 1, 192, 256, 2, 8, 8, "Standard Bitmap Mode" );
442 SCREEN_MODE_DEFINE( TILEMAP_MODE_STANDARD, 0, 32, 25, 8, 8, 8, "(emulated) Standard Character Mode" );
443
444 variable_import( _environment, "XGR", VT_POSITION, 0 );
445 variable_global( _environment, "XGR" );
446 variable_import( _environment, "YGR", VT_POSITION, 0 );
447 variable_global( _environment, "YGR" );
448 variable_import( _environment, "LINE", VT_WORD, (unsigned short)(0xffff) );
449 variable_global( _environment, "LINE" );
450 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
451 variable_global( _environment, "TABCOUNT" );
452
453 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
454 variable_global( _environment, "CLIPX1" );
455 variable_import( _environment, "CLIPX2", VT_POSITION, 255 );
456 variable_global( _environment, "CLIPX2" );
457 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
458 variable_global( _environment, "CLIPY1" );
459 variable_import( _environment, "CLIPY2", VT_POSITION, 191 );
460 variable_global( _environment, "CLIPY2" );
461
462 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
463 variable_global( _environment, "ORIGINX" );
464 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
465 variable_global( _environment, "ORIGINY" );
466
467 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
468 variable_global( _environment, "RESOLUTIONX" );
469 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
470 variable_global( _environment, "RESOLUTIONY" );
471
472 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
473 variable_global( _environment, "TABCOUNT" );
474
475 variable_import( _environment, "TILEX", VT_BYTE, 0 );
476 variable_global( _environment, "TILEX" );
477 variable_import( _environment, "TILEY", VT_BYTE, 0 );
478 variable_global( _environment, "TILEY" );
479 variable_import( _environment, "TILEX2", VT_BYTE, 0 );
480 variable_global( _environment, "TILEX2" );
481 variable_import( _environment, "TILET", VT_BYTE, 0 );
482 variable_global( _environment, "TILET" );
483 variable_import( _environment, "TILEW", VT_BYTE, 0 );
484 variable_global( _environment, "TILEW" );
485 variable_import( _environment, "TILEH", VT_BYTE, 0 );
486 variable_global( _environment, "TILEH" );
487 variable_import( _environment, "TILEW2", VT_BYTE, 0 );
488 variable_global( _environment, "TILEW2" );
489 variable_import( _environment, "TILEH2", VT_BYTE, 0 );
490 variable_global( _environment, "TILEH2" );
491 variable_import( _environment, "TILEA", VT_BYTE, 0 );
492 variable_global( _environment, "TILEA" );
493 variable_import( _environment, "TILEO", VT_WORD, 0 );
494 variable_global( _environment, "TILEO" );
495
496 variable_import( _environment, "CURRENTMODE", VT_BYTE, 0 );
497 variable_global( _environment, "CURRENTMODE" );
498 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
499 variable_global( _environment, "CURRENTTILEMODE" );
500
501 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
502 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
503
504 variable_import( _environment, "BLITIMAGEBLITTINGADDR", VT_ADDRESS, 0 );
505 variable_global( _environment, "BLITIMAGEBLITTINGADDR" );
506 variable_import( _environment, "BLITTMPPTR", VT_ADDRESS, 0 );
507 variable_global( _environment, "BLITTMPPTR" );
508 variable_import( _environment, "BLITTMPPTR2", VT_ADDRESS, 0 );
509 variable_global( _environment, "BLITTMPPTR2" );
510
511 variable_import( _environment, "TEXTADDRESS", VT_ADDRESS, 0 );
512 variable_global( _environment, "TEXTADDRESS" );
513
514 variable_import( _environment, "CONSOLESA", VT_ADDRESS, 0x0 );
515 variable_global( _environment, "CONSOLESA" );
516 variable_import( _environment, "CONSOLEHB", VT_BYTE, 192 );
517 variable_global( _environment, "CONSOLEHB" );
518 variable_import( _environment, "CONSOLEWB", VT_BYTE, 32 );
519 variable_global( _environment, "CONSOLEWB" );
520
521 _environment->currentRgbConverterFunction = rgbConverterFunction;
522
523 _environment->screenWidth = 256;
524 _environment->screenHeight = 192;
525 _environment->fontWidth = 8;
526 _environment->fontHeight = 8;
527 _environment->screenColors = COLOR_COUNT;
528 _environment->screenTilesWidth = _environment->screenWidth / _environment->fontWidth;
529 _environment->screenTilesHeight = _environment->screenHeight / _environment->fontHeight;
530 _environment->consoleTilesWidth = _environment->screenTilesWidth;
531 _environment->consoleTilesHeight = _environment->screenTilesHeight;
532 _environment->currentModeBW = 1;
533
534 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
535 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
536 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
537 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
538 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
539 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
540 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
541 cpu_store_8bit( _environment, "FONTWIDTH", _environment->fontWidth );
542 cpu_store_8bit( _environment, "FONTHEIGHT", _environment->fontHeight );
543
544 console_init( _environment );
545
546 font_descriptors_init( _environment, 1 );
547
548 if (_environment->vestigialConfig.clsImplicit ) {
549 zx_cls( _environment, NULL, NULL );
550 }
551
552}
553
554void zx_finalization( Environment * _environment ) {
555
556 if ( _environment->vestigialConfig.clsImplicit ) {
557 deploy( cls, src_hw_zx_cls_asm );
558 }
559
560 CopperList * copperList = _environment->copperList;
561 if ( copperList ) {
562 while(copperList) {
563 outhead1("COPPERACTIVATE%s:", copperList->name ? copperList->name : "" );
564 outline0("RET");
565 copperList = copperList->next;
566 }
567 }
568
569 if ( ! _environment->deployed.audio1startup ) {
570 cpu_label( _environment, "MUSICPLAYER" );
571 outline0( "RET" );
572 }
573
574}
575
576void zx_screen_rows( Environment * _environment, char * _rows ) {
577
578}
579
580void zx_screen_columns( Environment * _environment, char * _columns ) {
581
582}
583
584void console_calculate( Environment * _environment ) {
585
586 int consoleSA = RowsAddress[ ( _environment->activeConsole.y1 * 8 ) ] + ( _environment->activeConsole.x1 * _environment->currentModeBW ) ;
587 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
588 int consoleHB = _environment->activeConsole.height * 8;
589
590 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
591 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
592 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
593
594}
595
596void console_calculate_vars( Environment * _environment ) {
597
598 _environment->dynamicConsole = 1;
599
600 outline0( "CALL CONSOLECALCULATE" );
601
602}
603
604int zx_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
605 _screen_mode->selected = 1;
606
607 _environment->screenWidth = 256;
608 _environment->screenHeight = 192;
609 _environment->fontWidth = 8;
610 _environment->fontHeight = 8;
611 _environment->screenColors = 8;
612 console_init( _environment );
613 if (_environment->vestigialConfig.clsImplicit ) {
614 zx_cls( _environment, NULL, NULL );
615 }
616 console_calculate( _environment );
617
618}
619
620void zx_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
621
622 deploy_preferred( vars, src_hw_zx_vars_asm );
623
624}
625
626void zx_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
627
628}
629
630void zx_back( Environment * _environment ) {
631
632 deploy( back, src_hw_zx_back_asm );
633
634 outline0("CALL BACK");
635
636}
637
638static Variable * zx_image_converter_bitmap_mode_standard( Environment * _environment, char * _source, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _transparent_color, int _flags ) {
639
640 (void)!_transparent_color;
641
642 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 8 );
643
644 if ( _environment->freeImageWidth ) {
645 if ( _width % 8 ) {
646 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
647 }
648 if ( _frame_width % 8 ) {
649 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
650 }
651 }
652
653 if ( _environment->freeImageHeight ) {
654 if ( _height % 8 ) {
655 _height = ( ( ( _height - 1 ) / 8 ) - 1 ) * 8;
656 }
657 if ( _frame_height % 8 ) {
658 _frame_height = ( ( ( _frame_height - 1 ) / 8 ) - 1 ) * 8;
659 }
660 }
661
662 RGBi * palette = malloc_palette( MAX_PALETTE );
663
664 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
665
666 if (paletteColorCount > 16) {
667 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
668 }
669
670 int i, j, k;
671
672 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
673 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
674
675 if ( _transparent_color & 0x0f0000 ) {
676 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
677 }
678 if ( _transparent_color & 0xf00000 ) {
679 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 8 );
680 paletteColorCount = 8;
681 }
682
683 lastUsedSlotInCommonPalette = paletteColorCount;
684 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
685
686 adilinepalette( "CPMS:%ld", sizeof(SYSTEM_PALETTE) / sizeof(RGBi), SYSTEM_PALETTE );
687
688 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
690 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
691
692 int bufferSize = zx_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_STANDARD );
693 // printf("bufferSize = %d\n", bufferSize );
694
695 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_DEFAULT );
696
697 adilinebeginbitmap("BMD");
698
699 char * buffer = malloc ( bufferSize );
700 memset( buffer, 0, bufferSize );
701
702 // Position of the pixel in the original image
703 int image_x, image_y;
704
705 // Position of the pixel, in terms of tiles
706 int tile_x, tile_y;
707
708 // Position of the pixel, in terms of offset and bitmask
709 int offset, bitmask;
710
711 // Color of the pixel to convert
712 RGBi rgb;
713
714 *(buffer) = ( _frame_width & 0xff );
715 *(buffer+1) = ( _frame_width >> 8 ) & 0xff;
716 *(buffer+2) = _frame_height;
717
718 char * source = _source;
719
720 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
721
722 int colorIndexCount[ MAX_PALETTE ];
723
724 char * colorBackgroundCells = malloc( ( _frame_height >> 3 ) * ( _frame_width >> 3 ) );
725
726 memset( colorBackgroundCells, 0, ( _frame_height >> 3 ) * ( _frame_width >> 3 ) );
727
728 char * colorForegroundCells = malloc( ( _frame_height >> 3 ) * ( _frame_width >> 3 ) );
729
730 memset( colorForegroundCells, 0, ( _frame_height >> 3 ) * ( _frame_width >> 3 ) );
731
732 int colorIndex;
733
734 int xx;
735
736 int step = 0;
737
738 if ( paletteColorCount > 2 ) {
739
740 // Loop for all the source surface, in order to calculate colors.
741 // We do it in one pass only.
742 for (image_y = 0; image_y < _frame_height; image_y+=8) {
743
744 for (image_x = 0; image_x < _frame_width; image_x+=8) {
745
746 memset( colorIndexCount, 0, MAX_PALETTE * sizeof( int ) );
747
748 for( int y = 0; y<8; ++y ) {
749
750 _source = source + ( ( _offset_y * _width ) + _offset_x ) * _depth +
751 ( ( image_y * _frame_width + image_x ) * _depth ) +
752 ( ( y * _frame_width ) * _depth );
753
754 for( int x = 0; x<8; ++x ) {
755
756 // Take the color of the pixel
757 rgb.red = *_source;
758 rgb.green = *(_source + 1);
759 rgb.blue = *(_source + 2);
760 if ( _depth > 3 ) {
761 rgb.alpha = *(_source + 3);
762 } else {
763 rgb.alpha = 255;
764 }
765 if ( rgb.alpha == 0 ) {
766 rgb.red = 0;
767 rgb.green = 0;
768 rgb.blue = 0;
769 }
770
771 colorIndex = 0;
772
773 int minDistance = 9999;
774 for( int index = 0; index <8; ++index ) {
775 int distance = rgbi_distance(&SYSTEM_PALETTE[index], &rgb );
776 if ( distance < minDistance ) {
777 minDistance = distance;
778 colorIndex = SYSTEM_PALETTE[index].index;
779 }
780 }
781
782 // printf( "%2.2x%2.2x%2.2x = %d\n", rgb.red, rgb.green, rgb.blue, colorIndex );
783
784 ++colorIndexCount[colorIndex];
785
786 _source += _depth;
787
788 }
789
790 // printf( "\n" );
791
792 }
793
794 // printf( "\n---\n" );
795
796 int colorBackgroundMax = 0;
797 int colorBackground = 0;
798 int colorForegroundMax = 0;
799 int colorForeground = 0;
800
801 if ( _transparent_color & 0x0f0000 ) {
802 colorBackground = ( _transparent_color & 0xff );
803 } else {
804 for( int xx = 0; xx<16; ++xx ) {
805 if ( colorIndexCount[xx] > colorBackgroundMax ) {
806 colorBackground = xx;
807 colorBackgroundMax = colorIndexCount[xx];
808 };
809 }
810 colorIndexCount[colorBackground] = 0;
811 }
812
813 if ( _transparent_color & 0xf00000 ) {
814 colorForeground = ( _transparent_color & 0xff00 ) >> 8;
815 } else {
816 for( int xx = 0; xx<16; ++xx ) {
817 if ( colorIndexCount[xx] > colorForegroundMax ) {
818 colorForeground = xx;
819 colorForegroundMax = colorIndexCount[xx];
820 };
821 }
822 if ( colorForeground == colorBackground ) {
823 colorForeground = ( colorBackground == 0 ) ? 1 : 0;
824 }
825 colorIndexCount[colorForeground] = 0;
826 }
827
828 // printf( "cell (%d,%d) = %2.2x, %2.2x\n", image_x>>3, image_y>>3, colorForeground, colorBackground );
829
830 *(colorForegroundCells + (image_y>>3)*(_frame_width>>3) + (image_x>>3)) = colorForeground;
831 *(colorBackgroundCells + (image_y>>3)*(_frame_width>>3) + (image_x>>3)) = colorBackground;
832
833 }
834
835 // printf("\n");
836
837 }
838
839 }
840
841 // printf("\n\n");
842
843 _source = source + ( ( _offset_y * _width ) + _offset_x ) * _depth;
844
845 // Loop for all the source surface.
846 for (image_y = 0; image_y < _frame_height; ++image_y) {
847
848 for (image_x = 0; image_x < _frame_width; image_x+=8) {
849
850 for( xx = 0; xx < 8; ++xx ) {
851 // Take the color of the pixel
852 rgb.red = *_source;
853 rgb.green = *(_source + 1);
854 rgb.blue = *(_source + 2);
855 if ( _depth > 3 ) {
856 rgb.alpha = *(_source + 3);
857 } else {
858 rgb.alpha = 255;
859 }
860 if ( rgb.alpha == 0 ) {
861 rgb.red = 0;
862 rgb.green = 0;
863 rgb.blue = 0;
864 }
865
866 colorIndex = 0;
867
868 int minDistance = 9999;
869 for( int i=0; i<paletteColorCount; ++i ) {
870 int distance = rgbi_distance(&commonPalette[i], &rgb );
871 if ( distance < minDistance ) {
872 minDistance = distance;
873 colorIndex = commonPalette[i].index;
874 }
875 }
876
877 int offset = ( image_y * _frame_width>>3 ) + (image_x>>3);
878 int bitmask = 1 << ( 7 - xx );
879 int colorForeground = 0;
880 int colorBackground = 0;
881
882 if ( paletteColorCount > 2 ) {
883
884 colorForeground = *(colorForegroundCells + (image_y>>3)*(_frame_width>>3) + (image_x>>3));
885 colorBackground = *(colorBackgroundCells + (image_y>>3)*(_frame_width>>3) + (image_x>>3));
886
887 } else {
888
889 colorBackground = commonPalette[0].index;
890 colorForeground = commonPalette[1].index;
891
892 }
893
894 // printf( "> cell (%d,%d) = %2.2x, %2.2x\n", image_x>>3, image_y>>3, colorForeground, colorBackground );
895
896 if ( colorIndex != colorBackground ) {
897 adilinepixel(colorForeground);
898 *( buffer + offset + 3) |= bitmask;
899 } else {
900 adilinepixel(colorBackground);
901 *( buffer + offset + 3) &= ~bitmask;
902 }
903
904 offset = ( ( image_y >> 3 ) * _frame_width>>3 ) + (image_x>>3);
905 // printf( "%d+(%d,%d)=%d\n", 3 + ( ( _frame_width >> 3 ) * _frame_height ), image_x, image_y, offset );
906
907 *( buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) + offset ) = ( colorBackground << 3 ) | ( colorForeground );
908
909 // if ( ! *( buffer + 2 + ( ( _frame_width >> 3 ) * _frame_height ) + offset ) ) {
910 // ++step;
911 // }
912 // *( buffer + 2 + ( ( _frame_width >> 3 ) * _frame_height ) + offset ) = (step&0xff);
913
914 _source += _depth;
915
916 }
917
918 }
919
920 _source += _depth * ( _width - _frame_width );
921
922 }
923
925
926 // printf("----\n");
927
928 // printf( "buffer size = %d\n", bufferSize );
929
930 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
931
932 // printf("----\n");
933
934 return result;
935
936}
937
938Variable * zx_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 ) {
939
940 switch( _mode ) {
941
944
945 return zx_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
946
947 break;
948 }
949
951
952 return zx_new_image( _environment, 8, 8, BITMAP_MODE_STANDARD );
953
954}
955
956static void zx_load_image_address_to_other_register( Environment * _environment, char * _register, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
957
958 outline2("LD %s, %s", _register, _source );
959 if ( _sequence ) {
960
961 outline0("LD DE, $0003" );
962 outline0("ADD HL, DE" );
963 if ( strlen(_sequence) == 0 ) {
964
965 } else {
966 outline0("PUSH HL" );
967 outline1("LD A, (%s)", _sequence );
968 outline0("LD L, A" );
969 outline0("LD H, 0" );
970 outline0("ADD HL, HL" );
971 outline0("LD DE, HL" );
972 outline1("LD HL, OFFSETS%4.4x", _frame_size * _frame_count );
973 outline0("ADD HL, DE" );
974 outline0("LD A, (HL)" );
975 outline0("LD E, A" );
976 outline0("INC HL" );
977 outline0("LD A, (HL)" );
978 outline0("LD D, A" );
979 outline0("POP HL" );
980 outline0("ADD HL, DE" );
981 }
982
983 if ( _frame ) {
984 if ( strlen(_frame) == 0 ) {
985
986 } else {
987 outline0("PUSH HL" );
988 outline1("LD A, (%s)", _frame );
989 outline0("LD L, A" );
990 outline0("LD H, 0" );
991 outline0("ADD HL, HL" );
992 outline0("LD DE, HL" );
993 outline1("LD HL, OFFSETS%4.4x", _frame_size );
994 outline0("ADD HL, DE" );
995 outline0("LD A, (HL)" );
996 outline0("LD E, A" );
997 outline0("INC HL" );
998 outline0("LD A, (HL)" );
999 outline0("LD D, A" );
1000 outline0("POP HL" );
1001 outline0("ADD HL, DE" );
1002 }
1003 }
1004
1005 } else {
1006
1007 if ( _frame ) {
1008 outline0("LD DE, $0003" );
1009 outline0("ADD HL, DE" );
1010 if ( strlen(_frame) == 0 ) {
1011
1012 } else {
1013 outline0("PUSH HL" );
1014 outline1("LD A, (%s)", _frame );
1015 outline0("LD L, A" );
1016 outline0("LD H, 0" );
1017 outline0("ADD HL, HL" );
1018 outline0("LD DE, HL" );
1019 outline1("LD HL, OFFSETS%4.4x", _frame_size );
1020 outline0("ADD HL, DE" );
1021 outline0("LD A, (HL)" );
1022 outline0("LD E, A" );
1023 outline0("INC HL" );
1024 outline0("LD A, (HL)" );
1025 outline0("LD D, A" );
1026 outline0("POP HL" );
1027 outline0("ADD HL, DE" );
1028 }
1029 }
1030
1031 }
1032
1033}
1034
1035void zx_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
1036
1037 outline0("LD HL, 0" );
1038 outline1("LD (%s), HL", _offset );
1039
1040 if ( _sequence ) {
1041
1042 outline0("LD DE, $0003" );
1043 outline0("ADD HL, DE" );
1044 if ( strlen(_sequence) == 0 ) {
1045
1046 } else {
1047 outline0("PUSH HL" );
1048 outline1("LD A, (%s)", _sequence );
1049 outline0("LD L, A" );
1050 outline0("LD H, 0" );
1051 outline0("ADD HL, HL" );
1052 outline0("LD DE, HL" );
1053 outline1("LD HL, OFFSETS%4.4x", _frame_size * _frame_count );
1054 outline0("ADD HL, DE" );
1055 outline0("LD A, (HL)" );
1056 outline0("LD E, A" );
1057 outline0("INC HL" );
1058 outline0("LD A, (HL)" );
1059 outline0("LD D, A" );
1060 outline0("POP HL" );
1061 outline0("ADD HL, DE" );
1062 }
1063
1064 if ( _frame ) {
1065 if ( strlen(_frame) == 0 ) {
1066
1067 } else {
1068 outline0("PUSH HL" );
1069 outline1("LD A, (%s)", _frame );
1070 outline0("LD L, A" );
1071 outline0("LD H, 0" );
1072 outline0("ADD HL, HL" );
1073 outline0("LD DE, HL" );
1074 outline1("LD HL, OFFSETS%4.4x", _frame_size );
1075 outline0("ADD HL, DE" );
1076 outline0("LD A, (HL)" );
1077 outline0("LD E, A" );
1078 outline0("INC HL" );
1079 outline0("LD A, (HL)" );
1080 outline0("LD D, A" );
1081 outline0("POP HL" );
1082 outline0("ADD HL, DE" );
1083 }
1084 }
1085
1086 } else {
1087
1088 if ( _frame ) {
1089 outline0("LD DE, $0003" );
1090 outline0("ADD HL, DE" );
1091 if ( strlen(_frame) == 0 ) {
1092
1093 } else {
1094 outline0("PUSH HL" );
1095 outline1("LD A, (%s)", _frame );
1096 outline0("LD L, A" );
1097 outline0("LD H, 0" );
1098 outline0("ADD HL, HL" );
1099 outline0("LD DE, HL" );
1100 outline1("LD HL, OFFSETS%4.4x", _frame_size );
1101 outline0("ADD HL, DE" );
1102 outline0("LD A, (HL)" );
1103 outline0("LD E, A" );
1104 outline0("INC HL" );
1105 outline0("LD A, (HL)" );
1106 outline0("LD D, A" );
1107 outline0("POP HL" );
1108 outline0("ADD HL, DE" );
1109 }
1110 }
1111
1112 }
1113
1114}
1115
1116static void zx_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
1117
1118 if ( !_sequence && !_frame ) {
1119 if ( _source->isAddress ) {
1120 outline1("LD HL, (%s)", _source->realName );
1121 } else {
1122 outline1("LD HL, %s", _source->realName );
1123 }
1124 } else {
1125 if ( _source->isAddress ) {
1126 outline1("LD HL, (%s)", _source->realName );
1127 } else {
1128 outline1("LD HL, %s", _source->realName );
1129 }
1130
1131 if ( _sequence ) {
1132 outline0("LD DE, $0003" );
1133 outline0("ADD HL, DE" );
1134 if ( strlen(_sequence) == 0 ) {
1135
1136 } else {
1137 outline1("LD A, (%s)", _sequence );
1138 outline0("PUSH HL" );
1139 outline0("POP IX" );
1140 outline1("CALL %soffsetsequence", _source->realName );
1141 }
1142 if ( _frame ) {
1143 if ( strlen(_frame) == 0 ) {
1144
1145 } else {
1146 outline1("LD A, (%s)", _frame );
1147 outline0("PUSH HL" );
1148 outline0("POP IX" );
1149 outline1("CALL %soffsetframe", _source->realName );
1150 }
1151 }
1152
1153 } else {
1154
1155 if ( _frame ) {
1156 outline0("LD DE, $0003" );
1157 outline0("ADD HL, DE" );
1158 if ( strlen(_frame) == 0 ) {
1159
1160 } else {
1161 outline0("PUSH HL" );
1162 outline0("POP IX" );
1163 outline1("LD A, (%s)", _frame );
1164 outline1("CALL %soffsetframe", _source->realName );
1165 }
1166 }
1167
1168 }
1169
1170 }
1171 if ( _register ) {
1172 outline1("LD (%s), HL", _register );
1173 }
1174
1175}
1176
1177void zx_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
1178
1179 // currently unused
1180 (void)!_flags;
1181
1183
1184 deploy_preferred( vars,src_hw_zx_vars_asm);
1185 deploy( putimage, src_hw_zx_put_image_asm );
1186
1187 if ( _frame_size ) {
1188 zx_load_image_address_to_register( _environment, NULL, _image, _sequence, _frame, _frame_size, _frame_count );
1189 }
1190
1191 outline1("LD A, (%s)", _x );
1192 outline0("LD (IMAGEX), A" );
1193 outline1("LD A, (%s)", _y );
1194 outline0("LD (IMAGEY), A" );
1195
1196 outline0("PUSH HL" );
1197 outline1("LD HL, %s", _flags );
1198 outline0("LD A, L" );
1199 outline0("LD (IMAGEF), A" );
1200 outline0("LD A, H" );
1201 outline0("LD (IMAGET), A" );
1202 outline0("POP HL" );
1203
1204 outline0("CALL PUTIMAGE");
1205
1206}
1207
1208void zx_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 ) {
1209
1210 deploy_preferred( vars,src_hw_zx_vars_asm);
1211 deploy( blitimage, src_hw_zx_blit_image_asm );
1212
1213 if ( _source_count > 2 ) {
1215 }
1216
1218
1219 outhead1("blitimage%s:", label);
1220 if ( _source_count > 0 ) {
1221 Resource resource;
1222 resource.realName = strdup( _sources[0] );
1223 resource.type = VT_IMAGE;
1224 zx_load_image_address_to_register( _environment, NULL, &resource, _sequence, _frame, _frame_size, _frame_count );
1225 } else {
1226 outline0( "LD HL, 0" );
1227 }
1228
1229 outline0("DI");
1230 outline0("EXX");
1231 outline0("EI");
1232
1233 if ( _source_count > 1 ) {
1234 Resource resource;
1235 resource.realName = strdup( _sources[1] );
1236 resource.type = VT_IMAGE;
1237 zx_load_image_address_to_register( _environment, NULL, &resource, _sequence, _frame, _frame_size, _frame_count );
1238 } else {
1239 outline0( "LD HL, 0" );
1240 }
1241
1242 outline1("LD DE, %s", _blit );
1243
1244 outline0("DI");
1245 outline0("EXX");
1246 outline0("EI");
1247
1248 outline1("LD A, (%s)", _x );
1249 outline0("LD (IMAGEX), A" );
1250 outline1("LD A, (%s)", _y );
1251 outline0("LD (IMAGEY), A" );
1252 outline1("LD A, $%2.2x", (_flags & 0Xff) );
1253 outline0("LD (IMAGEF), A" );
1254 outline1("LD A, $%2.2x", ((_flags>>8) & 0Xff) );
1255 outline0("LD (IMAGET), A" );
1256
1257 outline0("CALL BLITIMAGE");
1258
1259}
1260
1261
1262Variable * zx_new_image( Environment * _environment, int _width, int _height, int _mode ) {
1263
1264 deploy_preferred( vars, src_hw_zx_vars_asm );
1265
1266 int size = zx_image_size( _environment, _width, _height, _mode );
1267
1268 if ( ! size ) {
1270 }
1271
1272 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
1273
1274 char * buffer = malloc ( size );
1275 memset( buffer, 0, size );
1276
1277 *(buffer) = ( _width & 0xff );
1278 *(buffer+1) = ( ( _width >> 8 ) & 0xff );
1279 *(buffer+2) = _height;
1280
1281 result->valueBuffer = buffer;
1282 result->size = size;
1283
1284 return result;
1285
1286}
1287
1288Variable * zx_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1289
1290 deploy_preferred( vars, src_hw_zx_vars_asm );
1291
1292 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
1293 int frameSize = zx_image_size( _environment, _width, _height, _mode );
1294
1295 if ( ! size ) {
1297 }
1298
1299 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
1300
1301 char * buffer = malloc ( size );
1302 memset( buffer, 0, size );
1303
1304 *(buffer) = _frames;
1305 *(buffer+1) = ( _width & 0xff );
1306 *(buffer+2) = ( _width >> 8 ) & 0xff;
1307 for( int i=0; i<_frames; ++i ) {
1308 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
1309 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
1310 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
1311 }
1312
1313 result->valueBuffer = buffer;
1314 result->frameSize = frameSize;
1315 result->size = size;
1316 result->frameCount = _frames;
1317
1318 return result;
1319
1320}
1321
1322Variable * zx_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1323
1324 deploy_preferred( vars, src_hw_zx_vars_asm );
1325
1326 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
1327 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
1328 int frameSize = zx_image_size( _environment, _width, _height, _mode );
1329
1330 if ( ! size ) {
1332 }
1333
1334 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
1335
1336 char * buffer = malloc ( size2 );
1337 memset( buffer, 0, size2 );
1338
1339 *(buffer) = _frames;
1340 *(buffer+1) = _width;
1341 *(buffer+2) = _sequences;
1342 for( int i=0; i<(_frames*_sequences); ++i ) {
1343 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
1344 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
1345 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
1346 }
1347
1348 result->valueBuffer = buffer;
1349 result->frameSize = frameSize;
1350 result->size = size;
1351 result->frameCount = _frames;
1352
1353 return result;
1354
1355}
1356
1357void zx_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
1358
1360
1361 deploy_preferred( vars,src_hw_zx_vars_asm);
1362 deploy( getimage, src_hw_zx_get_image_asm );
1363
1364 zx_load_image_address_to_other_register( _environment, "HL", _image, _sequence, _frame, _frame_size, _frame_count );
1365
1366 outline1("LD A, (%s)", _x );
1367 outline0("LD (IMAGEX), A" );
1368 outline1("LD A, (%s)", _y );
1369 outline0("LD (IMAGEY), A" );
1370 outline1("LD A, $%2.2x", _palette & 0xff );
1371 outline0("LD (IMAGET), A" );
1372
1373 outline0("CALL GETIMAGE");
1374
1375}
1376
1377void zx_scroll( Environment * _environment, int _dx, int _dy ) {
1378
1379};
1380
1381void zx_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
1382
1383 deploy_preferred( vars,src_hw_zx_vars_asm);
1384 deploy( tiles, src_hw_zx_tiles_asm );
1385
1386 outline1("LD A, (%s)", _tile );
1387 outline0("LD (TILET), A" );
1388 outline1("LD A, (%s)", _x );
1389 outline0("LD (TILEX), A" );
1390 outline1("LD A, (%s)", _y );
1391 outline0("LD (TILEY), A" );
1392 outline0("LD A, 1" );
1393 outline0("LD (TILEW), A" );
1394 outline0("LD (TILEH), A" );
1395 outline0("LD (TILEW2), A" );
1396 outline0("LD (TILEH2), A" );
1397
1398 outline0("CALL PUTTILE");
1399
1400}
1401
1402void zx_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
1403
1404 Variable * tile = variable_retrieve( _environment, _tile );
1405 Variable * x = variable_retrieve( _environment, _x );
1406 Variable * y = variable_retrieve( _environment, _y );
1407
1408 deploy_preferred( vars,src_hw_zx_vars_asm);
1409 deploy( tiles, src_hw_zx_tiles_asm );
1410
1411 int size = ( tile->originalWidth >> 3 ) * ( tile->originalHeight >> 3 );
1412
1413 if ( size ) {
1414 outline1("LD HL, OFFSETS%4.4x", size );
1415 outline0("LD A, L" );
1416 outline0("LD (TILEO), A" );
1417 outline0("LD A, H" );
1418 outline0("LD (TILEO+1), A" );
1419 } else {
1420 outline0("LD A, 0" );
1421 outline0("LD (TILEO), A" );
1422 outline0("LD (TILEO+1), A" );
1423 }
1424
1425 outline1("LD A, (%s)", tile->realName );
1426 outline0("LD (TILET), A" );
1427 outline1("LD A, (%s)", x->realName );
1428 outline0("LD (TILEX), A" );
1429 outline1("LD A, (%s)", y->realName );
1430 outline0("LD (TILEY), A" );
1431 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "1") );
1432 outline0("LD (TILEW), A" );
1433 outline0("LD (TILEW2), A" );
1434 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "2") );
1435 outline0("LD (TILEH), A" );
1436 outline0("LD (TILEH2), A" );
1437 outline1("LD A, (%s)", address_displacement(_environment, tile->realName, "3") );
1438 outline0("LD (TILEA), A" );
1439
1440 outline0("CALL MOVETILE");
1441
1442}
1443
1444void zx_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
1445
1446 deploy_preferred( vars,src_hw_zx_vars_asm);
1447 deploy( tiles, src_hw_zx_tiles_asm );
1448
1449 outline1("LD A, (%s)", _tile );
1450 outline0("LD (TILET), A" );
1451 outline1("LD A, (%s)", _x );
1452 outline0("LD (TILEX), A" );
1453 outline1("LD A, (%s)", _y );
1454 outline0("LD (TILEY), A" );
1455 outline1("LD A, (%s)", address_displacement(_environment, _tile, "1") );
1456 outline0("LD (TILEW), A" );
1457 if ( _w ) {
1458 outline1("LD A, (%s)", _w );
1459 }
1460 outline0("LD (TILEW2), A" );
1461 outline1("LD A, (%s)", address_displacement(_environment, _tile, "2") );
1462 outline0("LD (TILEH), A" );
1463 if ( _h ) {
1464 outline1("LD A, (%s)", _h );
1465 }
1466 outline0("LD (TILEH2), A" );
1467
1468 outline0("CALL PUTTILE");
1469
1470}
1471
1472void zx_tile_at( Environment * _environment, char * _x, char * _y, char * _result ) {
1473
1474 deploy_preferred( vars,src_hw_zx_vars_asm);
1475 deploy( tiles, src_hw_zx_tiles_asm );
1476
1477 outline1("LD A, (%s)", _x );
1478 outline0("LD (TILEX), A" );
1479 outline1("LD A, (%s)", _y );
1480 outline0("LD (TILEY), A" );
1481
1482 outline0("CALL TILEAT");
1483
1484 outline0("LD A, (TILET)" );
1485 outline1("LD (%s), A", _result );
1486
1487}
1488
1489void zx_use_tileset( Environment * _environment, char * _tileset ) {
1490
1491 deploy_preferred( vars,src_hw_zx_vars_asm);
1492 deploy( tiles, src_hw_zx_tiles_asm );
1493
1494 outline1("LD A, (%s)", _tileset );
1495
1496 outline0("CALL USETILESET");
1497
1498}
1499
1501
1502 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
1503
1504 variable_store( _environment, result->name, 261 );
1505
1506 return result;
1507
1508}
1509
1510void zx_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
1511
1512}
1513
1514void zx_sys_call( Environment * _environment, int _destination ) {
1515
1516 outline1("CALL $%4.4x", _destination );
1517
1518}
1519
1520int zx_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
1521
1522 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1523
1524 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
1525
1526 int uniquePaletteCount = 0;
1527
1528 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
1529
1530 return uniquePaletteCount;
1531
1532}
1533
1534void zx_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
1535
1536 deploy_preferred( vars,src_hw_zx_vars_asm);
1537 deploy( textHScrollScreen, src_hw_zx_hscroll_screen_asm );
1538 deploy( textHScrollLine, src_hw_zx_hscroll_line_asm );
1539
1540 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1541 outline1("LD A, (%s)", y->realName );
1542 outline0("LD B, A");
1543 outline1("LD A, 0x%2.2x", (unsigned char)(_direction));
1544 outline1("LD IYL, 0x%2.2x", (unsigned char)(_overlap));
1545 outline0("CALL HSCROLLLINE");
1546
1547}
1548
1549void zx_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
1550
1551 deploy_preferred( vars,src_hw_zx_vars_asm);
1552 deploy( textHScrollScreen, src_hw_zx_hscroll_screen_asm );
1553
1554 outline1("LD A, 0x%2.2x", (unsigned char)(_direction));
1555 outline1("LD IYL, 0x%2.2x", (unsigned char)(_overlap));
1556 outline0("CALL HSCROLLSCREEN");
1557
1558}
1559
1560void zx_timer_set_status_on( Environment * _environment, char * _timer ) {
1561
1562 deploy( timer, src_hw_z80_timer_asm);
1563
1564 if ( _timer ) {
1565 outline1("LD A, (%s)", _timer );
1566 outline0("LD B, A" );
1567 } else {
1568 outline0("LD B, 0" );
1569 }
1570 outline0("LD A, 1" );
1571 outline0("LD C, A" );
1572 outline0("CALL TIMERSETSTATUS" );
1573
1574}
1575
1576void zx_timer_set_status_off( Environment * _environment, char * _timer ) {
1577
1578 deploy( timer, src_hw_z80_timer_asm);
1579
1580 if ( _timer ) {
1581 outline1("LD A, (%s)", _timer );
1582 outline0("LD B, A" );
1583 } else {
1584 outline0("LD B, 0" );
1585 }
1586 outline0("LD A, 0" );
1587 outline0("LD C, A" );
1588 outline0("CALL TIMERSETSTATUS" );
1589
1590
1591}
1592
1593void zx_timer_set_counter( Environment * _environment, char * _timer, char * _counter ) {
1594
1595 deploy( timer, src_hw_z80_timer_asm);
1596
1597 if ( _counter ) {
1598 outline1("LD A, (%s)", _counter );
1599 outline0("LD IXL, A" );
1600 outline1("LD A, (%s)", address_displacement( _environment, _counter, "1" ) );
1601 outline0("LD IXH, A" );
1602 } else {
1603 outline0("LD IX, 0" );
1604 }
1605 if ( _timer ) {
1606 outline1("LD A, (%s)", _timer );
1607 outline0("LD B, A" );
1608 } else {
1609 outline0("LD B, 0" );
1610 }
1611 outline0("CALL TIMERSETCOUNTER" );
1612
1613}
1614
1615void zx_timer_set_init( Environment * _environment, char * _timer, char * _init ) {
1616
1617 deploy( timer, src_hw_z80_timer_asm);
1618
1619 if ( _init ) {
1620 outline1("LD A, (%s)", _init );
1621 outline0("LD IXL, A" );
1622 outline1("LD A, (%s)", address_displacement( _environment, _init, "1" ) );
1623 outline0("LD IXH, A" );
1624 } else {
1625 outline0("LD IX, 0" );
1626 }
1627 if ( _timer ) {
1628 outline1("LD A, (%s)", _timer );
1629 outline0("LD B, A" );
1630 } else {
1631 outline0("LD B, 0" );
1632 }
1633 outline0("CALL TIMERSETINIT" );
1634
1635}
1636
1637void zx_timer_set_address( Environment * _environment, char * _timer, char * _address ) {
1638
1639 deploy( timer, src_hw_z80_timer_asm);
1640
1641 if ( _address ) {
1642 outline1("LD HL, %s", _address );
1643 outline0("LD A, L" );
1644 outline0("LD IXL, A" );
1645 outline0("LD A, H" );
1646 outline0("LD IXH, A" );
1647 } else {
1648 outline0("LD IX, 0" );
1649 }
1650 if ( _timer ) {
1651 outline1("LD A, (%s)", _timer );
1652 outline0("LD B, A" );
1653 } else {
1654 outline0("LD B, 0" );
1655 }
1656 outline0("CALL TIMERSETADDRESS" );
1657
1658}
1659
1660void zx_put_key( Environment * _environment, char *_string, char * _size ) {
1661
1662 _environment->bitmaskNeeded = 1;
1663
1664 deploy( keyboard, src_hw_zx_keyboard_asm);
1665
1666 outline1("LD HL, (%s)", _string );
1667 outline1("LD A, (%s)", _size );
1668 outline0("CALL PUTKEY" );
1669
1670}
1671
1672void zx_wait_vbl( Environment * _environment, char * _raster_line ) {
1673
1674 deploy_preferred( vars, src_hw_zx_vars_asm );
1675 deploy( vbl, src_hw_zx_vbl_asm);
1676
1677 if ( ! _raster_line ) {
1678 outline0("LD HL, 15624");
1679 outline0("CALL WAITVBL");
1680 } else {
1681 Variable * raster_line = variable_retrieve_or_define( _environment, _raster_line, VT_BYTE, 192 );
1682 outline1("LD A, (%s)", raster_line->realName);
1683 outline0("SLA A" );
1684 outline0("SLA A" );
1685 outline0("SLA A" );
1686 outline0("SLA A" );
1687 outline0("SLA A" );
1688 outline0("SLA A" );
1689 outline0("LD L, A" );
1690 outline0("LD H, 0" );
1691 outline0("CALL WAITVBL");
1692 }
1693
1694}
1695
1696static unsigned int SOUND_FREQUENCIES[] = {
1697 0x6868, 0x628d, 0x5d03, 0x57bf, 0x52d7, 0x4e2b, 0x49cc, 0x45a3, 0x41b6, 0x3e06, 0x3a87, 0x373e,
1698 0x3425, 0x3134, 0x2e6f, 0x2bd3, 0x295c, 0x2708, 0x24d5, 0x22c2, 0x20cd, 0x1ef4, 0x1d36, 0x1b90,
1699 0x1a02, 0x188b, 0x1728, 0x15da, 0x149e, 0x1374, 0x125b, 0x1152, 0x1058, 0x0f6b, 0x0e9d, 0x0db8,
1700 0x0cf2, 0x0c36, 0x0b86, 0x0add, 0x0a40, 0x09ab, 0x091e, 0x089a, 0x081c, 0x07a6, 0x0736, 0x06cd,
1701 0x066a, 0x060c, 0x05b3, 0x0560, 0x0511, 0x04c6, 0x0480, 0x043d, 0x03ff, 0x03c4, 0x038c, 0x0357,
1702 0x0325, 0x02f7, 0x02ca, 0x02a0, 0x0279, 0x0254, 0x0231, 0x020f, 0x01f0, 0x01d3, 0x01b7, 0x019c,
1703 0x0183, 0x016c, 0x0156, 0x0141, 0x012d, 0x011b, 0x0109, 0x00f8, 0x00e9, 0x00da, 0x00cc, 0x00bf,
1704 0x00b2, 0x00a7, 0x009c, 0x0091, 0x0087, 0x007e, 0x0075, 0x006d, 0x0065, 0x005e, 0x0057, 0x0050,
1705 0x004a, 0x0044, 0x003e, 0x0039, 0x0034, 0x0030, 0x002b, 0x0027, 0x0023, 0x0020, 0x001c, 0x0019
1706};
1707
1708static unsigned int SOUND_DURATIONS[] = {
1709 0x0010 / 0x20, 0x0011 / 0x20, 0x0012 / 0x20, 0x0013 / 0x20, 0x0014 / 0x20, 0x0015 / 0x20, 0x0017 / 0x20, 0x0018 / 0x20, 0x0019 / 0x20, 0x001b / 0x20, 0x001d / 0x20, 0x001e / 0x20,
1710 0x0020 / 0x20, 0x0022 / 0x20, 0x0024 / 0x20, 0x0026 / 0x20, 0x0029 / 0x20, 0x002b / 0x20, 0x002e / 0x20, 0x0031 / 0x20, 0x0033 / 0x20, 0x0037 / 0x20, 0x003a / 0x20, 0x003d / 0x20,
1711 0x0041 / 0x20, 0x0045 / 0x20, 0x0049 / 0x20, 0x004d / 0x20, 0x0052 / 0x20, 0x0057 / 0x20, 0x005c / 0x20, 0x0062 / 0x20, 0x0067 / 0x20, 0x006e / 0x20, 0x0074 / 0x20, 0x007b / 0x20,
1712 0x0082 / 0x20, 0x008a / 0x20, 0x0092 / 0x20, 0x009b / 0x20, 0x00a4 / 0x20, 0x00ae / 0x20, 0x00b9 / 0x20, 0x00c4 / 0x20, 0x00cf / 0x20, 0x00dc / 0x20, 0x00e9 / 0x20, 0x00f6 / 0x20,
1713 0x0105 / 0x20, 0x0115 / 0x20, 0x0125 / 0x20, 0x0137 / 0x20, 0x0149 / 0x20, 0x015d / 0x20, 0x0172 / 0x20, 0x0188 / 0x20, 0x019f / 0x20, 0x01b8 / 0x20, 0x01d2 / 0x20, 0x01ed / 0x20,
1714 0x020b / 0x20, 0x022a / 0x20, 0x024b / 0x20, 0x026e / 0x20, 0x0293 / 0x20, 0x02ba / 0x20, 0x02e4 / 0x20, 0x0310 / 0x20, 0x033e / 0x20, 0x0370 / 0x20, 0x03a4 / 0x20, 0x03db / 0x20,
1715 0x0417 / 0x20, 0x0455 / 0x20, 0x0497 / 0x20, 0x04dd / 0x20, 0x0527 / 0x20, 0x0575 / 0x20, 0x05c8 / 0x20, 0x0620 / 0x20, 0x067d / 0x20, 0x06e0 / 0x20, 0x0749 / 0x20, 0x07b8 / 0x20,
1716 0x082d / 0x20, 0x08a9 / 0x20, 0x092d / 0x20, 0x09b9 / 0x20, 0x0a4d / 0x20, 0x0aea / 0x20, 0x0b90 / 0x20, 0x0c40 / 0x20, 0x0cfa / 0x20, 0x0dc0 / 0x20, 0x0e91 / 0x20, 0x0f6f / 0x20,
1717 0x105a / 0x20, 0x1153 / 0x20, 0x125b / 0x20, 0x1372 / 0x20, 0x149a / 0x20, 0x15d4 / 0x20, 0x1720 / 0x20, 0x1880 / 0x20, 0x19f5 / 0x20, 0x1b80 / 0x20, 0x1d23 / 0x20, 0x1ede / 0x20
1718};
1719
1720void zx_set_pitch( Environment * _environment, int _channels, int _pitch, int _duration ) {
1721
1722 deploy( audio1startup, src_hw_zx_audio1_asm );
1723
1724 outline1("LD HL, $%4.4x", (unsigned short)(_pitch&0xffff) );
1725 outline1("LD DE, $%4.4x", (unsigned short)(_duration&0xffff) );
1726 outline0("CALL $03b5");
1727
1728}
1729
1730void zx_set_note( Environment * _environment, int _channels, int _note, int _duration ) {
1731
1732 zx_set_pitch( _environment, _channels, SOUND_FREQUENCIES[_note], SOUND_DURATIONS[_note] * ( _duration / 32 ) );
1733
1734}
1735
1736void zx_set_pitch_vars( Environment * _environment, char * _channels, char * _pitch, char * _duration ) {
1737
1738 deploy( audio1startup, src_hw_zx_audio1_asm );
1739
1740 outline1("LD A, (%s)", _pitch );
1741 outline0("LD L, A" );
1742 outline1("LD A, (%s)", address_displacement(_environment, _pitch, "1") );
1743 outline0("LD H, A" );
1744 if ( _duration ) {
1745 outline1("LD A, (%s)", _duration );
1746 outline0("LD E, A" );
1747 outline1("LD A, (%s)", address_displacement(_environment, _duration, "1") );
1748 outline0("LD D, A" );
1749 } else {
1750 outline0("LD DE, 1000");
1751 }
1752 outline0("CALL $03b5" );
1753
1754}
1755
1756void zx_set_note_vars( Environment * _environment, char * _channels, char * _note, char * _duration ) {
1757
1758 deploy( audio1startup, src_hw_zx_audio1_asm );
1759
1760 outline1("LD A, (%s)", _note);
1761 if ( _duration ) {
1762 outline1("LD DE, (%s)", _duration);
1763 } else {
1764 outline0("LD DE, 1000");
1765 }
1766 outline0("CALL ZXAUDIO1NOTE" );
1767
1768}
1769
1770#endif
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_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
int lastUsedSlotInCommonPalette
Definition 6847.c:100
#define COLOR_COUNT
Definition 6847.h:72
#define BITMAP_MODE_DEFAULT
Definition 6847.h:95
#define BITMAP_MODE_STANDARD
Definition 6847.h:96
void cpu_port_out(Environment *_environment, char *_port, char *_value)
Z80: emit code to send one byte throught a I/O port
Definition 8086.c:2979
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
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)
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".
void image_converter_asserts(Environment *_environment, int _width, int _height, int _offset_x, int _offset_y, int *_frame_width, int *_frame_height, int _modulo_x, int _modulo_y)
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Variable * variable_store_buffer(Environment *_environment, char *_destination, unsigned char *_buffer, int _size, int _at)
int size
Definition _optimizer.c:678
int offset
Definition _optimizer.c:681
void back(Environment *_environment, char *_color)
Emit ASM code to fill background color.
Definition back.c:53
void cls(Environment *_environment, char *_paper)
Emit code for CLS.
Definition cls.c:48
#define TILEMAP_MODE_STANDARD
Definition cga.h:80
void console_init(Environment *_environment)
Definition console.c:41
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
int 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 audio1startup
Definition ugbc.h:1837
int screenTilesWidth
Definition ugbc.h:2880
int fontHeight
Definition ugbc.h:2905
Console activeConsole
Definition ugbc.h:2910
int freeImageWidth
Definition ugbc.h:3088
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 dynamicConsole
Definition ugbc.h:3298
int currentModeBW
Definition ugbc.h:2701
int screenHeight
Definition ugbc.h:2860
int consoleTilesWidth
Definition ugbc.h:2890
int screenTiles
Definition ugbc.h:2875
int freeImageHeight
Definition ugbc.h:3086
int screenWidth
Definition ugbc.h:2855
Deployed deployed
Definition ugbc.h:2921
VestigialConfig vestigialConfig
Definition ugbc.h:2442
int notEmulated
Definition ugbc.h:1998
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
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
int originalWidth
Definition ugbc.h:1145
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
void * malloc(YYSIZE_T)
struct _ScreenMode ScreenMode
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
Definition ugbc.h:3502
struct _Resource Resource
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define adilineendbitmap()
Definition ugbc.h:4241
struct _Variable Variable
Structure of a single variable.
#define outline2(s, a, b)
Definition ugbc.h:4254
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_SBYTE
Definition ugbc.h:452
@ VT_IMAGES
Definition ugbc.h:495
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define adiline3(s, a, b, c)
Definition ugbc.h:4197
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
Definition ugbc.h:1516
#define MAX_PALETTE
Definition ugbc.h:568
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
Definition ugbc.h:3688
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
Definition ugbc.h:3880
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define adilinebeginbitmap(s)
Definition ugbc.h:4231
struct _CopperList CopperList
#define FLAG_EXACT
Definition ugbc.h:4569
#define adilinepixel(p)
Definition ugbc.h:4236
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)
Definition ugbc.h:3540
#define CRITICAL_BLIT_TOO_MUCH_SOURCES()
Definition ugbc.h:3613
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247
void zx_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition zx.c:1510
void zx_keyshift(Environment *_environment, char *_shifts)
Definition zx.c:380
Variable * zx_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition zx.c:1288
void zx_initialization(Environment *_environment)
Definition zx.c:424
void zx_cls(Environment *_environment, char *_pen, char *_paper)
Definition zx.c:171
void zx_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition zx.c:1637
void zx_set_pitch_vars(Environment *_environment, char *_channels, char *_pitch, char *_duration)
Definition zx.c:1736
void zx_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition zx.c:1615
void zx_clear_key(Environment *_environment)
Definition zx.c:391
void zx_wait_fire_semivar(Environment *_environment, char *_port, int _release)
Definition zx.c:263
void zx_screen_rows(Environment *_environment, char *_rows)
Definition zx.c:576
void zx_joystick_semivars(Environment *_environment, char *_joystick, char *_result)
Definition zx.c:284
Variable * zx_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition zx.c:1322
void zx_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition zx.c:1402
void zx_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition zx.c:620
int zx_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition zx.c:604
void zx_asciicode(Environment *_environment, char *_result)
Definition zx.c:348
void zx_timer_set_status_off(Environment *_environment, char *_timer)
Definition zx.c:1576
void zx_wait_key_or_fire(Environment *_environment, int _port, int _release)
Definition zx.c:228
void zx_screen_columns(Environment *_environment, char *_columns)
Definition zx.c:580
void zx_joystick(Environment *_environment, int _joystick, char *_result)
Definition zx.c:303
void zx_set_note(Environment *_environment, int _channels, int _note, int _duration)
Definition zx.c:1730
void zx_sys_call(Environment *_environment, int _destination)
Definition zx.c:1514
void zx_back(Environment *_environment)
Definition zx.c:630
void zx_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition zx.c:1444
void zx_set_pitch(Environment *_environment, int _channels, int _pitch, int _duration)
Definition zx.c:1720
void zx_scanshift(Environment *_environment, char *_shifts)
Definition zx.c:374
void zx_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition zx.c:1534
void zx_set_note_vars(Environment *_environment, char *_channels, char *_note, char *_duration)
Definition zx.c:1756
Variable * zx_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition zx.c:1262
void zx_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition zx.c:626
Variable * zx_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 zx.c:938
void console_calculate_vars(Environment *_environment)
Definition zx.c:596
int zx_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition zx.c:1520
void zx_inkey(Environment *_environment, char *_key)
Definition zx.c:203
void zx_use_tileset(Environment *_environment, char *_tileset)
Definition zx.c:1489
void zx_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition zx.c:147
void zx_put_key(Environment *_environment, char *_string, char *_size)
Definition zx.c:1660
void zx_vscroll(Environment *_environment, int _displacement, int _overlap)
Definition zx.c:135
void zx_timer_set_status_on(Environment *_environment, char *_timer)
Definition zx.c:1560
void zx_key_pressed(Environment *_environment, char *_scancode, char *_result)
Definition zx.c:359
void zx_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition zx.c:1381
void zx_finalization(Environment *_environment)
Definition zx.c:554
void zx_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition zx.c:1472
void zx_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition zx.c:1357
void zx_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 zx.c:1208
void zx_color_border(Environment *_environment, char *_color)
Definition zx.c:127
void zx_wait_key(Environment *_environment, int _release)
Definition zx.c:214
void zx_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition zx.c:1035
void zx_scancode(Environment *_environment, char *_result)
Definition zx.c:337
void zx_wait_vbl(Environment *_environment, char *_raster_line)
Definition zx.c:1672
void zx_wait_fire(Environment *_environment, int _port, int _release)
Definition zx.c:240
void zx_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition zx.c:1549
int zx_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition zx.c:85
Variable * zx_get_raster_line(Environment *_environment)
Definition zx.c:1500
void zx_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition zx.c:187
void zx_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition zx.c:1593
void zx_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition zx.c:1177
void zx_key_state(Environment *_environment, char *_scancode, char *_result)
Definition zx.c:322
void zx_wait_key_or_fire_semivar(Environment *_environment, char *_port, int _release)
Definition zx.c:234
void zx_scroll(Environment *_environment, int _dx, int _dy)
Definition zx.c:1377
void console_calculate(Environment *_environment)
Definition zx.c:584
#define PORT_COLOR_BORDER
Definition zx.h:72