vidmodes.c 11 KB
Newer Older
1 2
/* $Id$ */

deuce's avatar
deuce committed
3 4
#include <stdlib.h>

5 6 7
/* xpdev: */
#include <gen_defs.h>	/* FREE_AND_NULL */

8
#include "vidmodes.h"
deuce's avatar
deuce committed
9

10
struct video_params vparams[49] = {
11
	/* BW 40x25 */
12
	{BW40, GREYSCALE_PALETTE, 40, 25, 14, 15, 16, 8, 1},
13
	/* CO 40x25 */
14
	{C40, COLOUR_PALETTE, 40, 25, 14, 15, 16, 8, 1},
15
	/* BW 80x25 */
16
	{BW80, GREYSCALE_PALETTE, 80, 25, 14, 15, 16, 8, 1},
17
	/* CO 80x25 */
18
	{C80, COLOUR_PALETTE, 80, 25, 14, 15, 16, 8, 1},
19
	/* MONO */
20
	{MONO, 0, 80, 25, 14, 15, 16, 8, 1},
21
	/* CO 40x14 */
22
	{C40X14, COLOUR_PALETTE, 40, 14, 14, 15, 16, 8, 1},
23
	/* CO 40x21 */
24
	{C40X21, COLOUR_PALETTE, 40, 21, 14, 15, 16, 8, 1},
25
	/* CO 40x28 */
26
	{C40X28, COLOUR_PALETTE, 40, 28, 12, 13, 14, 8, 1},
27
	/* CO 40x43 */
28
	{C40X43, COLOUR_PALETTE, 40, 43, 7, 7, 8, 8, 1},
29
	/* CO 40x50 */
30
	{C40X50, COLOUR_PALETTE, 40, 50, 7, 7, 8, 8, 1},
31
	/* CO 40x60 */
32
	{C40X60, COLOUR_PALETTE, 40, 60, 7, 7, 8, 8, 1},
33
	/* CO 80x14 */
34
	{C80X14, COLOUR_PALETTE, 80, 14, 14, 15, 16, 8, 1},
35
	/* CO 80x21 */
36
	{C80X21, COLOUR_PALETTE, 80, 21, 14, 15, 16, 8, 1},
37
	/* CO 80x28 */
38
	{C80X28, COLOUR_PALETTE, 80, 28, 12, 13, 14, 8, 1},
39
	/* CO 80x43 */
40
	{C80X43, COLOUR_PALETTE, 80, 43, 7, 7, 8, 8, 1},
41
	/* CO 80x50 */
42
	{C80X50, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8, 1},
43
	/* CO 80x60 */
44
	{C80X60, COLOUR_PALETTE, 80, 60, 7, 7, 8, 8, 1},
45
	/* B 40x14 */
46
	{BW40X14, GREYSCALE_PALETTE, 40, 14, 14, 15, 16, 8, 1},
47
	/* BW 40x21 */
48
	{BW40X21, GREYSCALE_PALETTE, 40, 21, 14, 15, 16, 8, 1},
49
	/* BW 40x28 */
50
	{BW40X28, GREYSCALE_PALETTE, 40, 28, 12, 13, 14, 8, 1},
51
	/* BW 40x43 */
52
	{BW40X43, GREYSCALE_PALETTE, 40, 43, 7, 7, 8, 8, 1},
53
	/* BW 40x50 */
54
	{BW40X50, GREYSCALE_PALETTE, 40, 50, 7, 7, 8, 8, 1},
55
	/* BW 40x60 */
56
	{BW40X60, GREYSCALE_PALETTE, 40, 60, 7, 7, 8, 8, 1},
57
	/* BW 80x14 */
58
	{BW80X14, GREYSCALE_PALETTE, 80, 14, 14, 15, 16, 8, 1},
59
	/* BW 80x21 */
60
	{BW80X21, GREYSCALE_PALETTE, 80, 21, 14, 15, 16, 8, 1},
61
	/* BW 80x28 */
62
	{BW80X28, GREYSCALE_PALETTE, 80, 28, 12, 13, 14, 8, 1},
63
	/* BW 80x43 */
64
	{BW80X43, GREYSCALE_PALETTE, 80, 43, 7, 7, 8, 8, 1},
65
	/* BW 80x50 */
66
	{BW80X50, GREYSCALE_PALETTE, 80, 50, 7, 7, 8, 8, 1},
67
	/* BW 80x60 */
68
	{BW80X60, GREYSCALE_PALETTE, 80, 60, 7, 7, 8, 8, 1},
69
	/* MONO 80x14 */
70
	{MONO14, MONO_PALETTE, 80, 14, 14, 15, 16, 8, 1},
71
	/* MONO 80x21 */
72
	{MONO21, MONO_PALETTE, 80, 21, 14, 15, 16, 8, 1},
73
	/* MONO 80x28 */
74
	{MONO28, MONO_PALETTE, 80, 28, 12, 13, 14, 8, 1},
75
	/* MONO 80x43 */
76
	{MONO43, MONO_PALETTE, 80, 43, 7, 7, 8, 8, 1},
77
	/* MONO 80x50 */
78
	{MONO50, MONO_PALETTE, 80, 50, 7, 7, 8, 8, 1},
79
	/* MONO 80x60 */
80
	{MONO60, MONO_PALETTE, 80, 60, 7, 7, 8, 8, 1},
81
	/* Magical C4350 Mode */
82
	{C4350, COLOUR_PALETTE, 80, 50, 7, 7, 8, 8, 1},
83
	/* Commodore 64 40x25 mode */
84
	{C64_40X25, C64_PALETTE, 40, 25, 0, 7, 8, 8, 1},
85
	/* Commodore 128 40x25 mode */
86
	{C128_40X25, COLOUR_PALETTE, 40, 25, 0, 7, 8, 8, 1},
87
	/* Commodore 128 80x25 mode */
88
	{C128_80X25, COLOUR_PALETTE, 80, 25, 0, 7, 8, 8, 2},
89
	/* Atari 800 40x24 mode */
90
	{ATARI_40X24, ATARI_PALETTE, 40, 24, 0, 7, 8, 8, 1},
91
	/* Atari 800 XEP80 80x25 mode */
92
	{ATARI_80X25, GREYSCALE_PALETTE, 80, 25, 0, 15, 16, 8, 1},
deuce's avatar
deuce committed
93
	/* VESA 21x132 mode */
94
	{VESA_132X21, COLOUR_PALETTE, 132, 21, 14, 15, 16, 8, 1},
deuce's avatar
deuce committed
95
	/* VESA 25x132 mode */
96
	{VESA_132X25, COLOUR_PALETTE, 132, 25, 14, 15, 16, 8, 1},
deuce's avatar
deuce committed
97
	/* VESA 28x132 mode */
98
	{VESA_132X28, COLOUR_PALETTE, 132, 28, 12, 13, 14, 8, 1},
deuce's avatar
deuce committed
99
	/* VESA 30x132 mode */
100
	{VESA_132X30, COLOUR_PALETTE, 132, 30, 14, 15, 16, 8, 1},
deuce's avatar
deuce committed
101
	/* VESA 34x132 mode */
102
	{VESA_132X34, COLOUR_PALETTE, 132, 34, 12, 13, 14, 8, 1},
deuce's avatar
deuce committed
103
	/* VESA 43x132 mode */
104
	{VESA_132X43, COLOUR_PALETTE, 132, 43, 7, 7, 8, 8, 1},
deuce's avatar
deuce committed
105
	/* VESA 50x132 mode */
106
	{VESA_132X50, COLOUR_PALETTE, 132, 50, 7, 7, 8, 8, 1},
deuce's avatar
deuce committed
107
	/* VESA 60x132 mode */
108
	{VESA_132X60, COLOUR_PALETTE, 132, 60, 7, 7, 8, 8, 1},
109 110
};

111
uint32_t palettes[5][16] = {
112 113 114 115 116 117 118 119 120
	/* Mono */
	{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
	  0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
	},
	/* Black and White */
	{ 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
	  0x08, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
	},
	/* Colour */
121 122
	{ 0x00, 0x04, 0x02, 0x06, 0x01, 0x05, 0x03, 0x07, 
	  0x08, 0x0c, 0x0a, 0x0e, 0x09, 0x0d, 0x0b, 0x0f
deuce's avatar
deuce committed
123
	},
124
	/* C64 */
125 126
	{ 0x100, 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 
	  0x108, 0x109, 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f
127
	},
deuce's avatar
deuce committed
128
	/* Atari */
129 130
	{ 0x110, 0x111, 0x111, 0x111, 0x111, 0x111, 0x111, 0x111,
	  0x111, 0x111, 0x111, 0x111, 0x111, 0x111, 0x111, 0x111
deuce's avatar
deuce committed
131
	},
132 133
};

134
struct dac_colors dac_default[TOTAL_DAC_SIZE] = {
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
	/* "System" colours */
	{0, 0, 0},       // Black
	{168, 0, 0},     // Red
	{0, 168, 0},     // Green
	{168, 84, 0},    // Brown
	{0, 0, 168},     // Blue
	{168, 0, 168},   // Magenta
	{0, 168, 168},   // Cyan
	{168, 168, 168}, // Light Gray

	{84, 84, 84},    // Dark Gray
	{255, 84, 84},   // Light Red
	{84, 255, 84},   // Light Green
	{255, 255, 84},  // Yellow
	{84, 84, 255},   // Light Blue
	{255, 84, 255},  // Light Magenta
	{84, 255, 255},  // Light Cyan
	{255, 255, 255}, // White

	/* XTerm 256 colour palette */
	{0, 0, 0}, {0, 0, 95}, {0, 0, 135}, {0, 0, 175},
	{0, 0, 215}, {0, 0, 255}, {0, 95, 0}, {0, 95, 95},
	{0, 95, 135}, {0, 95, 175}, {0, 95, 215}, {0, 95, 255},
	{0, 135, 0}, {0, 135, 95}, {0, 135, 135}, {0, 135, 175},
	{0, 135, 215}, {0, 135, 255}, {0, 175, 0}, {0, 175, 95},
	{0, 175, 135}, {0, 175, 175}, {0, 175, 215}, {0, 175, 255},
	{0, 215, 0}, {0, 215, 95}, {0, 215, 135}, {0, 215, 175},
	{0, 215, 215}, {0, 215, 255}, {0, 255, 0}, {0, 255, 95},
	{0, 255, 135}, {0, 255, 175}, {0, 255, 215}, {0, 255, 255},
	{95, 0, 0}, {95, 0, 95}, {95, 0, 135}, {95, 0, 175},
	{95, 0, 215}, {95, 0, 255}, {95, 95, 0}, {95, 95, 95},
	{95, 95, 135}, {95, 95, 175}, {95, 95, 215}, {95, 95, 255},
	{95, 135, 0}, {95, 135, 95}, {95, 135, 135}, {95, 135, 175},
	{95, 135, 215}, {95, 135, 255}, {95, 175, 0}, {95, 175, 95},
	{95, 175, 135}, {95, 175, 175}, {95, 175, 215}, {95, 175, 255},
	{95, 215, 0}, {95, 215, 95}, {95, 215, 135}, {95, 215, 175},
	{95, 215, 215}, {95, 215, 255}, {95, 255, 0}, {95, 255, 95},
	{95, 255, 135}, {95, 255, 175}, {95, 255, 215}, {95, 255, 255},
	{135, 0, 0}, {135, 0, 95}, {135, 0, 135}, {135, 0, 175},
	{135, 0, 215}, {135, 0, 255}, {135, 95, 0}, {135, 95, 95},
	{135, 95, 135}, {135, 95, 175}, {135, 95, 215}, {135, 95, 255},
	{135, 135, 0}, {135, 135, 95}, {135, 135, 135}, {135, 135, 175},
	{135, 135, 215}, {135, 135, 255}, {135, 175, 0}, {135, 175, 95},
	{135, 175, 135}, {135, 175, 175}, {135, 175, 215}, {135, 175, 255},
	{135, 215, 0}, {135, 215, 95}, {135, 215, 135}, {135, 215, 175},
	{135, 215, 215}, {135, 215, 255}, {135, 255, 0}, {135, 255, 95},
	{135, 255, 135}, {135, 255, 175}, {135, 255, 215}, {135, 255, 255},
	{175, 0, 0}, {175, 0, 95}, {175, 0, 135}, {175, 0, 175},
	{175, 0, 215}, {175, 0, 255}, {175, 95, 0}, {175, 95, 95},
	{175, 95, 135}, {175, 95, 175}, {175, 95, 215}, {175, 95, 255},
	{175, 135, 0}, {175, 135, 95}, {175, 135, 135}, {175, 135, 175},
	{175, 135, 215}, {175, 135, 255}, {175, 175, 0}, {175, 175, 95},
	{175, 175, 135}, {175, 175, 175}, {175, 175, 215}, {175, 175, 255},
	{175, 215, 0}, {175, 215, 95}, {175, 215, 135}, {175, 215, 175},
	{175, 215, 215}, {175, 215, 255}, {175, 255, 0}, {175, 255, 95},
	{175, 255, 135}, {175, 255, 175}, {175, 255, 215}, {175, 255, 255},
	{215, 0, 0}, {215, 0, 95}, {215, 0, 135}, {215, 0, 175},
	{215, 0, 215}, {215, 0, 255}, {215, 95, 0}, {215, 95, 95},
	{215, 95, 135}, {215, 95, 175}, {215, 95, 215}, {215, 95, 255},
	{215, 135, 0}, {215, 135, 95}, {215, 135, 135}, {215, 135, 175},
	{215, 135, 215}, {215, 135, 255}, {215, 175, 0}, {215, 175, 95},
	{215, 175, 135}, {215, 175, 175}, {215, 175, 215}, {215, 175, 255},
	{215, 215, 0}, {215, 215, 95}, {215, 215, 135}, {215, 215, 175},
	{215, 215, 215}, {215, 215, 255}, {215, 255, 0}, {215, 255, 95},
	{215, 255, 135}, {215, 255, 175}, {215, 255, 215}, {215, 255, 255},
	{255, 0, 0}, {255, 0, 95}, {255, 0, 135}, {255, 0, 175},
	{255, 0, 215}, {255, 0, 255}, {255, 95, 0}, {255, 95, 95},
	{255, 95, 135}, {255, 95, 175}, {255, 95, 215}, {255, 95, 255},
	{255, 135, 0}, {255, 135, 95}, {255, 135, 135}, {255, 135, 175},
	{255, 135, 215}, {255, 135, 255}, {255, 175, 0}, {255, 175, 95},
	{255, 175, 135}, {255, 175, 175}, {255, 175, 215}, {255, 175, 255},
	{255, 215, 0}, {255, 215, 95}, {255, 215, 135}, {255, 215, 175},
	{255, 215, 215}, {255, 215, 255}, {255, 255, 0}, {255, 255, 95},
	{255, 255, 135}, {255, 255, 175}, {255, 255, 215}, {255, 255, 255},
	{8, 8, 8}, {18, 18, 18}, {28, 28, 28}, {38, 38, 38},
	{48, 48, 48}, {58, 58, 58}, {68, 68, 68}, {78, 78, 78},
	{88, 88, 88}, {98, 98, 98}, {108, 108, 108}, {118, 118, 118},
	{128, 128, 128}, {138, 138, 138}, {148, 148, 148}, {158, 158, 158},
	{168, 168, 168}, {178, 178, 178}, {188, 188, 188}, {198, 198, 198},
	{208, 208, 208}, {218, 218, 218}, {228, 228, 228}, {238, 238, 238}, 

216 217 218
	/* C64 colours */
	/* Black, White, Red, Cyan, Purple, Green, Blue, Yellow */
	/* Orange, Brown, Lt Red, Dk Grey, Grey, Lt Green, Lt Blue, Lt Grey */
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
	/* Taken from CTerm source */
	{0x00, 0x00, 0x00},	// Black
	{0xFD, 0xFE, 0xFC},	// White
	{0xBE, 0x1A, 0x24},	// Red
	{0x30, 0xE6, 0xC6},	// Cyan
	{0xB4, 0x1A, 0xE2},	// Purple
	{0x1F, 0xD2, 0x1E},	// Green
	{0x21, 0x1B, 0xAE},	// Blue
	{0xDF, 0xF6, 0x0A},	// Yellow
	{0xB8, 0x41, 0x04},	// Orange
	{0x6A, 0x33, 0x04},	// Brown
	{0xFE, 0x4A, 0x57},	// Light Red
	{0x42, 0x45, 0x40},	// Dark Grey
	{0x70, 0x74, 0x6F},	// Grey
	{0x59, 0xFE, 0x59},	// Light Green
	{0x5F, 0x53, 0xFE},	// Light Blue
	{0xA4, 0xA7, 0xA2},	// Light Grey
deuce's avatar
deuce committed
236 237
	/* Atari Colours */
	/* BG, FG */
deuce's avatar
deuce committed
238
	{0, 81, 129}, {96, 183, 231},
239 240 241 242 243 244 245 246 247 248 249 250 251
};

int find_vmode(int mode)
{
    unsigned i;

	for (i = 0; i < NUMMODES; i++)
		if (vparams[i].mode == mode)
			return i;

	return -1;
}

deuce's avatar
deuce committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
struct vstat_vmem *get_vmem(struct video_stats *vs)
{
	vs->vmem->refcount++;
	return vs->vmem;
}

void release_vmem(struct vstat_vmem *vm)
{
	if (vm == NULL)
		return;
	vm->refcount--;
	if (vm->refcount == 0) {
		FREE_AND_NULL(vm->vmem);
		FREE_AND_NULL(vm);
	}
}

static struct vstat_vmem *new_vmem(int cols, int rows)
{
	struct vstat_vmem *ret = malloc(sizeof(struct vstat_vmem));

	if (ret == NULL)
		return ret;
	ret->refcount = 1;
	ret->vmem = (unsigned short *)malloc(cols*rows*sizeof(unsigned short));
	if (ret->vmem == NULL) {
		free(ret);
		return NULL;
	}
	return ret;
}

284 285 286 287 288 289 290
int load_vmode(struct video_stats *vs, int mode)
{
	int i;

	i=find_vmode(mode);
	if(i==-1)
		return(-1);
deuce's avatar
deuce committed
291 292 293 294
	release_vmem(vs->vmem);
	vs->vmem=new_vmem(vparams[i].cols, vparams[i].rows);
	if (vs->vmem == NULL)
		return -1;
295 296 297 298 299 300
	vs->rows=vparams[i].rows;
	vs->cols=vparams[i].cols;
	vs->curs_start=vparams[i].curs_start;
	vs->curs_end=vparams[i].curs_end;
	vs->default_curs_start=vparams[i].curs_start;
	vs->default_curs_end=vparams[i].curs_end;
301 302 303 304 305
	vs->curs_blink=1;
	vs->curs_visible=1;
	vs->bright_background=0;
	vs->no_bright=0;
	vs->bright_altcharset=0;
306 307
	vs->no_blink=0;
	vs->blink_altcharset=0;
308 309 310 311 312 313 314 315
	if(vs->curs_row < 0)
		vs->curs_row=0;
	if(vs->curs_row >= vparams[i].rows)
		vs->curs_row=vparams[i].rows-1;
	if(vs->curs_col < 0)
		vs->curs_col=0;
	if(vs->curs_col >= vparams[i].cols)
		vs->curs_col=vparams[i].cols-1;
316
	memcpy(vs->palette, palettes[vparams[i].palette], sizeof(vs->palette));
317 318 319
	vs->charheight=vparams[i].charheight;
	vs->charwidth=vparams[i].charwidth;
	vs->mode=mode;
320
	vs->vmultiplier=vparams[i].vmultiplier;
321 322
	return(0);
}