无法向上移动垂直线(内存映射图形)

时间:2015-10-18 09:37:14

标签: assembly tasm

我试图通过视频模式13向上移动垂直线。但每次我这样做,它都会向下移动。这也是我第一次在内存映射图形中。有人能帮助我吗?我正在使用Tasm / windows

这是我的宏:

drawSquare MACRO color,cy,cx,dy,dx
    mov ah,06
    mov al, 0
    mov bh,color
    mov ch,cy
    mov cl,cx
    mov dh,dy
    mov dl,dx
    int 10h
endm

clearscreen MACRO
    drawSquare 00h, 00h, 00h, 18h, 27h
 endm
include macros.txt
.model small
.stack
.data

saveMode db ?
xVal dw 40
yVal dw 90

R db 0
G db 0
B db 63


lengths dw 0

.code
    main proc
    mov ax, @data
    mov ds, ax

    call SetVideoMode
    call SetScreenBackground       ;blue for the tank


    mov lengths, 20
    call line_vertical
    move:
        mov ah, 07
        int 21h

        cmp al, "w"
        je up
        jmp outA

        up:
        dec yVal
        clearscreen

        mov lengths, 20
        call line_vertical

    jmp move
    outA:

    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, R
    out dx, al

    mov al, G
    out dx, al

    mov al, B
    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 0A000h
    pop es
    ret
SetVideoMode endp

RestoreVideoMode proc
    mov ah, 10h
    int 16h

    mov ah, 0
    mov al, saveMode
    int 10h
    ret
RestoreVideoMode endp

line_horizontal proc
    mov dx, 3c8h
    mov al, 1
    out dx, al

    mov dx, 3c9h
    mov al, 255
    out dx, al
    mov al, 255
    out dx, al
    mov al, 255
    out dx, al

    mov ax, 320
    mul yVal
    add ax, xVal

    mov cx, lengths
    mov di, ax

    L1:
        mov BYTE PTR es:[di], 1
        add di, 1
    loop L1

    ret
line_horizontal endp

line_vertical proc
    mov dx, 3c8h
    mov al, 1
    out dx, al

    mov dx, 3c9h
    mov al, 255
    out dx, al
    mov al, 255
    out dx, al
    mov al, 255
    out dx, al

    mov cx, lengths

    L2:
        mov ax, 320
        mul yVal
        add ax, xVal

        mov di, ax

        mov BYTE PTR es:[di], 1

        inc yVal
    loop L2
    ret
line_vertical endp
end main

1 个答案:

答案 0 :(得分:0)

我最近找到了答案。问题是我只减了一个。我的line_vertical过程从上到下绘制线条。因此,yVal的最新值是该行的底部。要使线向上移动,我需要将其重置回顶部加上我想要移动的像素数。这样做;

yVal - =(行的长度+要移动的像素);

我只需要改变我的

dec yVal

sub yVal, 25

它完美无缺。 :d