diff --git a/specification/specification.typ b/specification/specification.typ index c4130bb..891fcfa 100644 --- a/specification/specification.typ +++ b/specification/specification.typ @@ -1,8 +1,11 @@ #import "@preview/colorful-boxes:1.4.0":slanted-colorbox #set page( paper:"a4", -background: rotate(24deg, - text(48pt, fill: rgb("FFCBC4"))[ +margin: 60pt, +columns: 1, +numbering: "- 1 -", +foreground: rotate(24deg, + text(48pt, fill: rgb("#ff4e375f"))[ *WORK IN PROGRESS* ] )) @@ -12,6 +15,8 @@ background: rotate(24deg, color: "gray", )[#txt] +#show link: underline + = SVC16: A Simple Virtual Computer @@ -47,7 +52,7 @@ Division by zero crashes the program. == The Simulated System #figure( - image("sketch.svg", width: 65%), + image("sketch.svg", width: 70%), caption: [A sketch of all components of the virtual computer.], ) @@ -86,7 +91,8 @@ When the console executes the *Sync* instruction, the screen buffer is drawn to It is not cleared. The system will be put to sleep until the beginning of the next frame. The targeted timing is 30fps. There is a hard limit of 3000000 instructions per frame. This means that if the Sync command has not been called for 3000000 instructions, it will be performed automatically. -This can mean that an event (like a mouse click) is never handled. An alternative way to describe it is that the syncing happens automatically every frame and the instructions each take $frac(1,30*3000000)$ seconds. Then the *Sync* command just sleeps until the next frame starts. +This can mean that an event (like a mouse click) is never handled. +An alternative way to describe it is that the syncing happens automatically every frame and the instructions each take $frac(1,30*3000000)$ seconds. Then the *Sync* command just sleeps until the next frame starts. == Instruction Set @@ -145,4 +151,83 @@ There is intentionally no way of restarting or even quitting a program from with #not-specified[ - There is no rule for how (or even if) the cause of the exception is reported. - It is not guaranteed that the emulator closes if an exception occurs. (So you can not use it to quit a program.) -] \ No newline at end of file +] + +== Example Program + +#[ + + #show raw: it => block( + fill: rgb("#0000000f"), + inset: 10pt, + radius: 4pt, + text(fill: rgb("#000000"), it)) + + +A simple example would be to print all $2^16$ possible colors to the screen. +We make our lives easier, by mapping each index of the screen buffer to the color which is encoded with the index. +Here, we use the names of the opcodes instead of their numbers. + +``` +Set 501 1 0 // Write the value 1 to address 501 +Set 502 65535 0 // Write the largest possible value to 502 +Print 500 500 0 // Display 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 instructions +Sync 0 0 0 // Sync +GoTo 0 0 0 // Repeat to keep the window open +``` +We could rely on the fact that the value at index 500 starts at zero and we did not have to initialize it. + +To build a program that we can execute, we could use python #emoji.snake: + +```python +import struct +code = [ + 0, 501, 1, 0, #Opcodes replaced with numbers + 0, 502, 65535, 0, + 11, 500, 500, 0, + # ... +] +with open("all_colors.svc16", "wb") as f: + for value in code: + f.write(struct.pack(" + +] + +== Miscellaneous +Further information, examples and a reference emulator can be found at #link("https://github.com/JanNeuendorf/SVC16"). +Everything contained in this project is provided under the _MIT License_. +Do with it whatever you want. + +One think we would ask is that if you distribute a modified version that is incompatible with the specifications, +you make it clear that it has breaking changes. \ No newline at end of file