汇编 – 内存映射图形输出

我正在探索使用Memory-Mapped Graphics绘制像素和线条.我在Windows中的Textpad中使用TASM.当我点击运行时,整个屏幕变为蓝色,就是这样,没有绘制像素.

.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
最佳答案
问题似乎与video mode 13h关联的细分市场有关.

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

你的代码做了:

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将使用段来寻址:偏移量(在您的情况下为ES:0)为0A000h:0. 0A000h:0将是物理地址(0A000h <<< 4)0 = 0A0000h. 可以通过将代码更改为:

    push 0A000h
    pop es

转载注明原文:汇编 – 内存映射图形输出 - 代码日志