Pong game in assembly language
I am trying to make a small pong game for my own practice in assembly language as I'm a beginner in this area.
I'm running the code on my x86 64-bit Windows pc. I'm using DOSBox emulator to run my game and test it.
The issue I'm running into is: while trying to draw the ball for my pong game the emulator is displaying a rectangular horizontal line and I cannot fix it to make a square block.
This is the code I have written so far:
STACK SEGMENT PARA STACK
DB 64 DUP (' ')
STACK ENDS
DATA SEGMENT PARA 'DATA'
BALL_X DW 0Ah ;current X position (column) of the ball
BALL_Y DW 0Ah ;current Y position (line) of the ball
BALL_SIZE DW 04h ;size of the ball (how many pixels does the ball have in width and height)
DATA ENDS
CODE SEGMENT PARA 'CODE'
MAIN PROC FAR
ASSUME CS:CODE,DS:DATA,SS:STACK ;assume as code, data and stack segments the respective registers
PUSH DS ; Push the DS segment to the stack
SUB AX, AX ; Clean the AX register
PUSH AX ; Push AX to the stack
MOV AX, DATA ; Load the DATA segment into AX
MOV DS, AX ; Set DS to the DATA segment
POP AX ; Release top item from stack
POP AX ; Release top item from stack
MOV AH, 00h ; Set the video mode configuration
MOV AL, 13h ; Choose the video mode (320x200 256-color VGA mode)
INT 10h ; Execute the configuration
MOV AH, 0Bh ; Set the background color
MOV BH, 00h ; Page number (usually 0)
MOV BL, 00h ; Choose black as the background color
INT 10h ; Execute the configuration
CALL DRAW_BALL
RET
MAIN ENDP
DRAW_BALL PROC NEAR
MOV CX,BALL_X ;set the column (X)
MOV DX,BALL_Y ;set the line (Y)
DRAW_BALL_HORIZONTAL:
MOV AH,0Ch ;set configuration to writing a pixel
MOV AL,0Fh ;set pixel color white
MOV BH,00h ;set the page number
INT 10h ;exec the config
INC CX ;CX = CX+1
MOV AX,CX ;CX - BALL_X > BALL_SIZE (Y-> We go to the next line, N-> We continue to the next column)
SUB AX,BALL_X
CMP AX,BALL_SIZE
JNG DRAW_BALL_HORIZONTAL
MOV CX,BALL_X ;the CX register goes back to initial column
INC DX ;DX = DX + 1
MOV AX,DX ;DX - BALL_Y > BALL_SIZE (Y-> We got to the next line, N-> We continue to the next column)
SUB DX,BALL_Y
CMP AX,BALL_SIZE
JNG DRAW_BALL_HORIZONTAL
RET
DRAW_BALL ENDP
CODE ENDS
The code for the ball is written in DRAW_BALL_HORIZONTAL.
I have tried different iterations to fix it to represent a square block but I'm still not able to do it.
What seems to be the issue here? How do I fix it?
I changed last part of
draw_ball procto this code:and it worked. Because
ball_yis the first line where code starts to draw ball and drawing should end atball_y + 10.