X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fpc%2Fmain.c;fp=src%2Fpc%2Fmain.c;h=df6a3f7cb748c6519574e2f8cbb0aa6b870a4bdb;hb=b0f9c6ecc15c2d4b5df77a7a963b742a6352ee1a;hp=91ce9daaf45a1e1ee92185443e19d3d122b0a72d;hpb=bb895563088da093a90f42fc6a532688adc36cf2;p=gbajam22 diff --git a/src/pc/main.c b/src/pc/main.c index 91ce9da..df6a3f7 100644 --- a/src/pc/main.c +++ b/src/pc/main.c @@ -5,8 +5,11 @@ #include "miniglut.h" #include "game.h" #include "gba.h" +#include "input.h" +#include "debug.h" static void display(void); +static void vblank(void); static void idle(void); static void reshape(int x, int y); static void keydown(unsigned char key, int x, int y); @@ -24,6 +27,8 @@ static unsigned char keystate[256]; static unsigned long start_time; static unsigned int modkeys; +static uint16_t bnstate, bnmask; + static float win_aspect; static unsigned int tex; @@ -89,26 +94,61 @@ int main(int argc, char **argv) glLoadIdentity(); glScalef(240.0f / tex_xsz, 160.0f / tex_ysz, 1); - gamescr(); + intr_disable(); + interrupt(INTR_VBLANK, vblank); + unmask(INTR_VBLANK); + intr_enable(); + + if(init_screens() == -1) { + fprintf(stderr, "failed to initialize screens"); + return 1; + } + + if(change_screen(find_screen("game")) == -1) { + fprintf(stderr, "failed to find game screen"); + return 1; + } + + glutMainLoop(); return 0; } -void blit_frame(void *pixels, int vsync) +void select_input(uint16_t bmask) +{ + bnstate = 0; + bnmask = bmask; +} + +uint16_t get_input(void) +{ + uint16_t s = bnstate; + bnstate = 0; + return s; +} + +#define PACK_RGB32(r, g, b) \ + ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff) | 0xff000000) + +#define UNPACK_R16(c) (((c) >> 9) & 0xf8) +#define UNPACK_G16(c) (((c) >> 3) & 0xf8) +#define UNPACK_B16(c) (((c) << 3) & 0xf8) + +void present(int buf) { - int i, npix = fb_width * fb_height; + int i, npix = 240 * 160; uint32_t *dptr = convbuf; - uint16_t *sptr = pixels; + uint8_t *sptr = buf ? gba_vram_lfb1 : gba_vram_lfb0; for(i=0; iframe(); } - return keystate[key]; } -static void display(void) +static void vblank(void) { - inp_update(); + vblperf_count++; - time_msec = get_msec(); - draw(); + if(curscr && curscr->vblank) { + curscr->vblank(); + } } static void idle(void) @@ -174,62 +203,70 @@ static void reshape(int x, int y) glViewport(0, 0, x, y); } +static int bnmap(int key) +{ + switch(key) { + case GLUT_KEY_LEFT: + return BN_LEFT; + case GLUT_KEY_RIGHT: + return BN_RIGHT; + case GLUT_KEY_UP: + return BN_UP; + case GLUT_KEY_DOWN: + return BN_DOWN; + case 'x': + return BN_A; + case 'z': + return BN_B; + case 'a': + return BN_LT; + break; + case 's': + return BN_RT; + case ' ': + return BN_SELECT; + case '\n': + return BN_START; + default: + break; + } + return -1; +} + static void keydown(unsigned char key, int x, int y) { - modkeys = glutGetModifiers(); + int bn = bnmap(key); + if(bn != -1) { + bnstate |= bn; + } - keystate[key] = 1; - //game_key(key, 1); + if(key == 27) { + exit(0); + } } static void keyup(unsigned char key, int x, int y) { - keystate[key] = 0; - //game_key(key, 0); + int bn = bnmap(key); + if(bn != -1) { + bnstate &= ~bn; + } } static void skeydown(int key, int x, int y) { - key = translate_special(key); - keystate[key] = 1; - //game_key(key, 1); + int bn = bnmap(key); + if(bn != -1) { + bnstate |= bn; + } } static void skeyup(int key, int x, int y) { - key = translate_special(key); - keystate[key] = 0; - //game_key(key, 0); -} - -static int translate_special(int skey) -{ - switch(skey) { - case 127: - return 127; -/* case GLUT_KEY_LEFT: - return KB_LEFT; - case GLUT_KEY_RIGHT: - return KB_RIGHT; - case GLUT_KEY_UP: - return KB_UP; - case GLUT_KEY_DOWN: - return KB_DOWN; - case GLUT_KEY_PAGE_UP: - return KB_PGUP; - case GLUT_KEY_PAGE_DOWN: - return KB_PGDN; - case GLUT_KEY_HOME: - return KB_HOME; - case GLUT_KEY_END: - return KB_END; - default: - if(skey >= GLUT_KEY_F1 && skey <= GLUT_KEY_F12) { - return KB_F1 + skey - GLUT_KEY_F1; - } - */ + int bn = bnmap(key); + if(bn != -1) { + bnstate &= ~bn; } - return 0; } static unsigned int next_pow2(unsigned int x)