Devices are external systems to the Uxn code such as the screen, the mouse, the keyboard, etc. There is a maximum of 16 devices, each device have 8 bytes to read from, and 8 bytes to write to.
An emulator implementation can choose which device to implement or to leave out, these are the suggested addresses and ports of this specific emulator.
|system||vector*||red*||The system device's vector is automatically set by the emulator and is the first vector that is triggered in a program.|
|console||vector*||char||The console's vector is currently unused.|
|screen||vector*||x*||The screen device's vector is triggered 60 times per second, it is typically used to update pixels on the screen.|
|audio||vector*||adsr*||The audio devices' vectors are currently unused.|
|midi||vector*||The midi device's vector is triggered when a midi note is received.|
|controller||vector*||nil||The controller device's vector is triggered each time a key is pressed or released.|
|mouse||vector*||nil||The mouse device's vector is triggered each time the mouse moved, or a button was pressed or released.|
|file||vector*||name*||The file's vector is currently unused. The reading/writing of a file will set the success short to the length of that data.|
|datetime||yearh*||refresh||The datetime's vector is currently unused.|
The screen device is made of two screen buffers, that are combined to form the pixels on the screen. The sprite device can be written to with a
The color byte defines the layer to draw on, the type of data to draw, and the colors to use. To paint a pixel on the first layer, use the
#01, to paint a pixel on the second layer, use the
* * M L D C B A | | | +---- Layer | | | +---- Blend | | +------ Mode | | +------ Blend | +-------- Flipx | +-------- Blend +---------- Flipy +---------- Blend
The device can also draw multiple bytes at once by writing the address* to a series of bytes in the screen's sprite address, to paint a 1-bit 8x8 sprite(8 bytes) on the first layer, use the
#21, to paint a 1-bit 8x8 sprite on the second layer, use the
#31. The blending mode 1, is demonstrated in the table below. To learn more about the sprite format, see .chr format.
|high nibble||low nibble|
pitch is written to any of the audio devices, it starts playing an audio sample from Uxn's memory, pointed to by
length*. It loops the sample (unless told not to) until it reaches the end of the ADSR envelope defined by
Several fields contain more than one component:
|Subfield||Attack||Decay||Sustain||Release||No Loop||Note Number||Left||Right|
Each of the ADSR components is measured in 16ths of a second, so writing
adsr* will play a note that lasts for exactly one second. If
#0000 then no envelope will be applied: this is most useful for longer samples that are set to play once by setting the most significant bit of
pitch to 1.
volume components set how loudly the next sample will play.
#ff sets maximum volume for both speakers.
pitch is written, any sample that is currently playing will be replaced with the sample defined by all the values set in the device. While the sample is playing, the
output byte can be read to find the loudness of the envelope at that moment.
All samples used by the audio devices are mono and signed 8-bit, so the space taken up by samples is minimized. The sample rate of the samples depends on
|Sample type||Sample rate|
|> 256||Middle-C pitched sample||44,100 Hz|
Long samples are assumed to be already pitched to Middle C and will loop (unless No Loop is 1) until the end of the envelope. To play the sample at the same rate as it was recorded, write the Middle C MIDI note number,
pitch. To play at double or half speed, for example, write an octave higher or lower to
The minimum sample size that can be pitched at 44.1 kHz to Middle C with reasonable accuracy is 337 bytes long, which represents two cycles of the 261 Hz wave. The single wavelength mode in Uxn allows much smaller samples to be used, even down to only two bytes for a square wave. In this mode the length of the entire sample is taken to be one cycle of the Middle C note, so the pitch is not heard to vary even if
length* were to change between sample plays.
This button byte works similarly to a NES controller, where there the state of each one of the 8 buttons is stored as a bit in a single byte. The keys byte contains the ascii character that is currently pressed.