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