Minimal Posit-92 Example

In this page, I can show how easy it is to start programming games with Posit-92 Wasm

How it looks like (including the game loop):

You can either use Pascal or C++ to accomplish this

library Game;

{$Mode ObjFPC}
{$J-}  { Switch off assignments to typed constants }

uses
  Logger, WasmMemMgr, VGA;

procedure init;
begin
  initMemMgr;
  initBuffer;
end;

procedure afterInit;
begin
  writeLog('Hello from hello_minimal!')
end;

procedure update;
begin
end;

procedure draw;
begin
  cls($FF6495ED);
  vgaFlush
end;

exports
  init, afterInit, update, draw;

begin
{ Starting point is intentionally left empty }
end.
#include "pascal_compat.hpp"

#include "logger.hpp"
#include "vga.hpp"
#include "wasm_heap.hpp"

export void init() {
  initBuffer();
}

export void afterInit() {
  writeLog("Hello from hello_minimal!");
}

export void update() {
}

export void draw() {
  cls(0xFF6495ED);

  vgaFlush();
}

The difference here is that when exporting functions from C++, you also have to declare them in the compile script. Something like this: EXPORTED_FUNCTIONS=_init,_afterInit,_update,_draw

Both examples can be compiled with the provided compile.ts or compile_demo.ts, depending on which target you want to develop: a standalone game or a demo project for Posit-92

This entry was posted in Posit-92 and tagged , , , . Bookmark the permalink.