I received an email asking for an example on how to detect the End-Of-File when doing file I/O.
This example assumes a text file named test1.txt exists in the same directory as the example.
Code:
*-----------------------------------------------------------
* Program Number:
* Written by : Chuck Kelly
* Date Created : November-8-2006
* Description : Demonstrate file I/O in EASy68K
* Reads and displays the contents of "test1.txt" file.
* Loops until End-Of-File is reached.
*-----------------------------------------------------------
ORG $800
lea filename,a1
move #51,d0 ;open "test1.txt" file
trap #15 ;returns file ID in d1
move.l d1,d4 ;save file ID
* Read lines from file and display
* Loop until EOF reached
lea buffer,a1
clr d2
repeat
if.b d2 <ne> #0 then.s ;if data was read from file
move.l d2,d1 ;number of characters read
move #1,d0 ;display text at (A1)
trap #15
endi
move.l d4,d1 ;restore file ID
move #80,d2 ;# bytes to read
move #53,d0 ;read from file
trap #15
until.w d0 <eq> #1 do.s ;until EOF
move #50,d0
trap #15 ;close all files
STOP #$2000
filename dc.b 'test1.txt',0
buffer ds.b 80
END $800