Jump to content
IGNORED

Sometimes faster is not good


TheBF

Recommended Posts

A while back Sometimes99er created this pretty demo of "Quasi" particles falling from the screen.

 

(can't seem to find it on the site, but I know I didn't imagine it)

 

Since I have little imagination for the visual arts I enjoy trying to emulate XB functionality made by the creative people here with my hobby Forth system.

So I whipped up some code and hit return and mine did not look like Sometimers99er's at all!

I went away humbled and didn't think much about it for long time, until this week when I realized that I was creating my sprites too fast. :-)

 

The beautiful way the Quasi particles fall from the top of the screen in BASIC was due to the delay created by the BASIC interpreter as it creates a new sprite.

I added some appropriate delays in my "particle sprayer" and voila! A thing of beauty.

 

And we all know that a thing of beauty is a joy forever. :-)

 

Doing this helped expose a few more bugs and speed ups for my Sprite file so a big thanks to Sometimes99er.

 

If I ever stop playing and work on my file interface I might have a complete system. :(

 

Here is the code with lots of comments:

 

 

 \ Quasi-particles by sometimes99er
 \ Converted to Camel99 MultiForth
 
 \ INCLUDE GRAFIX2.FTH    \ some day I will have files working
 \ INCLUDE SPRITES.FTH
 \ INCLUDE RANDOM.FTH

\ Extended BASIC does all this for you with ISR code
\ ------------------------------------------------
INIT-MULTI  \ must do this before invoking any Multi-tasker word

: TASK:   CREATE  USIZE ALLOT ;    \ makes the code look nicer

\ create and init the task blocks
TASK: AUTOMOTION          \ create mem block for the task
      AUTOMOTION FORK     \ copy the current task into AUTOMOTION but with new stacks

: SPMOVER   ( -- )  \ this does the ISR job for us
       BEGIN
          SP.MOVE  \ updates position of all sprites & write to VDP
          17 MS    \ approx. time between TI-99 interrupts
       AGAIN ;     \ run forever

' SPMOVER  AUTOMOTION ASSIGN  \ give AUTOMOTION the SPMOVER job

\ -----------------------------------------------
\ Program starts here

DECIMAL
32 CONSTANT N    \ number of PARTICLES we will create

\ random horizontal velocity ( -2 to -2 )
: RHORZ  ( -- +/- 5)  5 RND 2 - ;

: PARTICLES ( n -- ) \ create 'n' particle sprites
    0
    ?DO
    \ clr    chr      Y    X   #
      16  [CHAR] .   128   0   I SPRITE
    LOOP ;

\ And what the heck. Let's put the quasi particles in their own task
TASK: SPRAYER
      SPRAYER FORK

 \ releases particles
VARIABLE SPEED  60 SPEED !

: QUASI ( -- )
       BEGIN
          N 0 DO                  \ for all the particles
            128 0 I LOCATE        \ locate sprite at top of screen
            RHORZ 2  I MOTION     \ set in motion downward at random angle
            SPEED @  MS           \ wait before shooting the next one.
         LOOP
       AGAIN ;

' QUASI SPRAYER ASSIGN

CLEAR

N PARTICLES
AUTOMOTION WAKE

 

 

 

 

post-50750-0-98799800-1508592764.gif

  • Like 5
Link to comment
Share on other sites

Very nice Brian!

 

There is no classy task structure in fbForth 2.0, nevertheless here it is (more or less) ported to fbForth 2.0:

 

 

 

26 CONSTANT N   \ 25 sprites at 10px intervals to cover screen
: RHORZ ( -- n )  \ horizontal velocity, -2 to +2 
   5 RND 2-  ; 
: PARTICLES ( n -- )  \ define all sprites as periods  
   0 DO                                                         
   \ col row color  char   #                                      
     128  0  15    ASCII . I SPRITE                               
   LOOP  ;      
: DELAY 800 0 DO NOP LOOP  ;  \ sprite launch delay
: QUASI ( -- )    \ spray dots from top middle of screen
   VDPMDE @       \ current graphics mode to stack
   GRAPHICS       \ change to Graphics mode
   DELALL         \ initialize sprites
   N PARTICLES    \ define sprites
   N #MOTION      \ set all sprites in automotion, currently 0,0
   N 1 DO         \ give all sprites velocities except #0
      RHORZ 10 I MOTION
      DELAY       \ delay launch of next sprite
   LOOP  
   BEGIN          \ infinite spray loop 
      N 1 DO      \ reset each sprite in turn to top of screen
         128 0 I SPRPUT
         DELAY    \ delay reset of next sprite
      LOOP                       
   ?KEY UNTIL  \ allow a way out                              
   VMODE  ;    \ restore graphics mode with value left on stack

QUASI          \ start sprayer

 

 

 

post-29677-0-77373200-1508640989.gif

 

...lee

Link to comment
Share on other sites

Nice. It looks much better on the darker background. I was just pleased to get mine going.

 

In time I will take a run at porting the tasker to a few blocks in FB Forth. I am pretty sure the conventional version is straightforward.

 

It's fun to make the old 99 run in circles! :-)

  • Like 1
Link to comment
Share on other sites

Well just ran it in Classic99 on RXB side by side with XB and they look different, mostly due to RXB using a better faster RND generator from TI Basic.

 

You see the same issue that Forth has it just just to damn fast, but at least it does work just half as good as XB.

100 CALL CLEAR::CALL SCREEN(5)::FOR A=5 TO 12::CALL COLOR(A,16,1)::NEXT A
110 N$="00030C0F30333C3FC0C300000000000000CCCFF0F3FCFF"::FOR A=65 TO 90
120 CALL CHARPAT(A,C$)::PRINT CHR$(A)&CHR$(A+32);::FOR C=0 TO 1:: D$=""
130 FOR R=0 TO 7:$=D$&SEG$(N$,(ASC(SEG$(C$,C+R*2+1,1))-48)*2+1,2)::NEXT R
140 CALL CHAR(A+C*32,D$)::NEXT C::NEXT A::PRINT::PRINT::N$="QUASIPARTICLES"
150 FOR A=1 TO LEN(N$)::PRINT SEG$(N$,A,1)&CHR$(ASC(SEG$(N$,A,1))+32);::NEXT A
160 FOR A=1 TO 28::CALL SPRITE(#A,46,16,1,124,8,RND*10-5)::NEXT A::GOTO 160
Edited by RXB
Link to comment
Share on other sites

LOL. My first attempt at it created what looked like 3 sprites! :-)

 

It was because they were created so fast there were 3 tight clusters of them locked in motion on the screen.

 

I kept looking at the code thinking WT* ! I made 32 sprites!! Where are they???? And of course since I typed the code for the language and libraries I don't trust anything! So round and round you go looking for what you did wrong inside the system.

You probably had that happen with RXB.

 

And if you turn over a stone... there are always bugs. :-D But in this case it was the application code.

 

It's a weird hobby.

 

Sometime I think I need a shrink, but then I think it over and realize I just need a drink.

  • Like 1
Link to comment
Share on other sites

Just remember that fbForth 2.0 runs with interrupts enabled.

 

...lee

 

No problem. CAMEL99 does as well. In fact the standard Forth context switcher should be able to be installed as an ISR.

You would just have to be careful with tasks that used shared resources. Create some locks or something like that.

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