The above video goes away if you are a member and logged in, so log in now!
|
| |
Would you like to get all the new info from PSX-Scene in your email each day?
| |
|
-
#1
Something new on it's way but need help:
Something new on it's way but need help: –
04-01-2004,10:16 AM
I'm writing something in C++ but it kind of needs error compensation in it to work. It (hexByte) allocates a new line of code for every carrage return that is input. It then skips past any spaces and adds the next hex char to the byte array. If it finds that only part of a line has been entered (ie less than 8 bytes in a particular line) it is supposed to fill in the gaps with zeros but I can't figure out. I wanted to do this all by myself but I'm in a hurry as I won't have access to MSVC++ from tommorrow until after the easter holidays. Anyone who helps will be given credit when the device is completed.
long hexByte() {
Code* codes = new Code[1];
u8 currentByte = 0, firstC = 1;
u16 index = 0, bArrIndex = 0, thisLine = 0;
withoutNulls = 0;
for (index; index<(strlen(inputC)); index++) {
if ((strlen(inputC) > 0) && (isalnum(inputC[index])) &&
(firstC == 1)) { // Is there at least 1 char?
withoutNulls += 16; // Allocate a line
firstC = 0; // 1st char found
}
if ((strlen(inputC) > 1) && (index<(strlen(inputC))-1) &&
(inputC[index] == '\n') && (isalnum(inputC[index+1]))) {
// Need to add "or" statement to include remainder 16
// Is there a new line of Code?
withoutNulls += 16; // Allocate a new line
}
}
// Need loop to store size and position of codes.
byteArray = new u8[withoutNulls>>1];
index=0;
for (bArrIndex=0; index<strlen(inputC);) {
// Fill with zeros
if ((inputC[index] == '\r') | (inputC[index] == '\n')) {
for (;thisLine < 7; thisLine++)
byteArray[bArrIndex] = 0;
bArrIndex++;
}
while (isspace(inputC[index])) {index++;}
if ((inputC[index] >= 'a') & (inputC[index] <= 'f')) {
currentByte = ((inputC[index] - 'a' + 10)<<4);
}
else if ((inputC[index] >= 'A') & (inputC[index] <= 'F')) {
currentByte = ((inputC[index] - 'A' + 10)<<4);
}
else if ((inputC[index] >= '0') & (inputC[index] <= '9')) {
currentByte = ((inputC[index] - '0')<<4);
}
else {
currentByte = 0;
}
index++;
while (isspace(inputC[index])) {index++;}
if ((inputC[index] >= 'a') & (inputC[index] <= 'f')) {
currentByte += (inputC[index] - 'a' + 10);
}
else if ((inputC[index] >= 'A') & (inputC[index] <= 'F')) {
currentByte += (inputC[index] - 'A' + 10);
}
else if ((inputC[index] >= '0') & (inputC[index] <= '9')) {
currentByte += (inputC[index] - '0');
}
else {
currentByte += 0; // Will add 0 even if there is a new line.
}
index++;
byteArray[bArrIndex] = currentByte;
if (thisLine < 7) {thisLine++;}
else {thisLine = 0;}
bArrIndex++;
}
/*byteArray = new u8[8];
byteArray[0] = 0xBB;
byteArray[1] = 0xAA;
byteArray[2] = 0xAA;
byteArray[3] = 0xAA;
byteArray[4] = 0xFF;
byteArray[5] = 0xFF;
byteArray[6] = 0xFF;
byteArray[7] = 0xFF;
byteArray[8] = 0xDD;
byteArray[9] = 0xCC;
byteArray[10] = 0xCC;
byteArray[11] = 0xCC;
byteArray[12] = 0x22;
byteArray[13] = 0x22;
byteArray[14] = 0x22;
byteArray[15] = 0x22;
withoutNulls = 32;*/
return bArrIndex;
}
// Now to test hexByte and I'm making progress!
long byteHex() {
outputC = new char[19 * (withoutNulls>>4)];
u8 char0 = 0, char1 = 0, char2 = 0;
u32 index2 = 0;
for (u32 index = 0; index < (withoutNulls>>1); index += lineLength) {
for (u32 charNo = 0; charNo < lineLength; charNo++) {
char0 = byteArray[index + charNo];
char1 = char0 >> 4;
char2 = char0 &= 0x0F;
outputC[index2] = hexValues[char1];
index2++;
outputC[index2] = hexValues[char2];
index2++;
if (charNo == 3) {
outputC[index2] = ' ';
index2++;
}
if (charNo == 7) {
outputC[index2] = '\r';
index2++;
outputC[index2] = '\n';
index2++;
}
}
// outputC[index2] = '\n';
}
outputC[19 * (withoutNulls>>4)] = '\0';
return 19 * (withoutNulls>>4); // This part's just for testing.
}
EDIT: This improved it a little:
byteArray = new u8[withoutNulls>>1];
index=0;
for (bArrIndex=0; index<strlen(inputC);) {
// Fill with zeros
if ((inputC[index] == '\r') & (thisLine > 0)) { // \r !!!
currentByte = 0;
}
else {
while (isspace(inputC[index])) {index++;}
if ((inputC[index] >= 'a') & (inputC[index] <= 'f')) {
currentByte = ((inputC[index] - 'a' + 10)<<4);
}
Last edited by Vampmaster; 04-01-2004 at 12:18 PM.
-
04-02-2004,10:15 AM
Nevermind, I got it working!
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|