Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.13 KB | None | 0 0
  1. /* 915 resolution by steve tomljenovic
  2. *
  3. * This was tested only on Sony VGN-FS550. Use at your own risk
  4. *
  5. * This code is based on the techniques used in :
  6. *
  7. * - 855patch. Many thanks to Christian Zietz (czietz gmx net)
  8. * for demonstrating how to shadow the VBIOS into system RAM
  9. * and then modify it.
  10. *
  11. * - 1280patch by Andrew Tipton (andrewtipton null li).
  12. *
  13. * - 855resolution by Alain Poirier
  14. *
  15. * This source code is into the public domain.
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #define __USE_GNU
  22. #include <string.h>
  23. #include <sys/mman.h>
  24. #include <fcntl.h>
  25. #include <sys/io.h>
  26. #include <unistd.h>
  27. #include <assert.h>
  28.  
  29.  
  30.  
  31. #define NEW(a) ((a *)(calloc(1, sizeof(a))))
  32. #define FREE(a) (free(a))
  33.  
  34. #define VBIOS_START 0xc0000
  35. #define VBIOS_SIZE 0x10000
  36.  
  37. #define VBIOS_FILE "/dev/mem"
  38.  
  39. #define FALSE 0
  40. #define TRUE 1
  41.  
  42. #define MODE_TABLE_OFFSET_845G 617
  43.  
  44. #define VERSION "0.5.3"
  45.  
  46. #define ATI_SIGNATURE1 "ATI MOBILITY RADEON"
  47. #define ATI_SIGNATURE2 "ATI Technologies Inc"
  48. #define NVIDIA_SIGNATURE "NVIDIA Corp"
  49. #define INTEL_SIGNATURE "Intel Corp"
  50.  
  51. typedef unsigned char * address;
  52. typedef unsigned char byte;
  53. typedef unsigned short word;
  54. typedef unsigned char boolean;
  55. typedef unsigned int cardinal;
  56.  
  57. typedef enum {
  58. CT_UNKWN, CT_830, CT_845G, CT_855GM, CT_865G, CT_915G, CT_915GM, CT_945G, CT_945GM,
  59. CT_946GZ, CT_G965, CT_Q965
  60. } chipset_type;
  61.  
  62. char * chipset_type_names[] = {
  63. "UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM",
  64. "946GZ", "G965", "Q965"
  65. };
  66.  
  67. typedef enum {
  68. BT_UNKWN, BT_1, BT_2, BT_3
  69. } bios_type;
  70.  
  71. char * bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};
  72.  
  73. int freqs[] = { 60, 75, 85 };
  74.  
  75. typedef struct {
  76. byte mode;
  77. byte bits_per_pixel;
  78. word resolution;
  79. byte unknown;
  80. } __attribute__((packed)) vbios_mode;
  81.  
  82. typedef struct {
  83. byte unknow1[2];
  84. byte x1;
  85. byte x_total;
  86. byte x2;
  87. byte y1;
  88. byte y_total;
  89. byte y2;
  90. } __attribute__((packed)) vbios_resolution_type1;
  91.  
  92. typedef struct {
  93. unsigned long clock;
  94.  
  95. word x1;
  96. word htotal;
  97. word x2;
  98. word hblank;
  99. word hsyncstart;
  100. word hsyncend;
  101.  
  102. word y1;
  103. word vtotal;
  104. word y2;
  105. word vblank;
  106. word vsyncstart;
  107. word vsyncend;
  108. } __attribute__((packed)) vbios_modeline_type2;
  109.  
  110. typedef struct {
  111. byte xchars;
  112. byte ychars;
  113. byte unknown[4];
  114.  
  115. vbios_modeline_type2 modelines[];
  116. } __attribute__((packed)) vbios_resolution_type2;
  117.  
  118. typedef struct {
  119. unsigned long clock;
  120.  
  121. word x1;
  122. word htotal;
  123. word x2;
  124. word hblank;
  125. word hsyncstart;
  126. word hsyncend;
  127.  
  128. word y1;
  129. word vtotal;
  130. word y2;
  131. word vblank;
  132. word vsyncstart;
  133. word vsyncend;
  134.  
  135. word timing_h;
  136. word timing_v;
  137.  
  138. byte unknown[6];
  139. } __attribute__((packed)) vbios_modeline_type3;
  140.  
  141. typedef struct {
  142. unsigned char unknown[6];
  143.  
  144. vbios_modeline_type3 modelines[];
  145. } __attribute__((packed)) vbios_resolution_type3;
  146.  
  147.  
  148. typedef struct {
  149. cardinal chipset_id;
  150. chipset_type chipset;
  151. bios_type bios;
  152.  
  153. int bios_fd;
  154. address bios_ptr;
  155.  
  156. vbios_mode * mode_table;
  157. cardinal mode_table_size;
  158.  
  159. byte b1, b2;
  160.  
  161. boolean unlocked;
  162. } vbios_map;
  163.  
  164.  
  165. void initialize_system(char * filename) {
  166.  
  167. if (!filename) {
  168. if (iopl(3) < 0) {
  169. perror("Unable to obtain the proper IO permissions");
  170. exit(2);
  171. }
  172. }
  173. }
  174.  
  175. cardinal get_chipset_id(void) {
  176. outl(0x80000000, 0xcf8);
  177. return inl(0xcfc);
  178. }
  179.  
  180. chipset_type get_chipset(cardinal id) {
  181. chipset_type type;
  182.  
  183. switch (id) {
  184. case 0x35758086:
  185. type = CT_830;
  186. break;
  187.  
  188. case 0x25608086:
  189. type = CT_845G;
  190. break;
  191.  
  192. case 0x35808086:
  193. type = CT_855GM;
  194. break;
  195.  
  196. case 0x25708086:
  197. type = CT_865G;
  198. break;
  199.  
  200. case 0x25808086:
  201. type = CT_915G;
  202. break;
  203.  
  204. case 0x25908086:
  205. type = CT_915GM;
  206. break;
  207.  
  208. case 0x27708086:
  209. type = CT_945G;
  210. break;
  211.  
  212. case 0x27a08086:
  213. type = CT_945GM;
  214. break;
  215.  
  216. case 0x29708086:
  217. type = CT_946GZ;
  218. break;
  219.  
  220. case 0x29a08086:
  221. type = CT_G965;
  222. break;
  223.  
  224. case 0x29908086:
  225. type = CT_Q965;
  226. break;
  227.  
  228. default:
  229. type = CT_UNKWN;
  230. break;
  231. }
  232.  
  233. return type;
  234. }
  235.  
  236.  
  237. vbios_resolution_type1 * map_type1_resolution(vbios_map * map, word res) {
  238. vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res));
  239. return ptr;
  240. }
  241.  
  242. vbios_resolution_type2 * map_type2_resolution(vbios_map * map, word res) {
  243. vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res));
  244. return ptr;
  245. }
  246.  
  247. vbios_resolution_type3 * map_type3_resolution(vbios_map * map, word res) {
  248. vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res));
  249. return ptr;
  250. }
  251.  
  252.  
  253. boolean detect_bios_type(vbios_map * map, boolean modeline, int entry_size) {
  254. int i;
  255. short int r1, r2;
  256. float f;
  257.  
  258. r1 = r2 = 32000;
  259.  
  260. for (i=0; i < map->mode_table_size; i++) {
  261. if (map->mode_table[i].resolution <= r1) {
  262. r1 = map->mode_table[i].resolution;
  263. }
  264. else {
  265. if (map->mode_table[i].resolution <= r2) {
  266. r2 = map->mode_table[i].resolution;
  267. }
  268. }
  269.  
  270. /*printf("r1 = %d r2 = %d\n", r1, r2);*/
  271. }
  272.  
  273.  
  274. f = ((float) (r2-r1-6)) / entry_size;
  275.  
  276. return f == (int) f;
  277. }
  278.  
  279.  
  280. void close_vbios(vbios_map * map);
  281.  
  282.  
  283. vbios_map * open_vbios(char * filename, chipset_type forced_chipset) {
  284. vbios_map * map = NEW(vbios_map);
  285.  
  286. /*
  287. * Determine chipset
  288. */
  289.  
  290. if (!filename && forced_chipset == CT_UNKWN) {
  291. map->chipset_id = get_chipset_id();
  292.  
  293. map->chipset = get_chipset(map->chipset_id);
  294. }
  295. else if (forced_chipset != CT_UNKWN) {
  296. map->chipset = forced_chipset;
  297. }
  298. else {
  299. map->chipset = CT_915GM;
  300. }
  301.  
  302. /*
  303. * Map the video bios to memory
  304. */
  305.  
  306. if (!filename) {
  307. map->bios_fd = open(VBIOS_FILE, O_RDWR);
  308. if(map->bios_fd < 0) {
  309. if (map->chipset == CT_UNKWN) {
  310. fprintf(stderr, "Invalid chipset detected: %x\n", map->chipset_id);
  311. }
  312. perror("Unable to open the BIOS file");
  313. exit(2);
  314. }
  315.  
  316. map->bios_ptr = mmap(0, VBIOS_SIZE,
  317. PROT_READ | PROT_WRITE, MAP_SHARED,
  318. map->bios_fd, VBIOS_START);
  319.  
  320. if (map->bios_ptr == MAP_FAILED) {
  321. if (map->chipset == CT_UNKWN) {
  322. fprintf(stderr, "Invalid chipset detected: %x\n", map->chipset_id);
  323. }
  324. perror("Cannot mmap() the video BIOS\n");
  325. close(map->bios_fd);
  326. exit(2);
  327. }
  328. }
  329. else {
  330. map->bios_fd = open(filename, O_RDWR);
  331. if(map->bios_fd < 0) {
  332. if (map->chipset == CT_UNKWN) {
  333. fprintf(stderr, "Invalid chipset detected: %x\n", map->chipset_id);
  334. }
  335. perror("Unable to open the BIOS file");
  336. exit(2);
  337. }
  338.  
  339. map->bios_ptr = mmap(0, VBIOS_SIZE,
  340. PROT_READ | PROT_WRITE, MAP_SHARED,
  341. map->bios_fd, 0);
  342.  
  343. if (map->bios_ptr == MAP_FAILED) {
  344. if (map->chipset == CT_UNKWN) {
  345. fprintf(stderr, "Invalid chipset detected: %x\n", map->chipset_id);
  346. }
  347. perror("Cannot mmap() the BIOS file\n");
  348. close(map->bios_fd);
  349. exit(2);
  350. }
  351. }
  352.  
  353. /*
  354. * check if we have ATI Radeon
  355. */
  356.  
  357. if (memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE1, strlen(ATI_SIGNATURE1)) ||
  358. memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE2, strlen(ATI_SIGNATURE2)) ) {
  359. fprintf(stderr, "ATI chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
  360. close(map->bios_fd);
  361. exit(2);
  362. }
  363.  
  364. /*
  365. * check if we have NVIDIA
  366. */
  367.  
  368. if (memmem(map->bios_ptr, VBIOS_SIZE, NVIDIA_SIGNATURE, strlen(NVIDIA_SIGNATURE))) {
  369. fprintf(stderr, "NVIDIA chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");
  370. close(map->bios_fd);
  371. exit(2);
  372. }
  373.  
  374. /*
  375. * check if we have Intel
  376. */
  377.  
  378. if (map->chipset == CT_UNKWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {
  379. fprintf(stderr, "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n");
  380.  
  381. fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
  382.  
  383. fprintf(stderr, "Please report this problem to stomljen@yahoo.com\n");
  384.  
  385. close_vbios(map);
  386. exit(2);
  387. }
  388.  
  389. /*
  390. * check for others
  391. */
  392.  
  393. if (map->chipset == CT_UNKWN) {
  394. fprintf(stderr, "Unknown chipset type and unrecognized bios.\n");
  395. fprintf(stderr, "915resolution only works with Intel 800/900 series graphic chipsets.\n");
  396.  
  397. fprintf(stderr, "Chipset Id: %x\n", map->chipset_id);
  398. close_vbios(map);
  399. exit(2);
  400. }
  401.  
  402. /*
  403. * Figure out where the mode table is
  404. */
  405.  
  406. {
  407. address p = map->bios_ptr + 16;
  408. address limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
  409.  
  410. while (p < limit && map->mode_table == 0) {
  411. vbios_mode * mode_ptr = (vbios_mode *) p;
  412.  
  413. if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
  414. ((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {
  415.  
  416. map->mode_table = mode_ptr;
  417. }
  418.  
  419. p++;
  420. }
  421.  
  422. if (map->mode_table == 0) {
  423. fprintf(stderr, "Unable to locate the mode table.\n");
  424. fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
  425. fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
  426.  
  427. fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
  428. close_vbios(map);
  429. exit(2);
  430. }
  431. }
  432.  
  433. /*
  434. * Determine size of mode table
  435. */
  436.  
  437. {
  438. vbios_mode * mode_ptr = map->mode_table;
  439.  
  440. while (mode_ptr->mode != 0xff) {
  441. map->mode_table_size++;
  442. mode_ptr++;
  443. }
  444. }
  445.  
  446. /*
  447. * Figure out what type of bios we have
  448. * order of detection is important
  449. */
  450.  
  451. if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type3))) {
  452. map->bios = BT_3;
  453. }
  454. else if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type2))) {
  455. map->bios = BT_2;
  456. }
  457. else if (detect_bios_type(map, FALSE, sizeof(vbios_resolution_type1))) {
  458. map->bios = BT_1;
  459. }
  460. else {
  461. fprintf(stderr, "Unable to determine bios type.\n");
  462. fprintf(stderr, "Please run the program 'dump_bios' as root and\n");
  463. fprintf(stderr, "email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
  464.  
  465. fprintf(stderr, "Chipset: %s\n", chipset_type_names[map->chipset]);
  466. fprintf(stderr, "Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
  467. fprintf(stderr, "Mode Table Entries: %u\n", map->mode_table_size);
  468. exit(2);
  469. }
  470.  
  471. return map;
  472. }
  473.  
  474. void close_vbios(vbios_map * map) {
  475. assert(!map->unlocked);
  476.  
  477. if(map->bios_ptr == MAP_FAILED) {
  478. fprintf(stderr, "BIOS should be open already!\n");
  479. exit(2);
  480. }
  481.  
  482. munmap(map->bios_ptr, VBIOS_SIZE);
  483. close(map->bios_fd);
  484.  
  485. FREE(map);
  486. }
  487.  
  488. void unlock_vbios(vbios_map * map) {
  489.  
  490. assert(!map->unlocked);
  491.  
  492. map->unlocked = TRUE;
  493.  
  494. switch (map->chipset) {
  495. case CT_UNKWN:
  496. break;
  497. case CT_830:
  498. case CT_855GM:
  499. outl(0x8000005a, 0xcf8);
  500. map->b1 = inb(0xcfe);
  501.  
  502. outl(0x8000005a, 0xcf8);
  503. outb(0x33, 0xcfe);
  504. break;
  505. case CT_845G:
  506. case CT_865G:
  507. case CT_915G:
  508. case CT_915GM:
  509. case CT_945G:
  510. case CT_945GM:
  511. case CT_946GZ:
  512. case CT_G965:
  513. case CT_Q965:
  514. outl(0x80000090, 0xcf8);
  515. map->b1 = inb(0xcfd);
  516. map->b2 = inb(0xcfe);
  517.  
  518. outl(0x80000090, 0xcf8);
  519. outb(0x33, 0xcfd);
  520. outb(0x33, 0xcfe);
  521. break;
  522. }
  523.  
  524. #if DEBUG
  525. {
  526. cardinal t = inl(0xcfc);
  527. printf("unlock PAM: (0x%08x)\n", t);
  528. }
  529. #endif
  530. }
  531.  
  532. void relock_vbios(vbios_map * map) {
  533.  
  534. assert(map->unlocked);
  535. map->unlocked = FALSE;
  536.  
  537. switch (map->chipset) {
  538. case CT_UNKWN:
  539. break;
  540. case CT_830:
  541. case CT_855GM:
  542. outl(0x8000005a, 0xcf8);
  543. outb(map->b1, 0xcfe);
  544. break;
  545. case CT_845G:
  546. case CT_865G:
  547. case CT_915G:
  548. case CT_915GM:
  549. case CT_945G:
  550. case CT_945GM:
  551. case CT_946GZ:
  552. case CT_G965:
  553. case CT_Q965:
  554. outl(0x80000090, 0xcf8);
  555. outb(map->b1, 0xcfd);
  556. outb(map->b2, 0xcfe);
  557. break;
  558. }
  559.  
  560. #if DEBUG
  561. {
  562. cardinal t = inl(0xcfc);
  563. printf("relock PAM: (0x%08x)\n", t);
  564. }
  565. #endif
  566. }
  567.  
  568.  
  569. void list_modes(vbios_map *map, cardinal raw) {
  570. cardinal i, x, y;
  571.  
  572. for (i=0; i < map->mode_table_size; i++) {
  573. switch(map->bios) {
  574. case BT_1:
  575. {
  576. vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
  577.  
  578. x = ((((cardinal) res->x2) & 0xf0) << 4) | res->x1;
  579. y = ((((cardinal) res->y2) & 0xf0) << 4) | res->y1;
  580.  
  581. if (x != 0 && y != 0) {
  582. printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
  583. }
  584.  
  585. if (raw)
  586. {
  587. printf("Mode %02x (raw) :\n\t%02x %02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n", map->mode_table[i].mode, res->unknow1[0],res->unknow1[1], res->x1,res->x_total,res->x2,res->y1,res->y_total,res->y2);
  588. }
  589.  
  590. }
  591. break;
  592. case BT_2:
  593. {
  594. vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
  595.  
  596. x = res->modelines[0].x1+1;
  597. y = res->modelines[0].y1+1;
  598.  
  599. if (x != 0 && y != 0) {
  600. printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
  601. }
  602. }
  603. break;
  604. case BT_3:
  605. {
  606. vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
  607.  
  608. x = res->modelines[0].x1+1;
  609. y = res->modelines[0].y1+1;
  610.  
  611. if (x != 0 && y != 0) {
  612. printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
  613. }
  614. }
  615. break;
  616. case BT_UNKWN:
  617. break;
  618. }
  619. }
  620. }
  621.  
  622. static void gtf_timings(int x, int y, int freq,
  623. unsigned long *clock,
  624. word *hsyncstart, word *hsyncend, word *hblank,
  625. word *vsyncstart, word *vsyncend, word *vblank)
  626. {
  627. int hbl, vbl, vfreq;
  628.  
  629. vbl = y + (y+1)/(20000.0/(11*freq) - 1) + 1.5;
  630. vfreq = vbl * freq;
  631. hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) /
  632. (70.0 + 300000.0 / vfreq) / 16.0 + 0.5);
  633.  
  634. *vsyncstart = y;
  635. *vsyncend = y + 3;
  636. *vblank = vbl - 1;
  637. *hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;
  638. *hsyncend = x + hbl / 2 - 1;
  639. *hblank = x + hbl - 1;
  640. *clock = (x + hbl) * vfreq / 1000;
  641. }
  642.  
  643. void set_mode(vbios_map * map, cardinal mode, cardinal x, cardinal y, cardinal bp, cardinal htotal, cardinal vtotal) {
  644. int xprev, yprev;
  645. cardinal i, j;
  646.  
  647. for (i=0; i < map->mode_table_size; i++) {
  648. if (map->mode_table[i].mode == mode) {
  649. switch(map->bios) {
  650. case BT_1:
  651. {
  652. vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
  653.  
  654. if (bp) {
  655. map->mode_table[i].bits_per_pixel = bp;
  656. }
  657.  
  658. res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);
  659. res->x1 = (x & 0xff);
  660.  
  661. res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);
  662. res->y1 = (y & 0xff);
  663. if (htotal)
  664. res->x_total = ((htotal-x) & 0xff);
  665.  
  666. if (vtotal)
  667. res->y_total = ((vtotal-y) & 0xff);
  668. }
  669. break;
  670. case BT_2:
  671. {
  672. vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
  673.  
  674. res->xchars = x / 8;
  675. res->ychars = y / 16 - 1;
  676. xprev = res->modelines[0].x1;
  677. yprev = res->modelines[0].y1;
  678.  
  679. for(j=0; j < 3; j++) {
  680. vbios_modeline_type2 * modeline = &res->modelines[j];
  681.  
  682. if (modeline->x1 == xprev && modeline->y1 == yprev) {
  683. modeline->x1 = modeline->x2 = x-1;
  684. modeline->y1 = modeline->y2 = y-1;
  685.  
  686. gtf_timings(x, y, freqs[j], &modeline->clock,
  687. &modeline->hsyncstart, &modeline->hsyncend,
  688. &modeline->hblank, &modeline->vsyncstart,
  689. &modeline->vsyncend, &modeline->vblank);
  690.  
  691. if (htotal)
  692. modeline->htotal = htotal;
  693. else
  694. modeline->htotal = modeline->hblank;
  695.  
  696. if (vtotal)
  697. modeline->vtotal = vtotal;
  698. else
  699. modeline->vtotal = modeline->vblank;
  700. }
  701. }
  702. }
  703. break;
  704. case BT_3:
  705. {
  706. vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
  707.  
  708. xprev = res->modelines[0].x1;
  709. yprev = res->modelines[0].y1;
  710.  
  711. for (j=0; j < 3; j++) {
  712. vbios_modeline_type3 * modeline = &res->modelines[j];
  713.  
  714. if (modeline->x1 == xprev && modeline->y1 == yprev) {
  715. modeline->x1 = modeline->x2 = x-1;
  716. modeline->y1 = modeline->y2 = y-1;
  717.  
  718. gtf_timings(x, y, freqs[j], &modeline->clock,
  719. &modeline->hsyncstart, &modeline->hsyncend,
  720. &modeline->hblank, &modeline->vsyncstart,
  721. &modeline->vsyncend, &modeline->vblank);
  722. if (htotal)
  723. modeline->htotal = htotal;
  724. else
  725. modeline->htotal = modeline->hblank;
  726. if (vtotal)
  727. modeline->vtotal = vtotal;
  728. else
  729. modeline->vtotal = modeline->vblank;
  730.  
  731. modeline->timing_h = y-1;
  732. modeline->timing_v = x-1;
  733. }
  734. }
  735. }
  736. break;
  737. case BT_UNKWN:
  738. break;
  739. }
  740. }
  741. }
  742. }
  743.  
  744. void display_map_info(vbios_map * map) {
  745. printf("Chipset: %s\n", chipset_type_names[map->chipset]);
  746. printf("BIOS: %s\n", bios_type_names[map->bios]);
  747.  
  748. printf("Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
  749. printf("Mode Table Entries: %u\n", map->mode_table_size);
  750. }
  751.  
  752.  
  753. int parse_args(int argc, char *argv[], char ** filename, chipset_type *forced_chipset, cardinal *list, cardinal *mode, cardinal *x, cardinal *y, cardinal *bp, cardinal *raw, cardinal *htotal, cardinal *vtotal) {
  754. cardinal index = 1;
  755.  
  756. *list = *mode = *x = *y = *raw = *htotal = *vtotal = 0;
  757.  
  758. *forced_chipset = CT_UNKWN;
  759.  
  760. *filename = NULL;
  761.  
  762. if ((argc > index) && !strcmp(argv[index], "-f")) {
  763. index++;
  764.  
  765. if(argc<=index) {
  766. return 0;
  767. }
  768.  
  769. *filename = argv[index];
  770.  
  771. index++;
  772.  
  773. if(argc<=index) {
  774. return 0;
  775. }
  776. }
  777.  
  778. if ((argc > index) && !strcmp(argv[index], "-c")) {
  779. index++;
  780.  
  781. if(argc<=index) {
  782. return 0;
  783. }
  784.  
  785. if (!strcmp(argv[index], "845")) {
  786. *forced_chipset = CT_845G;
  787. }
  788. else if (!strcmp(argv[index], "855")) {
  789. *forced_chipset = CT_855GM;
  790. }
  791. else if (!strcmp(argv[index], "865")) {
  792. *forced_chipset = CT_865G;
  793. }
  794. else if (!strcmp(argv[index], "915G")) {
  795. *forced_chipset = CT_915G;
  796. }
  797. else if (!strcmp(argv[index], "915GM")) {
  798. *forced_chipset = CT_915GM;
  799. }
  800. else if (!strcmp(argv[index], "945G")) {
  801. *forced_chipset = CT_945G;
  802. }
  803. else if (!strcmp(argv[index], "945GM")) {
  804. *forced_chipset = CT_945GM;
  805. }
  806. else if (!strcmp(argv[index], "946GZ")) {
  807. *forced_chipset = CT_946GZ;
  808. }
  809. else if (!strcmp(argv[index], "G965")) {
  810. *forced_chipset = CT_G965;
  811. }
  812. else if (!strcmp(argv[index], "Q965")) {
  813. *forced_chipset = CT_Q965;
  814. }
  815. else {
  816. *forced_chipset = CT_UNKWN;
  817. }
  818.  
  819. index++;
  820.  
  821. if (argc<=index) {
  822. return 0;
  823. }
  824. }
  825.  
  826. if ((argc > index) && !strcmp(argv[index], "-l")) {
  827. *list = 1;
  828. index++;
  829.  
  830. if(argc<=index) {
  831. return 0;
  832. }
  833. }
  834.  
  835. if ((argc > index) && !strcmp(argv[index], "-r")) {
  836. *raw = 1;
  837. index++;
  838.  
  839. if(argc<=index) {
  840. return 0;
  841. }
  842. }
  843.  
  844. if (argc-index < 3 || argc-index > 6) {
  845. return -1;
  846. }
  847.  
  848. *mode = (cardinal) strtol(argv[index], NULL, 16);
  849. *x = (cardinal)atoi(argv[index+1]);
  850. *y = (cardinal)atoi(argv[index+2]);
  851.  
  852.  
  853. if (argc-index > 3) {
  854. *bp = (cardinal)atoi(argv[index+3]);
  855. }
  856. else {
  857. *bp = 0;
  858. }
  859.  
  860. if (argc-index > 4) {
  861. *htotal = (cardinal)atoi(argv[index+4]);
  862. }
  863. else {
  864. *htotal = 0;
  865. }
  866.  
  867. if (argc-index > 5) {
  868. *vtotal = (cardinal)atoi(argv[index+5]);
  869. }
  870. else {
  871. *vtotal = 0;
  872. }
  873.  
  874. return 0;
  875. }
  876.  
  877. void usage(char *name) {
  878. printf("Usage: %s [-f file] [-c chipset] [-l] [mode X Y] [bits/pixel] [htotal] [vtotal]\n", name);
  879. printf(" Set the resolution to XxY for a video mode\n");
  880. printf(" Bits per pixel are optional. htotal/vtotal settings are additionally optional.\n");
  881. printf(" Options:\n");
  882. printf(" -f use an alternate file (THIS IS USED FOR DEBUG PURPOSES)\n");
  883. printf(" -c force chipset type (THIS IS USED FOR DEBUG PURPOSES)\n");
  884. printf(" -l display the modes found in the video BIOS\n");
  885. printf(" -r display the modes found in the video BIOS in raw mode (THIS IS USED FOR DEBUG PURPOSES)\n");
  886. }
  887.  
  888. int main (int argc, char *argv[]) {
  889. vbios_map * map;
  890. cardinal list, mode, x, y, bp, raw, htotal, vtotal;
  891. char * filename;
  892. chipset_type forced_chipset;
  893.  
  894. printf("Intel 800/900 Series VBIOS Hack : version %s\n\n", VERSION);
  895.  
  896. if (parse_args(argc, argv, &filename, &forced_chipset, &list, &mode, &x, &y, &bp, &raw, &htotal, &vtotal) == -1) {
  897. usage(argv[0]);
  898. return 2;
  899. }
  900.  
  901. initialize_system(filename);
  902.  
  903. map = open_vbios(filename, forced_chipset);
  904. display_map_info(map);
  905.  
  906. printf("\n");
  907.  
  908. if (list) {
  909. list_modes(map, raw);
  910. }
  911.  
  912. if (mode!=0 && x!=0 && y!=0) {
  913. if (!filename)
  914. unlock_vbios(map);
  915.  
  916. set_mode(map, mode, x, y, bp, htotal, vtotal);
  917.  
  918. if (!filename)
  919. relock_vbios(map);
  920.  
  921. printf("Patch mode %02x to resolution %dx%d complete\n", mode, x, y);
  922.  
  923. if (list) {
  924. list_modes(map, raw);
  925. }
  926. }
  927.  
  928. close_vbios(map);
  929.  
  930. return 0;
  931. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement