qdos.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2020 by Karoly Balogh
  4. Interface QDOS OS functions used by the Sinclair QL RTL
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$i qdosh.inc}
  12. const
  13. _MT_INF = $00;
  14. _MT_ALCHP = $18;
  15. _MT_RECHP = $19;
  16. function mt_inf(sys_vars: ppchar; ver_ascii: plongint): Tjobid; assembler; nostackframe; public name '_mt_inf';
  17. asm
  18. move.l d2,-(sp)
  19. move.l sys_vars,-(sp)
  20. move.l ver_ascii,-(sp)
  21. moveq.l #_MT_INF,d0
  22. trap #1
  23. move.l (sp)+,a1
  24. move.l d2,(a1) { ver_ascii }
  25. move.l (sp)+,a1
  26. move.l a0,(a1) { sys_vars }
  27. move.l (sp)+,d2
  28. move.l d1,d0 { jobid }
  29. end;
  30. function mt_alchp(size: dword; sizegot: pdword; jobid: Tjobid): pointer; assembler; nostackframe; public name '_mt_alchp';
  31. asm
  32. movem.l d2-d3/a2-a3,-(sp)
  33. move.l sizegot,-(sp)
  34. move.l jobid,d2
  35. move.l size,d1
  36. moveq.l #_MT_ALCHP,d0
  37. trap #1
  38. move.l (sp)+,d2 // sizegot ptr
  39. tst d0
  40. bne @quit
  41. move.l d2,a1
  42. beq @nosizegot
  43. move.l d1,(a1)
  44. @nosizegot:
  45. move.l a0,d0
  46. @quit:
  47. movem.l (sp)+,d2-d3/a2-a3
  48. end;
  49. procedure mt_rechp(area: pointer); assembler; nostackframe; public name '_mt_rechp';
  50. asm
  51. movem.l d2-d3/a2-a3,-(sp)
  52. move.l area,a0
  53. moveq.l #_MT_RECHP,d0
  54. trap #1
  55. movem.l (sp)+,d2-d3/a2-a3
  56. end;
  57. const
  58. _IO_OPEN = $01;
  59. _IO_CLOSE = $02;
  60. function io_open_qlstr(name_qlstr: pointer; mode: longint): Tchanid; assembler; nostackframe; public name '_io_open_qlstr';
  61. asm
  62. movem.l d2-d3,-(sp)
  63. move.l name_qlstr,a0
  64. moveq.l #-1,d1
  65. move.l mode,d3
  66. moveq.l #_IO_OPEN,d0
  67. trap #2
  68. bne @quit
  69. move.l a0,d0
  70. @quit:
  71. movem.l (sp)+,d2-d3
  72. end;
  73. function io_open(name: pchar; mode: longint): Tchanid; public name '_io_open';
  74. var
  75. len: longint;
  76. name_qlstr: array[0..63] of char;
  77. begin
  78. len:=length(name);
  79. if len > length(name_qlstr)-2 then
  80. len:=length(name_qlstr)-2;
  81. PWord(@name_qlstr)[0]:=len;
  82. Move(name^,name_qlstr[2],len);
  83. result:=io_open_qlstr(@name_qlstr,mode);
  84. end;
  85. function io_close(chan: Tchanid): longint; assembler; nostackframe; public name '_io_close';
  86. asm
  87. move.l chan,a0
  88. moveq.l #_IO_CLOSE,d0
  89. trap #2
  90. end;
  91. const
  92. _IO_SBYTE = $05;
  93. _IO_SSTRG = $07;
  94. function io_sbyte(chan: Tchanid; timeout: Ttimeout; c: char): longint; assembler; public name '_io_sbyte';
  95. asm
  96. move.l d3,-(sp)
  97. move.w timeout,d3
  98. clr.l d1
  99. move.b c,d1
  100. move.l chan,a0
  101. moveq.l #_IO_SBYTE,d0
  102. trap #3
  103. move.l (sp)+,d3
  104. end;
  105. function io_sstrg(chan: Tchanid; timeout: Ttimeout; buf: pointer; len: smallint): smallint; assembler; public name '_io_sstrg';
  106. asm
  107. movem.l d2-d3,-(sp)
  108. move.w len,d2
  109. move.l buf,a1
  110. move.w timeout,d3
  111. move.l chan,a0
  112. moveq.l #_IO_SSTRG,d0
  113. trap #3
  114. tst.l d0
  115. beq @ok
  116. cmp.w #ERR_EF,d0
  117. beq @eof
  118. cmp.w #ERR_NC,d0
  119. bne @quit
  120. @eof:
  121. tst.w d1
  122. beq @quit
  123. @ok:
  124. clr.l d0
  125. move.w d1,d0
  126. @quit:
  127. movem.l (sp)+,d2-d3
  128. end;
  129. const
  130. _UT_CON = $c6;
  131. _UT_SCR = $c8;
  132. function ut_con(params: PConScrParams): Tchanid; assembler; nostackframe; public name '_ut_con';
  133. asm
  134. movem.l d2-d3/a2-a3,-(sp)
  135. move.l params,a1
  136. move.w _UT_CON,a2
  137. jsr (a2)
  138. bne @quit
  139. move.l a0,d0
  140. @quit:
  141. movem.l (sp)+,d2-d3/a2-a3
  142. end;
  143. function ut_scr(params: PConScrParams): Tchanid; assembler; nostackframe; public name '_ut_scr';
  144. asm
  145. movem.l d2-d3/a2-a3,-(sp)
  146. move.l params,a1
  147. move.w _UT_SCR,a2
  148. jsr (a2)
  149. bne @quit
  150. move.l a0,d0
  151. @quit:
  152. movem.l (sp)+,d2-d3/a2-a3
  153. end;