内存映射图形输出 [英] Memory-Mapped Graphics Output

查看:72
本文介绍了内存映射图形输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索使用内存映射图形绘制像素和线条.我在Windows的Textpad中使用TASM.当我单击运行时,整个屏幕变成蓝色,仅此而已,没有绘制像素.

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

推荐答案

问题似乎出在

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

设置视频模式后,下一步是在屏幕上绘制一些内容. VGA内存位于物理地址0xA0000

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将以0A000h:0的segment:offset(在您的情况下为 ES:0 )寻址. 0A000h:0是物理地址(0A000h<< 4)+ 0 = 0A0000h.

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

这篇关于内存映射图形输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆