seldes.pp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. Program sel_des;
  2. uses crt,
  3. go32;
  4. const maxx = 80;
  5. maxy = 25;
  6. bytespercell = 2;
  7. screensize = maxx * maxy * bytespercell;
  8. linB8000 = $B800 * 16;
  9. type string80 = string[80];
  10. var
  11. text_save : array[0..screensize-1] of byte;
  12. text_oldx, text_oldy : Word;
  13. text_sel : Word;
  14. procedure status(s : string80);
  15. begin
  16. gotoxy(1, 1);
  17. clreol;
  18. write(s);
  19. readkey;
  20. end;
  21. procedure selinfo(sel : Word);
  22. begin
  23. gotoxy(1, 24);
  24. clreol;
  25. writeln('Descriptor base address : $',
  26. hexstr(get_segment_base_address(sel), 8));
  27. clreol;
  28. write('Descriptor limit : ',
  29. get_segment_limit(sel));
  30. end;
  31. function makechar(ch : char; color : byte) : Word;
  32. begin
  33. result := byte(ch) or (color shl 8);
  34. end;
  35. begin
  36. seg_move(dosmemselector, linB8000,
  37. get_ds, longint(@text_save), screensize);
  38. text_oldx := wherex; text_oldy := wherey;
  39. seg_fillword(dosmemselector, linB8000,
  40. screensize div 2,
  41. makechar(' ', Black or (Black shl 4)));
  42. status('Creating selector ' +
  43. '''text_sel'' to a part of text screen memory');
  44. text_sel := allocate_ldt_descriptors(1);
  45. set_segment_base_address(text_sel, linB8000
  46. + bytespercell * maxx * 1);
  47. set_segment_limit(text_sel,
  48. screensize-1-bytespercell*maxx*3);
  49. selinfo(text_sel);
  50. status('and clearing entire memory ' +
  51. 'selected by ''text_sel'' descriptor');
  52. seg_fillword(text_sel, 0,
  53. (get_segment_limit(text_sel)+1) div 2,
  54. makechar(' ', LightBlue shl 4));
  55. status('Notice that only the memory described'+
  56. ' by the descriptor changed, nothing else');
  57. status('Now reducing it''s limit and base and '+
  58. 'setting it''s described memory');
  59. set_segment_base_address(text_sel,
  60. get_segment_base_address(text_sel)
  61. + bytespercell * maxx);
  62. set_segment_limit(text_sel,
  63. get_segment_limit(text_sel)
  64. - bytespercell * maxx * 2);
  65. selinfo(text_sel);
  66. status('Notice that the base addr increased by '+
  67. 'one line but the limit decreased by 2 lines');
  68. status('This should give you the hint that the '+
  69. 'limit is relative to the base');
  70. seg_fillword(text_sel, 0,
  71. (get_segment_limit(text_sel)+1) div 2,
  72. makechar(#176, LightMagenta or Brown shl 4));
  73. status('Now let''s get crazy and copy 10 lines'+
  74. ' of data from the previously saved screen');
  75. seg_move(get_ds, longint(@text_save),
  76. text_sel, maxx * bytespercell * 2,
  77. maxx * bytespercell * 10);
  78. status('At last freeing the descriptor and '+
  79. 'restoring the old screen contents..');
  80. status('I hope this little program may give '+
  81. 'you some hints on working with descriptors');
  82. free_ldt_descriptor(text_sel);
  83. seg_move(get_ds, longint(@text_save),
  84. dosmemselector, linB8000, screensize);
  85. gotoxy(text_oldx, text_oldy);
  86. end.