commanderx16 / x16-rom

Other
153 stars 43 forks source link

Verify that RAM size detection works on real hardware #132

Open differentprogramming opened 4 years ago

differentprogramming commented 4 years ago

2 problems here: 1) shouldn't there be some place to store the number of ram banks? The documentation says that Ramtas returns the number of banks. I don't know if that's stored anywhere but due to a bug, Ramtas always returns 1.

2) It calculates the number of banks by assuming that bank 64 will alias to bank 0 if you don't have all 256 banks. I know the emulator works that way, but it would seem surprising to me if the actual hardware did that. Certainly if a board was made to fully populate the ram and you took out some ram, it doesn't change the address to be modulo the number of actual ram sticks.

gaekwad commented 4 years ago
  1. The number of ram banks gets stored at $255 (which may change as development continues). The way you're supposed to retrieve it is by setting the carry flag, calling memtop ($ff99), and it will be in the A register (it also sets X and Y to the lower and upper byte of the top of memory). ramtas shouldn't be called except by the system at bootup or when resetting.

  2. Not sure what you mean. The algorithm simply stores $A000 in bank 0 in the X register and increments it, stores it in bank 1 and then increments the bank by powers of two, storing the value in $A000 and testing if it equals the value in bank 0. They won't be equal until you've wrapped around. So the number of banks you have is 2 to the power of however many loops it took. Case in point, if you change the amount of RAM given to the emulator with "-ram" it changes the amount of banks set by ramtas.

differentprogramming commented 4 years ago

" The algorithm simply stores a value in bank 0 and then loops until it sees that value again." Right, if you have the emulator set to only have 64 ram banks then when you get to bank 64, it's actually showing you bank 0 again.

But that's not what real hardware is likely to do. If you have a computer board with 2 megabytes of ram and you replace that ram with 512k of ram, the board isn't going to map that 512k of ram into a 2 megabytes space four times.

On Tue, Jan 28, 2020 at 5:34 PM gaekwad notifications@github.com wrote:

1.

The number of ram banks gets stored at $255 (which may change as development continues). The way you're supposed to retrieve it is by setting the carry flag, calling memtop ($ff99), and it will be in the A register (it also sets X and Y to the lower and upper byte of the top of memory). ramtas shouldn't be called except by the system at bootup or when resetting. 2.

Not sure what you mean. The algorithm simply stores a value in bank 0 and then loops until it sees that value again. The number of banks you have is 2 to the power of however many loops it took. Case in point, if you change the amount of RAM given to the emulator with "-ram" it changes the amount of banks set by ramtas.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/commanderx16/x16-rom/issues/132?email_source=notifications&email_token=AA4FICLXG6S5YEMWHOUHGVTRADMJHA5CNFSM4KMQJWJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKFUNAQ#issuecomment-579552898, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4FICPVFBFV4BDRDMGGNXDRADMJHANCNFSM4KMQJWJA .

BruceMcF commented 4 years ago

On the main issue, RAMTAS was a typo, it's MEMTOP. The current PRG has had the typo fixed,

" The algorithm simply stores a value in bank 0 and then loops until it sees that value again." Right, if you have the emulator set to only have 64 ram banks then when you get to bank 64, it's actually showing you bank 0 again. But that's not what real hardware is likely to do. If you have a computer board with 2 megabytes of ram and you replace that ram with 512k of ram, the board isn't going to map that 512k of ram into a 2 megabytes space four times.

One of the design team members has just said in a different thread on FB that the emulator tracks the design of the board. If the board currently has a jumper based on how many sockets are populated, it could indeed be wired to just ignore the top two socket select bits when there is only one 512K SRAM chip installed, or ignore the top socket select bit if there are two 512K SRAM chips installed. That's not even a single glue logic chip, that's only two gates from a Quad AND, plus a jumper block. That kind of mirroring wouldn't be unusual in 8bit systems ... the C64 did mirroring within it's I/O pages all the time.

If they change that, then they can change to writing $FF to segment $FF and reading it back, if it comes back 0, LSR the segment register until it comes back $FF.

mist64 commented 4 years ago

No, I have not tested the RAM size detection code against actual hardware not less than maxed out RAM.

With a single RAM chip, mirroring is the behavior you would get. The current board has several RAM chips, so I am not sure what will happen in practice. I'll check it. :)

mist64 commented 2 years ago

See also #199.