annotate libvo/vo_vesa.c @ 2307:1dcf06bfad9b

Bad fix of top rendering with libmpeg2
author nick
date Sat, 20 Oct 2001 16:42:17 +0000
parents 42cf51474f45
children ce35271bdb10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
1 /*
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
2 * video_out_vesa.c
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
3 *
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
5 *
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
6 * You can redistribute this file under terms and conditions
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
7 * GNU General Public licence v2.
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
8 * This file is partly based on vbetest.c from lrmi distributive.
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
9 */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
10
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
11 /*
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
12 TODO:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
13 - DGA support (need volunteers who have corresponding hardware)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
14 - hw YUV support (need volunteers who have corresponding hardware)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
15 - double (triple) buffering (if it will really speedup playback).
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
16 - refresh rate support (need additional info from mplayer)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
17 */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
18 #include <stdio.h>
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
19 #include <string.h>
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
20 #include <stddef.h>
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
21 #include <limits.h>
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
22
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
23 #include "config.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
24 #include "video_out.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
25 #include "video_out_internal.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
26
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
27 #include "fastmemcpy.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
28 #include "yuv2rgb.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
29
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
30 #include "linux/lrmi.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
31 #include "linux/vbelib.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
32 #include "bswap.h"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
33
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
34 #include "../postproc/swscale.h"
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
35
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
36 LIBVO_EXTERN(vesa)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
37 extern int verbose;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
38
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
39 #ifndef max
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
40 #define max(a,b) ((a)>(b)?(a):(b))
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
41 #endif
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
42 #ifndef min
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
43 #define min(a,b) ((a)<(b)?(a):(b))
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
44 #endif
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
45
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
46
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
47 static vo_info_t vo_info =
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
48 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
49 "VESA VBE 2.0 video output",
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
50 "vesa",
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
51 "Nick Kurshev <nickols_k@mail.ru>",
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
52 "Requires ROOT privileges"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
53 };
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
54
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
55 /* driver data */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
56
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
57 /*
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
58 TODO: for linear framebuffer mode:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
60 win.ptr = linear address of frame buffer;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
61 win.low = 0;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
62 win.high = vide_memory_size;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
63 */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
64 struct win_frame
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
65 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
66 uint8_t *ptr; /* pointer to window's frame memory */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
67 uint32_t low; /* lowest boundary of frame */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
68 uint32_t high; /* highest boundary of frame */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
69 uint8_t idx; /* indicates index of relocatable frame (A or B) */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
70 };
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
71
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
72 static int vesa_zoom=0; /* software scaling */
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
73 static unsigned int scale_xinc=0;
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
74 static unsigned int scale_yinc=0;
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
75
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
76 static uint32_t image_width, image_height; /* source image dimension */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
77 static uint32_t x_offset,y_offset; /* to center image on screen */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
78 static unsigned init_mode; /* mode before run of mplayer */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
79 static void *init_state = NULL; /* state before run of mplayer */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
80 static struct win_frame win; /* real-mode window to video memory */
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
81 static void *yuv_buffer = NULL; /* for yuv2rgb and sw_scaling */
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
82 static unsigned video_mode; /* selected video mode for playback */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
83 static struct VesaModeInfoBlock video_mode_info;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
84
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
85 #define MOVIE_MODE (MODE_ATTR_COLOR | MODE_ATTR_GRAPHICS)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
86 #define FRAME_MODE (MODE_WIN_RELOCATABLE | MODE_WIN_READABLE | MODE_WIN_WRITEABLE)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
87 static char * vbeErrToStr(int err)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
88 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
89 char *retval;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
90 static char sbuff[80];
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
91 if((err & VBE_VESA_ERROR_MASK) == VBE_VESA_ERROR_MASK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
92 {
2255
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
93 sprintf(sbuff,"VESA failed = 0x4f%x",(err & VBE_VESA_ERRCODE_MASK)>>8);
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
94 retval = sbuff;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
95 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
96 else
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
97 switch(err)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
98 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
99 case VBE_OK: retval = "No error"; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
100 case VBE_VM86_FAIL: retval = "vm86() syscall failed"; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
101 case VBE_OUT_OF_DOS_MEM: retval = "Out of DOS memory"; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
102 case VBE_OUT_OF_MEM: retval = "Out of memory"; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
103 default: sprintf(sbuff,"Uknown error: %i",err); retval=sbuff; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
104 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
105 return retval;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
106 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
107
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
108 #define PRINT_VBE_ERR(name,err) { printf("vo_vesa: %s returns: %s\n",name,vbeErrToStr(err)); fflush(stdout); }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
109
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
110 static void vesa_term( void )
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
111 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
112 int err;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
113 if((err=vbeRestoreState(init_state)) != VBE_OK) PRINT_VBE_ERR("vbeRestoreState",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
114 if((err=vbeSetMode(init_mode,NULL)) != VBE_OK) PRINT_VBE_ERR("vbeSetMode",err);
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
115 free(yuv_buffer);
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
116 vbeDestroy();
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
117 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
118
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
119 #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
120 #define VIDEO_PTR(offset) (win.ptr + offset - win.low)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
121
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
122 static inline void __vbeSwitchBank(unsigned long offset)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
123 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
124 unsigned long gran;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
125 unsigned new_offset;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
126 int err;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
127 gran = video_mode_info.WinGranularity*1024;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
128 new_offset = offset / gran;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
129 if((err=vbeSetWindow(win.idx,new_offset)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
130 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
131 PRINT_VBE_ERR("vbeSetWindow",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
132 printf("vo_vesa: Fatal error occured! Can't continue\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
133 vesa_term();
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
134 exit(-1);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
135 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
136 win.low = new_offset * gran;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
137 win.high = win.low + video_mode_info.WinSize*1024;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
138 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
139
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
140 static void __vbeSetPixel(int x, int y, int r, int g, int b)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
141 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
142 int x_res = video_mode_info.XResolution;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
143 int y_res = video_mode_info.YResolution;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
144 int shift_r = video_mode_info.RedFieldPosition;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
145 int shift_g = video_mode_info.GreenFieldPosition;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
146 int shift_b = video_mode_info.BlueFieldPosition;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
147 int pixel_size = (video_mode_info.BitsPerPixel+7)/8;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
148 int bpl = video_mode_info.BytesPerScanLine;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
149 int color, offset;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
150
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
151 if (x < 0 || x >= x_res || y < 0 || y >= y_res) return;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
152 r >>= 8 - video_mode_info.RedMaskSize;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
153 g >>= 8 - video_mode_info.GreenMaskSize;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
154 b >>= 8 - video_mode_info.BlueMaskSize;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
155 color = (r << shift_r) | (g << shift_g) | (b << shift_b);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
156 offset = y * bpl + (x * pixel_size);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
157 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
158 memcpy(VIDEO_PTR(offset), &color, pixel_size);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
159 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
160
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
161 /*
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
162 Copies line of frame to video memory. Data should be in the same format as video
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
163 memory.
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
164 */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
165 static void __vbeCopyBlock(unsigned long offset,uint8_t *image,unsigned long size)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
166 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
167 unsigned long delta,src_idx = 0;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
168 while(size)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
169 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
170 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
171 delta = min(size,win.high - offset);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
172 memcpy(VIDEO_PTR(offset),&image[src_idx],delta);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
173 src_idx += delta;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
174 offset += delta;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
175 size -= delta;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
176 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
177 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
178
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
179 static void __vbeCopyBlockSwap(unsigned long offset,uint8_t *image,unsigned long size)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
180 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
181 unsigned byte_len;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
182 uint8_t ch;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
183 while(size)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
184 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
185 switch(video_mode_info.BitsPerPixel)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
186 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
187 case 8: byte_len = 1; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
188 default:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
189 case 15:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
190 printf("vo_vesa: Can't swap non byte aligned data\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
191 vesa_term();
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
192 exit(-1);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
193 case 16: *(image + offset) = ByteSwap16(*(image + offset));
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
194 byte_len = 2; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
195 case 24: ch = *(image+offset);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
196 *(image+offset) = *(image+offset+3);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
197 *(image+offset+3) = ch;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
198 byte_len = 3; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
199 case 32: *(image + offset) = ByteSwap32(*(image + offset));
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
200 byte_len = 4; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
201 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
202 __vbeCopyBlock(offset,image,byte_len);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
203 size -= byte_len;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
204 image += byte_len;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
205 offset += byte_len;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
206 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
207 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
208
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
209 /*
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
210 Copies frame to video memory. Data should be in the same format as video
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
211 memory.
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
212 */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
213 static void __vbeCopyData(uint8_t *image)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
214 {
2305
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
215 unsigned long i,j,image_offset,offset,limit;
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
216 unsigned pixel_size,image_line_size,screen_line_size,x_shift;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
217 pixel_size = (video_mode_info.BitsPerPixel+7)/8;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
218 screen_line_size = video_mode_info.XResolution*pixel_size;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
219 image_line_size = image_width*pixel_size;
2306
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
220 if(image_width == video_mode_info.XResolution)
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
221 {
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
222 /* Special case for zooming */
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
223 __vbeCopyBlock(y_offset*screen_line_size,image,image_line_size*image_height);
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
224 }
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
225 else
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
226 {
2306
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
227 x_shift = x_offset*pixel_size;
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
228 limit = image_height+y_offset;
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
229 for(j=0,i=y_offset;i<limit;i++,j++)
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
230 {
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
231 offset = i*screen_line_size+x_shift;
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
232 image_offset = j*image_line_size;
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
233 __vbeCopyBlock(offset,&image[image_offset],image_line_size);
42cf51474f45 Qualitative speedup for P3 & K7 cpus
nick
parents: 2305
diff changeset
234 }
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
235 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
236 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
237 /* is called for yuv only */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
238 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
239 {
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
240 if(vesa_zoom)
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
241 {
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
242 SwScale_YV12slice_brg24(image,stride,y,h,
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
243 yuv_buffer,
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
244 image_width*((video_mode_info.BitsPerPixel+7)/8),
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
245 image_width, video_mode_info.BitsPerPixel,
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
246 scale_xinc, scale_yinc);
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
247 }
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
248 else
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
249 {
2307
1dcf06bfad9b Bad fix of top rendering with libmpeg2
nick
parents: 2306
diff changeset
250 uint8_t *yuv_slice;
1dcf06bfad9b Bad fix of top rendering with libmpeg2
nick
parents: 2306
diff changeset
251 yuv_slice=yuv_buffer+(image_width*y+x)*(video_mode_info.BitsPerPixel+7)/8;
1dcf06bfad9b Bad fix of top rendering with libmpeg2
nick
parents: 2306
diff changeset
252 yuv2rgb(yuv_slice, image[0], image[1], image[2], w, h,
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
253 image_width * ((video_mode_info.BitsPerPixel+7)/8),
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
254 stride[0], stride[1]);
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
255 }
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
256 __vbeCopyData((uint8_t *)yuv_buffer);
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
257 return 0;
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
258 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
259
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
260 static void draw_osd(void)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
261 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
262 /* nothing to do for now */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
263 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
264
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
265 static void flip_page(void)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
266 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
267 /*Is not required*/
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
268 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
269
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
270 /* is called for rgb only */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
271 static uint32_t draw_frame(uint8_t *src[])
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
272 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
273 __vbeCopyData(src[0]);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
274 return 0;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
275 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
276
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
277 static uint32_t query_format(uint32_t format)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
278 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
279 uint32_t retval;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
280 switch(format)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
281 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
282 case IMGFMT_YV12:
2296
1d100b2d668c Initial YUV (YV12) support
nick
parents: 2293
diff changeset
283 #if 0 /* Should be tested better */
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
284 case IMGFMT_I420:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
285 case IMGFMT_IYUV:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
286 #endif
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
287 case IMGFMT_RGB8:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
288 case IMGFMT_RGB15:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
289 case IMGFMT_RGB16:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
290 case IMGFMT_RGB24:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
291 case IMGFMT_RGB32:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
292 case IMGFMT_BGR8:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
293 case IMGFMT_BGR15:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
294 case IMGFMT_BGR16:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
295 case IMGFMT_BGR24:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
296 case IMGFMT_BGR32:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
297 retval = 1; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
298 default:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
299 if(verbose)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
300 printf("vo_vesa: unknown format: %x = %s\n",format,vo_format_name(format));
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
301 retval = 0;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
302 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
303 return retval;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
304 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
305
2305
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
306 static void vesa_aspect(uint32_t width,uint32_t height,
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
307 uint32_t xres,uint32_t yres,
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
308 uint32_t *image_width,uint32_t *image_height)
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
309 {
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
310 float factor;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
311 factor = (float)width / height;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
312 *image_width = xres;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
313 *image_height = xres / factor;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
314 if(verbose) printf("vo_vesa: aspect factor = %f(%ux%u) *image=%ux%u screen=%ux%u\n",factor,width,height,*image_width,*image_height,xres,yres);
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
315 if((*image_height) > yres)
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
316 {
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
317 *image_height = yres;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
318 *image_width = yres * factor;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
319 if(verbose) printf("vo_vesa: Y > X tehrefore *image=%ux%u\n",*image_width,*image_height);
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
320 }
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
321 }
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
322
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
323 static char *model2str(unsigned char type)
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
324 {
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
325 char *retval;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
326 switch(type)
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
327 {
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
328 case memText: retval = "Text"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
329 case memCGA: retval="CGA"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
330 case memHercules: retval="Hercules"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
331 case memPL: retval="Planar"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
332 case memPK: retval="Packed pixel"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
333 case mem256: retval="256"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
334 case memRGB: retval="Direct color RGB"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
335 case memYUV: retval="Direct color YUV"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
336 default: retval="Unknown"; break;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
337 }
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
338 return retval;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
339 }
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
340
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
341 /* fullscreen:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
342 * bit 0 (0x01) means fullscreen (-fs)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
343 * bit 1 (0x02) means mode switching (-vm)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
344 * bit 2 (0x04) enables software scaling (-zoom)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
345 * bit 3 (0x08) enables flipping (-flip)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
346 */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
347 static uint32_t
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
348 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
349 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
350 struct VbeInfoBlock vib;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
351 struct VesaModeInfoBlock vmib;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
352 size_t i,num_modes;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
353 unsigned short *mode_ptr,win_seg;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
354 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
355 int err;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
356 image_width = width;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
357 image_height = height;
2307
1dcf06bfad9b Bad fix of top rendering with libmpeg2
nick
parents: 2306
diff changeset
358 printf("subdevice: %s\n",vo_subdevice);
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
359 if(fullscreen & (0x1|0x8))
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
360 {
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
361 printf("vo_vesa: switches: -fs, -flip are not supported\n");
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
362 }
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
363 if(fullscreen & 0x04) vesa_zoom = 1;
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
364 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
365 memcpy(vib.VESASignature,"VBE2",4);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
366 if((err=vbeGetControllerInfo(&vib)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
367 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
368 PRINT_VBE_ERR("vbeGetControllerInfo",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
369 printf("vo_vesa: possible reason: No VBE2 BIOS found\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
370 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
371 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
372 /* Print general info here */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
373 printf("vo_vesa: Found VESA VBE BIOS Version %x.%x Revision: %x\n",
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
374 (int)(vib.VESAVersion >> 8) & 0xff,
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
375 (int)(vib.VESAVersion & 0xff),
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
376 (int)(vib.OemSoftwareRev & 0xffff));
2255
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
377 printf("vo_vesa: Video memory: %u Kb\n",vib.TotalMemory*64);
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
378 printf("vo_vesa: VESA Capabilities: %s %s %s %s %s\n"
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
379 ,vib.Capabilities & VBE_DAC_8BIT ? "8-bit DAC," : "6-bit DAC,"
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
380 ,vib.Capabilities & VBE_NONVGA_CRTC ? "non-VGA CRTC,":"VGA CRTC,"
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
381 ,vib.Capabilities & VBE_SNOWED_RAMDAC ? "snowed RAMDAC,":"normal RAMDAC,"
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
382 ,vib.Capabilities & VBE_STEREOSCOPIC ? "stereoscopic,":"no stereoscopic,"
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
383 ,vib.Capabilities & VBE_STEREO_EVC ? "Stereo EVC":"no stereo");
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
384 printf("vo_vesa: !!! Below will be printed OEM info. !!!\n");
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
385 printf("vo_vesa: You should watch 5 OEM related lines below else you've broken vm86\n");
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
386 printf("vo_vesa: OEM info: %s\n",vib.OemStringPtr);
2255
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
387 printf("vo_vesa: OEM Revision: %x\n",vib.OemSoftwareRev);
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
388 printf("vo_vesa: OEM vendor: %s\n",vib.OemVendorNamePtr);
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
389 printf("vo_vesa: OEM Product Name: %s\n",vib.OemProductNamePtr);
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
390 printf("vo_vesa: OEM Product Rev: %s\n",vib.OemProductRevPtr);
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
391 printf("vo_vesa: Hint: To get workable TV-Out you should have plugged tv-connector in\n"
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
392 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n");
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
393 /* Find best mode here */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
394 num_modes = 0;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
395 mode_ptr = vib.VideoModePtr;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
396 while(*mode_ptr++ != 0xffff) num_modes++;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
397 switch(format)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
398 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
399 case IMGFMT_BGR8:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
400 case IMGFMT_RGB8: bpp = 8; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
401 case IMGFMT_BGR15:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
402 case IMGFMT_RGB15: bpp = 15; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
403 case IMGFMT_YV12:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
404 case IMGFMT_I420:
2296
1d100b2d668c Initial YUV (YV12) support
nick
parents: 2293
diff changeset
405 case IMGFMT_IYUV: bpp=16;
1d100b2d668c Initial YUV (YV12) support
nick
parents: 2293
diff changeset
406 yuv2rgb_init(bpp, MODE_RGB);
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
407 default:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
408 case IMGFMT_BGR16:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
409 case IMGFMT_RGB16: bpp = 16; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
410 case IMGFMT_BGR24:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
411 case IMGFMT_RGB24: bpp = 24; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
412 case IMGFMT_BGR32:
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
413 case IMGFMT_RGB32: bpp = 32; break;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
414 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
415 if(verbose)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
416 {
2304
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
417 printf("vo_vesa: Requested mode: %ux%u@%u (%s)\n",width,height,bpp,vo_format_name(format));
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
418 printf("vo_vesa: Total modes found: %u\n",num_modes);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
419 mode_ptr = vib.VideoModePtr;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
420 printf("vo_vesa: Mode list:");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
421 for(i = 0;i < num_modes;i++)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
422 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
423 printf(" %04X",mode_ptr[i]);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
424 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
425 printf("\nvo_vesa: Modes in detail:\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
426 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
427 mode_ptr = vib.VideoModePtr;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
428 for(i=0;i < num_modes;i++)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
429 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
430 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
431 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
432 PRINT_VBE_ERR("vbeGetModeInfo",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
433 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
434 }
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
435 if(vmib.XResolution >= image_width &&
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
436 vmib.YResolution >= image_height &&
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
437 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE &&
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
438 vmib.BitsPerPixel == bpp &&
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
439 vmib.MemoryModel == memRGB)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
440 {
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
441 if(vmib.XResolution <= best_x &&
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
442 vmib.YResolution <= best_y)
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
443 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
444 best_x = vmib.XResolution;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
445 best_y = vmib.YResolution;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
446 best_mode_idx = i;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
447 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
448 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
449 if(verbose)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
450 {
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
451 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%04X\n"
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
452 "vo_vesa: #planes=%u model=%u(%s) #pages=%u\n"
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
453 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n"
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
454 "vo_vesa: direct_color=%u DGA_phys_addr=%08X\n"
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
455 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
456 ,vmib.NumberOfPlanes,vmib.MemoryModel,model2str(vmib.MemoryModel),vmib.NumberOfImagePages
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
457 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
458 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
459 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
460 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n"
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
461 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
462 fflush(stdout);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
463 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
464 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
465 if(best_mode_idx != UINT_MAX)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
466 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
467 video_mode = vib.VideoModePtr[best_mode_idx];
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
468 printf("vo_vesa: Using VESA mode (%u) = %x\n",best_mode_idx,video_mode);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
469 fflush(stdout);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
470 if((err=vbeGetMode(&init_mode)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
471 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
472 PRINT_VBE_ERR("vbeGetMode",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
473 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
474 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
475 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
476 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
477 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
478 PRINT_VBE_ERR("vbeGetModeInfo",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
479 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
480 }
2293
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
481 if(!(yuv_buffer = malloc(video_mode_info.XResolution*video_mode_info.YResolution*4)))
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
482 {
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
483 printf("vo_vesa: Can't allocate temporary buffer\n");
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
484 return -1;
638cd37032da Better resolution detection
nick
parents: 2255
diff changeset
485 }
2304
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
486 if( vesa_zoom )
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
487 {
2304
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
488 if( format==IMGFMT_YV12 )
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
489 {
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
490 /* software scale */
2305
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
491 vesa_aspect(width,height,
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
492 video_mode_info.XResolution,video_mode_info.YResolution,
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
493 &image_width,&image_height);
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
494 /* image_width = video_mode_info.XResolution;
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
495 image_height = video_mode_info.YResolution; */
2304
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
496 scale_xinc=(width << 16) / image_width - 2; /* needed for proper rounding */
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
497 scale_yinc=(height << 16) / image_height + 2;
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
498 SwScale_Init();
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
499 if(verbose) printf("vo_vesa: Using SCALE\n");
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
500 }
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
501 else
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
502 {
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
503 printf("vo_vesa: Can't apply zooming to non YV12 formats\n");
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
504 return -1;
0769b2fb3ce2 Fixed zooming bug
nick
parents: 2298
diff changeset
505 }
2298
674acdf0aa43 SwScaling support
nick
parents: 2296
diff changeset
506 }
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
507 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
508 win.idx = 0; /* frame A */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
509 else
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
510 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
511 win.idx = 1; /* frame B */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
512 else { printf("vo_vesa: Can't find usable frame of window\n"); return -1; }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
513 if(!(win_seg = win.idx == 0 ? video_mode_info.WinASegment:video_mode_info.WinBSegment))
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
514 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
515 printf("vo_vesa: Can't find valid window address\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
516 if(video_mode_info.ModeAttributes & MODE_ATTR_LINEAR)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
517 printf("vo_vesa: Your BIOS supports DGA access which is not implemented for now\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
518 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
519 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
520 win.ptr = PhysToVirtSO(win_seg,0);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
521 win.low = 0L;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
522 win.high= video_mode_info.WinSize*1024;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
523 x_offset = (video_mode_info.XResolution - image_width) / 2;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
524 y_offset = (video_mode_info.YResolution - image_height) / 2;
2305
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
525 if(verbose)
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
526 printf("vo_vesa: image: %ux%u screen = %ux%u x_offset = %u y_offset = %u\n"
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
527 ,image_width,image_height
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
528 ,video_mode_info.XResolution,video_mode_info.YResolution
82c17b134946 Fixed half-image bug and added computing of correct aspect during zooming
nick
parents: 2304
diff changeset
529 ,x_offset,y_offset);
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
530 if((err=vbeSaveState(&init_state)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
531 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
532 PRINT_VBE_ERR("vbeSaveState",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
533 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
534 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
535 if((err=vbeSetMode(video_mode,NULL)) != VBE_OK)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
536 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
537 PRINT_VBE_ERR("vbeSetMode",err);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
538 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
539 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
540 /* Now we are in video mode!!!*/
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
541 if(verbose)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
542 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
543 printf("vo_vesa: Graphics mode was activated\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
544 fflush(stdout);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
545 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
546 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
547 else
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
548 {
2255
98c2bfc87825 More hints. Use save-restore mechanism
nick
parents: 2244
diff changeset
549 printf("vo_vesa: Can't find mode for: %ux%u@%u\n",width,height,bpp);
2244
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
550 return -1;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
551 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
552 if(verbose)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
553 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
554 printf("vo_vesa: VESA initialization complete\n");
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
555 fflush(stdout);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
556 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
557 if(verbose)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
558 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
559 int x_res = video_mode_info.XResolution;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
560 int y_res = video_mode_info.YResolution;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
561 int x, y;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
562
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
563 for (y = 0; y < y_res; ++y)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
564 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
565 for (x = 0; x < x_res; ++x)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
566 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
567 int r, g, b;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
568 if ((x & 16) ^ (y & 16))
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
569 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
570 r = x * 255 / x_res;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
571 g = y * 255 / y_res;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
572 b = 255 - x * 255 / x_res;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
573 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
574 else
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
575 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
576 r = 255 - x * 255 / x_res;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
577 g = y * 255 / y_res;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
578 b = 255 - y * 255 / y_res;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
579 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
580
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
581 __vbeSetPixel(x, y, r, g, b);
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
582 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
583 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
584 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
585 return 0;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
586 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
587
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
588 static const vo_info_t*
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
589 get_info(void)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
590 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
591 return &vo_info;
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
592 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
593
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
594 static void
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
595 uninit(void)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
596 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
597 vesa_term();
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
598 }
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
599
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
600
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
601 static void check_events(void)
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
602 {
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
603 /* Nothing to do */
4e464b527f5a vo_vesa support
nick
parents:
diff changeset
604 }