# HG changeset patch # User Mike Pavone # Date 1378667822 25200 # Node ID 166d58b234c31d38965e43ee740cc7c9d1d35764 # Parent 30f1d4c90900621a45b29a741e340e13eef4e511 Added my old sprite library I forgot to add earlier diff -r 30f1d4c90900 -r 166d58b234c3 sprites.s68 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sprites.s68 Sun Sep 08 12:17:02 2013 -0700 @@ -0,0 +1,269 @@ +;Sprite Management Library +;Copyright 2003 by Mike Pavone a.k.a. Mask of Destiny +; +;This library manages the allocation and deallocation of sprites for use with the Genesis VDP +;Keep in mind that you shouldn't play with the link field of your sprites when using this library +; + +SpriteTable equ $FFFFF000 +SpriteTable4 equ SpriteTable+4 +SpriteLink equ SpriteTable+3 + + +;InitSprites - This initializes the library, call it once before using the any of the other functions +;Doesn't effect any registers + +InitSprites: + move.l #0,(SpriteTable).w + move.l #0,(SpriteTable4).w + rts + +;AddSprites - Adds a sprite to the sprite list and initializes it's entry. Returns pointer to sprite list +;entry in A0, destroys data in a0, d2, d1 and d0 + +AddSprite: + lea (SpriteLink).w,a0 + moveq #0,d2 + moveq #0,d0 + + tst.b (FirstSprite) + beq FoundFirst + + + moveq #78,d1 +FindEmpty: + move.b (a0),d0 + tst.b d0 + beq FoundEmpty + + sub.b d2,d0 + cmp.b #1,d0 + bne FoundEmpty + add.b #1,d2 + add.l #8,a0 + dbra d1,FindEmpty + + move.l #0,a0 + rts + +FoundFirst: + sub.l #3,a0 + move.b #1,(FirstSprite) + bra CopyDefaultSprite + +FoundEmpty: + move.b (a0),d0 + add.b #1,d2 + move.b d2,(a0) + add.l #5,a0 + +CopyDefaultSprite: + move.w #144,(a0)+ + move.b $0,(a0)+ + move.b d0,(a0)+ + move.l #144,(a0) + sub.l #4,a0 + + rts + + +DefaultSprite: ;not actually used, just there for reference + dc.b $0, $20, $0, $0, $0, $0, $0, $20 +FirstSprite + dc.w $0 + + +;FreeSprite - Deletes a sprite from the sprite table. Takes a pointer to the sprite table entry to be removed in a0 + +FreeSprite: + move.l a0,d0 + move.b 3(a0),d2 + sub.w #SpriteTable,d0 + lsr.w #3,d0 + + + + + lea (SpriteLink).w,a0 +FindPrecedingSprite: + move.b (a0),d1 + beq PrecedingSpriteNotFound + + cmp.b d1,d0 + beq FoundPrecedingSprite + + add.l #8,a0 + + bra FindPrecedingSprite + +FoundPrecedingSprite: + move.b d2,(a0) + +PrecedingSpriteNotFound: + rts + + + +;SpriteCopyVRAM - Copies the sprite table from RAM to VRAM. Should be called once every frame during VBLANK. Expects addresses for VDP to +;be in A4 and A5 and that auto-increment is set appropriately + +SpriteCopyVRAM: + move.l #$95009678,(a5) ;setup DMA source + move.w #$977F,(a5) + move.l #$93409401,(a5) ;set DMA length + move.l #$78000083,(a5) ;Do DMA to sprite table + + rts + + lea (SpriteTable).w,a0 + move.l #$78000003,(a5) ;VDP command word for sprite table + + moveq #39,d0 +SpriteCopyLoop: + move.l (a0)+,(a4) + move.l (a0)+,(a4) + move.l (a0)+,(a4) + move.l (a0)+,(a4) + dbra d0,SpriteCopyLoop + + rts +Stuff: + dc.b 0 +Stuffb: + dc.b 0 + dc.w 0 + +AddBigSprite: + move.w (a1)+,d3 + lea BigSpritePointerTable(pc),a2 + subq #1,d3 ;change back to a sub 1 + +BigSpriteMapLoop: + bsr AddSprite + move.w #$265D,d1 + move.b (a1)+,2(a0) + add.b (a1)+,d1 + move.w d1,4(a0) + move.b (a1)+,d1 + add.b d1,7(a0) + move.b (a1)+,d1 + add.b d1,1(a0) + move.l a0,(a2)+ + dbra d3,BigSpriteMapLoop + + move.l #0,(a2) + + move.w (a1)+,d0 + move.w #$9360,(a5) + move.w #$9404,(a5) + + move.l a1,d7 + move.w #$9500,d6 + ror.l #1,d7 + move.b d7,d6 + move.w d6,(a5) + ror.l #8,d7 + move.b d7,d6 + add.w #$100,d6 + move.w d6,(a5) + ror.l #8,d7 + move.b d7,d6 + add.w #$100,d6 + and.b #$7F,d6 + move.w d6,(a5) + + move.l #$4BA00083,(a5) + +;SpriteLoop: +; move.w (a1)+,(a4) +; dbra d0,SpriteLoop + +; move.l (BigSpriteXPos),(BigSpriteXPosOld) + +; move.l #$00900090,(BigSpriteXPos) + rts + +FreeBigSprite: + lea BigSpritePointerTable(pc),a1 +BigSpriteFreeLoop: + move.l (a1)+,d0 + beq BigspriteFreeDone + move.l d0,a0 + bsr FreeSprite + bra BigSpriteFreeLoop + + +BigspriteFreeDone: + rts + +ChangeFrameBigSprite: + lea BigSpriteFrameTable(pc),a2 +; move.l (a2),d0 +; beq OldFreeBigSprite + + bsr FreeBigSprite + +OldFreeBigSprite: + add.l d3,d3 + add.l d3,d3 + add.l d3,a2 + + move.l (a2),a1 + + bsr AddBigSprite + + move.w (BigSpriteXPos),d0 + move.w (BigSpriteYPos),d1 + bsr MoveBigSprite + move.w d0,(BigSpriteXPos) + move.w d1,(BigSpriteYPos) + + rts + +InitFrameBigSprite: + lea BigSpriteFrameTable(pc),a1 +InitFrameBigSpriteLoop: + move.l (a0)+,d0 + beq DoneInitBigSprite + move.l a0,(a1)+ + add.l d0,a0 + bra InitFrameBigSpriteLoop + +DoneInitBigSprite: + move.l a0,(a1)+ + move.l #0,(a1) + move.l a0,a1 + bsr AddBigSprite + rts + + +MoveBigSprite: + lea BigSpritePointerTable(pc),a0 +BigSpriteMoveLoop: + move.l (a0)+,a1 + move.l a1,d2 + beq BigSpriteMoveDone + add.w d1,(a1) + + add.w d0,6(a1) + bra BigSpriteMoveLoop +BigSpriteMoveDone: + add.w d1,(BigSpriteYPos) + add.w d0,(BigSpriteXPos) + rts + + +; include sendrecv.asm + +BigSpritePointerTable: + dc.l 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +BigSpriteFrameTable: + dc.l 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +BigSpriteXPos: + dc.w 0 +BigSpriteYPos: + dc.w 0 +BigSpriteXPosOld: + dc.w 0 +BigSpriteYPosOld: + dc.w $0