IPS(Interpreter for Process Structures) for mbed
Dependencies: ConfigFile FATFileSystem mbed
IPS port from linux/unix version.
mbed_blinky.ips
0 VAR led1 " LED1 " DigitalOut led1 ! : main ANFANG 1 JA? 1 led1 @ write 200 wait_ms 0 led1 @ write 200 wait_ms DANN/NOCHMAL ; main
- ips-02.tgz - ips for linux/unix
- ipsdoc.zip - document
- https://bitbucket.org/va009039/ips/
main.cpp@1:e74530ad6b9e, 2015-05-13 (annotated)
- Committer:
- va009039
- Date:
- Wed May 13 18:39:01 2015 +0900
- Revision:
- 1:e74530ad6b9e
- Child:
- 2:908338b1151a
add L152RE.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 |
1:e74530ad6b9e | 1 | // main.cpp 2015/5/13 |
va009039 |
1:e74530ad6b9e | 2 | #include "mbed.h" |
va009039 |
1:e74530ad6b9e | 3 | #include "BaseIPS.h" |
va009039 |
1:e74530ad6b9e | 4 | #include "VideoRAM.h" |
va009039 |
1:e74530ad6b9e | 5 | #include "VirtualRAM.h" |
va009039 |
1:e74530ad6b9e | 6 | #include "SDFileSystem.h" |
va009039 |
1:e74530ad6b9e | 7 | #include "ConfigFile.h" |
va009039 |
1:e74530ad6b9e | 8 | #include <string> |
va009039 |
1:e74530ad6b9e | 9 | |
va009039 |
1:e74530ad6b9e | 10 | #define CFG_FILE "/local/ips.cfg" |
va009039 |
1:e74530ad6b9e | 11 | |
va009039 |
1:e74530ad6b9e | 12 | #ifndef MBED_SPI0 |
va009039 |
1:e74530ad6b9e | 13 | #define MBED_SPI0 D11, D12, D13, D4 |
va009039 |
1:e74530ad6b9e | 14 | #endif |
va009039 |
1:e74530ad6b9e | 15 | SDFileSystem local(MBED_SPI0, "local"); // mosi, miso, sclk, cs, name |
va009039 |
1:e74530ad6b9e | 16 | |
va009039 |
1:e74530ad6b9e | 17 | RawSerial pc(USBTX,USBRX); |
va009039 |
1:e74530ad6b9e | 18 | |
va009039 |
1:e74530ad6b9e | 19 | class myips : public BaseIPS { |
va009039 |
1:e74530ad6b9e | 20 | VideoRAM vram; |
va009039 |
1:e74530ad6b9e | 21 | VirtualRAM mem; |
va009039 |
1:e74530ad6b9e | 22 | RawSerial& _pc; |
va009039 |
1:e74530ad6b9e | 23 | Timer t20ms; |
va009039 |
1:e74530ad6b9e | 24 | public: |
va009039 |
1:e74530ad6b9e | 25 | myips(RawSerial& pc): vram(pc),_pc(pc) { |
va009039 |
1:e74530ad6b9e | 26 | t20ms.reset(); |
va009039 |
1:e74530ad6b9e | 27 | t20ms.start(); |
va009039 |
1:e74530ad6b9e | 28 | } |
va009039 |
1:e74530ad6b9e | 29 | virtual u8 peekB(u16 a) { |
va009039 |
1:e74530ad6b9e | 30 | return mem.peek(a); |
va009039 |
1:e74530ad6b9e | 31 | } |
va009039 |
1:e74530ad6b9e | 32 | virtual void pokeB(u16 a, u8 b) { |
va009039 |
1:e74530ad6b9e | 33 | mem.poke(a, b); |
va009039 |
1:e74530ad6b9e | 34 | vram.vpoke(a, b); |
va009039 |
1:e74530ad6b9e | 35 | } |
va009039 |
1:e74530ad6b9e | 36 | virtual void* file_open(const char* filename, const char* mode) { |
va009039 |
1:e74530ad6b9e | 37 | string path = string("/local/") + filename; |
va009039 |
1:e74530ad6b9e | 38 | return fopen(path.c_str(), mode); |
va009039 |
1:e74530ad6b9e | 39 | } |
va009039 |
1:e74530ad6b9e | 40 | virtual int file_getc(void* handle) { |
va009039 |
1:e74530ad6b9e | 41 | MBED_ASSERT(handle); |
va009039 |
1:e74530ad6b9e | 42 | int c = fgetc((FILE*)handle); |
va009039 |
1:e74530ad6b9e | 43 | return c == EOF ? (-1) : c; |
va009039 |
1:e74530ad6b9e | 44 | } |
va009039 |
1:e74530ad6b9e | 45 | virtual void file_putc(int c, void* handle) { |
va009039 |
1:e74530ad6b9e | 46 | MBED_ASSERT(handle); |
va009039 |
1:e74530ad6b9e | 47 | fputc(c, (FILE*)handle); |
va009039 |
1:e74530ad6b9e | 48 | } |
va009039 |
1:e74530ad6b9e | 49 | virtual bool file_close(void* handle) { |
va009039 |
1:e74530ad6b9e | 50 | MBED_ASSERT(handle); |
va009039 |
1:e74530ad6b9e | 51 | if (fclose((FILE*)handle) == 0) { |
va009039 |
1:e74530ad6b9e | 52 | return true; |
va009039 |
1:e74530ad6b9e | 53 | } |
va009039 |
1:e74530ad6b9e | 54 | return false; |
va009039 |
1:e74530ad6b9e | 55 | } |
va009039 |
1:e74530ad6b9e | 56 | |
va009039 |
1:e74530ad6b9e | 57 | virtual bool test_20ms() { |
va009039 |
1:e74530ad6b9e | 58 | if (t20ms.read_ms() >= 20) { |
va009039 |
1:e74530ad6b9e | 59 | t20ms.reset(); |
va009039 |
1:e74530ad6b9e | 60 | return true; |
va009039 |
1:e74530ad6b9e | 61 | } |
va009039 |
1:e74530ad6b9e | 62 | return false; |
va009039 |
1:e74530ad6b9e | 63 | } |
va009039 |
1:e74530ad6b9e | 64 | |
va009039 |
1:e74530ad6b9e | 65 | virtual void do_io() { |
va009039 |
1:e74530ad6b9e | 66 | if (_pc.readable()) { |
va009039 |
1:e74530ad6b9e | 67 | int c = _pc.getc(); |
va009039 |
1:e74530ad6b9e | 68 | if (c == '\n' || c == '\r') { |
va009039 |
1:e74530ad6b9e | 69 | if (input_ptr != peek(a_PI)) { |
va009039 |
1:e74530ad6b9e | 70 | pokeB(READYFLAG, 1); |
va009039 |
1:e74530ad6b9e | 71 | poke(a_PE, input_ptr - 1); |
va009039 |
1:e74530ad6b9e | 72 | } |
va009039 |
1:e74530ad6b9e | 73 | else if (c == 0x08) // BS |
va009039 |
1:e74530ad6b9e | 74 | if (input_ptr > 0) { |
va009039 |
1:e74530ad6b9e | 75 | input_ptr--; |
va009039 |
1:e74530ad6b9e | 76 | } |
va009039 |
1:e74530ad6b9e | 77 | } else { |
va009039 |
1:e74530ad6b9e | 78 | if (input_ptr <= TVE) { |
va009039 |
1:e74530ad6b9e | 79 | pokeB(input_ptr++, c); |
va009039 |
1:e74530ad6b9e | 80 | } |
va009039 |
1:e74530ad6b9e | 81 | } |
va009039 |
1:e74530ad6b9e | 82 | } |
va009039 |
1:e74530ad6b9e | 83 | } |
va009039 |
1:e74530ad6b9e | 84 | }; |
va009039 |
1:e74530ad6b9e | 85 | |
va009039 |
1:e74530ad6b9e | 86 | int main() { |
va009039 |
1:e74530ad6b9e | 87 | string image = "IPS-Mu.bin"; |
va009039 |
1:e74530ad6b9e | 88 | string file; |
va009039 |
1:e74530ad6b9e | 89 | string cmd; |
va009039 |
1:e74530ad6b9e | 90 | ConfigFile cfg; |
va009039 |
1:e74530ad6b9e | 91 | if(cfg.read(CFG_FILE)) { |
va009039 |
1:e74530ad6b9e | 92 | char buf[128]; |
va009039 |
1:e74530ad6b9e | 93 | if (cfg.getValue("image", buf, sizeof(buf))) { |
va009039 |
1:e74530ad6b9e | 94 | image = buf; |
va009039 |
1:e74530ad6b9e | 95 | } |
va009039 |
1:e74530ad6b9e | 96 | if (cfg.getValue("file", buf, sizeof(buf))) { |
va009039 |
1:e74530ad6b9e | 97 | file = buf; |
va009039 |
1:e74530ad6b9e | 98 | cmd = string("\" ") + file + string(" \" READ"); |
va009039 |
1:e74530ad6b9e | 99 | } |
va009039 |
1:e74530ad6b9e | 100 | if (cfg.getValue("cmd", buf, sizeof(buf))) { |
va009039 |
1:e74530ad6b9e | 101 | cmd = buf; |
va009039 |
1:e74530ad6b9e | 102 | } |
va009039 |
1:e74530ad6b9e | 103 | } |
va009039 |
1:e74530ad6b9e | 104 | |
va009039 |
1:e74530ad6b9e | 105 | myips* ips = new myips(pc); |
va009039 |
1:e74530ad6b9e | 106 | void* fh = ips->file_open(image.c_str(), "rb"); |
va009039 |
1:e74530ad6b9e | 107 | MBED_ASSERT(fh); |
va009039 |
1:e74530ad6b9e | 108 | if (fh) { |
va009039 |
1:e74530ad6b9e | 109 | for(int i = 0; i <= 65535; i++) { |
va009039 |
1:e74530ad6b9e | 110 | int c = ips->file_getc(fh); |
va009039 |
1:e74530ad6b9e | 111 | if (c == (-1)) { |
va009039 |
1:e74530ad6b9e | 112 | break; |
va009039 |
1:e74530ad6b9e | 113 | } |
va009039 |
1:e74530ad6b9e | 114 | ips->pokeB(i, c); |
va009039 |
1:e74530ad6b9e | 115 | } |
va009039 |
1:e74530ad6b9e | 116 | ips->file_close(fh); |
va009039 |
1:e74530ad6b9e | 117 | } |
va009039 |
1:e74530ad6b9e | 118 | if (cmd != "") { |
va009039 |
1:e74530ad6b9e | 119 | ips->command(cmd.c_str()); |
va009039 |
1:e74530ad6b9e | 120 | } |
va009039 |
1:e74530ad6b9e | 121 | ips->emulator(); |
va009039 |
1:e74530ad6b9e | 122 | /* NOTREACHED */ |
va009039 |
1:e74530ad6b9e | 123 | } |
va009039 |
1:e74530ad6b9e | 124 |