IMSAI 8080 Console I/O


Introduction to IMSAI 8080 Console I/O

In this section, we’ll send text to the IMSAI 8080 Console I/O. This is useful in your programs for interfacing with the operator. In this case, we’ll be using assembly language. The assembler I’m using is Z80ASM. I’ll just be creating a non-document file in WordStar to edit the program, and I’m operating under CP/M 2.2.

CP/M makes this easy for us through the use of BDOS calls. For this reason, we don’t need to write much logic.

In WordStar, I’m creating a new Non-Document file named HELLO.Z80. This resides on the B: drive.

Writing to the Console

Our Program

Let’s take a look at how we would write data to the console. Here we have a simple program. This is a type of “Hello World” program with just a few lines of code. First, we set the origin of our program. It originates at 0100H. To clarify, the “H” indicates the value is in Hexadecimal.

If you take a look at the function calls in CP/M, you will see that we need a function call 9 to write to the console. Therefore, we load the value of 9 to the C register. Once we BDOS, it will look at the C register to determine which function code to execute.

Meanwhile, we load the STARTING ADDRESS of our text to the register pair DE. Again, BDOS will look at DE to determine where to get the text to write to the console. BDOS will continue reading the string from this text until it encounters the $. This is called the “Termination Character”.

At the same time, you will notice that we have a label called “MYTEXT” toward the bottom of the logic. This defines the starting address of our text. The DB instruction defines bytes which simply contain an ASCII String. In this case, the String is “Good Afternoon!$”. Keep in mind the $ is our termination character.

After we load the address of MYTEXT to DE, we need to call BDOS, which resides at memory location 5H. This will print the string to the terminal. Finally, we CALL 0, which resets, exiting our program.

        ORG 0100H                                                              
        LD C,9H                                                                
        LD DE,MYTEXT                                                            
        CALL 5H                                                                
        CALL 0                                                                 
MYTEXT:                                                                         
        DB "GOOD AFTERNOON!$"                                        
        END            

Save and Assemble

At this point, I’m going to press CTRL-K, then CTRL-X to save my work, and exit WordStar. We are ready to run the assembler. Keep in mind that HELLO.Z80 is on the B drive, which is where I also want the destination file to be. Additionally, I’m saving a full listing to the B drive, which is useful for troubleshooting.

With this purpose in mind, our command will be Z80ASM HELLO.BBB/F. Remember the “.z80” extension is implied.

Reading IMSAI 8080 Console I/O Data

CP/M also provides a BDOS function to read operator input from the keyboard. We’ll take advantage of this feature, and put everything we learned so far together into one program.

In this case, we’ll ask the operator what his name is. After that, we’ll print the name back to the operator. This program will prove that we know how to read and write to the operator console.

Let’s take a look at the program:

; Ask user's name and print that to the console.
BDOS:       EQU     0005H
INBUFLEN    EQU     100
CR:         EQU     13
LF:         EQU     10



            ORG     0100H  ; CP/M PROGRAMS BEGIN HERE
            
            ; PRINT QUESTION TO ASK USER'S NAME
            LD      DE,ASK ; LOAD THE ADDRESS OF THE QUESTION TO ASK NAME
            LD      C,9    ; SET UP FOR BDOS FUNCTION 9
            CALL    BDOS   ; PRINT THE QUESTION TO THE DISPLAY
            
            ; OPERATOR INPUTS NAME
            LD      DE,INBUF ; LOAD DE WITH ADDRESS OF CONSOLE INPUT BUFFER
            LD      A,INBUFLEN    ; MAXIMUM STRING LENGTH WILL BE 100
            LD      (DE), A  ; STORE THE INPUT BUFFER LENGTH TO DE.
            LD      C, 10    ; C WILL CONTAIN THE BDOS FUNCTION CODE
            CALL    BDOS     ; CALL BDOS WHICH READS USER NAME FRO CONSOLE.
            
            ; ANSWER BACK TO THE OPERATOR
            LD      DE, HANSWER ; 
            LD      C,9      ; LOAD C WITH FUNCTION CODE TO WRITE STRING
            CALL    BDOS     ; CALL BDOS 
            
            ; WRITE THE USER'S NAME
            LD      HL,INBUF+1 ; SET HL TO THE ADDRESS OF OPERATOR INPUT
            LD      D,0     ; UPPER DE PAIR TO 0
            LD      E, (HL) ; E CONTAINS HOW MANY CHARACTERS WE HAVE FROM OPERATOR
            ADD     HL,DE   ; HL = HL + DE  TO THE END OF THE STRING
            INC     HL      ; ONE CHARACTER AFTER USER INPUT
            LD      A,'$'   ; WE NEED A $ AT THE END OF USER INPUT
            LD      (HL),A  ; STORE $ AT END OF STRING
            LD      DE,INBUF+2 ; DE WILL BE THE ADDRESS OF THE FIRST CHARACTER
            LD      C,9        ; FUNCTION CODE 9 WHICH WILL PRINT STRING
            CALL    BDOS       ; CALL BDOS TO PRINT THE STRING TO THE SCREEN
            RET     ; BACK TO CPM
            
                      
            
ASK:        DEFB      'WHAT IS YOUR NAME? $' ; DEFINE STARTING BYTE  *
HANSWER:    DEFB      13,10,'HELLO $'        ; DEFINE STARTING BYTE  *
INBUF:      DEFS      INBUFLEN+2             ; DEFINE DATA STRING *
            END

At this point, I’ll press CTRL-K, and CTRL-X to save the file. After that, I’ll type Z80ASM NAME.BBB/F to assemble the file. Finally, we can run the “NAME” program on our B: drive.

For more information, visit the IMSAI 8080 Category Page!

— Ricky Bryce

Leave a comment

Your email address will not be published. Required fields are marked *