Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

#1 2026-01-23 20:10:28

judgevorak
New member
Registered: 2026-01-23
Posts: 2

VRAM address and Bitmap management

Greetings,

Apologies if this my question has already been answered; a brief search for "vram tilemap" didn't yield the answers I was hoping for, but please link me to a resource if I missed it.  My development environment consists of vi, vasm, and rgbfix -- no GBDK, mostly just following Keith's multi-platform Z80 tutorials at ChibiAkumas and referring to SM83 opcode charts at GBdev and PastRaiser.

My question: What is the best non-static method for obtaining a bitmap's initial byte address in VRAM?  I have a function that copies 2bpp bitmaps into VRAM, so creating a label has proved fruitless both before the copy and inside of it.  Those labels have just given me the address of my "incbin" and "call" opcodes respectively, and my instincts say that "org" in VRAM is a bad idea for maintainability.

The VRAM consists of a 96-character 1bpp font copied in per Keith's tutorial (&8000 - &85FF), then a couple of 2bpp spritemaps at &8600.  Without specifically referring to the Listing file, bgb debugger, or manually tracking bytes, is there a way to know and/or refer to each bitmap copied into VRAM?

I am very new to GB development and assembly in general, but have recently come to understand how bitplanes fit into &8000 - &8FFF VRAM and how the TileMap &9800 - &9BFF contains pointers to VRAM offsets.  After banging my head on some bits, I came up with the function below to convert a VRAM address into its TileNumber offset, but would like a sane method of finding desired VRAM addresses:

Code:

        ld  hl, &8600   ; arbitrary VRAM address &8600
                        ;       1000 0110 0000 0000
        res 7, h        ; "subtract" &8000, leaving &0600:
                        ;       0000 0110 0000 0000
                        ; The high byte will be &06 (06d)
                        ; We need to bang this from 6 to 96 (&60)
        ld  a, h        ;       0000 0110
        rla             ;       0000 1100
        rla             ;       0001 1000
        rla             ;       0011 0000
        rla             ;       0110 0000
        ld  hl, &9800   ; choose Tile coords (use SetPos or similar)
        call DrawFunction

Offline

 

#2 Yesterday 14:43:18

judgevorak
New member
Registered: 2026-01-23
Posts: 2

Re: VRAM address and Bitmap management

I settled on managing memory locations for each bitmap copied into VRAM; this may not scale well when VRAM is full and needs shuffling, but I'll burn that bridge when I get to it.  In practice, I've copied all my bitmaps consecutively so the font is &8000 - &85FF, then Alien at &8600 - &863F, and Flower at &8640 - &86FF

Here's my hacky method of obtaining the initial byte of a bitmap copied into VRAM:

1. Declare two bytes of memory per bitmap

Code:

                bmpAlienH equ &c000
                bmpAlienL equ &c001

2. Store HL values just before CopyBitmapLoop

Code:

                ld de, AlienSprite      ; incbin label
                ld a, h         ; prepare to store bmpAlienH
                ld (bmpAlienH), a
                ld a, l         ; prepare to store bmpAlienL
                ld (bmpAlienL), a
                ld bc, AlienSpriteEnd-AlienSprite ; counter for CopyBitmapLoop
                call CopyBitmapLoop

3. Refer to those memory locations for DrawSprite functions

Code:

                ld a, (bmpAlienH)       ; ye olde 8-bit shufflee
                ld h, a
                ld a, (bmpAlienL)
                ld l, a                 ; now HL is AlienSprite VRAM addr
                call CalcTileOffset     ; bangs &8600 into &60
                call DrawFunction     ; render bitmap at VRAM addr HL

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson