update example, update spec to follow new vm
This commit is contained in:
parent
6f5d9931d0
commit
8f6af5de8c
|
@ -92,5 +92,5 @@ ZRE bridges retro-inspired creativity with modern portability for:
|
||||||
- Game jams (rapid prototyping + 3D engine).
|
- Game jams (rapid prototyping + 3D engine).
|
||||||
- Indie games (5th/6th-gen aesthetics).
|
- Indie games (5th/6th-gen aesthetics).
|
||||||
- Permacomputing (low-resource, sustainable code).
|
- Permacomputing (low-resource, sustainable code).
|
||||||
- Education (simple VM/language design), a language which scales to the developers level.
|
- Education (simple VM/language design).
|
||||||
|
|
||||||
|
|
142
docs/MACHINE.org
142
docs/MACHINE.org
|
@ -1,39 +1,26 @@
|
||||||
* machine
|
* machine
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: machine
|
:CUSTOM-ID: machine
|
||||||
:END:
|
:END:
|
||||||
I like uxn's idea of it being 16 bit because its 0 to 65535 or -32768 to
|
|
||||||
32767 which fits in your head nicely.
|
|
||||||
|
|
||||||
** memory
|
** memory
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: memory
|
:CUSTOM-ID: memory
|
||||||
:END:
|
:END:
|
||||||
ideas for memory (ram) is going to be a giant hashmap of some kind, or
|
|
||||||
maybe like picolisp?
|
|
||||||
|
|
||||||
picolisp has 64 bit machine words, a cell is 2 words
|
one large uint32 array
|
||||||
|
|
||||||
** types
|
** types
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: types
|
:CUSTOM-ID: types
|
||||||
:END:
|
:END:
|
||||||
number (fixed point numbers), symbols (string), cons-pairs (lists)
|
real (fixed point numbers)| Q16.16 number
|
||||||
|
int (integer) i32
|
||||||
|
nat (unsigned integer) u32
|
||||||
|
|
||||||
0000 0000 0000 0000 0000 0000 0000 0000
|
3-3-2 bit rgb
|
||||||
|
|
||||||
tfff xxxx yyyy zzzz
|
|
||||||
|
|
||||||
0rgb xxxx yyyy zzzz
|
|
||||||
|
|
||||||
mmrr rrrg ggb0 0000 {xxxx xxxx yyyy yyyy zzzz zzzz} {xxxx xxxx yyyy yyyy
|
|
||||||
zzzz zzzz} vz{xxxx xxxx yyyy yyyy zzzz zzzz}
|
|
||||||
|
|
||||||
rrrx gggy bbbz xxxx yyyy zzzz
|
|
||||||
|
|
||||||
**** 3-3-2 bit rgb
|
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: bit-rgb
|
:CUSTOM-ID: bit-rgb
|
||||||
:END:
|
:END:
|
||||||
rrrg ggbb xxxx yyyy
|
rrrg ggbb xxxx yyyy
|
||||||
|
|
||||||
|
@ -41,33 +28,33 @@ triangles
|
||||||
|
|
||||||
textures
|
textures
|
||||||
|
|
||||||
** devices
|
devices
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: devices
|
:CUSTOM-ID: devices
|
||||||
:END:
|
:END:
|
||||||
*** screen
|
** screen
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: screen
|
:CUSTOM-ID: screen
|
||||||
:END:
|
:END:
|
||||||
default screen is a single 2 triangle square face with a single dynamic
|
default screen is a single 2 triangle square face with a single dynamic
|
||||||
texture that can be drawn on it
|
texture that can be drawn on it
|
||||||
|
|
||||||
*** keyboard
|
** keyboard
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: keyboard
|
:CUSTOM-ID: keyboard
|
||||||
:END:
|
:END:
|
||||||
ASCII/UTF8 encoded values
|
ASCIIUTF8 encoded values
|
||||||
|
|
||||||
*** mouse/joystick
|
** mousejoystick
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: mousejoystick
|
:CUSTOM-ID: mousejoystick
|
||||||
:END:
|
:END:
|
||||||
Theoretically a modern controller could be mapped into 3 mouse/joystick
|
Theoretically a modern controller could be mapped into 3 mousejoystick
|
||||||
devices
|
devices
|
||||||
|
|
||||||
A nes controller could be mapped onto 1 mouse/joystick device
|
A nes controller could be mapped onto 1 mousejoystick device
|
||||||
|
|
||||||
x axis -> J1 -> J2 -> Dpad left/right y axis -> J1 -> J2 -> Dpad up/down
|
x axis -> J1 -> J2 -> Dpad leftright y axis -> J1 -> J2 -> Dpad updown
|
||||||
button 1 -> A -> t1 -> select button 2 -> B -> t2 -> start button 3 -> X
|
button 1 -> A -> t1 -> select button 2 -> B -> t2 -> start button 3 -> X
|
||||||
-> b2 -> "meta button like controller start" button 4 -> Y -> b2 ->
|
-> b2 -> "meta button like controller start" button 4 -> Y -> b2 ->
|
||||||
unused
|
unused
|
||||||
|
@ -77,52 +64,65 @@ xxxx yyyy 1234
|
||||||
x (4 bits) y (4 bits) 1 is button 1 pressed? 2 is button 2 pressed? 3 is
|
x (4 bits) y (4 bits) 1 is button 1 pressed? 2 is button 2 pressed? 3 is
|
||||||
button 3 pressed? 4 is button 4 pressed?
|
button 3 pressed? 4 is button 4 pressed?
|
||||||
|
|
||||||
*** sound/music
|
** soundmusic
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: soundmusic
|
:CUSTOM-ID: soundmusic
|
||||||
:END:
|
:END:
|
||||||
This one is going to be the hardest most likely, but its prolly going to
|
This one is going to be the hardest most likely| but its prolly going to
|
||||||
be something like the backend dac for ORCA.
|
be something like the backend dac for ORCA.
|
||||||
|
|
||||||
*** network/filesystem
|
** networkfilesystem
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: networkfilesystem
|
:CUSTOM-ID: networkfilesystem
|
||||||
:END:
|
:END:
|
||||||
9p filesystem/network by default.
|
9p filesystemnetwork by default.
|
||||||
|
|
||||||
Have an easy way to network.
|
Have an easy way to network.
|
||||||
|
|
||||||
*** opcodes
|
** opcodes
|
||||||
|
|
||||||
|---------------------------------------------------------------------------------------+------------------------------------------------------------------|
|
|----------------+------------------------------------------------------|
|
||||||
| opcode | description |
|
| opcode | description |
|
||||||
|---------------------------------------------------------------------------------------+------------------------------------------------------------------|
|
|----------------+------------------------------------------------------|
|
||||||
| nil | noop/nil/eos |
|
| HALT | terminate execution |
|
||||||
| *bbbb call | calls the address as a function |
|
| ADD-INT | dest = src1 + src2 |
|
||||||
| b syscall | calls a system call based on the opcode |
|
| SUB-INT | dest = src1 - src2 |
|
||||||
| bbbb pushReal - | allocates Q16.16 bits on the stack |
|
| MUL-INT | dest = src1 src2 |
|
||||||
| - popReal bbbb | deallocates Q16.16 bits from the stack |
|
| DIV-INT | dest = src1 src2 |
|
||||||
| b *bbbb storeByte - | stores 8 bits from the stack to the address |
|
| JEQ-INT | jump to address dest if src1 as int == src2 as int |
|
||||||
| bbbb *bbbb storeReal - | stores 64 bits from the stack to the address |
|
| JGT-INT | jump to address dest if src1 as int > src2 as int |
|
||||||
| *bbbb loadByte b | loads 8 bits from the address to the stack |
|
| JLT-INT | jump to address dest if src1 as int < src2 as int |
|
||||||
| *bbbb loadReal bbbb | loads 64 bits from the address to the stack |
|
| JLE-INT | jump to address dest if src1 as int <= src2 as int |
|
||||||
| bbbb bbbb addReal bbbb | adds 64 bits from the stack |
|
| JGE-INT | jump to address dest if src1 as int >= src2 as int |
|
||||||
| bbbb bbbb subReal bbbb | subtracts 64 bits from the stack |
|
| INT-TO-REAL | dest = src1 as f32 |
|
||||||
| bbbb bbbb mulReal bbbb | multiplies 64 bits from the stack |
|
| ADD-UINT | dest = src1 + src2 |
|
||||||
| bbbb bbbb divReal bbbb | divides 64 bits from the stack |
|
| SUB-UINT | dest = src1 - src2 |
|
||||||
| bbbb [bbbb bbbb bbbb] scalevec3 [bbbb bbbb bbbb] | scales the vec3 by the f64 on the stack |
|
| MUL-UINT | dest = src1 src2 |
|
||||||
| [bbbb bbbb bbbb] [bbbb bbbb bbbb] addvec3 [bbbb bbbb bbbb] | adds 2 vec3 together from the stack |
|
| DIV-UINT | dest = src1 src2 |
|
||||||
| [bbbb bbbb bbbb] [bbbb bbbb bbbb] subvec3 [bbbb bbbb bbbb] | subtracts 2 vec3 together from the stack |
|
| JEQ-UINT | jump to address dest if src1 as int == src2 as uint |
|
||||||
| [bbbb bbbb bbbb] [bbbb bbbb bbbb] mulvec3 [bbbb bbbb bbbb] | multiplies 2 vec3 together from the stack |
|
| JGT-UINT | jump to address dest if src1 as int > src2 as uint |
|
||||||
| [bbbb bbbb bbbb] [bbbb bbbb bbbb] dotvec3 bbbb | dot product of 2 vec3 together from the stack |
|
| JLT-UINT | jump to address dest if src1 as int < src2 as uint |
|
||||||
| [bbbb bbbb bbbb] [bbbb bbbb bbbb] crossvec3 [bbbb bbbb bbbb] | cross product of 2 vec3 together from the stack |
|
| JLE-UINT | jump to address dest if src1 as int <= src2 as uint |
|
||||||
| [bbbb bbbb bbbb] normvec3 [bbbb bbbb bbbb] | normalizes a vec3 |
|
| JGE-UINT | jump to address dest if src1 as int >= src2 as uint |
|
||||||
| [[bbbb bbbb bbbb bbbb]*4] invmat4 [[bbbb bbbb bbbb bbbb]*4] | inverts a mat4 from the stack |
|
| UINT-TO-REAL | dest = src1 as f32 |
|
||||||
| [[bbbb bbbb bbbb bbbb]*4] [[bbbb bbbb bbbb bbbb]*4] mulmat4 [[bbbb bbbb bbbb bbbb]*4] | multiplies 2 mat4's from the stack |
|
| ADD-REAL | dest = src1 + src2 |
|
||||||
| *triangle-array-ptr nnnn drawtriangles - | drawn 'n' many triangles using a array of vertices and its color |
|
| SUB-REAL | dest = src1 - src2 |
|
||||||
| *str1 *str2 streq b | checks 2 strings returns a bool of if they are the same |
|
| MUL-REAL | dest = src1 src2 |
|
||||||
| *str1 *str2 strcat *str3 | concatinates 2 strings and returns the address of the new string |
|
| DIV-REAL | dest = src1 src2 |
|
||||||
| *str strlen bbbb | pushes the length of the string onto the stack |
|
| JEQ-REAL | jump to address dest if src1 as real == src2 as real |
|
||||||
|
| JGE-REAL | jump to address dest if src1 as real >= src2 as real |
|
||||||
|
| JGT-REAL | jump to address dest if src1 as real > src2 as real |
|
||||||
|
| JLT-REAL | jump to address dest if src1 as real < src2 as real |
|
||||||
|
| JLE-REAL | jump to address dest if src1 as real <= src2 as real |
|
||||||
|
| REAL-TO-INT | dest = src1 as int |
|
||||||
|
| REAL-TO-UINT | dest = src1 as int |
|
||||||
|
| MOV | dest = src1 |
|
||||||
|
| JMP | jump to address src1 unconditionally |
|
||||||
|
| INT-TO-STRING | dest = src1 as str |
|
||||||
|
| UINT-TO-STRING | dest = src1 as str |
|
||||||
|
| REAL-TO-STRING | dest = src1 as str |
|
||||||
|
| READ-STRING | dest = read as str |
|
||||||
|
| PRINT-STRING | write src1 to stdout |
|
||||||
|
| CMP-STRING | dest = src1 as str == src2 as str |
|
||||||
| | |
|
| | |
|
||||||
| | |
|
|----------------+------------------------------------------------------|
|
||||||
|---------------------------------------------------------------------------------------+------------------------------------------------------------------|
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use "common.ztl";
|
use "common.ztl";
|
||||||
|
|
||||||
fn main(argc real, argv str[]) {
|
fn main(argc real, argv str[]) {
|
||||||
let screen_width = 800;
|
let screen_width = 800; /* implied uint32 */
|
||||||
let screen_height = 450;
|
let screen_height = 450; /* implied uint32 */
|
||||||
|
|
||||||
let username = argv[0];
|
let username = argv[0]; /* implied str */
|
||||||
let password = argv[1];
|
let password = argv[1]; /* implied str */
|
||||||
|
|
||||||
let me = Player(username, Vec3(0.0, 1.0, 2.0), PURPLE);
|
let me = Player(username, Vec3(0.0, 1.0, 2.0), PURPLE); /* implied Player struct */
|
||||||
|
|
||||||
let running = true;
|
let running = true;
|
||||||
while (running) {
|
while (running) {
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Note that these look like classes but act like structs
|
||||||
|
* the methods actually have a implied struct as their first argument
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Camera .
|
* Camera .
|
||||||
*/
|
*/
|
Loading…
Reference in New Issue