vidmodes.c 6.84 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
};

deuce's avatar
deuce committed
111
unsigned char palettes[5][16] = {
112 113 114 115 116 117 118 119 120 121 122
	/* 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 */
	{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
	  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
deuce's avatar
deuce committed
123
	},
124 125 126
	/* C64 */
	{ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
	  0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
127
	},
deuce's avatar
deuce committed
128 129 130 131
	/* Atari */
	{ 0x20, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
	  0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21
	},
132 133
};

134
struct dac_colors dac_default[TOTAL_DAC_SIZE] = {
135 136 137
	{0, 0, 0},    {0, 0, 168},   {0, 168, 0},   {0, 168, 168},
	{168, 0, 0},   {168, 0, 168},  {168, 84, 0},  {168, 168, 168},
	{84, 84, 84}, {84, 84, 255}, {84, 255, 84}, {84, 255, 255},
deuce's avatar
deuce committed
138
	{255, 84, 84}, {255, 84, 255}, {255, 255, 84}, {255, 255, 255},
139 140 141 142 143 144 145 146
	/* C64 colours */
	/* Black, White, Red, Cyan, Purple, Green, Blue, Yellow */
	/* Orange, Brown, Lt Red, Dk Grey, Grey, Lt Green, Lt Blue, Lt Grey */
	{0x00, 0x00, 0x00}, {0xff, 0xff, 0xff}, {0x68, 0x37, 0x2b}, 
	{0x70, 0xa4, 0xb2}, {0x6f, 0x3d, 0x86}, {0x58, 0x8d, 0x43},
	{0x35, 0x29, 0x79}, {0xb8, 0xc7, 0x6f}, {0x6f, 0x4f, 0x25},
	{0x43, 0x39, 0x00}, {0x9a, 0x67, 0x59}, {0x44, 0x44, 0x44},
	{0x6c, 0x6c, 0x6c}, {0x9a, 0xd2, 0x84}, {0x6c, 0x5e, 0xb5},
147
	{0x95, 0x95, 0x95},
deuce's avatar
deuce committed
148 149
	/* Atari Colours */
	/* BG, FG */
deuce's avatar
deuce committed
150
	{0, 81, 129}, {96, 183, 231},
151 152 153 154 155 156 157 158 159 160 161 162 163
};

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
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
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;
}

196 197 198 199 200 201 202
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
203 204 205 206
	release_vmem(vs->vmem);
	vs->vmem=new_vmem(vparams[i].cols, vparams[i].rows);
	if (vs->vmem == NULL)
		return -1;
207 208 209 210 211 212
	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;
213 214 215 216 217
	vs->curs_blink=1;
	vs->curs_visible=1;
	vs->bright_background=0;
	vs->no_bright=0;
	vs->bright_altcharset=0;
218 219
	vs->no_blink=0;
	vs->blink_altcharset=0;
220 221 222 223 224 225 226 227
	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;
228 229
	memcpy(vs->palette, palettes[vparams[i].palette], sizeof(vs->palette));
	memcpy(vs->dac_colors, dac_default, sizeof(dac_default));
230 231 232
	vs->charheight=vparams[i].charheight;
	vs->charwidth=vparams[i].charwidth;
	vs->mode=mode;
233
	vs->vmultiplier=vparams[i].vmultiplier;
234 235
	return(0);
}