Loading Multiple Versions of an Object

Discussion in 'Discussion and Q&A Archive' started by Psi, Dec 28, 2014.

Thread Status:
Not open for further replies.
  1. Psi

    Psi Well-Known Member Member

    Joined:
    Dec 20, 2014
    Messages:
    102
    This is something of a complex coding request. Does anyone know how to code a routine so that the same object loads multiple times, albeit in different locations from each other and each delayed from another by one frame? Basically, if the object is loaded four times and has an animation of three frames:

    Frame 1: 1

    Frame 2: 1-2

    Frame 3: 1-2-3

    Frame 4:   2-3-4

    Frame 5:      3-4

    Frame 6:         4

    The object will be activated through the player and is coded for Sonic 1.
     
    Last edited by a moderator: Dec 28, 2014
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    http://pastebin.com/GLwJJztz

    Code:
    ; ===========================================================================
    ; ---------------------------------------------------------------------------
    ; Object ??
    ; ---------------------------------------------------------------------------
    
    Obj??:
    		moveq	#$00,d0				; clear d0
    		move.b	$24(a0),d0			; load routine counter
    		move.w	Obj??_Index(pc,d0.w),d0		; load correct relative address
    		jmp	Obj??_Index(pc,d0.w)		; add and jump
    
    ; ---------------------------------------------------------------------------
    ; Index
    ; ---------------------------------------------------------------------------
    
    Obj??_Index:	dc.w	Obj??_Setup-Obj??_Index		; 00
    		dc.w	Obj??_Delay-Obj??_Index		; 02
    		dc.w	Obj??_Run-Obj??_Index		; 04
    
    ; ===========================================================================
    ; ---------------------------------------------------------------------------
    ; Setup routine
    ; ---------------------------------------------------------------------------
    
    Obj??_Setup:
    		addq.b	#$04,$24(a0)			; increase routine counter
    		ori.l	#$00040000|($????/$20),(a0)	; set render modes/VRAM pattern index
    		move.l	#Obj??_Mappings,$04(a0)		; set mapping list address
    		move.l	#$????????,$16(a0)		; set height, width, priority and draw width (HHWWPPDD)
    		st.b	$1A(a0)				; reset animation frame to FF
    		move.b	#$03,$2A(a0)			; set display counter
    		moveq	#$00,d3				; reset delay frame counter
    		move.w	$08(a0),d2			; load current X position
    		moveq	#$04-$01,d1			; set number of objects to load
    
    Obj??_NextObject:
    		jsr	SingleObjLoad2			; find a free object slot "after" this slot
    		bne.s	Obj??_NextBefore		; if there are no slots "after", branch
    		move.l	(a0),(a1)			; copy object ID, render modes and VRAM pattern index
    		move.l	$04(a0),$04(a1)			; copy mapping list
    		move.l	$16(a0),$16(a1)			; copy width/height, etc
    		move.b	$1A(a0),$1A(a1)			; copy animation frame
    		addq.w	#$08,d2				; move to the right
    		move.w	d2,$08(a1)			; set X position
    		move.w	$0C(a0),$0C(a1)			; copy Y position
    		addq.b	#$02,$24(a1)			; set routine counter
    		addq.b	#$01,d3				; increase delay by 1 (Before)
    		move.b	d3,$29(a1)			; set delay amount
    		move.b	$2A(a0),$2A(a1)			; copy display delay amount
    		dbf	d1,Obj??_NextObject		; repeat for all objects
    		bra.s	Obj??_Run			; continue
    
    Obj??_NextBefore:
    		jsr	SingleObjLoad			; find a free object slot
    		bne.s	Obj??_Run			; if there are no slots available, branch
    		move.l	(a0),(a1)			; copy object ID, render modes and VRAM pattern index
    		move.l	$04(a0),$04(a1)			; copy mapping list
    		move.l	$16(a0),$16(a1)			; copy width/height, etc
    		move.b	$1A(a0),$1A(a1)			; copy animation frame
    		addq.w	#$08,d2				; move to the right
    		move.w	d2,$08(a1)			; set X position
    		move.w	$0C(a0),$0C(a1)			; copy Y position
    		addq.b	#$02,$24(a1)			; set routine counter
    		move.b	d3,$29(a1)			; set delay amount
    		addq.b	#$01,d3				; increase delay by 1 (Afterwards)
    		move.b	$2A(a0),$2A(a1)			; copy display delay amount
    		dbf	d1,Obj??_NextBefore		; repeat for all objects
    		bra.s	Obj??_Run			; continue
    
    ; ===========================================================================
    ; ---------------------------------------------------------------------------
    ; Delay routine
    ; ---------------------------------------------------------------------------
    
    Obj??_Delay:
    		subq.b	#$01,$29(a0)			; decrease delay counter
    		bmi.s	Obj??_RunStart			; if finished, branch
    		rts					; return (Wait another frame)
    
    ; ===========================================================================
    ; ---------------------------------------------------------------------------
    ; Running routine
    ; ---------------------------------------------------------------------------
    
    Obj??_RunStart:
    		addq.b	#$02,$24(a0)			; increase routine counter
    
    Obj??_Run:
    		subq.b	#$01,$2A(a0)			; decrease display delay counter
    		bmi.s	Obj??_Delete			; if finished, branch
    		addq.b	#$01,$1A(a0)			; increase animation frame
    		jmp	DisplaySprite			; save object to display list
    
    Obj??_Delete:
    		jmp	DeleteObject			; erase object from SST
    
    ; ===========================================================================
     
    Last edited by a moderator: Dec 28, 2014
Thread Status:
Not open for further replies.