07 March 2019, 13:52 | #1 |
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 |
07 March 2019, 15:06 | #2 |
son of 68k
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 Note that longword ops are painful for 68000 so if possible you should limit this to 16-bit quantities. |
07 March 2019, 15:20 | #3 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
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 |
|
07 March 2019, 15:27 | #4 |
son of 68k
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).
|
07 March 2019, 15:29 | #5 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
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.
|
07 March 2019, 16:01 | #6 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
Quote:
Code:
btst d7,d6 |
|
07 March 2019, 16:13 | #7 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
|
Quote:
Yeah, you guessed it right |
|
07 March 2019, 16:19 | #8 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
|
07 March 2019, 16:28 | #9 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,355
|
|
07 March 2019, 16:48 | #10 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 54
Posts: 4,491
|
|
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 |
|
|