1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
23 * Functions for handling modex and doing other basic graphics stuff.
28 #include "src/lib/16_head.h"
29 #include "src/lib/bitmap.h"
30 #include "src/lib/planar.h"
31 #include "src/lib/modex16/16planar.h"
32 #include "src/lib/16text.h"
33 #include "src/lib/modex16/16render.h"
34 #include "src/lib/modex16/320x240.h"
35 // #include "src/lib/modex16/320x200.h"
36 // #include "src/lib/modex16/256x192.h"
37 // #include "src/lib/modex16/192x144_.h"
38 // #include "src/lib/modex16/160x120.h"
40 #include <hw/cpu/cpu.h>
41 #include <hw/dos/dos.h>
42 #include <hw/vga/vga.h>
43 #include <hw/vga/vrl.h>
45 static struct pcxHeader {
70 #define TILEWHD TILEWH*2
71 #define QUADWH TILEWH/2
73 /* -========================== Types & Macros ==========================- */
74 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))
75 #define PLANE(x) (1 << ((x) & 3))
76 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)
86 /* -======================= Constants & Vars ==========================- */
87 extern byte far* VGA; /* The VGA Memory */
88 #define SCREEN_SEG 0xa000
89 #define VIDEO_INT 0x10
91 #define VGA_256_COLOR_MODE 0x13
92 #define TEXT_MODE 0x03
94 #define AC_INDEX 0x03c0
95 #define SC_INDEX 0x03c4
96 #define SC_DATA 0x03c5
97 #define CRTC_INDEX 0x03d4
98 #define CRTC_DATA 0x03d5
99 #define GC_INDEX 0x03ce
100 #define MISC_OUTPUT 0x03c2
101 #define HIGH_ADDRESS 0x0C
102 #define LOW_ADDRESS 0x0D
103 #define VRETRACE 0x08
104 //#define INPUT_STATUS_1 0x03da defined in 16_head
105 #define DISPLAY_ENABLE 0x01
106 #define MAP_MASK 0x02
107 #define PAL_READ_REG 0x03C7 /* Color register, read address */
108 #define PAL_WRITE_REG 0x03C8 /* Color register, write address */
109 #define PAL_DATA_REG 0x03C9 /* Color register, data port */
110 #define PAL_SIZE (256 * 3)
112 /* -============================ Functions =============================- */
113 /* mode switching, page, and plane functions */
114 void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv);
115 void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv);
118 void modexsetBaseXMode();
119 page_t modexDefaultPage(page_t *p);
120 page_t modexNextPage(page_t *p);
121 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);
122 void modexCalcVmemRemain(video_t *video);
123 void modexHiganbanaPageSetup(video_t *video);
124 void modexShowPage(page_t *page);
125 void modexPanPage(page_t *page, int dx, int dy);
126 void modexSelectPlane(byte plane);
127 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);
128 /* moved to src/lib/modex16/16render.c */
129 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
131 /* Palette fade and flash effects */
132 void modexFadeOn(word fade, byte *palette);
133 void modexFadeOff(word fade, byte *palette);
134 void modexFlashOn(word fade, byte *palette);
135 void modexFlashOff(word fade, byte *palette);
137 /* palette loading and saving */
138 void modexPalSave(byte *palette);
140 void modexLoadPalFile(char *filename, byte **palette);
141 void modexSavePalFile(char *filename, byte *palette);
143 /* fixed palette functions */
144 void modexPalBlack();
145 void modexPalWhite();
147 /* utility functions */
148 void modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset);
149 void modexPalUpdate1(byte *p);
150 void modexPalUpdate0(byte *p);
151 void modexPalOverscan(byte *p, word col);
152 void modexchkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/);
153 void modexputPixel(page_t *page, int x, int y, byte color);
154 byte modexgetPixel(page_t *page, int x, int y);
156 #if 0 // not needed anymore. maybe good for reference purposes though.
157 static inline void modexwritepixel(page_t *page, int x, int y, word addr, byte color)
159 /* Each address accesses four neighboring pixels, so set
160 Write Plane Enable according to which pixel we want
161 to modify. The plane is determined by the two least
162 significant bits of the x-coordinate: */
163 modexSelectPlane(PLANE(x));
164 //outp(SC_INDEX, 0x02);
165 //outp(SC_DATA, 0x01 << (x & 3));
167 /* The offset of the pixel into the video segment is
168 offset = (width * y + x) / 4, and write the given
169 color to the plane we selected above. Heed the active
170 page start selection. */
171 vga_state.vga_graphics_ram[addr] = color;
173 static inline byte modexreadPixel(page_t *page, int x, int y, word addr)
175 /* Select the plane from which we must read the pixel color: */
176 outpw(GC_INDEX, 0x04);
177 outpw(GC_INDEX+1, x & 3);
178 return vga_state.vga_graphics_ram[addr];
182 void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
183 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
184 void modexpdump(page_t *pee);
185 void modexcls(page_t *page, byte color, byte *Where);
186 void modexWaitBorder();