Strange behaviour (bug?) on SPRATR base addr register on V9938/58

By albs_br

Champion (375)

albs_br's picture

10-01-2022, 19:06

Hi guys,
I found a very strange thing: when setting the SPRATR base addr register to 0x1fa00, the SPRCOL table won't work properly (it is supposed to bet automatically set 512 bytes before the SPRATR).

This bug happens on openMSX and real machine (WSX), but on WebMSX the sprite colors are perfect:


It looks like the first 8 sprite color entries are being repeated.

This is how I set the registers:

; ---- set SPRATR to 0x1fa00 (SPRCOL is automatically set 512 bytes before SPRATR, so 0x1f800)
    ; bits:    16 14        7
    ;           |  |        |
    ; 0x1fa00 = 1 1111 1010 0000 0000
    ; low bits (aaaaaaaa: bits 14 to 7)
    ld      b, 1111 0100 b  ; data
    ;ld      b, 1111 0111 b  ; data          ; not sure why, but bits 7 and 8 should be 1, otherwise won't work ok on openmsx (though on WebMSX runs fine)
    ld      c, 5            ; register #
    call    BIOS_WRTVDP
    ; high bits (000000aa: bits 16 to 15)
    ld      b, 0000 0011 b  ; data
    ld      c, 11           ; register #
    call    BIOS_WRTVDP

; ---- set SPRPAT to 0x1f000
    ; bits:    16     11
    ;           |      |
    ; 0x1f000 = 1 1111 0000 0000 0000
    ; high bits (00aaaaaa: bits 16 to 11)
    ld      b, 0011 1110 b  ; data
    ld      c, 6            ; register #
    call    BIOS_WRTVDP

Full code here: https://github.com/albs-br/msx-tests/blob/master/test-sprite...

On a try and error base I discovered that if bits 7 and 8 are set it works fine (both on openMSX and WebMSX).

I made the tests on Screen 11, but the same issue happens on 8 and 5.

Am I doing something wrong or is it a bug of the VDP that openMSX is able to reproduce and WebMSX isn't?

Login or register to post comments

By Grauw

Ascended (10581)

Grauw's picture

10-01-2022, 20:22

Quote:

not sure why, but bits 7 and 8 should be 1, otherwise won't work ok on openmsx (though on WebMSX runs fine)

In sprite mode 2 the least significant three bits in register 5 should be 1 otherwise mirroring will occur.

This is documented in the sprite mode 2 documentation in the V9938 Application Manual (page 102). (By the way, other V9938 table base address registers also have bits that must be 1 or else mirroring occurs, e.g. the pattern name table base (r#2) in screen 5.)

See also my comments here.

albs_br wrote:

Am I doing something wrong or is it a bug of the VDP that openMSX is able to reproduce and WebMSX isn't?

This is a bug in WebMSX, which does not implement the mirroring of the real hardware.

Nothing negative about WebMSX, but its goals are to run quick and in a browser, not to have perfect emulation accuracy. For software development I recommend to use a more accurate emulator, openMSX. Anyway, that aside, probably worth reporting this bug to ppeccin.

By Sandy Brand

Champion (279)

Sandy Brand's picture

10-01-2022, 20:16

According to the V9938 MSX-VIDEO Technical Data Book Programmer's Guide (page 49), bits A7 through A9 must always be set, or otherwise you get 'undefined behavior'.

This basically means you can only position the sprite attribute table in VRAM starting at 512 with increments of 1024 bytes (note that 1024 is enough to store a full sprite attribute table (32 * 4 = 128 bytes) and sprite color table (32 * 16 = 512 bytes)).

Most likely, in the actual VDP hardware the sprite color table is not computed by actually subtracting 512 from the base address of the sprite attribute table. Instead, they just mask bit 9 to 0, which is faster and gives the same effect given the rules described above.

In your example, bit 9 is already reset, which basically means the sprite attributes table and sprite color are overlapping in VRAM.

So the bug is in WebMSX not implementing the actual VDP hardware behavior for this edge-case :)

By Sandy Brand

Champion (279)

Sandy Brand's picture

10-01-2022, 20:18

Ah lol, Grauw beat me to it by 1 minute Tongue

By Grauw

Ascended (10581)

Grauw's picture

10-01-2022, 20:25

I beat you by more than that actually, but I kept editing afterwards so the timestamp updated Smile.

Anyway now things are super clear!

By albs_br

Champion (375)

albs_br's picture

10-01-2022, 20:44

Thanks @Grauw and @Sandy Brand. That solves the case.

Maybe it could be more emphasized on manual, the "2.1.2 Table base address registers" section (where I was looking before) has no mention of it.

So, a game that uses this mirroring feature (for example to don't need to load a big quantity of bytes on SPRCOL) will not work properly on WebMSX.

By Manuel

Ascended (18794)

Manuel's picture

10-01-2022, 22:39

And that's why it's a good idea to notify ppeccin, the author of WebMSX Smile