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