View Single Post
Old 07 July 2019, 16:22   #1149
Registered User

Join Date: Oct 2017
Location: Sunderland, England
Posts: 1,406
Originally Posted by spud View Post
@mcgeezer and @ross thanks for posting your sprite-flipping code, that'll be really useful for me!
You are welcome, I actually ditched my reverse byte generator in favour of Ross', but kept my longword reverse code, Ross's generator has a slight error in that d1 needs to be 0 on entry. (I'm sure he won't mind me showing it).

Here is the code now in Rygar.

; Input d1=longword
; Output d1=longword reversed
	movem.l	d0/d2/d3/a0,-(a7)
	lea	BYTE_REVERSE_TAB(a4),a0
	moveq	#8,d3

; Do first 3 bytes
	rept	3
	moveq	#0,d0
	move.b	d1,d0
	move.b	(a0,d0),d2
	lsr.l	d3,d1
	lsl.l	d3,d2

; Final byte but without shift
	moveq	#0,d0
	move.b	d1,d0
	move.b	(a0,d0),d2
	move.l	d2,d1
	movem.l	(a7)+,d0/d2/d3/a0
; Ross's code to generate a byte swap table
; Conisderably more efficient and smaller than my effort.
	movem.l	d0-d3/a0,-(a7)
	moveq	#0,d1
	lea     BYTE_REVERSE_TAB(a4),a0
	moveq   #0,d3
.k:	moveq   #7,d2
	move.b  d3,d0
.l:	add.b   d0,d0
	roxr.b  #1,d1
	dbf     d2,.l
	move.b  d1,(a0)+
	addq.b  #1,d3
	bne.b   .k
	movem.l	(a7)+,d0-d3/a0
mcgeezer is offline  
Page generated in 0.04278 seconds with 11 queries