XXIIVV

Uxnemu is a Uxn emulator written in ANSI C, and SDL2.

The thin layer that is the Uxn emulator is the only part of this project needing to be ported to make the system available on a new platform. For that reason, Uxn was designed with a focus on portability and simplicity such that it welcomes anyone to try their hand at building their own implementation. The current emulator is 400 lines of C89, with SDL2 as its only dependecy.

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.

Devices

An emulator implementation can choose which device to implement or to leave out, these are the suggested addresses and ports of this specific emulator.

devicei/oNotes
0x000x08
0100systemvector*red*The system device's vector is automatically set by the emulator and is the first vector that is triggered in a program.
green*
blue*
0110consolevector*charThe console's vector is currently unused.
byte
short*
string*
0120screenvector*x*The screen device's vector is triggered 60 times per second, it is typically used to update pixels on the screen.
width*y*
height*addr*
color
0130audiowave*volumeThe APU multiplies two waveforms, defined by the wave and envelope vectors. In the main program, write the vectors, volume (left/right nibbles) and pitch (MIDI note number) to define the note, then the channel number to the play byte.
envelope*pitch
play
value*
delay*
finish
0140controllervector*nilThe controller device's vector is triggered each time a key is pressed or released.
button
key
0160mousevector*nilThe mouse device's vector is triggered each time the mouse moved, or a button was pressed or released.
x*
y*
state
chord
0170filevector*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.
success*length*
offset*addr(r)*
addr(w)*
0190midivector*devicewThe midi device's vector is triggered when a midi note is received.
devicerbyte1
byte1byte2
byte2
01a0datetimeyearh*refreshThe datetime's vector is currently unused.
yearl*
dayh*
dayl*

Screen Device(PPU)

Buffersbackground64kb
foreground64kb

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 x*, y* and color.

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 #11.

* * M L            D C B A            
| | | +---- Layer  | | | +---- Blend   
| | +------ Mode   | | +------ Blend   
| +-------- Nil    | +-------- Blend  
+---------- Nil    +---------- 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 nibblelow nibble
0bgpixel00802
1fg110912
2bg1-bit220a2
3fg330b32
4bg2-bit401c03
5fg51d13
6bgnil621e23
7fg731f3

Audio Device(APU)

In the wave and envelope vectors, write the value (amplitude) and delay shorts to define the next part of the waveform. A delay of 0x8000 in the wave vector represents half the note's period: in the envelope vector, it represents half a second. The waveform is linearly interpolated between pairs of values. During these vectors, the channel number used for the note can be read from the play byte.

The wave and envelope vectors repeat until (a) no value/delay pairs are written to the device or (b) any value is written to the finish byte.

Controller Device

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.

0x01Ctrl0x10Up
0x02Alt0x20Down
0x04Shift0x40Left
0x08Escape0x80Right
— Submit an edit to uxnemu.htm(117 lines)

incoming(1): uxn

Last update on 15H04, edited 7 times. +24/40fh -----|