mirror of
https://github.com/JanNeuendorf/SVC16.git
synced 2025-06-06 03:25:28 +00:00
Moved example program to a new file
This commit is contained in:
parent
7be70269e9
commit
2bbe0027f2
56
README.md
56
README.md
@ -141,61 +141,7 @@ A program is just the initial state of the main memory.
|
||||
There is no distinction between memory that contains instructions and memory that contains some other asset.
|
||||
The initial state is loaded from a binary file that is read as containing the (little-endian) u16 values in order. The maximum size is $2*2^{16}$ bytes ($\approx$ 131.1kB).
|
||||
It can be shorter, in which case the end is padded with zeroes. The computer will begin by executing the instruction at index 0.
|
||||
|
||||
## Example
|
||||
|
||||
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:
|
||||
|
||||
```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("<H", value))
|
||||
|
||||
```
|
||||
|
||||
Inspecting the file, we should see:
|
||||
```ansi
|
||||
➜ 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 following output:
|
||||
|
||||

|
||||
You can find an example of how to achieve this 
|
||||
|
||||
|
||||
## Contributing
|
||||
|
55
example_projects.md
Normal file
55
example_projects.md
Normal file
@ -0,0 +1,55 @@
|
||||
## The first program
|
||||
|
||||
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:
|
||||
|
||||
```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("<H", value))
|
||||
|
||||
```
|
||||
|
||||
Inspecting the file, we should see:
|
||||
```ansi
|
||||
➜ 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 following output:
|
||||
|
||||

|
||||
|
Loading…
x
Reference in New Issue
Block a user