Download QLUB ISSUE 4

Transcript
QLUBNews
23
the use of some of these routines, we'll
write a short program to copy a named
file to the screen. We'll write it in such a
way that it will run as an independant job,
or multi-tasking program. It uses a lot of
the vectored utilities and TRAP #3 routines
we've discussed here.
·
The code starting at the BEGIN label
opens a console device as previously
described, and saves the channel ID on
the stack. It then uses UT.MTEXT to print
a message saying ' Filename: ' to this
console window, and collects a line of
input from the keyboard using the very
useful IO.FUNE trap routine. This collects .
bytes from the specified channel until
either more bytes than expected are collected or a newline character is met. The
maximum number of characters to read
is specified in 02, and each character is
put into the buffer pointed to by Al. This
routine is particularly useful as it allows
the user to edit the !me being entered in
the normal QL way. When the routine
returns, register D1 holds the number of
characters read including the terminating
newline. By subtracting 1 from D1 we are
left with the number of real characters
read in. Putting this in the word preceding
the first character gives us a Qdos format
string, which we pass to the IO.OPEN
routine. This decodes the string as if it
were a device name, and then attempts to
open a channel connected to that device.
We specify how that channel should be
opened by the value of 03. If, as in this
case, it contains 1, the channel is opened
in such a way that it can only be read.
If this channel, is opened successfully,
you save the ID on the stack and proceed.
If not, you must print out an error message
to the console and try the whole process
all over again. You use the UT.ERR utility
to do this. When you have finally opened
your file, you enter a loop in which a byte
is read from the file, using IO.FBYTE, and
then transferred to the console usiRg
IO.SBYTE. If an error condition occurs
during the IO.FBYTE call, then it either
means that you have reached the end of
the file, or some unexpected error, such as
• A pr oqr .. to copy a nated fil e to a screen dtvi ce - for QLUB by Adn Otnning
198S
• lit usu11 no trrors fr01 JO.FLHIE ull
• JO t hJt~niU ry
SIZE
100
NT.FRJOB
IO . OPEN
IO. CLDSE
IO .FBYTE
IO. Fll!l£
10. S8YTE
UT. CDIC
UT. ER1!
UT. ft!Ell
OPEM. IMS
ERR.EF
EiU
Ellll
EiU
EiU
Ei U
Eitl
Ellll
EiU
EiU
EQU
EiU
fCb
fCC
fDO
I
·10
il
httder fill!
trap I kty for h r u job reton
trap 2 key for gt ntral ch1nntl open
trap 2 by for channel don
tr ap l hy f or sin9ll byte rud
tr ap l hy for LF· teni n1tH li nr read
trap 3 key for lin9h byte • r ih
vutor addrtn for consolt 1Jt1H ut il i t y
vector ddnu for trror pri nti ng ut il it y
vrctor addnss f or ltU<ICJt pri nt utility
D3 h y for IO.OfiEtl • sharft rtiid .tctess
error code f or ' tn d of fil e '
• Thebtg inningof thecode
START
BRA.S
DC .l
DC.i
DC . M
DC.B
BEGIN
ju.p to thr t cf
progr~•
0
mFB
I
'ilUB '
LEA.L
SUBU
NOVU
NOVEQ
NDVEQ
· NDVEQ
TRAP
TST.L
BEi. S
,QVE ,i
' OVE.L
JSR
Use 'DATA ' far Sincllir AIHibler
too byh! iii tnauqh for the buffer •nd
the jab ' s A7 shck
Equttts, conshnh, 1.nd so on -these •ould nonllty be in
t
'shndilrd fcrut ' i dent ification
proQrll:l natt - lt11gth first
t hen the ilt tu d chiracter s
BRA.S
.
GOTF ILE ·MDVU
"OVEi
I
l
7
COPV FILE 'DVE . L
MOVEO
TRAP
TST.L
BNE.S
J
m
100
bordrr col our (.tlih l
border11 idth
colour lrtdl
int colaur llfhittl
• i ndChl 11idth- 512 pirth
11 ind011htight · IOO piuls
lf i n d ot~ori t itl l t tO ,Ol
Oc.M
f
Yts 1 the progru stilrh herr !
BEGIN
GETNME
LEA.L
miYE. i
JSR
FILEI£SS 1A1
UT.IHEIT ,A2
!All
print tht fllEtESS pro.,t
lEA.l
IIOYEi
110\'Ei
IIDYEi
TRAP
atJFFERt 2,•1.
t · t , Ol
put buH~ HU ddr11n in Al
t. itul i nfinite ti lltOUt
rtl ~ a strin' i nta lht bu.fftr
cri up t oSOcllilfiiCtltl"s
IIO.FlliiE , ~
t80 ,D2
ll
dait
II O.OPEN ,DO
t ·t, DI
IDPEN_INS,DJ
ll
DO
GDTF ILE
UT.ERR 1 A2
!A7l 1 AO
'erase' terainating lint h td
get rudy t o open Hl t /dtvi ct
for t hi s job
wi th shired rud access
no11doit
;my errors?
branch if not
print QDOS l!rror
usug~
toourconsole citannel
!All
GETN"E
andth Emtryltill ovtr
A0 1 -U71
H,Ol
u ve the fil e c~ a nnel ID
si~n a l inhn1te !i aeout -
ag~~:in
D~ is preserved
by both IO.FBYTE and IO.SBYTE btl o•
lA7l,AO
tiO.FBYTE,DO
ll
00
LOSTCOPY
1ft
CO!.!Id uk e the transf er aor t
put fi\ i! (h annel Jto1n AC
prepare to r ead a byte i rc,.Jt
do1t
iony er rors'
yes 1 so branch
4fA7)lAO
I !O.SBYTE,DO
13
COPYFILE
put consoJe chann el ID inAO
pr eparetosl!nd abytl!tc it
do it
assuae no errors and continue
1 Then 111as an t>rror duri nq ID.FBVTE. If this er ror 111as '!!nd of ftl!!' ~ then
f OK and ttean~ •e'v t fin i shed. Otherw i se -. e·d better prin t illl error 11etUQt
LASTCOPV cnPLW
OEO .S
KOYE.L
l'lDVE.Ii
JSR
Open the dtfined 11 indo"
n i consalt dt~ict
• , .1111 ilstutt no error ~
na.uvt ch1nne l ID
PBUH:K 1Al
UT.CDIC,!l
!All
AO,· IA7)
TRAP
BRA.S
K1LLIT
LEA.l
'OYE , M
JSR
KDYE. l
stor e str in g length at shrt of 5tring
Byte ru o is r.o111 if'l Dt . O
"om
pt~p tr
get addrns of b11f h r in
t i,DI
D1 1 (A0l
t IO.SSTR6 1nstead of IO . FBYTE i nd IC.SBYTE,
1 eHicitnt, but 'Ill! won't
' OV£.l
DC .B
OC.B
OC. B
DU
Dc.M
DC .M
OC.M
~0
BUFFER ,!O
• No• t ranshr the fi l e byh-by-byh to the scn en. By using IO.FSTRG illd
t A 11i nd o11 definition blod f c ~ Ul. COM
PILOCK
'bad medium', has occured. To find out
which, we compare the value oi DO
against that of the 'end of file' error. If this
was the error condition, we end the
program, but if another error has occurred
we report it to the console beforehand.
The closing sequence simply uses
IO.CLOSE to close the two channels, and
MT.FRJOB to kill the job. At this point, it is
worth noting that no code needs to follow
the TRAP #1 instruction there, as that call
will remove the job from memory - the
68008's program counter will not point to
this location again until a new job is
loaded. Some authors in some magazines
have been putting entirely redundant
(and semantically meaningless) RTS instructions here.
With the host of routines available
witbin Qdos, it is a very simple matter for
even novice machine code programmers
to play around with window and screen
handling. In later issues we'll be looking
at methods of implementing high resolution graphics from machine code.
.
FI LE"ESS
HUFFER
IERR.EF,DO
KI LLIT
41A7) 1 AO
Ul. ERR 1A2
tA21
!A7H 1 AO
t!O.CLOSE,DO
ll
get fil e channt llD
anilcl oselt
KOVE .l
KOVEO
TRAP
tA7J +, Ag
IIO . CLOSE,DO
ll
get console Chi nnell D
and close it
1\0VEQ
KOVEO
!OYEi
TRIIf'
' "T .FRJ08,DO
1-l,DI
IO,Dl
II
n o t~
oc.•
10
proapt l tss. qe
Dc.B
'f il rnne.
END
hr~t
·end of fi l e' error?
yep ~
else get console channe l ID
and print er~or tessio~t'
' OVE.l
"OIJEQ
TRAP
EOU
it' ~>
force kil l
t his job
•ithnor l!tu rn trrcr (if EXEC_W-in¥ Dhdl
thtend 1
the job' s da ta i rt'i shrh hert