ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
6847.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSì COM'è", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#if defined(__d32__) || defined(__d64__) || defined(__coco__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40static RGBi SYSTEM_PALETTE_ALTERNATE[][4] = {
41 {
42 { 0x00, 0xcc, 0x55, 0xff, 0, "GREEN" },
43 { 0xee, 0xee, 0x77, 0xff, 1, "YELLOW" },
44 { 0x00, 0x00, 0xaa, 0xff, 2, "BLUE" },
45 { 0x88, 0x00, 0x00, 0xff, 3, "RED" }
46 },
47 {
48 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK" },
49 { 0xf0, 0xf0, 0xf0, 0xff, 5, "BUFF" },
50 { 0xaa, 0xff, 0xe6, 0xff, 6, "CYAN" },
51 { 0xcc, 0x44, 0xcc, 0xff, 7, "MAGENTA" } //,
52 // { 0xa1, 0x68, 0x3c, 0xff, 8, "ORANGE" }
53 }
54};
55
56static RGBi SYSTEM_PALETTE_SG4[9] =
57 // SEMIGRAPHICS 4
58 {
59 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK" },
60 { 0x00, 0xff, 0x00, 0xff, 1, "GREEN" },
61 { 0xff, 0xff, 0x00, 0xff, 2, "YELLOW" },
62 { 0x00, 0x00, 0xff, 0xff, 3, "BLUE" },
63 { 0xff, 0x00, 0x00, 0xff, 4, "RED" },
64 { 0xff, 0xff, 0xff, 0xff, 5, "BUFF" },
65 { 0x00, 0xff, 0xff, 0xff, 6, "CYAN" },
66 { 0xff, 0x00, 0xff, 0xff, 7, "MAGENTA" },
67 { 0xff, 0x80, 0x00, 0xff, 8, "ORANGE" }
68 }
69;
70
71static RGBi SYSTEM_PALETTE_SG6[4] =
72 // SEMIGRAPHICS 4
73 {
74 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK" },
75 { 0x00, 0x00, 0x00, 0xff, 1, "UNUSED" },
76 { 0x00, 0x00, 0xff, 0xff, 2, "BLUE" },
77 { 0xff, 0x00, 0x00, 0xff, 3, "RED" }
78 }
79;
80
81static RGBi SYSTEM_PALETTE_SG8[9] =
82 // SEMIGRAPHICS 8
83 {
84 { 0x00, 0x00, 0x00, 0xff, 0, "BLACK" },
85 { 0x00, 0xff, 0x00, 0xff, 1, "GREEN" },
86 { 0xff, 0xff, 0x00, 0xff, 2, "YELLOW" },
87 { 0x00, 0x00, 0xff, 0xff, 3, "BLUE" },
88 { 0xff, 0x00, 0x00, 0xff, 4, "RED" },
89 { 0xff, 0xff, 0xff, 0xff, 5, "BUFF" },
90 { 0x00, 0xff, 0xff, 0xff, 6, "CYAN" },
91 { 0xff, 0x00, 0xff, 0xff, 7, "MAGENTA" },
92 { 0xff, 0x80, 0x00, 0xff, 8, "ORANGE" }
93 }
94;
95
96
97static RGBi * SYSTEM_PALETTE = &SYSTEM_PALETTE_ALTERNATE[0][0];
98
99static RGBi * commonPalette;
101
102/****************************************************************************
103 * CODE SECTION
104 ****************************************************************************/
105
117void c6847_collision( Environment * _environment, char * _sprite_mask, char * _result ) {
118
119}
120
132void c6847_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
133
134}
135
145void c6847_border_color( Environment * _environment, char * _border_color ) {
146
148
149 outline1( "LDA %s", _border_color );
150 outline0( "CMPA 4" );
151 outline1( "BCs %scss0", label );
152 outhead1( "%scss1", label );
153 CSS_SET;
154 outline1( "JMP %sdone", label );
155 outhead1( "%scss0", label );
156 CSS_CLR;
157 outhead1( "%sdone", label );
158
159}
160
171void c6847_background_color( Environment * _environment, char * _index, char * _background_color ) {
172
174
175 (void) _index;
176
177 outline1( "LDA %s", _background_color );
178 outline0( "CMPA 4" );
179 outline1( "BCs %scss0", label );
180 outhead1( "%scss1", label );
181 CSS_SET;
182 outline1( "JMP %sdone", label );
183 outhead1( "%scss0", label );
184 CSS_CLR;
185 outhead1( "%sdone", label );
186
187}
188
199void c6847_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
200
201}
202
218void c6847_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
219
220}
221
232void c6847_next_raster( Environment * _environment ) {
233
234}
235
249void c6847_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
250
251}
252
253void c6847_bank_select( Environment * _environment, int _bank ) {
254
255}
256
257#define SET_VIDEOAT_ZERO SAM_F0_CLR; SAM_F1_CLR; SAM_F2_CLR; SAM_F3_CLR; SAM_F4_CLR; SAM_F5_CLR; SAM_F6_CLR;
258
259#define SET_VIDEOAT_0400 SET_VIDEOAT_ZERO; SAM_F1_SET;
260#define SET_VIDEOAT_1C00 SET_VIDEOAT_ZERO; SAM_F2_SET; SAM_F3_SET; SAM_F4_SET;
261
262void console_calculate( Environment * _environment ) {
263
264 int consoleSA = 0x0c00;
265 int consoleWB = _environment->activeConsole.width;
266 int consoleHB = _environment->activeConsole.height * 8;
267
268 switch( _environment->currentMode ) {
269 case TILEMAP_MODE_INTERNAL: // Alphanumeric Internal 32 × 16 2 512
270 case TILEMAP_MODE_EXTERNAL: // Alphanumeric External 32 × 16 2 512
271 case TILEMAP_MODE_SEMIGRAPHICS4: // Semigraphics 4 64 × 32 8 512
272 case TILEMAP_MODE_SEMIGRAPHICS6: // Semigraphics 6 64 × 48 4 512
273 case TILEMAP_MODE_SEMIGRAPHICS8: // Semigraphics 8 64 × 64 2 512
274 case TILEMAP_MODE_SEMIGRAPHICS12: // Semigraphics 6 64 × 96 1 3072
275 case TILEMAP_MODE_SEMIGRAPHICS24: // Semigraphics 6 64 × 96 1 3072
276 break;
277 case BITMAP_MODE_COLOR1: // Color Graphics 1 64 × 64 4 1024
278 consoleSA += ( _environment->activeConsole.y1 << 7 ) + ( _environment->activeConsole.x1 << 1 );
279 consoleWB = _environment->activeConsole.width * 2;
280 break;
281 case BITMAP_MODE_RESOLUTION1: // Resolution Graphics 1 128 × 64 1 + Black 1024
282 consoleSA += ( _environment->activeConsole.y1 << 7 ) + ( _environment->activeConsole.x1 << 2 );
283 break;
284 case BITMAP_MODE_COLOR2: // Color Graphics 2 128 × 64 4 2048
285 consoleSA += ( _environment->activeConsole.y1 << 8 ) + ( _environment->activeConsole.x1 << 1 );
286 consoleWB = _environment->activeConsole.width * 2;
287 break;
288 case BITMAP_MODE_RESOLUTION2: // Resolution Graphics 2 128 × 96 1 + Black 1536
289 consoleSA += ( _environment->activeConsole.y1 << 7 ) + ( _environment->activeConsole.x1 << 1 );
290 break;
291 case BITMAP_MODE_COLOR3: // Color Graphics 3 128 × 96 4 3072
292 consoleSA += ( _environment->activeConsole.y1 << 8 ) + ( _environment->activeConsole.x1 << 1 );
293 consoleWB = _environment->activeConsole.width * 2;
294 break;
295 case BITMAP_MODE_RESOLUTION3: // Resolution Graphics 3 128 × 192 1 + Black 3072
296 consoleSA += ( _environment->activeConsole.y1 << 7 ) + ( _environment->activeConsole.x1 << 2 );
297 break;
298 case BITMAP_MODE_COLOR6: // Color Graphics 6 128 × 192 4 6144
299 consoleSA += ( _environment->activeConsole.y1 << 8 ) + ( _environment->activeConsole.x1 << 1 );
300 consoleWB = _environment->activeConsole.width * 2;
301 break;
302 case BITMAP_MODE_RESOLUTION6: // Resolution Graphics 6 256 × 192 1 + Black 6144 break;
303 consoleSA += ( _environment->activeConsole.y1 << 8 ) + ( _environment->activeConsole.x1 );
304 consoleWB = _environment->activeConsole.width * 2;
305 break;
306 default:
308 }
309
310 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
311 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
312 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
313
314}
315
316void console_calculate_vars( Environment * _environment ) {
317
318 _environment->dynamicConsole = 1;
319
320 outline0( "JSR CONSOLECALCULATE" );
321
322}
323
324
325int c6847_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
326
327 _screen_mode->selected = 1;
328
329 deploy_preferred( c6847vars, src_hw_6847_vars_asm );
330
331 _environment->fontWidth = 8;
332 _environment->fontHeight = 8;
333 _environment->screenShades = 4;
334 _environment->screenTiles = 128;
335 switch( _screen_mode->id ) {
336 // ALPHANUMERIC DISPLAY MODES – All alphanumeric modes occupy an 8 x 12
337 // dot character matrix box and there are 32 x 16 character boxes per TV frame.
338 // Each horizontal dot (dot-clock) corresponds to one half the period duration of
339 // the 3.58 MHz clock and each vertical dot is one scan line. One of two colors
340 // for the lighted dots may be selected by the color set select pin (pin 39).
341 // An internal ROM will generate 64 ASCII display characters in a standard 5 x 7 box.
342 // Six bits of the eight-bit data word are used for the ASCII character generator
343 // and the two bits not used are used to implement inverse video and mode
344 // switching to semigraphics – 4, – 8, – 12, or – 24.
345 case TILEMAP_MODE_INTERNAL: // Alphanumeric Internal 32 × 16 2 512
346 _environment->screenWidth = 32*8;
347 _environment->screenHeight = 16*12;
348 _environment->screenTilesWidth = 32;
349 _environment->screenTilesHeight = 16;
350 _environment->screenColors = 4;
351 // Internal alphanumeric 0 X X 0 0 0 0 32x16 ( 5x7 pixel ch)
353 VDG_TEXT;
357 GM2_CLR;
358 GM1_CLR;
359 GM0_CLR;
360 cpu_store_16bit( _environment, "CLIPX1", 0 );
361 cpu_store_16bit( _environment, "CLIPX2", 31 );
362 cpu_store_16bit( _environment, "CLIPY1", 0 );
363 cpu_store_16bit( _environment, "CLIPY2", 15 );
364 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 32*16 );
365 break;
366 case TILEMAP_MODE_EXTERNAL: // Alphanumeric External 32 × 16 2 512
367 _environment->screenWidth = 32*8;
368 _environment->screenHeight = 16*12;
369 _environment->screenTilesWidth = 32;
370 _environment->screenTilesHeight = 16;
371 _environment->screenColors = 4;
372 // External alphanumeric 0 X X 1 0 0 0 32x16 (8x12 pixel ch)
374 VDG_TEXT;
378 GM2_CLR;
379 GM1_CLR;
380 GM0_SET;
381 cpu_store_16bit( _environment, "CLIPX1", 0 );
382 cpu_store_16bit( _environment, "CLIPX2", 31 );
383 cpu_store_16bit( _environment, "CLIPY1", 0 );
384 cpu_store_16bit( _environment, "CLIPY2", 15 );
385 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 32*16 );
386 break;
387 // The ALPHA SEMIGRAPHICS – 4 mode translates bits 0 through 3 into a 4 x 6 dot
388 // element in the standard 8 x 12 dot box. Three data bits may be used to select
389 // one of eight colors for the entire character box. The extra bit is used to
390 // switch to alphanumeric. A 512 byte display memory is required. A density of
391 // 64 x 32 elements is available in the display area. The element area is four
392 // dot-clocks wide by six lines high.
393 case TILEMAP_MODE_SEMIGRAPHICS4: // Semigraphics 4 64 × 32 8 512
394 _environment->screenWidth = 64;
395 _environment->screenHeight = 32;
396 _environment->screenTilesWidth = 32;
397 _environment->screenTilesHeight = 16;
398 _environment->screenColors = 4;
399 // Semigraphic-4 0 X X 0 0 0 0 32x16 ch, 64x32 pixels
401 VDG_TEXT;
405 GM2_CLR;
406 GM1_CLR;
407 GM0_CLR;
408 cpu_store_16bit( _environment, "CLIPX1", 0 );
409 cpu_store_16bit( _environment, "CLIPX2", 63 );
410 cpu_store_16bit( _environment, "CLIPY1", 0 );
411 cpu_store_16bit( _environment, "CLIPY2", 31 );
412 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 512 );
413 cpu_store_8bit( _environment, "CURRENTSL", 32 );
414 break;
415 // The ALPHA SEMIGRAPHICS – 6 mode maps six 4 x 4 dot elements into the standard
416 // 8 x 12 dot alphanumeric box, a screen density of 64 x 48 elements is available.
417 // Six bits are used to generate this map and two data bits may be used to select
418 // one of four colors in the display box. A 512 byte display memory is required.
419 // The element area is four dot-clocks wide by four lines high.
420 case TILEMAP_MODE_SEMIGRAPHICS6: // Semigraphics 6 64 × 48 4 512
421 _environment->screenWidth = 64;
422 _environment->screenHeight = 48;
423 _environment->screenTilesWidth = 32;
424 _environment->screenTilesHeight = 16;
425 _environment->screenColors = 4;
426 // Semigraphic-6 0 X X 1 0 0 0 64x48 pixels
428 VDG_TEXT;
432 GM2_CLR;
433 GM1_CLR;
434 GM0_SET;
435 cpu_store_16bit( _environment, "CLIPX1", 0 );
436 cpu_store_16bit( _environment, "CLIPX2", 63 );
437 cpu_store_16bit( _environment, "CLIPY1", 0 );
438 cpu_store_16bit( _environment, "CLIPY2", 47 );
439 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 512 );
440 break;
441 // The ALPHA SEMIGRAPHICS – 8 mode maps eight 4 x 3 dot elements into the
442 // standard 8 x 12 dot box. This mode requires four memory locations per box
443 // and each memory location may specify one of eight colors or black.
444 // A 2048 byte display memory is required. A density of 64 x 64 elements is
445 // available in the display area. The element area is four dot-clocks wide
446 // by three lines high.
447 case TILEMAP_MODE_SEMIGRAPHICS8: // Semigraphics 8 64 × 64 2 512
448 _environment->screenWidth = 64;
449 _environment->screenHeight = 64;
450 _environment->screenTilesWidth = 32;
451 _environment->screenTilesHeight = 16;
452 _environment->screenColors = 4;
453 cpu_store_16bit( _environment, "CLIPX1", 0 );
454 cpu_store_16bit( _environment, "CLIPX2", 63 );
455 cpu_store_16bit( _environment, "CLIPY1", 0 );
456 cpu_store_16bit( _environment, "CLIPY2", 63 );
457 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 2048 );
458 break;
459 // The ALPHA SEMIGRAPHICS – 12 mode maps twelve 4 x 2 dot elements into the
460 // standard 8 x 12 dot box. This mode requires six memory locations per box and
461 // each memory location may specify one of eight colors or black. A 3072 byte
462 // display memory is required. A density of 64 x 96 elements is available in the
463 // display area. The element area is four dot-clocks wide by two lineshigh.
464 case TILEMAP_MODE_SEMIGRAPHICS12: // Semigraphics 6 64 × 96 1 3072
465 _environment->screenWidth = 64;
466 _environment->screenHeight = 96;
467 _environment->screenTilesWidth = 32;
468 _environment->screenTilesHeight = 16;
469 _environment->screenColors = 4;
470 cpu_store_16bit( _environment, "CLIPX1", 0 );
471 cpu_store_16bit( _environment, "CLIPX2", 63 );
472 cpu_store_16bit( _environment, "CLIPY1", 0 );
473 cpu_store_16bit( _environment, "CLIPY2", 95 );
474 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 3072 );
475 break;
476 // The ALPHA SEMIGRAPHICS – 24 mode maps twenty-four 4 x 1 dot elements into
477 // the standard 8 x 12 dot box. This mode requires twelve memory locations
478 // per box and each memory location may specify one of eight colors or black.
479 // A 6144 byte display memory is required. A density of 64 x 192
480 // elements is available in the display are. The element area is four
481 // dot-clocks wide by one line high.
482 case TILEMAP_MODE_SEMIGRAPHICS24: // Semigraphics 6 64 × 96 1 3072
483 _environment->screenWidth = 64;
484 _environment->screenHeight = 96;
485 _environment->screenTilesWidth = 32;
486 _environment->screenTilesHeight = 16;
487 _environment->screenColors = 4;
488 cpu_store_16bit( _environment, "CLIPX1", 0 );
489 cpu_store_16bit( _environment, "CLIPX2", 63 );
490 cpu_store_16bit( _environment, "CLIPY1", 0 );
491 cpu_store_16bit( _environment, "CLIPY2", 191 );
492 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 6144 );
493 break;
494 // The 64 x 64 Color Graphics mode generates a display matrix of 64
495 // elements wide by 64 elements high. Each element may be one of four
496 // colors. A 1K x 8 display memory is required. Each pixel equals
497 // four dot-clocks by three scan lines.
498 case BITMAP_MODE_COLOR1: // Color Graphics 1 64 × 64 4 1024
499 _environment->screenWidth = 64;
500 _environment->screenHeight = 64;
501 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
502 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
503 _environment->screenColors = 4;
504 // Full graphic 1-C 1 0 0 0 0 0 1 64x64x4 $400(1024)
506 VDG_GRAPH;
510 GM2_CLR;
511 GM1_CLR;
512 GM0_CLR;
513 cpu_store_16bit( _environment, "CLIPX1", 0 );
514 cpu_store_16bit( _environment, "CLIPX2", 63 );
515 cpu_store_16bit( _environment, "CLIPY1", 0 );
516 cpu_store_16bit( _environment, "CLIPY2", 63 );
517 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 1024 );
518 cpu_store_8bit( _environment, "CURRENTSL", 64 / 4 );
519 break;
520 // The 128 x 64 Graphics Mode generates a matrix 128 elements wide
521 // by 64 elements high. Each element may be either ON or OFF. However,
522 // the entire display may be one of two colors, selected by using the
523 // color set select pin. A 1K x 8 display memory is required. Each
524 // pixel equals two dotclocks by three scan lines.
525 case BITMAP_MODE_RESOLUTION1: // Resolution Graphics 1 128 × 64 1 + Black 1024
526 _environment->screenWidth = 128;
527 _environment->screenHeight = 64;
528 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
529 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
530 _environment->screenColors = 2;
531 // Full graphic 1-R 1 0 0 1 0 0 1 128x64x2 $400(1024)
533 VDG_GRAPH;
537 GM2_CLR;
538 GM1_CLR;
539 GM0_SET;
540 cpu_store_16bit( _environment, "CLIPX1", 0 );
541 cpu_store_16bit( _environment, "CLIPX2", 127 );
542 cpu_store_16bit( _environment, "CLIPY1", 0 );
543 cpu_store_16bit( _environment, "CLIPY2", 63 );
544 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 1024 );
545 cpu_store_8bit( _environment, "CURRENTSL", 128 / 8 );
546 break;
547 // The 128 x 64 Color Graphics mode generates a display matrix 128
548 // elements wide by 64 elements high. Each element may be one of four
549 // colors. A 2K x 8 display memory is required. Each pixel equals
550 // two dot-clocks by three scan lines.
551 case BITMAP_MODE_COLOR2: // Color Graphics 2 128 × 64 4 2048
552 _environment->screenWidth = 128;
553 _environment->screenHeight = 64;
554 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
555 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
556 _environment->screenColors = 4;
557 // Full graphic 2-C 1 0 1 0 0 1 0 128x64x4 $800(2048)
559 VDG_GRAPH;
563 GM2_CLR;
564 GM1_SET;
565 GM0_CLR;
566 cpu_store_16bit( _environment, "CLIPX1", 0 );
567 cpu_store_16bit( _environment, "CLIPX2", 127 );
568 cpu_store_16bit( _environment, "CLIPY1", 0 );
569 cpu_store_16bit( _environment, "CLIPY2", 63 );
570 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 2048 );
571 cpu_store_8bit( _environment, "CURRENTSL", 128 / 4 );
572 break;
573 // The 128 x 96 Graphics mode generates a display matrix 128
574 // elements wide by 96 elements high. Each element may be either
575 // ON or OFF. However, the entire display may be one of two colors
576 // selected by using the color select pin. A 2K x 8 display memory
577 // is required. Each pixel equals two dot-clocks by two scan lines.
578 case BITMAP_MODE_RESOLUTION2: // Resolution Graphics 2 128 × 96 1 + Black 1536
579 _environment->screenWidth = 128;
580 _environment->screenHeight = 96;
581 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
582 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
583 _environment->screenColors = 2;
584 // Full graphic 2-R 1 0 1 1 0 1 1 128x96x2 $600(1536)
586 VDG_GRAPH;
590 GM2_CLR;
591 GM1_SET;
592 GM0_SET;
593 cpu_store_16bit( _environment, "CLIPX1", 0 );
594 cpu_store_16bit( _environment, "CLIPX2", 127 );
595 cpu_store_16bit( _environment, "CLIPY1", 0 );
596 cpu_store_16bit( _environment, "CLIPY2", 95 );
597 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 1536 );
598 cpu_store_8bit( _environment, "CURRENTSL", 128 / 8 );
599 break;
600 // The 128 x 96 Color Graphics mode generates a display 128 elements
601 // wide by 96 elements high. Each element may be one of four colors.
602 // A 3K x 8 display memory is required. Each pixel equals two
603 // dot-clocks by two scan lines.
604 case BITMAP_MODE_COLOR3: // Color Graphics 3 128 × 96 4 3072
605 _environment->screenWidth = 128;
606 _environment->screenHeight = 96;
607 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
608 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
609 _environment->screenColors = 4;
610 // Full graphic 3-C 1 1 0 0 1 0 0 128x96x4 $C00(3072)
612 VDG_GRAPH;
616 GM2_SET;
617 GM1_CLR;
618 GM0_CLR;
619 cpu_store_16bit( _environment, "CLIPX1", 0 );
620 cpu_store_16bit( _environment, "CLIPX2", 127 );
621 cpu_store_16bit( _environment, "CLIPY1", 0 );
622 cpu_store_16bit( _environment, "CLIPY2", 95 );
623 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 3072 );
624 cpu_store_8bit( _environment, "CURRENTSL", 128 / 4 );
625 break;
626 // The 128 x 192 Graphics mode generates a display matrix 128 elements
627 // wide by 192 elements high. Each element may be either ON or OFF,
628 // but the ON elements may be one of two colors selected with color
629 // set select pin. A 3K x 8 display memory is required. Each pixel
630 // equals two dot-clocks by one scan line.
631 case BITMAP_MODE_RESOLUTION3: // Resolution Graphics 3 128 × 192 1 + Black 3072
632 _environment->screenWidth = 128;
633 _environment->screenHeight = 192;
634 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
635 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
636 _environment->screenColors = 2;
637 // Full graphic 3-R 1 1 0 1 1 0 1 128x192x2 $C00(3072)
639 VDG_GRAPH;
643 GM2_SET;
644 GM1_CLR;
645 GM0_SET;
646 cpu_store_16bit( _environment, "CLIPX1", 0 );
647 cpu_store_16bit( _environment, "CLIPX2", 127 );
648 cpu_store_16bit( _environment, "CLIPY1", 0 );
649 cpu_store_16bit( _environment, "CLIPY2", 191 );
650 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 3072 );
651 cpu_store_8bit( _environment, "CURRENTSL", 128 / 8 );
652 break;
653 // The 128 x 192 Color Graphics mode generates a display 128 elements
654 // wide by 192 elements high. Each element may be one of four colors.
655 // A 6K x 8 display memory is required. Each pixel equals two dot-clocks
656 // by one scan line.
657 case BITMAP_MODE_COLOR6: // Color Graphics 6 128 × 192 4 6144
658 _environment->screenWidth = 128;
659 _environment->screenHeight = 192;
660 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
661 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
662 _environment->screenColors = 4;
663 // Full graphic 6-C 1 1 1 0 1 1 0 128x192x4 $1800(6144)
665 VDG_GRAPH;
669 GM2_SET;
670 GM1_SET;
671 GM0_CLR;
672 cpu_store_16bit( _environment, "CLIPX1", 0 );
673 cpu_store_16bit( _environment, "CLIPX2", 127 );
674 cpu_store_16bit( _environment, "CLIPY1", 0 );
675 cpu_store_16bit( _environment, "CLIPY2", 191 );
676 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 6144 );
677 cpu_store_8bit( _environment, "CURRENTSL", 128 / 4 );
678 break;
679 // The 256 x 192 Graphics mode generates a display 256 elements wide by
680 // 192 elements high. Each element may be either ON or OFF, but the ON
681 // element may be one of two colors selected with the color set select pin.
682 // A 6K x 8 display memory is required. Each pixel equals one
683 // dot-clock by one scan line.
684 case BITMAP_MODE_RESOLUTION6: // Resolution Graphics 6 256 × 192 1 + Black 6144 break;
685 _environment->screenWidth = 256;
686 _environment->screenHeight = 192;
687 _environment->screenTilesWidth = _environment->screenWidth/_environment->fontWidth;
688 _environment->screenTilesHeight = _environment->screenHeight/_environment->fontHeight;
689 _environment->screenColors = 2;
690 // Full graphic 6-R 1 1 1 1 1 1 0 256x192x2 $1800(6144)
692 VDG_GRAPH;
696 GM2_SET;
697 GM1_SET;
698 GM0_SET;
699 cpu_store_16bit( _environment, "CLIPX1", 0 );
700 cpu_store_16bit( _environment, "CLIPX2", 255 );
701 cpu_store_16bit( _environment, "CLIPY1", 0 );
702 cpu_store_16bit( _environment, "CLIPY2", 191 );
703 cpu_store_16bit( _environment, "CURRENTFRAMESIZE", 6144 );
704 cpu_store_8bit( _environment, "CURRENTSL", 256 / 8 );
705 break;
706 default:
707 CRITICAL_SCREEN_UNSUPPORTED( _screen_mode->id );
708 }
709
710 _environment->consoleTilesWidth = _environment->screenTilesWidth;
711 _environment->consoleTilesHeight = _environment->screenTilesHeight;
712
713 cpu_store_16bit( _environment, "ORIGINX", 0 );
714 cpu_store_16bit( _environment, "ORIGINY", 0 );
715 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
716 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
717 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
718 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
719 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
720 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
721 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
722
723 console_init( _environment );
724
725 console_calculate( _environment );
726
727 console_calculate_vars( _environment );
728
729 if (_environment->vestigialConfig.clsImplicit ) {
730 c6847_cls( _environment );
731 }
732
733}
734
735void c6847_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
736
737 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
738
739 if ( mode ) {
740
741 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
742 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
743
744 _environment->currentMode = mode->id;
745 _environment->currentTileMode = 0;
746
747 c6847_screen_mode_enable( _environment, mode );
748
749 } else {
751 }
752
753}
754
755void c6847_bitmap_disable( Environment * _environment ) {
756
757}
758
759void c6847_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
760
761 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
762
763 if ( mode ) {
764
765 _environment->currentMode = mode->id;
766 _environment->currentTileMode = 1;
767
768 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
769 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
770
771 c6847_screen_mode_enable( _environment, mode );
772
773
774 } else {
776 }
777
778}
779
780void c6847_bitmap_at( Environment * _environment, char * _address ) {
781
782 outline1("LDD %s", _address);
783 outline0("JSR C6847VIDEOSTARTATB" );
784
785}
786
787void c6847_colormap_at( Environment * _environment, char * _address ) {
788
789}
790
791void c6847_textmap_at( Environment * _environment, char * _address ) {
792
793 outline1("LDD %s", _address);
794 outline0("JSR C6847VIDEOSTARTATT" );
795
796}
797
798void c6847_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
799
800 deploy_preferred( c6847vars, src_hw_6847_vars_asm );
801 deploy_preferred( plot, src_hw_6847_plot_asm );
802
803 outline1("LDX %4.4x", (_x & 0xffff ) );
804 outline0("STX <PLOTX");
805 outline1("LDD %4.4x", ( _y & 0xffff ) );
806 outline0("STD <PLOTY");
807 if ( _c ) {
808 outline1("LDA %2.2x", ( *_c & 0Xff ) );
809 } else {
810 Variable * c = variable_retrieve( _environment, "PEN" );
811 outline1("LDA %s", c->realName );
812 }
813 outline0("STA <PLOTCPE");
814 outline0("LDA #1");
815 outline0("STA <PLOTM");
816 outline0("JSR PLOT");
817
818
819}
820
821void c6847_pset_vars( Environment * _environment, char *_x, char *_y, char * _c ) {
822
823 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
824 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
825 Variable * c;
826
827 if ( _c ) {
828 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
829 } else {
830 c = variable_retrieve( _environment, "PEN" );
831 }
832
833 deploy_preferred( c6847vars, src_hw_6847_vars_asm );
834 deploy_preferred( plot, src_hw_6847_plot_asm );
835
836 outline1("LDX %s", x->realName );
837 outline0("STX <PLOTX");
838 outline1("LDD %s", y->realName );
839 outline0("STD <PLOTY");
840 outline1("LDA %s", c->realName );
841 outline0("STA <PLOTCPE");
842 outline0("LDA #1");
843 outline0("STA <PLOTM");
844 outline0("JSR PLOT");
845
846}
847
848void c6847_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
849
850 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
851 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
852 Variable * result = variable_retrieve_or_define( _environment, _result, VT_BYTE, 0 );
853
854 deploy_preferred( c6847vars, src_hw_6847_vars_asm );
855 deploy_preferred( plot, src_hw_6847_plot_asm );
856
857 outline1("LDD %s", x->realName );
858 outline0("STD <PLOTX");
859 outline1("LDD %s", y->realName );
860 outline0("STD <PLOTY");
861 outline0("LDA #3");
862 outline0("STA <PLOTM");
863 outline0("JSR PLOT");
864 outline0("LDA <PLOTM");
865 outline1("STA %s", result->realName );
866
867}
868
869void c6847_screen_on( Environment * _environment ) {
870
871}
872
873void c6847_screen_off( Environment * _environment ) {
874
875}
876
877void c6847_screen_rows( Environment * _environment, char * _rows ) {
878
879}
880
881void c6847_screen_columns( Environment * _environment, char * _columns ) {
882
883}
884
885void c6847_sprite_data_from( Environment * _environment, char * _sprite, char * _address ) {
886
887}
888
889void c6847_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
890
891}
892
893void c6847_sprite_enable( Environment * _environment, char * _sprite ) {
894
895}
896
897void c6847_sprite_disable( Environment * _environment, char * _sprite ) {
898
899}
900
901void c6847_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
902
903}
904
905void c6847_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
906
907}
908
909void c6847_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
910
911}
912
913void c6847_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
914
915}
916
917void c6847_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
918
919}
920
921void c6847_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
922
923}
924
925void c6847_sprite_multicolor( Environment * _environment, char * _sprite ) {
926
927}
928
929void c6847_sprite_monocolor( Environment * _environment, char * _sprite ) {
930
931}
932
933void c6847_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
934
935}
936
937void c6847_tiles_at( Environment * _environment, char * _address ) {
938
939}
940
941void c6847_vertical_scroll( Environment * _environment, char * _displacement ) {
942
943}
944
945void c6847_horizontal_scroll( Environment * _environment, char * _displacement ) {
946
947}
948
949void c6847_get_width( Environment * _environment, char *_result ) {
950
951 outline0("LDX CURRENTWIDTH" );
952 outline1("STX %s", _result );
953
954}
955
956void c6847_tiles_get( Environment * _environment, char *_result ) {
957
958 outline0("LDA CURRENTTILES" );
959 outline1("STA %s", _result );
960
961}
962
963void c6847_get_height( Environment * _environment, char *_result ) {
964
965 outline0("LDX CURRENTHEIGHT" );
966 outline1("STX %s", _result );
967
968}
969
970void c6847_cls( Environment * _environment ) {
971
972 if ( _environment->currentMode < 7 ) {
973 deploy( clsText, src_hw_6847_cls_text_asm );
974 outline0("JSR CLST");
975 } else {
976 deploy( clsGraphic, src_hw_6847_cls_graphic_asm );
977 outline0("JSR CLSG");
978 }
979
980}
981
982void c6847_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
983
984 if ( _environment->currentMode < 7 ) {
985
986 } else {
987 deploy( clsBox, src_hw_6847_cls_box_asm );
988 outline1("LDD %s", _x1 );
989 outline0("STD <IMAGEX" );
990 outline1("LDD %s", _y1 );
991 outline0("STD <IMAGEY" );
992 outline1("LDA %s", _w );
993 outline0("STA <IMAGEW" );
994 outline1("LDA %s", _h );
995 outline0("STA <IMAGEH" );
996 outline0("JSR CLSBOX");
997 }
998
999}
1000
1001void c6847_scroll_text( Environment * _environment, int _direction, int _overlap ) {
1002
1003 if ( _environment->currentMode < 7 ) {
1004 deploy_preferred( vScrollText, src_hw_6847_vscroll_text_asm );
1005 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1006 outline0("STA <DIRECTION" );
1007 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
1008 outline0("STA <PORT" );
1009 outline0("JSR VSCROLLT");
1010 } else {
1011 deploy_preferred( vScroll, src_hw_6847_vscroll_graphic_asm );
1012 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1013 outline0("STA <DIRECTION" );
1014 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
1015 outline0("STA <PORT" );
1016 outline0("JSR VSCROLLG");
1017 }
1018
1019}
1020
1021void c6847_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
1022
1023 deploy_preferred( c6847vars, src_hw_6847_vars_asm);
1024 deploy( textEncodedAt, src_hw_6847_text_at_asm );
1025
1026 outline1("LDY %s", _text);
1027 outline0("STY <TEXTPTR" );
1028 outline1("LDA %s", _text_size);
1029 outline0("STA <TEXTSIZE" );
1030
1031 if ( _raw ) {
1032 if ( _environment->currentMode < 7 ) {
1033 deploy( clsText, src_hw_6847_cls_text_asm );
1034 deploy_preferred( vScrollText, src_hw_6847_vscroll_text_asm );
1035 deploy( textEncodedAtTextRaw, src_hw_6847_text_at_text_raw_asm );
1036 outline0("JSR TEXTATTILEMODERAW");
1037 } else {
1038 deploy( clsGraphic, src_hw_6847_cls_graphic_asm );
1039 deploy( vScroll, src_hw_6847_vscroll_graphic_asm );
1040 deploy( textEncodedAtGraphicRaw, src_hw_6847_text_at_graphic_raw_asm );
1041 outline0("JSR TEXTATBITMAPMODERAW");
1042 }
1043 } else {
1044 if ( _environment->currentMode < 7 ) {
1045 deploy( clsText, src_hw_6847_cls_text_asm );
1046 deploy_preferred( vScrollText, src_hw_6847_vscroll_text_asm );
1047 deploy( textEncodedAtText, src_hw_6847_text_at_text_asm );
1048 outline0("JSR TEXTATTILEMODE");
1049 } else {
1050 deploy( clsGraphic, src_hw_6847_cls_graphic_asm );
1051 deploy( vScroll, src_hw_6847_vscroll_graphic_asm );
1052 deploy( textEncodedAtGraphic, src_hw_6847_text_at_graphic_asm );
1053 outline0("JSR TEXTATBITMAPMODE");
1054 }
1055 }
1056
1057}
1058
1059void c6847_initialization( Environment * _environment ) {
1060
1061 deploy_preferred( c6847vars, src_hw_6847_vars_asm );
1062 deploy( c6847startup, src_hw_6847_startup_asm );
1063
1064 variable_import( _environment, "CURRENTMODE", VT_BYTE, 0 );
1065 variable_global( _environment, "CURRENTMODE" );
1066 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
1067 variable_global( _environment, "CURRENTTILEMODE" );
1068
1069 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 256 );
1070 variable_global( _environment, "CURRENTWIDTH" );
1071 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 128 );
1072 variable_global( _environment, "CURRENTHEIGHT" );
1073 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 32 );
1074 variable_global( _environment, "CURRENTTILESWIDTH" );
1075 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 16 );
1076 variable_global( _environment, "CURRENTTILESHEIGHT" );
1077 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
1078 variable_global( _environment, "CURRENTTILES" );
1079 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
1080 variable_global( _environment, "FONTWIDTH" );
1081 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
1082 variable_global( _environment, "FONTHEIGHT" );
1083
1084 SCREEN_MODE_DEFINE( TILEMAP_MODE_INTERNAL, 0, 32, 16, 2, 8, 8, "Alphanumeric Internal");
1085 SCREEN_MODE_DEFINE( TILEMAP_MODE_EXTERNAL, 0, 32, 16, 2, 8, 8, "Alphanumeric External");
1086 SCREEN_MODE_DEFINE( TILEMAP_MODE_SEMIGRAPHICS4, 0, 64, 32, 8, 8, 8, "Semigraphics 4" );
1087 SCREEN_MODE_DEFINE( TILEMAP_MODE_SEMIGRAPHICS6, 0, 64, 48, 4, 8, 8, "Semigraphics 6" );
1088 SCREEN_MODE_DEFINE( TILEMAP_MODE_SEMIGRAPHICS8, 0, 64, 64, 8, 8, 8, "Semigraphics 8" );
1089
1090 SCREEN_MODE_DEFINE( BITMAP_MODE_COLOR6, 1, 128, 192, 4, 8, 8, "Color Graphics 6" );
1091 SCREEN_MODE_DEFINE( BITMAP_MODE_RESOLUTION6, 1, 256, 192, 2, 8, 8, "Resolution Graphics 6" );
1092 SCREEN_MODE_DEFINE( BITMAP_MODE_COLOR3, 1, 128, 96, 4, 8, 8, "Color Graphics 3" );
1093 SCREEN_MODE_DEFINE( BITMAP_MODE_RESOLUTION3, 1, 128, 192, 2, 8, 8, "Resolution Graphics 3" );
1094 SCREEN_MODE_DEFINE( BITMAP_MODE_COLOR2, 1, 128, 64, 4, 8, 8, "Color Graphics 2" );
1095 SCREEN_MODE_DEFINE( BITMAP_MODE_RESOLUTION2, 1, 128, 96, 2, 8, 8, "Resolution Graphics 2" );
1096 SCREEN_MODE_DEFINE( BITMAP_MODE_COLOR1, 1, 64, 64, 4, 8, 8, "Color Graphics 1" );
1097 SCREEN_MODE_DEFINE( BITMAP_MODE_RESOLUTION1, 1, 128, 64, 2, 8, 8, "Resolution Graphics 1" );
1098
1099 outline0("JSR C6847STARTUP");
1100
1101 variable_import( _environment, "XGR", VT_POSITION, 0 );
1102 variable_global( _environment, "XGR" );
1103 variable_import( _environment, "YGR", VT_POSITION, 0 );
1104 variable_global( _environment, "YGR" );
1105 variable_import( _environment, "LINE", VT_WORD, (unsigned short)(0xffff) );
1106 variable_global( _environment, "LINE" );
1107 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
1108 variable_global( _environment, "TABCOUNT" );
1109
1110 variable_import( _environment, "PLOTCPE", VT_BYTE, 0 );
1111 variable_global( _environment, "PLOTCPE" );
1112
1113 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
1114 variable_global( _environment, "CLIPX1" );
1115 variable_import( _environment, "CLIPX2", VT_POSITION, 255 );
1116 variable_global( _environment, "CLIPX2" );
1117 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
1118 variable_global( _environment, "CLIPY1" );
1119 variable_import( _environment, "CLIPY2", VT_POSITION, 127 );
1120 variable_global( _environment, "CLIPY2" );
1121
1122 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
1123 variable_global( _environment, "ORIGINX" );
1124 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
1125 variable_global( _environment, "ORIGINY" );
1126 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
1127 variable_global( _environment, "RESOLUTIONX" );
1128 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
1129 variable_global( _environment, "RESOLUTIONY" );
1130
1131 _environment->fontConfig.schema = FONT_SCHEMA_ASCII;
1132
1133 font_descriptors_init( _environment, 0 );
1134
1135 _environment->fontWidth = 8;
1136 _environment->fontHeight = 8;
1137 _environment->screenTilesWidth = 32;
1138 _environment->screenTilesHeight = 16;
1139 _environment->consoleTilesWidth = 32;
1140 _environment->consoleTilesHeight = 16;
1141 _environment->screenTiles = 128;
1142 _environment->screenWidth = _environment->screenTilesWidth*_environment->fontWidth;
1143 _environment->screenHeight = _environment->screenTilesHeight*_environment->fontHeight;
1144 _environment->screenShades = 4;
1145 _environment->screenColors = 4;
1146
1147 console_init( _environment );
1148
1149 if ( _environment->vestigialConfig.clsImplicit ) {
1150 c6847_cls( _environment );
1151 }
1152
1153}
1154
1155void c6847_finalization( Environment * _environment ) {
1156
1157 if (_environment->vestigialConfig.clsImplicit ) {
1158 deploy( clsText, src_hw_6847_cls_text_asm );
1159 }
1160
1161 CopperList * copperList = _environment->copperList;
1162 if ( copperList ) {
1163 while(copperList) {
1164 outhead1("COPPERACTIVATE%s", copperList->name ? copperList->name : "" );
1165 outline0("RTS");
1166 copperList = copperList->next;
1167 }
1168 }
1169
1170}
1171
1172void c6847_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
1173
1174 deploy_preferred( textHScroll, src_hw_6847_hscroll_text_asm );
1175
1176 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1177 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1178 outline0("STA <DIRECTION" );
1179 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
1180 outline0("STA <PORT" );
1181 outline1("LDA %s", y->realName );
1182 outline0("STA <CLINEY");
1183
1184 outline0("JSR HSCROLLLT");
1185
1186}
1187
1188void c6847_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
1189
1190 deploy_preferred( textHScroll, src_hw_6847_hscroll_text_asm );
1191
1192 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1193 outline0("STA <DIRECTION" );
1194 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
1195 outline0("STA <PORT" );
1196
1197 outline0("JSR HSCROLLST");
1198
1199}
1200
1201void c6847_back( Environment * _environment ) {
1202
1203}
1204
1205void c6847_cline( Environment * _environment, char * _characters ) {
1206
1207 Variable * x = variable_retrieve( _environment, "XCURSYS" );
1208 Variable * y = variable_retrieve( _environment, "YCURSYS" );
1209
1210 if ( _characters ) {
1211 outline1("LDD %s", _characters);
1212 } else {
1213 outline0("LDD #0");
1214 }
1215 outline0("STB <CHARACTERS");
1216 outline1("LDA %s", x->realName );
1217 outline0("STA <CLINEX" );
1218 outline1("LDA %s", y->realName );
1219 outline0("STA <CLINEY");
1220
1221 if ( _environment->currentMode < 7 ) {
1222 deploy( textCline, src_hw_6847_cline_text_asm );
1223 outline0("JSR CLINE");
1224 } else {
1225 deploy( textClineGraphic, src_hw_6847_cline_graphic_asm );
1226 outline0("JSR CLINEG");
1227 }
1228
1229}
1230
1231int c6847_image_size( Environment * _environment, int _width, int _height, int _mode, int _transparent ) {
1232
1233 switch( _mode ) {
1234 case TILEMAP_MODE_INTERNAL: // Alphanumeric Internal 32 × 16 2 512
1235 case TILEMAP_MODE_EXTERNAL: // Alphanumeric External 32 × 16 2 512
1236 break;
1237 case TILEMAP_MODE_SEMIGRAPHICS4: // Semigraphics 4 64 × 32 8 512
1238 case TILEMAP_MODE_SEMIGRAPHICS6: // Semigraphics 6 64 × 48 4 512
1239 return 3 + ( ( _width >> 3 ) * ( _height / 12 ) );
1240 case TILEMAP_MODE_SEMIGRAPHICS8: // Semigraphics 8 64 × 64 2 512
1241 case TILEMAP_MODE_SEMIGRAPHICS12: // Semigraphics 6 64 × 96 1 3072
1242 case TILEMAP_MODE_SEMIGRAPHICS24: // Semigraphics 6 64 × 96 1 3072
1243 break;
1244 case BITMAP_MODE_COLOR1: // Color Graphics 1 64 × 64 4 1024
1245 case BITMAP_MODE_COLOR2: // Color Graphics 2 128 × 64 4 2048
1246 case BITMAP_MODE_COLOR3: // Color Graphics 3 128 × 96 4 3072
1247 case BITMAP_MODE_COLOR6: // Color Graphics 6 128 × 192 4 6144
1248 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1249 return 3 + ( ( _width >> 2 ) * _height );
1250 } else {
1251 return 2 + ( ( _width >> 2 ) * _height );
1252 }
1253 case BITMAP_MODE_RESOLUTION1: // Resolution Graphics 1 128 × 64 1 + Black 1024
1254 case BITMAP_MODE_RESOLUTION2: // Resolution Graphics 2 128 × 96 1 + Black 1536
1255 case BITMAP_MODE_RESOLUTION3: // Resolution Graphics 3 128 × 192 1 + Black 3072
1256 case BITMAP_MODE_RESOLUTION6: // Resolution Graphics 6 256 × 192 1 + Black 6144 break;
1257 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1258 if ( _transparent ) {
1259 return 3 + 2*( ( _width >> 3 ) * _height );
1260 } else {
1261 return 3 + ( ( _width >> 3 ) * _height );
1262 }
1263 } else {
1264 return 2 + ( ( _width >> 3 ) * _height );
1265 }
1266
1267 }
1268
1269 return 0;
1270
1271}
1272
1273static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode, int _transparent ) {
1274
1275 switch( _mode ) {
1276 case TILEMAP_MODE_INTERNAL: // Alphanumeric Internal 32 × 16 2 512
1277 case TILEMAP_MODE_EXTERNAL: // Alphanumeric External 32 × 16 2 512
1278 break;
1279 case TILEMAP_MODE_SEMIGRAPHICS4: // Semigraphics 4 64 × 32 8 512
1280 case TILEMAP_MODE_SEMIGRAPHICS6: // Semigraphics 6 64 × 48 4 512
1281 return 3 + ( 3 + ( ( _width >> 3 ) * ( _height / 12 ) ) ) * _frames;
1282 case TILEMAP_MODE_SEMIGRAPHICS8: // Semigraphics 8 64 × 64 2 512
1283 case TILEMAP_MODE_SEMIGRAPHICS12: // Semigraphics 6 64 × 96 1 3072
1284 case TILEMAP_MODE_SEMIGRAPHICS24: // Semigraphics 6 64 × 96 1 3072
1285 break;
1286 case BITMAP_MODE_COLOR1: // Color Graphics 1 64 × 64 4 1024
1287 case BITMAP_MODE_COLOR2: // Color Graphics 2 128 × 64 4 2048
1288 case BITMAP_MODE_COLOR3: // Color Graphics 3 128 × 96 4 3072
1289 case BITMAP_MODE_COLOR6: // Color Graphics 6 128 × 192 4 6144
1290 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1291 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) ) * _frames;
1292 } else {
1293 return 3 + ( 2 + ( ( _width >> 2 ) * _height ) ) * _frames;
1294 }
1295 case BITMAP_MODE_RESOLUTION1: // Resolution Graphics 1 128 × 64 1 + Black 1024
1296 case BITMAP_MODE_RESOLUTION2: // Resolution Graphics 2 128 × 96 1 + Black 1536
1297 case BITMAP_MODE_RESOLUTION3: // Resolution Graphics 3 128 × 192 1 + Black 3072
1298 case BITMAP_MODE_RESOLUTION6: // Resolution Graphics 6 256 × 192 1 + Black 6144 break;
1299 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1300 if ( _transparent ) {
1301 return 3 + ( 3 + 2* ( ( _width >> 3 ) * _height ) ) * _frames;
1302 } else {
1303 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) ) * _frames;
1304 }
1305 } else {
1306 return 3 + ( 2 + ( ( _width >> 3 ) * _height ) ) * _frames;
1307 }
1308
1309 }
1310
1311 return 0;
1312
1313}
1314
1315static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode, int _transparent ) {
1316
1317 switch( _mode ) {
1318 case TILEMAP_MODE_INTERNAL: // Alphanumeric Internal 32 × 16 2 512
1319 case TILEMAP_MODE_EXTERNAL: // Alphanumeric External 32 × 16 2 512
1320 break;
1321 case TILEMAP_MODE_SEMIGRAPHICS4: // Semigraphics 4 64 × 32 8 512
1322 case TILEMAP_MODE_SEMIGRAPHICS6: // Semigraphics 6 64 × 48 4 512
1323 return 3 + ( ( 3 + ( ( _width >> 3 ) * ( _height / 12 ) ) ) * _frames ) * _sequences;
1324 case TILEMAP_MODE_SEMIGRAPHICS8: // Semigraphics 8 64 × 64 2 512
1325 case TILEMAP_MODE_SEMIGRAPHICS12: // Semigraphics 6 64 × 96 1 3072
1326 case TILEMAP_MODE_SEMIGRAPHICS24: // Semigraphics 6 64 × 96 1 3072
1327 break;
1328 case BITMAP_MODE_COLOR1: // Color Graphics 1 64 × 64 4 1024
1329 case BITMAP_MODE_COLOR2: // Color Graphics 2 128 × 64 4 2048
1330 case BITMAP_MODE_COLOR3: // Color Graphics 3 128 × 96 4 3072
1331 case BITMAP_MODE_COLOR6: // Color Graphics 6 128 × 192 4 6144
1332 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1333 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) ) * _frames ) * _sequences;
1334 } else {
1335 return 3 + ( ( 2 + ( ( _width >> 2 ) * _height ) ) * _frames ) * _sequences;
1336 }
1337 case BITMAP_MODE_RESOLUTION1: // Resolution Graphics 1 128 × 64 1 + Black 1024
1338 case BITMAP_MODE_RESOLUTION2: // Resolution Graphics 2 128 × 96 1 + Black 1536
1339 case BITMAP_MODE_RESOLUTION3: // Resolution Graphics 3 128 × 192 1 + Black 3072
1340 case BITMAP_MODE_RESOLUTION6: // Resolution Graphics 6 256 × 192 1 + Black 6144 break;
1341 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1342 if ( _transparent ) {
1343 return 3 + ( ( 3 + 2 * ( ( _width >> 3 ) * _height ) ) * _frames ) * _sequences;
1344 } else {
1345 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) ) * _frames ) * _sequences;
1346 }
1347 } else {
1348 return 3 + ( ( 2 + ( ( _width >> 3 ) * _height ) ) * _frames ) * _sequences;
1349 }
1350
1351 }
1352
1353 return 0;
1354
1355}
1356
1357static Variable * c6847_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 ) {
1358
1359 // ignored on bitmap mode
1360 (void)!_transparent_color;
1361
1362 RGBi white = { 0xff, 0xff, 0xff, 0xff };
1363 RGBi black = { 0x00, 0x00, 0x00, 0xff };
1364
1365 // ignored on bitmap mode
1366 (void)!_transparent_color;
1367
1368 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
1369
1370 if ( _environment->freeImageWidth ) {
1371 if ( _width % 8 ) {
1372 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1373 }
1374 if ( _frame_width % 8 ) {
1375 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1376 }
1377 }
1378
1379 RGBi * palette = malloc_palette( MAX_PALETTE );
1380
1381 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1382
1383 if (paletteColorCount > 3) {
1384 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1385 }
1386
1387 if ( _transparent_color == 0 ) {
1388 for( int i=0; i<3; ++i ) {
1389 if ( palette[i].alpha < 255 ) {
1390 _transparent_color = 0x0f0000;
1391 break;
1392 }
1393 }
1394 }
1395
1396 int i, j, k;
1397
1398 SYSTEM_PALETTE = &SYSTEM_PALETTE_ALTERNATE[_environment->paletteSelected][0];
1399
1400 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE_ALTERNATE[0]) / sizeof(RGBi) );
1401 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1402 lastUsedSlotInCommonPalette = paletteColorCount;
1403 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1404
1405 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE_ALTERNATE[0]) / sizeof(RGBi)), SYSTEM_PALETTE );
1406
1407 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1409 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1410
1411 int bufferSize = c6847_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_RESOLUTION1, (_transparent_color & 0x0f0000 ) ? 1 : 0 );
1412 // printf("bufferSize = %d\n", bufferSize );
1413
1414 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_RESOLUTION1 );
1415
1416 char * buffer = malloc ( bufferSize );
1417 memset( buffer, 0, bufferSize );
1418
1419 // Position of the pixel in the original image
1420 int image_x, image_y;
1421
1422 // Position of the pixel, in terms of tiles
1423 int tile_x, tile_y;
1424
1425 // Position of the pixel, in terms of offset and bitmask
1426 int offset, bitmask;
1427
1428 // Color of the pixel to convert
1429 RGBi rgb;
1430
1431 *(buffer) = _frame_width;
1432 *(buffer+1) = _frame_height;
1433 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1434 *(buffer+2) = (_transparent_color & 0x0f0000) ? 0x01 : 0x00;
1435 }
1436
1437 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1438
1439 adilinebeginbitmap("BMD");
1440
1441 int colorIndex = 0;
1442
1443 // Loop for all the source surface.
1444 for (image_y = 0; image_y < _frame_height; ++image_y) {
1445 for (image_x = 0; image_x < _frame_width; ++image_x) {
1446
1447 // Take the color of the pixel
1448 rgb.red = *_source;
1449 rgb.green = *(_source + 1);
1450 rgb.blue = *(_source + 2);
1451 if ( _depth > 3 ) {
1452 rgb.alpha = *(_source + 3);
1453 } else {
1454 rgb.alpha = 255;
1455 }
1456 if ( rgb.alpha == 0 ) {
1457 rgb.red = 0;
1458 rgb.green = 0;
1459 rgb.blue = 0;
1460 }
1461
1462 if ( rgbi_equals_rgba( &black, &rgb ) || rgb.alpha < 255 ) {
1463 colorIndex = 0;
1464 } else if ( rgbi_equals_rgba( &white, &rgb ) ) {
1465 colorIndex = 1;
1466 } else {
1467 int minDistance = 9999;
1468 for( int i=0; i<2; ++i ) {
1469 int distance = rgbi_distance(&commonPalette[i], &rgb );
1470 if ( distance < minDistance ) {
1471 minDistance = distance;
1472 colorIndex = i;
1473 }
1474 }
1475 }
1476
1477
1478 // printf("%d", i );
1479
1480 // Calculate the offset starting from the tile surface area
1481 // and the bit to set.
1482 offset = ( image_y * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
1483 bitmask = 1 << ( 7 - (image_x & 0x7) );
1484
1485 if ( colorIndex > 0) {
1486 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1487 *( buffer + offset + 3) |= bitmask;
1488 } else {
1489 *( buffer + offset + 2) |= bitmask;
1490 }
1491 // printf("*");
1492 } else {
1493 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1494 *( buffer + offset + 3) &= ~bitmask;
1495 } else {
1496 *( buffer + offset + 2) &= ~bitmask;
1497 }
1498 // printf(" ");
1499 }
1500
1501 if ( _transparent_color & 0x0f0000 ) {
1502 if ( rgb.alpha == 0 ) {
1503 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1504 *( buffer + ( _frame_height * ( _frame_width >> 3 ) ) + offset + 3) |= bitmask;
1505 } else {
1506 *( buffer + ( _frame_height * ( _frame_width >> 3 ) ) + offset + 2) |= bitmask;
1507 }
1508 // printf("*");
1509 } else {
1510 if ( ! _environment->vestigialConfig.rchack_acme_1172 ) {
1511 *( buffer + ( _frame_height * ( _frame_width >> 3 ) ) + offset + 3) &= ~bitmask;
1512 } else {
1513 *( buffer + ( _frame_height * ( _frame_width >> 3 ) ) + offset + 2) &= ~bitmask;
1514 }
1515 // printf(" ");
1516 }
1517 }
1518
1519 adilinepixel(colorIndex);
1520
1521 _source += _depth;
1522
1523 }
1524
1525 _source += ( _width - _frame_width ) * _depth;
1526
1527 // printf("\n" );
1528
1529 }
1530
1532
1533 // printf("----\n");
1534
1535 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1536
1537 // printf("----\n");
1538
1539 return result;
1540
1541}
1542
1543static Variable * c6847_image_converter_multicolor_mode_standard( Environment * _environment, char * _source, int _width, int _height, int _depth, int _offset_x, int _offset_y, int _frame_width, int _frame_height, int _transparent_color, int _flags ) {
1544
1545 RGBi white = { 0xff, 0xff, 0xff, 0xff };
1546 RGBi black = { 0x00, 0x00, 0x00, 0x00 };
1547
1548 // ignored on bitmap mode
1549 (void)!_transparent_color;
1550
1551 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
1552
1553 if ( _environment->freeImageWidth ) {
1554 if ( _width % 8 ) {
1555 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1556 }
1557 if ( _frame_width % 8 ) {
1558 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1559 }
1560 }
1561
1562 RGBi * palette = malloc_palette( MAX_PALETTE );
1563
1564 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1565
1566 if (paletteColorCount > 4) {
1567 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1568 }
1569
1570 int i, j, k;
1571
1572 SYSTEM_PALETTE = &SYSTEM_PALETTE_ALTERNATE[_environment->paletteSelected][0];
1573
1574 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE_ALTERNATE[0]) / sizeof(RGBi) );
1575 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1576 lastUsedSlotInCommonPalette = paletteColorCount;
1577 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1578
1579 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE_ALTERNATE[0]) / sizeof(RGBi)), SYSTEM_PALETTE );
1580
1581 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1583 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1584
1585 int bufferSize = c6847_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_COLOR1, 0 );
1586
1587 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_RESOLUTION1 );
1588
1589 char * buffer = malloc ( bufferSize );
1590 memset( buffer, 0, bufferSize );
1591
1592 // Position of the pixel in the original image
1593 int image_x, image_y;
1594
1595 // Position of the pixel, in terms of tiles
1596 int tile_x, tile_y;
1597
1598 // Position of the pixel, in terms of offset and bitmask
1599 int offset, offsetc, bitmask;
1600
1601 // Color of the pixel to convert
1602 RGBi rgb;
1603
1604 *(buffer) = _frame_width;
1605 *(buffer+1) = _frame_height;
1606 *(buffer+2) = 0;
1607
1608 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1609
1610 adilinebeginbitmap("BMD");
1611
1612 // Loop for all the source surface.
1613 for (image_y = 0; image_y < _frame_height; ++image_y) {
1614 for (image_x = 0; image_x < _frame_width; ++image_x) {
1615
1616 // Take the color of the pixel
1617 rgb.red = *_source;
1618 rgb.green = *(_source + 1);
1619 rgb.blue = *(_source + 2);
1620 if ( _depth > 3 ) {
1621 rgb.alpha = *(_source + 3);
1622 } else {
1623 rgb.alpha = 255;
1624 }
1625 if ( rgb.alpha == 0 ) {
1626 rgb.red = 0;
1627 rgb.green = 0;
1628 rgb.blue = 0;
1629 }
1630
1631 offset = ( image_y * ( _frame_width >> 2 ) ) + ( image_x >> 2 );
1632
1633 int colorIndex = 0;
1634
1635 if ( rgb.alpha < 255 ) {
1636 colorIndex = 0;
1637 } else {
1638 int minDistance = 9999;
1639 for( int i=0; i<lastUsedSlotInCommonPalette; ++i ) {
1640 int distance = rgbi_distance(&commonPalette[i], &rgb );
1641 if ( distance < minDistance ) {
1642 minDistance = distance;
1643 colorIndex = commonPalette[i].index;
1644 }
1645 }
1646 }
1647
1648 adilinepixel(colorIndex);
1649
1650 // printf( "%1.1x", colorIndex );
1651
1652 bitmask = colorIndex << (6 - ((image_x & 0x3) * 2));
1653
1654 *(buffer + 3 + offset) |= bitmask;
1655
1656 _source += _depth;
1657
1658 }
1659
1660 _source += ( _width - _frame_width ) * _depth;
1661
1662 // printf("\n" );
1663 }
1664
1666
1667 // for(i=0; i<4; ++i ) {
1668 // printf( "%1.1x = %2.2x\n", i, palette[i].index );
1669 // }
1670
1671 // printf("\n" );
1672 // printf("\n" );
1673
1674 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1675
1676 return result;
1677
1678}
1679
1680
1681static int sg4_blocks[128][4] = {
1682 {0,0,0,0}, {1,0,0,0}, {0,1,0,0}, {1,1,0,0}, {0,0,1,0}, {1,0,1,0}, {0,1,1,0}, {1,1,1,0}, {0,0,0,1}, {1,0,0,1}, {0,1,0,1}, {1,1,0,1}, {0,0,1,1}, {1,0,1,1}, {0,1,1,1}, {1,1,1,1},
1683 {0,0,0,0}, {2,0,0,0}, {0,2,0,0}, {2,2,0,0}, {0,0,2,0}, {2,0,2,0}, {0,2,2,0}, {2,2,2,0}, {0,0,0,2}, {2,0,0,2}, {0,2,0,2}, {2,2,0,2}, {0,0,2,2}, {2,0,2,2}, {0,2,2,2}, {2,2,2,2},
1684 {0,0,0,0}, {3,0,0,0}, {0,3,0,0}, {3,3,0,0}, {0,0,3,0}, {3,0,3,0}, {0,3,3,0}, {3,3,3,0}, {0,0,0,3}, {3,0,0,3}, {0,3,0,3}, {3,3,0,3}, {0,0,3,3}, {3,0,3,3}, {0,3,3,3}, {3,3,3,3},
1685 {0,0,0,0}, {4,0,0,0}, {0,4,0,0}, {4,4,0,0}, {0,0,4,0}, {4,0,4,0}, {0,4,4,0}, {4,4,4,0}, {0,0,0,4}, {4,0,0,4}, {0,4,0,4}, {4,4,0,4}, {0,0,4,4}, {4,0,4,4}, {0,4,4,4}, {4,4,4,4},
1686 {0,0,0,0}, {5,0,0,0}, {0,5,0,0}, {5,5,0,0}, {0,0,5,0}, {5,0,5,0}, {0,5,5,0}, {5,5,5,0}, {0,0,0,5}, {5,0,0,5}, {0,5,0,5}, {5,5,0,5}, {0,0,5,5}, {5,0,5,5}, {0,5,5,5}, {5,5,5,5},
1687 {0,0,0,0}, {6,0,0,0}, {0,6,0,0}, {6,6,0,0}, {0,0,6,0}, {6,0,6,0}, {0,6,6,0}, {6,6,6,0}, {0,0,0,6}, {6,0,0,6}, {0,6,0,6}, {6,6,0,6}, {0,0,6,6}, {6,0,6,6}, {0,6,6,6}, {6,6,6,6},
1688 {0,0,0,0}, {7,0,0,0}, {0,7,0,0}, {7,7,0,0}, {0,0,7,0}, {7,0,7,0}, {0,7,7,0}, {7,7,7,0}, {0,0,0,7}, {7,0,0,7}, {0,7,0,7}, {7,7,0,7}, {0,0,7,7}, {7,0,7,7}, {0,7,7,7}, {7,7,7,7},
1689 {0,0,0,0}, {8,0,0,0}, {0,8,0,0}, {8,8,0,0}, {0,0,8,0}, {8,0,8,0}, {0,8,8,0}, {8,8,8,0}, {0,0,0,8}, {8,0,0,8}, {0,8,0,8}, {8,8,0,8}, {0,0,8,8}, {8,0,8,8}, {0,8,8,8}, {8,8,8,8}
1690};
1691
1692static int pow2( int _value ) {
1693 return _value*_value;
1694}
1695
1696static int c6847_image_converter_sg4_block( Environment * _environment, char * _source, int _width, int _depth ) {
1697
1698 int x, y, i;
1699
1700 int block[8][12];
1701 int sampled_block[2][2];
1702 int sg4_blocks_distance[128];
1703
1704 memset(block, 0, 8 * 12 * sizeof(int));
1705
1706 for (y = 0; y < 12; ++y) {
1707 for (x = 0; x < 8; ++x) {
1708
1709 RGBi rgb;
1710
1711 // Take the color of the pixel
1712 rgb.red = *_source;
1713 rgb.green = *(_source + 1);
1714 rgb.blue = *(_source + 2);
1715 if ( _depth > 3 ) {
1716 rgb.alpha = *(_source + 3);
1717 } else {
1718 rgb.alpha = 255;
1719 }
1720 if ( rgb.alpha == 0 ) {
1721 rgb.red = 0;
1722 rgb.green = 0;
1723 rgb.blue = 0;
1724 }
1725
1726 // printf( " | %2.2x%2.2x%2.2x = ", rgb.red, rgb.green, rgb.blue );
1727
1728 int colorIndex = 0;
1729
1730 if ( rgb.alpha < 255 ) {
1731 colorIndex = 0;
1732 } else {
1733 int minDistance = 9999;
1734 for( int i=0; i<sizeof(SYSTEM_PALETTE_SG4)/sizeof(RGBi); ++i ) {
1735 int distance = rgbi_distance(&SYSTEM_PALETTE_SG4[i], &rgb );
1736 // printf( " <---> (%d) = %d; ", i, distance );
1737 if ( distance < minDistance ) {
1738 minDistance = distance;
1739 colorIndex = SYSTEM_PALETTE_SG4[i].index;
1740 }
1741 }
1742 }
1743
1744 block[x][y] = colorIndex;
1745
1746 // printf( "%x", colorIndex );
1747
1748 _source += _depth;
1749
1750 }
1751
1752 // printf( "\n" );
1753
1754 _source += ( _width - 8 ) * _depth;
1755
1756 }
1757
1758 for (y = 0; y < 2; ++y) {
1759 for (x = 0; x < 2; ++x) {
1760
1761 int y2, x2;
1762 int colorCount[9];
1763
1764 memset( colorCount, 0, 9 * sizeof( int ) );
1765
1766 for( y2 = 0; y2 < 6; ++y2 ) {
1767 for( x2 = 0; x2 < 4; ++x2 ) {
1768 colorCount[block[4*x+x2][6*y+y2]]++;
1769 }
1770 }
1771
1772 int colorCountMax = 0;
1773 int colorIndex = 0;
1774
1775 for( i = 0; i<9; ++i ) {
1776 if ( colorCount[i] > colorCountMax ) {
1777 colorCountMax = colorCount[i];
1778 colorIndex = i;
1779 }
1780 }
1781
1782 sampled_block[x][y] = colorIndex;
1783
1784 // printf( "%x", colorIndex );
1785
1786 }
1787
1788 // printf( "\n" );
1789
1790 }
1791
1792 int min_sg4_block_distance = 9999;
1793 int min_sg4_block_number = 0;
1794
1795 for( i=0; i<128; ++i ) {
1796 int absoluteDistance =
1797 (int)sqrt(
1798 pow2( sampled_block[0][0] - sg4_blocks[i][3] ) +
1799 pow2( sampled_block[1][0] - sg4_blocks[i][2] ) +
1800 pow2( sampled_block[0][1] - sg4_blocks[i][1] ) +
1801 pow2( sampled_block[1][1] - sg4_blocks[i][0] )
1802 );
1803
1804 int diagonalDistance =
1805 (int)sqrt(
1806 pow2( sampled_block[0][0] - sg4_blocks[i][3] ) +
1807 pow2( sampled_block[1][1] - sg4_blocks[i][0] )
1808 ) +
1809 (int)sqrt(
1810 pow2( sampled_block[1][0] - sg4_blocks[i][2] ) +
1811 pow2( sampled_block[0][1] - sg4_blocks[i][1] )
1812 )
1813 ;
1814
1815 // printf( "%d) absDis = %d, diagDis = %d, * = %d, min = %d\n", i, absoluteDistance, diagonalDistance, (absoluteDistance * diagonalDistance), min_sg4_block_distance );
1816
1817 if ( (absoluteDistance * diagonalDistance) < min_sg4_block_distance ) {
1818 min_sg4_block_distance = (absoluteDistance * diagonalDistance);
1819 min_sg4_block_number = i;
1820 }
1821
1822 }
1823
1824 // printf( "--> %d\n", min_sg4_block_number );
1825
1826 return 0x80 | ( min_sg4_block_number & 0x7f );
1827
1828}
1829
1830static Variable * c6847_image_converter_sg4( 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 ) {
1831
1832 // ignored on bitmap mode
1833 (void)!_transparent_color;
1834
1835 if ( _environment->freeImageWidth ) {
1836 if ( _width % 2 ) {
1837 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1838 }
1839 if ( _frame_width % 2 ) {
1840 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1841 }
1842 }
1843
1844 if ( _environment->freeImageHeight ) {
1845 if ( _height % 2 ) {
1846 _height = ( ( ( _height - 1 ) / 12 ) - 1 ) * 12;
1847 }
1848 if ( _frame_height % 2 ) {
1849 _frame_height = ( ( ( _frame_height - 1 ) / 12 ) - 1 ) * 12;
1850 }
1851 }
1852
1853 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 12 );
1854
1855 RGBi * palette = malloc_palette( MAX_PALETTE );
1856
1857 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1858
1859 if (paletteColorCount > 9) {
1860 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1861 }
1862
1863 int i, j, k;
1864
1865 SYSTEM_PALETTE = &SYSTEM_PALETTE_SG4[0];
1866
1867 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE_SG4) / sizeof(RGBi) );
1868 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1869 lastUsedSlotInCommonPalette = paletteColorCount;
1870 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1871
1872 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE_SG4) / sizeof(RGBi)), SYSTEM_PALETTE );
1873
1874 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1876 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1877
1878 int bufferSize = c6847_image_size( _environment, _frame_width, _frame_height, TILEMAP_MODE_SEMIGRAPHICS4, 0 );
1879
1880 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, TILEMAP_MODE_SEMIGRAPHICS4 );
1881
1882 char * buffer = malloc ( bufferSize );
1883 memset( buffer, 0, bufferSize );
1884
1885 // Position of the pixel in the original image
1886 int image_x, image_y;
1887
1888 // Position of the pixel, in terms of tiles
1889 int tile_x, tile_y;
1890
1891 // Position of the pixel, in terms of offset and bitmask
1892 int offset, offsetc, bitmask;
1893
1894 // Color of the pixel to convert
1895 RGBi rgb;
1896
1897 *(buffer) = _frame_width;
1898 *(buffer+1) = _frame_height / 12;
1899 *(buffer+2) = 0;
1900
1901 _source += ( ( _offset_y * (_width>>3) ) + _offset_x ) * _depth;
1902
1903 adilinebeginbitmap("BMD");
1904
1905 // Loop for all the source surface.
1906 for (image_y = 0; image_y < _frame_height; image_y+=12) {
1907 for (image_x = 0; image_x < _frame_width; image_x+=8) {
1908
1909 // printf( "\n\nx = %d, y = %d\n", image_x, image_y );
1910
1911 offset = ( ( image_y / 12 ) * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
1912
1913 int colorIndex = c6847_image_converter_sg4_block( _environment, _source, _width, _depth );
1914
1915 // printf( "%d\n", offset );
1916 *(buffer + 3 + offset) = colorIndex;
1917
1918 adilinepixel(colorIndex);
1919
1920 _source += 8 * _depth;
1921
1922 }
1923
1924 _source += 12 * _width * _depth;
1925 _source -= _frame_width * _depth;
1926
1927 // printf("\n" );
1928 }
1929
1931
1932 // for(i=0; i<4; ++i ) {
1933 // printf( "%1.1x = %2.2x\n", i, palette[i].index );
1934 // }
1935
1936 // printf("\n" );
1937 // printf("\n" );
1938
1939 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1940
1941 return result;
1942
1943}
1944
1945static int sg6_blocks[256][6] = {
1946{0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0},
1947{0,0,0,0,0,0}, {1,0,0,0,0,0}, {0,1,0,0,0,0}, {1,1,0,0,0,0}, {0,0,1,0,0,0}, {1,0,1,0,0,0}, {0,1,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0,3,3,0}, {3,0,0,3,3,0}, {0,3,0,3,3,0}, {3,3,0,3,3,0}, {0,0,3,3,3,0}, {3,0,3,3,3,0}, {0,3,3,3,3,0}, {3,3,3,3,3,0}, {0,0,0,0,0,3}, {3,0,0,0,0,3}, {0,3,0,0,0,3}, {3,3,0,0,0,3}, {0,0,3,0,0,3}, {3,0,3,0,0,3}, {0,3,3,0,0,3}, {3,3,3,0,0,3}, {0,0,0,3,0,3}, {3,0,0,3,0,3}, {0,3,0,3,0,3}, {3,3,0,3,0,3}, {0,0,3,3,0,3}, {3,0,3,3,0,3}, {0,3,3,3,0,3}, {3,3,3,3,0,3}, {0,0,0,0,3,3}, {3,0,0,0,3,3}, {0,3,0,0,3,3}, {3,3,0,0,3,3}, {0,0,3,0,3,3}, {3,0,3,0,3,3}, {0,3,3,0,3,3}, {3,3,3,0,3,3}, {0,0,0,3,3,3}, {3,0,0,3,3,3}, {0,3,0,3,3,3}, {3,3,0,3,3,3}, {0,0,3,3,3,3}, {3,0,3,3,3,3}, {0,3,3,3,3,3}, {3,3,3,3,3,3},
1950};
1951
1952static int c6847_image_converter_sg6_block( Environment * _environment, char * _source, int _width, int _depth ) {
1953
1954 int x, y, i;
1955
1956 int block[8][12];
1957 int sampled_block[2][3];
1958 int sg6_blocks_distance[256];
1959
1960 memset(block, 0, 8 * 12 * sizeof(int));
1961
1962 for (y = 0; y < 12; ++y) {
1963 for (x = 0; x < 8; ++x) {
1964
1965 RGBi rgb;
1966
1967 // Take the color of the pixel
1968 rgb.red = *_source;
1969 rgb.green = *(_source + 1);
1970 rgb.blue = *(_source + 2);
1971 if ( _depth > 3 ) {
1972 rgb.alpha = *(_source + 3);
1973 } else {
1974 rgb.alpha = 255;
1975 }
1976 if ( rgb.alpha == 0 ) {
1977 rgb.red = 0;
1978 rgb.green = 0;
1979 rgb.blue = 0;
1980 }
1981
1982 // printf( " | %2.2x%2.2x%2.2x = ", rgb.red, rgb.green, rgb.blue );
1983
1984 int colorIndex = 0;
1985
1986 if ( rgb.alpha < 255 ) {
1987 colorIndex = 0;
1988 } else {
1989 int minDistance = 9999;
1990 for( int i=0; i<sizeof(SYSTEM_PALETTE_SG6)/sizeof(RGBi); ++i ) {
1991 int distance = rgbi_distance(&SYSTEM_PALETTE_SG6[i], &rgb );
1992 // printf( " <---> (%d) = %d; ", i, distance );
1993 if ( distance < minDistance ) {
1994 minDistance = distance;
1995 colorIndex = SYSTEM_PALETTE_SG6[i].index;
1996 }
1997 }
1998 }
1999
2000 block[x][y] = colorIndex;
2001
2002 // printf( "%x", colorIndex );
2003
2004 _source += _depth;
2005
2006 }
2007
2008 // printf( "\n" );
2009
2010 _source += ( _width - 8 ) * _depth;
2011
2012 }
2013
2014 for (y = 0; y < 3; ++y) {
2015 for (x = 0; x < 2; ++x) {
2016
2017 int y2, x2;
2018 int colorCount[4];
2019
2020 memset( colorCount, 0, 4 * sizeof( int ) );
2021
2022 for( y2 = 0; y2 < 4; ++y2 ) {
2023 for( x2 = 0; x2 < 4; ++x2 ) {
2024 colorCount[block[4*x+x2][4*y+y2]]++;
2025 }
2026 }
2027
2028 int colorCountMax = 0;
2029 int colorIndex = 0;
2030
2031 for( i = 0; i<4; ++i ) {
2032 if ( colorCount[i] > colorCountMax ) {
2033 colorCountMax = colorCount[i];
2034 colorIndex = i;
2035 }
2036 }
2037
2038 sampled_block[x][y] = colorIndex;
2039
2040 // printf( "%x", colorIndex );
2041
2042 }
2043
2044 // printf( "\n" );
2045
2046 }
2047
2048 int min_sg6_block_distance = 9999;
2049 int min_sg6_block_number = 0;
2050
2051 for( i=0; i<256; ++i ) {
2052 int absoluteDistance =
2053 (int)sqrt(
2054 pow2( sampled_block[0][0] - sg6_blocks[i][5] ) +
2055 pow2( sampled_block[1][0] - sg6_blocks[i][4] ) +
2056 pow2( sampled_block[0][1] - sg6_blocks[i][3] ) +
2057 pow2( sampled_block[1][1] - sg6_blocks[i][2] ) +
2058 pow2( sampled_block[0][2] - sg6_blocks[i][1] ) +
2059 pow2( sampled_block[1][2] - sg6_blocks[i][0] )
2060 );
2061
2062 int diagonalDistance =
2063 (int)sqrt(
2064 pow2( sampled_block[0][0] - sg6_blocks[i][5] ) +
2065 pow2( sampled_block[0][1] - sg6_blocks[i][3] ) +
2066 pow2( sampled_block[1][1] - sg6_blocks[i][2] ) +
2067 pow2( sampled_block[1][2] - sg6_blocks[i][0] )
2068 ) +
2069 (int)sqrt(
2070 pow2( sampled_block[1][0] - sg6_blocks[i][4] ) +
2071 pow2( sampled_block[1][1] - sg6_blocks[i][2] ) +
2072 pow2( sampled_block[1][2] - sg6_blocks[i][0] ) +
2073 pow2( sampled_block[0][2] - sg6_blocks[i][1] )
2074 )
2075 ;
2076
2077 // printf( "%d) absDis = %d, diagDis = %d, * = %d, min = %d\n", i, absoluteDistance, diagonalDistance, (absoluteDistance * diagonalDistance), min_sg6_block_distance );
2078
2079 if ( (absoluteDistance * diagonalDistance) < min_sg6_block_distance ) {
2080 min_sg6_block_distance = (absoluteDistance * diagonalDistance);
2081 min_sg6_block_number = i;
2082 }
2083
2084 }
2085
2086 // printf( "--> %d\n", min_sg6_block_number );
2087
2088 return 0x80 | min_sg6_block_number;
2089
2090}
2091
2092static Variable * c6847_image_converter_sg6( 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 ) {
2093
2094 // ignored on bitmap mode
2095 (void)!_transparent_color;
2096
2097 if ( _environment->freeImageWidth ) {
2098 if ( _width % 2 ) {
2099 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2100 }
2101 if ( _frame_width % 2 ) {
2102 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2103 }
2104 }
2105
2106 if ( _environment->freeImageHeight ) {
2107 if ( _height % 2 ) {
2108 _height = ( ( ( _height - 1 ) / 12 ) - 1 ) * 12;
2109 }
2110 if ( _frame_height % 2 ) {
2111 _frame_height = ( ( ( _frame_height - 1 ) / 12 ) - 1 ) * 12;
2112 }
2113 }
2114
2115 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 12 );
2116
2117 RGBi * palette = malloc_palette( MAX_PALETTE );
2118
2119 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2120
2121 if (paletteColorCount > 5) {
2122 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
2123 }
2124
2125 int i, j, k;
2126
2127 SYSTEM_PALETTE = &SYSTEM_PALETTE_SG6[0];
2128
2129 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE_SG6) / sizeof(RGBi) );
2130 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
2131 lastUsedSlotInCommonPalette = paletteColorCount;
2132 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
2133
2134 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE_SG6) / sizeof(RGBi)), SYSTEM_PALETTE );
2135
2136 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2138 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
2139
2140 int bufferSize = c6847_image_size( _environment, _frame_width, _frame_height, TILEMAP_MODE_SEMIGRAPHICS6, 0 );
2141
2142 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, TILEMAP_MODE_SEMIGRAPHICS6 );
2143
2144 char * buffer = malloc ( bufferSize );
2145 memset( buffer, 0, bufferSize );
2146
2147 // Position of the pixel in the original image
2148 int image_x, image_y;
2149
2150 // Position of the pixel, in terms of tiles
2151 int tile_x, tile_y;
2152
2153 // Position of the pixel, in terms of offset and bitmask
2154 int offset, offsetc, bitmask;
2155
2156 // Color of the pixel to convert
2157 RGBi rgb;
2158
2159 *(buffer) = _frame_width;
2160 *(buffer+1) = _frame_height / 12;
2161 *(buffer+2) = 0;
2162
2163 _source += ( ( _offset_y * (_width>>3) ) + _offset_x ) * _depth;
2164
2165 adilinebeginbitmap("BMD");
2166
2167 // Loop for all the source surface.
2168 for (image_y = 0; image_y < _frame_height; image_y+=12) {
2169 for (image_x = 0; image_x < _frame_width; image_x+=8) {
2170
2171 // printf( "\n\nx = %d, y = %d\n", image_x, image_y );
2172
2173 offset = ( ( image_y / 12 ) * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
2174
2175 int colorIndex = c6847_image_converter_sg6_block( _environment, _source, _width, _depth );
2176
2177 // printf( "%d\n", offset );
2178 *(buffer + 3 + offset) = colorIndex;
2179
2180 adilinepixel(colorIndex);
2181
2182 _source += 8 * _depth;
2183
2184 }
2185
2186 _source += 12 * _width * _depth;
2187 _source -= _frame_width * _depth;
2188
2189 // printf("\n" );
2190 }
2191
2193
2194 // for(i=0; i<4; ++i ) {
2195 // printf( "%1.1x = %2.2x\n", i, palette[i].index );
2196 // }
2197
2198 // printf("\n" );
2199 // printf("\n" );
2200
2201 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2202
2203 return result;
2204
2205}
2206
2207static int sg8_blocks[256*8][8] = {
2208 {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,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,0,7,7,7,0,7,7}, {7,0,7,7,7,0,7,7}, {0,7,7,7,7,0,7,7}, {7,7,7,7,7,0,7,7}, {0,0,0,0,0,7,7,7}, {7,0,0,0,0,7,7,7}, {0,7,0,0,0,7,7,7}, {7,7,0,0,0,7,7,7}, {0,0,7,0,0,7,7,7}, {7,0,7,0,0,7,7,7}, {0,7,7,0,0,7,7,7}, {7,7,7,0,0,7,7,7}, {0,0,0,7,0,7,7,7}, {7,0,0,7,0,7,7,7}, {0,7,0,7,0,7,7,7}, {7,7,0,7,0,7,7,7}, {0,0,7,7,0,7,7,7}, {7,0,7,7,0,7,7,7}, {0,7,7,7,0,7,7,7}, {7,7,7,7,0,7,7,7}, {0,0,0,0,7,7,7,7}, {7,0,0,0,7,7,7,7}, {0,7,0,0,7,7,7,7}, {7,7,0,0,7,7,7,7}, {0,0,7,0,7,7,7,7}, {7,0,7,0,7,7,7,7}, {0,7,7,0,7,7,7,7}, {7,7,7,0,7,7,7,7}, {0,0,0,7,7,7,7,7}, {7,0,0,7,7,7,7,7}, {0,7,0,7,7,7,7,7}, {7,7,0,7,7,7,7,7}, {0,0,7,7,7,7,7,7}, {7,0,7,7,7,7,7,7}, {0,7,7,7,7,7,7,7}, {7,7,7,7,7,7,7,7}
2216};
2217
2218static int c6847_image_converter_sg8_block( Environment * _environment, char * _source, int _width, int _depth ) {
2219
2220 int x, y, i;
2221
2222 int block[8][12];
2223 int sampled_block[2][3];
2224 int sg8_blocks_distance[256];
2225
2226 memset(block, 0, 8 * 12 * sizeof(int));
2227
2228 for (y = 0; y < 12; ++y) {
2229 for (x = 0; x < 8; ++x) {
2230
2231 RGBi rgb;
2232
2233 // Take the color of the pixel
2234 rgb.red = *_source;
2235 rgb.green = *(_source + 1);
2236 rgb.blue = *(_source + 2);
2237 if ( _depth > 3 ) {
2238 rgb.alpha = *(_source + 3);
2239 } else {
2240 rgb.alpha = 255;
2241 }
2242 if ( rgb.alpha == 0 ) {
2243 rgb.red = 0;
2244 rgb.green = 0;
2245 rgb.blue = 0;
2246 }
2247
2248 // printf( " | %2.2x%2.2x%2.2x = ", rgb.red, rgb.green, rgb.blue );
2249
2250 int colorIndex = 0;
2251
2252 if ( rgb.alpha < 255 ) {
2253 colorIndex = 0;
2254 } else {
2255 int minDistance = 9999;
2256 for( int i=0; i<sizeof(SYSTEM_PALETTE_SG8)/sizeof(RGBi); ++i ) {
2257 int distance = rgbi_distance(&SYSTEM_PALETTE_SG8[i], &rgb );
2258 if ( distance < minDistance ) {
2259 minDistance = distance;
2260 colorIndex = SYSTEM_PALETTE_SG8[i].index;
2261 }
2262 }
2263 }
2264
2265 block[x][y] = colorIndex;
2266
2267 // printf( "%x", colorIndex );
2268
2269 _source += _depth;
2270
2271 }
2272
2273 // printf( "\n" );
2274
2275 _source += ( _width - 8 ) * _depth;
2276
2277 }
2278
2279 for (y = 0; y < 4; ++y) {
2280 for (x = 0; x < 2; ++x) {
2281
2282 int y2, x2;
2283 int colorCount[4];
2284
2285 memset( colorCount, 0, 6 * sizeof( int ) );
2286
2287 for( y2 = 0; y2 < 3; ++y2 ) {
2288 for( x2 = 0; x2 < 2; ++x2 ) {
2289 colorCount[block[4*x+x2][3*y+y2]]++;
2290 }
2291 }
2292
2293 int colorCountMax = 0;
2294 int colorIndex = 0;
2295
2296 for( i = 0; i<4; ++i ) {
2297 if ( colorCount[i] > colorCountMax ) {
2298 colorCountMax = colorCount[i];
2299 colorIndex = i;
2300 }
2301 }
2302
2303 sampled_block[x][y] = colorIndex;
2304
2305 // printf( "%x", colorIndex );
2306
2307 }
2308
2309 // printf( "\n" );
2310
2311 }
2312
2313 int min_sg8_block_distance = 9999;
2314 int min_sg8_block_number = 0;
2315
2316 for( i=0; i<256*8; ++i ) {
2317 int absoluteDistance =
2318 (int)sqrt(
2319 pow2( sampled_block[0][0] - sg8_blocks[i][5] ) +
2320 pow2( sampled_block[1][0] - sg8_blocks[i][4] ) +
2321 pow2( sampled_block[0][1] - sg8_blocks[i][3] ) +
2322 pow2( sampled_block[1][1] - sg8_blocks[i][2] ) +
2323 pow2( sampled_block[0][2] - sg8_blocks[i][1] ) +
2324 pow2( sampled_block[1][2] - sg8_blocks[i][0] )
2325 );
2326
2327 int diagonalDistance =
2328 (int)sqrt(
2329 pow2( sampled_block[0][0] - sg8_blocks[i][5] ) +
2330 pow2( sampled_block[0][1] - sg8_blocks[i][3] ) +
2331 pow2( sampled_block[1][1] - sg8_blocks[i][2] ) +
2332 pow2( sampled_block[1][2] - sg8_blocks[i][0] )
2333 ) +
2334 (int)sqrt(
2335 pow2( sampled_block[1][0] - sg8_blocks[i][4] ) +
2336 pow2( sampled_block[1][1] - sg8_blocks[i][2] ) +
2337 pow2( sampled_block[1][2] - sg8_blocks[i][0] ) +
2338 pow2( sampled_block[0][2] - sg8_blocks[i][1] )
2339 )
2340 ;
2341
2342 // printf( "%d) absDis = %d, diagDis = %d, * = %d, min = %d\n", i, absoluteDistance, diagonalDistance, (absoluteDistance * diagonalDistance), min_sg8_block_distance );
2343
2344 if ( (absoluteDistance * diagonalDistance) < min_sg8_block_distance ) {
2345 min_sg8_block_distance = (absoluteDistance * diagonalDistance);
2346 min_sg8_block_number = i;
2347 }
2348
2349 }
2350
2351 // printf( "--> %d\n", min_sg8_block_number );
2352
2353 return 0x80 | min_sg8_block_number;
2354
2355}
2356
2357static Variable * c6847_image_converter_sg8( 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 ) {
2358
2359 // ignored on bitmap mode
2360 (void)!_transparent_color;
2361
2362 if ( _environment->freeImageWidth ) {
2363 if ( _width % 2 ) {
2364 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2365 }
2366 if ( _frame_width % 2 ) {
2367 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2368 }
2369 }
2370
2371 if ( _environment->freeImageHeight ) {
2372 if ( _height % 2 ) {
2373 _height = ( ( ( _height - 1 ) / 12 ) - 1 ) * 12;
2374 }
2375 if ( _frame_height % 2 ) {
2376 _frame_height = ( ( ( _frame_height - 1 ) / 12 ) - 1 ) * 12;
2377 }
2378 }
2379
2380 image_converter_asserts( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8, 12 );
2381
2382 RGBi * palette = malloc_palette( MAX_PALETTE );
2383
2384 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2385
2386 if (paletteColorCount > 5) {
2387 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
2388 }
2389
2390 int i, j, k;
2391
2392 SYSTEM_PALETTE = &SYSTEM_PALETTE_SG6[0];
2393
2394 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE_SG6) / sizeof(RGBi) );
2395 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
2396 lastUsedSlotInCommonPalette = paletteColorCount;
2397 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
2398
2399 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE_SG6) / sizeof(RGBi)), SYSTEM_PALETTE );
2400
2401 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2403 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
2404
2405 int bufferSize = c6847_image_size( _environment, _frame_width, _frame_height, TILEMAP_MODE_SEMIGRAPHICS6, 0 );
2406
2407 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, TILEMAP_MODE_SEMIGRAPHICS6 );
2408
2409 char * buffer = malloc ( bufferSize );
2410 memset( buffer, 0, bufferSize );
2411
2412 // Position of the pixel in the original image
2413 int image_x, image_y;
2414
2415 // Position of the pixel, in terms of tiles
2416 int tile_x, tile_y;
2417
2418 // Position of the pixel, in terms of offset and bitmask
2419 int offset, offsetc, bitmask;
2420
2421 // Color of the pixel to convert
2422 RGBi rgb;
2423
2424 *(buffer) = _frame_width;
2425 *(buffer+1) = _frame_height / 12;
2426 *(buffer+2) = 0;
2427
2428 _source += ( ( _offset_y * (_width>>3) ) + _offset_x ) * _depth;
2429
2430 adilinebeginbitmap("BMD");
2431
2432 // Loop for all the source surface.
2433 for (image_y = 0; image_y < _frame_height; image_y+=12) {
2434 for (image_x = 0; image_x < _frame_width; image_x+=8) {
2435
2436 // printf( "\n\nx = %d, y = %d\n", image_x, image_y );
2437
2438 offset = ( ( image_y / 12 ) * ( _frame_width >> 3 ) ) + ( image_x >> 3 );
2439
2440 int colorIndex = c6847_image_converter_sg8_block( _environment, _source, _width, _depth );
2441
2442 // printf( "%d\n", offset );
2443 *(buffer + 3 + offset) = colorIndex;
2444
2445 adilinepixel(colorIndex);
2446
2447 _source += 8 * _depth;
2448
2449 }
2450
2451 _source += 12 * _width * _depth;
2452 _source -= _frame_width * _depth;
2453
2454 // printf("\n" );
2455 }
2456
2458
2459 // for(i=0; i<4; ++i ) {
2460 // printf( "%1.1x = %2.2x\n", i, palette[i].index );
2461 // }
2462
2463 // printf("\n" );
2464 // printf("\n" );
2465
2466 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2467
2468 return result;
2469
2470}
2471
2472Variable * c6847_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 ) {
2473
2474 switch( _mode ) {
2475 case TILEMAP_MODE_INTERNAL: // Alphanumeric Internal 32 × 16 2 512
2476 case TILEMAP_MODE_EXTERNAL: // Alphanumeric External 32 × 16 2 512
2477 break;
2478 case TILEMAP_MODE_SEMIGRAPHICS4: // Semigraphics 4 64 × 32 8 512
2479 return c6847_image_converter_sg4( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2480
2481 break;
2482 case TILEMAP_MODE_SEMIGRAPHICS6: // Semigraphics 6 64 × 48 4 512
2483 return c6847_image_converter_sg6( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2484
2485 break;
2486 case TILEMAP_MODE_SEMIGRAPHICS8: // Semigraphics 8 64 × 64 2 512
2487 return c6847_image_converter_sg8( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2488
2489 break;
2490 case TILEMAP_MODE_SEMIGRAPHICS12: // Semigraphics 6 64 × 96 1 3072
2491 case TILEMAP_MODE_SEMIGRAPHICS24: // Semigraphics 6 64 × 96 1 3072
2492 break;
2493 case BITMAP_MODE_COLOR1: // Color Graphics 1 64 × 64 4 1024
2494 case BITMAP_MODE_COLOR2: // Color Graphics 2 128 × 64 4 2048
2495 case BITMAP_MODE_COLOR3: // Color Graphics 3 128 × 96 4 3072
2496 case BITMAP_MODE_COLOR6: // Color Graphics 6 128 × 192 4 6144
2497
2498 return c6847_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2499
2500 break;
2501
2502 case BITMAP_MODE_RESOLUTION1: // Resolution Graphics 1 128 × 64 1 + Black 1024
2503 case BITMAP_MODE_RESOLUTION2: // Resolution Graphics 2 128 × 96 1 + Black 1536
2504 case BITMAP_MODE_RESOLUTION3: // Resolution Graphics 3 128 × 192 1 + Black 3072
2505 case BITMAP_MODE_RESOLUTION6: // Resolution Graphics 6 256 × 192 1 + Black 6144 break;
2506
2507 return c6847_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
2508
2509 }
2510
2512
2513 return c6847_new_image( _environment, 8, 8, BITMAP_MODE_RESOLUTION6 );
2514
2515}
2516
2517static void c6847_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2518
2519 if ( !_sequence && !_frame ) {
2520 if ( _source->isAddress ) {
2521 outline1("LDY %s", _source->realName );
2522 outline1("STY %s", _register );
2523 } else {
2524 outline1("LDY #%s", _source->realName );
2525 outline1("STY %s", _register );
2526 }
2527 } else {
2528
2529 if ( _source->isAddress ) {
2530 outline1("LDY %s", _source->realName );
2531 } else {
2532 outline1("LDY #%s", _source->realName );
2533 }
2534
2535 if ( _sequence ) {
2536 outline0("LEAY 3,y" );
2537 if ( strlen(_sequence) == 0 ) {
2538 } else {
2539 outline1("LDB %s", _sequence );
2540 outline1("JSR %soffsetsequence", _source->realName );
2541 }
2542 if ( _frame ) {
2543 if ( strlen(_frame) == 0 ) {
2544 } else {
2545 outline1("LDB %s", _frame );
2546 outline1("JSR %soffsetframe", _source->realName );
2547 }
2548 }
2549 } else {
2550 if ( _frame ) {
2551 outline0("LEAY 3,y" );
2552 if ( strlen(_frame) == 0 ) {
2553 } else {
2554 outline1("LDB %s", _frame );
2555 outline1("JSR %soffsetframe", _source->realName );
2556 }
2557 }
2558 }
2559
2560 outline1("STY %s", _register );
2561
2562 }
2563
2564}
2565
2566void c6847_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 ) {
2567
2568 deploy_preferred( c6847vars, src_hw_6847_vars_asm);
2569 deploy( blitimage, src_hw_6847_blit_image_asm );
2570
2571 if ( _source_count > 2 ) {
2573 }
2574
2576
2577 outhead1("blitimage%s", label);
2578
2579 outline1("LDY #%s", _blit );
2580 outline0("STY BLITIMAGEBLITADDR" );
2581
2582 if ( _source_count > 0 ) {
2583 Resource resource;
2584 resource.realName = strdup( _sources[0] );
2585 resource.isAddress = 0;
2586 resource.type = VT_IMAGE;
2587 c6847_load_image_address_to_register( _environment, "BLITTMPPTR", &resource, _sequence, _frame, _frame_size, _frame_count );
2588 } else {
2589 outline0( "LDY #0" );
2590 outline0( "STY BLITTMPPTR" );
2591 }
2592
2593 if ( _source_count > 1 ) {
2594 Resource resource;
2595 resource.realName = strdup( _sources[1] );
2596 resource.isAddress = 0;
2597 resource.type = VT_IMAGE;
2598 c6847_load_image_address_to_register( _environment, "BLITTMPPTR2", &resource, _sequence, _frame, _frame_size, _frame_count );
2599 } else {
2600 outline0( "LDY #0" );
2601 outline0( "STY BLITTMPPTR2" );
2602 }
2603
2604 outline1("LDD %s", _x );
2605 outline0("STD <IMAGEX" );
2606 outline1("LDD %s", _y );
2607 outline0("STD <IMAGEY" );
2608
2609 outline1("LDA #$%2.2x", ( _flags & 0xff ) );
2610 outline0("STA <IMAGEF" );
2611 outline1("LDA #$%2.2x", ( (_flags>>8) & 0xff ) );
2612 outline0("STA <IMAGET" );
2613
2614 outline0("JSR BLITIMAGE");
2615
2616}
2617
2618void c6847_put_image( Environment * _environment, Resource * _source, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
2619
2620 deploy_preferred( c6847vars, src_hw_6847_vars_asm);
2621 deploy( putimage, src_hw_6847_put_image_asm );
2622
2623 if ( _source->isAddress ) {
2624 outline1("LDY %s", _source->realName );
2625 } else {
2626 outline1("LDY #%s", _source->realName );
2627 }
2628
2629 if ( _frame_size ) {
2630 if ( !_sequence && !_frame ) {
2631 } else {
2632 if ( _sequence ) {
2633 outline0("LEAY 3,y" );
2634 if ( strlen(_sequence) == 0 ) {
2635 } else {
2636 outline1("LDB %s", _sequence );
2637 outline1("JSR %soffsetsequence", _source->realName );
2638 }
2639 if ( _frame ) {
2640 if ( strlen(_frame) == 0 ) {
2641 } else {
2642 outline1("LDB %s", _frame );
2643 outline1("JSR %soffsetframe", _source->realName );
2644 }
2645 }
2646 } else {
2647 if ( _frame ) {
2648 outline0("LEAY 3,y" );
2649 if ( strlen(_frame) == 0 ) {
2650 } else {
2651 outline1("LDB %s", _frame );
2652 outline1("JSR %soffsetframe", _source->realName );
2653 }
2654 }
2655 }
2656
2657 }
2658 }
2659
2660 outline1("LDD %s", _x );
2661 outline0("STD <IMAGEX" );
2662 outline1("LDD %s", _y );
2663 outline0("STD <IMAGEY" );
2664
2665 outline1("LDD %s", _flags );
2666 outline0("STB <IMAGEF" );
2667 outline0("STA <IMAGET" );
2668
2669 outline0("JSR PUTIMAGE");
2670
2671}
2672
2673Variable * c6847_new_image( Environment * _environment, int _width, int _height, int _mode ) {
2674
2675 int size = c6847_image_size( _environment, _width, _height, _mode, 0 );
2676
2677 if ( ! size ) {
2679 }
2680
2681 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
2682
2683 char * buffer = malloc ( size );
2684 memset( buffer, 0, size );
2685
2686 *(buffer) = _width;
2687 *(buffer+1) = _height;
2688 *(buffer+2) = 0;
2689
2690 result->valueBuffer = buffer;
2691 result->size = size;
2692
2693 return result;
2694
2695}
2696
2697Variable * c6847_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2698
2699 int size = calculate_images_size( _environment, _frames, _width, _height, _mode, 0 );
2700 int frameSize = c6847_image_size( _environment, _width, _height, _mode, 0 );
2701
2702 if ( ! size ) {
2704 }
2705
2706 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
2707
2708 char * buffer = malloc ( size );
2709 memset( buffer, 0, size );
2710
2711 *(buffer) = _frames;
2712 *(buffer+1) = ( _width & 0xff );
2713 *(buffer+2) = ( _width >> 8 ) & 0xff;
2714 for( int i=0; i<_frames; ++i ) {
2715 *(buffer+3+(i*frameSize)) = _width;
2716 *(buffer+3+(i*frameSize)+1) = _height;
2717 }
2718
2719 result->valueBuffer = buffer;
2720 result->frameSize = frameSize;
2721 result->size = size;
2722 result->frameCount = _frames;
2723
2724 return result;
2725
2726}
2727
2728Variable * c6847_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2729
2730 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode, 0 );
2731 int size = calculate_images_size( _environment, _frames, _width, _height, _mode, 0 );
2732 int frameSize = c6847_image_size( _environment, _width, _height, _mode, 0 );
2733
2734 if ( ! size ) {
2736 }
2737
2738 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
2739
2740 char * buffer = malloc ( size2 );
2741 memset( buffer, 0, size2 );
2742
2743 *(buffer) = _frames;
2744 *(buffer+1) = _width;
2745 *(buffer+2) = _sequences;
2746 for( int i=0; i<(_frames * _sequences); ++i ) {
2747 *(buffer+3+(i*frameSize)) = _width;
2748 *(buffer+3+(i*frameSize)+1) = _height;
2749 }
2750
2751 result->valueBuffer = buffer;
2752 result->frameSize = frameSize;
2753 result->size = size2;
2754 result->frameCount = _frames;
2755
2756 return result;
2757
2758}
2759
2760void c6847_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
2761
2762 deploy_preferred( c6847vars, src_hw_6847_vars_asm);
2763 deploy( getimage, src_hw_6847_get_image_asm );
2764
2765 outline1("LDY #%s", _image );
2766 if ( _sequence ) {
2767 outline0("LEAY 3,y" );
2768 if ( strlen(_sequence) == 0 ) {
2769 } else {
2770 outline1("LDX #OFFSETS%4.4x", _frame_count * _frame_size );
2771 outline1("LDB %s", _sequence );
2772 outline0("LDA #0" );
2773 outline0("ABX" );
2774 outline0("ABX" );
2775 outline0("LDD ,X" );
2776 outline0("LEAY D, Y" );
2777 }
2778 if ( _frame ) {
2779 if ( strlen(_frame) == 0 ) {
2780 } else {
2781 outline1("LDX #OFFSETS%4.4x", _frame_size );
2782 outline1("LDB %s", _frame );
2783 outline0("LDA #0" );
2784 outline0("ABX" );
2785 outline0("ABX" );
2786 outline0("LDD ,X" );
2787 outline0("LEAY D, Y" );
2788 }
2789 }
2790 } else {
2791 if ( _frame ) {
2792 outline0("LEAY 3,y" );
2793 if ( strlen(_frame) == 0 ) {
2794 } else {
2795 outline1("LDX #OFFSETS%4.4x", _frame_size );
2796 outline1("LDB %s", _frame );
2797 outline0("LDA #0" );
2798 outline0("ABX" );
2799 outline0("ABX" );
2800 outline0("LDD ,X" );
2801 outline0("LEAY D, Y" );
2802 }
2803 }
2804 }
2805
2806 outline1("LDD %s", _x );
2807 outline0("STD <IMAGEX" );
2808 outline1("LDD %s", _y );
2809 outline0("STD <IMAGEY" );
2810 outline1("LDA #$%2.2x", _palette );
2811 outline0("STA <IMAGET");
2812
2813 outline0("JSR GETIMAGE");
2814
2815}
2816
2817void c6847_scroll( Environment * _environment, int _dx, int _dy ) {
2818
2819}
2820
2821void c6847_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
2822
2823}
2824
2825void c6847_tile_at( Environment * _environment, char * _x, char * _y, char * _result ) {
2826
2827}
2828
2829void c6847_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
2830
2831}
2832
2833void c6847_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
2834
2835
2836}
2837
2838void c6847_use_tileset( Environment * _environment, char * _tileset ) {
2839
2840}
2841
2843
2844 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
2845
2846 variable_store( _environment, result->name, 0 );
2847
2848 return result;
2849
2850}
2851
2852void c6847_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
2853
2854}
2855
2856int c6847_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
2857
2858 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2859
2860 SYSTEM_PALETTE = &SYSTEM_PALETTE_ALTERNATE[_environment->paletteSelected][0];
2861
2862 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
2863
2864 int uniquePaletteCount = 0;
2865
2866 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
2867
2868 return uniquePaletteCount;
2869
2870}
2871
2872void c6847_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
2873
2874 outline0("LDY #$0" );
2875 if ( _sequence ) {
2876 outline0("LEAY 3,y" );
2877 if ( strlen(_sequence) == 0 ) {
2878 } else {
2879 outline1("LDX #OFFSETS%4.4x", _frame_count * _frame_size );
2880 outline1("LDB %s", _sequence );
2881 outline0("LDA #0" );
2882 outline0("ABX" );
2883 outline0("ABX" );
2884 outline0("LDD ,X" );
2885 outline0("LEAY D, Y" );
2886 }
2887 if ( _frame ) {
2888 if ( strlen(_frame) == 0 ) {
2889 } else {
2890 outline1("LDX #OFFSETS%4.4x", _frame_size );
2891 outline1("LDB %s", _frame );
2892 outline0("LDA #0" );
2893 outline0("ABX" );
2894 outline0("ABX" );
2895 outline0("LDD ,X" );
2896 outline0("LEAY D, Y" );
2897 }
2898 }
2899 } else {
2900 if ( _frame ) {
2901 outline0("LEAY 3,y" );
2902 if ( strlen(_frame) == 0 ) {
2903 } else {
2904 outline1("LDX #OFFSETS%4.4x", _frame_size );
2905 outline1("LDB %s", _frame );
2906 outline0("LDA #0" );
2907 outline0("ABX" );
2908 outline0("ABX" );
2909 outline0("LDD ,X" );
2910 outline0("LEAY D, Y" );
2911 }
2912 }
2913 }
2914
2915 outline1("STY %s", _offset );
2916
2917}
2918
2919void c6847_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
2920
2921 deploy_preferred( c6847vars, src_hw_6847_vars_asm);
2922
2923 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0001" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
2924 c6847_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
2925 deploy( flipimagex, src_hw_6847_flip_image_x_asm );
2926 outline0("JSR FLIPIMAGEX");
2927 } else {
2928
2930
2931 c6847_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
2932 deploy( flipimagex, src_hw_6847_flip_image_x_asm );
2933 outline1("LDA %s", _direction );
2934 outline1("ANDA #$%2.2x", FLAG_FLIP_X );
2935 outline1("BEQ %s", label );
2936 outline0("JSR FLIPIMAGEX");
2937 outhead1("%s", label );
2938
2939 }
2940
2941 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0002" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
2942 c6847_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
2943 deploy( flipimagey, src_hw_6847_flip_image_y_asm );
2944 outline0("JSR FLIPIMAGEY");
2945 } else {
2946
2948
2949 c6847_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
2950 deploy( flipimagey, src_hw_6847_flip_image_y_asm );
2951 outline1("LDA %s", _direction );
2952 outline1("ANDA #$%2.2x", FLAG_FLIP_Y );
2953 outline1("BEQ %s", label );
2954 outline0("JSR FLIPIMAGEY");
2955 outhead1("%s", label );
2956
2957 }
2958
2959}
2960
2961void c6847_screen( Environment * _environment, char * _x, char * _y, char * _c ) {
2962
2963 deploy( screen, src_hw_6847_screen_asm);
2964
2965 outline1("LDA %s", _x );
2966 outline1("LDB %s", _y );
2967 outline0("JSR SCREEN" );
2968 outline1("STA %s", _c );
2969
2970}
2971#endif
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void c6847_bitmap_disable(Environment *_environment)
Definition 6847.c:755
void c6847_sprite_enable(Environment *_environment, char *_sprite)
Definition 6847.c:893
void c6847_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition 6847.c:735
void c6847_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition 6847.c:759
void c6847_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition 6847.c:2821
int lastUsedSlotInCommonPalette
Definition 6847.c:100
void c6847_scroll(Environment *_environment, int _dx, int _dy)
Definition 6847.c:2817
void c6847_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6847.c:2825
void c6847_hit(Environment *_environment, char *_sprite_mask, char *_result)
VIC-II: emit code to check for collision
Definition 6847.c:132
Variable * c6847_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition 6847.c:2728
void c6847_textmap_at(Environment *_environment, char *_address)
Definition 6847.c:791
void c6847_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 6847.c:2566
int c6847_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition 6847.c:2856
void c6847_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition 6847.c:2833
void c6847_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition 6847.c:901
void c6847_screen_rows(Environment *_environment, char *_rows)
Definition 6847.c:877
int c6847_image_size(Environment *_environment, int _width, int _height, int _mode, int _transparent)
Definition 6847.c:1231
void c6847_put_image(Environment *_environment, Resource *_source, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition 6847.c:2618
void c6847_sprite_data_from(Environment *_environment, char *_sprite, char *_address)
Definition 6847.c:885
void c6847_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition 6847.c:2852
void c6847_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition 6847.c:889
void c6847_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition 6847.c:1172
void c6847_back(Environment *_environment)
Definition 6847.c:1201
void c6847_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
VIC-II: emit code to change common sprite's color
Definition 6847.c:199
void c6847_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition 6847.c:2919
void c6847_tiles_at(Environment *_environment, char *_address)
Definition 6847.c:937
void c6847_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition 6847.c:933
void c6847_initialization(Environment *_environment)
Definition 6847.c:1059
void c6847_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition 6847.c:2872
void c6847_use_tileset(Environment *_environment, char *_tileset)
Definition 6847.c:2838
Variable * c6847_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition 6847.c:2673
void c6847_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition 6847.c:905
void c6847_tiles_get(Environment *_environment, char *_result)
Definition 6847.c:956
void c6847_sprite_multicolor(Environment *_environment, char *_sprite)
Definition 6847.c:925
void c6847_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition 6847.c:909
void c6847_screen_columns(Environment *_environment, char *_columns)
Definition 6847.c:881
void c6847_next_raster(Environment *_environment)
VIC-II: emit code to wait for next raster irq
Definition 6847.c:232
int c6847_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition 6847.c:325
void c6847_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition 6847.c:917
void c6847_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition 6847.c:798
void c6847_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition 6847.c:921
void c6847_background_color(Environment *_environment, char *_index, char *_background_color)
VIC-II: emit code to change background color
Definition 6847.c:171
Variable * c6847_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 6847.c:2472
void console_calculate_vars(Environment *_environment)
Definition 6847.c:316
void c6847_get_width(Environment *_environment, char *_result)
Definition 6847.c:949
void c6847_bitmap_at(Environment *_environment, char *_address)
Definition 6847.c:780
void c6847_cls(Environment *_environment)
Definition 6847.c:970
Variable * c6847_get_raster_line(Environment *_environment)
Definition 6847.c:2842
void c6847_collision(Environment *_environment, char *_sprite_mask, char *_result)
VIC-II: emit code to check for collision
Definition 6847.c:117
void c6847_colormap_at(Environment *_environment, char *_address)
Definition 6847.c:787
void c6847_border_color(Environment *_environment, char *_border_color)
VIC-II: emit code to change border color
Definition 6847.c:145
void c6847_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
VIC-II: emit code to wait for next raster irq at different position
Definition 6847.c:249
void c6847_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition 6847.c:982
void c6847_horizontal_scroll(Environment *_environment, char *_displacement)
Definition 6847.c:945
void c6847_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition 6847.c:2760
void c6847_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition 6847.c:1021
Variable * c6847_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition 6847.c:2697
void c6847_sprite_disable(Environment *_environment, char *_sprite)
Definition 6847.c:897
void c6847_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
VIC-II: emit code to set raster irq
Definition 6847.c:218
void c6847_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition 6847.c:821
void c6847_screen_off(Environment *_environment)
Definition 6847.c:873
void c6847_cline(Environment *_environment, char *_characters)
Definition 6847.c:1205
void c6847_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition 6847.c:848
void c6847_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition 6847.c:913
#define SET_VIDEOAT_0400
Definition 6847.c:259
void c6847_finalization(Environment *_environment)
Definition 6847.c:1155
void c6847_screen_on(Environment *_environment)
Definition 6847.c:869
void c6847_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition 6847.c:1001
void c6847_bank_select(Environment *_environment, int _bank)
Definition 6847.c:253
void c6847_get_height(Environment *_environment, char *_result)
Definition 6847.c:963
void console_calculate(Environment *_environment)
Definition 6847.c:262
void c6847_sprite_monocolor(Environment *_environment, char *_sprite)
Definition 6847.c:929
void c6847_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition 6847.c:1188
void c6847_vertical_scroll(Environment *_environment, char *_displacement)
Definition 6847.c:941
void c6847_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition 6847.c:2829
void c6847_screen(Environment *_environment, char *_x, char *_y, char *_c)
Definition 6847.c:2961
#define GM2_SET
Definition 6847.h:141
#define VDG_TEXT
Definition 6847.h:150
#define BITMAP_MODE_RESOLUTION6
Definition 6847.h:93
#define BITMAP_MODE_RESOLUTION2
Definition 6847.h:89
#define SAM_V0_SET
Definition 6847.h:116
#define BITMAP_MODE_COLOR2
Definition 6847.h:88
#define BITMAP_MODE_COLOR1
Definition 6847.h:86
#define TILEMAP_MODE_SEMIGRAPHICS6
Definition 6847.h:81
#define SAM_V2_SET
Definition 6847.h:120
#define GM1_CLR
Definition 6847.h:140
#define SAM_V0_CLR
Definition 6847.h:115
#define CSS_SET
Definition 6847.h:144
#define TILEMAP_MODE_INTERNAL
Definition 6847.h:77
#define BITMAP_MODE_COLOR6
Definition 6847.h:92
#define GM2_CLR
Definition 6847.h:142
#define TILEMAP_MODE_EXTERNAL
Definition 6847.h:78
#define BITMAP_MODE_COLOR3
Definition 6847.h:90
#define TILEMAP_MODE_SEMIGRAPHICS8
Definition 6847.h:82
#define TILEMAP_MODE_SEMIGRAPHICS4
Definition 6847.h:80
#define VDG_GRAPH
Definition 6847.h:149
#define BITMAP_MODE_RESOLUTION3
Definition 6847.h:91
#define SAM_V1_CLR
Definition 6847.h:117
#define GM1_SET
Definition 6847.h:139
#define GM0_CLR
Definition 6847.h:138
#define GM0_SET
Definition 6847.h:137
#define CSS_CLR
Definition 6847.h:145
#define TILEMAP_MODE_SEMIGRAPHICS12
Definition 6847.h:83
#define BITMAP_MODE_RESOLUTION1
Definition 6847.h:87
#define SAM_V1_SET
Definition 6847.h:118
#define SAM_V2_CLR
Definition 6847.h:119
#define TILEMAP_MODE_SEMIGRAPHICS24
Definition 6847.h:84
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
int rgbi_equals_rgba(RGBi *_first, RGBi *_second)
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 * malloc_palette(int _size)
Allocate a palette space.
void variable_global(Environment *_environment, char *_pattern)
ScreenMode * find_screen_mode_by_suggestion(Environment *_environment, int _bitmap, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
void font_descriptors_init(Environment *_environment, int _embedded_present)
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
void image_converter_asserts(Environment *_environment, int _width, int _height, int _offset_x, int _offset_y, int *_frame_width, int *_frame_height, int _modulo_x, int _modulo_y)
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 plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
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 screenTilesWidth
Definition ugbc.h:2880
int screenShades
Definition ugbc.h:2865
int fontHeight
Definition ugbc.h:2905
Console activeConsole
Definition ugbc.h:2910
int freeImageWidth
Definition ugbc.h:3088
int currentMode
Definition ugbc.h:2696
int screenTilesHeight
Definition ugbc.h:2885
int consoleTilesHeight
Definition ugbc.h:2895
int fontWidth
Definition ugbc.h:2900
CopperList * copperList
Definition ugbc.h:3282
int paletteSelected
Definition ugbc.h:2975
int screenColors
Definition ugbc.h:2870
int dynamicConsole
Definition ugbc.h:3298
FontConfig fontConfig
Definition ugbc.h:2415
int screenHeight
Definition ugbc.h:2860
int consoleTilesWidth
Definition ugbc.h:2890
int currentTileMode
Definition ugbc.h:2706
int screenTiles
Definition ugbc.h:2875
int freeImageHeight
Definition ugbc.h:3086
int screenWidth
Definition ugbc.h:2855
VestigialConfig vestigialConfig
Definition ugbc.h:2442
int schema
Definition ugbc.h:2063
unsigned char red
Definition ugbc.h:433
unsigned char green
Definition ugbc.h:434
unsigned char blue
Definition ugbc.h:435
unsigned char alpha
Definition ugbc.h:436
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
char * name
Definition ugbc.h:979
int originalColors
Definition ugbc.h:1154
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
char rchack_acme_1172
Definition ugbc.h:2015
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.
struct _Environment Environment
Structure of compilation environment.
#define FLAG_FLIP_X
Definition ugbc.h:4553
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_SBYTE
Definition ugbc.h:452
@ VT_IMAGES
Definition ugbc.h:495
@ VT_COLOR
Definition ugbc.h:471
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define adiline3(s, a, b, c)
Definition ugbc.h:4197
#define 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 CRITICAL_SCREEN_UNSUPPORTED(v)
Definition ugbc.h:3496
#define outline0(s)
Definition ugbc.h:4252
#define FLAG_FLIP_Y
Definition ugbc.h:4554
#define outline1(s, a)
Definition ugbc.h:4253
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
Definition ugbc.h:3880
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define FONT_SCHEMA_ASCII
Definition ugbc.h:582
#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