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 
27 namespace 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 
36 typedef uint32 dword; /* generic 32 bit data */
37 typedef uint16 word; /* generic 16 bit data */
38 
39 /* vertical data types */
40 
41 /* A single palette color */
42 struct 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 };
52 typedef RGBcolor Palette[256]; /* An entire Mcga palette */
53 typedef byte PaletteMap[256][3]; /* An entire Mcga palette #2 */
54 
55 #define pal_color(p,i,c) (*(((byte *)&p[i])+c))
56 
57 struct 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.
70 extern 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 #if 0
116 #define true (-1)
117 #define false 0
118 #endif
119 
120 constexpr int none = 0;
121 constexpr int stop = 99;
122 
123 
124 /* misc functional defines */
125 
126 #define getrandom( min, max ) ((rand() % (int)(((max)+1) - (min))) + (min))
127 
128 
129 #define hibyte(x) ( (byte) ( (x) >> 8 ) )
130 #define lobyte(x) ( (byte) ( ( (word) ( (x) << 8 ) ) >> 8 ) )
131 
132 #define neg(x) ((~(x))+1) /* Negate w/o multiply */
133 #define abs(x) ( ((x)>0) ? (x) : neg(x) ) /* Abs val w/o multiply */
134 
135 #define sgn(x) ( ((x)>0) ? 1 : ( ((x)<0) ? -1 : 0 ) ) /* sign */
136 #define sign(x) ( ((x) > 0.0) ? 1 : ( ((x) < 0.0) ? -1 : 0 ) ) /* sign (double) */
137 
138 #define sgn_in(x,s) ( ((s) >= 0) ? (x) : (neg(x)) ) /* Incorporate sign */
139 
140 inline char *mads_strupr(char *str) {
141  for (char *s = str; *s; ++s)
142  *s = toupper(*s);
143  return str;
144 }
145 
146 inline char *mads_strlwr(char *str) {
147  for (char *s = str; *s; ++s)
148  *s = tolower(*s);
149  return str;
150 }
151 
152 inline char *mads_itoa(int value, char *buffer, int radix) {
153  assert(radix == 10);
154  Common::strcpy_s(buffer, 16, Common::String::format("%d", value).c_str());
155  return buffer;
156 }
157 
158 inline void mads_fullpath(char *buffer, const char *path, uint bufferCount) {
159  Common::strcpy_s(buffer, bufferCount, path);
160 }
161 inline char *mads_getcwd(char *buffer, int count) {
162  *buffer = '\0';
163  return buffer;
164 }
165 
166 } // namespace MADS
167 
168 #endif
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: general.h:42
Definition: general.h:57
Definition: stream.h:745
byte readByte()
Definition: stream.h:434
Definition: anim_timer.h:27
void strcpy_s(char *dst, size_t size, const char *src)
Definition: atari-screen.h:42