Remove this ad

Lead

Jun 21 13 1:51 PM

Tags : :

I'm having a frightful time trying to read files, despite having a decent reference - the source code for EinTrans.

Call me naive but I expected this to work:


   ld   de,fcb                     ; read next block
   ld   c,CPM_FUNC_READ_SEQ
   call  5
   or   a
   jr    nz,_eof

but it doesn't. I get premature EOFs. I'm looking in the dos/mos introduction manual I have here, and the error code explanation is vague, to say the least.

Some calls are documented as returning a 'directory code', others an 'error code'.

Are these actually documented anywhere or do I have to keep breaking out an emulator every time I want to do anything :¬/

C

Quote    Reply   
Remove this ad
Remove this ad

#1 [url]

Jun 22 13 2:05 PM

Opening a file that exists consistently returns 2. Sequential reads return 1, but never finish, almost like the same block is being read over and over. I just can't see what I'm doing wrong :(


   ld    de,fcb
   ld   c,CPM_FUNC_OPEN_FILE
   call 5

   inc a
   jp   z,dosReportError

; ***********************************************************
; Read the file block by block, writing to the card as we go.
; ***********************************************************

_loop:
   ld   de,fcb                     ; read next block
   ld   c,CPM_FUNC_READ_SEQ
   call  5

   or   a
   jr    nz,_loop

_eof:
   ld   de,fcb
   ld   c,CPM_FUNC_CLOSE_FILE
   call 5                          ; ignore any error closing the file


HELP!
 :((

Quote    Reply   

#2 [url]

Jun 23 13 12:54 PM

It's amazing what a good night's sleep and a dump (the hex sort) can do.

I was clearing the FBC incorrectly - there was a spare space character in the fcb which was confusing DOS. After removing this all is good.

C

Quote    Reply   

#3 [url]

Jun 24 13 3:15 AM

You' re so right Charlie!
Also make sure you declare and clear a  full FCB size of 36 bytes not just the 32 that the directory entry needs.


In the routine below you  can of course use LDIR but this can fail on the Einey randomly because it can mess up the interrupts even using DI EI -  don't ask me why :-)


This is a useful routine to call before any new file work and preserves all registers


; On Entry DE points to FCB


_ClearFCB: 
                push af 
                push hl 
                push bc
                ex de,hl
                ld bc,2400h     ; a 16 bit load is faster 
                xor a


loop:         ld (hl),a
                inc a
                djnz loop


                ex de,hl
                pop bc
                pop hl
                pop af
                ret
   By modifying  this routine and entering with a fill character in A and bc as a counter you can fill any size buffer (64k) with anything. Of course you will have to dump djnz and do and extra test on C because a Z80 bug doesn't set the zero flag when bc reaches zero.


Fill a buffer with any character.


; On Entry DE points to FCB, BC is the counter, A holds  the fill character. Preserves HL/DE


_ClearBUFF: 
                push de
                push hl
                ex de,hl        ; just for  convenience as  A to (hl) loads are fastest.
             

loop:         ld (hl),a
                inc a
                dec bc     ; now we'll have to  test for bc = 0
                ld e,a        ;don't do a push af here because reg loads are the fastest (inner loop)
                ld a,b
                or c
                ld a,e       ;don't do a pop  af here because reg loads are the fastest  (inner loop)

                jr nz, loop


                                 ;ex de,hl is redundant because we messed with E & we saved DE/HL anyway
                pop hl
                pop de
                ret


A useful tip is to label your buffers is with NameBuffStart and NameBuffEnd then to load BC with the buffer size size is simply  LD BC,NameBuffEnd - NameBuffStart
              


P

Quote    Reply   
Add Reply

Quick Reply

bbcode help