Contest! Detecting the memory mapper size, closes 08/31/2022.

Página 2/2
1 |

Por MagicBox

Master (208)

imagem de MagicBox

12-08-2022, 16:24

Yes, I remembered again why it works most of the time. The old circuits are of open-collector type; the Z80 data bus requires a pull-up resistor network array. When chips are connected that drive a high rather than not pulling down through the collector will short to any other chip driving low. Regardless, it's never a good idea to have multiple chips output data at the same time, but with open-collector networks this is legitimate. When it happens, obviously read values will no longer be expected values.

Por Eugeny_Brychkov

Paragon (1225)

imagem de Eugeny_Brychkov

12-08-2022, 16:36

MagicBox wrote:

because it would normally reflect the actual size of the available RAM in the slot containing the mapper.

Wrong. I recall dealing with some advanced machine (Turbo or MSX2+) having something like mapper size of 256k but missing several RAM pages at the top (on purpose of course).

I still did not get: why do you need mapper size? Why you can not look for RAM and identify size of RAM at your disposal - and this task will be 100% reliable in contrast with assuming something about how hardware mapper is designed?

Por MagicBox

Master (208)

imagem de MagicBox

12-08-2022, 18:57

Eugeny_Brychkov wrote:
MagicBox wrote:

because it would normally reflect the actual size of the available RAM in the slot containing the mapper.

Wrong. I recall dealing with some advanced machine (Turbo or MSX2+) having something like mapper size of 256k but missing several RAM pages at the top (on purpose of course).

I still did not get: why do you need mapper size? Why you can not look for RAM and identify size of RAM at your disposal - and this task will be 100% reliable in contrast with assuming something about how hardware mapper is designed?

Because for all intent and purpose, the mappersize for DRAM implies the available memory, thus memory size. It is by design that the pages 'ripple over', thus, that on a 128KB machine, setting page 8 will select page 0. Mapper + RAM are an atomic unit to the Z80 / computer. In cartridge form, it would contain the RAM ICs and the mapper logic for this set of ICs in the slot the cartridge is plugged into.

The exception you speak of likely has its own reason to be an exception. If the Turbo R you are talking about misses pages because it is an upgradable machine (stick in another row of DRAMs and get a double-up), then it is understandable that this situation yields empty pages. And I would call that an incomplete implementation and would have added a jumper that would enable the 2nd set by enabling an extra mapper bit in its logically accompanying mapper registers. See my comment about the mapper I made with the 4 ICs I gave away in the previous posting. I designed it for 1MB and so the mapper registers are 6-bit wide and leave bit 6 and 7 unused. It also ripples around pages as expected and missing ICs are a fault condition. But, that's just my opinion.

Por Manuel

Ascended (19055)

imagem de Manuel

12-08-2022, 19:14

Here is an example of a weird mapper: https://github.com/openMSX/openMSX/issues/992

Por Eugeny_Brychkov

Paragon (1225)

imagem de Eugeny_Brychkov

12-08-2022, 19:36

MagicBox wrote:

Because for all intent and purpose, the mappersize for DRAM implies the available memory, thus memory size.

Mapped RAM size can not be bigger than mapper size, mapper size can be of any size bigger than physical RAM (if whole RAM space is used). Mapper size is not equal to RAM size.

MagicBox wrote:

The exception you speak of likely has its own reason to be an exception. If the Turbo R you are talking about misses pages because it is an upgradable machine (stick in another row of DRAMs and get a double-up), then it is understandable that this situation yields empty pages.

No, those pages were used for firmware (ROM). And they actually were read-only with some system data in them.

Por MagicBox

Master (208)

imagem de MagicBox

12-08-2022, 20:24

Manuel wrote:

Here is an example of a weird mapper: https://github.com/openMSX/openMSX/issues/992

Ah thank you. I took a look and now it happens that I had one of those, it was my first MSX2. I sold it and got me a 8235 with single sided disk after this one. I didn't know about that little detail though. But yes, this is what I meant with 'reserving' pages for an upgrade. Be it by the manufacturer with an extra set of ICs, or by users themselves.

As for some Turbo R models mapping ROM into the memory mapper, I think that's a bit strange but that's me. I'm not going to disagree with the existence of models like that.

Regardless, I updated my own size detector so that it now determines the size of the first contigeous set of pages. It cost me only one more byte in opcode ;) Though it rounds up for any incrementally doubled up banks that themselves are only filled half, like would be the casse with 768KB. It would then detect 1MB. But, with 6 bits for the mapper registers with only 512KB of ICs it will accuratly return 512KB for the size.

Por MagicBox

Master (208)

imagem de MagicBox

27-08-2022, 15:50

Sooo... okay, it's not quite the end of the month but it's just before in the last weekend before the end. So I was like, well let's keep my end of the deal and publish what I cooked up. It should be straight forward and yes, comments welcome. It may also be freely used. The code:

; Mapper size test. Tests for sizes 64KB - 4MB.
; MagicBox 2022, may be used freely!

; In:   None.
; Out:  A  - Upper memory mapper page available, unmapped will return 3.
; Flg:  CF - 0: RAM found in page.
;            1: No RAM found in page.
;       xF - ?
; Mod:  B, C, D, H, L
; Rem:  Tests in page 2 by default. Update the mapper IO register in
;       register C to test in another page and change HL to an address
;       inside that page as well. Make sure HL never points to a
;       R/W location in a ROM page (like with the diskrom) when this
;       routine is used in a slot-scan.

        ORG   &HC000          ; The routine may be anywhere

MTSTRT: LD    B,&H00          ; Page in which the test values are written
        LD    C,&HFE          ; Load C with the mapper register
        LD    HL,&H8000       ; Load HL with the test location
        OUT   (C),B           ; Set the test value page
        LD    D,(HL)          ; Get the memory location value to save it
        PUSH  DE              ; Save the original value
        LD    D,&HFC          ; Lower page under test, starting at 64KB
MTLOOP: LD    A,&H55          ; Test value 1
        CALL  MTTVAL          ; Test the value for the page under test
        JR    NZ,MTNEXT       ; Test value fail, exit test for the page.
        LD    A,&HAA          ; Test value 2
        CALL  MTTVAL          ; And test this value for the page under test
        JR    Z,MTOK          ; When test was ok exit the test and form output
MTNEXT: SLA   D               ; Shift-left D and nudge out the MSB
        JR    C,MTLOOP        ; Keep looping untill D rotates out a non-carry
MTFAIL: SCF                   ; Failed finding RAM, set carry
MTOK:   LD    A,D             ; Move the upper page to A
        CPL                   ; Complement the result, it's now the upper page
        POP   DE              ; Restore the original value and page
        LD    (HL),D          ; Put back the original value
        RET                   ; Return from the test, A contains the upper page
MTTVAL: LD    (HL),A          ; Store the test value in the write page
        CP    (HL)            ; Compare it to see whether it's ROM/RAM
        RET   NZ              ; If not equal, return; it was ROM
        OUT   (C),D           ; Set the page under test
        LD    A,(HL)          ; Load the value from the page under test
        OUT   (C),B           ; Restore the test value write page
        CP    (HL)            ; Compare the test value with the memory content
        RET                   ; Return, Z is set when the value was identical

        END

B.t.w. you can use the WBASS2 assembler to run and test this. For small things and having an assembly playground on an MSX itself it's a great piece of software since the code you assemble and run runs in its own space. Meaning, you can set the slot layout to all ram for example (using the PAGE command) and run your code. The documentation is available to from the original website which is still accessible as I discovered. Have fun Smile

Por Eugeny_Brychkov

Paragon (1225)

imagem de Eugeny_Brychkov

27-08-2022, 19:59

LD BC, 0FEh
will save you one byte and several T-cycles.

Did not trace the code, does it restore all the locations it writes to?

Por MagicBox

Master (208)

imagem de MagicBox

27-08-2022, 21:05

Hey,
Yes it restores the one single location it writes to. As for the 16-bit load, you're right. I had a version that needed reg H filled only, from which C could be derived and decided I didn't want a parameter, figuring no additional processing and let the user specify the port and write address.
As a note, reg B should not be changed and is not a user parameter; the routine is designed around the fact that the test values are written in bank 0 of the mapper.

Página 2/2
1 |