char * memory = new char[0xFFFF];
int readmemory_long(int pointer)
{
unsigned int r_pointer = pointer - 0xA4000000; //converts given pointer to the array address
if (r_pointer > 0x1FFFFF) return 0;
return ntohl(memory[r_pointer]); //ntohl(), converts data to little endian (I hope :P) issue here
// I want to get the 32 bit value at this address
}
void writememory_long(int pointer, int data)
{
unsigned int r_pointer = pointer - 0xA4000000;
if (r_pointer > 0x1FFFFF) return;
memory[r_pointer] = htonl(data); //converts data to big endian: same issue
}
I was considering using for loops, but that could be kinda tricky. Any ideas/examples would be smiled upon :)
char * memory = new char[0xFFFF];
int readmemory_long(int pointer)
{
unsigned int r_pointer = pointer - 0xA4000000;
if (r_pointer > 0x1FFFFF) return 0;
int temp = int(memory[r_pointer]) * 0x1000000;
temp |= int(memory[r_pointer + 1]) * 0x10000;
temp |= int(memory[r_pointer + 2]) * 0x100;
temp |= int(memory[r_pointer + 3]);
return ntohl(temp);
}
short readmemory_word(int pointer)
{
unsigned int r_pointer = pointer - 0xA4000000;
if (r_pointer > 0x1FFFFF) return 0;
short temp = short(memory[r_pointer]) * 0x100;
temp |= short(memory[r_pointer + 1]);
return ntohs(temp);
}
70 01 71 01 8B FD FF FE
PC = 0xA4000000;
ifstream program("spectrum.data", ios::in|ios::binary);
if(!program.is_open())
{
cout << "Error opening spectrum.data";
cin.get();
return -1;
}
program.seekg(0, ios::beg);
int program_counter;
char buffer;
program.read(&buffer, 1);
int prog_index;
while(program.good())
{
writememory_byte(prog_index + 0xA4000000, buffer);
prog_index++;
program.seekg(prog_index);
program.read(&buffer, 1);
}
So for the first instruction I should be getting a value of $7001, but I get the 3d44 instead. In the other code block I have the code for reading the input file, but I don't believe there is any error there.
int temp = int(memory[r_pointer]) * 0x1000000;If you read the integer byte-by-byte, with the multipliers being for big-endian, then it's already correct and you don't need to use ntohl.
temp |= int(memory[r_pointer + 1]) * 0x10000;
temp |= int(memory[r_pointer + 2]) * 0x100;
temp |= int(memory[r_pointer + 3]);
return ntohl(temp);
program >> hex;
int buffer;
program >> buffer;
int prog_index = 0;
while(program.good())
{
writememory_byte(prog_index + 0xA4000000, buffer);
prog_index++;
program >> buffer;
}
Goplat, if it's parsing "70" to the ASCII codes 0x37 and 0x30, then "01" would read 0x3031, not 0x3001. 0x01 is a non-printable ASCII control character.Right, that was a typo, sorry :(
if (ADD_v == instruction & ADD_v)
ADD();
else if (MOVi_v == instruction & MOVi_v)
MOVi();
else if (ADDi_v == instruction & ADDi_v)
ADDi();
else if (MOVLi_v == instruction & MOVLi_v)
MOVLi();
You might recognize these as SH3 opcodes.(don't worry there are many more in my code) The first instruction in memory is $7001 aka ADD $01,R0. Now I have a debug statement right after data is loaded into instruction and that reads $7001 as expected. Now this instruction is represented by ADDi_v which is defined earlier as $7000. So if I do $7001 & $7000, I should get $7000 which would equal ADDi_v. But my program doesn't seem to respond to this for some reason.