serial: backport from upstream. Clean-up

This commit is contained in:
Flyinghead 2019-11-03 17:26:35 +01:00
parent b7dd8f16d4
commit a7926a2357
3 changed files with 59 additions and 30 deletions

View File

@ -4,10 +4,10 @@
*/
#include "types.h"
#include "hw/sh4/sh4_mmr.h"
#include "hw/sh4/sh4_interrupts.h"
SCIF_SCFSR2_type SCIF_SCFSR2;
u8 SCIF_SCFRDR2;
SCIF_SCFDR2_type SCIF_SCFDR2;
SCIF_SCSCR2_type SCIF_SCSCR2;
/*
//SCIF SCSMR2 0xFFE80000 0x1FE80000 16 0x0000 0x0000 Held Held Pclk
@ -43,49 +43,78 @@ SCSPTR2_type SCIF_SCSPTR2;
SCLSR2_type SCIF_SCLSR2;
*/
void SerialWrite(u32 addr, u32 data)
static void Serial_UpdateInterrupts()
{
if (settings.debug.SerialConsole) {
InterruptPend(sh4_SCIF_TXI, SCIF_SCFSR2.TDFE);
InterruptMask(sh4_SCIF_TXI, SCIF_SCSCR2.TIE);
InterruptPend(sh4_SCIF_RXI, SCIF_SCFSR2.RDF);
InterruptMask(sh4_SCIF_RXI, SCIF_SCSCR2.RIE);
}
static void SerialWrite(u32 addr, u32 data)
{
if (settings.debug.SerialConsole)
putc(data, stdout);
}
SCIF_SCFSR2.TDFE = 1;
SCIF_SCFSR2.TEND = 1;
Serial_UpdateInterrupts();
}
//SCIF_SCFSR2 read
u32 ReadSerialStatus(u32 addr)
static u32 ReadSerialStatus(u32 addr)
{
if (false /*PendingSerialData()*/)
{
return 0x60 | 2;
return SCIF_SCFSR2.full | 2;
}
else
{
return 0x60| 0;
return SCIF_SCFSR2.full | 0;
}
/*
//TODO : Add status for serial input
return 0x60;//hackish but works !
*/
}
void WriteSerialStatus(u32 addr,u32 data)
static void WriteSerialStatus(u32 addr,u32 data)
{
/*
//TODO : do something ?
*/
if (!SCIF_SCFSR2.BRK)
data &= ~0x10;
SCIF_SCFSR2.full = data & ~3;
SCIF_SCFSR2.TDFE = 1;
SCIF_SCFSR2.TEND = 1;
Serial_UpdateInterrupts();
}
//SCIF_SCFDR2 - 16b
u32 Read_SCFDR2(u32 addr)
static u32 Read_SCFDR2(u32 addr)
{
return 0;
}
//SCIF_SCFRDR2
u32 ReadSerialData(u32 addr)
static u32 ReadSerialData(u32 addr)
{
s32 rd=0;//ReadSerial();
return (u8)rd ;
}
//SCSCR2
static u32 SCSCR2_read(u32 addr)
{
return SCIF_SCSCR2.full;
}
static void SCSCR2_write(u32 addr, u32 data)
{
SCIF_SCSCR2.full = data;
Serial_UpdateInterrupts();
}
//Init term res
void serial_init()
{
@ -96,7 +125,7 @@ void serial_init()
sh4_rio_reg(SCIF,SCIF_SCBRR2_addr,RIO_DATA,8);
//SCIF SCSCR2 0xFFE80008 0x1FE80008 16 0x0000 0x0000 Held Held Pclk
sh4_rio_reg(SCIF,SCIF_SCSCR2_addr,RIO_DATA,16);
sh4_rio_reg(SCIF, SCIF_SCSCR2_addr, RIO_FUNC, 16, &SCSCR2_read, &SCSCR2_write);
//Write only
//SCIF SCFTDR2 0xFFE8000C 0x1FE8000C 8 Undefined Undefined Held Held Pclk
@ -140,9 +169,9 @@ void serial_reset()
SCIF_SCBRR2=0xFF;
SCIF_SCFSR2.full=0x060;
SCIF_SCFCR2.full=0x000;
SCIF_SCFDR2.full=0x000;
SCIF_SCSPTR2.full=0x000;
SCIF_SCLSR2.full=0x000;
SCIF_SCSCR2.full = 0;
}
void serial_term()

View File

@ -1307,7 +1307,7 @@ union SCIF_SCSCR2_type
};
u16 full;
};
#define SCIF_SCSCR2 SH4IO_REG_T(SCIF,SCSCR2,16)
extern SCIF_SCSCR2_type SCIF_SCSCR2;
//SCIF SCFTDR2 0xFFE8000C 0x1FE8000C 8 Undefined Undefined Held Held Pclk
#define SCIF_SCFTDR2 SH4IO_REG(SCIF,SCFTDR2,8)
@ -1387,7 +1387,6 @@ union SCIF_SCFDR2_type
};
u16 full;
};
extern SCIF_SCFDR2_type SCIF_SCFDR2;
//SCIF SCSPTR2 0xFFE80020 0x1FE80020 16 0x0000 0x0000 Held Held Pclk
union SCIF_SCSPTR2_type

View File

@ -188,8 +188,6 @@ extern int rtc_schid;
//./core/hw/sh4/modules/serial.o
extern SCIF_SCFSR2_type SCIF_SCFSR2;
extern u8 SCIF_SCFRDR2;
extern SCIF_SCFDR2_type SCIF_SCFDR2;
//./core/hw/sh4/modules/bsc.o
extern BSC_PDTRA_type BSC_PDTRA;
@ -503,8 +501,9 @@ bool dc_serialize(void **data, unsigned int *total_size)
#endif
REICAST_S(SCIF_SCFSR2);
REICAST_S(SCIF_SCFRDR2);
REICAST_S(SCIF_SCFDR2);
bool dum_bool;
REICAST_S(dum_bool);// SCIF_SCFRDR2
REICAST_S(i); // SCIF_SCFDR2
REICAST_S(BSC_PDTRA);
@ -814,8 +813,9 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size)
#endif
REICAST_US(SCIF_SCFSR2);
REICAST_US(SCIF_SCFRDR2);
REICAST_US(SCIF_SCFDR2);
bool dum_bool;
REICAST_US(dum_bool); // SCIF_SCFRDR2
REICAST_US(i); // SCIF_SCFDR2
REICAST_US(BSC_PDTRA);
@ -1175,8 +1175,9 @@ bool dc_unserialize(void **data, unsigned int *total_size)
#endif
REICAST_US(SCIF_SCFSR2);
REICAST_US(SCIF_SCFRDR2);
REICAST_US(SCIF_SCFDR2);
bool dum_bool;
REICAST_US(dum_bool); // SCIF_SCFRDR2
REICAST_US(i); // SCIF_SCFDR2
REICAST_US(BSC_PDTRA);