hreodwrit/hreodwrit.baz

125 lines
2.8 KiB
Plaintext
Raw Normal View History

2019-01-17 00:00:00 +00:00
rem //////////////////////////////////////////////////////////
2019-01-14 03:45:46 +00:00
rem Program: Hreodwrit - A writing pen
rem Author: Bill Chatfield
rem License: GPL2
rem //////////////////////////////////////////////////////////
section variables
dim b$(500) { Editing buffer }
d$=chr$(4)
2019-01-17 00:00:00 +00:00
f${nameOfFileInEditor}=""
lc{lineCount}=0
ml{maxLines}=500
mc{maxColumns}=255
cx{currentScreenX}=1
cy{currentScreenY}=1
cl{currentLineInFile}=1
cc{currentColumnInFile}=1
sw{screenWidth}=40
sh{screenHeight}=24
bm{bufferModified}=0
oa{openApple}=0
2019-01-14 03:45:46 +00:00
closesection
section splash
2019-01-17 00:00:00 +00:00
text
2019-01-14 03:45:46 +00:00
print "Hreodwrit - A writing pen"
print "Copyright (c) 2019 Bill Chatfield"
2019-01-15 03:37:43 +00:00
print "Distributed under the GPLv2"
2019-01-14 03:45:46 +00:00
closesection
section main
2019-01-15 03:37:43 +00:00
gosub @openFile
2019-01-17 00:00:00 +00:00
gosub @display
£eventLoop
# Check open apple and closed apple keys
get k$
if peek(49249) > 127 then goto @openApplePressed
if asc(k$) = 3 then gosub @copyText
£openApplePressed
if k$ = "s" then gosub @saveFile
goto @eventLoop
2019-01-15 03:37:43 +00:00
2019-01-17 00:00:00 +00:00
£atExit
if bm{bufferModified} = 0 then goto @exit
print "Save file ";f${nameOfFileInEditor};"? (Y/N) ";
get k$
print k$
if k$ = "y" or k$ = "Y" then gosub @saveFile
£exit
end
2019-01-14 03:45:46 +00:00
closesection
£openFile
print "File:";
input f$
2019-01-17 00:00:00 +00:00
if f$ = "" then return
2019-01-14 03:45:46 +00:00
print d$;"open";f$
print d$;"read";f$
2019-01-15 03:37:43 +00:00
lc{lineCount}=0
2019-01-14 03:45:46 +00:00
on err goto @errorHandler
£readLineLoop
2019-01-17 00:00:00 +00:00
if lc{lineCount} < ml{maxLines} then goto @addLine
print "File too large: ";f${nameOfFileInEditor}
print d$;"close";f$
end
£addLine
2019-01-15 03:37:43 +00:00
lc{lineCount}=lc{lineCount}+1
input b$(lc{lineCount})
2019-01-14 03:45:46 +00:00
goto @readLineLoop
£errorHandler
poke 216,0 { Turn off error handler }
e = peek(222) { Get the error code }
print d$;"close";f$ { Close the open file }
if e < > 5 then goto @die { 5 is the expected EOF }
return
2019-01-15 03:37:43 +00:00
£saveFile
print d$;"open";f$
print d$;"write";f$
on err goto @errorHandler
for i = 1 to lc{lineCount}
print b$(i)
next
£errorHandler
poke 216,0 { Turn off error handler }
e = peek(222) { Get the error code }
print d$;"close";f$ { Close the open file }
goto @die
return
£saveAsFile
print "File:";
input f$
print d$;"open";f$
print d$;"write";f$
on err goto @errorHandler
for i = 1 to lc{lineCount}
print b$(i)
next
£errorHandler
poke 216,0 { Turn off error handler }
e = peek(222) { Get the error code }
print d$;"close";f$ { Close the open file }
goto @die
return
£display
home
for i = 1 to 24
print b$(i)
next
return
2019-01-14 03:45:46 +00:00
£die
print "Error ";e
end