PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/vid_mode_morphos.c

https://gitlab.com/fzwoch/fodquake
C | 181 lines | 128 code | 35 blank | 18 comment | 26 complexity | 2393ce5642a26851a86c1719b1468229 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. Copyright (C) 2009-2010 Mark Olsen
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include <graphics/displayinfo.h>
  16. #include <proto/exec.h>
  17. #include <proto/graphics.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include "vid_mode_morphos.h"
  22. typedef struct vrect_s vrect_t;
  23. typedef enum keynum keynum_t;
  24. #include "sys_video.h"
  25. int modeline_to_modeinfo(const char *modeline, struct modeinfo *modeinfo)
  26. {
  27. const char *p;
  28. const char *p2;
  29. unsigned int commas;
  30. commas = 0;
  31. p = modeline;
  32. while((p = strchr(p, ',')))
  33. {
  34. commas++;
  35. p = p + 1;
  36. }
  37. if (commas != 3)
  38. return 0;
  39. p = modeline;
  40. p2 = strchr(p, ',');
  41. strlcpy(modeinfo->monitorname, p, p2-p<sizeof(modeinfo->monitorname)?p2-p+1:sizeof(modeinfo->monitorname));
  42. p = p2 + 1;
  43. modeinfo->width = strtoul(p, 0, 0);
  44. p = strchr(p, ',') + 1;
  45. modeinfo->height = strtoul(p, 0, 0);
  46. p = strchr(p, ',') + 1;
  47. modeinfo->depth = strtoul(p, 0, 0);
  48. return 1;
  49. }
  50. const char * const *Sys_Video_GetModeList(void)
  51. {
  52. const char **ret;
  53. char buf[256];
  54. ULONG id;
  55. unsigned int nummodes;
  56. unsigned int i;
  57. APTR handle;
  58. struct DisplayInfo dispinfo;
  59. struct DimensionInfo diminfo;
  60. struct MonitorInfo moninfo;
  61. id = INVALID_ID;
  62. nummodes = 0;
  63. while((id = NextDisplayInfo(id)) != INVALID_ID)
  64. {
  65. nummodes++;
  66. }
  67. ret = AllocVec((nummodes + 1) * sizeof(*ret), MEMF_ANY|MEMF_CLEAR);
  68. if (ret == 0)
  69. return 0;
  70. id = INVALID_ID;
  71. i = 0;
  72. while((id = NextDisplayInfo(id)) != INVALID_ID)
  73. {
  74. if (i == nummodes)
  75. break;
  76. handle = FindDisplayInfo(id);
  77. if (handle)
  78. {
  79. if (!GetDisplayInfoData(handle, &dispinfo, sizeof(dispinfo), DTAG_DISP, 0)
  80. || !GetDisplayInfoData(handle, &diminfo, sizeof(diminfo), DTAG_DIMS, 0)
  81. || !GetDisplayInfoData(handle, &moninfo, sizeof(moninfo), DTAG_MNTR, 0))
  82. continue;
  83. if (dispinfo.NotAvailable || !(dispinfo.PropertyFlags&DIPF_IS_WB))
  84. continue;
  85. #ifdef GLQUAKE
  86. if (diminfo.MaxDepth <= 8)
  87. continue;
  88. #else
  89. if (diminfo.MaxDepth != 8)
  90. continue;
  91. #endif
  92. snprintf(buf, sizeof(buf), "%s,%d,%d,%d", moninfo.Mspc->ms_Node.xln_Name, diminfo.StdOScan.MaxX + 1, diminfo.StdOScan.MaxY + 1, diminfo.MaxDepth);
  93. ret[i] = AllocVec(strlen(buf) + 1, MEMF_ANY);
  94. if (ret[i] == 0)
  95. break;
  96. strcpy((char *)ret[i], buf);
  97. i++;
  98. }
  99. }
  100. if (id == INVALID_ID)
  101. {
  102. ret[i] = 0;
  103. return ret;
  104. }
  105. for(i=0;ret[i];i++)
  106. FreeVec((void *)ret[i]);
  107. FreeVec(ret);
  108. return 0;
  109. }
  110. void Sys_Video_FreeModeList(const char * const *displaymodes)
  111. {
  112. unsigned int i;
  113. for(i=0;displaymodes[i];i++)
  114. FreeVec((void *)displaymodes[i]);
  115. FreeVec((void *)displaymodes);
  116. }
  117. const char *Sys_Video_GetModeDescription(const char *mode)
  118. {
  119. struct modeinfo mi;
  120. char monitorname[64]; /* Mneh, this is longer than it can be anyway :P */
  121. char buf[256];
  122. char *p;
  123. if (modeline_to_modeinfo(mode, &mi))
  124. {
  125. strlcpy(monitorname, mi.monitorname, sizeof(monitorname));
  126. p = strchr(monitorname, '.');
  127. if (p)
  128. *p = 0;
  129. snprintf(buf, sizeof(buf), "%s: %dx%d %dbpp", monitorname, mi.width, mi.height, mi.depth);
  130. p = AllocVec(strlen(buf) + 1, MEMF_ANY);
  131. if (p)
  132. {
  133. strcpy(p, buf);
  134. return p;
  135. }
  136. }
  137. return 0;
  138. }
  139. void Sys_Video_FreeModeDescription(const char *modedescription)
  140. {
  141. FreeVec((void *)modedescription);
  142. }