vgatest.pp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. { From VGAlib, changed for svgalib }
  2. { partially copyrighted (C) 1993 by Hartmut Schirmer }
  3. Program vgatest;
  4. uses svgalib,strings;
  5. Var
  6. line : array [0..2048 * 3-1] of byte;
  7. Procedure testmode (Mode : Longint);
  8. var
  9. xmax, ymax, i, x, y, yw, ys, c : longint;
  10. modeinfo : Pvga_modeinfo;
  11. begin
  12. vga_setmode(mode);
  13. modeinfo := vga_getmodeinfo(mode);
  14. Writeln ('Width: ',modeinfo^.width,' Height: ',modeinfo^.height,
  15. ' Colors: ',modeinfo^.colors);
  16. Write ('DisplayStartRange: ',modeinfo^.startaddressrange,
  17. ' Maxpixels: ',modeinfo^.maxpixels,' Blit: ');
  18. if modeinfo^.haveblit<>0 then
  19. writeln ('YES') else writeln ('NO');
  20. vga_screenoff();
  21. xmax := vga_getxdim - 1;
  22. ymax := vga_getydim - 1;
  23. vga_setcolor(vga_white);
  24. vga_drawline(0, 0, xmax, 0);
  25. vga_drawline(xmax, 0, xmax, ymax);
  26. vga_drawline(xmax, ymax, 0, ymax);
  27. vga_drawline(0, ymax, 0, 0);
  28. for i := 0 to 25 do
  29. begin
  30. vga_setegacolor(i);
  31. vga_drawline(10 + i * 5, 10, 90 + i * 5, 90);
  32. end;
  33. for i := 0 to 25 do
  34. begin
  35. vga_setegacolor(i);
  36. vga_drawline(90 + i * 5, 10, 10 + i * 5, 90);
  37. end;
  38. vga_screenon();
  39. ys := 100;
  40. yw := (ymax - 100) div 4;
  41. Case vga_getcolors of
  42. 256:
  43. begin
  44. for i := 0 to 60 do
  45. begin
  46. c := (i * 64) div 60;
  47. vga_setpalette(i + 16, c, c, c);
  48. vga_setpalette(i + 16 + 60, c, 0, 0);
  49. vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
  50. vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
  51. end;
  52. line[0] := 15;
  53. line[xmax] := 15;
  54. line[1] := 0;
  55. line[xmax - 1] := 0;
  56. for x := 2 to xmax - 1 do
  57. line[x] := (((x - 2) * 60) div (xmax - 3)) + 16;
  58. for y := ys to (ys + yw-1) do { gray }
  59. vga_drawscanline(y, line);
  60. for x := 2 to xmax - 1 do
  61. inc(line[x],60);
  62. inc(ys,yw);
  63. for y := ys to ys + yw-1 do
  64. vga_drawscanline(y, line);
  65. for x := 2 to xmax - 1 do
  66. inc(line[x],60);
  67. inc(ys,yw);
  68. for y := ys to ys + yw-1 do
  69. vga_drawscanline(y, line);
  70. for x := 2 to xmax - 1 do
  71. inc(line[x],60);
  72. inc(ys,yw);
  73. for y := ys to ys + yw-1 do
  74. vga_drawscanline(y, line);
  75. end;
  76. 1 shl 15,
  77. 1 shl 16,
  78. 1 shl 24:
  79. begin
  80. for x := 2 to xmax - 1 do
  81. begin
  82. c := ((x - 2) * 256) div (xmax - 3);
  83. y := ys;
  84. vga_setrgbcolor(c, c, c);
  85. vga_drawline(x, y, x, y + yw - 1);
  86. inc (y,yw);
  87. vga_setrgbcolor(c, 0, 0);
  88. vga_drawline(x, y, x, y + yw - 1);
  89. inc(y, yw);
  90. vga_setrgbcolor(0, c, 0);
  91. vga_drawline(x, y, x, y + yw - 1);
  92. inc (y,yw);
  93. vga_setrgbcolor(0, 0, c);
  94. vga_drawline(x, y, x, y + yw - 1);
  95. end;
  96. for y := 0 to 63 do
  97. for x := 0 to 63 do
  98. begin
  99. vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 0);
  100. vga_drawpixel(xmax div 2 - 160 + x, y + ymax div 2 - 80);
  101. vga_setrgbcolor(x * 4 + 3, 0, y * 4 + 3);
  102. vga_drawpixel(xmax div 2 - 32 + x, y + ymax div 2 - 80);
  103. vga_setrgbcolor(0, x * 4 + 3, y * 4 + 3);
  104. vga_drawpixel(xmax div 2 + 160 - 64 + x, y + ymax div 2 - 80);
  105. vga_setrgbcolor(x * 4 + 3, y * 4 + 3, 255);
  106. vga_drawpixel(xmax div 2 - 160 + x, y + ymax div 2 + 16);
  107. vga_setrgbcolor(x * 4 + 3, 255, y * 4 + 3);
  108. vga_drawpixel(xmax div 2 - 32 + x, y + ymax div 2 + 16);
  109. vga_setrgbcolor(255, x * 4 + 3, y * 4 + 3);
  110. vga_drawpixel(xmax div 2 + 160 - 64 + x, y + ymax div 2 + 16);
  111. end;
  112. end;
  113. else
  114. begin
  115. if (vga_getcolors = 16) then
  116. begin
  117. for i := 0 to xmax - 2 do
  118. line[i] := (i + 2) mod 16;
  119. line[0] := 15;
  120. line[xmax] := 15;
  121. line[1] := 0;
  122. line[xmax - 1] := 0;
  123. end;
  124. if (vga_getcolors = 2) then
  125. begin
  126. for i := 0 to xmax do
  127. line[i] := $11;
  128. line[0] := $91;
  129. end;
  130. for i := 100 to ymax - 1 do
  131. vga_drawscanline(i, line);
  132. end;
  133. end;
  134. readln;
  135. vga_setmode(GTEXT);
  136. end;
  137. Var
  138. i,highest,mode : longint;
  139. info : pvga_modeinfo;
  140. expl : PAnsiChar;
  141. Const cols : PAnsiChar = NiL;
  142. begin
  143. getmem (expl,100);
  144. vga_init(); { Initialize. }
  145. mode := vga_getdefaultmode();
  146. if (mode=-1) then
  147. begin
  148. Writeln ('Choose one of the following video modes:');
  149. highest := 0;
  150. for i := 1 to GLASTMODE do
  151. if vga_hasmode(i) then
  152. begin
  153. expl[0]:=#0;
  154. info := vga_getmodeinfo(i);
  155. Case info^.colors of
  156. 2: begin
  157. cols := '2';
  158. strcopy(expl, '1 bitplane, monochrome');
  159. end;
  160. 16: begin
  161. cols := '16';
  162. strcopy(expl, '4 bitplanes');
  163. end;
  164. 256: begin
  165. if i=G320x200x256 then
  166. strcopy(PAnsiChar(@expl[0]), 'packed-pixel')
  167. else if (i=G320x240x256) or
  168. ((i=G320x400x256) or
  169. (i=G360x480x256)) then
  170. strcopy(expl, 'Mode X')
  171. else
  172. strcopy(expl,'packed-pixel,banked');
  173. end;
  174. 1 shl 15:
  175. begin
  176. cols := '32K';
  177. strcopy(expl, '5-5-5 RGB,blue at LSB, banked');
  178. end;
  179. 1 shl 16:
  180. begin
  181. cols := '64K';
  182. strcopy(expl, '5-6-5 RGB,blue at LSB,banked');
  183. end;
  184. 1 shl 24:
  185. begin
  186. cols := '16M';
  187. if info^.bytesperpixel = 3 then
  188. if (info^.flags and RGB_MISORDERED)=0 then
  189. strcopy(expl, '8-8-8 BGR, red byte first, banked')
  190. else
  191. strcopy(expl, '8-8-8 RGB, blue byte first, banked')
  192. else if (info^.flags and RGB_MISORDERED)=0 then
  193. strcopy(expl, '8-8-8 RGBX, 32-bit pixels, X byte first, banked')
  194. else
  195. strcopy(expl, '8-8-8 XRGB, 32-bit pixels, blue byte first, banked')
  196. end;
  197. end;
  198. if (info^.flags and IS_INTERLACED)=0 then
  199. begin
  200. if (expl[0] <> #0) then
  201. strcat(expl, ',');
  202. strcat(expl, 'interlaced');
  203. end;
  204. if (info^.flags and IS_DYNAMICMODE)=0 then
  205. begin
  206. if (expl[0] <> #0) then
  207. strcat(expl, ',');
  208. strcat(expl, 'dynamically loaded');
  209. end;
  210. highest := i;
  211. Write (i,': ', info^.width,'x', info^.height,' ');
  212. if (cols = NiL) then
  213. write (info^.colors)
  214. else
  215. write (cols);
  216. write (' colors ');
  217. if (expl[0]<>#0) then
  218. write('(', expl,')');
  219. writeln;
  220. end;
  221. Write ('Enter mode number (1-', highest,') : ');
  222. Readln (mode);
  223. if (mode < 1) or (mode > GLASTMODE) then
  224. begin
  225. Writeln ('Error: Mode number out of range');
  226. halt(1);
  227. end;
  228. end;
  229. if (vga_hasmode(mode)) then
  230. testmode(mode)
  231. else
  232. begin
  233. Writeln ('Error: Video mode not supported by driver.');
  234. Halt(1);
  235. end;
  236. end.