:*: This is a fully functional 8-bit computer with 4KB of RAM implemented in CS2D using buildings.  :*: 


 :>: Did anybody ask for this? 
 :>: Does anybody need this?
 :>: Does it have any use to anyone?

 :>: Answer to all three: No! But I made it anyway. :par-t:

 :>: Does it work?
I haven't tested everything, as this was a 12-hour challenge, but the important parts do, and I will fix bugs if you find any!


[more="How does this work?"]

You copy the map and the lua file into their respective folders and play. That's it. 
All standard tilesets and images stolen from the hud because I couldn't be bothered to create my own.[/more]


[more="How do I use this?"]

There is an extensive console at spawn.

On the left side there are two buttons. The top button saves the current memory to the file "sys/lua/PROGRAM.CS2D-BIN". It is not, as the name would suggest, a binary file, because I wouldn't be arsed with luas binary I/O implementation. 

On the right side there are also two buttons. The top one clears the entire memory while the bottom one says that it clears the registers, but it doesn't. Feel free to use the Aperture Science™ laser provided for free to all operators to do this yourself.

The bottom console has a green execute button (F2 works, too) and a red abort button (F3 works here, too). It runs the program from where the program counter points until it reaches a NOP.

the top console has 8 bits, displayed by dynamic walls, which can individually be switched on and off as well as a set button, which writes the bits to the interrupt byte of the memory.
[/more]


[more="How do I write code?"]

I was too lazy to provide any examples, so here is a short intro:

there are 64x64 (=4096) bytes of data in the memory. The last 8 bytes of these are reserved for the program counter (2B), the carry bit (1B), the interrupt (1B) and the system clock (4B).

One byte is made up of a 2x1 tile area, which can be populated by 2 buildings. These buildings represent the data (speedmod is recommended for getting about, and an unltimited build script, also not included, is necessary for proper programs. Also a lot of health. Automatically generated turrets of the opposite team may try to kill you).

These are the 16 values a half-byte (tile) can have:
0: [nothing]
1: T Barbed Wire
2: T Barricade
3: T Wall I
4: T Wall II
5: T Wall III
6: T Turret
7: T Supply
8: Any CT building or mine (not recommended) not listed
9: CT Barbed Wire
A: CT Barricade
B: CT Wall I
C: CT Wall II
D: CT Wall III
E: CT Turret
F: CT Supply

The op-codes take up 1 Byte, all further data is given in the brakets after and represent the bytes reserved for data after the op-code)
There are currently 15 operations defined, these are:
0: [b]NOP[/b] - the program stops
1: [b]writeRegister[/b](1B register, 1B value) - write a value to a register
2: [b]copyRegister[/b](0.5B regA, 0.5B regB) - copy the value of one register to another
3: [b]registerToMemory[/b](1B Register, 2B Memory Address) - copy the value of a register to memory
4: [b]MemoryToRegister[/b](2B Memory Address, 1B Register) - copy the value from a address in memory to a register
5: [b]jump[/b](2B MemAddr) - jump the program counter to a new location in memory
6: [b]jumpEquals[/b](0.5B regA, 0.5B regB, 2B MemAddr) - jump the program counter to a new location in memory if the two given registers have equal values
7: [b]jumpLessThan[/b](0.5B regA, 0.5B regB, 2B MemAddr) - jump the program counter to a new location in memory if regA has a smaller value than regB
8: [b]add[/b](0.5B regA, 0.5B regB) - add the value of register B to register A
9: [b]subtract[/b](0.5B regA, 0.5B regB) - subtract the value of register B from register A
A: [b]multiply[/b](0.5B regA, 0.5B regB) - multiply the value of register B to register A, with overflow bits written to register B.
B: [b]divide[/b](0.5B regA, 0.5B regB) - divide the value of register A by register B, with remainder written to register B.
C: [b]and[/b](0.5B regA, 0.5B regB) - bitwise and the value of register B to register A
D: [b]or[/b](0.5B regA, 0.5B regB) - bitwise or the value of register B to register A
E: [b]not[/b](0.5B regA, 0.5B regB) - bitwise not the value of register B and register A. If you want to only not one register, use the same for both parameters.
F: [b]xor[/b](0.5B regA, 0.5B regB) - bitwise xor the value of register B to register A


A big shoutout to the people who implemented bitwise operators in lua 5.3 - why would anyone ever feel the need to leave them out of a language?
[/more]

That's pretty much it. Please leave a comment if you have any questions and feel free to expand upon this project in any (non-commercial) manner you like, I'd love to hear of anything useful that actually comes from this!

Also, due to math, code can go out of bounds in several places, so be weary of bytes popping up in random places. Literally.

Also he who first implements Arbitrary Code Execution through this script, wins a bag of cookies, I'd be seriously impressed by the effort! :cookies: