Fix two signed/unsigned mismatch warnings.

Also tidied up SDCardUtil - made the variables make more sense (typewise)
This commit is contained in:
Lioncash 2013-01-11 19:38:04 -05:00
parent 104f5a4699
commit dfc0c4b08d
2 changed files with 52 additions and 52 deletions

View file

@ -40,7 +40,7 @@
#include <unistd.h> // for unlink()
#endif
/* believe me, you *don't* want to change these constants !! */
/* Believe me, you *don't* want to change these constants !! */
#define BYTES_PER_SECTOR 512
#define RESERVED_SECTORS 32
#define BACKUP_BOOT_SECTOR 6
@ -52,15 +52,15 @@
#define POKES(p,v) ( BYTE_(p,0) = (u8)(v), BYTE_(p,1) = (u8)((v) >> 8) )
#define POKEW(p,v) ( BYTE_(p,0) = (u8)(v), BYTE_(p,1) = (u8)((v) >> 8), BYTE_(p,2) = (u8)((v) >> 16), BYTE_(p,3) = (u8)((v) >> 24) )
static u8 s_boot_sector [ BYTES_PER_SECTOR ]; /* boot sector */
static u8 s_boot_sector [ BYTES_PER_SECTOR ]; /* Boot sector */
static u8 s_fsinfo_sector [ BYTES_PER_SECTOR ]; /* FS Info sector */
static u8 s_fat_head [ BYTES_PER_SECTOR ]; /* first FAT sector */
static u8 s_fat_head [ BYTES_PER_SECTOR ]; /* First FAT sector */
/* this is the date and time when creating the disk */
static int get_serial_id()
/* This is the date and time when creating the disk */
static unsigned int get_serial_id()
{
u16 lo, hi;
time_t now = time(NULL);
time_t now = time(nullptr);
struct tm tm = gmtime( &now )[0];
lo = (u16)(tm.tm_mday + ((tm.tm_mon+1) << 8) + (tm.tm_sec << 8));
@ -69,7 +69,7 @@ static int get_serial_id()
return lo + (hi << 16);
}
static int get_sectors_per_cluster(u64 disk_size)
static unsigned int get_sectors_per_cluster(u64 disk_size)
{
u64 disk_MB = disk_size/(1024*1024);
@ -88,60 +88,60 @@ static int get_sectors_per_cluster(u64 disk_size)
return 32;
}
static int get_sectors_per_fat(u64 disk_size, int sectors_per_cluster)
static unsigned int get_sectors_per_fat(u64 disk_size, u32 sectors_per_cluster)
{
u64 divider;
/* weird computation from MS - see fatgen103.doc for details */
disk_size -= RESERVED_SECTORS * BYTES_PER_SECTOR; /* don't count 32 reserved sectors */
disk_size /= BYTES_PER_SECTOR; /* disk size in sectors */
/* Weird computation from MS - see fatgen103.doc for details */
disk_size -= RESERVED_SECTORS * BYTES_PER_SECTOR; /* Don't count 32 reserved sectors */
disk_size /= BYTES_PER_SECTOR; /* Disk size in sectors */
divider = ((256 * sectors_per_cluster) + NUM_FATS) / 2;
return (int)( (disk_size + (divider-1)) / divider );
return (u32)( (disk_size + (divider-1)) / divider );
}
static void boot_sector_init(u8* boot, u8* info, u64 disk_size, const char* label)
{
int sectors_per_cluster = get_sectors_per_cluster(disk_size);
int sectors_per_fat = get_sectors_per_fat(disk_size, sectors_per_cluster);
int sectors_per_disk = (int)(disk_size / BYTES_PER_SECTOR);
int serial_id = get_serial_id();
int free_count;
u32 sectors_per_cluster = get_sectors_per_cluster(disk_size);
u32 sectors_per_fat = get_sectors_per_fat(disk_size, sectors_per_cluster);
u32 sectors_per_disk = (u32)(disk_size / BYTES_PER_SECTOR);
u32 serial_id = get_serial_id();
u32 free_count;
if (label == NULL)
if (label == nullptr)
label = "DOLPHINSD";
POKEB(boot, 0xeb);
POKEB(boot+1, 0x5a);
POKEB(boot+2, 0x90);
strcpy( (char*)boot + 3, "MSWIN4.1" );
POKES( boot + 0x0b, BYTES_PER_SECTOR ); /* sector size */
POKEB( boot + 0xd, sectors_per_cluster ); /* sectors per cluster */
POKES( boot + 0xe, RESERVED_SECTORS ); /* reserved sectors before first FAT */
POKEB( boot + 0x10, NUM_FATS ); /* number of FATs */
POKES( boot + 0x11, 0 ); /* max root directory entries for FAT12/FAT16, 0 for FAT32 */
POKES( boot + 0x13, 0 ); /* total sectors, 0 to use 32-bit value at offset 0x20 */
POKEB( boot + 0x15, 0xF8 ); /* media descriptor, 0xF8 == hard disk */
POKES( boot + 0x0b, BYTES_PER_SECTOR ); /* Sector size */
POKEB( boot + 0xd, sectors_per_cluster ); /* Sectors per cluster */
POKES( boot + 0xe, RESERVED_SECTORS ); /* Reserved sectors before first FAT */
POKEB( boot + 0x10, NUM_FATS ); /* Number of FATs */
POKES( boot + 0x11, 0 ); /* Max root directory entries for FAT12/FAT16, 0 for FAT32 */
POKES( boot + 0x13, 0 ); /* Total sectors, 0 to use 32-bit value at offset 0x20 */
POKEB( boot + 0x15, 0xF8 ); /* Media descriptor, 0xF8 == hard disk */
POKES( boot + 0x16, 0 ); /* Sectors per FAT for FAT12/16, 0 for FAT32 */
POKES( boot + 0x18, 9 ); /* Sectors per track (whatever) */
POKES( boot + 0x1a, 2 ); /* Number of heads (whatever) */
POKEW( boot + 0x1c, 0 ); /* Hidden sectors */
POKEW( boot + 0x20, sectors_per_disk ); /* Total sectors */
/* extension */
/* Extension */
POKEW( boot + 0x24, sectors_per_fat ); /* Sectors per FAT */
POKES( boot + 0x28, 0 ); /* FAT flags */
POKES( boot + 0x2a, 0 ); /* version */
POKEW( boot + 0x2c, 2 ); /* cluster number of root directory start */
POKES( boot + 0x30, 1 ); /* sector number of FS information sector */
POKES( boot + 0x32, BACKUP_BOOT_SECTOR ); /* sector number of a copy of this boot sector */
POKEB( boot + 0x40, 0x80 ); /* physical drive number */
POKEB( boot + 0x42, 0x29 ); /* extended boot signature ?? */
POKEW( boot + 0x43, serial_id ); /* serial ID */
POKES( boot + 0x2a, 0 ); /* Version */
POKEW( boot + 0x2c, 2 ); /* Cluster number of root directory start */
POKES( boot + 0x30, 1 ); /* Sector number of FS information sector */
POKES( boot + 0x32, BACKUP_BOOT_SECTOR ); /* Sector number of a copy of this boot sector */
POKEB( boot + 0x40, 0x80 ); /* Physical drive number */
POKEB( boot + 0x42, 0x29 ); /* Extended boot signature ?? */
POKEW( boot + 0x43, serial_id ); /* Serial ID */
strncpy( (char*)boot + 0x47, label, 11 ); /* Volume Label */
memcpy( boot + 0x52, "FAT32 ", 8 ); /* FAT system type, padded with 0x20 */
POKEB( boot + BYTES_PER_SECTOR-2, 0x55 ); /* boot sector signature */
POKEB( boot + BYTES_PER_SECTOR-2, 0x55 ); /* Boot sector signature */
POKEB( boot + BYTES_PER_SECTOR-1, 0xAA );
/* FSInfo sector */
@ -149,25 +149,25 @@ static void boot_sector_init(u8* boot, u8* info, u64 disk_size, const char* labe
POKEW( info + 0, 0x41615252 );
POKEW( info + 484, 0x61417272 );
POKEW( info + 488, free_count ); /* number of free clusters */
POKEW( info + 492, 3 ); /* next free clusters, 0-1 reserved, 2 is used for the root dir */
POKEW( info + 488, free_count ); /* Number of free clusters */
POKEW( info + 492, 3 ); /* Next free clusters, 0-1 reserved, 2 is used for the root dir */
POKEW( info + 508, 0xAA550000 );
}
static void fat_init(u8* fat)
{
POKEW( fat, 0x0ffffff8 ); /* reserve cluster 1, media id in low byte */
POKEW( fat + 4, 0x0fffffff ); /* reserve cluster 2 */
POKEW( fat + 8, 0x0fffffff ); /* end of clust chain for root dir */
POKEW( fat, 0x0ffffff8 ); /* Reserve cluster 1, media id in low byte */
POKEW( fat + 4, 0x0fffffff ); /* Reserve cluster 2 */
POKEW( fat + 8, 0x0fffffff ); /* End of cluster chain for root dir */
}
static int write_sector(FILE* file, u8* sector)
static unsigned int write_sector(FILE* file, u8* sector)
{
return fwrite(sector, 1, 512, file) != 512;
}
static int write_empty(FILE* file, u64 count)
static unsigned int write_empty(FILE* file, u64 count)
{
static u8 empty[64*1024];
@ -188,8 +188,8 @@ static int write_empty(FILE* file, u64 count)
bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
{
int sectors_per_fat;
int sectors_per_disk;
u32 sectors_per_fat;
u32 sectors_per_disk;
FILE* f;
// Convert MB to bytes
@ -200,21 +200,21 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
return false;
}
// pretty unlikely to overflow.
sectors_per_disk = (int)(disk_size / 512);
// Pretty unlikely to overflow.
sectors_per_disk = (u32)(disk_size / 512);
sectors_per_fat = get_sectors_per_fat(disk_size, get_sectors_per_cluster(disk_size));
boot_sector_init(s_boot_sector, s_fsinfo_sector, disk_size, NULL );
boot_sector_init(s_boot_sector, s_fsinfo_sector, disk_size, nullptr);
fat_init(s_fat_head);
f = fopen(filename, "wb");
if (!f)
{
ERROR_LOG(COMMON, "could not create file '%s', aborting...\n", filename);
ERROR_LOG(COMMON, "Could not create file '%s', aborting...\n", filename);
return false;
}
/* here's the layout:
/* Here's the layout:
*
* boot_sector
* fsinfo_sector
@ -251,7 +251,7 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
return true;
FailWrite:
ERROR_LOG(COMMON, "could not write to '%s', aborting...\n", filename);
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename);
if (unlink(filename) < 0)
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename, GetLastErrorMsg());
fclose(f);

View file

@ -28,7 +28,7 @@
#include "NativeVertexFormat.h"
static void StageHash(int stage, u32* out)
static void StageHash(u32 stage, u32* out)
{
out[0] |= bpmem.combiners[stage].colorC.hex & 0xFFFFFF; // 24
u32 alphaC = bpmem.combiners[stage].alphaC.hex & 0xFFFFF0; // 24, strip out tswap and rswap for now
@ -141,7 +141,7 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 compo
}
u32* ptr = &uid->values[2];
for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i)
for (unsigned int i = 0; i < bpmem.genMode.numtevstages+1; ++i)
{
StageHash(i, ptr);
ptr += 4; // max: ptr = &uid->values[66]
@ -204,7 +204,7 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u
*ptr++ = bpmem.tevindref.hex; // 31
for (int i = 0; i < bpmem.genMode.numtevstages+1; ++i) // up to 16 times
for (unsigned int i = 0; i < bpmem.genMode.numtevstages+1; ++i) // up to 16 times
{
*ptr++ = bpmem.combiners[i].colorC.hex; // 32+5*i
*ptr++ = bpmem.combiners[i].alphaC.hex; // 33+5*i