我最近开始用TASM进行编码,目前正在研究sprites。在我的程序中,我接收一个精灵并在屏幕上打印它(图形模式)。
这个程序基本上运行良好,但是打印出来的数字看起来很奇怪。应该在彼此下方的像素看起来有点遥远。
我就是这样调用这个函数的:
push 10 ; amount of lines
push 10 ; length of each line
push 4 ; color
push 100 ; y
push 160 ; x
push offset card2
call Sprite_Figure以下是功能:
proc Sprite_Figure
push bp
mov bp, sp
push ax
push bx
push cx
push dx
push si
mov si, [bp+4] ; sprite offset
mov cx, [bp+14] ; number of lines
loop1:
mov dx, [bp+12] ; size of one line
loop2:
push dx
xor dx, dx
cmp [byte ptr si], 0
je continue
print:
mov bx, [bp+8] ; current row
mov ax, 320
mul bx
mov bx, ax ; calculation to get location of pixel on screen
add bx, [bp+6] ; x
mov ax, [bp+10] ; color
mov [es:bx], al ; color location, es val is 0A000h
continue:
pop dx
inc si ; next element in array
dec dx
inc [bp+6] ; right by one
cmp dx, 0
jne loop2
mov ax, 320
sub ax, [bp+12] ; the size of one line
add [bp+6], ax ; new line
inc [bp+8] ; one line down
dec cx
cmp cx, 0
jne loop1
pop si
pop dx
pop cx
pop bx
pop ax
pop bp
ret 12
endp Sprite_Figure 这就是精灵在屏幕上的样子:

有人有什么想法吗?
发布于 2022-06-01 17:09:49
代码是混合两种方式下移动一条线!这就解释了为什么代码在屏幕上以双倍的速度下降,值320被增加两次。
基本上,您有几种方法来绘制您的字符矩阵:
线
公司bp+8;向下一条线
适合于第一种方法,而行
mov,320 sub,bp+12;一行的大小加上bp+6,ax;新行
适合第二种方法。
Method1
由于内循环多次递增X坐标,因此为了恢复目的,您必须减去增量的总数:
...
dec dx
jnz loop2
mov ax, [bp+12] ; Size of one line (number of increments)
sub [bp+6], ax ; X is now restored
inc [bp+8] ; Y+ one line down
dec cx
jnz loop1Method2
只使用一次坐标就可以获得BX中的地址。在那之后,只有地址不一样。循环中的指令要少得多,这意味着这是一种更有效的方法。
mov ax, 320
mul [word ptr bp+8] ; Y
mov bx, ax
add bx, [bp+6] ; X
mov si, [bp+4] ; sprite offset
mov cx, [bp+14] ; number of lines
mov al, [bp+10] ; color
loop1:
mov dx, [bp+12] ; size of one line
loop2:
cmp [byte ptr si], 0
je continue
mov [es:bx], al ; ES val is 0A000h
continue:
inc si ; next byte in character pattern
inc bx ; X+ right by one on screen
dec dx
jnz loop2
sub bx, [bp+12] ; Address of left side
add bx, 320 ; Address of new line
dec cx
jnz loop1https://stackoverflow.com/questions/72453882
复制相似问题