Shop OBEX P1 Docs P2 Docs Learn Events
Propeller II Simulator — Parallax Forums

Propeller II Simulator

Dave HeinDave Hein Posts: 6,347
edited 2014-03-06 09:14 in Propeller 2
I've updated spinsim to support P2. Spinsim supports most of the core instructions, but it currently does not support instructions related to the counters, cordic engine or video hardware. I also have not implemented the hub exec mode or threads. Look at the readme.txt file in the zip file to see which instructions are supported.

The zip file contains a spinsim.exe file that runs under Cygwin, but it will need to be built for other platforms. Just type make to build it. I have a sample program called pfth.obj that can be run by typing "./spinsim -t -b pfth.obj". This will run the pfth Forth compiler under spinsim.

I've tested most of the implemented instructions, but there are many instructions that I haven't tested. Let me know if you encounter any problems, or if you want me to implement any particular instruction. I plan on adding hub execution next, and then threads.

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2014-02-17 10:37
    Cool! I just built it on my Mac (OS X 10.9.1) and ran pfth.obj. The only strangeness I saw was that I got double characters when typing things in from the terminal

    ok
    words

    comes out as wwoorrddss

    Other than that, it is running pfth just fine.

    YAY!!! A new Toy!!! Thanks, Dave!!
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-17 10:48
    Yes, I need to figure out a better way to handle unbuffered console I/O. It works fine under Cywin on one of my computers, but unbuffered I/O doesn't work very well on one of my other computers. It also repeats an occasional character when I run it under Linux.
  • Bill HenningBill Henning Posts: 6,445
    edited 2014-02-17 11:10
    Nice work Dave.

    It will allow people without access to FPGA boards to try the P2 before chips ship (excluding video)
    Dave Hein wrote: »
    I've updated spinsim to support P2. Spinsim supports most of the core instructions, but it currently does not support instructions related to the counters, cordic engine or video hardware. I also have not implemented the hub exec mode or threads. Look at the readme.txt file in the zip file to see which instructions are supported.

    The zip file contains a spinsim.exe file that runs under Cygwin, but it will need to be built for other platforms. Just type make to build it. I have a sample program called pfth.obj that can be run by typing "./spinsim -t -b pfth.obj". This will run the pfth Forth compiler under spinsim.

    I've tested most of the implemented instructions, but there are many instructions that I haven't tested. Let me know if you encounter any problems, or if you want me to implement any particular instruction. I plan on adding hub execution next, and then threads.
  • mindrobotsmindrobots Posts: 6,506
    edited 2014-02-17 11:44
    Dave,

    I was wondering if you somehow had a way to output the pin states while running which led me to thinking if this can be single stepped with a display of processor state after each step....which led to to fondly remember the Sperry 1100 series mainframe simulator we had which let me load up my operating system and run it to a certain point and then examine registers, change things and single step through instructions. This was 1980/1981, so, these were very cool things to be able to sit at a terminal and do interactively with a program that was doing a simulation.

    Which brings me back to spinsim - are some of these single stepping and processor state examination features lurking around in the code? If so, then this is a really great tool for learning PASM(2) also!
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-17 12:16
    There is the beginnings of a simple debugger in debug.c. I have another version of spinsim that I worked on several months ago that is able to single-step and set a breakpoint. I'll try to get that integrated into the P2 version.

    I think I have a solution for the double-characters. I'll try it on my other computer to see if it resolves the issue with it.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-17 17:41
    If you're having trouble with repeated or garbled characters in spinsim, try this version of conion.c. It works much better on my PC that was having problems.
    c
    c
    798B
  • mindrobotsmindrobots Posts: 6,506
    edited 2014-02-17 17:43
    I'll try it on my Mac that was having the pprroobblleemm but it won't be until tomorrow morning.

    Thanks!
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-20 19:00
    Here's a new version of spinsim that supports hub execution, a simple debugger and a fix for the console I/O problem. The debugger is enabled by using the "-d" command-line option. The "step" command will execute a single cycle, and the "stepx" will step through non-executed cycles until it encounters an executed instruction. This is convenient for skipping over invalidated instructions, instructions that are conditionally not executed, and cycles waiting for hub access. The "run" command will cause the simulator to run until a breakpoint is encountered or Control-] is typed.
  • jazzedjazzed Posts: 11,803
    edited 2014-02-20 19:37
    Hi Dave,

    Is there any way we can live without conion.c functions on Windows?

    Thanks.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-21 04:51
    Spinsim needs an unbuffered, non-blocking character input function. Otherwise, it can't accept character input while running. The old TurboC compiler provided this function as well as the kbhit function, but gcc doesn't provide it. Are you having problems with conion.c? I was hoping the latest changes fixed the problems.
  • jazzedjazzed Posts: 11,803
    edited 2014-02-21 07:15
    Dave Hein wrote: »
    Spinsim needs an unbuffered, non-blocking character input function. Otherwise, it can't accept character input while running.

    Header termios.h and library are available in Linux, but apparently not with Msys/Mingw. I don't use Cygwin.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-21 08:14
    A web search of "termios mingw" shows that this is a common problem. It looks like there may be a solution, but it seems like most people disable the features that require termios to get around the problem. I could add a compile flag that disables the "-b" option and the support for the ^] character that interrupts the simulation. This would allow the use of the normal buffered console input. I'll also dig a bit deeper to see what is needed for unbuffered character input in mingw.
  • jazzedjazzed Posts: 11,803
    edited 2014-02-21 08:26
    Dave Hein wrote: »
    A web search of "termios mingw" shows that this is a common problem. It looks like there may be a solution, but it seems like most people disable the features that require termios to get around the problem. I could add a compile flag that disables the "-b" option and the support for the ^] character that interrupts the simulation. This would allow the use of the normal buffered console input. I'll also dig a bit deeper to see what is needed for unbuffered character input in mingw.

    Great.

    As you know Spinsim was used heavily in bringing up PropellerGCC the first time. I would like to include whatever you do in the P2 tools also, and Msys/MinGW are required there for Windows.

    Thanks Dave.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-21 14:10
    Steve, use the files in patch.zip to replace conion.h, conion.c and debug.c from the previous zip file, and you can build spinsim without termios. With this configuration spinsim will not support a simulated serial input, and you cannot use ^] to stop a running program. Everything else should work OK.

    A flag called STD_CONSOLE_INPUT is defined in conion.h that causes stub routines for kbhit() and getch() to be compiled. In this mode kbhit() always returns 0, and getch() returns the output from getchar(). debug.c also had to be changed because it waits for kbhit() to return a 1.

    BTW, you can still use the -b option to get serial output from the program that is being run.
  • jazzedjazzed Posts: 11,803
    edited 2014-02-21 14:39
    Thanks Dave.

    Compiles just fine.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-21 20:39
    The latest version of spinsim is having some problem compute wait cycles for some instructions. I'll try to get a fixed version posted tomorrow.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-02-22 06:26
    I've attached a new update to spinsim that fixes the problem with computing wait cycles. The problem was related to instructions that shared the same 7-bit opcode with CALLA and CALLAD.

    I've also included the patch that disables using termios. termios is used by default, and the compile flag STD_CONSOLE_INPUT must be defined in conion.h to disable it.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-03-05 20:16
    Here's a new version of spinsim that supports a few more P2 instructions. It also contains fixes for several of the P2 instructions that were previously implemented. I also included a version of p1spin that runs under spinsim. p1spin runs P1 Spin programs on P2.
  • RaymanRayman Posts: 13,918
    edited 2014-03-06 09:14
    This looks very cool. Noticed it has an MIT license, which is very nice.

    I'm dreaming about combining something like this with a circuit simulator...
Sign In or Register to comment.