]> 4ch.mooo.com Git - 16.git/blob - src/exmmtest.c
wwww debugging EMS on 386+
[16.git] / src / exmmtest.c
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         exmm test\r
24 */\r
25 #include <malloc.h>             // for _memavl()\r
26 #include "src/lib/16_head.h"\r
27 #include "src/lib/16_tail.h"\r
28 #include "src/lib/16_pm.h"\r
29 #include "src/lib/16_ca.h"\r
30 #include "src/lib/16_mm.h"\r
31 #include "src/lib/16_hc.h"\r
32 //#include "src/lib/16_vl.h"\r
33 #include "src/lib/16_dbg.h"\r
34 \r
35 #pragma hdrstop\r
36 \r
37 #pragma warn -pro\r
38 #pragma warn -use\r
39 \r
40 //file load or read definition\r
41 #define FILEREADLOAD\r
42 #define FILEREAD\r
43 //#define EXMMVERBOSE\r
44 //#define BUFFDUMPPAUSE\r
45 //#define EXMMVERBOSE__\r
46 //      #define PRINTBBDUMP\r
47 #define BUFFDUMP\r
48 \r
49 #define BBUFNAME gvar.ca.tinf[0]//bigbuffer\r
50 //#define INITBBUF static memptr BBUFNAME;\r
51 #define BBUFPTR &BBUFNAME\r
52 \r
53 #ifdef __BORLANDC__\r
54 #define BBUF            (memptr *)BBUFPTR//\r
55 #define BBUFSTRING      (memptr *)BBUFNAME\r
56 #endif\r
57 #ifdef __WATCOMC__\r
58 #define BBUF            BBUFNAME\r
59 #define BBUFSTRING      BBUF\r
60 #endif\r
61 \r
62 \r
63 void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv)\r
64 {\r
65         printf("VGAmodeX dummy:\n       %Fp     %Fp     %Fp\n", &vq, &cmem, gv);\r
66 }\r
67 \r
68 //printf("*     %Fp\t", *BBUF);\r
69 //printf("*          %04x\t", *BBUF);\r
70 #define PRINTBB {\\r
71         printf("-------------------------------------------------------------------------------\n");\\r
72         printf("&main()=        %Fp\n", argv[0]);\\r
73         printf("buffer:\n");\\r
74         printf("        %Fp\t", BBUF);\\r
75         printf("&%Fp\n", BBUFPTR);\\r
76         printf("             %04x\t", BBUF);\\r
77         printf("&     %04x\n", BBUFPTR);\\r
78         printf("-------------------------------------------------------------------------------\n");\\r
79 }\r
80         //printf("&main()=      %Fp\n", *argv[0]);\r
81         //printf("bigbuffer=    %Fp\n", bigbuffer);\r
82         //printf("&bigbuffer=   %Fp\n", &bigbuffer);\r
83         //printf("bigbuffer=    %04x\n", bigbuffer);\r
84         //printf("&bigbuffer=   %04x\n", &bigbuffer);\r
85 #ifdef __WATCOMC__\r
86 void segatesuto()\r
87 {\r
88         __segment screen;\r
89         char __based( void ) * scrptr;\r
90 \r
91         screen = 0xB800;\r
92         scrptr = 0;\r
93         printf( "Top left character is '%c'.\n", *(screen:>scrptr) );\r
94 //      printf("Next string is: [");\r
95 //      while(*scrptr<16)\r
96 //      {\r
97 //              printf("%c", *(screen:>scrptr));\r
98 //              //printf("\b");\r
99 //              scrptr++;\r
100 //\r
101 //      }\r
102 //      printf("]\n");\r
103 //      printf("press any key to continue!\n");\r
104 //      getch();\r
105 }\r
106 #endif\r
107 \r
108 void\r
109 main(int argc, char *argv[])\r
110 {\r
111         byte w;\r
112         static global_game_variables_t gvar;\r
113 #ifdef INITBBUF\r
114         INITBBUF\r
115 #endif\r
116 //#ifdef __WATCOMC__\r
117 //      __segment sega;\r
118 //#endif\r
119         //static byte bakapee[64];\r
120         char *bakapee1, *bakapee2;\r
121         word baka;\r
122 \r
123 #ifdef __BORLANDC__\r
124         argc=argc;\r
125 #endif\r
126         //file name //\r
127         bakapee1 = malloc(24);\r
128         bakapee2 = malloc(24);\r
129         //file name //\r
130 \r
131 #ifdef __16_PM__\r
132 #ifdef __DEBUG_PM__\r
133         dbg_debugpm=1;  //debug pm\r
134 #endif\r
135 #endif\r
136 \r
137 #ifdef __DEBUG_CA__\r
138         dbg_debugca=1;\r
139 #endif\r
140 #ifdef PRINTBBDUMP\r
141 //0000PRINTBB; printf("press any key to continue!\n"); getch();\r
142 #endif\r
143         if(argv[1]){ bakapee1 = argv[1];\r
144         if(argv[2]) bakapee2 = argv[2]; }\r
145         else{\r
146         //{ printf("filename!: "); scanf("%[^\n]", &bakapee); }\r
147                 bakapee1 = "data/koishi~.pcx";\r
148                 bakapee2 = "data/test.map";\r
149         }\r
150         //printf("main()=%Fp    start MM\n", *argv[0]);\r
151         MM_Startup(&gvar); //printf("ok\n");\r
152 #ifdef __16_PM__\r
153 #ifdef __DEBUG_PM__\r
154         if(dbg_debugpm>0)\r
155         {\r
156 #endif\r
157                 PM_Startup(&gvar); PM_CheckMainMem(&gvar); PM_UnlockMainMem(&gvar);\r
158 //0000          printf("PM Started\n"); printf("press any key to continue!\n"); getch();\r
159 #ifdef __DEBUG_PM__\r
160         }\r
161 #endif\r
162 #endif\r
163 \r
164 #ifdef __DEBUG_MM__\r
165         dbg_debugmm=0;\r
166 #endif\r
167         CA_Startup(&gvar);\r
168 //      printf("                done!\n");\r
169 #ifdef PRINTBBDUMP\r
170 //0000\r
171 PRINTBB; printf("\n\npress any key to continue!\n"); getch();\r
172 #endif\r
173 #ifdef __DEBUG_MM__\r
174         dbg_debugmm=1;\r
175 #endif\r
176 \r
177         w=0;\r
178 #ifdef FILEREADLOAD\r
179 #ifdef FILEREAD\r
180         for(;w<2;w++)\r
181         {\r
182         //      printf("size of big buffer~=%u\n", _bmsize(segu, BBUF));\r
183                 if(w>0)\r
184                 {\r
185                         printf("======================================read=====================================\n");\r
186                         if(CA_ReadFile(bakapee2, BBUFPTR, &gvar)) baka=1; else baka=0;\r
187                         printf("====================================read end===================================\n");\r
188                 }\r
189 #endif\r
190                 if(w==0)\r
191                 {\r
192                         printf("======================================load=====================================\n");\r
193                         if(CA_LoadFile(bakapee1, BBUFPTR, &gvar)) baka=1; else baka=0;\r
194                         printf("====================================load end===================================\n");\r
195                 }\r
196 //#ifdef __WATCOMC__\r
197 //      printf("\nsize of big buffer~=%u\n", _bmsize(sega, BBUF));\r
198 //#endif\r
199 #ifdef BUFFDUMP\r
200                 printf("contents of the buffer\n[\n%s\n]\n", BBUFSTRING);\r
201 #endif// #else\r
202 #ifdef PRINTBBDUMP\r
203                 PRINTBB;\r
204 #endif\r
205 //endif // BUFFDUMP\r
206 \r
207                 //printf("dark purple = purgable\n");\r
208                 //printf("medium blue = non purgable\n");\r
209                 //printf("red = locked\n");\r
210         //      printf("press any key to continue!\n");\r
211         //      DebugMemory_(&gvar, 1);\r
212                 if(baka) printf("\nyay!\n");\r
213                 else printf("\npoo!\n");\r
214 #ifdef BUFFDUMPPAUSE\r
215                 printf("press any key to continue!\n"); getch();\r
216 #endif\r
217 #ifdef FILEREAD\r
218         }\r
219 #endif\r
220 #ifndef BUFFDUMPPAUSE\r
221         printf("press any key to continue!\n"); getch();\r
222 #endif\r
223 #endif  //filereadload\r
224 \r
225 /*\r
226 #ifdef __WATCOMC__\r
227         IN_Shutdown(&gvar);\r
228         ShapeTest (&gvar);\r
229         IN_Startup(&gvar);\r
230 #endif\r
231 */\r
232 \r
233         DebugMemory_(&gvar, 1);\r
234         MM_DumpData(&gvar);\r
235         MM_Report_(&gvar);\r
236         //printf("bakapee1=%s\n", bakapee1);\r
237         //printf("bakapee2=%s\n", bakapee2);\r
238         MM_FreePtr(BBUFPTR, &gvar);\r
239 #ifdef __16_PM__\r
240 #ifdef __DEBUG_PM__\r
241         if(dbg_debugpm>0)\r
242 #endif\r
243                 PM_Shutdown(&gvar);\r
244 #endif\r
245         CA_Shutdown(&gvar);\r
246         MM_Shutdown(&gvar);\r
247         free(bakapee1); free(bakapee2);\r
248         printf("========================================\n");\r
249         printf("near=   %Fp ", gvar.mm.nearheap);\r
250         printf("far=    %Fp", gvar.mm.farheap);\r
251         printf("\n");\r
252         printf("&near=  %Fp ", &(gvar.mm.nearheap));\r
253         printf("&far=   %Fp", &(gvar.mm.farheap));\r
254         printf("\n");\r
255 #ifdef EXMMVERBOSE\r
256         printf("bigb=   %Fp ", BBUF);\r
257         //printf("bigbr=        %04x", BBUF);\r
258         //printf("\n");\r
259         printf("&bigb=%Fp ", BBUFPTR);\r
260         //printf("&bigb=%04x", BBUFPTR);\r
261         printf("\n");\r
262 #endif\r
263         printf("========================================\n");\r
264 \r
265 #ifdef EXMMVERBOSE__\r
266         printf("coreleft():                     %u\n", _memavl());\r
267         printf("farcoreleft():                  %lu\n", (dword)HC_farcoreleft());\r
268 #endif\r
269 #ifdef __WATCOMC__\r
270 //this is far   printf("Total free:                     %lu\n", (dword)(HC_GetFreeSize()));\r
271 //super buggy   printf("HC_coreleft():                  %u\n", HC_coreleft());\r
272 //      printf("HC_farcoreleft():                       %lu\n", (dword)HC_farcoreleft());\r
273         //printf("HC_GetNearFreeSize():         %u\n", HC_GetNearFreeSize());\r
274         //printf("HC_GetFarFreeSize():                  %lu\n", (dword)HC_GetFarFreeSize());\r
275         HC_heapdump(&gvar);\r
276 //      segatesuto();\r
277 #endif\r
278 /*#ifdef __BORLANDC__\r
279         //printf("core left:                    %lu\n", (dword)HC_coreleft());\r
280         //printf("far core left:                        %lu\n", (dword)HC_farcoreleft());\r
281 //      printf("\nfarcoreleft():                        %lu\n", farcoreleft());\r
282 #endif*/\r
283         printf("Project 16 ");\r
284 #ifdef __WATCOMC__\r
285         printf("exmmtest");\r
286 #endif\r
287 #ifdef __BORLANDC__\r
288         printf("bcexmm");\r
289 #endif\r
290         printf(".exe. This is just a test file!\n");\r
291         printf("version %s\n", VERSION);\r
292 #if defined(__DEBUG__) && ( defined(__DEBUG_PM__) || defined(__DEBUG_MM__) )\r
293 #ifdef __DEBUG_MM__\r
294         printf("debugmm: %u\t", dbg_debugmm);\r
295 #endif\r
296 #ifdef __DEBUG_PM__\r
297         printf("debugpm: %u", dbg_debugpm);\r
298 #endif\r
299         printf("\n");\r
300 #endif\r
301         //printf("based core left:                      %lu\n", (dword)_basedcoreleft());\r
302         //printf("huge core left:                       %lu\n", (dword)_hugecoreleft());\r
303 }\r