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