psxmode: prepare mdec

This commit is contained in:
Robert Neumann 2016-09-23 16:55:19 +02:00 committed by Gregory Hainaut
parent 236c0c78c3
commit f22a8126ed
2 changed files with 83 additions and 43 deletions

View File

@ -18,7 +18,7 @@
/* This code was based on the FPSE v0.08 Mdec decoder*/
#if 0
#include "PrecompiledHeader.h"
#include <stdio.h>
#include <string.h>
@ -26,6 +26,25 @@
#include "IopCommon.h"
#include "Mdec.h"
struct {
u32 command;
u32 status;
u16 *rl;
int rlsize;
} mdec;
struct config_mdec {
u32 Mdec;
};
struct config_mdec Config;
u32 mdecArr2[0x100000] = { 0 };
u32 mdecMem[0x100000]; //watherver large size. //Memory only used to get DMA data and not really for anything else.
//Sould be optimized(the funcs. that use it) to read IOP RAM direcly.
#define PSXM(x) ((uptr)mdecMem + x)
int iq_y[DCTSIZE2],iq_uv[DCTSIZE2];
static void idct1(int *block)
@ -150,7 +169,11 @@ void idct(int *block,int k)
}
void mdecInit(void) {
mdec.rl = (u16*)&psxM[0x100000];
Config.Mdec = 1; //XXXXXXXXXXXXXXXXX 0 or 1
mdec.rl = (u16*)PSXM(0);
//mdec.rl = (u16*)&psxM[0x100000];
mdec.command = 0;
mdec.status = 0;
round_init();
@ -189,21 +212,34 @@ u32 mdecRead1(void) {
void psxDma0(u32 adr, u32 bcr, u32 chcr) {
int cmd = mdec.command;
int size;
MDEC_LOG("DMA0 %lx %lx %lx", adr, bcr, chcr);
if (chcr!=0x01000201) return;
if (chcr != 0x01000201) return;
size = (bcr>>16)*(bcr&0xffff);
if (cmd==0x40000001) {
u8 *p = (u8*)PSXM(adr);
iqtab_init(iq_y,p);
iqtab_init(iq_uv,p+64);
// bcr LSBs are the blocksize in words
// bcr MSBs are the number of block
int size = (bcr >> 16)*(bcr & 0xffff);
if (size < 0) {
// Need to investigate what happen if the transfer is huge
Console.Error("psxDma0 DMA transfer overflow !");
return;
}
else if ((cmd&0xf5ff0000)==0x30000000) {
mdec.rl = (u16*)PSXM(adr);
for (int i = 0; i<(size); i++) {
*(u32*)PSXM(((i + 0) * 4)) = iopMemRead32(adr + ((i + 0) * 4));
if (i <20)
MDEC_LOG(" data %08X %08X ", iopMemRead32((adr & 0x00FFFFFF) + (i * 4)), *(u32*)PSXM((i * 4)));
}
if (cmd == 0x40000001) {
u8 *p = (u8*)PSXM(0); //u8 *p = (u8*)PSXM(adr);
iqtab_init(iq_y, p);
iqtab_init(iq_uv, p + 64);
}
else if ((cmd & 0xf5ff0000) == 0x30000000) {
mdec.rl = (u16*)PSXM(0); //mdec.rl = (u16*)PSXM(adr);
}
HW_DMA0_CHCR &= ~0x01000000;
@ -213,15 +249,22 @@ void psxDma0(u32 adr, u32 bcr, u32 chcr) {
void psxDma1(u32 adr, u32 bcr, u32 chcr) {
int blk[DCTSIZE2*6];
unsigned short *image;
int size;
MDEC_LOG("DMA1 %lx %lx %lx (cmd = %lx)", adr, bcr, chcr, mdec.command);
if (chcr != 0x01000200) return;
// bcr LSBs are the blocksize in words
// bcr MSBs are the number of block
int size = (bcr >> 16)*(bcr & 0xffff);
int size2 = (bcr >> 16)*(bcr & 0xffff);
if (size < 0) {
// Need to investigate what happen if the transfer is huge
Console.Error("psxDma1 DMA transfer overflow !");
return;
}
if (chcr!=0x01000200) return;
image = (u16*)mdecArr2;//(u16*)PSXM(0); //image = (u16*)PSXM(adr);
size = (bcr>>16)*(bcr&0xffff);
image = (u16*)PSXM(adr);
if (mdec.command&0x08000000) {
for (;size>0;size-=(16*16)/2,image+=(16*16)) {
mdec.rl = rl2blk(blk,mdec.rl);
@ -234,6 +277,12 @@ void psxDma1(u32 adr, u32 bcr, u32 chcr) {
}
}
for (int i = 0; i<(size2); i++) {
iopMemWrite32(((adr & 0x00FFFFFF) + (i * 4) + 0), mdecArr2[i]);
if (i <20)
MDEC_LOG(" data %08X %08X ", iopMemRead32((adr & 0x00FFFFFF) + (i * 4)), mdecArr2[i]);
}
HW_DMA1_CHCR &= ~0x01000000;
psxDmaInterrupt(1);
}
@ -407,15 +456,12 @@ void yuv2rgb24(int *blk,unsigned char *image) {
}
}
int SaveState::mdecFreeze() {
Freeze(mdec);
Freeze(iq_y);
Freeze(iq_uv);
return 0;
}
#endif
//todo: psxmode: add mdec savestate support
//int SaveState::mdecFreeze() {
// Freeze(mdec);
// Freeze(iq_y);
// Freeze(iq_uv);
//
// return 0;
//
//}

View File

@ -85,14 +85,15 @@
image[n+1] = ROUND(Y); \
image[n+0] = ROUND(Y);
void mdecInit();
void mdecWrite0(u32 data);
void mdecWrite1(u32 data);
u32 mdecRead0();
u32 mdecRead1();
void psxDma0(u32 madr, u32 bcr, u32 chcr);
void psxDma1(u32 madr, u32 bcr, u32 chcr);
int mdecFreeze(gzFile f, int Mode);
extern void mdecInit();
extern void mdecWrite0(u32 data);
extern void mdecWrite1(u32 data);
extern u32 mdecRead0();
extern u32 mdecRead1();
extern void psxDma0(u32 madr, u32 bcr, u32 chcr);
extern void psxDma1(u32 madr, u32 bcr, u32 chcr);
//int mdecFreeze(gzFile f, int Mode);
u16* rl2blk(int *blk,u16 *mdec_rl);
void iqtab_init(int *iqtab,unsigned char *iq_y);
@ -100,11 +101,4 @@ void round_init(void);
void yuv2rgb24(int *blk,unsigned char *image);
void yuv2rgb15(int *blk,u16 *image);
struct {
u32 command;
u32 status;
u16 *rl;
int rlsize;
} mdec;
#endif /* __MDEC_H__ */