Mode 13h tutorial
Back to index


Mode 13h is probably the easiest screen mode to display graphics in. It's resolution is 320x200 and it has a 256 color palette.
It's memory is linear and starts at address a000:0000.
Offset 0 is the upper left corner and offset 63999 is in the lower right corner. Each pixel takes up 1 byte of memory so the whole screen takes up 64000 bytes.
It's simple to translate x,y into an offset
offset = y * 320 + x

To enter mode 13h just use the screen interupt

     mov ax,0013h
     int 10h

To exit mode 13h simply return the screen to textmode

     mov ax,0003h
     int 10h

To put a pixel on the screen simply you write something to the screen memory.
Here's a fast way to put a pixel at x,y

    mov ax,0a000h
    mov es,ax
    mov ax,y
    mov bx,y
    shl ax,8
    shl bx,6
    add ax,bx
    add ax,x
    mov di,ax
    mov al,color
    mov es:[di],al

This is how you change one of the colors to a rgb value of your choice.
The red, greeb and blue values needs to be between 0 and 63

    mov dx,3c8h
    mov al,color
    out dx,al
    mov dx,3c9h
    mov al,r
    out dx,al
    mov al,g
    out dx,al
    mov al,b
    out dx,al

And this is how you read a color

    mov dx,3c7h
    mov al,color
    out dx,al
    mov dx,3c9h
    in al,dx
    mov r,al
    in al,dx
    mov g,al
    in al,dx
    mov b,al

Here is a sample program
mode13h.zip (823 bytes)


Jesper L. Poulsen