Prev: 40359 Up: Map Next: 40527
40446: Send Program Packet
Used by the routine at MainLoop.
Starts a program packet flying from a program transmitter, unless one is already on its way. It queues the messages "PROGRAM SENT FROM" and "SECTOR n".
Input
HL Address of the program transmitter in the map
SendProgramPacket 40446 LD A,(38768) Fetch the type of the program packet (entity 14).
40449 AND A Return if it is already in use.
40450 RET NZ
40451 PUSH HL Save the address of the transmitter...
40452 PUSH HL ...twice.
40453 LD HL,38768 Point HL at ProgramPacketEntity.
40456 LD B,16 Clear all 16 bytes of the entity.
SendProgramPacket_ClearEntity 40458 LD (HL),0 Zero a byte.
40460 INC HL Move on to the next byte.
40461 DJNZ SendProgramPacket_ClearEntity Loop back until the entity has been cleared.
40463 POP HL Restore the address of the transmitter.
40464 LD IX,38768 Point IX at ProgramPacketEntity.
40468 LD (IX+0),110 Set the type of the entity to 110, the first sprite of the program packet.
40472 LD DE,50453 Point DE at Map.
40475 SBC HL,DE Subtract it to find the offset of the transmitter.
40477 LD A,L Fetch the low byte of the offset.
40478 AND 63 The column is in the low six bits.
40480 ADD HL,HL Multiply the offset by four...
40481 ADD HL,HL
40482 LD L,A ...and keep the column in L.
40483 LD A,H The row is in the high byte, in the low six bits.
40484 AND 63 Limit the row to 0-63...
40486 LD H,A ...and keep it in H.
40487 LD A,(38423) Fetch the random number...
40490 AND 63 ...limited to 0-63...
40492 LD (IX+7),A ...as a timer for the program packet.
40495 LD (IX+2),L Set the X cell of the packet to that of the transmitter.
40498 LD (IX+4),H Set the Y cell of the packet to that of the transmitter.
40501 PUSH DE Save the registers.
40502 PUSH BC Save the registers.
40503 LD DE,2 Queue message 2, "PROGRAM SENT FROM"...
40506 CALL QueueMessage ...using QueueMessage.
40509 CALL FindSector Find the sector that the packet is in using FindSector.
40512 LD E,1 Queue message 1, "SECTOR n"...
40514 CALL QueueMessage ...using QueueMessage.
40517 LD HL,261 Start effect 1 (five tones).
40520 LD (38536),HL Store the length and the effect number for PlaySoundStep.
40523 POP BC Restore the registers.
40524 POP DE Restore the registers.
40525 POP HL Restore the address of the transmitter.
40526 RET Return.
Prev: 40359 Up: Map Next: 40527