Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Various minor tweaks

  • Loading branch information...
commit ef88d0dacad09d7d41fefb144bd4d496de1c9a49 1 parent 62b6788
Josiah Worcester authored

Showing 1 changed file with 31 additions and 35 deletions. Show diff stats Hide diff stats

  1. +31 35 mako-vm.c
66 mako-vm.c
@@ -31,6 +31,10 @@ static int sound_playing;
31 31 static uint32_t execution_start;
32 32 static int stored;
33 33
  34 +#if USE_GL
  35 +static uint32_t buf[240][320];
  36 +#endif
  37 +
34 38 static void draw(SDL_Surface*);
35 39
36 40 static void push(int32_t v)
@@ -121,6 +125,10 @@ static void sync() {
121 125 glLoadIdentity();
122 126 glEnable(GL_TEXTURE_2D);
123 127 glGenTextures(1, &tex);
  128 + glBindTexture(GL_TEXTURE_2D, tex);
  129 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  130 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  131 + glTexImage2D(GL_TEXTURE_2D, 0, 3, 320, 240, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf);
124 132 #else
125 133 scr = SDL_SetVideoMode(320, 240, 32, SDL_SWSURFACE);
126 134 #endif
@@ -175,7 +183,6 @@ static void sync() {
175 183 draw(scr);
176 184
177 185 uint32_t total = SDL_GetTicks() - execution_start;
178   -
179 186 if(total < 1000/60)
180 187 SDL_Delay(1000/60 - total);
181 188
@@ -218,6 +225,7 @@ static void tick() {
218 225 case OP_SLT: goto SLT; \
219 226 case OP_NEXT: goto NEXT; \
220 227 case OP_SYNC: goto SYNC; \
  228 + default: goto EXIT; \
221 229 }
222 230
223 231 STEP;
@@ -317,13 +325,12 @@ static void tick() {
317 325 SYNC:
318 326 sync();
319 327 STEP;
320   -}
321 328
322   -#if USE_GL
323   -static uint32_t buf[240][320];
324   -#endif
  329 +EXIT:
  330 + exit(1);
  331 +}
325 332
326   -static void draw_pixel(SDL_Surface *scr, uint32_t x, uint32_t y, uint32_t col)
  333 +static void draw_pixel(SDL_Surface *scr, int32_t x, int32_t y, uint32_t col)
327 334 {
328 335 if((col & 0xFF000000) != 0xFF000000) return;
329 336 if(x < 0 || x >= 320 || y < 0 || y >= 240) return;
@@ -352,29 +359,25 @@ static void draw_sprite(SDL_Surface *scr, int32_t tile, int32_t status, int px,
352 359 if (status % 2 == 0) return;
353 360 int w = (((status & 0x0F00) >> 8) + 1) * 8;
354 361 int h = (((status & 0xF000) >> 12) + 1) * 8;
  362 + int i = m[ST] + (tile * w * h);
355 363
356   - int xd = 1;
357   - int yd = 1;
358   - int x0 = 0;
359   - int y0 = 0;
360   - int x1 = w;
361   - int y1 = h;
362   -
363   - if ((status & H_MIRROR_MASK) != 0) {
364   - xd = -1;
365   - x0 = w - 1;
366   - x1 = -1;
367   - }
368   - if((status & V_MIRROR_MASK) != 0) {
369   - yd = -1;
370   - y0 = h - 1;
371   - y1 = -1;
  364 + if((status & H_MIRROR_MASK) == 0 && (status & V_MIRROR_MASK) == 0) {
  365 + for(int y = 0; y != w; y++)
  366 + for(int x = 0; x != h; x++)
  367 + draw_pixel(scr, x+px, y+py, m[i++]);
  368 + } else if((status & H_MIRROR_MASK) == 0) {
  369 + for(int y = 0; y != w; y++)
  370 + for(int x = w; x != 0; x--)
  371 + draw_pixel(scr, x+px, y+py, m[i++]);
  372 + } else if((status & V_MIRROR_MASK) == 0) {
  373 + for(int y = w; y != 0; y--)
  374 + for(int x = 0; x != h; x++)
  375 + draw_pixel(scr, x+px, y+py, m[i++]);
  376 + } else {
  377 + for(int y = w; y != 0; y--)
  378 + for(int x = h; x != 0; x--)
  379 + draw_pixel(scr, x+px, y+py, m[i++]);
372 380 }
373   -
374   - int i = m[ST] + (tile * w * h);
375   - for(int y = y0; y != y1; y+=yd)
376   - for(int x = x0; x != x1; x+=xd)
377   - draw_pixel(scr, x+px, y+py, m[i++]);
378 381 }
379 382
380 383 static void draw_grid(SDL_Surface *scr, int zbit)
@@ -423,15 +426,10 @@ static void draw(SDL_Surface *scr)
423 426 draw_grid(scr, 1);
424 427
425 428 #if USE_GL
426   - glClearColor(0, 0, 0, 1);
427   - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
428   -
429   - glMatrixMode(GL_MODELVIEW);
430   - glLoadIdentity();
431 429 glBindTexture(GL_TEXTURE_2D, tex);
432 430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
433 431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
434   - glTexImage2D(GL_TEXTURE_2D, 0, 3, 320, 240, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf);
  432 + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 240, GL_BGRA, GL_UNSIGNED_BYTE, buf);
435 433 glBegin(GL_QUADS);
436 434 glTexCoord2f(0, 0); glVertex2f(0, 240);
437 435 glTexCoord2f(1, 0); glVertex2f(320, 240);
@@ -453,8 +451,6 @@ static void draw(SDL_Surface *scr)
453 451
454 452 static void snd_callback(void *userdata, uint8_t *stream, int len)
455 453 {
456   - while (snd_buf_r == snd_buf_w);
457   -
458 454 for(int i = 0; i < len && snd_buf_w != (snd_buf_r+1) % SND_BUF_SIZE; i++) {
459 455 snd_buf_r++;
460 456 snd_buf_r %= SND_BUF_SIZE;

0 comments on commit ef88d0d

Please sign in to comment.
Something went wrong with that request. Please try again.