Add PV UART read (into emulator)
This commit is contained in:
parent
831a115881
commit
d7d30c5608
3 changed files with 49 additions and 8 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
#include "m68k.h"
|
#include "m68k.h"
|
||||||
#include "machw.h"
|
#include "machw.h"
|
||||||
|
|
||||||
|
#undef DEBUG
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define DDBG(...) printf(__VA_ARGS__)
|
#define DDBG(...) printf(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
11
src/main.c
11
src/main.c
|
|
@ -82,6 +82,8 @@ static int disassemble = 0;
|
||||||
|
|
||||||
static void update_overlay_layout(void);
|
static void update_overlay_layout(void);
|
||||||
|
|
||||||
|
extern int pv_uart_read();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static int m68k_dump_regs(char *buf, int len)
|
static int m68k_dump_regs(char *buf, int len)
|
||||||
|
|
@ -246,7 +248,6 @@ static void kbd_rx(uint8_t data)
|
||||||
int evt = KBD_RSP_NULL;
|
int evt = KBD_RSP_NULL;
|
||||||
if (ringbuf_avail(&kbd_pending_evt)) {
|
if (ringbuf_avail(&kbd_pending_evt)) {
|
||||||
evt = ringbuf_get(&kbd_pending_evt);
|
evt = ringbuf_get(&kbd_pending_evt);
|
||||||
printf("via sr rx %s %02x\n", data == KBD_CMD_INSTANT ? "INSTANT" : "inquiry", evt);
|
|
||||||
}
|
}
|
||||||
via_sr_rx(evt);
|
via_sr_rx(evt);
|
||||||
}
|
}
|
||||||
|
|
@ -401,6 +402,10 @@ unsigned int FAST_FUNC(cpu_read_word)(unsigned int address)
|
||||||
if (IS_ROM(address))
|
if (IS_ROM(address))
|
||||||
return ROM_RD16(address & (ROM_SIZE - 1));
|
return ROM_RD16(address & (ROM_SIZE - 1));
|
||||||
|
|
||||||
|
if (address == PV_UART_ADDR) {
|
||||||
|
return pv_uart_read();
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_TESTSW(address))
|
if (IS_TESTSW(address))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
@ -476,11 +481,7 @@ void FAST_FUNC(cpu_write_byte)(unsigned int address, unsigned int value)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (address == PV_UART_ADDR) {
|
if (address == PV_UART_ADDR) {
|
||||||
if(value < 32 && value != '\r' && value != '\n') {
|
|
||||||
printf("0x%02x", value);
|
|
||||||
} else {
|
|
||||||
putchar(value);
|
putchar(value);
|
||||||
}
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,43 @@ static int open_disc(unix_disc_descr_t *desc, int slot, int opt_write, const cha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from micropython
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <poll.h>
|
||||||
|
static struct termios orig_termios;
|
||||||
|
|
||||||
|
static void stdio_mode_raw(void) {
|
||||||
|
// save and set terminal settings
|
||||||
|
tcgetattr(0, &orig_termios);
|
||||||
|
static struct termios termios;
|
||||||
|
termios = orig_termios;
|
||||||
|
termios.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||||
|
termios.c_cflag = (termios.c_cflag & ~(CSIZE | PARENB)) | CS8;
|
||||||
|
termios.c_lflag = 0;
|
||||||
|
termios.c_cc[VMIN] = 1;
|
||||||
|
termios.c_cc[VTIME] = 0;
|
||||||
|
tcsetattr(0, TCSAFLUSH, &termios);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stdio_mode_orig(void) {
|
||||||
|
// restore terminal settings
|
||||||
|
tcsetattr(0, TCSAFLUSH, &orig_termios);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pv_uart_read() {
|
||||||
|
|
||||||
|
struct pollfd p = { .fd = 0, .events = POLLIN };
|
||||||
|
int r = poll(&p, 1, 0);
|
||||||
|
if (r > 0) {
|
||||||
|
unsigned char result;
|
||||||
|
r = read(0, &result, 1);
|
||||||
|
if (r == 1) return result;
|
||||||
|
}
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
||||||
/* The emulator core expects to be given ROM and RAM pointers,
|
/* The emulator core expects to be given ROM and RAM pointers,
|
||||||
|
|
@ -346,7 +383,7 @@ int main(int argc, char *argv[])
|
||||||
perror("SDL window");
|
perror("SDL window");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
SDL_SetWindowGrab(window, SDL_TRUE);
|
SDL_SetWindowGrab(window, SDL_FALSE);
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -371,10 +408,12 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
umac_init(ram_base, rom_base, discs);
|
umac_init(ram_base, rom_base, discs);
|
||||||
umac_opt_disassemble(opt_disassemble);
|
umac_opt_disassemble(opt_disassemble);
|
||||||
|
stdio_mode_raw();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Main loop
|
// Main loop
|
||||||
|
|
||||||
|
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int mouse_button = 0;
|
int mouse_button = 0;
|
||||||
uint64_t last_vsync = 0;
|
uint64_t last_vsync = 0;
|
||||||
|
|
@ -395,7 +434,6 @@ int main(int argc, char *argv[])
|
||||||
case SDL_KEYUP: {
|
case SDL_KEYUP: {
|
||||||
int c = SDLScan2MacKeyCode(event.key.keysym.scancode);
|
int c = SDLScan2MacKeyCode(event.key.keysym.scancode);
|
||||||
c = (c << 1) | 1;
|
c = (c << 1) | 1;
|
||||||
printf("Key 0x%x -> 0x%x\n", event.key.keysym.scancode, c);
|
|
||||||
if (c != MKC_None)
|
if (c != MKC_None)
|
||||||
umac_kbd_event(c, (event.type == SDL_KEYDOWN));
|
umac_kbd_event(c, (event.type == SDL_KEYDOWN));
|
||||||
} break;
|
} break;
|
||||||
|
|
@ -441,5 +479,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
} while (!done);
|
} while (!done);
|
||||||
|
|
||||||
|
stdio_mode_orig();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue