Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 27. apríl 2025

Súbor: [Platon] / games / _shared / dos2linux.c (stiahnutie)

Revízia 1.10, Tue Apr 6 09:59:10 2004 UTC (21 years ago) by nepto


Zmeny od 1.9: +2 -2 [lines]

Debug printings in function getch() turned off.

/*
 * games/_shared/ - shared routines for games
 *
 * dos2linux.c - MS-Dos to GNU/Linux call convertor
 * ____________________________________________________________
 *
 * Developed by Ondrej Jombik <nepto@platon.sk>
 * Copyright (c) 2003-2004 Platon SDG, http://platon.sk/
 * All rights reserved.
 *
 * See README file for more information about this software.
 * See COPYING file for license information.
 *
 * Download the latest version from
 * http://platon.sk/projects/games/
 *
 * Changelog:
 * 2003-05-03 - created
 * 2003-08-12 - X11 adaptations
 */

/* $Platon: games/_shared/dos2linux.c,v 1.9 2004/04/06 09:54:15 nepto Exp $ */

#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <typedef.h>
#include <system.h>

#include "dos2linux.h"

static int getch_next_ret = 0; /* used by both, SVGAlib and X11 */

#if PLATON_SYSTEM_SVGALIB

#include <vga.h>

int kbhit(void) /* {{{ */
{
    register int ret;
    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;
    ret = vga_waitevent(/* VGA_MOUSEEVENT | */ VGA_KEYEVENT,
            NULL, NULL, NULL, &timeout);
    return ret > 0 ? 1 : 0;
} /* }}} */

int getch(void) /* {{{ */
{
    register int ret;
#if 0 /* debug mode */
    ret = vga_getch();
    fprintf(stderr, "getch(): ret = %d\n", ret);
#else
    if (getch_next_ret != 0) {
        ret = getch_next_ret;
        getch_next_ret = 0;
    } else {
        ret = vga_getch();
        if (ret == 27 && kbhit() && (ret = vga_getch()) == 91 && kbhit()) {
            ret = vga_getch();
            if (ret == 91) {
                switch (ret = vga_getch()) {
                    case 65: getch_next_ret =  F1; break;
                    case 66: getch_next_ret =  F2; break;
                    case 67: getch_next_ret =  F3; break;
                    case 68: getch_next_ret =  F4; break;
                    case 69: getch_next_ret =  F5; break;
                    case 70: getch_next_ret =  F6; break;
                    case 71: getch_next_ret =  F7; break;
                    case 72: getch_next_ret =  F8; break;
                    case 73: getch_next_ret =  F9; break;
                    case 74: getch_next_ret = F10; break;
                }
            } else {
                switch (ret) {
                    case 65: getch_next_ret = SUP;    break;
                    case 66: getch_next_ret = SDOWN;  break;
                    case 67: getch_next_ret = SRIGHT; break;
                    case 68: getch_next_ret = SLEFT;  break;
                    case 49: getch_next_ret = HOME;   break;
                    case 50: getch_next_ret = INSERT; break;
                    case 51: getch_next_ret = DELETE; break;
                    case 52: getch_next_ret = END;    break;
                    case 53: getch_next_ret = PGUP;   break;
                    case 54: getch_next_ret = PGDOWN; break;
                }
                if (ret >= 49 && ret <= 54 && kbhit())
                    ret = vga_getch(); /* == 126 */
            }
            if (getch_next_ret != 0)
                ret = NUL;
        } else if (ret == LF) {
            ret = EOL;
        } else if (ret == 127) {
            ret = BS;
        }
    }
#endif
    return ret;
} /* }}} */

#endif

#if PLATON_SYSTEM_X11

#include <x11-bgi.h>

int kbhit(void) /* {{{ */
{
    X11_BGI_update_IO();
    return KEYINFO_buffer != 0;
} /* }}} */

int getch(void) /* {{{ */
{
    register int ret;
    if (getch_next_ret != 0) {
        ret = getch_next_ret;
        getch_next_ret = 0;
    } else {
        do {
            X11_BGI_update_IO();
        } while (KEYINFO_buffer == 0);
        ret = KEYINFO_buffer;
        if (ret > 0xff00)
            ret -= 0xff00;
        switch (ret) {
            case 81: getch_next_ret = SLEFT;  break;
            case 82: getch_next_ret = SUP;    break;
            case 83: getch_next_ret = SRIGHT; break;
            case 84: getch_next_ret = SDOWN;  break;
            case 190: getch_next_ret = F1;    break;
            case 191: getch_next_ret = F2;    break;
            case 192: getch_next_ret = F3;    break;
            case 193: getch_next_ret = F4;    break;
            case 194: getch_next_ret = F5;    break;
            case 195: getch_next_ret = F6;    break;
            case 196: getch_next_ret = F7;    break;
            case 197: getch_next_ret = F8;    break;
            case 198: getch_next_ret = F9;    break;
            case 199: getch_next_ret = F10;   break;
        }
        if (getch_next_ret != 0)
            ret = NUL;
#if 0 /* debug mode */
        fprintf(stderr, "getch() input key transformation: %x (%d) => %x (%d)",
                KEYINFO_buffer, KEYINFO_buffer, ret, ret);
        if (getch_next_ret != 0)
            fprintf(stderr, " + %x (%d)", getch_next_ret, getch_next_ret);
        fputc('\n', stderr);
#endif
        KEYINFO_buffer = 0;
    }
    return ret;
} /* }}} */

#endif

void getdate(struct date *datep) /* {{{ */
{
    time_t secs;
    struct tm *t;
    time(&secs);
    t = gmtime(&secs);
    datep->da_year = (short) t->tm_year + 1900;
    datep->da_mon  = (char)  t->tm_mon + 1;
    datep->da_day  = (char)  t->tm_mday;
} /* }}} */

/* Modeline for ViM {{{
 * vim: set ts=4:
 * vim600: fdm=marker fdl=0 fdc=0:
 * }}} */


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok