Unsigned char array to string?

I'm working on an NES emulator and am testing my CPU core. The test I am using outputs the test results to RAM addresses 0x6000-0x7FFF. My RAM array is of type unsigned char. Currently, I'm using memchr to try and output the data with mixed results. Sometimes I get text output, and sometimes I just get blank spaces. When I get blank spaces as output, I check my hex dump of the addresses and use an online hex to string calculator to see if there is actually nothing being outputted. My dump always says that I should be outputting something, so I know I'm doing something wrong.

This is my current code for text output. I'm sure it's not working right since memchr returns a pointer to the string terminator (0x0A in this test), and I'm not really sure how to output text from that pointer.
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
  void memory::dump()
{
	bool stringEnd = false, stringStart = false;
	unsigned char temp[0x3FF];
	int tempCounter = 0;
	char* text;


	for(int i = 0x6000; i < 0x8000; i++)
	{
		if(RAM[i] != 0)
		{
			temp[tempCounter++] = RAM[i];
			stringStart = true;
		}

		if(stringStart)
		{
			if(RAM[i] == 0)
			{
				temp[tempCounter++] = RAM[i];
				stringEnd = true;
			}
		}

		if(stringEnd)
		{
			for(int q = 0; q < tempCounter; q++)
				debug << std::hex << std::uppercase << (int)temp[q] << std::endl;

			debug << "NEW STRING" << std::endl;
			text = (char*) memchr(temp, 0x0A, tempCounter);
			std::cout << text << std::endl;
			stringEnd = stringStart = false;
			tempCounter = 0;
		}
	}
}
Bump...
As for me I do not understand what you are trying to do. For example why are you sure that value 0x0A must be in the array.
Because the test I am using uses 0x0A as a null character (or at least that's what the creator of the test said in a thread). The test ALWAYS outputs something - if it fails, it outputs the opcodes that failed, and if it passed, it outputs "passed". However, the text can be spread out over the entire address range, so I needed to scan the entire 0x2000 area of address space for output text.

From the test readme:

All text output is written starting at $6004, with a zero-byte
terminator at the end. As more text is written, the terminator is moved
forward, so an emulator can print the current text at any time.

The test status is written to $6000. $80 means the test is running, $81
means the test needs the reset button pressed, but delayed by at least
100 msec from now. $00-$7F means the test has completed and given that
result code.

To allow an emulator to know when one of these tests is running and the
data at $6000+ is valid, as opposed to some other NES program, $DE $B0
$G1 is written to $6001-$6003.
Last edited on
Topic archived. No new replies allowed.