]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_tdef.h
it is semi working the bg preservation wwww
[16.git] / src / lib / 16_tdef.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 #ifndef _TYPEDEFSTRUCT_H_\r
24 #define _TYPEDEFSTRUCT_H_\r
25 \r
26 #include "src/lib/16_t.h"\r
27 \r
28 #define AARED           "\x1b[41;31m"\r
29 #define AABLUE          "\x1b[44;34m"\r
30 #define AAGREEN "\x1b[42;32m"\r
31 #define AAYELLOW        "\x1b[43;33m"\r
32 #define AAGREY          "\x1b[47;37m"\r
33 #define AABLACK "\x1b[40;30m"\r
34 #define AAWHITE         "\x1b[47;37m"\r
35 #define AAMAGENTA       "\x1b[45;35m"\r
36 #define AARESET "\x1b[0m"\r
37 \r
38 #define MAXPAGE 4\r
39 \r
40 /*\r
41  * typedefs of the game variables!\r
42  */\r
43 typedef struct {\r
44         byte *data;\r
45         word width;\r
46         word height;\r
47         byte *palette;\r
48         word offset;\r
49 } bitmap_t;\r
50 \r
51 typedef struct {\r
52         byte far **data;\r
53         word ntiles;   /* the number of tiles */\r
54         word twidth;   /* width of the tiles */\r
55         word theight;  /* height of the tiles */\r
56         byte *palette; /* palette for the tile set */\r
57 } tileset_t;\r
58 \r
59 typedef struct {\r
60         byte far *plane[4];     // 4 planes of image data\r
61         word width;                     // width of the image (spread across 4 planes)\r
62         word height;            // height of the image (spread across 4 planes)\r
63         word pwidth;            // the number of bytes in each plane\r
64         byte *palette;\r
65 } planar_buf_t;\r
66 \r
67 //TODO: 16_mm and 16_ca must handle this\r
68 typedef struct {\r
69         bitmap_t far *btdata;           //old\r
70         planar_buf_t far *data; //old\r
71         word tileHeight, tileWidth;\r
72         unsigned int rows, cols;\r
73 //      #ifdef __DEBUG__\r
74 //      boolean debug_text;     //show the value of the tile! wwww\r
75 //      byte *debug_data;\r
76 //      #endif\r
77 } tiles_t;\r
78 \r
79 //TODO: 16_mm and 16_ca must handle this\r
80 //TODO: add variables from 16_ca\r
81 typedef struct {\r
82         //long          planestart[3];\r
83         //unsigned      planelength[3];\r
84         byte *data;                     //TODO: 16_mm and 16_ca must handle this\r
85         byte * far *layerdata;  //TODO: 16_mm and 16_ca must handle this\r
86         tiles_t *tiles;         //TODO: 16_mm and 16_ca must handle this\r
87         tiles_t * far *layertile;       //TODO: 16_mm and 16_ca must handle this\r
88         int width, height;              //this has to be signed!\r
89         char            name[16];\r
90 } map_t;\r
91 \r
92 //TODO USE THIS tile info\r
93 typedef struct{\r
94         word tw;                /* screen width in tiles */\r
95         word th;                /* screen height in tiles */\r
96         word tilesw;            /* virtual screen width in tiles */\r
97         word tilesh;            /* virtual screen height in tiles */\r
98         sword tilemidposscreenx;        /* middle tile x position */    /* needed for scroll system to work accordingly */\r
99         sword tilemidposscreeny;        /* middle tile y position */    /* needed for scroll system to work accordingly */\r
100         sword tileplayerposscreenx;     /* player position on screen */ /* needed for scroll and map system to work accordingly */\r
101         sword tileplayerposscreeny;     /* player position on screen */ /* needed for scroll and map system to work accordingly */\r
102 } tileinfo_t;\r
103 \r
104 typedef struct {\r
105         nibble/*word*/ id;      /* the Identification number of the page~ For layering~ */\r
106         byte far* data; /* the data for the page */\r
107         tileinfo_t      ti;\r
108         word dx;                /* col we are viewing on virtual screen (on page[0]) */ /* off screen buffer on the left size */\r
109         word dy;                /* row we are viewing on virtual screen (on page[0]) */ /* off screen buffer on the top size */\r
110         word sw;                /* screen width */      /* resolution */\r
111         word sh;                /* screen heigth */     /* resolution */\r
112         word width;             /* virtual width of the page */\r
113         word height;    /* virtual height of the page */\r
114         word stridew;                   /* width/4 */   /* VGA */\r
115         word pagesize;                  /* page size */\r
116         word pi;                                /* increment page by this much to preserve location */\r
117 //newer vars\r
118 //TODO: find where they are used\r
119         sword delta;                    // How much should we shift the page for smooth scrolling\r
120 } page_t;\r
121 \r
122 //newer structs\r
123 typedef struct\r
124 {\r
125         int x; //entity exact position on the viewable map\r
126         int y; //entity exact position on the viewable map\r
127         int tx; //entity tile position on the viewable map\r
128         int ty; //entity tile position on the viewable map\r
129         int triggerx; //entity's trigger box tile position on the viewable map\r
130         int triggery; //entity's trigger box tile position on the viewable map\r
131         int sheetsetx; //NOT USED YET! entity sprite sheet set on the image x\r
132         int sheetsety; //NOT USED YET! entity sprite sheet set on the image y\r
133         nibble d;               //direction to render sprite!! wwww\r
134         nibble pred;    //prev. direction for animation changing\r
135         word dire;              //sprite in use\r
136         nibble q;               //loop variable for anumation and locking the playing to compleate the animation cycle to prevent issues with misalignment www\r
137         word speed;             //entity speed!\r
138         word spt;               //speed per tile\r
139         struct sprite *spri; // sprite used by entity\r
140         sword hp; //hitpoints of the entity\r
141         nibble overdraww, overdrawh;    // how many pixels to "overdraw" so that moving sprites with edge pixels don't leave streaks.\r
142                                                 // if the sprite's edge pixels are clear anyway, you can set this to 0.\r
143         nibble /*int*/ persist_aniframe;    // gonna be increased to 1 before being used, so 0 is ok for default\r
144 } entity_t;\r
145 \r
146 //TODO: MAKE THIS WWWW\r
147 typedef struct\r
148 {\r
149         //sprite ....\r
150         boolean wwww;\r
151 } spri_t;\r
152 \r
153 //TODO: MAKE THIS TO WWWW\r
154 typedef struct\r
155 {\r
156         //vrs with sprite ....\r
157         spri_t *spri;\r
158 } vrs_t;\r
159 \r
160 //from 16_in\r
161 //==========================================================================\r
162 typedef byte            ScanCode;\r
163 \r
164 typedef enum            {\r
165                                                 //ctrl_None,                            // MDM (GAMERS EDGE) - added\r
166                                                 ctrl_Keyboard,\r
167                                                         ctrl_Keyboard1 = ctrl_Keyboard,ctrl_Keyboard2,\r
168                                                 ctrl_Joystick,\r
169                                                         ctrl_Joystick1 = ctrl_Joystick,ctrl_Joystick2,\r
170                                                 ctrl_Mouse,\r
171                                         } ControlType;\r
172 typedef enum            {\r
173                                                 motion_Left = -1,motion_Up = -1,\r
174                                                 motion_None = 0,\r
175                                                 motion_Right = 1,motion_Down = 1\r
176                                         } Motion;\r
177 typedef enum            {\r
178                                                 dir_North,//dir_NorthEast,\r
179                                                 dir_West,//dir_Nortinest,\r
180                                                 dir_None,\r
181                                                 dir_East,//,dir_SouthEast,\r
182                                                 dir_South,//dir_Soutinest,\r
183                                         } Direction;\r
184 typedef struct          {\r
185                                                 boolean near    button0,button1,button2,button3;\r
186                                                 int     near            x,y;\r
187                                                 Motion  near    xaxis,yaxis;\r
188                                                 Direction near  dir;\r
189                                         } CursorInfo;\r
190 \r
191 typedef struct          {\r
192                                                 ScanCode near   button0,button1,\r
193                                                                         //upleft,\r
194                                                                         up,\r
195                                                                         down,\r
196                                                                         left,\r
197                                                                         right\r
198                                                                         //upright,\r
199                                                                         //downleft,\r
200                                                                         //,downright\r
201                                                                         ;\r
202                                         } KeyboardDef;\r
203 typedef struct          {\r
204                                                 word    near    joyMinX,joyMinY,\r
205                                                                         threshMinX,threshMinY,\r
206                                                                         threshMaxX,threshMaxY,\r
207                                                                         joyMaxX,joyMaxY,\r
208                                                                         joyMultXL,joyMultYL,\r
209                                                                         joyMultXH,joyMultYH;\r
210                                         } JoystickDef;\r
211 \r
212 //==========================================================================\r
213 \r
214 typedef struct\r
215 {\r
216         entity_t near   enti;\r
217 #ifdef  __WATCOMC__\r
218         //struct sprite *spri;  //supposively the sprite sheet data\r
219         memptr          gr;\r
220 #endif\r
221         bitmap_t        *data;          //supposively the sprite sheet data//old format\r
222         bitmap_t        bmp;\r
223 \r
224         //input\r
225         byte near               pdir;   //previous direction~ used in IN_16 in IN_ReadControl()\r
226         CursorInfo              info;\r
227         ControlType     Controls;\r
228         word walktype;\r
229 //newer vars\r
230         int dx, dy, delta;      //TODO: what is this? ^^\r
231 } player_t;\r
232 \r
233 //===========================================//\r
234 \r
235 typedef struct\r
236 {\r
237         int profilehandle,debughandle,showmemhandle;\r
238         int heaphandle;\r
239 } loghandle_t;\r
240 \r
241 typedef struct\r
242 {\r
243         word frames_per_second;\r
244         clock_t t;\r
245         dword tiku;             //frames passed\r
246         word clock_start;       //timer start\r
247         word *clock;    //current time on clock\r
248         boolean fpscap; //cap the fps var\r
249 } kurokku_t;\r
250 \r
251 //video\r
252 typedef struct\r
253 {\r
254         unsigned int offscreen_ofs;\r
255         unsigned int pattern_ofs;\r
256 } ofs_t;\r
257 #define NUMCHUNKS       416     //keen\r
258 \r
259 typedef struct\r
260 {\r
261         char old_mode;          //old video mode before game!\r
262         byte palette[768];              //palette array\r
263         page_t page[MAXPAGE];   //can be used as a pointer to root page[0]\r
264         word vmem_remain;       //remaining video memory\r
265         byte num_of_pages;      //number of actual pages\r
266         //doslib origi vars\r
267         byte far * omemptr;\r
268         byte vga_draw_stride;\r
269         byte vga_draw_stride_limit;             // further X clipping\r
270         //end of doslib origi vars\r
271         boolean __near rss;                     //render sprite switch\r
272         sword __near sprifilei;         //player file's i\r
273         nibble __near p;                        //render page number\r
274         nibble __near sp;                       //show page number(for showpage)\r
275         boolean __near r;                       //page flip, showpage, or render        if true\r
276         word pr[MAXPAGE][4];    //render sections of pages (this is supposed to be set up to draw sections of the screen if updated)\r
277 \r
278         nibble sfip;            //shinku_fps_indicator_page; // we're on page 1 now, shinku(). follow along please or it will not be visible.\r
279         ofs_t   ofs;            //offset vars used for doslib\r
280         word    vh;             //video combined height\r
281         //0000word startclk; float clk, tickclk;        //timer\r
282 //newer vars\r
283 //TODO: find out how they are used\r
284         byte grneeded[NUMCHUNKS];\r
285 } video_t;\r
286 \r
287 //from scroll16\r
288 //==========================================================================\r
289 typedef struct\r
290 {\r
291         map_t *map;\r
292         page_t *page;\r
293         int tx,ty; //appears to be the top left tile position on the viewable screen map\r
294         word dxThresh,dyThresh; //Threshold for physical tile switch\r
295         video_t *video; //pointer to game variables of the video\r
296         nibble __near *p;       // pointer to video's render page num\r
297         nibble __near *sp;      // pointer to video's show page num\r
298         int dx, dy;     // draw row and col var\r
299 //newer vars!\r
300         int delta, d;\r
301 } map_view_t;\r
302 /* Map is presumed to:\r
303  * 1. Have all the required layers and tilesets within itself\r
304  * 2. Have a 'fence' around accessible blocks to simplify boundary logic\r
305  * 3. Have a persistent map and tile size among the layers\r
306  * Map view is presumed to:\r
307  * 1. Calculate, store and update a panning info, which includes, but not limited to:\r
308  *      combined layer information, actual map representation (reflecting real state of the game),\r
309  *      pixel shift for smooth tile scrolling.\r
310  * 2. Provide ways to draw a visible part of map. For simplicity with smooth scrolling,\r
311  *      additional row/column is always drawn at the each side of the map. This implies that 'fence'\r
312  *      should have a sprite too. Map is drawn left-to-right, top-to-bottom.\r
313  */\r
314 \r
315 //==========================================================================\r
316 \r
317 //from 16_mm\r
318 //==========================================================================\r
319 \r
320 #define MAXBLOCKS               1024\r
321 #define MAXUMBS         12\r
322 \r
323 typedef struct mmblockstruct\r
324 {\r
325         word    start,length;\r
326         //word  start;  dword length;\r
327         word    blob;   //for data larger than 64k\r
328         unsigned        attributes;\r
329         memptr          *useptr;        // pointer to the segment start\r
330         struct mmblockstruct far *next;\r
331 } mmblocktype;\r
332 \r
333 typedef struct\r
334 {\r
335         dword   nearheap,farheap,EMSmem,XMSmem,mainmem;\r
336 //      boolean         PMStarted, MainPresent, EMSPresent, XMSPresent;\r
337 } mminfotype;\r
338 \r
339 typedef struct\r
340 {\r
341         memptr bufferseg;\r
342         boolean         mmstarted, bombonerror, mmerror;\r
343         void far        *farheap;\r
344 #ifdef __BORLANDC__\r
345         void    *nearheap;\r
346 #endif\r
347 #ifdef __WATCOMC__\r
348         void __near     *nearheap;\r
349 #endif\r
350         unsigned int            EMSVer;\r
351         word numUMBs,UMBbase[MAXUMBS];\r
352         word                    totalEMSpages, freeEMSpages, EMSpagesmapped, EMSHandle, EMSPageFrame;\r
353         //dword numUMBs,UMBbase[MAXUMBS];\r
354         mmblocktype     far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;\r
355 } mminfo_t;\r
356 \r
357 //==========================================================================\r
358 \r
359 \r
360 //from 16_pm\r
361 //==========================================================================\r
362 \r
363 //      NOTE! PMPageSize must be an even divisor of EMSPageSize, and >= 1024\r
364 #define EMSPageSize             16384\r
365 #define EMSPageSizeSeg  (EMSPageSize >> 4)\r
366 #define EMSPageSizeKB   (EMSPageSize >> 10)\r
367 #define EMSFrameCount   4\r
368 #define PMPageSize              4096\r
369 #define PMPageSizeSeg   (PMPageSize >> 4)\r
370 #define PMPageSizeKB    (PMPageSize >> 10)\r
371 #define PMEMSSubPage    (EMSPageSize / PMPageSize)\r
372 \r
373 #define PMMinMainMem    10                      // Min acceptable # of pages from main\r
374 #define PMMaxMainMem    100                     // Max number of pages in main memory\r
375 \r
376 #define PMThrashThreshold       1       // Number of page thrashes before panic mode\r
377 #define PMUnThrashThreshold     5       // Number of non-thrashing frames before leaving panic mode\r
378 \r
379 typedef enum\r
380                 {\r
381                         pml_Unlocked,\r
382                         pml_Locked\r
383                 } PMLockType;\r
384 \r
385 typedef enum\r
386                 {\r
387                         pmba_Unused = 0,\r
388                         pmba_Used = 1,\r
389                         pmba_Allocated = 2\r
390                 } PMBlockAttr;\r
391 \r
392 typedef struct\r
393                 {\r
394                         dword   offset;         // Offset of chunk into file\r
395                         word            length;         // Length of the chunk\r
396 \r
397                         int                     xmsPage;        // If in XMS, (xmsPage * PMPageSize) gives offset into XMS handle\r
398 \r
399                         PMLockType      locked;         // If set, this page can't be purged\r
400                         int                     emsPage;        // If in EMS, logical page/offset into page\r
401                         int                     mainPage;       // If in Main, index into handle array\r
402 \r
403                         dword   lastHit;        // Last frame number of hit\r
404                 } PageListStruct;\r
405 \r
406 typedef struct\r
407                 {\r
408                         int                     baseEMSPage;    // Base EMS page for this phys frame\r
409                         dword   lastHit;                // Last frame number of hit\r
410                 } EMSListStruct;\r
411 \r
412 //      Main Mem specific variables\r
413 typedef struct\r
414 {\r
415         boolean                 MainPresent;\r
416         memptr                  MainMemPages[PMMaxMainMem];\r
417         PMBlockAttr             MainMemUsed[PMMaxMainMem];\r
418         int                             MainPagesAvail;\r
419 } pm_mmi_t;\r
420 \r
421 //      EMS specific variables\r
422 typedef struct\r
423 {\r
424         boolean                 EMSPresent;\r
425         unsigned int                    EMSVer;\r
426         word                    EMSAvail,EMSPagesAvail,EMSHandle,\r
427                                         EMSPageFrame,EMSPhysicalPage;\r
428         word                    totalEMSpages, freeEMSpages, EMSpagesmapped;\r
429         EMSListStruct   EMSList[EMSFrameCount];\r
430 } pm_emmi_t;\r
431 \r
432 //      XMS specific variables\r
433 typedef struct\r
434 {\r
435         boolean                 XMSPresent;\r
436         word                    XMSAvail,XMSPagesAvail,XMSHandle;//,XMSVer;\r
437         dword                   XMSDriver;\r
438         int                             XMSProtectPage;// = -1;\r
439 } pm_xmmi_t;\r
440 \r
441 //      File specific variables\r
442 typedef struct\r
443 {\r
444         char                    PageFileName[13];// = {"VSWAP."};\r
445         int                             PageFile;// = -1;\r
446         word                    ChunksInFile;\r
447         word                    PMSpriteStart,PMSoundStart;\r
448 } pm_fi_t;\r
449 \r
450 //      General usage variables\r
451 typedef struct\r
452 {\r
453         boolean                 PMStarted,\r
454                                         PMPanicMode,\r
455                                         PMThrashing;\r
456         word                    XMSPagesUsed,\r
457                                         EMSPagesUsed,\r
458                                         MainPagesUsed,\r
459                                         PMNumBlocks;\r
460         long                    PMFrameCount;\r
461         PageListStruct  far *PMPages;\r
462         __SEGA *PMSegPages;\r
463         pm_mmi_t        mm;\r
464         pm_emmi_t       emm;\r
465         pm_xmmi_t       xmm;\r
466         pm_fi_t fi;\r
467 } pm_t;\r
468 \r
469 //==========================================================================\r
470 \r
471 //from 16_ca\r
472 //==========================================================================\r
473 \r
474 #define NUMMAPS         4//39\r
475 #define MAPPLANES               3\r
476 \r
477 typedef struct\r
478 {\r
479   word bit0,bit1;       // 0-255 is a character, > is a pointer to a node\r
480 } huffnode;\r
481 \r
482 typedef struct\r
483 {\r
484         int             mapon, mapnum;\r
485         __SEGA  *mapsegs[4];\r
486         __SEGA  *mapheaderseg[NUMMAPS];\r
487         __SEGA  *tinf;\r
488 } ca_mapinfo_t;\r
489 \r
490 typedef struct\r
491 {\r
492         int                     maphandle[4];           // handle to MAPTEMP / GAMEMAPS\r
493 } ca_handle_t;\r
494 \r
495 typedef struct\r
496 {\r
497         byte            ca_levelbit,ca_levelnum;\r
498         ca_handle_t     file;           //files to open\r
499         ca_mapinfo_t    camap;\r
500         __SEGA  *grsegs[NUMCHUNKS];\r
501         byte            far     grneeded[NUMCHUNKS];\r
502         huffnode huffnode;\r
503 \r
504         //TODO: extend! and learn from keen/wolf/catacomb's code wwww\r
505         memptr  spribuff;\r
506 } ca_t;\r
507 \r
508 //==========================================================================\r
509 \r
510 //actual global game varables!\r
511 typedef enum {\r
512         ENGI_EXIT,\r
513         ENGI_QUIT,\r
514         ENGI_RUN,\r
515         ENGI_INPUT,\r
516         ENGI_PAUSE\r
517 } engi_stat_t;\r
518 \r
519 typedef struct\r
520 {\r
521         video_t video;  // video settings variable\r
522         ca_t            ca;     // ca stuff\r
523         pm_t            pm;     // pm stuff\r
524         loghandle_t handle;     //handles for file logging\r
525         kurokku_t kurokku;      //clock struct\r
526         mminfo_t mm; mminfotype mmi;\r
527 } global_game_variables_t;\r
528 \r
529 extern char global_temp_status_text[512];\r
530 #ifdef __WATCOMC__\r
531 #define EINVFMT EMFILE\r
532 #endif\r
533 #endif /* _TYPEDEFSTRUCT_H_ */\r