callback.pp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. Program callback;
  2. uses crt,
  3. go32;
  4. const mouseint = $33;
  5. var mouse_regs : trealregs;
  6. mouse_seginfo : tseginfo;
  7. var mouse_numbuttons : longint;
  8. mouse_action : word;
  9. mouse_x, mouse_y : Word;
  10. mouse_b : Word;
  11. userproc_installed : Longbool;
  12. userproc_length : Longint;
  13. userproc_proc : pointer;
  14. {$ASMMODE DIRECT}
  15. procedure callback_handler; assembler;
  16. asm
  17. pushw %es
  18. pushw %ds
  19. pushl %edi
  20. pushl %esi
  21. cmpl $1, _USERPROC_INSTALLED
  22. je .LNoCallback
  23. pushal
  24. movw %es, %ax
  25. movw %ax, %ds
  26. movw U_GO32_DOSMEMSELECTOR, %ax
  27. movw %ax, %fs
  28. call *_USERPROC_PROC
  29. popal
  30. .LNoCallback:
  31. popl %esi
  32. popl %edi
  33. popw %ds
  34. popw %es
  35. movl (%esi), %eax
  36. movl %eax, %es: 42(%edi)
  37. addw $4, %es: 46(%edi)
  38. iret
  39. end;
  40. procedure mouse_dummy; begin end;
  41. procedure textuserproc;
  42. begin
  43. mouse_b := mouse_regs.bx;
  44. mouse_x := (mouse_regs.cx shr 3) + 1;
  45. mouse_y := (mouse_regs.dx shr 3) + 1;
  46. end;
  47. procedure install_mouse (userproc : pointer;
  48. userproclen : longint);
  49. var r : trealregs;
  50. begin
  51. r.eax := $0; realintr(mouseint, r);
  52. if (r.eax <> $FFFF) then begin
  53. Writeln('No Mircosoft compatible mouse found');
  54. Write('A Mircosoft compatible mouse driver is');
  55. writeln(' necessary to run this example');
  56. halt;
  57. end;
  58. if (r.bx = $ffff) then mouse_numbuttons := 2
  59. else mouse_numbuttons := r.bx;
  60. Writeln(mouse_numbuttons,
  61. ' button Mircosoft compatible mouse found.');
  62. if (userproc <> nil) then begin
  63. userproc_proc := userproc;
  64. userproc_installed := true;
  65. userproc_length := userproclen;
  66. lock_code(userproc_proc, userproc_length);
  67. end else begin
  68. userproc_proc := nil;
  69. userproc_length := 0;
  70. userproc_installed := false;
  71. end;
  72. lock_data(mouse_x, sizeof(mouse_x));
  73. lock_data(mouse_y, sizeof(mouse_y));
  74. lock_data(mouse_b, sizeof(mouse_b));
  75. lock_data(mouse_action, sizeof(mouse_action));
  76. lock_data(userproc_installed, sizeof(userproc_installed));
  77. lock_data(@userproc_proc, sizeof(userproc_proc));
  78. lock_data(mouse_regs, sizeof(mouse_regs));
  79. lock_data(mouse_seginfo, sizeof(mouse_seginfo));
  80. lock_code(@callback_handler,
  81. longint(@mouse_dummy)
  82. - longint(@callback_handler));
  83. get_rm_callback(@callback_handler, mouse_regs, mouse_seginfo);
  84. r.eax := $0c; r.ecx := $7f; r.edx := longint(mouse_seginfo.offset);
  85. r.es := mouse_seginfo.segment;
  86. realintr(mouseint, r);
  87. r.eax := $01;
  88. realintr(mouseint, r);
  89. end;
  90. procedure remove_mouse;
  91. var r : trealregs;
  92. begin
  93. r.eax := $02; realintr(mouseint, r);
  94. r.eax := $0c; r.ecx := 0; r.edx := 0; r.es := 0;
  95. realintr(mouseint, r);
  96. free_rm_callback(mouse_seginfo);
  97. if (userproc_installed) then begin
  98. unlock_code(userproc_proc, userproc_length);
  99. userproc_proc := nil;
  100. userproc_length := 0;
  101. userproc_installed := false;
  102. end;
  103. unlock_data(mouse_x, sizeof(mouse_x));
  104. unlock_data(mouse_y, sizeof(mouse_y));
  105. unlock_data(mouse_b, sizeof(mouse_b));
  106. unlock_data(mouse_action, sizeof(mouse_action));
  107. unlock_data(@userproc_proc, sizeof(userproc_proc));
  108. unlock_data(userproc_installed,
  109. sizeof(userproc_installed));
  110. unlock_data(mouse_regs, sizeof(mouse_regs));
  111. unlock_data(mouse_seginfo, sizeof(mouse_seginfo));
  112. unlock_code(@callback_handler,
  113. longint(@mouse_dummy)
  114. - longint(@callback_handler));
  115. fillchar(mouse_seginfo, sizeof(mouse_seginfo), 0);
  116. end;
  117. begin
  118. install_mouse(@textuserproc, 400);
  119. Writeln('Press any key to exit...');
  120. while (not keypressed) do begin
  121. { write mouse state info }
  122. gotoxy(1, wherey);
  123. write('MouseX : ', mouse_x:2,
  124. ' MouseY : ', mouse_y:2,
  125. ' Buttons : ', mouse_b:2);
  126. end;
  127. remove_mouse;
  128. end.