assemblyx86-16pong

Pong project in assembly 8086


I have a problem in my pong project. I try that when the ball hits the red bat it will randomly bounce back to the other side, but for some reason it does not recognize the red color. I use AH = 0Dh in int = 10h. The part of the check is in the hitcheck proc.

Here's the code. relevant to my question.

hitcheck    PROC
;------batt and com check-------
MOV BH, 2H
MOV DX, ballx
MOV CX, bally
SUB CX, 2
MOV AH, 0Dh      
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

MOV BH, 2H
MOV DX, ballx
MOV CX, bally
ADD CX, 2
MOV AH, 0Dh            
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

MOV BH, 2H
MOV DX, ballx
MOV CX, bally
SUB DX, 2
MOV AH, 0Dh      
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

MOV BH, 2H
MOV DX, ballx
MOV CX, bally
ADD DX, 2
MOV AH, 0Dh      
INT 10H

CMP AL, 1
JE hitmovement
CMP AL, 3
JE comhitmovement

Solution

  • MOV AL, 13H ;changes the num of pixels to 640X480 with 16 colors
    

    Here the comment does not match the video mode number. Mode 13h has a resolution of 320x200 with 256 colors.

    mov base, 0
    printleftbase:
    printpixel 0, base, 2, 2
    INC base
    CMP base, 199
    JNE printleftbase
    
    mov base, 0
    printrightbase:
    printpixel 319, base, 2, 2
    INC base                   
    CMP base, 199
    JNE printrightbase
    

    If the intent of the previous code is to draw vertical lines running the height of the screen then you need to compare with 200 instead of 199.

    ;------batt and com check-------
    MOV BH, 2H
    MOV DX, ballx
    MOV CX, bally
    SUB CX, 2
    MOV AH, 0Dh      
    INT 10H
    

    In all of your ReadPixel calls you erroneously put the X coord in DX and the Y coord in CX. It's the other way round. Your printpixel macro does is OK.

    Also you print the pixels for batt and com on page 1 but you check for collisions on page 2!

    Question: Does your video adapter even support multiple pages in mode 13h?