summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openbios/packages/molvideo.c
blob: 787c4dc08b123609d18ad9bd6a170bafce6b786b (plain)
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
/*
 *   Creation Date: <2002/10/23 20:26:40 samuel>
 *   Time-stamp: <2004/01/07 19:39:15 samuel>
 *
 *	<molvideo.c>
 *
 *	Mac-on-Linux display node
 *
 *   Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se)
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation
 *
 */

#include "config.h"
#include "libopenbios/bindings.h"
#include "libc/diskio.h"
#include "libopenbios/ofmem.h"
#include "drivers/drivers.h"
#include "packages/video.h"
#include "libopenbios/video.h"
#include "drivers/vga.h"


/************************************************************************/
/*	OF methods							*/
/************************************************************************/

DECLARE_NODE( video, 0, 0, "Tdisplay" );

/* ( r g b index -- ) */
static void
molvideo_color_bang( void )
{
	int index = POP();
	int b = POP();
	int g = POP();
	int r = POP();
	unsigned long col = ((r << 16) & 0xff0000) | ((g << 8) & 0x00ff00) | (b & 0xff);
	/* printk("color!: %08lx %08lx %08lx %08lx\n", r, g, b, index ); */

	if( VIDEO_DICT_VALUE(video.depth) == 8 ) {
		OSI_SetColor( index, col );
		OSI_RefreshPalette();
	}
}

/* ( -- ) - really should be reworked as draw-logo */
static void
molvideo_startup_splash( void )
{
	int fd, s, i, y, x, dx, dy;
	int width, height;
	char *pp, *p;
	char buf[64];

	/* only draw logo in 24-bit mode (for now) */
	if( VIDEO_DICT_VALUE(video.depth) < 15 )
		return;

	for( i=0; i<2; i++ ) {
		if( !BootHGetStrResInd("bootlogo", buf, sizeof(buf), 0, i) )
			return;
		*(!i ? &width : &height) = atol(buf);
	}

	if( (s=width * height * 3) > 0x20000 )
		return;

	if( (fd=open_io("pseudo:,bootlogo")) >= 0 ) {
		p = malloc( s );
		if( read_io(fd, p, s) != s )
			printk("bootlogo size error\n");
		close_io( fd );

		dx = (VIDEO_DICT_VALUE(video.w) - width)/2;
		dy = (VIDEO_DICT_VALUE(video.h) - height)/3;

		pp = (char*)VIDEO_DICT_VALUE(video.mvirt) + dy * VIDEO_DICT_VALUE(video.rb) + dx * (VIDEO_DICT_VALUE(video.depth) >= 24 ? 4 : 2);

		for( y=0 ; y<height; y++, pp += VIDEO_DICT_VALUE(video.rb) ) {
			if( VIDEO_DICT_VALUE(video.depth) >= 24 ) {
				unsigned long *d = (unsigned long*)pp;
				for( x=0; x<width; x++, p+=3, d++ )
					*d = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2];
			} else if( VIDEO_DICT_VALUE(video.depth) == 15 ) {
				unsigned short *d = (unsigned short*)pp;
				for( x=0; x<width; x++, p+=3, d++ ) {
					int col = ((int)p[0] << 16) | ((int)p[1] << 8) | p[2];
					*d = ((col>>9) & 0x7c00) | ((col>>6) & 0x03e0) | ((col>>3) & 0x1f);
				}
			}
		}
		free( p );
	}

	/* No bootlogo support yet on other platforms */
	return;
}


NODE_METHODS( video ) = {
	{"mol-startup-splash",	molvideo_startup_splash },
};


/************************************************************************/
/*	init 								*/
/************************************************************************/

void
molvideo_init(void)
{
	xt_t color_bang;

	REGISTER_NODE( video );

	/* Bind the MOL graphic routines to the mol-color! defer */
	color_bang = bind_noname_func(molvideo_color_bang);
	PUSH(color_bang);
	feval(" to mol-color!");
}