mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 18:08:05 +11:00
97a46a7b9b
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.
29 lines
517 B
C
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;
|
|
}
|