Jump to content
IGNORED

Sinusoid


Recommended Posts

For this series of demos I'll need a sine function. All I did for now was to create a table, and very specific to the task at hand, namely to just show/plot the function (=sine wave). I could create the table using two dimensional motion control (which I did in an earlier demo), but for now I'll be using tables. Apparently the wave is plotted in less than 1/15th of a second.

 

sine1c.gif

 

:)

Edited by sometimes99er
Link to comment
Share on other sites

Very nice. How big is the routine and how much working memory (RAM) does it require? I'd love to have some math library as an add-on library for spectra2. I'm a noob in math so always looking on learning some new tricks :)

Thanks for feedback.

 

The cartridge header is 21 bytes. VDP initialization is 134 bytes. Main is 26 bytes. Plot routine is 52 bytes. VDP routines are 186 bytes. Tables are 264 bytes.

 

Registers R0 through R5 are used. No other CPU RAM in use. VDP use is of course almost 13K.

 

No math as such in use, and code is all very sloppy right now.

 

The wave looks "broken" as is. I'm moving steadily through x values and getting the y values (= coordinate for plot). I could use a smaller table and draw lines between plots to get exactly the same wave, but "unbroken". The line drawing routine has a bit of overhead, so small lines are relatively "heavy" compared with longer lines. Right now I'm however going down other paths.

 

Will let you know, when and if parts get sober and clean for any other use.

 

:)

Link to comment
Share on other sites

This time I'm doing some simple math. The demo draws 46 sine waves. That should amount to 46 x 256 plots = 11776 plots in less than 5 seconds. That's only 39 plots per frame (60 fps). I have to compare this with alleged 1123 moving dots (in a 16 x 16 character area), 50 fps on a Commodore 64. Probably involving a few tricks - and/or cheating. Have to check that.

 

sine2c.gif

 

:)

Edited by sometimes99er
  • Like 1
Link to comment
Share on other sites

We had to do similar graphing in Calculus with my TI-83 Plus... Of course it was designed specifically for this purpose. The Jupiter Ace FORTH has some very cool graphing/plotting utilities as well. Here's a link you can click if you'd like to see it running. (it's pretty impressive for 1k)

 

 

I'm interested in seeing what you're up to with this demo, sometimes... =)

Link to comment
Share on other sites

Thanks for feedback.

 

The first demo was something like

 


And the second one was like

 


It might be an optical illusion, but it looks as if the plotting slows down. Now the divisor becomes bigger and bigger, and chances becomes greater that the divisor is greater than the dividend, which should cause a special condition in the CPU and lower clock cycles with the DIV instruction from 98-130 to only 19. If that was true, it should start drawing faster as it approaches the top.

 

Both Classic99, MESS and Win994a seem to run the demo at about the very same speed.

 

The third demo is like this

 


For the division I'll use the SRA instruction instead of DIV.

 

sine3c.gif

 

We might have gone from less than 5 seconds to less than 4. Other than DIV there are many other instructions performed for every plot, so I guess the result is as one could expect.

 

icon_smile.gif

Edited by sometimes99er
Link to comment
Share on other sites

Nice! I can't recall that I ever used the SRA instruction. So I had to look it up.

(I did all my bit shifting with SLA and SRL until now).

 

Cool learned something new :)

I actually think I have too. And then I suddenly confuse them with eachother (didn't look them up). Had to check if they both (SRA and SRL) uses the same number of clock cycles, and they do. My value range is 0 to 191, so no sign bit in action.

 

;)

Link to comment
Share on other sites

Interesting visual effect on some of these.

 

I vaguely recall having to write code to plot a circle on the TI-99 way back in high school. For that, you need sin and cos functions. A single circle is not nearly so interesting to look at, though.

 

(I think it's "sinusoid")

Edited by BigO
Link to comment
Share on other sites

I love how those SIN waves look.. I actually tried to reproduce the first effect with my TI BASIC plot, just for kicks (but it couldn't get even half done before running out of characters ;) ).

 

As for timing, Classic99 uses a fixed timing for DIV. I didn't want to guess at how it actually uses cycles internally so for now it's just locked to the minimum time.

Link to comment
Share on other sites

I love how those SIN waves look.. I actually tried to reproduce the first effect with my TI BASIC plot, just for kicks (but it couldn't get even half done before running out of characters ;) ).

 

As for timing, Classic99 uses a fixed timing for DIV. I didn't want to guess at how it actually uses cycles internally so for now it's just locked to the minimum time.

Thanks. I'm going to try and avoid DIV for now. Most of the other major home computers of the early eighties didn't have this instruction, and got away with some nice effects anyway.

 

For my demo the dividend was in the 0 to 191 range, and the divisor was in the 2 to 47. That's probably around the minimum time in most cases.

 

Did you consider the cases, where ST4 is also set, I think that's when the divisor is equal or greater than the dividend, in which case the result is not "calculated" but sort of "given". See description at the bottom of page 23 in TMS 9900 Microprocessor Data Manual.

 

ST4 is the Overflow bit. And this looks like a special clock cycle case with the DIV in both Classic99 and MESS.

 

:)

Edited by sometimes99er
Link to comment
Share on other sites

What I have done with the 3 previous demos is something like this (simplified) ...

 

1. Plot(X,Sin(X))

2. Plot(X,Sin(X)/N)

3. Plot(X,Sin(X)/2)

 

Now the 4th demo is like this

 

Plot(X,Sin(X))

Plot(X,Sin(X/2))

 

Note that I'm dividing the X value before applying the sinus function.

 

sine4.png

 

And then finally, for today, in the 5th demo combining the two waves above into one

 

Plot(X,(Sin(X)+Sin(X/2))/2)

 

sine5.png

 

:)

Link to comment
Share on other sites

Did you consider the cases, where ST4 is also set, I think that's when the divisor is equal or greater than the dividend, in which case the result is not "calculated" but sort of "given". See description at the bottom of page 23 in TMS 9900 Microprocessor Data Manual.

 

ST4 is the Overflow bit. And this looks like a special clock cycle case with the DIV in both Classic99 and MESS.

 

Yes, that's covered, I used the datasheet when I implemented cycle counting. But the datasheet doesn't discuss the details of the variable cycle timing on success. With a little time and some theories I can probably model it well enough, but that's nowhere near important right now.

 

void op_div()
{ 
// DIVide: DIV src, dst
// Dest, a 2 word number, is divided by src. The result is stored as two words at the dst:
// the first is the whole number result, the second is the remainder

Word x1,x2; 
unsigned __int32 x3;

FormatIX;
x2=ROMWORD(S);
post_inc(SRC);

D=WP+(D<<1);
x3=ROMWORD(D);

if (x2>x3)						// x2 can not be zero because they're unsigned										
{ 
	x3=(x3<<16)|ROMWORD(D+2);
	x1=(Word)(x3/x2);
	WRWORD(D,x1);
	x1=(Word)(x3%x2);
	WRWORD(D+2,x1);
	reset_OV;
	nCycleCount+=92;			// This is not accurate. (Up to 124 "depends on the partial quotient after each clock cycle during execution")
}
else
{
	set_OV;						// division wasn't possible - change nothing
	nCycleCount+=16;
}

Link to comment
Share on other sites

We try and get a bit more complicated.

 

Plot( X, ( 2*Sin(X+48) + Sin(X*2) + Sin(X/2) ) /4 )

 

The "X+48" moves this sine wave to the left.

 

The "2*" makes that wave twice as important as any of the following.

 

"X*2" makes the wave twice as wide, so 256 positions will not be enough to go through a complete cycle (512 will). The "Sin" function only has a lookup table of 256 bytes, but it seem to work alright with the demo.

 

We have seen "X/2" before and it simply halves the cycle length. 256 positions will then represent 2 cycles. 512 positions will have 4 cycles.

 

The overall wave repeats itself every 512 positions. The screen width is 256, so I'm just keeping the one overall wave in there, which makes it look like 2 waves.

 

sine6.png

 

It draws in less than 5 frames. Both calculations and plot routine can be optimized.

 

:)

Edited by sometimes99er
Link to comment
Share on other sites

That's pretty cool stuff, mate! Are you developing a graphing application or just having some fun? ;)

Thanks. Last afternoon (Kentucky + 7 hours) I looked at Helmet (based on Tursi's input) and later began work on Parachute (Game & Watch) graphics. Today I'm wondering what to try to do in this thread (Sinusoid). The sinus function is apparently basis of many old school effects, so I'm hoping to have both time and ability to knock off a few socks. If I get there, I wonder if they will be grand (full screen) or limited (like 8 by 8 characters). Not only do I have to try and push the TI, but I guess I have to be really clever about it too - like invent or reinvent many tricks of the trade. I may have to join other computer groups to get insight info on how some of the effects are done as the source code I've come across really does not explain what's happening.

 

:cool:

Link to comment
Share on other sites

We have implemented a sinus function using a table.

 

Y = Sin(X)

 

The table has 256 bytes of conversion data, which fits the screen width nicely - for now.

 

Moving the sine wave one quarter to the left makes it the cosinus wave.

 

sine7.png

 

Since our cycle width is 256, one quarter makes 64. We now have

 

Cos(X) = Sin(X+64)

 

Sinus and cosinus makes me think of circles. Basically we want to do

 

Plot( Cos(X), Sin(X) )

 

For the demo we end up with this

 

For N=64 to 112 Step 8

Plot( Sin(X+N), Sin(X) )

Next N

 

Then doing the same but "unplotting" ...

 

sine6c.gif

 

:cool:

Edited by sometimes99er
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...