rem *----------------------------------------------*
rem *		SCREEN COMMANDS ROUTINES	   *
rem *		------------------------	   *
rem *	   FROM: CBASIC USER GUIDE		   *
rem *	     BY: Osborne, Eubanks, McNiff	   *
rem *	   DATE: December 15, 1982		   *
rem *	VERSION: 1.25				   *
rem *----------------------------------------------*

500 rem ......screen commands routines..............

    def fn.mod%(j%,i%)
      a% = j% - int%( (j%-1)/i% ) * i%
      fn.mod% = a%
    RETURN
    fend

rem ******************* define constants *******************************

home$  = chr$(30)              :     \ move cursor to column 1, row 1
clear$ = chr$(26)              :     \ clear screen, home cursor
up$    = chr$(11)              :     \ move cursor up 1 row
down$  = chr$(10)              :     \ move cursor down one row
cr$    = chr$(13)              :     \ carriage return without line feed
rht$   = chr$(12)              :     \ move cursor right one space
lft$   = chr$(8)               :     \ move cursor left one position
bell$  = chr$(7)               :     \ ring bell
line%  = 60

rem ... printer control ...

newpage$ = chr$(12)
small.print$ = chr$(29)

rem .....the following cursor movement string characters are defined at 
rem .....the start of the program to be used by all modules
rem ******************** initialize string variables ********************

bl$ = " "
for j% = 1 to 7
  bl$ = bl$ + bl$
next j%

movr$ = rht$
for j% = 1 to 7
  movr$ = movr$ + movr$
next j%

movu$ = up$
for j% = 1 to 6
  movu$ = movu$ + movu$
next j%

movd$ = down$
for j% = 1 to 6
  movd$ = movd$ + movd$
next j%

rem ******************** define functions ****************************

def fn.up$(i%) = left$(movu$,i% * len(up$))

def fn.down$(i%) = left$(movd$,i% * len(down$))

def fn.right$(i%) 
    print up$
    fn.right$ = left$(movr$,(i%-1) * len(rht$))
    return
fend

def fn.line$(i%)
    fn.line$ = home$ + \
               fn.down$(i%-1)
    return
fend

def fn.clear$(first%,last%)
    fn.clear$ = fn.right$(first%-1) + \
                left$(bl$,last%-first%+1)
    return
fend

def fn.entry$(row%,col%,prompt$,linep%,colp%)


rem ... prints a prompt in the comment section of the display at 
rem ...   line linp%, column colp%
rem ... moves the cursor up row% rows and over to column col%
rem ...   to print a question mark and receive input

    print fn.line$(linep%) ; fn.clear$(colp%,line%) ;   \ write prompt
          bell$; fn.right$(colp%); prompt$          ;   \
          fn.up$(row%) ;                         \ position cursor
          fn.clear$(col%,line%); fn.right$(col%);
    input temp$
    fn.entry$ = temp$
    return
fend

rem ---------------------------- end of utility routines ---------------
