File: rt-config.c

package info (click to toggle)
atari800 0.8.6-2
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 1,364 kB
  • ctags: 2,457
  • sloc: ansic: 22,055; asm: 2,812; cpp: 581; makefile: 68; sh: 8
file content (275 lines) | stat: -rw-r--r-- 7,769 bytes parent folder | download
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static char *rcsid = "$Id: rt-config.c,v 1.4 1998/02/21 14:51:54 david Exp $";

#define FALSE   0
#define TRUE    1

#include "atari.h"
#include "prompts.h"
#include "rt-config.h"

char atari_osa_filename[MAX_FILENAME_LEN];
char atari_osb_filename[MAX_FILENAME_LEN];
char atari_xlxe_filename[MAX_FILENAME_LEN];
char atari_basic_filename[MAX_FILENAME_LEN];
char atari_5200_filename[MAX_FILENAME_LEN];
char atari_disk_dir[MAX_FILENAME_LEN];
char atari_rom_dir[MAX_FILENAME_LEN];
char atari_h1_dir[MAX_FILENAME_LEN];
char atari_h2_dir[MAX_FILENAME_LEN];
char atari_h3_dir[MAX_FILENAME_LEN];
char atari_h4_dir[MAX_FILENAME_LEN];
char print_command[256];
int refresh_rate;
int default_system;
int default_tv_mode;
int hold_option;
int enable_c000_ram;
int enable_sio_patch;
int enable_xcolpf1;

static char *rtconfig_filename1 = "atari800.cfg";
static char *rtconfig_filename2 = "/etc/atari800.cfg";

int RtConfigLoad(char *rtconfig_filename)
{
	FILE *fp;
	int status = TRUE;

	/*
	 * Set Configuration Parameters to sensible values
	 * in case the configuration file is missing.
	 */

	atari_osa_filename[0] = '\0';
	atari_osb_filename[0] = '\0';
	atari_xlxe_filename[0] = '\0';
	atari_basic_filename[0] = '\0';
	atari_5200_filename[0] = '\0';
	atari_disk_dir[0] = '\0';
	atari_rom_dir[0] = '\0';
	atari_h1_dir[0] = '\0';
	atari_h2_dir[0] = '\0';
	atari_h3_dir[0] = '\0';
	atari_h4_dir[0] = '\0';
	strcpy(print_command, "lpr %s");
	refresh_rate = 1;
	default_system = 3;
	default_tv_mode = 1;
	hold_option = 0;
	enable_c000_ram = 0;
	enable_sio_patch = 1;
	enable_xcolpf1 = 0;

	if (rtconfig_filename) {
		fp = fopen(rtconfig_filename, "r");
		if (!fp) {
			perror(rtconfig_filename);
			exit(1);
		}
	}
	else {
		fp = fopen(rtconfig_filename1, "r");
		if (!fp)
			fp = fopen(rtconfig_filename2, "r");
	}

	if (fp) {
		char string[256];
		char *ptr;

		fgets(string, 256, fp);

		printf("Configuration Created by %s", string);

		while (fgets(string, 256, fp)) {
			RemoveLF(string);
			ptr = strchr(string, '=');
			if (ptr) {
				*ptr++ = '\0';

				if (strcmp(string, "OS/A_ROM") == 0)
					strcpy(atari_osa_filename, ptr);
				else if (strcmp(string, "OS/B_ROM") == 0)
					strcpy(atari_osb_filename, ptr);
				else if (strcmp(string, "XL/XE_ROM") == 0)
					strcpy(atari_xlxe_filename, ptr);
				else if (strcmp(string, "BASIC_ROM") == 0)
					strcpy(atari_basic_filename, ptr);
				else if (strcmp(string, "5200_ROM") == 0)
					strcpy(atari_5200_filename, ptr);
				else if (strcmp(string, "DISK_DIR") == 0)
					strcpy(atari_disk_dir, ptr);
				else if (strcmp(string, "ROM_DIR") == 0)
					strcpy(atari_rom_dir, ptr);
				else if (strcmp(string, "H1_DIR") == 0)
					strcpy(atari_h1_dir, ptr);
				else if (strcmp(string, "H2_DIR") == 0)
					strcpy(atari_h2_dir, ptr);
				else if (strcmp(string, "H3_DIR") == 0)
					strcpy(atari_h3_dir, ptr);
				else if (strcmp(string, "H4_DIR") == 0)
					strcpy(atari_h4_dir, ptr);
				else if (strcmp(string, "PRINT_COMMAND") == 0)
					strcpy(print_command, ptr);
				else if (strcmp(string, "SCREEN_REFRESH_RATIO") == 0)
					sscanf(ptr, "%d", &refresh_rate);
				else if (strcmp(string, "HOLD_OPTION") == 0)
					sscanf(ptr, "%d", &hold_option);
				else if (strcmp(string, "ENABLE_C000_RAM") == 0)
					sscanf(ptr, "%d", &enable_c000_ram);
				else if (strcmp(string, "ENABLE_SIO_PATCH") == 0)
					sscanf(ptr, "%d", &enable_sio_patch);
				else if (strcmp(string, "ENABLE_XCOLPF1") == 0)
					sscanf(ptr, "%d", &enable_xcolpf1);
				else if (strcmp(string, "DEFAULT_SYSTEM") == 0) {
					if (strcmp(ptr, "Atari OS/A") == 0)
						default_system = 1;
					else if (strcmp(ptr, "Atari OS/B") == 0)
						default_system = 2;
					else if (strcmp(ptr, "Atari XL") == 0)
						default_system = 3;
					else if (strcmp(ptr, "Atari XE") == 0)
						default_system = 4;
					else if (strcmp(ptr, "Atari 5200") == 0)
						default_system = 5;
					else
						printf("Invalid System: %s\n", ptr);
				}
				else if (strcmp(string, "DEFAULT_TV_MODE") == 0) {
					if (strcmp(ptr, "PAL") == 0)
						default_tv_mode = 1;
					else if (strcmp(ptr, "NTSC") == 0)
						default_tv_mode = 2;
					else
						printf("Invalid TV Mode: %s\n", ptr);
				}
				else
					printf("Unrecognized Variable: %s\n", string);
			}
			else {
				printf("Ignored Config Line: %s\n", string);
			}
		}


		fclose(fp);
	}
	else {
		status = FALSE;
	}

	return status;
}

void RtConfigSave(void)
{
	FILE *fp;

	fp = fopen(rtconfig_filename1, "w");
	if (!fp) {
		perror(rtconfig_filename1);
		exit(1);
	}
	printf("\nWriting: %s\n\n", rtconfig_filename1);

	fprintf(fp, "%s\n", ATARI_TITLE);
	fprintf(fp, "OS/A_ROM=%s\n", atari_osa_filename);
	fprintf(fp, "OS/B_ROM=%s\n", atari_osb_filename);
	fprintf(fp, "XL/XE_ROM=%s\n", atari_xlxe_filename);
	fprintf(fp, "BASIC_ROM=%s\n", atari_basic_filename);
	fprintf(fp, "5200_ROM=%s\n", atari_5200_filename);
	fprintf(fp, "DISK_DIR=%s\n", atari_disk_dir);
	fprintf(fp, "ROM_DIR=%s\n", atari_rom_dir);
	fprintf(fp, "H1_DIR=%s\n", atari_h1_dir);
	fprintf(fp, "H2_DIR=%s\n", atari_h2_dir);
	fprintf(fp, "H3_DIR=%s\n", atari_h3_dir);
	fprintf(fp, "H4_DIR=%s\n", atari_h4_dir);
	fprintf(fp, "PRINT_COMMAND=%s\n", print_command);
	fprintf(fp, "SCREEN_REFRESH_RATIO=%d\n", refresh_rate);

	fprintf(fp, "DEFAULT_SYSTEM=Atari ");
	switch (default_system) {
	case 1:
		fprintf(fp, "OS/A\n");
		break;
	case 2:
		fprintf(fp, "OS/B\n");
		break;
	case 3:
		fprintf(fp, "XL\n");
		break;
	case 4:
		fprintf(fp, "XE\n");
		break;
	case 5:
		fprintf(fp, "5200\n");
		break;
	}

	if (default_tv_mode == 1)
		fprintf(fp, "DEFAULT_TV_MODE=PAL\n");
	else
		fprintf(fp, "DEFAULT_TV_MODE=NTSC\n");

	fprintf(fp, "HOLD_OPTION=%d\n", hold_option);
	fprintf(fp, "ENABLE_C000_RAM=%d\n", enable_c000_ram);
	fprintf(fp, "ENABLE_SIO_PATCH=%d\n", enable_sio_patch);
	fprintf(fp, "ENABLE_XCOLPF1=%d\n", enable_xcolpf1);

	fclose(fp);
}

void RtConfigUpdate(void)
{
	GetString("Enter path to Atari OS/A ROM [%s] ", atari_osa_filename);
	GetString("Enter path to Atari OS/B ROM [%s] ", atari_osb_filename);
	GetString("Enter path to Atari XL/XE ROM [%s] ", atari_xlxe_filename);
	GetString("Enter path to Atari BASIC ROM [%s] ", atari_basic_filename);
	GetString("Enter path to Atari 5200 ROM [%s] ", atari_5200_filename);
	GetString("Enter path for disk images [%s] ", atari_disk_dir);
	GetString("Enter path for ROM images [%s] ", atari_rom_dir);
	GetString("Enter path for H1: device [%s] ", atari_h1_dir);
	GetString("Enter path for H2: device [%s] ", atari_h2_dir);
	GetString("Enter path for H3: device [%s] ", atari_h3_dir);
	GetString("Enter path for H4: device [%s] ", atari_h4_dir);
	GetString("Enter print command [%s] ", print_command);
	GetNumber("Enter default screen refresh ratio 1:[%d] ", &refresh_rate);
	if (refresh_rate < 1)
		refresh_rate = 1;
	else if (refresh_rate > 60)
		refresh_rate = 60;

	do {
		GetNumber("Default System 1) OS/A, 2) OS/B, 3) XL, 4) XE, 5) 5200 [%d] ",
				  &default_system);
	} while ((default_system < 1) || (default_system > 5));

	do {
		GetNumber("Default TV mode 1) PAL, 2) NTSC [%d] ",
				  &default_tv_mode);
	} while ((default_tv_mode < 1) || (default_tv_mode > 2));

	do {
		GetNumber("Hold OPTION during Coldstart [%d] ",
				  &hold_option);
	} while ((hold_option < 0) || (hold_option > 1));

	do {
		GetNumber("Enable C000-CFFF RAM in Atari800 mode [%d] ",
				  &enable_c000_ram);
	} while ((enable_c000_ram < 0) || (enable_c000_ram > 1));

	do {
		GetNumber("Enable SIO PATCH (Recommended) [%d] ",
				  &enable_sio_patch);
	} while ((enable_sio_patch < 0) || (enable_sio_patch > 1));

	do {
		GetNumber("Enable Extended COLPF1 [%d] ",
				  &enable_xcolpf1);
	} while ((enable_xcolpf1 < 0) || (enable_xcolpf1 > 1));
}