New BASIC compiler for Prop1 and Prop2

1131415161719»

Comments

  • Roy Eltham is porting the Simple Libraries to fastspin's C compiler. That will allow us to access those libraries from BASIC and Spin as well, since fastspin supports all 3 languages.
    I am thinking about doing a test run, using my CM2302 module and using fastspin Basic. Of course what I would like to do is use the dht22 C code that is in the SimpleIDE library.

    Not quite sure as to where I should start with this. First I would have to get the actual C code that is in the SimpleIDE library, then what do I have to do to make it usable with fastspin Basic.

    Ray
  • Hi
    Having much fun playing with fastspin basic on P1, version 3.9.24.
    Just found a bugget- It seems hex numbers not recognised in data statements.
    ie.
    data 0xaa,0haa,&haa when read into ubyte array all return 0
    changing to decimal works fine
    using hex otherwise seems ok

    Dave


  • tritonium wrote: »
    Hi
    Having much fun playing with fastspin basic on P1, version 3.9.24.
    Just found a bugget- It seems hex numbers not recognised in data statements.
    ie.
    data 0xaa,0haa,&haa when read into ubyte array all return 0
    changing to decimal works fine
    using hex otherwise seems ok

    Dave

    Thanks for the bug report! The "data" statement uses the same code that input does, and it only supported decimal. The next release of fastspin will support hex and binary numbers in data and input. 3.9.26 should be available soon.

    Regards,
    Eric
  • New versions of fastspin and spin2gui (version 3.9.26) are available now from the usual places. There are several improvements to the BASIC compiler, including support for DEF FN and for hex numbers in DATA and INPUT, and also a bug fix for SELECT CASE. There is also an experimental -z flag for compressing the output code, but this is still somewhat buggy so not really ready for production.
  • Hi
    Thanks ersmith.
    I have been using FreeBasic for a number of years so this is a nice resource I never expected. Its going to be especially useful when I finally get my hands on a P2. Being reliant on PropBasic I thought I would be stranded but now I look forward to P2's arrival.
    Thanks again
    Dave
  • ersmith wrote: »
    There is also an experimental -z flag for compressing the output code, but this is still somewhat buggy so not really ready for production.
    It took a while of scratching the back of my head until I realised that "-z" needs a slower terminal baud rate... \o/
    ...at least on P1.
    ◁ propeller-wiki ▷ ◁ FastSpin ▷ ◁ DK-E ▷ ◁ :-D ▷ ◁ Stay OmmmmmmPtimistic! ▷ ◁ No Source – No Go! ▷ ◁ Help Spin at RosettaCode.org ▷ ◁ Why Asimov's Laws of Robotics Don't Work ▷ ◁ DNA is a four letter word. ▷
  • Hi again

    Pleased to report all permutations of hex formatting accepted in data statements in new version- thanks.

    Dave
  • Hi

    In trying to read the character rom on P1 in fastspin basic I needed a way to access memory and could not fine a peek or rdlong so resorted to making a function.-
    function rdval(adr as uinteger)
    dim valu as uinteger
    	asm
    	rdlong valu,adr
    	end asm
    return valu
    end function
    


    Is there a proper way?
    Did I miss the obvious?

    Dave
  • The "obvious" way to read from memory is to use a pointer. To cast integers to pointers it's necessary to go through a generic value (of type "any"), like so:
    function rdval(adr as any) as uinteger
      dim p as uinteger pointer
      p = adr
      return p(0)
    end function
    
    print rdval(0xe000)
    
  • kwinnkwinn Posts: 8,278
    edited 2019-05-09 - 14:26:28
    ersmith wrote: »
    The "obvious" way to read from memory is to use a pointer. To cast integers to pointers it's necessary to go through a generic value (of type "any"), like so:
    function rdval(adr as any) as uinteger
      dim p as uinteger pointer
      p = adr
      return p(0)
    end function
    
    print rdval(0xe000)
    

    That looks to me like a very "C" style expression and function. It has been a long time since I have done any Basic coding. Have modern day Basics all morphed towards C or is this an atypical version?
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • kwinn wrote: »
    ersmith wrote: »
    The "obvious" way to read from memory is to use a pointer. To cast integers to pointers it's necessary to go through a generic value (of type "any"), like so:
    function rdval(adr as any) as uinteger
      dim p as uinteger pointer
      p = adr
      return p(0)
    end function
    
    print rdval(0xe000)
    

    That looks to me like a very "C" style expression and function. It has been a long time since I have done any Basic coding. Have modern day Basics all morphed towards C or is this an atypical version?
    I guess traditional BASIC would have PEEK and POKE. This seems much cleaner.

  • David Betz wrote: »
    kwinn wrote: »
    ersmith wrote: »
    The "obvious" way to read from memory is to use a pointer. To cast integers to pointers it's necessary to go through a generic value (of type "any"), like so:
    function rdval(adr as any) as uinteger
      dim p as uinteger pointer
      p = adr
      return p(0)
    end function
    
    print rdval(0xe000)
    

    That looks to me like a very "C" style expression and function. It has been a long time since I have done any Basic coding. Have modern day Basics all morphed towards C or is this an atypical version?
    I guess traditional BASIC would have PEEK and POKE. This seems much cleaner.

    I agree. Nice to see multiple languages merging towards common expressions and simpler logical ways of doing things.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • HI
    The "obvious" way to read from memory is to use a pointer. To cast integers to pointers it's necessary to go through a generic value (of type "any"), like so:
    function rdval(adr as any) as uinteger
    dim p as uinteger pointer
    p = adr
    return p(0)
    end function

    print rdval(0xe000)

    Oh boy "casting is one of those new fangled things I've never needed like oop in general and although that is in FreeBasic I've somehow survived without it.

    Anyway that worked fine- so I tried to put that straight into the main code-

    If I try-
    dim z as uinteger
    dim adr as any
    dim p as uinteger pointer
    adr=&H8000
     p = adr(0)
    
    I get-
    
    error: incompatible types in assignment
    

    I'm out of my depth here, but it seems this can only be done within a function

    I've tried all sorts of other permutations and get various errors (like 'not a function')

    can I use a pointer outside a function? if so can you please give me an example.

    Perhaps I'll stick to my way of doing it within pasm blocks.
    are there any other 'refinements' I need to be aware of-
    is it not possible to have good old uncomplicated peek and poke so dumbos like me can survive.

    Don't get me wrong- I think the work you are doing is incredible- but when we old timers see "basic", well old dogs new tricks etc....

    Dave

  • David BetzDavid Betz Posts: 13,403
    edited 2019-05-10 - 01:18:39
    Maybe you can try this:
    function peek(adr as any) as uinteger
      dim p as uinteger pointer
      p = adr
      return p(0)
    end function
    
    sub poke(adr as any, val as uinteger)
      dim p as uinteger pointer
      p = adr
      p(0) = val
    end sub
    

    Well, I don't really know BASIC all that well so this might not be quite right but something like this should get you back to the old way BASIC did this.
  • You can't use a variable of type "any" as an array, which is why the compiler is complaining about "adr(0)" ("adr" is of type "any" so you could be asking for an array reference or a function call, it doesn't know which). You'll have to assign the address to a pointer before trying to read from it:
       dim adr as any
       dim p as uinteger pointer
       adr = &H8000
       p = adr ' we have to index through p
       x = p(0) ' sets x to data from &H8000
       y = p(1) ' sets y to data from &H8004
    
    I don't know if there's a shorter way to do this in FreeBasic; some quick googling didn't turn up any equivalent to C casts, but I may have just missed it. I'd like to add something like that though so we could do something like C's:
       p = (uint *)0x8000
    
    Actually there is one way to avoid it, although it's a bit ugly. The literal "0" already has type "any" so it can be assigned to anything:
       dim memp as uinteger pointer
       memp = 0
       print memp(0x8000/4)
    
    The ugliness is that you have to remember to divide by 4 when doing the indexing. If you're using a byte pointer that won't be necessary though.
  • @David Betz 's "peek" and "poke" functions (or something like them) look fine too, you could include them in your code. The only change I would make is to make the "val" parameter to "poke" be a uinteger to match the uinteger pointer inside the function.
  • ersmith wrote: »
    @David Betz 's "peek" and "poke" functions (or something like them) look fine too, you could include them in your code. The only change I would make is to make the "val" parameter to "poke" be a uinteger to match the uinteger pointer inside the function.
    Thanks for the suggestion. I fixed it in my post.

  • There's a new release of fastspin with improved BASIC support. This round I've added much better support for objects, including inline class definitions (they no longer have to be in a separate file) and passing objects to functions. There's also a STR$() function for converting numbers to strings, and a new template syntax for generic functions. I've made an announcement in the fastspin thread, but also wanted to post here because (a) the BASIC language is considerably updated, and (b) it works on P1 as well as P2, and some people may not follow the P2 threads.

    I've added "basic.pdf", the current FlexBASIC manual, to the first post; links to fastspin and spin2gui releases are also in that post.
Sign In or Register to comment.