1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2015 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.
29 #include "src/lib/types.h"
30 #include "src/lib/bitmap.h"
31 #include "src/lib/planar.h"
32 #include "src/lib/16_head.h"
33 #include "src/lib/16text.h"
34 #include "src/lib/modex16/16render.h"
35 #include "src/lib/modex16/320x240.h"
36 #include "src/lib/modex16/320x200.h"
37 #include "src/lib/modex16/256x192.h"
38 #include "src/lib/modex16/192x144_.h"
39 #include "src/lib/modex16/160x120.h"
46 #define QUADWH TILEWH/2
48 /* -========================== Types & Macros ==========================- */
49 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))
50 #define PLANE(x) (1<< (x&3))
51 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)
60 /* -============================ Functions =============================- */
61 /* mode switching, page, and plane functions */
62 void VGAmodeX(sword vq, global_game_variables_t *gv);
63 void modexEnter(sword vq, global_game_variables_t *gv);
66 void modexsetBaseXMode(page_t *page);
67 page_t modexDefaultPage(page_t *p);
68 page_t modexNextPage(page_t *p);
69 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);
70 void modexShowPage(page_t *page);
71 void modexPanPage(page_t *page, int dx, int dy);
72 void modexSelectPlane(byte plane);
73 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);
74 /* moved to src/lib/modex16/16render.c */
75 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
77 /* Palette fade and flash effects */
78 void modexFadeOn(word fade, byte *palette);
79 void modexFadeOff(word fade, byte *palette);
80 void modexFlashOn(word fade, byte *palette);
81 void modexFlashOff(word fade, byte *palette);
83 /* palette loading and saving */
84 void modexPalSave(byte *palette);
86 void modexLoadPalFile(char *filename, byte **palette);
87 void modexSavePalFile(char *filename, byte *palette);
89 /* fixed palette functions */
93 /* utility functions */
94 void modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset);
95 void modexPalUpdate1(byte *p);
96 void modexPalUpdate0(byte *p);
97 void modexPalOverscan(byte *p, word col);
98 void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/);
99 void modexputPixel(page_t *page, int x, int y, byte color);
100 byte modexgetPixel(page_t *page, int x, int y);
101 void modexhlin(page_t *page, word xl, word xh, word y, word color);
102 void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
103 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
104 void pdump(page_t *pee);
105 void cls(page_t *page, byte color, byte *Where);
106 void modexWaitBorder();
108 /* -======================= Constants & Vars ==========================- */
109 extern byte far* VGA; /* The VGA Memory */
110 //extern int old_mode;
111 #define SCREEN_SEG 0xa000
112 #define VIDEO_INT 0x10
113 #define SET_MODE 0x00
114 #define VGA_256_COLOR_MODE 0x13
115 #define TEXT_MODE 0x03
116 //#define SCREEN_WIDTH 320
117 //#define SCREEN_HEIGHT 240
118 //#define PAGE_SIZE (word)(SCREEN_WIDTH/4 * SCREEN_HEIGHT)
120 #define AC_INDEX 0x03c0
121 #define SC_INDEX 0x03c4
122 #define SC_DATA 0x03c5
123 #define CRTC_INDEX 0x03d4
124 #define CRTC_DATA 0x03d5
125 #define GC_INDEX 0x03ce
126 #define MISC_OUTPUT 0x03c2
127 #define HIGH_ADDRESS 0x0C
128 #define LOW_ADDRESS 0x0D
129 #define VRETRACE 0x08
130 #define INPUT_STATUS_1 0x03da
131 #define DISPLAY_ENABLE 0x01
132 #define MAP_MASK 0x02
133 #define PAL_READ_REG 0x03C7 /* Color register, read address */
134 #define PAL_WRITE_REG 0x03C8 /* Color register, write address */
135 #define PAL_DATA_REG 0x03C9 /* Color register, data port */
136 #define PAL_SIZE (256 * 3)