]> 4ch.mooo.com Git - 16.git/blob - src/lib/modex16.h
going to fix it but lower resolution system is implemented!! ^^;
[16.git] / src / lib / modex16.h
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 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 //#include <conio.h>
28
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"
34 #include "src/lib/modex16/320x240.h"
35 #include "src/lib/modex16/256x192.h"
36
37 //320x240 = 20x15
38 //256x192 = 16x12
39
40 //temp defines
41 #define TILEWH 16
42 #define QUADWH                  TILEWH/2
43
44 /* -========================== Types & Macros ==========================- */
45 #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2))
46 #define PLANE(x) (1<< (x&3))
47 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)
48
49 typedef struct {
50         word id;        /* the Identification number of the page~ For layering~ */
51         byte far* data; /* the data for the page */
52         word dx;                /* col we are viewing on the virtual screen */
53         word dy;                /* row we are viewing on the virtual screen */
54         word width;             /* virtual width of the page */
55         word height;    /* virtual height of the page */
56         word tw;
57         word th;
58 } page_t;
59
60 typedef union
61 {
62         byte red;
63         byte green;
64         byte blue;
65 } rgb_t;
66
67 /* -============================ Functions =============================- */
68 /* mode switching, page, and plane functions */
69 void VGAmodeX(sword vq, global_game_variables_t *gv);
70 void modex__320x240_256__Enter(global_game_variables_t *gv);
71 void modex__256x192_256__Enter(global_game_variables_t *gv);
72 void modexLeave();
73 void modexsetBaseXMode(void);
74 page_t modexDefaultPage();
75 page_t modexNextPage(page_t *p);
76 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);
77 void modexShowPage(page_t *page);
78 void modexPanPage(page_t *page, int dx, int dy);
79 void modexSelectPlane(byte plane);
80 void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color);
81 void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite);
82 //void CDrawBmp(byte far* vgamem, page_t* page, int x, int y, bitmap_t *bmp, byte sprite);
83 void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp);
84 void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);
85 void modex_sparky4_DrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);
86 void modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp);
87 void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp);
88 void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);
89 void modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
90
91 /* Palette fade and flash effects */
92 void modexFadeOn(word fade, byte *palette);
93 void modexFadeOff(word fade, byte *palette);
94 void modexFlashOn(word fade, byte *palette);
95 void modexFlashOff(word fade, byte *palette);
96
97 /* palette loading and saving */
98 void modexPalSave(byte *palette);
99 byte *modexNewPal();
100 void modexLoadPalFile(char *filename, byte **palette);
101 void modexSavePalFile(char *filename, byte *palette);
102
103 /* fixed palette functions */
104 void modexPalBlack();
105 void modexPalWhite();
106
107 /* utility functions */
108 void modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset);
109 void modexPalUpdate1(byte *p);
110 void modexPalUpdate0(byte *p);
111 void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/);
112 void modexputPixel(page_t *page, int x, int y, byte color);
113 byte modexgetPixel(page_t *page, int x, int y);
114 void modexhlin(page_t *page, word xl, word xh, word y, word color);
115 void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
116 void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str);
117 void cls(page_t *page, byte color, byte *Where);
118 void modexWaitBorder();
119
120 /* -======================= Constants & Vars ==========================- */
121 extern byte far*  VGA;  /* The VGA Memory */
122 //extern int old_mode;
123 #define SCREEN_SEG              0xa000
124 #define VIDEO_INT               0x10
125 #define SET_MODE                0x00
126 #define VGA_256_COLOR_MODE      0x13
127 #define TEXT_MODE               0x03
128 #define SCREEN_WIDTH            320
129 #define SCREEN_HEIGHT           240
130 #define PAGE_SIZE               (word)(SCREEN_WIDTH/4 * SCREEN_HEIGHT)
131
132 #define AC_INDEX                0x03c0
133 #define SC_INDEX                0x03c4
134 #define SC_DATA                 0x03c5
135 #define CRTC_INDEX              0x03d4
136 #define CRTC_DATA               0x03d5
137 #define GC_INDEX                0x03ce
138 #define MISC_OUTPUT             0x03c2
139 #define HIGH_ADDRESS            0x0C
140 #define LOW_ADDRESS             0x0D
141 #define VRETRACE                0x08
142 #define INPUT_STATUS_1          0x03da
143 #define DISPLAY_ENABLE          0x01
144 #define MAP_MASK                0x02
145 #define PAL_READ_REG                    0x03C7   /* Color register, read address */
146 #define PAL_WRITE_REG              0x03C8   /* Color register, write address */
147 #define PAL_DATA_REG                    0x03C9   /* Color register, data port */
148 #define PAL_SIZE                                (256 * 3)
149 #endif