%from IMP %include MCODE, FORMATS, Depio, SysSpecs %externalroutine TT Input Empty %alias "3L___tt_input_empty" %record(SCB Fm) %name S %integer Size, H, A, L %label OK, L1, No *STR _ R1, S S_Position = S_Position + S_ThisB_Size ; S_ThisB_Size = 0 Flush TTY {Flush chain of TTY output SCBs ...} %if Prompt String # "" %start A = Addr(Prompt String) *LDR _ R5, A {address of prompt string} *LDRB _ R9, [R5], #1 {bytes to transfer} L1: *LDRB _ R0, [R5], #1 {pick up the next byte} *CMPS _ R0, #10 {newline?} *SWINE _ Brasil WriteC {no, treat normally} *SWIEQ _ Brasil NewLine {yes, treat specially} *SUBS _ R9, R9, #1 *BGT _ L1 %finish %signal 9,1 %if S_Flags&SCB Eof Pending # 0 {Read block - User1 conventionally ignored for TT input} A = S_AllocB_Base L = S_AllocB_Size *LDR _ R0, A *LDR _ R1, L *MOV _ R2, #0 *MOV _ R3, #255 *SWI _ Brasil ReadLine {The book is all lies. R0 = address of buffer, R1 = bytes transferred} { excluding the terminator} *BCC _ Ok {no escape} {deal with escape - treat as EOF} *MOV _ R0, #124 {124 = clear escape condition} *SWI _ 6 {osbyte} No:S_Flags = S_Flags ! SCB Eof Pending {end of file pending} %signal 9,1 {actually true eof now} Ok:*MOV _ R2, #10 {NL} *STRB _ R2, [R0, R1] {overwrite the CR with NL} *LDRB _ R3, [R0] {first character} *ADD _ R0, R1, #1 {one more} *STR _ R0, Size *CMPS _ R3, #4 {EOT = ^D} *BEQ _ No {signal eof} {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