OSDN Git Service

-- reverted to before layer vars
[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/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/modex16/320x240.h"\r
34 // #include "src/lib/modex16/320x200.h"\r
35 // #include "src/lib/modex16/256x192.h"\r
36 // #include "src/lib/modex16/192x144_.h"\r
37 // #include "src/lib/modex16/160x120.h"\r
38 \r
39 #ifdef __WATCOMC__\r
40 #include <hw/cpu/cpu.h>\r
41 #include <hw/dos/dos.h>\r
42 #include <hw/vga/vga.h>\r
43 #include <hw/vga/vrl.h>\r
44 #include <hw/vga/vrs.h>\r
45 #endif\r
46 \r
47 //320x240 = 20x15\r
48 //192x144 = 12x9\r
49 \r
50 //temp defines\r
51 #define TILEWH  16\r
52 #define TILEWHD TILEWH*2\r
53 #define QUADWH                  TILEWH/2\r
54 \r
55 //#define OLDBGPRESERVE\r
56 \r
57 /* -========================== Types & Macros ==========================- */\r
58 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))\r
59 #define PLANE(x) (1 << ((x) & 3))\r
60 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)\r
61 #define     PALSIZE            768\r
62 \r
63 typedef union\r
64 {\r
65         byte red;\r
66         byte green;\r
67         byte blue;\r
68 } rgb_t;\r
69 \r
70 /* -======================= Constants & Vars ==========================- */\r
71 extern byte far*  VGA;  /* The VGA Memory */\r
72 #define SCREEN_SEG              0xa000\r
73 #define VIDEO_INT               0x10\r
74 #define SET_MODE                0x00\r
75 #define VGA_256_COLOR_MODE      0x13\r
76 #define TEXT_MODE               0x03\r
77 \r
78 #define AC_INDEX                0x03c0\r
79 #define SC_INDEX                0x03c4\r
80 #define SC_DATA                 0x03c5\r
81 #define CRTC_INDEX              0x03d4\r
82 #define CRTC_DATA               0x03d5\r
83 #define GC_INDEX                0x03ce\r
84 #define MISC_OUTPUT             0x03c2\r
85 #define HIGH_ADDRESS            0x0C\r
86 #define LOW_ADDRESS             0x0D\r
87 #define VRETRACE                0x08\r
88 //#define INPUT_STATUS_1                0x03da  defined in 16_head\r
89 #define DISPLAY_ENABLE          0x01\r
90 #define MAP_MASK                0x02\r
91 #define PAL_READ_REG                    0x03C7   /* Color register, read address */\r
92 #define PAL_WRITE_REG              0x03C8   /* Color register, write address */\r
93 #define PAL_DATA_REG                    0x03C9   /* Color register, data port */\r
94 #define PAL_SIZE                                (256 * 3)\r
95 \r
96 /* -============================ Functions =============================- */\r
97 /* mode switching, page, and plane functions */\r
98 void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv);\r
99 void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv);\r
100 byte vgaGetMode();\r
101 void modexLeave();\r
102 void modexsetBaseXMode();\r
103 page_t modexDefaultPage(page_t *p);\r
104 page_t modexNextPage(page_t *p);\r
105 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);\r
106 void modexCalcVmemRemain(video_t *video);\r
107 void VL_Initofs(video_t *video);\r
108 void modexHiganbanaPageSetup(video_t *video);\r
109 //void modexShowPage(page_t *page);\r
110 void VL_ShowPage(page_t *page, boolean vsync, boolean sr);\r
111 void modexPanPage(page_t *page, int dx, int dy);\r
112 void modexSelectPlane(byte plane);\r
113 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);\r
114 /* moved to src/lib/modex16/16render.c */\r
115 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);\r
116 \r
117 /* Palette fade and flash effects */\r
118 void modexFadeOn(word fade, byte *palette);\r
119 void modexFadeOff(word fade, byte *palette);\r
120 void modexFlashOn(word fade, byte *palette);\r
121 void modexFlashOff(word fade, byte *palette);\r
122 \r
123 /* palette loading and saving */\r
124 void modexPalSave(byte *palette);\r
125 byte *modexNewPal();\r
126 void modexLoadPalFile(char *filename, byte **palette);\r
127 void VL_LoadPalFile(const char *filename, byte *palette);\r
128 void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o);\r
129 void modexSavePalFile(char *filename, byte *palette);\r
130 \r
131 /* fixed palette functions */\r
132 void modexPalBlack();\r
133 void modexPalWhite();\r
134 \r
135 /* utility functions */\r
136 void modexPalUpdate(byte *p);\r
137 void modexPalUpdate0(byte *p);\r
138 void modexPalOverscan(word col);\r
139 void modexputPixel(page_t *page, int x, int y, byte color);\r
140 byte modexgetPixel(page_t *page, int x, int y);\r
141 \r
142 #if 0 // not needed anymore. maybe good for reference purposes though.\r
143 static inline void modexwritepixel(page_t *page, int x, int y, word addr, byte color)\r
144 {\r
145         /* Each address accesses four neighboring pixels, so set\r
146            Write Plane Enable according to which pixel we want\r
147            to modify.  The plane is determined by the two least\r
148            significant bits of the x-coordinate: */\r
149         modexSelectPlane(PLANE(x));\r
150         //outp(SC_INDEX, 0x02);\r
151         //outp(SC_DATA, 0x01 << (x & 3));\r
152 \r
153         /* The offset of the pixel into the video segment is\r
154            offset = (width * y + x) / 4, and write the given\r
155            color to the plane we selected above.  Heed the active\r
156            page start selection. */\r
157         vga_state.vga_graphics_ram[addr] = color;\r
158 }\r
159 static inline byte modexreadPixel(page_t *page, int x, int y, word addr)\r
160 {\r
161         /* Select the plane from which we must read the pixel color: */\r
162         outpw(GC_INDEX, 0x04);\r
163         outpw(GC_INDEX+1, x & 3);\r
164         return vga_state.vga_graphics_ram[addr];\r
165 }\r
166 #endif\r
167 \r
168 void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, word col, word bgcol, word addr);\r
169 void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);\r
170 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);\r
171 void modexpdump(page_t *pee);\r
172 void modexcls(page_t *page, byte color, byte *Where);\r
173 void VL_PatternDraw(video_t *video, word pn, boolean sw, boolean allsw);\r
174 void modexWaitBorder();\r
175 void modexWaitBorder_start();\r
176 void modexWaitBorder_end();\r
177 void VL_PrintmodexmemInfo(video_t *v);\r
178 \r
179 #endif\r