ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/xpram_windows.cpp
Revision: 1.4
Committed: 2009-07-23T19:19:13Z (15 years, 3 months ago) by asvitkine
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
Log Message:
BasiliskII side of changes to support .sheepvm bundles for SheepShaver

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * xpram_windows.cpp - XPRAM handling, Windows specific stuff
3     *
4 gbeauche 1.3 * Basilisk II (C) 1997-2008 Christian Bauer
5 gbeauche 1.1 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include "sysdeps.h"
22    
23     #define WIN32_LEAN_AND_MEAN
24     #include <windows.h>
25    
26     #include <string>
27     using std::string;
28    
29     #include "xpram.h"
30    
31    
32     // XPRAM file name and path
33     #if POWERPC_ROM
34     const char XPRAM_FILE_NAME[] = "SheepShaver_nvram.dat";
35     #else
36     const char XPRAM_FILE_NAME[] = "BasiliskII_xpram.dat";
37     #endif
38     static string xpram_path;
39    
40    
41     /*
42     * Construct XPRAM path
43     */
44    
45     static void build_xpram_path(void)
46     {
47     xpram_path.clear();
48     int pwd_len = GetCurrentDirectory(0, NULL);
49     char *pwd = new char[pwd_len];
50     if (GetCurrentDirectory(pwd_len, pwd) == pwd_len - 1)
51     xpram_path = string(pwd) + '\\';
52     delete[] pwd;
53     xpram_path += XPRAM_FILE_NAME;
54     }
55    
56    
57     /*
58     * Load XPRAM from settings file
59     */
60    
61 asvitkine 1.4 void LoadXPRAM(const char *vmdir)
62 gbeauche 1.1 {
63     // Construct XPRAM path
64     build_xpram_path();
65    
66     // Load XPRAM from settings file
67     HANDLE fh = CreateFile(xpram_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
68     if (fh != INVALID_HANDLE_VALUE) {
69     DWORD bytesRead;
70     ReadFile(fh, XPRAM, XPRAM_SIZE, &bytesRead, NULL);
71     CloseHandle(fh);
72     }
73     }
74    
75    
76     /*
77     * Save XPRAM to settings file
78     */
79    
80     void SaveXPRAM(void)
81     {
82     HANDLE fh = CreateFile(xpram_path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
83     if (fh != INVALID_HANDLE_VALUE) {
84     DWORD bytesWritten;
85     WriteFile(fh, XPRAM, XPRAM_SIZE, &bytesWritten, NULL);
86     CloseHandle(fh);
87     }
88     }
89    
90    
91     /*
92     * Delete PRAM file
93     */
94    
95     void ZapPRAM(void)
96     {
97     // Construct PRAM path
98     build_xpram_path();
99    
100     // Delete file
101     DeleteFile(xpram_path.c_str());
102     }