Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ======================================================================
- ; ----------------------------------------------------------------------
- ; Routine to build sprite table in RAM
- ; ----------------------------------------------------------------------
- BldSpr_ScrPos: dc.l 0 ; blank
- dc.l $FFF700 ; main screen x-position
- dc.l $FFF708 ; background x-position 1
- dc.l $FFF718 ; background x-position 2
- ; ======================================================================
- BuildSprites:
- lea (vSpriteBuffer).w,a2 ; RAM-space, where sprites in SMD format will be
- moveq #0,d5 ; d5 will be sprite counter
- lea (vSpriteQueue).w,a4 ; load sprite table
- moveq #7,d7
- @DoLayer:
- tst.w (a4) ; is priority layer empty?
- beq.w @NextLayer ; if yes, branch
- moveq #2,d6
- @DoObject:
- movea.w (a4,d6.w),a0 ; load an object to display
- tst.b (a0) ; is object empty?
- beq.w @NextObject ; if yes, branch
- bclr #7,1(a0) ; clear display flag
- move.b 1(a0),d0
- move.b d0,d4
- andi.w #%1100,d0 ; test coordinate system flags
- beq.s @OnScreenCoords ; if on-screen coordinate system used, branch
- movea.l BldSpr_ScrPos(pc,d0.w),a1
- moveq #0,d0
- move.b $19(a0),d0 ; move H-radius to d0
- move.w 8(a0),d3 ; move X-axis to d3
- sub.w (a1),d3
- move.w d3,d1
- add.w d0,d1
- bmi.w @NextObject ; if object is out of screen, branch
- move.w d3,d1
- sub.w d0,d1
- cmpi.w #$140,d1
- bge.s @NextObject ; if object is out of screen, branch
- addi.w #$80,d3
- btst #4,d4 ; standard height flag set?
- beq.s @StandardHeight ; if not, branch
- moveq #0,d0
- move.b $16(a0),d0 ; move V-radius to d0
- move.w $C(a0),d2 ; move Y-axis to d2
- sub.w 4(a1),d2
- move.w d2,d1
- add.w d0,d1
- bmi.s @NextObject ; if object is out of screen, branch
- move.w d2,d1
- sub.w d0,d1
- cmpi.w #$E0,d1
- bge.s @NextObject ; if object is out of screen, branch
- addi.w #$80,d2
- bra.s @DisplaySprite
- ; ---------------------------------------------------------------------------
- @OnScreenCoords:
- move.w $A(a0),d2
- move.w 8(a0),d3
- bra.s @DisplaySprite
- ; ---------------------------------------------------------------------------
- @StandardHeight:
- move.w $C(a0),d2
- sub.w 4(a1),d2
- addi.w #$80,d2
- cmpi.w #$60,d2
- bcs.s @NextObject ; if object is out of screen, branch
- cmpi.w #$180,d2
- bcc.s @NextObject ; if object is out of screen, branch
- ; ---------------------------------------------------------------------------
- @DisplaySprite:
- movea.l 4(a0),a1 ; load mappings addr
- moveq #0,d1
- btst #5,d4 ; is raw mappings bit set?
- bne.s @DisplayMapFrame; if yes, branch
- move.b $1A(a0),d1 ; get mapping frame
- add.b d1,d1
- adda.w (a1,d1.w),a1 ; load mappings for this frame
- move.b (a1)+,d1 ; get item count in mappings data
- subq.b #1,d1 ; sub 1 from it
- bmi.s @QuitDisplay ; if there mapping frame is empty, branch
- @DisplayMapFrame:
- bsr.w BuildSpriteMap
- @QuitDisplay:
- bset #7,1(a0) ; set display flag
- @NextObject:
- addq.w #2,d6
- subq.w #2,(a4) ; next object in priority layer
- bne.w @DoObject
- @NextLayer:
- lea $80(a4),a4 ; next priority layer
- dbf d7,@DoLayer ; repeat 7 more times
- move.b d5,(vSpriteCount).w ; save sprite counter
- cmpi.b #80,d5 ; are 80 sprites displayed?
- beq.s @SpriteOverflow ; if yes, branch
- move.l #0,(a2) ; cut off sprite buffer
- rts
- @SpriteOverflow:
- move.b #0,-5(a2) ; unlink the last sprite
- rts
- ; ======================================================================
- ; ----------------------------------------------------------------------
- ; Subroutine to build a single sprite mapping
- ; ----------------------------------------------------------------------
- ; INPUT: A0 - Object struct
- ; A1 - Sprite mappings + 1
- ; A2 - Sprite buffer
- ;
- ; D1 - Number of sprites in mapping
- ; D2 - Obj Y-pos on screen
- ; D3 - Obj X-pos on screen
- ; D5 - Sprite counter
- ;
- ; ----------------------------------------------------------------------
- BuildSpriteMap:
- movea.w 2(a0),a3 ; load obj art pointer
- btst #0,d4 ; X flip set?
- bne.s SpriteMap_FlipX ; if yes, branch
- btst #1,d4 ; Y flip set?
- bne.w SpriteMap_FlipY ; if yes, branch
- @DoSprite:
- cmpi.b #$50,d5 ; are 80 sprites displayed?
- beq.s @Return ; if yes, branch
- move.b (a1)+,d0 ; load sprite Y-pos
- ext.w d0
- add.w d2,d0 ; calc absolute Y-pos
- move.w d0,(a2)+ ; SPRITE => Set Y-pos
- move.b (a1)+,(a2)+ ; SPRITE => Render flags
- addq.b #1,d5 ; count this sprite
- move.b d5,(a2)+ ; SPRITE => Link with next sprite
- move.b (a1)+,d0 ;
- lsl.w #8,d0 ;
- move.b (a1)+,d0 ; get start tile
- add.w a3,d0 ; calc absoulute start tile
- move.w d0,(a2)+ ; SPRITE => Start tile + flags
- move.b (a1)+,d0 ; load sprite X-pos
- ext.w d0
- add.w d3,d0 ; calc absolute X-pos
- andi.w #$1FF,d0
- bne.s @NotMasking ; ensure sprite is not masking
- addq.w #1,d0 ; otherwise, fix X-pos
- @NotMasking:
- move.w d0,(a2)+ ; SPRITE => X-ps
- dbf d1,@DoSprite
- @Return:
- rts
- ; ===========================================================================
- SpriteMap_FlipX:
- btst #1,d4
- bne.w SpriteMap_FlipXY
- @DoSprite:
- cmpi.b #$50,d5 ; are 80 sprites displayed?
- beq.s @Return ; if yes, branch
- move.b (a1)+,d0
- ext.w d0
- add.w d2,d0
- move.w d0,(a2)+
- move.b (a1)+,d4
- move.b d4,(a2)+
- addq.b #1,d5
- move.b d5,(a2)+
- move.b (a1)+,d0
- lsl.w #8,d0
- move.b (a1)+,d0
- add.w a3,d0
- eori.w #$800,d0
- move.w d0,(a2)+
- move.b (a1)+,d0
- ext.w d0
- neg.w d0
- add.b d4,d4
- andi.w #$18,d4
- addq.w #8,d4
- sub.w d4,d0
- add.w d3,d0
- andi.w #$1FF,d0
- bne.s @NotMasking
- addq.w #1,d0
- @NotMasking:
- move.w d0,(a2)+
- dbf d1,@DoSprite
- @Return:
- rts
- ; ===========================================================================
- SpriteMap_FlipY:
- cmpi.b #$50,d5 ; are 80 sprites displayed?
- beq.s @Return ; if yes, branch
- move.b (a1)+,d0
- move.b (a1),d4
- ext.w d0
- neg.w d0
- lsl.b #3,d4
- andi.w #$18,d4
- addq.w #8,d4
- sub.w d4,d0
- add.w d2,d0
- move.w d0,(a2)+
- move.b (a1)+,(a2)+
- addq.b #1,d5
- move.b d5,(a2)+
- move.b (a1)+,d0
- lsl.w #8,d0
- move.b (a1)+,d0
- add.w a3,d0
- eori.w #$1000,d0
- move.w d0,(a2)+
- move.b (a1)+,d0
- ext.w d0
- add.w d3,d0
- andi.w #$1FF,d0
- bne.s @NotMasking
- addq.w #1,d0
- @NotMasking:
- move.w d0,(a2)+
- dbf d1,SpriteMap_FlipY
- @Return:
- rts
- ; ===========================================================================
- SpriteMap_FlipXY:
- cmpi.b #$50,d5 ; are 80 sprites displayed?
- beq.s @Return ; if yes, branch
- move.b (a1)+,d0
- move.b (a1),d4
- ext.w d0
- neg.w d0
- lsl.b #3,d4
- andi.w #$18,d4
- addq.w #8,d4
- sub.w d4,d0
- add.w d2,d0
- move.w d0,(a2)+
- move.b (a1)+,d4
- move.b d4,(a2)+
- addq.b #1,d5
- move.b d5,(a2)+
- move.b (a1)+,d0
- lsl.w #8,d0
- move.b (a1)+,d0
- add.w a3,d0
- eori.w #$1800,d0
- move.w d0,(a2)+
- move.b (a1)+,d0
- ext.w d0
- neg.w d0
- add.b d4,d4
- andi.w #$18,d4
- addq.w #8,d4
- sub.w d4,d0
- add.w d3,d0
- andi.w #$1FF,d0
- bne.s @NotMasking
- addq.w #1,d0
- @NotMasking:
- move.w d0,(a2)+
- dbf d1,SpriteMap_FlipXY
- @Return:
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement