OSDN Git Service

no idea how to get joy buttons 2 and 3 to function.
[proj16/16.git] / src / fd-dbg.c
1 /*      $Id: dbg_mem.c 1807 2018-04-17 02:47:19Z bartoldeman $\r
2 \r
3  *  Defines the functions only necessary while debugging is active\r
4 \r
5         This file bases on DEBUG.C of FreeCOM v0.81 beta 1.\r
6 \r
7         $Log$\r
8         Revision 1.5  2006/09/11 00:07:22  blairdude\r
9         Fixed compilation completely with Turbo C\r
10 \r
11         Revision 1.4  2004/02/01 13:52:17  skaus\r
12         add/upd: CVS $id$ keywords to/of files\r
13 \r
14         Revision 1.3  2001/06/11 20:45:38  skaus\r
15         fix: dbg_printmem() #if must be #ifdef\r
16 \r
17         Revision 1.2  2001/06/11 20:33:37  skaus\r
18         fix: dbg_printmem() if compiled in Large memory model, near is invalid\r
19 \r
20         Revision 1.1  2001/04/12 00:33:53  skaus\r
21         chg: new structure\r
22         chg: If DEBUG enabled, no available commands are displayed on startup\r
23         fix: PTCHSIZE also patches min extra size to force to have this amount\r
24            of memory available on start\r
25         bugfix: CALL doesn't reset options\r
26         add: PTCHSIZE to patch heap size\r
27         add: VSPAWN, /SWAP switch, .SWP resource handling\r
28         bugfix: COMMAND.COM A:\\r
29         bugfix: CALL: if swapOnExec == ERROR, no change of swapOnExec allowed\r
30         add: command MEMORY\r
31         bugfix: runExtension(): destroys command[-2]\r
32         add: clean.bat\r
33         add: localized CRITER strings\r
34         chg: use LNG files for hard-coded strings (hangForEver(), init.c)\r
35                 via STRINGS.LIB\r
36         add: DEL.C, COPY.C, CBREAK.C: STRINGS-based prompts\r
37         add: fixstrs.c: prompts & symbolic keys\r
38         add: fixstrs.c: backslash escape sequences\r
39         add: version IDs to DEFAULT.LNG and validation to FIXSTRS.C\r
40         chg: splitted code apart into LIB\*.c and CMD\*.c\r
41         bugfix: IF is now using error system & STRINGS to report errors\r
42         add: CALL: /N\r
43 \r
44  */\r
45 \r
46 //#include "../config.h"\r
47 #include "src/lib/16_hc.h"\r
48 \r
49 //#ifdef DEBUG\r
50 \r
51 #include <conio.h>      /* cputs */\r
52 #ifdef __WATCOMC__\r
53 #include <malloc.h>     /* _heapchk */\r
54 #else\r
55 #include <alloc.h>      /* heapcheck, coreleft, farcoreleft */\r
56 #endif\r
57 #include <stdlib.h>     /* abort */\r
58 \r
59 #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)\r
60 #define DISP_NEAR\r
61 #endif\r
62 \r
63 void dbg_printmem (void) {\r
64 #ifdef DISP_NEAR\r
65         static unsigned nearLast = 0;\r
66 #endif\r
67         static unsigned long farLast = 0;\r
68 \r
69 #ifdef DISP_NEAR\r
70         unsigned nearThis;\r
71 #endif\r
72 //      unsigned long farThis;\r
73         unsigned int farThis;\r
74 \r
75 #if __TURBOC__ > 0x201 || defined(__WATCOMC__)\r
76 #ifdef __WATCOMC__\r
77         switch(_heapchk())\r
78 #else\r
79         switch(heapcheck())\r
80 #endif\r
81         {\r
82 #ifdef __WATCOMC__\r
83         case _HEAPBADBEGIN:\r
84         case _HEAPBADNODE:\r
85         case _HEAPEND:\r
86         case _HEAPBADPTR:\r
87 #else\r
88         case _HEAPCORRUPT:\r
89 #endif\r
90                 cputs("HEAP CORRUPTED. Cannot proceed!\r\n");\r
91                 abort();\r
92         case _HEAPEMPTY:\r
93 //              cputs("NO HEAP. Cannot proceed!\r\n");\r
94 //              abort();\r
95                 break;\r
96         default:\r
97                 cputs("Unknown heapcheck() error. Cannot proceed!\r\n");\r
98                 abort();\r
99         case _HEAPOK:\r
100                 break;\r
101         }\r
102 #endif\r
103 \r
104 #ifdef __WATCOMC__\r
105 #ifdef DISP_NEAR\r
106         nearThis = _memavl();\r
107 #endif\r
108         _dos_allocmem(0xffff, &farThis);\r
109         farThis <<= 4;\r
110 #else\r
111 #ifdef DISP_NEAR\r
112         nearThis = coreleft();\r
113 #endif\r
114         farThis = farcoreleft();\r
115 #endif\r
116 \r
117 #ifdef DISP_NEAR\r
118 //      dprintf(("[free memory: near=%6u far=%13lu]\n", nearThis, farThis));\r
119         printf("[free memory: near=%6u far=%13lu]\n", nearThis, farThis);\r
120         if(nearLast)\r
121 //              dprintf(("[changed    : near=%6d far=%13ld]\n"           , nearThis - nearLast , farThis - farLast));\r
122                 printf("[changed    : near=%6d far=%13ld]\n"             , nearThis - nearLast , farThis - farLast);\r
123 #else\r
124 //      dprintf(("[free memory: far=%13lu]\n", farThis));\r
125         printf("[free memory: far=%13lu]\n", (unsigned long)farThis);\r
126         if(farLast)\r
127 //              dprintf(("[changed    : far=%13ld]\n", farThis - farLast));\r
128                 printf("[changed    : far=%13d]\n", (farThis - farLast));\r
129 #endif\r
130         printf("farcoreleft()=%lu\n", farcoreleft());\r
131         printf("HC_farcoreleft()=%lu\n", HC_farcoreleft());\r
132 \r
133 #ifdef DISP_NEAR\r
134         nearLast = nearThis;\r
135 #endif\r
136         farLast = farThis;\r
137 }\r
138 \r
139 void main()\r
140 {\r
141 //      static global_game_variables_t gvar;\r
142         int pee; pee=1;\r
143         dbg_printmem ();\r
144 //      dbg_printmem ();\r
145 }\r
146 \r
147 //#endif /* DEBUG */\r