%from IMP %include MCODE, FORMATS, Depio, Sysspecs %external %routine Binary Input Empty %alias "3L___binary_input_empty" {This routine reads in the next disc block - TT input is handled elsewhere} {In: R1 = addr(SCB)} {Out: R1 : unchanged} { R2 = address of first character position} %record(SCB Fm) %name S %integer Size, H, A, L %label OK *STR _ R1, S S_Position = S_Position + S_ThisB_Size ; S_ThisB_Size = 0 %signal 9,1 %if S_Flags&SCB Eof Pending # 0 {Read block} H = S_User1 A = S_AllocB_Base L = S_AllocB_Size *MOV _ R0, #4 {a file} *LDR _ R1, H {the handle} *LDR _ R2, A {start address} *LDR _ R3, L {bytes to transfer} *STR _ R9, [Sp, #-4]! *SWI _ Brasil Multiple *LDR _ R9, [Sp], #4 *LDR _ R0, L {bytes requested} *SUB _ R0, R0, R3 {bytes transfered} *MOVVS _ R0, #0 {in case of a trap} *STR _ R0, Size *BCC _ OK S_Flags = S_Flags ! SCB Eof Pending {end of file pending} %signal 9,1 %if Size = 0 {actually true eof now} Ok:{Successful record read, set buffer pointers and return} S_ThisB_Base = S_AllocB_Base S_ThisB_Size = Size S_Next = S_ThisB_Base S_Limit = S_Next+Size *LDR _ R1, S {restore pointer to SCB} *LDR _ R2, [R1] {character pointer, S_Next} %end %external %routine Input Empty %alias "3L___input_empty" {This routine reads in the next disc block - TT input is handled elsewhere} {It converts CR/LF into LF and treats CTRL-Z as end of input} {In: R1 = addr(SCB)} {Out: R1 : unchanged} { R2 = address of first character position} %record(SCB Fm) %name S %integer P, Z, F, N %label L0, L1, L2, L3 *STR _ R1, S Binary Input Empty P = S_Next {first character} Z = S_Limit %signal 9,1 %if Z = P {perhaps not strictly necessary} %constinteger In = R1, {pointer into input buffer} Out = R2, {pointer to output buffer} Base = R3, {start of buffer} Lim = R4, {buffer limit (past last char)} Last = R0, {last character dumped} C = R5 {character holder} *LDR _ Base, P *MOV _ In, Base *MOV _ Out, Base *LDR _ Lim, Z *MOV _ Last, #0 {anything except CR} *STR _ Last, F {EOF flag = 0} L0:*LDRB _ C, [In], #1 {next character} *CMPS _ C, #10 {is it LF?} *BNE _ L1 {no, ->} *CMPS _ Last, #13 {last character CR?} *SUBEQ _ Out, Out, #1 {Yes, overwrite CR with the LF} *BR _ L2 L1:*CMPS _ C, #26 {is it CTRL-Z} *BNE _ L2 {No, ->} *STR _ C, F {EOF flag = #0} *BR _ L3 L2:*MOV _ Last, C {remember the last char in the buffer} *STRB _ C, [Out], #1 {put it in the buffer} *CMPS _ In, Lim *BNE _ L0 {more to process} L3:*STR _ Out, Z {new output limit} S_Flags = S_Flags ! SCB Eof Pending %if F # 0 {end of file pending} S_Limit = Z N = Z-S_Next S_ThisB_Size = N %signal 9,1 %if N = 0 *LDR _ R1, S {restore pointer to SCB} *LDR _ R2, [R1] {character pointer, S_Next} %end