Author |
Message |
|
MaxVT103
Member
Joined: 24 Aug 2003 Posts: 109
|
Posted: 08 Feb 2004 03:48:45 pm Post subject: |
|
|
ok, I just wrote this. It should calculate the amount to add to x and y to get a new coordinate by using the angle and magnitude. Here it is, so if some nice person could tell me how I did, that'd be nice
Code: ;Vector Calculation routine, Donald Ritter 2004
;inputs angle(hl), magnitude(de)
;vector_calc(int angle,int magnitude)
;output values to add to both x and y, hl, de
vector_calc:
set Trigflags(iy+1)
push de
ld de,op1
ld bc,9
ldir
bcall(_sin)
bcall(_op2toop4)
pop de
ex hl,de
ld de,op2
ld bc,9
ldir
bcall(_fpmult)
bcall(_op1toop5)
bcall(_op4toop1)
bcall(_fpmult)
ld hl,op5;x
ex de,hl
ld hl,op1;y
ret
Last edited by Guest on 08 Feb 2004 03:49:14 pm; edited 1 time in total |
|
Back to top |
|
|
Job the GameQuitter
Member
Joined: 04 Jun 2003 Posts: 102
|
Posted: 08 Feb 2004 04:33:09 pm Post subject: |
|
|
I don't know the exact workings of the bcalls used, but it seems like it would work. Mind you, if you're just doing this for vector graphics you're calculating with unnecesary precision. |
|
Back to top |
|
|
MaxVT103
Member
Joined: 24 Aug 2003 Posts: 109
|
Posted: 08 Feb 2004 06:23:34 pm Post subject: |
|
|
I know I am, and I've posted about this before. I just want to come up with a routine that works then work from their. |
|
Back to top |
|
|
CoBB
Active Member
Joined: 30 Jun 2003 Posts: 720
|
Posted: 09 Feb 2004 03:04:18 pm Post subject: |
|
|
If you use romcalls, you can't really "work from there". You have to trash fp routines and rewrite the whole thing using fixed point arithmetic from scratch. |
|
Back to top |
|
|
MaxVT103
Member
Joined: 24 Aug 2003 Posts: 109
|
Posted: 09 Feb 2004 10:49:52 pm Post subject: |
|
|
well whenever I learn how to do that I will. |
|
Back to top |
|
|
Job the GameQuitter
Member
Joined: 04 Jun 2003 Posts: 102
|
Posted: 10 Feb 2004 04:50:12 am Post subject: |
|
|
Fixed point arithmatic isn't difficult. Let's say we have two-byte FPM, which has more than enough precision when used for graphics on the 83.
One byte is the integer, the other the er... what's the english term for this? Quotient? Remainder? The stuff behind the comma... I mean dot (where I live we use commas, confusing eh?).
EDIT: So decimal it is :)
So if we use the 16 bit registers (HL, DE, BC) and want to store 2.5, how do we store it? Well, one of the registers is the whole number and the other the decimal, and I hope it's obvious that H=integer and L=remainder. Why? Well, if we ADD HL,HL and L+L>255, L overflows and H increases by one. Which is exactly what you want with a decimal: 0.5 + 0.5 = 1.0
So that works out perfectly! But what to store in L? Well, I hope you recall that a shift to the left was the same as multyplying by 2 and a shift to the right was the same as dividing by two. So when we shift to the right from H=1, we get L= "0,5" = 128. And so forth:
[font="Terminal"]Bit:
76543210
10101010
||||||||
|||||||1/256 = 0.00390625
|||||||
||||||1/128 = 0.0078125
||||||
|||||1/64 = 0.015625
|||||
||||1/32 = 0.03125
||||
|||1/16 = 0.0625
|||
||1/8 = 0.125
||
|1/4 = 0.25
|
1/2 = 0.5
In the example above we have a total value of 0.5+0.125+0.03125+0.0078125 = 0.6640625.And in the case of HL = 2.5 we store 2 in H and %10000000 or 128 into L. But normally you don't have to worry about that, because the division/multiplication routines automatically handle that for you. You only should worry about in when your trying to get user input or want to output the value.
Also, note that rounding is easy: just load 0 into L. And in your case, where you probably want tu use it for vectors, just use H (or D or as the input for your coordinates and you're set. You could ofcourse make it a bit more complex, and do stuff like "upper four bits of H is the integer, lower four bits plus L is decimal", but it's unlikely that that is necessary.
Last edited by Guest on 11 Feb 2004 06:55:49 am; edited 1 time in total |
|
Back to top |
|
|
Adm.Wiggin aka Tianon
Know-It-All
Joined: 02 Jun 2003 Posts: 1874
|
Posted: 10 Feb 2004 06:24:16 pm Post subject: |
|
|
that would be Decimal Job |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 10 Feb 2004 07:37:12 pm Post subject: |
|
|
Mantissa is more scholarly. And as a bonus, the integer part is called the Characteristic
Last edited by Guest on 10 Feb 2004 07:38:03 pm; edited 1 time in total |
|
Back to top |
|
|
Job the GameQuitter
Member
Joined: 04 Jun 2003 Posts: 102
|
Posted: 11 Feb 2004 06:53:16 am Post subject: |
|
|
Thanks, Wiggin/sigma. I'll stick to decimal though :P
EDIT: Hey sigma, does your tutorial include FPM? because it might be a good idea to have an explanation of it.
Last edited by Guest on 11 Feb 2004 06:57:05 am; edited 1 time in total |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 11 Feb 2004 12:47:29 pm Post subject: |
|
|
Yes |
|
Back to top |
|
|
CoBB
Active Member
Joined: 30 Jun 2003 Posts: 720
|
Posted: 11 Feb 2004 03:08:50 pm Post subject: |
|
|
Mine as well. We can compare. (That part will be on-line probably this week. I'm writing up a bit on LUTs as well.) |
|
Back to top |
|
|
|