Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/attic/PsxHawk.Core/psx.sio.cpp
2 views
1
/*
2
this file contains the sio subsystem emulation.
3
*/
4
5
#include "psx.h"
6
#include <assert.h>
7
#include <stdio.h>
8
#include <stddef.h>
9
10
11
static u8 getPrescaler(const u32 prescaler_type)
12
{
13
static const u8 prescalers[] = {0,1,16,64};
14
return prescalers[prescaler_type];
15
}
16
17
18
//information in this file is derived from observatoins in mednafen and mame
19
20
void PSX::SioController::Reset()
21
{
22
status.TX_EMPTY = 1;
23
status.TX_RDY = 1;
24
status.RX_RDY = 0;
25
status.OVERRUN = 0;
26
status.IRQ = 0;
27
}
28
29
float PSX::SioController::CalculateBaud()
30
{
31
return (float)PSX_CLOCK / this->baud_reg / getPrescaler(mode.prescaler_type);
32
}
33
34
void PSX::sio_wr(const int size, const u32 addr, const u32 val)
35
{
36
assert(size==2);
37
assert((addr&1)==0);
38
DEBUG_SIO("sio write size %d addr %08X = %08X\n",size,addr,val);
39
const u32 portnum = (addr>>4)&1;
40
SioController &port = sio[portnum];
41
42
switch(addr&0xF)
43
{
44
case 0x00:
45
break;
46
case 0x08:
47
port.mode.value = val;
48
printf("baud set to approx %f\n",port.CalculateBaud());
49
break;
50
case 0x0A:
51
{
52
SioController::ControlReg reg;
53
reg.value = val;
54
if(reg.RESET)
55
{
56
DEBUG_SIO("reset port %d\n",portnum);
57
port.Reset();
58
}
59
if(reg.IACK)
60
{
61
port.status.IRQ = 0;
62
port.control.IACK = 0;
63
//todo - irq sync
64
}
65
66
//check for rising edge of DTR signal and alert the appropriate port
67
if(port.control.DTR == 0 && reg.DTR == 1)
68
{
69
sio_dtr(port.control.PORT_SEL);
70
}
71
72
//replicate stored bits
73
port.control.TX_IENA = reg.RX_IENA;
74
port.control.RX_IENA = reg.RX_IENA;
75
port.control.DSR_IENA = reg.DSR_IENA;
76
port.control.DTR = reg.DTR;
77
port.control.PORT_SEL = reg.PORT_SEL;
78
}
79
break;
80
case 0x0E:
81
port.baud_reg = val;
82
printf("baud set to approx %f\n",port.CalculateBaud());
83
break;
84
default:
85
DEBUG_SIO("UNHANDLED\n");
86
}
87
}
88
89
void PSX::sio_dtr(const u32 port)
90
{
91
}
92
93
u32 PSX::sio_rd(const int size, const u32 addr)
94
{
95
assert(size==2);
96
assert((addr&1)==0);
97
u32 ret = 0;
98
DEBUG_SIO("sio read size %d addr %08X = %08X\n",size,addr,ret);
99
const u32 port = (addr>>4)&1;
100
101
return 0;
102
}
103
104