BIOS Programming

Setting up the display

Before we can show anything on the screen we need to set up the display. There are multiple display modes available and you can seem them by clicking here.

Let's look at video mode 0x3 as an example. This video mode supports color text at a resolution of 80 characters by 25 characters. There are some other details in the table that we will look at later but let's show an example of how to set this to video mode 0x3.

                    
    use16
    org 0x7c00

    mov ah, 0x0
    mov al, 0x3
    int 10h

    510 times ($ - $$) db 0
    0xaa55
                    
                

As you can see we are setting `ah` to 0x0. Interrupt 10h handles all our video needs. There is a table of commands that it will do and when `ah` is set to `0x0` it means set the display. Next, we are setting `al` to `0x3` which is our video mode 0x3. Last step is to call `int 10h` with triggers the video services to look at `ah` and `al` and do what we want them to do.

We are just beginning but there is actually a more efficient way of writing this. We can replace:

                    
    mov ah, 0x0
    mov al, 0x3
    int 10h
                    
                

with

                    
    mov ax, 0x3
    int 10h
                    
                

`ax` is a combination of `ah` and `al`. The high byte will (ah) will be set to 0x0, and the low byte (al) will be set to 0x3. By doing it this way our code will take up 3 bytes rather than 4 bytes.