 #include <avr/pgmspace.h>
 Arduboy display;
 
+// Game options
+// Interpreter size tuning (turning off some interpreter support can save PROGMEM memory, but code must not contain related bytecodes (unless stated!)
+
+#define SOUND ON             // 574 bytes (If support is disabled, bytecode is skipped properly)
+#define SERIAL OFF           // 182 bytes (no impact on bytecode interpreting)
+
+#define VARIABLES ON
+#define MUSIC ON
+#define SFXLIB ON            // 496 bytes (If support is disabled, bytecode is skipped properly)
+#define VECTOR ON
+
+// Button definition
+
 #define FIRE_BUTTON 1
 #define JUMP_BUTTON 2
 #define RIGHT 4

             x++; 
      }  
      x = 0; 
      if(sound == 1) { display.tunes.tone(1318, 50); }
      display.fillRect(display.getCursorX(),display.getCursorY(),8,8,BLACK); display.display();
      display.print("\nB] ");  display.display(); col=3;
       while(1) { 
             if(exitb[x] == 0) { break; } 
             printer(exitb[x]);

  showIntro();
  display.clearDisplay();
  display.display();
  #if SERIAL == ON
  Serial.begin(9600);
  #endif
}

void loop() {
startVM(0);
}

void showIntro()    // Show Arduino retro intro
{
   for(int i=-8; i<28; i=i+2) {
    display.clearDisplay();
    display.drawSlowXYBitmap(46,i, arduino, 32,8,1);
    display.display();
    delay(1000/30);
  }  
  #if SOUND == ON
   display.tunes.tone(987, 160);
    delay(160);
   display.tunes.tone(1318, 400);
   delay(2000);
  #endif
}

void startVM(uint16_t pc) {
 while(1) {  
  uint16_t type = pgm_read_byte_near(&(gti[pc])) << 8 | pgm_read_byte_near(&(gti[pc+1])) & 0xFF;  // Read in type of frame
  pc++;                                                                                           // bump program counter
  col = 0;                                                                                        // reset columns in text display
  if(type == 65535) {                                                                             // SPECIAL Frame Detected
     pc++;                                                                                        // bump program counter
     uint8_t mode = pgm_read_byte_near(&(gti[pc]));                                               // get the special packet mode

     switch (mode) {                                                                              // switch based on what mode the frame is

       // 0x00 - Game Over

       case 0:                                                                                    // Game Over handler
           while(1) {                                                                             // loop over text until we hit a null
             pc++;                                                                                // bump program counter
             uint8_t buff = pgm_read_byte_near(&(gti[pc]));                                       // read a chracter
             if(buff == 0) { break; }                                                             // is it a null? then we are done printing text
             printer(pgm_read_byte_near(&(gti[pc])));                                             // print out the text using our text output handler
           }
           display.print("*GAME OVER*");                                                          // print generic Game Over message
           #if SERIAL == ON
           Serial.print("*GAME OVER*");                                                           // if the serial port is turned on, print message over serial
           #endif
           anykey();                                                                              // wait for anykey
           col = 0;                                                                               // reset the columns (probably not needed)
           return;                                                                                // quit out of the VM
           break;                                                                                 // break that will not be executed
           
       // 0x05 - Jump    
           
       case 5:                                                                                    // Jump handler
           pc++;                                                                                  // bump the program counter
           pc = pgm_read_byte_near(&(gti[pc])) << 8 | pgm_read_byte_near(&(gti[pc+1])) & 0xFF;    // Set the program counter to the address in 16 bit field
           break;                                                                                 // switch break
           
       // 0x0D - Effects Library    

       case 13:                                                                                   // Effects Handler
       #if SFXLIB == ON                                                                           // If our effects library is switched on
            pc++;                                                                                 // Bump program counter
            effect = pgm_read_byte_near(&(gti[pc]));                                              // Get effect type
            
            switch(effect) {                                                                      // Effect switcher
            
               // 0x00 - Low pitched rumbling sound
            
               case 0:                                                                            // rumble handler
                   #if SOUND == ON                                                                // Is sound turned on?
                   for(int x = 60; x < 150; x++) {                                                // Low frequency sweep 
                   display.tunes.tone(x, 10);  delay(10); }                                       // Play our low frequency sweep
                   #endif                                                                         // end sound check
                   break;                                                                         // switch break
                  
               // 0x01 - Random lightning flash   
                   
               case 1:                                                                            // Random lightning flash 
                   for(int x = 0; x < 100; x++) {                                                 // Small loop for our flashes
                     if(random(0,10) == 1) {                                                      // 1 in 10 chance of a flash
                            display.fillScreen(WHITE);                                            // Fill screen with white
                            display.display();                                                    // push it out
                     } 
                     else {                                                                       // Not a 1 in 10 chance?
                            display.fillScreen(BLACK);                                            // Make screen black
                            display.display();                                                    // Push it out
                     } 
                   }
                   break;                                                                         // switch break
            }  
            pc++;                                                                                 // Bump program counter
       #else                                                                                      // Otherwise, is the SFX mode disabled?
         pc++; pc++;                                                                              // Increment program counter so we dont lose position
       #endif
            break;                                                                                // switch break

       // 0x10 - Display page of text and wait for any key
       
       case 16:                                                                                   // text handler
           while(1) {                                                                             // print some text until we find a null
             pc++;                                                                                // Bump program counter
             uint8_t buff = pgm_read_byte_near(&(gti[pc]));                                       // Read a character
             if(buff == 0) { break; }                                                             // Is it null? then break out of loop
             printer(pgm_read_byte_near(&(gti[pc])));                                             // Send text off to our printer 
           }         
           anykey();                                                                              // Wait for any key 
           pc++;                                                                                  // Bump program counter
           break;                                                                                 // Switch case break
    }
  }
  
  // We did not find a SPECIAL frame, so we assume it is a NORMAL frame (and per framing format, it must be)
  // We reuse the 'type' uint16_t variable as jump a's address
  
  else {    

     // Jump A description buffer
    
      pc++;                                                                                                   // bump program counter
      uint16_t alterexit = pgm_read_byte_near(&(gti[pc])) << 8 | pgm_read_byte_near(&(gti[pc+1])) & 0xFF;     // get jump b address
      pc++; pc++;                                                                                             // bump program counter
      int i = 0;                                                                                              // initalize i (to keep track of array position)
      while(1 == 1) {                                                                                         // fill jump a description buffer
        uint8_t buff = pgm_read_byte_near(&(gti[pc]));                                                        // get a chracter
        if(buff == 0) { exita[i] = 0; break; }                                                                // Is it null? append the null to array then stop
        exita[i] = buff;                                                                                      // fill array with newest character
        i++; pc++;                                                                                            // bump array position and program counter
      }

     // Jump B description buffer
      
      pc++;                                                                                                   // bump program counter
      i = 0;                                                                                                  // reset array position
      while(1 == 1) {                                                                                         // fill jump b description buffer 
        uint8_t buff = pgm_read_byte_near(&(gti[pc]));                                                        // get a character
        if(buff == 0) { exitb[i] = 0; break; }                                                                // Is it null? append the null to array then stop
        exitb[i] = buff;                                                                                      // fill array with newest character
        i++; pc++;                                                                                            // bump array position and program counter
      } 
      
      int x = 0;                                                                                              // define x (we could probably still reuse i?)
 
      // Main description printing (since the description goes before the jump selections)
      
      while(1) {                                                                                              // print the main description text, null terminated
             pc++;                                                                                            // bump program counter
             uint8_t buff = pgm_read_byte_near(&(gti[pc]));                                                   // get character from main description
             if(buff == 0) { break; }                                                                         // did we find a null? stop printing description
             printer(pgm_read_byte_near(&(gti[pc])));                                                         // Print out our newest character
      }  
      pc++; 
      #if SOUND == ON
      display.tunes.tone(1318, 50); 
      #endif
      display.fillRect(display.getCursorX(),display.getCursorY(),8,8,BLACK); display.display();
      if(display.getCursorY() < 40) { display.print("\n"); 
      #if SERIAL == ON
      Serial.println();
      #endif
      } 
      
      display.print("\nA] ");  display.display();  col=3; 
      #if SERIAL == ON
      Serial.print("\nA] ");
      #endif
       x = 0;
       while(1) { 
             if(exita[x] == 0) { break; } 
