ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
cga.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(__pccga__)
36
37#include "../ugbc.h"
38#include <math.h>
39
40static RGBi SYSTEM_PALETTE_ALTERNATE[][4] = {
41 // CGA_COLOR_CSET1
42 {
43 { 0, 0, 0, 0xff, 0, "BLACK" },
44 { 85, 255, 85, 0xff, 1, "LIGHT_GREEN" },
45 { 255, 85, 85, 0xff, 2, "LIGHT_RED" },
46 { 170, 85, 0, 0xff, 3, "BROWN" },
47 },
48 // CGA_COLOR_CSET2
49 {
50 { 0, 0, 0, 0xff, 0, "BLACK" },
51 { 85, 255, 255, 0xff, 11, "LIGHT_CYAN" },
52 { 255, 85, 255, 0xff, 2, "LIGHT_MAGENTA" },
53 { 255, 255, 255, 0xff, 3, "WHITE" }
54 }
55};
56
57static RGBi * SYSTEM_PALETTE = &SYSTEM_PALETTE_ALTERNATE[0][0];
58
59// static RGBi SYSTEM_PALETTE[] = {
60// { 0, 0, 0, 0xff, 0, "BLACK" },
61// { 0, 0, 170, 0xff, 1, "DARK_BLUE" },
62// { 0, 170, 0, 0xff, 2, "DARK_GREEN" },
63// { 0, 170, 170, 0xff, 3, "DARK_CYAN" },
64// { 170, 0, 0, 0xff, 4, "DARK_RED" },
65// { 170, 0, 170, 0xff, 5, "DARK_MAGENTA" },
66// { 170, 85, 0, 0xff, 6, "BROWN" },
67// { 170, 170, 170, 0xff, 7, "LIGHT_GRAY" },
68// { 85, 85, 85, 0xff, 8, "DARK_GRAY" },
69// { 85, 85, 255, 0xff, 9, "LIGHT_BLUE" },
70// { 85, 255, 85, 0xff, 10, "LIGHT_GREEN" },
71// { 85, 255, 255, 0xff, 11, "LIGHT_CYAN" },
72// { 255, 85, 85, 0xff, 12, "LIGHT_RED" },
73// { 255, 85, 255, 0xff, 13, "LIGHT_MAGENTA" },
74// { 255, 255, 85, 0xff, 14, "YELLOW" },
75// { 255, 255, 255, 0xff, 15, "WHITE" }
76// };
77
78static RGBi * commonPalette;
80
81/****************************************************************************
82 * CODE SECTION
83 ****************************************************************************/
84
85#define CGA_REG_HZ_TOTAL 0x00
86#define CGA_REG_HZ_DISP 0x01
87#define CGA_REG_HZ_SYNC_POS 0x02
88#define CGA_REG_HZ_SYNC_WIDTH 0x03
89#define CGA_REG_VT_TOTAL 0x04
90#define CGA_REG_VT_TOTAL_ADJUST 0x05
91#define CGA_REG_VT_VERT_TOTAL_ADJUST 0x06
92#define CGA_REG_VT_VERT_SYNC_POSITION 0x07
93#define CGA_REG_INTERLACE_MODE 0x08
94#define CGA_REG_MAX_SCAN_LINE_ADDRESS 0x09
95#define CGA_REG_CURSOR_START 0x0a
96#define CGA_REG_CURSOR_END 0x0b
97#define CGA_REG_START_ADDRESS_H 0x0c
98#define CGA_REG_START_ADDRESS_L 0x0d
99#define CGA_REG_CURSOR_ADDRESS_H 0x0e
100#define CGA_REG_CURSOR_ADDRESS_L 0x0f
101#define CGA_REG_LPEN_ADDRESS_H 0x10
102#define CGA_REG_LPEN_ADDRESS_L 0x11
103
104#define WRITE_REGISTER( r, v ) \
105 outline1("MOV AH, 0x%2.2x", r ) \
106 outline1("MOV AL, 0x%2.2x", v ) \
107 outline0("CALL WRITECGAREG")
108
109#define CGA_COLOR_BLUE 0x01
110#define CGA_COLOR_GREEN 0x02
111#define CGA_COLOR_RED 0x04
112#define CGA_COLOR_LIGHT 0x08
113#define CGA_COLOR_LIGHT2 0x10
114#define CGA_COLOR_CSET1 0x00
115#define CGA_COLOR_CSET2 0x20
116
117#define WRITE_COLOR_SELECT_REGISTER( v ) \
118 outline1("MOV AL, 0x%2.2x", v ) \
119 outline0("CALL WRITECGACOLORSELECTREG")
120
121#define CGA_MODE_80x25 0x01
122#define CGA_MODE_40x25 0x00
123
124#define CGA_MODE_GRAPHIC 0x02
125#define CGA_MODE_TEXT 0x00
126
127#define CGA_MODE_BW 0x04
128#define CGA_MODE_COLOR 0x00
129
130#define CGA_MODE_ENABLE 0x08
131#define CGA_MODE_DISABLE 0x00
132
133#define CGA_MODE_HIRES 0x10
134#define CGA_MODE_LORES 0x00
135
136#define CGA_MODE_BLINK 0x20
137#define CGA_MODE_NOBLINK 0x00
138
139#define WRITE_MODE_CONTROL_REGISTER( v ) \
140 outline1("MOV AL, 0x%2.2x", v ) \
141 outline0("CALL WRITECGAMODECONTROLREG")
142
143#define BIOS_VIDEO_MODE( m ) \
144 outline1("MOV AX, 0x%4.4x", m ) \
145 outline0("INT 0x10")
146
148
149 unsigned int minDistance = 0xffff;
150 int colorIndex = 0;
151 for (int j = 0; j < COLOR_COUNT; ++j) {
152 int distance = rgbi_distance(&SYSTEM_PALETTE[j], _color);
153 if ( _color->alpha < 255 ) {
154 if ( rgbi_equals_rgb( &SYSTEM_PALETTE[j], _color ) ) {
155 minDistance = 0;
156 distance = 0;
157 colorIndex = j;
158 }
159 } else {
160 if ( SYSTEM_PALETTE[j].alpha < 255 ) {
161 continue;
162 }
163 if (distance < minDistance) {
164 minDistance = distance;
165 colorIndex = j;
166 }
167 }
168 }
169
170 return &SYSTEM_PALETTE[colorIndex];
171
172}
173
174Variable * cga_collision( Environment * _environment, char * _sprite ) {
175
176 Variable * result = variable_temporary( _environment, VT_SBYTE, "(collision)" );
177
178 return result;
179
180}
181
193void cga_hit( Environment * _environment, char * _sprite_mask, char * _result ) {
194
195}
196
206void cga_border_color( Environment * _environment, char * _border_color ) {
207
208 outline0("CALL READCGACOLORSELECTREG" );
209 outline0("AND AL, 0xf0" );
210 outline1("MOV BL, [%s]", _border_color );
211 outline0("AND BL, 0x0f" );
212 outline0("OR AL, BL" );
213 outline0("CALL WRITECGACOLORSELECTREG" );
214
215}
216
227void cga_background_color( Environment * _environment, int _index, int _background_color ) {
228
229 outline0("CALL READCGACOLORSELECTREG" );
230 outline0("AND AL, 0xf0" );
231 outline1("MOV BL, 0x%2.2x", (unsigned char)(_background_color&0x0f) );
232 outline0("OR AL, BL" );
233 outline0("CALL WRITECGACOLORSELECTREG" );
234
235}
236
247void cga_background_color_vars( Environment * _environment, char * _index, char * _background_color ) {
248
249 outline0("CALL READCGACOLORSELECTREG" );
250 outline0("AND AL, 0xf0" );
251 outline1("MOV BL, [%s]", _background_color );
252 outline0("AND BL, 0x0f" );
253 outline0("OR AL, BL" );
254 outline0("CALL WRITECGACOLORSELECTREG" );
255
256}
257
268void cga_background_color_semivars( Environment * _environment, int _index, char * _background_color ) {
269
270 outline0("CALL READCGACOLORSELECTREG" );
271 outline0("AND AL, 0xf0" );
272 outline1("MOV BL, [%s]", _background_color );
273 outline0("AND BL, 0x0f" );
274 outline0("OR AL, BL" );
275 outline0("CALL WRITECGACOLORSELECTREG" );
276
277}
278
289void cga_background_color_get_vars( Environment * _environment, char * _index, char * _background_color ) {
290
291 outline0("CALL READCGACOLORSELECTREG" );
292 outline0("AND AL, 0x0f" );
293 outline1("MOV [%s], AL", _background_color );
294
295}
296
307void cga_sprite_common_color( Environment * _environment, char * _index, char * _common_color ) {
308
309}
310
326void cga_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
327
328}
329
340void cga_next_raster( Environment * _environment ) {
341
342}
343
357void cga_next_raster_at( Environment * _environment, char * _label, char * _positionlo, char * _positionhi ) {
358
359}
360
361void cga_bank_select( Environment * _environment, int _bank ) {
362
363}
364
365int cga_screen_mode_enable( Environment * _environment, ScreenMode * _screen_mode ) {
366
367 _screen_mode->selected = 1;
368
369 cpu_store_8bit( _environment, "_PEN", _environment->defaultPenColor );
370 cpu_store_8bit( _environment, "_PAPER", _environment->defaultPaperColor );
371
372 switch( _screen_mode->id ) {
373
375 _environment->fontWidth = 8;
376 _environment->fontHeight = 8;
377 _environment->screenTilesWidth = 40;
378 _environment->screenTilesHeight = 25;
379 _environment->screenTiles = 255;
380 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
381 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
382 _environment->screenColors = 2;
383 _environment->currentModeBW = 2;
384
385 // Sequence of Events for Changing Modes
386 // 1 Determine the mode of operation.
387 // 2 Reset the video-enable bit in the mode-control register.
388 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
389 // 3 Program the 6845 CRT Controller to select the mode.
390 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
391
392 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
393 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
394 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
395 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
396 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
397 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
398 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
399 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
400 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
401 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
402 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
403 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
404 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
405 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
406 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
407 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
408 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
409 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
410
411 BIOS_VIDEO_MODE( 0x0000 );
412
413 // 4 Program the mode-control and color-select registers
414 // including re-enabling the video.
416 // 4 Program the mode-control and color-select registers
417 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_TEXT | CGA_MODE_BW | CGA_MODE_ENABLE );
418
419 cpu_store_16bit( _environment, "TEXTADDRESS", 0x0000 );
420
421 break;
422
424 _environment->fontWidth = 8;
425 _environment->fontHeight = 8;
426 _environment->screenTilesWidth = 40;
427 _environment->screenTilesHeight = 25;
428 _environment->screenTiles = 255;
429 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
430 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
431 _environment->screenColors = 16;
432 _environment->currentModeBW = 2;
433
434 // Sequence of Events for Changing Modes
435 // 1 Determine the mode of operation.
436 // 2 Reset the video-enable bit in the mode-control register.
437 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
438 // 3 Program the 6845 CRT Controller to select the mode.
439 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
440
441 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
442 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
443 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
444 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
445 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
446 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
447 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
448 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
449 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
450 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
451 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
452 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
453 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
454 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
455 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
456 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
457 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
458 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
459
460 BIOS_VIDEO_MODE( 0x0001 );
461
462 // 4 Program the mode-control and color-select registers
463 // including re-enabling the video.
465 // 4 Program the mode-control and color-select registers
466 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_TEXT | CGA_MODE_COLOR | CGA_MODE_ENABLE );
467
468 cpu_store_16bit( _environment, "TEXTADDRESS", 0x0000 );
469
470 break;
471
473 _environment->fontWidth = 8;
474 _environment->fontHeight = 8;
475 _environment->screenTilesWidth = 80;
476 _environment->screenTilesHeight = 25;
477 _environment->screenTiles = 255;
478 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
479 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
480 _environment->screenColors = 2;
481 _environment->currentModeBW = 2;
482
483 // Sequence of Events for Changing Modes
484 // 1 Determine the mode of operation.
485 // 2 Reset the video-enable bit in the mode-control register.
486 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
487 // 3 Program the 6845 CRT Controller to select the mode.
488 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
489
490 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
491 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
492 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
493 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
494 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
495 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
496 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
497 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
498 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
499 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
500 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
501 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
502 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
503 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
504 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
505 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
506 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
507 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
508
509 BIOS_VIDEO_MODE( 0x0002 );
510
511 // 4 Program the mode-control and color-select registers
512 // including re-enabling the video.
514 // 4 Program the mode-control and color-select registers
515 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_80x25 | CGA_MODE_TEXT | CGA_MODE_BW | CGA_MODE_ENABLE );
516
517 cpu_store_16bit( _environment, "TEXTADDRESS", 0x0000 );
518
519 break;
520
522 _environment->fontWidth = 8;
523 _environment->fontHeight = 8;
524 _environment->screenTilesWidth = 80;
525 _environment->screenTilesHeight = 25;
526 _environment->screenTiles = 255;
527 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
528 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
529 _environment->screenColors = 16;
530 _environment->currentModeBW = 2;
531
532 // Sequence of Events for Changing Modes
533 // 1 Determine the mode of operation.
534 // 2 Reset the video-enable bit in the mode-control register.
535 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
536 // 3 Program the 6845 CRT Controller to select the mode.
537 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
538
539 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
540 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
541 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
542 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
543 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
544 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
545 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
546 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
547 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
548 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
549 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
550 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
551 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
552 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
553 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
554 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
555 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
556 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
557
558 BIOS_VIDEO_MODE( 0x0003 );
559
560 // 4 Program the mode-control and color-select registers
561 // including re-enabling the video.
563 // 4 Program the mode-control and color-select registers
565
566 cpu_store_16bit( _environment, "TEXTADDRESS", 0x0000 );
567
568 break;
569
571 _environment->fontWidth = 8;
572 _environment->fontHeight = 8;
573 _environment->screenTilesWidth = 40;
574 _environment->screenTilesHeight = 25;
575 _environment->screenTiles = 255;
576 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
577 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
578 _environment->screenColors = 2;
579 _environment->currentModeBW = 0;
580
581 // Sequence of Events for Changing Modes
582 // 1 Determine the mode of operation.
583 // 2 Reset the video-enable bit in the mode-control register.
584 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
585 // 3 Program the 6845 CRT Controller to select the mode.
586 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
587
588 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
589 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
590 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
591 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
592 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
593 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
594 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
595 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
596 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
597 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
598 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
599 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
600 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
601 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
602 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
603 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
604 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
605 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
606
607 BIOS_VIDEO_MODE( 0x0005 );
608 // 4 Program the mode-control and color-select registers
609 // including re-enabling the video.
611 // 4 Program the mode-control and color-select registers
612 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_LORES | CGA_MODE_GRAPHIC | CGA_MODE_BW | CGA_MODE_ENABLE );
613
614 cpu_store_16bit( _environment, "BITMAPADDRESS", 0x0000 );
615
616 break;
617
619 _environment->fontWidth = 8;
620 _environment->fontHeight = 8;
621 _environment->screenTilesWidth = 40;
622 _environment->screenTilesHeight = 25;
623 _environment->screenTiles = 255;
624 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
625 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
626 _environment->screenColors = 4;
627 _environment->currentModeBW = 0;
628
629 // Sequence of Events for Changing Modes
630 // 1 Determine the mode of operation.
631 // 2 Reset the video-enable bit in the mode-control register.
632 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
633 // 3 Program the 6845 CRT Controller to select the mode.
634 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
635
636 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
637 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
638 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
639 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
640 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
641 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
642 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
643 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
644 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
645 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
646 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
647 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
648 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
649 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
650 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
651 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
652 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
653 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
654
655 BIOS_VIDEO_MODE( 0x0004 );
656
657 // 4 Program the mode-control and color-select registers
658 // including re-enabling the video.
660 // 4 Program the mode-control and color-select registers
661 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_LORES | CGA_MODE_GRAPHIC | CGA_MODE_COLOR | CGA_MODE_ENABLE );
662
663 cpu_store_16bit( _environment, "BITMAPADDRESS", 0x0000 );
664
665 break;
666
668 _environment->fontWidth = 8;
669 _environment->fontHeight = 8;
670 _environment->screenTilesWidth = 80;
671 _environment->screenTilesHeight = 25;
672 _environment->screenTiles = 255;
673 _environment->screenWidth = _environment->screenTilesWidth * _environment->fontWidth;
674 _environment->screenHeight = _environment->screenTilesHeight * _environment->fontHeight;
675 _environment->screenColors = 4;
676 _environment->currentModeBW = 0;
677
678 // Sequence of Events for Changing Modes
679 // 1 Determine the mode of operation.
680 // 2 Reset the video-enable bit in the mode-control register.
681 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_DISABLE )
682 // 3 Program the 6845 CRT Controller to select the mode.
683 // WRITE_MODE_CONTROL_REGISTER( CGA_MODE_40x25 | CGA_MODE_BW );
684
685 // WRITE_REGISTER( CGA_REG_HZ_TOTAL, 0x38 );
686 // WRITE_REGISTER( CGA_REG_HZ_DISP, 0x28 );
687 // WRITE_REGISTER( CGA_REG_HZ_SYNC_POS, 0x2d );
688 // WRITE_REGISTER( CGA_REG_HZ_SYNC_WIDTH, 0x0a );
689 // WRITE_REGISTER( CGA_REG_VT_TOTAL, 0x1f );
690 // WRITE_REGISTER( CGA_REG_VT_TOTAL_ADJUST, 0x06 );
691 // WRITE_REGISTER( CGA_REG_VT_VERT_TOTAL_ADJUST, 0x19 );
692 // WRITE_REGISTER( CGA_REG_VT_VERT_SYNC_POSITION, 0x1c );
693 // WRITE_REGISTER( CGA_REG_INTERLACE_MODE, 0x02 );
694 // WRITE_REGISTER( CGA_REG_MAX_SCAN_LINE_ADDRESS, 0x07 );
695 // WRITE_REGISTER( CGA_REG_CURSOR_START, 0x06 );
696 // WRITE_REGISTER( CGA_REG_CURSOR_END, 0x07 );
697 // WRITE_REGISTER( CGA_REG_START_ADDRESS_H, 0x0c );
698 // WRITE_REGISTER( CGA_REG_START_ADDRESS_L, 0x00 );
699 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_H, 0x?? );
700 // WRITE_REGISTER( CGA_REG_CURSOR_ADDRESS_L, 0x?? );
701 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_H, 0x?? );
702 // WRITE_REGISTER( CGA_REG_LPEN_ADDRESS_L, 0x?? );
703
704 BIOS_VIDEO_MODE( 0x0006 );
705
706 // 4 Program the mode-control and color-select registers
707 // including re-enabling the video.
709 // 4 Program the mode-control and color-select registers
711
712 cpu_store_16bit( _environment, "BITMAPADDRESS", 0x0000 );
713
714 break;
715
716 }
717
718 _environment->consoleTilesWidth = _environment->screenTilesWidth;
719 _environment->consoleTilesHeight = _environment->screenTilesHeight;
720
721 cpu_store_16bit( _environment, "CLIPX1", 0 );
722 cpu_store_16bit( _environment, "CLIPX2", (_environment->screenWidth-1) );
723 cpu_store_16bit( _environment, "CLIPY1", 0 );
724 cpu_store_16bit( _environment, "CLIPY2", (_environment->screenHeight-1) );
725
726 cpu_store_16bit( _environment, "ORIGINX", 0 );
727 cpu_store_16bit( _environment, "ORIGINY", 0 );
728
729 cpu_store_16bit( _environment, "CURRENTWIDTH", _environment->screenWidth );
730 cpu_store_16bit( _environment, "CURRENTHEIGHT", _environment->screenHeight );
731 cpu_move_16bit( _environment, "CURRENTWIDTH", "RESOLUTIONX" );
732 cpu_move_16bit( _environment, "CURRENTHEIGHT", "RESOLUTIONY" );
733 cpu_store_8bit( _environment, "CURRENTTILES", _environment->screenTiles );
734 cpu_store_8bit( _environment, "CURRENTTILESWIDTH", _environment->screenTilesWidth );
735 cpu_store_8bit( _environment, "CURRENTTILESWIDTHX8", _environment->screenTilesWidth * 8 );
736 cpu_store_8bit( _environment, "CURRENTTILESHEIGHT", _environment->screenTilesHeight );
737 cpu_store_8bit( _environment, "FONTWIDTH", _environment->fontWidth );
738 cpu_store_8bit( _environment, "FONTHEIGHT", _environment->fontHeight );
739 cpu_store_8bit( _environment, "CONSOLEX1", 0 );
740 cpu_store_8bit( _environment, "CONSOLEY1", 0 );
741 cpu_store_8bit( _environment, "CONSOLEX2", _environment->consoleTilesWidth-1 );
742 cpu_store_8bit( _environment, "CONSOLEY2", _environment->consoleTilesHeight-1 );
743 cpu_store_8bit( _environment, "CONSOLEW", _environment->consoleTilesWidth );
744 cpu_store_8bit( _environment, "CONSOLEH", _environment->consoleTilesHeight );
745
746 console_calculate( _environment );
747
748 if (_environment->vestigialConfig.clsImplicit ) {
749 cga_cls( _environment );
750 }
751
752}
753
754void console_calculate( Environment * _environment ) {
755
756 int startAddress = 0;
757
758 int consoleSA = startAddress + ( _environment->activeConsole.y1 * _environment->screenTilesWidth ) + _environment->activeConsole.x1;
759 int consoleWB = _environment->activeConsole.width * _environment->currentModeBW;
760 int consoleHB = _environment->activeConsole.height * 8;
761
762 cpu_store_16bit( _environment, "CONSOLESA", consoleSA );
763 cpu_store_8bit( _environment, "CONSOLEWB", consoleWB );
764 cpu_store_8bit( _environment, "CONSOLEHB", consoleHB );
765
766}
767
768void console_calculate_vars( Environment * _environment ) {
769
770 _environment->dynamicConsole = 1;
771
772 outline0( "CALL CONSOLECALCULATE" );
773
774}
775
776void cga_bitmap_enable( Environment * _environment, int _width, int _height, int _colors ) {
777
778 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 1, _width, _height, _colors, 8, 8 );
779
780 if ( mode ) {
781 cga_screen_mode_enable( _environment, mode );
782
783 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
784 cpu_store_8bit( _environment, "CURRENTTILEMODE", 0 );
785
786 _environment->currentMode = mode->id;
787 _environment->currentTileMode = 0;
788
789 if (_environment->vestigialConfig.clsImplicit ) {
790 cga_cls( _environment );
791 }
792
793 } else {
795 }
796
797}
798
799void cga_bitmap_disable( Environment * _environment ) {
800
801}
802
803void cga_tilemap_enable( Environment * _environment, int _width, int _height, int _colors, int _tile_width, int _tile_height ) {
804
805 ScreenMode * mode = find_screen_mode_by_suggestion( _environment, 0, _width, _height, _colors, _tile_width, _tile_height );
806
807 if ( mode ) {
808
809 // printf("cga_tilemap_enable() -> %d\n", mode->id );
810
811 cga_screen_mode_enable( _environment, mode );
812
813 _environment->currentMode = mode->id;
814 _environment->currentTileMode = 1;
815
816 cpu_store_8bit( _environment, "CURRENTMODE", mode->id );
817 cpu_store_8bit( _environment, "CURRENTTILEMODE", 1 );
818
819 if (_environment->vestigialConfig.clsImplicit ) {
820 cga_cls( _environment );
821 }
822
823 } else {
824 // printf("cga_tilemap_enable() -> -1\n" );
826 }
827
828}
829
830void cga_bitmap_at( Environment * _environment, char * _address ) {
831
832}
833
834void cga_colormap_at( Environment * _environment, char * _address ) {
835
836}
837
838void cga_textmap_at( Environment * _environment, char * _address ) {
839
840}
841
842void cga_pset_int( Environment * _environment, int _x, int _y, int *_c ) {
843
844 // deploy( cgavars, src_hw_cga_vars_asm);
845 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
846 deploy( plot, src_hw_cga_plot_asm );
847
848 if ( _c ) {
849 outline1("MOV AL, 0x%2.2x", ( *_c & 0xff ) );
850 } else {
851 Variable * c = variable_retrieve( _environment, "PEN" );
852 outline1("MOV AL, [%s]", c->realName );
853 }
854 outline0("MOV [PLOTCPE], AL");
855 outline0("AND AL, 3");
856 outline1("MOV CX, 0x%4.4x", ( _x & 0xffff ) );
857 outline1("MOV DX, 0x%4.4x", ( _y & 0xffff ) );
858 outline0("MOV AL, 1");
859 outline0("CALL PLOT");
860
861}
862
863void cga_pset_vars( Environment * _environment, char *_x, char *_y, char *_c ) {
864
865 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
866 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
867 Variable * c;
868
869 if ( _c ) {
870 c = variable_retrieve_or_define( _environment, _c, VT_COLOR, 0 );
871 } else {
872 c = variable_retrieve( _environment, "PEN" );
873 }
874
875 // deploy( cgavars, src_hw_cga_vars_asm);
876 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
877 deploy( plot, src_hw_cga_plot_asm );
878
879 outline1("MOV AL, [%s]", c->realName );
880 outline0("AND AL, 3");
881 outline0("MOV [PLOTCPE], AL");
882 outline1("MOV CX, [%s]", x->realName );
883 outline1("MOV DX, [%s]", y->realName );
884 outline0("MOV AL, 1");
885 outline0("CALL PLOT");
886
887}
888
889void cga_pget_color_vars( Environment * _environment, char *_x, char *_y, char * _result ) {
890
891 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
892 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
893 Variable * result = variable_retrieve_or_define( _environment, _result, VT_COLOR, 0 );
894
895 // deploy( cgavars, src_hw_cga_vars_asm);
896 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
897 deploy( plot, src_hw_cga_plot_asm );
898
899 outline1("MOV CX, [%s]", x->realName );
900 outline1("MOV DX, [%s]", y->realName );
901 outline0("MOV AL, 3");
902 outline0("CALL PLOT")
903 outline1("MOV [%s], AL", result->realName );
904
905}
906
907void cga_screen_on( Environment * _environment ) {
908
909 outline0("CALL READCGAMODECONTROLREG")
910 outline0("OR AL, 0x80")
911 outline0("CALL WRITECGAMODECONTROLREG")
912
913}
914
915void cga_screen_off( Environment * _environment ) {
916
917 outline0("CALL READCGAMODECONTROLREG")
918 outline0("AND AL, 0xf7")
919 outline0("CALL WRITECGAMODECONTROLREG")
920
921}
922
923void cga_screen_rows( Environment * _environment, char * _rows ) {
924
925}
926
927void cga_screen_columns( Environment * _environment, char * _columns ) {
928
929}
930
931void cga_sprite_data_set( Environment * _environment, char * _sprite, char * _address ) {
932
933}
934
935void cga_sprite_data_from( Environment * _environment, char * _sprite, char * _image ) {
936
937}
938
939void cga_sprite_enable( Environment * _environment, char * _sprite ) {
940
941}
942
943void cga_sprite_disable( Environment * _environment, char * _sprite ) {
944
945}
946
947void cga_sprite_at( Environment * _environment, char * _sprite, char * _x, char * _y ) {
948
949}
950
951void cga_sprite_expand_vertical( Environment * _environment, char * _sprite ) {
952
953}
954
955void cga_sprite_expand_horizontal( Environment * _environment, char * _sprite ) {
956
957}
958
959void cga_sprite_compress_vertical( Environment * _environment, char * _sprite ) {
960
961}
962
963void cga_sprite_compress_horizontal( Environment * _environment, char * _sprite ) {
964
965}
966
967void cga_sprite_multicolor( Environment * _environment, char * _sprite ) {
968
969}
970
971void cga_sprite_monocolor( Environment * _environment, char * _sprite ) {
972
973}
974
975void cga_sprite_color( Environment * _environment, char * _sprite, char * _color ) {
976
977}
978
979void cga_sprite_priority( Environment * _environment, char * _sprite, char * _priority ) {
980
981}
982
983void cga_tiles_at( Environment * _environment, char * _address ) {
984
985}
986
987void cga_vertical_scroll( Environment * _environment, char * _displacement ) {
988
989}
990
991void cga_horizontal_scroll( Environment * _environment, char * _displacement ) {
992
993}
994
995void cga_busy_wait( Environment * _environment, char * _timing ) {
996
997}
998
999void cga_get_width( Environment * _environment, char *_result ) {
1000
1001}
1002
1003void cga_tiles_get( Environment * _environment, char *_result ) {
1004
1005}
1006
1007void cga_get_height( Environment * _environment, char *_result ) {
1008
1009}
1010
1011void cga_cls( Environment * _environment ) {
1012
1013 if ( _environment->currentMode <= 3 ) {
1014 deploy( clsText, src_hw_cga_cls_text_asm );
1015 outline0("CALL CLST");
1016 } else {
1017
1018 }
1019
1020}
1021
1022void cga_cls_box( Environment * _environment, char * _x1, char * _y1, char * _w, char * _h ) {
1023
1024}
1025
1026void cga_scroll_text( Environment * _environment, int _direction, int _overlap ) {
1027
1028 if ( _direction > 0 ) {
1029 // deploy( vScrollTextDown, src_hw_tms9918_vscroll_text_down_asm );
1030 // outline0("CALL VSCROLLTDOWN");
1031 } else {
1032 deploy( vScrollTextUp, src_hw_cga_vscroll_text_up_asm );
1033 outline0("CALL VSCROLLTUP");
1034 }
1035
1036}
1037
1038void cga_text( Environment * _environment, char * _text, char * _text_size, int _raw ) {
1039
1040 deploy( cgavars, src_hw_cga_vars_asm);
1041
1042 outline1("MOV SI, [%s]", _text);
1043 outline1("MOV CL, [%s]", _text_size);
1044
1045 if ( _raw ) {
1046
1047 // if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1048 // deploy( clsGraphic, src_hw_cga_cls_graphic_asm );
1049 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
1050 // deploy( textEncodedAtGraphicRaw, src_hw_cga_text_at_graphic_raw_asm );
1051 // if ( ! _environment->hasGameLoop ) {
1052 // outline0("CALL TEXTATBITMAPMODERAW");
1053 // } else {
1054 // outline0("CALL TEXTATBITMAPMODENMI2RAW");
1055 // }
1056 // } else {
1057 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
1058 // deploy( clsText, src_hw_cga_cls_text_asm );
1059 // deploy( textEncodedAtTextRaw, src_hw_cga_text_at_text_raw_asm );
1060 // if ( ! _environment->hasGameLoop ) {
1061 // outline0("CALL TEXTATTILEMODERAW");
1062 // } else {
1063 // outline0("CALL TEXTATTILEMODENMI2RAW");
1064 // }
1065 // }
1066
1067 } else {
1068
1069 // if ( ( _environment->currentMode == 2 || _environment->currentMode == 3 ) && !_environment->currentTileMode ) {
1070 // deploy( clsGraphic, src_hw_cga_cls_graphic_asm );
1071 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
1072 // deploy( textEncodedAtGraphic, src_hw_cga_text_at_graphic_asm );
1073 // if ( ! _environment->hasGameLoop ) {
1074 // outline0("CALL TEXTATBITMAPMODE");
1075 // } else {
1076 // outline0("CALL TEXTATBITMAPMODENMI2");
1077 // }
1078 // } else {
1079 // deploy( cgavarsGraphic, src_hw_cga_vars_graphic_asm );
1080 deploy( clsText, src_hw_cga_cls_text_asm );
1081 deploy( vScrollTextUp, src_hw_cga_vscroll_text_up_asm );
1082 deploy( textEncodedAtText, src_hw_cga_text_at_text_asm );
1083 outline0("CALL TEXTATTILEMODE");
1084 // }
1085
1086
1087 }
1088
1089}
1090
1091void cga_initialization( Environment * _environment ) {
1092
1093 // deploy( cgavars, src_hw_cga_vars_asm );
1094 deploy_preferred( cgastartup, src_hw_cga_startup_asm );
1095
1096 cpu_call( _environment, "CGASTARTUP" );
1097
1098 variable_import( _environment, "CURRENTWIDTH", VT_POSITION, 256 );
1099 variable_global( _environment, "CURRENTWIDTH" );
1100 variable_import( _environment, "CURRENTHEIGHT", VT_POSITION, 192 );
1101 variable_global( _environment, "CURRENTHEIGHT" );
1102 variable_import( _environment, "CURRENTTILES", VT_BYTE, 255 );
1103 variable_global( _environment, "CURRENTTILES" );
1104 variable_import( _environment, "CURRENTTILESWIDTH", VT_SBYTE, 40 );
1105 variable_global( _environment, "CURRENTTILESWIDTH" );
1106 variable_import( _environment, "CURRENTTILESWIDTHX8", VT_WORD, 320 );
1107 variable_global( _environment, "CURRENTTILESWIDTHX8" );
1108 variable_import( _environment, "CURRENTTILESHEIGHT", VT_SBYTE, 24 );
1109 variable_global( _environment, "CURRENTTILESHEIGHT" );
1110 variable_import( _environment, "FONTWIDTH", VT_BYTE, 8 );
1111 variable_global( _environment, "FONTWIDTH" );
1112 variable_import( _environment, "FONTHEIGHT", VT_BYTE, 8 );
1113 variable_global( _environment, "FONTHEIGHT" );
1114 variable_import( _environment, "SPRITEADDRESS", VT_ADDRESS, 0x3b00 );
1115 variable_global( _environment, "SPRITEADDRESS" );
1116 variable_import( _environment, "SPRITEAADDRESS", VT_ADDRESS, 0x1800 );
1117 variable_global( _environment, "SPRITEAADDRESS" );
1118 variable_import( _environment, "TEXTADDRESS", VT_ADDRESS, 0x0e * 0x0400 );
1119 variable_global( _environment, "TEXTADDRESS" );
1120 variable_import( _environment, "COLORMAPADDRESS", VT_ADDRESS, 0x2000 );
1121 variable_global( _environment, "COLORMAPADDRESS" );
1122 variable_import( _environment, "PATTERNADDRESS", VT_ADDRESS, 0x0000 );
1123 variable_global( _environment, "PATTERNADDRESS" );
1124
1125 SCREEN_MODE_DEFINE( TILEMAP_MODE_40x25x2, 0, 40, 25, 2, 8, 8, "Text Mode (40x25, b/w)" );
1126 SCREEN_MODE_DEFINE( TILEMAP_MODE_40x25x16, 0, 40, 25, 16, 8, 8, "Text Mode (40x25, 16 colors)" );
1127 SCREEN_MODE_DEFINE( TILEMAP_MODE_80x25x2, 0, 80, 25, 2, 8, 8, "Text Mode (80x25, 2 colors)" );
1128 SCREEN_MODE_DEFINE( TILEMAP_MODE_80x25x16, 0, 80, 25, 16, 8, 8, "Text Mode (80x25, 16 colors)" );
1129
1130 SCREEN_MODE_DEFINE( BITMAP_MODE_320x200x4, 1, 320, 200, 4, 8, 8, "Grahic Mode (320x200, 4 colors)" );
1131 SCREEN_MODE_DEFINE( BITMAP_MODE_320x200x2, 1, 320, 200, 2, 8, 8, "Grahic Mode (320x200, 2 colors)" );
1132 SCREEN_MODE_DEFINE( BITMAP_MODE_640x200x2, 1, 640, 200, 2, 8, 8, "Grahic Mode (640x200, 2 colors)" );
1133
1134 // outline0("CALL TMS9918STARTUP");
1135
1136 variable_import( _environment, "XGR", VT_POSITION, 0 );
1137 variable_global( _environment, "XGR" );
1138 variable_import( _environment, "YGR", VT_POSITION, 0 );
1139 variable_global( _environment, "YGR" );
1140 variable_import( _environment, "LINE", VT_WORD, (unsigned short)(0xffff) );
1141 variable_global( _environment, "LINE" );
1142
1143 variable_import( _environment, "CLIPX1", VT_POSITION, 0 );
1144 variable_global( _environment, "CLIPX1" );
1145 variable_import( _environment, "CLIPX2", VT_POSITION, 255 );
1146 variable_global( _environment, "CLIPX2" );
1147 variable_import( _environment, "CLIPY1", VT_POSITION, 0 );
1148 variable_global( _environment, "CLIPY1" );
1149 variable_import( _environment, "CLIPY2", VT_POSITION, 191 );
1150 variable_global( _environment, "CLIPY2" );
1151
1152 variable_import( _environment, "ORIGINX", VT_POSITION, 0 );
1153 variable_global( _environment, "ORIGINX" );
1154 variable_import( _environment, "ORIGINY", VT_POSITION, 0 );
1155 variable_global( _environment, "ORIGINY" );
1156
1157 variable_import( _environment, "RESOLUTIONX", VT_POSITION, 0 );
1158 variable_global( _environment, "RESOLUTIONX" );
1159 variable_import( _environment, "RESOLUTIONY", VT_POSITION, 0 );
1160 variable_global( _environment, "RESOLUTIONY" );
1161
1162 variable_import( _environment, "TABCOUNT", VT_BYTE, 4 );
1163 variable_global( _environment, "TABCOUNT" );
1164
1165 variable_import( _environment, "CLINEX", VT_BYTE, 0 );
1166 variable_global( _environment, "CLINEX" );
1167
1168 variable_import( _environment, "CLINEY", VT_BYTE, 0 );
1169 variable_global( _environment, "CLINEY" );
1170
1171 variable_import( _environment, "PLOTCPE", VT_BYTE, 0 );
1172 variable_global( _environment, "PLOTCPE" );
1173
1174 variable_import( _environment, "TABSTODRAW", VT_BYTE, 0 );
1175 variable_global( _environment, "TABSTODRAW" );
1176
1177 variable_import( _environment, "CURRENTMODE", VT_BYTE, 2 );
1178 variable_global( _environment, "CURRENTMODE" );
1179 variable_import( _environment, "CURRENTTILEMODE", VT_BYTE, 1 );
1180 variable_global( _environment, "CURRENTTILEMODE" );
1181
1182 variable_import( _environment, "SPRITECOUNT", VT_SPRITE, 0 );
1183 variable_global( _environment, "SPRITECOUNT" );
1184
1185 variable_import( _environment, "TILEX", VT_BYTE, 0 );
1186 variable_global( _environment, "TILEX" );
1187 variable_import( _environment, "TILEY", VT_BYTE, 0 );
1188 variable_global( _environment, "TILEY" );
1189 variable_import( _environment, "TILEX2", VT_BYTE, 0 );
1190 variable_global( _environment, "TILEX2" );
1191 variable_import( _environment, "TILET", VT_BYTE, 0 );
1192 variable_global( _environment, "TILET" );
1193 variable_import( _environment, "TILEW", VT_BYTE, 0 );
1194 variable_global( _environment, "TILEW" );
1195 variable_import( _environment, "TILEH", VT_BYTE, 0 );
1196 variable_global( _environment, "TILEH" );
1197 variable_import( _environment, "TILEW2", VT_BYTE, 0 );
1198 variable_global( _environment, "TILEW2" );
1199 variable_import( _environment, "TILEH2", VT_BYTE, 0 );
1200 variable_global( _environment, "TILEH2" );
1201 variable_import( _environment, "TILEA", VT_BYTE, 0 );
1202 variable_global( _environment, "TILEA" );
1203 variable_import( _environment, "TILEO", VT_WORD, 0 );
1204 variable_global( _environment, "TILEO" );
1205
1206 variable_import( _environment, "XSCROLLPOS", VT_BYTE, 0 );
1207 variable_global( _environment, "XSCROLLPOS" );
1208 variable_import( _environment, "YSCROLLPOS", VT_BYTE, 0 );
1209 variable_global( _environment, "YSCROLLPOS" );
1210 variable_import( _environment, "XSCROLL", VT_BYTE, 0 );
1211 variable_global( _environment, "XSCROLL" );
1212 variable_import( _environment, "YSCROLL", VT_BYTE, 0 );
1213 variable_global( _environment, "YSCROLL" );
1214 variable_import( _environment, "DIRECTION", VT_BYTE, 0 );
1215 variable_global( _environment, "DIRECTION" );
1216
1217 variable_import( _environment, "ONSCROLLUP", VT_BUFFER, 3 );
1218 variable_global( _environment, "ONSCROLLUP" );
1219
1220 variable_import( _environment, "ONSCROLLDOWN", VT_BUFFER, 3 );
1221 variable_global( _environment, "ONSCROLLDOWN" );
1222
1223 variable_import( _environment, "ONSCROLLLEFT", VT_BUFFER, 3 );
1224 variable_global( _environment, "ONSCROLLLEFT" );
1225
1226 variable_import( _environment, "ONSCROLLRIGHT", VT_BUFFER, 3 );
1227 variable_global( _environment, "ONSCROLLRIGHT" );
1228
1229 variable_import( _environment, "IMAGEF", VT_BYTE, 0 );
1230 variable_global( _environment, "IMAGEF" );
1231
1232 variable_import( _environment, "IMAGET", VT_BYTE, 0 );
1233 variable_global( _environment, "IMAGET" );
1234
1235 variable_import( _environment, "IMAGEY", VT_BYTE, 0 );
1236 variable_global( _environment, "IMAGEY" );
1237
1238 variable_import( _environment, "BLITIMAGEBLITTINGADDR", VT_ADDRESS, 0 );
1239 variable_global( _environment, "BLITIMAGEBLITTINGADDR" );
1240 variable_import( _environment, "BLITTMPPTR", VT_ADDRESS, 0 );
1241 variable_global( _environment, "BLITTMPPTR" );
1242 variable_import( _environment, "BLITTMPPTR2", VT_ADDRESS, 0 );
1243 variable_global( _environment, "BLITTMPPTR2" );
1244
1245 variable_import( _environment, "VBLFLAG", VT_BYTE, 0 );
1246 variable_global( _environment, "VBLFLAG" );
1247 variable_import( _environment, "VDPINUSE", VT_BYTE, 0 );
1248 variable_global( _environment, "VDPINUSE" );
1249
1250 variable_import( _environment, "SLICEX", VT_POSITION, 0 );
1251 variable_global( _environment, "SLICEX" );
1252 variable_import( _environment, "SLICEY", VT_POSITION, 0 );
1253 variable_global( _environment, "SLICEY" );
1254 variable_import( _environment, "SLICEDTARGET", VT_POSITION, 0 );
1255 variable_global( _environment, "SLICEDTARGET" );
1256
1257 variable_import( _environment, "CONSOLESA", VT_ADDRESS, 0x0 );
1258 variable_global( _environment, "CONSOLESA" );
1259 variable_import( _environment, "CONSOLEHB", VT_BYTE, 0x0 );
1260 variable_global( _environment, "CONSOLEHB" );
1261 variable_import( _environment, "CONSOLEWB", VT_BYTE, 0x0 );
1262 variable_global( _environment, "CONSOLEWB" );
1263
1264 cga_tilemap_enable( _environment, 40, 25, 16, 8, 8 );
1265
1266 font_descriptors_init( _environment, 0 );
1267
1268 console_init( _environment );
1269
1270 // _environment->currentRgbConverterFunction = rgbConverterFunction;
1271 _environment->screenShades = 16;
1272
1273}
1274
1275void cga_finalization( Environment * _environment ) {
1276
1277 if ( _environment->vestigialConfig.clsImplicit ) {
1278 deploy( clsText, src_hw_cga_cls_text_asm );
1279 }
1280
1281 CopperList * copperList = _environment->copperList;
1282 if ( copperList ) {
1283 while(copperList) {
1284 outhead1("COPPERACTIVATE%s:", copperList->name ? copperList->name : "" );
1285 outline0("RET");
1286 copperList = copperList->next;
1287 }
1288 }
1289
1290}
1291
1292void cga_hscroll_line( Environment * _environment, int _direction, int _overlap ) {
1293
1294}
1295
1296void cga_hscroll_screen( Environment * _environment, int _direction, int _overlap ) {
1297
1298}
1299
1300void cga_back( Environment * _environment ) {
1301
1302}
1303
1304void cga_cline( Environment * _environment, char * _characters ) {
1305
1306}
1307
1308int cga_image_size( Environment * _environment, int _width, int _height, int _mode ) {
1309
1310 switch( _mode ) {
1311
1318 break;
1319
1321
1322 return 3 + ( ( _width >> 2 ) * _height );
1323
1324 }
1325
1326 return 1;
1327
1328}
1329
1330static int calculate_images_size( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1331
1332 switch( _mode ) {
1339 break;
1340
1342 return 3 + ( 3 + ( ( _width >> 2 ) * _height ) ) * _frames;
1343
1344 }
1345
1346 return 0;
1347
1348}
1349
1350static int calculate_sequence_size( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1351
1352 switch( _mode ) {
1359 break;
1360
1362 return 3 + ( ( 3 + ( ( _width >> 2 ) * _height ) ) * _frames ) * _sequences;
1363
1364 }
1365
1366 return 0;
1367
1368}
1369
1370Variable * cga_sprite_converter( Environment * _environment, char * _source, int _width, int _height, int _depth, RGBi * _color, int _slot_x, int _slot_y ) {
1371
1372 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1373
1374 return result;
1375
1376}
1377
1378static Variable * cga_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 ) {
1379
1380 RGBi white = { 0xff, 0xff, 0xff, 0xff };
1381 RGBi black = { 0x00, 0x00, 0x00, 0x00 };
1382
1383 // ignored on bitmap mode
1384 (void)!_transparent_color;
1385
1386 image_converter_asserts_free_height( _environment, _width, _height, _offset_x, _offset_y, &_frame_width, &_frame_height, 8 );
1387
1388 if ( _environment->freeImageWidth ) {
1389 if ( _width % 8 ) {
1390 _width = ( ( ( _width - 1 ) / 8 ) - 1 ) * 8;
1391 }
1392 if ( _frame_width % 8 ) {
1393 _frame_width = ( ( ( _frame_width - 1 ) / 8 ) - 1 ) * 8;
1394 }
1395 }
1396
1397 RGBi * palette = malloc_palette( MAX_PALETTE );
1398
1399 int paletteColorCount = rgbi_extract_palette(_environment, _source, _width, _height, _depth, palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1400
1401 if (paletteColorCount > 4) {
1402 CRITICAL_IMAGE_CONVERTER_TOO_COLORS( paletteColorCount );
1403 }
1404
1405 int i, j, k;
1406
1407 SYSTEM_PALETTE = &SYSTEM_PALETTE_ALTERNATE[_environment->paletteSelected][0];
1408
1409 commonPalette = palette_match( palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE_ALTERNATE[0]) / sizeof(RGBi) );
1410 commonPalette = palette_remove_duplicates( commonPalette, paletteColorCount, &paletteColorCount );
1411 lastUsedSlotInCommonPalette = paletteColorCount;
1412 adilinepalette( "CPM1:%d", paletteColorCount, commonPalette );
1413
1414 adilinepalette( "CPMS:%d", (int)(sizeof(SYSTEM_PALETTE_ALTERNATE[0]) / sizeof(RGBi)), SYSTEM_PALETTE );
1415
1416 Variable * result = variable_temporary( _environment, VT_IMAGE, 0 );
1418 memcpy( result->originalPalette, commonPalette, lastUsedSlotInCommonPalette * sizeof( RGBi ) );
1419
1420 int bufferSize = cga_image_size( _environment, _frame_width, _frame_height, BITMAP_MODE_320x200x4 );
1421
1422 adiline3("BMP:%4.4x:%4.4x:%2.2x", _frame_width, _frame_height, BITMAP_MODE_320x200x4 );
1423
1424 char * buffer = malloc ( bufferSize );
1425 memset( buffer, 0, bufferSize );
1426
1427 // Position of the pixel in the original image
1428 int image_x, image_y;
1429
1430 // Position of the pixel, in terms of tiles
1431 int tile_x, tile_y;
1432
1433 // Position of the pixel, in terms of offset and bitmask
1434 int offset, offsetc, bitmask;
1435
1436 // Color of the pixel to convert
1437 RGBi rgb;
1438
1439 *(buffer) = _frame_width;
1440 *(buffer+1) = _frame_height;
1441 *(buffer+2) = 0;
1442
1443 _source += ( ( _offset_y * _width ) + _offset_x ) * _depth;
1444
1445 adilinebeginbitmap("BMD");
1446
1447 // Loop for all the source surface.
1448 for (image_y = 0; image_y < _frame_height; ++image_y) {
1449 for (image_x = 0; image_x < _frame_width; ++image_x) {
1450
1451 // Take the color of the pixel
1452 rgb.red = *_source;
1453 rgb.green = *(_source + 1);
1454 rgb.blue = *(_source + 2);
1455 if ( _depth > 3 ) {
1456 rgb.alpha = *(_source + 3);
1457 } else {
1458 rgb.alpha = 255;
1459 }
1460 if ( rgb.alpha == 0 ) {
1461 rgb.red = 0;
1462 rgb.green = 0;
1463 rgb.blue = 0;
1464 }
1465
1466 offset = ( image_y * ( _frame_width >> 2 ) ) + ( image_x >> 2 );
1467
1468 int colorIndex = 0;
1469
1470 if ( rgb.alpha < 255 ) {
1471 colorIndex = 0;
1472 } else {
1473 int minDistance = 9999;
1474 for( int i=0; i<lastUsedSlotInCommonPalette; ++i ) {
1475 int distance = rgbi_distance(&commonPalette[i], &rgb );
1476 if ( distance < minDistance ) {
1477 minDistance = distance;
1478 colorIndex = commonPalette[i].index;
1479 }
1480 }
1481 }
1482
1483 adilinepixel(colorIndex);
1484
1485 // printf( "%1.1x", colorIndex );
1486
1487 bitmask = colorIndex << (6 - ((image_x & 0x3) * 2));
1488
1489 *(buffer + 3 + offset) |= bitmask;
1490
1491 _source += _depth;
1492
1493 }
1494
1495 _source += ( _width - _frame_width ) * _depth;
1496
1497 // printf("\n" );
1498 }
1499
1501
1502 // for(i=0; i<4; ++i ) {
1503 // printf( "%1.1x = %2.2x\n", i, palette[i].index );
1504 // }
1505
1506 // printf("\n" );
1507 // printf("\n" );
1508
1509 variable_store_buffer( _environment, result->name, buffer, bufferSize, 0 );
1510
1511 return result;
1512
1513}
1514
1515Variable * cga_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 ) {
1516
1517 switch( _mode ) {
1518
1525 break;
1526
1528
1529 return cga_image_converter_multicolor_mode_standard( _environment, _data, _width, _height, _depth, _offset_x, _offset_y, _frame_width, _frame_height, _transparent_color, _flags );
1530
1531 break;
1532
1533 }
1534
1536
1537 return cga_new_image( _environment, 8, 8, BITMAP_MODE_320x200x4 );
1538
1539}
1540
1541void cga_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 ) {
1542
1543}
1544
1545void cga_put_image( Environment * _environment, Resource * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _flags ) {
1546
1547}
1548
1549void cga_wait_vbl( Environment * _environment ) {
1550
1551}
1552
1553Variable * cga_new_image( Environment * _environment, int _width, int _height, int _mode ) {
1554
1555 int size = cga_image_size( _environment, _width, _height, _mode );
1556
1557 if ( ! size ) {
1559 }
1560
1561 Variable * result = variable_temporary( _environment, VT_IMAGE, "(new image)" );
1562
1563 char * buffer = malloc ( size );
1564 memset( buffer, 0, size );
1565
1566 *(buffer) = _width;
1567 *(buffer+1) = _height;
1568 *(buffer+2) = 0;
1569
1570 result->valueBuffer = buffer;
1571 result->size = size;
1572
1573 return result;
1574
1575}
1576
1577Variable * cga_new_images( Environment * _environment, int _frames, int _width, int _height, int _mode ) {
1578
1579 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
1580 int frameSize = cga_image_size( _environment, _width, _height, _mode );
1581
1582 if ( ! size ) {
1584 }
1585
1586 Variable * result = variable_temporary( _environment, VT_IMAGES, "(new images)" );
1587
1588 char * buffer = malloc ( size );
1589 memset( buffer, 0, size );
1590
1591 *(buffer) = _frames;
1592 *(buffer+1) = ( _width & 0xff );
1593 *(buffer+2) = ( _width >> 8 ) & 0xff;
1594 for( int i=0; i<_frames; ++i ) {
1595 *(buffer+3+(i*frameSize)) = _width;
1596 *(buffer+3+(i*frameSize)+1) = _height;
1597 }
1598
1599 result->valueBuffer = buffer;
1600 result->frameSize = frameSize;
1601 result->size = size;
1602 result->frameCount = _frames;
1603
1604 return result;
1605
1606}
1607
1608Variable * cga_new_sequence( Environment * _environment, int _sequences, int _frames, int _width, int _height, int _mode ) {
1609
1610 int size2 = calculate_sequence_size( _environment, _sequences, _frames, _width, _height, _mode );
1611 int size = calculate_images_size( _environment, _frames, _width, _height, _mode );
1612 int frameSize = cga_image_size( _environment, _width, _height, _mode );
1613
1614 if ( ! size ) {
1616 }
1617
1618 Variable * result = variable_temporary( _environment, VT_SEQUENCE, "(new sequence)" );
1619
1620 char * buffer = malloc ( size2 );
1621 memset( buffer, 0, size2 );
1622
1623 *(buffer) = _frames;
1624 *(buffer+1) = _width;
1625 *(buffer+2) = _sequences;
1626 for( int i=0; i<(_frames * _sequences); ++i ) {
1627 *(buffer+3+(i*frameSize)) = _width;
1628 *(buffer+3+(i*frameSize)+1) = _height;
1629 }
1630
1631 result->valueBuffer = buffer;
1632 result->frameSize = frameSize;
1633 result->size = size2;
1634 result->frameCount = _frames;
1635
1636 return result;
1637
1638}
1639
1640void cga_get_image( Environment * _environment, char * _image, char * _x, char * _y, char * _frame, char * _sequence, int _frame_size, int _frame_count, int _palette ) {
1641
1642}
1643
1644void cga_scroll( Environment * _environment, int _dx, int _dy ) {
1645
1646}
1647
1648void cga_put_tile( Environment * _environment, char * _tile, char * _x, char * _y ) {
1649
1650}
1651
1652void cga_move_tiles( Environment * _environment, char * _tile, char * _x, char * _y ) {
1653
1654}
1655
1656void cga_put_tiles( Environment * _environment, char * _tile, char * _x, char * _y, char *_w, char *_h ) {
1657
1658}
1659
1660void cga_tile_at( Environment * _environment, char * _x, char * _y, char *_result ) {
1661
1662}
1663
1664void cga_use_tileset( Environment * _environment, char * _tileset ) {
1665
1666}
1667
1669
1670 Variable * result = variable_temporary( _environment, VT_WORD, "(raster line)" );
1671
1672 variable_store( _environment, result->name, 0 );
1673
1674 return result;
1675
1676}
1677
1678void cga_move_memory_video( Environment * _environment, char * _from, char * _to, char * _size ) {
1679
1680}
1681
1682void cga_move_video_memory( Environment * _environment, char * _from, char * _to, char * _size ) {
1683
1684}
1685
1686void cga_colors_vars( Environment * _environment, char * _foreground_color, char * _background_color ) {
1687
1688}
1689
1690void cga_slice_image( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
1691
1692}
1693
1694void cga_slice_image_copy( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
1695
1696}
1697
1698void cga_slice_image_extract( Environment * _environment, char * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _destination ) {
1699
1700}
1701
1702int cga_palette_extract( Environment * _environment, char * _data, int _width, int _height, int _depth, int _flags, RGBi * _palette ) {
1703
1704 int paletteColorCount = rgbi_extract_palette(_environment, _data, _width, _height, _depth, _palette, MAX_PALETTE, ( ( _flags & FLAG_EXACT ) ? 0 : 1 ) /* sorted */);
1705
1706 memcpy( _palette, palette_match( _palette, paletteColorCount, SYSTEM_PALETTE, sizeof(SYSTEM_PALETTE) / sizeof(RGBi) ), paletteColorCount * sizeof( RGBi ) );
1707
1708 int uniquePaletteCount = 0;
1709
1710 memcpy( _palette, palette_remove_duplicates( _palette, paletteColorCount, &uniquePaletteCount ), paletteColorCount * sizeof( RGBi ) );
1711
1712 return uniquePaletteCount;
1713
1714}
1715
1716void cga_calculate_sequence_frame_offset( Environment * _environment, char * _offset, char * _sequence, char * _frame, int _frame_size, int _frame_count ) {
1717
1718}
1719
1720void cga_flip_image( Environment * _environment, Resource * _image, char * _frame, char * _sequence, int _frame_size, int _frame_count, char * _direction ) {
1721
1722}
1723
1724void cga_screen( Environment * _environment, char * _x, char * _y, char * _c ) {
1725
1726}
1727
1728#endif
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_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
int lastUsedSlotInCommonPalette
Definition 6847.c:100
#define COLOR_COUNT
Definition 6847.h:72
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int rgbi_distance(RGBi *_e1, RGBi *_e2)
Calculate the distance between two colors.
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 rgbi_equals_rgb(RGBi *_first, RGBi *_second)
Variable * variable_import(Environment *_environment, char *_name, VariableType _type, int _size_or_value)
RGBi * malloc_palette(int _size)
Allocate a palette space.
void variable_global(Environment *_environment, char *_pattern)
ScreenMode * find_screen_mode_by_suggestion(Environment *_environment, int _bitmap, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int rgbi_extract_palette(Environment *_environment, unsigned char *_source, int _width, int _height, int _depth, RGBi _palette[], int _palette_size, int _sorted)
Extract the color palette from the given image.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
RGBi * palette_remove_duplicates(RGBi *_source, int _source_size, int *_unique_size)
Remove duplicates from a palette.
void font_descriptors_init(Environment *_environment, int _embedded_present)
RGBi * palette_match(RGBi *_source, int _source_size, RGBi *_system, int _system_size)
Make a "palette match".
Variable * variable_store_buffer(Environment *_environment, char *_destination, unsigned char *_buffer, int _size, int _at)
int size
Definition _optimizer.c:678
int offset
Definition _optimizer.c:681
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
void cga_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 cga.c:1541
void cga_initialization(Environment *_environment)
Definition cga.c:1091
void cga_colormap_at(Environment *_environment, char *_address)
Definition cga.c:834
#define CGA_MODE_TEXT
Definition cga.c:125
void cga_scroll_text(Environment *_environment, int _direction, int _overlap)
Definition cga.c:1026
Variable * cga_new_sequence(Environment *_environment, int _sequences, int _frames, int _width, int _height, int _mode)
Definition cga.c:1608
void cga_move_video_memory(Environment *_environment, char *_from, char *_to, char *_size)
Definition cga.c:1682
void cga_next_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
CGA: emit code to wait for next raster irq at different position
Definition cga.c:357
void cga_screen_columns(Environment *_environment, char *_columns)
Definition cga.c:927
void cga_border_color(Environment *_environment, char *_border_color)
CGA: emit code to change border color
Definition cga.c:206
int cga_screen_mode_enable(Environment *_environment, ScreenMode *_screen_mode)
Definition cga.c:365
void cga_vertical_scroll(Environment *_environment, char *_displacement)
Definition cga.c:987
void cga_screen_on(Environment *_environment)
Definition cga.c:907
void cga_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition cga.c:1716
void cga_cls(Environment *_environment)
Definition cga.c:1011
RGBi * CGA_image_nearest_system_color(RGBi *_color)
Definition cga.c:147
void cga_sprite_data_set(Environment *_environment, char *_sprite, char *_address)
Definition cga.c:931
Variable * cga_collision(Environment *_environment, char *_sprite)
Definition cga.c:174
void cga_slice_image_copy(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition cga.c:1694
void cga_hscroll_line(Environment *_environment, int _direction, int _overlap)
Definition cga.c:1292
void cga_text(Environment *_environment, char *_text, char *_text_size, int _raw)
Definition cga.c:1038
void cga_sprite_color(Environment *_environment, char *_sprite, char *_color)
Definition cga.c:975
void cga_sprite_compress_vertical(Environment *_environment, char *_sprite)
Definition cga.c:959
#define CGA_MODE_80x25
Definition cga.c:121
void cga_screen_rows(Environment *_environment, char *_rows)
Definition cga.c:923
void cga_sprite_compress_horizontal(Environment *_environment, char *_sprite)
Definition cga.c:963
void cga_background_color_vars(Environment *_environment, char *_index, char *_background_color)
CGA: emit code to change background color
Definition cga.c:247
#define CGA_MODE_HIRES
Definition cga.c:133
#define CGA_MODE_GRAPHIC
Definition cga.c:124
void cga_sprite_expand_vertical(Environment *_environment, char *_sprite)
Definition cga.c:951
void cga_raster_at(Environment *_environment, char *_label, char *_positionlo, char *_positionhi)
CGA: emit code to set raster irq
Definition cga.c:326
#define WRITE_COLOR_SELECT_REGISTER(v)
Definition cga.c:117
void cga_tiles_at(Environment *_environment, char *_address)
Definition cga.c:983
void cga_sprite_multicolor(Environment *_environment, char *_sprite)
Definition cga.c:967
void cga_bitmap_enable(Environment *_environment, int _width, int _height, int _colors)
Definition cga.c:776
void cga_pset_vars(Environment *_environment, char *_x, char *_y, char *_c)
Definition cga.c:863
void cga_sprite_common_color(Environment *_environment, char *_index, char *_common_color)
CGA: emit code to change common sprite's color
Definition cga.c:307
void cga_get_image(Environment *_environment, char *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, int _palette)
Definition cga.c:1640
void cga_bitmap_disable(Environment *_environment)
Definition cga.c:799
Variable * cga_new_image(Environment *_environment, int _width, int _height, int _mode)
Definition cga.c:1553
void cga_busy_wait(Environment *_environment, char *_timing)
Definition cga.c:995
void cga_slice_image(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition cga.c:1690
#define CGA_MODE_ENABLE
Definition cga.c:130
void cga_bank_select(Environment *_environment, int _bank)
Definition cga.c:361
#define WRITE_MODE_CONTROL_REGISTER(v)
Definition cga.c:139
void cga_move_memory_video(Environment *_environment, char *_from, char *_to, char *_size)
Definition cga.c:1678
void cga_get_height(Environment *_environment, char *_result)
Definition cga.c:1007
void cga_get_width(Environment *_environment, char *_result)
Definition cga.c:999
void cga_back(Environment *_environment)
Definition cga.c:1300
void cga_bitmap_at(Environment *_environment, char *_address)
Definition cga.c:830
int cga_palette_extract(Environment *_environment, char *_data, int _width, int _height, int _depth, int _flags, RGBi *_palette)
Definition cga.c:1702
void cga_sprite_data_from(Environment *_environment, char *_sprite, char *_image)
Definition cga.c:935
#define BIOS_VIDEO_MODE(m)
Definition cga.c:143
void cga_sprite_expand_horizontal(Environment *_environment, char *_sprite)
Definition cga.c:955
Variable * cga_sprite_converter(Environment *_environment, char *_source, int _width, int _height, int _depth, RGBi *_color, int _slot_x, int _slot_y)
Definition cga.c:1370
void cga_horizontal_scroll(Environment *_environment, char *_displacement)
Definition cga.c:991
void cga_use_tileset(Environment *_environment, char *_tileset)
Definition cga.c:1664
void cga_cline(Environment *_environment, char *_characters)
Definition cga.c:1304
#define CGA_MODE_BW
Definition cga.c:127
void cga_sprite_disable(Environment *_environment, char *_sprite)
Definition cga.c:943
void cga_move_tiles(Environment *_environment, char *_tile, char *_x, char *_y)
Definition cga.c:1652
void cga_sprite_monocolor(Environment *_environment, char *_sprite)
Definition cga.c:971
void cga_sprite_priority(Environment *_environment, char *_sprite, char *_priority)
Definition cga.c:979
void cga_sprite_at(Environment *_environment, char *_sprite, char *_x, char *_y)
Definition cga.c:947
void cga_put_tiles(Environment *_environment, char *_tile, char *_x, char *_y, char *_w, char *_h)
Definition cga.c:1656
void cga_screen_off(Environment *_environment)
Definition cga.c:915
void cga_finalization(Environment *_environment)
Definition cga.c:1275
void cga_sprite_enable(Environment *_environment, char *_sprite)
Definition cga.c:939
void console_calculate_vars(Environment *_environment)
Definition cga.c:768
#define CGA_COLOR_CSET1
Definition cga.c:114
void cga_background_color_get_vars(Environment *_environment, char *_index, char *_background_color)
CGA: emit code to retrieve background color
Definition cga.c:289
void cga_tile_at(Environment *_environment, char *_x, char *_y, char *_result)
Definition cga.c:1660
void cga_textmap_at(Environment *_environment, char *_address)
Definition cga.c:838
void cga_next_raster(Environment *_environment)
CGA: emit code to wait for next raster irq
Definition cga.c:340
void cga_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition cga.c:1720
void cga_background_color(Environment *_environment, int _index, int _background_color)
CGA: emit code to change background color
Definition cga.c:227
Variable * cga_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 cga.c:1515
Variable * cga_get_raster_line(Environment *_environment)
Definition cga.c:1668
Variable * cga_new_images(Environment *_environment, int _frames, int _width, int _height, int _mode)
Definition cga.c:1577
void cga_pget_color_vars(Environment *_environment, char *_x, char *_y, char *_result)
Definition cga.c:889
void cga_tilemap_enable(Environment *_environment, int _width, int _height, int _colors, int _tile_width, int _tile_height)
Definition cga.c:803
void cga_pset_int(Environment *_environment, int _x, int _y, int *_c)
Definition cga.c:842
int cga_image_size(Environment *_environment, int _width, int _height, int _mode)
Definition cga.c:1308
void cga_hscroll_screen(Environment *_environment, int _direction, int _overlap)
Definition cga.c:1296
void cga_cls_box(Environment *_environment, char *_x1, char *_y1, char *_w, char *_h)
Definition cga.c:1022
void cga_put_tile(Environment *_environment, char *_tile, char *_x, char *_y)
Definition cga.c:1648
void cga_slice_image_extract(Environment *_environment, char *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_destination)
Definition cga.c:1698
void cga_wait_vbl(Environment *_environment)
Definition cga.c:1549
void cga_tiles_get(Environment *_environment, char *_result)
Definition cga.c:1003
void cga_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition cga.c:1545
void cga_colors_vars(Environment *_environment, char *_foreground_color, char *_background_color)
Definition cga.c:1686
#define CGA_MODE_COLOR
Definition cga.c:128
void cga_hit(Environment *_environment, char *_sprite_mask, char *_result)
CGA: emit code to check for collision
Definition cga.c:193
void cga_scroll(Environment *_environment, int _dx, int _dy)
Definition cga.c:1644
void console_calculate(Environment *_environment)
Definition cga.c:754
void cga_background_color_semivars(Environment *_environment, int _index, char *_background_color)
CGA: emit code to change background color
Definition cga.c:268
void cga_screen(Environment *_environment, char *_x, char *_y, char *_c)
Definition cga.c:1724
#define TILEMAP_MODE_40x25x2
Definition cga.h:76
#define BITMAP_MODE_320x200x4
Definition cga.h:83
#define BITMAP_MODE_320x200x2
Definition cga.h:82
#define TILEMAP_MODE_80x25x16
Definition cga.h:79
#define TILEMAP_MODE_80x25x2
Definition cga.h:78
#define TILEMAP_MODE_40x25x16
Definition cga.h:77
#define BITMAP_MODE_640x200x2
Definition cga.h:84
void console_init(Environment *_environment)
Definition console.c:41
Variable * distance(Environment *_environment, char *_x1, char *_y1, char *_x2, char *_y2)
Return the distance between two (screen) positions.
Definition distance.c:76
int width
Definition ugbc.h:2209
int y1
Definition ugbc.h:2206
int x1
Definition ugbc.h:2205
int height
Definition ugbc.h:2210
char * name
Definition ugbc.h:2252
struct _CopperList * next
Definition ugbc.h:2255
int screenTilesWidth
Definition ugbc.h:2880
int screenShades
Definition ugbc.h:2865
int fontHeight
Definition ugbc.h:2905
Console activeConsole
Definition ugbc.h:2910
int freeImageWidth
Definition ugbc.h:3088
int currentMode
Definition ugbc.h:2696
int screenTilesHeight
Definition ugbc.h:2885
int consoleTilesHeight
Definition ugbc.h:2895
int fontWidth
Definition ugbc.h:2900
CopperList * copperList
Definition ugbc.h:3282
int paletteSelected
Definition ugbc.h:2975
int screenColors
Definition ugbc.h:2870
int dynamicConsole
Definition ugbc.h:3298
int currentModeBW
Definition ugbc.h:2701
int screenHeight
Definition ugbc.h:2860
int consoleTilesWidth
Definition ugbc.h:2890
int currentTileMode
Definition ugbc.h:2706
int screenTiles
Definition ugbc.h:2875
int screenWidth
Definition ugbc.h:2855
int defaultPaperColor
Definition ugbc.h:3226
int defaultPenColor
Definition ugbc.h:3225
VestigialConfig vestigialConfig
Definition ugbc.h:2442
unsigned char red
Definition ugbc.h:433
unsigned char green
Definition ugbc.h:434
unsigned char blue
Definition ugbc.h:435
unsigned char alpha
Definition ugbc.h:436
int selected
Definition ugbc.h:1510
unsigned char * valueBuffer
Definition ugbc.h:1061
int size
Definition ugbc.h:1077
char * name
Definition ugbc.h:979
int originalColors
Definition ugbc.h:1154
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
char clsImplicit
Definition ugbc.h:2008
void * malloc(YYSIZE_T)
struct _ScreenMode ScreenMode
#define CRITICAL_IMAGE_CONVERTER_TOO_COLORS(f)
Definition ugbc.h:3502
struct _Resource Resource
struct _RGBi RGBi
Structure to store color components (red, green and blue).
#define adilineendbitmap()
Definition ugbc.h:4241
#define WARNING_SCREEN_MODE(v1)
Definition ugbc.h:3878
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_BUFFER
Definition ugbc.h:477
@ VT_SPRITE
Definition ugbc.h:501
@ VT_SBYTE
Definition ugbc.h:452
@ VT_IMAGES
Definition ugbc.h:495
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_COLOR
Definition ugbc.h:471
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define adiline3(s, a, b, c)
Definition ugbc.h:4197
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#define SCREEN_MODE_DEFINE(_id, _bitmap, _width, _height, _colors, _tile_width, _tile_height, _description)
Definition ugbc.h:1516
#define MAX_PALETTE
Definition ugbc.h:568
#define CRITICAL_NEW_IMAGES_UNSUPPORTED_MODE(f)
Definition ugbc.h:3688
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253
#define WARNING_IMAGE_CONVERTER_UNSUPPORTED_MODE(f)
Definition ugbc.h:3880
#define adilinepalette(s, c, p)
Definition ugbc.h:4219
#define adilinebeginbitmap(s)
Definition ugbc.h:4231
struct _CopperList CopperList
#define FLAG_EXACT
Definition ugbc.h:4569
#define adilinepixel(p)
Definition ugbc.h:4236
#define CRITICAL_NEW_IMAGE_UNSUPPORTED_MODE(f)
Definition ugbc.h:3540
#define deploy(s, e)
Definition ugbc.h:4288
#define outhead1(s, a)
Definition ugbc.h:4247