1 |
|
/* |
2 |
|
* video_amiga.cpp - Video/graphics emulation, AmigaOS specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2002 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
25 |
|
#include <cybergraphics/cybergraphics.h> |
26 |
|
#include <dos/dostags.h> |
27 |
|
#include <devices/timer.h> |
28 |
+ |
#define __USE_SYSBASE |
29 |
|
#include <proto/exec.h> |
30 |
|
#include <proto/dos.h> |
31 |
|
#include <proto/intuition.h> |
32 |
|
#include <proto/graphics.h> |
33 |
|
#include <proto/Picasso96.h> |
34 |
|
#include <proto/cybergraphics.h> |
35 |
+ |
#include <inline/exec.h> |
36 |
+ |
#include <inline/dos.h> |
37 |
+ |
#include <inline/intuition.h> |
38 |
+ |
#include <inline/Picasso96.h> |
39 |
+ |
#include <inline/cybergraphics.h> |
40 |
|
|
41 |
|
#include "sysdeps.h" |
42 |
|
#include "cpu_emulation.h" |
50 |
|
#include "debug.h" |
51 |
|
|
52 |
|
|
53 |
+ |
// Supported video modes |
54 |
+ |
static vector<video_mode> VideoModes; |
55 |
+ |
|
56 |
|
// Display types |
57 |
|
enum { |
58 |
|
DISPLAY_WINDOW, |
63 |
|
|
64 |
|
// Global variables |
65 |
|
static int32 frame_skip; |
66 |
< |
static int display_type = DISPLAY_WINDOW; // See enum above |
67 |
< |
static struct Screen *the_screen = NULL; |
68 |
< |
static struct Window *the_win = NULL; |
60 |
< |
static struct BitMap *the_bitmap = NULL; |
61 |
< |
static UWORD *null_pointer = NULL; // Blank mouse pointer data |
62 |
< |
static UWORD *current_pointer = (UWORD *)-1; // Currently visible mouse pointer data |
63 |
< |
static LONG black_pen = -1, white_pen = -1; |
64 |
< |
static struct Process *periodic_proc = NULL; // Periodic process |
65 |
< |
static int window_width, window_height; // width and height for window display |
66 |
< |
static ULONG screen_mode_id; // mode ID for screen display |
66 |
> |
static UWORD *null_pointer = NULL; // Blank mouse pointer data |
67 |
> |
static UWORD *current_pointer = (UWORD *)-1; // Currently visible mouse pointer data |
68 |
> |
static struct Process *periodic_proc = NULL; // Periodic process |
69 |
|
|
70 |
< |
extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) |
70 |
> |
extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) |
71 |
|
|
72 |
|
|
73 |
|
// Amiga -> Mac raw keycode translation table |
91 |
|
}; |
92 |
|
|
93 |
|
|
94 |
< |
// Prototypes |
95 |
< |
static bool video_open(const video_mode &mode); |
96 |
< |
static void video_close(); |
97 |
< |
static void periodic_func(void); |
98 |
< |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth); |
99 |
< |
static void add_modes(uint32 width, uint32 height, video_depth depth); |
100 |
< |
static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth); |
101 |
< |
static ULONG bits_from_depth(video_depth depth); |
102 |
< |
static bool is_valid_modeid(int display_type, ULONG mode_id); |
103 |
< |
static bool check_modeid_p96(ULONG mode_id); |
104 |
< |
static bool check_modeid_cgfx(ULONG mode_id); |
94 |
> |
class Amiga_monitor_desc : public monitor_desc { |
95 |
> |
public: |
96 |
> |
Amiga_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id, int default_display_type) |
97 |
> |
: monitor_desc(available_modes, default_depth, default_id), display_type(default_display_type) {}; |
98 |
> |
~Amiga_monitor_desc() {}; |
99 |
> |
|
100 |
> |
virtual void switch_to_current_mode(void); |
101 |
> |
virtual void set_palette(uint8 *pal, int num); |
102 |
> |
|
103 |
> |
bool video_open(void); |
104 |
> |
void video_close(void); |
105 |
> |
public: |
106 |
> |
int display_type; // See enum above |
107 |
> |
}; |
108 |
|
|
109 |
|
|
110 |
|
/* |
111 |
< |
* Initialization |
111 |
> |
* Display "driver" classes |
112 |
|
*/ |
113 |
|
|
114 |
+ |
class driver_base { |
115 |
+ |
public: |
116 |
+ |
driver_base(Amiga_monitor_desc &m); |
117 |
+ |
virtual ~driver_base(); |
118 |
+ |
|
119 |
+ |
virtual void set_palette(uint8 *pal, int num) {}; |
120 |
+ |
virtual struct BitMap *get_bitmap() { return NULL; }; |
121 |
+ |
public: |
122 |
+ |
Amiga_monitor_desc &monitor; // Associated video monitor |
123 |
+ |
const video_mode &mode; // Video mode handled by the driver |
124 |
+ |
BOOL init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
125 |
+ |
struct Window *the_win; |
126 |
+ |
}; |
127 |
|
|
110 |
– |
// Open window |
111 |
– |
static bool init_window(int width, int height) |
112 |
– |
{ |
113 |
– |
// Set absolute mouse mode |
114 |
– |
ADBSetRelMouseMode(false); |
115 |
– |
|
116 |
– |
// Open window |
117 |
– |
the_win = OpenWindowTags(NULL, |
118 |
– |
WA_Left, 0, WA_Top, 0, |
119 |
– |
WA_InnerWidth, width, WA_InnerHeight, height, |
120 |
– |
WA_SimpleRefresh, TRUE, |
121 |
– |
WA_NoCareRefresh, TRUE, |
122 |
– |
WA_Activate, TRUE, |
123 |
– |
WA_RMBTrap, TRUE, |
124 |
– |
WA_ReportMouse, TRUE, |
125 |
– |
WA_DragBar, TRUE, |
126 |
– |
WA_DepthGadget, TRUE, |
127 |
– |
WA_SizeGadget, FALSE, |
128 |
– |
WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
129 |
– |
TAG_END |
130 |
– |
); |
131 |
– |
if (the_win == NULL) { |
132 |
– |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
133 |
– |
return false; |
134 |
– |
} |
135 |
– |
|
136 |
– |
// Create bitmap ("height + 2" for safety) |
137 |
– |
the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL); |
138 |
– |
if (the_bitmap == NULL) { |
139 |
– |
ErrorAlert(STR_NO_MEM_ERR); |
140 |
– |
return false; |
141 |
– |
} |
142 |
– |
|
143 |
– |
// Add resolution and set VideoMonitor |
144 |
– |
VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0]; |
145 |
– |
|
146 |
– |
// Set FgPen and BgPen |
147 |
– |
black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); |
148 |
– |
white_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0xffffffff, 0xffffffff, 0xffffffff, NULL); |
149 |
– |
SetAPen(the_win->RPort, black_pen); |
150 |
– |
SetBPen(the_win->RPort, white_pen); |
151 |
– |
SetDrMd(the_win->RPort, JAM2); |
152 |
– |
return true; |
153 |
– |
} |
154 |
– |
|
155 |
– |
// Open PIP (requires Picasso96) |
156 |
– |
static bool init_pip(int width, int height) |
157 |
– |
{ |
158 |
– |
// Set absolute mouse mode |
159 |
– |
ADBSetRelMouseMode(false); |
160 |
– |
|
161 |
– |
// Open window |
162 |
– |
ULONG error = 0; |
163 |
– |
the_win = p96PIP_OpenTags( |
164 |
– |
P96PIP_SourceFormat, RGBFB_R5G5B5, |
165 |
– |
P96PIP_SourceWidth, width, |
166 |
– |
P96PIP_SourceHeight, height, |
167 |
– |
P96PIP_ErrorCode, (ULONG)&error, |
168 |
– |
WA_Left, 0, WA_Top, 0, |
169 |
– |
WA_InnerWidth, width, WA_InnerHeight, height, |
170 |
– |
WA_SimpleRefresh, TRUE, |
171 |
– |
WA_NoCareRefresh, TRUE, |
172 |
– |
WA_Activate, TRUE, |
173 |
– |
WA_RMBTrap, TRUE, |
174 |
– |
WA_ReportMouse, TRUE, |
175 |
– |
WA_DragBar, TRUE, |
176 |
– |
WA_DepthGadget, TRUE, |
177 |
– |
WA_SizeGadget, FALSE, |
178 |
– |
WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
179 |
– |
WA_PubScreenName, (ULONG)"Workbench", |
180 |
– |
TAG_END |
181 |
– |
); |
182 |
– |
if (the_win == NULL || error) { |
183 |
– |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
184 |
– |
return false; |
185 |
– |
} |
186 |
– |
|
187 |
– |
// Find bitmap |
188 |
– |
p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); |
189 |
– |
|
190 |
– |
// Add resolution and set VideoMonitor |
191 |
– |
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); |
128 |
|
|
129 |
< |
return true; |
130 |
< |
} |
129 |
> |
class driver_window : public driver_base { |
130 |
> |
public: |
131 |
> |
driver_window(Amiga_monitor_desc &m, int width, int height); |
132 |
> |
~driver_window(); |
133 |
> |
|
134 |
> |
struct BitMap *get_bitmap() { return the_bitmap; }; |
135 |
> |
|
136 |
> |
private: |
137 |
> |
LONG black_pen, white_pen; |
138 |
> |
struct BitMap *the_bitmap; |
139 |
> |
}; |
140 |
|
|
141 |
< |
// Open Picasso96 screen |
142 |
< |
static bool init_screen_p96(ULONG mode_id) |
143 |
< |
{ |
144 |
< |
// Set relative mouse mode |
200 |
< |
ADBSetRelMouseMode(true); |
141 |
> |
class driver_pip : public driver_base { |
142 |
> |
public: |
143 |
> |
driver_pip(Amiga_monitor_desc &m, int width, int height); |
144 |
> |
~driver_pip(); |
145 |
|
|
146 |
< |
// Check if the mode is one we can handle |
203 |
< |
if (!check_modeid_p96(mode_id)) |
204 |
< |
{ |
205 |
< |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
206 |
< |
return false; |
207 |
< |
} |
146 |
> |
struct BitMap *get_bitmap() { return the_bitmap; }; |
147 |
|
|
148 |
< |
// Yes, get width and height |
149 |
< |
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
150 |
< |
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
212 |
< |
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
148 |
> |
private: |
149 |
> |
struct BitMap *the_bitmap; |
150 |
> |
}; |
151 |
|
|
152 |
< |
// Open screen |
153 |
< |
the_screen = p96OpenScreenTags( |
154 |
< |
P96SA_DisplayID, mode_id, |
155 |
< |
P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
218 |
< |
P96SA_Quiet, TRUE, |
219 |
< |
P96SA_NoMemory, TRUE, |
220 |
< |
P96SA_NoSprite, TRUE, |
221 |
< |
P96SA_Exclusive, TRUE, |
222 |
< |
TAG_END |
223 |
< |
); |
224 |
< |
if (the_screen == NULL) { |
225 |
< |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
226 |
< |
return false; |
227 |
< |
} |
152 |
> |
class driver_screen_p96 : public driver_base { |
153 |
> |
public: |
154 |
> |
driver_screen_p96(Amiga_monitor_desc &m, ULONG mode_id); |
155 |
> |
~driver_screen_p96(); |
156 |
|
|
157 |
< |
// Open window |
230 |
< |
the_win = OpenWindowTags(NULL, |
231 |
< |
WA_Left, 0, WA_Top, 0, |
232 |
< |
WA_Width, width, WA_Height, height, |
233 |
< |
WA_SimpleRefresh, TRUE, |
234 |
< |
WA_NoCareRefresh, TRUE, |
235 |
< |
WA_Borderless, TRUE, |
236 |
< |
WA_Activate, TRUE, |
237 |
< |
WA_RMBTrap, TRUE, |
238 |
< |
WA_ReportMouse, TRUE, |
239 |
< |
WA_CustomScreen, (ULONG)the_screen, |
240 |
< |
TAG_END |
241 |
< |
); |
242 |
< |
if (the_win == NULL) { |
243 |
< |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
244 |
< |
return false; |
245 |
< |
} |
157 |
> |
void set_palette(uint8 *pal, int num); |
158 |
|
|
159 |
< |
ScreenToFront(the_screen); |
159 |
> |
private: |
160 |
> |
struct Screen *the_screen; |
161 |
> |
}; |
162 |
|
|
163 |
< |
// Add resolution and set VideoMonitor |
164 |
< |
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
163 |
> |
class driver_screen_cgfx : public driver_base { |
164 |
> |
public: |
165 |
> |
driver_screen_cgfx(Amiga_monitor_desc &m, ULONG mode_id); |
166 |
> |
~driver_screen_cgfx(); |
167 |
|
|
168 |
< |
return true; |
253 |
< |
} |
168 |
> |
void set_palette(uint8 *pal, int num); |
169 |
|
|
170 |
< |
// Open CyberGraphX screen |
171 |
< |
static bool init_screen_cgfx(ULONG mode_id) |
172 |
< |
{ |
258 |
< |
// Set relative mouse mode |
259 |
< |
ADBSetRelMouseMode(true); |
170 |
> |
private: |
171 |
> |
struct Screen *the_screen; |
172 |
> |
}; |
173 |
|
|
261 |
– |
// Check if the mode is one we can handle |
262 |
– |
if (!check_modeid_cgfx(mode_id)) |
263 |
– |
{ |
264 |
– |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
265 |
– |
return false; |
266 |
– |
} |
174 |
|
|
175 |
< |
// Yes, get width and height |
269 |
< |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
270 |
< |
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
271 |
< |
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
175 |
> |
static driver_base *drv = NULL; // Pointer to currently used driver object |
176 |
|
|
273 |
– |
// Open screen |
274 |
– |
the_screen = OpenScreenTags(NULL, |
275 |
– |
SA_DisplayID, mode_id, |
276 |
– |
SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
277 |
– |
SA_Quiet, TRUE, |
278 |
– |
SA_Exclusive, TRUE, |
279 |
– |
TAG_END |
280 |
– |
); |
281 |
– |
if (the_screen == NULL) { |
282 |
– |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
283 |
– |
return false; |
284 |
– |
} |
177 |
|
|
286 |
– |
// Open window |
287 |
– |
the_win = OpenWindowTags(NULL, |
288 |
– |
WA_Left, 0, WA_Top, 0, |
289 |
– |
WA_Width, width, WA_Height, height, |
290 |
– |
WA_SimpleRefresh, TRUE, |
291 |
– |
WA_NoCareRefresh, TRUE, |
292 |
– |
WA_Borderless, TRUE, |
293 |
– |
WA_Activate, TRUE, |
294 |
– |
WA_RMBTrap, TRUE, |
295 |
– |
WA_ReportMouse, TRUE, |
296 |
– |
WA_CustomScreen, (ULONG)the_screen, |
297 |
– |
TAG_END |
298 |
– |
); |
299 |
– |
if (the_win == NULL) { |
300 |
– |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
301 |
– |
return false; |
302 |
– |
} |
178 |
|
|
179 |
< |
ScreenToFront(the_screen); |
180 |
< |
static UWORD ptr[] = { 0, 0, 0, 0 }; |
181 |
< |
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer |
179 |
> |
// Prototypes |
180 |
> |
static void periodic_func(void); |
181 |
> |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth); |
182 |
> |
static void add_modes(uint32 width, uint32 height, video_depth depth); |
183 |
> |
static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth); |
184 |
> |
static ULONG bits_from_depth(video_depth depth); |
185 |
> |
static bool is_valid_modeid(int display_type, ULONG mode_id); |
186 |
> |
static bool check_modeid_p96(ULONG mode_id); |
187 |
> |
static bool check_modeid_cgfx(ULONG mode_id); |
188 |
|
|
308 |
– |
// Set VideoMonitor |
309 |
– |
ULONG frame_base; |
310 |
– |
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
311 |
– |
LBMI_BASEADDRESS, (ULONG)&frame_base, |
312 |
– |
TAG_END |
313 |
– |
); |
314 |
– |
UnLockBitMap(handle); |
189 |
|
|
190 |
< |
VideoMonitor.mac_frame_base = frame_base; |
190 |
> |
/* |
191 |
> |
* Initialization |
192 |
> |
*/ |
193 |
|
|
318 |
– |
return true; |
319 |
– |
} |
194 |
|
|
195 |
|
bool VideoInit(bool classic) |
196 |
|
{ |
197 |
< |
int default_width, default_height, default_depth; |
197 |
> |
video_depth default_depth = VDEPTH_1BIT; |
198 |
> |
int default_width, default_height; |
199 |
> |
int default_display_type = DISPLAY_WINDOW; |
200 |
> |
int window_width, window_height; // width and height for window display |
201 |
> |
ULONG screen_mode_id; // mode ID for screen display |
202 |
|
|
203 |
|
// Allocate blank mouse pointer data |
204 |
|
null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR); |
219 |
|
else |
220 |
|
mode_str = PrefsFindString("screen"); |
221 |
|
|
344 |
– |
// Determine type and mode |
345 |
– |
display_type = DISPLAY_WINDOW; |
346 |
– |
|
222 |
|
default_width = window_width = 512; |
223 |
|
default_height = window_height = 384; |
224 |
|
|
225 |
|
if (mode_str) { |
226 |
|
if (sscanf(mode_str, "win/%d/%d", &window_width, &window_height) == 2) |
227 |
< |
display_type = DISPLAY_WINDOW; |
227 |
> |
default_display_type = DISPLAY_WINDOW; |
228 |
|
else if (sscanf(mode_str, "pip/%d/%d", &window_width, &window_height) == 2 && P96Base) |
229 |
< |
display_type = DISPLAY_PIP; |
229 |
> |
default_display_type = DISPLAY_PIP; |
230 |
|
else if (sscanf(mode_str, "scr/%08lx", &screen_mode_id) == 1 && (CyberGfxBase || P96Base)) { |
231 |
|
if (P96Base && p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) |
232 |
< |
display_type = DISPLAY_SCREEN_P96; |
232 |
> |
default_display_type = DISPLAY_SCREEN_P96; |
233 |
|
else if (CyberGfxBase && IsCyberModeID(screen_mode_id)) |
234 |
< |
display_type = DISPLAY_SCREEN_CGFX; |
234 |
> |
default_display_type = DISPLAY_SCREEN_CGFX; |
235 |
|
else { |
236 |
|
ErrorAlert(STR_NO_P96_MODE_ERR); |
237 |
|
return false; |
239 |
|
} |
240 |
|
} |
241 |
|
|
242 |
+ |
D(bug("default_display_type %d, window_width %d, window_height %d\n", default_display_type, window_width, window_height)); |
243 |
+ |
|
244 |
|
// Construct list of supported modes |
245 |
< |
switch (display_type) { |
245 |
> |
switch (default_display_type) { |
246 |
|
case DISPLAY_WINDOW: |
247 |
|
default_width = window_width; |
248 |
|
default_height = window_height; |
249 |
< |
default_depth = 1; |
249 |
> |
default_depth = VDEPTH_1BIT; |
250 |
|
add_modes(window_width, window_height, VDEPTH_1BIT); |
251 |
|
break; |
252 |
|
|
253 |
|
case DISPLAY_PIP: |
254 |
< |
default_depth = 16; |
254 |
> |
default_depth = VDEPTH_16BIT; |
255 |
|
default_width = window_width; |
256 |
|
default_height = window_height; |
257 |
|
add_modes(window_width, window_height, VDEPTH_16BIT); |
262 |
|
struct DimensionInfo dimInfo; |
263 |
|
DisplayInfoHandle handle = FindDisplayInfo(screen_mode_id); |
264 |
|
|
265 |
< |
if (NULL == handle) |
265 |
> |
if (handle == NULL) |
266 |
|
return false; |
267 |
|
|
268 |
|
if (GetDisplayInfoData(handle, (UBYTE *) &dimInfo, sizeof(dimInfo), DTAG_DIMS, 0) <= 0) |
270 |
|
|
271 |
|
default_width = 1 + dimInfo.Nominal.MaxX - dimInfo.Nominal.MinX; |
272 |
|
default_height = 1 + dimInfo.Nominal.MaxY - dimInfo.Nominal.MinY; |
396 |
– |
default_depth = dimInfo.MaxDepth; |
273 |
|
|
274 |
< |
for (unsigned d=VDEPTH_8BIT; d<=VDEPTH_32BIT; d++) |
274 |
> |
switch (dimInfo.MaxDepth) |
275 |
|
{ |
276 |
+ |
case 1: |
277 |
+ |
default_depth = VDEPTH_1BIT; |
278 |
+ |
break; |
279 |
+ |
case 8: |
280 |
+ |
default_depth = VDEPTH_8BIT; |
281 |
+ |
break; |
282 |
+ |
case 15: |
283 |
+ |
case 16: |
284 |
+ |
default_depth = VDEPTH_16BIT; |
285 |
+ |
break; |
286 |
+ |
case 24: |
287 |
+ |
case 32: |
288 |
+ |
default_depth = VDEPTH_32BIT; |
289 |
+ |
break; |
290 |
+ |
} |
291 |
+ |
|
292 |
+ |
for (unsigned d=VDEPTH_8BIT; d<=VDEPTH_32BIT; d++) { |
293 |
|
ULONG mode_id = find_mode_for_depth(default_width, default_height, bits_from_depth(video_depth(d))); |
294 |
|
|
295 |
< |
if (is_valid_modeid(display_type, mode_id)) |
403 |
< |
{ |
295 |
> |
if (is_valid_modeid(default_display_type, mode_id)) |
296 |
|
add_modes(default_width, default_height, video_depth(d)); |
297 |
< |
} |
406 |
< |
} |
297 |
> |
} |
298 |
|
break; |
299 |
|
} |
300 |
|
|
301 |
< |
video_init_depth_list(); |
301 |
> |
// video_init_depth_list(); |
302 |
|
|
303 |
|
#if DEBUG |
304 |
|
bug("Available video modes:\n"); |
305 |
|
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
306 |
|
while (i != end) { |
307 |
< |
bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits_from_depth(i->depth)); |
307 |
> |
bug(" %ld x %ld (ID %02lx), %ld colors\n", i->x, i->y, i->resolution_id, 1 << bits_from_depth(i->depth)); |
308 |
|
++i; |
309 |
|
} |
310 |
|
#endif |
311 |
|
|
312 |
< |
D(bug("VideoInit: def_width=%ld def_height=%ld def_depth=%ld\n", default_width, default_height, default_depth)); |
312 |
> |
D(bug("VideoInit/%ld: def_width=%ld def_height=%ld def_depth=%ld\n", \ |
313 |
> |
__LINE__, default_width, default_height, default_depth)); |
314 |
|
|
315 |
|
// Find requested default mode and open display |
316 |
|
if (VideoModes.size() == 1) |
317 |
< |
return video_open(VideoModes[0]); |
317 |
> |
{ |
318 |
> |
uint32 default_id ; |
319 |
> |
|
320 |
> |
// Create Amiga_monitor_desc for this (the only) display |
321 |
> |
default_id = VideoModes[0].resolution_id; |
322 |
> |
D(bug("VideoInit/%ld: default_id=%ld\n", __LINE__, default_id)); |
323 |
> |
Amiga_monitor_desc *monitor = new Amiga_monitor_desc(VideoModes, default_depth, default_id, default_display_type); |
324 |
> |
VideoMonitors.push_back(monitor); |
325 |
> |
|
326 |
> |
// Open display |
327 |
> |
return monitor->video_open(); |
328 |
> |
} |
329 |
|
else { |
330 |
|
// Find mode with specified dimensions |
331 |
|
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
332 |
< |
for (i = VideoModes.begin(); i != end; ++i) |
333 |
< |
{ |
334 |
< |
D(bug("VideoInit: w=%ld h=%ld d=%ld\n", i->x, i->y, bits_from_depth(i->depth))); |
335 |
< |
if (i->x == default_width && i->y == default_height && bits_from_depth(i->depth) == default_depth) |
336 |
< |
return video_open(*i); |
337 |
< |
} |
338 |
< |
return video_open(VideoModes[0]); |
332 |
> |
for (i = VideoModes.begin(); i != end; ++i) { |
333 |
> |
D(bug("VideoInit/%ld: w=%ld h=%ld d=%ld\n", __LINE__, i->x, i->y, bits_from_depth(i->depth))); |
334 |
> |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) |
335 |
> |
{ |
336 |
> |
// Create Amiga_monitor_desc for this (the only) display |
337 |
> |
uint32 default_id = i->resolution_id; |
338 |
> |
D(bug("VideoInit/%ld: default_id=%ld\n", __LINE__, default_id)); |
339 |
> |
Amiga_monitor_desc *monitor = new Amiga_monitor_desc(VideoModes, default_depth, default_id, default_display_type); |
340 |
> |
VideoMonitors.push_back(monitor); |
341 |
> |
|
342 |
> |
// Open display |
343 |
> |
return monitor->video_open(); |
344 |
> |
} |
345 |
> |
} |
346 |
> |
|
347 |
> |
// Create Amiga_monitor_desc for this (the only) display |
348 |
> |
uint32 default_id = VideoModes[0].resolution_id; |
349 |
> |
D(bug("VideoInit/%ld: default_id=%ld\n", __LINE__, default_id)); |
350 |
> |
Amiga_monitor_desc *monitor = new Amiga_monitor_desc(VideoModes, default_depth, default_id, default_display_type); |
351 |
> |
VideoMonitors.push_back(monitor); |
352 |
> |
|
353 |
> |
// Open display |
354 |
> |
return monitor->video_open(); |
355 |
|
} |
356 |
|
|
357 |
|
return true; |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
< |
static bool video_open(const video_mode &mode) |
361 |
> |
bool Amiga_monitor_desc::video_open() |
362 |
|
{ |
363 |
+ |
const video_mode &mode = get_current_mode(); |
364 |
|
ULONG depth_bits = bits_from_depth(mode.depth); |
365 |
|
ULONG ID = find_mode_for_depth(mode.x, mode.y, depth_bits); |
366 |
|
|
367 |
< |
D(bug("video_open: width=%ld height=%ld depth=%ld ID=%08lx\n", mode.x, mode.y, depth_bits, ID)); |
367 |
> |
D(bug("video_open/%ld: width=%ld height=%ld depth=%ld ID=%08lx\n", __LINE__, mode.x, mode.y, depth_bits, ID)); |
368 |
|
|
369 |
< |
if (INVALID_ID == ID) |
450 |
< |
{ |
369 |
> |
if (ID == INVALID_ID) { |
370 |
|
ErrorAlert(STR_NO_VIDEO_MODE_ERR); |
371 |
|
return false; |
372 |
< |
} |
372 |
> |
} |
373 |
|
|
374 |
< |
VideoMonitor.mode = mode; |
374 |
> |
// VideoMonitor.mode = mode; |
375 |
> |
|
376 |
> |
D(bug("video_open/%ld: display_type=%ld\n", __LINE__, display_type)); |
377 |
|
|
378 |
|
// Open display |
379 |
|
switch (display_type) { |
380 |
|
case DISPLAY_WINDOW: |
381 |
< |
if (!init_window(mode.x, mode.y)) |
461 |
< |
return false; |
381 |
> |
drv = new driver_window(*this, mode.x, mode.y); |
382 |
|
break; |
383 |
|
|
384 |
|
case DISPLAY_PIP: |
385 |
< |
if (!init_pip(mode.x, mode.y)) |
466 |
< |
return false; |
385 |
> |
drv = new driver_pip(*this, mode.x, mode.y); |
386 |
|
break; |
387 |
|
|
388 |
|
case DISPLAY_SCREEN_P96: |
389 |
< |
if (!init_screen_p96(ID)) |
471 |
< |
return false; |
389 |
> |
drv = new driver_screen_p96(*this, ID); |
390 |
|
break; |
391 |
|
|
392 |
|
case DISPLAY_SCREEN_CGFX: |
393 |
< |
if (!init_screen_cgfx(ID)) |
476 |
< |
return false; |
393 |
> |
drv = new driver_screen_cgfx(*this, ID); |
394 |
|
break; |
395 |
|
} |
396 |
|
|
397 |
+ |
D(bug("video_open/%ld: drv=%08lx\n", __LINE__, drv)); |
398 |
+ |
|
399 |
+ |
if (drv == NULL) |
400 |
+ |
return false; |
401 |
+ |
|
402 |
+ |
D(bug("video_open/%ld: init_ok=%ld\n", __LINE__, drv->init_ok)); |
403 |
+ |
if (!drv->init_ok) { |
404 |
+ |
delete drv; |
405 |
+ |
drv = NULL; |
406 |
+ |
return false; |
407 |
+ |
} |
408 |
+ |
|
409 |
|
// Start periodic process |
410 |
|
periodic_proc = CreateNewProcTags( |
411 |
|
NP_Entry, (ULONG)periodic_func, |
413 |
|
NP_Priority, 0, |
414 |
|
TAG_END |
415 |
|
); |
416 |
+ |
|
417 |
+ |
D(bug("video_open/%ld: periodic_proc=%08lx\n", __LINE__, periodic_proc)); |
418 |
+ |
|
419 |
|
if (periodic_proc == NULL) { |
420 |
|
ErrorAlert(STR_NO_MEM_ERR); |
421 |
|
return false; |
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
< |
static void video_close() |
428 |
> |
void Amiga_monitor_desc::video_close() |
429 |
|
{ |
430 |
|
// Stop periodic process |
431 |
|
if (periodic_proc) { |
434 |
|
Wait(SIGF_SINGLE); |
435 |
|
} |
436 |
|
|
437 |
< |
switch (display_type) { |
506 |
< |
|
507 |
< |
case DISPLAY_WINDOW: |
508 |
< |
|
509 |
< |
// Window mode, free bitmap |
510 |
< |
if (the_bitmap) { |
511 |
< |
WaitBlit(); |
512 |
< |
FreeBitMap(the_bitmap); |
513 |
< |
} |
514 |
< |
|
515 |
< |
// Free pens and close window |
516 |
< |
if (the_win) { |
517 |
< |
ReleasePen(the_win->WScreen->ViewPort.ColorMap, black_pen); |
518 |
< |
ReleasePen(the_win->WScreen->ViewPort.ColorMap, white_pen); |
519 |
< |
|
520 |
< |
CloseWindow(the_win); |
521 |
< |
the_win = NULL; |
522 |
< |
} |
523 |
< |
break; |
524 |
< |
|
525 |
< |
case DISPLAY_PIP: |
526 |
< |
|
527 |
< |
// Close PIP |
528 |
< |
if (the_win) |
529 |
< |
p96PIP_Close(the_win); |
530 |
< |
break; |
531 |
< |
|
532 |
< |
case DISPLAY_SCREEN_P96: |
533 |
< |
|
534 |
< |
// Close window |
535 |
< |
if (the_win) |
536 |
< |
{ |
537 |
< |
CloseWindow(the_win); |
538 |
< |
the_win = NULL; |
539 |
< |
} |
540 |
< |
|
541 |
< |
// Close screen |
542 |
< |
if (the_screen) { |
543 |
< |
p96CloseScreen(the_screen); |
544 |
< |
the_screen = NULL; |
545 |
< |
} |
546 |
< |
break; |
547 |
< |
|
548 |
< |
case DISPLAY_SCREEN_CGFX: |
549 |
< |
|
550 |
< |
// Close window |
551 |
< |
if (the_win) |
552 |
< |
{ |
553 |
< |
CloseWindow(the_win); |
554 |
< |
the_win = NULL; |
555 |
< |
} |
556 |
< |
|
557 |
< |
// Close screen |
558 |
< |
if (the_screen) { |
559 |
< |
CloseScreen(the_screen); |
560 |
< |
the_screen = NULL; |
561 |
< |
} |
562 |
< |
break; |
563 |
< |
} |
437 |
> |
delete drv; |
438 |
|
|
439 |
|
// Free mouse pointer |
440 |
|
if (null_pointer) { |
450 |
|
|
451 |
|
void VideoExit(void) |
452 |
|
{ |
453 |
< |
video_close(); |
453 |
> |
// Close displays |
454 |
> |
vector<monitor_desc *>::iterator i, end = VideoMonitors.end(); |
455 |
> |
for (i = VideoMonitors.begin(); i != end; ++i) |
456 |
> |
dynamic_cast<Amiga_monitor_desc *>(*i)->video_close(); |
457 |
|
} |
458 |
|
|
459 |
|
|
461 |
|
* Set palette |
462 |
|
*/ |
463 |
|
|
464 |
< |
void video_set_palette(uint8 *pal, int num) |
464 |
> |
void Amiga_monitor_desc::set_palette(uint8 *pal, int num) |
465 |
|
{ |
466 |
< |
if ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
590 |
< |
&& !IsDirectMode(VideoMonitor.mode)) { |
591 |
< |
|
592 |
< |
// Convert palette to 32 bits |
593 |
< |
ULONG table[2 + 256 * 3]; |
594 |
< |
table[0] = num << 16; |
595 |
< |
table[num * 3 + 1] = 0; |
596 |
< |
for (int i=0; i<num; i++) { |
597 |
< |
table[i*3+1] = pal[i*3] * 0x01010101; |
598 |
< |
table[i*3+2] = pal[i*3+1] * 0x01010101; |
599 |
< |
table[i*3+3] = pal[i*3+2] * 0x01010101; |
600 |
< |
} |
601 |
< |
|
602 |
< |
// And load it |
603 |
< |
LoadRGB32(&the_screen->ViewPort, table); |
604 |
< |
} |
466 |
> |
drv->set_palette(pal, num); |
467 |
|
} |
468 |
|
|
469 |
|
|
471 |
|
* Switch video mode |
472 |
|
*/ |
473 |
|
|
474 |
< |
void video_switch_to_mode(const video_mode &mode) |
474 |
> |
void Amiga_monitor_desc::switch_to_current_mode() |
475 |
|
{ |
476 |
|
// Close and reopen display |
477 |
|
video_close(); |
478 |
< |
if (!video_open(mode)) |
617 |
< |
{ |
478 |
> |
if (!video_open()) { |
479 |
|
ErrorAlert(STR_OPEN_WINDOW_ERR); |
480 |
|
QuitEmulator(); |
481 |
< |
} |
481 |
> |
} |
482 |
|
} |
483 |
|
|
484 |
|
|
511 |
|
struct IntuiMessage *msg; |
512 |
|
ULONG win_mask = 0, timer_mask = 0; |
513 |
|
|
514 |
+ |
D(bug("periodic_func/%ld: \n", __LINE__)); |
515 |
+ |
|
516 |
|
// Create message port for window and attach it |
517 |
|
struct MsgPort *win_port = CreateMsgPort(); |
518 |
|
if (win_port) { |
519 |
|
win_mask = 1 << win_port->mp_SigBit; |
520 |
< |
the_win->UserPort = win_port; |
521 |
< |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); |
520 |
> |
drv->the_win->UserPort = win_port; |
521 |
> |
ModifyIDCMP(drv->the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | |
522 |
> |
((drv->monitor.display_type == DISPLAY_SCREEN_P96 || drv->monitor.display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); |
523 |
|
} |
524 |
|
|
525 |
+ |
D(bug("periodic_func/%ld: \n", __LINE__)); |
526 |
+ |
|
527 |
|
// Start 60Hz timer for window refresh |
528 |
< |
if (display_type == DISPLAY_WINDOW) { |
528 |
> |
if (drv->monitor.display_type == DISPLAY_WINDOW) { |
529 |
|
timer_port = CreateMsgPort(); |
530 |
|
if (timer_port) { |
531 |
|
timer_io = (struct timerequest *)CreateIORequest(timer_port, sizeof(struct timerequest)); |
532 |
|
if (timer_io) { |
533 |
< |
if (!OpenDevice((UBYTE *)TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timer_io, 0)) { |
533 |
> |
if (!OpenDevice((UBYTE *) TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timer_io, 0)) { |
534 |
|
timer_mask = 1 << timer_port->mp_SigBit; |
535 |
|
timer_io->tr_node.io_Command = TR_ADDREQUEST; |
536 |
|
timer_io->tr_time.tv_secs = 0; |
541 |
|
} |
542 |
|
} |
543 |
|
|
544 |
+ |
D(bug("periodic_func/%ld: \n", __LINE__)); |
545 |
+ |
|
546 |
|
// Main loop |
547 |
|
for (;;) { |
548 |
+ |
const video_mode &mode = drv->monitor.get_current_mode(); |
549 |
|
|
550 |
|
// Wait for timer and/or window (CTRL_C is used for quitting the task) |
551 |
|
ULONG sig = Wait(win_mask | timer_mask | SIGBREAKF_CTRL_C); |
553 |
|
if (sig & SIGBREAKF_CTRL_C) |
554 |
|
break; |
555 |
|
|
556 |
< |
if (sig & timer_mask) { |
556 |
> |
// D(bug("periodic_func/%ld: display_type=%ld the_win=%08lx\n", __LINE__, drv->monitor.display_type, drv->the_win)); |
557 |
|
|
558 |
< |
// Timer tick, update display |
559 |
< |
BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, |
560 |
< |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); |
558 |
> |
if (sig & timer_mask) { |
559 |
> |
if (drv->get_bitmap()) |
560 |
> |
{ |
561 |
> |
// Timer tick, update display |
562 |
> |
BltTemplate(drv->get_bitmap()->Planes[0], 0, |
563 |
> |
drv->get_bitmap()->BytesPerRow, drv->the_win->RPort, |
564 |
> |
drv->the_win->BorderLeft, drv->the_win->BorderTop, |
565 |
> |
mode.x, mode.y); |
566 |
> |
} |
567 |
|
|
568 |
|
// Restart timer |
569 |
|
timer_io->tr_node.io_Command = TR_ADDREQUEST; |
588 |
|
// Handle message according to class |
589 |
|
switch (cl) { |
590 |
|
case IDCMP_MOUSEMOVE: |
591 |
< |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
591 |
> |
switch (drv->monitor.display_type) |
592 |
> |
{ |
593 |
> |
case DISPLAY_SCREEN_P96: |
594 |
> |
case DISPLAY_SCREEN_CGFX: |
595 |
> |
// D(bug("periodic_func/%ld: IDCMP_MOUSEMOVE mx=%ld my=%ld\n", __LINE__, mx, my)); |
596 |
|
ADBMouseMoved(mx, my); |
597 |
< |
else { |
598 |
< |
ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); |
599 |
< |
if (mx < the_win->BorderLeft |
600 |
< |
|| my < the_win->BorderTop |
601 |
< |
|| mx >= the_win->BorderLeft + VideoMonitor.mode.x |
602 |
< |
|| my >= the_win->BorderTop + VideoMonitor.mode.y) { |
597 |
> |
break; |
598 |
> |
default: |
599 |
> |
// D(bug("periodic_func/%ld: IDCMP_MOUSEMOVE mx=%ld my=%ld\n", __LINE__, mx - drv->the_win->BorderLeft, my - drv->the_win->BorderTop)); |
600 |
> |
ADBMouseMoved(mx - drv->the_win->BorderLeft, my - drv->the_win->BorderTop); |
601 |
> |
if (mx < drv->the_win->BorderLeft |
602 |
> |
|| my < drv->the_win->BorderTop |
603 |
> |
|| mx >= drv->the_win->BorderLeft + mode.x |
604 |
> |
|| my >= drv->the_win->BorderTop + mode.y) { |
605 |
|
if (current_pointer) { |
606 |
< |
ClearPointer(the_win); |
606 |
> |
ClearPointer(drv->the_win); |
607 |
|
current_pointer = NULL; |
608 |
|
} |
609 |
|
} else { |
610 |
|
if (current_pointer != null_pointer) { |
611 |
|
// Hide mouse pointer inside window |
612 |
< |
SetPointer(the_win, null_pointer, 1, 16, 0, 0); |
612 |
> |
SetPointer(drv->the_win, null_pointer, 1, 16, 0, 0); |
613 |
|
current_pointer = null_pointer; |
614 |
|
} |
615 |
|
} |
616 |
< |
} |
616 |
> |
break; |
617 |
> |
} |
618 |
|
break; |
619 |
|
|
620 |
|
case IDCMP_MOUSEBUTTONS: |
652 |
|
} |
653 |
|
} |
654 |
|
|
655 |
+ |
D(bug("periodic_func/%ld: \n", __LINE__)); |
656 |
+ |
|
657 |
|
// Stop timer |
658 |
|
if (timer_io) { |
659 |
|
if (!CheckIO((struct IORequest *)timer_io)) |
670 |
|
msg = (struct IntuiMessage *)win_port->mp_MsgList.lh_Head; |
671 |
|
struct Node *succ; |
672 |
|
while (succ = msg->ExecMessage.mn_Node.ln_Succ) { |
673 |
< |
if (msg->IDCMPWindow == the_win) { |
673 |
> |
if (msg->IDCMPWindow == drv->the_win) { |
674 |
|
Remove((struct Node *)msg); |
675 |
|
ReplyMsg((struct Message *)msg); |
676 |
|
} |
677 |
|
msg = (struct IntuiMessage *)succ; |
678 |
|
} |
679 |
< |
the_win->UserPort = NULL; |
680 |
< |
ModifyIDCMP(the_win, 0); |
679 |
> |
drv->the_win->UserPort = NULL; |
680 |
> |
ModifyIDCMP(drv->the_win, 0); |
681 |
|
Permit(); |
682 |
|
DeleteMsgPort(win_port); |
683 |
|
|
702 |
|
VideoModes.push_back(mode); |
703 |
|
} |
704 |
|
|
705 |
< |
// Add standard list of windowed modes for given color depth |
705 |
> |
// Add standard list of modes for given color depth |
706 |
|
static void add_modes(uint32 width, uint32 height, video_depth depth) |
707 |
|
{ |
708 |
|
D(bug("add_modes: w=%ld h=%ld d=%ld\n", width, height, depth)); |
753 |
|
if (INVALID_ID == mode_id) |
754 |
|
return false; |
755 |
|
|
756 |
< |
switch (display_type) |
757 |
< |
{ |
758 |
< |
case DISPLAY_SCREEN_P96: |
759 |
< |
return check_modeid_p96(mode_id); |
760 |
< |
break; |
761 |
< |
case DISPLAY_SCREEN_CGFX: |
762 |
< |
return check_modeid_cgfx(mode_id); |
763 |
< |
break; |
764 |
< |
default: |
765 |
< |
return false; |
766 |
< |
break; |
883 |
< |
} |
756 |
> |
switch (display_type) { |
757 |
> |
case DISPLAY_SCREEN_P96: |
758 |
> |
return check_modeid_p96(mode_id); |
759 |
> |
break; |
760 |
> |
case DISPLAY_SCREEN_CGFX: |
761 |
> |
return check_modeid_cgfx(mode_id); |
762 |
> |
break; |
763 |
> |
default: |
764 |
> |
return false; |
765 |
> |
break; |
766 |
> |
} |
767 |
|
} |
768 |
|
|
769 |
|
|
773 |
|
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
774 |
|
uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
775 |
|
|
776 |
< |
if (!p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) |
776 |
> |
D(bug("check_modeid_p96: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); |
777 |
> |
|
778 |
> |
if (!p96GetModeIDAttr(mode_id, P96IDA_ISP96)) |
779 |
|
return false; |
780 |
|
|
781 |
|
switch (depth) { |
804 |
|
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
805 |
|
uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
806 |
|
|
807 |
< |
D(bug("init_screen_cgfx: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); |
807 |
> |
D(bug("check_modeid_cgfx: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); |
808 |
|
|
809 |
|
if (!IsCyberModeID(mode_id)) |
810 |
|
return false; |
814 |
|
break; |
815 |
|
case 15: |
816 |
|
case 16: |
932 |
– |
// !!! PIXFMT_RGB15 is correct !!! |
817 |
|
if (format != PIXFMT_RGB15) |
818 |
|
return false; |
819 |
|
break; |
829 |
|
return true; |
830 |
|
} |
831 |
|
|
832 |
+ |
|
833 |
+ |
driver_base::driver_base(Amiga_monitor_desc &m) |
834 |
+ |
: monitor(m), mode(m.get_current_mode()), init_ok(false) |
835 |
+ |
{ |
836 |
+ |
} |
837 |
+ |
|
838 |
+ |
driver_base::~driver_base() |
839 |
+ |
{ |
840 |
+ |
} |
841 |
+ |
|
842 |
+ |
|
843 |
+ |
// Open window |
844 |
+ |
driver_window::driver_window(Amiga_monitor_desc &m, int width, int height) |
845 |
+ |
: black_pen(-1), white_pen(-1), driver_base(m) |
846 |
+ |
{ |
847 |
+ |
// Set relative mouse mode |
848 |
+ |
ADBSetRelMouseMode(false); |
849 |
+ |
|
850 |
+ |
// Open window |
851 |
+ |
the_win = OpenWindowTags(NULL, |
852 |
+ |
WA_Left, 0, WA_Top, 0, |
853 |
+ |
WA_InnerWidth, width, WA_InnerHeight, height, |
854 |
+ |
WA_SimpleRefresh, true, |
855 |
+ |
WA_NoCareRefresh, true, |
856 |
+ |
WA_Activate, true, |
857 |
+ |
WA_RMBTrap, true, |
858 |
+ |
WA_ReportMouse, true, |
859 |
+ |
WA_DragBar, true, |
860 |
+ |
WA_DepthGadget, true, |
861 |
+ |
WA_SizeGadget, false, |
862 |
+ |
WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
863 |
+ |
TAG_END |
864 |
+ |
); |
865 |
+ |
if (the_win == NULL) { |
866 |
+ |
init_ok = false; |
867 |
+ |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
868 |
+ |
return; |
869 |
+ |
} |
870 |
+ |
|
871 |
+ |
// Create bitmap ("height + 2" for safety) |
872 |
+ |
the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL); |
873 |
+ |
if (the_bitmap == NULL) { |
874 |
+ |
init_ok = false; |
875 |
+ |
ErrorAlert(STR_NO_MEM_ERR); |
876 |
+ |
return; |
877 |
+ |
} |
878 |
+ |
|
879 |
+ |
// Add resolution and set VideoMonitor |
880 |
+ |
monitor.set_mac_frame_base((uint32)the_bitmap->Planes[0]); |
881 |
+ |
|
882 |
+ |
// Set FgPen and BgPen |
883 |
+ |
black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); |
884 |
+ |
white_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0xffffffff, 0xffffffff, 0xffffffff, NULL); |
885 |
+ |
SetAPen(the_win->RPort, black_pen); |
886 |
+ |
SetBPen(the_win->RPort, white_pen); |
887 |
+ |
SetDrMd(the_win->RPort, JAM2); |
888 |
+ |
|
889 |
+ |
init_ok = true; |
890 |
+ |
} |
891 |
+ |
|
892 |
+ |
|
893 |
+ |
driver_window::~driver_window() |
894 |
+ |
{ |
895 |
+ |
// Window mode, free bitmap |
896 |
+ |
if (the_bitmap) { |
897 |
+ |
WaitBlit(); |
898 |
+ |
FreeBitMap(the_bitmap); |
899 |
+ |
} |
900 |
+ |
|
901 |
+ |
// Free pens and close window |
902 |
+ |
if (the_win) { |
903 |
+ |
ReleasePen(the_win->WScreen->ViewPort.ColorMap, black_pen); |
904 |
+ |
ReleasePen(the_win->WScreen->ViewPort.ColorMap, white_pen); |
905 |
+ |
|
906 |
+ |
CloseWindow(the_win); |
907 |
+ |
the_win = NULL; |
908 |
+ |
} |
909 |
+ |
} |
910 |
+ |
|
911 |
+ |
|
912 |
+ |
// Open PIP (requires Picasso96) |
913 |
+ |
driver_pip::driver_pip(Amiga_monitor_desc &m, int width, int height) |
914 |
+ |
: driver_base(m) |
915 |
+ |
{ |
916 |
+ |
// Set relative mouse mode |
917 |
+ |
ADBSetRelMouseMode(false); |
918 |
+ |
|
919 |
+ |
// Open window |
920 |
+ |
ULONG error = 0; |
921 |
+ |
the_win = p96PIP_OpenTags( |
922 |
+ |
P96PIP_SourceFormat, RGBFB_R5G5B5, |
923 |
+ |
P96PIP_SourceWidth, width, |
924 |
+ |
P96PIP_SourceHeight, height, |
925 |
+ |
P96PIP_ErrorCode, (ULONG)&error, |
926 |
+ |
WA_Left, 0, WA_Top, 0, |
927 |
+ |
WA_InnerWidth, width, WA_InnerHeight, height, |
928 |
+ |
WA_SimpleRefresh, true, |
929 |
+ |
WA_NoCareRefresh, true, |
930 |
+ |
WA_Activate, true, |
931 |
+ |
WA_RMBTrap, true, |
932 |
+ |
WA_ReportMouse, true, |
933 |
+ |
WA_DragBar, true, |
934 |
+ |
WA_DepthGadget, true, |
935 |
+ |
WA_SizeGadget, false, |
936 |
+ |
WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
937 |
+ |
WA_PubScreenName, (ULONG)"Workbench", |
938 |
+ |
TAG_END |
939 |
+ |
); |
940 |
+ |
if (the_win == NULL || error) { |
941 |
+ |
init_ok = false; |
942 |
+ |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
943 |
+ |
return; |
944 |
+ |
} |
945 |
+ |
|
946 |
+ |
// Find bitmap |
947 |
+ |
p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); |
948 |
+ |
|
949 |
+ |
// Add resolution and set VideoMonitor |
950 |
+ |
monitor.set_mac_frame_base(p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY)); |
951 |
+ |
|
952 |
+ |
init_ok = true; |
953 |
+ |
} |
954 |
+ |
|
955 |
+ |
driver_pip::~driver_pip() |
956 |
+ |
{ |
957 |
+ |
// Close PIP |
958 |
+ |
if (the_win) |
959 |
+ |
p96PIP_Close(the_win); |
960 |
+ |
} |
961 |
+ |
|
962 |
+ |
|
963 |
+ |
// Open Picasso96 screen |
964 |
+ |
driver_screen_p96::driver_screen_p96(Amiga_monitor_desc &m, ULONG mode_id) |
965 |
+ |
: driver_base(m) |
966 |
+ |
{ |
967 |
+ |
// Set absolute mouse mode |
968 |
+ |
ADBSetRelMouseMode(true); |
969 |
+ |
|
970 |
+ |
// Check if the mode is one we can handle |
971 |
+ |
if (!check_modeid_p96(mode_id)) |
972 |
+ |
{ |
973 |
+ |
init_ok = false; |
974 |
+ |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
975 |
+ |
return; |
976 |
+ |
} |
977 |
+ |
|
978 |
+ |
// Yes, get width and height |
979 |
+ |
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
980 |
+ |
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
981 |
+ |
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
982 |
+ |
|
983 |
+ |
// Open screen |
984 |
+ |
the_screen = p96OpenScreenTags( |
985 |
+ |
P96SA_DisplayID, mode_id, |
986 |
+ |
P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
987 |
+ |
P96SA_Quiet, true, |
988 |
+ |
P96SA_NoMemory, true, |
989 |
+ |
P96SA_NoSprite, true, |
990 |
+ |
P96SA_Exclusive, true, |
991 |
+ |
TAG_END |
992 |
+ |
); |
993 |
+ |
if (the_screen == NULL) { |
994 |
+ |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
995 |
+ |
init_ok = false; |
996 |
+ |
return; |
997 |
+ |
} |
998 |
+ |
|
999 |
+ |
// Open window |
1000 |
+ |
the_win = OpenWindowTags(NULL, |
1001 |
+ |
WA_Left, 0, WA_Top, 0, |
1002 |
+ |
WA_Width, width, WA_Height, height, |
1003 |
+ |
WA_SimpleRefresh, true, |
1004 |
+ |
WA_NoCareRefresh, true, |
1005 |
+ |
WA_Borderless, true, |
1006 |
+ |
WA_Activate, true, |
1007 |
+ |
WA_RMBTrap, true, |
1008 |
+ |
WA_ReportMouse, true, |
1009 |
+ |
WA_CustomScreen, (ULONG)the_screen, |
1010 |
+ |
TAG_END |
1011 |
+ |
); |
1012 |
+ |
if (the_win == NULL) { |
1013 |
+ |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
1014 |
+ |
init_ok = false; |
1015 |
+ |
return; |
1016 |
+ |
} |
1017 |
+ |
|
1018 |
+ |
ScreenToFront(the_screen); |
1019 |
+ |
|
1020 |
+ |
// Add resolution and set VideoMonitor |
1021 |
+ |
monitor.set_mac_frame_base(p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY)); |
1022 |
+ |
|
1023 |
+ |
init_ok = true; |
1024 |
+ |
} |
1025 |
+ |
|
1026 |
+ |
|
1027 |
+ |
driver_screen_p96::~driver_screen_p96() |
1028 |
+ |
{ |
1029 |
+ |
// Close window |
1030 |
+ |
if (the_win) |
1031 |
+ |
{ |
1032 |
+ |
CloseWindow(the_win); |
1033 |
+ |
the_win = NULL; |
1034 |
+ |
} |
1035 |
+ |
|
1036 |
+ |
// Close screen |
1037 |
+ |
if (the_screen) { |
1038 |
+ |
p96CloseScreen(the_screen); |
1039 |
+ |
the_screen = NULL; |
1040 |
+ |
} |
1041 |
+ |
} |
1042 |
+ |
|
1043 |
+ |
|
1044 |
+ |
void driver_screen_p96::set_palette(uint8 *pal, int num) |
1045 |
+ |
{ |
1046 |
+ |
// Convert palette to 32 bits |
1047 |
+ |
ULONG table[2 + 256 * 3]; |
1048 |
+ |
table[0] = num << 16; |
1049 |
+ |
table[num * 3 + 1] = 0; |
1050 |
+ |
for (int i=0; i<num; i++) { |
1051 |
+ |
table[i*3+1] = pal[i*3] * 0x01010101; |
1052 |
+ |
table[i*3+2] = pal[i*3+1] * 0x01010101; |
1053 |
+ |
table[i*3+3] = pal[i*3+2] * 0x01010101; |
1054 |
+ |
} |
1055 |
+ |
|
1056 |
+ |
// And load it |
1057 |
+ |
LoadRGB32(&the_screen->ViewPort, table); |
1058 |
+ |
} |
1059 |
+ |
|
1060 |
+ |
|
1061 |
+ |
// Open CyberGraphX screen |
1062 |
+ |
driver_screen_cgfx::driver_screen_cgfx(Amiga_monitor_desc &m, ULONG mode_id) |
1063 |
+ |
: driver_base(m) |
1064 |
+ |
{ |
1065 |
+ |
D(bug("driver_screen_cgfx/%ld: mode_id=%08lx\n", __LINE__, mode_id)); |
1066 |
+ |
|
1067 |
+ |
// Set absolute mouse mode |
1068 |
+ |
ADBSetRelMouseMode(true); |
1069 |
+ |
|
1070 |
+ |
// Check if the mode is one we can handle |
1071 |
+ |
if (!check_modeid_cgfx(mode_id)) |
1072 |
+ |
{ |
1073 |
+ |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
1074 |
+ |
init_ok = false; |
1075 |
+ |
return; |
1076 |
+ |
} |
1077 |
+ |
|
1078 |
+ |
// Yes, get width and height |
1079 |
+ |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
1080 |
+ |
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
1081 |
+ |
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
1082 |
+ |
|
1083 |
+ |
// Open screen |
1084 |
+ |
the_screen = OpenScreenTags(NULL, |
1085 |
+ |
SA_DisplayID, mode_id, |
1086 |
+ |
SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
1087 |
+ |
SA_Quiet, true, |
1088 |
+ |
SA_Exclusive, true, |
1089 |
+ |
TAG_END |
1090 |
+ |
); |
1091 |
+ |
if (the_screen == NULL) { |
1092 |
+ |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
1093 |
+ |
init_ok = false; |
1094 |
+ |
return; |
1095 |
+ |
} |
1096 |
+ |
|
1097 |
+ |
// Open window |
1098 |
+ |
the_win = OpenWindowTags(NULL, |
1099 |
+ |
WA_Left, 0, WA_Top, 0, |
1100 |
+ |
WA_Width, width, WA_Height, height, |
1101 |
+ |
WA_SimpleRefresh, true, |
1102 |
+ |
WA_NoCareRefresh, true, |
1103 |
+ |
WA_Borderless, true, |
1104 |
+ |
WA_Activate, true, |
1105 |
+ |
WA_RMBTrap, true, |
1106 |
+ |
WA_ReportMouse, true, |
1107 |
+ |
WA_CustomScreen, (ULONG)the_screen, |
1108 |
+ |
TAG_END |
1109 |
+ |
); |
1110 |
+ |
if (the_win == NULL) { |
1111 |
+ |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
1112 |
+ |
init_ok = false; |
1113 |
+ |
return; |
1114 |
+ |
} |
1115 |
+ |
|
1116 |
+ |
ScreenToFront(the_screen); |
1117 |
+ |
static UWORD ptr[] = { 0, 0, 0, 0 }; |
1118 |
+ |
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer |
1119 |
+ |
|
1120 |
+ |
// Set VideoMonitor |
1121 |
+ |
ULONG frame_base; |
1122 |
+ |
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
1123 |
+ |
LBMI_BASEADDRESS, (ULONG)&frame_base, |
1124 |
+ |
TAG_END |
1125 |
+ |
); |
1126 |
+ |
UnLockBitMap(handle); |
1127 |
+ |
|
1128 |
+ |
D(bug("driver_screen_cgfx/%ld: frame_base=%08lx\n", __LINE__, frame_base)); |
1129 |
+ |
|
1130 |
+ |
monitor.set_mac_frame_base(frame_base); |
1131 |
+ |
|
1132 |
+ |
init_ok = true; |
1133 |
+ |
} |
1134 |
+ |
|
1135 |
+ |
|
1136 |
+ |
driver_screen_cgfx::~driver_screen_cgfx() |
1137 |
+ |
{ |
1138 |
+ |
D(bug("~driver_screen_cgfx/%ld: \n", __LINE__)); |
1139 |
+ |
|
1140 |
+ |
// Close window |
1141 |
+ |
if (the_win) |
1142 |
+ |
{ |
1143 |
+ |
CloseWindow(the_win); |
1144 |
+ |
the_win = NULL; |
1145 |
+ |
} |
1146 |
+ |
|
1147 |
+ |
// Close screen |
1148 |
+ |
if (the_screen) { |
1149 |
+ |
CloseScreen(the_screen); |
1150 |
+ |
the_screen = NULL; |
1151 |
+ |
} |
1152 |
+ |
} |
1153 |
+ |
|
1154 |
+ |
|
1155 |
+ |
void driver_screen_cgfx::set_palette(uint8 *pal, int num) |
1156 |
+ |
{ |
1157 |
+ |
// Convert palette to 32 bits |
1158 |
+ |
ULONG table[2 + 256 * 3]; |
1159 |
+ |
table[0] = num << 16; |
1160 |
+ |
table[num * 3 + 1] = 0; |
1161 |
+ |
for (int i=0; i<num; i++) { |
1162 |
+ |
table[i*3+1] = pal[i*3] * 0x01010101; |
1163 |
+ |
table[i*3+2] = pal[i*3+1] * 0x01010101; |
1164 |
+ |
table[i*3+3] = pal[i*3+2] * 0x01010101; |
1165 |
+ |
} |
1166 |
+ |
|
1167 |
+ |
// And load it |
1168 |
+ |
LoadRGB32(&the_screen->ViewPort, table); |
1169 |
+ |
} |
1170 |
+ |
|