The “system registers” on the VB’s CPU represent features of the architecture not directly pertinent to the program being executed. The status register is found in here, as are some other things like exception processing and the hardware breakpoint.
Let’s see, it was… three and a half years ago now… I discovered the presence of three more system registers by typing in undocumented register numbers just to see what would happen. Indexes 29, 30 and 31 do not correspond to any system registers in the V810 documentation, but they do respond to probing on Virtual Boy.
At the time, it appeared that system register 31 was just a solitary flag. My tests were quite simple: write 0xFFFFFFFF to a system register, then read the value back to see if it can be written. System register 31 told me 0x00000001, and when I wrote a zero, it gave me a zero back. That looks like a 1-bit register to me. I don’t blame my past self for jumping to that conclusion.
While researching for the emulator initiative, I decided to test multiple values on all of the system registers just in case, and 31 was behaving unexpectedly. Not only was it not a 1-bit register, but it has an actual function!
System register 31’s secret powers are…
Drum roll please…
Wait for it…
It calculates the absolute value of the number you write to it. Like, you write a 32-bit two’s-complement number and when you read from it, you get that number’s absolute value. Yeah, that’s all. Nothing fancy, but certainly interesting!
Turns out that 0xFFFFFFFF is the two’s complement representation of -1, so writing that value to system register 31 gives me a positive 1 in return. And writing a zero, well, gives back a zero. It tricked me and went under the radar for years after I thought I’d conquered it. O-:<
Wow, nice find! It’s crazy there’s stuff beyond the documented stuff that you can do with the CPU. Especially finding out about it 23ish years after the console released!
Guy Perfect wrote:
The “system registers” on the VB’s CPU represent features of the architecture not directly pertinent to the program being executed. The status register is found in here, as are some other things like exception processing and the hardware breakpoint.Let’s see, it was… three and a half years ago now… I discovered the presence of three more system registers by typing in undocumented register numbers just to see what would happen. Indexes 29, 30 and 31 do not correspond to any system registers in the V810 documentation, but they do respond to probing on Virtual Boy.
At the time, it appeared that system register 31 was just a solitary flag. My tests were quite simple: write 0xFFFFFFFF to a system register, then read the value back to see if it can be written. System register 31 told me 0x00000001, and when I wrote a zero, it gave me a zero back. That looks like a 1-bit register to me. I don’t blame my past self for jumping to that conclusion.
While researching for the emulator initiative, I decided to test multiple values on all of the system registers just in case, and 31 was behaving unexpectedly. Not only was it not a 1-bit register, but it has an actual function!
System register 31’s secret powers are…
Drum roll please…
Wait for it…
It calculates the absolute value of the number you write to it. Like, you write a 32-bit two’s-complement number and when you read from it, you get that number’s absolute value. Yeah, that’s all. Nothing fancy, but certainly interesting!
Turns out that 0xFFFFFFFF is the two’s complement representation of -1, so writing that value to system register 31 gives me a positive 1 in return. And writing a zero, well, gives back a zero. It tricked me and went under the radar for years after I thought I’d conquered it. O-:<
speedyink wrote:
Wow, nice find! It’s crazy there’s stuff beyond the documented stuff that you can do with the CPU. Especially finding out about it 23ish years after the console released!
I guess we’re still duscovering secrets on old systems years after their release…
Hi Guy:
I tried to implement a custom abs function based on your findings, but I guess the compiler that I’m using doesn’t have support for the system registers 26-31.
Given that I don’t want to bother ElmerPCFX and I don’t want to go through the whole process of trying to compile the compiler again, I would like to know if there is any way to write the hex op code for the stsr and ldsr instructions in my C code without having to hack the ROM directly.
jorgeche
Attachments:
You should be able to specify the register with the number 31, rather than the symbol “sr31”.
Interesting! Did you test all 2^32 values?
Unfortunately, given that LDSR and STSR take 8 cycles each, the fastest way to get the absolute value of an integer is still the routine on page 23 of V810 Programming.
HorvatM wrote:
Interesting! Did you test all 2^32 values?
I did not, but I checked enough test cases to be confident that its operation is what it appears to be.
If you want to write up a program to test every value, I’d be happy to run it on the hardware. For science.