]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/doom/m_cheat.c
games/doom: fix mips
[plan9front.git] / sys / src / games / doom / m_cheat.c
1 // Emacs style mode select   -*- C++ -*- 
2 //-----------------------------------------------------------------------------
3 //
4 // $Id:$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
11 //
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15 // for more details.
16 //
17 // $Log:$
18 //
19 // DESCRIPTION:
20 //      Cheat sequence checking.
21 //
22 //-----------------------------------------------------------------------------
23
24
25 static const char
26 rcsid[] = "$Id: m_cheat.c,v 1.1 1997/02/03 21:24:34 b1 Exp $";
27
28 #include "m_cheat.h"
29
30 //
31 // CHEAT SEQUENCE PACKAGE
32 //
33
34 static int              firsttime = 1;
35 static unsigned char    cheat_xlate_table[256];
36
37
38 //
39 // Called in st_stuff module, which handles the input.
40 // Returns a 1 if the cheat was successful, 0 if failed.
41 //
42 int
43 cht_CheckCheat
44 ( cheatseq_t*   cht,
45   char          key )
46 {
47     int i;
48     int rc = 0;
49
50     if (firsttime)
51     {
52         firsttime = 0;
53         for (i=0;i<256;i++) cheat_xlate_table[i] = SCRAMBLE(i);
54     }
55
56     if (!cht->p)
57         cht->p = cht->sequence; // initialize if first time
58
59     if (*cht->p == 0)
60         *(cht->p++) = key;
61     else if
62         (cheat_xlate_table[(unsigned char)key] == *cht->p) cht->p++;
63     else
64         cht->p = cht->sequence;
65
66     if (*cht->p == 1)
67         cht->p++;
68     else if (*cht->p == 0xff) // end of sequence character
69     {
70         cht->p = cht->sequence;
71         rc = 1;
72     }
73
74     return rc;
75 }
76
77 void
78 cht_GetParam
79 ( cheatseq_t*   cht,
80   char*         buffer )
81 {
82
83     unsigned char *p, c;
84
85     p = cht->sequence;
86     while (*(p++) != 1);
87     
88     do
89     {
90         c = *p;
91         *(buffer++) = c;
92         *(p++) = 0;
93     }
94     while (c && *p!=0xff );
95
96     if (*p==0xff)
97         *buffer = 0;
98
99 }
100
101