IUTILITA.PAS 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. (* programme comment‚ et expliqu‚ dans le livre *)
  2. (* LE DESASSEMBLEUR 8086 COLIBRI, publi‚ par *)
  3. (* L'INSTITUT PASCAL: *)
  4. (* 26 Rue Lamartine, 75009 PARIS *)
  5. (* Tel: (1) 42.85.10.82 *)
  6. procedure stop;
  7. begin
  8. read(kbd, choix1);
  9. end;
  10. procedure affiche_erreur(p_message: string80);
  11. begin
  12. writeln;
  13. write('erreur: ', p_message);
  14. readln;
  15. end;
  16. function f_octet_hexadecimal(p_octet: byte): string4;
  17. const kt_hexa: array[0..15] of char= '0123456789ABCDEF';
  18. begin
  19. f_octet_hexadecimal:= concat(kt_hexa[p_octet div 16],
  20. kt_hexa[p_octet mod 16]);
  21. end;
  22. function f_entier_hexadecimal(p_entier: integer): string4;
  23. begin
  24. f_entier_hexadecimal:= concat(f_octet_hexadecimal(hi(p_entier)),
  25. f_octet_hexadecimal(lo(p_entier)));
  26. end;
  27. function f_lis_commande(p_ensemble_ok: t_set_of_char): char;
  28. var l_touche: char;
  29. l_x, l_y: integer;
  30. begin
  31. l_x:= wherex; l_y:= wherey;
  32. repeat
  33. read(kbd, l_touche);
  34. l_touche:= upcase(l_touche); write(l_touche);
  35. if not (l_touche in p_ensemble_ok)
  36. then gotoxy(l_x, l_y);
  37. until l_touche in p_ensemble_ok;
  38. writeln;
  39. f_lis_commande:= l_touche;
  40. end;
  41. procedure lis_entier(var pv_valeur: integer);
  42. const k_touche_recul= #8;
  43. k_touche_return= #13;
  44. var l_indice: integer;
  45. l_touche: char;
  46. l_chaine_numerique: string[5];
  47. begin
  48. l_chaine_numerique:= ' ';
  49. l_indice:= 1;
  50. repeat
  51. repeat
  52. read(kbd, l_touche);
  53. until (l_touche in ['0'..'9', k_touche_recul, k_touche_return]);
  54. if (l_touche= k_touche_recul) and (l_indice>1)
  55. then begin
  56. l_indice:= l_indice- 1;
  57. write(l_touche);
  58. end
  59. else
  60. if (l_touche in ['0'..'9'])
  61. and not (l_touche= k_touche_return)
  62. then begin
  63. write(l_touche);
  64. l_chaine_numerique[l_indice]:= l_touche;
  65. l_indice:= l_indice+ 1;
  66. end;
  67. until (l_touche= k_touche_return) or (l_indice> 5);
  68. writeln;
  69. pv_valeur:= 0;
  70. for l_indice:= 1 to l_indice- 1 do
  71. begin
  72. l_touche:= l_chaine_numerique[l_indice];
  73. pv_valeur:= pv_valeur* 10 + ord(l_touche)- 48;
  74. end;
  75. end;
  76. procedure lis_entier_hexadecimal(p_colonne, p_ligne: integer;
  77. var pv_valeur: integer);
  78. const k_touche_recul= #8;
  79. k_touche_return= #13;
  80. var l_indice: integer;
  81. l_touche: char;
  82. l_chaine_numerique: string[4];
  83. begin
  84. l_chaine_numerique:= f_entier_hexadecimal(pv_valeur);
  85. l_indice:= 1;
  86. repeat
  87. gotoxy(p_colonne, p_ligne);
  88. repeat
  89. read(kbd, l_touche); l_touche:= upcase(l_touche);
  90. until (l_touche in ['0'..'9', 'A'..'F', k_touche_recul, ' ', k_touche_return]);
  91. if (l_touche= k_touche_recul) and (l_indice>1)
  92. then begin
  93. l_indice:= l_indice- 1;
  94. p_colonne:= p_colonne- 1;
  95. end
  96. else
  97. if (l_touche= ' ') and not (l_touche= k_touche_return)
  98. then begin
  99. p_colonne:= p_colonne+ 1;
  100. l_indice:= l_indice+ 1;
  101. end
  102. else
  103. if (l_touche in ['0'..'9', 'A'..'F'])
  104. and not (l_touche= k_touche_return)
  105. then begin
  106. write(l_touche);
  107. l_chaine_numerique[l_indice]:= l_touche;
  108. p_colonne:= p_colonne+ 1;
  109. l_indice:= l_indice+ 1;
  110. end;
  111. until (l_touche= k_touche_return) or (l_indice> 4);
  112. pv_valeur:= 0;
  113. for l_indice:= 1 to 4 do
  114. begin
  115. l_touche:= l_chaine_numerique[l_indice];
  116. if l_touche<= '9'
  117. then pv_valeur:= pv_valeur* 16 + ord(l_touche)- 48
  118. else pv_valeur:= pv_valeur* 16 + ord(l_touche)- 55;
  119. end;
  120. end;
  121. procedure entre_debut_fin(p_prompte: string80);
  122. var l_ligne: integer;
  123. begin
  124. if adresse_fin- $8000< adresse_debut- $8000
  125. then adresse_fin:= adresse_debut;
  126. write('$', f_entier_hexadecimal(adresse_debut_tampon));
  127. write('-$', f_entier_hexadecimal(adresse_fin_tampon), ' : ');
  128. l_ligne:= wherey;
  129. if p_prompte<> ''
  130. then begin
  131. gotoxy(29, l_ligne); write(p_prompte);
  132. end;
  133. gotoxy(15, l_ligne);
  134. write('[$', f_entier_hexadecimal(adresse_debut), '-');
  135. write('$', f_entier_hexadecimal(adresse_fin), ']');
  136. repeat
  137. lis_entier_hexadecimal(17, l_ligne, adresse_debut);
  138. until (adresse_debut- $8000>= adresse_debut_tampon- $8000)
  139. and
  140. (adresse_debut- $8000<= adresse_fin_tampon- $8000);
  141. repeat
  142. lis_entier_hexadecimal(23, l_ligne, adresse_fin);
  143. until (adresse_fin- $8000>= adresse_debut_tampon- $8000)
  144. and
  145. (adresse_fin- $8000<= adresse_fin_tampon- $8000);
  146. gotoxy(68, l_ligne);
  147. end;
  148. function f_hexadecimal_octet(p_chaine: string2): byte;
  149. function f_hexadecimal_quartet(p_caractere: char): byte;
  150. begin
  151. if p_caractere<= '9'
  152. then f_hexadecimal_quartet:= ord(p_caractere)- 48
  153. else f_hexadecimal_quartet:= ord(p_caractere)- 55;
  154. end;
  155. begin
  156. f_hexadecimal_octet:= f_hexadecimal_quartet(p_chaine[1]) shl 4
  157. + f_hexadecimal_quartet(p_chaine[2]);
  158. end;
  159. procedure lis_booleen(p_message: string80; var pv_booleen: boolean);
  160. begin
  161. write(p_message, ' Ok ? ');
  162. read(kbd, choix1); writeln(choix1);
  163. pv_booleen:= upcase(choix1)= 'O';
  164. end;
  165. procedure affiche_booleen(p_message: string80; p_booleen: boolean);
  166. begin
  167. if p_booleen
  168. then write('avec ')
  169. else write('sans ');
  170. write(p_message);
  171. end;
  172. procedure choisis_sortie;
  173. begin
  174. write('nom sortie <a:essai.txt> ? '); readln(nom_sortie);
  175. writeln(sortie); close(sortie);
  176. assign(sortie, nom_sortie); rewrite(sortie);
  177. writeln(sortie);
  178. end;