OSDN Git Service

p16 is being worked on a bunch by me wwww [16_ca needs huge amounts of work and I...
[proj16/16.git] / src / lib / 16_vl.h
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 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/planar.h"\r
30 //#include "src/lib/modex16/16planar.h"\r
31 #include "src/lib/16text.h"\r
32 ////#include "src/lib/modex16/320x240.h"\r
33 // #include "src/lib/modex16/320x200.h"\r
34 // #include "src/lib/modex16/256x192.h"\r
35 // #include "src/lib/modex16/192x144_.h"\r
36 // #include "src/lib/modex16/160x120.h"\r
37 \r
38 //320x240 = 20x15\r
39 //192x144 = 12x9\r
40 \r
41 //temp defines\r
42 #define TILEWH  16\r
43 #define TILEWHD TILEWH*2\r
44 #define QUADWH                  TILEWH/2\r
45 \r
46 //#define OLDBGPRESERVE\r
47 \r
48 /* -========================== Types & Macros ==========================- */\r
49 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))\r
50 #define PLANE(x) (1 << ((x) & 3))\r
51 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)\r
52 \r
53 // clips for rectangles not on 4s\r
54 #define LRCLIPDEF \\r
55         static byte lclip[4] = {0x0f, 0x0e, 0x0c, 0x08}; \\r
56         static byte rclip[4] = {0x00, 0x01, 0x03, 0x07};\r
57 \r
58 #define VCLIPDEF \\r
59         static byte pclip[4] = {1,2,4,8};\r
60 \r
61 typedef union\r
62 {\r
63         byte red;\r
64         byte green;\r
65         byte blue;\r
66 } rgb_t;\r
67 \r
68 /* -======================= Constants & Vars ==========================- */\r
69 extern byte far*  VGA;  /* The VGA Memory */\r
70 #define SCREEN_SEG              0xa000\r
71 #define VIDEO_INT               0x10\r
72 #define SET_MODE                0x00\r
73 #define VGA_256_COLOR_MODE      0x13\r
74 #define TEXT_MODE               0x03\r
75 \r
76 #define SC_INDEX                0x03c4\r
77 #define SC_RESET                        0\r
78 #define SC_CLOCK                        1\r
79 #define SC_MAPMASK                      2\r
80 #define SC_CHARMAP                      3\r
81 #define SC_MEMMODE                      4\r
82 \r
83 #define CRTC_INDEX                      0x3D4\r
84 #define CRTC_H_TOTAL            0\r
85 #define CRTC_H_DISPEND          1\r
86 #define CRTC_H_BLANK            2\r
87 #define CRTC_H_ENDBLANK         3\r
88 #define CRTC_H_RETRACE          4\r
89 #define CRTC_H_ENDRETRACE       5\r
90 #define CRTC_V_TOTAL            6\r
91 #define CRTC_OVERFLOW           7\r
92 #define CRTC_ROWSCAN            8\r
93 #define CRTC_MAXSCANLINE        9\r
94 #define CRTC_CURSORSTART        10\r
95 #define CRTC_CURSOREND          11\r
96 #define CRTC_STARTHIGH          12\r
97 #define CRTC_STARTLOW           13\r
98 #define CRTC_CURSORHIGH         14\r
99 #define CRTC_CURSORLOW          15\r
100 #define CRTC_V_RETRACE          16\r
101 #define CRTC_V_ENDRETRACE       17\r
102 #define CRTC_V_DISPEND          18\r
103 #define CRTC_OFFSET                     19\r
104 #define CRTC_UNDERLINE          20\r
105 #define CRTC_V_BLANK            21\r
106 #define CRTC_V_ENDBLANK         22\r
107 #define CRTC_MODE                       23\r
108 #define CRTC_LINECOMPARE        24\r
109 \r
110 #define GC_INDEX                0x03ce\r
111 #define GC_SETRESET                     0\r
112 #define GC_ENABLESETRESET       1\r
113 #define GC_COLORCOMPARE         2\r
114 #define GC_DATAROTATE           3\r
115 #define GC_READMAP                      4\r
116 #define GC_MODE                         5\r
117 #define GC_MISCELLANEOUS        6\r
118 #define GC_COLORDONTCARE        7\r
119 #define GC_BITMASK                      8\r
120 \r
121 #define AC_INDEX                0x03c0\r
122 #define SC_DATA                 0x03c5\r
123 #define CRTC_DATA               0x03d5\r
124 #define MISC_OUTPUT             0x03c2\r
125 #define HIGH_ADDRESS            0x0C\r
126 #define LOW_ADDRESS             0x0D\r
127 #define VRETRACE                0x08\r
128 //#define INPUT_STATUS_1                0x03da  defined in 16_head\r
129 #define STATUS_REGISTER_1       INPUT_STATUS_1\r
130 #define ATR_INDEX                       AC_INDEX\r
131 #define ATR_OVERSCAN            17\r
132 #define DISPLAY_ENABLE          0x01\r
133 #define MAP_MASK                0x02\r
134 #define PAL_READ_REG                    0x03C7   /* Color register, read address */\r
135 #define PAL_WRITE_REG              0x03C8   /* Color register, write address */\r
136 #define PAL_DATA_REG                    0x03C9   /* Color register, data port */\r
137 #define PAL_SIZE                                (256 * 3)\r
138 \r
139 //===========================================================================\r
140 \r
141 #define SCREENSEG               0xa000\r
142 \r
143 //#define SCREENWIDTH           80                      // default screen width in bytes\r
144 //#define MAXSCANLINES  240                     // size of ylookup table\r
145 \r
146 //#define CHARWIDTH             2\r
147 //#define TILEWIDTH             4\r
148 \r
149 //===========================================================================\r
150 \r
151 //\r
152 // VGA hardware routines\r
153 //\r
154 \r
155 void VGAMAPMASK(byte x);\r
156 void VGAWRITEMODE(byte x);\r
157 void VGAREADMAP(byte x);\r
158 \r
159 #define VW_Hlin(x,z,y,c,q)      VL_Hlin(x,y,(z)-(x)+1,c,q)\r
160 #define VW_Vlin(y,z,x,c,q)      VL_Vlin(x,y,(z)-(y)+1,c,q)\r
161 \r
162 /* -============================ Functions =============================- */\r
163 /* mode switching, page, and plane functions */\r
164 void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv);\r
165 void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv);\r
166 byte vgaGetMode();\r
167 void modexLeave();\r
168 void VL_SetLineWidth (unsigned width, ofs_t *ofs);\r
169 void modexsetBaseXMode();\r
170 page_t modexDefaultPage(page_t *p);\r
171 page_t modexNextPage(page_t *p);\r
172 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);\r
173 void modexCalcVmemRemain(video_t *video);\r
174 void VL_Initofs(video_t *video);\r
175 void modexHiganbanaPageSetup(video_t *video);\r
176 //void modexShowPage(page_t *page);\r
177 void VL_ShowPage(page_t *page, boolean vsync, boolean sr);\r
178 void modexPanPage(page_t *page, int dx, int dy);\r
179 void modexSelectPlane(byte plane);\r
180 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);\r
181 /* moved to src/lib/modex16/16render.c */\r
182 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);\r
183 \r
184 /* Palette fade and flash effects */\r
185 void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v);\r
186 void modexFadeOn(word fade, byte *palette);\r
187 void modexFadeOff(word fade, byte *palette);\r
188 void modexFlashOn(word fade, byte *palette);\r
189 void modexFlashOff(word fade, byte *palette);\r
190 \r
191 /* palette loading and saving */\r
192 void modexPalSave(byte *palette);\r
193 //byte *modexNewPal();\r
194 void modexLoadPalFile(char *filename, byte *palette);\r
195 void VL_LoadPalFile(const char *filename, byte *palette);\r
196 void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o);\r
197 void VL_UpdatePaletteWrite(byte *palette, word o);\r
198 void modexSavePalFile(char *filename, byte *palette);\r
199 #define MenuFadeIn()    VL_FadeIn(0,255,&gamepal,10)\r
200 \r
201 /* fixed palette functions */\r
202 void modexPalBlack();\r
203 void modexPalWhite();\r
204 \r
205 /* utility functions */\r
206 void modexPalUpdate(byte *p);\r
207 void modexPalUpdate0(byte *p);\r
208 word modexPalOverscan(word col);\r
209 void VL_Plot (int x, int y, int color, ofs_t *ofs);\r
210 void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs);\r
211 void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs);\r
212 void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs);\r
213 void modexputPixel(page_t *page, int x, int y, byte color);\r
214 byte modexgetPixel(page_t *page, int x, int y);\r
215 \r
216 #if 0 // not needed anymore. maybe good for reference purposes though.\r
217 static inline void modexwritepixel(page_t *page, int x, int y, word addr, byte color)\r
218 {\r
219         /* Each address accesses four neighboring pixels, so set\r
220            Write Plane Enable according to which pixel we want\r
221            to modify.  The plane is determined by the two least\r
222            significant bits of the x-coordinate: */\r
223         modexSelectPlane(PLANE(x));\r
224         //outp(SC_INDEX, 0x02);\r
225         //outp(SC_DATA, 0x01 << (x & 3));\r
226 \r
227         /* The offset of the pixel into the video segment is\r
228            offset = (width * y + x) / 4, and write the given\r
229            color to the plane we selected above.  Heed the active\r
230            page start selection. */\r
231         vga_state.vga_graphics_ram[addr] = color;\r
232 }\r
233 static inline byte modexreadPixel(page_t *page, int x, int y, word addr)\r
234 {\r
235         /* Select the plane from which we must read the pixel color: */\r
236         outpw(GC_INDEX, 0x04);\r
237         outpw(GC_INDEX+1, x & 3);\r
238         return vga_state.vga_graphics_ram[addr];\r
239 }\r
240 #endif\r
241 \r
242 void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, word col, word bgcol, word addr);\r
243 void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, word bgcol, boolean sw, const byte *str);\r
244 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);\r
245 void modexpdump(page_t *pee);\r
246 void modexcls(page_t *page, byte color, byte *Where);\r
247 void VL_PatternDraw(video_t *video, word pn, boolean sw, boolean allsw);\r
248 void modexWaitBorder();\r
249 void modexWaitBorder_start();\r
250 void modexWaitBorder_end();\r
251 void VL_WaitVBL(word num);\r
252 void VL_PrintmodexmemInfo(video_t *v);\r
253 \r
254 #endif\r