fixed 16bpp offsets in csprite generator (hardcoded for now)
[dosdemo] / src / screen.c
index a0faa4b..68a8c7f 100644 (file)
@@ -1,26 +1,71 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 #include "screen.h"
 #include "demo.h"
 
 struct screen *tunnel_screen(void);
+struct screen *fract_screen(void);
+struct screen *grise_screen(void);
+struct screen *polytest_screen(void);
+struct screen *plasma_screen(void);
+struct screen *bump_screen(void);
+struct screen *thunder_screen(void);
+struct screen *metaballs_screen(void);
+struct screen *greets_screen(void);
+struct screen *infcubes_screen(void);
+struct screen *hairball_screen(void);
 
-#define NUM_SCR        1
+#define NUM_SCR 32
 static struct screen *scr[NUM_SCR];
+static int num_screens;
 
 static struct screen *cur, *prev, *next;
 static long trans_start, trans_dur;
 
 int scr_init(void)
 {
-       int i;
+       int i, idx = 0;
 
-       if(!(scr[0] = tunnel_screen())) {
+       if(!(scr[idx++] = tunnel_screen())) {
+               return -1;
+       }
+       if(!(scr[idx++] = fract_screen())) {
+               return -1;
+       }
+       if (!(scr[idx++] = grise_screen())) {
+               return -1;
+       }
+       if(!(scr[idx++] = polytest_screen())) {
+               return -1;
+       }
+       if (!(scr[idx++] = plasma_screen())) {
+               return -1;
+       }
+       if (!(scr[idx++] = bump_screen())) {
+               return -1;
+       }
+       if (!(scr[idx++] = thunder_screen())) {
+               return -1;
+       }
+       if(!(scr[idx++] = metaballs_screen())) {
                return -1;
        }
+       if(!(scr[idx++] = greets_screen())) {
+               return -1;
+       }
+       if(!(scr[idx++] = infcubes_screen())) {
+               return -1;
+       }
+       if(!(scr[idx++] = hairball_screen())) {
+               return -1;
+       }
+       num_screens = idx;
+
+       assert(num_screens <= NUM_SCR);
 
-       for(i=0; i<NUM_SCR; i++) {
+       for(i=0; i<num_screens; i++) {
                if(scr[i]->init() == -1) {
                        return -1;
                }
@@ -31,17 +76,19 @@ int scr_init(void)
 void scr_shutdown(void)
 {
        int i;
-       for(i=0; i<NUM_SCR; i++) {
+       for(i=0; i<num_screens; i++) {
                scr[i]->shutdown();
        }
 }
 
 void scr_update(void)
 {
-       if(prev) {      /* we're in the middle of a transition */
+       if(prev) {  /* we're in the middle of a transition */
                long interval = time_msec - trans_start;
                if(interval >= trans_dur) {
-                       next->start(trans_dur);
+                       if(next->start) {
+                               next->start(trans_dur);
+                       }
                        prev = 0;
                        cur = next;
                        next = 0;
@@ -49,15 +96,28 @@ void scr_update(void)
        }
 }
 
+
 void scr_draw(void)
 {
-       if(cur) cur->draw();
+       if(cur) {
+               cur->draw();
+
+               /* print screen name */
+               cs_puts(fb_pixels, 0, 0, cur->name);
+       }
+}
+
+void scr_keypress(int key)
+{
+       if(cur && cur->keypress) {
+               cur->keypress(key);
+       }
 }
 
 struct screen *scr_lookup(const char *name)
 {
        int i;
-       for(i=0; i<NUM_SCR; i++) {
+       for(i=0; i<num_screens; i++) {
                if(strcmp(scr[i]->name, name) == 0) {
                        return scr[i];
                }
@@ -65,25 +125,36 @@ struct screen *scr_lookup(const char *name)
        return 0;
 }
 
+struct screen *scr_screen(int idx)
+{
+       return scr[idx];
+}
+
+int scr_num_screens(void)
+{
+       return num_screens;
+}
+
 int scr_change(struct screen *s, long trans_time)
 {
        if(!s) return -1;
        if(s == cur) return 0;
 
        if(trans_time) {
-               trans_dur = trans_time / 2;     /* half for each part transition out then in */
+               trans_dur = trans_time / 2; /* half for each part transition out then in */
                trans_start = time_msec;
        } else {
                trans_dur = 0;
        }
 
-       if(cur) {
+       if(cur && cur->stop) {
                cur->stop(trans_dur);
-
                prev = cur;
                next = s;
        } else {
-               s->start(trans_dur);
+               if(s->start) {
+                       s->start(trans_dur);
+               }
 
                cur = s;
                prev = 0;