diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-01-24 13:51:19 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-01-24 13:51:19 +0100 |
commit | a4cb669e7f45b252181f1e062353ec40ab3b817a (patch) | |
tree | ff1a6d7dc2e8f3da6259dd1d95a38ee98cfbcfd4 /main.hpp | |
parent | prvi commit (diff) | |
download | ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.tar ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.tar.gz ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.tar.bz2 ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.tar.lz ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.tar.xz ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.tar.zst ov-a4cb669e7f45b252181f1e062353ec40ab3b817a.zip |
Diffstat (limited to 'main.hpp')
-rw-r--r-- | main.hpp | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1,12 +1,14 @@ #include <vector> #include <queue> +#include <string> namespace ov { using namespace std; enum opts { // opts are pas-1 bits aftr last ram ptr (2**ras)-1 and can be w/r from prg DEFAULT, - BUFOUT, // output from program in VM is always possible and no blocks - BUFIN, // input to program in VM is always possible and no blocks - BUFCLR, // clears whatever is in the buffer + BUFOUT, // output from program in VM is always possible and no blocks + BUFIN, // input to program in VM is always possible and no blocks + BUFINCLR, // clears whatever is in the input buffer + BUFOUTCLR, // clears whatever is in the output buffer OPTSLEN }; // read those last bits with the COPY instruction with source/dest on last pointer enum iobits { @@ -24,7 +26,7 @@ namespace ov { unsigned int s = 0; // source unsigned int d = 0; // destination bool i = 0; // instruction - bool p = 0; // enobitni padding, lahko za metainštrukcije + bool p = 0; // enobitni padding, lahko za metainštrukcije, pri COPY je že }; // privzeto inicializiran na NOOP inštrukcijo template<typename value_type, typename index_type, class Memory> class Mmu { private: @@ -57,8 +59,8 @@ namespace ov { class Ov; template<typename value_type, typename index_type> class Ram { private: - vector<value_type> storage; public: + vector<value_type> storage; Ov * ov; value_type peek (index_type); void poke(index_type, value_type); @@ -67,7 +69,7 @@ namespace ov { /* v Program (memory) bi lahko uporabili metainštrukcije (tisti padding bit) v * vsaki inštrukciji in v metainštrukcijah reprezentirali assembly org (lokacijo). * s tem bi lahko imeli npr. 128 biten program counter in s tem zelo preproste jumpe, - * ne bi pa bilo treba narediti 2^128 vektor in posledično binarno datoteko. + * ne bi pa bilo treba narediti 2^128 vektorja in posledično binarne datoteke. * Tak način bi bilo verjetno težko implementirati na dejanski strojni opremi, * tukaj pa bi v enem passu čez cel deserializan program memory zaznali te org * metainštrukcije in naredili neko tabelo oziroma prevajalnik program counterja @@ -76,8 +78,8 @@ namespace ov { * */ template<typename value_type, typename index_type> class Program { private: - vector<value_type> storage; public: + vector<value_type> storage; Ov * ov; value_type & peek (index_type addr) { return storage[addr]; @@ -133,7 +135,7 @@ namespace ov { Program<struct instr, unsigned int> pstor{this}; Mmu<struct instr, unsigned, class Program<struct instr, unsigned>> pm{pstor}; Ov (unsigned short int is = 2, unsigned short int pas = 16) - : is(is), pas(pas) { + : is(is), pas(pas) { // add bound checks for (int i = 0; i < OPTSLEN; i++) opts[i] = 0; for (int i = 0; i < IOLEN; i++) @@ -144,8 +146,9 @@ namespace ov { char outc (void); void in (bool); void inc (char); - struct instr deserialize (const char *); + struct instr deserialize (const char [sizeof(struct instr)]); void deserialize (istream &, unsigned int); - void pd (ostream); // print debug + string serialize (struct instr * i, unsigned int); + void pd (ostream &); }; } |