FastSpin

Table of Contents

1 Famous First Words

This is work in progress or better work in FastSpin and will change often and massively.

I'm assimilating my FastSpin related snippets, programs, thoughts and whatsoever into this EMACS Orgmode document admittedly with far too few comments and explanations so reading more about FastSpin in Parallax's forum and FastSpin's own source and documentation is a better start than this place.

Still being new to Orgmode, I have to find out a lot of things about how to manage HOWTO like documents containing lots of active code snippets and complete programs.

It sure wit take some time until it all settles down.

1.1 Forum Threads

fastspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler
https://forums.parallax.com/discussion/164187

New BASIC compiler for Prop1 and Prop2
https://forums.parallax.com/discussion/168913

Testing the new Fastspin Assembly, Spin, BASIC, and C for P1
https://forums.parallax.com/discussion/169141

1.2 Use the Source, Luke!

"Use the Source, Luke!" shall not mean you have to compile everything on your own. Typically you will find compiled bundles and documentation in these locations too and if something does not behave as expected, you should find issue trackers in the sources repositories.

2 Appetiser

2.1 FlexSPIN

This example would compile with other Spin dialects too. A pure FlexSPIN example could look different. See minimal.spin for some hints.

File hello.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub main

  ser.start(31, 30, 0, 115200)

  ser.str(string("Hello, FlexSPIN!",13,10))

  waitcnt(_clkfreq + cnt)
  ser.stop

  cogstop(0)

Compile to hello.spin.binary:

fastspin -O2 hello.spin -o hello.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
hello.spin
|-FullDuplexSerial.spin
hello.spin.pasm
Done.
Program size is 1688 bytes

Run the result in spinsim:

spinsim -b hello.spin.binary
Hello, FlexSPIN!

2.2 FlexBASIC

File hello.bas:

print"Hello, FlexBASIC!"

Compile to hello.bas.binary:

fastspin -O2 hello.bas -o hello.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
hello.bas
fmt.c
strlen.c
hello.bas.pasm
Done.
Program size is 1696 bytes

Run the result in spinsim:

spinsim -b hello.bas.binary
Hello, FlexBASIC!

2.3 FlexC

File hello.c:

#include <stdio.h>

void main( void )
{
    printf("Hello, FlexC!\n");
}

Compile to hello.c.binary:

fastspin -O2 hello.c -o hello.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
hello.c
fmt.c
strlen.c
hello.c.pasm
Done.
Program size is 1560 bytes

Run the result in spinsim:

spinsim -b hello.c.binary
Hello, FlexC!

3 FastSpin - The Program

Assuming you have fastspin installed in a directory being mentioned in your PATH variable:

fastspin
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.31 Compiled on: Sep 13 2019
usage: fastspin-3.9.31 [options] filename.spin | filename.bas
  [ -h ]              display this help
  [ -L or -I <path> ] add a directory to the include path
  [ -o <name> ]      set output filename to <name>
  [ -b ]             output binary file format
  [ -e ]             output eeprom file format
  [ -c ]             output only DAT sections
  [ -l ]             output DAT as a listing file
  [ -f ]             output list of file names
  [ -q ]             quiet mode (suppress banner and non-error text)
  [ -p ]             disable the preprocessor
  [ -D <define> ]    add a define
  [ -u ]             ignore for openspin compatibility (unused method elimination always enabled)
  [ -2 ]             compile for Prop2
  [ -O# ]            set optimization level:
          -O0 = no optimization
          -O1 = basic optimization
          -O2 = all optimization
  [ -H nnnn ]        set starting hub address
  [ -E ]             skip initial coginit code (usually used with -H)
  [ -w ]             compile for COG with Spin wrappers
  [ -C ]             enable case sensitive mode
  [ -z ]             compress code
  [ --code=cog ]     compile for COG mode instead of LMM
  [ --fcache=N ]     set FCACHE size to N (0 to disable)
  [ --fixedreal ]    use 16.16 fixed point in place of floats
  [ --lmm=xxx ]      use alternate LMM implementation for P1
           xxx = orig uses original fastspin LMM
           xxx = slow uses traditional (slow) LMM

4 Unsorted Snippets and Examples

As long as I have no better idea, the examples are sorted by their hopefully meaningful filenames.

4.1 FlexSPIN

4.1.1 conditional-expression-demo1.spin

@@@TODO@@@ Find a nicer example.

FlexSPIN documentation: conditional-expressions(FlexSPIN)

File conditional-expression-demo1.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub main

  ser.start(31, 30, 0, 115200)

  ser.dec( ( 1 < 2 ) ? 1 : 0 ) 
  ser.str(string(13,10))

  ser.dec( ( 1 > 2 ) ? 1 : 0 ) 
  ser.str(string(13,10))

  waitcnt(_clkfreq + cnt)
  ser.stop

  cogstop(0)

Compile to conditional-expression-demo1.spin.binary:

fastspin -O2 conditional-expression-demo1.spin -o conditional-expression-demo1.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.31 Compiled on: Sep 13 2019
conditional-expression-demo1.spin
|-FullDuplexSerial.spin
conditional-expression-demo1.spin.pasm
Done.
Program size is 2244 bytes

Run it in spinsim:

spinsim -b conditional-expression-demo1.spin.binary
1
0

4.1.2 conditional-expression-demo2.spin

FlexSPIN documentation: conditional-expressions(FlexSPIN)

File conditional-expression-demo2.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub main

  ser.start(31, 30, 0, 115200)

  ser.dec( ( 1 < 2 ) ? a : b )
  ser.str(string(13,10))

  waitcnt(_clkfreq + cnt)
  ser.stop

  cogstop(0)

pri a
  ser.str(string("called a",13,10))
  return 1

pri b
  ser.str(string("called b",13,10))
  return 2

Compile to conditional-expression-demo2.spin.binary:

fastspin -O2 conditional-expression-demo2.spin -o conditional-expression-demo2.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.31 Compiled on: Sep 13 2019
conditional-expression-demo2.spin
|-FullDuplexSerial.spin
conditional-expression-demo2.spin.pasm
Done.
Program size is 2248 bytes

Run it in spinsim:

spinsim -b conditional-expression-demo2.spin.binary
called a
1

No called b shows up. That's waht we want!

4.1.3 inline-asm.spin

FlexSPIN documentation: inline-assembly(FlexSPIN)

File inline-asm.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub main
  ser.start(31,30,0,115200)

  ser.str(string("the answer is "))
  ser.dec(answer(14))
  ser.str(string(13,10))

  waitcnt(_clkfreq+cnt)
  ser.stop
  cogstop(0)

pub answer(question)
  asm
	  mov     result, question        ' result as target
	  add     result, result          ' result as source too
	  add     result, question
  endasm

Compile to inline-asm.spin.binary:

fastspin -O2 inline-asm.spin -o inline-asm.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
inline-asm.spin
|-FullDuplexSerial.spin
inline-asm.spin.pasm
Done.
Program size is 2244 bytes

Run it in spinsim:

spinsim -b inline-asm.spin.binary
the answer is 42

4.1.4 inline-asm-loop-unroll.spin

FlexSPIN documentation: inline-assembly(FlexSPIN)

@@@TODO@@@ the PASM loop unrolling is not specific to using Spin as outer envelope. Maybe expamples focussing on PASM and inline PASM better should get an own section…

File inline-asm-loop-unroll.spin:

' see https://forums.parallax.com/discussion/comment/1177581/#Comment_1177581

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub main | r,t,d,d1,d2
  ser.start(31,30,0,115200)

  d1:=r?
  d2:=r?

  ser.str(string("d1,d2        ... "))
  ser.dec(d1)
  ser.tx(",")
  ser.dec(d2)
  ser.str(string(13,10))

  t:=cnt
  d:=d1*d2
  t:=cnt-t
  ser.str(string("internal     ... "))
  ser.dec(t)
  ser.str(string(13,10))

  t:=cnt
  d:=mul1(d1,d2)
  t:=cnt-t
  ser.str(string("assembler(1) ... "))
  ser.dec(t)
  ser.str(string(13,10))

  t:=cnt
  d:=mul2(d1,d2)
  t:=cnt-t
  ser.str(string("assembler(2) ... "))
  ser.dec(t)
  ser.str(string(13,10))

  t:=cnt
  d:=mul4(d1,d2)
  t:=cnt-t
  ser.str(string("assembler(4) ... "))
  ser.dec(t)
  ser.str(string(13,10))

  waitcnt(_clkfreq+cnt)
  ser.stop
  cogstop(0)

pub mul1(v1,v2):vres
  asm
	      abs       v1, v1 wc
	if_c  neg       v2, v2
	      abs       v2, v2 wc
	      mov       vRes, v2
	      min       v2, v1
	      max       v1, vRes
	if_c  neg       v2, v2
	      mov       vRes, #0
  :loop       shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	if_nz jmp       #:loop
  endasm

pub mul2(v1,v2):vres
  asm
	      abs       v1, v1 wc
	if_c  neg       v2, v2
	      abs       v2, v2 wc
	      mov       vRes, v2
	      min       v2, v1
	      max       v1, vRes
	if_c  neg       v2, v2
	      mov       vRes, #0
  :loop       shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	      shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	if_nz jmp       #:loop
  endasm

pub mul4(v1,v2):vres
  asm
	      abs       v1, v1 wc
	if_c  neg       v2, v2
	      abs       v2, v2 wc
	      mov       vRes, v2
	      min       v2, v1
	      max       v1, vRes
	if_c  neg       v2, v2
	      mov       vRes, #0
  :loop       shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	      shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	      shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	      shr       v1, #1 wc, wz
	if_c  add       vRes, v2
	      shl       v2, #1
	if_nz jmp       #:loop
  endasm

Compile to inline-asm-loop-unroll.spin.lmm.binary:

fastspin -O2 inline-asm-loop-unroll.spin -o inline-asm-loop-unroll.spin.lmm.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
inline-asm-loop-unroll.spin
|-FullDuplexSerial.spin
inline-asm-loop-unroll.spin.lmm.pasm
Done.
Program size is 2988 bytes

Run it in spinsim:

spinsim -b inline-asm-loop-unroll.spin.lmm.binary
d1,d2        ... -16097087,1024734416
internal     ... 592
assembler(1) ... 816
assembler(2) ... 864
assembler(4) ... 1024

Compile to inline-asm-loop-unroll.spin.cog.binary:

fastspin -O2 inline-asm-loop-unroll.spin --code=cog -o inline-asm-loop-unroll.spin.cog.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
inline-asm-loop-unroll.spin
|-FullDuplexSerial.spin
inline-asm-loop-unroll.spin.cog.pasm
Done.
Program size is 2244 bytes

Run it in spinsim:

spinsim -b inline-asm-loop-unroll.spin.cog.binary
d1,d2        ... -2131455532,-1176269796
internal     ... 548
assembler(1) ... 544
assembler(2) ... 496
assembler(4) ... 464

Interesting: In LMM assembler, unrolling the loop slows it down. This needs a closer look.

4.1.5 mandelbrot-s4p12.spin

File mandelbrot-s4p12.spin:

''
'' mandelbrot-s4p12.spin
''
con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

  xmin=round(-2.1*float(1<<12))
  xmax=round( 0.7*float(1<<12))

  ymin=round(-1.2*float(1<<12))
  ymax=round( 1.2*float(1<<12))

  maxiter=32

  MPX=79 ' 0..79
  MPY=24 ' 0..24

  dx=(xmax-xmin)/MPX
  dy=(ymax-ymin)/MPY

  c4=4<<12

obj
  ser : "spin/FullDuplexSerial"

pub main | c,cx,cy,x,y,x2,y2,iter,px,py

  ser.start(31,30,0,115200)

  cy:=ymin
  repeat py from 0 to MPY
    cx:=xmin
    repeat px from 0 to MPX
      x:=0
      y:=0
      iter:=0
      repeat while iter=<maxiter
	x2:=(x*x)~>12
	y2:=(y*y)~>12
	if x2+y2>c4
	  quit
	y:=((x*y)~>11)+cy
	x:=x2-y2+cx
	iter+=1
      cx+=dx
      ser.tx(iter+32)
    cy+=dy
    ser.tx(10)

  waitcnt(_clkfreq+cnt)
  ser.stop
  cogstop(0)

Compile to mandelbrot-s4p12.spin.binary:

fastspin -O2 mandelbrot-s4p12.spin -o mandelbrot-s4p12.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
mandelbrot-s4p12.spin
|-FullDuplexSerial.spin
mandelbrot-s4p12.spin.pasm
Done.
Program size is 2048 bytes

Run it in spinsim:

spinsim -b mandelbrot-s4p12.spin.binary
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$######""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*4:/+('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),AAAAAAA,'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*,AAAAAA/+))('&&&&)'%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.AA=/<AAAAAAAAAAAAAAA/++A..:2%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&'),+1AAAAAAAAAAAAAAAAAAAAAAAAA1('&%$$####
!!!!"##########$$$$$%%&(-(''''''''''''(*,5AAAAAAAAAAAAAAAAAAAAAAAAAAAA+)-&%$$###
!!!!####$$$$$$$$%%%%%&'(*-A1.+.A-4+))**AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4-(&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.5AAAAAAAAA8/0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3(%%$$$$#
!!!#$$$$$$$%&&&&''().-5.5AAAAAAAAAAAAA>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'&%%$$$$#
!!!(**+-+;732/;0045;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-3.AAAAAAAAAAAAAA?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'&%%$$$$#
!!!!#$$$$$$$$$%%%%%%'''/,.7AAAAAAAAA;/0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-:2.,/>-5+))**<AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4+(&%$$$##
!!!!"##########$$$$$%%&(-(''''(''''''((*,4AAAAAAAAAAAAAAAAAAAAAAAAAAA4+)-&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&')A,4AAAAAAAAAAAAAAAAAAAAAAAAA/('&%%$####
!!!!!!""##################$$$$$$%%%%%%&&&'*.AAA0AAAAAAAAAAAAAAAA1,,A//9)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&(())((()**-AAAAAA/+)))'&&&')'%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,AAAAAAA+'&&%%%%%$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*7A0+('&%%%$$$$$#######"""
!!!!!!!!!!!"""""""######################$$$$$$$$$%%%&&(+.)-*&%$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$%%'6(%%%$$$$$######""""""""""
!!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""

4.1.6 mandelbrot-s8p24.spin

File mandelbrot-s8p24.spin:

' mandelbrot-s8p24.spin

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

  xmin=round(-2.1*float(1<<24))
  xmax=round( 0.7*float(1<<24))

  ymin=round(-1.2*float(1<<24))
  ymax=round( 1.2*float(1<<24))

  maxiter=32

  MPX=79 ' 0..MPX
  MPY=24 ' 0..MPY

  dx=(xmax-xmin)/MPX
  dy=(ymax-ymin)/MPY

  c4=4<<24

obj
  ser : "spin/FullDuplexSerial"

pub main | c,cx,cy,x,y,x2,y2,iter,px,py

  ser.start(31,30,0,115200)

  cy:=ymin
  repeat py from 0 to MPY
    cx:=xmin
    repeat px from 0 to MPX
      x:=0
      y:=0
      iter:=0
      repeat while iter=<maxiter
	x2:=(x**x)<<8 | (x*x)>>24 ' x*x
	y2:=(y**y)<<8 | (y*y)>>24 ' y*y
	if x2+y2>c4
	  quit
	y:=((x**y)<<9 | (x*y)>>23)+cy ' 2*x*y+cy
	x:=x2-y2+cx
	iter+=1
      cx+=dx
      ser.tx(iter+32)
    cy+=dy
    ser.tx(10)

  waitcnt(_clkfreq+cnt)
  ser.stop
  cogstop(0)

Compile to mandelbrot-s8p24.spin.binary:

fastspin -O2 mandelbrot-s8p24.spin -o mandelbrot-s8p24.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
mandelbrot-s8p24.spin
|-FullDuplexSerial.spin
mandelbrot-s8p24.spin.pasm
Done.
Program size is 2132 bytes

Run it in spinsim:

spinsim -b mandelbrot-s8p24.spin.binary
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####"""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*A;/*('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),AAAAAA@+'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-AAAAAA.+))('&&&&+&%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.AAA08AAAAAAAAAAAAAAA/+,A//A)%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&')-+7AAAAAAAAAAAAAAAAAAAAAAAAA4(&&%$$####
!!!!"##########$$$$$%%&(,('''''''''''((*-5AAAAAAAAAAAAAAAAAAAAAAAAAAA3+)4&%$$###
!!!!####$$$$$$$$%%%%%&'(*-A1.+/A-4+))**AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3+'&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.7AAAAAAAAA9/0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<6'%%$$$$#
!!!#$$$$$$$%&&&&''().-2.6AAAAAAAAAAAAA>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'&%%$$$$#
!!!378<@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-2.6AAAAAAAAAAAAA>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'&%%$$$$#
!!!!#$$$$$$$$$%%%%%%'''++.7AAAAAAAAA9/0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<6'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-A1.+/A-4+))**AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3+'&%$$$##
!!!!"##########$$$$$%%&(,('''''''''''((*-5AAAAAAAAAAAAAAAAAAAAAAAAAAA3+)4&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&')-+7AAAAAAAAAAAAAAAAAAAAAAAAA4(&&%$$####
!!!!!!""###################$$$$$%%%%%%&&&'+.AAA08AAAAAAAAAAAAAAA/+,A//A)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-AAAAAA.+))('&&&&+&%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),AAAAAA@+'&%%%%%$$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*A;/*('&%%$$$$$$#######"""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####"""""""""""
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""

4.1.7 minimal.spin

Like FlexBASIC and FlexC, FlexSPIN defaults (on Propeller1) to expecting a 5MHz quartz and will use a 16 times PLL.

@@@TODO@@@ look up Propeller2 defaults.

Also there are some useful library functions available (e.g. _tx, pausems) but more about this will be added later. Maybe… ;-)

File minimal.spin:

pub surprise | s, c
  s := string("Surprised?", 13, 10)
  repeat while c := byte[s++]
    _tx(c)
  pausems(1000)

Compile to minimal.bas.binary:

fastspin minimal.spin -o minimal.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  8 2019
minimal.spin
minimal.spin.pasm
Done.
Program size is 916 bytes

Run it in spinsim:

spinsim -b minimal.spin.binary
Surprised?

4.1.8 pseudorandom.spin

File pseudorandom.spin:

con
  _clkmode = xtal1 + pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial.spin"

pub main | r
  ser.start(31, 30, 0, 115200)

  repeat 10
    ser.dec(||?r // 20)
    ser.tx(32)

  waitcnt(_clkfreq + cnt)
  ser.stop
  cogstop(0)

Compile to pseudorandom.spin.binary:

fastspin -O2 pseudorandom.spin -o pseudorandom.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
pseudorandom.spin
|-FullDuplexSerial.spin
pseudorandom.spin.pasm
Done.
Program size is 2208 bytes

Run it in spinsim:

spinsim -b pseudorandom.spin.binary
9 19 2 8 8 0 3 8 6 6 

4.1.9 spin2-operators.spin

FlexSPIN documentation: spin2-operators(FlexSPIN)

File spin2-operators.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub init
  ser.start( 31, 30, 0, 115200 )
  main
  waitcnt( _clkfreq + cnt )
  ser.stop
  cogstop( 0 )

pub main | a, b, c, d

  ''++
  '' a \ b   uses the value of a, but then sets a to b
  ''
  a := 113
  b := 335

  ser.dec( a \ b )
  ser.str( string( 13, 10 ) )
  ser.dec( a )
  ser.str( string( 13, 10 ) )
  ''--

  ''++
  '' evil mad scientist mode... mwhuaaahaahhaahahaaa...
  ''
  a := 0
  b := 90
  c := 180
  d := 270

  repeat 13
    ser.dec( a \ b \ c \ d \ a )
    ser.tx( 32 )

  ser.str( string( "...", 13, 10 ) )
  ''--

  ''++
  '' x <=> y returns -1, 0, or 1 if x < y, x == y, or x > y
  ''
  '' @@@TODO@@@ add example
  ''--

Compile to spin2-operators.spin.binary:

fastspin spin2-operators.spin -o spin2-operators.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
spin2-operators.spin
|-FullDuplexSerial.spin
spin2-operators.spin.pasm
Done.
Program size is 2484 bytes

Run it in spinsim:

spinsim -b spin2-operators.spin.binary
113
335
0 90 180 270 0 90 180 270 0 90 180 270 0 ...

4.1.10 tuple.spin

FlexSPIN documentation: multiple-return-values-and-assignments(FlexSPIN)

File tuple.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

pub main | i, s, d

  ser.start(31, 30, 0, 115200)

  s, d := 0, 1                  ' tuple assignment
  repeat i from 1 to 10
    s, d := f(s, d)             ' tuple assignment
    ser.dec(s)
    ser.tx(32)

  ser.str(string(13, 10))
  waitcnt(_clkfreq + cnt)
    ser.stop
  cogstop(0)

pub f(s, d) : ss, dd            ' function returning a tuple
  ss := s + d
  dd := s

Compile to tuple.spin.binary:

fastspin -O2 tuple.spin -o tuple.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
tuple.spin
|-FullDuplexSerial.spin
tuple.spin.pasm
Done.
Program size is 2224 bytes

Run it in spinsim:

spinsim -b tuple.spin.binary
1 1 2 3 5 8 13 21 34 55 

4.2 FlexBASIC

4.2.1 anonymous-function1.bas

FlexBASIC documentation: anonymous-functions(FlexBASIC)

File anonymous-function1.bas:

type intfunc as function(x as integer) as integer
dim as intfunc anonfunc

anonfunc = function(n as integer) as integer
	     return n * n
	   end function

print anonfunc(5)

Compile to anonymous-function1.bas.binary:

fastspin -O2 anonymous-function1.bas -o anonymous-function1.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
anonymous-function1.bas
fmt.c
gcptrs.spin
strlen.c
anonymous-function1.bas.pasm
Done.
Program size is 6384 bytes

Run it in spinsim:

spinsim -b anonymous-function1.bas.binary
25

4.2.2 anonymous-function2.bas

FlexBASIC documentation: anonymous-functions(FlexBASIC)

See https://github.com/totalspectrum/spin2cpp/blob/master/doc/basic.md#anonymous-functions.

File anonymous-function2.bas:

type intfunc as function(x as integer) as integer
dim as intfunc anonfunc

anonfunc = (function(n as integer) n * n)

print anonfunc(6)

Compile to anonymous-function2.bas.binary:

fastspin -O2 anonymous-function2.bas -o anonymous-function2.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
anonymous-function2.bas
fmt.c
gcptrs.spin
strlen.c
anonymous-function2.bas.pasm
Done.
Program size is 6384 bytes

Run it in spinsim:

spinsim -b anonymous-function2.bas.binary
36

4.2.3 anonymous-function3.bas

FlexBASIC documentation: anonymous-functions(FlexBASIC)

See https://github.com/totalspectrum/spin2cpp/blob/master/doc/basic.md#anonymous-functions.

File anonymous-function3.bas:

type intfunc as function(x as integer) as integer
dim as intfunc anonfunc

anonfunc = [ n :=> n * n ]

print anonfunc(7)

Compile to anonymous-function3.bas.binary:

fastspin -O2 anonymous-function3.bas -o anonymous-function3.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
anonymous-function3.bas
fmt.c
gcptrs.spin
strlen.c
anonymous-function3.bas.pasm
Done.
Program size is 6384 bytes

Run it in spinsim:

spinsim -b anonymous-function3.bas.binary
49

4.2.4 anonymous-sub1.bas

@@@TODO@@@ (Where in the doc are anonymous subroutines?)

File anonymous-sub1.bas:

dim as sub() anonsub

anonsub = sub()
  print "Rumpelstiltskin?"
end sub

anonsub
anonsub()

Compile to anonymous-sub1.bas.binary:

fastspin -O2 anonymous-sub1.bas -o anonymous-sub1.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
anonymous-sub1.bas
fmt.c
gcptrs.spin
strlen.c
anonymous-sub1.bas.pasm
Done.
Program size is 5376 bytes

Run it in spinsim:

spinsim -b anonymous-sub1.bas.binary
Rumpelstiltskin?
Rumpelstiltskin?

4.2.5 anonymous-sub2.bas

@@@TODO@@@ (Where in the doc are anonymous subroutines?)

File anonymous-sub2.bas:

dim as sub() anonsub

anonsub = [: print "Rumpelstiltskin!" ]

anonsub
anonsub()

Compile to anonymous-sub2.bas.binary:

fastspin -O2 anonymous-sub2.bas -o anonymous-sub2.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
anonymous-sub2.bas
fmt.c
gcptrs.spin
strlen.c
anonymous-sub2.bas.pasm
Done.
Program size is 5376 bytes

Run it in spinsim:

spinsim -b anonymous-sub2.bas.binary
Rumpelstiltskin!
Rumpelstiltskin!

4.2.6 cnt-dira-outa.bas

Using the well known register names works and makes BASIC look a bit SPINier. It's nice to have this option!

File cnt-dira-outa.bas:

dira = 0xFFFFFFFF
do
  outa = cnt
loop

Compile to cnt-dira-outa.bas.binary:

fastspin --code=cog -o cnt-dira-outa.bas.binary cnt-dira-outa.bas
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  8 2019
cnt-dira-outa.bas
cnt-dira-outa.bas.pasm
Done.
Program size is 68 bytes

Run it in gear:

cnt-dira-outa.bas.png

cnt-dira-outa.bas.png

4.2.7 colon.bas

FlexBASIC documentation: multiple-statements-per-line(FlexBASIC)

File colon.bas:

print"Hello, "; : print "world!"

Compile to colon.bas.binary:

fastspin -O2 colon.bas -o colon.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
colon.bas
fmt.c
strlen.c
colon.bas.pasm
Done.
Program size is 1768 bytes

Run it in spinsim:

spinsim -b colon.bas.binary
Hello, world!

4.2.8 extending-lines.bas

FlexBASIC documentation: extending-lines(FlexBASIC)

An extremely long line can be seen in static-image-vga-512x384x1.bas.

File extending-lines.bas:

print"Hello, "; _
     "World!"

Compile to extending-lines.bas.binary:

fastspin -O2 extending-lines.bas -o extending-lines.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
extending-lines.bas
fmt.c
strlen.c
extending-lines.bas.pasm
Done.
Program size is 1860 bytes

Run it in spinsim:

spinsim -b extending-lines.bas.binary
Hello, World!

4.2.9 hopper-vga-512x384x1.bas

See https://forums.parallax.com/discussion/comment/1453190/#Comment_1453190.

File hopper-vga-512x384x1.bas:

''++ -------------------------------------------------------------------------
'' hopper-vga-512x384x1.bas
''
'' set the VGA pin(group) as needed a few lines below.
''-- -------------------------------------------------------------------------

''++
'' set up VGA and preset the tiles' colors
''
dim vga as class using "VGA_512x384_Bitmap.spin"
''
dim shared as ulong sync
dim shared as ulong bitmap(vga.hp/32*vga.vp)
dim shared as ushort colors(vga.xtiles*vga.ytiles)
''
''        lowest pin of VGA pingroup
''        |
''        V
vga.start(16, @colors, @bitmap, @sync)
''
'' set same colorpair for all tiles
''
wordfill(@colors,&b111111_00_010101_00,192) ' ffffff_00_bbbbbb_00
''--

''++ =========================================================================

const a =   3.0
const b =  -5.0
const c =   7.0

const scale = 10.0

dim as single x,y,xn,yn

x = 0.0
y = 0.0

do
  xn = y-sgn(x)*sqrt(abs(b*x-c))
  yn = a-x
  x  = xn
  y  = yn
  plot 255.5+x*scale,191.5+y*scale
loop

''-- =========================================================================

''++
sub plot(x as integer,y as integer)
#ifdef PRINT
  print x," ",y
#endif
  if 0<=x and x<=511 and 0<=y and y<=383 then
    var index = y<<4 + x>>5 + 1
    bitmap(index) = bitmap(index) or 1<<(x and 31)
  end if
end sub
''--

''++
function sgn(x as single) as single
  if x>0.0 return 1.0
  if x<0.0 return -1.0
  return 0.0
end function
''--

Compile to hopper-vga-512x384x1.bas.binary:

fastspin -O2 hopper-vga-512x384x1.bas -o hopper-vga-512x384x1.bas.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
hopper-vga-512x384x1.bas
|-VGA_512x384_Bitmap.spin
hopper-vga-512x384x1.bas.pasm
Done.
Program size is 27940 bytes

Run it in gear:

hopper-vga-512x384x1.bas.png

hopper-vga-512x384x1.bas.png

4.2.10 inline-asm.bas

FlexBASIC documentation: asm(FlexBASIC)

File inline-asm.bas:

function answer(question as ulong) as ulong
  dim result as ulong
  asm
	  mov     result, question
	  add     result, result
	  add     result, question
  end asm
  return result
end function

print "the answer is ";answer(14)

Compile to inline-asm.bas.binary:

fastspin -O2 inline-asm.bas -o inline-asm.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
inline-asm.bas
fmt.c
strlen.c
inline-asm.bas.pasm
Done.
Program size is 2644 bytes

Run it in spinsim:

spinsim -b inline-asm.bas.binary
the answer is 42

4.2.11 line-numbers.bas

@@@TODO@@@ where are line numbers in the docs?

File line-numbers.bas:

100 for i=0 to 5
110   gosub 900
120 next i
199 goto 999
900 if i < 2 print "book! ";
910 if i mod 2 print "raaadiiiooo! ";
920 if i mod 3 print "yipyip! ";
930 print
940 return
999 print "happy! happy! happy!"

Loosely based upon https://www.youtube.com/watch?v=z_trSIBCgF0. ;-)

Compile to line-numbers.bas.binary:

fastspin -O2 line-numbers.bas -o line-numbers.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
line-numbers.bas
fmt.c
strlen.c
line-numbers.bas.pasm
Done.
Program size is 2124 bytes

Run it in spinsim:

spinsim -b line-numbers.bas.binary
book! 
book! raaadiiiooo! yipyip! 
yipyip! 
raaadiiiooo! 
yipyip! 
raaadiiiooo! yipyip! 
happy! happy! happy!

4.2.12 mandelbrot-s4p12.bas

File mandelbrot-s4p12.bas:

'
' translated to BASIC from mandelbrot16-20180406-fds.spin
'-------------------------------------------------------------------------------

'++
  const xmin = (-21<<12)/10
  const xmax = (  7<<12)/10

  const ymin = (-12<<12)/10
  const ymax = ( 12<<12)/10

  const maxiter = 32

  const MPX = 79 ' 0..79
  const MPY = 24 ' 0..24

  const dx = (xmax-xmin)/MPX
  const dy = (ymax-ymin)/MPY

  const c4 = 4<<12
'--

'++
' was main
'
  dim as integer x,y,x2,y2,cx,cy,iter

  cy = ymin
  for py = 0 to MPY
    cx = xmin
    for px = 0 to MPX
      x = 0
      y = 0
      x2 = 0
      y2 = 0
      iter = 0
      while iter < maxiter and x2+y2 <= c4
	y = ((x*y)>>11)+cy
	x = x2-y2+cx
	iter = iter+1
	x2 = (x*x)>>12
	y2 = (y*y)>>12
      end while
      cx = cx+dx
      print \(iter+32);
    next px
    cy = cy+dy
    print
  next py

#ifdef MagicExit
  print \255;\0;\0;
#endif
'--

Compile to mandelbrot-s4p12.bas.binary:

fastspin -O2 mandelbrot-s4p12.bas -o mandelbrot-s4p12.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
mandelbrot-s4p12.bas
fmt.c
mandelbrot-s4p12.bas.pasm
Done.
Program size is 1528 bytes

Run it in spinsim:

spinsim -b mandelbrot-s4p12.bas.binary
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$#####"""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*5:/+('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@,'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*,@@@@@@/+))('&&&&)'%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.@@=/<@@@@@@@@@@@@@@@/++@..93%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&'),+2@@@@@@@@@@@@@@@@@@@@@@@@@1(&&%$$####
!!!!"##########$$$$$%%&(-(''''''''''''(*,5@@@@@@@@@@@@@@@@@@@@@@@@@@@@+)-&%$$###
!!!!####$$$$$$$$%%%%%&'(*-@1.+.@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4-(&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.6@@@@@@@@@8/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3(%%$$$$#
!!!#$$$$$$$%&&&&''()/-5.5@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?'&%%$$$$#
!!!(**+/+<523/80/46@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-2.@@@@@@@@@@@@@@?@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$#
!!!!#$$$$$$$$$%%%%%&'''/,.7@@@@@@@@@;/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@0'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-:2.,/?-5+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4+(&%$$$##
!!!!"##########$$$$$%%&(-(''''(''''''((*,4@@@@@@@@@@@@@@@@@@@@@@@@@@@4+).&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&')<,4@@@@@@@@@@@@@@@@@@@@@@@@@/('&%%$####
!!!!!!""##################$$$$$$%%%%%%&&&'*.@@@0@@@@@@@@@@@@@@@@1,,@//9)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&(())((()**-@@@@@@/+)))'&&&')'%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,@@@@@@@+'&&%%%%%$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*7@0+('&%%%$$$$$#######"""
!!!!!!!!!!!"""""""######################$$$$$$$$$%%%&&(+-).*&%$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$%%'3(%%%$$$$$######""""""""""
!!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""

4.2.13 mandelbrot-s4p12-vga-320x240x2.bas

Everyone loves a fresh almond bread (Mandelbrot).
Right?

This program uses [Kwabena W. Agyeman]'s "VGA64 Bitmap Engine" to display a 320x240x2 image. Its initialisation is slightly different than in the monochrome examples and its drawing routine and named constants for the colours are used from BASIC.

The Mandelbrot algorithm is run in 16 bit rational arithmetic with 12 bit accuracy (1/4096) for the broken part. That's enough for some simple pictures but for deeper zooms you'd need 32 bit rationals or floating point. The main focus of the example is how to interface this VGA engine, so using the faster and a bit less accurate arithmetic is ok here.

@@@TODO@@@ link to VGA64 Bitmap Engine in OBEX.

File mandelbrot-s4p12-vga-320x240x2.bas:

''++ -------------------------------------------------------------------------
'' mandelbrot-s4p12-vga-320x240x2.bas
''
''                     translated to BASIC from mandelbrot16-20180406-fds.spin
''
'' set the VGA pin(group) as needed a few lines below.
''-- -------------------------------------------------------------------------

dim vga as class using "VGA64_BMPEngine.spin"

const pingroup = 2
const bpp = 2 ' bits per pixel

const xsize = 320
const ysize = 240

dim as ulong bitmap(((xsize*ysize)/32)*bpp)

vga.bmpenginestart(pingroup,bpp,xsize,ysize,@bitmap) ' check rc

vga.displaycolor(0,vga.black)
vga.displaycolor(1,vga.light_red)
vga.displaycolor(2,vga.light_green)
vga.displaycolor(3,vga.light_blue)

''++ ===========================================================================

const xmin = (-14<<12)/10 ' (-21<<12)/10
const xmax =            0 ' (  7<<12)/10

const ymin = (-12<<12)/10 ' (-12<<12)/10
const ymax =            0 ' ( 12<<12)/10

const maxiter = 32

const MPX = xsize-1
const MPY = ysize-1

const dx = (xmax-xmin)/MPX
const dy = (ymax-ymin)/MPY

const c4 = 4<<12

dim as integer x,y,x2,y2,cx,cy,iter

cy = ymin
for py = 0 to MPY
  cx = xmin
  for px = 0 to MPX
    x = 0
    y = 0
    x2 = 0
    y2 = 0
    iter = 0
    while iter < maxiter and x2+y2 <= c4
      y = ((x*y)>>11)+cy
      x = x2-y2+cx
      iter = iter+1
      x2 = (x*x)>>12
      y2 = (y*y)>>12
    end while
    cx = cx+dx
    vga.plotpixel(iter and 3,px,py,@bitmap)
  next px
  cy = cy+dy
next py

''-- ===========================================================================

''++
do
loop
''--

Compile to mandelbrot-s4p12-vga-320x240x2.bas.binary:

fastspin mandelbrot-s4p12-vga-320x240x2.bas -o mandelbrot-s4p12-vga-320x240x2.bas.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
mandelbrot-s4p12-vga-320x240x2.bas
|-VGA64_BMPEngine.spin
mandelbrot-s4p12-vga-320x240x2.bas.pasm
Done.
Program size is 21964 bytes

Run it in gear:

mandelbrot-s4p12-vga-320x240x2.bas.png

mandelbrot-s4p12-vga-320x240x2.bas.png

4.2.14 mandelbrot-s8p24.bas

File mandelbrot-s8p24.bas:

'
' translated from mandelbrot32-20180317-b.spin
'-------------------------------------------------------------------------------

'++
  const xmin = (-21<<24)/10
  const xmax = (  7<<24)/10

  const ymin = (-12<<24)/10
  const ymax = ( 12<<24)/10

  const maxiter = 32

  const MPX = 79 ' 0..79
  const MPY = 24 ' 0..24

  const dx = (xmax-xmin)/MPX
  const dy = (ymax-ymin)/MPY

  const c4 = 4<<24
'--

'++
' was main
'
dim as integer x,y,x2,y2,cx,cy,iter

  cy = ymin
  for py = 0 to MPY
    cx = xmin
    for px = 0 to MPX
      x = 0
      y = 0
      x2 = 0
      y2 = 0
      iter = 0
      while iter < maxiter and x2+y2 <= c4
	y = hack.multimes2(x,y)+cy
	x = x2-y2+cx
	iter = iter+1
	x2 = hack.mul(x,x)
	y2 = hack.mul(y,y)
      end while
      cx = cx+dx
      print \(iter+32);
    next px
    cy = cy+dy
    print
  next py

#ifdef MagicExit
  print \255;\0;\0;
#endif
'--

'++
class hacks using "mandelbrot-s8p24.hacks.spin"
dim hack as hacks
' hack.mul(x,y) does s8p24 fp multiplication
' hack.multimes2(x,y) does mul(x,y)*2
'--

File mandelbrot-s8p24.hacks.spin:

pub mul(x,y)
  return (x**y)<<8 | (x*y)>>24

pub multimes2(x,y)
  return (x**y)<<9 | (x*y)>>23

Compile to mandelbrot-s8p24.bas.binary:

fastspin -O2 mandelbrot-s8p24.bas -o mandelbrot-s8p24.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
mandelbrot-s8p24.bas
|-mandelbrot-s8p24.hacks.spin
fmt.c
mandelbrot-s8p24.bas.pasm
Done.
Program size is 1604 bytes

Run it in spinsim:

spinsim -b mandelbrot-s8p24.bas.binary
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####"""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*@;/*('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@+'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-@@@@@@.+))('&&&&+&%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.@@@08@@@@@@@@@@@@@@@/+,@//@)%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&')-+7@@@@@@@@@@@@@@@@@@@@@@@@@4(&&%$$####
!!!!"##########$$$$$%%&(,('''''''''''((*-5@@@@@@@@@@@@@@@@@@@@@@@@@@@3+)4&%$$###
!!!!####$$$$$$$$%%%%%&'(*-@1.+/@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3+'&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.7@@@@@@@@@9/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<6'%%$$$$#
!!!#$$$$$$$%&&&&''().-2.6@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$#
!!!379<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-2.6@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$#
!!!!#$$$$$$$$$%%%%%%'''++.7@@@@@@@@@9/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<6'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-@1.+/@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3+'&%$$$##
!!!!"##########$$$$$%%&(,('''''''''''((*-5@@@@@@@@@@@@@@@@@@@@@@@@@@@3+)4&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&')-+7@@@@@@@@@@@@@@@@@@@@@@@@@4(&&%$$####
!!!!!!""###################$$$$$%%%%%%&&&'+.@@@08@@@@@@@@@@@@@@@/+,@//@)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-@@@@@@.+))('&&&&+&%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@+'&%%%%%$$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*@;/*('&%%$$$$$$#######"""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####"""""""""""
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""

4.2.15 mandelbrot-single.bas

File mandelbrot-single.bas:

'
' translated to BASIC from mandelbrot16-20180406-fds.spin
'-------------------------------------------------------------------------------

'++
  const xmin = -2.1
  const xmax =  0.7

  const ymin = -1.2
  const ymax =  1.2

  const maxiter = 32

  const MPX = 79 ' 0..79
  const MPY = 24 ' 0..24

  const dx = (xmax-xmin)/MPX
  const dy = (ymax-ymin)/MPY

  const c4 = 4.0 ' square of escape radius
'--

'++
' was main
'
  dim as single x,y,x2,y2,cx,cy
  dim as integer iter

  cy = ymin
  for py = 0 to MPY
    cx = xmin
    for px = 0 to MPX
      x = 0.0
      y = 0.0
      x2 = 0.0
      y2 = 0.0
      iter = 0
      while iter < maxiter and x2+y2 <= c4
	y = 2.0*x*y+cy
	x = x2-y2+cx
	iter = iter+1
	x2 = x*x
	y2 = y*y
      end while
      cx = cx+dx
      print \(iter+32);
    next px
    cy = cy+dy
    print
  next py

#ifdef MagicExit
  print \255;\0;\0;
#endif
'--

Compile to mandelbrot-single.bas.binary:

fastspin -O2 mandelbrot-single.bas -o mandelbrot-single.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
mandelbrot-single.bas
fmt.c
mandelbrot-single.bas.pasm
Done.
Program size is 2416 bytes

Run it in spinsim:

spinsim -b mandelbrot-single.bas.binary
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####"""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*@;/*('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@+'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-@@@@@@.+))('&&&&+&%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.@@@08@@@@@@@@@@@@@@@/+,@//@)%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&')-+7@@@@@@@@@@@@@@@@@@@@@@@@@4(&&%$$####
!!!!"##########$$$$$%%&(,('''''''''''((*-5@@@@@@@@@@@@@@@@@@@@@@@@@@@3+)4&%$$###
!!!!####$$$$$$$$%%%%%&'(*-@1.+/@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3+'&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.7@@@@@@@@@9/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<6'%%$$$$#
!!!#$$$$$$$%&&&&''().-2.6@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$#
!!!7:=?@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-2.6@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$#
!!!!#$$$$$$$$$%%%%%%'''++.7@@@@@@@@@9/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<6'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-@1.+/@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3+'&%$$$##
!!!!"##########$$$$$%%&(,('''''''''''((*-5@@@@@@@@@@@@@@@@@@@@@@@@@@@3+)4&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&')-+7@@@@@@@@@@@@@@@@@@@@@@@@@4(&&%$$####
!!!!!!""###################$$$$$%%%%%%&&&'+.@@@08@@@@@@@@@@@@@@@/+,@//@)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-@@@@@@.+))('&&&&+&%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@+'&%%%%%$$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*@;/*('&%%$$$$$$#######"""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####"""""""""""
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""

4.2.16 mandelbrot-single-pgm-800x800.bas

File mandelbrot-single-pgm-800x800.bas:

'
' translated from mandelbrot32-20180317-b.spin
'-------------------------------------------------------------------------------

'++
' constants

  const xmin = -2.1 ' -0.79568
  const xmax =  2.1 ' -0.79068

  const ymin = -2.1 ' -0.16337
  const ymax =  2.1 ' -0.15837

  const maxiter = 31

  const MPX = 799 ' 0..800
  const MPY = 799 ' 0..800

  const dx = (xmax-xmin)/MPX
  const dy = (ymax-ymin)/MPY

  const c4 = 4.0
'--

'++
' was main
'
  dim as single x,y,x2,y2,cx,cy
  dim as integer iter

  ' portable greymap header
  print"P2 ";MPX+1;" ";MPY+1;" ";maxiter

  cy = ymin
  for py = 0 to MPY
    cx = xmin
    for px = 0 to MPX
      x = 0.0
      y = 0.0
      x2 = 0.0
      y2 = 0.0
      iter = 0
      while iter < maxiter and  x2+y2 <= c4
	y = 2.0*x*y+cy
	x = x2-y2+cx
	iter = iter+1
	x2 = x*x
	y2 = y*y
      end while
      cx = cx+dx
      print iter
    next px
    cy = cy+dy
  next py
'--

Compile to mandelbrot-single-pgm-800x800.bas.binary:

fastspin -O2 mandelbrot-single-pgm-800x800.bas -o mandelbrot-single-pgm-800x800.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
mandelbrot-single-pgm-800x800.bas
fmt.c
strlen.c
mandelbrot-single-pgm-800x800.bas.pasm
Done.
Program size is 4268 bytes

Run it in spinsim:

spinsim -b mandelbrot-single-pgm-800x800.bas.binary > mandelbrot-single-pgm-800x800.bas.pgm

mandelbrot-single-pgm-800x800.bas.pgm

pnmtopng < mandelbrot-single-pgm-800x800.bas.pgm > mandelbrot-single-pgm-800x800.bas.pgm.png

mandelbrot-single-pgm-800x800.bas.pgm.png

mandelbrot-single-pgm-800x800.bas.pgm.png

4.2.17 option-base.bas

FlexBASIC documentation: option-base(FlexBASIC)

File option-base.bas:

option base 1

dim a(2)
dim b(3)

''
'' set
''
for i=1 to 2
  a(i) = 1000+i
next i

for i=0 to 2
  b(i) = 2000+i
next i

''
'' get
''
for i=1 to 2
  print "a(";i;") = ";a(i)
next i

for i=0 to 2
  print "b(";i;") = ";b(i)
next i

Compile to option-base.bas.binary:

fastspin -O2 option-base.bas -o option-base.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
option-base.bas
fmt.c
strlen.c
option-base.bas.pasm
Done.
Program size is 3124 bytes

Run it in spinsim:

spinsim -b option-base.bas.binary
a(1) = 1001
a(2) = 2000
b(0) = 2000
b(1) = 2001
b(2) = 2002

option base 1 did not prevent using the wrong array indices but at least it documents what the coder had in mind and so may give a hint in which direction the code should be corrected.

That's why I think defining arrays without prior option base n settings should be illegal. There should not be a default because being forced to use option base n adds a bit of documentation that may help to find such errors faster.

4.2.18 peekpoke.bas

@@@TODO@@@ chisel a better example using FlexBASIC's cast. (cast.bas)

See https://forums.parallax.com/discussion/comment/1470253/#Comment_1470253 and its answers, especially https://forums.parallax.com/discussion/comment/1470314/#Comment_1470314.

File peekpoke.bas.bas:

function peek(adr as any) as ubyte
  dim p as ubyte pointer
  p = adr
  return p(0)
end function

sub poke(adr as any, val as ubyte)
  dim p as ubyte pointer
  p = adr
  p(0) = val
end sub

''++ ===========================================================================
'' cast to any
'' is there a better way?
''
'' edit @ 20190510:
'' yes, now there is.
'' see https://github.com/totalspectrum/spin2cpp/blob/master/doc/basic.md#cast
''
function toany(adr as any) as any
  toany = adr
end function
''-- ===========================================================================

dim as string Question$
Question$ = "Surprise?"

'' check "?" being where expected.
'' just to demonstrate peek()
''
if peek(toany(Question$) + 8) == asc("?") then
  print Question$
  poke toany(Question$) + 8, 33
  print Question$
else
  print "Strange things are happening!"
end if

Compile to peekpoke.bas.binary:

fastspin -O2 peekpoke.bas -o peekpoke.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
peekpoke.bas
peekpoke.bas(32) warning: parameter passing discards const attribute from pointer
peekpoke.bas(34) warning: parameter passing discards const attribute from pointer
fmt.c
strlen.c
peekpoke.bas.pasm
Done.
Program size is 1932 bytes

Run it in spinsim:

spinsim -b peekpoke.bas.binary
Surprise?
Surprise!

4.2.19 preprocessor-directive-define.bas

FlexBASIC documentation: define(FlexBASIC)

File preprocessor-directive-define.bas:

#define camouflage "/\/\oo!"
print camouflage

Compile to preprocessor-directive-define.bas.binary:

fastspin -O2 preprocessor-directive-define.bas -o preprocessor-directive-define.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
preprocessor-directive-define.bas
fmt.c
strlen.c
preprocessor-directive-define.bas.pasm
Done.
Program size is 1776 bytes

Run it in spinsim:

spinsim -b preprocessor-directive-define.bas.binary
/\/\oo!

4.2.20 preprocessor-predefined-symbols

@@@TODO@@@ check for new defines. Checked/version: 20190907/3.9.30

FlexBASIC documentation: predefined-symbols(FlexBASIC)

File preprocessor-predefined-symbols.bas:

print "__propeller__  -> ";_
#ifdef __propeller__
  __propeller__
#else
  "*undefined*"
#endif

print "__propeller2__ -> ";_
#ifdef __propeller2__
  __propeller2__
#else
  "*undefined*"
#endif

print "__P2__         -> ";_
#ifdef __P2__
  __P2__
#else
  "*undefined*"
#endif

print "__FLEXBASIC__  -> ";_
#ifdef __FLEXBASIC__
  __FLEXBASIC__
#else
  "*undefined*"
#endif

print "__FASTSPIN__   -> ";_
#ifdef __FASTSPIN__
  __FASTSPIN__
#else
  "*undefined*"
#endif

print "__SPINCVT__    -> ";_
#ifdef __SPINCVT__
  __SPINCVT__
#else
  "*undefined*"
#endif

print "__SPIN2PASM__  -> ";_
#ifdef __SPIN2PASM__
  __SPIN2PASM__
#else
  "*undefined*"
#endif

print "__SPIN2CPP__   -> ";_
#ifdef __SPIN2CPP__
  __SPIN2CPP__
#else
  "*undefined*"
#endif

print "__cplusplus    -> ";_
#ifdef __cplusplus
  __cplusplus
#else
  "*undefined*"
#endif

Compile to preprocessor-predefined-symbols.bas.binary:

fastspin -O2 preprocessor-predefined-symbols.bas -o preprocessor-predefined-symbols.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
preprocessor-predefined-symbols.bas
fmt.c
strlen.c
preprocessor-predefined-symbols.bas.pasm
Done.
Program size is 3580 bytes

Run it in spinsim:

spinsim -b preprocessor-predefined-symbols.bas.binary
__propeller__  -> 1
__propeller2__ -> *undefined*
__P2__         -> *undefined*
__FLEXBASIC__  -> 3
__FASTSPIN__   -> 3
__SPINCVT__    -> 3
__SPIN2PASM__  -> 1
__SPIN2CPP__   -> *undefined*
__cplusplus    -> *undefined*

4.2.21 screen-bitmap-as-2d-array.bas

The ability to define two dimensional arrays loke bitmap(y,x) directly did not exist in earlier versions of FlexBASIC. An older variant of this example defining the screen as array of scanlines addressed as bitmap(y)(x) can be found as screen-bitmap-as-array-of-arrays.bas.

File screen-bitmap-as-2d-array.bas:

option base 0

dim vga as class using "VGA_512x384_Bitmap.spin"

dim shared as ulong sync
dim shared as ubyte bitmap(vga.vp - 1, vga.hp / 8 - 1)

dim shared as ushort colors(vga.xtiles * vga.ytiles - 1)
''
''        lowest pin of VGA pin group
''        |
''        V
vga.start(16, @colors, @bitmap, @sync)
''
'' set set same colorpair for all tiles
''
wordfill(@colors, &b111111_00_010101_00, vga.xtiles * vga.ytiles)

bytefill(@bitmap, 0, vga.vp * vga.hp / 8 )

var xmax = vga.hp - 1
var ymax = vga.vp - 1

for x = 0 to xmax : plot x, 0 : plot x, ymax : next
for y = 0 to ymax : plot 0, y : plot xmax, y : next

for x = 0 to ymax
  plot        x,        x
  plot xmax - x,        x
  plot        x, ymax - x
  plot xmax - x, ymax - x
next

do
loop

sub plot x,y
  bitmap(y, x >> 3) = bitmap(y, x >> 3) or (1 << (x and 7))
end sub

Compile to screen-bitmap-as-2d-array.bas.binary:

fastspin -O2 screen-bitmap-as-2d-array.bas -o screen-bitmap-as-2d-array.bas.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
screen-bitmap-as-2d-array.bas
|-VGA_512x384_Bitmap.spin
screen-bitmap-as-2d-array.bas.pasm
Done.
Program size is 26568 bytes

Run it in gear:

screen-bitmap-as-2d-array.bas.png

screen-bitmap-as-2d-array.bas.png

4.2.22 screen-bitmap-as-array-of-arrays.bas

This demonstrates a way to define multidimensional arrays a(y)(x) as alternative to the more common form a(y,x) which was not possible in earlier versions of FlexBASIC. The example screen-bitmap-as-2d-array.bas demonstrates the newer a(y,x) way.

This example using an array of arrays may still be useful in some contexts:

File screen-bitmap-as-array-of-arrays.bas:

option base 0

dim vga as class using "VGA_512x384_Bitmap.spin"

type scanline as ubyte(vga.hp / 8 - 1)
type screen as scanline(vga.vp - 1)

dim shared as ulong sync
dim shared as screen bitmap

dim shared as ushort colors(vga.xtiles * vga.ytiles - 1)
''
''        lowest pin of VGA pin group
''        |
''        V
vga.start(16, @colors, @bitmap, @sync)
''
'' set set same colorpair for all tiles
''
wordfill(@colors, &b111111_00_000000_00, 192)

bytefill(@bitmap, 0, vga.vp * vga.hp / 8 )

var xmax = vga.hp - 1
var ymax = vga.vp - 1

for x = 0 to xmax : plot x, 0 : plot x, ymax : next
for y = 0 to ymax : plot 0, y : plot xmax, y : next

for x = 0 to ymax
  plot        x,        x
  plot xmax - x,        x
  plot        x, ymax - x
  plot xmax - x, ymax - x
next

do
loop

sub plot x,y
  var byt = x >> 3
  bitmap(y)(byt) = bitmap(y)(byt) or (1 << (x and 7))
end sub

Compile to screen-bitmap-as-array-of-arrays.bas.binary:

fastspin -O2 screen-bitmap-as-array-of-arrays.bas -o screen-bitmap-as-array-of-arrays.bas.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
screen-bitmap-as-array-of-arrays.bas
|-VGA_512x384_Bitmap.spin
screen-bitmap-as-array-of-arrays.bas.pasm
Done.
Program size is 26568 bytes

Run it in gear:

screen-bitmap-as-array-of-arrays.bas.png

screen-bitmap-as-array-of-arrays.bas.png

4.2.23 sendrecvdevice-demo.bas

FlexBASIC documentation: sendrecvdevice(FlexBASIC)

File sendrecvdevice-demo.bas:

dim ser2 as class using "spin/FullDuplexSerial.spin"

ser2.start(31, 30, 0, 115200)

open SendRecvDevice( @ser2.tx, @ser2.rx, @ser2.stop ) as #2

print #2,"Hi! (printed via FullDuplexSerial.spin)"

waitcnt cnt+clkfreq

close #2

Compile to sendrecvdevice-demo.bas.binary:

fastspin -O2 sendrecvdevice-demo.bas -o sendrecvdevice-demo.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
sendrecvdevice-demo.bas
|-FullDuplexSerial.spin
fmt.c
gcptrs.spin
strlen.c
sendrecvdevice-demo.bas.pasm
Done.
Program size is 7092 bytes

Run it in spinsim:

spinsim -b sendrecvdevice-demo.bas.binary
Hi! (printed via FullDuplexSerial.spin)

4.2.24 static-image-vga-512x384x1.bas

An extreme example for a really long line as array initialisation. ;-)

A moderate example can be found in extending-lines.bas.

See https://forums.parallax.com/discussion/comment/1453190/#Comment_1453190.

File static-image-vga-512x384x1.bas.
(Too long to be displayed inline.)

Compile to static-image-vga-512x384x1.bas.binary:

fastspin -O2 static-image-vga-512x384x1.bas -o static-image-vga-512x384x1.bas.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
static-image-vga-512x384x1.bas
|-VGA_512x384_Bitmap.spin
static-image-vga-512x384x1.bas.pasm
Done.
Program size is 26216 bytes

Run it in gear:

static-image-vga-512x384x1.bas.png

static-image-vga-512x384x1.bas.png

4.2.25 xor.bas

FlexBASIC documentation: XOR(FlexBASIC).

File xor.bas:

var x = 13
var y = 42
print x, y

x = x xor y
y = y xor x
x = x xor y
print x, y

Compile to xor.bas.binary:

fastspin xor.bas -o xor.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
xor.bas
fmt.c
strlen.c
xor.bas.pasm
Done.
Program size is 2920 bytes

Run it in spinsim:

spinsim -b xor.bas.binary
13	42
42	13

4.3 FlexC

4.3.1 inline-asm.c

FlexC documentation: inline-assembly(FlexC)

File inline-asm.c:

#include <stdio.h>

int answer(int question) {
   int result;
   __asm {
       mov result, question
       add result, result
       add result, question
   };
   return result;
}

void main( void ) {
  printf( "the answer is %d\n", answer(14) );
}

Compile to inline-asm.c.binary:

fastspin -O2 inline-asm.c -o inline-asm.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
inline-asm.c
fmt.c
strlen.c
inline-asm.c.pasm
Done.
Program size is 2684 bytes

Run it in spinsim:

spinsim -b inline-asm.c.binary
the answer is 42

4.3.2 mandelbrot-float.c

File mandelbrot-float.c:

#include <stdio.h>
#include <stdint.h>

#define XMIN (-2.1)
#define XMAX (0.7)
#define YMIN (-1.2)
#define YMAX (1.2)

#define MAXI (32)

#define DX   ((XMAX-XMIN)/79)
#define DY   ((YMAX-YMIN)/24)

int main(){
  float cx, cy, x, y, x2, y2;
  uint32_t iter;

  for( cy=YMIN; cy<=YMAX; cy+=DY ) {
    for( cx=XMIN; cx<=XMAX; cx+=DX ) {
      x = y = x2 = y2 = 0.0;
      for( iter=0; iter<MAXI && x2+y2<=4.0; iter++ ) {
	y = 2*x*y+cy;
	x = x2-y2+cx;
	x2 = x*x;
	y2 = y*y;
      }
      putchar(32+iter);
    }
    putchar(10);
  }
}

Compile to mandelbrot-float.c.binary:

fastspin -O2 mandelbrot-float.c -o mandelbrot-float.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
mandelbrot-float.c
ftab.c
mandelbrot-float.c.pasm
Done.
Program size is 2856 bytes

Run it in spinsim:

spinsim -b mandelbrot-float.c.binary
!!!!!!!!!!!!!!!"""""""""""""####################################"""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######"""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*@;/*('&%%$$$$$$#######""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@+'&%%%%%$$$$#######
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-@@@@@@.+))('&&&&+&%$$#####
!!!!!!""###################$$$$$%%%%%%&&&'+.@@@08@@@@@@@@@@@@@@@/+,@//@)%%$####
!!!!!"################$$$%%%%%%%%%%&&&&')-+7@@@@@@@@@@@@@@@@@@@@@@@@@4(&&%$$###
!!!!"##########$$$$$%%&(,('''''''''''((*-5@@@@@@@@@@@@@@@@@@@@@@@@@@@3+)4&%$$##
!!!!####$$$$$$$$%%%%%&'(*-@1.+/@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3+'&%$$$#
!!!!#$$$$$$$$$%%%%%%'''++.7@@@@@@@@@9/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<6'%%$$$$
!!!#$$$$$$$%&&&&''().-2.6@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$
!!!7:=?@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2+)'&&%%$$$$
!!!#$$$$$$$%&&&&''().-2.6@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$
!!!!#$$$$$$$$$%%%%%%'''++.7@@@@@@@@@9/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<6'%%$$$$
!!!!####$$$$$$$$%%%%%&'(*-@1.+/@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3+'&%$$$#
!!!!"##########$$$$$%%&(,('''''''''''((*-5@@@@@@@@@@@@@@@@@@@@@@@@@@@3+)4&%$$##
!!!!!"################$$$%%%%%%%%%%&&&&')-+7@@@@@@@@@@@@@@@@@@@@@@@@@4(&&%$$###
!!!!!!""###################$$$$$%%%%%%&&&'+.@@@08@@@@@@@@@@@@@@@/+,@//@)%%$####
!!!!!!!"""####################$$$$$$$$%%%&'())((())*-@@@@@@.+))('&&&&+&%$$#####
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@+'&%%%%%$$$$#######
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*@;/*('&%%$$$$$$#######""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(++)++&$$$$$$$######"""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'0(%%%$$$$$#####""""""""""

4.3.3 mandelbrot-s4p12.c

File mandelbrot-s4p12.c:

// fixpoint arithmetic mandelbrot program
// using 16 bits: viiiffffffffffff
//                ||  |_ broken part
//                ||____ integer part
//                |_____ sign bit
//
// so fixedpoint(x) = x * 4096
//                  = x << 12
// and fixedpoint(x*y) = (x*y)>>12

#include <stdio.h>
#include <stdint.h>

#define XMIN (-8601)
#define XMAX ( 2867)
#define YMIN (-4915)
#define YMAX ( 4915)

#define MAXI (32)

#define DX   ((XMAX-XMIN)/79)
#define DY   ((YMAX-YMIN)/24)

int main() {
  int32_t cx,cy,x,y,x2,y2;
  uint32_t iter;

  for( cy=YMIN; cy<=YMAX; cy+=DY ) {
    for( cx=XMIN; cx<=XMAX; cx+=DX ) {
      x = y = x2 = y2 = 0;
      for( iter=0; iter<MAXI && x2+y2<=16384; iter++ ) {
	y = ((x*y)>>11)+cy;
	x = x2-y2+cx;
	x2 = (x*x)>>12;
	y2 = (y*y)>>12;
      }
      putchar(32+iter);
    }
    putchar(10);
  }
}

Compile to mandelbrot-s4p12.c.binary:

fastspin -O2 mandelbrot-s4p12.c -o mandelbrot-s4p12.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
mandelbrot-s4p12.c
ftab.c
mandelbrot-s4p12.c.pasm
Done.
Program size is 1512 bytes

Run it in spinsim:

spinsim -b mandelbrot-s4p12.c.binary
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$#####"""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*5:/+('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@,'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*,@@@@@@/+))('&&&&)'%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.@@=/<@@@@@@@@@@@@@@@/++@..93%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&'),+2@@@@@@@@@@@@@@@@@@@@@@@@@1(&&%$$####
!!!!"##########$$$$$%%&(-(''''''''''''(*,5@@@@@@@@@@@@@@@@@@@@@@@@@@@@+)-&%$$###
!!!!####$$$$$$$$%%%%%&'(*-@1.+.@-4+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4-(&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.6@@@@@@@@@8/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3(%%$$$$#
!!!#$$$$$$$%&&&&''()/-5.5@@@@@@@@@@@@@>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@?'&%%$$$$#
!!!(**+/+<523/80/46@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-2.@@@@@@@@@@@@@@?@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'&%%$$$$#
!!!!#$$$$$$$$$%%%%%&'''/,.7@@@@@@@@@;/0@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@0'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-:2.,/?-5+))**@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4+(&%$$$##
!!!!"##########$$$$$%%&(-(''''(''''''((*,4@@@@@@@@@@@@@@@@@@@@@@@@@@@4+).&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&')<,4@@@@@@@@@@@@@@@@@@@@@@@@@/('&%%$####
!!!!!!""##################$$$$$$%%%%%%&&&'*.@@@0@@@@@@@@@@@@@@@@1,,@//9)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&(())((()**-@@@@@@/+)))'&&&')'%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,@@@@@@@+'&&%%%%%$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*7@0+('&%%%$$$$$#######"""
!!!!!!!!!!!"""""""######################$$$$$$$$$%%%&&(+-).*&%$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$%%'3(%%%$$$$$######""""""""""
!!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""

4.3.4 monochrome-vga.c

This example is focussing on how to include and initialise the monocrome VGA bitmap "driver".

File monochrome-vga.c:

#include <stdint.h>

struct __using("VGA_512x384_Bitmap.spin") vga;

uint32_t bitmap[vga.hp/32*vga.vp];
uint16_t colors[vga.xtiles*vga.ytiles];
uint32_t sync;

void main(void)
{
  //
  //        lowest pin of VGA pingroup
  //        |
  //        V
  vga.start(16,colors,bitmap,sync);
  //
  // set same colorpair for all tiles
  //
  wordfill(colors,0b110011_00_001100_00,vga.xtiles*vga.ytiles);
  //               magenta on green

  longfill(bitmap,0xf0f0f0f0,vga.hp/32*vga.vp);

  for(;;); // for(ever)
}

Compile to monochrome-vga.c.binary:

fastspin -O2 monochrome-vga.c -o monochrome-vga.c.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.31 Compiled on: Sep 13 2019
monochrome-vga.c
|-VGA_512x384_Bitmap.spin
monochrome-vga.c.pasm
Done.
Program size is 26284 bytes

Run it in gear:

monochrome-vga.c.png

monochrome-vga.c.png

4.3.5 Importing Stuff in C

4.3.5.1 (OLD) Importing LMM-C in LMM-C - io-funcs.c

See https://github.com/totalspectrum/spin2cpp/blob/master/doc/c.md#external-classes-eg-spin-objects. File io-funcs.c:

int puts( const char *s ) {
  int n = 0;

  while( *s ) {
    _tx( *(s++) );
    ++n;
  }
  return n;
}

File io-funcs-demo.c:

struct __using("io-funcs.c") io;

void main( void ) {
  io.puts("Hello, FlexC!\r\n");
}

Compile to io-funcs-demo.c.binary:

fastspin -O2 io-funcs-demo.c -o io-funcs-demo.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
io-funcs-demo.c
|-io-funcs.c
io-funcs-demo.c.pasm
Done.
Program size is 580 bytes

Run it in spinsim:

spinsim -b io-funcs-demo.c.binary
Hello, FlexC!

4.3.5.2 (NEW) Importing LMM-C and Cog-C in LMM-C - SimpleSerial.c

This is a quick and dirty partial translation of SimpleSerial.spin to C. It will be used to demonstrate including of external objects running in LMM or COG mode.

See https://github.com/totalspectrum/spin2cpp/blob/master/Lib/SimpleSerial.spin.

File SimpleSerial.c:

//
// SimpleSerial.c
//
// ...a crude, quick and dirty partial translation of spin2cpp's
// Lib/SimpleSerial.spin (commit 5c67857f0523280874ee654e6139a8d23c7b21c9)
//

#include <stdint.h>

uint8_t txpin, rxpin;
uint32_t baud, txmask, rxmask, bitcycles;

#ifdef PC
// we will be using stdio
#include <stdio.h>
#include <stdlib.h>
//
#else
//
#include <propeller.h>
#ifdef __P2__
#define DIRR DIRB   
#define OUTR OUTB
#define INR  INB
#else
#define DIRR DIRA
#define OUTR OUTA
#define INR  INA
#endif
//
#endif

//
// code: largely taken from FullDuplexSerial.spin
//

uint32_t start(uint32_t rx_pin, uint32_t tx_pin, uint32_t mode, uint32_t baudrate)
{
#ifndef PC
  baud = baudrate;
  bitcycles = clkfreq / baudrate;
  txpin = tx_pin;
  txmask = 1<<txpin;
  rxpin = rx_pin;
  rxmask = 1<<rxpin;
#endif
  return 1;
}

void tx(uint8_t c)
{
  uint32_t val, waitcycles;
#ifdef PC
  putchar(c);
#else
  OUTR |= txmask;
  DIRR |= txmask;
  val = ((uint16_t)c | 256) << 1; // c needs the cast or a bigger type above
  waitcycles = CNT + bitcycles;
  for( int8_t i = 0 ; i<10 ; i++ ) {
     waitcnt( waitcycles += bitcycles );
     if (val & 1)
       OUTR |= txmask;
     else
       OUTR &= !txmask;
     val >>= 1;
  }
#endif
}

uint8_t rx(void) // does NOT return errorcodes outside of the 8 bit range
{
  uint32_t waitcycles, mask, val, x;
#ifdef PC
  val = getchar();
#else
  mask = rxmask;
  DIRR &= !mask; // set for input
  // wait for start bit
  do{
    x = INR;
  }while( x & mask );
  val = 0;
  waitcycles = CNT + (bitcycles >> 1);  // sync for one half bit
  for( int i=0 ; i<8 ; i++ ) {
      val = val >> 1;
      waitcnt(waitcycles += bitcycles);
      x = INR;
      if ( x & mask )
	val |= 0x80;
  }
  // wait for stop bit?
  // skip it for now
  // waitpeq(mask, mask, 0)
#endif
  return val;
}

int32_t stop(void)
{
  waitcnt(clkfreq + cnt);
  return 1;
}
4.3.5.2.1 Include SimpleSerial.c

This simply includes SimpleSerial.c while compiling the main program. It is like including Spin objects in Spin programs and indeed FlexC's way of doing this works with code from FlexSPIN and FlexBASIC too.

File SimpleSerialDemo1.c:

struct __using("SimpleSerial.c") sio;

void str(const char *s)
{
  char c;
  while( c = *s++ )
    sio.tx(c);
}

void main(void)
{
  sio.start(31, 30, 0, 115200);

  str("Yayyyy FastSpin!.\r\n");

  // @@@TODO@@@ make a better batchable sio.rx() test.
  for(;;) {
    char c = sio.rx();
    if( c == 27 )
      break;
    else
      sio.tx( c );
  }

  sio.stop();
}

Compile to SimpleSerialDemo1.c.binary:

fastspin -O2 SimpleSerialDemo1.c -o SimpleSerialDemo1.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
SimpleSerialDemo1.c
|-SimpleSerial.c
SimpleSerialDemo1.c.pasm
Done.
Program size is 1308 bytes

Run it in spinsim:

( sleep 1 ; printf "Absolutely!\r\n\e" ) | spinsim -b SimpleSerialDemo1.c.binary
Yayyyy FastSpin!.
Absolutely!

4.3.5.2.2 Include SimpleSerial.c compiled to COG-PASM

For information about compiling for running in an own cog, see https://github.com/totalspectrum/spin2cpp/blob/master/Fastspin.md#spin-wrappers.

Compile the same SimpleSerial.c from above to SimpleSerial.c.cog.spin:

fastspin -O2 -w SimpleSerial.c -o SimpleSerial.c.cog.spin
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
SimpleSerial.c

File SimpleSerialDemo2.c:

struct __using("SimpleSerial.c.cog.spin") sio;

void str(const char *s)
{
  char c;
  while( c = *s++ )
    sio.tx(c);
}

void main(void)
{
  sio.__cognew();
  sio.start(31, 30, 0, 115200);

  str("Yayyyy FastSpin!.\r\n");

  // @@@TODO@@@ make a better batchable sio.rx() test.
  for(;;) {
    char c = sio.rx();
    if( c == 27 )
      break;
    else
      sio.tx( c );
  }

  sio.stop();
  sio.__cogstop();
}

Compile to sio-funcs-demo.c.binary:

fastspin -O2 SimpleSerialDemo2.c -o SimpleSerialDemo2.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
SimpleSerialDemo2.c
|-SimpleSerial.c.cog.spin
SimpleSerialDemo2.c.pasm
Done.
Program size is 2288 bytes

Run it in spinsim:

( sleep 1 ; printf "Absolutely!\r\n\e" ) | spinsim -b SimpleSerialDemo2.c.binary
Yayyyy FastSpin!.
Absolutely!

6 Labour Ward

6.1 FlexSpin

6.1.1 TODO conditional-expression-demo0.spin

@@@TODO@@@ rename example to conditional-expression-demo0.

FlexSPIN documentation: conditional-expressions(FlexSPIN)

@@@TODO@@@ example for the r := if a then b else c variant.

6.1.2 spinlibdemo.spin

See https://github.com/totalspectrum/spin2cpp/blob/master/doc/spin.md#pub-file-and-pri-file.

File spinlibdemo.spinlib:

pub strcpy(s, d) : r
  r := d
  repeat while byte[d++] := byte[s++]

pub strlen(s) : r
  r := s
  repeat while byte[r]
    r++
  r -= s

File spinlibdemo.spinh:

pub file "spinlibdemo.spinlib" strcpy(s, d)
pub file "spinlibdemo.spinlib" strlen(s)

File spinlibdemo.spin:

con
  _clkmode = xtal1+pll16x
  _clkfreq = 80_000_000

obj
  ser : "spin/FullDuplexSerial"

var
  byte str32[32]

pub main
  ser.start(31, 30, 0, 115200)

  strcpy(string("Hello, World!", 13, 10), str32)
  ser.str(str32)

  ser.dec(strlen(str32))
  ser.str(string(" bytes including CR/LF", 13, 10))

  waitcnt(_clkfreq + cnt)
    ser.stop
  cogstop(0)

''
'' this is the thing to be demonstrated:
''
#include "spinlibdemo.spinh"

Compile to spinlibdemo.spin.binary:

fastspin -O2 spinlibdemo.spin -o spinlibdemo.spin.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
spinlibdemo.spin
|-FullDuplexSerial.spin
spinlibdemo.spinlib
spinlibdemo.spin.pasm
Done.
Program size is 2368 bytes

Run it in spinsim:

spinsim -b spinlibdemo.spin.binary
Hello, World!
15 bytes including CR/LF

6.2 FlexBASIC

6.2.1 The Mystery Of Array Initialising

See http://forums.parallax.com/discussion/comment/1457704/#Comment_1457704 and FlexBASIC documentation: global-member-and-local-variables(FlexBASIC).

File array-initialiser-1.bas:

dim as integer a(5) = { _
1, 2, 3, _
4, 5 _
}

print a(2)

Compile to array-initialiser-1.bas:

fastspin -O2 array-initialiser-1.bas -o array-initialiser-1.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
array-initialiser-1.bas
array-initialiser-1.bas(4) error: initialization is not supported for member variable a

Retry:

File array-initialiser-2.bas:

dim shared as integer a(5) = { _
1, 2, 3, _
4, 5 _
}

print a(2)

Compile to array-initialiser-2.bas.binary:

fastspin -O2 array-initialiser-2.bas -o array-initialiser-2.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
array-initialiser-2.bas
fmt.c
strlen.c
array-initialiser-2.bas.pasm
Done.
Program size is 2700 bytes

Run it in spinsim:

spinsim -b array-initialiser-2.bas.binary
3

Eric explains this behaviour in https://forums.parallax.com/discussion/comment/1457711/#Comment_1457711:

The reason is a little obscure: an ordinary "dim" declares a member variable, which will be different in each instance of a class (even the top level program is really embedded in a class). These cannot be initialized because they're not in a fixed place in memory and there are many copies. "shared" variables though can be initialized because there is only one copy.

6.2.2 variable-initialisation.spin

con
  _clkmode = xtal1 + pll16x
  _clkfreq = 80_000_000

obj
  ser : "FullDuplexSerial.spin"

pub main | s
  ser.start(31, 30, 0, 115200)

  ser.dec(s)
  ser.str(string(13,10))

  waitcnt(_clkfreq + cnt)
  ser.stop
  cogstop(0)

Except for FlexSpin, the other tested compilers initialise the variable s to 0. This may have impact on existing code which assumes the behaviour of the other compilers.

6.2.2.1 BST/BSTC
bstc -Oa -b -L lib -o variable-initialisation.bstc variable-initialisation.spin
Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
Compiled for i386 Linux at 08:17:46 on 2009/07/20
Loading Object variable-initialisation
Loading Object FullDuplexSerial.spin
Program size is 640 longs
Compiled 184 Lines of Code in 0.01 Seconds

spinsim -b variable-initialisation.bstc.binary
0

6.2.2.2 FastSpin/FlexSpin
fastspin -O2 variable-initialisation.spin -o variable-initialisation.flexspin.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
variable-initialisation.spin
|-FullDuplexSerial.spin
variable-initialisation.flexspin.pasm
Done.
Program size is 1948 bytes

spinsim -b variable-initialisation.flexspin.binary
-1593999360

6.2.2.3 HomeSpun
homespun variable-initialisation.spin -b -o variable-initialisation.homespun -L lib/
Homespun Spin Compiler 0.32p1 - Batang Build
parsing variable-initialisation.spin
parsing lib/FullDuplexSerial.spin
compiling variable-initialisation.spin
compiling FullDuplexSerial.spin
writing 760 bytes to variable-initialisation.homespun.binary

spinsim -b variable-initialisation.homespun.binary
0

6.2.2.4 OpenSpin
openspin -u variable-initialisation.spin -o variable-initialisation.openspin.binary -L lib
Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2018 Parallax Inc. DBA Parallax Semiconductor.
Version 1.00.81 Compiled on Jul 15 2019 17:50:54
Compiling...
variable-initialisation.spin
|-FullDuplexSerial.spin
Done.
Unused Method Elimination:
    4 methods removed
    0 objects removed
  116 bytes saved
--------------------------
Program size is 644 bytes
spinsim -b variable-initialisation.openspin.binary
0

6.2.3 TODO compressed-lmm.bas

@@@TODO@@@ It works with 3.9.26, 3.9.27 but not with 3.9.28 to 3.9.30 and this needs investigation.

Starting with version 3.9.26 Spin2CPP/FastSpin supports compressed LMM code generation.

For now just a short reminder.

File compressed-lmm.bas:

_setbaud(33600)
print"Don't forget to switch to a slower baud rate when using compressed LMM."

Compile to compressed-lmm.bas.binary:

fastspin-3.9.27 -z -O2 compressed-lmm.bas -o compressed-lmm.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.27 Compiled on: Sep  4 2019
compressed-lmm.bas
compressed-lmm.bas.pasm
Done.
Program size is 1916 bytes

Run it in spinsim:

spinsim -b33600 compressed-lmm.bas.binary
Don't forget to switch to a slower baud rate when using compressed LMM.

6.2.4 TODO compressed-lmm-2.bas

@@@TODO@@@ With 3.9.28 to 3.9.30 print fails but a simpler example still works.

_setbaud(9600)
var s$="This time the magic word is uvwwv!"
for i=1 to len(s$)
  _tx asc(mid$(s$,i,1))
next
waitcnt cnt+clkfreq

Compile to compressed-lmm-2.bas.binary:

fastspin -z -O2 compressed-lmm-2.bas -o compressed-lmm-2.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
compressed-lmm-2.bas
strings.bas
gcptrs.spin
compressed-lmm-2.bas.pasm
Done.
Program size is 4076 bytes

Run it in spinsim:

spinsim -b9600 compressed-lmm-2.bas.binary
This time the magic word is uvwwv!

6.2.5 TODO cast.bas

FlexBASIC documentation: cast(FlexBASIC)

Version 3.9.27-beta introduces cast.

@@@TODO@@@ more later.

6.2.6 TODO closure.bas

FlexBASIC documentation: closures(FlexBASIC)

6.2.7 TODO nil.bas

FlexBASIC documentation: nil(FlexBASIC)

6.2.8 TODO option-explicit.bas

FlexBASIC documentation: option-explicit(FlexBASIC)

6.2.9 TODO option-implicit.bas

FlexBASIC documentation: option-implicit(FlexBASIC)

6.2.10 TODO pausems.bas

FlexBASIC documentation: pausems(FlexBASIC)

Note to $SELF: waitcnt cnt+clkfreq is soooooo 1980! ;-)
Note to $SELF: pausems can be used in SPIN and C too!

6.2.11 TODO pseudorandom.bas

FlexBASIC documentation: rnd(FlexBASIC)

6.2.12 TODO TV examples

6.2.13 TODO strange.bas

This feels like being in an alternate reality… ;-)

File strange.bas:

dim as integer s$
s$ = 1330
print s$+7

Compile to strange.bas.binary:

fastspin strange.bas -o strange.bas.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  5 2019
strange.bas
fmt.c
strlen.c
strange.bas.pasm
Done.
Program size is 2796 bytes

Run it in spinsim:

spinsim -b strange.bas.binary
1337

6.3 FlexC

6.3.1 TODO classes.c

FlexC documentation: classes(FlexC)

6.3.2 TODO monochrome-bytearray-vga-512x384x1.c

This example is addressing the VGA as two dimensional array of scanlines of unsigned bytes and shows piyel set and clear functions.

The choice of unsigned bytes as the underlying data type makes stamping 8 pixels wide character patterns into the VGA buffer easier.

@@@TODO@@@ show something with characters.

File monochrome-bytearray-vga-512x384x1.c:

#include <stdint.h>

struct __using("VGA_512x384_Bitmap.spin") vga;

uint8_t bitmap[vga.vp][vga.hp/8];
//             \_  _/  \__  __/
//               \/       \/
//        scanlines       (scanline pixels) / (bits of uint8_t)
//
uint16_t colors[vga.xtiles*vga.ytiles];
uint32_t sync;

void plot(int32_t x, int32_t y)         // use smaller (unsigned?) type?
{
  if(0<=x && x<vga.hp && 0<=y && y<vga.vp)
    bitmap[y][x>>3] |= 1<<(x&7);
}

void unplot(int32_t x, int32_t y)       // use smaller (unsigned?) type?
{
  if(0<=x && x<vga.hp && 0<=y && y<vga.vp)
    bitmap[y][x>>3] &= !(1<<(x&7));
}

void main(void)
{
  //
  //        lowest pin of VGA pingroup
  //        |
  //        V
  vga.start(16,colors,bitmap,sync);
  //
  // set same colorpair for all tiles
  //
  wordfill(colors,0b001100_00_010101_00,vga.xtiles*vga.ytiles);
  //                 green on grey

  for( int32_t x=0 ; x<vga.hp; x++ ) { plot(x,0); plot(x,vga.vp-1); }
  for( int32_t y=0 ; y<vga.vp; y++ ) { plot(0,y); plot(vga.hp-1,y); }

  // @@@TODO@@@ show/test unplot()
  // @@@TODO@@@ show/test manipulating tile colorpairs

  for(;;); // for(ever)
}

Compile to monochrome-bytearray-vga-512x384x1.c.binary:

fastspin -O2 monochrome-bytearray-vga-512x384x1.c -o monochrome-bytearray-vga-512x384x1.c.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.31 Compiled on: Sep 13 2019
monochrome-bytearray-vga-512x384x1.c
|-VGA_512x384_Bitmap.spin
monochrome-bytearray-vga-512x384x1.c.pasm
Done.
Program size is 26488 bytes

Run it in gear:

monochrome-bytearray-vga-512x384x1.c.png

monochrome-bytearray-vga-512x384x1.c.png

6.3.3 TODO pseudorandom.c

6.4 General

6.4.1 TODO Generate Directories for Examples Using Org On The Fly

@@@TODO@@@ test putting examples in own directories.

@@@TODO@@@ find way to make these direcories as needed by org.

6.4.2 TODO Need Catchall Category Name

@@@TODO@@@ find name for examples fitting no other category.

6.4.3 TODO Using FastSpin cog objects in bytecode Spin environments

@@@TODO@@@ What would be nice to run compiled by FastSpin in a classic bytecode Spin context?

7 Sick Bay

7.1 FlexSPIN

7.3 FlexC

7.3.1 DONE Block Local Variables

$ cat bnmmn.c

#include <stdio.h>

void main( void ) {
  for( int s=0 ; s<8 ; s++ ) printf("%d ",s);
  for( int s=7 ; s>-1 ; s-- ) printf("%d ",s);
$ make -B bnmmn
cc     bnmmn.c   -o bnmmn
$ ./bnmmn 
0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0 
$ fastspin bnmmn.c 
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.32-beta-5ade57ef Compiled on: Sep 15 2019
bnmmn.c
/tmp/mc-yeti/bnmmn.c:5: error: duplicate definition for s

Shouldn't "int s" be forgotten after each "for"?

Fixed in 3.9.32-beta-dda15696:

$ fastspin bnmmn.c 
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.32-beta-dda15696 Compiled on: Sep 17 2019
bnmmn.c
fmt.c
strlen.c
bnmmn.pasm
Done.
Program size is 2812 bytes
$ spinsim -b bnmmn.binary 
0 1 2 3 4 5 6 7 7 6 5 4 3 2 1 0 

7.3.2 TODO hopper-vga-512x384x1.c

@@@TODO@@@ debug: PEBCAK or bug?

This example should show the same result as the hopper-vga-512x384x1.bas example.

File hopper-vga-512x384x1.c:

#include <stdint.h>
#include <math.h>

struct __using("VGA_512x384_Bitmap.spin") vga;

uint32_t sync;
uint32_t bitmap[vga.hp/32*vga.vp];
uint16_t colors[vga.xtiles*vga.ytiles];

float sgn(float x)
{
  if( 0.0 < x ) return x;
  if( x < 0.0 ) return -x;
  return 0.0;
}

void hopper(float a, float b, float c, float cx, float cy, float scale)
{
  float x=0.0, y=0.0, xn, yn;

  for(;;)
  {
    xn = y-sgn(x)*sqrt(fabs(b*x-c));
    yn = a-x;
    x  = xn;
    y  = yn;
    plot(cx+x*scale,cy+y*scale);
  }
  /*notreached*/
}

void plot(int32_t x, int32_t y)
{
  if( 0<=x && x<vga.hp && 0<=y && y<vga.vp )
     bitmap[y<<4 + x>>5] |= (1<<(x & 31));
}

void main( void )
{
  //
  //        lowest pin of VGA pingroup
  //        |
  //        V
  vga.start(16,colors,bitmap,sync);
  //
  // set same colorpair for all tiles
  //
  wordfill(colors,0b111111_00_010101_00,vga.xtiles*vga.ytiles);
  //                 white on grey

  hopper(3.0, -5.0, 7.0, (vga.hp-1.0)/2.0, (vga.vp-1.0)/2.0, 10.0);

  /*notreached*/
}

Compile to hopper-vga-512x384x1.c.binary:

fastspin -O2 hopper-vga-512x384x1.c -o hopper-vga-512x384x1.c.binary -L lib
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.31-beta-362be4d7 Compiled on: Sep 11 2019
hopper-vga-512x384x1.c
|-VGA_512x384_Bitmap.spin
math.c
hopper-vga-512x384x1.c.pasm
Done.
Program size is 28380 bytes

Run it in gear:

hopper-vga-512x384x1.c.png

hopper-vga-512x384x1.c.png

7.3.3 TODO stdio.h - printf

To do … laaater. ;-)

#include <stdio.h>

void main(void)
{
  int i = printf("%s\n","Test.");
  printf("printf returned %d\n",i);
}

Compile to printftest.c.binary:

fastspin -O2 printftest.c -o printftest.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
printftest.c
fmt.c
strlen.c
printftest.c.pasm
Done.
Program size is 2736 bytes

Run it in spinsim:

spinsim -b printftest.c.binary
Test.
printf returned 0

With gcc:

gcc printftest.c -o printftest && ./printftest
Test.
printf returned 6

Citation needed: Where is the definition that printf() returns the number of characters printed?

7.3.4 TODO longlong.c

FlexC documentation: missing-features(FlexC)

File longlong.c:

#include <stdio.h>

void main(void) {
   long long a, a1, a2;

   printf("sizeof(long long) = %d\n", sizeof(a));

   a1 = 0xffffffff;
   a2 = 0x10101010;
   a  = a1 * a2;
}

Compile to longlong.c.binary:

fastspin -O2 longlong.c -o longlong.c.binary
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  8 2019
longlong.c
fmt.c
strlen.c
/home/yeti/wrk/orgy/fastspin/longlong.c(8) error: Cannot handle expression yet
/home/yeti/wrk/orgy/fastspin/longlong.c(9) error: Cannot handle expression yet
/home/yeti/wrk/orgy/fastspin/longlong.c(10) error: Cannot handle expression yet

7.4 General

7.4.1 TODO forced echo of input

_rx in spin2cpp/sys/p1_code.spin echoes the input. This has to change!

7.4.2 TODO The CRLF question needs to be discussed!

LF is all *nixish OSes want and an extra CR sometimes can cause trouble.

8 Build FastSpin

git clone https://github.com/totalspectrum/spin2cpp.git
Cloning into 'spin2cpp'...

cd spin2cpp
make
mkdir -p ./build
bison -p spinyy -t -b ./build/spin -d frontends/spin/spin.y
frontends/spin/spin.y: warning: 20 shift/reduce conflicts [-Wconflicts-sr]
bison -p basicyy -t -b ./build/basic -d frontends/basic/basic.y
frontends/basic/basic.y: warning: 7 shift/reduce conflicts [-Wconflicts-sr]
bison -p cgramyy -t -b ./build/cgram -d frontends/c/cgram.y
frontends/c/cgram.y: warning: 3 shift/reduce conflicts [-Wconflicts-sr]
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/lexer.o -c frontends/lexer.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/symbol.o -c symbol.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/ast.o -c ast.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/expr.o -c expr.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/dofmt.o -c util/dofmt.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/flexbuf.o -c util/flexbuf.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/lltoa_prec.o -c util/lltoa_prec.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/strupr.o -c util/strupr.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/strrev.o -c util/strrev.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/strdupcat.o -c util/strdupcat.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/to_utf8.o -c util/to_utf8.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/from_utf8.o -c util/from_utf8.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/preprocess.o -c preprocess.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/cppexpr.o -c backends/cpp/cppexpr.c
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/testlex testlex.c build/lexer.o build/symbol.o build/ast.o build/expr.o build/dofmt.o build/flexbuf.o build/lltoa_prec.o build/strupr.o build/strrev.o build/strdupcat.o build/to_utf8.o build/from_utf8.o build/preprocess.o build/cppexpr.o -lm
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/common.o -c frontends/common.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/case.o -c frontends/case.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/spinc.o -c spinc.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/functions.o -c functions.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/cse.o -c cse.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/loops.o -c loops.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/pasm.o -c pasm.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/outdat.o -c backends/dat/outdat.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/outlst.o -c backends/dat/outlst.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/spinlang.o -c frontends/spin/spinlang.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/basiclang.o -c frontends/basic/basiclang.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/clang.o -c frontends/c/clang.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/outasm.o -c backends/asm/outasm.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/assemble_ir.o -c backends/asm/assemble_ir.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/optimize_ir.o -c backends/asm/optimize_ir.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/inlineasm.o -c backends/asm/inlineasm.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/compress_ir.o -c backends/asm/compress_ir.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/outcpp.o -c backends/cpp/outcpp.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/cppfunc.o -c backends/cpp/cppfunc.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/outgas.o -c backends/cpp/outgas.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/directive.o -c mcpp/directive.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/expand.o -c mcpp/expand.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/mbchar.o -c mcpp/mbchar.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/mcpp_eval.o -c mcpp/mcpp_eval.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/mcpp_main.o -c mcpp/mcpp_main.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/mcpp_system.o -c mcpp/mcpp_system.c
gcc -MMD -MP -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/mcpp_support.o -c mcpp/mcpp_support.c
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -DGITREV=29eb7bdd -o build/version.o -c version.c
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/spin.tab.o -c build/spin.tab.c
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/basic.tab.o -c build/basic.tab.c
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/cgram.tab.o -c build/cgram.tab.c
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/spin2cpp spin2cpp.c build/common.o build/case.o build/spinc.o build/lexer.o build/symbol.o build/ast.o build/expr.o build/dofmt.o build/flexbuf.o build/lltoa_prec.o build/strupr.o build/strrev.o build/strdupcat.o build/to_utf8.o build/from_utf8.o build/preprocess.o build/cppexpr.o build/functions.o build/cse.o build/loops.o build/pasm.o build/outdat.o build/outlst.o build/spinlang.o build/basiclang.o build/clang.o build/outasm.o build/assemble_ir.o build/optimize_ir.o build/inlineasm.o build/compress_ir.o build/outcpp.o build/cppfunc.o build/outgas.o build/directive.o build/expand.o build/mbchar.o build/mcpp_eval.o build/mcpp_main.o build/mcpp_system.o build/mcpp_support.o build/version.o build/spin.tab.o build/basic.tab.o build/cgram.tab.o -lm
gcc -g -Wall -I. -I./build -DFLEXSPIN_BUILD -o build/fastspin fastspin.c build/common.o build/case.o build/spinc.o build/lexer.o build/symbol.o build/ast.o build/expr.o build/dofmt.o build/flexbuf.o build/lltoa_prec.o build/strupr.o build/strrev.o build/strdupcat.o build/to_utf8.o build/from_utf8.o build/preprocess.o build/cppexpr.o build/functions.o build/cse.o build/loops.o build/pasm.o build/outdat.o build/outlst.o build/spinlang.o build/basiclang.o build/clang.o build/outasm.o build/assemble_ir.o build/optimize_ir.o build/inlineasm.o build/compress_ir.o build/outcpp.o build/cppfunc.o build/outgas.o build/directive.o build/expand.o build/mbchar.o build/mcpp_eval.o build/mcpp_main.o build/mcpp_system.o build/mcpp_support.o build/version.o build/spin.tab.o build/basic.tab.o build/cgram.tab.o -lm
ls -l build/fastspin build/spin2cpp
-rwxr-xr-x 1 yeti yeti 1556176 Sep  4 23:48 build/fastspin
-rwxr-xr-x 1 yeti yeti 1564184 Sep  4 23:48 build/spin2cpp

build/fastspin
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.30 Compiled on: Sep  4 2019
usage: build/fastspin [options] filename.spin | filename.bas
  [ -h ]              display this help
  [ -L or -I <path> ] add a directory to the include path
  [ -o <name> ]      set output filename to <name>
  [ -b ]             output binary file format
  [ -e ]             output eeprom file format
  [ -c ]             output only DAT sections
  [ -l ]             output DAT as a listing file
  [ -f ]             output list of file names
  [ -q ]             quiet mode (suppress banner and non-error text)
  [ -p ]             disable the preprocessor
  [ -D <define> ]    add a define
  [ -u ]             ignore for openspin compatibility (unused method elimination always enabled)
  [ -2 ]             compile for Prop2
  [ -O# ]            set optimization level:
          -O0 = no optimization
          -O1 = basic optimization
          -O2 = all optimization
  [ -H nnnn ]        set starting hub address
  [ -E ]             skip initial coginit code (usually used with -H)
  [ -w ]             compile for COG with Spin wrappers
  [ -C ]             enable case sensitive mode
  [ -z ]             compress code
  [ --code=cog ]     compile for COG mode instead of LMM
  [ --fcache=N ]     set FCACHE size to N (0 to disable)
  [ --fixedreal ]    use 16.16 fixed point in place of floats
  [ --lmm=xxx ]      use alternate LMM implementation for P1
           xxx = orig uses original fastspin LMM
           xxx = slow uses traditional (slow) LMM
build/spin2cpp
Spin to C++ converter version 3.9.30
Usage: build/spin2cpp [options] file.spin
Options:
  --asm:     output (user readable) PASM code
  --binary:  create binary file for download
  --cogspin: create PASM based Spin object (translate Spin to PASM)
  --ccode:   output C code instead of C++
  --cse:     perform common subexpression optimizations on C code
  --cc=CC:   use CC as the C++ compiler instead of PropGCC
  --code=x : PASM output only: control placement of code
             x can be cog (default) or hub (for LMM)
  --ctypes : use inferred pointer (and other) types in generated C/C++ code
  --data=x : PASM output only: control placement of data
             x can be cog or hub (default is hub)
  --dat:     output binary blob of DAT section only
  --eeprom:  create EEPROM binary file for download
  --elf:     create executable ELF file with propgcc
  --files:   print list of .cpp files to stdout
  --fixed:   use 16.16 fixed point in place of float
  --fcache=N: set size of FCACHE area
  --gas:     create inline assembly out of DAT area;
             with --dat, create gas .S file from DAT area
  --list:    produce a listing file
  --main:    include C++ main() function
  --noheader: skip the normal comment about spin2cpp version
  --nocse:   disable common subexpression optimizations on PASM code
  --noopt:   turn off all optimization in PASM output
  --nopre:   do not run preprocessor on the .spin file
  --nofcache: disable FCACHE (same as --fcache=0)
  --normalize: normalize case of all identifiers
  --p2:       use Propeller 2 instructions (experimental)
  --require:  require a specific version (or later) of spin2cpp
  --side:     create a SimpleIDE file for the C/C++ outputs
  -Dname=val: define a preprocessor symbol
  -g:         add debug info to output (original source for PASM output)
  -I dir:     add dir to the object search path
  -L dir:     same as -I
  -o file:    place final output in file
  -y:         debug parser
  --version:  print version and exit

9 Famous Last Words


                                           .-----+-----.
                         .----+----.       |  The END  |
                         | Repent! |       | is neigh! |
                         ·----+----·       ·-----+-----·
                              |  _    _       _  |
                              |\°v°  °v°     ò.ó/|
                                |_|\/|_|)   /|_|
--------------------------------^-^--^-^-----^-^--------------------------------

10 The End

Author: yeti

Created: 2019-09-18 Wed 08:43