1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-23 07:30:31 +00:00

First attempt at adding serial port emulated via named pipe on host.

This commit is contained in:
Radosław Kujawa 2017-02-22 21:58:41 +01:00
parent 53f0136cab
commit 7ab946c5df
3 changed files with 91 additions and 1 deletions

View File

@ -1,7 +1,7 @@
CLI=rk65c02cli CLI=rk65c02cli
CLI_OBJS=rk65c02cli.o CLI_OBJS=rk65c02cli.o
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o
LIB_SO=librk65c02.so LIB_SO=librk65c02.so
LIB_STATIC=librk65c02.a LIB_STATIC=librk65c02.a

80
src/device_serial.c Normal file
View File

@ -0,0 +1,80 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "bus.h"
#include "device.h"
const static char *pipepath = "/tmp/serial"; /* should really be configurable */
struct device_serial_priv {
int pipefd;
};
uint8_t device_serial_read_1(void *, uint16_t);
void device_serial_write_1(void *, uint16_t, uint8_t);
uint8_t
device_serial_read_1(void *vd, uint16_t offset)
{
device_t *d;
struct device_serial_priv *dp;
d = (device_t *) vd;
dp = d->aux;
// XXX: TODO
return 0xAA;
}
void
device_serial_write_1(void *vd, uint16_t offset, uint8_t val)
{
device_t *d;
struct device_serial_priv *dp;
d = (device_t *) vd;
dp = d->aux;
write(dp->pipefd, &val, 1);
fsync(dp->pipefd);
}
device_t *
device_serial_init()
{
device_t *d;
struct device_serial_priv *dp;
d = (device_t *) malloc(sizeof(device_t));
assert(d != NULL);
d->name = "Serial";
d->size = 4;
d->read_1 = device_serial_read_1;
d->write_1 = device_serial_write_1;
dp = (struct device_serial_priv *) malloc(sizeof(struct device_serial_priv));
d->aux = dp;
dp->pipefd = mkfifo(pipepath, 600);
return d;
}
void
device_serial_finish(device_t *d)
{
free(d->aux);
//close pipe
}

10
src/device_serial.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _DEVICE_SERIAL_H_
#define _DEVICE_SERIAL_H_
#include "device.h"
device_t * device_serial_init();
void device_serial_finish(device_t *);
#endif /* _DEVICE_SERIAL_H_ */