EASy68K  
It is currently Fri Nov 15, 2019 9:39 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Text Reader Code
PostPosted: Sun Mar 11, 2012 4:06 pm 
Offline

Joined: Sat Mar 10, 2012 5:07 pm
Posts: 4
Location: Jamaica
How can I modify the code of the text reader to print a file (that contains all lower case
characters) , converting each character to upper case as it is printed?

How can I modify the code of the text reader to print a line number for each line that is to be printed?

I really hardly understand the code that I have given, I would also like to know where the values from the file are being stored, before they are output.



Code:
   ORG   $1000
START



   MOVE #0,D0               Set Trap task 1 (Print string)
   MOVE #50,D1              Set String length to be printed to max 50
   lea   welcomePrompt,a1 load address of string to display into A1
   trap   #15            trap #15 activates input/output task

        BSR.s      do_InitFile         * go setup stuff

   BSR      do_OpenFile         * go open a file
   MOVEQ      #-1,d0                 * set test value
   CMP.l      d0,d1            * test the file ID
   BEQ      do_Exit         * if no file just quit

   BSR      do_LoadFile         * load the file
   TST.l      d1            * test the returned flag
   BMI      do_Exit         * if something was wrong just quit


   LEA       txtFile(a3),a4
   move       #0,d5
   BSR      do_ProcessFile     * was all ok so process the file

   BRA START
   



do_InitFile
   MOVEQ      #0,d1         * turn off keyboard echo
   MOVEQ      #12,d0         * keyboard echo
   TRAP      #15

   MOVEQ      #50,d0         * close all files
   TRAP      #15

   RTS

do_OpenFile
   LEA      dialogTitle(pc),a1      * set the request title string pointer
   LEA      dialogList(pc),a2         * set the file types list pointer
   LEA      fileName(a3),a3      * set the file name buffer pointer
   MOVEQ      #0,d1            * file open
   MOVE.b   d1,(a3)         * ensure null source file
   MOVEQ      #58,d0         * file I/O
   TRAP      #15

   MOVEA.l   a3,a1            * copy the file name pointer
   TST.l      d1            * did the user hit open
   BEQ.s      do_NoOpenFile      * if not do no file exit

   MOVE      #51,d0         * else open existing file
   TRAP      #15

   MOVE.l   d1,fileName(a3)      * save the file ID
   RTS
       
do_NoOpenFile
   MOVEQ      #-1,d1         * clear the file id
        rts


   
do_LoadFile
   MOVE.l   fileName(a3),d1      * get the file ID
   move #0, d4
   LEA      txtFile(a3),a1      * point to the file buffer
   
do_ReadMore
   MOVE      #recordSize,d2   * set the byte count to load the file header
   MOVE.l   d2,d3            * copy the file header byte count
   MOVE      #53,d0         * read from the file
   TRAP      #15

   CMP.l      d3,d2         * compare the bytes read with the expected
                  * byte count
   BNE.s      do_ExitLoadFile      * if incorrect do exit

   
   ADD #recordSize, a1
   add #1,d4
   BRA do_ReadMore

do_ExitLoadFile
   move.b d4, (numRecords)
   RTS

dialogTitle
   dc.b   'Open data file',0


dialoglist
   dc.b   '*.txt',0            * file type list
   ds.w   0   
   
do_ProcessFile   
       
   move  a4,A1     
        *if converting, move each byte from its relative position to A5
   * then convert it storing the result in A6
   * then update memory   
   move #(recordsize), d1
   move #1, d0
   Trap #15
       
        add #recordSize,a4
        add #1,d5
        move.b (numRecords),d4
        cmp d4,d5
        BGE do_Exit
   bra do_Processfile
   RTS

do_ConvertToNum
   move.w d5,d6                   
   and.w #$FF00,d6
   lsr #8,d6
   sub.b #$30,d6
        mulu #10,d6                      
   move.b d5,d7                   
   sub #$30,d7
   add d6,d7
   RTS
   
do_ConvertToUpper
   move.w d5,d6
     *add conversion code here
   RTS
   
do_Exit   
   MOVE #0,D0               Set Trap task 1 (Print string)
   MOVE #50,D1              Set String length to be printed to max 50
   lea   spacePrompt,a1 load address of string to display into A1
   trap   #15            trap #15 activates input/output task
   

   MOVE #0,D0               Set Trap task 1 (Print string)
   MOVE #50,D1              Set String length to be printed to max 50
   lea   exitPrompt,a1 load address of string to display into A1
   trap   #15            trap #15 activates input/output task
   
 
   
*variable declarations
WelcomePrompt   dc.b   'Welcome to the file reader: ',0   null terminated string

ExitPrompt   dc.b   'Exiting the file reader: ',0   null terminated string
spacePrompt   dc.b   ' ',0   null terminated string

vars             *base address for variables
      
recordSize    EQU  12            
dataSize    EQU  3   
costLimit    EQU  1
durationLimit    EQU  1
numRecords    ds.b  1
         
fileName   EQU            * -variables
   ds.l   1               * file ID longword
txtFile   EQU            *
   ds.b    512

   END   START      ; last line of source

_________________
SAnderson


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group