| ← CA08 | Map | CAF0 → |
CA54: Advance an object one step along its heading
|
Moves an object one step along its heading. It also publishes the heading code for that heading in the per-slot heading-code array.
|
|||||||||||
|
|||||||||||
|
Two jobs per frame. First publish the heading code. The object's heading is mapped through the heading-code table to a heading code in the ball-angle code set. The code goes in the object's cell of the heading-code array. For the ball gem that cell is ball B's heading code. Then, unless the move-freeze flag is set, advance the sprite one step along the heading.
The pixel step equals the movement speed for speeds 0 and 1, and is one less for any greater speed.
The heading chooses which axes move. Rightward headings move X right and leftward headings move it left. Downward headings move Y down and upward headings move it up. So the pure left and right headings move horizontally only, and the pure up and down headings vertically only. The diagonal headings move by the same step on both axes.
|
|||||||||||
| move_object | CA54 | LD A,(IY+$00) | Publish the heading code: map the heading to its heading code and store it in the per-slot array at the object's index C. | ||||||||
| CA57 | LD E,A | ||||||||||
| CA58 | LD D,$00 | ||||||||||
| CA5A | LD HL,heading_dir_table | ||||||||||
| CA5D | ADD HL,DE | ||||||||||
| CA5E | LD A,(HL) | ||||||||||
| CA5F | LD HL,bat_heading | ||||||||||
| CA62 | LD E,C | ||||||||||
| CA63 | ADD HL,DE | ||||||||||
| CA64 | LD (HL),A | ||||||||||
| CA65 | LD A,(move_freeze) | Skip all movement while the move-freeze flag is set; the heading code above is still published. | |||||||||
| CA68 | OR A | ||||||||||
| CA69 | RET NZ | ||||||||||
| CA6A | LD A,(IY+$01) | Take the movement speed as the pixel step, less one above the two slowest speeds. | |||||||||
| CA6D | LD (object_step),A | ||||||||||
| CA70 | OR A | ||||||||||
| CA71 | JR Z,move_object_apply_x | ||||||||||
| CA73 | CP $01 | ||||||||||
| CA75 | JR Z,move_object_parity | ||||||||||
| CA77 | SUB $01 | ||||||||||
| CA79 | LD (object_step),A | ||||||||||
| CA7C | JR move_object_apply_x | ||||||||||
| move_object_parity | CA7E | LD A,($0002) | BUG: at the slowest movement speed, the code tries to move only on alternate frames via a parity flag. But the flag address $0002 is ROM, so the store is discarded and the RET Z never fires. The pixel step keeps its value, and the object still moves a pixel every frame. | ||||||||
| CA81 | XOR $01 | ||||||||||
| CA83 | LD ($0002),A | ||||||||||
| CA86 | RET Z | ||||||||||
| move_object_apply_x | CA87 | LD A,(IY+$00) | Move along X by the heading; 5, 6 and 7 run leftward. | ||||||||
| CA8A | CP $05 | ||||||||||
| CA8C | JR Z,move_object_x_sub | ||||||||||
| CA8E | CP $06 | ||||||||||
| CA90 | JR Z,move_object_x_sub | ||||||||||
| CA92 | CP $07 | ||||||||||
| CA94 | JR NZ,move_object_x_right | ||||||||||
| move_object_x_sub | CA96 | LD A,(object_step) | Those take the step off the position. | ||||||||
| CA99 | LD E,A | ||||||||||
| CA9A | LD A,(IX+$00) | ||||||||||
| CA9D | SUB E | ||||||||||
| CA9E | LD (IX+$00),A | ||||||||||
| CAA1 | JR move_object_apply_y | ||||||||||
| move_object_x_right | CAA3 | CP $01 | Not that heading; the rightward group is the next three. | ||||||||
| CAA5 | JR Z,move_object_x_add | ||||||||||
| CAA7 | CP $02 | ||||||||||
| CAA9 | JR Z,move_object_x_add | ||||||||||
| CAAB | CP $03 | ||||||||||
| CAAD | JR NZ,move_object_apply_y | ||||||||||
| move_object_x_add | CAAF | LD A,(object_step) | Those put the step onto the position. | ||||||||
| CAB2 | ADD A,(IX+$00) | ||||||||||
| CAB5 | LD (IX+$00),A | ||||||||||
| move_object_apply_y | CAB8 | LD A,(IY+$00) | Move along Y by the heading; 7, 0 and 1 run upward. | ||||||||
| CABB | CP $07 | ||||||||||
| CABD | JR Z,move_object_y_sub | ||||||||||
| CABF | CP $00 | ||||||||||
| CAC1 | JR Z,move_object_y_sub | ||||||||||
| CAC3 | CP $01 | ||||||||||
| CAC5 | JR NZ,move_object_y_down | ||||||||||
| move_object_y_sub | CAC7 | LD A,(object_step) | Those take the step off the position. | ||||||||
| CACA | LD E,A | ||||||||||
| CACB | LD A,(IX+$01) | ||||||||||
| CACE | SUB E | ||||||||||
| CACF | LD (IX+$01),A | ||||||||||
| CAD2 | RET | ||||||||||
| move_object_y_down | CAD3 | CP $03 | The downward group is the next three. | ||||||||
| CAD5 | JR Z,move_object_y_add | ||||||||||
| CAD7 | CP $04 | ||||||||||
| CAD9 | JR Z,move_object_y_add | ||||||||||
| CADB | CP $05 | ||||||||||
| CADD | RET NZ | ||||||||||
| move_object_y_add | CADE | LD A,(object_step) | Those put the step onto the position. | ||||||||
| CAE1 | ADD A,(IX+$01) | ||||||||||
| CAE4 | LD (IX+$01),A | ||||||||||
| CAE7 | RET | ||||||||||
| heading_dir_table | CAE8 | DEFB $60 | The heading code for each of the eight headings | ||||||||
| CAE9 | DEFB $57 | ||||||||||
| CAEA | DEFB $4E | ||||||||||
| CAEB | DEFB $8D | ||||||||||
| CAEC | DEFB $84 | ||||||||||
| CAED | DEFB $7B | ||||||||||
| CAEE | DEFB $72 | ||||||||||
| CAEF | DEFB $69 | ||||||||||
| ← CA08 | Map | CAF0 → |
