home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
sourcecode
/
utilities
/
file_view.amos
/
file_view.amosSourceCode
Wrap
AMOS Source Code
|
1990-10-09
|
3KB
|
123 lines
'
' File Viewer
' (c) 1990 Jason D Banks
'
' I know it's far from perfect, but it can handle any standard ascii text.
'
NAME$=Fsel$("","","Enter Name of File","To View")
_GETDATA[NAME$] : LGTH=Param : _LOADFILE[NAME$,LGTH]
Global SIZE,STRT,P_TOP,P_BOT
SIZE=LGTH : STRT=Start(15) : P_TOP=0 : P_BOT=0
_INIT_SCREEN
_INIT_PAGE
DNE=False
While Not DNE
_GET_OPT[Chr$(28)+Chr$(29)+Chr$(30)+Chr$(31)+Chr$(27)] : OPT$=Param$
If OPT$=Chr$(27) Then DNE=True
If OPT$=Chr$(28) Then PAGE_DWN
If OPT$=Chr$(29) Then PAGE_UP
Wend
' Erase 15 : Edit
'
' file is now stored in bank 15
'
Procedure PAGE_DWN
If P_BOT>=SIZE Then Shoot : Pop Proc
Cls 0 : Locate 0,1
P_TOP=P_BOT
LINES=0 : DNE=False : CNT=0 : Cls 0 : Locate 0,1 :
While Not DNE
A=Peek(STRT+P_TOP+CNT)
If A=10 Then Print : Inc LINES Else Print Chr$(A);
Inc CNT
If LINES=20 Then DNE=True
If CNT+P_TOP>SIZE Then DNE=True
Wend
P_BOT=CNT+P_TOP : If P_BOT>SIZE Then P_BOT=SIZE
End Proc
Procedure PAGE_UP
If P_TOP=0 Then Shoot : Pop Proc
_MOVE_UP[20]
LINES=0 : DNE=False : CNT=0 : Cls 0 : Locate 0,1
While Not DNE
A=Peek(STRT+P_TOP+CNT)
If A=10 Then Print : Inc LINES Else Print Chr$(A);
Inc CNT
If LINES=20 Then DNE=True
If CNT+P_TOP>SIZE Then DNE=True
Wend
P_BOT=CNT+P_TOP : If P_BOT>SIZE Then P_BOT=SIZE
End Proc
Procedure _MOVE_UP[NO]
Inc NO
DNE=False : CNT=0
While Not DNE
A=Peek(STRT+P_TOP-CNT)
If A=10 Then Dec NO
Inc CNT
If P_TOP-CNT=0 Then DNE=True
If NO=0 Then DNE=True
Wend
P_TOP=P_TOP-CNT
End Proc
Procedure _GETDATA[NAME$]
Erase 15
Reserve As Work 15,260
Dreg(1)=Varptr(NAME$) : Dreg(2)=-2
HANDLE=Doscall(-84)
If HANDLE=0 Then Pop Proc
Dreg(1)=HANDLE
Dreg(2)=Start(15)
WORKS=Doscall(-102)
If WORKS=0 Then Dreg(1)=HANDLE : DUMMY=Doscall(-90) : Pop Proc
LGTH=Leek(Start(15)+124)
Dreg(1)=HANDLE
DUMMY=Doscall(-90)
Erase 15
' this procedure loads a files information block into bank 15
' and then examines it to find out what it's length is.
' I don't know if this is better than
' OPEN in x,"FILE NAME"
' lgth=LOF(x)
' close X
' but it seems to be a little faster and doesn't take up use of
' the meagre supply of files we've been given.
End Proc[LGTH]
Procedure _LOADFILE[NAME$,LGTH]
Erase 15
Reserve As Work 15,LGTH
Dreg(1)=Varptr(NAME$)
Dreg(2)=1005
HANDLE=Doscall(-30)
' = open file for reading
Dreg(1)=HANDLE
Dreg(2)=Start(15)
Dreg(3)=LGTH
RDIN=Doscall(-42)
' = read in file contents
Dreg(1)=HANDLE
DUMMY=Doscall(-36)
' = close file down
' this proc loads a file into bank 15, given it's name and length
' to get the length, just use the _GETDATA proc.
End Proc
Procedure _INIT_PAGE
LINES=0 : DNE=False : CNT=0 : Cls 0 : Locate 0,1 :
While Not DNE
A=Peek(STRT+P_TOP+CNT)
If A=10 Then Print : Inc LINES Else Print Chr$(A);
Inc CNT
If LINES=20 Then DNE=True
If CNT>SIZE Then DNE=True
Wend
P_BOT=CNT
End Proc
Procedure _INIT_SCREEN
Screen Open 0,640,256,4,Hires
Curs Off : Flash Off : Pen 1 : Paper 0 : Palette Colour(1),0
Cls 0
End Proc
Procedure _GET_OPT[TEST$]
TEST$=Upper$(TEST$)
While Instr(TEST$,OUT$)<1 : OUT$=Upper$(Inkey$) : Wend
End Proc[OUT$]