Obj_Hit / BXTEST (0xf8ff).
Programmer Manual description:
Symmetric collision test
Entry Address = $F8FF
Maximum Stack Requirements = 10 bytes
A = Box ‘Y’ dimension (delta ‘Y’)
B = Box ‘X’ dimension (delta ‘X’)
X = Y:X coordinates of point to be tested
Y = Y:X coordinates of box center
C = 1 – collision detected
This function might also be called “is point in rectangle?” Since actually no objects or lists are compared, but only coordinates and width/height.
This also means, if you use this function two things are essential if you compare “objects”, it is assumed that two objects are placed on screen with
- The same positioning scale
- The same drawing scale
The “collision” takes two sets of coordinates (high byte y-position, low byte x-position) in registers Y and X (oh this is bad naming… I mean: in register Y is one YX pair of coordinates, and in register X is another YX pair of coordinates).
You can think of one of them being a point and one a rectangle.
The dimension (height and width) of the rectangle is given in register D (A = height/2, B = width/2 – thus the coordinate denotes the center of the rectangle, and the width given is actually the distance of a rectangle side to the center, thus only half).
If a “hit” occurred the carry flag is set, cleared otherwise.
Often this “simple” functionality is enough for a hit detection. If “player” and “enemy” objects are thought of as rectangles (must not be squares like in the example image above) and both (vectorlists) start in the center, good results can be achieved. Even different sizes of player and enemies do not matter, since both width and height can be set manually and can thus respect different sizes. In general register A and register B would countain:
A = playerHeight/2 + enemyHeight/2
B = playerWidth/2 + enemyWidth/2
Which are usually constants…
The ObjHit uses less than 100 cycles and is thus one of the faster BIOS functions.