Essential Stack-Operated Phone
54822247 — Luxferre 2 months ago
a01c502a — Luxferre 2 months ago
a626c70d — Luxferre 4 months ago
Decimal short output successful


browse  log 



You can also use your local clone with git send-email.

#ESOP: Essential Stack-Operated Phone

ESOP is a specification and a reference implementation of a minimalist mobile phone running upon the stack-based Uxn VM.

ESOP was created as a result of reducing the vastly universal SPARTA specs to the bare minimum that would be the easiest to implement and support (but still retain the phone's usability) and rearranging everything to have the smallest memory footprint possible. However, ESOP cannot be viewed as a stripped-down version of SPARTA, as it uses completely different principles of interfacing with the phone components and the only thing it has in common with SPARTA is using Uxn as the core ISA.

As with Uxn/Varvara and Uxn/SPARTA, Uxn/ESOP applications are written in Uxntal so the recommended source code suffix is .tal, but the recommended file suffix for Uxn/ESOP binaries is .eso.

#Hardware specification

ESOP's hardware was largely inspired by Nokia 5110 family and some other ideas collected elsewhere. Besides the speakerphone and microphone used for GSM calls, ESOP features:

  • a monochrome 84x48 screen with controllable backlight;
  • a 16-key keypad (0-9, *, #, A (Advance), B (Back), C (Cancel), D (Do));
  • a removable battery with controllable status;
  • a mono audio beeper;
  • 64K (65536 bytes) of addressable memory fully available to the currently running app.

The 64K of memory are arranged as follows (size is specified in bytes in decimal):

Addresses Size Purpose
0000-fbff 64512 Uxn application RAM
fc00-fcff 256 Uxn work stack
fd00-fdff 256 Uxn return stack
fe00-fff7 504 Video memory
fff8-ffff 8 Control block

Every ESOP implementation must emulate the exact same memory layout as per this table.

#Control block

Unlike Uxn/Varvara or Uxn/SPARTA, Uxn/ESOP only exposes the control block ports (00 to 07) for DEI and DEO instructions. When calling these instructions, the control block memory area is automatically updated accordingly.

In Uxntal, the ESOP's control block would be described as follows:

|00 @Control [ &framevec $2 &io $2 &random $1 &status $1 &sound $1 &syscall $1 ]

The fields of the control block are:

  • Frame vector (00-01) - the port to set the vector to be run on each frame (60 frames per second);
  • Input/output (02-03) - the port to read input status bits of every key on the keypad and to output pixels at given coordinates;
  • Random/debug port (04) - the port to trace debug information on output and retrieve a random byte value on input;
  • Status port (05) - the port to get the information on battery and get/set screen brightness level;
  • Sound port (06) - the port to perform mono audio beeper operations;
  • Syscall port (07) - the port to run system calls to the phone's underlying operating system.

Implementation note: direct writing to or reading from the control block memory area may have the same effect as calling the corresponding DEO/DEI instructions. E.g. if the application directly stores a byte into #ffff, the runtime may consider it writing to the 07 control port and process it as a system call. For now, this rule is not enforced and DEO/DEI instructions are the main source of truth when interacting with control block, but this can (and most likely will) change in the future specification versions.

#Screen output

All the 4032 pixels of 84x48 screen are allocated in the 504-byte video memory of ESOP (#fe00-#fff7) in the left-to-right, top-to-bottom, high-to-low order. To output a pixel at the given coordinates using memory manipulation opcodes, the app must calculate the appropriate byte position itself and then set the corresponding bit within that byte. This process is made easier by reusing I/O port 02-03 with the DEO2 instruction where you can directly pass X and Y coordinates of the pixel to light it up.

Every frame (60 times per second), the following actions must be performed in the particular order:

  1. All 504 bytes in the video memory block are set to #00.
  2. If the control port short 00-01 is not zero, the frame vector is run from that address. All graphics operations, be it direct video memory modification or the pixel draw calls, must be done within the frame vector.
  3. The actual screen contents get updated according to the resulting video memory contents when the frame vector is finished.

Due to shared nature of the I/O device port, the handler responsible for pixel output in the ESOP implementation must preserve the input state between port write calls, i.e. save it before the processing and restore afterwards.

Standard input/output ports of Varvara are not supported in ESOP.

#Keypad input

When in input mode, the 16 bits of the input ports (02 and 03) have the following mapping:

Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Key # * D C B A 9 8 7 6 5 4 3 2 1 0

The A (Advance), B (Back), C (Cancel) and D (Do) keys should be implemented within runtimes and apps as having Nokia 5110 semantics: A maps to Up/Forward, B maps to Down/Back, C maps to Cancel and D maps to Navi/Action key.

#Random/debug port

The 04 port must return a random byte from 0 to 255 when read from, and initiate the stack trace print to the runtime when written to. Since standard output is not supported by ESOP, it is up to the runtime to decide where to output the debug information.

Just like with SPARTA, it's entirely up to the implementation to choose the randomness source, to implement a truly random or a secure enough pseudorandom generator. From the Uxn/ESOP application standpoint, the byte value obtained from the 04 port (or #fffc memory address) must be considered truly random and not derived from anything else.

#Status port

The 05 port is divided as follows:

Bits 7 6-4 3 2-0
Meaning Charger plugged Battery level Keypad BL switch Screen BL brightness

The higher nibble (bits 4 to 7) is used to indicate the status of charging and battery level. This nibble is read-only and must be ignored on modification.

The lower nibble (bits 0 to 3) of the status can be modified from the application, and the runtime should attempt to change the screen backlight brightness level, where 7 is the highest and 0 means backlight off, and toggle the keypad backlight switch as well if supported.

Note: emulated environments are allowed to always return ff when this port is read from, which means emulating a fully charged phone with external power supply connected on the maximum screen brightness and backlit keypad.

#Sound output

ESOP supports monophonic sound output with a beeper controllable via 06 port. As long as the port value is non-zero, the beeper must emit a sound wave of the specified frequency. The frequency is specified in semitones relative to A4 (440 Hz), with A4 itself being located at the value 30. Setting the port value to 00 must stop the sound.

Note: this specification does not enforce any particular waveform to be used for playing the notes, but in emulated ESOP environments, a square wave is recommended as the closest option for phone beeper emulation.

#System calls

ESOP supports up to 32 different system calls (syscalls), with up to 7 byte parameters each. The command byte passed to the 07 port is arranged as follows:

Bits 7-5 4-0
Meaning number of parameters syscall ID

Number of parameters determines how many subsequent writes to the syscall port the runtime must process as parameter pass as opposed to the syscall invokation. For instance, if we run #8a #07 DEO, it means we're starting the syscall 0a with four byte (or two short) parameters expected to pass afterwards using the same 07 port.

To distinguish between command byte and parameter byte, command byte must never be equal to zero. I.e. a hypothetical syscall with ID 0 and no parameters would be invalid by definition.

The syscall port cannot be read from, but runtime has the full access to application's memory during the syscall, and can write some information into it as the result.

The only system call required to be implemented in any ESOP-compatible runtime is 1f, the halting call. In addition to that, system calls can extend the basic ESOP functionality with:

  • serial/debug port I/O;
  • persistent/flash memory I/O (up to 16 MB), operating with 256-byte pages or individual bytes;
  • setting and getting datetime information;
  • initiating and receiving GSM voice calls;
  • sending DTMF signals during active voice calls;
  • active voice call manipulation (terminate, hold/unhold, bridge);
  • sending SMS messages;
  • sending USSD queries;
  • polling for incoming SMS messages;
  • polling for incoming USSD messages;
  • polling for incoming WEA messages;
  • reading the network information;
  • STK calls;
  • loading and invoking other Uxn/ESOP programs from the persistent memory.

On call completion, the 07 port value must be set to zero by the ESOP runtime.

ID Params Command Meaning
00 1b [data] 20 Write a byte to serial/debug port
01 1s [addr] 41 Read a byte from serial/debug port
02 1b 3b [data addr] 82 Write a byte under the 3-byte flash address
03 1s 3b [addr addr] a3 Read a byte under the 3-byte flash address
04 1b 3b [page addr] 84 Write a page under the 3-byte flash address
05 1b 3b [page addr] 85 Read a page under the 3-byte flash address
06 1s [addr] 46 Read the current system time/date information (see below) into the address
07 1s [addr] 47 Set the current system time/date information (see below) from the address
08-1d (reserved)
1e 1b 3b [flag addr] 9e Load and run another Uxn/ESOP application from flash address according to the flags
1f None 1f Halt (required)

#Datetime syscall implementation notes

The 46 and 47 calls, where implemented, should operate on 10 bytes of memory addressed by the value passed to them. The layout of these 10 bytes is similar to the one defined in Uxn/Varvara and Uxn/SPARTA specs:

  • 00-01: year
  • 02: month
  • 03: day
  • 04: hour
  • 05: minute
  • 06: second
  • 07: day of the week
  • 08-09: day of the year
  • 0a: DST flag for the local time


Spec and reference implementation developed by Luxferre in 2022, released into the public domain.

Made in Ukraine.