X-Git-Url: http://git.joshuawise.com/firearm.git/blobdiff_plain/3a57f3e5cbccf519c546eebed9fa9db7c328d72c..dfddccfb552a24c60589696269a5325ec267c46d:/testbench.cpp diff --git a/testbench.cpp b/testbench.cpp index 4188d71..e89de38 100644 --- a/testbench.cpp +++ b/testbench.cpp @@ -1,8 +1,55 @@ #include "Vsystem.h" #include +#define _XOPEN_SOURCE +#include +#include +#include Vsystem *top; +int ptyfd = -1; + +void openpty() +{ + int fd = posix_openpt(O_RDWR); + char b[128]; + struct termios kbdios; + + grantpt(fd); + fcntl(fd, F_SETFD, 0); /* clear close-on-exec */ + tcgetattr(fd, &kbdios); + kbdios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + tcsetattr(fd, TCSANOW, &kbdios); + sprintf(b, "rxvt -pty-fd %d -bg black -fg white -title \"Output terminal\" &", fd); + system(b); + unlockpt(fd); + ptyfd = open(ptsname(fd), O_RDWR | O_NONBLOCK); + close(fd); +} + +unsigned int term_input() +{ + int rv; + unsigned char c; + if (ptyfd == -1) + openpty(); + rv = read(ptyfd, &c, 1); + if (rv < 0) + return 0; + return 0x100 | c; +} + +void term_output(unsigned char d) +{ + int fd = posix_openpt(O_RDWR); + static int fd2 = -1; + char b[128]; + + if (ptyfd == -1) + openpty(); + write(ptyfd, &d, 1); +} + unsigned int main_time = 0; double sc_time_stamp ()