18 November 2014, 22:40 | #41 | |||
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
Code:
move.w joy1dat(a5),d0 and.w #$0303,d0 Quote:
Quote:
|
|||
18 November 2014, 22:41 | #42 |
Glastonbridge Software
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
|
because you might want to treat each direction (that is, vertical and horizontal) independently, regardless of diagonals.
|
18 November 2014, 22:51 | #43 | |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 372
|
Quote:
There's nothing that says the addresses in the table have to point back directly into the game code. The destination addresses for the jmp (a0) could just as well all be small code snippits, all ending in rts, that place arbitrary values in any location convenient to the game's code. |
|
18 November 2014, 23:13 | #44 | |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 372
|
Quote:
I just find it enjoyable to try and puzzle out faster and faster code. I can't be the only one here that thinks that's fun. |
|
18 November 2014, 23:53 | #45 |
Glastonbridge Software
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
|
yeah i love cycle shaving, pointless though it can be
|
19 November 2014, 00:01 | #46 | ||
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
Quote:
Anyway, how about this (for the heck of it): Code:
move.w joy1dat(a5),d0 and.w #$0303,d0 move.w d0,d1 add.w d1,d1 add.w #$0101,d0 add.w d1,d0 Code:
Bits: 01 = right 02 = down 09 = left 10 = up |
||
19 November 2014, 03:45 | #47 |
Registered User
Join Date: Jan 2012
Location: USA
Posts: 372
|
Oh, that's fast for sure, Thorham.
What's cool is the code starts to look a bit like SIMD. And the obvious extension with longs to handle joy2dat too let's you process 4 pairs of bits at a time. Nice. |
19 November 2014, 11:23 | #48 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
Code:
move.l joy0dat(a5),d0 and.l #$03030303,d0 move.l d0,d1 add.l d1,d1 add.l #$01010101,d0 add.l d1,d0 Bits: direction joy0dat joy1dat right 17 1 down 18 2 left 25 9 up 26 10 |
|
19 November 2014, 19:07 | #49 |
Beyond Mutton
Join Date: Mar 2011
Location: North West, UK
Age: 52
Posts: 347
|
Calm down dear, its just a question ;)
EDIT: I didn't want to start a new thread as this one is very active at the moment - hope its not too OT..
Would this code be OK for reading buttons 1 and 2 in the routine? Code:
; ReadJoystick - Reads joystick port 2 and populates variables ; EXIT: All "JOY" variables are either 0 or 2 (if pressed) ReadJoystick: move.w HWBase+joy1dat,d0 ; Read Up Down Left Right move.w d0,d1 add.w d1,d1 eor.w d0,d1 move.w #514,d2 and.w d2,d0 and.w d2,d1 lea JoyLeft(pc),a0 move.w d0,(a0)+ move.w d1,(a0) ; rts sub d0,d0 ; Fire Button btst.b #7,ciaa ; Was using $bfe0ff bne.s .NoFire or #512,d0 .NoFire btst #14,HWBase+potgor ; 2nd Fire Button bne.b .No2ndFire or #2,d0 .No2ndFire: move.w d0,JoyButton move.w #$c000,HWBase+potgo ; This line *MIGHT* have to be moved away from potgor read rts JoyLeft dc.b 0 ; Joystick input JoyRight dc.b 0 JoyUp dc.b 0 JoyDown dc.b 0 JoyButton dc.b 0 JoyButton2 dc.b 0 Last edited by jimmy2x2x; 19 November 2014 at 20:12. |
19 November 2014, 20:36 | #50 |
Glastonbridge Software
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
|
|
19 November 2014, 21:47 | #51 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Sure, but is it useful? You have to read several registers to read all three buttons, and then you need extra code to mix that data with the directional data. Seems like a better idea to just btst those registers directly. It's probably faster and easier.
|
19 November 2014, 23:10 | #52 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
If you don't mind splitting the joystick direction bits into two registers, then you can do this:
Code:
move.l joy0dat(a5),d0 move.l d0,d1 add.l d1,d1 eor.l d0,d1 Bits: register direction joy0dat joy1dat d0 left 25 9 d0 right 17 1 d1 up 25 9 d1 down 17 1 |
19 November 2014, 23:18 | #53 |
Glastonbridge Software
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
|
well it might be faster but i don't know about easier...
from a stylistic point of view, i prefer to keep all the joystick reading code in a single subroutine, and return the result in a data register. also i like to do things like (newValue AND NOT oldValue) in order to test which buttons have just been pressed or released. |
20 November 2014, 12:24 | #54 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
It's for inlining.
Quote:
Code:
move.l joy0dat(a5),d0 and.l #$03030303,d0 move.l d0,d1 add.l d1,d1 add.l #$01010101,d0 add.l d1,d0 move.b $bfe001,d1 and.b #$c0,d1 or.b d1,d0 swap d0 move.w potgor(a5),d1 and.w #$5500,d1 rol.w #4,d1 lsl.b #4,d1 or.w d1,d0 If you only want button 1 for both ports, just drop everything from the swap (inclusive). |
|
21 November 2014, 04:06 | #55 |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,182
|
Don't forget CD32 controller buttons too
|
23 November 2014, 13:20 | #56 | ||
Posts: n/a
|
@robinsonb5
Quote:
Quote:
So the lookup-tables really should look like this: Code:
_joy_tableX: dc.w 0, 0, 1, 1, 0, 0, 0, 1,-1, 0, 0, 0,-1,-1 _joy_tableY: dc.w 0, 1, 1, 0,-1, 0, 0,-1,-1, 0, 0, 0, 0, 1 LEFT: $0018 = 24/2 = 12 + 1 = 13th value in table _joy_tableX = -1 RIGHT: $0006 = 6/2 = 3 + 1 = 4th value in table _joy_tableX = 1 UP: $0008 = 8/2 = 4 +1 = 5th value in table _joy_tableY = -1 DOWN: $0002 = 2/2 = 1 + 1 = 2th value in table _joy_tableY = 1 LEFT+UP $0010 = 16/2 = 8+1 = 9th value in both tables (-1, -1) LEFT+DOWN $001A = 26/2 = 13+1 = 14th value in both tables (-1, 1) RIGHT+UP $000E = 14/2 = 7+1 = 8th value in both tables (1, -1) RIGHT+DOWN $0004 = 4/2 = 2+1 = 3rd value in both tables (1, 1) Now I also understand why these tables both are 14 values long, because of the LEFT+DOWN combo. |
||
23 November 2014, 13:34 | #57 |
Posts: n/a
|
Just to be complete:
My first attempt of joystick-reading code looked like this: Code:
move.w #1,d6 move.w $dff00c,d0 ; X1 move.w d0,d1 ; Y1 lsr.w #1,d1 eor.w d0,d1 btst #1,d0 bne .joyRight btst #9,d0 bne .joyLeft btst #0,d1 bne .joyDown btst #8,d1 bne .joyUp bra .noJoy ;----- move Sprite .joyRight: add.b d6,1(a6) ; increase sprite Hstart btst #0,d1 bne .joyDown btst #8,d1 bne .joyUp bra .noJoy .joyLeft: sub.b d6,1(a6) ; decrease sprite Hstart btst #0,d1 bne .joyDown btst #8,d1 bne .joyUp bra .noJoy .joyDown: add.b d6,(a6) ; increase sprite Vstart add.b d6,2(a6) ; increase sprite Vstop bra .noJoy .joyUp: sub.b d6,(a6) ; decrease sprite Vstart sub.b d6,2(a6) ; decrease sprite Vstop .noJoy: |
23 November 2014, 14:08 | #58 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
Why are those lookup tables not needed? Because they create more code, and in the end you still have to use compare instructions. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Quickshot Python: crap joystick or crappest joystick ever? | T_hairy_bootson | Nostalgia & memories | 141 | 13 September 2016 15:36 |
Reading Memory | you8mysandwich | support.WinUAE | 10 | 26 January 2011 12:00 |
Reading PC discs | Unregistered | support.Hardware | 12 | 01 September 2004 11:00 |
Reading CD-RW Media | @UAE | support.Apps | 4 | 14 December 2002 11:44 |
3D code and/or internet code for Blitz Basic 2.1 | EdzUp | Retrogaming General Discussion | 0 | 10 February 2002 11:40 |
|
|