LoginLogin

Midori-OS: making your first app

Root / Submissions / [.]

Autz64Created:
This is a simple guide to make a simple app for Midori-OS. Unlike other mock-OS for smileBASIC, Midori-OS comes with tools that makes app development more easy:
  • You don't need to edit the sourcecode of Midori-OS at all!
  • The necesary parameters are easy to setup.
  • You can export your app so other can import it with no hassle.

Setting things up

First, you need to load TEMPLATE.PKG on SLOT1, which contains the necessary parameters and structure to run an app. And why SLOT1? Because PKG Loader loads and copy the content of .pkg files on SLOT1, so is important that the SLOT1 doesn't have anything important. Load TEMPLATE.PKG with the following command:
LOAD"PRG1:TEMPLATE.PKG"
and now SLOT1 has the basic structure to create an app. You can test it right now! Press START (assuming EXECUTE is loaded on SLOT0) and PKG Loader will inject the app in the OS's code. When finished, you will see this:

Looking up the DEF

Go back to SLOT1 and see the code, it has plenty of comments to barely understand each piece. But most importantly, you will see a DEF at the bottom that looks like this:
COMMON DEF APP WID,STARTX,STARTY,ENDX,ENDY
END
This DEF is the main DEF that is used to draw the app, at least on our current state. The DEFs the OS will execute need to fulfill that structure, so it can pass the correct arguments to the DEF. The code inside the DEF must (or should) refer to these parameters to either draw inside the window, or to set/retrieve "reserved memory" of the window. STARTX, STARTY, ENDX and ENDY refers to the beginning and end of the window canvas, as seen here: And, as you can see inside TEMPLATE.PKG:
GPUTCHR STARTX,STARTY,"Hello world!",#BLACK
This command takes the DEF parameter of the canvas (the beginning of X and Y coordinate) and draws the message.

Using variables

One of the DEF parameters is WID. WID stands for "window ID" and is a key piece on app development. This ID allows us to work with the current window and use window specific commands. Here will use VARS_NUM and VARS_STR$ respectively. Since Midori-OS needs to call this main DEF on every frame, it needs to use data outside of it to achieve data persistency, this is where VARS_NUM and VARS_STR$ comes in. These 2D array allows us to get or set data using the window ID as the first dimension, so any app can have its own vars without interfering with eachother (but you can manipulate variables of ANOTHER window using APP_WINDOW_INIT). To test this, go to TEMPLATE.PKG and add the following code:
VAR A = VARS_NUM[WID,0] 'Retrieve slot 0
VAR B = VARS_NUM[WID,1] 'Retrieve slot 1

INC A
INC B

GPUTCHR STARTX+2,STARTY+2,"A: "STR$(A),#BLACK
GPUTCHR STARTX+2,STARTY+12,"B: "STR$(B),#BLACK

VARS_NUM[WID,0]=A 'Set the value for the next cycle
VARS_NUM[WID,1]=B
now press START to PKG Loader to inject it, and now the app should display both A and B increasing! If the last two lines are not set, it will always display 0. Because on each cycle, the window retrieves the vars as they were new.

Exporting the app

Once your app is ready, the only things you need to do are the following:
  • Set DEBUG to 0 at the top of the PKG
  • Save the code as <name>.PKG, where <name> is anything you want.
Now, each time EXECUTE runs, it will inject the app and it will add it on the Program List! To execute your imported program, go to Start Menu -> Programs. and locate your app. You can also create a shortcut with the Terminal app. Open the Terminal app and type:
SHORT + NAME DEF_NAME
Where NAME is the name of the shortcut you want to create, and DEF_NAME is the name of the main DEF to execute.

No posts yet (will you be the first?)