GRAFCORE.DEF 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. FOREIGN DEFINITION MODULE GrafCore;
  2. (*
  3. ** Michael McCarthy & John Pfitzner,
  4. ** CSP-960 Project, Semester 2, 1991
  5. **
  6. ** A module of graphics routines for GPM Modula-2.
  7. ** Most procedures were adapted from Richard Wilton's
  8. ** "Programmers guide to PC and PS/2 VIDEO SYSTEMS",
  9. ** Microsoft Press, 1987
  10. **
  11. ** Last revision : 30/10/91
  12. **
  13. ** IMPORTANT NOTES:
  14. **
  15. ** (i) For the routines in this module to work correctly, it is
  16. ** ESSENTIAL that all video mode changes are done via SetVideoMode
  17. ** rather than via external procedure(s).
  18. **
  19. ** (ii) The low level facilities provided in this module are intended
  20. ** only for export to a native Modula-2 library module such as
  21. ** Graph. Programmers are strongly advised to use Graph rather
  22. ** than to import directly from GrafCore, since the latter has no
  23. ** initialization section or error handling capabilities.
  24. **
  25. ** (iii) Since this is a "bottom level" module absolutely NO CHECKING
  26. ** for legality of parameter values is carried out. At the very
  27. ** least, passing row or column values that are off screen has
  28. ** unpredictable consequences. Be warned !!
  29. **
  30. ** (iv) All coordinate parameters are passed in (column,row) order,
  31. ** where column refers to the horizontal or x coordinate, and
  32. ** row is the vertical or y coordinate. Legal column and row
  33. ** values for the various graphics modes are given below.
  34. *)
  35. IMPORT IMPLEMENTATION FROM "Grafcore.obj" ;
  36. FROM SYSTEM IMPORT ADDRESS, BYTE;
  37. FROM Types IMPORT SHORTCARD;
  38. (* ======================= Colours ============================== *)
  39. (*
  40. ** Standard 4 colour CGA palette: Black; Cyan; Magenta; White;
  41. **
  42. ** Alternative 4 colour CGA palette: Black; Green; Red; Yellow;
  43. **
  44. ** 16 colour EGA/VGA palette:
  45. **
  46. ** Dark colors Light colors
  47. **
  48. ** Black = 0; DarkGray = 8;
  49. ** Blue = 1; LightBlue = 9;
  50. ** Green = 2; LightGreen = 10;
  51. ** Cyan = 3; LightCyan = 11;
  52. ** Red = 4; LightRed = 12;
  53. ** Magenta = 5; LightMagenta = 13;
  54. ** Brown = 6; Yellow = 14;
  55. ** LightGray = 7; White = 15;
  56. *)
  57. (* ======================== Video modes ========================= *)
  58. (*
  59. ** On MCGA, EGA, or VGA, mode 0 is the same as mode 1, and mode 2 is
  60. ** the same as mode 3. CGA colour burst is disabled in modes 0 and 2.
  61. **
  62. ** TEXT_BW40 = 0; (* 40 column text, 16 (grey on CGA) *)
  63. ** TEXT_C40 = 1; (* 40 column text, 16 *)
  64. ** TEXT_BW80 = 2; (* 80 column text, 16 (grey on CGA) *)
  65. ** TEXT_C80 = 3; (* 80 column text, 16 *)
  66. **
  67. **
  68. ** CGA modes. On EGA, MCGA and VGA adapters, modes 4 and 5 are
  69. ** identical. On CGA colour displays, mode 5 gives a cyan-red-white
  70. ** palette, while on mono displays it gives better gray shade
  71. ** differentiation. Mode 4 allows selection of 2 different
  72. ** palettes on colour displays; the standard cyan-violet-white, or
  73. ** green-red-yellow. See procedure SetPal4 to switch palettes.
  74. **
  75. ** CGA_Mode_4 = 4; (* 320x200 4 colours *)
  76. ** CGA_Mode_5 = 5; (* 320x200 4 colours, col. burst disabled *)
  77. ** CGA_Mode_6 = 6; (* 640x200 monochrome *)
  78. **
  79. **
  80. ** TEXT_MONO = 7; (* 80 column text, 2 colours *)
  81. **
  82. **
  83. ** EGA modes. Note that on 64K EGA cards, only 4 colours are
  84. ** available in mode 16
  85. **
  86. ** EGA_Mode_13 = 13; (* 320x200 16 colours *)
  87. ** EGA_Mode_14 = 14; (* 640x200 16 colours *)
  88. ** EGA_Mode_16 = 16; (* 640x350 16 colours *)
  89. **
  90. ** VGA_Mode_18 = 18; (* 640x480 16 colours *)
  91. **
  92. ** ### Not supported modes ###
  93. ** ### EGA_Mode_15 = 15; (* 640x350 2 colours .. not supported *)
  94. ** ### VGA_Mode_17 = 17; (* 640x480 2 colours .. not supported *)
  95. ** ### VGA_Mode_19 = 19; (* 320x200 256 colours .. not supported *)
  96. **
  97. **
  98. ** Hercules monochrome adapters. Note that this mode number has no
  99. ** meaning to the BIOS, or anything else outside this module!
  100. **
  101. ** HGC_Graphics_Mode = 31; (* 720x348 monochrome *)
  102. *)
  103. (* ===================== Video adapters ========================= *)
  104. (*
  105. ** MDA_Adapter = 1;
  106. ** CGA_Adapter = 2;
  107. ** EGA_Adapter = 3;
  108. ** MCGA_Adapter = 4;
  109. ** VGA_Adapter = 5;
  110. ** HGC_Adapter = 80H;
  111. ** HGC_Plus_Adapter = 81H;
  112. ** InColor_Adapter = 82H;
  113. *)
  114. (* ===================== Video displays ========================= *)
  115. (*
  116. ** MDA_Display = 1;
  117. ** CGA_Display = 2;
  118. ** EGA_Color_Display = 3;
  119. ** PS2_Mono_Display = 4;
  120. ** PS2_Color_Display = 5;
  121. *)
  122. TYPE
  123. Palette16 = ARRAY [0..16] OF BYTE;
  124. WriteMode = (replaceMode, andMode, orMode, xorMode);
  125. VideoHW = RECORD
  126. Adapter1, Display1 : BYTE;(* primary adapter & display *)
  127. Adapter2, Display2 : BYTE (* secondary video, if fitted *)
  128. END;
  129. (* ================== Mode independent procedures ============== *)
  130. PROCEDURE SetVideoMode(vmode : CARDINAL);
  131. (*
  132. ** Switches video mode. Assumes that vmode is one of the supported
  133. ** graphics modes - [4..6,13,14,16,18,31] - or an alphanumeric mode
  134. ** [0..3,7]. If vmode is not one of these values, does nothing.
  135. *)
  136. PROCEDURE GetVideoMode(VAR textcols : CARDINAL) : CARDINAL;
  137. (*
  138. ** Returns the current video mode, and sets the variable textcols to
  139. ** the number of text columns for that mode.
  140. *)
  141. PROCEDURE SetWriteMode(wmode : WriteMode) ;
  142. (*
  143. ** Sets the default method for interaction with background pixels in
  144. ** line drawing, block restoration, and char/string output.
  145. ** If default method is replaceMode, object overwrites the current screen
  146. ** contents; if the default method is xorMode, the object is XORed with
  147. ** the current screen contents, and so on.
  148. ** This function is only implemented for all write functions in EGA/VGA
  149. ** modes. For CGA and Hercules modes, it is only functional for WrPxlXXX
  150. ** and BlockRestoreXXX.
  151. *)
  152. PROCEDURE GetVideoHW( VAR vstruc : VideoHW) ;
  153. (*
  154. ** Fills out a VideoHW record with information on the video adapter
  155. ** and display type. Also detects a secondary adapter and display if
  156. ** there is one.
  157. *)
  158. (* ================== Mode dependent procedures ================== *)
  159. (* ______________________________________________________
  160. ** The following table defines legal values for column,
  161. ** row and colour parameters in the procedures below.
  162. **
  163. ** Video Column Row Colour
  164. ** Mode Range Range Range
  165. ** -----------------------------------
  166. ** 4,5 0..320 0..199 0..3
  167. ** 6 0..639 0..199 0..1
  168. ** 13 0..319 0..199 0..15
  169. ** 14 0..639 0..199 0..15
  170. ** 16 0..639 0..349 0..15
  171. ** 18 0..639 0..479 0..15
  172. ** 31 0..719 0..347 0..1
  173. ** -----------------------------------
  174. *)
  175. (*========================================================*)
  176. (*== ==*)
  177. (*== Return the colour value of a specified pixel ==*)
  178. (*== ==*)
  179. (*========================================================*)
  180. PROCEDURE RdPxl10(col,row: INTEGER) : CARDINAL; (* Modes 13,14,16,18 *)
  181. PROCEDURE RdPxl06(col,row: INTEGER) : CARDINAL; (* Mode 6 *)
  182. PROCEDURE RdPxl04(col,row: INTEGER) : CARDINAL; (* Modes 4 and 31 *)
  183. (*========================================================*)
  184. (*== ==*)
  185. (*== Set a pixel in specified colour ==*)
  186. (*== ==*)
  187. (*========================================================*)
  188. PROCEDURE WrPxl10(col,row : INTEGER; color : CARDINAL); (* Modes 13,14,16,18 *)
  189. PROCEDURE WrPxl06(col,row : INTEGER; color : CARDINAL); (* Mode 6 *)
  190. PROCEDURE WrPxl04(col,row : INTEGER; color : CARDINAL); (* Modes 4 and 31 *)
  191. (*========================================================*)
  192. (*== ==*)
  193. (*== Draw a line from (col1,row1) to (col2,row2) in ==*)
  194. (*== specified colour ==*)
  195. (*== ==*)
  196. (*========================================================*)
  197. PROCEDURE Line10( col1, row1, (* Modes 13,14,16,18 *)
  198. col2, row2 : INTEGER;
  199. color : CARDINAL
  200. );
  201. PROCEDURE LineCGA( col1, row1, (* Modes 4 and 6 *)
  202. col2, row2 : INTEGER;
  203. color : CARDINAL
  204. );
  205. PROCEDURE LineHGC( col1, row1, (* Hercules mono *)
  206. col2, row2 : INTEGER;
  207. color : CARDINAL
  208. );
  209. (*========================================================*)
  210. (*== ==*)
  211. (*== Clear the screen with specified colour ==*)
  212. (*== ==*)
  213. (*========================================================*)
  214. PROCEDURE Cls10(color:CARDINAL); (* Modes 13,14,16,18 *)
  215. PROCEDURE Cls06(color:CARDINAL); (* Mode 6 *)
  216. PROCEDURE Cls04(color:CARDINAL); (* Mode 4 *)
  217. PROCEDURE ClsHGC(color:CARDINAL); (* Hercules *)
  218. (*========================================================*)
  219. (*== ==*)
  220. (*== Write a character at specified screen position ==*)
  221. (*== (col,row) refers to coordinates of top-left hand ==*)
  222. (*== corner of the rectangular cell in which the char ==*)
  223. (*== is drawn. The character itself is drawn in the ==*)
  224. (*== colour "fg", while the rest of the cell is in ==*)
  225. (*== colour "bg". For monochrome graphics modes, bg is ==*)
  226. (*== ignored, and the cell background is the inverse of ==*)
  227. (*== fg. As noted above, the current writeMode only has ==*)
  228. (*== effect for EGA/VGA modes. ==*)
  229. (*== The character cell is 8 pixels wide except for ==*)
  230. (*== Hercules adapters, which provide for a width of 9 ==*)
  231. (*== in hardware - the 9th pixel is the same as the 8th ==*)
  232. (*== For all EGA modes, the cell has 14 pixel rows, ==*)
  233. (*== while for CGA and Hercules, it has 8. ==*)
  234. (*== ==*)
  235. (*========================================================*)
  236. PROCEDURE WrChar10(ch : CHAR; col, row : INTEGER; fg, bg : CARDINAL);
  237. PROCEDURE WrChar04(ch : CHAR; col, row : INTEGER; fg, bg : CARDINAL);
  238. PROCEDURE WrChar06(ch : CHAR; col, row : INTEGER; fg, bg : CARDINAL);
  239. PROCEDURE WrCharHGC(ch : CHAR; col, row : INTEGER; fg, bg : CARDINAL);
  240. (*========================================================*)
  241. (*== ==*)
  242. (*== Write a string at a specified screen position ==*)
  243. (*== ==*)
  244. (*========================================================*)
  245. PROCEDURE WrStr(str : ARRAY OF CHAR; col, row : INTEGER; fg, bg : CARDINAL);
  246. (*========================================================*)
  247. (*== ==*)
  248. (*== Save a rectangular region of the screen to memory ==*)
  249. (*== ==*)
  250. (*========================================================*)
  251. PROCEDURE BlockSave10( blockAddress : ADDRESS;
  252. col1, row1,
  253. col2, row2 : INTEGER
  254. ) : SHORTCARD;
  255. (*
  256. ** Stores graphics data in colour plane bitmap format at the
  257. ** specified address. Used for modes 13,14,16 and 18.
  258. **
  259. ** IT IS THE RESPONSIBILITY OF THE CALLER TO ENSURE THAT ENOUGH
  260. ** CONTIGUOUS ALLOCATED MEMORY IS AVAILABLE AT THE SPECIFIED ADDRESS !
  261. **
  262. ** The space required can be calculated via the formula
  263. **
  264. ** 4*(row2 - row1 + 1)*(INT((col2 - col1 + 1)/8) + x) + 5
  265. **
  266. ** where x = 0 if (col2 - col1 + 1) MOD 8 = 0
  267. ** 1 otherwise
  268. **
  269. ** e.g. for 175 full screen rows,
  270. ** 4 * 175 * (INT(640/8)) + 5 = 4*175*80 + 5 = 56,005 bytes
  271. **
  272. ** IMPLEMENTATION RESTRICTION : THE LARGEST MEMORY BLOCK THAT CAN BE
  273. ** WRITTEN IN A SINGLE CALL IS 64k bytes.
  274. **
  275. ** Returns the number of bytes storage actually written.
  276. *)
  277. PROCEDURE BlockSaveCGA( blockAddress : ADDRESS;
  278. col1, row1,
  279. col2, row2 : INTEGER
  280. ) : SHORTCARD;
  281. (*
  282. ** As above, for CGA modes 4,5 and 6.
  283. **
  284. ** The space required is given by the formula
  285. **
  286. ** (row2 - row1 + 1) * (INT((col2 - col1 + 1)/b) + x) + 5
  287. **
  288. ** where b = 4 (modes 4 and 5)
  289. ** or 8 (mode 6)
  290. ** and
  291. ** x = 0 if (col2 - col1 + 1) MOD b = 0
  292. ** 1 otherwise
  293. *)
  294. PROCEDURE BlockSaveHGC( blockAddress : ADDRESS;
  295. col1, row1,
  296. col2, row2 : INTEGER
  297. ) : SHORTCARD;
  298. (*
  299. ** As above for Hercules monochrome graphics mode. Space required is
  300. ** calculated by thesame formula as for CGA mode 6.
  301. *)
  302. (*========================================================*)
  303. (*== ==*)
  304. (*== Restore a rectangular region from memory to screen ==*)
  305. (*== The duals of BlockSave10, BlockSaveCGA, and ==*)
  306. (*== BlockSaveHGC. ==*)
  307. (*== ==*)
  308. (*========================================================*)
  309. PROCEDURE BlockRestore10(blockAddress : ADDRESS; col, row : INTEGER);
  310. PROCEDURE BlockRestoreCGA(blockAddress : ADDRESS; col, row : INTEGER);
  311. PROCEDURE BlockRestoreHGC(blockAddress : ADDRESS; col, row : INTEGER);
  312. (*========================================================*)
  313. (*== ==*)
  314. (*== Set/Get the EGA/VGA 16 colour palette registers ==*)
  315. (*== ==*)
  316. (*========================================================*)
  317. PROCEDURE SetPal16(pal : Palette16);
  318. (* Sets the EGA 16 colour palette and border registers *)
  319. PROCEDURE GetPal16(VAR pal : Palette16);
  320. (*
  321. ** Gets the EGA 16 colour palette and border registers ..
  322. ** ONLY WORKS FOR VGA ADAPTERS
  323. *)
  324. (*========================================================*)
  325. (*== ==*)
  326. (*== Miscellaneous ==*)
  327. (*== ==*)
  328. (*========================================================*)
  329. PROCEDURE SetPal4(altPalette : BOOLEAN) ;
  330. (*
  331. ** Sets the CGA 4 colour palette to one of two possible sets.
  332. ** N.B. FALSE gives standard cyan-violet-white palette,
  333. ** TRUE gives alternate green-red-yellow palette
  334. ** Only works for video mode 4
  335. *)
  336. PROCEDURE WaitForRetrace();
  337. (*
  338. ** Waits for vertical retrace .. used for synchronizing updates for small
  339. ** animations
  340. *)
  341. END GrafCore.