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 2010-06-24 12:05:44

stereochris
New member
Registered: 2010-06-24
Posts: 8

All Points Accessible HELP

hello! i'm really excited to find this forum, I hope its still active. I have a few questions concerning coding a GB (dmg/pocket) APA in ASM

i'm using RGBDS and the Gameboy Assembler Studio, and just familiarizing myself with the syntax and general basics of GB ASM

i conquered writing a "place tile" function that works as both a "call FUNCTION" and as a MACRO, to give you an idea where i am in ability.

I read in the gb devrs FAQ that to create an APA environment on the GB you need to place 20x18 individual clear tiles (to fill the screen), and edit them
individually as need be. This is where I need help. Please correct my on my thought process if i'm wrong, but...

I want to write a "place pixel" function, and i believe i need to:

- Fill ALL of tile memory bank 1 with individual blank tiles and part of tile memory bank 2 with blank tiles
- _SCRN0 (background) will continuously read _VRAM (video ram), so i can write to video ram to edit the tiles as opposed to reading video ram, altering data, writing to video ram, and setting background again (correct? this is where i need help)
- Determine which tile, which row, etc, the pixel I want to alter is on
- load two bytes representing the row within a tile that my pixel is on
- alter one bit within each byte and rewrite those bytes to the video memory

maybe someone has sample code? or anything that could help me on this path

i ultimately want to be able to call "placePixel" from large functions, and define memory space to hold the properties of the placed pixels because they will exist as objects, but not as sprites, so that i can define a lifespan for the pixel. So I will place the pixel, and across many timer interrupts it will fade out across the shades of grey.

I got a ways to go but hopefully posting here will help! thanks a lot!

Offline

 

#2 2010-06-24 17:32:01

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

Re: All Points Accessible HELP

As you've noticed, the map is 20*18 tiles = 360 tiles. One set of tiles is 256 tiles, which is not enough to fill the map with drawable tiles the "dead-simple" way. You have two choices...
1) Dynamic allocation. You allocate a new tile every time you need to draw something in a tile that is currently unallocated. This will work, but could potentially become very slow. Actually, I think there's code that does uses this method in GBDK.
2) There are are two tile sets to choose from that share 50% of the tiles, which with a little trick can give you 128 more possible tiles and allow statically mapped pixels for the whole screen.

But in the end, do you really, really need exact pixel control like that? My opinion is that you should work with the tile mapping, not against. Do you actually need the pixel drawing for anything, or is it just something you think would be "nice to have"?

Also, I recommend that you drop by #gbdev on the EFNet IRC network.


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

Offline

 

#3 2010-06-25 10:34:40

stereochris
New member
Registered: 2010-06-24
Posts: 8

Re: All Points Accessible HELP

I decided to only use 225 dynamic tiles and write a 2 tile deep black border around the whole thing to avoid any special tricks to have the dynamic tiles. right now i'm working on writing a placePixel function that will take $00,$00,$00 or Color, X, Y input and turn the right pixel on... this is what ihave so far but it seems bloated

placePixel:
    ld    hl, _VRAM
    inc    b
    inc    c
.yCheck:                           ; Check to see if Y is 0, otherwise jump to checking if X is 0
    dec    c
    jp    z, .xCheck
    push    af
    ld    a, c
    sra    c                          ; Shift right, or divide by two, right?
    sra    c
    sra    c
    ld    d, c                     ; d is the number of vertical rows you need to jump to get to the correct tile to write to
    sla    c
    sla    c
    sla    c
    sub    c
    ld    e, a
    pop    af
.addRows:
    push    de
    ld    de, $0100
    add    hl, de
    pop    de
    dec    d
    jp    nz, .addRows
.addRow:
    push    de
    ld    de, $0002
    add    hl, de
    pop    de
    dec    e
    jp    nz, .addRow
.xCheck:
    dec    b
    jp    z, .placePix
    push    af
    ld    a, b
    sra    b
    sra    b
    sra    b
    ld    d, b
    sla    b
    sla    b
    sla    b
    sub    b
   
.placePix:
    ret









am i way off??

Offline

 

#4 2010-06-27 22:37:34

stereochris
New member
Registered: 2010-06-24
Posts: 8

Re: All Points Accessible HELP

This works as a place pixel function. various variable such as the INC A $0100 will have to be changed varying on the width / height of the environment. mine is 16 by 14 tiles. are there any obvious ways to lighten this up? i know there must be a way to create loops for the last parts, concerning setting and resetting bits within the vram variables,  but i couldnt figure out how to pass SET and RES a variable as opposed to a decimal for the first input, such as SET 0, B.. any clarification here?

placePixel:
    ld    hl, _VRAM
    inc    b
    inc    c
.yCheck:
    dec    c
    jp    z, .xCheck
    push    af
    ld    a, c
    sra    c
    sra    c
    sra    c
    ld    d, c
    inc    d
    sla    c
    sla    c
    sla    c
    sub    c
    ld    e, a
    pop    af
.addRows:
    dec    d
    jp    z, .addRow
    push    de
    ld    de, $0100
    add    hl, de
    pop    de
    jp    .addRows
.addRow:
    push    de
    ld    de, $0002
    add    hl, de
    pop    de
    dec    e
    jp    nz, .addRow
.xCheck
    dec    b
    jp    z, .placePix
    push    af
    ld    a, b
    sra    b
    sra    b
    sra    b
    ld    d, b
    inc    d
    sla    b
    sla    b
    sla    b
    sub    b
    ld    e, a
    pop    af
.addCols:
    dec    d
    jp    z, .placePix
    push    de
    ld    de, $0010
    add    hl, de
    pop    de
    jp    .addCols
.placePix:
    push    af
    ld    a, e
    cp    $00
    jp    z, .pix0
    cp    $01
    jp    z, .pix1
    cp    $02
    jp    z, .pix2
    cp    $03
    jp    z, .pix3
    cp    $04
    jp    z, .pix4
    cp    $05
    jp    z, .pix5
    cp    $06
    jp    z, .pix6
    cp    $07
    jp    z, .pix7       
    ret

.pix0:
    pop    af
    cp    $03
    jp    z, .pix0col3
    cp    $02
    jp    z, .pix0col2
    cp    $01
    jp    z, .pix0col1
    cp    $00
    jp    z, .pix0col0
    ret

.pix0col3:
    ld    b, [hl]
    set    7, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    7, b
    ld    [hl], b
    ret
.pix0col2:
    ld    b, [hl]
    res    7, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    7, b
    ld    [hl], b
    ret
.pix0col1:
    ld    b, [hl]
    set    7, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    7, b
    ld    [hl], b
    ret
.pix0col0:
    ld    b, [hl]
    res    7, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    7, b
    ld    [hl], b
    ret

.pix1:
    pop    af
    cp    $03
    jp    z, .pix1col3
    cp    $02
    jp    z, .pix1col2
    cp    $01
    jp    z, .pix1col1
    cp    $00
    jp    z, .pix1col0
    ret

.pix1col3:
    ld    b, [hl]
    set    6, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    6, b
    ld    [hl], b
    ret
.pix1col2:
    ld    b, [hl]
    res    6, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    6, b
    ld    [hl], b
    ret
.pix1col1:
    ld    b, [hl]
    set    6, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    6, b
    ld    [hl], b
    ret
.pix1col0:
    ld    b, [hl]
    res    6, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    6, b
    ld    [hl], b
    ret

.pix2:
    pop    af
    cp    $03
    jp    z, .pix2col3
    cp    $02
    jp    z, .pix2col2
    cp    $01
    jp    z, .pix2col1
    cp    $00
    jp    z, .pix2col0
    ret

.pix2col3:
    ld    b, [hl]
    set    5, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    5, b
    ld    [hl], b
    ret
.pix2col2:
    ld    b, [hl]
    res    5, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    5, b
    ld    [hl], b
    ret
.pix2col1:
    ld    b, [hl]
    set    5, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    5, b
    ld    [hl], b
    ret
.pix2col0:
    ld    b, [hl]
    res    5, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    5, b
    ld    [hl], b
    ret

.pix3:
    pop    af
    cp    $03
    jp    z, .pix3col3
    cp    $02
    jp    z, .pix3col2
    cp    $01
    jp    z, .pix3col1
    cp    $00
    jp    z, .pix3col0
    ret

.pix3col3:
    ld    b, [hl]
    set    4, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    4, b
    ld    [hl], b
    ret
.pix3col2:
    ld    b, [hl]
    res    4, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    4, b
    ld    [hl], b
    ret
.pix3col1:
    ld    b, [hl]
    set    4, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    4, b
    ld    [hl], b
    ret
.pix3col0:
    ld    b, [hl]
    res    4, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    4, b
    ld    [hl], b
    ret

.pix4:
    pop    af
    cp    $03
    jp    z, .pix4col3
    cp    $02
    jp    z, .pix4col2
    cp    $01
    jp    z, .pix4col1
    cp    $00
    jp    z, .pix4col0
    ret

.pix4col3:
    ld    b, [hl]
    set    3, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    3, b
    ld    [hl], b
    ret
.pix4col2:
    ld    b, [hl]
    res    3, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    3, b
    ld    [hl], b
    ret
.pix4col1:
    ld    b, [hl]
    set    3, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    3, b
    ld    [hl], b
    ret
.pix4col0:
    ld    b, [hl]
    res    3, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    3, b
    ld    [hl], b
    ret

.pix5:
    pop    af
    cp    $03
    jp    z, .pix5col3
    cp    $02
    jp    z, .pix5col2
    cp    $01
    jp    z, .pix5col1
    cp    $00
    jp    z, .pix5col0
    ret

.pix5col3:
    ld    b, [hl]
    set    2, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    2, b
    ld    [hl], b
    ret
.pix5col2:
    ld    b, [hl]
    res    2, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    2, b
    ld    [hl], b
    ret
.pix5col1:
    ld    b, [hl]
    set    2, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    2, b
    ld    [hl], b
    ret
.pix5col0:
    ld    b, [hl]
    res    2, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    2, b
    ld    [hl], b
    ret

.pix6:
    pop    af
    cp    $03
    jp    z, .pix6col3
    cp    $02
    jp    z, .pix6col2
    cp    $01
    jp    z, .pix6col1
    cp    $00
    jp    z, .pix6col0
    ret

.pix6col3:
    ld    b, [hl]
    set    1, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    1, b
    ld    [hl], b
    ret
.pix6col2:
    ld    b, [hl]
    res    1, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    1, b
    ld    [hl], b
    ret
.pix6col1:
    ld    b, [hl]
    set    1, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    1, b
    ld    [hl], b
    ret
.pix6col0:
    ld    b, [hl]
    res    1, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    1, b
    ld    [hl], b
    ret

.pix7:
    pop    af
    cp    $03
    jp    z, .pix7col3
    cp    $02
    jp    z, .pix7col2
    cp    $01
    jp    z, .pix7col1
    cp    $00
    jp    z, .pix7col0
    ret

.pix7col3:
    ld    b, [hl]
    set    0, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    0, b
    ld    [hl], b
    ret
.pix7col2:
    ld    b, [hl]
    res    0, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    set    0, b
    ld    [hl], b
    ret
.pix7col1:
    ld    b, [hl]
    set    0, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    0, b
    ld    [hl], b
    ret
.pix7col0:
    ld    b, [hl]
    res    0, b
    ld    [hl], b
    inc    hl
    ld    b, [hl]
    res    0, b
    ld    [hl], b
    ret

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson