source: xtideuniversalbios/trunk/Serial_Server/win32/Win32File.h@ 597

Last change on this file since 597 was 589, checked in by Krister Nordvall, 8 years ago

Changes:

  • BIOS: Fixed a purely cosmetic bug from r542 where, in builds containing MODULE_EBIOS, the boot menu would display an incorrect drive size (0.4 kB with MODULE_STRINGS_COMPRESSED or 0.5 kB without) for old drives with no support for LBA.
  • Fixed a bug from r392 where Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent would return the ID in AL instead of AH (if DANGEROUS_DETECTION had been defined).
  • Fixed a bug from r587 in AdvAtaInit.asm that would prevent detection of QDI Vision controllers.
  • Also changed how the QDI Vision IDs are defined (removed the need for shifting) to avoid confusion. This fixed a potential bug from r587 in AdvAtaInit.asm where some IDs were not being shifted.
  • Fixed a bug in PDC20x30.asm from r587 where GetPdcIDtoAX would not return with the IDE base port in DX so DisablePdcProgrammingMode would fail.
  • Made some changes to ModuleDependency.inc and other files so that MODULE_ADVANCED_ATA now requires USE_386. Consequently it is no longer included in the regular AT-builds, only in the 386_8k-build.
  • Moved the UNROLL_SECTORS_IN_CX_TO_xWORDS macros from IDE_8bit.inc to IdeIO.inc which means it's now possible to build a BIOS without MODULE_8BIT_IDE.
  • XTIDECFG: Added a minimum DOS version check (since it needs DOS version 2+) to allow the program to quit gracefully in the unlikely scenario where someone tries to run it under DOS version 1.
  • Made some changes to Drive.asm to improve drive enumeration. The old method using GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE worked well in Windows XP but not in Windows 98 SE (in Windows or in DOS mode). The two problems were; 1) The function call would access the drives which on single floppy drive systems would cause Windows to swap between A: and B: (throwing a blue screen asking the user to insert a disk etc). 2) Only floppy drives and FAT16 drives would be available in the list of drives, no FAT32/optical/network drives.
  • Improved code in IdeControllerMenu.asm so that the default port addresses for all IDE interfaces are now restored when (re-)selecting the (same) type of IDE device.
  • Also made it impossible to select a device type unless the required module is included in the loaded BIOS.
  • The version check done when loading a BIOS now uses the FLASH_SIGNATURE definition from Version.inc. Any changes affecting RomVars now only requires updating that definition. This means that changes to RomVars must be implemented in both the BIOS and XTIDECFG before being committed to the repository.
  • Added a compatibility fix for 3Com 3C503 cards to the ROM checksumming code in Buffers.asm (Buffers_GenerateChecksum).
  • SerDrive: Made some minor changes to file names and paths to improve compatibility with case sensitive environments.
  • BIOSDRVS: Made a minor size optimization which as a side effect also makes it compatible with all DOS versions including DOS version 1.
  • Library: Renamed the WAIT_RETRACE_IF_NECESSARY_THEN macro to CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN and made a tail-call-optimized version of it (JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN).
  • A speed optimization to the eRCL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Other minor optimizations and fixes.
File size: 3.5 KB
Line 
1//======================================================================
2//
3// Project: XTIDE Universal BIOS, Serial Port Server
4//
5// File: Win32File.h - Microsoft Windows file system access.
6//
7// Routines for accessing the file system under Win32. It's important
8// to use these direct Win32 calls for large files, since FILE * routines,
9// in particular ftell() and fseek(), are limited to signed 32-bits (2 GB).
10// These are also likely faster since they are more direct.
11//
12
13//
14// XTIDE Universal BIOS and Associated Tools
15// Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
16//
17// This program is free software; you can redistribute it and/or modify
18// it under the terms of the GNU General Public License as published by
19// the Free Software Foundation; either version 2 of the License, or
20// (at your option) any later version.
21//
22// This program is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26// Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
27//
28
29#include <windows.h>
30#include <stdio.h>
31#include "../library/Library.h"
32
33class FileAccess
34{
35public:
36 int Create( char *p_name )
37 {
38 fp = CreateFileA( p_name, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
39
40 if( fp == INVALID_HANDLE_VALUE )
41 {
42 if( GetLastError() == ERROR_FILE_EXISTS )
43 {
44 log( 0, "'%s', file already exists", p_name );
45 return( 0 );
46 }
47 else
48 log( -1, "'%s', could not create file", p_name );
49 }
50
51 name = p_name;
52
53 return( 1 );
54 }
55
56 void Open( char *p_name )
57 {
58 fp = CreateFileA( p_name, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
59
60 if( fp == INVALID_HANDLE_VALUE )
61 log( -1, "'%s', could not open file", p_name );
62
63 name = p_name;
64 }
65
66 void Close()
67 {
68 if( fp )
69 {
70 if( !CloseHandle( fp ) )
71 log( 0, "'%s', could not close file handle", name ? name : "unknown" );
72 }
73 }
74
75 unsigned long SizeSectors(void)
76 {
77 LARGE_INTEGER li;
78 unsigned long i;
79
80 if( !GetFileSizeEx( fp, &li ) )
81 log( -1, "'%s', could not retrieve file size (error %ul)", name, GetLastError() );
82
83 if( li.LowPart & 0x1ff )
84 log( -1, "'%s', file size is not a multiple of 512 byte sectors", name );
85
86 if( li.HighPart > 0x1f )
87 log( -1, "'%s', file size greater than LBA28 limit of 137,438,952,960 bytes", name );
88
89 i = ((li.HighPart << 23 ) & 0xff800000) | ((li.LowPart >> 9) & 0x7fffff);
90
91 return( (unsigned long) i );
92 }
93
94 void SeekSectors( unsigned long lba )
95 {
96 LARGE_INTEGER dist;
97
98 dist.HighPart = lba >> 23;
99 dist.LowPart = lba << 9;
100
101 if( !SetFilePointerEx( fp, dist, NULL, FILE_BEGIN ) )
102 log( -1, "'%s', Failed to seek to lba=%lu", name, lba );
103 }
104
105 void Read( void *buff, unsigned long len )
106 {
107 unsigned long out_len;
108
109 if( !ReadFile( fp, buff, len, &out_len, NULL ) || len != out_len )
110 log( -1, "'%s', ReadFile failed", name );
111 }
112
113 void Write( void *buff, unsigned long len )
114 {
115 unsigned long out_len;
116
117 if( !WriteFile( fp, buff, len, &out_len, NULL ) || len != out_len )
118 log( -1, "'%s', WriteFile failed", name );
119 }
120
121 FileAccess()
122 {
123 fp = NULL;
124 name = NULL;
125 }
126
127 // LBA 28 limit - 28-bits (could be 1 more, but not worth pushing it)
128 const static unsigned long MaxSectors = 0xfffffff;
129#define USAGE_MAXSECTORS "137438 MB (LBA28 limit)"
130
131private:
132 HANDLE fp;
133 char *name;
134};
135
Note: See TracBrowser for help on using the repository browser.