c++/rgb-assembler/rgb-assembler.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 21 Dec 2017 13:30:54 +0100
changeset 0 ee60ce4d8af5
child 1 ac1c16f0ebcd
permissions -rw-r--r--
first version
     1 #include <cstdlib>
     2 #include <iostream>
     3 #include <wchar.h>
     4 #include <locale.h>
     5 #include <cstring>
     6 
     7 using namespace std;
     8 
     9 typedef uint16_t address_t;
    10 typedef uint8_t command_t;
    11 
    12 const address_t MEMORY_SIZE = 1024;
    13 
    14 const command_t CMD_GOTO = 100;
    15 const command_t CMD_SLEEP = 101;
    16 const command_t CMD_END = 102;
    17 
    18 command_t readCommand(command_t (&memory)[MEMORY_SIZE], const address_t index) {
    19 	// TODO: map higher memory to static hardcoded areas or peripherals
    20 	return memory[index];
    21 }
    22 
    23 void writeMemoryChar(command_t (&memory)[MEMORY_SIZE], const address_t index, const int value) {
    24 	memory[index] = value;
    25 }
    26 
    27 void writeMemoryChar(command_t* memory[], const address_t index, const command_t value) {
    28 	*memory[index] = value;
    29 }
    30 
    31 int main(int argc, char* argv[]) {
    32 
    33 	setlocale(LC_ALL, "");
    34 
    35 
    36 	command_t memory[MEMORY_SIZE] = {
    37 		CMD_SLEEP,
    38 		CMD_SLEEP,
    39 		CMD_SLEEP,
    40 		CMD_END,
    41 	};
    42 	address_t memorySize = sizeof (memory) / sizeof (*memory);
    43 
    44 
    45 	for (address_t i = 0; i < memorySize; i++) {
    46 		command_t ch = readCommand(memory, i);
    47 		wprintf(L"command %d = %d\n", i, ch);
    48 
    49 		string command;
    50 
    51 		switch (ch) {
    52 			case CMD_GOTO:
    53 				command.append("GOTO");
    54 				break;
    55 			case CMD_SLEEP:
    56 				command.append("SLEEP");
    57 				break;
    58 			case CMD_END:
    59 				command.append("END");
    60 				i = memorySize;
    61 				break;
    62 
    63 		}
    64 
    65 		if (!command.empty()) {
    66 			wprintf(L"\t%s\n", command.c_str());
    67 		}
    68 	}
    69 
    70 
    71 
    72 	wprintf(L"all done\n");
    73 	return 0;
    74 }
    75