put sprite

ZXNet echo conference «code.zx»

From Aleksandr Majorov To Slavka Kalinin 8 August 2000

Hello Slavka! 06 Aug 00 22:49, Slavka Kalinin -> All CODERS !!!: [skipped] SK> In short, when writing a game, I needed the fastest possible one SK> procedure for displaying a sprite 3 or 4 spaces wide and high SK> 16 pixels, output based on familiarity. I wrote the procedure, but it SK> turned out to be not fast enough, after which I decided to turn to It was necessary to think further and conduct experiments. Or disable some kind of program... [skipped] SK> Listing: ...nightmare :)))) [skipped] SK> LD IX,TABLS (ADDRESS TABLE, SCREEN 384 BYTES) SK> .2 ADD IX,BC If you publish a listing, beware of using it such features of your ASMA. Remember that not everyone uses Storm. SK> LD H,(IX+1) SK> LD A,D SK> ADD A,(IX) SK> LD L,A SK> POP BC,DE SK> LD (PTSP1+1),SP SK> LD SP,HL SK> PUSH DE,BC SK> INC H SK> LD A,H SK> AND 7 SK> JP NZ,PTSP1 SK> LD A,L SK> ADD A,32 SK> LD L,A SK> JP C,PTSP1 SK> LD A,H SK> SUB 8 SK> LD H,A I STILL don’t understand this piece! WHY do you calculate the address of the next line on the screen, when do you have a SCREEN ADDRESS TABLE??? SK> PTSP1 LD SP,0 SK> POP BC,DE SK> LD (PTSP2+1),SP SK> LD SP,HL SK> PUSH DE,BC SK> INC H SK> LD A,H SK> AND 7 SK> JP NZ,PTSP2 SK> LD A,L SK> ADD A,32 SK> LD L,A SK> JP C,PTSP2 SK> LD A,H SK> SUB 8 SK> LD H,A SK> PTSP2 LD SP,0 SK> ........ SK> ........ SK> ........ SK> (PTSP SUBROUTINE REPEATS 16 TIMES) Nightmare! ╒═════════════════════════ Home asm1.asm ═════════════════════════╕ ;display the sprite WITHOUT USING the stack SPRT_Y EQU $+2 ;y pointer to the coordinate. Y LD BC,0 LD IX,SCR_ADDR ;ADDRESS TABLE, SCREEN 512 BYTES ADD IX,BC ADD IX,BC LD HL,SPRT_ADDR ;SPRITE ADDRESS LD B,16 OUT_SPRT LD A,(IX+0) LD D,(IX+1) INC IX INC IX SPRT_Y EQU $+1 ;y pointer to the coordinate. X ADD A,0 LD E,A LD C,D LDI ; what are you like LDI ; is there the width of the sprite? LDI ; 3 or 4 familiar places? LDI ; specify! DJNZ OUT_SPRT RET S/n "OUT_SPRT" can be expanded, only in this case you will have to either register the coordinates. X 16 times :) Or store it somewhere :)))))) And here is the output with the stack: ;display the sprite USING the stack OUT_SPRT DI LD(EOUT_SPTR+1),SP SPRT_Y EQU $+1 ;y pointer to the coordinate. Y LD BC,0 LD HL,SCR_ADDR ;ADDRESS TABLE, SCREEN 512 BYTES ADD HL,BC ADD HL,BC LDSP,HL LD HL,SPRT_ADDR ;SPRITE ADDRESS LD B,16 OUT_SPRT POP DE SPRT_Y EQU $+1 ;y pointer to the coordinate. X LD A,0 ADD A,E LD E,ALD C,D LDI ; what are you like LDI ; is there the width of the sprite? LDI ; 3 or 4 familiar places? LDI ; specify! DJNZ OUT_SPRT EOUT_SPTR LD SP,0 RET ;But with “unfolding”: OUT_SPRT DI LD(EOUT_SPTR+1),SP SPRT_Y EQU $+1 ;y pointer to the coordinate. Y LD BC,0 LD HL,SCR_ADDR ;ADDRESS TABLE, SCREEN 512 BYTES ADD HL,BC ADD HL,BC LDSP,HL LD HL,SPRT_ADDR ;SPRITE ADDRESS SPRT_Y EQU $+1 ;y pointer to the coordinate. X LD B,0 ;REPEAT 16 TIMES ;---------------------------------- POP DE ;| LD A,B: ADD A,E: LD E,A ;| LD C,D ;| LDI: LDI: LDI: LDI ;| ;---------------------------------- EOUT_SPTR LD SP,0 RET How to use: LD A,coord_X : LD (SPRT_X),A LD A,coord_Y : LD (SPRT_Y),A CALL OUT_SPRT :-)))) Disadvantages: the sprite goes beyond the border is not checked screen. Those. if if output at X>27, then “tail” The sprite will come out on the left. ╘═════════════════════════ End asm1.asm ═════════════════════════╛ PS: there may be errors and glitches - I typed this right away and did not check it. But I think the idea of ​​the conclusion itself is clear. Alexand