ESOP is a specification and a reference implementation of a minimalist mobile phone running upon the stack-based [Uxn](https://wiki.xxiivv.com/site/uxn.html) VM.
ESOP was created as a result of reducing the vastly universal [SPARTA](https://gitlab.com/suborg/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`.
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:
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.
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.
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.
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.
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.
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.
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.
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.
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:
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: