INT24.LST 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. Listing:
  2. 1 IMPLEMENTATION MODULE Int24 ;
  3. 2 (*========================================================
  4. 3 == TopSpeed Modula-2 V3 ==
  5. 4 == demo program: ==
  6. 5 == ==
  7. 6 == Int24 handler ==
  8. 7 == ==
  9. 8 == Skeleton handler for "critical errors" ==
  10. 9 == ==
  11. 10 ========================================================*)
  12. 11 (*# check(stack=>off,index=>off,range=>off,overflow=>off,nil_ptr=>off) *)
  13. 12
  14. 13 (* Example of defining an interrupt handler in Modula-2 *)
  15. 14
  16. 15 IMPORT SYSTEM,Lib,Str ;
  17. 16
  18. 17 CONST
  19. 18 ContinueProg = FALSE; (* Set this to TRUE if you want to continue
  20. 19 after an abort (returning 255 to the
  21. 20 calling program).
  22. 21 If ContinueProg is set to FALSE then the
  23. 22 program will terminate on 'abort' *)
  24. 23
  25. 24 (*----------------------------------------------------------------------*)
  26. 25
  27. 26 (* These are "safe" version of IO routines,
  28. 27 i.e. they do not call any DOS function > 12
  29. 28 Alternatively "Window" routines could be used.
  30. 29 *)
  31. 30
  32. 31 PROCEDURE WrStr(string: ARRAY OF CHAR);
  33. ***** ^ not supported yet
  34. 32 VAR R : SYSTEM.Registers;
  35. ***** ^ not supported yet
  36. 33 i : CARDINAL;
  37. 34 BEGIN
  38. 35 i := 0;
  39. 36 WHILE (i<SIZE(string))AND(string[i]<>CHR(0)) DO
  40. ***** ^ undeclared identifier
  41. ***** ^ not supported yet
  42. ***** ^ not supported yet
  43. ***** ^ not supported yet
  44. ***** ^ undeclared identifier
  45. ***** ^ not supported yet
  46. 37 R.DL := SHORTCARD(string[i]);
  47. ***** ^ not supported yet
  48. ***** ^ not supported yet
  49. ***** ^ not supported yet
  50. ***** ^ not supported yet
  51. 38 R.AH := 6;
  52. ***** ^ not supported yet
  53. ***** ^ not supported yet
  54. 39 Lib.Intr( R ,21H ); (* Don't use Lib.Dos as this will trigger
  55. ***** ^ not supported yet
  56. ***** ^ not supported yet
  57. ***** ^ not supported yet
  58. ***** ^ not supported yet
  59. 40 re-entered check *)
  60. 41 INC(i);
  61. ***** ^ undeclared identifier
  62. ***** ^ not supported yet
  63. 42 END;
  64. 43 END WrStr;
  65. ***** ^ not supported yet
  66. 44
  67. 45 PROCEDURE WrLn;
  68. 46 TYPE
  69. 47 a3 = ARRAY [0..1] OF CHAR;
  70. ***** ^ not supported yet
  71. ***** ^ not supported yet
  72. 48 CONST
  73. 49 crlf = a3(CHR(13),CHR(10));
  74. ***** ^ undeclared identifier
  75. ***** ^ not supported yet
  76. ***** ^ undeclared identifier
  77. ***** ^ not supported yet
  78. 50 BEGIN
  79. 51 WrStr( crlf );
  80. ***** ^ not supported yet
  81. ***** ^ not supported yet
  82. 52 END WrLn;
  83. ***** ^ not supported yet
  84. 53
  85. 54 PROCEDURE RdKey(): CHAR;
  86. 55 VAR R : SYSTEM.Registers;
  87. ***** ^ not supported yet
  88. 56 BEGIN
  89. 57 R.AH := 7;
  90. ***** ^ not supported yet
  91. ***** ^ not supported yet
  92. 58 Lib.Intr( R ,21H ); (* Don't use Lib.Dos as this will trigger
  93. ***** ^ not supported yet
  94. ***** ^ not supported yet
  95. ***** ^ not supported yet
  96. ***** ^ not supported yet
  97. 59 re-entered check *)
  98. 60 RETURN CHAR(R.AL);
  99. ***** ^ not supported yet
  100. ***** ^ not supported yet
  101. 61 END RdKey;
  102. ***** ^ not supported yet
  103. 62
  104. 63 (*----------------------------------------------------------------------*)
  105. 64 (* The pop stack inline code is required if the program should
  106. 65 continue after an abort (returning 255 to the calling program).
  107. 66 *)
  108. 67
  109. 68 TYPE
  110. 69 Code26 = ARRAY[0..25] OF SHORTCARD ;
  111. ***** ^ not supported yet
  112. ***** ^ not supported yet
  113. 70
  114. 71 (*# save,
  115. 72 call( reg_saved=>(dx,ax,bx,cx,si,di,es,ds,st1,st2),
  116. 73 inline=>on )
  117. 74 *)
  118. 75
  119. 76 PROCEDURE PopStack()=Code26(
  120. ***** ^ not supported yet
  121. 77 08BH,0E5H, (* mov sp,bp *)
  122. 78 083H,0C4H,01CH, (* add sp,1CH *)
  123. 79 058H, (* pop ax *)
  124. 80 05BH, (* pop bx *)
  125. 81 059H, (* pop cx *)
  126. 82 05AH, (* pop dx *)
  127. 83 05EH, (* pop si *)
  128. 84 05FH, (* pop di *)
  129. 85 058H, (* pop ax *)
  130. 86 01FH, (* pop ds *)
  131. 87 007H, (* pop es *)
  132. 88 08BH,0ECH, (* mov bp,sp *)
  133. 89 080H,04EH,004H,001H, (* or byte [bp][4],1 *)
  134. 90 08BH,0E8H, (* mov bp,ax *)
  135. 91 0B8H,0FFH,000H, (* mov ax,0FFH *)
  136. 92 0CFH); (* iret *)
  137. 93
  138. 94
  139. 95 (*----------------------------------------------------------------------*)
  140. 96 (* Actual Int24 Interrupt Handler
  141. 97 *)
  142. 98
  143. 99 (* pragmas for interrupt handler *)
  144. 100 (*# save,
  145. 101 call(interrupt => on,
  146. 102 reg_param => (),
  147. 103 same_ds => off
  148. 104 )
  149. 105 *)
  150. 106
  151. 107 (* NB, The interrupt pragma sets up the registers as parameters to the
  152. 108 procedure in the order defined below. This allows easy access to
  153. 109 the entry registers
  154. 110 *)
  155. 111 PROCEDURE Irpt24 ( Flags : BITSET; (* Registers on entry *)
  156. ***** ^ undeclared identifier
  157. 112 CS,IP : CARDINAL;
  158. 113 AX,CX : CARDINAL;
  159. 114 DX,BX : CARDINAL;
  160. 115 SP,BP : CARDINAL;
  161. 116 SI,DI : CARDINAL;
  162. 117 DS,ES : CARDINAL ) ;
  163. 118 VAR
  164. 119 s : ARRAY[0..40] OF CHAR ;
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. 120 k : CHAR ;
  168. 121 saveipf : BOOLEAN ;
  169. 122 P_AL : POINTER TO SHORTCARD;
  170. ***** ^ not supported yet
  171. 123 BEGIN
  172. 124 (* N.B. Only DOS functions <= 12 may be called from a critical
  173. 125 error handler
  174. 126 *)
  175. 127 CASE DI OF
  176. 128 0 : s := 'Disk write protected' |
  177. ***** ^ not supported yet
  178. ***** ^ not supported yet
  179. 129 2 : s := 'Drive not ready' |
  180. ***** ^ not supported yet
  181. ***** ^ not supported yet
  182. 130 9 : s := 'Printer out of paper' |
  183. ***** ^ not supported yet
  184. ***** ^ not supported yet
  185. 131 ELSE
  186. 132 s := 'Disk error' ;
  187. ***** ^ not supported yet
  188. ***** ^ not supported yet
  189. 133 END ;
  190. 134 Str.Append(s,'. Abort, Retry, Ignore?');
  191. ***** ^ not supported yet
  192. ***** ^ not supported yet
  193. ***** ^ not supported yet
  194. ***** ^ not supported yet
  195. 135 WrStr(s) ; WrLn ;
  196. ***** ^ not supported yet
  197. ***** ^ not supported yet
  198. ***** ^ not supported yet
  199. 136 REPEAT
  200. 137 k := CAP(RdKey()) ;
  201. ***** ^ undeclared identifier
  202. ***** ^ not supported yet
  203. ***** ^ not supported yet
  204. 138 UNTIL (k='R') OR (k='I') OR (k='A') ;
  205. 139 P_AL := ADR(AX);
  206. ***** ^ not supported yet
  207. ***** ^ undeclared identifier
  208. ***** ^ not supported yet
  209. 140 IF k='I' THEN P_AL^ := 0 ; (* ignore *)
  210. ***** ^ not supported yet
  211. 141 ELSIF k='R' THEN P_AL^ := 1 ; (* retry *)
  212. ***** ^ not supported yet
  213. 142 ELSE (* abort *)
  214. 143 IF ContinueProg THEN
  215. ***** ^ not supported yet
  216. 144 PopStack; (* Removes MSDOS call frame and Return 255 to caller *)
  217. ***** ^ not supported yet
  218. 145 (* Does not return here *)
  219. 146 ELSE
  220. 147 HALT ;
  221. ***** ^ undeclared identifier
  222. 148 END ;
  223. 149 END ;
  224. 150 END Irpt24;
  225. ***** ^ not supported yet
  226. 151 (*# restore *)
  227. 152
  228. 153
  229. 154 VAR
  230. 155 Int24Vec[0:24H*4] : FarADDRESS;
  231. ***** ^ not supported yet
  232. ***** ^ not supported yet
  233. ***** ^ undeclared identifier
  234. 156 VAR
  235. 157 h : CARDINAL;
  236. 158 BEGIN
  237. 159 SYSTEM.DI ;
  238. ***** ^ not supported yet
  239. ***** ^ not supported yet
  240. 160 (* Install interrupt 24 *)
  241. 161 Int24Vec := FarADR(Irpt24) ;
  242. ***** ^ not supported yet
  243. ***** ^ undeclared identifier
  244. ***** ^ not supported yet
  245. 162 SYSTEM.EI ;
  246. ***** ^ not supported yet
  247. ***** ^ not supported yet
  248. 163 END Int24.
  249. ***** ^ not supported yet
  250. 85 errors