Graphic output with memory

I study drawings of pixels and lines using graphics with memory mapping. I use TASM on Textpad, on Windows. When I press the start button, the whole screen turns blue, and this is without pixels.

.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
+4
source share
1 answer

The problem is with the segment that the 13h video mode is associated with .

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

Your code has:

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

13h video mode will be addressed by: offset (ES: 0 in your case) 0A000h:0. 0A000h:0will be the physical address (0A000h <4) + 0 = 0A0000h.

The code can be fixed by changing it to:

    push 0A000h
    pop es
+2

Source: https://habr.com/ru/post/1611058/


All Articles