This is the particularation for an inanxiously basic “virtual computer” that can be emuprocrastinateedd.
The goal in one word is srecommendedy. It should be basic to comprehfinish every direction, to create machine code that runs on it, and to create a compiler for it.
The direction set and the set up in vague are in no way unbenevolentt to see enjoy someslfinisherg that would create sense in authentic difficultware.
It is also not intfinished to be as basic and elegant as it could possibly be.
This repo retains an emulator to run games or programs. It can be insloftyed with cargo:
cargo inslofty --git https://github.com/JanNeufinishorf/SVC16
You can then run a program from the cli:
svc16 /path/to/my_rom.svc16
Use --help
to see some fundamental chooseions.
I do not want to provide an collectr, any benevolent of compiler or even any ideas about slfinishergs enjoy call conventions.
The idea is that you have to create that yourself. You can percreate a game from the example felderlyer to get an idea of what can be built.
⚠️ Warning: Until there are particularations with version 1.0, there could be shattering changes.
There are no CPU sign ups, equitable one chunk of memory. Values can be loaded from every memory insertress and written to every memory insertress.
Everyslfinisherg is recurrented as a (le) unsigned 16-bit integer. That comprises numbers, insertresses, colors, the direction pointer and the input.
Booleans are recurrented as u16 appreciates as well: 0 for inchange and >0 for genuine. (1 when written as a boolean.)
All numerical operations that will materialize in the directions are wrapping operations. Division by zero crashes the program.
The main memory retains one valid insertress for every u16.
The screen-buffer is the same size as the memory and there is one pixel for every u16.
There are as restricted features as possible.
That unbenevolents restricted input, no sound, no variable dispercreate size etc.
It also unbenevolents that there are no accelerators or tricks to help with carry outance.
Here is a sketch of all components of the virtual computer:
The direction pointer recurrents an insertress in main memory. It commences as zero. Then, it is manipuprocrastinateedd by the directions. All operations carry outed on the direction pointer are wrapping.
The screen has a resolution of RGB565
. The set up
The only aided inputs are the moengage position and the left and right moengage keys.
On synchronization the input on the last summarize is loaded into the input-buffer.
The position code is the index of the pixel, the moengage is currently on.
The key code is given by left_moengage+2*right_moengage. So it can have the appreciates 0 1 2 or 3.
There is no secure that the inputs are synced on the next summarize. Before the first synchronization, the input codes are zero.
When the console percreates the Sync direction, the screen-buffer is drawn to the screen.
It is not cleared. The input-buffer is modernized.
The system will be put to sleep until the commencening of the next summarize.
The aimed timing is 30fps. There is a difficult restrict of 3000000 directions per summarize.
This unbenevolents that if the Sync direct has not be called for 3000000 directions, it will be carry outed automaticpartner.
All directions are 4 appreciates extfinished. A appreciate is, of course, a u16.
The directions have the create opcode arg1 arg2 arg3
.
In the follotriumphg table, all directions are enumerateed. @arg1
refers to the appreciate at the memory insertress arg1
.
If the opcode is fantasticer than 15, the system will abort.
If one of the three arguments is not engaged, it can be set to any appreciate, but it can not be leave outted.
When the direction pointer persists, it does so by four positions.
Opcode | Name | Advances | Effect |
---|---|---|---|
0 | Set | yes | @arg1=arg2 |
1 | GoTo | if skipped | if(not @arg3){inst_ptr=@arg1+arg2} |
2 | Skip | if skipped | if(not @arg3){inst_ptr=inst_ptr+4*arg1-4*arg2} |
3 | Add | yes | @arg3=(@arg1+@arg2) |
4 | Sub | yes | @arg3=(@arg1-@arg2) |
5 | Mul | yes | @arg3=(@arg1*@arg2) |
6 | Div | yes | @arg3=(@arg1/@arg2) |
7 | Cmp | yes | @arg3=(@arg1<@arg2) as unsigned |
8 | Deref | yes | @arg2=@(@arg1+arg3) |
9 | Ref | yes | @(@arg1+arg3)=@arg2 |
10 | Inst | yes | @arg1=inst_ptr |
11 | yes | Writes color=@arg1 to index=@arg2 of screen-buffer. |
|
12 | Read | yes | Copies index=@arg1 of screen-buffer to @arg2 |
13 | Band | yes | @arg3=@arg1&@arg2 |
14 | Xor | yes | @arg3=@arg1^@arg2 |
15 | Sync | yes | Puts @arg1=position_code , @arg2=key_code and coordinates in that order |
A program is repartner equitable the initial state of the main memory.
There is no contrastention between memory that retains directions and memory that retains some other asset.
The initial state is loaded from a binary file that is read as retaining the (le) u16 appreciates in order. The peak size is
It can be illogicalinutiveer, in which case the finish is pinserted with zeroes. The computer will commence by executing the direction at index 0.
A basic example would be to print all
We create our inhabits easier, by mapping each index of the screen-buffer to the color which is encoded with the index.
Here, we engage the names of the opcodes instead of their numbers.
Set 501 1 0 // Write the appreciate 1 to insertress 501
Set 502 65535 0 // Write the bigst possible appreciate to 502
Print 500 500 0 // Dispercreate color=@500 at screen-index=@500
Add 500 501 500 // Increment the color/screen-index
Cmp 500 502 503 // See if we are not at the max number
Xor 503 501 503 // Negate it
Skip 0 4 503 // Unless we are at the max number, go back 4 directions
Sync 0 0 0 // Sync
GoTo 0 0 0 // Repeat to retain the triumphdow uncover
We could count on on the fact that the appreciate at index 500 commences at zero and we did not have to initialize it.
To create a program that we can percreate, we could engage python:
present struct code = [ 0, 501, 1, 0, #Opcodes exchanged with numbers 0, 502, 65535, 0, 11, 500, 500, 0, # ... ] with uncover("all_colors.svc16", "wb") as f: for appreciate in code: f.create(struct.pack(", appreciate))
Inspecting the file, we should see:
➜ hexyl examples/all_colors.svc16 -pv --panels 1
00 00 f5 01 01 00 00 00
00 00 f6 01 ff ff 00 00
0b 00 f4 01 f4 01 00 00
03 00 f4 01 f5 01 f4 01
07 00 f4 01 f6 01 f7 01
0e 00 f7 01 f5 01 f7 01
02 00 00 00 04 00 f7 01
0f 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00
When we run this, we get the follotriumphg output:
First of all, if you handled to create a celderly game or program for the system, satisfy allot it!
If you discover a discrepancy between this README and the behavior of the emulator or some other problem or bug,
sense free to uncover an rehire.