summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/video/pc_video.c
blob: 48736b58720f51a7c63dd95f4afff3dee0ab85ac (plain) (blame)
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
/*********************************************************************

    pc_video.c

    PC Video code

*********************************************************************/

#include "emu.h"
#include "memconv.h"
//#include "includes/crtc6845.h"
#include "video/pc_video.h"



/***************************************************************************

    Local variables

***************************************************************************/

static pc_video_update_proc (*pc_choosevideomode)(running_machine *machine, int *width, int *height);
static int pc_anythingdirty;
static int pc_current_height;
static int pc_current_width;
static const UINT16 dummy_palette[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };



/**************************************************************************/

static STATE_POSTLOAD( pc_video_postload )
{
	pc_anythingdirty = 1;
	pc_current_height = -1;
	pc_current_width = -1;
}



void pc_video_start(running_machine *machine, 
	pc_video_update_proc (*choosevideomode)(running_machine *machine, int *width, int *height),
	size_t vramsize)
{
	pc_choosevideomode = choosevideomode;
	pc_anythingdirty = 1;
	pc_current_height = -1;
	pc_current_width = -1;
	machine->generic.tmpbitmap = NULL;

	machine->generic.videoram_size = vramsize;

	if (machine->generic.videoram_size)
	{
		video_start_generic_bitmapped(machine);
	}

	state_save_register_postload(machine, pc_video_postload, NULL);
}



VIDEO_UPDATE( pc_video )
{
	UINT32 rc = 0;
	int w = 0, h = 0;
	pc_video_update_proc video_update;

	video_update = pc_choosevideomode(screen->machine, &w, &h);

	if (video_update)
	{
		if ((pc_current_width != w) || (pc_current_height != h))
		{
			int width = screen->width();
			int height = screen->height();

			pc_current_width = w;
			pc_current_height = h;
			pc_anythingdirty = 1;

			if (pc_current_width > width)
				pc_current_width = width;
			if (pc_current_height > height)
				pc_current_height = height;

			if ((pc_current_width > 100) && (pc_current_height > 100))
				screen->set_visible_area(0, pc_current_width-1, 0, pc_current_height-1);

			bitmap_fill(bitmap, cliprect, 0);
		}

		video_update(screen->machine->generic.tmpbitmap ? screen->machine->generic.tmpbitmap : bitmap);

		if (screen->machine->generic.tmpbitmap)
		{
			copybitmap(bitmap, screen->machine->generic.tmpbitmap, 0, 0, 0, 0, cliprect);
			if (!pc_anythingdirty)
				rc = UPDATE_HAS_NOT_CHANGED;
			pc_anythingdirty = 0;
		}
	}
	return rc;
}



WRITE8_HANDLER ( pc_video_videoram_w )
{
	if (space->machine->generic.videoram.u8 && space->machine->generic.videoram.u8[offset] != data)
	{
		space->machine->generic.videoram.u8[offset] = data;
		pc_anythingdirty = 1;
	}
}


WRITE16_HANDLER( pc_video_videoram16le_w ) { write16le_with_write8_handler(pc_video_videoram_w, space, offset, data, mem_mask); }

WRITE32_HANDLER( pc_video_videoram32_w )
{
	COMBINE_DATA(space->machine->generic.videoram.u32 + offset);
	pc_anythingdirty = 1;
}