;---------------------------------------
; MORE - Display file          11/7/1991
; Last ammendment: 14/7/1991
;---------------------------------------
; Flags:
;       L -- Line wrap off
;       c -- Clear screen (page)
;---------------------------------------
         *= $6000

tty      = $0830

openfnum = $0906
close    = $0909
chrout   = $090c
chrin    = $090f
nounstart = $101b
nounlen  = $1021
opstdout = $1026
opstdin  = $1029
stdwrite = $102c
stdread  = $102f
clostdout = $1032
clostdin = $1035
writestr = $1038

stderr   = $06
nountick = $59
buffer   = $0840
stdinum  = $63
stdonum  = $61
stdomode = $62

flagchk  = $101e
decout   = $1012

;---------------------------------------
         lda stdonum
         cmp tty
         beq *+5
         jmp badout

         jsr opstdin
         bcc *+5
         jmp exit
         jsr opstdout
         bcs *-5

         lda #0
         sta lines
         sta xx

         lda #76  ;"L" line wrap off
         jsr flagchk
         bcs *+5
         lda #0
         .byte $2c
         lda #1
         sta wrap

         lda #99 ;"c"
         jsr flagchk
         bcc *+5
         lda #0
         .byte $2c
         lda #1
         sta cls

;---------------------------------------

main     jsr chkclr
         jsr linput
         bcc main1
         jmp exit

main1    jsr printline
         bcc main
         jmp exit0

;---------------------------------------
chkclr   lda lines
         bne clr1
         lda cls
         beq clr1
         lda #147
         jmp $ffd2
clr1     rts

;---------------------------------------
linput   ldy #0
         sty strlen

input1   jsr stdread
         bcs lexit
         ldy strlen
         sta string,y
         inc strlen
         cmp #13
         bne input1
         clc
lexit    rts

;---------------------------------------
printline
         ldy #0
         ldx strlen
         lda wrap
         bne pbran1
         cpx #40
         bcc *+4
         ldx #40

pbran1   cpx #0
         beq pexit
         lda string,y
         jsr ascout
         iny
         cpy #41
         bne pbran2
         lda wrap
         bne pbran2
         inc lines

pbran2   dex
         bne pbran1

         inc lines
         ldy lines
         cpy #22
         bcc pexit
         jmp keypause

pexit    rts

;---------------------------------------
keypause ldy #0
         sty lines
loop2    lda pausetxt,y
         jsr ascout
         iny
         cpy #10
         bne loop2
loop3    jsr $ffe4
         cmp #3
         beq keybreak
         cmp #32
         bne loop3
         clc

keybreak php
         lda #32
         ldy #10
loop4    lda pausetxt,y
         jsr ascout
         iny
         cpy #18
         bne loop4
         plp
         rts

;---------------------------------------
ascout   stx tmp1
         ldx stdonum
         jsr chrout
         ldx tmp1
         rts

;---------------------------------------
exit0    lda #12
exit     pha
         jsr clostdin
         jsr clostdout
         pla
         cmp #12
         bne badexit
         lda #0
         clc
         rts

badout   ldx stderr  ;tty not output
         jsr writestr
         .word nountxt

badex1   lda #24        ;Failed
badexit  sec
         rts
;---------------------------------------

nountxt  .text "Not console output_"
pausetxt .byte 18,123
         .text "more"
         .byte 125,146,145,13
         .text "      "
         .byte 13,145


wrap     .byte 0
lines    .byte 0
xx       .byte 0
strlen   .byte 0
tmp1     .byte 0
cls      .byte 0

string   = (*/256)*256+256


