main.cpp@0:1dac8a6d8994, 2015-09-04 (annotated)
- Committer:
- tothjani
- Date:
- Fri Sep 04 08:29:15 2015 +0000
- Revision:
- 0:1dac8a6d8994
6502 emulator, BASIC, Serial port output (115200), nucleo STM32F401RE board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tothjani | 0:1dac8a6d8994 | 1 | #include <stdint.h> |
tothjani | 0:1dac8a6d8994 | 2 | #include "mbed.h" |
tothjani | 0:1dac8a6d8994 | 3 | |
tothjani | 0:1dac8a6d8994 | 4 | uint8_t curkey = 0; |
tothjani | 0:1dac8a6d8994 | 5 | |
tothjani | 0:1dac8a6d8994 | 6 | Serial ser(SERIAL_TX, SERIAL_RX); |
tothjani | 0:1dac8a6d8994 | 7 | |
tothjani | 0:1dac8a6d8994 | 8 | |
tothjani | 0:1dac8a6d8994 | 9 | extern "C" { |
tothjani | 0:1dac8a6d8994 | 10 | uint16_t getpc(); |
tothjani | 0:1dac8a6d8994 | 11 | uint8_t getop(); |
tothjani | 0:1dac8a6d8994 | 12 | void exec6502(int32_t tickcount); |
tothjani | 0:1dac8a6d8994 | 13 | void reset6502(); |
tothjani | 0:1dac8a6d8994 | 14 | void serout(uint8_t val) |
tothjani | 0:1dac8a6d8994 | 15 | { |
tothjani | 0:1dac8a6d8994 | 16 | ser.printf("%c", val); |
tothjani | 0:1dac8a6d8994 | 17 | } |
tothjani | 0:1dac8a6d8994 | 18 | uint8_t getkey() |
tothjani | 0:1dac8a6d8994 | 19 | { |
tothjani | 0:1dac8a6d8994 | 20 | return(curkey); |
tothjani | 0:1dac8a6d8994 | 21 | } |
tothjani | 0:1dac8a6d8994 | 22 | void clearkey() |
tothjani | 0:1dac8a6d8994 | 23 | { |
tothjani | 0:1dac8a6d8994 | 24 | curkey = 0; |
tothjani | 0:1dac8a6d8994 | 25 | } |
tothjani | 0:1dac8a6d8994 | 26 | void printhex(uint16_t val) |
tothjani | 0:1dac8a6d8994 | 27 | { |
tothjani | 0:1dac8a6d8994 | 28 | ser.printf("%#08x", val); |
tothjani | 0:1dac8a6d8994 | 29 | } |
tothjani | 0:1dac8a6d8994 | 30 | } |
tothjani | 0:1dac8a6d8994 | 31 | |
tothjani | 0:1dac8a6d8994 | 32 | int main () |
tothjani | 0:1dac8a6d8994 | 33 | { |
tothjani | 0:1dac8a6d8994 | 34 | ser.baud (115200); |
tothjani | 0:1dac8a6d8994 | 35 | ser.printf("\nStart\n"); |
tothjani | 0:1dac8a6d8994 | 36 | |
tothjani | 0:1dac8a6d8994 | 37 | reset6502(); |
tothjani | 0:1dac8a6d8994 | 38 | |
tothjani | 0:1dac8a6d8994 | 39 | while(1) { |
tothjani | 0:1dac8a6d8994 | 40 | exec6502(100); //if timing is enabled, this value is in 6502 clock ticks. otherwise, simply instruction count. |
tothjani | 0:1dac8a6d8994 | 41 | if(ser.readable()) { |
tothjani | 0:1dac8a6d8994 | 42 | curkey = ser.getc() & 0x7F; |
tothjani | 0:1dac8a6d8994 | 43 | } |
tothjani | 0:1dac8a6d8994 | 44 | } |
tothjani | 0:1dac8a6d8994 | 45 | } |