TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Peter Fitzsimmons
from: Andrew Graham
date: 1995-06-12 17:22:52
subject: adding a thread

Hi Peter!
You said that if we needed help with threads, we should ask...

This is a little colour-picker for text mode that I cobbled togther from
some source in an old PC Techniques magazine and the get_key() routine from
the
MsgEd soource code. I want the cursor to spin, rather than just showing
a solid ASCII 15.

If it were a DOS program, I would put the draws and keyboard input inside
a loop that changed the character from '-' to '\' to '|' to '/' at a 
regular interval.

Can I do this using a second thread?

=====================================================================
#define INCL_VIO
#define INCL_KBD
#include
#include
#include

HVIO            VHandle;
VIOMODEINFO     ModeData;

KBDKEYINFO      KChar;
USHORT          IOW;
HKBD            KHandle;

int pick_colour(void);
unsigned char contents[2];

#define ROW 5
#define COLUMN 5

main()
{
    int value;

    VHandle = 0;
    ModeData.cb = sizeof(ModeData);
    VioGetMode( &ModeData, VHandle );

    value = pick_colour();
    printf("\nColour picked was: %d", value);
    return 0;
}
/* this function is based on one in the Msged source
*/
unsigned int getkey(void)
{
    KBDKEYINFO ki;

    ki.chChar = ki.chScan = 0;
    KbdCharIn (&ki, IO_WAIT, 0);

    if (ki.chChar == 0xe0)
    {
        if (ki.chScan)
        {
            ki.chChar = 0;                        /* Force Scan return */
        }
        else
        {                                         /* Get next block     */
            ki.chChar = 0;
            KbdCharIn (&ki, IO_WAIT, 0);
            if (!ki.chScan)
            {                                     /* Still no scan?     */
                ki.chScan = ki.chChar;            /* Move new char over*/
                ki.chChar = 0;                    /* Force its return  */
            }
            else
            {
                ki.chChar = 0;                    /* Force new scan     */
            }
        }
    }
    if (ki.chScan == 0xe0)
    {
        if (!ki.chChar)
        {
            ki.chScan = 0;
            KbdCharIn (&ki, IO_WAIT, 0);
            if (!ki.chScan)
            {                                     /* Still no scan?     */
                ki.chScan = ki.chChar;            /* Move new char over*/
                ki.chChar = 0;                    /* Force its return  */
            }
            else
            {
                ki.chChar = 0;                    /* Force new scan     */
            }
        }
        else
        {
            ki.chScan = 0;                        /* Handle 0xe00d case*/
        }
    }

    if (ki.chChar)
        ki.chScan = 0;
    return (unsigned int) ((ki.chScan << 8) + (ki.chChar));
}


int pick_colour()
{
    VIOCURSORINFO CursorData;
    signed short row, column;
    unsigned int input = 0;
    long fill = 0L;

    VioGetCurType( &CursorData, 0 );
/*    for(row = 0; row < 8; row++) */
    for(row = 0; row < 16; row++)
    {
        for(column = 0; column < 16; column++)
        {
/*            contents[0] = 7; */
            contents[0] = 254;
            contents[1] = column;
            contents[1] |= row << 4;
            VioSetCurPos( row + ROW, column + COLUMN, 0 );
            VioWrtNCell(&contents, 1, column + COLUMN, row + ROW, VHandle);
        }
    }

    row = 0;
    column = 0;
    VioSetCurPos( row + ROW, column + COLUMN, 0 );


    CursorData.attr = -1;
    VioSetCurType( &CursorData, 0 );

    contents[0] = 15;
    contents[1] = column;
    contents[1] |= (row + 7) << 4;
    VioWrtNCell(&contents, 1, column + COLUMN, row + ROW, VHandle);

    for(;;)
    {
        input = getkey();
        VioSetCurPos(row + ROW, column + COLUMN, 0);
/*        contents[0] = 7; */
        contents[0] = 254;
        contents[1] = column;
        contents[1] |= row << 4;
        VioWrtNCell(&contents, 1, column + COLUMN, row + ROW, VHandle);
        switch(input)
        {
            case 0x4800:
                    column --;
                break;

            case 0x4b00:
                    row--;
                break;

            case 0x4d00:
                    row ++;
                break;

            case 0x5000:
                    column ++;
                break;
        }
        if (input == 27 || input == 13) break;
/*        if(row > 7) row = 0; */
        if(row > 15) row = 0;
/*        else if(row < 0) row = 7; */
        else if(row < 0) row = 15;
        if(column > 15) column = 0;
        else if(column < 0) column = 15;
        VioSetCurPos( row + ROW, column + COLUMN, 0 );
        contents[0] = 15;
        contents[1] = column;
        contents[1] |= (row + 7) << 4;
        VioWrtNCell(&contents, 1, column + COLUMN, row + ROW, VHandle);
    }

    CursorData.attr = 1;
    VioSetCurType( &CursorData, 0 );

    if(input == 27)
        return -1;
    else
        return ((row << 4) + column);
}
=====================================================================

...andrew

@EOT:

---
* Origin: Code Outside/2 Day (705)458 0528 (1:252/500)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 252/500 503 99 3615/50 396/1 270/101 105/103 42 712/515 711/808 809
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.