skx / cpmulator

Golang CP/M emulator for zork, Microsoft BASIC, Turbo Pascal, Wordstar, lighthouse-of-doom, etc
MIT License
104 stars 3 forks source link

Overhaul our file handling #27

Closed skx closed 7 months ago

skx commented 7 months ago

I tried to write a file-copy command this morning, in z80 assembly, however it turned out to be painful:

  1. Open the source file
  2. Count the number of blocks.
  3. Close the source file
  4. Open the source file
  5. Read a block of data
  6. Close the file
  7. Open the destination file
  8. Write the block of data
  9. Close the file
  10. Goto 4 until all blocks are copied.

The root cause of this is that we only keep one cached/open filehandle - when an OpenFile request is made we close any previously opened file.

We need to allow N files to be opened, perhaps with a lower mask. We can probably assume that the Open/Read/Write/Close operations carried out will keep the same FCB address. We can probably fill in FCB.Al with the filehandle, or some other "invisible" strucutre. Needs thought, but we should do better.

skx commented 7 months ago

I thought I could save the filehandle in FCB.S1, however that is not maintained across operations.

However .Al[0] seems to work. I need more testing to confirm that though.