Autodetecting the amount of VRAM?

By santiontanon

Paragon (1757)

santiontanon's picture

22-04-2017, 05:18

I have seen many examples of assembler code to autodetect which version of the VDP an MSX is equipped with. But is it possible to also detect how much VRAM does it have?

Login or register to post comments

By Victor

Champion (509)

Victor's picture

22-04-2017, 06:34

I think that is the same way like detecting the amount of RAM: WRITE -> READ and COMPARE

- Select a bank of VRAM with register 14
- Write in a direction of VRAM a value
- Read that direction and compare
- The same value?? -> select next bank of VRAM....

By santiontanon

Paragon (1757)

santiontanon's picture

22-04-2017, 07:39

oh! ok, that actually makes sense. I just gave it a try, and assuming we have an MSX2, just doing this is enough to know if we have more than 16KB of VRAM:

    xor a
    ld hl,#0000
    call NWRVRM
    ld a,1
    ld hl,#4000
    call NWRVRM
    ld hl,#0000
    call NWRVRM
    or a
    jp z,morethan16kb

I'll play around with this tomorrow to see if I can find a way to do it without assuming we are on an MSX2 (since those BIOS calls are only available on MSX2...)

By Victor

Champion (509)

Victor's picture

22-04-2017, 08:24

Do it direclty:

Taken from Grauws page:

;
;Set VDP port #98 to start writing at address AHL (17-bit)
;
SetVdp_Write: rlc h
rla
rlc h
rla
srl h
srl h
di
out (#99),a ;set bits 15-17
ld a,14+128
out (#99),a
ld a,l ;set bits 0-7
nop
out (#99),a
ld a,h ;set bits 8-14
or 64 ; + write access
ei
out (#99),a
ret

;
;Set VDP port #98 to start reading at address AHL (17-bit)
;
SetVdp_Read: rlc h
rla
rlc h
rla
srl h
srl h
di
out (#99),a ;set bits 15-17
ld a,14+128
out (#99),a
ld a,l ;set bits 0-7
nop
out (#99),a
ld a,h ;set bits 8-14
ei ; + read access
out (#99),a
ret

By gdx

Enlighted (6071)

gdx's picture

22-04-2017, 09:11

The bits 2 and 1 of the system variable "MODE" at 0FAFCh is used to indicate the amount of VRAM of the MSX. (00 for 16kB, 01 for 64kB, 10 for 128kB and 11 for 192Ko)

By Victor

Champion (509)

Victor's picture

22-04-2017, 09:20

gdx wrote:

The bits 2 and 1 of the system variable "MODE" at 0FAFCh is used to indicate the amount of VRAM of the MSX. (00 for 16kB, 01 for 64kB, 10 for 128kB and 11 for 192Ko)

gdx!!! That's really an easier way!! LOL Smile

By santiontanon

Paragon (1757)

santiontanon's picture

22-04-2017, 20:41

Oh! even better, thanks guys! going to try this right now! Big smile

edit: confirmed, just these three lines of code do the trick!! (thanks again!)

    ld a,(MODE)
    and #06
    jp z,only16kb

By Manuel

Ascended (19273)

Manuel's picture

22-04-2017, 22:28

santiontanon: a few very rare MSX2's only have 64kB VRAM. So take care of that, if you want Smile