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 2023-12-27 10:50:01

Btara
New member
Registered: 2023-12-27
Posts: 2

Gameboy Assembly Help With Tilemap

Hello, I am new to programming with Assembly and I was trying to load a few rows of tiles onto the screen. The tiles do load onto the screen and are displayed but some tiles are missing in very specific patterns on the screen. I am not sure what is wrong, here is the code I am using if anyone can help:

Code:

begin:          
    di                       ; Disable Interrupts
    ld sp , $fffe         ; Initialise Stack Pointer
    call stop_lcd        ; Need to stop the LCD to write to display
                
    ; Load tiles into vram
    ld de, $8010   
    ld hl, Tiles
    ld b, $10    
    call CopyTiles 
                
    ; Set tilemap stuff
    ld de, $9800
    ld hl, BGMap
    ld b, $A0
    call CopyMap
                
    call init_registers
    ei          
                
    jp Done     
                
                   
stop_lcd:       
    ld  a , (R_LY)
    cp  145     
    jr  nz , stop_lcd
    ld  a , (R_LY)
    res 7 , a   
    ld  (R_LY) , a
    ret         
                   
Done:           
    nop         
    jp Done        
                
CopyTiles:
    ld a, (hl)
    ld (de), a
    inc de
    inc hl
    dec b
    jr nz, CopyTiles
    ret       
                
CopyMap:
    ld a, (hl)
    ld (de), a
    inc de
    inc hl
    dec b
    jr nz, CopyMap
    ret      

                
init_registers: 
    ; Initialise Registers
    ld a, $00   
    xor a       
    ld  (R_SCX), a
    ld  (R_SCY), a
    ld  a , %11100100    ; Standard Palette Colours
    ld  (R_BGP), a
    ld  a , %10010011    ; LCD On, Tile Map 0, Window Off, TDT 1, BGTM 0, 8x8, sprite off, BG On
    ld  (R_LCDC), a
    ret         
                     
Tiles:          
    db $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff 
    db $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff 
    db $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff 
    db $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff 
                
BGMap:          
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

Last edited by nitro2k01 (2023-12-27 10:51:15)

Offline

 

#2 2023-12-27 10:58:34

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 244

Re: Gameboy Assembly Help With Tilemap

The issue is your code for disabling the LCD, which writes to the wrong register. The pattern you're seeing is the time when VRAM is inaccessible because the screen is rendering.

Code:

    ld  a , (R_LCDC)
    res 7 , a   
    ld  (R_LCDC) , a

Last edited by nitro2k01 (2023-12-27 10:59:37)


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#3 2023-12-27 11:37:22

Btara
New member
Registered: 2023-12-27
Posts: 2

Re: Gameboy Assembly Help With Tilemap

Thank you, It works great now!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson