Developing Applications for FRANK OS

Apps are standalone ARM ELF binaries compiled against frankos-app.h. Call OS through sys_table at 0x10FFF000 — binary compatible across firmware versions.

Minimal App Example

#include "frankos-app.h"

static hwnd_t my_hwnd;

static void on_paint(hwnd_t hwnd) {
    wd_begin(hwnd);
    wd_clear(COLOR_WHITE);
    wd_text_ui(10, 10, "Hello, FRANK OS!", COLOR_BLACK, COLOR_WHITE);
    wd_end();
}

static bool on_event(hwnd_t hwnd, const window_event_t *ev) {
    if (ev->type == WM_CLOSE) {
        wm_destroy_window(hwnd);
        return true;
    }
    return false;
}

int main(void) {
    my_hwnd = wm_create_window(100, 50, 300, 200,
                                "My App", WSTYLE_DEFAULT,
                                on_event, on_paint);
    wm_show_window(my_hwnd);
    wm_set_focus(my_hwnd);
    ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
    return 0;
}

Window Management API

OptionDescription
wm_create_window(x,y,w,h,title,style,event_cb,paint_cb)Create window, returns hwnd_t
wm_destroy_window(hwnd)Destroy and free
wm_show_window(hwnd)Make visible
wm_set_focus(hwnd)Set input focus
wm_invalidate(hwnd)Mark for repaint
wm_toggle_fullscreen(hwnd)Toggle fullscreen

Window Styles

OptionDescription
WSTYLE_DEFAULTClosable, resizable, movable, bordered
WSTYLE_DIALOGClosable, movable, bordered (not resizable)
WSTYLE_POPUPNo decorations

Drawing Context

All drawing in wd_begin()/wd_end(). Coordinates relative to client area. Key functions:

OptionDescription
wd_pixel(x,y,color)Set pixel
wd_hline(x,y,w,color)Horizontal line
wd_vline(x,y,h,color)Vertical line
wd_fill_rect(x,y,w,h,color)Filled rect
wd_clear(color)Clear client area
wd_text_ui(x,y,str,fg,bg)Draw text (6x12 font)
wd_button(x,y,w,h,label,focused,pressed)Win95 button

Event Types

OptionDescription
WM_CREATEWindow created
WM_CLOSEClose button clicked
WM_PAINTRepaint needed
WM_KEYDOWNKey pressed (scancode + modifiers)
WM_CHARCharacter input
WM_MOUSEMOVEMouse moved (x, y, buttons)
WM_LBUTTONDOWNLeft click
WM_RBUTTONDOWNRight click
WM_TIMERTimer fired
WM_COMMANDMenu/dialog command (id)
WM_DROPFILESFile opened via association

The menu_bar_t struct supports up to 5 menus with 8 items each. Alt+letter accelerators are available for keyboard navigation. Selections arrive as WM_COMMAND events with the menu item id.

Dialogs

  • Message boxes (OK/Cancel/Yes/No) via dialog_show()
  • File Open dialog via file_dialog_open()
  • File Save dialog via file_dialog_save()
  • Input dialog via dialog_input_show()
  • Find/Replace dialogs (modeless)

Clipboard

  • clipboard_set_text(text, len)
  • clipboard_get_text()
  • clipboard_get_length()
  • clipboard_clear()

Sound

snd_open(sample_rate) opens a mixer channel, snd_write(ch, samples, count) writes stereo 16-bit PCM, snd_close(ch) closes. 4 concurrent channels, resampled to 44100 Hz.

PSRAM Allocator

psram_is_available(), psram_alloc(size), psram_free(ptr). For large buffers that don't need SRAM speed.

Fullscreen 8bpp Mode

Apps request 320x240 8bpp exclusive mode via display_request_mode(). Set 256-color palette, render to display_draw_buffer_ptr, display_swap_buffers(). Poll keyboard directly. Restore with display_request_mode(640,480,4) + wm_force_full_repaint().

File Associations

Apps register via .inf file (format: AppName\next:txt,log,cfg). Users opening matching files launch the app with WM_DROPFILES.

Application Flags

OptionDescription
APPFLAG_BACKGROUNDApp keeps running when not focused
APPFLAG_SINGLETONOnly one instance allowed

Deploying

  • Place source in apps/source/myapp/
  • Create CMakeLists.txt
  • Add myapp.ico for icon
  • Add to tools/regen_inf.py APPS list
  • Run build_apps.sh
  • Copy sdcard/fos/ to SD card