franta-hg@29: /**
franta-hg@29: * RGB assembler
franta-hg@29: * Copyright © 2017 František Kučera (frantovo.cz)
franta-hg@29: *
franta-hg@29: * This program is free software: you can redistribute it and/or modify
franta-hg@29: * it under the terms of the GNU General Public License as published by
franta-hg@29: * the Free Software Foundation, either version 3 of the License, or
franta-hg@29: * (at your option) any later version.
franta-hg@29: *
franta-hg@29: * This program is distributed in the hope that it will be useful,
franta-hg@29: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@29: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@29: * GNU General Public License for more details.
franta-hg@29: *
franta-hg@29: * You should have received a copy of the GNU General Public License
franta-hg@29: * along with this program. If not, see .
franta-hg@29: */
franta-hg@29:
franta-hg@0: #include
franta-hg@0: #include
franta-hg@0: #include
franta-hg@0: #include
franta-hg@0: #include
franta-hg@20: #include
franta-hg@6:
franta-hg@19: #include "types.h"
franta-hg@20: #include "memory.h"
franta-hg@20: #include "Command.h"
franta-hg@28: #include "commands.h"
franta-hg@20: #include "commands/Goto.h"
franta-hg@25: #include "commands/GotoCompare.h"
franta-hg@22: #include "commands/Sleep.h"
franta-hg@23: #include "commands/End.h"
franta-hg@24: #include "commands/Color.h"
franta-hg@26: #include "commands/IncrementDecrement.h"
franta-hg@19:
franta-hg@0: using namespace std;
franta-hg@0:
franta-hg@0: int main(int argc, char* argv[]) {
franta-hg@0:
franta-hg@0: setlocale(LC_ALL, "");
franta-hg@0:
franta-hg@31: Memory memory;
franta-hg@31:
franta-hg@16: // Sample program / data:
franta-hg@16: // TODO: load bytes from file, stdin, serial port, network…
franta-hg@2: {
franta-hg@31: memory.write(CMD_SLEEP);
franta-hg@31: memory.write(255);
franta-hg@31: memory.write(CMD_SLEEP);
franta-hg@31: memory.write(10);
franta-hg@31: memory.write(CMD_SLEEP);
franta-hg@31: memory.write(255);
franta-hg@31: memory.write(CMD_GOTO);
franta-hg@31: memory.write(memory.getIndex() + sizeof (address_t) + 2 * sizeof (command_t));
franta-hg@31: memory.write(CMD_INVALID);
franta-hg@31: memory.write(CMD_INVALID);
franta-hg@31: memory.write(CMD_SLEEP);
franta-hg@31: memory.write(255);
franta-hg@31: memory.write(CMD_COLOR);
franta-hg@31: memory.write(23);
franta-hg@31: memory.write(0);
franta-hg@31: memory.write(200);
franta-hg@31: memory.write(255);
franta-hg@31: memory.write(CMD_INCREMENT);
franta-hg@31: memory.write(0);
franta-hg@31: memory.write(CMD_DECREMENT);
franta-hg@31: memory.write(0);
franta-hg@31: memory.write(CMD_GOTO_COMPARE);
franta-hg@31: memory.write(0);
franta-hg@31: memory.write(0 + sizeof (command_t) + sizeof (sleep_t));
franta-hg@31: memory.write(memory.getIndex() - 3 * sizeof (address_t) - 2 * sizeof (command_t));
franta-hg@31: memory.write(0);
franta-hg@31: memory.write(memory.getIndex() + sizeof (address_t));
franta-hg@31: memory.write(CMD_END);
franta-hg@31: memory.start();
franta-hg@2: }
franta-hg@0:
franta-hg@30: // Supported commands
franta-hg@30: // TODO: dynamic reconfiguration
franta-hg@21: unordered_map> commands = {
franta-hg@21: {CMD_GOTO, make_shared()},
franta-hg@25: {CMD_GOTO_COMPARE, make_shared()},
franta-hg@22: {CMD_SLEEP, make_shared()},
franta-hg@23: {CMD_END, make_shared()},
franta-hg@24: {CMD_COLOR, make_shared()},
franta-hg@30: {CMD_INCREMENT, make_shared (true, 1)},
franta-hg@30: {CMD_DECREMENT, make_shared (false, 1)},
franta-hg@21: };
franta-hg@27:
franta-hg@21:
franta-hg@30: // Main loop / interpreter:
franta-hg@31: while (memory.isInside()) {
franta-hg@31: wprintf(L"command %*d = ", 4, memory.getIndex());
franta-hg@31: command_t commandCode = memory.read();
franta-hg@26: wprintf(L"%02X ", commandCode);
franta-hg@0:
franta-hg@26: shared_ptr command = commands[commandCode];
franta-hg@21:
franta-hg@26: if (command) {
franta-hg@31: command->process(memory);
franta-hg@21: } else {
franta-hg@26: wprintf(L"invalid command\n");
franta-hg@21: }
franta-hg@0: }
franta-hg@0:
franta-hg@0: wprintf(L"all done\n");
franta-hg@0: return 0;
franta-hg@0: }