ScummVM API documentation
general.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef MADS_CORE_GENERAL_H
23#define MADS_CORE_GENERAL_H
24
25#include "common/stream.h"
26
27namespace MADS {
28
29/* Code optimization parameters */
30
31#define fastcall /* register calling convention */
32#define aggressive true /* allow "Z" optimizations */
33
34/* universal interlanguage data types */
35
36typedef uint32 dword; /* generic 32 bit data */
37typedef uint16 word; /* generic 16 bit data */
38
39/* vertical data types */
40
41/* A single palette color */
42struct RGBcolor {
43 byte r, g, b;
44
45 static constexpr size_t SIZE = 3;
46 inline void load(Common::SeekableReadStream *src) {
47 r = src->readByte();
48 g = src->readByte();
49 b = src->readByte();
50 }
51};
52typedef RGBcolor Palette[256]; /* An entire Mcga palette */
53typedef byte PaletteMap[256][3]; /* An entire Mcga palette #2 */
54
55#define pal_color(p,i,c) (*(((byte *)&p[i])+c))
56
57struct Buffer { /* Video buffer structure */
58 int y; /* Wrap value for buffer (y size) */
59 int x; /* X size of buffer */
60 byte *data; /* Pointer to actual data */
61};
62
63#define far_string(v,s) char _based(_segname("FARSTRING")) v[] = s;
64
65
66/* Timer and clock stuff */
67
68// ScummVM: replace the DOS hardware address with a safe writable dummy so
69// that game code which writes *timer_address doesn't touch unmapped memory.
70extern long _timer_clock;
71#define clock_address (&_timer_clock)
72#define dos_timer_address (&_timer_clock)
73
74#define interrupt_controller 0x20 /* Interrupt controller */
75#define end_of_interrupt 0x20 /* End of interrupt ack */
76
77#define timer_controller 0x43 /* Timer controller port */
78#define timer_channel_0 0x40 /* Timer channel 0 data */
79#define timer_channel_1 0x41 /* Timer channel 1 data */
80#define timer_channel_2 0x42 /* Timer channel 2 data */
81
82#define time_set 0x36 /* Set timer countdown 00110110b */
83
84#define timer_speed_600 1880 /* 600/s 1960? */
85#define timer_speed_300 3920 /* 300/s */
86#define timer_speed_60 19600 /* 60/s */
87
88
89/* video defines */
90
91#define video_x 320 /* Screen max X size */
92#define video_y 200 /* Screen max Y size */
93
94#define display_y 156 /* Picture area max Y size */
95
96#define mcga_video (byte *)g_engine->getScreen()->getPixels()
97
98#define text_mode 0x03
99#define mono_text_mode 0x07
100#define tandy_mode 0x09
101#define ega_mode 0x0d
102#define mcga_mode 0x13
103
104#define secret_video_area ((color_text_video) + (PACK_EXPLODE_SIZE))
105#define secret_video_size (32768L - PACK_EXPLODE_SIZE)
106
107/* Things-you-need-for-Tandy */
108
109#define dos_memory (byte *)0x00400013 /* Dos memory # */
110#define abs_memory (byte *)0x00400015 /* Abs memory # */
111
112/* logical defines (boolean etc) */
113#define yes true //(-1)
114#define no false //0
115
116constexpr int none = 0;
117constexpr int stop = 99;
118
119
120/* misc functional defines */
121
122#define getrandom( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
123
124
125#define hibyte(x) ( (byte) ( (x) >> 8 ) )
126#define lobyte(x) ( (byte) ( ( (word) ( (x) << 8 ) ) >> 8 ) )
127
128#define neg(x) ((~(x))+1) /* Negate w/o multiply */
129#define abs(x) ( ((x)>0) ? (x) : neg(x) ) /* Abs val w/o multiply */
130
131#define sgn(x) ( ((x)>0) ? 1 : ( ((x)<0) ? -1 : 0 ) ) /* sign */
132#define sign(x) ( ((x) > 0.0) ? 1 : ( ((x) < 0.0) ? -1 : 0 ) ) /* sign (double) */
133
134#define sgn_in(x,s) ( ((s) >= 0) ? (x) : (neg(x)) ) /* Incorporate sign */
135
136inline char *mads_strupr(char *str) {
137 for (char *s = str; *s; ++s)
138 *s = toupper(*s);
139 return str;
140}
141
142inline char *mads_strlwr(char *str) {
143 for (char *s = str; *s; ++s)
144 *s = tolower(*s);
145 return str;
146}
147
148inline char *mads_itoa(int value, char *buffer, int radix) {
149 assert(radix == 10);
150 Common::strcpy_s(buffer, 16, Common::String::format("%d", value).c_str());
151 return buffer;
152}
153
154inline void mads_fullpath(char *buffer, const char *path, uint bufferCount) {
155 Common::strcpy_s(buffer, bufferCount, path);
156}
157inline char *mads_getcwd(char *buffer, int count) {
158 *buffer = '\0';
159 return buffer;
160}
161
162} // namespace MADS
163
164#endif
byte readByte()
Definition: stream.h:434
Definition: stream.h:745
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: atari-screen.h:42
void strcpy_s(char *dst, size_t size, const char *src)
Definition: general.h:57
Definition: general.h:42