Jump to content

Photo

FORTH and BASIC graphic program comparison


37 replies to this topic

#26 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Fri Jul 21, 2017 11:11 AM

I get your "implication"😜

#27 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Fri Jul 21, 2017 11:13 AM

accidental double post

Edited by TheBF, Fri Jul 21, 2017 11:14 AM.


#28 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,342 posts
  • Location:Silver Run, Maryland

Posted Fri Jul 21, 2017 12:42 PM

I was wrong about TI Extended Basic's initial PRNG seed.  :dunce:   I have edited my last post to correct my error.

 

...lee


  • RXB likes this

#29 Asmusr OFFLINE  

Asmusr

    River Patroller

  • 2,438 posts
  • Location:Denmark

Posted Fri Jul 21, 2017 2:43 PM

 

I don't exactly understand what you mean.

 

I am not the "sharpest knife in the drawer" as we say,  but if you wanted R to relate to a random number,

why would you use a function that does not have a random number in it somewhere? :?

 

(or did I miss a joke here)

 

Sorry, as Mizapf wrote it was kind of a joke, but I have been wondering about how to make a test for randomness too.

 

http://atariage.com/...d/#entry3650547



#30 mizapf OFFLINE  

mizapf

    River Patroller

  • 2,532 posts
  • Location:Germany

Posted Fri Jul 21, 2017 2:52 PM

Patterns on the screen? Maybe you can evaluate randomness with a hires pattern that should become a kind of white noise, but this is still not general enough because it just adds one dimension.

 

Sorry, as Mizapf wrote it was kind of a joke.

 

Your jokes are suitable as exam questions. :-D



#31 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Fri Jul 21, 2017 8:08 PM

I was wrong about TI Extended Basic's initial PRNG seed.  :dunce:   I have edited my last post to correct my error.

 

...lee

Say it ain't so !  :(



#32 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,342 posts
  • Location:Silver Run, Maryland

Posted Fri Jul 21, 2017 8:31 PM

Say it ain't so !  :(

 

Sadly true.  :P  I had assumed that >83C0 was used because it is identified by TI documentation as the “random number seed”, continued changing until a program was started and is, in fact, used by several other TI languages (TI Basic, GPL, TI Forth among them) for their respective PRNGs.  Of course, you know what “assume” does.   :)

 

My awareness of the truth came from finally walking TI Extended Basic's GPL code for the PRNG, which Rich has posted several times.  I had not tried to slog through the GPL code to date because I was so sure I would be in for a long session with GPL.  It was actually not that difficult.  ;-)

 

...lee


  • RXB likes this

#33 RXB OFFLINE  

RXB

    River Patroller

  • 2,764 posts
  • Location:Vancouver, Washington, USA

Posted Sat Jul 22, 2017 12:03 AM

Yea I posted GPL XB RND code to deal with protests that I did not understand how RND in XB worked.

 

I made a post stating how insane Texas Instruments was for putting Advanced Calculator code in RND for 49 million in better random histograms.

 

But consider 99% of the time people only needed 1 to 1000 at most, so 49 million is just insane overkill and detrimental to performance on games.

 

This combined with my pointing out in Fest West 2017 that TI made XB slow on purpose so XB could be compatible with TI Basic, can you imagine 

typing in a game for TI Basic and it would not work in XB only because it was to fast? (So TI put slows into XB to make it backward Compatible.)



#34 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Wed Jul 26, 2017 8:44 AM

So I took a look at TI-Forth source code for RNDW, RND etc...

 

Very simple and it performs quite well. I did 2 things that improved the speed of RNDW from 703 uS down to 681.6 uS

measured with the 9901 hardware timer under CLASSIC99

 

Manual cycle counting on TurboForth indicate it would be about 90uS for the ALC version.

\ TI-FORTH PRNG minor mods for CAMEL99

HEX
83C0 CONSTANT 'SEED  ( address of random number seed in PAD RAM)

\ SEED=SRC(5,SEED*6FE5+7AB9)
: RNDW      ( -- n)   'SEED @ 6FE5 * 7AB9 + 5 SRC DUP 'SEED ! ;
  
: RND       ( n -- n) RNDW ABS SWAP MOD ;

Since the Histogram was not as revealing as much as I wanted it to, I tried looking for the first time a number repeated in a sequence.

 

This simple little PRNG did not repeat until 20,053 random numbers with most SEED values. Some SEEDs go over 26,000 numbers.

 

Here is the test code.

( I used a 32 bit counter to avoid the chance of overflow)

\ Random number test code
CREATE DCNT   4 ALLOT                         \ 32bit integer variable, 4 bytes

: DCNT++    ( -- ) DCNT 2@ 1 M+ DCNT 2! ;     \ incr. 32 bit counter
: CLRCNT    ( -- ) 0 0 DCNT 2! ;              \ clear counter
: UD.       ( d -- )  <# #S #>  TYPE SPACE ;  \ print double, unsigned
: .DCNT     ( -- )  DCNT 2@ UD. ;             \ print counter

HEX
: NEXT_REP    \ find next repetition of Random number
        CLRCNT
        9900 'SEED !
        RNDW DUP
        CR         
        CR ." Searching for:" DECIMAL U.
        BEGIN
            DCNT++
            RNDW
            OVER =
        UNTIL
        CR  ." Duplicate after "  .DCNT  ." random no.s"  ;



#35 Lee Stewart OFFLINE  

Lee Stewart

    River Patroller

  • 3,342 posts
  • Location:Silver Run, Maryland

Posted Wed Jul 26, 2017 9:19 AM

I converted those to ALC in fbForth 2.0.  You have the source.  I forget which file and I am not home to check right now.

 

...lee



#36 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Wed Jul 26, 2017 12:36 PM

I converted those to ALC in fbForth 2.0.  You have the source.  I forget which file and I am not home to check right now.

 

...lee

 

Thanks Lee



#37 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Wed Jul 26, 2017 8:31 PM

Update.

 

I coded RNDW in ALC and it comes in at 149.1 uS in Indirect threaded code and 127.8 uS in the DTC system.

I think I will keep that in the Kernel.

 

Here is the ASM version with top of stack cached in register. 

By doing the MPY in R3 the answer falls out into R4 which is my TOS cache.

Save 1 instruction!

CODE: RNDW    ( -- n)    \ replaces: 'SEED @ 6FE5 * 7AB9 + 5 SRC DUP 'SEED ! 24+4=28 bytes DTC
              TOS PUSH,
              83C0 @@ R3 MOV,
              R2 6FE5 LI,
              R2 R3 MPY,
              TOS 7AB9 ADDI,
              TOS 5 SRC,
              TOS 83C0 @@ MOV,
              NEXT,
              END-CODE   \ 24 bytes

Here is the test code using 9901 timer read called TMR@ which returns 21.3 uS ticks.

: RNDTEST ( -- ) TMR@ RNDW TMR@  NIP  - . ;

\ ticks * 213 = uS*10


Edited by TheBF, Wed Jul 26, 2017 8:32 PM.


#38 TheBF OFFLINE  

TheBF

    Moonsweeper

  • Topic Starter
  • 321 posts
  • Location:The Great White North

Posted Sun Sep 17, 2017 5:40 PM

While trolling through the library code for GForth,  the GNU Forth system, I found a random number generator.

 

I uses a very simple algorithm and might be useful to Assembly language programmers here.

Here is the Forth Code:

\ generates random numbers                             12jan94py

\ Copyright (C) 1995,2000,2003,2007 Free Software Foundation, Inc.

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.

\ From Gforth, modified for CAMEL99 system
HEX 
83C0 CONSTANT SEED   \ RAM where TI has a number incrementing in main menu
1045 CONSTANT GEN#   \ GForth uses $10450405  \ taking the 1st 16 bits

: RND  ( -- N )  SEED @ GEN# UM* DROP 1+ DUP SEED ! ;
: RANDOMIZE ( N -- 0..N-1 )  RND UM* NIP ;  (edit: CORRECTED this code with UM*)

If we were to translate it to infix notation as a function in integer BASIC it would something like this:

The multiplication (UM*) in Forth is unsigned, mixed multiply ( int*int->double) which is really just the TMS9900 MPY instruction.

Nice and easy.

DEF RND()
    R=SEED*GEN#+1
    SEED=R

The cool thing is where the TI-Forth algorithm repeats after 20,000 ints or so, this one repeats after 65,536 and the Histogram is very flat.

In both cases I started with the >3567 seed value used by TI-BASIC just for consistency. (Thanks Lee)

Increased my histogram samples to 320 to give all 32 buckets a potential 10 random numbers which seemed a better way to do it.

 

Might be useful to someone making games.

 

PS

For reference I re-did the TI-BASIC histogram using 320 random samples.

Attached Files


Edited by TheBF, Fri Sep 22, 2017 7:59 AM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users