Shop OBEX P1 Docs P2 Docs Learn Events
Missing FastSpin C library functions — Parallax Forums

Missing FastSpin C library functions

Any chance these could be added sometime soon?
/Users/dbetz/Dropbox/work/junkbasic/edit.c:57: error: unknown identifier strcasecmp used in function call
/Users/dbetz/Dropbox/work/junkbasic/system.c:68: error: unknown identifier vsprintf used in function call

Comments

  • They should be in git now.
  • Wow! That was fast. Unfortunately, I'm now getting this error:
    junkbasic.pasm
    junkbasic.pasm:14331: error: fit 496 failed: pc is 612
    
    Is it trying to put my entire program in COG memory?
  • Never mind. I forgot the -2b option.
  • David Betz wrote: »
    Wow! That was fast. Unfortunately, I'm now getting this error:
    junkbasic.pasm
    junkbasic.pasm:14331: error: fit 496 failed: pc is 612
    
    Is it trying to put my entire program in COG memory?

    No, it's just using too many registers. It looks like you're compiling for P1. Does it work if you add "-2" to the command line to compile for P2? That'll use less COG memory. Alternatively, you could try setting "--fcache=0" to remove the fcache.
  • ersmith wrote: »
    David Betz wrote: »
    Wow! That was fast. Unfortunately, I'm now getting this error:
    junkbasic.pasm
    junkbasic.pasm:14331: error: fit 496 failed: pc is 612
    
    Is it trying to put my entire program in COG memory?

    No, it's just using too many registers. It looks like you're compiling for P1. Does it work if you add "-2" to the command line to compile for P2? That'll use less COG memory. Alternatively, you could try setting "--fcache=0" to remove the fcache.
    Yes, I was compiling for P1. It compiled successfully for P2 but now I'm trying to figure out how to run it. A simple "loadp2 junkbasic.p2 -t command loads it but I get garbage on the terminal. Does loadp2 have a different default baud rate than fastspin compiled programs expect?

  • Looks like the FastSpin runtime library uses 230400 baud but loadp2 defaults to 115200. As soon as I added "-b 230400" to my loadp2 command line things started working.
  • My line editor and BASIC parser seem to be working but I notice that the terminal seems to default to "raw" mode. Is there a "cooked" mode? I end up having to end all of my lines with ^J instead of just using the RETURN key and there is no line editing. Do I have to build that myself?
  • FYI, if you want to try compiling this, it's here: https://github.com/dbetz/junkbasic.git

    It is not anywhere near done though but you can build and run it by typing "make run-p2". You should be able to type lines of BASIC (starting with line numbers) and type "LIST" or "RUN". If you try running the program all that happens is that it gets parsed and the resulting parse tree is printed.
  • David Betz wrote: »
    My line editor and BASIC parser seem to be working but I notice that the terminal seems to default to "raw" mode. Is there a "cooked" mode? I end up having to end all of my lines with ^J instead of just using the RETURN key and there is no line editing. Do I have to build that myself?

    There's not really a cooked mode yet. In fact all the stdio code is under heavy development (as you've probably noticed).

    Looks like you've made a good start to your BASIC!
  • David BetzDavid Betz Posts: 14,516
    edited 2020-04-12 01:07
    I added my own line editor for the time being until you get "cooked" mode added to the library. My program is starting to work. Here is an example of it running on the P2. It is currently displaying a lot of debug code. First it shows all of the tokens it found in the input. Then it parses the program and displays the parse tree.
    dbetz@Davids-Mac-mini-2 junkbasic % make run-p2
    loadp2 -b 230400 junkbasic.p2 -t
    ( Entering terminal mode.  Press Ctrl-] to exit. )
    10 a=1
    20 function foo(x,y)
    30  return x+y
    40 end function
    50 b=2
    list
    10 a=1
    20 function foo(x,y)
    30  return x+y
    40 end function
    50 b=2
    OK
    run
    tkn: <IDENTIFIER>
    tkn: '='
    tkn: <NUMBER>
    tkn: <EOL>
    tkn: FUNCTION
    tkn: <IDENTIFIER>
    tkn: '('
    tkn: <IDENTIFIER>
    tkn: ','
    tkn: <IDENTIFIER>
    tkn: ')'
    tkn: <EOL>
    tkn: PRINT
    tkn: <IDENTIFIER>
    tkn: '+'
    tkn: <IDENTIFIER>
    tkn: <EOL>
    tkn: END FUNCTION
    FunctionDefinition: foo
    Arguments:
      x 00000000
      y 00000001
      Return
        expr
          BinaryOp: 8
            left
              ArgumentRef: 0
            right
              ArgumentRef: 1
    tkn: <IDENTIFIER>
    tkn: '='
    tkn: <NUMBER>
    tkn: <EOL>
    Globals:
      a 00000000
      foo 00000000
      b 00000000
    FunctionDefinition: <main>
      Let
        lvalue
          GlobalRef: a
        rvalue
          IntegerLit: 1
      Let
        lvalue
          GlobalRef: b
        rvalue
          IntegerLit: 2
    OK
    
  • David BetzDavid Betz Posts: 14,516
    edited 2020-04-12 01:13
    @ersmith BTW, you have done a fabulous job with FastSpin! I went looking through the directories trying to find where to add vsprintf and in the process saw the huge amount of code you've written for FastSpin. Not only have you implemented three different languages that interoperate with each other. They are very well fleshed out with substantial libraries. Congratulations on a tremendous contribution to the P1 and P2 tool set and thanks for all of your hard work!
  • David Betz wrote: »
    @ersmith BTW, you have done a fabulous job with FastSpin! I went looking through the directories trying to find where to add vsprintf and in the process saw the huge amount of code you've written for FastSpin. Not only have you implemented three different languages that interoperate with each other. They are very well fleshed out with substantial libraries.

    Thank you, but I really can't take credit for all of that. The C library functions largely come from PropGCC, which many people (including you!) worked on. @"Roy Eltham" has done great work porting the simpletools libraries (originally written by Andy @ Parallax, IIRC) to the P2 and FlexC. @JRoark contributed a bunch of BASIC libraries, and @avsa242, @dgately, @yeti, and many others have contributed bug fixes and suggestions. Like any successful project, fastspin is a community effort, and I'm always happy to get pull requests for it. There's still a lot of work to be done to improve the compiler and libraries!
  • RaymanRayman Posts: 14,646
    What do edit.c and system.c do?

    Funny how I do a lot of C++ programming, but do it with MFC, so know almost nothing about basic C libraries...
  • Rayman wrote: »
    What do edit.c and system.c do?

    Funny how I do a lot of C++ programming, but do it with MFC, so know almost nothing about basic C libraries...
    edit.c and editbuf.c are the simple line editor.
    system.c is the interface to the underlying system. Mostly they have terminal I/O functions and memory allocation.

  • This may be unfair, but as I have been watching lots of interviews with Brian Kernighan on YouTube, I thought it would be fun to run K&R demos through the FastSpin compiler for the P2. Based on Brian's comments in nearly every interview, it seems like the P2 has far more memory than what Unix had back in the late 70s when they wrote the book.

    I have the Edition 1 book, which doesn't use...
    #include <stdio.h>
    
    ...but I am adding it to the listings.

    First program (hello.c)... perfect. The second program (Fahrenheit to Celsius table) works, but seems to show a bug in printf() on the P2. I opened the file in Geany and compiled it there -- the output is as intended.

    I don't know if this is worth fixing, but thought I'd point it out. In the attached image, the FlexGUI terminal is on the left, the Geany terminal on the right.
    1497 x 649 - 62K
  • JonnyMac wrote: »
    First program (hello.c)... perfect. The second program (Fahrenheit to Celsius table) works, but seems to show a bug in printf() on the P2. I opened the file in Geany and compiled it there -- the output is as intended.
    Thank you for the bug report, Jon. The case of floating point output with 0 fractional digits was not being handled correctly. That's fixed in github now and will be in the next release.

    This is why having lots of people try the tools is so useful... printf of floats with no trailing digits just hadn't come up yet, and I think I misread what the spec said about that case. Thanks!

    Eric
  • JonnyMacJonnyMac Posts: 9,104
    edited 2020-04-13 00:39
    As I pointed out in the article I submitted to Nuts & Volts, the P2 is friendlier to external tool makers, and as I have been watching a lot of interviews with Brian Kernighan, I thought I'd give C a try on the P2 as I'm working through the K&R on my PC.

    I'm not a retro computer guy, but watching all the interviews with BK on C and Unix makes me wonder if one of those old versions of Unix -- with proper hardware drivers -- would run on the P2. It would be kind of neat to experience Unix as they did in the late 70s/early 80s running on a P2 with a terminal output and the SD card for files. I suppose if someone could find an old dot-matrix printer, there are enough pins to drive that as well.
  • yetiyeti Posts: 818
    edited 2020-04-13 14:25
    Start here: https://unix50.org

    I have no experiences with most of the systems there, just explored a bit B on Unics.
Sign In or Register to comment.