Skip to content

Commit

Permalink
- Match libOGC's R1 timeout.
Browse files Browse the repository at this point in the history
- Minor optimizations.
  • Loading branch information
Extrems committed Nov 9, 2019
1 parent 14fe93c commit f413d75
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
11 changes: 5 additions & 6 deletions cube/patches/alt/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void di_complete_transfer(void)
uint32_t address = (*DI_EMU)[5] + OS_BASE_CACHED;
uint32_t length = (*DI_EMU)[6];

disable_breakpoint();

(*DI_EMU)[0] |= 0b0010000;
(*DI_EMU)[7] &= ~0b001;

Expand All @@ -52,6 +54,7 @@ static void di_execute_command(void)
uint32_t address = (*DI_EMU)[5] + OS_BASE_CACHED;

perform_read(offset, length, address);
enable_breakpoint();
} else {
(*DI_EMU)[0] |= 0b0000100;
(*DI_EMU)[7] &= ~0b001;
Expand Down Expand Up @@ -191,15 +194,11 @@ static bool ppc_step(OSContext *context)

OSContext *exception_handler(OSException exception, OSContext *context, uint32_t dsisr, uint32_t dar)
{
uint32_t dabr;

switch (exception) {
case OS_EXCEPTION_DSI:
{
if ((dsisr & 0x400000) == 0x400000) {
asm volatile("mfdabr %0" : "=r" (dabr));
asm volatile("mtdabr %0" :: "r" (dabr & ~0b011));

disable_breakpoint();
trickle_read();
context->srr1 |= 0x400;
break;
Expand Down Expand Up @@ -258,7 +257,7 @@ OSInterruptHandler set_di_handler(OSInterrupt interrupt, OSInterruptHandler hand
DVDCommandBlock *set_breakpoint(DVDCommandBlock *block)
{
uint32_t dabr = (uint32_t)&block->state & ~0b111;
asm volatile("mtdabr %0" :: "r" (dabr | 0b101));
asm volatile("mtdabr %0" :: "r" (dabr | 0b100));
return block;
}

Expand Down
14 changes: 14 additions & 0 deletions cube/patches/base/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ typedef volatile f64 vf64;
asm volatile ("mtmsr %0" :: "r" (msr)); \
})

#define disable_breakpoint() ({ \
unsigned long dabr; \
asm volatile ("mfdabr %0" : "=r" (dabr)); \
asm volatile ("clrrwi %0,%0,2" : "+r" (dabr)); \
asm volatile ("mtdabr %0" :: "r" (dabr)); \
})

#define enable_breakpoint() ({ \
unsigned long dabr; \
asm volatile ("mfdabr %0" : "=r" (dabr)); \
asm volatile ("ori %0,%0,1" : "+r" (dabr)); \
asm volatile ("mtdabr %0" :: "r" (dabr)); \
})

#define mftb(rval) ({unsigned long u; do { \
asm volatile ("mftbu %0" : "=r" (u)); \
asm volatile ("mftb %0" : "=r" ((rval)->l)); \
Expand Down
7 changes: 3 additions & 4 deletions cube/patches/bba/bba.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,9 @@ void perform_read(uint32_t offset, uint32_t length, uint32_t address)
*_position = offset;
*_remainder = length;
*_data = (void *)address;
*_data_size = 0;

if (!is_frag_read(offset, length))
fsp_output(_file, *_filelen, offset, length);
fsp_get_file(offset, length);
}

void trickle_read(void)
Expand All @@ -290,13 +289,13 @@ void trickle_read(void)

if (!remainder) di_complete_transfer();
else if (!is_frag_read(position, remainder))
fsp_output(_file, *_filelen, position, remainder);
fsp_get_file(position, remainder);
} else {
tb_t end;
mftb(&end);

if (tb_diff_usec(&end, _start) > 1000000)
fsp_output(_file, *_filelen, position, remainder);
fsp_get_file(position, remainder);
}
}
}
7 changes: 5 additions & 2 deletions cube/patches/bba/tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ static uint8_t fsp_checksum(fsp_header_t *header, size_t size)
return sum;
}

static void fsp_output(const char *file, uint8_t filelen, uint32_t offset, size_t size)
static void fsp_get_file(uint32_t offset, size_t size)
{
const char *file = _file;
uint8_t filelen = *_filelen;

uint8_t data[MIN_FRAME_SIZE + filelen];
eth_header_t *eth = (eth_header_t *)data;
ipv4_header_t *ipv4 = (ipv4_header_t *)eth->data;
Expand Down Expand Up @@ -258,7 +261,7 @@ static void udp_input(bba_page_t page, eth_header_t *eth, ipv4_header_t *ipv4, u
*_data = data + data_size;
*_data_size = 0;

if (remainder) fsp_output(_file, *_filelen, position, remainder);
if (remainder) fsp_get_file(position, remainder);
}

if (!*_received)
Expand Down
6 changes: 2 additions & 4 deletions cube/patches/sdgecko/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ static void send_cmd(u32 cmd, u32 sector) {
exi_imm_write(1<<24, 1);
if (cmd == CMD12) rcvr_spi();

int timeout = 10;
while((rcvr_spi() & 0x80) && timeout) {
timeout--;
}
int timeout = 16;
while((rcvr_spi() & 0x80) && --timeout);
}

static void exi_read_to_buffer(void *dest, u32 len) {
Expand Down

0 comments on commit f413d75

Please sign in to comment.