Deja Vu #05
31 мая 1998 |
|
CODING - Using a stack interrupt enable.
SoundTrack: SECTOR / SERIOUS S.G. '97 (CMG98) __________________________________________ (C) RLA / CRG __________________________________________ Stack Usage When resolving PREREYVANIYAH It is no secret that for fast manipulation with graphics in games and, especially, in the demonstrations are commonly used commands stack. With their help, you can achieve the greatest rate of work with graphics. However, the steeper the effect, the longer it takes. There may be occasions when effect does not have time to work out 69,888 cycles and an interrupt occurs. Return address discarded onto the stack and irreversibly damages contained underneath the information. But not all lost. We consider several cases as You can save the data and work with stack enabled interrupts the second kind. 1. If there is a clearing or filling the screen with any data, it is not so scary, because when you return from interrupt PUSH HL continue the cycle and the return address will be overwritten by the required data. 1.1 It is possible that the stack will be equal to 4000h and the return address will be lost, but this case can be controlled if you know address those points in which this can happen and go there not to RET'u and JP ADDRESS. Example: LD SP, # 4020, net the most LD HL, # 0000 top line PUSH HL; in the screen PUSH HL PUSH HL ... * 16 times PUSH HL PUSH HL ADR1 LD SP, (SAVESP) RET The latter case is possible if the interruption wedged between the teams PUSH HL and LD SP, (SAVESP). Handler 2 (!) Interrupts in this case would look like: ORG # BFBF INT2 DI LD (TOSP +1), SP LD SP, INT2-1 PUSH HL PUSH DE PUSH BC PUSH AF PUSH IX EXX EX AF, AF PUSH HL PUSH DE PUSH BC PUSH AF PUSH IY LD HL, (TOSP +1) LD DE, - # 4000 ADD HL, DE LD A, # C9; RET JR C, OK LD A, # C3; JP LD (TO_RET), A ... treatment interruption POP IY POP AF POP BC POP DE POP HL EXX EX AF, AF POP IX POP AF POP BC POP DE POP HL EI TOSP LD SP, 0 TO_RET DB 0 DW ADR1 2. There is another insidious case where data through the stack will not be recorded, and read. Most often it is consumed, when the screen is moving most of it Part (TRASH DEMO, ART'98, all sorts of intros to the games). In memory of pre-created great sprite and displayed on the screen roughly the chain of bytes: POP HL LD (# 4000), HL POP HL LD (# 4002), HL ... POP HL LD (# 57FE), HL LD SP, (SAVESP) RET In these programs, part of the screen time to exchange a per interrupt, and this problem does not arise, but there were cases, when running a single effect, and then need to throw the top window with the wishes of or GTX'ami. If an interrupt, then the stack is dropped again return address and the sprite will be "permanently damaged. It is in such a case appealed to me one of my friends coder. After some time the problem was solved. Its effects worked in the interrupt enable, and graphics are not spoiled. Processor: ORG # BFBF INT2 DI LD (TOSP +1), SP LD SP, INT2-1 PUSH HL PUSH DE PUSH BC PUSH AF PUSH IX EXX EX AF, AF PUSH HL PUSH DE PUSH BC PUSH AF PUSH IY LD HL, (TOSP +1) LD E, (HL) INC HL LD D, (HL) LD (_JP +1), DE ... treatment interruption POP IY POP AF POP BC POP DE POP HL EXX EX AF, AF POP IX POP AF POP BC POP DE POP HL TOSP LD SP, 0 PUSH HL; Record POP HL; Adjustment stack EI _JP JP 0 Consider the possible cases when an interrupt can occur: a) between the teams and POP HL LD (NN), HL Reads a byte in register HL and before returning to the team will be recorded PUSH HL. b) between the commands LD (NN), HL POP HL and data again are in the HL and recover the same manner. It is worth noting that the return from the handler will always be performed by direct transition. I note that demonstrations such workarounds tricks with the stack I have not met. I hope that this paper will reduce the work of some of your effects on the excess 10-20 thousand cycles are so impeded make your impact on the Int faster.
Other articles:
Similar articles:
В этот день... 21 November