Entity: Difference between revisions
Piranhaplant (talk | contribs) No edit summary |
Piranhaplant (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
An entity is created by calling [[$80:825E]] and providing a pointer to the start of the entity code in the Y register and accumulator. Upon creation, 10 bytes ($00-$09) are copied from the current direct page to the direct page of the new entity. This can be used to provide various parameters to the entity. |
An entity is created by calling [[$80:825E]] and providing a pointer to the start of the entity code in the Y register and accumulator. Upon creation, 10 bytes ($00-$09) are copied from the current direct page to the direct page of the new entity. This can be used to provide various parameters to the entity. |
||
[[$80:8353]] is called to yield control to other entities. The accumulator contains the number of frames before this entity is resumed. Control resumes immediately following the call to $80:8353. Yielding control will preserve the data bank register, processor status register, and direct page register by pushing them onto the stack in that order. No other registers are preserved. |
[[$80:8353]] is called to yield control to other entities. The accumulator contains the number of frames before this entity is resumed. However, an entity may resume early if its [[Sprite#Collision|sprite collision handler]] forces it to. Control resumes immediately following the call to $80:8353. Yielding control will preserve the data bank register, processor status register, and direct page register by pushing them onto the stack in that order. No other registers are preserved. |
Latest revision as of 23:33, 11 July 2024
Entities are used to run multiple distinct things at the same time through a cooperative multitasking system. Almost all code in the game is run as part of an entity. Monsters, the players, weapon projectiles, and even the main game loop are separate entities.
Overview[edit]
Each entity is allocated the following:
- 0x80 bytes in RAM. The direct page will be set to this area, so it can be accessed with $00-$7F.
- 0x30 bytes of stack.
An entity is created by calling $80:825E and providing a pointer to the start of the entity code in the Y register and accumulator. Upon creation, 10 bytes ($00-$09) are copied from the current direct page to the direct page of the new entity. This can be used to provide various parameters to the entity.
$80:8353 is called to yield control to other entities. The accumulator contains the number of frames before this entity is resumed. However, an entity may resume early if its sprite collision handler forces it to. Control resumes immediately following the call to $80:8353. Yielding control will preserve the data bank register, processor status register, and direct page register by pushing them onto the stack in that order. No other registers are preserved.