sysos.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. {*****************************************************************************
  2. Watcom Helpers
  3. *****************************************************************************}
  4. const
  5. carryflag = 1;
  6. type
  7. tseginfo=packed record
  8. offset : pointer;
  9. segment : word;
  10. end;
  11. var
  12. old_int00 : tseginfo;cvar;
  13. old_int75 : tseginfo;cvar;
  14. procedure getinoutres(def : word);
  15. var
  16. regs : trealregs;
  17. begin
  18. regs.realeax:=$5900;
  19. regs.realebx:=$0;
  20. sysrealintr($21,regs);
  21. InOutRes:=lo(regs.realeax);
  22. case InOutRes of
  23. 19 : InOutRes:=150;
  24. 21 : InOutRes:=152;
  25. 32 : InOutRes:=5;
  26. end;
  27. if InOutRes=0 then
  28. InOutRes:=Def;
  29. end;
  30. function far_strlen(selector : word;linear_address : sizeuint) : longint;assembler;
  31. asm
  32. movl linear_address,%edx
  33. movl %edx,%ecx
  34. movw selector,%gs
  35. .Larg19:
  36. movb %gs:(%edx),%al
  37. testb %al,%al
  38. je .Larg20
  39. incl %edx
  40. jmp .Larg19
  41. .Larg20:
  42. movl %edx,%eax
  43. subl %ecx,%eax
  44. end;
  45. function get_ds : word;assembler;
  46. asm
  47. movw %ds,%ax
  48. end;
  49. function get_cs : word;assembler;
  50. asm
  51. movw %cs,%ax
  52. end;
  53. function dos_selector : word; assembler;
  54. asm
  55. movw %ds,%ax { no separate selector needed }
  56. end;
  57. procedure alloc_tb; assembler;
  58. { allocate 8kB real mode transfer buffer }
  59. asm
  60. pushl %ebx
  61. movw $0x100,%ax
  62. movw $512,%bx
  63. int $0x31
  64. movw %ax,tb_segment
  65. shll $16,%eax
  66. shrl $12,%eax
  67. movl %eax,tb
  68. popl %ebx
  69. end;
  70. procedure sysseg_move(sseg : word;source : sizeuint;dseg : word;dest : sizeuint;count : longint);
  71. begin
  72. if count=0 then
  73. exit;
  74. if (sseg<>dseg) or ((sseg=dseg) and (source>dest)) then
  75. asm
  76. pushl %esi
  77. pushl %edi
  78. pushw %es
  79. pushw %ds
  80. cld
  81. movl count,%ecx
  82. movl source,%esi
  83. movl dest,%edi
  84. movw dseg,%ax
  85. movw %ax,%es
  86. movw sseg,%ax
  87. movw %ax,%ds
  88. movl %ecx,%eax
  89. shrl $2,%ecx
  90. rep
  91. movsl
  92. movl %eax,%ecx
  93. andl $3,%ecx
  94. rep
  95. movsb
  96. popw %ds
  97. popw %es
  98. popl %edi
  99. popl %esi
  100. end
  101. else if (source<dest) then
  102. { copy backward for overlapping }
  103. asm
  104. pushl %esi
  105. pushl %edi
  106. pushw %es
  107. pushw %ds
  108. std
  109. movl count,%ecx
  110. movl source,%esi
  111. movl dest,%edi
  112. movw dseg,%ax
  113. movw %ax,%es
  114. movw sseg,%ax
  115. movw %ax,%ds
  116. addl %ecx,%esi
  117. addl %ecx,%edi
  118. movl %ecx,%eax
  119. andl $3,%ecx
  120. orl %ecx,%ecx
  121. jz .LSEG_MOVE1
  122. { calculate esi and edi}
  123. decl %esi
  124. decl %edi
  125. rep
  126. movsb
  127. incl %esi
  128. incl %edi
  129. .LSEG_MOVE1:
  130. subl $4,%esi
  131. subl $4,%edi
  132. movl %eax,%ecx
  133. shrl $2,%ecx
  134. rep
  135. movsl
  136. cld
  137. popw %ds
  138. popw %es
  139. popl %edi
  140. popl %esi
  141. end;
  142. end;