From 78e17b9d87c3b5a869921f4f0d5e96c9cf7536fe Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 15 Jul 2024 19:54:42 +0300 Subject: [PATCH] Better handling for file-sizes --- cpm/cpm_bdos.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cpm/cpm_bdos.go b/cpm/cpm_bdos.go index 1aa1c73..3d577dc 100644 --- a/cpm/cpm_bdos.go +++ b/cpm/cpm_bdos.go @@ -1584,6 +1584,16 @@ func BdosSysCallFileSize(cpm *CPM) error { // of records records := int(fileSize / 128) + // Block size is used so round up, if we need to. + if (fileSize % blkSize) != 0 { + records += 1 + } + + // Cap the size appropriately. + if records >= 65536 { + records = 65536 + } + // Store the value in the three fields fcbPtr.R0 = uint8(records & 0xFF) fcbPtr.R1 = uint8(records >> 8)