 .OPT NO LIST›;  SAVE #D1:CIO.M65›;› .PAGE "CIO"›;  LOAD #D1:PERHNDLR.M65›;› *= $E456›CIOV› JMP CIO› *= $E46E›CIOINV› JMP ICIO›;›  *= $E4C1›  LIST› .LOCAL›;›; Initialize CIO. Clear all IOCB's›; Placing $FF in ICHID and address›; of Iocb not open minus one in›; Icptl/h.›;›ICIO› LDX #0›?ICIO1› LDA #$FF› STA ICHID,X› LDA # <IIN-1› STA ICPTL,X› LDA # >IIN-1› STA ICPTH,X› TXA› CLC› ADC #$10› TAX› CMP #$80› BCC ?ICIO1› RTS›IIN› LDY #133› RTS›;›; Entry point via Jsr Ciov›;›CIO› STA ICAX6Z  Save output character› STX ICAX5Z  Save iocb index›;›; Verify iocb number›;› TXA› AND #$0F› BNE ?CIERR1› CPX #$80› BCC ?IOC1›?CIERR1› LDY #134    Iocb number err› JMP ?CIRTN1›;›; Copy bytes 0 to 11 of the Iocb›; to page 0. (Ichid-Icax2 incl.)›;›?IOC1› LDY #0›?IOC1A› LDA ICHID,X› STA ICHIDZ,Y› INX› INY› CPY #12› BCC ?IOC1A›;›; Check for parallel device handler›;› LDA ICHIDZ› CMP #$7F› BNE ?CMDCHECK›; -----------------------------›; Parallel device handlers only› LDA ICCOMZ› CMP #12     Close command?› BEQ ?CICLOS›;›; HNDLOD = $02E9›; ref'd 58635   58698   59008   61233›;› LDA HNDLOD  Flag set by device open› BNE ?GOTDEV›ERR130› LDY #130    No device err›?JYEXIT› JMP ?CIRTN1›?GOTDEV› JSR INITPD  Load peripheral› BMI ?JYEXIT handler for open›; -----------------------------›;›; Evaluate command and go to›; appropriate routine›;›?CMDCHECK› LDY #132   Xio syntax error default› LDA ICCOMZ› CMP #3          Open?› BCC ?CIERR4     Error if less› TAY› CPY #14         Special?› BCC ?IOC2       No› LDY #14         Yes, use special index›?IOC2› STY ICCOMT      Save index› LDA ?COMTAB-3,Y Get offset› BEQ ?CIOPEN     Open cmd if 0› CMP #2          Close?› BEQ ?CICLOS› CMP #8          Status or Special?› BCS ?CISTSP› CMP #4          Read?› BEQ ?CIREAD› JMP ?CIWRIT     Must be write›;›; -----------------------------›; Execute Open command›;›?CIOPEN› LDA ICHIDZ  Ensure channel free› CMP #$FF› BEQ ?IOC6›;› LDY #129    Already open!›?CIERR4› JMP ?CIRTN1 exit›;›?IOC6› LDA HNDLOD  Hndlod flagged?› BNE ?POLL   Yes, go look for device›;›; Go find device in Hatabs›;› JSR ?DEVSRC› BCS ?POLL   Failed, try parallel›;›; Clear Dvstat bytes›;› LDA #0› STA DVSTAT› STA DVSTAT+1›;›; Go put open vector-1 into Icax3/4z›;›IOC7› JSR ?COMENT   Label for external code› BCS ?CIERR4   Exit on error›;›; Execute handler code via indirect Jmp›;› JSR ?GOHAND›;›; Store putbyt-1 address into Iocb›;› LDA #11     Simulate put byte command› STA ICCOMT› JSR ?COMENT Go load Icax3/4z› LDA ICAX3Z  Copy to Icptl/hz› STA ICPTLZ› LDA ICAX3Z+1› STA ICPTHZ› JMP ?CIRTN2 Return to user›;›; end of normal device open code›;›?POLL› JSR PDOPENPOLL Poll peripheral› JMP ?CIRTN1    for open›;›; -----------------------------›;›;›?CICLOS› LDY #1      ;  Exec close› STY ICSTAZ› JSR ?COMENT compute entry› BCS ?CICLO2 ignore error›;› JSR ?GOHAND to hdlr for cls›;›;›?CICLO2› LDA #$FF    set iocb free› STA ICHIDZ› LDA # >IIN-1 set putbyt to› STA ICPTHZ  point to err› LDA # <IIN-1› STA ICPTLZ› JMP ?CIRTN2 to user›;›; Status/special do implied›; open if req and go to device›;›?CISTSP› LDA ICHIDZ  handler id? opened› CMP #$FF› BNE ?CIST1  yes›;›; iocb free, do implied open›;› JSR ?DEVSRC find dev in tble› BCS ?CIERR4›;›; compute & go to hdlr entry›;›?CIST1› JSR ?COMENT› JSR ?GOHAND›;›; restore handler index›; do implied close›;› LDX ICAX5Z  Recover index› LDA ICHID,X get hdlr id› STA ICHIDZ  restore zpage› JMP ?CIRTN2 return›;›; Execute get command›;›?CIREAD› LDA ICCOMZ  Get cmd› AND ICAX1Z  Is read legal› BNE ?RCI1A  Yes›;› LDY #131    Iocb write only›;›?RCI1B› JMP ?CIRTN1›;›;›;  comp & check entry point›;›?RCI1A› JSR ?COMENT› BCS ?RCI1B›;  get record or characters› LDA ICBLLZ  Single byte get› ORA ICBLLZ+1 or put?› BNE ?RCI3   No›;› JSR ?GOHAND Yes› STA ICAX6Z› JMP ?CIRTN2›;  loop to fill buffer or›;  to end record›;›?RCI3› JSR ?GOHAND to hdlr get› STA ICAX6Z  save byte› BMI ?RCI4   end if error›;› LDY #0› STA (ICBALZ),Y byte to user› JSR ?INCBFP bufr and inc ptr›;› LDA ICCOMZ  Is cmd get› AND #2      record?› BNE ?RCI1   No.›;› LDA ICAX6Z  Check for end› CMP #155    of line› BNE ?RCI1   No›;› JSR ?DECBFL Yes, dec bufrlen› JMP ?RCI4   end transfer›;›; check buffer full›;›?RCI1› JSR ?DECBFL dec length› BNE ?RCI3   cont if non 0›; bufr full rec not ended› LDA ICCOMZ  discard bytes› AND #2      til end record› BNE ?RCI4›; loop to wait for eol›;›?RCI6› JSR ?GOHAND get byte› STA ICAX6Z  save› BMI ?CIREAD.6 go if error›; text record wait for eol› LDA ICAX6Z› CMP #155› BNE ?RCI6›; end record buffer full› LDA #137    Truncated record› STA ICSTAZ›;›;›?CIREAD.6› JSR ?DECPTR› LDY #0› LDA #155› STA (ICBALZ),Y› JSR ?INCBFP›;›; transfer done›;›?RCI4› JSR ?SUBBFL set final› JMP ?CIRTN2 buffer length›;›;›;›?CIWRIT› LDA ICCOMZ  Exec PUT› AND ICAX1Z› BNE ?WCI1A›;› LDY #135    IOCB read only›;›?WCI1B› JMP ?CIRTN1›;›;›;›?WCI1A› JSR ?COMENT› BCS ?WCI1B›;› LDA ICBLLZ  bufrlen=0?› ORA ICBLHZ› BNE ?WCI3   No›;› LDA ICAX6Z  set char› INC ICBLLZ  set len› BNE ?WCI4   transfer 1 byte›; loop to send bytes to hdlr›;›?WCI3› LDY #0› LDA (ICBALZ),Y get byte› STA ICAX6Z  save›;›;›?WCI4› JSR ?GOHAND put byte› PHP› JSR ?INCBFP inc bufr ptr› JSR ?DECBFL dec bufr len› PLP› BMI ?WCI5   end if error›;› LDA ICCOMZ  is cmd putrec?› AND #2› BNE ?WCI1   No›;› LDA ICAX6Z  Got eol?› CMP #155› BEQ ?WCI5   Yes›;›;›?WCI1› LDA ICBLLZ› ORA ICBLHZ› BNE ?WCI3›; bufr empty, record not full› LDA ICCOMZ› AND #2      put bytes?› BNE ?WCI5   yes end›; buffer empty text record› LDA #155    send eol› JSR ?GOHAND›;›;›?WCI5› JSR ?SUBBFL set real len› JMP ?CIRTN2 exit›;›; -------------------------------›; Common exit points›;›?CIRTN1› STY ICSTAZ  Set status into Icstaz›?CIRTN2› LDY ICAX5Z  y=Iocb*$10› LDA ICBAL,Y Leave Icbal/hz set› STA ICBALZ  for devices to match› LDA ICBAH,Y filespec or buffer› STA ICBAHZ  address as applicable›;› LDX #0      for entry caller› STX HNDLOD  Flag no handler?›;›?CIRT3› LDA ICHIDZ,X Copy› STA ICHID,Y  zero page Iocb back› INX          to Iocb› INY› CPX #12› BCC ?CIRT3›;›; Restore a,x to entry values›;› LDA ICAX6Z› LDX ICAX5Z› LDY ICSTAZ  Return status in y› RTS         with s flag valid›;›; -------------------------------›; Place handler entry point-1 for›; desired operation into Icax3/4z›;›; Return c=1 if failed›;›?COMENT› LDY ICHIDZ  Verify device in Hatabs› CPY #34› BCC ?COM1› LDY #133    Flag Iocb not open› BCS ?COM2   and exit with c=1›;›; Place address of device table›; in ICAX3/4Z›;›?COM1› LDA HATABS+1,Y› STA ICAX3Z› LDA HATABS+2,Y› STA ICAX3Z+1›;›; Recover command table index›;› LDY ICCOMT›;›; Now get command offset into device›; table. i.e. 0,2,4,6,8,10›;› LDA ?COMTAB-3,Y› TAY›;›; Get the address-1 from the device›; table. Replace the table address›; in Icax3/4z with the routine›; address-1›;› LDA (ICAX3Z),Y› TAX› INY› LDA (ICAX3Z),Y› STA ICAX3Z+1› STX ICAX3Z› CLC         Flag success›?COM2› RTS›; --------------------------›;›; Decrement buffer length (Icbll/hz)›;›?DECBFL› LDA ICBLLZ› BNE ?DECBF1› DEC ICBLHZ›?DECBF1› DEC ICBLLZ› LDA ICBLLZ  Return Z flag if› ORA ICBLHZ  done› RTS›; --------------------------›;›; Decrement buffer address (Icbal/hz)›;›?DECPTR› LDA ICBALZ› BNE ?DECPT1› DEC ICBAHZ›?DECPT1› DEC ICBALZ› RTS›; --------------------------›;›; Increment buffer address (Icbal/hz)›;›?INCBFP› INC ICBALZ  Increment› BNE ?INCBF1 buffer pointer› INC ICBAHZ›?INCBF1› RTS›; --------------------------›;›; Set final buffer length›; i.e. ›;›?SUBBFL› LDX ICAX5Z› SEC› LDA ICBLL,X› SBC ICBLLZ› STA ICBLLZ› LDA ICBLH,X› SBC ICBLHZ› STA ICBLHZ› RTS›; ----------------------------›; Execute handler routine via›; indirect jmp›;›; Return status in y, Icstaz, s valid›; carry always set›;›?GOHAND› LDY #146    Not implemented default› JSR ?CIJUMP Execute handler command› STY ICSTAZ  Return status› CPY #0      and set s flag for y› RTS›;›?CIJUMP› TAX         Save a› LDA ICAX3Z+1 Push address-1› PHA› LDA ICAX3Z› PHA› TXA         Restore a› LDX ICAX5Z  Set x=Iocb*16› RTS›; ----------------------------›;›; Get the device from the buffer›; address (points to filespec)›;›; Exit with valid number (1-9)›; and index into Hatabs in Ichidz›;›; Return found: c=0›;  device index (ICHIDZ) in a and y›;›; Return not found: c=1›;  a=device name y=130›;›?DEVSRC› SEC         Get device number› LDY #1      and strip Ascii› LDA (ICBALZ),Y plus one.› SBC #'1     If device now› BMI ?DEFAULT less than 0 or› CMP #8+1     more than 8,› BCC ?GOTNUM  it is valid›?DEFAULT› LDA #0      Else make it 0›?GOTNUM› STA ICDNOZ  And then bump back› INC ICDNOZ  to number 1-9› LDY #0      Find device name› LDA (ICBALZ),Y in 1st character›; Following label for external code›ERR130B› BEQ ?CIERR2›;› LDY #33›?DEVS1› CMP HATABS,Y   Search handler table› BEQ ?DEVS2     for device name in a› DEY› DEY› DEY› BPL ?DEVS1›?CIERR2› LDY #130    Unknown device› SEC         return s=1 and c=1› RTS›?DEVS2› TYA         Found device› STA ICHIDZ  save and return› CLC         flag ok› RTS›;›; Table of offsets into device›; table for various vectors.›; Note all commands<9 treated›; as get byte, commands<12›; treated as put byte›;›?COMTAB› .BYTE 0        Open (cmd=3)› .BYTE 4,4,4,4  Get (3<cmd<8)› .BYTE 6,6,6,6  Put (7<cmd<12)› .BYTE 2        Close (cmd=12)› .BYTE 8        Status (cmd=13)› .BYTE 10       Special (cmd=14+)›