Snippets

ScorpionIlluminati Routine corrupting d0 and d1

Created by ScorpionIlluminati
SetSpritePosY:
	; Set sprite Y position
	; d0 (b)  - Sprite ID
	; d1 (w)  - Y coord
	; d2 (bb) - Sprite dimensions (width/height in subsprites)
	; d3 (w)  - Sprite height (pixels)
	; d4 (b)  - Y flipped
	; a1 ---- - Subsprite dimensions array
	
	; Correct Y coord for flipping
	cmp.b #0x0, d4
	beq.s @NoFlipY
	add.w d3, d1	; Flipped, working from bottom to top
	@NoFlipY:
	
	; Backup height
	move.w d1, d5
		
	; Loop columns
	clr.l  d3
	move.w d2, d3
	lsr.w  #0x8, d3 ; Num cols to bottom byte
	sub.w  #0x1, d3 ; -1 for loop counter
	@ColLp:
		
		; Reset height
		move.w d5, d1
		
		; Loop rows
		clr.l  d6
		move.w d2, d6
		and.w  #0xFF, d6; Num rows in bottom byte
		sub.w  #0x1, d6 ; -1 for loop counter
		@RowLp:
		
			; If flipped, pre-decrement Y pos
			cmp.b #0x0, d4
			beq.s @NoPreDec
			move.w (a1)+, d7	; Get subsprite width/height from dimensions array
			andi.w #0xFF, d7	; Get height
			mulu   #0x8, d7		; To pixels
			sub.w  d7, d1       ; Working bottom to top, sub height
			@NoPreDec:
		
			; Write X position
			clr.l	d7						; Clear d7
			move.b	d0, d7					; Move sprite ID to d7
	
			mulu.w	#SizeSpriteDesc, d7		; Sprite array offset, Y in first byte
			swap	d7						; Move to upper word
			or.l	#vdp_write_sprite_table, d7	; Add to sprite attr table
	
			move.l	d7, vdp_control			; Set dest address
			move.w	d1, vdp_data			; Move Y pos to data port

			addq.w  #0x1, d0				; Next subsprite ID
		
			; If not flipped, post-increment Y pos
			cmp.b #0x0, d4
			bne.s @NoPostInc
			move.w (a1)+, d7	; Get subsprite width/height from dimensions array
			andi.w #0xFF, d7	; Get height
			mulu   #0x8, d7		; To pixels
			add.w  d7, d1       ; Working top to bottom, add height
			@NoPostInc:
		
			dbra    d6, @RowLp

		dbra d3, @ColLp

	rts

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.