forked from kilobyte/lastbeer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baller.c
207 lines (161 loc) · 5.38 KB
/
baller.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* Allegro port Copyright (C) 2014 Gavin Smith. */
/*-----------------------------------------------------*/
/* */
/* T H E L A S T E I C H H O F */
/* */
/* [c] copyrigth 1993 by ALPHA-HELIX */
/* This module written by Dany Schoch */
/* */
/*-----------------------------------------------------*/
#define MAIN_MODULE
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <errno.h>
#include "xmode.h"
#include "fileman.h"
#include "sound.h"
#include "baller.h"
#define MEMORYREQUIRED 500000L // Memory used to run.
#define CMDLEN 40 // Max length of command line.
static char cmd[CMDLEN]; // Command line given at startup.
extern unsigned _stklen; // Programs stacklength.
// Code.
// Error handling routines.
void error(char *text, int code, ...)
{
void powerdown(void); // Prototype.
va_list ap; // Variable for variable argument list.
va_start(ap, code);
powerdown(); // Leave graphics, close files, ...
switch (code) {
case ENOMEM : printf("%s : NO MORE MEMORY !\n\n", text);
break;
case ENOENT: printf("%s : File '%s' not found !\n\n",
text, va_arg(ap, char *));
break;
case E2BIG : printf("%s : Out of index table space.\n\n", text);
break;
case EINVAL: printf("%s : Wrong level.\n\n", text);
break;
case -1 :
case EFAULT : printf("James Bond quitting style !!\n\n");
break;
default : perror(text);
}
va_end(ap);
exit(1);
}
/*------------------------------------------------------
Function: powerup & powerdown
powerup : Initializes the system.
powerdown : Undoes the effect of powerup.
Please note that powerdown should not be
called within powerup or the sytem will
hang. So errors encountered in powerup
can't be handled by the function 'error',
because this would call powerdown indirectly.
------------------------------------------------------*/
static void create_pages(void);
void powerup(void)
{
allegro_init();
install_keyboard();
if (install_sound(DIGI_AUTODETECT, MIDI_NONE, 0)) {
printf ("%s\n", allegro_error);
exit(2);
}
// Clear NUM_LOCK, SCROLL_LOCK and CAPS_LOCK.
set_leds (0);
install_timer();
setspeed(GAMESPEED);
initxmode(); // Enter graphic mode.
windowy1 = BARY; // Game window y-Size.
create_pages ();
page = 0;
}
static void create_pages (void)
{
full_pages[0] = create_system_bitmap (320, 240);
full_pages[1] = create_system_bitmap (320, 240);
pages[0] = create_sub_bitmap(full_pages[0], 0, 0, windowx1, windowy1);
pages[1] = create_sub_bitmap(full_pages[1], 0, 0, windowx1, windowy1);
}
void powerdown(void)
{
shutxmode();
shutsound();
shutfilemanager();
}
/*------------------------------------------------------
Function: cmdline
Description: Do first steps on the command line.
------------------------------------------------------*/
void cmdline(int argc, char *argv[])
{
int i;
char *e1;
// Concatenate all command strings together in 'cmd'.
cmd[0] = '\0'; // Clear string.
for (i = 1; i < argc; i++) {
if (strlen(cmd)+strlen(argv[i]) < CMDLEN)
strcat(cmd, argv[i]);
}
strupr(cmd);
// Help?
if (strstr(cmd, "/?") || strstr(cmd, "-?")) { // Help?
printf("Syntax: BALLER [options]\n");
printf(" /vga Override VGA detection.\n");
printf(" /ns Play without sound.\n");
printf("\n");
printf("To force SoundBlaster on, use the BLASTER environment variable.\n");
printf(" e.g. set BLASTER = A220 I7 D1\n");
printf("\n\n");
exit(0); // Exit nicely.
}
// Get cheat level.
if ((e1 = strstr(cmd, "007.")) == NULL) {
cheatlevel = 0; // No cheating this time.
} else {
cheatlevel = e1[4] - '0';
printf("Cheat level:\n");
if(cheatlevel & CHEATLIFES) printf(" - Unlimited lives\n");
if(cheatlevel & CHEATMONEY) printf(" - Unlimited money\n");
if(cheatlevel & CHEATCRASH) printf(" - Eichhof can't be destroyed\n");
printf("\n");
}
}
int main(int argc, char *argv[])
{
#if 0
printf("\n\n\nTHE LAST EICHHOF [c] copyright 1993 by ALPHA-HELIX.\n");
printf("Release 1.1\n\n");
printf("This game is FREEWARE. Please copy like crazy.\n");
/* Don't know if this is still valid. */
printf("If you like it, just send a postcard to ALPHA-HELIX\n");
printf(" Rehhalde 18\n");
printf(" 6332 Hagendorn\n");
printf(" Switzerland\n");
printf("\nInternet contact address: [email protected]\n\n\n");
#endif
// Process command line.
cmdline(argc, argv);
// Do initialization.
powerup();
// Load options of last time.
loadconfig();
// Check command line for 'nosound' option.
if (strstr(cmd, "/NS") || strstr(cmd, "-NS")) speaker(0);
// Open date bases.
initfilemanager(40, 512, 8192, error);
datapool = opendatabase("BEER.DAT");
intro(); // Show Blick intro.
menu();
closedatabase(datapool);
// Going down and return to OS.
powerdown();
return 0;
}