1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/c++/rgb-assembler/rgb-assembler.cpp Thu Dec 21 13:30:54 2017 +0100
1.3 @@ -0,0 +1,75 @@
1.4 +#include <cstdlib>
1.5 +#include <iostream>
1.6 +#include <wchar.h>
1.7 +#include <locale.h>
1.8 +#include <cstring>
1.9 +
1.10 +using namespace std;
1.11 +
1.12 +typedef uint16_t address_t;
1.13 +typedef uint8_t command_t;
1.14 +
1.15 +const address_t MEMORY_SIZE = 1024;
1.16 +
1.17 +const command_t CMD_GOTO = 100;
1.18 +const command_t CMD_SLEEP = 101;
1.19 +const command_t CMD_END = 102;
1.20 +
1.21 +command_t readCommand(command_t (&memory)[MEMORY_SIZE], const address_t index) {
1.22 + // TODO: map higher memory to static hardcoded areas or peripherals
1.23 + return memory[index];
1.24 +}
1.25 +
1.26 +void writeMemoryChar(command_t (&memory)[MEMORY_SIZE], const address_t index, const int value) {
1.27 + memory[index] = value;
1.28 +}
1.29 +
1.30 +void writeMemoryChar(command_t* memory[], const address_t index, const command_t value) {
1.31 + *memory[index] = value;
1.32 +}
1.33 +
1.34 +int main(int argc, char* argv[]) {
1.35 +
1.36 + setlocale(LC_ALL, "");
1.37 +
1.38 +
1.39 + command_t memory[MEMORY_SIZE] = {
1.40 + CMD_SLEEP,
1.41 + CMD_SLEEP,
1.42 + CMD_SLEEP,
1.43 + CMD_END,
1.44 + };
1.45 + address_t memorySize = sizeof (memory) / sizeof (*memory);
1.46 +
1.47 +
1.48 + for (address_t i = 0; i < memorySize; i++) {
1.49 + command_t ch = readCommand(memory, i);
1.50 + wprintf(L"command %d = %d\n", i, ch);
1.51 +
1.52 + string command;
1.53 +
1.54 + switch (ch) {
1.55 + case CMD_GOTO:
1.56 + command.append("GOTO");
1.57 + break;
1.58 + case CMD_SLEEP:
1.59 + command.append("SLEEP");
1.60 + break;
1.61 + case CMD_END:
1.62 + command.append("END");
1.63 + i = memorySize;
1.64 + break;
1.65 +
1.66 + }
1.67 +
1.68 + if (!command.empty()) {
1.69 + wprintf(L"\t%s\n", command.c_str());
1.70 + }
1.71 + }
1.72 +
1.73 +
1.74 +
1.75 + wprintf(L"all done\n");
1.76 + return 0;
1.77 +}
1.78 +