vbe.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. Copyright (c) 2000 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <kdrive-config.h>
  21. #endif
  22. #include "vesa.h"
  23. static int VbeGetVib(Vm86InfoPtr vi, VbeInfoBlock * vib)
  24. {
  25. int code;
  26. int mark;
  27. int vib_base;
  28. VbeInfoBlock *vib_low;
  29. mark = Vm86MarkMemory(vi);
  30. vib_base = Vm86AllocateMemory(vi, sizeof(VbeInfoBlock));
  31. vib_low = (VbeInfoBlock *) & (LM(vi, vib_base));
  32. vi->vms.regs.eax = 0x4F00;
  33. vi->vms.regs.es = POINTER_SEGMENT(vib_base);
  34. vi->vms.regs.edi = POINTER_OFFSET(vib_base);
  35. memcpy(vib_low->VbeSignature, "VBE2", 4);
  36. code = VbeDoInterrupt10(vi);
  37. if (code >= 0) {
  38. if (memcmp(vib_low->VbeSignature, "VESA", 4) == 0)
  39. *vib = *vib_low;
  40. else
  41. code = -1;
  42. }
  43. Vm86ReleaseMemory(vi, mark);
  44. return code;
  45. }
  46. static int VbeGetVmib(Vm86InfoPtr vi, int mode, VbeModeInfoBlock * vmib)
  47. {
  48. int code;
  49. int mark;
  50. int vmib_base;
  51. VbeModeInfoBlock *vmib_low;
  52. mark = Vm86MarkMemory(vi);
  53. vmib_base = Vm86AllocateMemory(vi, sizeof(VbeModeInfoBlock));
  54. vmib_low = (VbeModeInfoBlock *) & (LM(vi, vmib_base));
  55. vi->vms.regs.eax = 0x4F01;
  56. vi->vms.regs.ecx = mode & 0xFFFF;
  57. vi->vms.regs.es = POINTER_SEGMENT(vmib_base);
  58. vi->vms.regs.edi = POINTER_OFFSET(vmib_base);
  59. code = VbeDoInterrupt10(vi);
  60. if (code >= 0)
  61. *vmib = *vmib_low;
  62. Vm86ReleaseMemory(vi, mark);
  63. return code;
  64. }
  65. static int VbeReportVib(Vm86InfoPtr vi, VbeInfoBlock * vib)
  66. {
  67. U32 i, p;
  68. unsigned char c;
  69. int error = 0;
  70. ErrorF("VBE version %c.%c (",
  71. ((vib->VbeVersion >> 8) & 0xFF) + '0',
  72. (vib->VbeVersion & 0xFF) + '0');
  73. p = vib->OemStringPtr;
  74. for (i = 0; 1; i++) {
  75. c = Vm86Memory(vi, MAKE_POINTER_1(p + i));
  76. if (!c)
  77. break;
  78. if (c >= ' ')
  79. ErrorF("%c", c);
  80. if (i > 32000) {
  81. error = 1;
  82. break;
  83. }
  84. }
  85. ErrorF(")\n");
  86. ErrorF("DAC is %s, controller is %sVGA compatible%s\n",
  87. (vib->Capabilities[0] & 1) ? "fixed" : "switchable",
  88. (vib->Capabilities[0] & 2) ? "not " : "",
  89. (vib->Capabilities[0] & 3) ? ", RAMDAC causes snow" : "");
  90. ErrorF("Total memory: %lu kilobytes\n", 64L * vib->TotalMemory);
  91. if (error)
  92. return -1;
  93. return 0;
  94. }
  95. #if 0
  96. static int VbeReportModeInfo(Vm86InfoPtr vi, U16 mode, VbeModeInfoBlock * vmib)
  97. {
  98. int supported = (vmib->ModeAttributes & 0x1) ? 1 : 0;
  99. int colour = (vmib->ModeAttributes & 0x8) ? 1 : 0;
  100. int graphics = (vmib->ModeAttributes & 0x10) ? 1 : 0;
  101. int vga_compatible = !((vmib->ModeAttributes & 0x20) ? 1 : 0);
  102. int linear_fb = (vmib->ModeAttributes & 0x80) ? 1 : 0;
  103. ErrorF("0x%04X: %dx%dx%d%s",
  104. (unsigned)mode,
  105. (int)vmib->XResolution, (int)vmib->YResolution,
  106. (int)vmib->BitsPerPixel,
  107. colour ? "" : " (monochrome)",
  108. graphics ? "" : " (graphics)",
  109. vga_compatible ? "" : " (vga compatible)",
  110. linear_fb ? "" : " (linear frame buffer)");
  111. switch (vmib->MemoryModel) {
  112. case 0:
  113. ErrorF(" text mode (%dx%d)",
  114. (int)vmib->XCharSize, (int)vmib->YCharSize);
  115. break;
  116. case 1:
  117. ErrorF(" CGA graphics");
  118. break;
  119. case 2:
  120. ErrorF(" Hercules graphics");
  121. break;
  122. case 3:
  123. ErrorF(" Planar (%d planes)", vmib->NumberOfPlanes);
  124. break;
  125. case 4:
  126. ErrorF(" PseudoColor");
  127. break;
  128. case 5:
  129. ErrorF(" Non-chain 4, 256 colour");
  130. break;
  131. case 6:
  132. if (vmib->DirectColorModeInfo & 1)
  133. ErrorF(" DirectColor");
  134. else
  135. ErrorF(" TrueColor");
  136. ErrorF(" [%d:%d:%d:%d]",
  137. vmib->RedMaskSize, vmib->GreenMaskSize,
  138. vmib->BlueMaskSize, vmib->RsvdMaskSize);
  139. if (vmib->DirectColorModeInfo & 2)
  140. ErrorF(" (reserved bits are reserved)");
  141. break;
  142. case 7:
  143. ErrorF("YUV");
  144. break;
  145. default:
  146. ErrorF("unknown MemoryModel 0x%X ", vmib->MemoryModel);
  147. }
  148. if (!supported)
  149. ErrorF(" (unsupported)");
  150. else if (!linear_fb)
  151. ErrorF(" (no linear framebuffer)");
  152. ErrorF("\n");
  153. return 0;
  154. }
  155. #endif
  156. void VbeReportInfo(Vm86InfoPtr vi)
  157. {
  158. VbeInfoBlock vib;
  159. int code;
  160. code = VbeGetVib(vi, &vib);
  161. if (code >= 0)
  162. VbeReportVib(vi, &vib);
  163. }
  164. int VbeGetNmode(Vm86InfoPtr vi)
  165. {
  166. VbeInfoBlock vib;
  167. int code;
  168. unsigned int p;
  169. int n;
  170. int mode;
  171. code = VbeGetVib(vi, &vib);
  172. if (code >= 0) {
  173. p = MAKE_POINTER_1(vib.VideoModePtr);
  174. for (n = 0;; n++) {
  175. mode = Vm86MemoryW(vi, p);
  176. if (mode == 0xffff)
  177. break;
  178. p += 2;
  179. }
  180. code = n;
  181. }
  182. return code;
  183. }
  184. int VbeGetModes(Vm86InfoPtr vi, VesaModePtr modes, int nmode)
  185. {
  186. VbeInfoBlock vib;
  187. int code;
  188. unsigned int p;
  189. int n;
  190. int mode;
  191. VbeModeInfoBlock vmib;
  192. code = VbeGetVib(vi, &vib);
  193. if (code < 0)
  194. return code;
  195. memset(modes, '\0', nmode * sizeof(VesaModeRec));
  196. p = MAKE_POINTER_1(vib.VideoModePtr);
  197. for (n = 0; n < nmode; n++) {
  198. mode = Vm86MemoryW(vi, p);
  199. if (mode == 0xffff)
  200. break;
  201. modes[n].mode = mode;
  202. modes[n].vbe = 1;
  203. p += 2;
  204. }
  205. nmode = n;
  206. for (n = 0; n < nmode; n++) {
  207. code = VbeGetVmib(vi, modes[n].mode, &vmib);
  208. if (code >= 0) {
  209. modes[n].ModeAttributes = vmib.ModeAttributes;
  210. modes[n].NumberOfPlanes = vmib.NumberOfPlanes;
  211. modes[n].BitsPerPixel = vmib.BitsPerPixel;
  212. modes[n].MemoryModel = vmib.MemoryModel;
  213. modes[n].RedMaskSize = vmib.RedMaskSize;
  214. modes[n].RedFieldPosition = vmib.RedFieldPosition;
  215. modes[n].GreenMaskSize = vmib.GreenMaskSize;
  216. modes[n].GreenFieldPosition = vmib.GreenFieldPosition;
  217. modes[n].BlueMaskSize = vmib.BlueMaskSize;
  218. modes[n].BlueFieldPosition = vmib.BlueFieldPosition;
  219. modes[n].RsvdMaskSize = vmib.RsvdMaskSize;
  220. modes[n].RsvdFieldPosition = vmib.RsvdFieldPosition;
  221. modes[n].DirectColorModeInfo = vmib.DirectColorModeInfo;
  222. modes[n].XResolution = vmib.XResolution;
  223. modes[n].YResolution = vmib.YResolution;
  224. modes[n].BytesPerScanLine = vmib.BytesPerScanLine;
  225. }
  226. }
  227. return nmode;
  228. }
  229. VbeInfoPtr VbeInit(Vm86InfoPtr vi)
  230. {
  231. VbeInfoPtr vbe;
  232. int code;
  233. VbeInfoBlock vib;
  234. code = VbeGetVib(vi, &vib);
  235. if (code < 0)
  236. return 0;
  237. vbe = malloc(sizeof(VbeInfoRec));
  238. if (!vbe)
  239. return 0;
  240. vbe->palette_format = 6;
  241. vbe->palette_wait = TRUE;
  242. return vbe;
  243. }
  244. void VbeCleanup(Vm86InfoPtr vi, VbeInfoPtr vbe)
  245. {
  246. free(vbe);
  247. }
  248. static int VbeSetPaletteOptions(Vm86InfoPtr vi, VbeInfoPtr vbe, U8 bits, int wait)
  249. {
  250. int code;
  251. if (bits < 6 || bits > 8) {
  252. ErrorF("Impossible palette format %d\n", bits);
  253. return -1;
  254. }
  255. if (bits != vbe->palette_format) {
  256. vbe->palette_format = 0;
  257. vi->vms.regs.eax = 0x4F08;
  258. vi->vms.regs.ebx = bits << 8;
  259. code = VbeDoInterrupt10(vi);
  260. if (code < 0)
  261. return -1;
  262. vbe->palette_format = bits;
  263. }
  264. vbe->palette_wait = wait;
  265. return 0;
  266. }
  267. int VbeSetMode(Vm86InfoPtr vi, VbeInfoPtr vbe, int mode, int linear, int direct)
  268. {
  269. int code;
  270. VbeInfoBlock vib;
  271. int palette_wait = 0, palette_hi = 0;
  272. code = VbeGetVib(vi, &vib);
  273. if (code < 0)
  274. return -1;
  275. code = VbeGetVmib(vi, mode, &vbe->vmib);
  276. if (code < 0)
  277. return -1;
  278. mode = (mode & 0xffff) & ~0x8000;
  279. if (linear)
  280. mode |= 0x4000;
  281. vi->vms.regs.eax = 0x4F02;
  282. vi->vms.regs.ebx = mode;
  283. code = VbeDoInterrupt10(vi);
  284. if (code < 0)
  285. return -1;
  286. vbe->windowA_offset = vbe->windowB_offset = -1;
  287. vbe->last_window = 1;
  288. if (!direct) {
  289. if (vib.Capabilities[0] & 1)
  290. palette_hi = 1;
  291. if (vib.Capabilities[0] & 4)
  292. palette_wait = 1;
  293. if (palette_hi || palette_wait)
  294. VbeSetPaletteOptions(vi, vbe, palette_hi ? 8 : 6,
  295. palette_wait);
  296. }
  297. return 0;
  298. }
  299. int VbeGetMode(Vm86InfoPtr vi, int *mode)
  300. {
  301. int code;
  302. vi->vms.regs.eax = 0x4F03;
  303. code = VbeDoInterrupt10(vi);
  304. if (code < 0)
  305. return -1;
  306. *mode = vi->vms.regs.ebx & 0xFFFF;
  307. return 0;
  308. }
  309. void *VbeMapFramebuffer(Vm86InfoPtr vi, VbeInfoPtr vbe, int mode, int *ret_size,
  310. CARD32 * ret_phys)
  311. {
  312. U8 *fb;
  313. VbeInfoBlock vib;
  314. VbeModeInfoBlock vmib;
  315. int size;
  316. int pagesize = getpagesize();
  317. int before, after;
  318. if (VbeGetVib(vi, &vib) < 0)
  319. return 0;
  320. if (VbeGetVmib(vi, mode, &vmib) < 0)
  321. return 0;
  322. size = 1024 * 64L * vib.TotalMemory;
  323. *ret_size = size;
  324. *ret_phys = vmib.PhysBasePtr;
  325. before = vmib.PhysBasePtr % pagesize;
  326. after = pagesize - ((vmib.PhysBasePtr + size) % pagesize);
  327. if (after == pagesize)
  328. after = 0;
  329. fb = KdMapDevice(vmib.PhysBasePtr - before, before + size + after);
  330. if (fb == 0) {
  331. ErrorF("Failed to map framebuffer\n");
  332. return NULL;
  333. }
  334. KdSetMappedMode(vmib.PhysBasePtr - before, before + size + after,
  335. KD_MAPPED_MODE_FRAMEBUFFER);
  336. return fb + before;
  337. }
  338. void VbeUnmapFramebuffer(Vm86InfoPtr vi, VbeInfoPtr vbe, int mode, void *fb)
  339. {
  340. VbeInfoBlock vib;
  341. VbeModeInfoBlock vmib;
  342. int size;
  343. int pagesize = getpagesize();
  344. int before, after;
  345. if (VbeGetVib(vi, &vib) < 0)
  346. return;
  347. if (VbeGetVmib(vi, mode, &vmib) < 0)
  348. return;
  349. size = 1024 * 64L * vib.TotalMemory;
  350. before = vmib.PhysBasePtr % pagesize;
  351. after = pagesize - ((vmib.PhysBasePtr + size) % pagesize);
  352. if (after == pagesize)
  353. after = 0;
  354. fb = (void *)((char *)fb - before);
  355. KdUnmapDevice(fb, before + size + after);
  356. KdResetMappedMode(vmib.PhysBasePtr - before, before + size + after,
  357. KD_MAPPED_MODE_FRAMEBUFFER);
  358. }
  359. int
  360. VbeSetPalette(Vm86InfoPtr vi, VbeInfoPtr vbe, int first, int number,
  361. U8 * entries)
  362. {
  363. U8 *palette_scratch;
  364. int mark;
  365. int palette_base;
  366. int i, code;
  367. if (number == 0)
  368. return 0;
  369. if (first < 0 || number < 0 || first + number > 256) {
  370. ErrorF("Cannot set %d, %d palette entries\n", first, number);
  371. return -1;
  372. }
  373. if (vbe->palette_format < 6 || vbe->palette_format > 8) {
  374. ErrorF("Impossible palette format %d\n", vbe->palette_format);
  375. return -1;
  376. }
  377. mark = Vm86MarkMemory(vi);
  378. palette_base = Vm86AllocateMemory(vi, 4 * 256);
  379. palette_scratch = &LM(vi, palette_base);
  380. for (i = 0; i < number * 4; i++)
  381. palette_scratch[i] = entries[i] >> (8 - vbe->palette_format);
  382. vi->vms.regs.eax = 0x4F09;
  383. if (vbe->palette_wait)
  384. vi->vms.regs.ebx = 0x80;
  385. else
  386. vi->vms.regs.ebx = 0x00;
  387. vi->vms.regs.ecx = number;
  388. vi->vms.regs.edx = first;
  389. vi->vms.regs.es = POINTER_SEGMENT(palette_base);
  390. vi->vms.regs.edi = POINTER_OFFSET(palette_base);
  391. code = VbeDoInterrupt10(vi);
  392. Vm86ReleaseMemory(vi, mark);
  393. if (code < 0)
  394. return -1;
  395. return 0;
  396. }
  397. int
  398. VbeGetPalette(Vm86InfoPtr vi, VbeInfoPtr vbe, int first, int number,
  399. U8 * entries)
  400. {
  401. U8 *palette_scratch;
  402. int mark;
  403. int palette_base;
  404. int i, code;
  405. if (number == 0)
  406. return 0;
  407. if (first < 0 || number < 0 || first + number > 256) {
  408. ErrorF("Cannot get %d, %d palette entries\n", first, number);
  409. return -1;
  410. }
  411. if (vbe->palette_format < 6 || vbe->palette_format > 8) {
  412. ErrorF("Impossible palette format %d\n", vbe->palette_format);
  413. return -1;
  414. }
  415. mark = Vm86MarkMemory(vi);
  416. palette_base = Vm86AllocateMemory(vi, 4 * 256);
  417. palette_scratch = &LM(vi, palette_base);
  418. vi->vms.regs.eax = 0x4F09;
  419. vi->vms.regs.ebx = 0x01;
  420. vi->vms.regs.ecx = number;
  421. vi->vms.regs.edx = first;
  422. vi->vms.regs.es = POINTER_SEGMENT(palette_base);
  423. vi->vms.regs.edi = POINTER_OFFSET(palette_base);
  424. code = VbeDoInterrupt10(vi);
  425. if (code >= 0) {
  426. for (i = 0; i < number * 4; i++)
  427. entries[i] =
  428. palette_scratch[i] << (8 - vbe->palette_format);
  429. }
  430. Vm86ReleaseMemory(vi, mark);
  431. return 0;
  432. }
  433. static int VbeReallySetWindow(Vm86InfoPtr vi, U8 window, U16 winnum)
  434. {
  435. int code;
  436. vi->vms.regs.eax = 0x4F05;
  437. vi->vms.regs.ebx = window;
  438. vi->vms.regs.edx = winnum;
  439. code = VbeDoInterrupt10(vi);
  440. if (code < 0)
  441. return -1;
  442. return 0;
  443. }
  444. void *VbeSetWindow(Vm86InfoPtr vi, VbeInfoPtr vbe, int offset, int purpose,
  445. int *size_return)
  446. {
  447. int window_size = vbe->vmib.WinSize * 1024;
  448. int code;
  449. int winnum;
  450. if (vbe->windowA_offset >= 0)
  451. if (vbe->windowA_offset <= offset
  452. && vbe->windowA_offset + window_size > offset)
  453. if (vbe->vmib.WinAAttributes & purpose)
  454. goto windowA;
  455. if (vbe->windowB_offset >= 0)
  456. if (vbe->windowB_offset <= offset
  457. && vbe->windowB_offset + window_size > offset)
  458. if (vbe->vmib.WinBAttributes & purpose)
  459. goto windowB;
  460. if (!(vbe->vmib.WinBAttributes & purpose) ||
  461. !(vbe->vmib.WinBAttributes & VBE_WINDOW_RELOCATE))
  462. goto set_windowA;
  463. if (!(vbe->vmib.WinAAttributes & purpose) ||
  464. !(vbe->vmib.WinAAttributes & VBE_WINDOW_RELOCATE))
  465. goto set_windowB;
  466. if (vbe->last_window)
  467. goto set_windowA;
  468. else
  469. goto set_windowB;
  470. set_windowA:
  471. winnum = offset / (vbe->vmib.WinGranularity * 1024);
  472. code = VbeReallySetWindow(vi, 0, winnum);
  473. if (code < 0) {
  474. ErrorF("Couldn't set window A to %d*%d\n",
  475. (int)winnum, (int)vbe->vmib.WinGranularity);
  476. return NULL;
  477. }
  478. vbe->windowA_offset = winnum * vbe->vmib.WinGranularity * 1024;
  479. windowA:
  480. vbe->last_window = 0;
  481. *size_return =
  482. vbe->vmib.WinSize * 1024 - (offset - vbe->windowA_offset);
  483. return ((U8 *) & (LM(vi, MAKE_POINTER(vbe->vmib.WinASegment, 0)))) +
  484. offset - vbe->windowA_offset;
  485. set_windowB:
  486. winnum = offset / (vbe->vmib.WinGranularity * 1024);
  487. code = VbeReallySetWindow(vi, 1, winnum);
  488. if (code < 0) {
  489. ErrorF("Couldn't set window B to %d*%d\n",
  490. (int)winnum, (int)vbe->vmib.WinGranularity);
  491. return NULL;
  492. }
  493. vbe->windowB_offset = winnum * vbe->vmib.WinGranularity * 1024;
  494. windowB:
  495. vbe->last_window = 1;
  496. *size_return =
  497. vbe->vmib.WinSize * 1024 - (offset - vbe->windowB_offset);
  498. return ((U8 *) & (LM(vi, MAKE_POINTER(vbe->vmib.WinBSegment, 0)))) +
  499. offset - vbe->windowB_offset;
  500. }
  501. static const int VbeDPMSModes[4] = {
  502. 0x00, /* KD_DPMS_NORMAL */
  503. 0x01, /* KD_DPMS_STANDBY */
  504. 0x02, /* KD_DPMS_SUSPEND */
  505. 0x04, /* KD_DPMS_POWERDOWN */
  506. };
  507. Bool VbeDPMS(Vm86InfoPtr vi, int mode)
  508. {
  509. int code;
  510. /*
  511. * Check which modes are supported
  512. */
  513. vi->vms.regs.eax = 0x4f10;
  514. vi->vms.regs.ebx = 0x0000;
  515. vi->vms.regs.es = 0;
  516. vi->vms.regs.edi = 0;
  517. code = VbeDoInterrupt10(vi);
  518. if (code < 0) {
  519. ErrorF("No DPMS Support %d\n", code);
  520. return FALSE;
  521. }
  522. /* Skip this stage if it's not supported */
  523. if (((vi->vms.regs.ebx >> 4) & VbeDPMSModes[mode]) !=
  524. VbeDPMSModes[mode])
  525. return FALSE;
  526. /* Select this mode */
  527. vi->vms.regs.eax = 0x4f10;
  528. vi->vms.regs.ebx = (VbeDPMSModes[mode] << 8) | 0x01;
  529. code = VbeDoInterrupt10(vi);
  530. if (code < 0) {
  531. ErrorF("DPMS failed %d\n", code);
  532. return FALSE;
  533. }
  534. return TRUE;
  535. }
  536. static int VbeDoInterruptE6(Vm86InfoPtr vi)
  537. {
  538. int code;
  539. int oldax;
  540. oldax = vi->vms.regs.eax & 0xffff;
  541. code = Vm86DoPOST(vi);
  542. ErrorF("POST (0x%04X): 0x%04lX\n", oldax, vi->vms.regs.eax & 0xffff);
  543. return code;
  544. }
  545. Bool VbeBoot(Vm86InfoPtr vi)
  546. {
  547. int code;
  548. int bus = 1;
  549. int device = 0;
  550. int function = 0;
  551. vi->vms.regs.eax = (bus << 8) | (device << 3) | (function & 0x7);
  552. code = VbeDoInterruptE6(vi);
  553. ErrorF("Boot: %d\n", code);
  554. return TRUE;
  555. }
  556. int VbeDoInterrupt10(Vm86InfoPtr vi)
  557. {
  558. int code;
  559. int oldax;
  560. oldax = vi->vms.regs.eax & 0xFFFF;
  561. code = Vm86DoInterrupt(vi, 0x10);
  562. if (code < 0)
  563. return -1;
  564. if ((vi->vms.regs.eax & 0xFFFF) != 0x4F && (oldax & 0xFF00) == 0x4F00) {
  565. ErrorF("Int 10h (0x%04X) failed: 0x%04lX",
  566. oldax, vi->vms.regs.eax & 0xFFFF);
  567. if ((oldax & 0xFF00) == 0x4F00) {
  568. switch ((vi->vms.regs.eax & 0xFF00) >> 8) {
  569. case 0:
  570. ErrorF(" (success)\n");
  571. return 0;
  572. case 1:
  573. ErrorF(" (function call failed)\n");
  574. break;
  575. case 2:
  576. ErrorF
  577. (" (function not supported on this hardware)\n");
  578. break;
  579. case 3:
  580. ErrorF
  581. (" (function call invalid in this video mode)\n");
  582. break;
  583. default:
  584. ErrorF(" (unknown error)\n");
  585. break;
  586. }
  587. return -1;
  588. } else {
  589. ErrorF("\n");
  590. }
  591. }
  592. return code;
  593. }