Quantcast

Results 1 to 13 of 13

Thread: Time to update to gcc 4.6.2!

  1. #1
    ESWAT Veteran Chilly Willy's Avatar
    Join Date
    Feb 2009
    Posts
    5,795
    Rep Power
    50

    Default Time to update to gcc 4.6.2!

    Building a Genesis/32X toolchain

    1 - Go here and download the following:

    gcc-4.6.2.tar.bz2

    Decompress it to wherever you keep your projects; you should end up with a folder called gcc-4.6.2.

    2.1 - Go here and download mpfr-2.4.2.tar.bz2.
    2.2 - Go here and download mpc-0.9.tar.gz.
    2.3 - Go here and download gmp-5.0.4.tar.bz2.

    Decompress them all in the same folder. You should have three folders called mpfr-2.4.2, mpc-0.9, and gmp-5.0.4. Rename them to get rid of the version numbers, leaving you with mpfr, mpc, and gmp. Copy them into the gcc-4.6.2 folder.

    3 - Go here and download binutils-2.22.tar.bz2.

    Decompress it in the same folder as the gcc folder so that you have two folders - gcc-4.6.2 and binutils-2.22.

    4 - Go here and download newlib-1.20.0.tar.gz.

    Decompress it in the same folder as gcc and binutils, leaving you with the folders - gcc-4.6.2, binutils-2.22, and newlib-1.20.0.

    5 - Get this archive and decompress it to the same place as the previous directories. You should have two more directories, bin and ldscripts, in addition to the file, makefile-sega.

    6 - If you wish to leave the makefile with the default path of /opt/toolchains/sega, make sure you have permission to write to /opt or the toolchain will fail to install to the path. Since there's nothing critical in /opt, it's easiest just to do "sudo chmod 777 -R /opt" which allows anyone to do anything they want in /opt.

    7 - Run "make -f makefile-sega" - depending on the speed of your computer, in an hour or two you should have two toolchains in /opt/toolchains/sega: m68k-elf and sh-elf. Copy the ldscripts and bin directories to /opt/toolchains/sega.

    You now have the latest gcc, binutils, and newlib for both the 68000 and the SH2. Both have compilers for C, C++, Objective-C, and Objective-C++. The bin directory has a few common tools one might use for compiling Z80 code for the MD. Copy whatever other tools you use into it, like sixpack or bin2c.

    Note: The size of the built toolchain can be reduced by stripping the debug symbols from the executables in the bin directories, and by deleting the libraries meant for CPUs other than the 68000 and SH2. For example, you don't need the libraries for the 68020 or 68040 or SH3 or SH4, etc.


    Here is an archive with example code - it includes Tic-Tac-Toe in both C and C++ for both the MD and the 32X. You should be able to compile them with the toolchain you just built. They should run on an emulator like Kega Fusion or Gens/GS, or on a real MD/32X with a flash cart.

    Here are a few archives of things I've built for the 32X using the toolchain. They should all build and run fine using this toolchain.
    32xrick-20120212.7z
    Wolf32X-20120212.7z
    TremorTest-20120212.7z
    yeti3d-20120212.7z

    Here is an archive with three libraries. You will need them for the Tremor example. Build them BEFORE trying to build the Tremor test. Be sure to run "make install" to install the libraries into the toolchain so it can find them.


    Note: You don't need to set any environment variables for this toolchain as long as you use the default path for the toolchain (/opt/toolchains/sega). The examples and games come with a binary image for people who wish to try them without needing to build anything.

  2. #2
    Smith's Minister of War Raging in the Streets Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Portugal
    Age
    23
    Posts
    4,564
    Rep Power
    51

    Default

    Thanks, I can't wait till I finally have time to start my MD project. Just a few more months... almost...
    This thread needs more... ENGINEERS

  3. #3
    Mortal Kombat expert Master of Shinobi N.Saibot's Avatar
    Join Date
    Sep 2009
    Location
    Germany
    Age
    27
    Posts
    1,135
    Rep Power
    12

    Default

    Wow, gcc compiling stuff for the Mega Drive? I thought you needed some other compiler for the M68K.

    Is it a good idea to compile object oriented programs in C++ with the gcc for the Mega Drive? I'm kind of writing a textadventure right now, if it will be ever done I might look into porting it to Segas 16-Bit wonder.

    Free your music,

  4. #4
    ESWAT Veteran Chilly Willy's Avatar
    Join Date
    Feb 2009
    Posts
    5,795
    Rep Power
    50

    Default

    C++ on the MD is fine, just be careful about which libraries you use. For example, iostream shouldn't be used as it bloats the program considerably... not to mention the functions aren't really useful on the MD in any case. Modern compilers like gcc can make C++ nearly as fast as C, so as long as you're careful about the memory usage, it's still a viable language for programming the MD.

  5. #5
    Mortal Kombat expert Master of Shinobi N.Saibot's Avatar
    Join Date
    Sep 2009
    Location
    Germany
    Age
    27
    Posts
    1,135
    Rep Power
    12

    Default

    This sounds bad, since I use iostream for cin and cout. It is also the only means of input-output in C that I've learned so far.
    The game is textbased, so every command the player will type in is read through cin and every reaction is output through cout. I believe this will be the only reason for dependency on iostream.

    What do you usually do to output simple text on the Mega Drive, if not cout?

    Free your music,

  6. #6
    Raging in the Streets TrekkiesUnite118's Avatar
    Join Date
    May 2010
    Age
    25
    Posts
    4,333
    Rep Power
    41

    Default

    Well the issue with it is that the system has no basic text graphics to know how to print and read input like that. So you'd basically need to create your own system of doing that if I remember correctly.

    For example the equivalent of Hello World on these older systems isn't actually printing the words Hello World, it's making the screen Blue or something like that. You can't really write or read words when there's no alphabet to write or read words with.

  7. #7
    Mortal Kombat expert Master of Shinobi N.Saibot's Avatar
    Join Date
    Sep 2009
    Location
    Germany
    Age
    27
    Posts
    1,135
    Rep Power
    12

    Default

    I see, so porting will be much more work than I imagined. When the game has advanced enough to announce a demo, I'll do it somewhere around here : ) Development will be done for PC first of course. All ideas that I have pretty much require a real keyboard for best experience anyway.

    Free your music,

  8. #8
    Smith's Minister of War Raging in the Streets Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Portugal
    Age
    23
    Posts
    4,564
    Rep Power
    51

    Default

    The sega genesis dev kit by stef has text printing functions. You'll need to take care of input some other way since the genesis doesn't have a keyboard.
    This thread needs more... ENGINEERS

  9. #9
    Mortal Kombat expert Master of Shinobi N.Saibot's Avatar
    Join Date
    Sep 2009
    Location
    Germany
    Age
    27
    Posts
    1,135
    Rep Power
    12

    Default

    Quote Originally Posted by Kamahl View Post
    The sega genesis dev kit by stef has text printing functions. You'll need to take care of input some other way since the genesis doesn't have a keyboard.
    It's obvious that one would need some other way of text input. The first thing that comes to mind is a menu of verbs combined with a menu of available objects.

    I think I'll just develop it without wasting time to think about how to port it. It was a surprise for me that gcc compiles for the M68K as well, so naturally a Mega Drive port crossed my mind. Wether or not I'm going to do it is a completely different story, I should finish the project for some platform at first, then think about porting it second.

    Free your music,

  10. #10
    Smith's Minister of War Raging in the Streets Kamahl's Avatar
    Join Date
    Jan 2011
    Location
    Portugal
    Age
    23
    Posts
    4,564
    Rep Power
    51

    Default

    Quote Originally Posted by N.Saibot View Post
    I should finish the project for some platform at first, then think about porting it second.
    Indeed. For me it's the same.
    This thread needs more... ENGINEERS

  11. #11
    ESWAT Veteran Chilly Willy's Avatar
    Join Date
    Feb 2009
    Posts
    5,795
    Rep Power
    50

    Default

    Converting prints and couts to something that can display text on a console is often a major part of porting a project. My examples include simple printing functions so that you can fairly easily print text to the screen. So that shouldn't be TOO hard to deal with. Converting input from cin to a console is a lot more work. You need an on-screen keyboard (OSK) that uses the pad to select the letters. Here's an example - I made this for the N64, but could easily be converted to the MD.

    Code:
    int doOSKeyb(char *title, char *deflt, char *buffer, int max, int bfill)
    {
        display_context_t dcon;
        uint16_t previous = 0, buttons;
        int crsr;
        short xcoord[16] = { 0, 23, 14, 0, 17, 20, 14, 0, 20, 23, 17, 0, 0, 0, 0, 0 };
        short ycoord[16] = { 0, 7, 5, 0, 7, 7, 7, 0, 5, 5, 5, 0, 0, 0, 0, 0 };
        char *shft_text1[16] = { "", ":\"|", "!@#", "", "FGH", "JKL", "ASD", "", "&*(", ")_+", "$%^", "", "", "", "", "" };
        char *shft_text2[16] = { "", "? ~", "QWE", "", "VBN", "M<>", "ZXC", "", "UIO", "P{}", "RTY", "", "", "", "", "" };
        char *norm_text1[16] = { "", ";'\\", "123", "", "fgh", "jkl", "asd", "", "789", "0-=", "456", "", "", "", "", "" };
        char *norm_text2[16] = { "", "/ `", "qwe", "", "vbn", "m,.", "zxc", "",  "uio", "p[]", "rty", "", "", "", "", "" };
    
        memset(buffer, 0, max);
        strncpy(buffer, deflt, max-1);
        buffer[max-1] = 0;
        crsr = strlen(buffer);
    
        while (1)
        {
            // get next buffer to draw in
            dcon = lockVideo(1);
            graphics_fill_screen(dcon, 0);
    
            if (browser && (bfill == 4))
            {
                drawImage(dcon, browser);
            }
            else if ((bfill < 3) && (pattern[bfill] != NULL))
            {
                rdp_sync(SYNC_PIPE);
                rdp_set_default_clipping();
                rdp_enable_texture_copy();
                rdp_attach_display(dcon);
                // Draw pattern
                rdp_sync(SYNC_PIPE);
                rdp_load_texture(0, 0, MIRROR_DISABLED, pattern[bfill]);
                for (int j=0; j<240; j+=pattern[bfill]->height)
                    for (int i=0; i<320; i+=pattern[bfill]->width)
                        rdp_draw_sprite(0, i, j);
                rdp_detach_display();
            }
    
            // show title
            graphics_set_color(gTextColors.title, 0);
            printText(dcon, title, 20 - strlen(title)/2, 1);
    
            // print text line buffer (line 3)
            if (strlen(buffer))
            {
                graphics_set_color(gTextColors.usel_game, 0);
                printText(dcon, buffer, 20 - strlen(buffer)/2, 3);
            }
    
            {
                char temp[2];
                temp[0] = buffer[crsr];
                if ((temp[0] == 0) | (temp[0] == 0x20))
                    temp[0] = '_';
                temp[1] = 0;
                graphics_set_color(gTextColors.usel_game, gTextColors.sel_game);
                printText(dcon, temp, 20 - strlen(buffer)/2 + crsr, 3);
            }
    
            // get buttons
            buttons = getButtons(0);
    
            // draw OSK (lines 5 to 8)
            if (TR_BUTTON(buttons))
            {
                // shift held - do shift characters
                graphics_set_color(gTextColors.usel_game, 0);
                printText(dcon, "!@#$%^&*()_+", xcoord[2], ycoord[2]);
                printText(dcon, "QWERTYUIOP{}", xcoord[2], ycoord[2]+1);
                printText(dcon, "ASDFGHJKL:\"|", xcoord[6], ycoord[6]);
                printText(dcon, "ZXCVBNM<>? ~", xcoord[6], ycoord[6]+1);
    
                if ((buttons & 0x0F00) && (buttons & 0xC00F))
                {
                    short dx = -1, dy = -1;
                    // hilite square behind button being pressed
                    graphics_set_color(0, gTextColors.usel_game);
                    if (B_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 0;
                    }
                    else if (CL_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 0;
                    }
                    else if (CU_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    else if (A_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 1;
                    }
                    else if (CD_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 1;
                    }
                    else if (CR_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    if (dx >= 0)
                        printText(dcon, "_", xcoord[(buttons>>8)&15]+dx, ycoord[(buttons>>8)&15]+dy);
                }
    
                graphics_set_color(gTextColors.sel_game, 0);
                if (xcoord[(buttons>>8)&15])
                {
                    printText(dcon, shft_text1[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]);
                    printText(dcon, shft_text2[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]+1);
                }
    
            }
            else
            {
                // no shift - do normal characters
                graphics_set_color(gTextColors.usel_game, 0);
                printText(dcon, "1234567890-=", xcoord[2], ycoord[2]);
                printText(dcon, "qwertyuiop[]", xcoord[2], ycoord[2]+1);
                printText(dcon, "asdfghjkl;'\\", xcoord[6], ycoord[6]);
                printText(dcon, "zxcvbnm,./ `", xcoord[6], ycoord[6]+1);
    
                if ((buttons & 0x0F00) && (buttons & 0xC00F))
                {
                    short dx = -1, dy = -1;
                    // hilite square behind button being pressed
                    graphics_set_color(0, gTextColors.usel_game);
                    if (B_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 0;
                    }
                    else if (CL_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 0;
                    }
                    else if (CU_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    else if (A_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 1;
                    }
                    else if (CD_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 1;
                    }
                    else if (CR_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    if (dx >= 0)
                        printText(dcon, "_", xcoord[(buttons>>8)&15]+dx, ycoord[(buttons>>8)&15]+dy);
                }
    
                graphics_set_color(gTextColors.sel_game, 0);
                if (xcoord[(buttons>>8)&15])
                {
                    printText(dcon, norm_text1[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]);
                    printText(dcon, norm_text2[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]+1);
                }
            }
    
            // show display
            unlockVideo(dcon);
    
            if (buttons & 0x0F00)
            {
                // pressing a direction => OSK
                char c = 0;
    
                if (B_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text1[((buttons>>8)&15)][0] : norm_text1[((buttons>>8)&15)][0];
                else if (CL_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text1[((buttons>>8)&15)][1] : norm_text1[((buttons>>8)&15)][1];
                else if (CU_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text1[((buttons>>8)&15)][2] : norm_text1[((buttons>>8)&15)][2];
                else if (A_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text2[((buttons>>8)&15)][0] : norm_text2[((buttons>>8)&15)][0];
                else if (CD_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text2[((buttons>>8)&15)][1] : norm_text2[((buttons>>8)&15)][1];
                else if (CR_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text2[((buttons>>8)&15)][2] : norm_text2[((buttons>>8)&15)][2];
                if (c && (crsr < (max-2)))
                {
                    if (buffer[crsr] == 0)
                        buffer[crsr+1] = 0;
                    buffer[crsr] = c;
                    crsr++;
                }
            }
            else
            {
                if (A_BUTTON(buttons ^ previous))
                {
                    // A changed
                    if (!A_BUTTON(buttons))
                    {
                        // A just released - Enter
                        return strlen(buffer);
                    }
                }
                if (B_BUTTON(buttons ^ previous))
                {
                    // B changed
                    if (!B_BUTTON(buttons))
                    {
                        // B just released - Escape
                        return 0;
                    }
                }
                if (CL_BUTTON(buttons ^ previous))
                {
                    // CL changed
                    if (!CL_BUTTON(buttons))
                    {
                        // CL just released - Cursor Left
                        if (crsr > 0)
                            crsr--;
                    }
                }
                if (CR_BUTTON(buttons ^ previous))
                {
                    // CR changed
                    if (!CR_BUTTON(buttons))
                    {
                        // CR just released - Cursor Right
                        if (crsr < (strlen(buffer)))
                            crsr++;
                    }
                }
                if (CU_BUTTON(buttons ^ previous))
                {
                    // CU changed
                    if (!CU_BUTTON(buttons))
                    {
                        // CU just released - Delete
                        if (crsr > 0)
                        {
                            crsr--;
                            if (buffer[crsr+1] == 0)
                                buffer[crsr] = 0;
                            else
                                strcpy(&buffer[crsr], &buffer[crsr+1]);
                        }
                    }
                }
                if (CD_BUTTON(buttons ^ previous))
                {
                    // CD changed
                    if (!CD_BUTTON(buttons))
                    {
                        // CD just released - Space
                        if (crsr < (max-2))
                        {
                            if (buffer[crsr] == 0)
                                buffer[crsr+1] = 0;
                            buffer[crsr] = ' ';
                            crsr++;
                        }
                    }
                }
            }
    
            previous = buttons;
            delay(7);
        }
    
        return strlen(buffer);
    }

  12. #12
    Mortal Kombat expert Master of Shinobi N.Saibot's Avatar
    Join Date
    Sep 2009
    Location
    Germany
    Age
    27
    Posts
    1,135
    Rep Power
    12

    Default

    Quote Originally Posted by Chilly Willy View Post
    Converting prints and couts to something that can display text on a console is often a major part of porting a project. My examples include simple printing functions so that you can fairly easily print text to the screen. So that shouldn't be TOO hard to deal with. Converting input from cin to a console is a lot more work. You need an on-screen keyboard (OSK) that uses the pad to select the letters. Here's an example - I made this for the N64, but could easily be converted to the MD.

    Code:
    int doOSKeyb(char *title, char *deflt, char *buffer, int max, int bfill)
    {
        display_context_t dcon;
        uint16_t previous = 0, buttons;
        int crsr;
        short xcoord[16] = { 0, 23, 14, 0, 17, 20, 14, 0, 20, 23, 17, 0, 0, 0, 0, 0 };
        short ycoord[16] = { 0, 7, 5, 0, 7, 7, 7, 0, 5, 5, 5, 0, 0, 0, 0, 0 };
        char *shft_text1[16] = { "", ":\"|", "!@#", "", "FGH", "JKL", "ASD", "", "&*(", ")_+", "$%^", "", "", "", "", "" };
        char *shft_text2[16] = { "", "? ~", "QWE", "", "VBN", "M<>", "ZXC", "", "UIO", "P{}", "RTY", "", "", "", "", "" };
        char *norm_text1[16] = { "", ";'\\", "123", "", "fgh", "jkl", "asd", "", "789", "0-=", "456", "", "", "", "", "" };
        char *norm_text2[16] = { "", "/ `", "qwe", "", "vbn", "m,.", "zxc", "",  "uio", "p[]", "rty", "", "", "", "", "" };
    
        memset(buffer, 0, max);
        strncpy(buffer, deflt, max-1);
        buffer[max-1] = 0;
        crsr = strlen(buffer);
    
        while (1)
        {
            // get next buffer to draw in
            dcon = lockVideo(1);
            graphics_fill_screen(dcon, 0);
    
            if (browser && (bfill == 4))
            {
                drawImage(dcon, browser);
            }
            else if ((bfill < 3) && (pattern[bfill] != NULL))
            {
                rdp_sync(SYNC_PIPE);
                rdp_set_default_clipping();
                rdp_enable_texture_copy();
                rdp_attach_display(dcon);
                // Draw pattern
                rdp_sync(SYNC_PIPE);
                rdp_load_texture(0, 0, MIRROR_DISABLED, pattern[bfill]);
                for (int j=0; j<240; j+=pattern[bfill]->height)
                    for (int i=0; i<320; i+=pattern[bfill]->width)
                        rdp_draw_sprite(0, i, j);
                rdp_detach_display();
            }
    
            // show title
            graphics_set_color(gTextColors.title, 0);
            printText(dcon, title, 20 - strlen(title)/2, 1);
    
            // print text line buffer (line 3)
            if (strlen(buffer))
            {
                graphics_set_color(gTextColors.usel_game, 0);
                printText(dcon, buffer, 20 - strlen(buffer)/2, 3);
            }
    
            {
                char temp[2];
                temp[0] = buffer[crsr];
                if ((temp[0] == 0) | (temp[0] == 0x20))
                    temp[0] = '_';
                temp[1] = 0;
                graphics_set_color(gTextColors.usel_game, gTextColors.sel_game);
                printText(dcon, temp, 20 - strlen(buffer)/2 + crsr, 3);
            }
    
            // get buttons
            buttons = getButtons(0);
    
            // draw OSK (lines 5 to 8)
            if (TR_BUTTON(buttons))
            {
                // shift held - do shift characters
                graphics_set_color(gTextColors.usel_game, 0);
                printText(dcon, "!@#$%^&*()_+", xcoord[2], ycoord[2]);
                printText(dcon, "QWERTYUIOP{}", xcoord[2], ycoord[2]+1);
                printText(dcon, "ASDFGHJKL:\"|", xcoord[6], ycoord[6]);
                printText(dcon, "ZXCVBNM<>? ~", xcoord[6], ycoord[6]+1);
    
                if ((buttons & 0x0F00) && (buttons & 0xC00F))
                {
                    short dx = -1, dy = -1;
                    // hilite square behind button being pressed
                    graphics_set_color(0, gTextColors.usel_game);
                    if (B_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 0;
                    }
                    else if (CL_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 0;
                    }
                    else if (CU_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    else if (A_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 1;
                    }
                    else if (CD_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 1;
                    }
                    else if (CR_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    if (dx >= 0)
                        printText(dcon, "_", xcoord[(buttons>>8)&15]+dx, ycoord[(buttons>>8)&15]+dy);
                }
    
                graphics_set_color(gTextColors.sel_game, 0);
                if (xcoord[(buttons>>8)&15])
                {
                    printText(dcon, shft_text1[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]);
                    printText(dcon, shft_text2[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]+1);
                }
    
            }
            else
            {
                // no shift - do normal characters
                graphics_set_color(gTextColors.usel_game, 0);
                printText(dcon, "1234567890-=", xcoord[2], ycoord[2]);
                printText(dcon, "qwertyuiop[]", xcoord[2], ycoord[2]+1);
                printText(dcon, "asdfghjkl;'\\", xcoord[6], ycoord[6]);
                printText(dcon, "zxcvbnm,./ `", xcoord[6], ycoord[6]+1);
    
                if ((buttons & 0x0F00) && (buttons & 0xC00F))
                {
                    short dx = -1, dy = -1;
                    // hilite square behind button being pressed
                    graphics_set_color(0, gTextColors.usel_game);
                    if (B_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 0;
                    }
                    else if (CL_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 0;
                    }
                    else if (CU_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    else if (A_BUTTON(buttons))
                    {
                        dx = 0;
                        dy = 1;
                    }
                    else if (CD_BUTTON(buttons))
                    {
                        dx = 1;
                        dy = 1;
                    }
                    else if (CR_BUTTON(buttons))
                    {
                        dx = 2;
                        dy = 0;
                    }
                    if (dx >= 0)
                        printText(dcon, "_", xcoord[(buttons>>8)&15]+dx, ycoord[(buttons>>8)&15]+dy);
                }
    
                graphics_set_color(gTextColors.sel_game, 0);
                if (xcoord[(buttons>>8)&15])
                {
                    printText(dcon, norm_text1[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]);
                    printText(dcon, norm_text2[(buttons>>8)&15], xcoord[(buttons>>8)&15], ycoord[(buttons>>8)&15]+1);
                }
            }
    
            // show display
            unlockVideo(dcon);
    
            if (buttons & 0x0F00)
            {
                // pressing a direction => OSK
                char c = 0;
    
                if (B_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text1[((buttons>>8)&15)][0] : norm_text1[((buttons>>8)&15)][0];
                else if (CL_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text1[((buttons>>8)&15)][1] : norm_text1[((buttons>>8)&15)][1];
                else if (CU_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text1[((buttons>>8)&15)][2] : norm_text1[((buttons>>8)&15)][2];
                else if (A_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text2[((buttons>>8)&15)][0] : norm_text2[((buttons>>8)&15)][0];
                else if (CD_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text2[((buttons>>8)&15)][1] : norm_text2[((buttons>>8)&15)][1];
                else if (CR_BUTTON(buttons))
                    c = TR_BUTTON(buttons) ? shft_text2[((buttons>>8)&15)][2] : norm_text2[((buttons>>8)&15)][2];
                if (c && (crsr < (max-2)))
                {
                    if (buffer[crsr] == 0)
                        buffer[crsr+1] = 0;
                    buffer[crsr] = c;
                    crsr++;
                }
            }
            else
            {
                if (A_BUTTON(buttons ^ previous))
                {
                    // A changed
                    if (!A_BUTTON(buttons))
                    {
                        // A just released - Enter
                        return strlen(buffer);
                    }
                }
                if (B_BUTTON(buttons ^ previous))
                {
                    // B changed
                    if (!B_BUTTON(buttons))
                    {
                        // B just released - Escape
                        return 0;
                    }
                }
                if (CL_BUTTON(buttons ^ previous))
                {
                    // CL changed
                    if (!CL_BUTTON(buttons))
                    {
                        // CL just released - Cursor Left
                        if (crsr > 0)
                            crsr--;
                    }
                }
                if (CR_BUTTON(buttons ^ previous))
                {
                    // CR changed
                    if (!CR_BUTTON(buttons))
                    {
                        // CR just released - Cursor Right
                        if (crsr < (strlen(buffer)))
                            crsr++;
                    }
                }
                if (CU_BUTTON(buttons ^ previous))
                {
                    // CU changed
                    if (!CU_BUTTON(buttons))
                    {
                        // CU just released - Delete
                        if (crsr > 0)
                        {
                            crsr--;
                            if (buffer[crsr+1] == 0)
                                buffer[crsr] = 0;
                            else
                                strcpy(&buffer[crsr], &buffer[crsr+1]);
                        }
                    }
                }
                if (CD_BUTTON(buttons ^ previous))
                {
                    // CD changed
                    if (!CD_BUTTON(buttons))
                    {
                        // CD just released - Space
                        if (crsr < (max-2))
                        {
                            if (buffer[crsr] == 0)
                                buffer[crsr+1] = 0;
                            buffer[crsr] = ' ';
                            crsr++;
                        }
                    }
                }
            }
    
            previous = buttons;
            delay(7);
        }
    
        return strlen(buffer);
    }
    Wow, this is quite a lot of code. I'm imagining the inconvenience it would create for the player, selecting every letter with the D-pad. What if he wants to try to use three keys from the inventory with three doors around him and doesn't know which key belongs to which door?

    The better way to handle the input will be, imo, a menu of verbs like "use", "open", etc. Once you select the use verb, you should be able to scroll through objects around you. If you want to use something from the inventory, go there and select "use", then scroll through all stuff in the inventory AND all the stuff around you.

    Free your music,

  13. #13
    ESWAT Veteran Chilly Willy's Avatar
    Join Date
    Feb 2009
    Posts
    5,795
    Rep Power
    50

    Default

    Yes, that's a generic On-Screen Keyboard for full text input. If you only allow select phrases, it would be easier to just make a selector for them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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