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"
40 #define QUADWH TILEWH/2
42 /* -========================== Types & Macros ==========================- */
43 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))
44 #define PLANE(x) (1<< (x&3))
45 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)
48 word id; /* the Identification number of the page~ For layering~ */
49 byte far* data; /* the data for the page */
50 word dx; /* col we are viewing on the virtual screen */
51 word dy; /* row we are viewing on the virtual screen */
52 word width; /* virtual width of the page */
53 word height; /* virtual height of the page */
65 /* -============================ Functions =============================- */
66 /* mode switching, page, and plane functions */
67 void VGAmodeX(sword vq, global_game_variables_t *gv);
70 page_t modexDefaultPage();
71 page_t modexNextPage(page_t *p);
72 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);
73 void modexShowPage(page_t *page);
74 void modexPanPage(page_t *page, int dx, int dy);
75 void modexSelectPlane(byte plane);
76 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);
77 void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite);
78 //void CDrawBmp(byte far* vgamem, page_t* page, int x, int y, bitmap_t *bmp, byte sprite);
79 void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp);
80 void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);
81 void modex_sparky4_DrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);
82 void modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp);
83 void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp);
84 void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);
85 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
87 /* Palette fade and flash effects */
88 void modexFadeOn(word fade, byte *palette);
89 void modexFadeOff(word fade, byte *palette);
90 void modexFlashOn(word fade, byte *palette);
91 void modexFlashOff(word fade, byte *palette);
93 /* palette loading and saving */
94 void modexPalSave(byte *palette);
96 void modexLoadPalFile(char *filename, byte **palette);
97 void modexSavePalFile(char *filename, byte *palette);
99 /* fixed palette functions */
100 void modexPalBlack();
101 void modexPalWhite();
103 /* utility functions */
104 void modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset);
105 void modexPalUpdate1(byte *p);
106 void modexPalUpdate0(byte *p);
107 void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/);
108 void modexputPixel(page_t *page, int x, int y, byte color);
109 byte modexgetPixel(page_t *page, int x, int y);
110 void modexhlin(page_t *page, word xl, word xh, word y, word color);
111 void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
112 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
113 void cls(page_t *page, byte color, byte *Where);
114 void modexWaitBorder();
116 /* -======================= Constants & Vars ==========================- */
117 extern byte far* VGA; /* The VGA Memory */
119 #define SCREEN_SEG 0xa000
120 #define VIDEO_INT 0x10
121 #define SET_MODE 0x00
122 #define VGA_256_COLOR_MODE 0x13
123 #define TEXT_MODE 0x03
124 #define SCREEN_WIDTH 320
125 #define SCREEN_HEIGHT 240
126 #define PAGE_SIZE (word)(SCREEN_WIDTH/4 * SCREEN_HEIGHT)
128 #define AC_INDEX 0x03c0
129 #define SC_INDEX 0x03c4
130 #define SC_DATA 0x03c5
131 #define CRTC_INDEX 0x03d4
132 #define CRTC_DATA 0x03d5
133 #define GC_INDEX 0x03ce
134 #define MISC_OUTPUT 0x03c2
135 #define HIGH_ADDRESS 0x0C
136 #define LOW_ADDRESS 0x0D
137 #define VRETRACE 0x08
138 #define INPUT_STATUS_1 0x03da
139 #define DISPLAY_ENABLE 0x01
140 #define MAP_MASK 0x02
141 #define PAL_READ_REG 0x03C7 /* Color register, read address */
142 #define PAL_WRITE_REG 0x03C8 /* Color register, write address */
143 #define PAL_DATA_REG 0x03C9 /* Color register, data port */
144 #define PAL_SIZE (256 * 3)