[Tutorial][Advanced]2.PokittoSim - programming using a Simulator


#1

Introduction to PokittoSim

PokittoSim is a API-level simulation of the Pokitto Application Programming Interface (API) that allows you to try out and develop most* of your Application/Game ideas on a PC.

This means you can write, run and debug your program on a Windows/Linux (Mac coming soon) PC without needing the actual Pokitto itself.

This is what it looks like:

In the simulator buttons are arrow keys + Z,X,C (A,B,C) !!

Tutorial video

Why use a simulator?

  1. Speed. Developing code just on a PC is much faster than on the actual hardware, because you do not have to copy the code to the Pokitto each time you compile.

  2. Easy debugging. Most problems you encounter while developing your program have more to do with mistakes in your own code than anything else. It may be a jumping algorithm for your platform game or something else. On a PC you can perfect your code and then focus on optimizing it for the hardware. All Pokitto core library has actually been developed in this way.

  3. No need to have the device at hand. Are you travelling and haven’t got your Pokitto with you? No problem. We have proven time and time again that programs made by talk.pokitto.com users work without changes when moving from simulator to hardware.

How the simulator works

PokittoSim is an API-level simulator. It uses the well-known SDL2 (Simple DirectMedia Layer) library to create a “window” where your code will run almost exactly like it would on the Pokitto hardware (see below).

What actually happens with the simulator is as follows: you write your code inside Code::Blocks, your code gets compiled into a Windows / Linux program (Mac coming soon) and runs as a native Win/Linux program on your PC!

*Difference between a simulator and an emulator

A simulator works by making things work in a similar way (hence the name simulator). Emulator is something that emulates the entire hardware. For example, there are emulators that can run Playstation games on a PC. PokittoSim is a simulator, not an emulator. An emulator for the NXP LPC11U68 chip and all the other components inside Pokitto would have been a humongous task. For the sake of development time, Pokitto is launching with a simulator. It helps you get your work done, but be aware that it can not simulate everything the hardware can. This means things like controlling motors through the Pokitto Extension Header etc.

Who is the simulator intended for?

Installing and using the PokittoSim simulator requires some prior knowledge of programming tools and computers in general. PokittoSim is released now in order to allow the community to begin creating and testing their own ideas. Support for using the simulator at this moment is a bit limited, because we are still busy with fulfilling the Pokitto Kickstarter. Support and tutorials for using the PokittoSim will improve over time.

However, several users with limited experience have already reported successfully installing and running Pokitto programs on the PokittoSim, so don’t be afraid to try. You can’t break anything by trying!

STEP 1: Installation of Code::Blocks environment

Download the free Code::Blocks. Code::Blocks is an IDE. An IDE is like Microsoft Word for programmers. With Word, you write text. With an IDE, you write code. You can learn more at codeblocks.org

Downloading Code::Blocks

All downloadable binary versions

http://www.codeblocks.org/downloads/binaries

Direct link to a trusted Windows binary

This is a direct link to the correct version of the Code::Blocks program (Windows mingw 16.01) coming from a trustworthy site (SourceForge)

https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-setup.exe/download

I recommend installing Code::Blocks using default settings!

STEP 2: Get the repository from Github

STEP 3: Open project file inside Code::Blocks

Click File-Open in Code::Blocks. Navigate to where you cloned/extracted the PokittoSim repository from Github.

Open file Pokitto_sim.cpb under directory POKITTO_SIM

.cbp files are Code::Blocks project files. They contain the source and settings of an entire project.

Select Windows / Linux target

Next, choose correct target inside Code::Blocks after you have opened the .cbp project file

STEP 4: You are ready to run

Now you can change the text “Hello World” to something else, press CTRL-F11 to rebuild and CTRL-F10 to run the program.


Cross Platform Unified Online or Offline IDE/Devp Env dedicated for Pokitto Apps / Game Devlopment
#2

Will the simulator run on arm Linux? Debian 4.4?


#3

Haven’t tried. What kind of device would that be?


#4

I can try with RPi 2, 3 and Zero today


#5

I’m guessing Raspberry Pi but I’ll let BigBadHodad confirm :wink:


#6

This

https://getchip.com/pages/pocketchip


#7

Tried on RPI2 today. Some HelloLinux target linker settings changed, SDL2 libraries worked without error but there is only one .a file compiled for only x86 architecture. Filename is “libPokitto_sim.a”. This file must be compile for ARM.


#8

I have tried getting codeblocks to run on my Mac, but it keeps telling me that the debugger isn’t installed.
Not sure what to do or how to fix it.


#9

Those who are interested to run it on Linux (mine on Fedora 25 (RPM)) they can use it with Wine !!!

  1. Install Wine
  2. Install Windows version of Code::Blocks
  3. Run on Wine
  4. Simulator works fine under Wine

#10

I need to buy a mac.

In any case, have you got the XCode package first?



#11

I will post the execution of same on my Mac Machine soon with Wine !!!
I think if it works with Fedora it might be with Mac also because Mac OS also supports Wine !!!


#12

Thanks for those links. I have xcode but not the command line stuff.
I’ll let you know how I go.


#13

I will get my hands on a mac soon and try it out myself also.


#14

Whoo hoo! Progress.
I downloaded and installed the Command line utilities.
I then added gdb to the debugger preference.
It still didn’t want to work, so I downloaded the pokkito example from github. Previously I had a pokkito zip file.
It is still erroring, but I am closer than before.


#15

So I have had a chance to play a bit more.
I get the following error when I try to run any of the examples.

ld: unknown option: -Map=main.map
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The main.map file exists within the pokkito github files.
Build target is Helloworld.win.
This type of coding is very new to me, so any suggestions are greatly appreciated.
Ray


#16

I’ve found a little glitch with the Chipengine_win build target. It seems like you accidentally put GuiTools.cpp into the build target, so it gives an error about there being two main() functions. It’s a fairly easy fix, but it might be a good idea to fix it so others don’t get confused :slight_smile:


#17

Thanks for reporting. Please put a note to bugs and features category also so it is not lost.


#18

hmmm, having suffered a hdd failure I had to reinstall everything, but now I can’t get the setup to work.

||=== Build: Pokittris in PokittoSimHello (compiler: GNU GCC Compiler) ===|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoCore.cpp|187|warning: unused variable 'counter' [-Wunused-variable]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoCore.cpp|459|warning: variable 'fc' set but not used [-Wunused-but-set-variable]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoCore.cpp|459|warning: variable 'bc' set but not used [-Wunused-but-set-variable]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoCore.cpp|491|warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoCore.cpp|488|warning: control reaches end of non-void function [-Wreturn-type]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoCore.cpp|559|warning: control reaches end of non-void function [-Wreturn-type]|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
C:\Users\Spinal\Documents\Pokitto\EXAMPLES\tetris.cpp||In function 'void checkLine()':|
C:\Users\Spinal\Documents\Pokitto\EXAMPLES\tetris.cpp|198|warning: unused variable 'y1' [-Wunused-variable]|
C:\Users\Spinal\Documents\Pokitto\EXAMPLES\tetris.cpp||In function 'int SDL_main()':|
C:\Users\Spinal\Documents\Pokitto\EXAMPLES\tetris.cpp|312|warning: unused variable 'oldMode' [-Wunused-variable]|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoDisplay.cpp|395|warning: operation on 'index2' may be undefined [-Wsequence-point]|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoSound.cpp|212|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_CORE\PokittoSound.cpp|819|warning: no return statement in function returning non-void [-Wreturn-type]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_LIBS\FileIO\FileIO_SIM.cpp||In function 'char* getNextFile()':|
C:\Users\Spinal\Documents\Pokitto\POKITTO_LIBS\FileIO\FileIO_SIM.cpp|138|warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_LIBS\FileIO\FileIO_SIM.cpp||In function 'char* getFirstFile()':|
C:\Users\Spinal\Documents\Pokitto\POKITTO_LIBS\FileIO\FileIO_SIM.cpp|163|warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]|
C:\Users\Spinal\Documents\Pokitto\POKITTO_LIBS\FileIO\FileIO_SIM.cpp||In function 'char* getNextFile(char*)':|
C:\Users\Spinal\Documents\Pokitto\POKITTO_LIBS\FileIO\FileIO_SIM.cpp|134|warning: control reaches end of non-void function [-Wreturn-type]|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
..\Pokitto_settings.h|169|warning: "POK_COLORDEPTH" redefined|
..\Pokitto_settings.h|128|note: this is the location of the previous definition|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|243|error: macro "min" passed 3 arguments, but takes just 2|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|265|error: macro "max" passed 3 arguments, but takes just 2|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|195|error: expected unqualified-id before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|195|error: expected ')' before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|195|error: expected ')' before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|195|error: expected initializer before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|219|error: expected unqualified-id before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|219|error: expected ')' before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|219|error: expected ')' before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|219|error: expected initializer before 'const'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|243|error: 'std::min' declared as an 'inline' variable|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|246|error: expected primary-expression before 'if'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|246|error: expected '}' before 'if'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|246|error: expected ';' before 'if'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|248|error: expected unqualified-id before 'return'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|265|error: 'max' declared as an 'inline' variable|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|268|error: expected primary-expression before 'if'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|268|error: expected '}' before 'if'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|268|error: expected ';' before 'if'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|270|error: expected unqualified-id before 'return'|
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algobase.h|271|error: expected declaration before '}' token|
||=== Build failed: 21 error(s), 57 warning(s) (0 minute(s), 15 second(s)) ===|

Can anyone help? Have I missed an installation step? has a bug crept in since I last installed? What have I done wrong?


#19

The errors seem to be coming from mingw32 itself.

I don’t know if it’s a fault in mingw or a conflict with min and max being defined in different places.

It could be that it’s trying to use some function forms of min and max that are designed to take a variable number of arguments and some macros are interfering.
I’m guessing from the file name that it’s supposed to be part of an implementation of the C++ stdlib (part of which was formerly referred to as the ‘standard template library’ (stl)), which would make sense since C++ does have a 3-argument variation of std::min and std::max.
C++ isn’t supposed to have min and max macros in the standard library so that implies to me that it’s possibly an overspill issue in which a file defining min and max macros is being included before one defining min and max functions.
Whitout actually being able to read the file, I’d guess that that’s the crux of the issue and all the other errors are a knock-on effect.

Ultimately though that’s all just a big guess and without seeing the file or knowing what else is being included and where I can only make guesses.

Looking at the Pokitto source code, the warnings coming from that would be expected to happen because there’s nothing to guard against them.


#20

Caused by change in stdlib. min max used to be macros, now are functions. Lots of problems, not only for Pokitto.

put DISABLEAVRMIN in your #defines in the project build options to disable AVR versions of min and max