4 // TODO: Could we also provide a build mode to emit debug to the "Bochs E9 hack?"
6 unsigned char _DEBUG_INITed = 0;
7 struct info_8250 *_DEBUG_uart = NULL;
14 if (!init_8250()) return 0;
16 // what does the BIOS say the serial ports are?
17 probe_8250_bios_ports();
18 for (i=0;i < bios_8250_ports;i++) {
19 port = get_8250_bios_port(i);
20 if (port == 0) continue;
24 // what about the standard serial ports?
25 for (i=0;i < (sizeof(standard_8250_ports)/sizeof(standard_8250_ports[0]));i++) {
26 port = standard_8250_ports[i];
27 if (port == 0) continue;
31 // pick the first port, which is probably COM1
32 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[]
33 _DEBUG_uart = &info_8250_port[0];
37 // in DOSBox-X, the "log" mode will receive our text and print it into the log file
38 // 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.
39 // if nothing is connected, then the bytes go off into the ether to get lost and life goes on.
40 uart_8250_enable_interrupt(_DEBUG_uart,0); // disable interrupts
41 uart_8250_set_FIFO(_DEBUG_uart,0x07); // enable FIFO (why not?), also clear xmit/recv FIFO buffers, set threshhold to 1 byte
42 uart_8250_set_MCR(_DEBUG_uart,3); // RTS and DTS on
43 uart_8250_set_line_control(_DEBUG_uart,UART_8250_LCR_8BIT | UART_8250_LCR_PARITY); // 8 bit 1 stop bit odd parity
44 uart_8250_set_baudrate(_DEBUG_uart,uart_8250_baud_to_divisor(_DEBUG_uart,9600)); // 9600 baud
50 void _DEBUG(const char *msg) {
51 if (_DEBUG_uart != NULL) {
54 while ((c=(*msg++)) != 0/*NUL*/) {
55 while (!uart_8250_can_write(_DEBUG_uart)); // wait for the UART to indicate readiness for our output
56 uart_8250_write(_DEBUG_uart,(uint8_t)c); // then write it