ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
gtia.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(__atari__) || defined(__atarixl__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40static RGBi SYSTEM_PALETTE[] = {
41 { 0x00, 0x00, 0x00, 0xff, 0x00, "BLACK", 0x00 }, //
42 { 0xff, 0xff, 0xff, 0xff, 0x0f, "WHITE", 0x0f }, //
43 { 0x90, 0x18, 0x29, 0xff, 0x24, "RED", 0x24 }, //
44 { 0x8e, 0xff, 0xff, 0xff, 0xae, "CYAN", 0xae }, //
45 { 0x77, 0x27, 0x93, 0xff, 0x64, "VIOLET", 0x64 }, //
46 { 0x00, 0x82, 0x67, 0xff, 0xa2, "GREEN", 0xb6 }, //
47 { 0x51, 0x34, 0xae, 0xff, 0x74, "BLUE", 0x74 }, //
48 { 0xee, 0xee, 0x77, 0xff, 0x1f, "YELLOW", 0x1f }, //
49 { 0xaa, 0x7e, 0x00, 0xff, 0x29, "ORANGE", 0x29 }, //
50 { 0x65, 0x3d, 0x00, 0xff, 0x24, "BROWN", 0x24 }, //
51 { 0xd6, 0x60, 0x72, 0xff, 0x28, "LIGHT RED", 0x28 }, //
52 { 0x3e, 0x3c, 0x3f, 0xff, 0x04, "DARK GREY", 0x04 }, //
53 { 0x83, 0x7e, 0x85, 0xff, 0x08, "GREY", 0x08 }, //
54 { 0x00, 0xc2, 0xab, 0xff, 0xba, "LIGHT GREEN", 0xba }, //
55 { 0x7d, 0x56, 0xd6, 0xff, 0x76, "LIGHT BLUE", 0x76 }, //
56 { 0xf3, 0xeb, 0xf8, 0xff, 0x0e, "LIGHT GREY", 0x0e }, //
57 { 0xff, 0xab, 0xff, 0xff, 0x6d, "MAGENTA", 0x6d }, //
58 { 0xe5, 0x89, 0xfd, 0xff, 0x6a, "LAVENDER", 0x6a }, //
59 { 0xf5, 0xc5, 0x64, 0xff, 0x2c, "GOLD", 0x2c }, //
60 { 0x8e, 0xff, 0xff, 0xff, 0xaf, "TURQUOISE", 0xaf }, //
61 { 0x22, 0xb9, 0xdf, 0xff, 0xab, "TAN", 0xab }, //
62 { 0x7f, 0x8e, 0x00, 0xff, 0x18, "YELLOW GREEN", 0x18 }, //
63 { 0x36, 0x4f, 0x00, 0xff, 0x14, "OLIVE GREEN", 0x14 }, //
64 { 0xff, 0xb6, 0x8c, 0xff, 0x3a, "PINK", 0x3c }, //
65 { 0xf0, 0x93, 0x65, 0xff, 0x3b, "PEACH", 0x3b }, //
66 { 0x8e, 0xff, 0xff, 0xff, 0xae, "CYAN", 0xae }, //
67 { 0x00, 0x13, 0x5f, 0xff, 0x71, "DARK BLUE", 0x71 } //
68};
69
70static RGBi * commonPalette;
72
73/****************************************************************************
74 * CODE SECTION
75 ****************************************************************************/
76
77void gtia_collision( Environment * _environment, char * _sprite_mask, char * _result ) {
78
79}
80
81void gtia_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
82
83}
84
94void gtia_border_color( Environment * _environment, int _border_color ) {
95
96 switch( _environment->currentMode ) {
100 outline1("LDA #$%2.2x", _border_color );
101 outline0("STA $02c8");
102 break;
103
107 break;
108
117 break;
118 }
119
120}
121
122void gtia_border_color_vars( Environment * _environment, char * _border_color ) {
123
124 switch( _environment->currentMode ) {
128 outline1("LDA %s", _border_color );
129 outline0("STA $02c8");
130 break;
131
135 break;
136
145 break;
146 }
147
148}
149
160void gtia_background_color( Environment * _environment, int _index, int _background_color ) {
161
162 switch( _environment->currentMode ) {
166 break;
167
171 outline1("LDA #$%2.2x", (unsigned char)(_background_color) );
172 switch( _index ) {
173 case 0:
174 outline0("STA $02C8" )
175 outline0("STA $D01A" )
176 break;
177 case 1:
178 outline0("STA $02C4" )
179 outline0("STA $D016" )
180 break;
181 case 2:
182 outline0("STA $02C6" )
183 outline0("STA $D018" )
184 break;
185 case 3:
186 outline0("STA $02C5" )
187 outline0("STA $D017" )
188 break;
189 }
190 break;
191
193 outline1("LDA #$%2.2x", _background_color );
194 outline0("STA $02C8" )
195 outline0("STA $D01A" )
196 break;
197
199 outline1("LDA #$%2.2x", _background_color );
200 outline0("STA $02C4" )
201 outline0("STA $D016" )
202 break;
203
205 outline1("LDA #$%2.2x", _background_color );
206 switch( _index ) {
207 case 0:
208 outline0("STA $02C6" )
209 outline0("STA $D017" )
210 break;
211 case 1:
212 outline0("STA $02C5" )
213 outline0("STA $D018" )
214 break;
215 }
216
219 outline1("LDA #$%2.2x", _background_color );
220 switch( _index ) {
221 case 0:
222 outline0("STA $02C8" )
223 outline0("STA $D01A" )
224 break;
225 case 1:
226 outline0("STA $02C4" )
227 outline0("STA $D016" )
228 break;
229 case 2:
230 outline0("STA $02C5" )
231 outline0("STA $D017" )
232 break;
233 case 3:
234 outline0("STA $02C6" )
235 outline0("STA $D018" )
236 break;
237 }
238 break;
239
241 outline1("LDA #$%2.2x", _background_color );
242 switch( _index ) {
243 case 0:
244 outline0("STA $02C6" )
245 outline0("STA $D018" )
246 break;
247 }
248 break;
249
251 outline1("LDA #$%2.2x", _background_color );
252 switch( _index ) {
253 case 0:
254 outline0("STA $02C8" )
255 outline0("STA $D01A" )
256 break;
257 case 1:
258 outline0("STA $02C4" )
259 outline0("STA $D016" )
260 break;
261 case 2:
262 outline0("STA $02C5" )
263 outline0("STA $D017" )
264 break;
265 case 3:
266 outline0("STA $02C6" )
267 outline0("STA $D018" )
268 break;
269 }
270 break;
271
273 break;
274 }
275
276
277}
278
289void gtia_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
290
292
293 switch( _environment->currentMode ) {
297 break;
298
302 outline1("LDA %s", _index);
303 outline0("AND #$03");
304 outline0("TAX");
305 outline1("LDA %s", _background_color );
306 outline0("CPX #0" );
307 outline1("BNE %snc0", label );
308 outline0("STA $02C8" )
309 outline0("STA $D01A" )
310 outline1("JMP %scdone", label )
311 outhead1("%snc0:", label);
312 outline0("CPX #1" );
313 outline1("BNE %snc1", label );
314 outline0("STA $02C4" )
315 outline0("STA $D016" )
316 outline1("JMP %scdone", label )
317 outhead1("%snc1:", label);
318 outline0("CPX #2" );
319 outline1("BNE %snc2", label );
320 outline0("STA $02C6" )
321 outline0("STA $D018" )
322 outline1("JMP %scdone", label )
323 outhead1("%snc2:", label);
324 outline0("STA $02C5")
325 outline0("STA $D017" )
326 outhead1("%scdone:", label);
327 break;
328
330 outline1("LDA #$%2.2x", _background_color );
331 outline0("STA $02C8" )
332 outline0("STA $D01A" )
333 break;
334
336 outline1("LDA #$%2.2x", _background_color );
337 outline0("STA $02C4" )
338 outline0("STA $D016" )
339 break;
340
342 outline1("LDA %s", _index);
343 outline0("AND #$01");
344 outline0("TAX");
345 outline1("LDA %s", _background_color );
346 outline0("CPX #0" );
347 outline1("BNE %snc0", label );
348 outline0("STA $02C6" )
349 outline0("STA $D017" )
350 outline1("JMP %scdone", label )
351 outhead1("%snc0:", label);
352 outline0("STA $02C5")
353 outline0("STA $D018" )
354 outhead1("%scdone:", label);
355 break;
356
359 outline1("LDA %s", _index);
360 outline0("AND #$03");
361 outline0("TAX");
362 outline1("LDA %s", _background_color );
363 outline0("CPX #0" );
364 outline1("BNE %snc0", label );
365 outline0("STA $02C8" )
366 outline0("STA $D01a" )
367 outline1("JMP %scdone", label )
368 outhead1("%snc0:", label);
369 outline0("CPX #1" );
370 outline1("BNE %snc1", label );
371 outline0("STA $02C4" )
372 outline0("STA $D016" )
373 outline1("JMP %scdone", label )
374 outhead1("%snc1:", label);
375 outline0("CPX #2" );
376 outline1("BNE %snc2", label );
377 outline0("STA $02C6" )
378 outline0("STA $D018" )
379 outline1("JMP %scdone", label )
380 outhead1("%snc2:", label);
381 outline0("STA $02C5")
382 outline0("STA $D017" )
383 outhead1("%scdone:", label);
384 break;
385
387 outline1("LDA %s", _index);
388 outline0("STA $02C6" )
389 outline0("STA $D018" )
390 break;
391
393 outline1("LDA %s", _index);
394 outline0("AND #$03");
395 outline0("TAX");
396 outline1("LDA %s", _background_color );
397 outline0("CPX #0" );
398 outline1("BNE %snc0", label );
399 outline0("STA $02C8" )
400 outline0("STA $D01A" )
401 outline1("JMP %scdone", label )
402 outhead1("%snc0:", label);
403 outline0("CPX #1" );
404 outline1("BNE %snc1", label );
405 outline0("STA $02C4" )
406 outline0("STA $D016" )
407 outline1("JMP %scdone", label )
408 outhead1("%snc1:", label);
409 outline0("CPX #2" );
410 outline1("BNE %snc2", label );
411 outline0("STA $02C5" )
412 outline0("STA $D017" )
413 outline1("JMP %scdone", label )
414 outhead1("%snc2:", label);
415 outline0("STA $02C6")
416 outline0("STA $D018" )
417 outhead1("%scdone:", label);
418 break;
419
421 break;
422 }
423
424}
425
436void gtia_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
437
439
440 switch( _environment->currentMode ) {
444 break;
445
449 outline1("LDA #$%2.2x", _index);
450 outline0("AND #$03");
451 outline0("TAX");
452 outline1("LDA %s", _background_color );
453 outline0("CPX #0" );
454 outline1("BNE %snc0", label );
455 outline0("STA $02C8" )
456 outline0("STA $D01A" )
457 outline1("JMP %scdone", label )
458 outhead1("%snc0:", label);
459 outline0("CPX #1" );
460 outline1("BNE %snc1", label );
461 outline0("STA $02C4" )
462 outline0("STA $D016" )
463 outline1("JMP %scdone", label )
464 outhead1("%snc1:", label);
465 outline0("CPX #2" );
466 outline1("BNE %snc2", label );
467 outline0("STA $02C6" )
468 outline0("STA $D018" )
469 outline1("JMP %scdone", label )
470 outhead1("%snc2:", label);
471 outline0("STA $02C5")
472 outline0("STA $D017" )
473 outhead1("%scdone:", label);
474 break;
475
477 outline1("LDA %s", _background_color );
478 outline0("STA $02C8" )
479 outline0("STA $D01A" )
480 break;
481
483 outline1("LDA %s", _background_color );
484 outline0("STA $02C4" )
485 outline0("STA $D016" )
486 break;
487
489 outline1("LDA #$%2.2x", _index);
490 outline0("AND #$01");
491 outline0("TAX");
492 outline1("LDA %s", _background_color );
493 outline0("CPX #0" );
494 outline1("BNE %snc0", label );
495 outline0("STA $02C6" )
496 outline0("STA $D017" )
497 outline1("JMP %scdone", label )
498 outhead1("%snc0:", label);
499 outline0("STA $02C5")
500 outline0("STA $D018" )
501 outhead1("%scdone:", label);
502 break;
503
506 outline1("LDA #$%2.2x", _index);
507 outline0("AND #$03");
508 outline0("TAX");
509 outline1("LDA %s", _background_color );
510 outline0("CPX #0" );
511 outline1("BNE %snc0", label );
512 outline0("STA $02C8" )
513 outline0("STA $D01A" )
514 outline1("JMP %scdone", label )
515 outhead1("%snc0:", label);
516 outline0("CPX #1" );
517 outline1("BNE %snc1", label );
518 outline0("STA $02C4" )
519 outline0("STA $D016" )
520 outline1("JMP %scdone", label )
521 outhead1("%snc1:", label);
522 outline0("CPX #2" );
523 outline1("BNE %snc2", label );
524 outline0("STA $02C6" )
525 outline0("STA $D018" )
526 outline1("JMP %scdone", label )
527 outhead1("%snc2:", label);
528 outline0("STA $02C5")
529 outline0("STA $D017" )
530 outhead1("%scdone:", label);
531 break;
532
534 outline1("LDA %s", _background_color );
535 outline0("STA $02C6" )
536 outline0("STA $D018" )
537 break;
538
540 outline1("LDA #$%2.2x", _index);
541 outline0("AND #$03");
542 outline0("TAX");
543 outline1("LDA %s", _background_color );
544 outline0("CPX #0" );
545 outline1("BNE %snc0", label );
546 outline0("STA $02C8" )
547 outline0("STA $D01A" )
548 outline1("JMP %scdone", label )
549 outhead1("%snc0:", label);
550 outline0("CPX #1" );
551 outline1("BNE %snc1", label );
552 outline0("STA $02C4" )
553 outline0("STA $D016" )
554 outline1("JMP %scdone", label )
555 outhead1("%snc1:", label);
556 outline0("CPX #2" );
557 outline1("BNE %snc2", label );
558 outline0("STA $02C5" )
559 outline0("STA $D017" )
560 outline1("JMP %scdone", label )
561 outhead1("%snc2:", label);
562 outline0("STA $02C6")
563 outline0("STA $D018" )
564 outhead1("%scdone:", label);
565 break;
566
568 break;
569 }
570
571}
572
583void gtia_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
584
586
587 switch( _environment->currentMode ) {
591 outline0("LDA #0");
592 break;
593
597 outline1("LDA %s", _index);
598 outline0("AND #$03");
599 outline0("TAX");
600 outline0("CPX #0" );
601 outline1("BNE %snc0", label );
602 outline0("LDA $02C8" )
603 outline0("STA $D01A" )
604 outline1("JMP %scdone", label )
605 outhead1("%snc0:", label);
606 outline0("CPX #1" );
607 outline1("BNE %snc1", label );
608 outline0("LDA $02C4" )
609 outline0("STA $D016" )
610 outline1("JMP %scdone", label )
611 outhead1("%snc1:", label);
612 outline0("CPX #2" );
613 outline1("BNE %snc2", label );
614 outline0("LDA $02C6" )
615 outline0("STA $D018" )
616 outline1("JMP %scdone", label )
617 outhead1("%snc2:", label);
618 outline0("LDA $02C5")
619 outline0("STA $D017" )
620 outhead1("%scdone:", label);
621 break;
622
624 outline0("LDA $02C8" )
625 outline0("STA $D01A" )
626 break;
627
629 outline0("LDA $02C4" )
630 outline0("STA $D016" )
631 break;
632
634 outline1("LDA %s", _index);
635 outline0("AND #$01");
636 outline0("TAX");
637 outline0("CPX #0" );
638 outline1("BNE %snc0", label );
639 outline0("LDA $02C6" )
640 outline0("STA $D017" )
641 outline1("JMP %scdone", label )
642 outhead1("%snc0:", label);
643 outline0("LDA $02C5")
644 outline0("STA $D018" )
645 outhead1("%scdone:", label);
646 break;
647
650 outline1("LDA %s", _index);
651 outline0("AND #$03");
652 outline0("TAX");
653 outline0("CPX #0" );
654 outline1("BNE %snc0", label );
655 outline0("LDA $02C8" )
656 outline0("STA $D01A" )
657 outline1("JMP %scdone", label )
658 outhead1("%snc0:", label);
659 outline0("CPX #1" );
660 outline1("BNE %snc1", label );
661 outline0("LDA $02C4" )
662 outline0("STA $D016" )
663 outline1("JMP %scdone", label )
664 outhead1("%snc1:", label);
665 outline0("CPX #2" );
666 outline1("BNE %snc2", label );
667 outline0("LDA $02C5" )
668 outline0("STA $D017" )
669 outline1("JMP %scdone", label )
670 outhead1("%snc2:", label);
671 outline0("LDA $02C6")
672 outline0("STA $D018" )
673 outhead1("%scdone:", label);
674 break;
675
677 outline0("LDA $02C6" )
678 outline0("STA $D018" )
679 break;
680
682 outline1("LDA %s", _index);
683 outline0("AND #$03");
684 outline0("TAX");
685 outline0("CPX #0" );
686 outline1("BNE %snc0", label );
687 outline0("LDA $02C8" )
688 outline0("STA $D01A" )
689 outline1("JMP %scdone", label )
690 outhead1("%snc0:", label);
691 outline0("CPX #1" );
692 outline1("BNE %snc1", label );
693 outline0("LDA $02C4" )
694 outline0("STA $D016" )
695 outline1("JMP %scdone", label )
696 outhead1("%snc1:", label);
697 outline0("CPX #2" );
698 outline1("BNE %snc2", label );
699 outline0("LDA $02C5" )
700 outline0("STA $D017" )
701 outline1("JMP %scdone", label )
702 outhead1("%snc2:", label);
703 outline0("LDA $02C6")
704 outline0("STA $D018" )
705 outhead1("%scdone:", label);
706 break;
707
709 break;
710 }
711
712 outline1("STA %s", _background_color );
713
714}
715
716void gtia_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
717
718}
719
720void gtia_bank_select( Environment * _environment, int _bank ) {
721
722}
723
724static int rgbConverterFunction( int _red, int _green, int _blue ) {
725
726 int j;
727
728 RGBi rgb;
729 rgb.red = _red;
730 rgb.green = _green;
731 rgb.blue = _blue;
732
733 double r = (double)rgb.red / (double)255;
734 double g = (double)rgb.green / (double)255;
735 double b = (double)rgb.blue / (double)255;
736
737 double max = max_of_three(r, g, b);
738 double min = min_of_three(r, g, b);
739 double h = 0, l = 0;
740
741 l = (0.2126*(rgb.red) + 0.7152*(rgb.green) + 0.0722*(rgb.blue));
742
743 if ( (max-min) == 0 ) {
744 h = 0;
745 } else {
746 if ( max == r ) {
747 h = (g-b)/(max-min);
748 } else if ( max == g ) {
749 h = 2.0f + (b-r)/(max-min);
750 } else if ( max == b ) {
751 h = 4.0f + (r-g)/(max-min);
752 } else {
753 h = 0;
754 }
755 }
756
757 return ( (((int)h)& 0x0f ) <<4 ) | ( (((int)l)& 0x0f )) ;
758
759}
760
761void console_calculate( Environment * _environment ) {
762
763 int consoleSA = 0x4000;
764 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
765 int consoleHB = _environment->activeConsole.height * 8;
766
767 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
768 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
769 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
770
771}
772
773void console_calculate_vars( Environment * _environment ) {
774
775 _environment->dynamicConsole = 1;
776
777 if ( _environment->currentMode >= 2 && _environment->currentMode <= 7 ) {
778 outline0( "JSR CONSOLECALCULATE" );
779 }
780
781}
782
784
785 cpu_math_sub_8bit( _environment, "CURRENTTILESWIDTH", "CONSOLEW", "CONSOLESL" );
786 cpu_math_sub_8bit( _environment, "CONSOLESL", "CONSOLEX1", "CONSOLESL" );
787 cpu_inc( _environment, "CONSOLESL" );
788
789 switch( _environment->currentMode ) {
793 cpu_math_mul2_const_8bit( _environment, "CONSOLESL", 1, 0 );
794 break;
795
801 break;
802
809 break;
810 default:
812 }
813
814}
815
817// FRAME BUFFER CALCULATION
819
820static void calculate_frame_buffer( Environment * _environment, int _size_required ) {
821 if ( _environment->frameBufferStart > ( FRAME_BUFFER_ADDRESS - _size_required ) ) {
822 _environment->frameBufferStart = ( FRAME_BUFFER_ADDRESS - _size_required );
823 }
824 if ( _size_required > 1024 ) {
825 _environment->frameBufferStart = ( _environment->frameBufferStart >> 12 ) << 12;
826 } else {
827 _environment->frameBufferStart = ( _environment->frameBufferStart >> 8 ) << 8;
828 }
829}
830
832// BUILD A LIST OF USED SCANLINES FOR A COPPER LIST
834
835static int * calculate_scanlines_for_copper_list( CopperList * _copper_list ) {
836
837 int * copperUsedLines = malloc( 312 * sizeof(int) );
838 memset(copperUsedLines, 0, 312 * sizeof(int));
839
840 CopperInstruction * actual = _copper_list->first;
841 while( actual ) {
842 switch( actual->operation ) {
843 case COP_WAIT:
844 copperUsedLines[actual->param1] = 1;
845 break;
846 break;
847 }
848 actual = actual->next;
849 }
850
851 return copperUsedLines;
852
853}
854
856// BUILD A DLI FOR A SINGLE SEGMENT SCREEN
858
859static unsigned char * dli_build( Environment * _environment,
860 int _mode, int _rows, CopperList * _copper_list,
861 int * _screen_memory_offset, int * _dlilist_start_offset,
862 int * _dli_size ) {
863
864 int * copperUsedLines = NULL;
865 if ( _copper_list ) {
866 copperUsedLines = calculate_scanlines_for_copper_list( _copper_list );
867 }
868
869 unsigned char * dliListStart = malloc( DLI_COUNT );
870 unsigned char * dliListCurrent = dliListStart;
871
872 memset( dliListStart, 0, DLI_COUNT );
873
874 DLI_BLANK( dliListCurrent, 8 );
875 DLI_BLANK( dliListCurrent, 8 );
876 DLI_BLANK( dliListCurrent, 8 );
877 if ( _environment->horizontalScrollOff ||
878 (
879 (_mode == TILEMAP_MODE_ANTIC2) || (_mode == TILEMAP_MODE_ANTIC3) ||
880 (_mode == TILEMAP_MODE_ANTIC4) || (_mode == TILEMAP_MODE_ANTIC6) ||
881 (_mode == TILEMAP_MODE_ANTIC7)
882 )
883 ) {
884 if ( _copper_list && copperUsedLines[0] ) {
885 DLI_LMS_VSCROLL_IRQ( dliListCurrent, _mode, _environment->frameBufferStart );
886 } else {
887 DLI_LMS_VSCROLL( dliListCurrent, _mode, _environment->frameBufferStart );
888 }
889 } else {
890 if ( _copper_list && copperUsedLines[0] ) {
891 DLI_LMS_VHSCROLL_IRQ( dliListCurrent, _mode, _environment->frameBufferStart );
892 } else {
893 DLI_LMS_VHSCROLL( dliListCurrent, _mode, _environment->frameBufferStart );
894 }
895 }
896
897 *_screen_memory_offset = dliListCurrent - dliListStart - 2;
898
899 for( int i=1; i<_rows; ++i ) {
900 if ( _environment->horizontalScrollOff ||
901 (
902 (_mode == TILEMAP_MODE_ANTIC2) || (_mode == TILEMAP_MODE_ANTIC3) ||
903 (_mode == TILEMAP_MODE_ANTIC4) || (_mode == TILEMAP_MODE_ANTIC6) ||
904 (_mode == TILEMAP_MODE_ANTIC7)
905 ) ) {
906 if ( _copper_list && copperUsedLines[i] ) {
907 DLI_MODE_VSCROLL_IRQ( dliListCurrent, _mode );
908 } else {
909 DLI_MODE_VSCROLL( dliListCurrent, _mode );
910 }
911 } else {
912 if ( _copper_list && copperUsedLines[i] ) {
913 DLI_MODE_VHSCROLL_IRQ( dliListCurrent, _mode );
914 } else {
915 DLI_MODE_VHSCROLL( dliListCurrent, _mode );
916 }
917 }
918 }
919
920 DLI_IRQ( dliListCurrent, _mode );
921
922 DLI_JVB( dliListCurrent, 0 );
923
924 *_dlilist_start_offset = dliListCurrent - dliListStart - 2;
925
926 *_dli_size = ( dliListCurrent - dliListStart );
927
928 return dliListStart;
929}
930
931static unsigned char * dli_build_antic12( Environment * _environment,
932 CopperList * _copper_list,
933 int * _screen_memory_offset, int * _dlilist_start_offset,
934 int * _screen_memory_offset2, int * _dli_size ) {
935
936 int * copperUsedLines = NULL;
937 if ( _copper_list ) {
938 copperUsedLines = calculate_scanlines_for_copper_list( _copper_list );
939 }
940
941 unsigned char * dliListStart = malloc( DLI_COUNT );
942 unsigned char * dliListCurrent = dliListStart;
943
944 memset( dliListStart, 0, DLI_COUNT );
945
946 DLI_BLANK( dliListCurrent, 8 );
947 DLI_BLANK( dliListCurrent, 8 );
948 DLI_BLANK( dliListCurrent, 8 );
949
950 if ( _environment->horizontalScrollOff ) {
951 if ( _copper_list && copperUsedLines[0] ) {
952 DLI_LMS_VSCROLL_IRQ( dliListCurrent, 12, _environment->frameBufferStart );
953 } else {
954 DLI_LMS_VSCROLL( dliListCurrent, 12, _environment->frameBufferStart );
955 }
956 } else {
957 if ( _copper_list && copperUsedLines[0] ) {
958 DLI_LMS_VHSCROLL_IRQ( dliListCurrent, 12, _environment->frameBufferStart );
959 } else {
960 DLI_LMS_VHSCROLL( dliListCurrent, 12, _environment->frameBufferStart );
961 }
962 }
963
964 *_screen_memory_offset = dliListCurrent - dliListStart - 2;
965
966 for( int i=1; i<96; ++i ) {
967 if ( _environment->horizontalScrollOff ) {
968 // 8 \Display ANTIC mode 12 for second mode line
969 if ( _copper_list && copperUsedLines[i] ) {
970 DLI_MODE_VSCROLL_IRQ( dliListCurrent, 12 );
971 } else {
972 DLI_MODE_VSCROLL( dliListCurrent, 12 );
973 }
974 } else {
975 if ( _copper_list && copperUsedLines[i] ) {
976 DLI_MODE_VHSCROLL_IRQ( dliListCurrent, 12 );
977 } else {
978 DLI_MODE_VHSCROLL( dliListCurrent, 12 );
979 }
980 }
981 }
982
983 int screenMemoryAddress2 = _environment->frameBufferStart + 4096;
984
985 _environment->frameBufferStart2 = screenMemoryAddress2;
986
987 if ( _environment->horizontalScrollOff ) {
988 DLI_LMS_VSCROLL( dliListCurrent, 15, screenMemoryAddress2 );
989 } else {
990 DLI_LMS_VHSCROLL( dliListCurrent, 15, screenMemoryAddress2 );
991 }
992
993 *_screen_memory_offset2 = dliListCurrent - dliListStart - 2;
994
995 for( int i=0; i<94; ++i ) {
996 if ( _environment->horizontalScrollOff ) {
997 if ( _copper_list && copperUsedLines[96+i] ) {
998 DLI_MODE_VSCROLL_IRQ( dliListCurrent, 15 );
999 } else {
1000 DLI_MODE_VSCROLL( dliListCurrent, 15 );
1001 }
1002 } else {
1003 if ( _copper_list && copperUsedLines[96+i] ) {
1004 DLI_MODE_VHSCROLL_IRQ( dliListCurrent, 15 );
1005 } else {
1006 DLI_MODE_VHSCROLL( dliListCurrent, 15 );
1007 }
1008 }
1009 }
1010
1011 DLI_IRQ( dliListCurrent, 15 );
1012
1013 DLI_JVB( dliListCurrent, 0 );
1014 *_dlilist_start_offset = dliListCurrent - dliListStart - 2;
1015
1016 *_dli_size = ( dliListCurrent - dliListStart );
1017
1018 return dliListStart;
1019
1020}
1021
1022static unsigned char * dli_build_antic15( Environment * _environment,
1023 CopperList * _copper_list,
1024 int * _screen_memory_offset, int * _dlilist_start_offset,
1025 int * _screen_memory_offset2, int * _dli_size ) {
1026
1027 int * copperUsedLines = NULL;
1028 if ( _copper_list ) {
1029 copperUsedLines = calculate_scanlines_for_copper_list( _copper_list );
1030 }
1031
1032 unsigned char * dliListStart = malloc( DLI_COUNT );
1033 unsigned char * dliListCurrent = dliListStart;
1034
1035 memset( dliListStart, 0, DLI_COUNT );
1036
1037 DLI_BLANK( dliListCurrent, 8 );
1038 DLI_BLANK( dliListCurrent, 8 );
1039 DLI_BLANK( dliListCurrent, 8 );
1040
1041 if ( _environment->horizontalScrollOff ) {
1042 if ( _copper_list && copperUsedLines[0] ) {
1043 DLI_LMS_VSCROLL_IRQ( dliListCurrent, 15, _environment->frameBufferStart );
1044 } else {
1045 DLI_LMS_VSCROLL( dliListCurrent, 15, _environment->frameBufferStart );
1046 }
1047 } else {
1048 if ( _copper_list && copperUsedLines[0] ) {
1049 DLI_LMS_VHSCROLL_IRQ( dliListCurrent, 15, _environment->frameBufferStart );
1050 } else {
1051 DLI_LMS_VHSCROLL( dliListCurrent, 15, _environment->frameBufferStart );
1052 }
1053 }
1054
1055 *_screen_memory_offset = dliListCurrent - dliListStart - 2;
1056
1057 for( int i=1; i<96; ++i ) {
1058 if ( _environment->horizontalScrollOff ) {
1059 // 8 \Display ANTIC mode 15 for second mode line
1060 if ( _copper_list && copperUsedLines[i] ) {
1061 DLI_MODE_VSCROLL_IRQ( dliListCurrent, 15 );
1062 } else {
1063 DLI_MODE_VSCROLL( dliListCurrent, 15 );
1064 }
1065 } else {
1066 if ( _copper_list && copperUsedLines[i] ) {
1067 DLI_MODE_VHSCROLL_IRQ( dliListCurrent, 15 );
1068 } else {
1069 DLI_MODE_VHSCROLL( dliListCurrent, 15 );
1070 }
1071 }
1072 }
1073
1074 int screenMemoryAddress2 = _environment->frameBufferStart + 4096;
1075
1076 _environment->frameBufferStart2 = screenMemoryAddress2;
1077
1078 if ( _environment->horizontalScrollOff ) {
1079 DLI_LMS_VSCROLL( dliListCurrent, 15, screenMemoryAddress2 );
1080 } else {
1081 DLI_LMS_VHSCROLL( dliListCurrent, 15, screenMemoryAddress2 );
1082 }
1083
1084 *_screen_memory_offset2 = dliListCurrent - dliListStart - 2;
1085
1086 for( int i=0; i<94; ++i ) {
1087 if ( _environment->horizontalScrollOff ) {
1088 if ( _copper_list && copperUsedLines[96+i] ) {
1089 DLI_MODE_VSCROLL_IRQ( dliListCurrent, 15 );
1090 } else {
1091 DLI_MODE_VSCROLL( dliListCurrent, 15 );
1092 }
1093 } else {
1094 if ( _copper_list && copperUsedLines[96+i] ) {
1095 DLI_MODE_VHSCROLL_IRQ( dliListCurrent, 15 );
1096 } else {
1097 DLI_MODE_VHSCROLL( dliListCurrent, 15 );
1098 }
1099 }
1100 }
1101
1102 DLI_IRQ( dliListCurrent, 15 );
1103
1104 DLI_JVB( dliListCurrent, 0 );
1105 *_dlilist_start_offset = dliListCurrent - dliListStart - 2;
1106
1107 *_dli_size = ( dliListCurrent - dliListStart );
1108
1109 return dliListStart;
1110
1111}
1112
1114
1115int gtia_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
1116
1117 _screen_mode->selected = 1;
1118
1119 int i;
1120 int screenMemoryOffset = 0;
1121 int screenMemoryOffset2 = 0;
1122 int currentHeight = 0;
1123 int scanline = 0;
1124 int dliListStartOffset;
1125 int dliSize = 0;
1126 int screenMemoryAddress2 = 0;
1127 int rows = 0;
1128
1129 cpu_store_8bit( _environment, "_PEN", _environment->defaultPenColor );
1130 cpu_store_8bit( _environment, "_PAPER", _environment->defaultPaperColor );
1131
1132 deploy( gtiavars, src_hw_gtia_vars_asm );
1133
1134 CopperList * copperList = find_copper_list( _environment, NULL );
1135
1136 if (copperList) {
1137 copperList->mode = _screen_mode->id;
1138 }
1139
1140 unsigned char * dliListStart = malloc( DLI_COUNT ), * dliListCurrent = dliListStart;
1141
1142 Variable * dli = variable_retrieve_or_define( _environment, "DLI", VT_BUFFER, 0 );
1143
1144 _environment->fontWidth = 8;
1145 _environment->fontHeight = 8;
1146
1147 _environment->screenShades = 256;
1148 _environment->screenTiles = 255;
1149 _environment->currentMode = _screen_mode->id;
1150
1151 switch( _screen_mode->id ) {
1152 // Graphics 3 (ANTIC 8)
1153 // This four-color graphics mode turns a split screen into 20 rows of 40 graphics cells or pixels.
1154 // Each pixel is 8 x 8 or the size of a normal character. The data in each pixel is encoded as two bit pairs,
1155 // four per byte. The four possible bit pair combinations 00, 01, 10, and 11 point to one of the four color registers.
1156 // The bits 00 is assigned to the background color register and the rest refer to the three foreground color registers.
1157 // When the CTIA/GTIA chip interprets the data for the four adjacent pixels stored within the byte, it refers to the color
1158 // register encoded in the bit pattern to plot the color.
1159 // 40x20, 4 colors
1160
1161 case BITMAP_MODE_ANTIC8:
1162
1163 calculate_frame_buffer( _environment, 240 + (1-_environment->horizontalScrollOff)*2*20 );
1164
1165 rows = 24;
1166
1167 _environment->screenWidth = 40;
1168 _environment->screenHeight = rows;
1169 _environment->screenColors = 4;
1170 _environment->currentModeBW = 2;
1171
1172 scanline = 10;
1173 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1174 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 40 );
1175 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1176
1177 break;
1178
1179 // Graphics 4 (ANTIC 9)
1180 // This is a two-color graphics mode with four times the resolution of GRAPHICS 3. The pixels are 4 x 4, and 48 rows of 80
1181 // pixels fit on a full screen. A single bit is used to store each pixel's color register. A zero refers to the background
1182 // color register and a one to the foreground color register. The mode is used primarily to conserve screen memory.
1183 // Only one bit is used for the color, so eight adjacent pixels are encoded within one byte, and only half as much screen
1184 // memory is needed for a display of similiar-sized pixels.
1185 // 80x48, 2 colors
1186 case BITMAP_MODE_ANTIC9:
1187
1188 calculate_frame_buffer( _environment, 480 + (1-_environment->horizontalScrollOff)*2*48 );
1189
1190 rows = 48;
1191
1192 _environment->screenWidth = 80;
1193 _environment->screenHeight = rows;
1194 _environment->screenColors = 2;
1195 _environment->currentModeBW = 1;
1196
1197 scanline = 10;
1198 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1199 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 40 );
1200 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1201 break;
1202
1203 // Graphics 5 (ANTIC A or 10)
1204 // This is the four color equivalent of GRAPHICS 4 sized pixels. The pixels are 4 x 4, but two bits are required to address
1205 // the four color registers. With only four adjacent pixels encoded within a byte, the screen uses twice as much memory,
1206 // about 1K.
1207 // 80x48, 4 colors
1209
1210 calculate_frame_buffer( _environment, 960 + (1-_environment->horizontalScrollOff)*4*48 );
1211
1212 rows = 48;
1213
1214 _environment->screenWidth = 80;
1215 _environment->screenHeight = rows;
1216 _environment->screenColors = 4;
1217 _environment->currentModeBW = 1;
1218
1219 currentHeight = 48;
1220 scanline = 20;
1221 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1222 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 40 );
1223 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1224 break;
1225
1226 // Graphics 6 (ANTIC B or 11)
1227 // This two color graphics mode has reasonably fine resolution. The 2 x 2 sized pixels allow 96 rows of 160 pixels to fit
1228 // on a full screen. Although only a single bit is used to encode the color, screen memory still requires approximately 2K.
1229 // 160x96, 2 colors
1230 case BITMAP_MODE_ANTIC11:
1231
1232 calculate_frame_buffer( _environment, 1920 + (1-_environment->horizontalScrollOff)*96 );
1233
1234 rows = 96;
1235
1236 _environment->screenWidth = 160;
1237 _environment->screenHeight = rows;
1238 _environment->screenColors = 2;
1239 _environment->currentModeBW = 1;
1240
1241 currentHeight = 96;
1242 scanline = 20;
1243 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1244 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 40 );
1245 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1246 break;
1247
1248 // Graphics 7 (ANTIC D or 13)
1249 // This is the four color equivalent to GRAPHICS mode 6. It is the finest resolution four color mode and naturally the
1250 // most popular. The color is encoded in two bit-pairs exactly the same way as in GRAPHICS 3. The memory requirements
1251 // of course is much greater as there are 96 rows of 160 - 2 x 2 sized pixels. It requires 3840 bytes of screen memory
1252 // with another 104 bytes for the display list.
1253 // 160x96, 4 colors
1255
1256 calculate_frame_buffer( _environment, 3840 + (1-_environment->horizontalScrollOff)*96 );
1257
1258 rows = 96;
1259
1260 _environment->screenWidth = 160;
1261 _environment->screenHeight = rows;
1262 _environment->screenColors = 4;
1263 _environment->currentModeBW = 2;
1264
1265 currentHeight = 96;
1266 scanline = 40;
1267 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1268 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 40 );
1269 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1270 break;
1271
1272 // Graphics 8 (ANTIC F or 15)
1273 // This mode is definitely the finest resolution available on the Atari. Individual dot-sized pixels can be addressed in
1274 // this one-color, two-luminance mode. There are 192 rows of 320 dots in the full screen mode. Graphics 8 is memory
1275 // intensive; it takes 8K bytes (eight pixels/byte) to address an entire screen. The color scheme is quite similar to that
1276 // in GRAPHICS mode 0. Color register #2 sets the background color. Color register #1 sets the luminance. Changing the color
1277 // in this register has no effect, but, this doesn't mean that you are limited to just one color.
1278 // Fortunately, the pixels are each one half of a color clock. It takes two pixels to span one color clock made up of
1279 // alternating columns of complementary colors. If the background is set to black, these columns consist of blue and
1280 // green stripes. If only the odd-columned pixels are plotted, you get blue pixels. If only the odd-columned pixels
1281 // are plotted, you get green pixels. And if pairs of adjacent pixels are plotted, you get white. So by cleverly
1282 // staggering the pixel patterns, you can achieve three colors. This method is called artifacting. This all depends
1283 // on background color and luminance.
1284 // 320x192, 3 colors
1286
1287 calculate_frame_buffer( _environment, 7680 );
1288
1289 rows = 192;
1290
1291 _environment->screenWidth = 320;
1292 _environment->screenHeight = rows;
1293 _environment->screenColors = 2;
1294 _environment->currentModeBW = 1;
1295
1296 screenMemoryAddress2 = _environment->frameBufferStart + 4096;
1297
1298 scanline = 40;
1299 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1300 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 40 );
1301 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1302 break;
1303
1304 // The following five graphics modes have no equivalent in BASIC on older machine but if indicated do correspond to
1305 // an equivalent graphics mode on the newer XL models.
1306
1307 // Antic C (Graphics 14-XL computers only)
1308 // This two-color, bit-mapped mode the eight bits correspond directly to the pixels on the screen. If a pixel is lit
1309 // it receives its color information from color register #0, otherwise the color is set to the background color
1310 // register #4. Each pixel is one scan line high and one color clock wide. This mode's advantages are that it
1311 // only uses 4K of screen memory and doesn't have artifacting problems.
1312 // 160x192, 2 colors
1314
1315 calculate_frame_buffer( _environment, 3840 + (1-_environment->horizontalScrollOff)*192 );
1316
1317 rows = 192;
1318
1319 _environment->screenWidth = 160;
1320 _environment->screenHeight = rows;
1321 _environment->screenColors = 2;
1322 _environment->currentModeBW = 1;
1323
1324 scanline = 20;
1325 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1326 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 20 );
1327 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1328 break;
1329
1330 // Antic E (Graphics 15-XL computers only)
1331 // This four-color, bit-mapped mode is sometimes known as BASIC 7 1/2. Its resolution is 160 x 192 or twice that of
1332 // GRAPHIC 7. Each byte is divided into four pairs of bits. Like the character data in ANTIC 4, the bit pairs point to a
1333 // particular color register. The screen data, however, is not character data but individual bytes. The user has a lot
1334 // more control, but this mode uses a lot more memory, approximately
1335 // 160x192, 4 colors
1337
1338 calculate_frame_buffer( _environment, 7680 );
1339
1340 rows = 192;
1341
1342 _environment->screenWidth = 160;
1343 _environment->screenHeight = rows;
1344 _environment->screenColors = 4;
1345 _environment->currentModeBW = 2;
1346
1347 scanline = 10;
1348 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 0 );
1349 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 20 );
1350 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1351 break;
1352
1353 // Graphics Mode 0 (ANTIC 2)
1354 // This is the normal-sized character or text mode that the computer defaults to on start up.
1355 // Being a character mode, screen memory consists of bytes that represent individual characters in either the
1356 // ROM or a custom character set. ANTIC displays forty of these 8 x 8 sized characters on each of
1357 // twenty-four lines. Graphics 0 is a 1 1/2 color mode. Color register #2 is used as the background color
1358 // register. Color register #1 sets the luminance of the characters against the background. Setting the
1359 // color has no effect. Bits within a character are turned on in pairs to produce the luminace color.
1360 // Otherwise single bits tend to produce colored artifacts on the high resolution screen. These colors
1361 // depend on whether the computer has a CTIA or GTIA chip, and the color of the background.
1362 // 40x24, 1 color
1364
1365 calculate_frame_buffer( _environment, 960 );
1366
1367 rows = 24;
1368
1369 _environment->screenWidth = 40 * _environment->fontWidth;
1370 _environment->screenHeight = rows * _environment->fontHeight;
1371 _environment->screenColors = 2;
1372 _environment->currentModeBW = 1;
1373
1374 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 152 );
1375 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 192 );
1376 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1377 break;
1378
1379 // Graphics 1 (ANTIC 6)
1380 // This is one the expanded text modes. Each characters is 8 x 8 but the pixels are one color clock in
1381 // width instead of the 1/2 color clock mode of Graphics 0 making the characters twice as wide. Only twenty
1382 // characters fit on any line. A graphics 1 screen has twenty rows while the full screen mode has twenty-four
1383 // rows of characters. The two high bits of each ATASCII character, that normally identify lowercase or
1384 // inverse video text in Graphics 1, set the color register for the 64 character set. Decimal character
1385 // numbers 0-63 use color register zero, while those same 64 characters if given character numbers 64-127
1386 // use color register #1. If you are typing from the Atari keyboard, the uppercase letters A-Z ATASCII 65-90
1387 // (Internal # 33-58) are assigned to color register zero, while the lowercase numbers 97-122
1388 // (Internal # 97-122) are signed to register #1.
1389 // 20x24, 4 color
1391
1392 calculate_frame_buffer( _environment, 480 );
1393
1394 rows = 24;
1395
1396 _environment->screenWidth = 20 * _environment->fontWidth;
1397 _environment->screenHeight = rows * _environment->fontHeight;
1398 _environment->screenColors = 2;
1399 _environment->currentModeBW = 1;
1400
1401 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 204 );
1402 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 224 );
1403 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1404 break;
1405
1406 // Graphics 2 (ANTIC 7)
1407 // This text mode is basically the same as the previous mode except that each row of pixels is two scan lines high.
1408 // Thus 12 rows of 20 characters are displayed on a full screen. Only ten rows fit on a split screen.
1409 // 20x12, 4 color
1411
1412 calculate_frame_buffer( _environment, 240 );
1413
1414 rows = 12;
1415
1416 _environment->screenWidth = 20 * _environment->fontWidth;
1417 _environment->screenHeight = rows * _environment->fontHeight;
1418 _environment->screenColors = 2;
1419 _environment->currentModeBW = 1;
1420
1421 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 204 );
1422 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 224 );
1423 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1424 break;
1425
1426 // Antic 3
1427 // This rarely used text mode is sometimes called the lowercase descenders mode. Each of the forty characters per line
1428 // are ten scan lines high, but since each of the characters are only eight scan lines high, the lower two scan lines are
1429 // normally left empty. However, if you use the last quarter of the character set, the top two lines remain blank,
1430 // allowing you to create lowercase characters with descenders.
1431 // 40x24, 4 color
1433
1434 calculate_frame_buffer( _environment, 760 );
1435
1436 rows = 24;
1437
1438 _environment->screenWidth = 40 * _environment->fontWidth;
1439 _environment->screenHeight = rows * _environment->fontHeight;
1440 _environment->screenColors = 2;
1441 _environment->currentModeBW = 1;
1442
1443 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 152 );
1444 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 192 );
1445 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1446 break;
1447
1448 // Antic 4 (Graphics 12-XL computers only)
1449 // This very powerful character graphics mode supports four colors while using relatively little screen memory (1 K).
1450 // In addition its 4 x 8 sized characters have the same horizontal resolution as GRAPHICS 7, yet twice the vertical resolution.
1451 // A large number of games with colorful and detailed playfields use this mode. These characters differ considerably from
1452 // ANTIC 6 (BASIC 2) characters, in that each character contains pixels of four different colors, not just a choice of one color
1453 // determined by the character number. Each byte in the character is broken into four bit pairs, each of which selects the color
1454 // register for the pixel. That is why the horizontal resolution is only four bits. A special character set generator is used
1455 // to form these characters.
1456 // 20x24, 4 color
1458
1459 calculate_frame_buffer( _environment, 960 );
1460
1461 rows = 24;
1462
1463 _environment->screenWidth = 20 * _environment->fontWidth;
1464 _environment->screenHeight = rows * _environment->fontHeight;
1465 _environment->screenColors = 4;
1466 _environment->currentModeBW = 2;
1467
1468 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 152 );
1469 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 192 );
1470 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1471 break;
1472
1473 // Antic 5 (Graphics 13-XL computers only)
1474 // This mode is essentially the same as ANTIC 4 except that each character is sixteen scan lines high.
1475 // The character set data is still eight bytes high so ANTIC double plots each scan line.
1476 // 20x24, 4 color
1478
1479 calculate_frame_buffer( _environment, 480 );
1480
1481 rows = 24;
1482
1483 _environment->screenWidth = 20 * _environment->fontWidth;
1484 _environment->screenHeight = rows * _environment->fontHeight;
1485 _environment->screenColors = 4;
1486 _environment->currentModeBW = 2;
1487
1488 cpu_store_8bit( _environment, "TEXTBLOCKREMAIN", 152 );
1489 cpu_store_8bit( _environment, "TEXTBLOCKREMAINPW", 192 );
1490 cpu_store_8bit( _environment, "CURRENTSL", scanline );
1491 break;
1492
1493 default:
1494 CRITICAL_SCREEN_UNSUPPORTED( _screen_mode->id );
1495 }
1496
1497 _environment->screenTilesWidth = _environment->screenWidth / _environment->fontWidth;
1498 _environment->screenTilesHeight = _environment->screenHeight / _environment->fontHeight;
1499 _environment->consoleTilesWidth = _environment->screenTilesWidth;
1500 _environment->consoleTilesHeight = _environment->screenTilesHeight;
1501
1502 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
1503 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
1504 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
1505 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
1506 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
1507 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
1508 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
1509 int consoleX1 = 0;
1510 if ( _environment->lmarginAtariBasicEnabled && _environment->currentMode == TILEMAP_MODE_ANTIC2 ) {
1511 consoleX1 = 2;
1512 }
1513 cpu_store_8bit( _environment, "CONSOLEX1", consoleX1 );
1514 cpu_store_8bit( _environment, "CONSOLEY1", 0 );
1515 cpu_store_8bit( _environment, "CONSOLEX2", _environment->consoleTilesWidth-1 );
1516 cpu_store_8bit( _environment, "CONSOLEY2", _environment->consoleTilesHeight-1 );
1517 cpu_store_8bit( _environment, "CONSOLEW", _environment->consoleTilesWidth );
1518 cpu_store_8bit( _environment, "CONSOLEH", _environment->consoleTilesHeight );
1519
1520 cpu_store_16bit( _environment, "ORIGINX", 0) ;
1521 cpu_store_16bit( _environment, "ORIGINY", 0) ;
1522
1523 cpu_store_16bit( _environment, "CLIPX1", 0) ;
1524 cpu_store_16bit( _environment, "CLIPX2", _environment->screenWidth-1 );
1525 cpu_store_16bit( _environment, "CLIPY1", 0) ;
1526 cpu_store_16bit( _environment, "CLIPY2", _environment->screenHeight-1 );
1527
1528 cpu_store_16bit( _environment, "TEXTADDRESS", _environment->frameBufferStart );
1529 cpu_store_16bit( _environment, "BITMAPADDRESS", _environment->frameBufferStart );
1530
1531 // dli->absoluteAddress = 0xA000 - (dliListCurrent - dliListStart) - 16;
1532
1533 if ( _screen_mode->id == BITMAP_MODE_ANTIC15 ) {
1534 dliListStart = dli_build_antic15( _environment,
1535 copperList,
1536 &screenMemoryOffset, &dliListStartOffset,
1537 &screenMemoryOffset2, &dliSize );
1538 } else if ( _screen_mode->id == BITMAP_MODE_ANTIC12 ) {
1539 dliListStart = dli_build_antic12( _environment,
1540 copperList,
1541 &screenMemoryOffset, &dliListStartOffset,
1542 &screenMemoryOffset2, &dliSize );
1543 } else {
1544 dliListStart = dli_build( _environment,
1545 _screen_mode->id /*mode*/,
1546 rows-1 /*rows*/,
1547 copperList,
1548 &screenMemoryOffset,
1549 &dliListStartOffset,
1550 &dliSize );
1551 }
1552
1553 variable_store_buffer( _environment, dli->name, dliListStart, dliSize, dli->absoluteAddress );
1554
1556
1557 cpu_jump(_environment, label );
1558
1559 CopperList * actual = _environment->copperList;
1560 while(actual) {
1561 actual->mode = _screen_mode->id;
1562 if ( actual->name ) {
1563 char dliCopperName[MAX_TEMPORARY_STORAGE];
1564 sprintf( dliCopperName, "DLI%s", actual->name );
1565 Variable * dliCopper = variable_define( _environment, dliCopperName, VT_BUFFER, 0 );
1566 if ( _screen_mode->id == BITMAP_MODE_ANTIC15 ) {
1567 dliListStart = dli_build_antic15( _environment,
1568 actual,
1569 &screenMemoryOffset, &dliListStartOffset,
1570 &screenMemoryOffset2, &dliSize );
1571 } else {
1572 dliListStart = dli_build( _environment,
1573 _screen_mode->id /*mode*/,
1574 rows-1 /*rows*/,
1575 actual,
1576 &screenMemoryOffset,
1577 &dliListStartOffset,
1578 &dliSize );
1579 }
1580 variable_store_buffer( _environment, dliCopper->name, dliListStart, dliSize, dliCopper->absoluteAddress );
1581 }
1582 actual = actual->next;
1583 }
1584
1585 char dliCommonLabel[MAX_TEMPORARY_STORAGE];
1586 sprintf( dliCommonLabel, "GTIAINITDLICOMMON%s%d", label, _screen_mode->id );
1587
1588 cpu_label(_environment, dliCommonLabel);
1589 if ( _screen_mode->bitmap ) {
1590 outline0("LDA BITMAPADDRESS" );
1591 outline1("STA DLI+$%4.4x", screenMemoryOffset );
1592 outline0("LDA BITMAPADDRESS+1" );
1593 outline1("STA DLI+$%4.4x+1", screenMemoryOffset );
1594 if ( screenMemoryOffset2 ) {
1595 outline1("LDA #$%2.2x", ( screenMemoryAddress2 & 0xff ) );
1596 outline1("STA DLI+$%4.4x", screenMemoryOffset2 );
1597 outline1("LDA #$%2.2x", ( screenMemoryAddress2 >> 8 ) & 0xff );
1598 outline1("STA DLI+$%4.4x+1", screenMemoryOffset2 );
1599 }
1600 } else {
1601 outline0("LDA TEXTADDRESS" );
1602 outline1("STA DLI+$%4.4x", screenMemoryOffset );
1603 outline0("LDA TEXTADDRESS+1" );
1604 outline1("STA DLI+$%4.4x+1", screenMemoryOffset );
1605 }
1606 outline0("LDA #<DLI" );
1607 outline1("STA DLI+$%4.4x", dliListStartOffset );
1608 outline0("LDA #>DLI" );
1609 outline1("STA DLI+$%4.4x+1", dliListStartOffset );
1610 cpu_return(_environment);
1611
1612 char dliLabel[MAX_TEMPORARY_STORAGE];
1613 sprintf( dliLabel, "GTIAINITDLI%d", _screen_mode->id );
1614
1615 if ( ! label_stored_exists_named( _environment, dliLabel ) ) {
1616
1617 cpu_label(_environment, dliLabel);
1618 cpu_mem_move_direct_size( _environment, dli->realName, "DLI", dli->size );
1619
1620 char dliLabel2[MAX_TEMPORARY_STORAGE];
1621 sprintf( dliLabel2, "GTIAINITDLIB%d", _screen_mode->id );
1622 cpu_label(_environment, dliLabel2);
1623
1624 cpu_call( _environment, dliCommonLabel);
1625
1626 outline0("SEI" );
1627 outline0("LDA #<DLI" );
1628 outline0("STA $0230" );
1629 outline0("STA $D402" );
1630 outline0("LDA #>DLI" );
1631 outline0("STA $0231" );
1632 outline0("STA $D403" );
1633 outline0("CLI" );
1634
1635 label_stored_define_named( _environment, dliLabel );
1636
1637 } else {
1638
1639 cpu_call( _environment, dliLabel);
1640
1641 }
1642
1643 cpu_return(_environment);
1644
1645 cpu_label(_environment, label );
1646 cpu_call(_environment, dliLabel);
1647
1648 if ( _environment->vestigialConfig.palettePreserve ) {
1649 outline0("LDA #$0");
1650 outline0("STA PALETTEPRESERVEUSED");
1651 outline0("STA LASTCOLOR");
1652 }
1653
1654 outline0("JSR GTIAAFTERINIT");
1655
1656}
1657
1658void gtia_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
1659
1660 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
1661
1662 if ( mode ) {
1663 gtia_screen_mode_enable( _environment, mode );
1664 // printf( "%d\n", mode->id);
1665 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
1666 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
1667 _environment->currentMode = mode->id;
1668 _environment->currentTileMode = 0;
1669 } else {
1670 WARNING_SCREEN_MODE( -1 );
1671 }
1672
1673}
1674
1675void gtia_bitmap_disable( Environment * _environment ) {
1676
1677}
1678
1679void gtia_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
1680
1681 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
1682
1683 if ( mode ) {
1684 gtia_screen_mode_enable( _environment, mode );
1685
1686 cpu_store_8bit( _environment, "_PEN", _environment->defaultPenColor );
1687 cpu_store_8bit( _environment, "_PAPER", _environment->defaultPaperColor );
1688
1689 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
1690 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
1691
1692 _environment->currentMode = mode->id;
1693 _environment->currentTileMode = 1;
1694 } else {
1695 WARNING_SCREEN_MODE( -1 );
1696 }
1697
1698}
1699
1700void gtia_bitmap_at( Environment * _environment, char * _address ) {
1701
1702}
1703
1704void gtia_colormap_at( Environment * _environment, char * _address ) {
1705
1706}
1707
1708void gtia_textmap_at( Environment * _environment, char * _address ) {
1709
1710}
1711
1712void gtia_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
1713
1714 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
1715 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
1716 deploy( plot, src_hw_gtia_plot_asm );
1717
1718 outline1("LDA %2.2x", (_x & 0xff ) );
1719 outline0("STA PLOTX");
1720 outline1("LDA %2.2x", ( ( _x >> 8 ) & 0xff ) );
1721 outline0("STA PLOTX+1");
1722 outline1("LDA %2.2x", ( _y & 0xff ) );
1723 outline0("STA PLOTY");
1724 if ( _c ) {
1725 outline1("LDA #$%2.2x", ( *_c & 0xff ) );
1726 } else {
1727 Variable * c = variable_retrieve( _environment, "PEN" );
1728 outline1("LDA %s", c->realName );
1729 }
1730 outline0("STA PLOTCPE");
1731 outline0("LDA #1");
1732 outline0("STA PLOTM");
1733 outline0("JSR PLOT");
1734
1735}
1736
1737void gtia_pset_vars( Environment * _environment, char *_x, char *_y, char *_c ) {
1738
1739 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
1740 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
1741 Variable * c;
1742
1743 if ( _c ) {
1744 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
1745 } else {
1746 c = variable_retrieve( _environment, "PEN" );
1747 }
1748
1749 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
1750 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
1751 deploy( plot, src_hw_gtia_plot_asm );
1752
1753 outline1("LDA %s", x->realName );
1754 outline0("STA PLOTX");
1755 if ( VT_BITWIDTH( x->type ) > 8 ) {
1756 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
1757 } else {
1758 outline0("LDA #0");
1759 }
1760 outline0("STA PLOTX+1");
1761 outline1("LDA %s", y->realName );
1762 outline0("STA PLOTY");
1763 outline1("LDA %s", c->realName);
1764 outline0("STA PLOTCPE");
1765 outline0("LDA #1");
1766 outline0("STA PLOTM");
1767 outline0("JSR PLOT");
1768
1769}
1770
1771void gtia_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
1772
1773 Variable * x = variable_retrieve( _environment, _x );
1774 Variable * y = variable_retrieve( _environment, _y );
1775 Variable * result = variable_retrieve( _environment, _result );
1776
1777 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
1778 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
1779 deploy( plot, src_hw_gtia_plot_asm );
1780
1781 outline1("LDA %s", x->realName );
1782 outline0("STA PLOTX");
1783 outline1("LDA %s", address_displacement(_environment, x->realName, "1") );
1784 outline0("STA PLOTX+1");
1785 outline1("LDA %s", y->realName );
1786 outline0("STA PLOTY");
1787 outline0("LDA #3");
1788 outline0("STA PLOTM");
1789 outline0("JSR PLOT");
1790 outline0("LDA PLOTM");
1791 outline1("STA %s", result->realName);
1792
1793}
1794
1795void gtia_screen_on( Environment * _environment ) {
1796
1797}
1798
1799void gtia_screen_off( Environment * _environment ) {
1800
1801}
1802
1803void gtia_screen_rows( Environment * _environment, char * _rows ) {
1804
1805}
1806
1807void gtia_screen_columns( Environment * _environment, char * _columns ) {
1808
1809}
1810
1811void gtia_sprite_data_from( Environment * _environment, char * _sprite, char * _address ) {
1812
1813}
1814
1815void gtia_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
1816
1817}
1818
1819void gtia_sprite_enable( Environment * _environment, char * _sprite ) {
1820
1821}
1822
1823void gtia_sprite_disable( Environment * _environment, char * _sprite ) {
1824
1825}
1826
1827void gtia_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
1828
1829}
1830
1831void gtia_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
1832
1833}
1834
1835void gtia_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
1836
1837}
1838
1839void gtia_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
1840
1841}
1842
1843void gtia_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
1844
1845}
1846
1847void gtia_sprite_multicolor( Environment * _environment, char * _sprite ) {
1848
1849}
1850
1851void gtia_sprite_monocolor( Environment * _environment, char * _sprite ) {
1852
1853}
1854
1855void gtia_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
1856
1857}
1858
1859void gtia_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
1860
1861}
1862
1863void gtia_tiles_at( Environment * _environment, char * _address ) {
1864
1865}
1866
1867void gtia_vertical_scroll( Environment * _environment, char * _displacement ) {
1868
1869 outline1("LDY %s", _displacement );
1870 outline0("LDA #<YSCROLLOFFSET" );
1871 outline0("STA TMPPTR" );
1872 outline0("LDA #>YSCROLLOFFSET" );
1873 outline0("STA TMPPTR+1" );
1874 outline0("LDA (TMPPTR),Y" );
1875 outline0("STA $D405" );
1876
1877}
1878
1879void gtia_horizontal_scroll( Environment * _environment, char * _displacement ) {
1880
1881 outline1("LDA %s", _displacement );
1882 outline0("AND #$0f" );
1883 outline0("STA $D404" );
1884
1885}
1886
1887void gtia_busy_wait( Environment * _environment, char * _timing ) {
1888
1890
1891 outline1("LDA %s", _timing );
1892 outline0("STA TMPPTR");
1893 outline1("LDA %s", address_displacement(_environment, _timing, "1") );
1894 outline0("STA TMPPTR+1");
1895 outhead1("%sfirst:", label );
1896 outline0("LDA $14");
1897 outhead1("%ssecond:", label );
1898 outline0("CMP $14");
1899 outline1("BEQ %ssecond", label);
1900 outline0("DEC TMPPTR");
1901 outline0("LDA TMPPTR");
1902 outline0("CMP #$FF");
1903 outline1("BNE %sfirst", label);
1904 outline0("DEC TMPPTR+1");
1905 outline0("LDA TMPPTR+1");
1906 outline0("CMP #$FF");
1907 outline1("BNE %sfirst", label);
1908 outline1("%sthird:", label);
1909
1910}
1911
1912void gtia_get_width( Environment * _environment, char *_result ) {
1913
1914 outline0("LDA CURRENTWIDTH" );
1915 outline1("STA %s", _result );
1916 outline0("LDA CURRENTWIDTH+1" );
1917 outline1("STA %s", address_displacement(_environment, _result, "1") );
1918
1919}
1920
1921void gtia_get_height( Environment * _environment, char *_result ) {
1922
1923 outline0("LDA CURRENTHEIGHT" );
1924 outline1("STA %s", _result );
1925 outline0("LDA CURRENTHEIGHT+1" );
1926 outline1("STA %s", address_displacement(_environment, _result, "1") );
1927
1928}
1929
1930void gtia_tiles_get( Environment * _environment, char *_result ) {
1931
1932 outline0("LDA CURRENTTILES" );
1933 outline1("STA %s", _result );
1934
1935}
1936
1937void gtia_cls( Environment * _environment ) {
1938
1939 deploy( cls, src_hw_gtia_cls_asm );
1940
1941 outline0("LDA #$0");
1942 outline0("STA PATTERN");
1943 outline0("JSR CLS");
1944
1945}
1946
1947void gtia_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
1948
1949 deploy( clsBox, src_hw_gtia_cls_box_asm );
1950
1951 outline1("LDA %s", _x1);
1952 outline0("STA IMAGEX");
1953 outline1("LDA %s", address_displacement( _environment, _x1, "1" ) );
1954 outline0("STA IMAGEX+1");
1955 outline1("LDA %s", _y1);
1956 outline0("STA IMAGEY");
1957 outline1("LDA %s", _w);
1958 outline0("STA IMAGEW");
1959 outline1("LDA %s", address_displacement( _environment, _w, "1" ) );
1960 outline0("STA IMAGEW+1");
1961 outline1("LDA %s", _h);
1962 outline0("STA IMAGEH");
1963 outline0("JSR CLSBOX");
1964
1965}
1966
1967void gtia_clear( Environment * _environment, char * _pattern ) {
1968
1969 deploy( cls, src_hw_gtia_cls_asm );
1970
1971 outline1("LDA %s", _pattern );
1972 outline0("STA PATTERN");
1973 outline0("JSR CLS");
1974
1975}
1976
1977void gtia_scroll_text( Environment * _environment, int _direction, int _overlap ) {
1978
1979 deploy_preferred( vScrollText, src_hw_gtia_vscroll_text_asm );
1980
1981 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
1982 outline0("STA DIRECTION" );
1983 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
1984 outline0("STA PORT" );
1985
1986 outline0("JSR VSCROLLT");
1987
1988}
1989
1990void gtia_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
1991
1992 deploy( gtiavars, src_hw_gtia_vars_asm );
1993 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
1994 deploy_preferred( vScrollText, src_hw_gtia_vscroll_text_asm );
1995 deploy( cls, src_hw_gtia_cls_asm );
1996 deploy( textEncodedAt, src_hw_gtia_text_at_asm );
1997
1998 outline1("LDA %s", _text);
1999 outline0("STA TEXTPTR" );
2000 outline1("LDA %s", address_displacement(_environment, _text, "1"));
2001 outline0("STA TEXTPTR+1" );
2002 outline1("LDA %s", _text_size);
2003 outline0("STA TEXTSIZE" );
2004
2005 if ( _raw ) {
2006 if ( _environment->currentMode >= 2 && _environment->currentMode <= 7 ) {
2007 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
2008 deploy_deferred( textEncodedAtTextRaw, src_hw_gtia_text_at_text_raw_asm );
2009 outline0("JSR TEXTATTILEMODERAW");
2010 } else {
2011 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
2012 deploy_deferred( textEncodedAtGraphicRaw, src_hw_gtia_text_at_graphic_raw_asm );
2013 outline0("JSR TEXTATBITMAPMODERAW");
2014 }
2015 } else {
2016 if ( _environment->currentMode >= 2 && _environment->currentMode <= 7 ) {
2017 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
2018 deploy_deferred( textEncodedAtText, src_hw_gtia_text_at_text_asm );
2019 outline0("JSR TEXTATTILEMODE");
2020 } else {
2021 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
2022 deploy_deferred( textEncodedAtGraphic, src_hw_gtia_text_at_graphic_asm );
2023 outline0("JSR TEXTATBITMAPMODE");
2024 }
2025 }
2026
2027}
2028
2029void gtia_initialization( Environment * _environment ) {
2030
2031 _environment->vestigialConfig.palettePreserve = 1;
2032
2033 deploy_preferred( gtiavars, src_hw_gtia_vars_asm );
2034 deploy_preferred( gtiastartup, src_hw_gtia_startup_asm );
2035
2036 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 320 );
2037 variable_global( _environment, "CURRENTWIDTH" );
2038 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 199 );
2039 variable_global( _environment, "CURRENTHEIGHT" );
2040 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
2041 variable_global( _environment, "CURRENTTILES" );
2042 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 40 );
2043 variable_global( _environment, "CURRENTTILESWIDTH" );
2044 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 25 );
2045 variable_global( _environment, "CURRENTTILESHEIGHT" );
2046 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
2047 variable_global( _environment, "FONTWIDTH" );
2048 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
2049 variable_global( _environment, "FONTHEIGHT" );
2050
2051#ifdef __atarixl__
2052 //SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC14, 1, 160, 192, 4, 8, 8, "Antic E (Graphics 15-XL computers only)" );
2053#endif
2054 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC13, 1, 160, 96, 4, 8, 8, "Graphics 7 (ANTIC D or 13)" );
2055#ifdef __atarixl__
2056 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC15, 1, 320, 192, 1, 8, 8, "Graphics 8 (ANTIC F or 15)" );
2057 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC12, 1, 160, 192, 2, 8, 8, "Antic C (Graphics 14-XL computers only)" );
2058#endif
2059 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC8, 1, 40, 24, 4, 8, 8, "Graphics 3 (ANTIC 8)" );
2060 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC9, 1, 80, 48, 2, 8, 8, "Graphics 4 (ANTIC 9)" );
2061 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC10, 1, 80, 48, 4, 8, 8, "Graphics 5 (ANTIC A or 10)" );
2062 SCREEN_MODE_DEFINE( BITMAP_MODE_ANTIC11, 1, 160, 96, 2, 8, 8, "Graphics 6 (ANTIC B or 11)" );
2063
2064 SCREEN_MODE_DEFINE( TILEMAP_MODE_ANTIC2, 0, 40, 24, 1, 8, 8, "Graphics Mode 0 (ANTIC 2)" );
2065 SCREEN_MODE_DEFINE( TILEMAP_MODE_ANTIC6, 0, 20, 24, 4, 8, 8, "Graphics 1 (ANTIC 6)" );
2066 SCREEN_MODE_DEFINE( TILEMAP_MODE_ANTIC7, 0, 20, 12, 4, 8, 8, "Graphics 2 (ANTIC 7)" );
2067 SCREEN_MODE_DEFINE( TILEMAP_MODE_ANTIC3, 0, 40, 24, 4, 8, 8, "Antic 3" );
2068
2069#ifdef __atarixl__
2070 SCREEN_MODE_DEFINE( TILEMAP_MODE_ANTIC4, 0, 40, 24, 4, 8, 8, "Antic 4 (Graphics 12-XL computers only)" );
2071 SCREEN_MODE_DEFINE( TILEMAP_MODE_ANTIC5, 0, 40, 24, 4, 8, 8, "Antic 5 (Graphics 13-XL computers only)" );
2072#endif
2073
2074 outline0("JSR GTIASTARTUP");
2075 outline0("JSR GTIAUDCCHAR");
2076
2077 variable_import( _environment, "CURRENTMODE", VT_BYTE, 0 );
2078 variable_global( _environment, "CURRENTMODE" );
2079 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
2080 variable_global( _environment, "CURRENTTILEMODE" );
2081
2082 variable_import( _environment, "XGR", VT_POSITION, 0 );
2083 variable_global( _environment, "XGR" );
2084 variable_import( _environment, "YGR", VT_POSITION, 0 );
2085 variable_global( _environment, "YGR" );
2086 variable_import( _environment, "LINE", VT_WORD, (unsigned short) (0xffff) );
2087 variable_global( _environment, "LINE" );
2088 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
2089 variable_global( _environment, "TABCOUNT" );
2090
2091 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
2092 variable_global( _environment, "CLIPX1" );
2093 variable_import( _environment, "CLIPX2", VT_POSITION, 319 );
2094 variable_global( _environment, "CLIPX2" );
2095 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
2096 variable_global( _environment, "CLIPY1" );
2097 variable_import( _environment, "CLIPY2", VT_POSITION, 199 );
2098 variable_global( _environment, "CLIPY2" );
2099
2100 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
2101 variable_global( _environment, "ORIGINX" );
2102 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
2103 variable_global( _environment, "ORIGINY" );
2104
2105 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
2106 variable_global( _environment, "RESOLUTIONX" );
2107 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
2108 variable_global( _environment, "RESOLUTIONY" );
2109
2110 _environment->currentMode = 2;
2111 _environment->currentTileMode = 1;
2112
2113 _environment->currentRgbConverterFunction = rgbConverterFunction;
2114#if defined(__atari__)
2115 _environment->frameBufferStart = 0xbf00; // 256 byte boundary alignment
2116#else
2117 _environment->frameBufferStart = 0xbf00; // 256 byte boundary alignment
2118#endif
2119
2120 gtia_tilemap_enable( _environment, 40, 24, 1, 8, 8 );
2121
2122 reset_screen_mode_selected( _environment );
2123
2124 if (_environment->vestigialConfig.clsImplicit ) {
2125 gtia_cls( _environment );
2126 }
2127
2128}
2129
2130void gtia_finalization( Environment * _environment ) {
2131
2132 if (_environment->vestigialConfig.clsImplicit ) {
2133 deploy( cls, src_hw_gtia_cls_asm );
2134 }
2135
2136 CopperList * copperList = _environment->copperList;
2137
2138 int anon = 0;
2139
2140 cpu_label( _environment, "GTIAFINALIZE" );
2141
2142 if ( copperList ) {
2143
2144 if ( !copperList->name ) {
2145 if ( copperList->mode == 0 ) {
2146 copperList->mode = _environment->currentMode;
2147 outline0( "JSR COPPERACTIVATE");
2148 }
2149 }
2150 outline0( "RTS");
2151
2152 while(copperList) {
2153 if ( !copperList->name ) {
2154 anon = 1;
2155 }
2156 char copperlist0Named[MAX_TEMPORARY_STORAGE];
2157 sprintf( copperlist0Named, "COPPERLIST0000%s", copperList->name ? copperList->name : "" );
2158 char dliLabel[MAX_TEMPORARY_STORAGE];
2159 sprintf( dliLabel, "GTIAINITDLI%d", copperList->mode );
2160 char dliLabel2[MAX_TEMPORARY_STORAGE];
2161 sprintf( dliLabel2, "GTIAINITDLIB%d", copperList->mode );
2162 char dliCopperName[MAX_TEMPORARY_STORAGE];
2163 sprintf( dliCopperName, "DLI%s", copperList->name ? copperList->name : "" );
2164
2165 Variable * dliCopper = variable_retrieve( _environment, dliCopperName );
2166
2167 outhead1("COPPERACTIVATE%s:", copperList->name ? copperList->name : "" );
2168 cpu_mem_move_direct_size( _environment, dliCopper->realName, "DLI", dliCopper->size );
2169 outline1("JSR %s", dliLabel2 );
2170 outhead1("GTIAVBLIRQNOCOPPER%s:", copperList->name ? copperList->name : "" );
2171 outline1("LDA #<%s", copperlist0Named );
2172 outline0("STA COPPERLISTJUMP+1" );
2173 outline1("LDA #>%s", copperlist0Named );
2174 outline0("STA COPPERLISTJUMP+2" );
2175 outline0("RTS");
2176
2177 CopperInstruction * actual = copperList->first;
2178 int currentLine = 0;
2179 cpu_label(_environment, copperlist0Named);
2180 while( actual ) {
2181 switch( actual->operation ) {
2182 case COP_NOP:
2183 outline0("NOP");
2184 break;
2185 case COP_WAIT:
2186 if ( actual->param1 > 0 ) {
2187 if ( actual->param1 > currentLine ) {
2188 if ( currentLine ) {
2189 outline2("LDA #<COPPERLIST%s%4.4x", copperList->name ? copperList->name : "", actual->param1 );
2190 outline0("STA COPPERLISTJUMP+1" );
2191 outline2("LDA #>COPPERLIST%s%4.4x", copperList->name ? copperList->name : "", actual->param1 );
2192 outline0("STA COPPERLISTJUMP+2" );
2193 outline0("RTS");
2194 }
2195 outhead2("COPPERLIST%s%4.4x:", copperList->name ? copperList->name : "", actual->param1 );
2196 currentLine = actual->param1;
2197 }
2198 }
2199 break;
2200 case COP_MOVE_DWORD:
2201 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff )+3 );
2202 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+3 );
2203 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff )+2 );
2204 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+2 );
2205 case COP_MOVE_WORD:
2206 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff )+1 );
2207 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+1 );
2208 case COP_MOVE_BYTE:
2209 outline1( "LDA $%4.4x", (unsigned short)( actual->param2 & 0xffff ) );
2210 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff ) );
2211 break;
2212 case COP_STORE_DWORD:
2213 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 >> 24 ) & 0xff ) );
2214 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+3 );
2215 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 >> 16 ) & 0xff ) );
2216 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+2 );
2217 case COP_STORE_WORD:
2218 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 >> 8 ) & 0xff ) );
2219 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff )+1 );
2220 case COP_STORE_BYTE:
2221 outline1( "LDA #$%2.2x", (unsigned char)( ( actual->param2 ) & 0xff ) );
2222 outline1( "STA $%4.4x", (unsigned short)( actual->param1 & 0xffff ) );
2223 break;
2224 case COP_COLOR:
2225 gtia_background_color( _environment, actual->param1, actual->param2 );
2226 break;
2228 gtia_background_color( _environment, 0, actual->param1 );
2229 break;
2230 case COP_COLOR_BORDER:
2231 gtia_border_color( _environment, actual->param1 );
2232 break;
2233
2234 }
2235 actual = actual->next;
2236 }
2237 outline1("LDA #<GTIAVBLIRQNOCOPPER%s", copperList->name ? copperList->name : "" );
2238 outline0("STA COPPERLISTJUMP+1" );
2239 outline1("LDA #>GTIAVBLIRQNOCOPPER%s", copperList->name ? copperList->name : "" );
2240 outline0("STA COPPERLISTJUMP+2" );
2241 outline0("RTS");
2242 copperList = copperList->next;
2243 }
2244 if ( !anon ) {
2245 outhead0("COPPERLIST0000:" );
2246 outline0("LDA #<GTIAVBLIRQNOCOPPER" );
2247 outline0("STA COPPERLISTJUMP+1" );
2248 outline0("LDA #>GTIAVBLIRQNOCOPPER" );
2249 outline0("STA COPPERLISTJUMP+2" );
2250 outline0("RTS");
2251 outhead0("GTIAVBLIRQNOCOPPER:");
2252 outline0("LDA #<COPPERLIST0000" );
2253 outline0("STA COPPERLISTJUMP+1" );
2254 outline0("LDA #>COPPERLIST0000" );
2255 outline0("STA COPPERLISTJUMP+2" );
2256 outline0("RTS");
2257 }
2258
2259 } else {
2260 outline0( "RTS");
2261 }
2262
2263}
2264
2265void gtia_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
2266
2267 deploy_preferred( textHScroll, src_hw_gtia_hscroll_text_asm );
2268
2269 Variable * y = variable_retrieve( _environment, "YCURSYS" );
2270 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
2271 outline0("STA DIRECTION" );
2272 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
2273 outline0("STA PORT" );
2274 outline1("LDA %s", y->realName );
2275 outline0("STA CLINEY");
2276
2277 outline0("JSR HSCROLLLT");
2278
2279}
2280
2281void gtia_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
2282
2283 deploy_preferred( textHScroll, src_hw_gtia_hscroll_text_asm );
2284
2285 outline1("LDA #$%2.2x", ( _direction & 0xff ) );
2286 outline0("STA DIRECTION" );
2287 outline1("LDA #$%2.2x", ( _overlap & 0xff ) );
2288 outline0("STA PORT" );
2289
2290 outline0("JSR HSCROLLST");
2291}
2292
2293void gtia_back( Environment * _environment ) {
2294
2295 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
2296 deploy( back, src_hw_gtia_back_asm );
2297
2298 outline0("JSR BACK");
2299
2300}
2301
2302void gtia_cline( Environment * _environment, char * _characters ) {
2303
2304 Variable * x = variable_retrieve( _environment, "XCURSYS" );
2305 Variable * y = variable_retrieve( _environment, "YCURSYS" );
2306
2307 if ( _characters ) {
2308 outline1("LDA %s", _characters);
2309 } else {
2310 outline0("LDA #0");
2311 }
2312 outline0("STA CHARACTERS");
2313 outline1("LDA %s", x->realName );
2314 outline0("STA CLINEX" );
2315 outline1("LDA %s", y->realName );
2316 outline0("STA CLINEY");
2317
2318 if ( _environment->currentMode >= 2 && _environment->currentMode <= 7 ) {
2319 deploy( textCline, src_hw_gtia_cline_text_asm );
2320 outline0("JSR CLINE");
2321 } else {
2322 deploy( textClineGraphic, src_hw_gtia_cline_graphic_asm );
2323 outline0("JSR CLINEG");
2324 }
2325
2326}
2327
2328int gtia_image_size( Environment * _environment, int _width, int _height, int _mode ) {
2329
2330 switch( _mode ) {
2331 // Graphics 3 (ANTIC 8)
2332 // This four-color graphics mode turns a split screen into 20 rows of 40 graphics cells or pixels.
2333 // Each pixel is 8 x 8 or the size of a normal character. The data in each pixel is encoded as two bit pairs,
2334 // four per byte. The four possible bit pair combinations 00, 01, 10, and 11 point to one of the four color registers.
2335 // The bits 00 is assigned to the background color register and the rest refer to the three foreground color registers.
2336 // When the CTIA/GTIA chip interprets the data for the four adjacent pixels stored within the byte, it refers to the color
2337 // register encoded in the bit pattern to plot the color.
2338 case BITMAP_MODE_ANTIC8:
2339 // Graphics 5 (ANTIC A or 10)
2340 // This is the four color equivalent of GRAPHICS 4 sized pixels. The pixels are 4 x 4, but two bits are required to address
2341 // the four color registers. With only four adjacent pixels encoded within a byte, the screen uses twice as much memory,
2342 // about 1K.
2344 // Graphics 7 (ANTIC D or 13)
2345 // This is the four color equivalent to GRAPHICS mode 6. It is the finest resolution four color mode and naturally the
2346 // most popular. The color is encoded in two bit-pairs exactly the same way as in GRAPHICS 3. The memory requirements
2347 // of course is much greater as there are 96 rows of 160 - 2 x 2 sized pixels. It requires 3840 bytes of screen memory
2348 // with another 104 bytes for the display list.
2350 // Antic E (Graphics 15-XL computers only)
2351 // This four-color, bit-mapped mode is sometimes known as BASIC 7 1/2. Its resolution is 160 x 192 or twice that of
2352 // GRAPHIC 7. Each byte is divided into four pairs of bits. Like the character data in ANTIC 4, the bit pairs point to a
2353 // particular color register. The screen data, however, is not character data but individual bytes. The user has a lot
2354 // more control, but this mode uses a lot more memory, approximately
2356 return 3 + ( ( _width >> 2 ) * _height ) + 4;
2357
2358 // Graphics 4 (ANTIC 9)
2359 // This is a two-color graphics mode with four times the resolution of GRAPHICS 3. The pixels are 4 x 4, and 48 rows of 80
2360 // pixels fit on a full screen. A single bit is used to store each pixel's color register. A zero refers to the background
2361 // color register and a one to the foreground color register. The mode is used primarily to conserve screen memory.
2362 // Only one bit is used for the color, so eight adjacent pixels are encoded within one byte, and only half as much screen
2363 // memory is needed for a display of similiar-sized pixels.
2364 case BITMAP_MODE_ANTIC9:
2365 // Graphics 6 (ANTIC B or 11)
2366 // This two color graphics mode has reasonably fine resolution. The 2 x 2 sized pixels allow 96 rows of 160 pixels to fit
2367 // on a full screen. Although only a single bit is used to encode the color, screen memory still requires approximately 2K.
2369 // Graphics 8 (ANTIC F or 15)
2370 // This mode is definitely the finest resolution available on the Atari. Individual dot-sized pixels can be addressed in
2371 // this one-color, two-luminance mode. There are 192 rows of 320 dots in the full screen mode. Graphics 8 is memory
2372 // intensive; it takes 8K bytes (eight pixels/byte) to address an entire screen. The color scheme is quite similar to that
2373 // in GRAPHICS mode 0. Color register #2 sets the background color. Color register #1 sets the luminance. Changing the color
2374 // in this register has no effect, but, this doesn't mean that you are limited to just one color.
2375 // Fortunately, the pixels are each one half of a color clock. It takes two pixels to span one color clock made up of
2376 // alternating columns of complementary colors. If the background is set to black, these columns consist of blue and
2377 // green stripes. If only the odd-columned pixels are plotted, you get blue pixels. If only the odd-columned pixels
2378 // are plotted, you get green pixels. And if pairs of adjacent pixels are plotted, you get white. So by cleverly
2379 // staggering the pixel patterns, you can achieve three colors. This method is called artifacting. This all depends
2380 // on background color and luminance.
2382 // Antic C (Graphics 14-XL computers only)
2383 // This two-color, bit-mapped mode the eight bits correspond directly to the pixels on the screen. If a pixel is lit
2384 // it receives its color information from color register #0, otherwise the color is set to the background color
2385 // register #4. Each pixel is one scan line high and one color clock wide. This mode's advantages are that it
2386 // only uses 4K of screen memory and doesn't have artifacting problems.
2388 return 3 + ( ( _width >> 3 ) * _height ) + 2;
2389
2390 // Graphics Mode 0 (ANTIC 2)
2391 // This is the normal-sized character or text mode that the computer defaults to on start up.
2392 // Being a character mode, screen memory consists of bytes that represent individual characters in either the
2393 // ROM or a custom character set. ANTIC displays forty of these 8 x 8 sized characters on each of
2394 // twenty-four lines. Graphics 0 is a 1 1/2 color mode. Color register #2 is used as the background color
2395 // register. Color register #1 sets the luminance of the characters against the background. Setting the
2396 // color has no effect. Bits within a character are turned on in pairs to produce the luminace color.
2397 // Otherwise single bits tend to produce colored artifacts on the high resolution screen. These colors
2398 // depend on whether the computer has a CTIA or GTIA chip, and the color of the background.
2400
2401 // Graphics 1 (ANTIC 6)
2402 // This is one the expanded text modes. Each characters is 8 x 8 but the pixels are one color clock in
2403 // width instead of the 1/2 color clock mode of Graphics 0 making the characters twice as wide. Only twenty
2404 // characters fit on any line. A graphics 1 screen has twenty rows while the full screen mode has twenty-four
2405 // rows of characters. The two high bits of each ATASCII character, that normally identify lowercase or
2406 // inverse video text in Graphics 1, set the color register for the 64 character set. Decimal character
2407 // numbers 0-63 use color register zero, while those same 64 characters if given character numbers 64-127
2408 // use color register #1. If you are typing from the Atari keyboard, the uppercase letters A-Z ATASCII 65-90
2409 // (Internal # 33-58) are assigned to color register zero, while the lowercase numbers 97-122
2410 // (Internal # 97-122) are signed to register #1.
2412
2413 // Graphics 2 (ANTIC 7)
2414 // This text mode is basically the same as the previous mode except that each row of pixels is two scan lines high.
2415 // Thus 12 rows of 20 characters are displayed on a full screen. Only ten rows fit on a split screen.
2417
2418 // Antic 3
2419 // This rarely used text mode is sometimes called the lowercase descenders mode. Each of the forty characters per line
2420 // are ten scan lines high, but since each of the characters are only eight scan lines high, the lower two scan lines are
2421 // normally left empty. However, if you use the last quarter of the character set, the top two lines remain blank,
2422 // allowing you to create lowercase characters with descenders.
2424
2425 // Antic 4 (Graphics 12-XL computers only)
2426 // This very powerful character graphics mode supports four colors while using relatively little screen memory (1 K).
2427 // In addition its 4 x 8 sized characters have the same horizontal resolution as GRAPHICS 7, yet twice the vertical resolution.
2428 // A large number of games with colorful and detailed playfields use this mode. These characters differ considerably from
2429 // ANTIC 6 (BASIC 2) characters, in that each character contains pixels of four different colors, not just a choice of one color
2430 // determined by the character number. Each byte in the character is broken into four bit pairs, each of which selects the color
2431 // register for the pixel. That is why the horizontal resolution is only four bits. A special character set generator is used
2432 // to form these characters.
2434
2435 // Antic 5 (Graphics 13-XL computers only)
2436 // This mode is essentially the same as ANTIC 4 except that each character is sixteen scan lines high.
2437 // The character set data is still eight bytes high so ANTIC double plots each scan line.
2439 break;
2440 }
2441
2442 return 0;
2443
2444}
2445
2446static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
2447
2448 switch( _mode ) {
2449 // Graphics 3 (ANTIC 8)
2450 // This four-color graphics mode turns a split screen into 20 rows of 40 graphics cells or pixels.
2451 // Each pixel is 8 x 8 or the size of a normal character. The data in each pixel is encoded as two bit pairs,
2452 // four per byte. The four possible bit pair combinations 00, 01, 10, and 11 point to one of the four color registers.
2453 // The bits 00 is assigned to the background color register and the rest refer to the three foreground color registers.
2454 // When the CTIA/GTIA chip interprets the data for the four adjacent pixels stored within the byte, it refers to the color
2455 // register encoded in the bit pattern to plot the color.
2456 case BITMAP_MODE_ANTIC8:
2457 // Graphics 5 (ANTIC A or 10)
2458 // This is the four color equivalent of GRAPHICS 4 sized pixels. The pixels are 4 x 4, but two bits are required to address
2459 // the four color registers. With only four adjacent pixels encoded within a byte, the screen uses twice as much memory,
2460 // about 1K.
2462 // Graphics 7 (ANTIC D or 13)
2463 // This is the four color equivalent to GRAPHICS mode 6. It is the finest resolution four color mode and naturally the
2464 // most popular. The color is encoded in two bit-pairs exactly the same way as in GRAPHICS 3. The memory requirements
2465 // of course is much greater as there are 96 rows of 160 - 2 x 2 sized pixels. It requires 3840 bytes of screen memory
2466 // with another 104 bytes for the display list.
2468 // Antic E (Graphics 15-XL computers only)
2469 // This four-color, bit-mapped mode is sometimes known as BASIC 7 1/2. Its resolution is 160 x 192 or twice that of
2470 // GRAPHIC 7. Each byte is divided into four pairs of bits. Like the character data in ANTIC 4, the bit pairs point to a
2471 // particular color register. The screen data, however, is not character data but individual bytes. The user has a lot
2472 // more control, but this mode uses a lot more memory, approximately
2474 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) + 4 ) * _frames;
2475
2476 // Graphics 4 (ANTIC 9)
2477 // This is a two-color graphics mode with four times the resolution of GRAPHICS 3. The pixels are 4 x 4, and 48 rows of 80
2478 // pixels fit on a full screen. A single bit is used to store each pixel's color register. A zero refers to the background
2479 // color register and a one to the foreground color register. The mode is used primarily to conserve screen memory.
2480 // Only one bit is used for the color, so eight adjacent pixels are encoded within one byte, and only half as much screen
2481 // memory is needed for a display of similiar-sized pixels.
2482 case BITMAP_MODE_ANTIC9:
2483 // Graphics 6 (ANTIC B or 11)
2484 // This two color graphics mode has reasonably fine resolution. The 2 x 2 sized pixels allow 96 rows of 160 pixels to fit
2485 // on a full screen. Although only a single bit is used to encode the color, screen memory still requires approximately 2K.
2487 // Graphics 8 (ANTIC F or 15)
2488 // This mode is definitely the finest resolution available on the Atari. Individual dot-sized pixels can be addressed in
2489 // this one-color, two-luminance mode. There are 192 rows of 320 dots in the full screen mode. Graphics 8 is memory
2490 // intensive; it takes 8K bytes (eight pixels/byte) to address an entire screen. The color scheme is quite similar to that
2491 // in GRAPHICS mode 0. Color register #2 sets the background color. Color register #1 sets the luminance. Changing the color
2492 // in this register has no effect, but, this doesn't mean that you are limited to just one color.
2493 // Fortunately, the pixels are each one half of a color clock. It takes two pixels to span one color clock made up of
2494 // alternating columns of complementary colors. If the background is set to black, these columns consist of blue and
2495 // green stripes. If only the odd-columned pixels are plotted, you get blue pixels. If only the odd-columned pixels
2496 // are plotted, you get green pixels. And if pairs of adjacent pixels are plotted, you get white. So by cleverly
2497 // staggering the pixel patterns, you can achieve three colors. This method is called artifacting. This all depends
2498 // on background color and luminance.
2500 // Antic C (Graphics 14-XL computers only)
2501 // This two-color, bit-mapped mode the eight bits correspond directly to the pixels on the screen. If a pixel is lit
2502 // it receives its color information from color register #0, otherwise the color is set to the background color
2503 // register #4. Each pixel is one scan line high and one color clock wide. This mode's advantages are that it
2504 // only uses 4K of screen memory and doesn't have artifacting problems.
2506 return 3 + ( 3 + ( ( _width >> 3 ) * _height ) + 2 ) * _frames;
2507
2508 // Graphics Mode 0 (ANTIC 2)
2509 // This is the normal-sized character or text mode that the computer defaults to on start up.
2510 // Being a character mode, screen memory consists of bytes that represent individual characters in either the
2511 // ROM or a custom character set. ANTIC displays forty of these 8 x 8 sized characters on each of
2512 // twenty-four lines. Graphics 0 is a 1 1/2 color mode. Color register #2 is used as the background color
2513 // register. Color register #1 sets the luminance of the characters against the background. Setting the
2514 // color has no effect. Bits within a character are turned on in pairs to produce the luminace color.
2515 // Otherwise single bits tend to produce colored artifacts on the high resolution screen. These colors
2516 // depend on whether the computer has a CTIA or GTIA chip, and the color of the background.
2518
2519 // Graphics 1 (ANTIC 6)
2520 // This is one the expanded text modes. Each characters is 8 x 8 but the pixels are one color clock in
2521 // width instead of the 1/2 color clock mode of Graphics 0 making the characters twice as wide. Only twenty
2522 // characters fit on any line. A graphics 1 screen has twenty rows while the full screen mode has twenty-four
2523 // rows of characters. The two high bits of each ATASCII character, that normally identify lowercase or
2524 // inverse video text in Graphics 1, set the color register for the 64 character set. Decimal character
2525 // numbers 0-63 use color register zero, while those same 64 characters if given character numbers 64-127
2526 // use color register #1. If you are typing from the Atari keyboard, the uppercase letters A-Z ATASCII 65-90
2527 // (Internal # 33-58) are assigned to color register zero, while the lowercase numbers 97-122
2528 // (Internal # 97-122) are signed to register #1.
2530
2531 // Graphics 2 (ANTIC 7)
2532 // This text mode is basically the same as the previous mode except that each row of pixels is two scan lines high.
2533 // Thus 12 rows of 20 characters are displayed on a full screen. Only ten rows fit on a split screen.
2535
2536 // Antic 3
2537 // This rarely used text mode is sometimes called the lowercase descenders mode. Each of the forty characters per line
2538 // are ten scan lines high, but since each of the characters are only eight scan lines high, the lower two scan lines are
2539 // normally left empty. However, if you use the last quarter of the character set, the top two lines remain blank,
2540 // allowing you to create lowercase characters with descenders.
2542
2543 // Antic 4 (Graphics 12-XL computers only)
2544 // This very powerful character graphics mode supports four colors while using relatively little screen memory (1 K).
2545 // In addition its 4 x 8 sized characters have the same horizontal resolution as GRAPHICS 7, yet twice the vertical resolution.
2546 // A large number of games with colorful and detailed playfields use this mode. These characters differ considerably from
2547 // ANTIC 6 (BASIC 2) characters, in that each character contains pixels of four different colors, not just a choice of one color
2548 // determined by the character number. Each byte in the character is broken into four bit pairs, each of which selects the color
2549 // register for the pixel. That is why the horizontal resolution is only four bits. A special character set generator is used
2550 // to form these characters.
2552
2553 // Antic 5 (Graphics 13-XL computers only)
2554 // This mode is essentially the same as ANTIC 4 except that each character is sixteen scan lines high.
2555 // The character set data is still eight bytes high so ANTIC double plots each scan line.
2557 break;
2558 }
2559
2560 return 0;
2561
2562}
2563
2564static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
2565
2566 switch( _mode ) {
2567 // Graphics 3 (ANTIC 8)
2568 // This four-color graphics mode turns a split screen into 20 rows of 40 graphics cells or pixels.
2569 // Each pixel is 8 x 8 or the size of a normal character. The data in each pixel is encoded as two bit pairs,
2570 // four per byte. The four possible bit pair combinations 00, 01, 10, and 11 point to one of the four color registers.
2571 // The bits 00 is assigned to the background color register and the rest refer to the three foreground color registers.
2572 // When the CTIA/GTIA chip interprets the data for the four adjacent pixels stored within the byte, it refers to the color
2573 // register encoded in the bit pattern to plot the color.
2574 case BITMAP_MODE_ANTIC8:
2575 // Graphics 5 (ANTIC A or 10)
2576 // This is the four color equivalent of GRAPHICS 4 sized pixels. The pixels are 4 x 4, but two bits are required to address
2577 // the four color registers. With only four adjacent pixels encoded within a byte, the screen uses twice as much memory,
2578 // about 1K.
2580 // Graphics 7 (ANTIC D or 13)
2581 // This is the four color equivalent to GRAPHICS mode 6. It is the finest resolution four color mode and naturally the
2582 // most popular. The color is encoded in two bit-pairs exactly the same way as in GRAPHICS 3. The memory requirements
2583 // of course is much greater as there are 96 rows of 160 - 2 x 2 sized pixels. It requires 3840 bytes of screen memory
2584 // with another 104 bytes for the display list.
2586 // Antic E (Graphics 15-XL computers only)
2587 // This four-color, bit-mapped mode is sometimes known as BASIC 7 1/2. Its resolution is 160 x 192 or twice that of
2588 // GRAPHIC 7. Each byte is divided into four pairs of bits. Like the character data in ANTIC 4, the bit pairs point to a
2589 // particular color register. The screen data, however, is not character data but individual bytes. The user has a lot
2590 // more control, but this mode uses a lot more memory, approximately
2592 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) + 4 ) * _frames ) * _sequences;
2593
2594 // Graphics 4 (ANTIC 9)
2595 // This is a two-color graphics mode with four times the resolution of GRAPHICS 3. The pixels are 4 x 4, and 48 rows of 80
2596 // pixels fit on a full screen. A single bit is used to store each pixel's color register. A zero refers to the background
2597 // color register and a one to the foreground color register. The mode is used primarily to conserve screen memory.
2598 // Only one bit is used for the color, so eight adjacent pixels are encoded within one byte, and only half as much screen
2599 // memory is needed for a display of similiar-sized pixels.
2600 case BITMAP_MODE_ANTIC9:
2601 // Graphics 6 (ANTIC B or 11)
2602 // This two color graphics mode has reasonably fine resolution. The 2 x 2 sized pixels allow 96 rows of 160 pixels to fit
2603 // on a full screen. Although only a single bit is used to encode the color, screen memory still requires approximately 2K.
2605 // Graphics 8 (ANTIC F or 15)
2606 // This mode is definitely the finest resolution available on the Atari. Individual dot-sized pixels can be addressed in
2607 // this one-color, two-luminance mode. There are 192 rows of 320 dots in the full screen mode. Graphics 8 is memory
2608 // intensive; it takes 8K bytes (eight pixels/byte) to address an entire screen. The color scheme is quite similar to that
2609 // in GRAPHICS mode 0. Color register #2 sets the background color. Color register #1 sets the luminance. Changing the color
2610 // in this register has no effect, but, this doesn't mean that you are limited to just one color.
2611 // Fortunately, the pixels are each one half of a color clock. It takes two pixels to span one color clock made up of
2612 // alternating columns of complementary colors. If the background is set to black, these columns consist of blue and
2613 // green stripes. If only the odd-columned pixels are plotted, you get blue pixels. If only the odd-columned pixels
2614 // are plotted, you get green pixels. And if pairs of adjacent pixels are plotted, you get white. So by cleverly
2615 // staggering the pixel patterns, you can achieve three colors. This method is called artifacting. This all depends
2616 // on background color and luminance.
2618 // Antic C (Graphics 14-XL computers only)
2619 // This two-color, bit-mapped mode the eight bits correspond directly to the pixels on the screen. If a pixel is lit
2620 // it receives its color information from color register #0, otherwise the color is set to the background color
2621 // register #4. Each pixel is one scan line high and one color clock wide. This mode's advantages are that it
2622 // only uses 4K of screen memory and doesn't have artifacting problems.
2624 return 3 + ( ( 3 + ( ( _width >> 3 ) * _height ) + 2 ) * _frames ) * _sequences;
2625
2626 // Graphics Mode 0 (ANTIC 2)
2627 // This is the normal-sized character or text mode that the computer defaults to on start up.
2628 // Being a character mode, screen memory consists of bytes that represent individual characters in either the
2629 // ROM or a custom character set. ANTIC displays forty of these 8 x 8 sized characters on each of
2630 // twenty-four lines. Graphics 0 is a 1 1/2 color mode. Color register #2 is used as the background color
2631 // register. Color register #1 sets the luminance of the characters against the background. Setting the
2632 // color has no effect. Bits within a character are turned on in pairs to produce the luminace color.
2633 // Otherwise single bits tend to produce colored artifacts on the high resolution screen. These colors
2634 // depend on whether the computer has a CTIA or GTIA chip, and the color of the background.
2636
2637 // Graphics 1 (ANTIC 6)
2638 // This is one the expanded text modes. Each characters is 8 x 8 but the pixels are one color clock in
2639 // width instead of the 1/2 color clock mode of Graphics 0 making the characters twice as wide. Only twenty
2640 // characters fit on any line. A graphics 1 screen has twenty rows while the full screen mode has twenty-four
2641 // rows of characters. The two high bits of each ATASCII character, that normally identify lowercase or
2642 // inverse video text in Graphics 1, set the color register for the 64 character set. Decimal character
2643 // numbers 0-63 use color register zero, while those same 64 characters if given character numbers 64-127
2644 // use color register #1. If you are typing from the Atari keyboard, the uppercase letters A-Z ATASCII 65-90
2645 // (Internal # 33-58) are assigned to color register zero, while the lowercase numbers 97-122
2646 // (Internal # 97-122) are signed to register #1.
2648
2649 // Graphics 2 (ANTIC 7)
2650 // This text mode is basically the same as the previous mode except that each row of pixels is two scan lines high.
2651 // Thus 12 rows of 20 characters are displayed on a full screen. Only ten rows fit on a split screen.
2653
2654 // Antic 3
2655 // This rarely used text mode is sometimes called the lowercase descenders mode. Each of the forty characters per line
2656 // are ten scan lines high, but since each of the characters are only eight scan lines high, the lower two scan lines are
2657 // normally left empty. However, if you use the last quarter of the character set, the top two lines remain blank,
2658 // allowing you to create lowercase characters with descenders.
2660
2661 // Antic 4 (Graphics 12-XL computers only)
2662 // This very powerful character graphics mode supports four colors while using relatively little screen memory (1 K).
2663 // In addition its 4 x 8 sized characters have the same horizontal resolution as GRAPHICS 7, yet twice the vertical resolution.
2664 // A large number of games with colorful and detailed playfields use this mode. These characters differ considerably from
2665 // ANTIC 6 (BASIC 2) characters, in that each character contains pixels of four different colors, not just a choice of one color
2666 // determined by the character number. Each byte in the character is broken into four bit pairs, each of which selects the color
2667 // register for the pixel. That is why the horizontal resolution is only four bits. A special character set generator is used
2668 // to form these characters.
2670
2671 // Antic 5 (Graphics 13-XL computers only)
2672 // This mode is essentially the same as ANTIC 4 except that each character is sixteen scan lines high.
2673 // The character set data is still eight bytes high so ANTIC double plots each scan line.
2675 break;
2676 }
2677
2678 return 0;
2679
2680}
2681
2682static Variable * gtia_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 ) {
2683
2684 // ignored on bitmap mode
2685 (void)!_transparent_color;
2686
2687 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
2688
2689 if ( _environment->freeImageWidth ) {
2690 if ( _width % 8 ) {
2691 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2692 }
2693 if ( _frame_width % 8 ) {
2694 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2695 }
2696 }
2697
2698 RGBi * palette = malloc_palette( MAX_PALETTE );
2699
2700 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2701
2702 if (paletteColorCount > 2) {
2703 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
2704 }
2705
2706 int i, j, k;
2707
2708 if ( ! commonPalette ) {
2709
2710 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2711 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
2712
2713 if ( _transparent_color & 0x0f0000 ) {
2714 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
2715 }
2716 if ( _transparent_color & 0xf00000 ) {
2717 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 2 );
2718 paletteColorCount = 2;
2719 }
2720
2721 lastUsedSlotInCommonPalette = paletteColorCount;
2722 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
2723
2724 } else {
2725
2726 RGBi * newPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2727 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
2728 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
2729
2730 int mergedCommonPalette = 0;
2731
2732 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
2733
2734 if ( _transparent_color & 0x0f0000 ) {
2735 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
2736 }
2737 if ( _transparent_color & 0xf00000 ) {
2738 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 2 );
2739 mergedCommonPalette = 2;
2740 }
2741
2742 lastUsedSlotInCommonPalette = mergedCommonPalette;
2743 if ( lastUsedSlotInCommonPalette > 2 ) {
2745 }
2746 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
2747
2748 }
2749
2750 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2752 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
2753
2754 int bufferSize = gtia_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_ANTIC9 );
2755
2756 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_ANTIC9 );
2757
2758 adilinebeginbitmap("BMD");
2759
2760 char * buffer = malloc ( bufferSize );
2761
2762 // Position of the pixel in the original image
2763 int image_x, image_y;
2764
2765 // Position of the pixel, in terms of tiles
2766 int tile_x, tile_y;
2767
2768 // Position of the pixel, in terms of offset and bitmask
2769 int offset, bitmask;
2770
2771 int colorIndex;
2772
2773 // Color of the pixel to convert
2774 RGBi rgb;
2775
2776 *(buffer) = (_frame_width & 0xff);
2777 *(buffer+1) = ( _frame_width >> 8 ) & 0xff;
2778 *(buffer+2) = _frame_height;
2779
2780 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2781
2782 // Loop for all the source surface.
2783 for (image_y = 0; image_y < _frame_height; ++image_y) {
2784 for (image_x = 0; image_x < _frame_width; ++image_x) {
2785
2786 // Take the color of the pixel
2787 rgb.red = *_source;
2788 rgb.green = *(_source + 1);
2789 rgb.blue = *(_source + 2);
2790 if ( _depth > 3 ) {
2791 rgb.alpha = *(_source + 3);
2792 } else {
2793 rgb.alpha = 255;
2794 }
2795 if ( rgb.alpha == 0 ) {
2796 rgb.red = 0;
2797 rgb.green = 0;
2798 rgb.blue = 0;
2799 }
2800
2801 if ( rgb.alpha < 255 ) {
2802 colorIndex = 0;
2803 } else {
2804 int minDistance = 9999;
2805 for( int i=(_transparent_color); i<lastUsedSlotInCommonPalette; ++i ) {
2806 int distance = rgbi_distance(&commonPalette[i], &rgb );
2807 if ( distance < minDistance ) {
2808 minDistance = distance;
2809 colorIndex = i;
2810 }
2811 }
2812 }
2813
2814 adilinepixel(colorIndex);
2815
2816 // printf("%d", i );
2817
2818 // Calculate the offset starting from the tile surface area
2819 // and the bit to set.
2820 offset = (image_y *( _frame_width >> 3 ) ) + (image_x >> 3 );
2821 bitmask = 1 << ( 7 - (image_x & 0x7) );
2822
2823 if ( colorIndex == 1 ) {
2824 *( buffer + offset + 3) |= bitmask;
2825 // printf( "%1.1x", commonPalette[1].index );
2826 } else {
2827 *( buffer + offset + 3) &= ~bitmask;
2828 // printf( "%1.1x", commonPalette[0].index );
2829 }
2830
2831 _source += _depth;
2832
2833 }
2834
2835 // printf( "\n" );
2836
2837 _source += ( _width - _frame_width ) * _depth;
2838
2839 // printf("\n" );
2840
2841 }
2842
2843 // printf( "\n\n\n" );
2844
2846
2847 if ( lastUsedSlotInCommonPalette > 1 ) {
2848 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) + 1 ) = palette[1].index;
2849 } else {
2850 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) + 1 ) = 0xff;
2851 }
2852
2853 if ( lastUsedSlotInCommonPalette > 0 ) {
2854 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) ) = palette[0].index;
2855 } else {
2856 *(buffer + 3 + ( ( _frame_width >> 3 ) * _frame_height ) ) = 0xff;
2857 }
2858
2859 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
2860
2861 return result;
2862
2863}
2864
2865
2866static Variable * gtia_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 ) {
2867
2868 // ignored on bitmap mode
2869 (void)!_transparent_color;
2870
2871 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
2872
2873 if ( _environment->freeImageWidth ) {
2874 if ( _width % 8 ) {
2875 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
2876 }
2877 if ( _frame_width % 8 ) {
2878 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
2879 }
2880 }
2881
2882 RGBi * palette = malloc_palette( MAX_PALETTE );
2883
2884 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
2885
2886 if (paletteColorCount > 4) {
2887 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
2888 }
2889
2890 int i, j, k;
2891
2892 if ( ! commonPalette ) {
2893
2894 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2895 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
2896
2897 if ( _transparent_color & 0x0f0000 ) {
2898 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, paletteColorCount );
2899 }
2900 if ( _transparent_color & 0xf00000 ) {
2901 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, paletteColorCount, 4 );
2902 paletteColorCount = 4;
2903 }
2904
2905 lastUsedSlotInCommonPalette = paletteColorCount;
2906 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
2907
2908 } else {
2909
2910 RGBi * newPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) );
2911 newPalette = palette_remove_duplicates( newPalette, paletteColorCount, &paletteColorCount );
2912 adilinepalette( "CPM1:%d", paletteColorCount, newPalette );
2913
2914 int mergedCommonPalette = 0;
2915
2916 commonPalette = palette_merge( commonPalette, lastUsedSlotInCommonPalette, newPalette, paletteColorCount, &mergedCommonPalette );
2917
2918 if ( _transparent_color & 0x0f0000 ) {
2919 commonPalette = palette_promote_color_as_background( _transparent_color & 0xff, commonPalette, mergedCommonPalette );
2920 }
2921 if ( _transparent_color & 0xf00000 ) {
2922 commonPalette = palette_promote_color_as_foreground( ( _transparent_color >> 8 ) & 0xff, commonPalette, mergedCommonPalette, 4 );
2923 mergedCommonPalette = 4;
2924 }
2925
2926 lastUsedSlotInCommonPalette = mergedCommonPalette;
2927 if ( lastUsedSlotInCommonPalette > 4 ) {
2929 }
2930 adilinepalette( "CPM2:%d", lastUsedSlotInCommonPalette, commonPalette );
2931
2932 }
2933
2934 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
2936 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
2937
2938 int bufferSize = gtia_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_ANTIC8 );
2939
2940 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_ANTIC8 );
2941
2942 adilinebeginbitmap("BMD");
2943
2944 char * buffer = malloc ( bufferSize );
2945 memset( buffer, 0, bufferSize );
2946
2947 // Position of the pixel in the original image
2948 int image_x, image_y;
2949
2950 // Position of the pixel, in terms of tiles
2951 int tile_x, tile_y;
2952
2953 // Position of the pixel, in terms of offset and bitmask
2954 int offset, offsetc, bitmask;
2955
2956 // Color of the pixel to convert
2957 RGBi rgb;
2958
2959 *(buffer) = (_frame_width & 0xff);
2960 *(buffer+1) = (_frame_width >> 8 ) & 0xff;
2961 *(buffer+2) = _frame_height;
2962
2963 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
2964
2965 // Loop for all the source surface.
2966 for (image_y = 0; image_y < _frame_height; ++image_y) {
2967 for (image_x = 0; image_x < _frame_width; ++image_x) {
2968
2969 // Take the color of the pixel
2970 rgb.red = *_source;
2971 rgb.green = *(_source + 1);
2972 rgb.blue = *(_source + 2);
2973 if ( _depth > 3 ) {
2974 rgb.alpha = *(_source + 3);
2975 } else {
2976 rgb.alpha = 255;
2977 }
2978 if ( rgb.alpha == 0 ) {
2979 rgb.red = 0;
2980 rgb.green = 0;
2981 rgb.blue = 0;
2982 }
2983
2984 // Calculate the offset starting from the tile surface area
2985 // and the bit to set.
2986 offset = (image_y * ( _frame_width >> 2 ) ) + (image_x>>2);
2987
2988 int colorIndex = 0;
2989
2990 if ( rgb.alpha < 255 ) {
2991 colorIndex = 0;
2992 } else {
2993 int minDistance = 9999;
2994 for( int i=(_transparent_color); i<lastUsedSlotInCommonPalette; ++i ) {
2995 int distance = rgbi_distance(&commonPalette[i], &rgb );
2996 if ( distance < minDistance ) {
2997 minDistance = distance;
2998 colorIndex = i;
2999 }
3000 }
3001 }
3002
3003 adilinepixel(colorIndex);
3004
3005 bitmask = colorIndex << (6 - ((image_x & 0x3) * 2));
3006
3007 *(buffer + 3 + offset) |= bitmask;
3008
3009 _source += _depth;
3010
3011 }
3012
3013 _source += ( _width - _frame_width ) * _depth;
3014
3015 }
3016
3018
3019 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) ) = commonPalette[0].index;
3020
3021 if ( lastUsedSlotInCommonPalette > 1 ) {
3022 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 1 ) = commonPalette[1].index;
3023 } else {
3024 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 1 ) = 0xff;
3025 }
3026
3027 if ( lastUsedSlotInCommonPalette > 2 ) {
3028 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 2 ) = commonPalette[2].index;
3029 } else {
3030 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 2 ) = 0xff;
3031 }
3032
3033 if ( lastUsedSlotInCommonPalette > 3 ) {
3034 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 3 ) = commonPalette[3].index;
3035 } else {
3036 *(buffer + 3 + ( ( _frame_width >> 2 ) * _frame_height ) + 3 ) = 0xff;
3037 }
3038
3039 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
3040
3041 return result;
3042
3043}
3044
3045Variable * gtia_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 ) {
3046
3047 switch( _mode ) {
3048 // Graphics 3 (ANTIC 8)
3049 // This four-color graphics mode turns a split screen into 20 rows of 40 graphics cells or pixels.
3050 // Each pixel is 8 x 8 or the size of a normal character. The data in each pixel is encoded as two bit pairs,
3051 // four per byte. The four possible bit pair combinations 00, 01, 10, and 11 point to one of the four color registers.
3052 // The bits 00 is assigned to the background color register and the rest refer to the three foreground color registers.
3053 // When the CTIA/GTIA chip interprets the data for the four adjacent pixels stored within the byte, it refers to the color
3054 // register encoded in the bit pattern to plot the color.
3055 case BITMAP_MODE_ANTIC8:
3056 return gtia_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3057
3058 // Graphics 4 (ANTIC 9)
3059 // This is a two-color graphics mode with four times the resolution of GRAPHICS 3. The pixels are 4 x 4, and 48 rows of 80
3060 // pixels fit on a full screen. A single bit is used to store each pixel's color register. A zero refers to the background
3061 // color register and a one to the foreground color register. The mode is used primarily to conserve screen memory.
3062 // Only one bit is used for the color, so eight adjacent pixels are encoded within one byte, and only half as much screen
3063 // memory is needed for a display of similiar-sized pixels.
3064 case BITMAP_MODE_ANTIC9:
3065 return gtia_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3066
3067 // Graphics 5 (ANTIC A or 10)
3068 // This is the four color equivalent of GRAPHICS 4 sized pixels. The pixels are 4 x 4, but two bits are required to address
3069 // the four color registers. With only four adjacent pixels encoded within a byte, the screen uses twice as much memory,
3070 // about 1K.
3072 return gtia_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3073
3074 // Graphics 6 (ANTIC B or 11)
3075 // This two color graphics mode has reasonably fine resolution. The 2 x 2 sized pixels allow 96 rows of 160 pixels to fit
3076 // on a full screen. Although only a single bit is used to encode the color, screen memory still requires approximately 2K.
3078 return gtia_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3079
3080 // Graphics 7 (ANTIC D or 13)
3081 // This is the four color equivalent to GRAPHICS mode 6. It is the finest resolution four color mode and naturally the
3082 // most popular. The color is encoded in two bit-pairs exactly the same way as in GRAPHICS 3. The memory requirements
3083 // of course is much greater as there are 96 rows of 160 - 2 x 2 sized pixels. It requires 3840 bytes of screen memory
3084 // with another 104 bytes for the display list.
3086 return gtia_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3087
3088 // Graphics 8 (ANTIC F or 15)
3089 // This mode is definitely the finest resolution available on the Atari. Individual dot-sized pixels can be addressed in
3090 // this one-color, two-luminance mode. There are 192 rows of 320 dots in the full screen mode. Graphics 8 is memory
3091 // intensive; it takes 8K bytes (eight pixels/byte) to address an entire screen. The color scheme is quite similar to that
3092 // in GRAPHICS mode 0. Color register #2 sets the background color. Color register #1 sets the luminance. Changing the color
3093 // in this register has no effect, but, this doesn't mean that you are limited to just one color.
3094 // Fortunately, the pixels are each one half of a color clock. It takes two pixels to span one color clock made up of
3095 // alternating columns of complementary colors. If the background is set to black, these columns consist of blue and
3096 // green stripes. If only the odd-columned pixels are plotted, you get blue pixels. If only the odd-columned pixels
3097 // are plotted, you get green pixels. And if pairs of adjacent pixels are plotted, you get white. So by cleverly
3098 // staggering the pixel patterns, you can achieve three colors. This method is called artifacting. This all depends
3099 // on background color and luminance.
3101 return gtia_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3102
3103 // The following five graphics modes have no equivalent in BASIC on older machine but if indicated do correspond to
3104 // an equivalent graphics mode on the newer XL models.
3105
3106 // Antic C (Graphics 14-XL computers only)
3107 // This two-color, bit-mapped mode the eight bits correspond directly to the pixels on the screen. If a pixel is lit
3108 // it receives its color information from color register #0, otherwise the color is set to the background color
3109 // register #4. Each pixel is one scan line high and one color clock wide. This mode's advantages are that it
3110 // only uses 4K of screen memory and doesn't have artifacting problems.
3112 return gtia_image_converter_bitmap_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3113
3114 // Antic E (Graphics 15-XL computers only)
3115 // This four-color, bit-mapped mode is sometimes known as BASIC 7 1/2. Its resolution is 160 x 192 or twice that of
3116 // GRAPHIC 7. Each byte is divided into four pairs of bits. Like the character data in ANTIC 4, the bit pairs point to a
3117 // particular color register. The screen data, however, is not character data but individual bytes. The user has a lot
3118 // more control, but this mode uses a lot more memory, approximately
3120 return gtia_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height , _transparent_color, _flags );
3121
3122 // Graphics Mode 0 (ANTIC 2)
3123 // This is the normal-sized character or text mode that the computer defaults to on start up.
3124 // Being a character mode, screen memory consists of bytes that represent individual characters in either the
3125 // ROM or a custom character set. ANTIC displays forty of these 8 x 8 sized characters on each of
3126 // twenty-four lines. Graphics 0 is a 1 1/2 color mode. Color register #2 is used as the background color
3127 // register. Color register #1 sets the luminance of the characters against the background. Setting the
3128 // color has no effect. Bits within a character are turned on in pairs to produce the luminace color.
3129 // Otherwise single bits tend to produce colored artifacts on the high resolution screen. These colors
3130 // depend on whether the computer has a CTIA or GTIA chip, and the color of the background.
3132
3133 // Graphics 1 (ANTIC 6)
3134 // This is one the expanded text modes. Each characters is 8 x 8 but the pixels are one color clock in
3135 // width instead of the 1/2 color clock mode of Graphics 0 making the characters twice as wide. Only twenty
3136 // characters fit on any line. A graphics 1 screen has twenty rows while the full screen mode has twenty-four
3137 // rows of characters. The two high bits of each ATASCII character, that normally identify lowercase or
3138 // inverse video text in Graphics 1, set the color register for the 64 character set. Decimal character
3139 // numbers 0-63 use color register zero, while those same 64 characters if given character numbers 64-127
3140 // use color register #1. If you are typing from the Atari keyboard, the uppercase letters A-Z ATASCII 65-90
3141 // (Internal # 33-58) are assigned to color register zero, while the lowercase numbers 97-122
3142 // (Internal # 97-122) are signed to register #1.
3144
3145 // Graphics 2 (ANTIC 7)
3146 // This text mode is basically the same as the previous mode except that each row of pixels is two scan lines high.
3147 // Thus 12 rows of 20 characters are displayed on a full screen. Only ten rows fit on a split screen.
3149
3150 // Antic 3
3151 // This rarely used text mode is sometimes called the lowercase descenders mode. Each of the forty characters per line
3152 // are ten scan lines high, but since each of the characters are only eight scan lines high, the lower two scan lines are
3153 // normally left empty. However, if you use the last quarter of the character set, the top two lines remain blank,
3154 // allowing you to create lowercase characters with descenders.
3156
3157 // Antic 4 (Graphics 12-XL computers only)
3158 // This very powerful character graphics mode supports four colors while using relatively little screen memory (1 K).
3159 // In addition its 4 x 8 sized characters have the same horizontal resolution as GRAPHICS 7, yet twice the vertical resolution.
3160 // A large number of games with colorful and detailed playfields use this mode. These characters differ considerably from
3161 // ANTIC 6 (BASIC 2) characters, in that each character contains pixels of four different colors, not just a choice of one color
3162 // determined by the character number. Each byte in the character is broken into four bit pairs, each of which selects the color
3163 // register for the pixel. That is why the horizontal resolution is only four bits. A special character set generator is used
3164 // to form these characters.
3166
3167 // Antic 5 (Graphics 13-XL computers only)
3168 // This mode is essentially the same as ANTIC 4 except that each character is sixteen scan lines high.
3169 // The character set data is still eight bytes high so ANTIC double plots each scan line.
3171 break;
3172 }
3173
3175
3176 return gtia_new_image( _environment, 8, 8, BITMAP_MODE_ANTIC13 );
3177
3178}
3179
3180static void gtia_load_image_address_to_other_register( Environment * _environment, char * _register, char * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
3181
3182 outline1("LDA #<%s", _source );
3183 outline1("STA %s", _register );
3184 outline1("LDA #>%s", _source );
3185 outline1("STA %s", address_displacement(_environment, _register, "1") );
3186
3187 if ( _sequence ) {
3188
3189 outline0("CLC" );
3190 outline1("LDA %s", _register );
3191 outline0("ADC #3" );
3192 outline1("STA %s", _register );
3193 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3194 outline0("ADC #0" );
3195 outline1("STA %s", address_displacement(_environment, _register, "1") );
3196 if ( strlen(_sequence) == 0 ) {
3197
3198 } else {
3199 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
3200 outline0("STA MATHPTR0" );
3201 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
3202 outline0("STA MATHPTR0+1" );
3203 outline0("CLC" );
3204 outline1("LDA %s", _sequence );
3205 outline0("ASL" );
3206 outline0("TAY" );
3207 outline1("LDA %s", _register );
3208 outline0("ADC (MATHPTR0), Y" );
3209 outline1("STA %s", _register );
3210 outline0("INY" );
3211 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3212 outline0("ADC (MATHPTR0), Y" );
3213 outline1("STA %s", address_displacement(_environment, _register, "1") );
3214 }
3215
3216 if ( _frame ) {
3217 if ( strlen(_frame) == 0 ) {
3218
3219 } else {
3220 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3221 outline0("STA MATHPTR0" );
3222 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3223 outline0("STA MATHPTR0+1" );
3224 outline0("CLC" );
3225 outline1("LDA %s", _frame );
3226 outline0("ASL" );
3227 outline0("TAY" );
3228 outline1("LDA %s", _register );
3229 outline0("ADC (MATHPTR0), Y" );
3230 outline1("STA %s", _register );
3231 outline0("INY" );
3232 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3233 outline0("ADC (MATHPTR0), Y" );
3234 outline1("STA %s", address_displacement(_environment, _register, "1") );
3235 }
3236 }
3237
3238 } else {
3239
3240 if ( _frame ) {
3241 outline0("CLC" );
3242 outline1("LDA %s", _register );
3243 outline0("ADC #3" );
3244 outline1("STA %s", _register );
3245 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3246 outline0("ADC #0" );
3247 outline1("STA %s", address_displacement(_environment, _register, "1") );
3248 if ( strlen(_frame) == 0 ) {
3249
3250 } else {
3251 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3252 outline0("STA MATHPTR0" );
3253 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3254 outline0("STA MATHPTR0+1" );
3255 outline0("CLC" );
3256 outline1("LDA %s", _frame );
3257 outline0("ASL" );
3258 outline0("TAY" );
3259 outline1("LDA %s", _register );
3260 outline0("ADC (MATHPTR0), Y" );
3261 outline1("STA %s", _register );
3262 outline0("INY" );
3263 outline1("LDA %s", address_displacement(_environment, _register, "1") );
3264 outline0("ADC (MATHPTR0), Y" );
3265 outline1("STA %s", address_displacement(_environment, _register, "1") );
3266 }
3267 }
3268
3269 }
3270
3271}
3272
3273
3274static void gtia_load_image_address_to_register( Environment * _environment, char * _register, Resource * _source, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
3275
3276 if ( !_sequence && !_frame ) {
3277 if ( _source->isAddress ) {
3278 outline1("LDA %s", _source->realName );
3279 outline1("STA %s", _register );
3280 outline1("LDA %s", address_displacement(_environment, _source->realName, "1") );
3281 outline1("STA %s", address_displacement(_environment, _register, "1") );
3282 } else {
3283 outline1("LDA #<%s", _source->realName );
3284 outline1("STA %s", _register );
3285 outline1("LDA #>%s", _source->realName );
3286 outline1("STA %s", address_displacement(_environment, _register, "1") );
3287 }
3288 } else {
3289 if ( _source->isAddress ) {
3290 outline1("LDA %s", _source->realName );
3291 outline0("STA TMPPTR" );
3292 outline1("LDA %s", address_displacement(_environment, _source->realName, "1") );
3293 outline0("STA TMPPTR+1" );
3294 } else {
3295 outline1("LDA #<%s", _source->realName );
3296 outline0("STA TMPPTR" );
3297 outline1("LDA #>%s", _source->realName );
3298 outline0("STA TMPPTR+1" );
3299 }
3300
3301 if ( _sequence ) {
3302 outline0("CLC" );
3303 outline0("LDA TMPPTR" );
3304 outline0("ADC #3" );
3305 outline0("STA TMPPTR" );
3306 outline0("LDA TMPPTR+1" );
3307 outline0("ADC #0" );
3308 outline0("STA TMPPTR+1" );
3309
3310 if ( strlen(_sequence) == 0 ) {
3311
3312 } else {
3313 outline1("LDA %s", _sequence );
3314 outline0("STA MATHPTR0" );
3315 outline1("JSR %soffsetsequence", _source->realName );
3316 }
3317 if ( _frame ) {
3318 if ( strlen(_frame) == 0 ) {
3319
3320 } else {
3321 outline1("LDA %s", _frame );
3322 outline0("STA MATHPTR0" );
3323 outline1("JSR %soffsetframe", _source->realName );
3324 }
3325 }
3326
3327 } else {
3328
3329 if ( _frame ) {
3330 outline0("CLC" );
3331 outline0("LDA TMPPTR" );
3332 outline0("ADC #3" );
3333 outline0("STA TMPPTR" );
3334 outline0("LDA TMPPTR+1" );
3335 outline0("ADC #0" );
3336 outline0("STA TMPPTR+1" );
3337 if ( strlen(_frame) == 0 ) {
3338
3339 } else {
3340 outline1("LDA %s", _frame );
3341 outline0("STA MATHPTR0" );
3342 outline1("JSR %soffsetframe", _source->realName );
3343 }
3344 }
3345
3346 }
3347
3348 if ( _source->isAddress ) {
3349 outline0("LDA TMPPTR" );
3350 outline1("STA %s", _register );
3351 outline0("LDA TMPPTR+1" );
3352 outline1("STA %s", address_displacement(_environment, _register, "1") );
3353 } else {
3354 outline0("LDA TMPPTR" );
3355 outline1("STA %s", _register );
3356 outline0("LDA TMPPTR+1" );
3357 outline1("STA %s", address_displacement(_environment, _register, "1") );
3358 }
3359
3360 }
3361
3362}
3363
3364void gtia_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
3365
3366 deploy( gtiavars, src_hw_gtia_vars_asm);
3367 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3368 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
3369 deploy( putimage, src_hw_gtia_put_image_asm );
3370
3371 if ( _frame_size ) {
3372 gtia_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3373 }
3374
3375 outline1("LDA %s", _x );
3376 outline0("STA IMAGEX" );
3377 outline1("LDA %s", address_displacement(_environment, _x, "1") );
3378 outline0("STA IMAGEX+1" );
3379 outline1("LDA %s", _y );
3380 outline0("STA IMAGEY" );
3381 outline1("LDA %s", address_displacement(_environment, _y, "1") );
3382 outline0("STA IMAGEY+1" );
3383 if ( strchr( _flags, '#' ) ) {
3384 outline1("LDA #(%s)&255", _flags+1 );
3385 outline0("STA IMAGEF" );
3386 outline1("LDA #((%s)>>8)&255", _flags+1 );
3387 outline0("STA IMAGET" );
3388 } else {
3389 outline1("LDA %s", _flags );
3390 outline0("STA IMAGEF" );
3391 outline1("LDA %s", address_displacement(_environment, _flags, "1") );
3392 outline0("STA IMAGET" );
3393 }
3394
3395 outline0("JSR PUTIMAGE");
3396
3397}
3398
3399void gtia_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
3400
3401 deploy( gtiavars, src_hw_gtia_vars_asm);
3402 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3403 deploy( tiles, src_hw_gtia_tiles_asm );
3404
3405 outline1("LDA %s", _tile );
3406 outline0("STA TILET" );
3407 outline1("LDA %s", _x );
3408 outline0("STA TILEX" );
3409 outline1("LDA %s", _y );
3410 outline0("STA TILEY" );
3411 outline0("LDA #1" );
3412 outline0("STA TILEW" );
3413 outline0("STA TILEH" );
3414 outline0("STA TILEW2" );
3415 outline0("STA TILEH2" );
3416
3417 outline0("JSR PUTTILE");
3418
3419}
3420
3421
3422void gtia_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
3423
3424 Variable * tile = variable_retrieve( _environment, _tile );
3425 Variable * x = variable_retrieve( _environment, _x );
3426 Variable * y = variable_retrieve( _environment, _y );
3427
3428 deploy( gtiavars, src_hw_gtia_vars_asm);
3429 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3430 deploy( tiles, src_hw_gtia_tiles_asm );
3431
3432 outline1("LDA %s", tile->realName );
3433 outline0("STA TILET" );
3434 outline1("LDA %s", x->realName );
3435 outline0("STA TILEX" );
3436 outline1("LDA %s", y->realName );
3437 outline0("STA TILEY" );
3438 outline1("LDA %s", address_displacement(_environment, tile->realName, "1") );
3439 outline0("STA TILEW" );
3440 outline0("STA TILEW2" );
3441 outline1("LDA %s", address_displacement(_environment, tile->realName, "2") );
3442 outline0("STA TILEH" );
3443 outline0("STA TILEH2" );
3444 outline1("LDA %s", address_displacement(_environment, tile->realName, "3") );
3445 outline0("STA TILEA" );
3446
3447 int size = ( tile->originalWidth >> 3 ) * ( tile->originalHeight >> 3 );
3448
3449 if ( size ) {
3450 outline1("LDA #<OFFSETS%4.4x", size );
3451 outline0("STA TMPPTR2" );
3452 outline1("LDA #>OFFSETS%4.4x", size );
3453 outline0("STA TMPPTR2+1" );
3454 } else {
3455 outline0("LDA #0" );
3456 outline0("STA TMPPTR2" );
3457 outline0("STA TMPPTR2+1" );
3458 }
3459
3460 outline0("JSR MOVETILE");
3461
3462}
3463
3464void gtia_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
3465
3466 outline0("LDA #0");
3467 outline1("STA %s", _offset );
3468 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3469
3470 if ( _sequence ) {
3471
3472 outline0("CLC" );
3473 outline1("LDA %s", _offset );
3474 outline0("ADC #3" );
3475 outline1("STA %s", _offset );
3476 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3477 outline0("ADC #0" );
3478 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3479 if ( strlen(_sequence) == 0 ) {
3480
3481 } else {
3482 outline1("LDA #<OFFSETS%4.4x", _frame_size * _frame_count );
3483 outline0("STA MATHPTR0" );
3484 outline1("LDA #>OFFSETS%4.4x", _frame_size * _frame_count );
3485 outline0("STA MATHPTR1" );
3486 outline0("CLC" );
3487 outline1("LDA %s", _sequence );
3488 outline0("ASL" );
3489 outline0("TAY" );
3490 outline1("LDA %s", _offset );
3491 outline0("ADC (MATHPTR0), Y" );
3492 outline1("STA %s", _offset );
3493 outline0("INY" );
3494 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3495 outline0("ADC (MATHPTR0), Y" );
3496 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3497 }
3498
3499 if ( _frame ) {
3500 if ( strlen(_frame) == 0 ) {
3501
3502 } else {
3503 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3504 outline0("STA MATHPTR0" );
3505 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3506 outline0("STA MATHPTR1" );
3507 outline0("CLC" );
3508 outline1("LDA %s", _frame );
3509 outline0("ASL" );
3510 outline0("TAY" );
3511 outline1("LDA %s", _offset );
3512 outline0("ADC (MATHPTR0), Y" );
3513 outline1("STA %s", _offset );
3514 outline0("INY" );
3515 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3516 outline0("ADC (MATHPTR0), Y" );
3517 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3518 }
3519 }
3520
3521 } else {
3522
3523 if ( _frame ) {
3524 outline0("CLC" );
3525 outline1("LDA %s", _offset );
3526 outline0("ADC #3" );
3527 outline1("STA %s", _offset );
3528 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3529 outline0("ADC #0" );
3530 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3531 if ( strlen(_frame) == 0 ) {
3532
3533 } else {
3534 outline1("LDA #<OFFSETS%4.4x", _frame_size );
3535 outline0("STA MATHPTR0" );
3536 outline1("LDA #>OFFSETS%4.4x", _frame_size );
3537 outline0("STA MATHPTR0+1" );
3538 outline0("CLC" );
3539 outline1("LDA %s", _frame );
3540 outline0("ASL" );
3541 outline0("TAY" );
3542 outline1("LDA %s", _offset );
3543 outline0("ADC (MATHPTR0), Y" );
3544 outline1("STA %s", _offset );
3545 outline0("INY" );
3546 outline1("LDA %s", address_displacement(_environment, _offset, "1") );
3547 outline0("ADC (MATHPTR0), Y" );
3548 outline1("STA %s", address_displacement(_environment, _offset, "1") );
3549 }
3550 }
3551
3552 }
3553
3554}
3555
3556void gtia_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 ) {
3557
3558 deploy( gtiavars, src_hw_gtia_vars_asm);
3559 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3560 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
3561 deploy( blitimage, src_hw_gtia_blit_image_asm );
3562
3563 if ( _source_count > 2 ) {
3565 }
3566
3568
3569 outhead1("blitimage%s:", label);
3570
3571 outline1("LDA #<%s", _blit );
3572 outline0("STA BLITIMAGEBLITADDR+1" );
3573 outline1("LDA #>%s", _blit );
3574 outline0("STA BLITIMAGEBLITADDR+2" );
3575
3576 if ( _source_count > 0 ) {
3577 Resource resource;
3578 resource.realName = strdup( _sources[0] );
3579 resource.type = VT_IMAGE;
3580 resource.isAddress = 0;
3581 gtia_load_image_address_to_register( _environment, "BLITTMPPTR", &resource, _sequence, _frame, _frame_size, _frame_count );
3582 } else {
3583 outline0( "LDA #$0" );
3584 outline0( "STA BLITTMPPTR" );
3585 outline0( "STA BLITTMPPTR+1" );
3586 }
3587
3588 if ( _source_count > 1 ) {
3589 Resource resource;
3590 resource.realName = strdup( _sources[0] );
3591 resource.type = VT_IMAGE;
3592 resource.isAddress = 0;
3593 gtia_load_image_address_to_register( _environment, "BLITTMPPTR2", &resource, _sequence, _frame, _frame_size, _frame_count );
3594 } else {
3595 outline0( "LDA #$0" );
3596 outline0( "STA BLITTMPPTR2" );
3597 outline0( "STA BLITTMPPTR2+1" );
3598 }
3599
3600 outhead1("putimage%s:", label);
3601
3602 outline1("LDA %s", _x );
3603 outline0("STA IMAGEX" );
3604 outline1("LDA %s", address_displacement(_environment, _x, "1") );
3605 outline0("STA IMAGEX+1" );
3606 outline1("LDA %s", _y );
3607 outline0("STA IMAGEY" );
3608 outline1("LDA %s", address_displacement(_environment, _y, "1") );
3609 outline0("STA IMAGEY+1" );
3610 outline1("LDA #$%2.2x", ( _flags & 0xff ) );
3611 outline0("STA IMAGEF" );
3612 outline1("LDA #$%2.2x", ( (_flags>>8) & 0xff ) );
3613 outline0("STA IMAGET" );
3614
3615 outline0("JSR BLITIMAGE");
3616
3617}
3618
3619void gtia_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
3620
3621 deploy( gtiavars, src_hw_gtia_vars_asm);
3622 deploy( tiles, src_hw_gtia_tiles_asm );
3623
3624 outline1("LDA %s", _tile );
3625 outline0("STA TILET" );
3626 outline1("LDA %s", _x );
3627 outline0("STA TILEX" );
3628 outline1("LDA %s", _y );
3629 outline0("STA TILEY" );
3630 outline1("LDA %s", address_displacement(_environment, _tile, "1") );
3631 outline0("STA TILEW" );
3632 outline1("LDA %s", address_displacement(_environment, _tile, "2") );
3633 outline0("STA TILEH" );
3634
3635 outline0("JSR PUTTILE");
3636
3637}
3638
3639void gtia_tile_at( Environment * _environment, char * _x, char * _y, char * _result ) {
3640
3641 deploy( gtiavars, src_hw_gtia_vars_asm);
3642 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3643 deploy( tiles, src_hw_gtia_tiles_asm );
3644
3645 outline1("LDA %s", _x );
3646 outline0("STA TILEX" );
3647 outline1("LDA %s", _y );
3648 outline0("STA TILEY" );
3649
3650 outline0("JSR TILEAT");
3651
3652 outline0("LDA TILET" );
3653 outline1("STA %s", _result );
3654
3655}
3656
3657void gtia_use_tileset( Environment * _environment, char * _tileset ) {
3658
3659 deploy( gtiavars, src_hw_gtia_vars_asm);
3660 deploy( tiles, src_hw_gtia_tiles_asm );
3661
3662 outline1("LDA %s", _tileset );
3663
3664 outline0("JSR USETILESET");
3665
3666}
3667
3668void gtia_wait_vbl( Environment * _environment, char * _raster_line ) {
3669
3670 deploy( vbl, src_hw_gtia_vbl_asm);
3671
3672 if ( _raster_line ) {
3673 Variable * raster_line = variable_retrieve_or_define( _environment, _raster_line, VT_BYTE, 255 );
3674 outline1( "LDX %s", raster_line->realName );
3675 } else {
3676 outline0( "LDX #0" );
3677 }
3678 outline0("JSR VBL");
3679
3680}
3681
3682Variable * gtia_new_image( Environment * _environment, int _width, int _height, int _mode ) {
3683
3684 int size = gtia_image_size( _environment, _width, _height, _mode );
3685
3686 if ( ! size ) {
3688 }
3689
3690 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
3691
3692 char * buffer = malloc ( size );
3693 memset( buffer, 0, size );
3694
3695 *(buffer) = (_width & 0xff);
3696 *(buffer+1) = (_width >> 8 ) & 0xff;
3697 *(buffer+2) = _height;
3698
3699 result->valueBuffer = buffer;
3700 result->size = size;
3701
3702 return result;
3703
3704}
3705
3706Variable * gtia_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
3707
3708 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
3709 int frameSize = gtia_image_size( _environment, _width, _height, _mode );
3710
3711 if ( ! size ) {
3713 }
3714
3715 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
3716
3717 char * buffer = malloc ( size );
3718 memset( buffer, 0, size );
3719
3720 *(buffer) = _frames;
3721 *(buffer+1) = ( _width & 0xff );
3722 *(buffer+2) = ( _width >> 8 ) & 0xff;
3723 for( int i=0; i<_frames; ++i ) {
3724 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
3725 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
3726 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
3727 }
3728
3729 result->valueBuffer = buffer;
3730 result->frameSize = frameSize;
3731 result->size = size;
3732 result->frameCount = _frames;
3733
3734 return result;
3735
3736}
3737
3738Variable * gtia_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
3739
3740 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
3741 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
3742 int frameSize = gtia_image_size( _environment, _width, _height, _mode );
3743
3744 if ( ! size ) {
3746 }
3747
3748 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
3749
3750 char * buffer = malloc ( size2 );
3751 memset( buffer, 0, size2 );
3752
3753 *(buffer) = _frames;
3754 *(buffer+1) = _width;
3755 *(buffer+2) = _sequences;
3756 for( int i=0; i<(_frames*_sequences); ++i ) {
3757 *(buffer+3+(i*frameSize)) = ( _width & 0xff );
3758 *(buffer+3+(i*frameSize)+1) = ( ( _width >> 8 ) & 0xff );
3759 *(buffer+3+(i*frameSize)+2) = ( _height & 0xff );
3760 }
3761
3762 result->valueBuffer = buffer;
3763 result->frameSize = frameSize;
3764 result->size = size2;
3765 result->frameCount = _frames;
3766
3767 return result;
3768
3769}
3770
3771void gtia_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
3772
3773 deploy( gtiavars, src_hw_gtia_vars_asm);
3774 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3775 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
3776 deploy( getimage, src_hw_gtia_get_image_asm );
3777
3778 gtia_load_image_address_to_other_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3779
3780 outline1("LDA %s", _x );
3781 outline0("STA IMAGEX" );
3782 outline1("LDA %s", address_displacement(_environment, _x, "1") );
3783 outline0("STA IMAGEX+1" );
3784 outline1("LDA %s", _y );
3785 outline0("STA IMAGEY" );
3786 outline1("LDA %s", address_displacement(_environment, _y, "1") );
3787 outline0("STA IMAGEY+1" );
3788 outline1("LDA #$%2.2x", _palette );
3789 outline0("STA IMAGET" );
3790
3791 outline0("JSR GETIMAGE");
3792
3793}
3794
3795void gtia_scroll( Environment * _environment, int _dx, int _dy ) {
3796
3797 deploy( gtiavars, src_hw_gtia_vars_asm);
3798 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3799 deploy( scroll, src_hw_gtia_scroll_asm);
3800 deploy_preferred( textHScroll, src_hw_gtia_hscroll_text_asm );
3801 deploy_preferred( vScrollText, src_hw_gtia_vscroll_text_asm );
3802
3803 outline1("LDA #$%2.2x", (unsigned char)(_dx&0xff) );
3804 outline0("STA MATHPTR0" );
3805 outline1("LDA #$%2.2x", (unsigned char)(_dy&0xff) );
3806 outline0("STA MATHPTR1" );
3807 outline0("JSR SCROLL");
3808
3809}
3810
3812
3813 Variable * result = variable_temporary( _environment, VT_BYTE, "(raster line)" );
3814
3815 cpu_move_8bit( _environment, "$D40B", result->realName );
3816 variable_sl_const( _environment, result->name, 1 );
3817
3818 return result;
3819
3820}
3821
3822void gtia_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
3823
3824}
3825
3826int gtia_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
3827
3828 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
3829
3830 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
3831
3832 int uniquePaletteCount = 0;
3833
3834 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
3835
3836 return uniquePaletteCount;
3837
3838}
3839
3840void gtia_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
3841
3842 deploy( gtiavars, src_hw_gtia_vars_asm);
3843 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3844
3845 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0001" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
3846 gtia_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3847 deploy( flipimagex, src_hw_gtia_flip_image_x_asm );
3848 outline0("JSR FLIPIMAGEX");
3849 } else {
3850
3852
3853 gtia_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3854 deploy( flipimagex, src_hw_gtia_flip_image_x_asm );
3855 outline1("LDA %s", _direction );
3856 outline1("AND #$%2.2x", FLAG_FLIP_X );
3857 outline1("BEQ %s", label );
3858 outline0("JSR FLIPIMAGEX");
3859 outhead1("%s:", label );
3860
3861 }
3862
3863 if ( strcmp( _direction, "#FLIPIMAGEDIRECTION0002" ) == 0 || strcmp( _direction, "#FLIPIMAGEDIRECTION0003" ) == 0 ) {
3864 gtia_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3865 deploy( flipimagey, src_hw_gtia_flip_image_y_asm );
3866 outline0("JSR FLIPIMAGEY");
3867 } else {
3868
3870
3871 gtia_load_image_address_to_register( _environment, "TMPPTR", _image, _sequence, _frame, _frame_size, _frame_count );
3872 deploy( flipimagey, src_hw_gtia_flip_image_y_asm );
3873 outline1("LDA %s", _direction );
3874 outline1("AND #$%2.2x", FLAG_FLIP_Y );
3875 outline1("BEQ %s", label );
3876 outline0("JSR FLIPIMAGEY");
3877 outhead1("%s:", label );
3878
3879 }
3880
3881}
3882
3883void gtia_fade( Environment * _environment, char * _ticks ) {
3884
3885 deploy( gtiavars, src_hw_gtia_vars_asm);
3886 deploy_deferred( gtiavarsGraphic, src_hw_gtia_vars_graphics_asm );
3887 deploy( gtiapreproc, src_hw_gtia__preproc_asm );
3888 deploy( fade, src_hw_gtia_fade_asm );
3889
3890 outline0( "SEI" );
3891 outline0( "LDA #0" );
3892 outline0( "STA FADESTEP" );
3893 outline1( "LDA %s", _ticks );
3894 outline0( "STA FADEDURATION" );
3895 outline0( "STA FADERESETDURATION" );
3896 outline1( "LDA %s", address_displacement( _environment, _ticks, "1" ) );
3897 outline0( "STA FADEDURATION+1" );
3898 outline0( "STA FADERESETDURATION+1" );
3899 outline0( "CLI" );
3900
3901}
3902
3903void gtia_screen( Environment * _environment, char * _x, char * _y, char * _c ) {
3904
3905 deploy( gtiavars, src_hw_gtia_vars_asm);
3906 deploy( screen, src_hw_gtia_screen_asm);
3907
3908 outline1( "LDA %s", _x );
3909 outline0( "STA MATHPTR1" );
3910 outline1( "LDA %s", _y );
3911 outline0( "STA MATHPTR0" );
3912 outline0( "JSR SCREEN" );
3913 outline1( "STA %s", _c );
3914
3915}
3916
3917void gtia_flash_begin( Environment * _environment, char * _index, char * _register ) {
3918
3919 deploy( flash, src_hw_gtia_flash_asm );
3920
3921 outline0("JSR FLASHBEGIN");
3922 if ( _register ) {
3923 outline1("LDA %s", _index );
3924 outline0("ASL" );
3925 outline0("TAX" );
3926 outline0("LDA FLASHREGISTERADDRESSES, X" );
3927 outline0("STA TMPPTR" );
3928 outline0("INX" );
3929 outline0("LDA FLASHREGISTERADDRESSES, X" );
3930 outline0("STA TMPPTR+1" );
3931 outline0("LDY #0" );
3932 outline1("LDA %s", _register );
3933 outline0("STA (TMPPTR), Y" );
3934 outline0("INY" );
3935 outline1("LDA %s", address_displacement( _environment, _register, "+1" ) );
3936 outline0("STA (TMPPTR), Y" );
3937 }
3938
3939}
3940
3941void gtia_flash_register( Environment * _environment, char * _index, char * _timer, char * _color ) {
3942
3943 deploy( flash, src_hw_gtia_flash_asm );
3944
3945 outline1("LDX %s", _index );
3946 outline1("LDY %s", _color );
3947 outline1("LDA %s", _timer );
3948 outline0("JSR FLASHREGISTER");
3949
3950}
3951
3952void gtia_flash_end( Environment * _environment ) {
3953
3954 deploy( flash, src_hw_gtia_flash_asm );
3955
3956 outline0("JSR FLASHEND");
3957
3958}
3959
3960void gtia_flash_off( Environment * _environment, char * _index ) {
3961
3962 deploy( flash, src_hw_gtia_flash_asm );
3963
3964 outline1("LDX %s", _index );
3965 outline0("JSR FLASHOFF");
3966
3967}
3968
3969#endif
void cpu_math_mul2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to double for several times a 8 bit value
Definition 6309.c:1397
void cpu_math_sub_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to subtract two 8 bit values
Definition 6309.c:1049
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_call(Environment *_environment, char *_label)
Definition 6309.c:3755
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_mem_move_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4798
void cpu_return(Environment *_environment)
Definition 6309.c:4030
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
int lastUsedSlotInCommonPalette
Definition 6847.c:100
Variable * variable_retrieve(Environment *_environment, char *_name)
int reset_screen_mode_selected(Environment *_environment)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
CopperList * find_copper_list(Environment *_environment, char *_name)
void label_stored_define_named(Environment *_environment, char *_label)
RGBi * palette_merge(RGBi *_palette1, int _palette1_size, RGBi *_palette2, int _palette2_size, int *_size)
Make a "palette merge".
float min_of_three(float _m, float _n, float _p)
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)
int label_stored_exists_named(Environment *_environment, char *_label)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * palette_promote_color_as_background(int _index, RGBi *_source, int _source_size)
Promote an index color in a palette.
RGBi * malloc_palette(int _size)
Allocate a palette space.
void variable_global(Environment *_environment, char *_pattern)
Variable * variable_define(Environment *_environment, char *_name, VariableType _type, int _value)
Define a variable for the program.
ScreenMode * find_screen_mode_by_suggestion(Environment *_environment, int _bitmap, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Variable * variable_sl_const(Environment *_environment, char *_destination, int _steps)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
RGBi * palette_promote_color_as_foreground(int _index, RGBi *_source, int _source_size, int _max_size)
Promote an index color in a palette.
float max_of_three(float _m, float _n, float _p)
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Variable * variable_store_buffer(Environment *_environment, char *_destination, unsigned char *_buffer, int _size, int _at)
#define DLI_COUNT
Definition antic.h:44
#define DLI_MODE_VHSCROLL(_list, _n)
Definition antic.h:135
#define DLI_LMS_VSCROLL_IRQ(_list, _n, _addr)
Definition antic.h:156
#define DLI_MODE_VHSCROLL_IRQ(_list, _n)
Definition antic.h:138
#define DLI_LMS_VHSCROLL_IRQ(_list, _n, _addr)
Definition antic.h:166
#define DLI_MODE_VSCROLL_IRQ(_list, _n)
Definition antic.h:132
#define DLI_MODE_VSCROLL(_list, _n)
Definition antic.h:129
#define DLI_JVB(list, addr)
Definition antic.h:253
#define DLI_LMS_VHSCROLL(_list, _n, _addr)
Definition antic.h:161
#define DLI_IRQ(_list, _n)
Definition antic.h:171
#define DLI_LMS_VSCROLL(_list, _n, _addr)
Definition antic.h:151
#define DLI_BLANK(_list, _n)
Definition antic.h:208
int size
Definition _optimizer.c:678
int offset
Definition _optimizer.c:681
void back(Environment *_environment, char *_color)
Emit ASM code to fill background color.
Definition back.c:53
void cls(Environment *_environment, char *_paper)
Emit code for CLS.
Definition cls.c:48
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
void scroll(Environment *_environment, int _dx, int _dy)
Definition scroll.c:41
void flash(Environment *_environment, char *_index, char *_register)
Definition flash.c:44
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
void gtia_border_color_vars(Environment *_environment, char *_border_color)
Definition gtia.c:122
void gtia_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition gtia.c:1990
void gtia_background_color_vars(Environment *_environment, char *_index, char *_background_color)
GTIA: emit code to change background color
Definition gtia.c:289
void gtia_use_tileset(Environment *_environment, char *_tileset)
Definition gtia.c:3657
void gtia_flash_begin(Environment *_environment, char *_index, char *_register)
Definition gtia.c:3917
void gtia_sprite_multicolor(Environment *_environment, char *_sprite)
Definition gtia.c:1847
void gtia_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition gtia.c:1712
int gtia_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition gtia.c:1115
void gtia_clear(Environment *_environment, char *_pattern)
Definition gtia.c:1967
int gtia_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition gtia.c:2328
void gtia_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition gtia.c:1679
void gtia_background_color(Environment *_environment, int _index, int _background_color)
GTIA: emit code to change background color
Definition gtia.c:160
void gtia_flash_end(Environment *_environment)
Definition gtia.c:3952
void gtia_screen_on(Environment *_environment)
Definition gtia.c:1795
void gtia_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition gtia.c:3364
void gtia_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition gtia.c:2281
void gtia_vertical_scroll(Environment *_environment, char *_displacement)
Definition gtia.c:1867
void gtia_busy_wait(Environment *_environment, char *_timing)
Definition gtia.c:1887
void gtia_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition gtia.c:3771
void gtia_get_width(Environment *_environment, char *_result)
Definition gtia.c:1912
void gtia_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition gtia.c:1827
void gtia_screen_rows(Environment *_environment, char *_rows)
Definition gtia.c:1803
void gtia_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition gtia.c:2265
void gtia_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition gtia.c:1855
Variable * gtia_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition gtia.c:3682
void gtia_border_color(Environment *_environment, int _border_color)
GTIA: emit code to change border color
Definition gtia.c:94
void gtia_back(Environment *_environment)
Definition gtia.c:2293
Variable * gtia_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition gtia.c:3738
void gtia_sprite_disable(Environment *_environment, char *_sprite)
Definition gtia.c:1823
void gtia_screen_off(Environment *_environment)
Definition gtia.c:1799
void gtia_initialization(Environment *_environment)
Definition gtia.c:2029
void gtia_wait_vbl(Environment *_environment, char *_raster_line)
Definition gtia.c:3668
void gtia_cls(Environment *_environment)
Definition gtia.c:1937
void gtia_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition gtia.c:3464
void gtia_fade(Environment *_environment, char *_ticks)
Definition gtia.c:3883
void gtia_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition gtia.c:1815
void gtia_scroll(Environment *_environment, int _dx, int _dy)
Definition gtia.c:3795
void gtia_background_color_semivars(Environment *_environment, int _index, char *_background_color)
GTIA: emit code to change background color
Definition gtia.c:436
void gtia_sprite_monocolor(Environment *_environment, char *_sprite)
Definition gtia.c:1851
void gtia_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition gtia.c:1947
void gtia_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition gtia.c:3399
void gtia_get_height(Environment *_environment, char *_result)
Definition gtia.c:1921
void gtia_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition gtia.c:1843
void gtia_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 gtia.c:3556
void gtia_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition gtia.c:1839
void gtia_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition gtia.c:1771
void console_update_width_in_bytes(Environment *_environment)
Definition gtia.c:783
void gtia_colormap_at(Environment *_environment, char *_address)
Definition gtia.c:1704
void gtia_sprite_enable(Environment *_environment, char *_sprite)
Definition gtia.c:1819
void console_calculate_vars(Environment *_environment)
Definition gtia.c:773
void gtia_tiles_at(Environment *_environment, char *_address)
Definition gtia.c:1863
void gtia_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
GTIA: emit code to change background color
Definition gtia.c:583
void gtia_textmap_at(Environment *_environment, char *_address)
Definition gtia.c:1708
void gtia_bank_select(Environment *_environment, int _bank)
Definition gtia.c:720
void gtia_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition gtia.c:1977
void gtia_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition gtia.c:3422
void gtia_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition gtia.c:3840
void gtia_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition gtia.c:1831
void gtia_screen(Environment *_environment, char *_x, char *_y, char *_c)
Definition gtia.c:3903
void gtia_tiles_get(Environment *_environment, char *_result)
Definition gtia.c:1930
void gtia_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
Definition gtia.c:716
void gtia_cline(Environment *_environment, char *_characters)
Definition gtia.c:2302
void gtia_finalization(Environment *_environment)
Definition gtia.c:2130
void gtia_flash_register(Environment *_environment, char *_index, char *_timer, char *_color)
Definition gtia.c:3941
void gtia_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition gtia.c:1859
void gtia_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition gtia.c:1835
void gtia_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition gtia.c:3619
Variable * gtia_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 gtia.c:3045
void gtia_bitmap_disable(Environment *_environment)
Definition gtia.c:1675
void gtia_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition gtia.c:3639
void gtia_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition gtia.c:3822
void gtia_screen_columns(Environment *_environment, char *_columns)
Definition gtia.c:1807
Variable * gtia_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition gtia.c:3706
void gtia_hit(Environment *_environment, char *_sprite_mask, char *_result)
Definition gtia.c:81
void gtia_flash_off(Environment *_environment, char *_index)
Definition gtia.c:3960
void gtia_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition gtia.c:1658
void gtia_collision(Environment *_environment, char *_sprite_mask, char *_result)
Definition gtia.c:77
void gtia_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition gtia.c:1737
int gtia_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition gtia.c:3826
void gtia_bitmap_at(Environment *_environment, char *_address)
Definition gtia.c:1700
void gtia_sprite_data_from(Environment *_environment, char *_sprite, char *_address)
Definition gtia.c:1811
Variable * gtia_get_raster_line(Environment *_environment)
Definition gtia.c:3811
void console_calculate(Environment *_environment)
Definition gtia.c:761
void gtia_horizontal_scroll(Environment *_environment, char *_displacement)
Definition gtia.c:1879
#define FRAME_BUFFER_ADDRESS
Definition gtia.h:241
#define BITMAP_MODE_ANTIC8
Definition gtia.h:104
#define BITMAP_MODE_ANTIC12
Definition gtia.h:154
#define BITMAP_MODE_ANTIC10
Definition gtia.h:118
#define BITMAP_MODE_ANTIC13
Definition gtia.h:130
#define BITMAP_MODE_ANTIC11
Definition gtia.h:123
#define TILEMAP_MODE_ANTIC2
Definition gtia.h:172
#define BITMAP_MODE_ANTIC15
Definition gtia.h:144
#define BITMAP_MODE_ANTIC9
Definition gtia.h:112
#define TILEMAP_MODE_ANTIC3
Definition gtia.h:196
#define TILEMAP_MODE_ANTIC5
Definition gtia.h:211
#define TILEMAP_MODE_ANTIC7
Definition gtia.h:189
#define TILEMAP_MODE_ANTIC4
Definition gtia.h:206
#define BITMAP_MODE_ANTIC14
Definition gtia.h:161
#define TILEMAP_MODE_ANTIC6
Definition gtia.h:184
int width
Definition ugbc.h:2209
int height
Definition ugbc.h:2210
CopperOperation operation
Definition ugbc.h:2243
struct _CopperInstruction * next
Definition ugbc.h:2246
int mode
Definition ugbc.h:2253
char * name
Definition ugbc.h:2252
struct _CopperInstruction * first
Definition ugbc.h:2254
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
RgbConverterFunction currentRgbConverterFunction
Definition ugbc.h:2711
int fontWidth
Definition ugbc.h:2900
CopperList * copperList
Definition ugbc.h:3282
int screenColors
Definition ugbc.h:2870
int dynamicConsole
Definition ugbc.h:3298
int currentModeBW
Definition ugbc.h:2701
int frameBufferStart2
Definition ugbc.h:3116
int screenHeight
Definition ugbc.h:2860
int consoleTilesWidth
Definition ugbc.h:2890
int frameBufferStart
Definition ugbc.h:3111
int currentTileMode
Definition ugbc.h:2706
int screenTiles
Definition ugbc.h:2875
int screenWidth
Definition ugbc.h:2855
int defaultPaperColor
Definition ugbc.h:3226
int lmarginAtariBasicEnabled
Definition ugbc.h:3229
int horizontalScrollOff
Definition ugbc.h:3300
int defaultPenColor
Definition ugbc.h:3225
VestigialConfig vestigialConfig
Definition ugbc.h:2442
unsigned char red
Definition ugbc.h:433
unsigned char green
Definition ugbc.h:434
unsigned char blue
Definition ugbc.h:435
unsigned char alpha
Definition ugbc.h:436
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
int bitmap
Definition ugbc.h:1496
int selected
Definition ugbc.h:1510
unsigned char * valueBuffer
Definition ugbc.h:1061
int size
Definition ugbc.h:1077
int originalHeight
Definition ugbc.h:1148
char * name
Definition ugbc.h:979
int absoluteAddress
Definition ugbc.h:1092
int originalColors
Definition ugbc.h:1154
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
int originalWidth
Definition ugbc.h:1145
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
char palettePreserve
Definition ugbc.h:2007
void * malloc(YYSIZE_T)
struct _ScreenMode ScreenMode
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
Definition ugbc.h:3502
struct _Resource Resource
@ COP_NOP
Definition ugbc.h:2223
@ COP_WAIT
Definition ugbc.h:2225
@ COP_STORE_DWORD
Definition ugbc.h:2229
@ COP_COLOR_BORDER
Definition ugbc.h:2235
@ COP_MOVE_BYTE
Definition ugbc.h:2231
@ COP_MOVE_WORD
Definition ugbc.h:2232
@ COP_STORE_WORD
Definition ugbc.h:2228
@ COP_COLOR
Definition ugbc.h:2237
@ COP_STORE_BYTE
Definition ugbc.h:2227
@ COP_MOVE_DWORD
Definition ugbc.h:2233
@ COP_COLOR_BACKGROUND
Definition ugbc.h:2236
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define adilineendbitmap()
Definition ugbc.h:4241
#define WARNING_SCREEN_MODE(v1)
Definition ugbc.h:3878
struct _Variable Variable
Structure of a single variable.
#define outline2(s, a, b)
Definition ugbc.h:4254
#define deploy_deferred(s, e)
Definition ugbc.h:4302
struct _Environment Environment
Structure of compilation environment.
#define FLAG_FLIP_X
Definition ugbc.h:4553
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_BUFFER
Definition ugbc.h:477
@ 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 outhead0(s)
Definition ugbc.h:4246
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
Definition ugbc.h:1516
#define MAX_PALETTE
Definition ugbc.h:568
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
Definition ugbc.h:3688
#define CRITICAL_SCREEN_UNSUPPORTED(v)
Definition ugbc.h:3496
#define outline0(s)
Definition ugbc.h:4252
#define outhead2(s, a, b)
Definition ugbc.h:4248
#define FLAG_FLIP_Y
Definition ugbc.h:4554
#define outline1(s, a)
Definition ugbc.h:4253
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
Definition ugbc.h:3880
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define VT_BITWIDTH(t)
Definition ugbc.h:595
#define adilinebeginbitmap(s)
Definition ugbc.h:4231
struct _CopperList CopperList
#define FLAG_EXACT
Definition ugbc.h:4569
struct _CopperInstruction CopperInstruction
#define adilinepixel(p)
Definition ugbc.h:4236
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)
Definition ugbc.h:3540
#define CRITICAL_BLIT_TOO_MUCH_SOURCES()
Definition ugbc.h:3613
#define deploy(s, e)
Definition ugbc.h:4288
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247