1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-24 00:08:06 +11:00
collapseos/emul/z80/rc2014_spi.c
Virgil Dupras 97a46a7b9b emul/z80: decouple SDC and SPI
My idea of plugging a RC2014 bridge directly onto a Sega Master System
cartridge doesn't work. The SMS eats all I/O addr space, we can't use
it. Therefore, this naive idea, in the emulator, of reusing sdc.c in
sms.c as-is, doesn't work either.

I'll have to find another way of communicating to a SPI device on the
SMS. I'll probably do it through a controller port. Meanwhile, I need
to decouple SPI from SDC in the emulator code so that I can reuse
sdc.c. This is what is done here.
2020-10-29 15:01:25 -04:00

29 lines
517 B
C

#include "rc2014_spi.h"
void spi_init(SPI *spi, EXCH spixfn)
{
spi->selected = false;
spi->resp = 0xff;
spi->spixfn = spixfn;
}
// TODO: for now, any nonzero value enables the SPI. To allow
// emulation of systems with multi-devices SPI relay, change
// this.
void spi_ctl_wr(SPI *spi, byte val)
{
spi->selected = val;
}
void spi_wr(SPI *spi, byte val)
{
if (spi->selected) {
spi->resp = spi->spixfn(val);
}
}
byte spi_rd(SPI *spi)
{
return spi->selected ? spi->resp : 0xff;
}