check_hit_flipper.asm - 89erik/NES-breakout GitHub Wiki

Tree: root /src/loop/check_hit_flipper.asm

This file contains the CheckHitFlipper subroutine which calculates the distance between the ball and the center of the racket. The distance is a signed integer which is returned through register A.

The first half of the subroutine calculates the center position of the racket (the horizontal racket coordinate plus half of the racket width), and subtract this from the center of the ball (the horizontal ball coordinate plus half of the width of sprites) giving the distance.

The second half detects an overflow. Because the processor is only 8 bits, overflows are particularly common when treating values as signed. An overflow is present if the ball is to the right of the racket AND the ball-racket difference is negative. In this case the ball is further away from the racket than what is possible to represent in a signed integer, and the highest possible signed integer is returned.