! NULL device interface module

%option "-low-nocheck-nodiag"
%include "io.inc"

%routine input
  %signal 9,,,"End of file (null device)"
%end

%routine output (%record(scbfm)%name cb)
  cb_p = cb_bs; cb_l = cb_bl
%end

%routine SOP (%record(scb fm)%name cb,%integer code,p1,p2,%bytename b)
%switch sw(sopclose:sopread)
  ->sw(code) %if sopclose<=code<=sopread
  %signal 3,4,code,"Illegal SCB operation (:N)"
sw(sopflush):
sw(sopwrite):   output(cb); %return
sw(sopclose):
sw(sopabort):   heapput(cb_bs) %unless cb_bs=0; dispose(cb); %return
sw(soprefresh):
sw(sopread):    input
%end

%externalrecord(scbfm)%map FOP %alias "FOP_N" -
  (%integer code,%string(*)%name file,%name x)
%record(scbfm)%name cb == nil
%integer fastpc,soppc
  *lea sop,a0; *move.l a0,soppc
  %if code = fop openi %start
    *lea input,a0; *move.l a0,fastpc
    cb == newscb(file)
    cb_fastpc = fastpc; cb_soppc = soppc; cb_gla = a4
  %elseif fop openo <= code <= fop opena
    *lea output,a0; *move.l a0,fastpc
    cb == newscb(file)
    cb_fastpc = fastpc; cb_soppc = soppc; cb_gla = a4
    cb_bs = heapget(256); make global(record(cb_bs)); cb_bl = cb_bs+256
    cb_fs = cb_bs; cb_p = cb_bs
    cb_fl = cb_bs; cb_l = cb_bl
  %else
    %signal 3,4,code,"File operation not supported (:N)"
  %finish
  %result == cb
%end

