@@ -394,7 +394,7 @@ func BdosSysCallFileOpen(cpm *CPM) error {
394394
395395 // Yes we can!
396396 // Save the file handle in our cache.
397- cpm .files [ptr ] = FileCache {name : fileName , handle : nil }
397+ cpm .files [fcbPtr . GetCacheKey () ] = FileCache {name : fileName , handle : nil }
398398
399399 // Get file size, in blocks
400400 fLen := uint8 (len (virt ) / blkSize )
@@ -405,10 +405,6 @@ func BdosSysCallFileOpen(cpm *CPM) error {
405405 fcbPtr .RC = fLen
406406 }
407407
408- // Write our cache-key in the FCB
409- fcbPtr .Al [0 ] = uint8 (ptr & 0xFF )
410- fcbPtr .Al [1 ] = uint8 (ptr >> 8 )
411-
412408 // Update the FCB in memory.
413409 cpm .Memory .SetRange (ptr , fcbPtr .AsBytes ()... )
414410
@@ -443,7 +439,7 @@ func BdosSysCallFileOpen(cpm *CPM) error {
443439 }
444440
445441 // Save the file handle in our cache.
446- cpm .files [ptr ] = FileCache {name : fileName , handle : file }
442+ cpm .files [fcbPtr . GetCacheKey () ] = FileCache {name : fileName , handle : file }
447443
448444 // Get file size, in bytes
449445 fi , err := file .Stat ()
@@ -469,10 +465,6 @@ func BdosSysCallFileOpen(cpm *CPM) error {
469465 slog .Int ("record_count" , int (fcbPtr .RC )),
470466 slog .Int64 ("file_size" , fileSize ))
471467
472- // Write our cache-key in the FCB
473- fcbPtr .Al [0 ] = uint8 (ptr & 0xFF )
474- fcbPtr .Al [1 ] = uint8 (uint16 (ptr >> 8 ))
475-
476468 // Update the FCB in memory.
477469 cpm .Memory .SetRange (ptr , fcbPtr .AsBytes ()... )
478470
@@ -498,14 +490,11 @@ func BdosSysCallFileClose(cpm *CPM) error {
498490 // Create a structure with the contents
499491 fcbPtr := fcb .FromBytes (xxx )
500492
501- // Get our cache-key from the FCB
502- key := uint16 (uint16 (fcbPtr .Al [1 ])<< 8 + uint16 (fcbPtr .Al [0 ]))
503-
504493 // Get the file handle from our cache.
505- obj , ok := cpm .files [key ]
494+ obj , ok := cpm .files [fcbPtr . GetCacheKey () ]
506495 if ! ok {
507496 slog .Debug ("SysCallFileClose tried to close a file that wasn't open" ,
508- slog .Int ( "fcb " , int ( ptr )))
497+ slog .String ( "guest " , fcbPtr . GetCacheKey ( )))
509498 cpm .CPU .States .HL .SetU16 (0x00FF )
510499 return nil
511500 }
@@ -545,11 +534,8 @@ func BdosSysCallFileClose(cpm *CPM) error {
545534 }
546535
547536 // delete the entry from the cache.
548- delete (cpm .files , key )
537+ delete (cpm .files , fcbPtr . GetCacheKey () )
549538
550- // Update the FCB in RAM
551- fcbPtr .Al [0 ] = 0x00
552- fcbPtr .Al [1 ] = 0x00
553539 cpm .Memory .SetRange (ptr , fcbPtr .AsBytes ()... )
554540
555541 // Record success
@@ -768,11 +754,8 @@ func BdosSysCallRead(cpm *CPM) error {
768754 // Create a structure with the contents
769755 fcbPtr := fcb .FromBytes (xxx )
770756
771- // Get our cache-key from the FCB
772- key := uint16 (uint16 (fcbPtr .Al [1 ])<< 8 + uint16 (fcbPtr .Al [0 ]))
773-
774757 // Get the file handle in our cache.
775- obj , ok := cpm .files [key ]
758+ obj , ok := cpm .files [fcbPtr . GetCacheKey () ]
776759 if ! ok {
777760 slog .Error ("SysCallRead: Attempting to read from a file that isn't open" ,
778761 slog .String ("filename" , fcbPtr .GetFileName ()))
@@ -883,11 +866,8 @@ func BdosSysCallWrite(cpm *CPM) error {
883866 // Create a structure with the contents
884867 fcbPtr := fcb .FromBytes (xxx )
885868
886- // Get our cache-key from the FCB
887- key := uint16 (uint16 (fcbPtr .Al [1 ])<< 8 + uint16 (fcbPtr .Al [0 ]))
888-
889869 // Get the file handle in our cache.
890- obj , ok := cpm .files [key ]
870+ obj , ok := cpm .files [fcbPtr . GetCacheKey () ]
891871 if ! ok {
892872 slog .Error ("SysCallWrite: Attempting to write to a file that isn't open" )
893873 cpm .CPU .States .HL .SetU16 (0x00FF )
@@ -1028,12 +1008,8 @@ func BdosSysCallMakeFile(cpm *CPM) error {
10281008 fcbPtr .RC = fLen
10291009 }
10301010
1031- // Write our cache-key in the FCB
1032- fcbPtr .Al [0 ] = uint8 (ptr & 0xFF )
1033- fcbPtr .Al [1 ] = uint8 (ptr >> 8 )
1034-
10351011 // Save the file-handle
1036- cpm .files [ptr ] = FileCache {name : fileName , handle : file }
1012+ cpm .files [fcbPtr . GetCacheKey () ] = FileCache {name : fileName , handle : file }
10371013
10381014 l .Debug ("result:OK" ,
10391015 slog .Int ("fcb" , int (ptr )),
@@ -1264,11 +1240,8 @@ func BdosSysCallReadRand(cpm *CPM) error {
12641240 // Create a structure with the contents
12651241 fcbPtr := fcb .FromBytes (xxx )
12661242
1267- // Get our cache-key from the FCB
1268- key := uint16 (uint16 (fcbPtr .Al [1 ])<< 8 + uint16 (fcbPtr .Al [0 ]))
1269-
12701243 // Get the file handle in our cache.
1271- obj , ok := cpm .files [key ]
1244+ obj , ok := cpm .files [fcbPtr . GetCacheKey () ]
12721245 if ! ok {
12731246 slog .Error ("SysCallReadRand: Attempting to read from a file that isn't open" ,
12741247 slog .String ("filename" , fcbPtr .GetFileName ()))
@@ -1361,11 +1334,8 @@ func BdosSysCallWriteRand(cpm *CPM) error {
13611334 // Create a structure with the contents
13621335 fcbPtr := fcb .FromBytes (xxx )
13631336
1364- // Get our cache-key from the FCB
1365- key := uint16 (uint16 (fcbPtr .Al [1 ])<< 8 + uint16 (fcbPtr .Al [0 ]))
1366-
13671337 // Get the file handle in our cache.
1368- obj , ok := cpm .files [key ]
1338+ obj , ok := cpm .files [fcbPtr . GetCacheKey () ]
13691339 if ! ok {
13701340 slog .Error ("SysCallWriteRand: Attempting to write to a file that isn't open" )
13711341 cpm .CPU .States .HL .SetU16 (0x00FF )
0 commit comments