]> 4ch.mooo.com Git - 16.git/blob - 16/fd-dbg.c
fdos debug thingy (16/fd-dbg.c) added for a farcoreleft verification wwww
[16.git] / 16 / fd-dbg.c
1 /*\r
2  *  Defines the functions only necessary while debugging is active\r
3  */\r
4 \r
5 #include "config.h"\r
6 \r
7 #ifdef DEBUG\r
8 \r
9 #include <conio.h>\r
10 #include <stdarg.h>\r
11 #include <stdlib.h>\r
12 #include <stdio.h>\r
13 #include <alloc.h>\r
14 \r
15 #include "command.h"\r
16 \r
17 FILE *dbg_logfile = stdout;\r
18 char *dbg_logname = 0;\r
19 unsigned firstMem = 0;\r
20 \r
21 void dbg_print(const char * const fmt, ...)\r
22 {       va_list ap;\r
23 \r
24         va_start(ap, fmt);\r
25         vfprintf(dbg_logfile, fmt, ap);\r
26         va_end(ap);\r
27         fflush(dbg_logfile);\r
28 }\r
29 \r
30 void dbg_outc(int ch)\r
31 {       putc(ch, dbg_logfile);\r
32 }\r
33 void dbg_outs(const char * const s)\r
34 {       if(s)   fputs(s, dbg_logfile);\r
35         fflush(dbg_logfile);\r
36 }\r
37 void dbg_outsn(const char * const s)\r
38 {       if(s)   fputs(s, dbg_logfile);\r
39         putc('\n', dbg_logfile);\r
40         fflush(dbg_logfile);\r
41 }\r
42 \r
43 \r
44 void dbg_printmem(void)\r
45 { static unsigned nearLast = 0;\r
46   static unsigned long farLast = 0;\r
47 \r
48   unsigned nearThis;\r
49   unsigned long farThis;\r
50 \r
51   switch(heapcheck()) {\r
52   case _HEAPCORRUPT:\r
53     cputs("HEAP CORRUPTED. Cannot proceed!\r\n");\r
54     abort();\r
55   case _HEAPEMPTY:\r
56     cputs("NO HEAP. Cannot proceed!\r\n");\r
57     abort();\r
58   default:\r
59     cputs("Unknown heapcheck() error. Cannot proceed!\r\n");\r
60     abort();\r
61   case _HEAPOK:\r
62     break;\r
63   }\r
64 \r
65   nearThis = coreleft();\r
66   farThis = farcoreleft();\r
67 \r
68   dprintf(("[free memory: near=%6u far=%13lu]\n", nearThis, farThis));\r
69   if(nearLast)\r
70     dprintf(("[changed    : near=%6d far=%13ld]\n"\r
71      , nearThis - nearLast , farThis - farLast));\r
72 \r
73   nearLast = nearThis;\r
74   farLast = farThis;\r
75 }\r
76 \r
77 #endif    /* defined(DEBUG) */\r