diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-10-12 12:31:17 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-10-12 12:31:17 -0700 |
commit | de23567d99c444c6f2c901cdb278fae83899521d (patch) | |
tree | f61312ee1e889e0a8caa6c5cec29b61dc497bf03 | |
parent | 3b158194a8fe2ea49843303a78649e0f5fac1320 (diff) | |
download | mu-de23567d99c444c6f2c901cdb278fae83899521d.tar.gz |
4029
-rw-r--r-- | subx/010core.cc | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/subx/010core.cc b/subx/010core.cc index d71df322..afbffb9e 100644 --- a/subx/010core.cc +++ b/subx/010core.cc @@ -91,31 +91,6 @@ void run(const string& text_bytes) { run_one_instruction(); } -void load_program(const string& text_bytes) { - uint32_t addr = 1; - // we'll use C's 'strtol` to parse ASCII hex bytes - // strtol needs a char*, so we grab the buffer backing the string object - char* curr = const_cast<char*>(&text_bytes[0]); // non-portable, but blessed by Herb Sutter (http://herbsutter.com/2008/04/07/cringe-not-vectors-are-guaranteed-to-be-contiguous/#comment-483) - char* max = curr + strlen(curr); - while (curr < max) { - // skip whitespace - while (*curr == ' ' || *curr == '\n') ++curr; - // skip comments - if (*curr == '#') { - while (*curr != '\n') { - ++curr; - if (curr >= max) break; - } - ++curr; - continue; - } - put(Memory, addr, strtol(curr, &curr, /*hex*/16)); - trace(99, "load") << addr << " -> " << HEXBYTE << static_cast<unsigned int>(get_or_insert(Memory, addr)) << end(); // ugly that iostream doesn't print uint8_t as an integer - addr++; - } - End_of_program = addr; -} - // skeleton of how x86 instructions are decoded void run_one_instruction() { uint8_t op=0, op2=0, op3=0; @@ -162,6 +137,31 @@ void run_one_instruction() { } } +void load_program(const string& text_bytes) { + uint32_t addr = 1; + // we'll use C's 'strtol` to parse ASCII hex bytes + // strtol needs a char*, so we grab the buffer backing the string object + char* curr = const_cast<char*>(&text_bytes[0]); // non-portable, but blessed by Herb Sutter (http://herbsutter.com/2008/04/07/cringe-not-vectors-are-guaranteed-to-be-contiguous/#comment-483) + char* max = curr + strlen(curr); + while (curr < max) { + // skip whitespace + while (*curr == ' ' || *curr == '\n') ++curr; + // skip comments + if (*curr == '#') { + while (*curr != '\n') { + ++curr; + if (curr >= max) break; + } + ++curr; + continue; + } + put(Memory, addr, strtol(curr, &curr, /*hex*/16)); + trace(99, "load") << addr << " -> " << HEXBYTE << static_cast<unsigned int>(get_or_insert(Memory, addr)) << end(); // ugly that iostream doesn't print uint8_t as an integer + addr++; + } + End_of_program = addr; +} + uint8_t next() { return get_or_insert(Memory, EIP++); } |