xref: /haiku/src/system/boot/platform/atari_m68k/video.cpp (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "toscalls.h"
8 #include "video.h"
9 //#include "mmu.h"
10 //#include "images.h"
11 
12 #include <arch/cpu.h>
13 #include <boot/stage2.h>
14 #include <boot/platform.h>
15 #include <boot/menu.h>
16 #include <boot/kernel_args.h>
17 #include <util/list.h>
18 #include <drivers/driver_settings.h>
19 #include <GraphicsDefs.h>
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 
26 //#define TRACE_VIDEO
27 #ifdef TRACE_VIDEO
28 #	define TRACE(x) dprintf x
29 #else
30 #	define TRACE(x) ;
31 #endif
32 
33 
34 // XXX: use falcon video monitor detection and build possible mode list there...
35 
36 // which API to use to handle this mode
37 // cf. http://toshyp.atari.org/004.htm
38 enum {
39 	MODETYPE_XBIOS_ST,
40 	MODETYPE_XBIOS_TT,
41 	MODETYPE_XBIOS_FALCON,
42 	MODETYPE_CENTSCREEN,
43 	MODETYPE_CRAZYDOTS,
44 	MODETYPE_CT60,
45 	MODETYPE_NATFEAT
46 };
47 
48 class ModeAPI {
49 public:
50 	ModeAPI(const char *name) { fName = name; };
51 	~ModeAPI() {};
52 	const char *Name() const { return fName; };
53 	virtual status_t Enumerate() = 0;
54 	virtual status_t Get(struct video_mode *mode) = 0;
55 	virtual status_t Set(const struct video_mode *mode) = 0;
56 private:
57 	const char *fName;
58 };
59 
60 struct video_mode {
61 	list_link	link;
62 	ModeAPI		*ops;
63 	color_space	space;
64 	uint16		mode;
65 	uint16		width, height, bits_per_pixel;
66 	uint32		bytes_per_row;
67 };
68 
69 static struct list sModeList;
70 static video_mode *sMode, *sDefaultMode;
71 
72 
73 //	#pragma mark - Falcon XBIOS API
74 
75 class FalconModeAPI : public ModeAPI {
76 public:
77 	FalconModeAPI() : ModeAPI("Falcon XBIOS") {};
78 	~FalconModeAPI() {};
79 	virtual status_t Enumerate();
80 	virtual status_t Get(struct video_mode *mode);
81 	virtual status_t Set(const struct video_mode *mode);
82 };
83 
84 
85 status_t
86 FalconModeAPI::Enumerate()
87 {
88 	int16 monitor;
89 	monitor = VgetMonitor();
90 	switch (monitor) {
91 		case 0:
92 			panic("Monochrome ??");
93 			break;
94 		//case 4 & 5: check for CT60
95 		case 1:
96 		default:
97 			dprintf("monitor type %d\n", monitor);
98 			break;
99 	}
100 	return ENODEV;
101 }
102 
103 
104 status_t
105 FalconModeAPI::Get(struct video_mode *mode)
106 {
107 	int16 m = VsetMode(VM_INQUIRE);
108 	int bpp;
109 	int width = 320;
110 	if (m < 0)
111 		return B_ERROR;
112 	bpp = 1 << (m & 0x0007);
113 	if (m & 0x0008)
114 		width *= 2;
115 	bool vga = (m & 0x0010) != 0;
116 	bool pal = (m & 0x0020) != 0;
117 	bool overscan = (m & 0x0040) != 0;
118 	bool st = (m & 0x0080) != 0;
119 	bool interlace = (m & 0x0100) != 0;
120 	return ENODEV;
121 }
122 
123 
124 status_t
125 FalconModeAPI::Set(const struct video_mode *mode)
126 {
127 	return ENODEV;
128 }
129 
130 
131 static FalconModeAPI sFalconModeAPI;
132 
133 
134 //	#pragma mark -
135 
136 
137 bool
138 video_mode_hook(Menu *menu, MenuItem *item)
139 {
140 	// nothing yet
141 #if 0
142 	// find selected mode
143 	video_mode *mode = NULL;
144 
145 	menu = item->Submenu();
146 	item = menu->FindMarked();
147 	if (item != NULL) {
148 		switch (menu->IndexOf(item)) {
149 			case 0:
150 				// "Default" mode special
151 				sMode = sDefaultMode;
152 				sModeChosen = false;
153 				return true;
154 			case 1:
155 				// "Standard VGA" mode special
156 				// sets sMode to NULL which triggers VGA mode
157 				break;
158 			default:
159 				mode = (video_mode *)item->Data();
160 				break;
161 		}
162 	}
163 
164 	if (mode != sMode) {
165 		// update standard mode
166 		// ToDo: update fb settings!
167 		sMode = mode;
168 	}
169 
170 	sModeChosen = true;
171 #endif
172 	return true;
173 }
174 
175 
176 Menu *
177 video_mode_menu()
178 {
179 	Menu *menu = new(nothrow) Menu(CHOICE_MENU, "Select Video Mode");
180 	MenuItem *item;
181 
182 	menu->AddItem(item = new(nothrow) MenuItem("Default"));
183 	item->SetMarked(true);
184 	item->Select(true);
185 	item->SetHelpText("The Default video mode is the one currently configured "
186 		"in the system. If there is no mode configured yet, a viable mode will "
187 		"be chosen automatically.");
188 
189 #if 0
190 	menu->AddItem(new(nothrow) MenuItem("Standard VGA"));
191 
192 	video_mode *mode = NULL;
193 	while ((mode = (video_mode *)list_get_next_item(&sModeList, mode)) != NULL) {
194 		char label[64];
195 		sprintf(label, "%ux%u %u bit", mode->width, mode->height,
196 			mode->bits_per_pixel);
197 
198 		menu->AddItem(item = new(nothrow) MenuItem(label));
199 		item->SetData(mode);
200 	}
201 #endif
202 
203 	menu->AddSeparatorItem();
204 	menu->AddItem(item = new(nothrow) MenuItem("Return to main menu"));
205 	item->SetType(MENU_ITEM_NO_CHOICE);
206 
207 	return menu;
208 }
209 
210 
211 //	#pragma mark -
212 
213 
214 extern "C" void
215 platform_switch_to_logo(void)
216 {
217 	// ToDo: implement me
218 }
219 
220 
221 extern "C" void
222 platform_switch_to_text_mode(void)
223 {
224 	// ToDo: implement me
225 }
226 
227 
228 extern "C" status_t
229 platform_init_video(void)
230 {
231 	// ToDo: implement me
232 	dprintf("current video mode: \n");
233 	dprintf("Vsetmode(-1): 0x%08x\n", VsetMode(VM_INQUIRE));
234 	sFalconModeAPI.Enumerate();
235 	return B_OK;
236 }
237 
238