Prev: AD49 Up: Map Next: AE54
AD8B: Load sprite pattern (RST $30)
Ensure sprite pattern is loaded and set screen position. Used by the routine at L801B.
Input
IX Pointer to sprite data
load_sprite_pattern AD8B PUSH HL
AD8C PUSH DE
AD8D PUSH BC
AD8E PUSH IY
AD90 LD E,(IX+$00) DE = Sprite type
AD93 LD D,$00 ...
AD95 LD HL,graphics_pointer_offsets_table Table of offsets for each sprite type into table at graphics_pointers_table
AD98 ADD HL,DE Add sprite type
AD99 LD E,(HL) Get graphics pointer offset for sprite type
AD9A LD HL,graphics_pointers_table Table of pointers to graphics
AD9D ADD HL,DE HL now points to graphics pointer (control word)
AD9E LD A,(IX+$01) Get polar y, which determines which scale we want
ADA1 LD DE,$0000 Pattern index within sprite type
ADA4 BIT 7,A If bit 7 of polar y is set, skip ahead with scale=0
ADA6 JR NZ,load_sprite_pattern_0 ...
ADA8 CP $15 Skip ahead if polar y < 21
ADAA JR C,load_sprite_pattern_0 ...
ADAC INC E Else set scale = 1
ADAD CP $1A Skip ahead if polar y < 26
ADAF JR C,load_sprite_pattern_0 ...
ADB1 INC E Else set scale = 2
ADB2 CP $22 Skip ahead if polar y < 34
ADB4 JR C,load_sprite_pattern_0 ...
ADB6 INC E Else set scale = 3
load_sprite_pattern_0 ADB7 LD A,E A = scale
ADB8 CP (HL) Compare with control word LSB (number of scales for sprite type)
ADB9 JR C,load_sprite_pattern_1 If number of scales > wanted scale, skip next
ADBB LD A,(HL) Requested scale is unavailable
ADBC DEC A so choose the last one.
load_sprite_pattern_1 ADBD INC HL Advance to MSB (rotations)
ADBE LD B,(HL) B = rotations (0 = 2^0 = 1 or 2 = 2^2 = 4)
ADBF LD C,A C = scale
ADC0 LD A,(IX+$02) Get polar x
ADC3 ADD A,$02 Plus 2
ADC5 AND $3F Mod 64
ADC7 LD (IX+$05),A Save in sprite data
ADCA INC B If rotations > 0
ADCB DEC B ...
ADCC JR NZ,load_sprite_pattern_2 Then skip ahead
ADCE XOR A Else set rotation offset = 0
ADCF JR load_sprite_pattern_3 And skip ahead
load_sprite_pattern_2 ADD1 SRL A Divide polar x by 2
ADD3 DJNZ load_sprite_pattern_2 B (rotations) times
ADD5 ADD A,A * 4
ADD6 ADD A,A ...
load_sprite_pattern_3 ADD7 ADD A,C + scale
ADD8 LD B,A Copy result into B, which is the index of pattern to fetch within sprite type
ADD9 CP (IX+$04) Same as existing?
ADDC JR Z,load_sprite_pattern_4 If so, skip ahead
ADDE LD (IX+$04),A Save new value
ADE1 LD L,(IX+$00) HL = Sprite type
ADE4 LD H,$00 ...
ADE6 ADD HL,HL * 2
ADE7 LD DE,sprite_pattern_vdp_addrs_table Table address
ADEA ADD HL,DE sprite_pattern_vdp_addrs_table + sprite type * 2
ADEB LD E,(HL) Get LSB of VDP address
ADEC INC HL TO MSB
ADED LD D,(HL) Get MSB of VDP address
ADEE LD L,B HL = Index of pattern to fetch within sprite type
ADEF LD H,$00 ...
ADF1 ADD HL,HL Multiply by 8
ADF2 ADD HL,HL ...
ADF3 ADD HL,HL ...
ADF4 ADD HL,DE And add base VDP address
ADF5 EX DE,HL Move HL into DE, which becomes source address
ADF6 LD HL,buffer Buffer
ADF9 LD BC,$0008 Read 8 bytes
ADFC CALL $1FE2 READ_VRAM
ADFF LD A,(IX+$0A) Get pattern
AE02 ADD A,A Multiply by 8
AE03 ADD A,A ...
AE04 ADD A,A ...
AE05 LD E,A ...
AE06 LD D,$08 DE = $800 + pattern * 8
AE08 LD HL,buffer Source
AE0B LD BC,$0008 Write 8 bytes
AE0E CALL $1FDF WRITE_VRAM
load_sprite_pattern_4 AE11 LD A,(IX+$00) Get sprite type
AE14 CP $01 If 1, i.e. ship exhaust
AE16 JR Z,load_sprite_pattern_5 Then skip ahead
AE18 LD D,(IX+$01) Polar y
AE1B LD E,(IX+$02) Polar x
AE1E CALL polar_to_screen Polar to screen
AE21 LD (IX+$08),D Set y
AE24 LD (IX+$09),E Set x
AE27 JR C,handle_off_screen_sprite If carry, sprite is outside visible screen, skip ahead
AE29 JR load_sprite_pattern_7 Return
load_sprite_pattern_5 AE2B LD HL,exhaust_position_table If sprite type is ship exhaust, set HL to table address
AE2E LD A,(IX+$04) Pattern index
AE31 AND $03 Mod 4
AE33 JR NZ,load_sprite_pattern_6 If not zero, skip ahead
AE35 LD A,(IX+$05) Get polar x (saved by ADC7)
AE38 RRA / 2
AE39 AND $1E 0, 2, 4 ... $1E
AE3B LD HL,$AFDF exhaust_position_table+2
AE3E RST $08 Add A to HL
load_sprite_pattern_6 AE3F LD A,($700A) Ship screen y
AE42 ADD A,(HL) Add table value
AE43 LD (IX+$08),A Set y
AE46 INC HL Next table address
AE47 LD A,($700B) Ship screen x
AE4A ADD A,(HL) Add table value
AE4B LD (IX+$09),A Set x
This entry point is used by the routines at handle_off_screen_sprite and handle_off_screen_sprite_1.
load_sprite_pattern_7 AE4E POP IY
AE50 POP BC
AE51 POP DE
AE52 POP HL
AE53 RET
Prev: AD49 Up: Map Next: AE54