@@ -267,13 +267,10 @@ func SysCallDriveAllReset(cpm *CPM) error {
267267 var ret uint8 = 0
268268
269269 // drive will default to our current drive, if the FCB drive field is 0
270- drive := cpm .currentDrive + 'A'
270+ drive := string ( cpm .currentDrive + 'A' )
271271
272- // Should we remap drives?
273- path := "."
274- if cpm .Drives {
275- path = string (drive )
276- }
272+ // Remap to the place we're supposed to use.
273+ path := cpm .drives [drive ]
277274
278275 // Look for a file with $ in its name
279276 files , err := os .ReadDir (path )
@@ -354,11 +351,8 @@ func SysCallFileOpen(cpm *CPM) error {
354351 drive = fcbPtr .Drive + 'A' - 1
355352 }
356353
357- // Should we remap drives?
358- path := "."
359- if cpm .Drives {
360- path = string (drive )
361- }
354+ // Remap to the place we're supposed to use.
355+ path := cpm .drives [string (drive )]
362356
363357 //
364358 // Ok we have a filename, but we probably have an upper-case
@@ -384,16 +378,8 @@ func SysCallFileOpen(cpm *CPM) error {
384378 slog .String ("drive" , string (cpm .currentDrive + 'A' )),
385379 slog .String ("result" , fileName ))
386380
387- // Should we remap drives?
388- if cpm .Drives {
389- before := fileName
390-
391- fileName = filepath .Join (string (drive ), fileName )
392-
393- l .Debug ("SysCallFileOpen remapped path" ,
394- slog .String ("before" , before ),
395- slog .String ("after" , fileName ))
396- }
381+ // Ensure the filename is qualified
382+ fileName = filepath .Join (path , fileName )
397383
398384 // Now we open..
399385 file , err := os .OpenFile (fileName , os .O_RDWR , 0644 )
@@ -531,10 +517,8 @@ func SysCallFindFirst(cpm *CPM) error {
531517 // Create a structure with the contents
532518 fcbPtr := fcb .FromBytes (xxx )
533519
534- dir := "."
535- if cpm .Drives {
536- dir = string (cpm .currentDrive + 'A' )
537- }
520+ // Look in the correct location.
521+ dir := cpm .drives [string (cpm .currentDrive + 'A' )]
538522
539523 // Find files in the FCB.
540524 res , err := fcbPtr .GetMatches (dir )
@@ -651,10 +635,8 @@ func SysCallDeleteFile(cpm *CPM) error {
651635 drive = fcbPtr .Drive + 'A' - 1
652636 }
653637
654- path := "."
655- if cpm .Drives {
656- path = string (drive )
657- }
638+ // Remap to the place we're supposed to use.
639+ path := cpm .drives [string (drive )]
658640
659641 // Find files in the FCB.
660642 res , err := fcbPtr .GetMatches (path )
@@ -857,11 +839,8 @@ func SysCallMakeFile(cpm *CPM) error {
857839 drive = fcbPtr .Drive + 'A' - 1
858840 }
859841
860- // Should we remap drives?
861- path := "."
862- if cpm .Drives {
863- path = string (drive )
864- }
842+ // Remap to the place we're supposed to use.
843+ path := cpm .drives [string (drive )]
865844
866845 //
867846 // Ok we have a filename, but we probably have an upper-case
@@ -887,16 +866,8 @@ func SysCallMakeFile(cpm *CPM) error {
887866 slog .String ("drive" , string (cpm .currentDrive + 'A' )),
888867 slog .String ("result" , fileName ))
889868
890- // Should we remap drives?
891- if cpm .Drives {
892- before := fileName
893-
894- fileName = filepath .Join (string (drive ), fileName )
895-
896- l .Debug ("SysCallMakeFile remapped path" ,
897- slog .String ("before" , before ),
898- slog .String ("after" , fileName ))
899- }
869+ // Qualify the path
870+ fileName = filepath .Join (path , fileName )
900871
901872 // Create the file
902873 file , err := os .OpenFile (fileName , os .O_CREATE | os .O_RDWR , 0644 )
@@ -967,11 +938,8 @@ func SysCallRenameFile(cpm *CPM) error {
967938 fileName += ext
968939 }
969940
970- // Should we remap drives?
971- path := "."
972- if cpm .Drives {
973- path = string (cpm .currentDrive + 'A' )
974- }
941+ // Point to the directory
942+ path := cpm .drives [string (cpm .currentDrive + 'A' )]
975943
976944 //
977945 // Ok we have a filename, but we probably have an upper-case
@@ -989,10 +957,8 @@ func SysCallRenameFile(cpm *CPM) error {
989957 }
990958 }
991959
992- // Should we remap drives?
993- if cpm .Drives {
994- fileName = filepath .Join (string (cpm .currentDrive + 'A' ), fileName )
995- }
960+ // Ensure the filename is qualified
961+ fileName = filepath .Join (path , fileName )
996962
997963 // 2. DEST
998964 // The pointer to the FCB
@@ -1011,10 +977,8 @@ func SysCallRenameFile(cpm *CPM) error {
1011977 dstName += dExt
1012978 }
1013979
1014- // Should we remap drives?
1015- if cpm .Drives {
1016- dstName = filepath .Join (string (cpm .currentDrive + 'A' ), dstName )
1017- }
980+ // ensure the name is qualified
981+ dstName = filepath .Join (path , dstName )
1018982
1019983 cpm .Logger .Debug ("Renaming file" ,
1020984 slog .String ("src" , fileName ),
@@ -1287,10 +1251,7 @@ func SysCallFileSize(cpm *CPM) error {
12871251 }
12881252
12891253 // Should we remap drives?
1290- path := "."
1291- if cpm .Drives {
1292- path = string (cpm .currentDrive + 'A' )
1293- }
1254+ path := cpm .drives [string (cpm .currentDrive + 'A' )]
12941255
12951256 //
12961257 // Ok we have a filename, but we probably have an upper-case
@@ -1308,10 +1269,8 @@ func SysCallFileSize(cpm *CPM) error {
13081269 }
13091270 }
13101271
1311- // Should we remap drives?
1312- if cpm .Drives {
1313- fileName = filepath .Join (string (cpm .currentDrive + 'A' ), fileName )
1314- }
1272+ // esnure the path is qualified
1273+ fileName = filepath .Join (path , fileName )
13151274
13161275 file , err := os .OpenFile (fileName , os .O_RDONLY , 0644 )
13171276 if err != nil {
0 commit comments