ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/1541d64.cpp
(Generate patch)

Comparing Frodo4/Src/1541d64.cpp (file contents):
Revision 1.7 by cebix, 2004-01-12T14:58:26Z vs.
Revision 1.9 by cebix, 2004-01-14T16:46:17Z

# Line 1 | Line 1
1   /*
2   *  1541d64.cpp - 1541 emulation in disk image files (.d64/.x64/zipcode)
3   *
4 < *  Frodo (C) 1994-1997,2002-2003 Christian Bauer
4 > *  Frodo (C) 1994-1997,2002-2004 Christian Bauer
5   *  zipcode decoding routines (C) 1993-1997 Marko Mäkelä, Paul David Doherty
6   *
7   *  This program is free software; you can redistribute it and/or modify
# Line 109 | Line 109 | const int accum_num_sectors[41] = {
109  
110   // Prototypes
111   static bool match(const uint8 *p, int p_len, const uint8 *n);
112 + static FILE *open_image_file(const char *path, bool write_mode);
113 + static bool parse_image_file(FILE *f, image_file_desc &desc);
114  
115  
116   /*
# Line 1292 | Line 1294 | const int conv_job_error[16] = {
1294   };
1295  
1296   // Read sector, return error code
1297 < int read_sector(FILE *f, const image_file_desc &desc, int track, int sector, uint8 *buffer)
1297 > static int read_sector(FILE *f, const image_file_desc &desc, int track, int sector, uint8 *buffer)
1298   {
1299          // Convert track/sector to byte offset in file
1300          long offset = offset_from_ts(desc, track, sector);
# Line 1312 | Line 1314 | int read_sector(FILE *f, const image_fil
1314   }
1315  
1316   // Write sector, return error code
1317 < int write_sector(FILE *f, const image_file_desc &desc, int track, int sector, uint8 *buffer)
1317 > static int write_sector(FILE *f, const image_file_desc &desc, int track, int sector, uint8 *buffer)
1318   {
1319          // Convert track/sector to byte offset in file
1320          long offset = offset_from_ts(desc, track, sector);
# Line 1348 | Line 1350 | bool ImageDrive::write_sector(int track,
1350   }
1351  
1352   // Write error info back to image file
1353 < void write_back_error_info(FILE *f, const image_file_desc &desc)
1353 > static void write_back_error_info(FILE *f, const image_file_desc &desc)
1354   {
1355          if (desc.type == TYPE_D64 && desc.has_error_info) {
1356                  int num_sectors = desc.num_tracks == 40 ? NUM_SECTORS_40 : NUM_SECTORS_35;
# Line 1358 | Line 1360 | void write_back_error_info(FILE *f, cons
1360   }
1361  
1362   // Format disk image
1363 < bool format_image(FILE *f, image_file_desc &desc, bool lowlevel, uint8 id1, uint8 id2, const uint8 *disk_name, int disk_name_len)
1363 > static bool format_image(FILE *f, image_file_desc &desc, bool lowlevel, uint8 id1, uint8 id2, const uint8 *disk_name, int disk_name_len)
1364   {
1365          uint8 p[256];
1366  
# Line 1955 | Line 1957 | error:
1957   *  Open disk image file, return file handle
1958   */
1959  
1960 < FILE *open_image_file(const char *path, bool write_mode)
1960 > static FILE *open_image_file(const char *path, bool write_mode)
1961   {
1962   #if 0
1963          if (is_zipcode_file(path)) {
# Line 2039 | Line 2041 | static bool parse_x64_file(FILE *f, imag
2041          return true;
2042   }
2043  
2044 < bool parse_image_file(FILE *f, image_file_desc &desc)
2044 > static bool parse_image_file(FILE *f, image_file_desc &desc)
2045   {
2046          // Read header
2047          uint8 header[64];
# Line 2061 | Line 2063 | bool parse_image_file(FILE *f, image_fil
2063   }
2064  
2065  
2066 + /*
2067 + *  Read directory of disk image file into (empty) c64_dir_entry vector,
2068 + *  returns false on error
2069 + */
2070 +
2071 + bool ReadImageDirectory(const char *path, vector<c64_dir_entry> &vec)
2072 + {
2073 +        bool result = false;
2074 +
2075 +        // Open file
2076 +        FILE *f = open_image_file(path, false);
2077 +        if (f) {
2078 +                int num_dir_blocks = 0;
2079 +
2080 +                // Determine file type and fill in image_file_desc structure
2081 +                image_file_desc desc;
2082 +                if (!parse_image_file(f, desc))
2083 +                        goto done;
2084 +
2085 +                // Scan all directory blocks
2086 +                uint8 dir[256];
2087 +                dir[DIR_NEXT_TRACK] = DIR_TRACK;
2088 +                dir[DIR_NEXT_SECTOR] = 1;
2089 +
2090 +                while (dir[DIR_NEXT_TRACK] && num_dir_blocks < num_sectors[DIR_TRACK]) {
2091 +                        if (read_sector(f, desc, dir[DIR_NEXT_TRACK], dir[DIR_NEXT_SECTOR], dir) != ERR_OK)
2092 +                                break;
2093 +                        num_dir_blocks++;
2094 +
2095 +                        // Scan all 8 entries of a block
2096 +                        uint8 *de = dir + DIR_ENTRIES;
2097 +                        for (int j=0; j<8; j++, de+=SIZEOF_DE) {
2098 +
2099 +                                // Skip empty entries
2100 +                                if (de[DE_TYPE] == 0)
2101 +                                        continue;
2102 +
2103 +                                // Convert file name (strip everything after and including the first trailing space)
2104 +                                uint8 name_buf[17];
2105 +                                memcpy(name_buf, de + DE_NAME, 16);
2106 +                                name_buf[16] = 0;
2107 +                                uint8 *p = (uint8 *)memchr(name_buf, 0xa0, 16);
2108 +                                if (p)
2109 +                                        *p = 0;
2110 +
2111 +                                // Convert file type
2112 +                                int type = de[DE_TYPE] & 7;
2113 +                                if (type > 4)
2114 +                                        type = FTYPE_UNKNOWN;
2115 +
2116 +                                // Read start address
2117 +                                uint8 sa_lo = 0, sa_hi = 0;
2118 +                                uint8 buf[256];
2119 +                                if (read_sector(f, desc, de[DE_TRACK], de[DE_SECTOR], buf) == ERR_OK) {
2120 +                                        sa_lo = buf[2];
2121 +                                        sa_hi = buf[3];
2122 +                                }
2123 +
2124 +                                // Add entry
2125 +                                vec.push_back(c64_dir_entry(name_buf, type, !(de[DE_TYPE] & 0x80), de[DE_TYPE] & 0x40, ((de[DE_NUM_BLOCKS_H] << 8) + de[DE_NUM_BLOCKS_L]) * 254, 0, sa_lo, sa_hi));
2126 +                        }
2127 +                }
2128 +
2129 +                result = true;
2130 + done:   fclose(f);
2131 +        }
2132 +        return result;
2133 + }
2134 +
2135 +
2136   /*
2137   *  Create new blank disk image file, returns false on error
2138   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines