English Amiga Board


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

 
 
Thread Tools
Old 17 September 2020, 21:59   #1
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Simple assembler maths problem

If you read some of my posts on here you'll know that I'm not scared to tell people how bad I am at maths, what most people find simple I find incredibly hard to work out.

Take this one for example which is pretty simple for Super Sprint.

Say I have a range 0-400 for the car throttle.

And I have a steer setting which goes from -300 to +300 (0 is when the car wheels are centred).

When the car is idle (no throttle), the steer should quickly interpolate (I think that's the right expression) to 0, when the car is going full throttle the steer should very slowly interpolate back to 0.

Been working on it a while now and I can't get it right.

Any ideas anyone?
mcgeezer is online now  
Old 17 September 2020, 22:11   #2
DMWCashy
Registered User
 
Join Date: Dec 2019
Location: Newcastle
Posts: 67
What do you have so far?,

If I understand you correctly, I would have a set point for the target steering position, and then move the current steering position towards the target set point by a delta amount(some fraction created by the current speed) each game frame.

Then you can just fine tune the delta equation until you get something that feels right.
DMWCashy is offline  
Old 17 September 2020, 22:19   #3
LeCaravage
Registered User
 
LeCaravage's Avatar
 
Join Date: May 2017
Location: AmigaLand
Posts: 459
Why not set car throttle in a unsigned byte (0-255) ? And same goes for steer but signed this time.
The way I understand it, if you have enough memory I'd go for a 256 bytes (may be more if more precision is needed) table of dx, where dx is the amount of steering indexed with throttle.
LeCaravage is offline  
Old 17 September 2020, 22:27   #4
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by DMWCashy View Post
What do you have so far?,

If I understand you correctly, I would have a set point for the target steering position, and then move the current steering position towards the target set point by a delta amount(some fraction created by the current speed) each game frame.

Then you can just fine tune the delta equation until you get something that feels right.
What I have at the moment... (which isn't right).

Code:
.steer_to_centre:
	move.l	carCurrentThrottle(a4),d0	; 400
	lsr.l	#8,d0
	moveq	#8,d1			; 0=0, 1=1, 2=4, 3=8, 4=16
	lsl.w	d0,d1
	
	tst.w	carSteerMod(a4)
	beq	.exit
	bmi	.steer_decr_left
	bra	.steer_decr_right

; If the car is not moving then the decrease is instant
.steer_decr_left:
	add.w	d1,carSteerMod(a4)
	bra	.exit

.steer_decr_right:
	sub.w	d1,carSteerMod(a4)
	bra	.exit
mcgeezer is online now  
Old 17 September 2020, 22:54   #5
DMWCashy
Registered User
 
Join Date: Dec 2019
Location: Newcastle
Posts: 67
Using a divide would normally be needed to make this feel right else it would be too linear,

I think @LeCaravage is on the right track here, to save the need for expensive division, use a lookup table.

I wouldn't even think you would require 256 lookups, if max throttle is 400, I would divide it by 16 so you can shift, and that would give you 25 lookups.

Then just create the lookup table values in a spreadsheet and play around until it feels right.
DMWCashy is offline  
Old 17 September 2020, 23:35   #6
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,975
Quote:
Originally Posted by mcgeezer View Post
What I have at the moment... (which isn't right).

Code:
.steer_to_centre:
	move.l	carCurrentThrottle(a4),d0	; 400
	lsr.l	#8,d0
	moveq	#8,d1			; 0=0, 1=1, 2=4, 3=8, 4=16
	lsl.w	d0,d1
	
	tst.w	carSteerMod(a4)
	beq	.exit
	bmi	.steer_decr_left
	bra	.steer_decr_right

; If the car is not moving then the decrease is instant
.steer_decr_left:
	add.w	d1,carSteerMod(a4)
	bra	.exit

.steer_decr_right:
	sub.w	d1,carSteerMod(a4)
	bra	.exit
Perhaps you can reduce number of branchs too.

tst.w carSteerMod(a4)
beq .exit
bpl.b .steer_decr_right
neg.w d1
.steer_decr_right
add.w d1,carSteerMod(a4)
bra .exit
Don_Adan is offline  
Old 18 September 2020, 00:59   #7
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
This is your problem:
Code:
	move.l	carCurrentThrottle(a4),d0	; 400
	lsr.l	#8,d0
After that d0 will be either 1 (if throttle >= 256) or 0 (otherwise). You need more levels, so either use bfffo (020+) to find the highest set bit in d0, or shift it say 4 times and then use that as index in a small logarithmic table.

Last edited by a/b; 18 September 2020 at 01:05.
a/b 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
[vbcc/win] Doing some maths.. guy lateur Coders. C/C++ 21 21 July 2017 01:51
simple network problem with Flower Pot/WinUAE mlankton support.WinUAE 4 01 March 2017 17:56
Seriously simple AE Problem :( Fingerlickin_B support.Apps 10 13 March 2007 20:50
Simple Desert Strike Problem itsonlyleggy support.Games 2 20 June 2006 12:24
help simple language problem Aeryn26 support.Apps 1 25 May 2002 15:29

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:41.

Top

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