]> Shamusworld >> Repos - apple2/blobdiff - src/floppy.cpp
Fixed stupid bug that caused LC RAM bank #1 to get clobbered when writing
[apple2] / src / floppy.cpp
index e811bb0f53d67d58ef17aa7b222e6ce4ef7361e2..942ffd9b088a245b59639f26e8aab8056099a83f 100755 (executable)
 #include "floppy.h"
 
 #include <stdio.h>
-#include <string>
+#include <string.h>
 #include "apple2.h"
 #include "log.h"
 #include "applevideo.h"                                        // For message spawning... Though there's probably a better approach than this!
 
-using namespace std;
+//using namespace std;
 
 // Useful enums
 
@@ -60,6 +60,8 @@ FloppyDrive::~FloppyDrive()
 
 bool FloppyDrive::LoadImage(const char * filename, uint8 driveNum/*= 0*/)
 {
+       WriteLog("FLOPPY: Attempting to load image '%s' in drive #%u.\n", filename, driveNum);
+
        if (driveNum > 1)
        {
                WriteLog("FLOPPY: Attempted to load image to drive #%u!\n", driveNum);
@@ -90,6 +92,20 @@ bool FloppyDrive::LoadImage(const char * filename, uint8 driveNum/*= 0*/)
        DetectImageType(filename, driveNum);
        strcpy(imageName[driveNum], filename);
 
+#if 0
+       WriteLog("FLOPPY: Opening image for drive #%u.\n", driveNum);
+       FILE * fp2 = fopen("bt-nybblized.nyb", "wb");
+
+       if (fp2 == NULL)
+               WriteLog("FLOPPY: Failed to open image file 'bt-nybblized.nyb' for writing...\n");
+       else
+       {
+               fwrite(nybblizedImage[driveNum], 1, 232960, fp2);
+               fclose(fp2);
+       }
+#endif
+       WriteLog("FLOPPY: Loaded image '%s' for drive #%u.\n", filename, driveNum);
+
        return true;
 }
 
@@ -135,6 +151,7 @@ bool FloppyDrive::SaveImage(uint8 driveNum/*= 0*/)
 bool FloppyDrive::SaveImageAs(const char * filename, uint8 driveNum/*= 0*/)
 {
 //WARNING: Buffer overflow possibility
+#warning "Buffer overflow possible--!!! FIX !!!"
        strcpy(imageName[driveNum], filename);
        return SaveImage(driveNum);
 }
@@ -226,8 +243,16 @@ WRT to the disk image itself.
 //*/
                }
 
+// Actually, it just might matter WRT to nybblyzing/denybblyzing
+// Here, we check for BT3
+//Nope, no change...
+//diskType[driveNum] = DT_PRODOS;
+
                NybblizeImage(driveNum);
        }
+
+#warning "Should we attempt to nybblize unknown images here? Definitely SHOULD issue a warning!"
+
 WriteLog("FLOPPY: Detected image type %s...\n", (diskType[driveNum] == DT_NYBBLE ?
        "Nybble image" : (diskType[driveNum] == DT_DOS33 ?
        "DOS 3.3 image" : (diskType[driveNum] == DT_PRODOS ? "ProDOS image" : "unknown"))));
@@ -316,8 +341,16 @@ void FloppyDrive::NybblizeImage(uint8 driveNum)
                        // Using a lookup table, convert the 6-bit bytes into disk bytes.
 
                        for(uint16 i=0; i<343; i++)
+//#define TEST_NYBBLIZATION
+#ifdef TEST_NYBBLIZATION
+{
+WriteLog("FL: i = %u, img[i] = %02X, diskbyte = %02X\n", i, img[i], diskbyte[img[i] >> 2]);
+#endif
                                img[i] = diskbyte[img[i] >> 2];
-
+#ifdef TEST_NYBBLIZATION
+//WriteLog("            img[i] = %02X\n", img[i]);
+}
+#endif
                        img += 343;
 
                        // Done with the nybblization, now for the epilogue...
@@ -470,7 +503,7 @@ bit 0 is the "do something" bit.
 SpawnMessage("Stepping to track %u...", track);
        }
 
-//     return something if read mode...        
+//     return something if read mode...
 }
 
 void FloppyDrive::ControlMotor(uint8 addr)
@@ -487,7 +520,8 @@ void FloppyDrive::DriveEnable(uint8 addr)
 
 uint8 FloppyDrive::ReadWrite(void)
 {
-SpawnMessage("%sing %s track %u, sector %u...", (ioMode == IO_MODE_READ ? "Read" : "Write"),
+SpawnMessage("%u:%sing %s track %u, sector %u...", activeDrive,
+       (ioMode == IO_MODE_READ ? "Read" : "Write"),
        (ioMode == IO_MODE_READ ? "from" : "to"), track, currentPos / 396);
        // $C0EC
 /*
@@ -505,6 +539,7 @@ Which we now do. :-)
        uint8 diskByte = nybblizedImage[activeDrive][(track * 6656) + currentPos];
        currentPos = (currentPos + 1) % 6656;
 
+//WriteLog("FL: diskByte=%02X, currentPos=%u\n", diskByte, currentPos);
        return diskByte;
 }
 
@@ -531,3 +566,38 @@ void FloppyDrive::SetWriteMode(void)
        // $C0EF
        ioMode = IO_MODE_WRITE;
 }
+
+/*
+PRODOS 8 MLI ERROR CODES
+
+$00:    No error
+$01:    Bad system call number
+$04:    Bad system call parameter count
+$25:    Interrupt table full
+$27:    I/O error
+$28:    No device connected
+$2B:    Disk write protected
+$2E:    Disk switched
+$40:    Invalid pathname
+$42:    Maximum number of files open
+$43:    Invalid reference number
+$44:    Directory not found
+$45:    Volume not found
+$46:    File not found
+$47:    Duplicate filename
+$48:    Volume full
+$49:    Volume directory full
+$4A:    Incompatible file format, also a ProDOS directory
+$4B:    Unsupported storage_type
+$4C:    End of file encountered
+$4D:    Position out of range
+$4E:    File access error, also file locked
+$50:    File is open
+$51:    Directory structure damaged
+$52:    Not a ProDOS volume
+$53:    Invalid system call parameter
+$55:    Volume Control Block table full
+$56:    Bad buffer address
+$57:    Duplicate volume
+$5A:    File structure damaged
+*/