直接写入视频内存

时间:2018-05-19 22:25:28

标签: assembly memory x86-16 vga

我听说int 10h,啊= 0Ch非常慢,为了获得合理的速度,我需要转到内存并将值放入我想要的像素中,我将视频模式设置为{{ 1}}与13h。 改变视频模式的呼吁:

int 10h

这是我为了将像素放在给定坐标中而编写的程序:

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

调用函数的代码:

drawFaster proc
    ; bp + 2 - row (dx)
    ; bp + 4 - column (cx)
    ; bp + 6 - color
    mov bp , sp
    pushad
    mov ax , 0A000h - presumably the memory address of the screen
    mov es , ax
    mov ax , [bp + 2]
    mov bx , [bp + 4]
    mov cx , 320
    mul cx

    add ax , bx
    mov di , ax
    mov ax , [bp + 6]

    mov [es:di] , al 

    popad
    ret 6
endp

但由于某种原因,这没有结果,我不知道内存地址是否不正确或是否有其他内容。我需要你的帮助。谢谢!

奇怪的是,下面的代码工作

    push bp
    mov ax , 30
    push ax
    mov cx , 50
    push cx
    mov dx , 50
    push dx
    call drawFaster
    pop bp

但下面的代码不是:

mov ax , 0A000H
mov es , ax
mov [es:0] , 30

1 个答案:

答案 0 :(得分:0)

我找到了一种解决方法,但它可能不是最好的方法,而不是使用es(因为它不起作用)

我将数据段的地址更改为0A000H

然后我用mov [di] , al更改像素,它可以正常工作!

但是如果你这样做,请务必将数据段的地址移回原来的位置。

我的功能处于工作状态,如果有人感兴趣的话:

drawFaster proc
    ; bp + 2 - row (dx)
    ; bp + 4 - column (cx)
    ; bp + 6 - color
    mov bp , sp ; changing bp to access the stack segment
    ; pushing the values to not lose them in the process of calling the function
    push ax
    push bx
    push cx
    push dx
    mov ax, 0A000h ; 0A000h is the video memory address (for some video modes like 13h)
    mov ds , ax
    mov ax , [bp + 2] ; getting the row ( Y )
    mov bx , [bp + 4] ; getting the column ( X )
    mov cx , 320 ; multiplying the row by 320 to get the offset, and then adding the column
    mul cx

    add ax , bx
    mov di , ax
    mov ax , [bp + 6] ; getting the desired color to paint the pixel in 
    mov [di] , al ; changing the color of the chosen pixel with the desired color
    ; changing the data segment's address back to its original state 
    ; VERY CRUCIAL PLEASE DON'T MISS THIS IF YOU DO IT THE SAME WAY
    mov ax , @data
    mov ds, ax
    ; changing the values back to what they were
    pop dx
    pop cx
    pop bx
    pop ax
    ret 6
endp
相关问题