xxx-system-io.red 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. %==============================================================================
  2. %
  3. % PT20:XXX-SYSTEM-IO.RED - 20 specific IO routines for PSL
  4. %
  5. % Author: Modified by Robert R. Kessler and MLG
  6. % From System-io.red for the 20 by Eric Benson
  7. % Computer Science Dept.
  8. % University of Utah
  9. % Date: Modified 16 August 1982
  10. % Original Date 16 September 1981
  11. %
  12. % Copyright (c) 1982 University of Utah
  13. %
  14. %==============================================================================
  15. ON Syslisp;
  16. % Each individual system must have the following routines defined.
  17. % SysClearIo, SysOpenRead, SysOpenWrite, SysReadRec, SysWriteRec, SysClose,
  18. % SysMaxBuffer
  19. %
  20. % The following definitions are used in the routines:
  21. % FileDescriptor - A machine dependent word that references a file once
  22. % opened.
  23. % FileName - A Lisp string of the file name.
  24. %
  25. % ---------- SysClearIo:
  26. % called by Cleario for system dep extras
  27. lap '((!*entry SysClearIO expr 0)
  28. %
  29. % ^C from RDTTY and restart causes trouble, but we don't want a full RESET
  30. % (don't want to close files or kill forks), so we'll just do the
  31. % part of RESET that we want, for terminal input
  32. %
  33. (!*MOVE (WConst 8#100) (reg 1)) % .priin
  34. (rfmod)
  35. (tro 2 2#001111100001000000) % tt%wak + tt%eco + .ttasi, like RESET
  36. (sfmod)
  37. (!*EXIT 0)
  38. );
  39. syslsp procedure SysOpenRead(Channel,FileName);
  40. % % Open FileName for input and
  41. % % return a file descriptor used
  42. % % in later references to the
  43. % % file.
  44. Dec20Open(FileName,
  45. % gj%old gj%sht
  46. 2#001000000000000001000000000000000000,
  47. % 7*of%bsz of%rd
  48. 2#000111000000000000010000000000000000);
  49. %/ later... if JFN eq 0 then return ContOpenError(FileName, 'INPUT);
  50. syslsp procedure SysOpenWrite(Channel,FileName);
  51. Dec20Open(FileName,
  52. % gj%fou gj%new gj%sht
  53. 2#110000000000000001000000000000000000,
  54. % 7*of%bsz of%wr
  55. 2#000111000000000000001000000000000000);
  56. %/ if JFN eq 0 then return ContOpenError(FileName, 'OUTPUT);
  57. lap '((!*entry Dec20Open expr 3)
  58. %
  59. % Dec20Open(Filename string, GTJFN bits, OPENF bits)
  60. %
  61. (!*WPLUS2 (reg 1) (WConst 1)) % increment r1 to point to characters
  62. (hrli (reg 1) 8#440700) % turn r1 into a byte pointer
  63. (!*MOVE (reg 1) (reg 4)) % save filename string in r4
  64. (!*MOVE (reg 2) (reg 1)) % GTJFN flag bits in r1
  65. (!*MOVE (reg 4) (reg 2)) % string in r2
  66. (gtjfn)
  67. (!*JUMP (Label CantOpen))
  68. (!*MOVE (reg 3) (reg 2)) % OPENF bits in r2, JFN in r1
  69. (openf)
  70. CantOpen
  71. (!*MOVE (WConst 0) (reg 1)) % return 0 on error
  72. (!*EXIT 0) % else return the JFN
  73. );
  74. syslsp procedure SysReadRec(FileDescriptor,StringBuffer);
  75. % % Read from the FileDescriptor, a
  76. % % record into the StringBuffer.
  77. % % Return the length of the
  78. % % string read.
  79. Begin scalar N,Ch;
  80. N:=0;
  81. Loop: Ch:=Dec20ReadChar(FileDescriptor);
  82. StrByt(StringBuffer,N):=Ch;
  83. If Ch eq Char EOL or Ch eq Char EOF then return N;
  84. N:=N+1;
  85. % Check buffer size here
  86. goto Loop;
  87. End;
  88. lap '((!*entry Dec20ReadChar expr 1)
  89. Loop
  90. (bin) % read a character
  91. (erjmp CheckEOF) % check for end-of-file on error
  92. (!*JUMPEQ (Label Loop) (reg 2) (WConst 0))% try again if it's null char
  93. (!*JUMPEQ (Label Loop) (reg 2) (WConst 8#15))% or carriage return
  94. (!*MOVE (reg 2) (reg 1)) % move char to reg 1
  95. %/ (camn (reg nil) (fluid !*ECHO)) % is echo on?
  96. (!*EXIT 0) % no, just return char
  97. %/ (!*PUSH (reg 1)) % yes, save char
  98. %/ (!*CALL WriteChar) % and write it
  99. %/ (!*POP (reg 1)) % restore it
  100. %/ (!*EXIT 0) % and return
  101. CheckEOF
  102. (gtsts) % check file status
  103. (tlnn (reg 2) 2#000000001000000000) % gs%eof
  104. (!*JUMP (Label ReadError))
  105. (!*MOVE (WConst 26) (reg 1)) % return EOF char
  106. (!*EXIT 0)
  107. ReadError
  108. (!*MOVE (QUOTE "Attempt to read from file failed") (reg 1))
  109. (!*JCALL IoError)
  110. );
  111. syslsp procedure SysWriteRec (FileDescriptor, StringToWrite, StringLength);
  112. % % Write StringLength characters
  113. % % from StringToWrite from the
  114. % % first position.
  115. for i:=0:StringLength do
  116. Dec20WriteChar(FileDescriptor,strbyt(StringToWrite,i));
  117. lap '((!*entry Dec20WriteChar expr 2)
  118. % Jfn,Chr
  119. (!*JUMPEQ (Label CRLF) (reg 2) (WConst 8#12)) % if LF, echo CRLF
  120. (bout) % no, just echo char
  121. (!*EXIT 0) % return
  122. CRLF
  123. (!*MOVE (WConst 8#15) (reg 2)) % write carriage-return
  124. (bout)
  125. (!*MOVE (WConst 8#12) (reg 2)) % write linefeed
  126. (bout)
  127. (!*EXIT 0) % return
  128. );
  129. % SysClose (FileDescriptor); % Close FileDescriptor, allowing
  130. % % it to be reused.
  131. lap '((!*entry SysClose expr 1)
  132. (closf)
  133. (!*JUMP (Label CloseError))
  134. (!*EXIT 0)
  135. CloseError
  136. (!*MOVE (QUOTE "Channel could not be closed") (reg 1))
  137. (!*JCALL ChannelError)
  138. );
  139. syslsp procedure SysMaxBuffer(FileDesc);
  140. 200;
  141. End;