Skip to content

Commit

Permalink
picotcp: fix kos ppp nego. modem,bba: fix kos detection
Browse files Browse the repository at this point in the history
picotcp: ignore conf ack received when lcp layer is up (kos ppp)
picotcp: ignore icmp ping seq and id #
scheduler: add void * arg to callback function. Get rid of static instances when possible
bba: use scheduler to delay link changes (fixes kos bba detection)
modem: fix soft reset. don't reset TDBE during reset (fixes kos modem detection)
  • Loading branch information
flyinghead committed Jun 23, 2023
1 parent 8b8113b commit aad4921
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 45 deletions.
3 changes: 2 additions & 1 deletion core/deps/picotcp/modules/pico_dev_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,8 @@ static const struct pico_ppp_fsm ppp_lcp_fsm[PPP_LCP_STATE_MAX][PPP_LCP_EVENT_MA
{ lcp_this_layer_down, lcp_send_terminate_request, lcp_send_configure_ack }},
[PPP_LCP_EVENT_RCR_NEG] = { PPP_LCP_STATE_REQ_SENT,
{ lcp_this_layer_down, lcp_send_configure_request, lcp_send_configure_nack }},
[PPP_LCP_EVENT_RCA] = { PPP_LCP_STATE_REQ_SENT, { lcp_this_layer_down, lcp_send_terminate_request } },
/* ignore conf acks received after auth/ipcp layer is up (kos) */
[PPP_LCP_EVENT_RCA] = { PPP_LCP_STATE_OPENED },
[PPP_LCP_EVENT_RCN] = { PPP_LCP_STATE_REQ_SENT, { lcp_this_layer_down, lcp_send_terminate_request } },
[PPP_LCP_EVENT_RTR] = { PPP_LCP_STATE_STOPPING, { lcp_this_layer_down, lcp_zero_restart_count, lcp_send_terminate_ack} },
[PPP_LCP_EVENT_RTA] = { PPP_LCP_STATE_REQ_SENT, { lcp_this_layer_down, lcp_send_terminate_request} },
Expand Down
4 changes: 3 additions & 1 deletion core/deps/picotcp/modules/pico_icmp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ static int pico_icmp4_process_in(struct pico_protocol *self, struct pico_frame *
if (f->dev && f->dev->eth)
f->len -= PICO_SIZE_ETHHDR;

/* Dreamcast doesn't increment sequence and id numbers
if (!firstpkt && (hdr->hun.ih_idseq.idseq_id == last_id) && (last_seq == hdr->hun.ih_idseq.idseq_seq)) {
/* The network duplicated the echo. Do not reply. */
/* The network duplicated the echo. Do not reply. * /
pico_frame_discard(f);
return 0;
}
*/

firstpkt = 0;
last_id = hdr->hun.ih_idseq.idseq_id;
Expand Down
2 changes: 1 addition & 1 deletion core/hw/aica/aica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ AicaTimer timers[3];
int aica_schid = -1;
const int AICA_TICK = 145125; // 44.1 KHz / 32

static int AicaUpdate(int tag, int c, int j)
static int AicaUpdate(int tag, int cycles, int jitter, void *arg)
{
arm::run(32);

Expand Down
6 changes: 3 additions & 3 deletions core/hw/aica/aica_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ template void writeAicaReg<>(u32 addr, u8 data);
template void writeAicaReg<>(u32 addr, u16 data);
template void writeAicaReg<>(u32 addr, u32 data);

static int DreamcastSecond(int tag, int c, int j)
static int DreamcastSecond(int tag, int cycles, int jitter, void *arg)
{
RealTimeClock++;

Expand Down Expand Up @@ -220,7 +220,7 @@ void termRtc()
rtc_schid = -1;
}

static int dma_end_sched(int tag, int cycl, int jitt)
static int dma_end_sched(int tag, int cycles, int jitter, void *arg)
{
u32 len = SB_ADLEN & 0x7FFFFFFF;

Expand Down Expand Up @@ -405,7 +405,7 @@ static void Write_SB_ADST(u32 addr, u32 data)
// Schedule the end of DMA transfer interrupt
int cycles = len * (SH4_MAIN_CLOCK / 2 / G2_BUS_CLOCK); // 16 bits @ 25 MHz
if (cycles <= 512)
dma_end_sched(0, 0, 0);
dma_end_sched(0, 0, 0, nullptr);
else
sh4_sched_request(dma_sched_id, cycles);
}
Expand Down
21 changes: 21 additions & 0 deletions core/hw/bba/rtl8139c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <zlib.h>
#include "rtl8139c.h"
#include "serialize.h"
#include "hw/sh4/sh4_sched.h"

/* debug RTL8139 card */
//#define DEBUG_RTL8139 1
Expand Down Expand Up @@ -444,6 +445,8 @@ struct RTL8139State {

MemoryRegion bar_io;
MemoryRegion bar_mem;

int schedId;
};

static void rtl8139_set_next_tctr_time(RTL8139State *s);
Expand Down Expand Up @@ -899,6 +902,8 @@ static void rtl8139_reset_phy(RTL8139State *s)
s->NWayExpansion = 0x0001; /* autonegotiation supported */

s->CSCR = CSCR_F_LINK_100 | CSCR_HEART_BIT | CSCR_LD;

sh4_sched_request(s->schedId, 2000000); /* 10 ms */
}

void rtl8139_reset(RTL8139State *s)
Expand Down Expand Up @@ -2263,6 +2268,15 @@ static void rtl8139_timer(void *opaque)
}
#endif

static int rtl8139_sched_callback(int tag, int cycles, int jitter, void *arg)
{
RTL8139State *state = (RTL8139State *)arg;
state->IntrStatus |= RxUnderrun; // Link change
rtl8139_update_irq(state);

return 0;
}

static void pci_rtl8139_uninit(PCIDevice *dev)
{
#ifdef RTL8139_TIMER
Expand Down Expand Up @@ -2315,13 +2329,15 @@ RTL8139State *rtl8139_init(NICConf *conf)
state->parent_obj.config = (uint8_t *)calloc(256, 1);
state->parent_obj.wmask = (uint8_t *)calloc(256, 1);
state->parent_obj.cmask = (uint8_t *)calloc(256, 1);
state->schedId = sh4_sched_register(0, rtl8139_sched_callback, state);

return state;
}

void rtl8139_destroy(RTL8139State *state)
{
pci_rtl8139_uninit(PCI_DEVICE(state));
sh4_sched_unregister(state->schedId);
free(state->parent_obj.config);
free(state->parent_obj.wmask);
free(state->parent_obj.cmask);
Expand Down Expand Up @@ -2390,6 +2406,8 @@ void rtl8139_serialize(RTL8139State *s, Serializer& ser)
ser << s->TCTR;
ser << s->TimerInt;
ser << s->TCTR_base;

sh4_sched_serialize(ser, s->schedId);
}

bool rtl8139_deserialize(RTL8139State *s, Deserializer& deser)
Expand Down Expand Up @@ -2455,5 +2473,8 @@ bool rtl8139_deserialize(RTL8139State *s, Deserializer& deser)
deser >> s->TimerInt;
deser >> s->TCTR_base;

if (deser.version() >= Deserializer::V38)
sh4_sched_deserialize(deser, s->schedId);

return s->bChipCmdState & CmdRxEnb;
}
4 changes: 2 additions & 2 deletions core/hw/gdrom/gdromv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ static int getGDROMTicks()
}

//is this needed ?
static int GDRomschd(int i, int c, int j)
static int GDRomschd(int tag, int cycles, int jitter, void *arg)
{
if (SecNumber.Status == GD_SEEK)
{
Expand Down Expand Up @@ -1275,7 +1275,7 @@ static void GDROM_DmaStart(u32 addr, u32 data)
int ticks = getGDROMTicks();
if (ticks < SH4_TIMESLICE)
{
ticks = GDRomschd(0,0,0);
ticks = GDRomschd(0, 0, 0, nullptr);
}

if (ticks)
Expand Down
2 changes: 1 addition & 1 deletion core/hw/maple/maple_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static void maple_DoDma()
sh4_sched_request(maple_schid, std::min((u64)xfer_count * (SH4_MAIN_CLOCK / (256 * 1024)), (u64)SH4_MAIN_CLOCK));
}

static int maple_schd(int tag, int c, int j)
static int maple_schd(int tag, int cycles, int jitter, void *arg)
{
if (SB_MDEN & 1)
{
Expand Down
15 changes: 8 additions & 7 deletions core/hw/modem/modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static FILE *recv_fp;
static FILE *sent_fp;
#endif

static int modem_sched_func(int tag, int cycles, int jitter)
static int modem_sched_func(int tag, int cycles, int jitter, void *arg)
{
#ifndef NDEBUG
if (os_GetSeconds() - last_comm_stats >= 2)
Expand Down Expand Up @@ -626,7 +626,10 @@ static void ModemNormalWrite(u32 reg, u32 data)
{
modem_regs.reg1a.SFRES = 0;
LOG("Soft Reset SET && NEWC, executing reset and init");
modem_reset(0);
modem_reset(1);
modem_regs.reg1f.NEWC = 1;
modem_regs.ptr[0x20] = 0;
}
else
{
Expand Down Expand Up @@ -702,15 +705,13 @@ u32 ModemReadMem_A0_006(u32 addr, u32 size)

case MS_ST_CONTROLER:
case MS_ST_DSP:
if (reg==0x10)
{
modem_regs.reg1e.TDBE=0;
case MS_END_DSP:
if (reg == 0x10)
// don't reset TBDE to help kos modem self test
//modem_regs.reg1e.TDBE = 0;
return 0;
}
else
{
return modem_regs.ptr[reg];
}

case MS_RESETING:
return 0; //still reset
Expand Down
2 changes: 1 addition & 1 deletion core/hw/naomi/multiboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static Multiboard *multiboard;

constexpr int SyncCycles = 500000;

static int schedCallback(int tag, int cycles, int jitter)
static int schedCallback(int tag, int cycles, int jitter, void *arg)
{
multiboard->syncWait();
return SyncCycles;
Expand Down
10 changes: 3 additions & 7 deletions core/hw/naomi/netdimm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@

const char *SERVER_NAME = "vfnet.duckdns.org";

NetDimm *NetDimm::Instance;

NetDimm::NetDimm(u32 size) : GDCartridge(size)
{
schedId = sh4_sched_register(0, schedCallback);
Instance = this;
schedId = sh4_sched_register(0, schedCallback, this);
if (serverIp == 0)
{
hostent *hp = gethostbyname(SERVER_NAME);
Expand All @@ -50,7 +47,6 @@ NetDimm::NetDimm(u32 size) : GDCartridge(size)
NetDimm::~NetDimm()
{
sh4_sched_unregister(schedId);
Instance = nullptr;
}

void NetDimm::Init(LoadProgress *progress, std::vector<u8> *digest)
Expand Down Expand Up @@ -141,9 +137,9 @@ bool NetDimm::Write(u32 offset, u32 size, u32 data)
return true;
}

int NetDimm::schedCallback(int tag, int sch_cycl, int jitter)
int NetDimm::schedCallback(int tag, int sch_cycl, int jitter, void *arg)
{
return Instance->schedCallback();
return ((NetDimm *)arg)->schedCallback();
}

int NetDimm::schedCallback()
Expand Down
2 changes: 1 addition & 1 deletion core/hw/naomi/netdimm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NetDimm : public GDCartridge

private:
void returnToNaomi(bool failed, u16 offsetl, u32 parameter);
static int schedCallback(int tag, int sch_cycl, int jitter);
static int schedCallback(int tag, int sch_cycl, int jitter, void *arg);
int schedCallback();
void process();
void systemCmd(int cmd);
Expand Down
15 changes: 6 additions & 9 deletions core/hw/naomi/touchscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ class TouchscreenPipe final : public SerialPipe
public:
TouchscreenPipe()
{
Instance = this;
schedId = sh4_sched_register(0, schedCallback);
schedId = sh4_sched_register(0, schedCallback, this);
serial_setPipe(this);
}

~TouchscreenPipe()
{
sh4_sched_unregister(schedId);
Instance = nullptr;
}

void write(u8 data) override
Expand Down Expand Up @@ -114,8 +112,9 @@ class TouchscreenPipe final : public SerialPipe
return 256 - c;
}

static int schedCallback(int tag, int cycles, int lag)
static int schedCallback(int tag, int cycles, int jitter, void *arg)
{
TouchscreenPipe *instance = (TouchscreenPipe *)arg;
u32 pack[2];
for (size_t i = 0; i < std::size(pack); i++)
{
Expand All @@ -127,14 +126,14 @@ class TouchscreenPipe final : public SerialPipe
// drag needs bit 22 off
// bit 23 is charge
pack[i] = (charge << 23) | (hit << 21) | (hit << 20) | (y << 10) | x;
if (!Instance->touch[i])
if (!instance->touch[i])
pack[i] |= hit << 22;
Instance->touch[i] = hit;
instance->touch[i] = hit;
}
u8 msg[] = { 0xaa, 0x10,
u8(pack[0] >> 16), u8(pack[0] >> 8), u8(pack[0]),
u8(pack[1] >> 16), u8(pack[1] >> 8), u8(pack[1]) };
Instance->send(msg, sizeof(msg));
instance->send(msg, sizeof(msg));

return FRAME_CYCLES;
}
Expand All @@ -144,10 +143,8 @@ class TouchscreenPipe final : public SerialPipe
bool schedulerStarted = false;
bool touch[2] {};

static TouchscreenPipe *Instance;
static constexpr int FRAME_CYCLES = SH4_MAIN_CLOCK / 60;
};
TouchscreenPipe *TouchscreenPipe::Instance;

std::unique_ptr<TouchscreenPipe> touchscreen;

Expand Down
2 changes: 1 addition & 1 deletion core/hw/pvr/Renderer_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void rend_start_render()
}
}

int rend_end_render(int tag, int cycles, int jitter)
int rend_end_render(int tag, int cycles, int jitter, void *arg)
{
if (settings.platform.isNaomi2())
{
Expand Down
2 changes: 1 addition & 1 deletion core/hw/pvr/Renderer_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool rend_init_renderer();
void rend_term_renderer();
void rend_vblank();
void rend_start_render();
int rend_end_render(int tag, int cycles, int jitter);
int rend_end_render(int tag, int cycles, int jitter, void *arg);
void rend_cancel_emu_wait();
bool rend_single_frame(const bool& enabled);
void rend_swap_frame(u32 fb_r_sof1);
Expand Down
2 changes: 1 addition & 1 deletion core/hw/pvr/spg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void rescheduleSPG()
sh4_sched_request(vblank_schid, getNextSpgInterrupt());
}

static int spg_line_sched(int tag, int cycles, int jitter)
static int spg_line_sched(int tag, int cycles, int jitter, void *arg)
{
clc_pvr_scanline += cycles + jitter;

Expand Down
2 changes: 1 addition & 1 deletion core/hw/sh4/modules/tmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void write_TMU_TSTR(u32 addr, u8 data)
turn_on_off_ch(i, data & (1 << i));
}

static int sched_tmu_cb(int ch, int sch_cycl, int jitter)
static int sched_tmu_cb(int ch, int sch_cycl, int jitter, void *arg)
{
if (tmu_mask[ch]) {

Expand Down
7 changes: 4 additions & 3 deletions core/hw/sh4/sh4_sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
struct sched_list
{
sh4_sched_callback* cb;
void *arg;
int tag;
int start;
int end;
Expand Down Expand Up @@ -70,9 +71,9 @@ void sh4_sched_ffts()
sh4_sched_ffb += Sh4cntx.sh4_sched_next;
}

int sh4_sched_register(int tag, sh4_sched_callback* ssc)
int sh4_sched_register(int tag, sh4_sched_callback* ssc, void *arg)
{
sched_list t{ ssc, tag, -1, -1};
sched_list t{ ssc, arg, tag, -1, -1};
for (sched_list& sched : sch_list)
if (sched.cb == nullptr)
{
Expand Down Expand Up @@ -157,7 +158,7 @@ static void handle_cb(sched_list& sched)
int jitter = elapsd - remain;

sched.end = -1;
int re_sch = sched.cb(sched.tag, remain, jitter);
int re_sch = sched.cb(sched.tag, remain, jitter, sched.arg);

if (re_sch > 0)
sh4_sched_request(&sched - &sch_list[0], std::max(0, re_sch - jitter));
Expand Down
4 changes: 2 additions & 2 deletions core/hw/sh4/sh4_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
sch_cycles, the cycle duration that the callback requested (sh4_sched_request)
jitter, the number of cycles that the callback was delayed, [0... 448]
*/
typedef int sh4_sched_callback(int tag, int sch_cycl, int jitter);
typedef int sh4_sched_callback(int tag, int sch_cycl, int jitter, void *arg);

/*
Register a callback to the scheduler. The returned id
is used for sh4_sched_request and sh4_sched_unregister calls
*/
int sh4_sched_register(int tag, sh4_sched_callback* ssc);
int sh4_sched_register(int tag, sh4_sched_callback* ssc, void *arg = nullptr);

/***
* Unregister a callback from the scheduler.
Expand Down
Loading

0 comments on commit aad4921

Please sign in to comment.