home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
601-625
/
apd602
/
file_editor.amos
/
file_editor.amosSourceCode
< prev
next >
Wrap
AMOS Source Code
|
1993-02-25
|
14KB
|
503 lines
'
' Filename: FileEd.AMOS
'
' Date: 23/05/92 Version: 1.32
'
' By: Tony Swanwick
'
'***************************************************************************
'
' This program is AMOS Public Domain.
'
'***************************************************************************
'
'
Set Buffer 100 : Dim PK(1,1000)
Global A,SX,SY,K$,BE,BF,BL,BP,BS,CB,CF,OCF,CX,CY,DEBUG,PK,LINE$,F$
Global NB,PB,PF,PK(),X0,Y0,X1,Y1,MSB
Global PIC$,VERSION$,FILEBANK,SCRNBANK,SHAPEBANK
Global EDSCRN,TEMPSCRN,PNTER,CROSS,CLOCK,BLACK,WHITE,BLUE,RED
'
VERSION$="1.32"
Goto L_COLD_START
'
L_LOOP:
P_SCREEN_XY
If Mouse Key=1 Then Goto L_KEY
If K$="" Then K$=Inkey$
If K$<>"" Then Goto L_KEYS
If BF<1 Then Goto L_LOOP
'
If Mouse Key=0 and CF=0 Then P_BOB_XY
P_CURSOR_FLASH
Goto L_LOOP
'
L_KEY:
If SX<19 and SY>0 and SY<11 Then SY=100 : P_EXIT
If SX>617 and SY>0 and SY<11 Then SY=100 : P_WORKBENCH
If BF<1 Then Goto L_LOOP
If SX>77 and SY>27 and SX<599 and SY<170 Then P_CURS_XY
If SX>607 and SY>25 and SX<633 and SY<172 Then SX=-1 : P_BAR_POSITION
If SX>613 and SY>15 and SX<625 and SY<23 Then SX=-1 : P_BLOCK_PREVIOUS
If SX>613 and SY>173 and SX<625 and SY<181 Then SX=-1 : P_BLOCK_NEXT
If SX>265 and SY>177 and SX<315 and SY<191 Then SY=100 : P_FIRST
If SX>317 and SY>177 and SX<363 and SY<191 Then SY=100 : P_UNDO
If SX>365 and SY>177 and SX<409 and SY<191 Then SY=100 : P_LAST
If SY<26 Then P_LINE_PREVIOUS
If SY>171 Then P_LINE_NEXT
MSB=1
Goto L_LOOP
'
L_KEYS:
S=Scancode : Clear Key : If DEBUG=1 Then Text 26,10,Str$(S)+" "
If S=69 Then P_EXIT
If BF<1 Then K$="" : Goto L_LOOP
If S<68 Then Goto L_TEXT_LEFT
If S=76 Then P_CURS_UP
If S=77 Then P_CURS_DOWN
If S=78 Then P_CURS_RIGHT
If S=79 Then P_CURS_LEFT
MSB=1 : P_QUICK_STATUS
Wait 1 : K$=Inkey$ : If K$<>"" Then Goto L_KEYS
Goto L_LOOP
'
L_TEXT_LEFT:
If OCF=2 Then Goto L_TEXT_RIGHT
A=Asc(Upper$(K$)) : If(A<65 or A>70) and(A<48 or A>57) Then Goto L_NULL
If A>64 Then A=A-55 Else A=A-48
PK=Peek(BS+CB)
If MSB=1
A=A*16 : PK=(PK and $F)+A : MSB=0
Else
PK=(PK and $F0)+A : MSB=1
End If : A=PK : PK=BS+CB : P_POKE
PK=BS+BP+(CY*16) : P_PEEK_LINE
Bob Off : Wait Vbl : Ink WHITE,BLACK : Text 5,34+(CY*9),LINE$ : K$=""
If MSB=1 Then P_CURS_RIGHT
P_BOB_XY
K$="" : P_QUICK_STATUS
Goto L_LOOP
'
L_NULL:
K$="" : MSB=1 : P_CURS_RIGHT
P_QUICK_STATUS
Goto L_LOOP
'
L_TEXT_RIGHT:
A=Asc(K$) : PK=BS+CB : P_POKE
PK=BS+BP+(CY*16) : P_PEEK_LINE
Bob Off : Wait Vbl : Ink WHITE,BLACK : Text 5,34+(CY*9),LINE$ : K$=""
OCX=CX : Inc CX : A=BL-BP-CX-(CY*16) : If A<1 Then CX=OCX
If CX>15 Then CX=0 : OCY=CY : Inc CY
A=BL-BP-CX-(CY*16) : If A<1 Then CY=OCY
If CY>15 Then CY=15 : P_LINE_NEXT
P_BOB_XY
K$="" : P_QUICK_STATUS
Goto L_LOOP
'
' ***** Fast Procedures *****
'
Procedure P_BOB_XY
CF=OCF : Wait Vbl : Bob 1,73+(CX*24),26+(CY*9),1 : Bob 2,467+(CX*8),26+(CY*9),2
End Proc
Procedure P_CLEAR_LIST
Screen EDSCRN : Bob Off : CF=0 : Wait Vbl : Ink BLACK : Bar 4,26 To 598,171
End Proc
Procedure P_COPY_LOAD
If CF>0 Then Bob Off : Wait Vbl : CF=0
Screen Copy TEMPSCRN,0,0,594,145 To EDSCRN,5,26
End Proc
Procedure P_COPY_SAVE
If CF>0 Then Bob Off : Wait Vbl : CF=0
Screen Copy EDSCRN,5,26,599,171 To TEMPSCRN,0,0
End Proc
Procedure P_CURSOR_FLASH
Timer=0 : A$="" : T=6 : If OCF=1
Bob Off 1
While Timer<T and Mouse Key=0 and(A$="") : A$=Inkey$ : Wend
Timer=0 : Bob 1,73+(CX*24),26+(CY*9),1
While Timer<T and Mouse Key=0 and(A$="") : A$=Inkey$ : Wend
Else
Bob Off 2
While Timer<T and Mouse Key=0 and(A$="") : A$=Inkey$ : Wend
Timer=0 : Bob 2,467+(CX*8),26+(CY*9),2
While Timer<T and Mouse Key=0 and(A$="") : A$=Inkey$ : Wend
End If : If A$<>"" Then K$=A$
End Proc
Procedure P_CURS_XY
If BF=0 Then Pop Proc
OCX=CX : OCY=CY
If SX<462
CX=(SX-74)/24 : CY=(SY-28)/9 : CF=1
Else
CX=(SX-470)/8 : CY=(SY-28)/9 : CF=2
End If
If CX<0 Then CX=0
If CX>15 Then CX=15
If CY<0 Then CY=0
If CY>15 Then CY=15
A=BL-BP-CX-(CY*16) : If A<1 Then CX=OCX : CY=OCY
OCF=CF : P_BOB_XY
P_QUICK_STATUS
End Proc
Procedure P_PEEK_LINE
T$=" " : LINE$=Right$(("00000000"+(Hex$(PK-BS)-"$")),7)+" "
For B=PK To PK+15
A=Peek(B) : H$=Right$(("0"+(Hex$(A)-"$")),2) : If A<32 or A>127 Then A=32
If B>BE Then H$="--" : A=127
LINE$=LINE$+H$+" " : T$=T$+Chr$(A)
Next B : LINE$=LINE$+T$
End Proc
Procedure P_POKE
Inc PF : If PF>1000 Then PF=0
PK(0,PF)=PK : PK(1,PF)=Peek(PK) : Poke PK,A
End Proc
Procedure P_SCREEN_XY
SX=X Screen(EDSCRN,X Mouse) : SY=Y Screen(EDSCRN,Y Mouse) : If DEBUG=0 Then Pop Proc
Ink WHITE,BLACK : X=462 : Y=182 : A$=" SX="+Str$(SX)+" " : Text X,Y,A$
A$=" SY="+Str$(SY)+" " : Text X,Y+9,A$
End Proc
Procedure P_SCROLL_BAR
If BF<1 Then Pop Proc
X0=608 : Y0=26 : X1=632 : Y1=171 : YL=Y1-Y0+1
Ink BLACK : Bar X0,Y0 To X1,Y1 : B=256*(1+((BL-1)/256))
A=Y0 : Y0=A+((YL*BP)/B) : Y1=A+((YL*(BP+255))/B)
Ink WHITE : If Y0<>Y1
Bar X0,Y0 To X1,Y1
Else
Draw X0,Y0 To X1,Y1
End If
End Proc
Procedure P_QUICK_STATUS
Ink WHITE,BLUE : Text 90,192,Space$(9) : Text 550,19,Space$(7)
If BF>0
CB=BP+CX+(CY*16)
Ink WHITE,BLACK : Text 90,192,Str$(PB)+" " : Text 550,19,Str$(CB)-" "
End If
End Proc
Procedure P_WRITE_LINES
Screen TEMPSCRN : Cls 0 : Ink WHITE,BLACK : X=0 : Y=8 : IY=9 : IL=16
For L=BS+BP To(BS+BP+(15*IL)) Step IL
PK=L : P_PEEK_LINE
Text X,Y,LINE$ : Y=Y+IY
Next L : Screen EDSCRN : P_COPY_LOAD
End Proc
'
' ***** Key Procedures *****
'
'
Procedure P_CURS_DOWN
OCY=CY : Inc CY : A=BL-BP-CX-(CY*16) : If A<1 Then CY=OCY
If CY>15 Then CY=15 : P_LINE_NEXT
P_BOB_XY
End Proc
Procedure P_CURS_LEFT
S=(Key Shift and 3) : If S>0 Then CF=1 : OCF=1 : Pop Proc
If CB=0 Then Pop Proc
Dec CX : If CX<0 Then CX=15 : Dec CY
If CY<0 Then CY=0 : P_LINE_PREVIOUS
P_BOB_XY
End Proc
Procedure P_CURS_RIGHT
S=(Key Shift and 3) : If S>0 Then CF=2 : OCF=2 : Pop Proc
OCX=CX : Inc CX : A=BL-BP-CX-(CY*16) : If A<1 Then CX=OCX
If CX>15 Then CX=0 : OCY=CY : Inc CY
A=BL-BP-CX-(CY*16) : If A<1 Then CY=OCY
If CY>15 Then CY=15 : P_LINE_NEXT
P_BOB_XY
End Proc
Procedure P_CURS_UP
If CB=0 Then Pop Proc
Dec CY : If CY<0 Then CY=0 : P_LINE_PREVIOUS
P_BOB_XY
End Proc
'
' ***** Menu Procedures *****
'
Procedure P_DISK
C=Choice(2) : A=Free
If C=4 Then P_EXIT
On C Proc P_DISK_LOAD,P_DISK_SAVE,P_DISK_SAVE_AS,P_NULL
On Menu On : P_MOUSE_UP
End Proc
Procedure P_DISK_LOAD
F$=Fsel$("","","Load Disk File","")
If F$="" Then Pop Proc
If Exist(F$)=0 Then Bell : Pop Proc
'
Bob Off : Change Mouse CLOCK : P_CLEAR_LIST
Ink WHITE,BLACK : Locate 0,13 : Centre "Loading <"+F$+"> "
Open In 1,F$ : BL=Lof(1) : Close 1
B=FILEBANK : Erase B : Reserve As Data B,BL
BF=1 : PB=1 : NB=1+((BL-1)/256)
P_STATUS
Bload F$,B : BS=Start(B) : BE=BS+BL-1
'
BP=0 : CB=0 : CF=0 : CX=0 : CY=0 : P_WRITE_LINES
P_SCROLL_BAR
Change Mouse PNTER
End Proc
Procedure P_DISK_SAVE
If BF<1 Then Bell : Pop Proc
Change Mouse CLOCK : P_CLEAR_LIST
Ink WHITE,BLACK : Locate 0,13 : Centre "Saving <"+F$+"> "
Bsave F$,BS To BS+BL : P_WRITE_LINES
Change Mouse PNTER
End Proc
Procedure P_DISK_SAVE_AS
If BF<1 Then Bell : Pop Proc
N$=Fsel$("","","Save File As...","")
If N$="" Then Pop Proc
F$=N$ : Change Mouse CLOCK : P_CLEAR_LIST
Ink WHITE,BLACK : Locate 0,13 : Centre "Saving <"+F$+"> "
Bsave F$,BS To BS+BL : P_WRITE_LINES
Change Mouse PNTER
End Proc
Procedure P_SEARCH
C=Choice(2) : A=Free
On C Proc P_TEXT,P_NULL
On Menu On
End Proc
Procedure P_TEXT
If BF<1 Then Pop Proc
P_COPY_SAVE
P_CLEAR_LIST
X Mouse=294 : Y Mouse=168
Locate 10,12 : Input "Enter text string for search ? ";A$
Change Mouse CLOCK : F=Hunt(BS To BS+BL-1,A$)
If F=0
Curs Off : Bell : P_COPY_LOAD
Else
PB=F-BS : BP=(PB/16)*16 : P_WRITE_LINES
CY=(PB-BP)/16 : CX=PB-BP-(CY*16)
P_SCROLL_BAR
End If
Change Mouse PNTER : P_BOB_XY
End Proc
Procedure P_SETUP
C=Choice(2) : A=Free
On C Proc P_DEBUG,P_RESET
On Menu On
End Proc
Procedure P_DEBUG
DEBUG=1
End Proc
Procedure P_OPEN_MENU
Pen WHITE : Paper BLACK : Menu Del
'
M=1 : I=1
Menu$(M)=" "
'
M=2 : I=1
Menu$(M)=" Disk "
Menu$(M,I)=" Load File " : Inc I
Menu$(M,I)=" Save This " : Inc I
Menu$(M,I)=" Save File As " : Inc I
Menu$(M,I)=" Quit " : Inc I
'
M=3 : I=1
Menu$(M)=" Search "
Menu$(M,I)=" Text String " : Inc I
'
M=4 : I=1
Menu$(M)=" SetUp "
Menu$(M,I)=" Debug ON " : Inc I
Menu$(M,I)=" Reset All " : Inc I
'
Menu On
End Proc
'
' ***** Procedures *****
'
Procedure P_BAR_POSITION
If BF<1 Then Bell : Wait 20 : Pop Proc
Y0=26 : Y1=171 : YL=Y1-Y0+1 : Y=SY-Y0+1
BP=256*(((Y*BL)/YL)/256)
PB=1+(BP/256) : P_STATUS
P_SCROLL_BAR
P_WRITE_LINES
End Proc
Procedure P_BLOCK_NEXT
If BF<1 Then Bell : Wait 20 : Pop Proc
If BP>=BL-256 Then Bell : Wait 20 : Pop Proc
A=BP+256 : If A<BE Then BP=A Else Pop Proc
PB=1+(BP/256) : P_STATUS
P_SCROLL_BAR
P_WRITE_LINES
End Proc
Procedure P_BLOCK_PREVIOUS
If BF<1 Then Bell : Wait 20 : Pop Proc
If BP<1 Then Bell : Wait 20 : Pop Proc
BP=BP-256 : If BP<0 Then BP=0
PB=1+(BP/256) : P_STATUS
P_SCROLL_BAR
P_WRITE_LINES
End Proc
Procedure P_CLOSE_SCREENS
While Screen>-1
Screen Close Screen
Wend
Bob Off : Close Editor : Hide On : Wait Vbl
End Proc
Procedure P_FIRST
If BF<1 Then Bell : Wait 20 : Pop Proc
Change Mouse CLOCK : PB=1 : BP=0 : P_SCROLL_BAR
P_WRITE_LINES
CX=0 : CY=0 : CF=0 : P_STATUS
Change Mouse PNTER
End Proc
Procedure P_LAST
If BF<1 Then Bell : Wait 20 : Pop Proc
Change Mouse CLOCK
A=(BL-1)/256 : BP=A*256
PB=1+A : P_SCROLL_BAR
P_WRITE_LINES
CY=(BL-BP)/16 : CX=BL-BP-(CY*16)-1 : CF=0
If CX<0 Then CX=15 : CY=CY-1
P_STATUS
Change Mouse PNTER
End Proc
Procedure P_LINE_NEXT
If BF<1 Then Bell : Wait 20 : Pop Proc
If BP>=BL-256 Then Bell : Wait 20 : Pop Proc
A=BP+16 : If A<BE Then BP=A Else Pop Proc
PB=1+(BP/256) : P_QUICK_STATUS
P_SCROLL_BAR
P_COPY_SAVE
Screen Copy TEMPSCRN,0,9,594,145 To EDSCRN,5,26
'
PK=BS+BP+240 : P_PEEK_LINE
Ink WHITE,BLACK : Text 5,169,LINE$
End Proc
Procedure P_LINE_PREVIOUS
If BF<1 Then Bell : Wait 20 : Pop Proc
If BP<1 Then Bell : Wait 20 : Pop Proc
BP=BP-16 : If BP<0 Then BP=0
PB=1+(BP/256) : P_QUICK_STATUS
P_SCROLL_BAR
P_COPY_SAVE
Screen Copy TEMPSCRN,0,0,594,136 To EDSCRN,5,35
'
PK=BS+BP : P_PEEK_LINE
Ink WHITE,BLACK : Text 5,34,LINE$
End Proc
Procedure P_MOUSE_UP
While Mouse Key<>0 : Wend
If BF>0 Then P_WRITE_LINES
End Proc
Procedure P_NULL
End Proc
Procedure P_OPEN_SCREENS
PIC$="df0:FileEd.IFF" : If Exist(PIC$)=0 Then PIC$="df1:FileEd.IFF"
If Length(SCRNBANK)>0
Unpack SCRNBANK To EDSCRN
Else
Load Iff PIC$,EDSCRN : Flash Off : Curs Off
Spack EDSCRN To SCRNBANK
End If
BLACK=0 : WHITE=1 : BLUE=2 : RED=3
Ink WHITE,BLUE : Text 284,10,"FileEd V"+VERSION$
Screen Open TEMPSCRN,640,256,2,Hires : Flash Off : Curs Off : Screen Hide TEMPSCRN
Screen EDSCRN : P_CLEAR_LIST
SHAPE$="df0:FileEd.abk" : If Exist(SHAPE$)=0 Then SHAPE$="df1:FileEd.abk"
If Length(SHAPEBANK)=0
Load SHAPE$,SHAPEBANK
End If
A$="Start by loading a file using the MENU."
Locate 0,12 : Pen WHITE : Paper BLACK : Centre A$
Set Bob 1,0,%111111,%11001010 : Set Bob 2,0,%111111,%11001010 : Make Mask
End Proc
Procedure P_RESET
BF=0 : BL=0 : CB=0 : CF=0 : OCF=2 : EDSCRN=0 : TEMPSCRN=1 : F$=""
MSB=1 : DEBUG=0 : PF=-1
SHAPEBANK=1 : FILEBANK=2 : SCRNBANK=3
P_CLOSE_SCREENS
P_OPEN_SCREENS
P_OPEN_MENU
P_STATUS
Limit Mouse 128,50 To 444,235
On Menu Proc P_NULL,P_DISK,P_SEARCH,P_SETUP
On Menu On : Change Mouse PNTER
X Mouse=288 : Y Mouse=160 : Show On
End Proc
Procedure P_STATUS
Screen EDSCRN : Ink WHITE,BLUE : Text 80,21,Space$(50)
If F$<>"" Then Ink WHITE,BLACK : Text 80,21," "+F$+" "
'
Ink WHITE,BLUE : Text 550,10,Space$(7) : Text 550,19,Space$(7)
Text 90,181,Space$(9) : Text 90,192,Space$(9)
If BF>0
CB=BP+CX+(CY*16)
Ink WHITE,BLACK : Text 550,10,Str$(BL)-" " : Text 550,19,Str$(CB)-" "
Text 90,181,Str$(NB)+" "
Text 90,192,Str$(PB)+" "
End If
End Proc
Procedure P_UNDO
If PF=-1 Then Pop Proc
PK=PK(0,PF) : A=PK(1,PF) : If PK=0 Then Pop Proc
PK(0,PF)=0 : PK(1,PF)=0
Poke PK,A : Dec PF : If PF<0 Then PF=-1 : If PK(0,1000)>0 Then PF=1000
'
Change Mouse CLOCK : PB=PK-BS
CY=(PB-BP)/16 : CX=PB-BP-(CY*16) : OCF=2
If PB<BP or PB>BP+255
BP=(PB/16)*16 : P_WRITE_LINES
CY=(PB-BP)/16 : CX=PB-BP-(CY*16)
P_SCROLL_BAR
Else
PK=BS+BP+(CY*16) : P_PEEK_LINE
Bob Off : Wait Vbl : Ink WHITE,BLACK : Text 5,34+(CY*9),LINE$ : K$=""
End If
If CX<0 Then CX=15 : CY=CY-1
P_BOB_XY
P_QUICK_STATUS
Change Mouse PNTER
End Proc
Procedure P_WORKBENCH
Amos To Back
While Amos Here=0
Multi Wait
Wend
End Proc
'
'
'
L_COLD_START:
PNTER=1 : CROSS=2 : CLOCK=3
P_RESET
Goto L_LOOP
' Break Off
'
Goto L_LOOP
'
Procedure P_EXIT
Erase FILEBANK
Default : Edit
End Proc
'
' Variable:
'
' A Any
' BE Bank end address
' BF Bank Flag, BF=0 Empty
' BL Bank length
' BP Block Bite pointer
' BS Bank start address
' CB Current bite
' CF Cursor flag
' CX,CY Cursor x,y
' FILEBANK Mem bank used for temp file
' F$ Filespec string
' LINE$ Peeked line string
' MSB Edit MSB flag
' NB No. 256 Bite Blocks
' OCF Old cursor flag
' PB Present Bite block pointer
' PF Poke array pointer
' PK Peek address pointer
' PK() Poked to array
' SCRNBANK Mem bank used for packed screen
' SHAPEBANK Mem bank used for bobs
' SX,SY Mouse x,y
'