直接写入视频内存



我听说int 10h,ah = 0Ch很慢,为了获得合理的速度,我需要去内存并将值放入我想要的像素中,我将视频模式设置为13hint 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

但以下代码段没有:

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

我找到了解决方法,但这可能不是最好的方法,而不是使用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

最新更新