English Amiga Board


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

 
 
Thread Tools
Old 16 November 2014, 16:46   #21
borchen
 
Posts: n/a
@robinsonb5
Thanks for final piece of info I needed to understand what's going on.
I knew something had to be divided by 2, because of the word/byte stuff.

Basically the index is as follows:
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

So I removed all the other (confusing) values from both tables and ended up with this:
Code:
_joy_tableX:
    dc.w    0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0 
_joy_tableY:    
    dc.w    0, 1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0
This appears to work fine!

I also tried to merge both tables into _joy_table, but that appeared not to work for some strange reason...

To move my sprite I use the following code:
Code:
    move.w    _dx_joy,d0
    add.b    d0,1(a6)        ; sprite Hstart

    move.w    _dy_joy,d0
    add.b    d0,(a6)            ; sprite Vstart
    add.b    d0,2(a6)        ; sprite Vstop
where a6 = pointer to first sprite-structure, which was 'stolen' from Photon <---- thats how the sprite looks
 
AdSense AdSense  
Old 16 November 2014, 16:49   #22
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,452
borchen: well it *isn't* obvious what bclr+beq does. Too bad it wasn't on that site, I'll try to find time to finish my on-line tools. But yep, until then your best bet is a CPU manual of some sort.

There's this and this, but I think for learning the instruction set, the Asm-One manual (I linked it in Downloads) is a sensible and concise summary with examples.

I also think you would learn better and faster by looking at better code examples.
Photon is offline  
Old 16 November 2014, 23:06   #23
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 522
Quote:
Originally Posted by borchen View Post
So I removed all the other (confusing) values from both tables and ended up with this:
Code:
_joy_tableX:
    dc.w    0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0 
_joy_tableY:    
    dc.w    0, 1, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0
This appears to work fine!
Cool - but just double check that the code still works for diagonals?
I'm wondering if that's what the other values were for?
robinsonb5 is offline  
Old 17 November 2014, 12:48   #24
obiwanken
Registered User
 
Join Date: Jan 2013
Location: Slovakia
Posts: 27
My code looks like this:

Code:
Start

		bsr	TestJoy1
		bra	Start

		rts

**************************************************************
*
*	Joystick 1 test
*
*	Joy1Pos bits	0=Right
*			1=Left
*			2=Down
*			3=Up
*			4=Fire
*
**************************************************************

TestJoy1

		lea	JoyTable(pc),a0
		move.w	$dff00c,d0

		and.w	#$0303,d0
		move.b	d0,d1
		lsr.w	#$06,d0
		or.w	d1,d0

		move.b	(a0,d0.w),14(a0)

		btst	#$07,$bfe001
		bne	NoFire1
		bset	#$04,14(a0)
NoFire1
		rts

JoyTable		dc.b	$00,$04,$05,$01,$08,$00,$00,$09,$0a,$00,$00,$00,$02,$06
Joy1Pos		dc.b	$00	;F U D L R
obiwanken is offline  
Old 17 November 2014, 13:34   #25
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Encoding the joystick directions as single bits in a byte is not optimal, as the BTST or AND instructions to check the directions are expensive.

I prefer to return the joystick state as a longword, with whole bytes showing the direction. For example:
Code:
First byte: button pressed ($ff), not pressed ($00)
Second byte: up ($ff), down ($01) or neither ($00)
Fourth byte: left ($ff), right ($01) or neither ($00)
phx is offline  
Old 17 November 2014, 14:11   #26
obiwanken
Registered User
 
Join Date: Jan 2013
Location: Slovakia
Posts: 27
I agree, but sometime the direction move value is not constant. For example moving object normal speed=2, falling object=3, object in water=1 etc. And yes, use BTST or AND is not optimal.

There is many ways
obiwanken is offline  
Old 17 November 2014, 14:47   #27
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 628
@phx

Try my best joystick routine. a5 = _custom ($dff000)

Code:
Joystick:
		move.w	joy1dat(a5),d0	;12c
		move.w	d0,d1		;4c
		add.w	d1,d1		;4c
		eor.w	d0,d1		;4c
		move.w	#514,d2		;8c
		and.w	d2,d0		;4c
		and.w	d2,d1		;4c
		lea	left(pc),a0	;8c
		move.w	d0,(a0)+	;8c
		move.w	d1,(a0)		;8c, total 64c
		rts			;16c (with rts 80c :))

left:		dc.b	0
right:		dc.b	0
up:		dc.b	0
down:		dc.b	0
And code for check directions work in following way.

Code:
		lea	left(pc),a0
		tst.b	(a0)+
		beq	.right

		;do something for left direction

.right
		tst.b	(a0)+
		beq	.up

		;right direction
.up
		;and so on...
Enjoy.
Asman is offline  
Old 17 November 2014, 16:49   #28
obiwanken
Registered User
 
Join Date: Jan 2013
Location: Slovakia
Posts: 27
Perfect.
obiwanken is offline  
Old 17 November 2014, 20:14   #29
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by obiwanken View Post
Perfect.
Maybe for a 68000 but I think Asman's code is better for the 68020-68060 like this:

Code:
Joystick:
        lea left(pc),a0
        move.w joy1dat(a5),d1
        move.w d1,d0
        add.w d1,d1
        eor.w d0,d1
        and.w #514,d0
        and.w #514,d1
        move.w d0,(a0)+
        move.w d1,(a0)
        rts

left:
   dc.b    0
right:
   dc.b    0
up:
   dc.b    0
down:
   dc.b    0
I believe this is best case only 5 cycles on the 68060 not counting the cost of reading a hardware register or the RTS. That's pretty good considering none of the instructions are longword operations. The MOVE.W #514,D2+AND.W D2,D0+AND.W D2,D1 didn't save anything, is slower on the 68040 and 68060 at least, used an extra scratch register and made instruction scheduling more difficult. I believe this is no worse on the 68000 while being significantly better for the 68020+. Perfect is how Asman got his columns all to line up .

Last edited by matthey; 17 November 2014 at 20:23.
matthey is offline  
Old 18 November 2014, 07:05   #30
mc6809e
Registered User
 
Join Date: Jan 2012
Location: USA
Posts: 281
How about a jump table?

Code:
	move.w joy1dat(a5), d0 ;12c 0f
	andi.w #$0303, d0 ;8c 0f
	ror.b #2, d0 ;10c 6f
	asr.w #4, d0 ;14c 10f
	movea.l stick(pc,d0.w), a0 ;18c 2f
	jmp (a0) ;8c 0f

stick:
	dc.l nothing
	dc.l back
	dc.l rightback
	dc.l right
	dc.l forward
	dc.l error
	dc.l error
	dc.l forwardright
	dc.l forwardleft
	dc.l error
	dc.l error
	dc.l error
	dc.l left
	dc.l backleft
	dc.l error
	dc.l error
If joystick state doesn't need long term storage, then this might be a win, taking 70 cycles total.

It also has the advantage of leaving 9 DMA slots free. That could mean a few more blitter accesses if the blitter is running.

I admit, though, that Asman has the best code for most situations. Very clever.

Last edited by mc6809e; 18 November 2014 at 07:20.
mc6809e is offline  
Old 18 November 2014, 14:21   #31
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,019
Very nice. I have adopted this code for my current project.
Thanks.
phx is offline  
Old 18 November 2014, 17:14   #32
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,972
This can be done in an easier way. Simply write a zero to JoyTest, then read Joy1Dat. No need for reading Joy1Dat, then anding, rotating, shifting and what not.
Thorham is offline  
Old 18 November 2014, 18:07   #33
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by mc6809e View Post
How about a jump table?
This code is not good for a 68040 and 68060 (or some future fpga processors with a similar hardware design). All the instructions are dependent, there is a 2-3 cycle bubble waiting for D0 to become valid for the (stick,PC,D0.W) addressing mode with no way to reschedule and most of the pipeline is lost on the JMP (the pipeline doesn't know what instructions to fetch for awhile) which is many cycles. The rotate and shift are slow on a 68000. The jump table is big on all 68k processors. Asman's code is good and it can be good for all 68k processors.
matthey is offline  
Old 18 November 2014, 19:04   #34
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,972
Code:
joy.left=$0300 
joy.right=$0003
joy.up=$0100
joy.down=$0001
joy.upLeft=$0200
joy.upRight=$0103
joy.downLeft=$0301
joy.downRight=$0002

    move.w  #0,joytest(a5)
    move.w  joy1dat(a5),d0

    cmp.w   #joy.left,d0
    beq     .left

    etc...
Thorham is offline  
Old 18 November 2014, 19:13   #35
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,025
I would just pick whatever fits best with the rest of the game code and logic, instead of worrying over the cycle count of a routine responsible for a tiny 0.1% of the execution time.
Leffmann is offline  
Old 18 November 2014, 19:30   #36
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,972
Quote:
Originally Posted by Leffmann View Post
I would just pick whatever fits best with the rest of the game code and logic, instead of worrying over the cycle count of a routine responsible for a tiny 0.1% of the execution time.
Indeed. The amount of CPU time required is so ridiculously small that you should just go for the easiest method. See code in my previous post. VERY simple.
Thorham is offline  
Old 18 November 2014, 21:24   #37
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,025
That's exactly the opposite to what I was saying. That code may be the best choice in some cases, but it also dictates that the game code must be adapted to the tiny joystick routine, when you should instead adapt the joystick routine to the game code.
Leffmann is offline  
Old 18 November 2014, 21:51   #38
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
Quote:
Originally Posted by phx View Post
Encoding the joystick directions as single bits in a byte is not optimal, as the BTST or AND instructions to check the directions are expensive.
but allows the whole joystick state to be kept in a register.

Also you could just shift bits out one at a time and test them like so:
Code:
add.b d0,d0
bmi .fire
Mrs Beanbag is offline  
Old 18 November 2014, 23:17   #39
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 41
Posts: 2,972
What's the point of all this if you can just clear joytest, read joy1dat and compare? Why bit shuffle the data from joy1dat, use a lookup table, and compare?
Thorham is offline  
Old 18 November 2014, 23:23   #40
mc6809e
Registered User
 
Join Date: Jan 2012
Location: USA
Posts: 281
Code:
joy.left=$0300 
joy.right=$0003
joy.up=$0100
joy.down=$0001
joy.upLeft=$0200
joy.upRight=$0103
joy.downLeft=$0301
joy.downRight=$0002

    move.w  #0,joytest(a5) ;16c
    move.w  joy1dat(a5),d0 ;12c

    cmp.w   #joy.left,d0 ;8c
    beq     .left ; 8c or 12c

    etc...
Interrupts probably should be off. If an interrupt is serviced between the first two moves, enough time may elapse to allow switch bouncing (arcing between contacts of the switch) to increment the counters in joy1dat. That may mean an extra test for the stick up position since otherwise illegal values will fall through all the check values you have listed and look like a stick up condition when some other input is desired.

With the additional stick up test, in the worst case it may take 28+9*20=208 cycles -- more than twice as many cycles.

But what bothers me the most about this sort of code is the variance it introduces in execution time. It increases the possibility that some obscure combination of inputs and state is going to cause things like dropped or skipped frames -- that makes debugging more difficult.
mc6809e is offline  
AdSense AdSense  
 


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 16:36
Reading Memory you8mysandwich support.WinUAE 10 26 January 2011 13:00
Reading PC discs Unregistered support.Hardware 12 01 September 2004 12:00
Reading CD-RW Media @UAE support.Apps 4 14 December 2002 12:44
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 12:40

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 18:40.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.38835 seconds with 12 queries