]> 4ch.mooo.com Git - 16.git/blobdiff - src/exmmtest.c
[16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / src / exmmtest.c
old mode 100644 (file)
new mode 100755 (executable)
index fccbacb..11cdf7c
-/* Project 16 Source Code~
- * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
- *
- * This file is part of Project 16.
- *
- * Project 16 is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Project 16 is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
- * write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-/*
-       exmm test
-*/
-#include <stdio.h>
-#include <bios.h>
-
-#include "src/lib/16_head.h"
-#include "src/lib/16_ca.h"
-#include "src/lib/16_mm.h"
-//#include "src/lib/modex16.h"
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ *\r
+ * This file is part of Project 16.\r
+ *\r
+ * Project 16 is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Project 16 is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
+ * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ */\r
+/*\r
+       exmm test\r
+*/\r
+#include <malloc.h>            // for _memavl()\r
+#include "src/lib/16_head.h"\r
+#include "src/lib/16_tail.h"\r
+#include "src/lib/16_pm.h"\r
+#include "src/lib/16_ca.h"\r
+#include "src/lib/16_mm.h"\r
+#include "src/lib/16_hc.h"\r
+//#include "src/lib/16_vl.h"\r
+#include "src/lib/16_dbg.h"\r
+\r
 #pragma hdrstop\r
 \r
 #pragma warn -pro\r
-#pragma warn -use
-
-//file load or read definition
-//#define FILERL
-//#define FILEREAD
-
-void
-main(int argc, char *argv[])
-{
-       mminfo_t mm; mminfotype mmi;
-       memptr bigbuffer;
-#ifdef FILERL
-       char *bakapee;
-//     int bakapeehandle;
-       word baka;
-#endif
-       //static page_t screen;
-
-       //mmi.segu=FP_SEG(segu);
-
-       printf("&main()=        %Fp\n", *argv[0]);
-       printf("bigbuffer=      %Fp\n", bigbuffer);
-       printf("&bigbuffer=     %Fp\n", &bigbuffer);
-       printf("bigbuffer=      %04x\n", bigbuffer);
-       printf("&bigbuffer=     %04x\n", &bigbuffer);
-
-#ifdef FILERL
-       bakapee = malloc(64);
-//     memset(bakapee, 0, 64);
-#endif
-       mm.mmstarted=0;
-
-#ifdef FILERL
-       if(argv[1]) bakapee = argv[1];
-       else bakapee = "data/koishi~~.pcx";
-#endif
-
-       textInit();\r
-
-       /* setup camera and screen~ */
-       //bug!!!\r
-       //screen = modexDefaultPage();\r
-       /*screen.width += (16*2);\r
-       screen.height += (16*2);*/
-
-       printf("main()=%Fp      start MM\n", *argv[0]);
-       MM_Startup(&mm, &mmi);
-       //PM_Startup();\r
-       //PM_UnlockMainMem();\r
-       CA_Startup();
-       printf("                done!\n");
-       /*if(FP_SEG(*argv[0])==0)
-       {
-               MM_Report(&screen, &mm, &mmi);
-               MM_Shutdown(&mm);
-               printf("&main()=%Fp\n", *argv[0]);
-               printf("&main() == %u\n", FP_SEG(*argv[0]));
-               exit(-5);
-       }*/
-       printf("&main()=        %Fp\n", *argv[0]);
-       printf("bigbuffer=      %Fp\n", bigbuffer);
-       printf("&bigbuffer=     %Fp\n", &bigbuffer);
-       printf("bigbuffer=      %04x\n", bigbuffer);
-       printf("&bigbuffer=     %04x\n", &bigbuffer);
-#ifdef FILERL
-//     bakapeehandle = open(bakapee,O_RDONLY | O_BINARY, S_IREAD);
-//     printf("size of big buffer~=%u\n", _bmsize(segu, bigbuffer));
-//     if(CA_FarRead(bakapeehandle,(void far *)&bigbuffer,sizeof(bigbuffer),&mm))
-#ifdef FILEREAD
-       printf("                read\n");
-       if(CA_ReadFile(bakapee, &bigbuffer, &mm))
-#else
-       printf("                load\n");
-       if(CA_LoadFile(bakapee, &bigbuffer, &mm, &mmi))
-#endif
-               baka=1;
-       else
-               baka=0;
-//     close(bakapeehandle);
-       //hmm functions in cache system use the buffered stuff
-//     printf("size of big buffer~=%u\n", _bmsize(segu, bigbuffer));
-#endif
-       printf("dark purple = purgable\n");
-       printf("medium blue = non purgable\n");
-       printf("red = locked\n");
-//     getch();
-       //++++modexEnter();
-       //++++modexShowPage(&screen);
-       MM_ShowMemory(/*&screen, */&mm);
-       //getch();
-       MM_DumpData(&mm);
-       //++++modexLeave();
-       MM_Report(&mm, &mmi);
-       printf("                stop!\n");
-#ifdef FILERL
-       MM_FreePtr(&bigbuffer, &mm);
-#endif
-       //PM_Shutdown();
-       CA_Shutdown();
-       MM_Shutdown(&mm);
-       printf("                done!\n");
-#ifdef FILERL
-       free(bakapee);
-       if(baka) printf("\nyay!\n");
-       else printf("\npoo!\n");
-#endif
-       //printf("_bios_memsize=%u\n", _bios_memsize());
-       printf("bigbuffer=      %Fp\n", bigbuffer);
-       printf("&bigbuffer=     %Fp\n", &bigbuffer);
-       printf("bigbuffer=      %04x\n", bigbuffer);
-       printf("&bigbuffer=     %04x\n", &bigbuffer);
-       printf("\n\n");
-       printf("Total free:                     %lu\n", (dword)(GetFreeSize()));
-       printf("Total near free:                %lu\n", (dword)(GetNearFreeSize()));
-       printf("Total far free:                 %lu\n", (dword)(GetFarFreeSize()));
-       getch();
-       printf("\n");
-       heapdump();
-       printf("core left:                      %lu\n", (dword)_coreleft());
-       printf("far core left:                  %lu\n", (dword)_farcoreleft());
-       //printf("based core left:                      %lu\n", (dword)_basedcoreleft());
-       //printf("huge core left:                       %lu\n", (dword)_hugecoreleft());
-}
+#pragma warn -use\r
+\r
+//file load or read definition\r
+#define FILEREADLOAD\r
+#define FILEREAD\r
+//#define EXMMVERBOSE\r
+//#define BUFFDUMPPAUSE\r
+//#define EXMMVERBOSE__\r
+//     #define PRINTBBDUMP\r
+#define BUFFDUMP\r
+\r
+#define BBUFNAME gvar.ca.tinf[0]//bigbuffer\r
+//#define INITBBUF static memptr BBUFNAME;\r
+#define BBUFPTR        (memptr *)&BBUFNAME\r
+\r
+#ifdef __BORLANDC__\r
+#define BBUF           (memptr *)BBUFPTR//\r
+#define BBUFSTRING     (memptr *)BBUFNAME\r
+#endif\r
+#ifdef __WATCOMC__\r
+#define BBUF           BBUFNAME\r
+#define BBUFSTRING     BBUF\r
+#endif\r
+\r
+////////////////////////////////////////////////////////////////////////////\r
+\r
+void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv)\r
+{\r
+       printf("VGAmodeX dummy:\n       %Fp     %Fp     %Fp\n", &vq, &cmem, gv);\r
+}\r
+\r
+//printf("*    %Fp\t", *BBUF);\r
+//printf("*         %04x\t", *BBUF);\r
+#define PRINTBB {\\r
+       printf("-------------------------------------------------------------------------------\n");\\r
+       printf("&main()=        %Fp\n", argv[0]);\\r
+       printf("buffer:\n");\\r
+       printf("        %Fp\t", BBUF);\\r
+       printf("&%Fp\n", BBUFPTR);\\r
+       printf("             %04x\t", BBUF);\\r
+       printf("&     %04x\n", BBUFPTR);\\r
+       printf("-------------------------------------------------------------------------------\n");\\r
+}\r
+       //printf("&main()=      %Fp\n", *argv[0]);\r
+       //printf("bigbuffer=    %Fp\n", bigbuffer);\r
+       //printf("&bigbuffer=   %Fp\n", &bigbuffer);\r
+       //printf("bigbuffer=    %04x\n", bigbuffer);\r
+       //printf("&bigbuffer=   %04x\n", &bigbuffer);\r
+#ifdef __WATCOMC__\r
+void segatesuto()\r
+{\r
+       __segment screen;\r
+       char __based( void ) * scrptr;\r
+\r
+       screen = 0xB800;\r
+       scrptr = 0;\r
+       printf( "Top left character is '%c'.\n", *(screen:>scrptr) );\r
+//     printf("Next string is: [");\r
+//     while(*scrptr<16)\r
+//     {\r
+//             printf("%c", *(screen:>scrptr));\r
+//             //printf("\b");\r
+//             scrptr++;\r
+//\r
+//     }\r
+//     printf("]\n");\r
+//     printf("press any key to continue!\n");\r
+//     getch();\r
+}\r
+#endif\r
+\r
+void\r
+main(int argc, char *argv[])\r
+{\r
+       byte w;\r
+       static global_game_variables_t gvar;\r
+#ifdef INITBBUF\r
+       INITBBUF\r
+#endif\r
+//#ifdef __WATCOMC__\r
+//     __segment sega;\r
+//#endif\r
+       //static byte bakapee[64];\r
+       char *bakapee1, *bakapee2;\r
+       word baka;\r
+\r
+#ifdef __BORLANDC__\r
+       argc=argc;\r
+#endif\r
+       //file name //\r
+       bakapee1 = malloc(24);\r
+       bakapee2 = malloc(24);\r
+       //file name //\r
+\r
+#ifdef __16_PM__\r
+#ifdef __DEBUG_PM__\r
+       dbg_debugpm=1;  //debug pm\r
+#endif\r
+#endif\r
+\r
+#ifdef __DEBUG_CA__\r
+       dbg_debugca=1;\r
+#endif\r
+#ifdef PRINTBBDUMP\r
+//0000PRINTBB; printf("press any key to continue!\n"); getch();\r
+#endif\r
+       if(argv[1]){ bakapee1 = argv[1];\r
+       if(argv[2]) bakapee2 = argv[2]; }\r
+       else{\r
+       //{ printf("filename!: "); scanf("%[^\n]", &bakapee); }\r
+               bakapee1 = "data/koishi~.pcx";\r
+               bakapee2 = "data/test.map";\r
+       }\r
+       //printf("main()=%Fp    start MM\n", *argv[0]);\r
+       MM_Startup(&gvar); //printf("ok\n");\r
+#ifdef __16_PM__\r
+#ifdef __DEBUG_PM__\r
+       if(dbg_debugpm>0)\r
+       {\r
+#endif\r
+               PM_Startup(&gvar); PM_CheckMainMem(&gvar); PM_UnlockMainMem(&gvar);\r
+//0000         printf("PM Started\n"); printf("press any key to continue!\n"); getch();\r
+#ifdef __DEBUG_PM__\r
+       }\r
+#endif\r
+#endif\r
+\r
+#ifdef __DEBUG_MM__\r
+       dbg_debugmm=0;\r
+#endif\r
+       CA_Startup(&gvar);\r
+//     printf("                done!\n");\r
+#ifdef PRINTBBDUMP\r
+//0000\r
+PRINTBB; printf("\n\npress any key to continue!\n"); getch();\r
+#endif\r
+#ifdef __DEBUG_MM__\r
+       dbg_debugmm=1;\r
+#endif\r
+\r
+       w=0;\r
+#ifdef FILEREADLOAD\r
+#ifdef FILEREAD\r
+       for(;w<2;w++)\r
+       {\r
+       //      printf("size of big buffer~=%u\n", _bmsize(segu, BBUF));\r
+               if(w>0)\r
+               {\r
+                       printf("======================================read=====================================\n");\r
+                       if(CA_ReadFile(bakapee2, BBUFPTR, &gvar)) baka=1; else baka=0;\r
+                       printf("====================================read end===================================\n");\r
+               }\r
+#endif\r
+               if(w==0)\r
+               {\r
+                       printf("======================================load=====================================\n");\r
+                       if(CA_LoadFile(bakapee1, BBUFPTR, &gvar)) baka=1; else baka=0;\r
+                       printf("====================================load end===================================\n");\r
+               }\r
+//#ifdef __WATCOMC__\r
+//     printf("\nsize of big buffer~=%u\n", _bmsize(sega, BBUF));\r
+//#endif\r
+#ifdef BUFFDUMP\r
+               printf("contents of the buffer\n[\n%s\n]\n", BBUFSTRING);\r
+#endif// #else\r
+#ifdef PRINTBBDUMP\r
+               PRINTBB;\r
+#endif\r
+//endif // BUFFDUMP\r
+\r
+               //printf("dark purple = purgable\n");\r
+               //printf("medium blue = non purgable\n");\r
+               //printf("red = locked\n");\r
+       //      printf("press any key to continue!\n");\r
+       //      DebugMemory_(&gvar, 1);\r
+               if(baka) printf("\nyay!\n");\r
+               else printf("\npoo!\n");\r
+#ifdef BUFFDUMPPAUSE\r
+               printf("press any key to continue!\n"); getch();\r
+#endif\r
+#ifdef FILEREAD\r
+       }\r
+#endif\r
+#ifndef BUFFDUMPPAUSE\r
+       printf("press any key to continue!\n"); getch();\r
+#endif\r
+#endif //filereadload\r
+\r
+\r
+#ifdef __WATCOMC__\r
+       IN_Startup(&gvar);\r
+       ShapeTest (&gvar);\r
+       IN_Shutdown(&gvar);\r
+#endif\r
+\r
+\r
+       DebugMemory_(&gvar, 1);\r
+       MM_DumpData(&gvar);\r
+       MM_Report_(&gvar);\r
+       //printf("bakapee1=%s\n", bakapee1);\r
+       //printf("bakapee2=%s\n", bakapee2);\r
+       MM_FreePtr(BBUFPTR, &gvar);\r
+#ifdef __16_PM__\r
+#ifdef __DEBUG_PM__\r
+       if(dbg_debugpm>0)\r
+#endif\r
+               PM_Shutdown(&gvar);\r
+#endif\r
+       CA_Shutdown(&gvar);\r
+       MM_Shutdown(&gvar);\r
+       free(bakapee1); free(bakapee2);\r
+       printf("========================================\n");\r
+       printf("near=   %Fp ", gvar.mm.nearheap);\r
+       printf("far=    %Fp", gvar.mm.farheap);\r
+       printf("\n");\r
+       printf("&near=  %Fp ", &(gvar.mm.nearheap));\r
+       printf("&far=   %Fp", &(gvar.mm.farheap));\r
+       printf("\n");\r
+#ifdef EXMMVERBOSE\r
+       printf("bigb=   %Fp ", BBUF);\r
+       //printf("bigbr=        %04x", BBUF);\r
+       //printf("\n");\r
+       printf("&bigb=%Fp ", BBUFPTR);\r
+       //printf("&bigb=%04x", BBUFPTR);\r
+       printf("\n");\r
+#endif\r
+       printf("========================================\n");\r
+\r
+#ifdef EXMMVERBOSE__\r
+       printf("coreleft():                     %u\n", _memavl());\r
+       printf("farcoreleft():                  %lu\n", (dword)HC_farcoreleft());\r
+#endif\r
+#ifdef __WATCOMC__\r
+//this is far  printf("Total free:                     %lu\n", (dword)(HC_GetFreeSize()));\r
+//super buggy  printf("HC_coreleft():                  %u\n", HC_coreleft());\r
+//     printf("HC_farcoreleft():                       %lu\n", (dword)HC_farcoreleft());\r
+       //printf("HC_GetNearFreeSize():         %u\n", HC_GetNearFreeSize());\r
+       //printf("HC_GetFarFreeSize():                  %lu\n", (dword)HC_GetFarFreeSize());\r
+       HC_heapdump(&gvar);\r
+//     segatesuto();\r
+#endif\r
+/*#ifdef __BORLANDC__\r
+       //printf("core left:                    %lu\n", (dword)HC_coreleft());\r
+       //printf("far core left:                        %lu\n", (dword)HC_farcoreleft());\r
+//     printf("\nfarcoreleft():                        %lu\n", farcoreleft());\r
+#endif*/\r
+       printf("Project 16 ");\r
+#ifdef __WATCOMC__\r
+       printf("exmmtest");\r
+#endif\r
+#ifdef __BORLANDC__\r
+       printf("bcexmm");\r
+#endif\r
+       printf(".exe. This is just a test file!\n");\r
+       printf("version %s\n", VERSION);\r
+#if defined(__DEBUG__) && ( defined(__DEBUG_PM__) || defined(__DEBUG_MM__) )\r
+#ifdef __DEBUG_MM__\r
+       printf("debugmm: %u\t", dbg_debugmm);\r
+#endif\r
+#ifdef __DEBUG_PM__\r
+       printf("debugpm: %u", dbg_debugpm);\r
+#endif\r
+       printf("\n");\r
+#endif\r
+       //printf("based core left:                      %lu\n", (dword)_basedcoreleft());\r
+       //printf("huge core left:                       %lu\n", (dword)_hugecoreleft());\r
+}\r