Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2015-06-14 18:53:05

comet
Member
Registered: 2012-04-09
Post 582/679

256-block tilesets

By default, there's a maximum of 128 (0-127) blocks usable in a tileset. After that, they appear to loop around back to 0. There doesn't seem to be any inherent limitation. After some digging, I found that Function2198 in home/map.asm looks up the graphics for blockdata.

Of interest to us is this bit, which multiplies the block id (in register a) by 16 (the number of graphics tiles in a block) to get its offset in the tileset's list of graphics for each block:

...

    add a
    ld l, a
    ld h, 0
    add hl, hl
    add hl, hl
    add hl, hl

...

This code adds 8-bit register a to itself (which is the same as multiplying it by 2). Then it puts the result in 16-bit hl and adds that to itself three times (multiplying by 2^3 = 8).

Multiplying by 2 is also the same as a left bitshift. By shifting left, the early `add a` is pushing our eighth bit out, making 128-255 act like 0-127! The fix is pretty simple:

...

    ld l, a
    ld h, 0
    add hl, hl
    add hl, hl
    add hl, hl
    add hl, hl

...

It looks like this was just an oversight. I wonder if this could have forced some maps to lose detail, since the overworld is pretty samey. Whirl Islands come to mind.

Offline

Board footer

Powered by FluxBB