22#include "ps2s/displayenv.h"
23#include "ps2s/drawenv.h"
25#include "ps2s/timer.h"
28#include "ps2gl/debug.h"
29#include "ps2gl/displaycontext.h"
30#include "ps2gl/drawcontext.h"
31#include "ps2gl/glcontext.h"
34DISABLE_EXTRA_TIMERS_FUNCTIONS();
41typedef void (*tFunctionPtr_ii)(int, int);
42typedef void (*tFunctionPtr_ucii)(
unsigned char, int, int);
43typedef void (*tFunctionPtr_iii)(int, int, int);
44typedef void (*tFunctionPtr)(void);
45typedef void (*tFunctionPtr_i)(int);
51static void normal_main_loop();
52static void initGsMemory();
59tFunctionPtr DisplayFunc = NULL;
60tFunctionPtr_ii ReshapeFunc = NULL;
61tFunctionPtr_ucii KeyboardFunc = NULL;
62tFunctionPtr_i VisibilityFunc = NULL;
63tFunctionPtr IdleFunc = NULL;
64tFunctionPtr_iii SpecialFunc = NULL;
66static CEETimer* Timer0;
68static bool printTimes =
false;
119 *GIF::Registers::ctrl = 1;
122 SetGsCrt(1 , 2 , 1 );
124 mWarn(
"ps2gl library has not been initialized by the user; using default values.");
125 int immBufferVertexSize = 64 * 1024;
126 pglInit(immBufferVertexSize, 1000);
132 mWarn(
"GS memory has not been allocated by the user; using default values.");
172 VisibilityFunc = func;
200 mErrorIf(DisplayFunc == NULL,
"ps2glut: No display function!");
203 VisibilityFunc(GLUT_VISIBLE);
210void glutInitDisplayMode(
unsigned int mode)
215void glutInitWindowPosition(
int x,
int y)
220void glutInitWindowSize(
int x,
int y)
225int glutCreateWindow(
const char* title)
232void glutPostRedisplay(
void)
237void glutSwapBuffers(
void)
241int glutGet(GLenum type)
247void* pglutAllocDmaMem(
unsigned int num_bytes)
250 return memalign(16, num_bytes);
253void pglutFreeDmaMem(
void* mem)
262void normal_main_loop()
264 bool firstTime =
true;
268 Timer0 =
new CEETimer(CEETimer::Timer0);
269 mInitTimers(Timer0, CEETimer::BusClock_256th);
272 ReshapeFunc(640, 448);
277 mStartTimer(
"frame time");
281 if (Pad0.WasPushed(Pads::kStart))
287 mStartTimer(
"DisplayFunc()");
291 mStopTimer(
"DisplayFunc()");
295 mStartTimer(
"IdleFunc()");
297 mStopTimer(
"IdleFunc()");
300 mStartTimer(
"wait for vu1");
302 pglFinishRenderingGeometry(PGL_DONT_FORCE_IMMEDIATE_STOP);
305 mStopTimer(
"wait for vu1");
307 mStopTimer(
"frame time");
324 static int frameCount = 0;
327 if (Pad0.WasPushed(Pads::kLeftUp)) {
328 SpecialFunc(GLUT_KEY_UP, 0, 0);
331 if (Pad0.WasPushed(Pads::kLeftDown)) {
332 SpecialFunc(GLUT_KEY_DOWN, 0, 0);
335 if (Pad0.WasPushed(Pads::kLeftRight)) {
336 SpecialFunc(GLUT_KEY_RIGHT, 0, 0);
339 if (Pad0.WasPushed(Pads::kLeftLeft)) {
340 SpecialFunc(GLUT_KEY_LEFT, 0, 0);
344 if (Pad0.WasPushed(Pads::kL1)) {
345 SpecialFunc(GLUT_KEY_HOME, 0, 0);
348 if (Pad0.WasPushed(Pads::kL2)) {
349 SpecialFunc(GLUT_KEY_END, 0, 0);
353 if (Pad0.WasPushed(Pads::kR1)) {
354 SpecialFunc(GLUT_KEY_PAGE_UP, 0, 0);
357 if (Pad0.WasPushed(Pads::kR2)) {
358 SpecialFunc(GLUT_KEY_PAGE_DOWN, 0, 0);
364 if (Pad0.IsDown(Pads::kRightUp)) {
365 KeyboardFunc(
'8', 0, 0);
368 if (Pad0.IsDown(Pads::kRightDown)) {
369 KeyboardFunc(
'2', 0, 0);
372 if (Pad0.IsDown(Pads::kRightLeft)) {
373 KeyboardFunc(
'4', 0, 0);
376 if (Pad0.IsDown(Pads::kRightRight)) {
377 KeyboardFunc(
'6', 0, 0);
382 if (frameCount > 40 && frameCount % 3 == 0) {
385 if (Pad0.IsDown(Pads::kLeftUp)) {
386 SpecialFunc(GLUT_KEY_UP, 0, 0);
388 if (Pad0.IsDown(Pads::kLeftDown)) {
389 SpecialFunc(GLUT_KEY_DOWN, 0, 0);
391 if (Pad0.IsDown(Pads::kLeftRight)) {
392 SpecialFunc(GLUT_KEY_RIGHT, 0, 0);
394 if (Pad0.IsDown(Pads::kLeftLeft)) {
395 SpecialFunc(GLUT_KEY_LEFT, 0, 0);
398 if (Pad0.IsDown(Pads::kL1)) {
399 SpecialFunc(GLUT_KEY_HOME, 0, 0);
401 if (Pad0.IsDown(Pads::kL2)) {
402 SpecialFunc(GLUT_KEY_END, 0, 0);
405 if (Pad0.IsDown(Pads::kR1)) {
406 SpecialFunc(GLUT_KEY_PAGE_UP, 0, 0);
408 if (Pad0.IsDown(Pads::kR2)) {
409 SpecialFunc(GLUT_KEY_PAGE_DOWN, 0, 0);
414 if (Pad0.IsDown(Pads::kRightUp)) {
415 KeyboardFunc(
'8', 0, 0);
417 if (Pad0.IsDown(Pads::kRightDown)) {
418 KeyboardFunc(
'2', 0, 0);
420 if (Pad0.IsDown(Pads::kRightLeft)) {
421 KeyboardFunc(
'4', 0, 0);
423 if (Pad0.IsDown(Pads::kRightRight)) {
424 KeyboardFunc(
'6', 0, 0);
436 pgl_slot_handle_t frame_slot_0, frame_slot_1, depth_slot;
446 pgl_area_handle_t frame_area_0, frame_area_1, depth_area;
void glutVisibilityFunc(void(*func)(int state))
void glutSpecialFunc(void(*func)(int key, int x, int y))
void glutReshapeFunc(void(*func)(int width, int height))
void glutIdleFunc(void(*func)(void))
void glutInit(int *argcp, char **argv)
void glutDisplayFunc(void(*func)(void))
void glutKeyboardFunc(void(*func)(unsigned char key, int x, int y))
void pglBindGsMemAreaToSlot(pgl_area_handle_t mem_area, pgl_slot_handle_t mem_slot)
pgl_area_handle_t pglCreateGsMemArea(int width, int height, unsigned int pix_format)
pgl_slot_handle_t pglAddGsMemSlot(int startingPage, int pageLength, unsigned int pixelMode)
void pglLockGsMemSlot(pgl_slot_handle_t slot_handle)
int pglHasGsMemBeenInitted(void)
void pglPrintGsMemAllocation(void)
void pglSetDisplayBuffers(int interlaced, pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem)
void pglSetDrawBuffers(int interlaced, pgl_area_handle_t frame0_mem, pgl_area_handle_t frame1_mem, pgl_area_handle_t depth_mem)
void pglSwapBuffers(void)
int pglHasLibraryBeenInitted(void)
void pglWaitForVSync(void)
int pglInit(int immBufferVertexSize, int immDrawBufferQwordSize)