SIN / COS in Sprint Compiler – could this perhaps work?

Hardware Hacking, Programming and Game Solutions/Cheats

SIN / COS in Sprint Compiler – could this perhaps work?

Postby Cloete » Thu Jun 21, 2012 6:28 am

Hi everyone. Sprint Compiler works great! (for someone like me who doesn’t know machine code yet, the improvement from Basic execution speed to Sprint speed on a real Dragon is a nice surprise). Thanks to everyone who helped making Sprint available.

I need an answer on the following problem: I know that Sprint doesn’t handle floating point numbers such as Sin Cos etc, so I was wondering if the following solution could be possible:
1. I write the body of the program in Basic.
2. The lines that handle the Sin Cos calculations, also gets written in Basic, but in the form of reading and poking using a for-loop. (It’s my guess that the Sin and Cos will be READ in as tokens or something like that. That way the Sprint Compiler won’t complain, or am I wrong here?)
3. Then I compile the program using Sprint and it works,… right? Hmmm…. I am aware that the Sprint won’t really improve the Sin/Cos calculation speed, but at least I want to improve on the graphics’ display speed, etc.
4. According to the Sprint Compiler Instructions, and I quote:
3.9 MACHINE CODE PROGRAMMING:
In this section we look at the layout of compiled program and how machine code may be incorporated into compiled programs.

3.9.1 PROGRAM LAYOUT:
A program compiled by OASIS BASIC will use all the RAM memory except that reserved by PCLEAR.
A program containing PCLEAR 0 will use all available RAM.
A program containing no PCLEAR will use all memory except graphics pages 1 to 4.

With OASIS BASIC the CLEAR command is ignored and cannot be used to reserve memory for machine code routines. Any attempt to place machine code at the top of RAM will corrupt the compiled program and have an unpredictable effect on the execution of the program.

3.9.2 MACHINE CODE STORAGE: page 12....
A machine code routine can still be used with OASIS BASIC by either placing it in a reserved graphics page or by reading it into a numeric array within the program. If code is to be placed into a numeric array we must place two bytes per component, i.e we must assign a value (256* byte one + byte two) to each component of the array.

**** For example, the following machine code routine can be used to invert the text screen****
8E, 04, 00, A6,84 ,81,80, 25, 04, 88, 0F, 20, 02. 88, 40, A7,80, 8C 05,FF,23,ED,39
We can either read it into a graphics page (say page 1) or we can read it into a numeric array (say X). Since this routine has 23 bytes the array will need 12 components, i.e DIM X(11).


If Sin Cos can be done by reading and poking using a for-loop in Basic (and then compiling using Sprint), can someone please write the following lines so that it can be placed into a numeric array for machine code purposes – the type where you read hex in Basic and poke it into some addresses using a FOR LOOP (like the machine code routine example that was used above to invert the text screen):

310 FOR T= 0 TO 25 STEP (1/10)
320 G=16+(V*T*(SIN(A/57)))
330 O1=V*T*(SIN(A/57))-(((5/10)*((98/100)*(T to the power of 2))))
450 NEXT T

Remember Sprint only works with integers, therefore 0.1 is represented by (1/10) and 0.5 will be (5/10) in code.
Now I don't know if the lines starting with 340 PSET(G9,O9,C9) and all the IF STATEMENTS up to 440 should also be written using the loop-read-poke sequence? These in between lines 340-440 deals with the IF’s and THEN’s.

Also the enemy’s calculations are done on the following lines:

770 FORC T= 0 TO 25 STEP (1/10)
780 CG=238-(CV*CT*(SIN(CA/57)))
790 OC=CV*CT*(SIN(CA/57))-(((5/10)*((98/100)*(CT tothepower2))))
910 NEXT CT

Again I left out the line 800 PSET(GC,OO,CB) and the IF – THEN statements from 810 to 900 – don’t know if it should it also be written using the loop/read/poke system?

Hope to hear from someone soon.
Regards, Cloete
Cloete
 
Posts: 35
Joined: Mon Jan 16, 2012 6:49 am
Location: Pretoria, Gauteng Province, South Africa

Re: SIN / COS in Sprint Compiler – could this perhaps work?

Postby Sarah » Thu Jun 21, 2012 12:32 pm

Hi Cloete! That's a tricky problem! :geek:

I'm not sure that including a Machine Code routine will help much here unless there's a crafty way of utilising the ROM function for SIN(); however if that's easy enough to do then I'd guess Oasis would've supported it already.

Perhaps an alternative viable approach would be to instead consider eliminating the need for SIN() within your BASIC program. If there are only a fixed number of SIN() values that you need computed then you could potentially use a lookup table instead of calling the unsupported function. The code snippet you've provided indicates that this depends upon the range of values that A or CA can take since those are the only variables affecting the SIN() results. We can't see here how A and CA are otherwise used, so it's unclear whether or not that's going to be easy. If the idea works out then the values in the lookup table could initially be scaled up (e.g. 100 or 1000 times the floating point values) for the DATA and then presumably divided again to scale down your calculations correctly. You might, however, come across an issue with integer sizes if working with scaled up values.
Sarah
 
Posts: 135
Joined: Wed Apr 13, 2011 3:36 pm

Re: SIN / COS in Sprint Compiler – could this perhaps work?

Postby Cloete » Thu Jun 21, 2012 4:32 pm

Hi Sarah,
Sorry, I forgot to mention - the user needs to input the ANGLE (0-90) and the SPEED (2-100).
This is meant to give a wide variety of canon ball trajectories, and off course I would like to have a smooth ball flying through the air - that why the TIME variable T increments by 0.1 ..... so I think that a read-up grid of values will be a huge excercise.
Herewith the correct Basic code that I hope someone can transelate into a FOR LOOP - READ DATA - POKE it in somewhere and hopefully it calculates faster than the normal Basic way. I omitted the graphic commands, etc..

305 INPUT”PLEASE ENTER THE ANGLE (0-90):”;A
306 INPUT”PLEASE ENTER THE TRAJECTORY SPEED (2-100):”;V
310 FOR T= 0 TO 25 STEP (1/10)
320 G=16+(V*T*(SIN(A/57)))
330 O1=V*T*(SIN(A/57))-(((5/10)*((98/100)*(T to the power of 2))))
340 PSET(G,O1,2)
450 NEXT T

It does not have to work on OASIS. I am asking for a translated version of the above - please - will someone help me with this?
Cloete
 
Posts: 35
Joined: Mon Jan 16, 2012 6:49 am
Location: Pretoria, Gauteng Province, South Africa

Re: SIN / COS in Sprint Compiler – could this perhaps work?

Postby Sarah » Thu Jun 21, 2012 5:19 pm

It looks like you're only using 91 different values of the SIN() function, so it could easily be replaced with an array look-up but I still think it would be non-trivial to perform the entire calculation in Machine Code unless you can rework the formula to only use integers. The 6809 processor doesn't have floating point instructions, unfortunately.
Sarah
 
Posts: 135
Joined: Wed Apr 13, 2011 3:36 pm


Return to Hints and Tips

Who is online

Users browsing this forum: No registered users and 0 guests

cron