// bcc -ansi -Md -O iodump.c -o iodump.com #define uartBase 0x2e8 #define uartClock 1843200 // Hz #define uartSpeed 115200 // bps #define uartDivisor (uartClock / (uartSpeed * 16)) #define RHR (uartBase + 0x00) // r #define THR (uartBase + 0x00) // w #define IER (uartBase + 0x01) // rw #define ISR (uartBase + 0x02) // r #define FCR (uartBase + 0x02) // w #define LCR (uartBase + 0x03) // rw #define MCR (uartBase + 0x04) // rw #define LSR (uartBase + 0x05) // r #define DLL (uartBase + 0x00) // rw #define DLM (uartBase + 0x01) // rw unsigned char in_b(unsigned short port) { #asm push bp mov bp, sp mov dx, [bp + 4] in al, dx pop bp #endasm } void out_b(unsigned short port, unsigned char data) { #asm push bp mov bp, sp mov dx, [bp + 4] mov al, [bp + 6] out dx, al pop bp #endasm } int putchar(int c) { while(!(in_b(LSR) & 0x20)); // wait for Tx ready out_b(THR, c); return c; } int getchar(void) { unsigned char s, c; while (1) { s = in_b(LSR); // get status if (s & 0x1f) { // Rx ready c = in_b(RHR); // read from FIFO if (!(s & 0x1e)) break; // no error } } return c; } void inituart(void) { out_b(IER, 0x00); // disable interrupt out_b(LCR, 0x80); // set divisor out_b(DLM, 0xff); // (avoid divisor=0) out_b(DLL, (uartDivisor >> 0) & 0xff); out_b(DLM, (uartDivisor >> 8) & 0xff); out_b(LCR, 0x03); // data 8bit, stop 1bit, non-parity out_b(MCR, 0x03); // RTS#, DTR# assert out_b(FCR, 0x07); // FIFO enable and reset return; } void putx1(unsigned char v) { static unsigned char c[] = "0123456789ABCDEF"; putchar(c[v & 0x0f]); return; } void putx2(unsigned char v) { putx1(v >> 4); putx1(v >> 0); } void putx4(unsigned short v) { putx2(v >> 8); putx2(v >> 0); } void putx8(unsigned long v) { putx4(v >> 16); putx4(v >> 0); } int putstr(char *str) { while (*str) putchar(*str++); return 0; } int main(int argc, char *argv[]) { unsigned int a; inituart(); putstr("Press any key to start\n"); getchar(); a = 0; do { if (!(a % 16)) { putx4(a); putchar(':'); putchar(' '); } putx2(in_b(a)); putchar(' '); a++; if (!(a % 16)) { putchar('\n'); } } while (a != 0); return 0; }