For the past couple of days I've been trying to come up with a way to load 16x16 metatiles into the PPU. The only way I could imagine is to have a buffer that you load into prior to pulling it all to the screen. As it is right now, I am working on getting the top 256 tiles in the PPU. I've tried a few things, and so far this is getting me the best results, but it's still not displaying properly.
What I am doing is grabbing the level number, which is in multiples of two, and getting the address from a table:
After that, I am using a pointer to get the kind of block in the address (in this case, board_1_1).
ldy #$00
: lda (address_temp_lo),y
sta get_block
After that, I do a couple of subroutines, one to grab the tile numbers from, which is also my first time dealing with jump tables, and the other routine sticks the tiles in a buffer located at $600. Then I increment Y, check it to be #$40, and go loading from the buffer at $600 to the PPU:
The left pic is what it looks like when I build it, and the right one is what it should look similar to (top 256 tiles):
I can't figure out what is going on at all :/ If anyone can spot something I'm doing entirely wrong, let me know. This is getting pretty aggravating.
What I am doing is grabbing the level number, which is in multiples of two, and getting the address from a table:
Code:
jsr PPU_off
ldy game_level
lda level_data_start,y
sta address_temp_lo
lda level_data_start+1,y
sta address_temp_hi
; The table of word sized labels
level_data_start:
.addr board_1_1, board_1_2, board_1_3, board_1_4
ldy game_level
lda level_data_start,y
sta address_temp_lo
lda level_data_start+1,y
sta address_temp_hi
; The table of word sized labels
level_data_start:
.addr board_1_1, board_1_2, board_1_3, board_1_4
After that, I am using a pointer to get the kind of block in the address (in this case, board_1_1).
Code:
ldy #$00
: lda (address_temp_lo),y
sta get_block
After that, I do a couple of subroutines, one to grab the tile numbers from, which is also my first time dealing with jump tables, and the other routine sticks the tiles in a buffer located at $600. Then I increment Y, check it to be #$40, and go loading from the buffer at $600 to the PPU:
Code:
jsr choose_block
jsr do_block_buffer
iny
cpy #$40
bne :-
inc address_temp_hi
jsr do_top_nametable
; ------------------------------------------
choose_block:
lda get_block
asl a
tax
lda block_types+1,x
pha
lda block_types,x
pha
rts
; Below is the table of addresses for what to do for each block
block_types:
.addr open_block-1
.addr stage1_solid_block-1
.addr electric_side_block-1
.addr stage2_solid_block-1
.addr electric_top_block-1
; Here are the kind of things I do in those subroutines:
open_block:
lda #$00
sta tile_1
sta tile_2
sta tile_3
sta tile_4
rts
stage1_solid_block:
lda #$01
sta tile_1
lda #$02
sta tile_2
; etc etc....
; Here is where the tiles are put into a buffer
do_block_buffer:
ldx metatile_index
lda tile_1
sta bg_buffer,x
inx
lda tile_2
sta bg_buffer,x
txa
clc
adc #31
tax
lda tile_3
sta bg_buffer,x
inx
lda tile_4
sta bg_buffer,x
txa
sec
sbc #31
tax
stx metatile_index
; bne :+
; inc metatile_index+1 ; I forgot to take this block out of the code
;: ; edited now
rts
; Pull it to the PPU
do_top_nametable:
lda #$20
sta $2006
ldx #$00
sta $2006
: lda bg_buffer,x
sta $2007
inx
bne :-
rts
jsr do_block_buffer
iny
cpy #$40
bne :-
inc address_temp_hi
jsr do_top_nametable
; ------------------------------------------
choose_block:
lda get_block
asl a
tax
lda block_types+1,x
pha
lda block_types,x
pha
rts
; Below is the table of addresses for what to do for each block
block_types:
.addr open_block-1
.addr stage1_solid_block-1
.addr electric_side_block-1
.addr stage2_solid_block-1
.addr electric_top_block-1
; Here are the kind of things I do in those subroutines:
open_block:
lda #$00
sta tile_1
sta tile_2
sta tile_3
sta tile_4
rts
stage1_solid_block:
lda #$01
sta tile_1
lda #$02
sta tile_2
; etc etc....
; Here is where the tiles are put into a buffer
do_block_buffer:
ldx metatile_index
lda tile_1
sta bg_buffer,x
inx
lda tile_2
sta bg_buffer,x
txa
clc
adc #31
tax
lda tile_3
sta bg_buffer,x
inx
lda tile_4
sta bg_buffer,x
txa
sec
sbc #31
tax
stx metatile_index
; bne :+
; inc metatile_index+1 ; I forgot to take this block out of the code
;: ; edited now
rts
; Pull it to the PPU
do_top_nametable:
lda #$20
sta $2006
ldx #$00
sta $2006
: lda bg_buffer,x
sta $2007
inx
bne :-
rts
The left pic is what it looks like when I build it, and the right one is what it should look similar to (top 256 tiles):
I can't figure out what is going on at all :/ If anyone can spot something I'm doing entirely wrong, let me know. This is getting pretty aggravating.