~ubuntu-branches/ubuntu/wily/gargoyle-free/wily-proposed

« back to all changes in this revision

Viewing changes to terps/level9/level9.h

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2009-09-11 20:09:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090911200943-idgzoyupq6650zpn
Tags: upstream-2009-08-25
ImportĀ upstreamĀ versionĀ 2009-08-25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************\
 
2
*
 
3
* Level 9 interpreter
 
4
* Version 4.1
 
5
* Copyright (c) 1996 Glen Summers
 
6
* Copyright (c) 2002,2003 Glen Summers and David Kinder
 
7
* Copyright (c) 2005,2007 Glen Summers, David Kinder, Alan Staniforth,
 
8
* Simon Baldwin and Dieter Baron
 
9
*
 
10
* This program is free software; you can redistribute it and/or modify
 
11
* it under the terms of the GNU General Public License as published by
 
12
* the Free Software Foundation; either version 2 of the License, or
 
13
* (at your option) any later version.
 
14
*
 
15
* This program is distributed in the hope that it will be useful,
 
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
* GNU General Public License for more details.
 
19
*
 
20
* You should have received a copy of the GNU General Public License
 
21
* along with this program; if not, write to the Free Software
 
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 
23
*
 
24
\***********************************************************************/
 
25
 
 
26
#include <limits.h>
 
27
 
 
28
#if UCHAR_MAX==0xff
 
29
typedef unsigned char L9BYTE;
 
30
#else
 
31
#error "Can't find an 8-bit integer type"
 
32
#endif
 
33
 
 
34
#if SHRT_MAX==0x7fff
 
35
typedef unsigned short L9UINT16;
 
36
#elif INT_MAX==0x7fff
 
37
typedef unsigned int   L9UINT16;
 
38
#else
 
39
#error "Can't find a 16-bit integer type"
 
40
#endif
 
41
 
 
42
#if INT_MAX==0x7fffffff
 
43
typedef unsigned int L9UINT32;
 
44
#elif LONG_MAX==0x7fffffff
 
45
typedef unsigned long L9UINT32;
 
46
#else
 
47
#error "Can't find a 32-bit integer type"
 
48
#endif
 
49
 
 
50
typedef int L9BOOL;
 
51
 
 
52
#ifndef FALSE
 
53
#define FALSE 0
 
54
#define TRUE 1
 
55
#endif
 
56
 
 
57
#define LISTAREASIZE 0x800
 
58
#define STACKSIZE 1024
 
59
#define V1FILESIZE 0x600
 
60
 
 
61
#ifndef MAX_PATH
 
62
#define MAX_PATH 256
 
63
#endif
 
64
 
 
65
typedef struct
 
66
{
 
67
        L9UINT32 Id;
 
68
        L9UINT16 codeptr,stackptr,listsize,stacksize,filenamesize,checksum;
 
69
        L9UINT16 vartable[256];
 
70
        L9BYTE listarea[LISTAREASIZE];
 
71
        L9UINT16 stack[STACKSIZE];
 
72
        char filename[MAX_PATH];
 
73
} GameState;
 
74
 
 
75
typedef enum
 
76
{
 
77
        NO_BITMAPS,
 
78
        AMIGA_BITMAPS,
 
79
        PC1_BITMAPS,
 
80
        PC2_BITMAPS,
 
81
        C64_BITMAPS,
 
82
        BBC_BITMAPS,
 
83
        CPC_BITMAPS,
 
84
        MAC_BITMAPS,
 
85
        ST1_BITMAPS,
 
86
        ST2_BITMAPS,
 
87
} BitmapType;
 
88
 
 
89
typedef struct
 
90
{
 
91
        L9BYTE red, green, blue;
 
92
} Colour;
 
93
 
 
94
typedef struct
 
95
{
 
96
        L9UINT16 width, height;
 
97
        L9BYTE* bitmap;
 
98
        Colour palette[32];
 
99
        L9UINT16 npalette;
 
100
} Bitmap;
 
101
 
 
102
#define MAX_BITMAP_WIDTH 512
 
103
#define MAX_BITMAP_HEIGHT 216
 
104
 
 
105
#if defined(_Windows) || defined(__MSDOS__) || defined (_WIN32) || defined (__WIN32__)
 
106
        #define L9WORD(x) (*(L9UINT16*)(x))
 
107
        #define L9SETWORD(x,val) (*(L9UINT16*)(x)=(L9UINT16)val)
 
108
        #define L9SETDWORD(x,val) (*(L9UINT32*)(x)=val)
 
109
#else
 
110
        #define L9WORD(x) (*(x) + ((*(x+1))<<8))
 
111
        #define L9SETWORD(x,val) *(x)=(L9BYTE) val; *(x+1)=(L9BYTE)(val>>8);
 
112
        #define L9SETDWORD(x,val) *(x)=(L9BYTE)val; *(x+1)=(L9BYTE)(val>>8); *(x+2)=(L9BYTE)(val>>16); *(x+3)=(L9BYTE)(val>>24);
 
113
#endif
 
114
 
 
115
#if defined(_Windows) && !defined(__WIN32__)
 
116
#include <alloc.h>
 
117
#define malloc farmalloc
 
118
#define calloc farcalloc
 
119
#define free farfree
 
120
#endif
 
121
 
 
122
#ifdef __cplusplus
 
123
extern "C" {
 
124
#endif
 
125
 
 
126
/* routines provided by os dependent code */
 
127
void os_printchar(char c);
 
128
L9BOOL os_input(char* ibuff, int size);
 
129
char os_readchar(int millis);
 
130
L9BOOL os_stoplist(void);
 
131
void os_flush(void);
 
132
L9BOOL os_save_file(L9BYTE* Ptr, int Bytes);
 
133
L9BOOL os_load_file(L9BYTE* Ptr, int* Bytes, int Max);
 
134
L9BOOL os_get_game_file(char* NewName, int Size);
 
135
void os_set_filenumber(char* NewName, int Size, int n);
 
136
void os_graphics(int mode);
 
137
void os_cleargraphics(void);
 
138
void os_setcolour(int colour, int index);
 
139
void os_drawline(int x1, int y1, int x2, int y2, int colour1, int colour2);
 
140
void os_fill(int x, int y, int colour1, int colour2);
 
141
void os_show_bitmap(int pic, int x, int y);
 
142
 
 
143
/* routines provided by level9 interpreter */
 
144
L9BOOL LoadGame(char* filename, char* picname);
 
145
L9BOOL RunGame(void);
 
146
void StopGame(void);
 
147
void RestoreGame(char* filename);
 
148
void FreeMemory(void);
 
149
void GetPictureSize(int* width, int* height);
 
150
L9BOOL RunGraphics(void);
 
151
void SetScaleGraphics(L9BOOL scale);
 
152
 
 
153
/* bitmap routines provided by level9 interpreter */
 
154
#ifdef BITMAP_DECODER
 
155
BitmapType DetectBitmaps(char* dir);
 
156
Bitmap* DecodeBitmap(char* dir, BitmapType type, int num, int x, int y);
 
157
#endif
 
158
 
 
159
#ifdef NEED_STRICMP_PROTOTYPE
 
160
int stricmp(const char* str1, const char* str2);
 
161
int strnicmp(const char* str1, const char* str2, size_t n);
 
162
#endif
 
163
 
 
164
#ifdef __cplusplus
 
165
}
 
166
#endif