]> 4ch.mooo.com Git - 16.git/blob - src/lib/modex16.h
cleaned up the repo from debugging watcom2 ^^
[16.git] / src / lib / modex16.h
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669
3  *
4  * This file is part of Project 16.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 /*
23  * Functions for handling modex and doing other basic graphics stuff.
24  */
25 #ifndef MODEX16_H
26 #define MODEX16_H
27
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"
39
40 #ifdef __WATCOMC__
41 #include <hw/cpu/cpu.h>
42 #include <hw/dos/dos.h>
43 #include <hw/vga/vga.h>
44 #include <hw/vga/vrl.h>
45 #endif
46
47 static struct pcxHeader {
48         byte id;
49         byte version;
50         byte encoding;
51         byte bpp;
52         word xmin;
53         word ymin;
54         word xmax;
55         word ymax;
56         word hres;
57         word vres;
58         byte pal16[48];
59         byte res1;
60         word bpplane;
61         word palType;
62         word hScreenSize;
63         word vScreenSize;
64         byte padding[54];
65 } head;
66
67 //320x240 = 20x15
68 //192x144 = 12x9
69
70 //temp defines
71 #define TILEWH  16
72 #define TILEWHD TILEWH*2
73 #define QUADWH                  TILEWH/2
74
75 /* -========================== Types & Macros ==========================- */
76 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))
77 #define PLANE(x) (1 << ((x) & 3))
78 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)
79 #define     PALSIZE            768
80
81 typedef union
82 {
83         byte red;
84         byte green;
85         byte blue;
86 } rgb_t;
87
88 /* -======================= Constants & Vars ==========================- */
89 extern byte far*  VGA;  /* The VGA Memory */
90 #define SCREEN_SEG              0xa000
91 #define VIDEO_INT               0x10
92 #define SET_MODE                0x00
93 #define VGA_256_COLOR_MODE      0x13
94 #define TEXT_MODE               0x03
95
96 #define AC_INDEX                0x03c0
97 #define SC_INDEX                0x03c4
98 #define SC_DATA                 0x03c5
99 #define CRTC_INDEX              0x03d4
100 #define CRTC_DATA               0x03d5
101 #define GC_INDEX                0x03ce
102 #define MISC_OUTPUT             0x03c2
103 #define HIGH_ADDRESS            0x0C
104 #define LOW_ADDRESS             0x0D
105 #define VRETRACE                0x08
106 //#define INPUT_STATUS_1                0x03da  defined in 16_head
107 #define DISPLAY_ENABLE          0x01
108 #define MAP_MASK                0x02
109 #define PAL_READ_REG                    0x03C7   /* Color register, read address */
110 #define PAL_WRITE_REG              0x03C8   /* Color register, write address */
111 #define PAL_DATA_REG                    0x03C9   /* Color register, data port */
112 #define PAL_SIZE                                (256 * 3)
113
114 /* -============================ Functions =============================- */
115 /* mode switching, page, and plane functions */
116 void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv);
117 void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv);
118 byte vgaGetMode();
119 void modexLeave();
120 void modexsetBaseXMode();
121 page_t modexDefaultPage(page_t *p);
122 page_t modexNextPage(page_t *p);
123 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);
124 void modexCalcVmemRemain(video_t *video);
125 void modexHiganbanaPageSetup(video_t *video);
126 void modexShowPage(page_t *page);
127 void modexPanPage(page_t *page, int dx, int dy);
128 void modexSelectPlane(byte plane);
129 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);
130 /* moved to src/lib/modex16/16render.c */
131 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
132
133 /* Palette fade and flash effects */
134 void modexFadeOn(word fade, byte *palette);
135 void modexFadeOff(word fade, byte *palette);
136 void modexFlashOn(word fade, byte *palette);
137 void modexFlashOff(word fade, byte *palette);
138
139 /* palette loading and saving */
140 void modexPalSave(byte *palette);
141 byte *modexNewPal();
142 void modexLoadPalFile(char *filename, byte **palette);
143 void modexSavePalFile(char *filename, byte *palette);
144
145 /* fixed palette functions */
146 void modexPalBlack();
147 void modexPalWhite();
148
149 /* utility functions */
150 void modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset);
151 void modexPalUpdate1(byte *p);
152 void modexPalUpdate0(byte *p);
153 void modexPalOverscan(word col);
154 void modexchkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/);
155 void modexputPixel(page_t *page, int x, int y, byte color);
156 byte modexgetPixel(page_t *page, int x, int y);
157
158 #if 0 // not needed anymore. maybe good for reference purposes though.
159 static inline void modexwritepixel(page_t *page, int x, int y, word addr, byte color)
160 {
161         /* Each address accesses four neighboring pixels, so set
162            Write Plane Enable according to which pixel we want
163            to modify.  The plane is determined by the two least
164            significant bits of the x-coordinate: */
165         modexSelectPlane(PLANE(x));
166         //outp(SC_INDEX, 0x02);
167         //outp(SC_DATA, 0x01 << (x & 3));
168
169         /* The offset of the pixel into the video segment is
170            offset = (width * y + x) / 4, and write the given
171            color to the plane we selected above.  Heed the active
172            page start selection. */
173         vga_state.vga_graphics_ram[addr] = color;
174 }
175 static inline byte modexreadPixel(page_t *page, int x, int y, word addr)
176 {
177         /* Select the plane from which we must read the pixel color: */
178         outpw(GC_INDEX, 0x04);
179         outpw(GC_INDEX+1, x & 3);
180         return vga_state.vga_graphics_ram[addr];
181 }
182 #endif
183
184 void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
185 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
186 void modexpdump(page_t *pee);
187 void modexcls(page_t *page, byte color, byte *Where);
188 void modexWaitBorder();
189 void modexprintmeminfo(video_t *v);
190
191 #endif