-
Notifications
You must be signed in to change notification settings - Fork 3
/
bkWrite7x.c
116 lines (90 loc) · 3.07 KB
/
bkWrite7x.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/******************************* LICENCE **************************************
* Any code in this file may be redistributed or modified under the terms of
* the GNU General Public Licence as published by the Free Software
* Foundation; version 2 of the licence.
****************************** END LICENCE ***********************************/
/******************************************************************************
* Author:
* Andrew Smith, http://littlesvr.ca/misc/contactandrew.php
*
* Contributors:
*
******************************************************************************/
/******************************************************************************
* Functions in this file write to volInfo.imageForWriting and are probably
* unsutable for anything else, except for the ones that write to arrays.
******************************************************************************/
#include "bkInternal.h"
#include "bkWrite7x.h"
#include "bkCache.h"
#include "bkError.h"
int write711(VolInfo* volInfo, unsigned char value)
{
return wcWrite(volInfo, (char*)&value, 1);
}
int write721(VolInfo* volInfo, unsigned short value)
{
unsigned char preparedValue[2];
write721ToByteArray(preparedValue, value);
return wcWrite(volInfo, (char*)preparedValue, 2);
}
void write721ToByteArray(unsigned char* dest, unsigned short value)
{
dest[0] = value & 0xFF;
dest[1] = (value >> 8) & 0xFF;
}
int write722(VolInfo* volInfo, unsigned short value)
{
char preparedValue[2];
preparedValue[0] = (value >> 8) & 0xFF;
preparedValue[1] = value & 0xFF;
return wcWrite(volInfo, preparedValue, 2);
}
int write723(VolInfo* volInfo, unsigned short value)
{
char preparedValue[4];
preparedValue[0] = value & 0xFF;
preparedValue[1] = (value >> 8) & 0xFF;
preparedValue[2] = preparedValue[1];
preparedValue[3] = preparedValue[0];
return wcWrite(volInfo, preparedValue, 4);
}
int write731(VolInfo* volInfo, unsigned value)
{
unsigned char preparedValue[4];
write731ToByteArray(preparedValue, value);
return wcWrite(volInfo, (char*)preparedValue, 4);
}
void write731ToByteArray(unsigned char* dest, unsigned value)
{
dest[0] = value & 0xFF;
dest[1] = (value >> 8) & 0xFF;
dest[2] = (value >> 16) & 0xFF;
dest[3] = value >> 24;
}
int write732(VolInfo* volInfo, unsigned value)
{
char preparedValue[4];
preparedValue[0] = (value >> 24);
preparedValue[1] = (value >> 16) & 0xFF;
preparedValue[2] = (value >> 8) & 0xFF;
preparedValue[3] = value & 0xFF;
return wcWrite(volInfo, preparedValue, 4);
}
int write733(VolInfo* volInfo, unsigned value)
{
char preparedValue[8];
write733ToByteArray((unsigned char*)preparedValue, value);
return wcWrite(volInfo, preparedValue, 8);
}
void write733ToByteArray(unsigned char* dest, unsigned value)
{
dest[0] = value & 0xFF;
dest[1] = (value >> 8) & 0xFF;
dest[2] = (value >> 16) & 0xFF;
dest[3] = value >> 24;
dest[4] = dest[3];
dest[5] = dest[2];
dest[6] = dest[1];
dest[7] = dest[0];
}