English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 07 March 2019, 13:52   #1
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
ASM Brain Teaser... doing my head in.

I've got a proper brain teaser going on with Rygar at the moment that would make for a good challenge, I still haven't managed it properly so far but I would be interested to see how the other coders would manage it.

Simply put... We have a value in d6 which represents all of the platform positions on the Y axis on any given 16x16 tile.

For example... d6=00000589

Would mean there are currently platforms at row 5, 8 and 9.... they are always in ascending order.

Now in d7 I have the current platform where a sprite is placed, for example d7=5 would mean we are standing on the uppermost platform.

What I need to do is two fold..
1) Check to see if the current platform nybble in d7 exists in any of the nybbles in d6, if it does then we set d6 to be -1

2) Check to see if the current platform nybble in d7 -2 also exists in any of the nybbles in d6, if it does then we set d6 to be -1.

This determines if the sprite will make a jump or not so think along the lines of a an enemy sprite moving right or left and you are checking to see if it needs to jump onto the next platform.

The problem bit I'm having is it has to be done in ascending order (most significant nybble first in the long word) and as fast as possible, it's the fast as possible bit I'm struggling with and keeping everything in registers.

Keep in mind that most of the nybbles in d6 will be 0 left justified, so if you reach a 0 then you can assume the check is complete.

I'll post my solution when it is done.

Geezer
mcgeezer is offline  
Old 07 March 2019, 15:06   #2
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
There is a coding trick to do this, provided some conditions are met :
- d7 would contain $55555555 rather than just 5 (a table lookup can perform the conversion)
- all nibbles of the longword are always checked (so unused ones have to be cleared)
- actual position is unknown, only information we have is that it's there
- I set D6 only for .B
- there is a temporary available (D1 below)

If these are ok, then the code is rather small and fast :
Code:
 eor.l d7,d6          ; this, because below code in fact checks for nibbles =0
 move.l d6,d1
 not.l d6
 sub.l #$11111111,d1
 and.l #$88888888,d6
 and.l d1,d6
 sne d6               ; could have been bne found
Second test is the same, just sub $22222222 from D7 (and copy D6 somewhere).

Note that longword ops are painful for 68000 so if possible you should limit this to 16-bit quantities.
meynaf is offline  
Old 07 March 2019, 15:20   #3
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by meynaf View Post
There is a coding trick to do this, provided some conditions are met :
- d7 would contain $55555555 rather than just 5 (a table lookup can perform the conversion)
- all nibbles of the longword are always checked (so unused ones have to be cleared)
- actual position is unknown, only information we have is that it's there
- I set D6 only for .B
- there is a temporary available (D1 below)

If these are ok, then the code is rather small and fast :
Code:
 eor.l d7,d6          ; this, because below code in fact checks for nibbles =0
 move.l d6,d1
 not.l d6
 sub.l #$11111111,d1
 and.l #$88888888,d6
 and.l d1,d6
 sne d6               ; could have been bne found
Second test is the same, just sub $22222222 from D7 (and copy D6 somewhere).

Note that longword ops are painful for 68000 so if possible you should limit this to 16-bit quantities.


That looks a lot damn faster than my fastest effort!

ugghhh..... I'll get my coat.

Code:
	moveq	#$9,d7		; Current Platform
	move.l	#$79,d6
	bsr	CHECK_NEXT_PLATFORM_POSITION
; d6 will be -1 if no platform or platform two position higher.
	tst.w	d6
	nop
	nop
	

CHECK_NEXT_PLATFORM_POSITION:
	move.w	d7,d5
	subq.b	#2,d5

	move.l	d6,d4
	swap	d4
	
	moveq	#5,d3
.loop1:	subq.b	#1,d3
	beq.s	.block2
	swap	d6
	lsl.l	#4,d6
	swap	d6
	and.w	#$f,d6
	subq.b	#2,d6
	cmp.b	d5,d6
	beq.s	.set_jump
	addq.b	#2,d6
	cmp.b	d7,d6
	beq.s	.set_jump
	bra.s	.loop1
	
	nop
	
.block2:	move.l	d4,d6
	moveq	#5,d3
.loop2:	subq.b	#1,d3
	beq.s	.exit
	swap	d6
	lsl.l	#4,d6
	swap	d6
	and.w	#$f,d6
	subq.b	#2,d6
	cmp.b	d5,d6
	beq.s	.set_jump
	addq.b	#2,d6
	cmp.b	d7,d6
	beq.s	.set_jump
	bra.s	.loop2

.set_jump:	moveq	#-1,d6

.exit:	rts
mcgeezer is offline  
Old 07 March 2019, 15:27   #4
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
There is an even faster way, but it needs data representation to be changed from D6=$00000589 to D6=%1100100000 (value with bits 9,8,5 set to 1).
meynaf is offline  
Old 07 March 2019, 15:29   #5
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by meynaf View Post
There is an even faster way, but it needs data representation to be changed from D6=$00000589 to D6=%1100100000 (value with bits 9,8,5 set to 1).
Where on Earth did you get that code trick from, did you figure that out yourself? I do very much appreciate it, the standard of this forum is awesome.
mcgeezer is offline  
Old 07 March 2019, 16:01   #6
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
Quote:
Originally Posted by meynaf View Post
There is an even faster way, but it needs data representation to be changed from D6=$00000589 to D6=%1100100000 (value with bits 9,8,5 set to 1).

Code:
    btst d7,d6
Quote:
Originally Posted by mcgeezer View Post
Where on Earth did you get that code trick from, did you figure that out yourself? I do very much appreciate it, the standard of this forum is awesome.
There was some interesting coder competition in the past
ross is offline  
Old 07 March 2019, 16:13   #7
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
Quote:
Originally Posted by mcgeezer View Post
Where on Earth did you get that code trick from, did you figure that out yourself? I do very much appreciate it, the standard of this forum is awesome.
Originally this code trick was for checking the presence of a null byte in a longword. It's not my invention, I just found it somewhere on the internet years ago, and adapted it for nibbles.


Quote:
Originally Posted by ross View Post

Code:
    btst d7,d6
Yeah, you guessed it right
meynaf is offline  
Old 07 March 2019, 16:19   #8
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
Quote:
Originally Posted by meynaf View Post
Yeah, you guessed it right
This made me remember one of the probably less used instructions in 68k coding:
Code:
   btst    d7,#%1100100000
A quick check of belonging to a small set of constant values
ross is offline  
Old 07 March 2019, 16:28   #9
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
Quote:
Originally Posted by ross View Post
This made me remember one of the probably less used instructions in 68k coding:
Code:
   btst    d7,#%1100100000
A quick check of belonging to a small set of constant values
Yes, but unfortunately it's limited to 8 bits so your example here doesn't work
meynaf is offline  
Old 07 March 2019, 16:48   #10
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
Quote:
Originally Posted by meynaf View Post
Yes, but unfortunately it's limited to 8 bits so your example here doesn't work
You are right!
So a register mask is the only possibility in this case.
ross is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wonder Girl in Monster Place - New Amiga game teaser by Moya Neil79 project.Amiga Game Factory 39 14 September 2022 00:01
Tool to convert asm to gnu asm (gas) Asman Coders. Asm / Hardware 13 30 December 2020 11:57
Aladdin 4D 6.0 Teaser Screenshots of Application and new Website Pyromania Amiga scene 0 25 September 2009 08:45
Duke Nukem Forever Teaser Releasing Tomorrow P-J Retrogaming General Discussion 15 20 December 2007 23:53

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:16.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08205 seconds with 13 queries