Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem with x86 drawing code

sk34991sk34991 Member Posts: 2
Hey all,
I am new here. I am also new to x86. I am trying to program a paddel moving up and down across the left side of the screen, but for some reason (and I have tried to figure this out for days) it will draw the paddle whereever, but when I hit Q or A to move it up or down, it will only move up and down on the top half of the screen, the initial image stays on the bottom half but it wont move on the bottom half. I am really confuse. Can someone please help me. Thanks

Here's the code:



jmp start

;=========================================
; Basic program test game
;=========================================
mode db 18 ;640 x 480
x_start dw 40
y_start dw 40
x_end dw 600
y_end dw 440
deadcolor db 4
colour db 1 ;1=blue
black db 0
;BALL RELATED--------------------------------
ballcolor db 15
ball_position_x dw 150
ball_position_y dw 200
old_ball_pos_x dw 0
old_ball_pos_y dw 0
x_dir dw 1
y_dir dw 1
;PADDLE RELATED:-----------------------------
paddlecolor db 3
pad_start_x dw 80
pad_end_x dw 84 ;81
paddle_pos_start_y dw 350
paddle_pos_end_y dw 400
old_pad_pos_start_y dw 0
old_pad_pos_end_y dw 0
pad_move dw 5
pad_move_neg dw -5
;=========================================




start:
mov ah,00 ;subfunction 0
mov al,mode ;select mode 18 (or 12h if prefer)
int 10h ;call graphics interrupt




read_move_key:
mov ah,01
int 16h
jz draw_paddle ;(if no keystroke, skip retrieve)
retrieve_key:
mov ah,00
int 16h ;wait for keypress
comp_a:
CMP al,61h ;compare to a
jnz comp_q ;if(key == a) goto a_key_handle
mov bx,pad_move
add bx, paddle_pos_start_y ;pad_pos_start_y += pad_move
mov paddle_pos_start_y,bx
mov bx,pad_move
add bx, paddle_pos_end_y ;pad_pos_end_y += pad_move
mov paddle_pos_end_y, bx
jmp draw_paddle
comp_q:
CMP al,71h ;compare to a
jnz comp_esc ;if(key == a) goto a_key_handle
mov bx,pad_move_neg
add bx, paddle_pos_start_y ;pad_pos_start_y += pad_move
mov paddle_pos_start_y,bx
mov bx,pad_move_neg
add bx, paddle_pos_end_y ;pad_pos_end_y += pad_move
mov paddle_pos_end_y, bx
jmp draw_paddle
comp_esc:
CMP al,27 ;cmp to esc
jz endit ;if(key == esc) quit
;ELSE: fall down to draw paddle

draw_paddle:
mov al,paddlecolor ;colour goes in al
mov ah,0ch
mov cx, pad_start_x ;start drawing lines along x
drawha:
mov dx, paddle_pos_end_y ;put point at bottom
int 10h
mov dx, paddle_pos_start_y ;put point on top
int 10h
inc cx ;move to next point
cmp cx, pad_end_x ;but check to see if its end
jnz drawha
drawve: ;dx already set
mov cx, pad_start_x ;plot on left side
int 10h
mov cx, pad_end_x ;plot on right side
int 10h
inc dx ;move down to next point
cmp dx, paddle_pos_end_y ;check for end
jnz drawve

mov old_pad_pos_start_y, paddle_pos_start_y
mov old_pad_pos_end_y, paddle_pos_end_y

jmp read_move_key

endit:
mov ah,00 ;again subfunc 0
mov al,03 ;text mode 3
int 10h ;call int
mov ah,04ch
mov al,00 ;end program normally
int 21h ;was call update


Comments

  • sk34991sk34991 Member Posts: 2

    Here is another try, this time it won't delete the paddle below the same line that breaks every other version. A pic is included.

    draw_loop:
    mov al,ballcolor ;color goes in al
    mov ah,0ch
    int 10h

    mov ax, -1
    ;neg ax
    adc dx, ax

    dec bx
    cmp bx, 0
    jnz draw_loop


    mov old_ball_pos_x, ball_position_x
    mov old_ball_pos_y, ball_position_y




    ;--Read UP or DOWN arrow Key--
    read_move_key:
    mov ah,01
    int 16h
    jz draw_dot ;(if no keystroke, skip retrieve)
    retrieve_key:
    mov ah,00
    int 16h ;wait for keypress
    comp_q:
    CMP al,71h ;CMP to q
    jnz comp_a ;if(key == q) goto q_key_handle
    mov old_ball_pos_y, ball_position_y
    adc ball_position_y , -1
    jmp draw_dot
    comp_a:
    CMP al,61h ;compare to a
    jnz comp_esc ;if(key == a) goto a_key_handle
    mov old_ball_pos_y, ball_position_y
    adc ball_position_y , 1
    CALL ERASE_ABOVE
    jmp draw_dot
    comp_esc:
    CMP al,27 ;cmp to esc
    jz endit ;if(key == esc) quit

    jmp draw_dot






    ERASE_ABOVE:
    mov dx, old_ball_pos_y
    mov cx, ball_position_x
    mov bx, old_ball_pos_y
    sbb bx, pad_size
    erase_loop2: ;remove old ball
    mov al,black ;colour goes in al
    mov ah,0ch
    int 10h ;draw
    adc dx, mark
    cmp dx, bx
    jnz erase_loop2
    ret



    endit:
    mov ah,00 ;again subfunc 0
    mov al,03 ;text mode 3
    int 10h ;call int
    mov ah,04ch
    mov al,00 ;end program normally
    int 21h ;was call update




    [img=null]
Sign In or Register to comment.