4

I'm exploring into drawing pixels and lines, using Memory-Mapped Graphics. I'm using TASM in Textpad, in Windows. When I click run the whole screen turns blue and that's it, no pixels drawn.

.model small
.stack
.data  

saveMode db ?
xVal dw ?
yVal dw ?

.code
main proc
mov ax, @data
mov ds, ax

call SetVideoMode
call SetScreenBackground        
call Draw_Some_Pixels
call RestoreVideoMode


mov ax, 4c00h
int 21h
main endp

SetScreenBackground proc
    mov dx, 3c8h
    mov al, 0
    out dx, al

    mov dx, 3c9h
    mov al, 0
    out dx, al

    mov al, 0
    out dx, al
    mov al, 35
    out dx, al
    ret
SetScreenBackground endp 

SetVideoMode proc
    mov ah, 0fh
    int 10h
    mov saveMode, al

    mov ah, 0
    mov al, 13h
    int 10h

    push 0A00h
    pop es
    ret
SetVideoMode endp

RestoreVideoMode proc
    mov ah, 10h
    int 16h

    mov ah, 0
    mov al, saveMode
    int 10h
    ret
RestoreVideoMode endp

Draw_Some_Pixels proc
    mov dx, 3c8h
    mov al, 1
    out dx, al

    mov dx, 3c9h
    mov al, 63
    out dx, al
    mov al, 63
    out dx, al
    mov al, 63
    out dx, al

    mov xVal, 160
    mov yVal, 100

    mov ax, 320
    mul yVal
    add ax, xVal

    mov cx, 10
    mov di, ax

    DP1:
        mov BYTE PTR es:[di], 1

        add di, 5
    Loop DP1
    ret

Draw_Some_Pixels endp
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 1
    I think the video memory you are looking at using is at `a0000` . This code `push 0A00h` `pop es` references `a000` ((a00<<4)+0) . I think you meant to use `push A000h` `pop es` ((a000<<4)+0) = `a0000` – Michael Petch Oct 10 '15 at 06:57
  • @MichaelPetch: `A000h` can be interpreted as label. Better is to decorate it with a null: `0A000h`. – rkhb Oct 10 '15 at 07:24
  • @rkhb : was a typo. I typed the comment up quickly. – Michael Petch Oct 10 '15 at 08:04

1 Answers1

2

The issue seems to be with the segment that video mode 13h is associated with.

After setting the video mode, the next step is to draw something onto the screen. The VGA memory is located at physical address 0xA0000

Your code does:

SetVideoMode proc
    mov ah, 0fh
    int 10h
    mov saveMode, al

    mov ah, 0
    mov al, 13h             ; Video mode 13h
    int 10h

    push 0A00h              ; Incorrect should be 0A000h
    pop es
    ret
SetVideoMode endp

Video mode 13h would be addressed with a segment:offset (ES:0 in your case) of 0A000h:0. 0A000h:0 would be physical address (0A000h << 4) + 0 = 0A0000h.

The code could be fixed by changing it to:

    push 0A000h
    pop es
Michael Petch
  • 46,082
  • 8
  • 107
  • 198