Skip to content

Commit 10b145b

Browse files
committed
Factorize new file creation and default filename on the editor.
1 parent d53505a commit 10b145b

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

src/editor.bas

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ OldMargin = PEEK(@@LMARGN)
4343
FileName$ = "D:HELP.TXT"
4444

4545
' MemStart: the start of available memory, used as a buffer for the file data
46+
' MemEnd: pointer to the end of the buffer.
4647
dim MemStart(-1) byte
47-
' MemEnd: the end of the current file, initialized to MemStart.
48-
MemEnd = Adr(MemStart)
4948

5049
' NOTE: variables already are initialized to '0' in the runtime.
5150
' topLine: Line at the top of the screen
@@ -65,14 +64,30 @@ MemEnd = Adr(MemStart)
6564
' Loads initial file, and change the filename
6665
exec InitScreen
6766
exec LoadFile
68-
FileName$ ="D:"
67+
exec DefaultFileName
6968

7069
' escape = 0 ' already initialized to 0
7170
do
7271
' Key reading loop
7372
exec ProcessKeys
7473
loop
7574

75+
'-------------------------------------
76+
' Sets FileName$ to the default drive
77+
'
78+
proc DefaultFileName
79+
FileName$="D:"
80+
endproc
81+
82+
83+
'-------------------------------------
84+
' Starts the editor with an empty file
85+
'
86+
proc NewFile
87+
exec DefaultFileName
88+
MemEnd = Adr(MemStart)
89+
exec RedrawNewFile
90+
endproc
7691

7792
'-------------------------------------
7893
' Clears top line to show a message
@@ -532,7 +547,6 @@ ENDPROC
532547
'
533548
PROC LoadFile
534549

535-
MemEnd = adr(MemStart)
536550
open #1, 4, 0, FileName$
537551
if err() = 1
538552
bget #1, Adr(MemStart), dpeek(@MEMTOP) - Adr(MemStart)
@@ -542,9 +556,12 @@ PROC LoadFile
542556
if err() = 136
543557
MemEnd = dpeek($358) + adr(MemStart)
544558
else
559+
' Load error, we show the error to the user
560+
' and restart with an empty file
545561
exec FileError
562+
exec NewFile
563+
exit
546564
endif
547-
close #1
548565

549566
exec RedrawNewFile
550567
ENDPROC
@@ -553,6 +570,7 @@ ENDPROC
553570
' Redraw screen after new file
554571
'
555572
PROC RedrawNewFile
573+
close #1
556574
fileSaved = 1
557575
column = 0
558576
topLine = 0
@@ -991,9 +1009,7 @@ PROC ProcessKeys
9911009
elif key = $0E
9921010
exec AskSaveFileChanged
9931011
if not key
994-
FileName$="D:"
995-
MemEnd = Adr(MemStart)
996-
exec RedrawNewFile
1012+
exec NewFile
9971013
endif
9981014
'
9991015
'--------- Control-L (load) -----
@@ -1047,7 +1063,7 @@ PROC SaveCompiledFile
10471063

10481064
' Save original filename
10491065
move Adr(FileName$), EditBuf, 128
1050-
poke Len(FileName$) + Adr(FileName$), $58
1066+
exec DefaultFileName
10511067

10521068
? "Name";
10531069
exec InputFileName

0 commit comments

Comments
 (0)