Newsgroups: comp.sys.apple2.programmer Path: news.uiowa.edu!news.physics.uiowa.edu!math.ohio-state.edu!uwm.edu!vixen.cso.uiuc.edu!newsfeed.internetmci.com!in1.uu.net!istar.net!news1.toronto.fonorola.net!news1.toronto.istar.net!news.toronto.istar.net!alpha.vaxxine.com!mhackett From: mhackett@vaxxine.com (Michael Hackett) Subject: Re: Program to put catalog of disk to txt file Message-ID: Organization: Some Assembly Required X-Newsreader: MacSOUP 1.0d6 References: <4d04am$omv@rock101.genie.net> <4d2nme$pj6@pith.uoregon.edu> <4d9ibt$9k4@pith.uoregon.edu> Date: Mon, 15 Jan 1996 04:05:34 GMT Lines: 59 Neil Parker wrote: > I'm pretty sure it *is* a bug. I stand corrected. There is a bug, actually two, but it's not in the handling of multiple open files in general. As others have said, the reading of directory files are a special case; the text lines are generated on the fly from the actual directory entries. It is in this special code that the bugs lie. I couldn't find my old code, so I tried whipping up the program and ran into the problem you are having. Also, I found that doing *two* INPUTs resulted in a blank line instead of the next entry for the first one, but the second INPUT gave the following entry correctly. So I pulled out my trusty old Disassembly Lines articles and with their help and a lot of poking and testing, I think I've tracked down the problems. First, the READ command resets CATFLAG to 1, which causes the next line read to be blank. You could get around this by executing two INPUTs each time, and ignoring the first. It would be easy to fix this problem by patching BASIC.SYSTEM, but the location moves from version to version, so I've provided another work-around below (or you can use the two INPUTs idea). The bigger problem is that the byte count for the ProDOS READ paramater block is never reset after the first INPUT on the directory file. As the same parameter block is used for both the ProDOS READ and WRITE calls, any intervening output statements will change the byte count and fowl up the directory reading code (it will read the wrong number of bytes and get out of sync with the directory entries). The easy fix, without patching BASIC.SYSTEM, is to add the following statements between the READ and INPUT statements for each line: POKE 48719,0: POKE 48857,39: POKE 48858,0 The first command resets CATFLAG to 0, as it should be, and the second two reset the byte count for the directory reading code to the size of a directory entry. All of these locations are on the BI's global page, and so do not change between versions. The following short program does correctly copy the contents of a directory catalog to a text file (yes, I've tested it): 10 D$ = CHR$ (4):DIR$ = "/programs/":OUT$ = "test.out" 20 PRINT D$;"OPEN";OUT$ 30 PRINT D$;"OPEN";DIR$;",TDIR" 40 PRINT D$;"READ";DIR$: INPUT A$: INPUT A$: INPUT A$ 50 PRINT D$;"READ";DIR$ 60 POKE 48719,0: POKE 48857,39: POKE 48858,0 70 INPUT A$: IF A$ = "" GOTO 100 80 PRINT D$;"WRITE";OUT$: PRINT A$ 90 GOTO 50 100 PRINT D$;"CLOSE" Let me know if that solves your problem. ======================================================================== Michael Hackett Internet: mhackett@vaxxine.com GEnie: M.HACKETT Some Assembly Required Voice: (905) 687-1729 BBS: (905) 687-9987