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

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

5
#include "vidmodes.h"
deuce's avatar
deuce committed
6

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

deuce's avatar
deuce committed
108
unsigned char palettes[5][16] = {
109 110 111 112 113 114 115 116 117 118 119
	/* 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
120
	},
121 122 123
	/* C64 */
	{ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
	  0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
124
	},
deuce's avatar
deuce committed
125 126 127 128
	/* Atari */
	{ 0x20, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
	  0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21
	},
129 130
};

131
struct dac_colors dac_default[TOTAL_DAC_SIZE] = {
132 133 134
	{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
135
	{255, 84, 84}, {255, 84, 255}, {255, 255, 84}, {255, 255, 255},
136 137 138 139 140 141 142 143
	/* 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},
144
	{0x95, 0x95, 0x95},
deuce's avatar
deuce committed
145 146
	/* Atari Colours */
	/* BG, FG */
deuce's avatar
deuce committed
147
	{0, 81, 129}, {96, 183, 231},
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
};

int find_vmode(int mode)
{
    unsigned i;

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

	return -1;
}

int load_vmode(struct video_stats *vs, int mode)
{
	int i;
	unsigned short *newvmem;

	i=find_vmode(mode);
	if(i==-1)
		return(-1);
	newvmem=(unsigned short *)realloc(vs->vmem, vparams[i].cols*vparams[i].rows*sizeof(unsigned short));
	if(newvmem==NULL)
		return(-1);
	vs->vmem=newvmem;
	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;
179 180 181 182 183
	vs->curs_blink=1;
	vs->curs_visible=1;
	vs->bright_background=0;
	vs->no_bright=0;
	vs->bright_altcharset=0;
184 185
	vs->no_blink=0;
	vs->blink_altcharset=0;
186 187 188 189 190 191 192 193
	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;
194 195
	memcpy(vs->palette, palettes[vparams[i].palette], sizeof(vs->palette));
	memcpy(vs->dac_colors, dac_default, sizeof(dac_default));
196 197 198
	vs->charheight=vparams[i].charheight;
	vs->charwidth=vparams[i].charwidth;
	vs->mode=mode;
199
	vs->vmultiplier=vparams[i].vmultiplier;
200 201
	return(0);
}