2008-12-11 18:38:29 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* ogc_video.c
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* Genesis Plus GX video support
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* code by Softdev (2006), Eke-Eke (2007,2008)
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "gcaram.h"
|
2008-10-02 22:22:53 +02:00
|
|
|
#include "md_ntsc.h"
|
|
|
|
#include "sms_ntsc.h"
|
|
|
|
|
2008-12-12 16:38:04 +01:00
|
|
|
#define TEX_WIDTH 720
|
2008-08-07 14:26:07 +02:00
|
|
|
#define TEX_HEIGHT 576
|
2008-12-12 16:38:04 +01:00
|
|
|
#define TEX_SIZE (TEX_WIDTH * TEX_HEIGHT * 2)
|
2008-08-07 14:26:07 +02:00
|
|
|
#define DEFAULT_FIFO_SIZE 256 * 1024
|
|
|
|
#define HASPECT 320
|
|
|
|
#define VASPECT 240
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/*** VI ***/
|
|
|
|
unsigned int *xfb[2]; /* External Framebuffers */
|
|
|
|
int whichfb = 0; /* Current Framebuffer */
|
|
|
|
GXRModeObj *vmode; /* Default Video Mode */
|
|
|
|
u8 *texturemem; /* Texture Data */
|
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
/* 50/60hz flag */
|
|
|
|
u8 gc_pal = 0;
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/*** NTSC Filters ***/
|
|
|
|
sms_ntsc_t sms_ntsc;
|
|
|
|
md_ntsc_t md_ntsc;
|
|
|
|
static sms_ntsc_setup_t sms_setup;
|
|
|
|
static md_ntsc_setup_t md_setup;
|
|
|
|
|
|
|
|
/*** GX FIFO ***/
|
2008-08-07 14:26:07 +02:00
|
|
|
static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32);
|
|
|
|
|
2009-01-06 18:15:28 +01:00
|
|
|
/*** custom Video modes ***/
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj *rmode;
|
2009-01-06 18:15:28 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* 288 lines progressive (PAL 50Hz) */
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj TV50hz_288p =
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
VI_TVMODE_PAL_DS, // viDisplayMode
|
|
|
|
640, // fbWidth
|
|
|
|
286, // efbHeight
|
|
|
|
286, // xfbHeight
|
|
|
|
0, // viXOrigin
|
|
|
|
(VI_MAX_HEIGHT_PAL - 572)/2, // viYOrigin
|
|
|
|
VI_MAX_WIDTH_PAL, // viWidth
|
|
|
|
572, // viHeight
|
|
|
|
VI_XFBMODE_SF, // xFBmode
|
|
|
|
GX_FALSE, // field_rendering
|
|
|
|
GX_FALSE, // aa
|
|
|
|
|
|
|
|
// sample points arranged in increasing Y order
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
|
|
|
{6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each
|
|
|
|
{6,6},{6,6},{6,6}, // pix 1
|
|
|
|
{6,6},{6,6},{6,6}, // pix 2
|
|
|
|
{6,6},{6,6},{6,6} // pix 3
|
|
|
|
},
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
// vertical filter[7], 1/64 units, 6 bits each
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
0, // line n-1
|
|
|
|
0, // line n-1
|
|
|
|
21, // line n
|
|
|
|
22, // line n
|
|
|
|
21, // line n
|
|
|
|
0, // line n+1
|
|
|
|
0 // line n+1
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 288 lines interlaced (PAL 50Hz) */
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj TV50hz_288i =
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
VI_TVMODE_PAL_INT, // viDisplayMode
|
|
|
|
640, // fbWidth
|
|
|
|
286, // efbHeight
|
|
|
|
286, // xfbHeight
|
|
|
|
0, // viXOrigin
|
|
|
|
(VI_MAX_HEIGHT_PAL - 572)/2, // viYOrigin
|
|
|
|
VI_MAX_WIDTH_PAL, // viWidth
|
|
|
|
572, // viHeight
|
|
|
|
VI_XFBMODE_SF, // xFBmode
|
|
|
|
GX_TRUE, // field_rendering
|
|
|
|
GX_FALSE, // aa
|
|
|
|
|
|
|
|
// sample points arranged in increasing Y order
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
|
|
|
{6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each
|
|
|
|
{6,6},{6,6},{6,6}, // pix 1
|
|
|
|
{6,6},{6,6},{6,6}, // pix 2
|
|
|
|
{6,6},{6,6},{6,6} // pix 3
|
|
|
|
},
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-01-06 18:15:28 +01:00
|
|
|
// vertical filter[7], 1/64 units, 6 bits each
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
0, // line n-1
|
|
|
|
0, // line n-1
|
|
|
|
21, // line n
|
|
|
|
22, // line n
|
|
|
|
21, // line n
|
|
|
|
0, // line n+1
|
|
|
|
0 // line n+1
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 576 lines interlaced (PAL 50Hz, scaled) */
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj TV50hz_576i =
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
VI_TVMODE_PAL_INT, // viDisplayMode
|
|
|
|
640, // fbWidth
|
|
|
|
480, // efbHeight
|
|
|
|
VI_MAX_HEIGHT_PAL, // xfbHeight
|
|
|
|
0, // viXOrigin
|
|
|
|
0, // viYOrigin
|
|
|
|
VI_MAX_WIDTH_PAL, // viWidth
|
|
|
|
VI_MAX_HEIGHT_PAL, // viHeight
|
|
|
|
VI_XFBMODE_DF, // xFBmode
|
|
|
|
GX_FALSE, // field_rendering
|
|
|
|
GX_FALSE, // aa
|
|
|
|
|
|
|
|
// sample points arranged in increasing Y order
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
|
|
|
{6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each
|
|
|
|
{6,6},{6,6},{6,6}, // pix 1
|
|
|
|
{6,6},{6,6},{6,6}, // pix 2
|
|
|
|
{6,6},{6,6},{6,6} // pix 3
|
|
|
|
},
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-01-06 18:15:28 +01:00
|
|
|
// vertical filter[7], 1/64 units, 6 bits each
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
8, // line n-1
|
|
|
|
8, // line n-1
|
|
|
|
10, // line n
|
|
|
|
12, // line n
|
|
|
|
10, // line n
|
|
|
|
8, // line n+1
|
|
|
|
8 // line n+1
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 240 lines progressive (NTSC or PAL 60Hz) */
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj TV60hz_240p =
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
VI_TVMODE_EURGB60_DS, // viDisplayMode
|
|
|
|
640, // fbWidth
|
|
|
|
VI_MAX_HEIGHT_NTSC/2, // efbHeight
|
|
|
|
VI_MAX_HEIGHT_NTSC/2, // xfbHeight
|
|
|
|
0, // viXOrigin
|
|
|
|
0, // viYOrigin
|
|
|
|
VI_MAX_WIDTH_NTSC, // viWidth
|
|
|
|
VI_MAX_HEIGHT_NTSC, // viHeight
|
|
|
|
VI_XFBMODE_SF, // xFBmode
|
|
|
|
GX_FALSE, // field_rendering
|
|
|
|
GX_FALSE, // aa
|
|
|
|
|
|
|
|
// sample points arranged in increasing Y order
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
|
|
|
{6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each
|
|
|
|
{6,6},{6,6},{6,6}, // pix 1
|
|
|
|
{6,6},{6,6},{6,6}, // pix 2
|
|
|
|
{6,6},{6,6},{6,6} // pix 3
|
|
|
|
},
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
// vertical filter[7], 1/64 units, 6 bits each
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
0, // line n-1
|
|
|
|
0, // line n-1
|
|
|
|
21, // line n
|
|
|
|
22, // line n
|
|
|
|
21, // line n
|
|
|
|
0, // line n+1
|
|
|
|
0 // line n+1
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 240 lines interlaced (NTSC or PAL 60Hz) */
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj TV60hz_240i =
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
VI_TVMODE_EURGB60_INT, // viDisplayMode
|
|
|
|
640, // fbWidth
|
|
|
|
VI_MAX_HEIGHT_NTSC/2, // efbHeight
|
|
|
|
VI_MAX_HEIGHT_NTSC/2, // xfbHeight
|
|
|
|
0, // viXOrigin
|
|
|
|
0, // viYOrigin
|
|
|
|
VI_MAX_WIDTH_NTSC, // viWidth
|
|
|
|
VI_MAX_HEIGHT_NTSC, // viHeight
|
|
|
|
VI_XFBMODE_SF, // xFBmode
|
|
|
|
GX_TRUE, // field_rendering
|
|
|
|
GX_FALSE, // aa
|
|
|
|
|
|
|
|
// sample points arranged in increasing Y order
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
|
|
|
{3,2},{9,6},{3,10}, // pix 0, 3 sample points, 1/12 units, 4 bits each
|
|
|
|
{3,2},{9,6},{3,10}, // pix 1
|
|
|
|
{9,2},{3,6},{9,10}, // pix 2
|
|
|
|
{9,2},{3,6},{9,10} // pix 3
|
|
|
|
},
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-01-06 18:15:28 +01:00
|
|
|
// vertical filter[7], 1/64 units, 6 bits each
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
0, // line n-1
|
|
|
|
0, // line n-1
|
|
|
|
21, // line n
|
|
|
|
22, // line n
|
|
|
|
21, // line n
|
|
|
|
0, // line n+1
|
|
|
|
0 // line n+1
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 480 lines interlaced (NTSC or PAL 60Hz) */
|
2009-01-14 17:32:35 +01:00
|
|
|
static GXRModeObj TV60hz_480i =
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
VI_TVMODE_EURGB60_INT,// viDisplayMode
|
2009-01-06 18:15:28 +01:00
|
|
|
640, // fbWidth
|
|
|
|
VI_MAX_HEIGHT_NTSC, // efbHeight
|
|
|
|
VI_MAX_HEIGHT_NTSC, // xfbHeight
|
|
|
|
0, // viXOrigin
|
|
|
|
0, // viYOrigin
|
|
|
|
VI_MAX_WIDTH_NTSC, // viWidth
|
|
|
|
VI_MAX_HEIGHT_NTSC, // viHeight
|
|
|
|
VI_XFBMODE_DF, // xFBmode
|
|
|
|
GX_FALSE, // field_rendering
|
|
|
|
GX_FALSE, // aa
|
|
|
|
|
|
|
|
// sample points arranged in increasing Y order
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
|
|
|
{6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each
|
|
|
|
{6,6},{6,6},{6,6}, // pix 1
|
|
|
|
{6,6},{6,6},{6,6}, // pix 2
|
|
|
|
{6,6},{6,6},{6,6} // pix 3
|
|
|
|
},
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-01-06 18:15:28 +01:00
|
|
|
// vertical filter[7], 1/64 units, 6 bits each
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2009-01-06 18:15:28 +01:00
|
|
|
8, // line n-1
|
|
|
|
8, // line n-1
|
|
|
|
10, // line n
|
|
|
|
12, // line n
|
|
|
|
10, // line n
|
|
|
|
8, // line n+1
|
|
|
|
8 // line n+1
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* TV modes pointer table */
|
|
|
|
static GXRModeObj *tvmodes[6] =
|
|
|
|
{
|
|
|
|
/* 60hz modes */
|
|
|
|
&TV60hz_240p,
|
|
|
|
&TV60hz_240i,
|
|
|
|
&TV60hz_480i,
|
|
|
|
|
|
|
|
/* 50Hz modes */
|
|
|
|
&TV50hz_288p,
|
|
|
|
&TV50hz_288i,
|
|
|
|
&TV50hz_576i
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct tagcamera
|
|
|
|
{
|
|
|
|
Vector pos;
|
|
|
|
Vector up;
|
|
|
|
Vector view;
|
|
|
|
} camera;
|
|
|
|
|
|
|
|
/*** Square Matrix
|
|
|
|
This structure controls the size of the image on the screen.
|
2008-12-10 19:16:30 +01:00
|
|
|
Think of the output as a -80 x 80 by -60 x 60 graph.
|
2008-08-07 14:26:07 +02:00
|
|
|
***/
|
|
|
|
static s16 square[] ATTRIBUTE_ALIGN (32) =
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* X, Y, Z
|
|
|
|
* Values set are for roughly 4:3 aspect
|
|
|
|
*/
|
2008-12-10 19:16:30 +01:00
|
|
|
-HASPECT, VASPECT, 0, // 0
|
|
|
|
HASPECT, VASPECT, 0, // 1
|
|
|
|
HASPECT, -VASPECT, 0, // 2
|
|
|
|
-HASPECT, -VASPECT, 0, // 3
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static camera cam = {
|
|
|
|
{0.0F, 0.0F, -100.0F},
|
|
|
|
{0.0F, -1.0F, 0.0F},
|
|
|
|
{0.0F, 0.0F, 0.0F}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-09 18:11:42 +01:00
|
|
|
/* Vertex Rendering */
|
2008-11-13 08:24:30 +01:00
|
|
|
static inline void draw_vert(u8 pos, f32 s, f32 t)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
GX_Position1x8(pos);
|
|
|
|
GX_TexCoord2f32(s, t);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* textured quad rendering */
|
2009-01-14 17:32:35 +01:00
|
|
|
static inline void draw_square(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
|
|
|
|
draw_vert(3, 0.0, 0.0);
|
|
|
|
draw_vert(2, 1.0, 0.0);
|
|
|
|
draw_vert(1, 1.0, 1.0);
|
|
|
|
draw_vert(0, 0.0, 1.0);
|
2008-08-07 14:26:07 +02:00
|
|
|
GX_End ();
|
|
|
|
}
|
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
/* Initialize GX renderer */
|
2008-08-07 14:26:07 +02:00
|
|
|
static void gxStart(void)
|
|
|
|
{
|
|
|
|
/*** Clear out FIFO area ***/
|
2009-01-14 17:32:35 +01:00
|
|
|
memset(&gp_fifo, 0, DEFAULT_FIFO_SIZE);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/*** GX default ***/
|
2009-01-14 17:32:35 +01:00
|
|
|
GX_Init(&gp_fifo, DEFAULT_FIFO_SIZE);
|
|
|
|
GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
|
|
|
|
GX_SetCullMode(GX_CULL_NONE);
|
|
|
|
GX_SetDispCopyGamma(GX_GM_1_0);
|
2008-08-07 14:26:07 +02:00
|
|
|
GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_TRUE);
|
2009-01-14 17:32:35 +01:00
|
|
|
GX_SetColorUpdate(GX_TRUE);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
/* Modelview */
|
|
|
|
Mtx view;
|
|
|
|
memset (&view, 0, sizeof (Mtx));
|
|
|
|
guLookAt(view, &cam.pos, &cam.up, &cam.view);
|
|
|
|
GX_LoadPosMtxImm(view, GX_PNMTX0);
|
2009-01-14 17:32:35 +01:00
|
|
|
GX_Flush();
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/*** Initialize texture data ***/
|
2008-12-19 16:38:26 +01:00
|
|
|
texturemem = memalign(32, TEX_SIZE);
|
|
|
|
memset (texturemem, 0, TEX_SIZE);
|
2009-02-22 20:57:41 +01:00
|
|
|
}
|
|
|
|
|
2009-04-01 09:37:54 +02:00
|
|
|
/* Reset GX rendering */
|
2009-04-01 14:36:14 +02:00
|
|
|
static void gxResetRendering(u8 isMenu)
|
2009-02-22 20:57:41 +01:00
|
|
|
{
|
|
|
|
GX_ClearVtxDesc();
|
|
|
|
|
|
|
|
if (isMenu)
|
|
|
|
{
|
2009-04-01 09:37:54 +02:00
|
|
|
/* GX menu (uses direct positionning, alpha blending & color channel) */
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_SetBlendMode(GX_BM_BLEND,GX_BL_SRCALPHA,GX_BL_INVSRCALPHA,GX_LO_CLEAR);
|
|
|
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_S16, 0);
|
2009-04-01 09:37:54 +02:00
|
|
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
|
|
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
|
2009-04-01 09:37:54 +02:00
|
|
|
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
|
|
|
GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT);
|
|
|
|
/*
|
|
|
|
Color.out = Color.rasterized*Color.texture
|
|
|
|
Alpha.out = Alpha.rasterized*Alpha.texture
|
|
|
|
*/
|
|
|
|
GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE);
|
|
|
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
|
|
|
|
GX_SetNumTexGens(1);
|
|
|
|
GX_SetNumChans(1);
|
2009-02-22 20:57:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-01 09:37:54 +02:00
|
|
|
/* video emulation (uses array positionning, no alpha blending, no color channel) */
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_SetBlendMode(GX_BM_NONE,GX_BL_SRCALPHA,GX_BL_INVSRCALPHA,GX_LO_CLEAR);
|
|
|
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
|
2009-04-01 09:37:54 +02:00
|
|
|
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
|
2009-04-01 09:37:54 +02:00
|
|
|
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_SetArray(GX_VA_POS, square, 3 * sizeof (s16));
|
2009-04-01 09:37:54 +02:00
|
|
|
/*
|
|
|
|
Color.out = Color.texture
|
|
|
|
Alpha.out = Alpha.texture
|
|
|
|
*/
|
|
|
|
GX_SetTevOp (GX_TEVSTAGE0, GX_REPLACE);
|
|
|
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL);
|
|
|
|
GX_SetNumTexGens(1);
|
|
|
|
GX_SetNumChans(0);
|
2009-02-22 20:57:41 +01:00
|
|
|
}
|
2008-11-13 08:24:30 +01:00
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_Flush();
|
|
|
|
}
|
|
|
|
|
2009-03-29 20:56:36 +02:00
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
/* Reset GX 2D rendering */
|
|
|
|
static void gxResetView(GXRModeObj *tvmode)
|
|
|
|
{
|
|
|
|
Mtx44 p;
|
|
|
|
f32 yScale = GX_GetYScaleFactor(tvmode->efbHeight, tvmode->xfbHeight);
|
|
|
|
u16 xfbHeight = GX_SetDispCopyYScale(yScale);
|
|
|
|
|
|
|
|
GX_SetCopyClear((GXColor)BLACK,0x00ffffff);
|
|
|
|
GX_SetViewport(0.0F, 0.0F, tvmode->fbWidth, tvmode->efbHeight, 0.0F, 1.0F);
|
|
|
|
GX_SetScissor(0, 0, tvmode->fbWidth, tvmode->efbHeight);
|
|
|
|
GX_SetDispCopySrc(0, 0, tvmode->fbWidth, tvmode->efbHeight);
|
|
|
|
GX_SetDispCopyDst(tvmode->fbWidth, xfbHeight);
|
2009-03-22 13:23:30 +01:00
|
|
|
GX_SetCopyFilter(tvmode->aa, tvmode->sample_pattern, (tvmode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE, tvmode->vfilter);
|
2009-02-22 20:57:41 +01:00
|
|
|
GX_SetFieldMode(tvmode->field_rendering, ((tvmode->viHeight == 2 * tvmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
|
|
|
|
guOrtho(p, tvmode->efbHeight/2, -(tvmode->efbHeight/2), -(tvmode->fbWidth/2), tvmode->fbWidth/2, 100, 1000);
|
|
|
|
GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC);
|
2009-03-06 16:57:31 +01:00
|
|
|
GX_Flush();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2008-10-23 22:38:06 +02:00
|
|
|
/* Reset GX/VI scaler */
|
2009-02-22 20:57:41 +01:00
|
|
|
static void gxResetScale(u32 width, u32 height)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-11-13 08:24:30 +01:00
|
|
|
int temp = 0;
|
|
|
|
int xscale, yscale, xshift, yshift;
|
2008-10-23 22:38:06 +02:00
|
|
|
|
2009-01-09 18:11:42 +01:00
|
|
|
/* aspect Ratio (depends on current configuration) */
|
2008-11-13 08:24:30 +01:00
|
|
|
if (config.aspect)
|
2008-10-23 22:38:06 +02:00
|
|
|
{
|
|
|
|
/* original aspect ratio */
|
|
|
|
/* the following values have been detected from comparison with a real 50/60hz Mega Drive */
|
|
|
|
if (config.overscan)
|
2008-12-10 19:16:30 +01:00
|
|
|
{
|
2008-10-23 22:38:06 +02:00
|
|
|
/* borders are emulated */
|
2008-12-10 19:16:30 +01:00
|
|
|
xscale = 358 + ((reg[12] & 1)*2) - gc_pal;
|
2008-11-13 08:24:30 +01:00
|
|
|
yscale = vdp_pal + ((gc_pal && !config.render) ? 143 : 120);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* borders are simulated (black) */
|
2008-12-10 19:16:30 +01:00
|
|
|
xscale = 325 + ((reg[12] & 1)*2) - gc_pal;
|
2008-08-07 14:26:07 +02:00
|
|
|
yscale = bitmap.viewport.h / 2;
|
2008-12-10 19:16:30 +01:00
|
|
|
if (vdp_pal && (!gc_pal || config.render)) yscale = yscale * 240 / 288;
|
|
|
|
else if (!vdp_pal && gc_pal && !config.render) yscale = yscale * 288 / 240;
|
2008-10-26 19:32:32 +01:00
|
|
|
}
|
2008-10-23 22:38:06 +02:00
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
xshift = config.xshift;
|
|
|
|
yshift = 2 - vdp_pal + 2*(gc_pal & !config.render) + config.yshift;
|
2008-12-10 19:16:30 +01:00
|
|
|
}
|
2008-10-23 22:38:06 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* manual aspect ratio (default is fullscreen) */
|
|
|
|
if (config.overscan)
|
2008-10-26 19:32:32 +01:00
|
|
|
{
|
2008-10-23 22:38:06 +02:00
|
|
|
/* borders are emulated */
|
|
|
|
xscale = 352;
|
|
|
|
yscale = (gc_pal && !config.render) ? (vdp_pal ? (268*144 / bitmap.viewport.h):143) : (vdp_pal ? (224*144 / bitmap.viewport.h):120);
|
2008-11-13 08:24:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* borders are simulated (black) */
|
2008-09-10 16:31:13 +02:00
|
|
|
xscale = 320;
|
2008-08-07 14:26:07 +02:00
|
|
|
yscale = (gc_pal && !config.render) ? 134 : 112;
|
|
|
|
}
|
2008-10-23 22:38:06 +02:00
|
|
|
|
|
|
|
/* user scaling */
|
2008-08-07 14:26:07 +02:00
|
|
|
xscale += config.xscale;
|
|
|
|
yscale += config.yscale;
|
|
|
|
|
2008-10-23 22:38:06 +02:00
|
|
|
xshift = config.xshift;
|
2008-12-10 19:16:30 +01:00
|
|
|
yshift = config.yshift;
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-01-09 18:11:42 +01:00
|
|
|
/* double resolution modes */
|
2008-10-23 22:38:06 +02:00
|
|
|
if (config.render)
|
2008-10-20 17:50:13 +02:00
|
|
|
{
|
2008-10-23 22:38:06 +02:00
|
|
|
yscale *= 2;
|
2008-10-20 17:50:13 +02:00
|
|
|
yshift *= 2;
|
2008-10-23 22:38:06 +02:00
|
|
|
}
|
2008-11-13 08:24:30 +01:00
|
|
|
|
2009-01-09 18:11:42 +01:00
|
|
|
/* GX scaler (by default, use EFB maximal width) */
|
2008-11-13 08:24:30 +01:00
|
|
|
rmode->fbWidth = 640;
|
2008-12-07 20:31:50 +01:00
|
|
|
if (!config.bilinear && !config.ntsc)
|
2008-11-13 08:24:30 +01:00
|
|
|
{
|
2008-12-07 20:31:50 +01:00
|
|
|
/* filtering (soft or hard) is disabled, let VI handles horizontal scaling */
|
2008-11-13 08:24:30 +01:00
|
|
|
/* if possible, let GX simply doubles the width, otherwise disable GX stretching completely */
|
|
|
|
if ((width * 2) <= 640) rmode->fbWidth = width * 2;
|
|
|
|
else if (width <= 640) rmode->fbWidth = width;
|
|
|
|
}
|
|
|
|
|
2009-01-09 18:11:42 +01:00
|
|
|
/* horizontal scaling (GX/VI) */
|
2008-11-13 08:24:30 +01:00
|
|
|
if (xscale > (rmode->fbWidth/2))
|
|
|
|
{
|
|
|
|
/* max width = 720 pixels */
|
|
|
|
if (xscale > 360)
|
|
|
|
{
|
|
|
|
/* save offset for later */
|
|
|
|
temp = xscale - 360;
|
|
|
|
xscale = 360;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable VI scaler */
|
|
|
|
rmode->viWidth = xscale * 2;
|
|
|
|
rmode->viXOrigin = (720 - (xscale * 2)) / 2;
|
|
|
|
|
|
|
|
/* set GX scaling to max EFB width */
|
|
|
|
xscale = temp + (rmode->fbWidth/2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* disable VI scaler */
|
|
|
|
rmode->viWidth = rmode->fbWidth;
|
|
|
|
rmode->viXOrigin = (720 - rmode->fbWidth) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update GX scaler (Vertex Position Matrix) */
|
|
|
|
square[6] = square[3] = xscale + xshift;
|
2008-12-10 19:16:30 +01:00
|
|
|
square[0] = square[9] = -xscale + xshift;
|
2008-11-13 08:24:30 +01:00
|
|
|
square[4] = square[1] = yscale + yshift;
|
2008-12-10 19:16:30 +01:00
|
|
|
square[7] = square[10] = -yscale + yshift;
|
2009-01-14 17:32:35 +01:00
|
|
|
DCFlushRange(square, 32);
|
|
|
|
GX_InvVtxCache();
|
2009-01-09 18:11:42 +01:00
|
|
|
}
|
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
|
|
|
|
static void VSyncCallback(u32 cnt)
|
2009-01-16 16:02:08 +01:00
|
|
|
{
|
2009-02-22 20:57:41 +01:00
|
|
|
frameticker++;
|
2009-01-16 16:02:08 +01:00
|
|
|
}
|
|
|
|
|
2009-03-29 20:56:36 +02:00
|
|
|
void gxResetCamera(f32 angle)
|
|
|
|
{
|
|
|
|
Mtx view;
|
|
|
|
|
|
|
|
if (angle)
|
|
|
|
{
|
|
|
|
Mtx m,m1;
|
|
|
|
Vector axis = (Vector) {0,0,1};
|
|
|
|
guLookAt(m, &cam.pos, &cam.up, &cam.view);
|
|
|
|
guMtxRotAxisDeg (m1, &axis, angle);
|
|
|
|
guMtxConcat(m,m1,view);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guLookAt(view, &cam.pos, &cam.up, &cam.view);
|
|
|
|
}
|
|
|
|
|
|
|
|
GX_LoadPosMtxImm(view, GX_PNMTX0);
|
|
|
|
GX_Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* Restore Menu Video mode */
|
2009-01-09 18:11:42 +01:00
|
|
|
void ogc_video__stop(void)
|
|
|
|
{
|
2009-02-22 20:57:41 +01:00
|
|
|
/* reset GX */
|
2009-04-01 14:36:14 +02:00
|
|
|
gxResetRendering(1);
|
2009-02-22 20:57:41 +01:00
|
|
|
gxResetView(vmode);
|
2009-04-01 14:36:14 +02:00
|
|
|
|
|
|
|
ogc_video_caption(0xff);
|
|
|
|
VIDEO_Configure(vmode);
|
|
|
|
VIDEO_SetPreRetraceCallback(NULL);
|
|
|
|
SetScreen ();
|
2009-01-09 18:11:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update Video settings */
|
2009-03-06 16:57:31 +01:00
|
|
|
void ogc_video__start(void)
|
2009-01-09 18:11:42 +01:00
|
|
|
{
|
2009-02-22 20:57:41 +01:00
|
|
|
/* 50Hz/60Hz mode */
|
|
|
|
if ((config.tv_mode == 1) || ((config.tv_mode == 2) && vdp_pal)) gc_pal = 1;
|
|
|
|
else gc_pal = 0;
|
|
|
|
|
|
|
|
/* Video Interrupt synchronization */
|
2009-04-01 14:36:14 +02:00
|
|
|
VIDEO_SetPostRetraceCallback(NULL);
|
|
|
|
if (!gc_pal && !vdp_pal)
|
|
|
|
{
|
|
|
|
VIDEO_SetPreRetraceCallback(VSyncCallback);
|
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
2009-01-09 18:11:42 +01:00
|
|
|
|
|
|
|
/* interlaced/progressive mode */
|
|
|
|
if (config.render == 2)
|
|
|
|
{
|
|
|
|
tvmodes[2]->viTVMode = VI_TVMODE_NTSC_PROG;
|
|
|
|
tvmodes[2]->xfbMode = VI_XFBMODE_SF;
|
|
|
|
}
|
|
|
|
else if (config.render == 1)
|
|
|
|
{
|
|
|
|
tvmodes[2]->viTVMode = tvmodes[0]->viTVMode & ~3;
|
|
|
|
tvmodes[2]->xfbMode = VI_XFBMODE_DF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* software NTSC filters */
|
2008-10-02 22:22:53 +02:00
|
|
|
if (config.ntsc == 1)
|
|
|
|
{
|
|
|
|
sms_setup = sms_ntsc_composite;
|
|
|
|
md_setup = md_ntsc_composite;
|
|
|
|
sms_ntsc_init( &sms_ntsc, &sms_setup );
|
|
|
|
md_ntsc_init( &md_ntsc, &md_setup );
|
|
|
|
}
|
|
|
|
else if (config.ntsc == 2)
|
|
|
|
{
|
|
|
|
sms_setup = sms_ntsc_svideo;
|
|
|
|
md_setup = md_ntsc_svideo;
|
|
|
|
sms_ntsc_init( &sms_ntsc, &sms_setup );
|
|
|
|
md_ntsc_init( &md_ntsc, &md_setup );
|
|
|
|
}
|
2008-10-03 16:14:20 +02:00
|
|
|
else if (config.ntsc == 3)
|
2008-10-02 22:22:53 +02:00
|
|
|
{
|
|
|
|
sms_setup = sms_ntsc_rgb;
|
|
|
|
md_setup = md_ntsc_rgb;
|
|
|
|
sms_ntsc_init( &sms_ntsc, &sms_setup );
|
|
|
|
md_ntsc_init( &md_ntsc, &md_setup );
|
|
|
|
}
|
2009-01-09 18:11:42 +01:00
|
|
|
|
|
|
|
/* apply changes on next video update */
|
|
|
|
bitmap.viewport.changed = 1;
|
2009-02-22 20:57:41 +01:00
|
|
|
|
2009-04-01 09:37:54 +02:00
|
|
|
/* reset GX rendering */
|
2009-04-01 14:36:14 +02:00
|
|
|
gxResetRendering(0);
|
2009-02-22 20:57:41 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-01 09:37:54 +02:00
|
|
|
static u32 vwidth,vheight;
|
2009-03-29 20:56:36 +02:00
|
|
|
|
2009-04-01 09:37:54 +02:00
|
|
|
void ogc_video_caption(u8 alpha)
|
2009-03-29 20:56:36 +02:00
|
|
|
{
|
2009-04-01 09:37:54 +02:00
|
|
|
GXTexObj texobj;
|
|
|
|
GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
2009-03-29 20:56:36 +02:00
|
|
|
GX_LoadTexObj(&texobj, GX_TEXMAP0);
|
|
|
|
GX_InvalidateTexAll();
|
2009-04-01 09:37:54 +02:00
|
|
|
|
|
|
|
/* reset Scaler (display screenshot in background) */
|
|
|
|
s32 x = config.overscan ? -352 : -320;
|
|
|
|
s32 y = config.overscan ? -240 : -224;
|
|
|
|
s32 w = config.overscan ? 704 : 640;
|
|
|
|
s32 h = config.overscan ? 480 : 448;
|
|
|
|
|
|
|
|
/* Draw textured quad */
|
|
|
|
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
|
|
|
|
GX_Position2s16(x,y+h);
|
|
|
|
GX_Color4u8(0xff,0xff,0xff,alpha);
|
|
|
|
GX_TexCoord2f32(0.0, 1.0);
|
|
|
|
GX_Position2s16(x+w,y+h);
|
|
|
|
GX_Color4u8(0xff,0xff,0xff,alpha);
|
|
|
|
GX_TexCoord2f32(1.0, 1.0);
|
|
|
|
GX_Position2s16(x+w,y);
|
|
|
|
GX_Color4u8(0xff,0xff,0xff,alpha);
|
|
|
|
GX_TexCoord2f32(1.0, 0.0);
|
|
|
|
GX_Position2s16(x,y);
|
|
|
|
GX_Color4u8(0xff,0xff,0xff,alpha);
|
|
|
|
GX_TexCoord2f32(0.0, 0.0);
|
|
|
|
GX_End ();
|
2009-03-29 20:56:36 +02:00
|
|
|
GX_DrawDone();
|
|
|
|
}
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* GX render update */
|
2009-03-06 16:57:31 +01:00
|
|
|
void ogc_video__update(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-01-14 17:32:35 +01:00
|
|
|
/* check if display has changed */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (bitmap.viewport.changed)
|
|
|
|
{
|
2008-10-26 19:32:32 +01:00
|
|
|
bitmap.viewport.changed = 0;
|
2008-12-12 15:21:23 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* update texture size */
|
2009-04-01 09:37:54 +02:00
|
|
|
vwidth = bitmap.viewport.w + 2 * bitmap.viewport.x;
|
|
|
|
vheight = bitmap.viewport.h + 2 * bitmap.viewport.y;
|
2008-10-02 22:22:53 +02:00
|
|
|
|
|
|
|
/* special cases */
|
2009-03-06 16:57:31 +01:00
|
|
|
if (config.render && interlaced) vheight = vheight << 1;
|
2008-10-02 22:22:53 +02:00
|
|
|
if (config.ntsc) vwidth = (reg[12]&1) ? MD_NTSC_OUT_WIDTH(vwidth) : SMS_NTSC_OUT_WIDTH(vwidth);
|
|
|
|
|
2008-10-03 16:14:20 +02:00
|
|
|
/* texels size must be multiple of 4 */
|
2009-03-06 16:57:31 +01:00
|
|
|
vwidth = (vwidth >> 2) << 2;
|
|
|
|
vheight = (vheight >> 2) << 2;
|
2008-10-23 22:38:06 +02:00
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* initialize texture object */
|
2009-04-01 09:37:54 +02:00
|
|
|
GXTexObj texobj;
|
2009-01-14 17:32:35 +01:00
|
|
|
GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE);
|
2008-10-23 22:38:06 +02:00
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* configure texture filtering */
|
2008-10-23 22:38:06 +02:00
|
|
|
if (!config.bilinear)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-03-22 13:23:30 +01:00
|
|
|
GX_InitTexObjLOD(&texobj,GX_NEAR,GX_NEAR_MIP_NEAR,0.0,10.0,0.0,GX_FALSE,GX_FALSE,GX_ANISO_1);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2008-11-13 08:24:30 +01:00
|
|
|
|
2009-01-14 17:32:35 +01:00
|
|
|
/* load texture object */
|
|
|
|
GX_LoadTexObj(&texobj, GX_TEXMAP0);
|
|
|
|
|
2009-03-06 16:57:31 +01:00
|
|
|
/* reset TV mode */
|
2009-01-14 17:32:35 +01:00
|
|
|
if (config.render) rmode = tvmodes[gc_pal*3 + 2];
|
|
|
|
else rmode = tvmodes[gc_pal*3 + interlaced];
|
|
|
|
|
|
|
|
/* reset aspect ratio */
|
2009-02-22 20:57:41 +01:00
|
|
|
gxResetScale(vwidth,vheight);
|
|
|
|
|
2009-03-06 16:57:31 +01:00
|
|
|
/* reconfigure VI */
|
2009-01-14 17:32:35 +01:00
|
|
|
VIDEO_Configure(rmode);
|
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
|
|
|
|
else while (VIDEO_GetNextField() != odd_frame) VIDEO_WaitVSync();
|
2009-02-22 20:57:41 +01:00
|
|
|
if (frameticker > 1) frameticker = 1;
|
2009-03-06 16:57:31 +01:00
|
|
|
|
|
|
|
/* reset GX */
|
|
|
|
gxResetView(rmode);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-01-14 17:32:35 +01:00
|
|
|
|
2008-12-04 20:32:22 +01:00
|
|
|
/* texture is now directly mapped by the line renderer */
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-03-06 16:57:31 +01:00
|
|
|
/* force texture cache update */
|
2009-01-14 17:32:35 +01:00
|
|
|
DCFlushRange(texturemem, TEX_SIZE);
|
|
|
|
GX_InvalidateTexAll();
|
2009-01-09 18:11:42 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* render textured quad */
|
2009-01-14 17:32:35 +01:00
|
|
|
draw_square();
|
|
|
|
GX_DrawDone();
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-03-06 16:57:31 +01:00
|
|
|
/* swap XFB then copy EFB to XFB */
|
2009-02-22 20:57:41 +01:00
|
|
|
whichfb ^= 1;
|
2009-03-06 16:57:31 +01:00
|
|
|
GX_CopyDisp(xfb[whichfb], GX_TRUE);
|
|
|
|
GX_Flush();
|
|
|
|
|
|
|
|
/* set next XFB */
|
2009-02-22 20:57:41 +01:00
|
|
|
VIDEO_SetNextFramebuffer(xfb[whichfb]);
|
|
|
|
VIDEO_Flush();
|
2009-01-14 17:32:35 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize VIDEO subsystem */
|
|
|
|
void ogc_video__init(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Before doing anything else under libogc,
|
|
|
|
* Call VIDEO_Init
|
|
|
|
*/
|
2009-01-14 17:32:35 +01:00
|
|
|
VIDEO_Init();
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Before any memory is allocated etc.
|
|
|
|
* Rescue any tagged ROM in data 2
|
|
|
|
*/
|
|
|
|
int *romptr = (int *)0x80700000;
|
|
|
|
StartARAM();
|
|
|
|
genromsize = 0;
|
2009-01-14 17:32:35 +01:00
|
|
|
if (memcmp((char *)romptr,"GENPLUSR",8) == 0)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
genromsize = romptr[2];
|
2009-01-14 17:32:35 +01:00
|
|
|
ARAMPut((char *) 0x80700000 + 0x20, (char *) 0x8000, genromsize);
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-01-07 18:12:03 +01:00
|
|
|
/* Get the current VIDEO mode then :
|
|
|
|
- set menu VIDEO mode (480p, 480i or 576i)
|
2008-08-07 14:26:07 +02:00
|
|
|
- set emulator rendering TV modes (PAL/MPAL/NTSC/EURGB60)
|
|
|
|
*/
|
|
|
|
vmode = VIDEO_GetPreferredMode(NULL);
|
|
|
|
|
2008-10-24 18:14:54 +02:00
|
|
|
/* Adjust display settings */
|
2008-08-07 14:26:07 +02:00
|
|
|
switch (vmode->viTVMode >> 2)
|
|
|
|
{
|
|
|
|
case VI_PAL: /* 576 lines (PAL 50Hz) */
|
|
|
|
|
|
|
|
TV60hz_240p.viTVMode = VI_TVMODE_EURGB60_DS;
|
|
|
|
TV60hz_240i.viTVMode = VI_TVMODE_EURGB60_INT;
|
|
|
|
TV60hz_480i.viTVMode = VI_TVMODE_EURGB60_INT;
|
|
|
|
config.tv_mode = 1;
|
|
|
|
|
2009-04-01 09:37:54 +02:00
|
|
|
/* use harwdare vertical scaling to fill screen */
|
2008-08-07 14:26:07 +02:00
|
|
|
vmode = &TVPal574IntDfScale;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VI_NTSC: /* 480 lines (NTSC 60hz) */
|
|
|
|
TV60hz_240p.viTVMode = VI_TVMODE_NTSC_DS;
|
|
|
|
TV60hz_240i.viTVMode = VI_TVMODE_NTSC_INT;
|
|
|
|
TV60hz_480i.viTVMode = VI_TVMODE_NTSC_INT;
|
|
|
|
config.tv_mode = 0;
|
2008-10-02 22:22:53 +02:00
|
|
|
|
|
|
|
#ifndef HW_RVL
|
2008-10-24 18:14:54 +02:00
|
|
|
/* force 480p on NTSC GameCube if the Component Cable is present */
|
2008-10-02 22:22:53 +02:00
|
|
|
if (VIDEO_HaveComponentCable()) vmode = &TVNtsc480Prog;
|
|
|
|
#endif
|
2008-08-07 14:26:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* 480 lines (PAL 60Hz) */
|
|
|
|
TV60hz_240p.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_NON_INTERLACE);
|
|
|
|
TV60hz_240i.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_INTERLACE);
|
|
|
|
TV60hz_480i.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_INTERLACE);
|
|
|
|
config.tv_mode = 2;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-12 15:21:23 +01:00
|
|
|
|
2009-03-22 13:23:30 +01:00
|
|
|
/* adjust overscan */
|
|
|
|
vmode->viWidth = 672;
|
|
|
|
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - 672)/2;
|
2008-12-12 15:21:23 +01:00
|
|
|
|
2009-01-09 18:11:42 +01:00
|
|
|
/* Configure VI */
|
2008-08-07 14:26:07 +02:00
|
|
|
VIDEO_Configure (vmode);
|
|
|
|
|
|
|
|
/* Configure the framebuffers (double-buffering) */
|
|
|
|
xfb[0] = (u32 *) MEM_K0_TO_K1((u32 *) SYS_AllocateFramebuffer(&TV50hz_576i));
|
|
|
|
xfb[1] = (u32 *) MEM_K0_TO_K1((u32 *) SYS_AllocateFramebuffer(&TV50hz_576i));
|
|
|
|
|
|
|
|
/* Define a console */
|
|
|
|
console_init(xfb[0], 20, 64, 640, 574, 574 * 2);
|
|
|
|
|
|
|
|
/* Clear framebuffers to black */
|
2009-01-14 17:32:35 +01:00
|
|
|
VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK);
|
|
|
|
VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* Set the framebuffer to be displayed at next VBlank */
|
2009-01-14 17:32:35 +01:00
|
|
|
VIDEO_SetNextFramebuffer(xfb[0]);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* Enable Video Interface */
|
2009-01-14 17:32:35 +01:00
|
|
|
VIDEO_SetBlack(FALSE);
|
2008-12-12 15:21:23 +01:00
|
|
|
|
2009-01-07 18:12:03 +01:00
|
|
|
/* Update VIDEO settings for next VBlank */
|
2009-01-14 17:32:35 +01:00
|
|
|
VIDEO_Flush();
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* Wait for VBlank */
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
/* Initialize GX */
|
|
|
|
gxStart();
|
2009-04-01 14:36:14 +02:00
|
|
|
gxResetRendering(1);
|
2009-02-22 20:57:41 +01:00
|
|
|
gxResetView(vmode);
|
|
|
|
|
2009-03-22 13:23:30 +01:00
|
|
|
/* Initialize Font */
|
|
|
|
FONT_Init();
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
}
|