]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_dbg.c
[16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / src / lib / 16_dbg.c
index 2215c42002c2acaa5ac9de10655db74ac1efa3a7..db8f71a10365279798763005f247c2be657b22b2 100755 (executable)
-
-#include "src/16.h"
-
-// TODO: Could we also provide a build mode to emit debug to the "Bochs E9 hack?"
-#ifdef DEBUGSERIAL
-# include <stdarg.h>
-# include <stdlib.h>
-# include <stdio.h>
-
-unsigned char _DEBUG_INITed = 0;
-struct info_8250 *_DEBUG_uart = NULL;
-
-int _DEBUG_INIT() {
-       if (!_DEBUG_INITed) {
-               unsigned int i;
-               uint16_t port;
-
-               if (!init_8250()) return 0;
-
-               // what does the BIOS say the serial ports are?
-               probe_8250_bios_ports();
-               for (i=0;i < bios_8250_ports;i++) {
-                       port = get_8250_bios_port(i);
-                       if (port == 0) continue;
-                       probe_8250(port);
-               }
-
-               // what about the standard serial ports?
-               for (i=0;i < (sizeof(standard_8250_ports)/sizeof(standard_8250_ports[0]));i++) {
-                       port = standard_8250_ports[i];
-                       if (port == 0) continue;
-                       probe_8250(port);
-               }
-
-               // pick the first port, which is probably COM1
-               if (base_8250_ports == 0) return 0; // FIXME: You know "base_8250_ports" is probably a bad variable name for the max entries in info_8250_port[]
-               _DEBUG_uart = &info_8250_port[0];
-               _DEBUG_INITed = 1;
-
-               // init the COM port.
-               // in DOSBox-X, the "log" mode will receive our text and print it into the log file
-               // on real hardware, our text will likely go over a null modem cable to another PC running a serial terminal program like PuTTY or minicom.
-               // if nothing is connected, then the bytes go off into the ether to get lost and life goes on.
-               uart_8250_enable_interrupt(_DEBUG_uart,0);      // disable interrupts
-               uart_8250_set_FIFO(_DEBUG_uart,0x07);           // enable FIFO (why not?), also clear xmit/recv FIFO buffers, set threshhold to 1 byte
-               uart_8250_set_MCR(_DEBUG_uart,3);               // RTS and DTS on
-               uart_8250_set_line_control(_DEBUG_uart,UART_8250_LCR_8BIT | UART_8250_LCR_PARITY); // 8 bit 1 stop bit odd parity
-               uart_8250_set_baudrate(_DEBUG_uart,uart_8250_baud_to_divisor(_DEBUG_uart,9600)); // 9600 baud
-       }
-
-       return _DEBUG_INITed;
-}
-
-void _DEBUG(const char *msg) {
-       if (_DEBUG_uart != NULL) {
-               char c;
-
-               while ((c=(*msg++)) != 0/*NUL*/) {
-                       while (!uart_8250_can_write(_DEBUG_uart)); // wait for the UART to indicate readiness for our output
-                       uart_8250_write(_DEBUG_uart,(uint8_t)c); // then write it
-               }
-       }
-}
-
-static char _DEBUGF_TMP[256];
-
-void _DEBUGF(const char *fmt,...) {
-       va_list va;
-
-       va_start(va,fmt);
-       vsnprintf(_DEBUGF_TMP,sizeof(_DEBUGF_TMP),fmt,va);
-       _DEBUG(_DEBUGF_TMP);
-       va_end(va);
-}
-#endif
-
+#include "src/lib/16_dbg.h"\r
+\r
+#ifdef __DEBUG__\r
+#ifdef __DEBUG_MM__\r
+boolean dbg_debugmm=0;\r
+#endif\r
+#ifdef __DEBUG_PM__\r
+boolean dbg_debugpm=0;\r
+#endif\r
+#ifdef __DEBUG_CA__\r
+boolean dbg_debugca=0;\r
+#endif\r
+#ifdef __DEBUG_InputMgr__\r
+boolean dbg_testkeyin=0,dbg_testcontrolnoisy=0,dbg_nointest=0;\r
+#endif\r
+#ifdef __DEBUG_MAP__\r
+boolean dbg_maptext=0;\r
+byte *dbg_mapdata;\r
+#endif\r
+#endif //debug\r
+\r
+#ifdef __WATCOMC__\r
+// TODO: Could we also provide a build mode to emit debug to the "Bochs E9 hack?"\r
+#ifdef DEBUGSERIAL\r
+# include <stdarg.h>\r
+# include <stdlib.h>\r
+# include <stdio.h>\r
+\r
+unsigned char _DEBUG_INITed = 0;\r
+struct info_8250 *_DEBUG_uart = NULL;\r
+\r
+int _DEBUG_INIT() {\r
+       if (!_DEBUG_INITed) {\r
+               unsigned int i;\r
+               uint16_t port;\r
+\r
+               if (!init_8250()) return 0;\r
+\r
+               // what does the BIOS say the serial ports are?\r
+               probe_8250_bios_ports();\r
+               for (i=0;i < bios_8250_ports;i++) {\r
+                       port = get_8250_bios_port(i);\r
+                       if (port == 0) continue;\r
+                       probe_8250(port);\r
+               }\r
+\r
+               // what about the standard serial ports?\r
+               for (i=0;i < (sizeof(standard_8250_ports)/sizeof(standard_8250_ports[0]));i++) {\r
+                       port = standard_8250_ports[i];\r
+                       if (port == 0) continue;\r
+                       probe_8250(port);\r
+               }\r
+\r
+               // pick the first port, which is probably COM1\r
+               if (base_8250_ports == 0) return 0; // FIXME: You know "base_8250_ports" is probably a bad variable name for the max entries in info_8250_port[]\r
+               _DEBUG_uart = &info_8250_port[0];\r
+               _DEBUG_INITed = 1;\r
+\r
+               // init the COM port.\r
+               // in DOSBox-X, the "log" mode will receive our text and print it into the log file\r
+               // on real hardware, our text will likely go over a null modem cable to another PC running a serial terminal program like PuTTY or minicom.\r
+               // if nothing is connected, then the bytes go off into the ether to get lost and life goes on.\r
+               uart_8250_enable_interrupt(_DEBUG_uart,0);      // disable interrupts\r
+               uart_8250_set_FIFO(_DEBUG_uart,0x07);           // enable FIFO (why not?), also clear xmit/recv FIFO buffers, set threshhold to 1 byte\r
+               uart_8250_set_MCR(_DEBUG_uart,3);               // RTS and DTS on\r
+               uart_8250_set_line_control(_DEBUG_uart,UART_8250_LCR_8BIT | UART_8250_LCR_PARITY); // 8 bit 1 stop bit odd parity\r
+               uart_8250_set_baudrate(_DEBUG_uart,uart_8250_baud_to_divisor(_DEBUG_uart,9600)); // 9600 baud\r
+       }\r
+\r
+       return _DEBUG_INITed;\r
+}\r
+\r
+void _DEBUG(const char *msg) {\r
+       if (_DEBUG_uart != NULL) {\r
+               char c;\r
+\r
+               while ((c=(*msg++)) != 0/*NUL*/) {\r
+                       while (!uart_8250_can_write(_DEBUG_uart)); // wait for the UART to indicate readiness for our output\r
+                       uart_8250_write(_DEBUG_uart,(uint8_t)c); // then write it\r
+               }\r
+       }\r
+}\r
+\r
+static char _DEBUGF_TMP[256];\r
+\r
+void _DEBUGF(const char *fmt,...) {\r
+       va_list va;\r
+\r
+       va_start(va,fmt);\r
+       vsnprintf(_DEBUGF_TMP,sizeof(_DEBUGF_TMP),fmt,va);\r
+       _DEBUG(_DEBUGF_TMP);\r
+       va_end(va);\r
+}\r
+#endif //serial\r
+#endif //watcomc\r
+/*\r
+================\r
+=\r
+= ShapeTest\r
+=\r
+================\r
+*/\r
+\r
+#pragma warn -pia\r
+void ShapeTest (global_game_variables_t *gvar)\r
+{\r
+extern word    NumDigi;\r
+extern word    _seg *DigiList;\r
+static char    buf[10];\r
+\r
+       boolean                 done;\r
+       ScanCode                scan;\r
+       int                             i,j;\r
+//     dword           l; word k,x;\r
+       memptr                  addr;\r
+       PageListStruct  far *page;\r
+\r
+//     CenterWindow(20,16);\r
+//     VW_UpdateScreen();\r
+       for (i = 0,done = false;!done;)\r
+       {\r
+//             US_ClearWindow();\r
+//             sound = -1;\r
+\r
+               page = &(gvar->pm.PMPages[i]);\r
+//             US_Print(" Page #");\r
+//             US_PrintUnsigned(i);\r
+               printf(" Page #%u", i);\r
+//++           if (i < (gvar->pm.fi.PMSpriteStart))\r
+//                     US_Print(" (Wall)");\r
+//++                   printf(" (Wall)");\r
+/*             else if (i < (gvar->pm.fi.PMSoundStart))\r
+//                     US_Print(" (Sprite)");\r
+                       printf(" (Sprite)");\r
+               else if (i == (gvar->pm.fi.ChunksInFile - 1))\r
+//                     US_Print(" (Sound Info)");\r
+                       printf(" (Sound Info)");\r
+               else\r
+//                     US_Print(" (Sound)");\r
+                       printf(" (Sound)");*/\r
+\r
+//             US_Print("\n XMS: ");\r
+               printf("\n XMS: ");\r
+               if (page->xmsPage != -1)\r
+//                     US_PrintUnsigned(page->xmsPage);\r
+                       printf("%u", page->xmsPage);\r
+               else\r
+//                     US_Print("No");\r
+                       printf("No");\r
+\r
+//             US_Print("\n Main: ");\r
+               if (page->mainPage != -1)\r
+//                     US_PrintUnsigned(page->mainPage);\r
+                       printf("\n Main: %u", page->mainPage);\r
+               else if (page->emsPage != -1)\r
+               {\r
+//                     US_Print("EMS ");\r
+//                     US_PrintUnsigned(page->emsPage);\r
+                       printf("EMS %u", page->emsPage);\r
+               }\r
+               else\r
+//                     US_Print("No");\r
+                       printf("No");\r
+\r
+//             US_Print("\n Last hit: ");\r
+//             US_PrintUnsigned(page->lastHit);\r
+               printf("\n Last hit: %u", page->lastHit);\r
+\r
+//             US_Print("\n Address: ");\r
+               printf("\n Address: ");\r
+               addr = PM_GetPageAddress(i, gvar);\r
+               sprintf(buf,"0x%04x",(word)addr);\r
+//             US_Print(buf);\r
+               printf("%s", buf);\r
+\r
+               if (addr)\r
+               {\r
+/*                     if (i < PMSpriteStart)\r
+                       {\r
+                       //\r
+                       // draw the wall\r
+                       //\r
+                               bufferofs += 32*SCREENWIDTH;\r
+                               postx = 128;\r
+                               postwidth = 1;\r
+                               postsource = ((long)((unsigned)addr))<<16;\r
+                               for (x=0;x<64;x++,postx++,postsource+=64)\r
+                               {\r
+                                       wallheight[postx] = 256;\r
+                                       FarScalePost ();\r
+                               }\r
+                               bufferofs -= 32*SCREENWIDTH;\r
+                       }\r
+                       else if (i < PMSoundStart)\r
+                       {\r
+                       //\r
+                       // draw the sprite\r
+                       //\r
+                               bufferofs += 32*SCREENWIDTH;\r
+                               SimpleScaleShape (160, i-PMSpriteStart, 64);\r
+                               bufferofs -= 32*SCREENWIDTH;\r
+                       }\r
+                       else if (i == ChunksInFile - 1)\r
+                       {\r
+                               US_Print("\n\n Number of sounds: ");\r
+                               US_PrintUnsigned(NumDigi);\r
+                               for (l = j = k = 0;j < NumDigi;j++)\r
+                               {\r
+                                       l += DigiList[(j * 2) + 1];\r
+                                       k += (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;\r
+                               }\r
+                               US_Print("\n Total bytes: ");\r
+                               US_PrintUnsigned(l);\r
+                               US_Print("\n Total pages: ");\r
+                               US_PrintUnsigned(k);\r
+                       }\r
+                       else\r
+                       {\r
+                               byte far *dp = (byte far *)MK_FP(addr,0);\r
+                               for (j = 0;j < NumDigi;j++)\r
+                               {\r
+                                       k = (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;\r
+                                       if\r
+                                       (\r
+                                               (i >= PMSoundStart + DigiList[j * 2])\r
+                                       &&      (i < PMSoundStart + DigiList[j * 2] + k)\r
+                                       )\r
+                                               break;\r
+                               }\r
+                               if (j < NumDigi)\r
+                               {\r
+//                                     sound = j;\r
+                                       US_Print("\n Sound #");\r
+                                       US_PrintUnsigned(j);\r
+                                       US_Print("\n Segment #");\r
+                                       US_PrintUnsigned(i - PMSoundStart - DigiList[j * 2]);\r
+                               }\r
+                               for (j = 0;j < page->length;j += 32)\r
+                               {\r
+                                       byte v = dp[j];\r
+                                       int v2 = (unsigned)v;\r
+                                       v2 -= 128;\r
+                                       v2 /= 4;\r
+                                       if (v2 < 0)\r
+                                               VWB_Vlin(WindowY + WindowH - 32 + v2,\r
+                                                               WindowY + WindowH - 32,\r
+                                                               WindowX + 8 + (j / 32),BLACK);\r
+                                       else\r
+                                               VWB_Vlin(WindowY + WindowH - 32,\r
+                                                               WindowY + WindowH - 32 + v2,\r
+                                                               WindowX + 8 + (j / 32),BLACK);\r
+                               }\r
+                       }*/\r
+                       printf("\naddr ok\n");\r
+               }\r
+\r
+//             VW_UpdateScreen();\r
+\r
+               while (!(scan = gvar->in.inst->LastScan))\r
+               {\r
+               }\r
+//                     scan = *IN_GetScanName(scan);\r
+//                     SD_Poll();\r
+\r
+if(IN_KeyDown(sc_Escape)) break;\r
+\r
+               IN_ClearKey(scan);\r
+               switch (scan)\r
+               {\r
+               case sc_LeftArrow:\r
+                       if (i)\r
+                               i--;\r
+                       break;\r
+               case sc_RightArrow:\r
+                       if (++i >= (gvar->pm.fi.ChunksInFile))\r
+                               i--;\r
+                       break;\r
+               case sc_W:      // Walls\r
+                       i = 0;\r
+                       break;\r
+               case sc_S:      // Sprites\r
+//                     i = (gvar->pm.fi.PMSpriteStart);\r
+                       break;\r
+               case sc_D:      // Digitized\r
+//                     i = (gvar->pm.fi.PMSoundStart);\r
+                       break;\r
+               case sc_I:      // Digitized info\r
+                       i = (gvar->pm.fi.ChunksInFile - 1);\r
+                       break;\r
+               case sc_L:      // Load all pages\r
+                       for (j = 0;j < (gvar->pm.fi.ChunksInFile);j++)\r
+                               PM_GetPage(j, gvar);\r
+                       break;\r
+               case sc_P:\r
+//                     if (sound != -1)\r
+//                             SD_PlayDigitized(sound);\r
+                       break;\r
+               case sc_Escape:\r
+                       done = true;\r
+                       break;\r
+               case sc_Enter:\r
+                       PM_GetPage(i, gvar);\r
+                       break;\r
+               }\r
+       }\r
+       //SD_StopDigitized();\r
+}\r
+#pragma warn +pia\r