Skip to content

Commit

Permalink
- Move some patches code to common.h and fix GCC 6.2 issues (need -O1…
Browse files Browse the repository at this point in the history
… now to avoid issues)
  • Loading branch information
emukidid committed Dec 19, 2016
1 parent 5ae1fda commit 316dc10
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 118 deletions.
90 changes: 45 additions & 45 deletions cube/patches/Makefile
Expand Up @@ -25,16 +25,16 @@ clean:

build-sd:
@echo Building SD Patch ...
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c sdgecko/sd.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c sdgecko/sd.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/Stream.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr_start.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr.c
@$(LD) -o sd.elf base.o igr.o frag.o sd.o dvdinterface.o dvdqueue.o usbgecko.o adp.o Stream.o __DSPHandler.o appldr_start.o appldr.o --section-start .text=0x80001000 --gc-sections
Expand All @@ -48,16 +48,16 @@ build-sd:

build-ideexi-v1:
@echo Building IDE-EXI-v1 Patch ...
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c ide-exi/hddread.c -DIDE_EXI_V1
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c ide-exi/hddread.c -DIDE_EXI_V1
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/Stream.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr_start.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr.c
@$(LD) -o ideexi_v1.elf base.o igr.o frag.o hddread.o dvdinterface.o dvdqueue.o usbgecko.o adp.o Stream.o __DSPHandler.o appldr_start.o appldr.o --section-start .text=0x80001000 -gc-sections
Expand All @@ -71,16 +71,16 @@ build-ideexi-v1:

build-ideexi-v2:
@echo Building IDE-EXI-v2 Patch ...
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c ide-exi/hddread.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c ide-exi/hddread.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/Stream.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr_start.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr.c
@$(LD) -o ideexi_v2.elf base.o igr.o frag.o hddread.o dvdinterface.o dvdqueue.o usbgecko.o adp.o Stream.o __DSPHandler.o appldr_start.o appldr.o --section-start .text=0x80001000 -gc-sections
Expand All @@ -94,13 +94,13 @@ build-ideexi-v2:

build-dvd:
@echo Building DVD Patch ...
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c dvd/base.S
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c dvd/dvd.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c sdgecko/sd.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c dvd/base.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c dvd/dvd.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c sdgecko/sd.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/usbgecko.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(LD) -o dvd.elf base.o igr.o frag.o sd.o dvd.o dvdqueue.o usbgecko.o --section-start .text=0x80001800
@rm -rf *.o
@$(OBJDUMP) -D dvd.elf > $(DISASM)/dvd_disasm.txt
Expand All @@ -112,17 +112,17 @@ build-dvd:

build-usb:
@echo Building USBGecko Patch ...
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c usbgecko/usbgecko.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/base.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c usbgecko/usbgecko.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdqueue.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/dvdinterface.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/adp.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/Stream.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/__DSPHandler.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr_start.S
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/appldr.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O2 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/frag.c
@$(CC) -O1 -ffunction-sections -mmultiple -mstring -c base/igr.c
@$(LD) -o usbgecko.elf base.o igr.o usbgecko.o dvdqueue.o dvdinterface.o adp.o Stream.o __DSPHandler.o appldr_start.o appldr.o frag.o --section-start .text=0x80001000 --gc-sections
@rm -rf *.o
@$(OBJDUMP) -D usbgecko.elf > $(DISASM)/usb_disasm.txt
Expand All @@ -134,9 +134,9 @@ build-usb:

build-wkf:
@echo Building WKF Patch ...
@$(CC) -O2 -c wkf/base.S
@$(CC) -O2 -c wkf/wkf.c
@$(CC) -O2 -c base/usbgecko.c
@$(CC) -O1 -c wkf/base.S
@$(CC) -O1 -c wkf/wkf.c
@$(CC) -O1 -c base/usbgecko.c
@$(LD) -o wkf.elf base.o wkf.o usbgecko.o --section-start .text=0x80001800
@rm -rf *.o
@$(OBJDUMP) -D wkf.elf > $(DISASM)/wkf_disasm.txt
Expand Down
11 changes: 3 additions & 8 deletions cube/patches/base/Stream.c
Expand Up @@ -19,16 +19,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "../../reservedarea.h"

typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef signed short s16;
#include "common.h"

#define ONE_BLOCK_SIZE 32
#define SAMPLES_PER_BLOCK 28

void device_frag_read(void *dst, u32 len, u32 offset);
void WritePCM48to32(u32 *buf_loc);
void WritePCM48(u32 *buf_loc);

Expand Down Expand Up @@ -66,7 +61,7 @@ void StreamUpdate()
u32 r32k = ((*(u32*)(AI_CR)) & AI_32K);
for(i = 0; i < (r32k ? CHUNK_48to32 : CHUNK_48); i += ONE_BLOCK_SIZE)
{
ADPdecodebuffer((u8*)DECODE_WORK_AREA+i,(s16*)VAR_AS_OUTL,(s16*)VAR_AS_OUTR,(u32*)VAR_AS_HIST_0,(u32*)VAR_AS_HIST_1,(u32*)VAR_AS_HIST_2,(u32*)VAR_AS_HIST_3);
ADPdecodebuffer((u8*)DECODE_WORK_AREA+i,(s16*)VAR_AS_OUTL,(s16*)VAR_AS_OUTR,(long*)VAR_AS_HIST_0,(long*)VAR_AS_HIST_1,(long*)VAR_AS_HIST_2,(long*)VAR_AS_HIST_3);
if(r32k) WritePCM48to32(&buf_loc); else WritePCM48(&buf_loc);
}
*(u8*)VAR_STREAM_CURBUF = *(u8*)VAR_STREAM_CURBUF ^ 1;
Expand Down Expand Up @@ -168,7 +163,7 @@ void StreamStartStream(u32 CurrentStart, u32 CurrentSize)
*(u8*)VAR_STREAM_LOOPING = 0;
}

void StreamEndStream()
void StreamEndStream(void)
{
*(u32*)VAR_STREAM_CUR = 0;
}
6 changes: 1 addition & 5 deletions cube/patches/base/appldr.c
Expand Up @@ -3,12 +3,8 @@ appldr.c for Swiss
Copyright (C) 2015 FIX94
*/
#include "../../reservedarea.h"
#include "common.h"

typedef volatile unsigned int vu32;
typedef unsigned int u32;
typedef int s32;
typedef unsigned short u16;
typedef unsigned char u8;

typedef int (*app_main)(char **dst, u32 *size, u32 *offset);
typedef void (*app_init)(int (*report)(const char *fmt, ...),u32 args);
Expand Down
34 changes: 34 additions & 0 deletions cube/patches/base/common.h
@@ -0,0 +1,34 @@
#ifndef _COMMON_H_

typedef volatile unsigned int vu32;
typedef unsigned int u32;
typedef int s32;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned char u8;

#define mftb(rval) ({unsigned long u; do { \
asm volatile ("mftbu %0" : "=r" (u)); \
asm volatile ("mftb %0" : "=r" ((rval)->l)); \
asm volatile ("mftbu %0" : "=r" ((rval)->u)); \
} while(u != ((rval)->u)); })

typedef struct {
unsigned long l, u;
} tb_t;

#define TB_CLOCK 40500000

void do_read(void* dst, u32 len, u32 offset, u32 sector);
void device_frag_read(void* dst, u32 len, u32 offset);
void dcache_flush_icache_inv(void* dst, u32 len);
int ADPdecodebuffer(unsigned char *input, short *outl, short * outr, long *histl1, long *histl2, long *histr1, long *histr2);
void StreamStartStream(u32 CurrentStart, u32 CurrentSize);
void StreamEndStream(void);
u32 process_queue(void* dst, u32 len, u32 offset, int readComplete);
unsigned long tb_diff_usec(tb_t* end, tb_t* start);

int usb_sendbuffer_safe(const void *buffer,int size);


#endif
24 changes: 4 additions & 20 deletions cube/patches/base/dvdinterface.c
Expand Up @@ -5,6 +5,7 @@
***************************************************************************/

#include "../../reservedarea.h"
#include "common.h"

#define DI_SR (0)
#define DI_CVR (1)
Expand All @@ -19,23 +20,6 @@

#define AGGRESSIVE_INT 1

typedef struct {
unsigned long l, u;
} tb_t;

#define mftb(rval) ({unsigned long u; do { \
asm volatile ("mftbu %0" : "=r" (u)); \
asm volatile ("mftb %0" : "=r" ((rval)->l)); \
asm volatile ("mftbu %0" : "=r" ((rval)->u)); \
} while(u != ((rval)->u)); })

//int usb_sendbuffer_safe(const void *buffer,int size);

typedef unsigned int u32;
typedef int s32;
typedef unsigned short u16;
typedef unsigned char u8;

void trigger_dvd_interrupt() {
volatile u32* realDVD = (volatile u32*)0xCC006000;
if(!(realDVD[7]&1))
Expand Down Expand Up @@ -179,16 +163,16 @@ void DIUpdateRegisters() {
{
//execD, jump to our own handler
*(u32*)dst = branch((u32)appldr_start, dst);
dcache_flush_icache_inv(dst, 0x20);
dcache_flush_icache_inv((void*)dst, 0x20);
dvd[DI_DMALEN] = 0;
diOpCompleted = 1;
}
else
{
// Read. We might not do the full read, depends how busy the game is
u32 amountRead = process_queue(dst, len, offset, readComplete);
u32 amountRead = process_queue((void*)dst, len, offset, readComplete);
if(amountRead) {
dcache_flush_icache_inv(dst, amountRead);
dcache_flush_icache_inv((void*)dst, amountRead);
dvd[DI_DMALEN] -= amountRead;
dvd[DI_DMAADDR] += amountRead;
dvd[DI_LBA] += amountRead>>2;
Expand Down
10 changes: 2 additions & 8 deletions cube/patches/base/dvdqueue.c
Expand Up @@ -5,19 +5,13 @@
***************************************************************************/

#include "../../reservedarea.h"

int usb_sendbuffer_safe(const void *buffer,int size);

typedef unsigned int u32;
typedef int s32;
typedef unsigned short u16;
typedef unsigned char u8;
#include "common.h"

#define SAMPLE_SIZE_32KHZ_1MS 128
#define SAMPLE_SIZE_32KHZ_1MS_SHIFT 7

// Returns how much was read.
u32 process_queue(u32 dst, u32 len, u32 offset, int readComplete) {
u32 process_queue(void* dst, u32 len, u32 offset, int readComplete) {

if(len) {
// read a bit
Expand Down
18 changes: 1 addition & 17 deletions cube/patches/base/frag.c
Expand Up @@ -7,12 +7,7 @@
*/

#include "../../reservedarea.h"

typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;

extern void do_read(void*, u32, u32, u32);
#include "common.h"

// Returns the amount read from the given offset until a frag is hit
u32 read_frag(void *dst, u32 len, u32 offset) {
Expand Down Expand Up @@ -61,17 +56,6 @@ void device_frag_read(void *dst, u32 len, u32 offset)
}
}

#define mftb(rval) ({unsigned long u; do { \
asm volatile ("mftbu %0" : "=r" (u)); \
asm volatile ("mftb %0" : "=r" ((rval)->l)); \
asm volatile ("mftbu %0" : "=r" ((rval)->u)); \
} while(u != ((rval)->u)); })

typedef struct {
unsigned long l, u;
} tb_t;

#define TB_CLOCK 40500000
unsigned long tb_diff_usec(tb_t* end, tb_t* start)
{
unsigned long upper, lower;
Expand Down

0 comments on commit 316dc10

Please sign in to comment.