Browse Source

Expanded display initialization code with proper handling of both NTSC and PAL aspect ratios, and allowing PAL to render at higher resolution.

Also includes provisioning for switching between progressive and interlaced modes.
tess_experiment
Nico de Poel 3 years ago
parent
commit
adff38b978
  1. 54
      display.c
  2. 4
      display.h

54
display.c

@ -55,15 +55,9 @@ void display_init()
// ISR subsystem to the kernel // ISR subsystem to the kernel
ResetGraph(0); ResetGraph(0);
//SetVideoMode(MODE_NTSC);
// Define display environments, first on top and second on bottom
SetDefDispEnv(&disp[0], 0, 0, SCREENWIDTH, SCREENHEIGHT);
SetDefDispEnv(&disp[1], 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT);
// Define drawing environments, first on bottom and second on top
SetDefDrawEnv(&draw[0], 0, SCREENHEIGHT, SCREENWIDTH, SCREENHEIGHT);
SetDefDrawEnv(&draw[1], 0, 0, SCREENWIDTH, SCREENHEIGHT);
// Start the display in progressive mode
int screenHeight;
display_reset(0, &screenHeight);
// Set and enable clear color // Set and enable clear color
setRGB0(&draw[0], 49, 77, 121); setRGB0(&draw[0], 49, 77, 121);
@ -84,14 +78,51 @@ void display_init()
FntLoad(960, 0); FntLoad(960, 0);
// Open up a test font text stream // Open up a test font text stream
FntOpen(0, 8, SCREENWIDTH, SCREENHEIGHT, 0, 512);
FntOpen(0, 8, SCREENWIDTH, screenHeight, 0, 512);
// Initialize GTE // Initialize GTE
InitGeom(); InitGeom();
gte_SetGeomOffset(SCREENWIDTH >> 1, SCREENHEIGHT >> 1);
gte_SetGeomOffset(SCREENWIDTH >> 1, screenHeight >> 1);
gte_SetGeomScreen(180); // Screen depth for FOV control. Determines the distance of the camera to the near plane. gte_SetGeomScreen(180); // Screen depth for FOV control. Determines the distance of the camera to the near plane.
} }
void display_reset(u_char interlaced, int *outScreenHeight)
{
int screenHeight, yOffset;
if (GetVideoMode() == MODE_NTSC)
{
screenHeight = SCREENHEIGHT_NTSC;
yOffset = (240 - SCREENHEIGHT_NTSC) >> 1; // Vertically center the image for NTSC displays
// Scale Y coordinates to correct the aspect ratio for NTSC's typical visible screen area
aspect_scale.vy = 224 * ONE / 240;
}
else // MODE_PAL
{
screenHeight = SCREENHEIGHT_PAL;
yOffset = (288 - SCREENHEIGHT_PAL) >> 1; // Vertically center the image for PAL displays
// Scale Y coordinates to correct the aspect ratio for PAL's non-square pixels
aspect_scale.vy = 256 * ONE / 240;
}
// Define display environments, first on top and second on bottom
SetDefDispEnv(&disp[0], 0, 0, SCREENWIDTH, screenHeight);
SetDefDispEnv(&disp[1], 0, screenHeight, SCREENWIDTH, screenHeight);
// Define drawing environments, first on bottom and second on top
SetDefDrawEnv(&draw[0], 0, screenHeight, SCREENWIDTH, screenHeight);
SetDefDrawEnv(&draw[1], 0, 0, SCREENWIDTH, screenHeight);
disp[0].screen.y = disp[1].screen.y = yOffset;
disp[0].screen.h = disp[1].screen.h = screenHeight;
gte_SetGeomOffset(SCREENWIDTH >> 1, screenHeight >> 1);
if (outScreenHeight != NULL)
*outScreenHeight = screenHeight;
}
void display_start() void display_start()
{ {
curOT = ot[db]; curOT = ot[db];
@ -143,7 +174,6 @@ void *display_allocPrim(size_t size)
if (nextpri + size > primbuff[db] + PRIMBUFLEN) if (nextpri + size > primbuff[db] + PRIMBUFLEN)
return NULL; return NULL;
// TODO: maybe add a bounds check?
void *prim = nextpri; void *prim = nextpri;
nextpri += size; nextpri += size;
return prim; return prim;

4
display.h

@ -2,7 +2,8 @@
#define __DISPLAY_H__ #define __DISPLAY_H__
#define SCREENWIDTH 512 #define SCREENWIDTH 512
#define SCREENHEIGHT 240
#define SCREENHEIGHT_NTSC 240
#define SCREENHEIGHT_PAL 256
#define OTLEN 1024 #define OTLEN 1024
@ -10,6 +11,7 @@ extern MATRIX vp_matrix;
extern u_long *curOT; extern u_long *curOT;
void display_init(); void display_init();
void display_reset(u_char interlaced, int *outScreenHeight);
void display_start(); void display_start();
void display_finish(); void display_finish();

Loading…
Cancel
Save