Results 1 to 5 of 5

Thread: Optimize this code!

  1. #1

    Thread Starter
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306

    Exclamation

    Can someone please optimize my poor excuse for C code???

    PHP Code:
    /* Set a VBE video mode */
    int setVBEMode(int mode)
    {
        
    union REGS in,out;
        
    in.x.ax 0x4F02in.x.bx mode;
        
    int86(0x10,&in,&out);

        if (
    mode==0x12)
        {   
    SCREENWIDTH=640;
            
    SCREENHEIGHT=400;
            
    SCREENCOLOR=4;     /* for screen color, put the bit-depth */
        
    }
        else if (
    mode==0x13)
        {   
    SCREENWIDTH=320;
            
    SCREENHEIGHT=200;
            
    SCREENCOLOR=8;     /* for screen color, put the bit-depth */
        
    }
        else if (
    mode==0x100)
        {   
    SCREENWIDTH=640;
            
    SCREENHEIGHT=400;
            
    SCREENCOLOR=8;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x101)
        {   
    SCREENWIDTH=640;
            
    SCREENHEIGHT=480;
            
    SCREENCOLOR=8;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x102)
        {   
    SCREENWIDTH=800;
            
    SCREENHEIGHT=600;
            
    SCREENCOLOR=4;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x103)
        {   
    SCREENWIDTH=800;
            
    SCREENHEIGHT=600;
            
    SCREENCOLOR=8;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x104)
        {   
    SCREENWIDTH=1024;
            
    SCREENHEIGHT=768;
            
    SCREENCOLOR=4;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x105)
        {   
    SCREENWIDTH=1024;
            
    SCREENHEIGHT=768;
            
    SCREENCOLOR=8;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x106)
        {   
    SCREENWIDTH=1280;
            
    SCREENHEIGHT=1024;
            
    SCREENCOLOR=4;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x107)
        {   
    SCREENWIDTH=1280;
            
    SCREENHEIGHT=1024;
            
    SCREENCOLOR=8;     /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x108)
        {   
    SCREENWIDTH=80;
            
    SCREENHEIGHT=60;
            
    SCREENCOLOR=1;     /* TEXT */
        
    }
        else if(
    mode==0x109)
        {   
    SCREENWIDTH=132;
            
    SCREENHEIGHT=25;
            
    SCREENCOLOR=1;     /* TEXT */
        
    }
        else if(
    mode==0x10a)
        {   
    SCREENWIDTH=132;
            
    SCREENHEIGHT=43;
            
    SCREENCOLOR=1;     /* TEXT */
        
    }
        else if(
    mode==0x10b)
        {   
    SCREENWIDTH=132;
            
    SCREENHEIGHT=50;
            
    SCREENCOLOR=1;     /* TEXT */
        
    }
        else if(
    mode==0x10c)
        {   
    SCREENWIDTH=132;
            
    SCREENHEIGHT=60;
            
    SCREENCOLOR=1;     /* TEXT */
        
    }
        else if(
    mode==0x10d)
        {   
    SCREENWIDTH=320;
            
    SCREENHEIGHT=200;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x10e)
        {   
    SCREENWIDTH=320;
            
    SCREENHEIGHT=200;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x10f)
        {   
    SCREENWIDTH=320;
            
    SCREENHEIGHT=200;
            
    SCREENCOLOR=24;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x110)
        {   
    SCREENWIDTH=640;
            
    SCREENHEIGHT=480;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x111)
        {   
    SCREENWIDTH=640;
            
    SCREENHEIGHT=480;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x112)
        {   
    SCREENWIDTH=640;
            
    SCREENHEIGHT=480;
            
    SCREENCOLOR=24;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x113)
        {   
    SCREENWIDTH=800;
            
    SCREENHEIGHT=600;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x114)
        {   
    SCREENWIDTH=800;
            
    SCREENHEIGHT=600;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x115)
        {   
    SCREENWIDTH=800;
            
    SCREENHEIGHT=600;
            
    SCREENCOLOR=24;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x116)
        {   
    SCREENWIDTH=1024;
            
    SCREENHEIGHT=768;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x117)
        {   
    SCREENWIDTH=1024;
            
    SCREENHEIGHT=768;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x118)
        {   
    SCREENWIDTH=1024;
            
    SCREENHEIGHT=768;
            
    SCREENCOLOR=24;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x119)
        {   
    SCREENWIDTH=1280;
            
    SCREENHEIGHT=1024;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x11a)
        {   
    SCREENWIDTH=1280;
            
    SCREENHEIGHT=1024;
            
    SCREENCOLOR=16;    /* for screen color, put the bit-depth */
        
    }
        else if(
    mode==0x11b)
        {   
    SCREENWIDTH=1280;
            
    SCREENHEIGHT=1024;
            
    SCREENCOLOR=24;    /* for screen color, put the bit-depth */
        
    }
        else
            return 
    0/* Not a VESA/VGA mode */

        
    return 1;     /* The mode was set correctly */

    Designer/Programmer of the Comtech Operating System(CTOS)

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    A Switch/Case statement is going to be faster for you
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3

    Thread Starter
    Hyperactive Member Warmaster199's Avatar
    Join Date
    Aug 2000
    Location
    Canada
    Posts
    306

    Red face DOH!

    DOH!!! How come I didn't think of that??? I am so stupid... Thankyou for reminding me of those...
    Designer/Programmer of the Comtech Operating System(CTOS)

  4. #4
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    hehe no problem
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  5. #5
    Lively Member
    Join Date
    Apr 2001
    Location
    Central NC
    Posts
    75
    Now, if I wanted to squeeze every last microsecond out of my code, I'd put all those values into an array and index to them with the mode.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width