1 #include "src/lib/16_dbg.h"
\r
2 //#include "src/16.h"
\r
7 boolean dbg_debugpm=0;
\r
9 #ifdef __DEBUG_InputMgr__
\r
10 boolean dbg_testkeyin=0,dbg_testcontrolnoisy=0;
\r
15 // TODO: Could we also provide a build mode to emit debug to the "Bochs E9 hack?"
\r
17 # include <stdarg.h>
\r
18 # include <stdlib.h>
\r
21 unsigned char _DEBUG_INITed = 0;
\r
22 struct info_8250 *_DEBUG_uart = NULL;
\r
25 if (!_DEBUG_INITed) {
\r
29 if (!init_8250()) return 0;
\r
31 // what does the BIOS say the serial ports are?
\r
32 probe_8250_bios_ports();
\r
33 for (i=0;i < bios_8250_ports;i++) {
\r
34 port = get_8250_bios_port(i);
\r
35 if (port == 0) continue;
\r
39 // what about the standard serial ports?
\r
40 for (i=0;i < (sizeof(standard_8250_ports)/sizeof(standard_8250_ports[0]));i++) {
\r
41 port = standard_8250_ports[i];
\r
42 if (port == 0) continue;
\r
46 // pick the first port, which is probably COM1
\r
47 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
48 _DEBUG_uart = &info_8250_port[0];
\r
51 // init the COM port.
\r
52 // in DOSBox-X, the "log" mode will receive our text and print it into the log file
\r
53 // 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
54 // if nothing is connected, then the bytes go off into the ether to get lost and life goes on.
\r
55 uart_8250_enable_interrupt(_DEBUG_uart,0); // disable interrupts
\r
56 uart_8250_set_FIFO(_DEBUG_uart,0x07); // enable FIFO (why not?), also clear xmit/recv FIFO buffers, set threshhold to 1 byte
\r
57 uart_8250_set_MCR(_DEBUG_uart,3); // RTS and DTS on
\r
58 uart_8250_set_line_control(_DEBUG_uart,UART_8250_LCR_8BIT | UART_8250_LCR_PARITY); // 8 bit 1 stop bit odd parity
\r
59 uart_8250_set_baudrate(_DEBUG_uart,uart_8250_baud_to_divisor(_DEBUG_uart,9600)); // 9600 baud
\r
62 return _DEBUG_INITed;
\r
65 void _DEBUG(const char *msg) {
\r
66 if (_DEBUG_uart != NULL) {
\r
69 while ((c=(*msg++)) != 0/*NUL*/) {
\r
70 while (!uart_8250_can_write(_DEBUG_uart)); // wait for the UART to indicate readiness for our output
\r
71 uart_8250_write(_DEBUG_uart,(uint8_t)c); // then write it
\r
76 static char _DEBUGF_TMP[256];
\r
78 void _DEBUGF(const char *fmt,...) {
\r
82 vsnprintf(_DEBUGF_TMP,sizeof(_DEBUGF_TMP),fmt,va);
\r
83 _DEBUG(_DEBUGF_TMP);
\r