x86uartdosboxproteus

How to transmit and receive data through serial UART port in DOSBox


DOS provides a variety of interrupts such as transmitting and receiving a word of data to/from a specific COM port. There are not enough guides on how to do that. After spending much time on it, I finally found the solution. This is a self-answer question and I introduce the solution in the answer section below.

I was simulating an STM32 project with Proteus, but before connecting the UART serial pins to a COMPIM, I tested whether the UART communication channel was working or not.

  1. I connected a virtual terminal to a COMPIM, set the baud rate and other configs, and ran the simulation.enter image description here

  2. Created a null-modem virtual COM port with com0com to connect the Proteus to DOSBox.

  3. Changed DOSBox config files to set serial1 to COM1:

    serial1=directserial realport:COM1  
    
  4. I expected to see printing a character after running this x86 code in DOSBox (v0.74) but nothing happened.

; Initialize the UART configs
MOV AH,0
MOV AL,10100011B
MOV DX,0
INT 14H

; Send a character
MOV AH,01H
MOV AL,'C'
MOV DX,0
INT 14H

This code first sets the baud rate to 2400, with no parity, one stop bit, and 8-bit word. Then sends the C character to serial port.

Now this is my question, what is the right way to transmit a character?


Solution

  • I didn't understand why it was not possible to transmit or receive data with interrupts. Is it a DOSBox bug or my mistake? but found a way instead of using interrupts.

    COM1 has a 0x3F8 IO address in DOS. So if write 8-bit data in this address, it will be sent in this serial port! Like below:

    MOV DX,03F8H
    MOV AL,'C'
    OUT DX,AL
    

    Done :)

    For receiving a character use IN instruction just like the OUT instruction.