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