diff --git a/src/bank1.asm b/src/bank1.asm index 76ae2cf..bd9b6ab 100644 --- a/src/bank1.asm +++ b/src/bank1.asm @@ -4251,7 +4251,7 @@ draw_player_hud_sprites: stx $04 rts -; table for hud sprites (#$10 bytes) +; table for hud sprites, references pattern table tiles (#$10 bytes) ; medals for number of lives or ; GAME ; OVER @@ -4272,7 +4272,7 @@ set_x_adv_OAMDMA_addr: adv_OAMDMA_addr: txa ; move current write offset to a clc ; clear carry in preparation for addition - adc #$c4 ; add #$c4 to current write offset () + adc #$c4 ; add #$c4 to current write offset tax ; move new offset back to x rts diff --git a/src/bank3.asm b/src/bank3.asm index b098b73..1a50a53 100644 --- a/src/bank3.asm +++ b/src/bank3.asm @@ -755,7 +755,7 @@ level_6_palette_data: level_6_nametable_update_palette_data: .byte $aa,$aa,$aa,$55,$55,$00,$00 -; namespace animation tiles codes - level 7 (#$c * #$5 = #$3c bytes) +; nametable animation tiles codes - level 7 (#$c * #$5 = #$3c bytes) ; first byte is number of groups of length 2 to update of data being written ; e.g. byte 0 (#$83) means to draw three rows of two tiles each ; $0c $0d store the ppu write address diff --git a/src/bank4.asm b/src/bank4.asm index fc8d2c8..a1df666 100644 --- a/src/bank4.asm +++ b/src/bank4.asm @@ -436,7 +436,7 @@ game_end_routine_04: bne game_end_routine_exit ; exit if not the 8th frame (scroll every 8 frames) inc VERTICAL_SCROLL ; vertical scroll offset lda VERTICAL_SCROLL - cmp #$f0 ; see if the view window needs to be set back to $2000 (scroll reached bottom of $2800 namespace) + cmp #$f0 ; see if the view window needs to be set back to $2000 (scroll reached bottom of $2800 nametable) bne @continue ; branch if no need to reset base nametable write address and vertical scroll lda #$20 ; initialize PPU write address to #$200 and set/reset VERTICAL_SCROLL sta $44 ; write nametable address high byte for PPU address #$2000 diff --git a/src/bank7.asm b/src/bank7.asm index 0717e68..806a5ad 100644 --- a/src/bank7.asm +++ b/src/bank7.asm @@ -4679,8 +4679,8 @@ handle_jump: clc ; clear carry in preparation for addition adc VERTICAL_SCROLL ; add vertical scroll offset and #$0f ; keep bits .... xxxx - cmp #$08 ; see if result ends in #$08 - bcs @apply_gravity ; branch to check collision every #$08 pixels + cmp #$08 ; seeing if result is less than #$08 + bcs @apply_gravity ; branch to check collision only when result is less than #$08 @check_collision: jsr get_player_bg_collision_code ; get player background collision code @@ -4698,9 +4698,9 @@ handle_jump: tay ; set y position for bg collision check lda SPRITE_X_POS,x ; load x position for bg collision check jsr get_bg_collision ; determine player background collision code at position (a,y) - bpl @apply_gravity ; branch if not empty collision code (floor, water, solid) - lda #$00 ; a = #$00 - sta PLAYER_Y_FAST_VELOCITY,x + bpl @apply_gravity ; branch if not solid collision + lda #$00 ; solid collision above player, set Y velocity to #$00 + sta PLAYER_Y_FAST_VELOCITY,x ; gravity will then pull the player down sta PLAYER_Y_FRACT_VELOCITY,x @apply_gravity: @@ -5899,10 +5899,11 @@ load_column_of_tiles_to_cpu_buffer: ; - looped through until all tiles for a single column have been written ; - ultimately is called 4 times for each super-tile because each time renders only 1 column of pattern table tiles for the super-tile ; * updates the in-memory background collision (BG_COLLISION_DATA) information (set_tile_collision) -; Y is the LEVEL_SCREEN_SUPERTILES offset (level_X_supertiles_screen_XX) -; $03 is the column offset of the super-tile to write to CPU_GRAPHICS_BUFFER block (currently drawing column) ; #$37 super-tiles per screen for horizontal levels ; #$40 super-tiles per screen for vertical levels +; input +; * y - is the LEVEL_SCREEN_SUPERTILES offset (level_X_supertiles_screen_XX) +; * $03 - is the column offset of the super-tile to write to CPU_GRAPHICS_BUFFER block (currently drawing column) ; CPU address #$df48 load_level_supertile_data: lda #$00 ; initialize LEVEL_SUPERTILE_DATA_PTR read offset @@ -5983,7 +5984,7 @@ set_vert_lvl_super_tiles: and #$03 ; keep bits .... ..xx asl asl - sta $02 + sta $02 ; byte offset into the super-tile lda PPU_WRITE_TILE_OFFSET and #$1c ; keep bits ...x xx.. asl @@ -6000,13 +6001,14 @@ set_vert_lvl_super_tiles: @set_supertile_tiles: lda #$00 ; a = #$00 sta $08 - lda LEVEL_SCREEN_SUPERTILES,y ; read byte specifying which super-tile to load (level_X_supertiles_screen_XX) + lda LEVEL_SCREEN_SUPERTILES,y ; read byte specifying which super-tile to load + ; decompressed level_X_supertiles_screen_XX data asl asl rol $08 asl rol $08 - asl + asl ; 4 total asl instructions since each super-tile is #$10 bytes rol $08 adc LEVEL_SUPERTILE_DATA_PTR ; (bank 3 pointer) sta $00 @@ -6164,8 +6166,8 @@ write_row_attribute_to_cpu_memory: ; determine tile collision code (0-3) for the pattern table tile updates BG_COLLISION_DATA ; input -; * a - namespace tile code from the super-tile -; * y - level namespace tile offset (level_X_SUPERTILE_data offset) +; * a - nametable tile code from the super-tile +; * y - level nametable tile offset (level_X_SUPERTILE_data offset) ; tile code 0 is always set to collision code 0 set_tile_collision: sty $14 ; store super-tile tile data read offset in $14 (LEVEL_SUPERTILE_DATA_PTR offset) @@ -6173,15 +6175,16 @@ set_tile_collision: bne tile_collision_exit ; exit if $11 is set tay ; move the pattern table tile code to Y beq set_collision_code_0 ; tile index is #$00, set to collision code 0 (empty) + ; tile index #$00 is always collision code #$0 cmp COLLISION_CODE_1_TILE_INDEX ; compare against collision code 1 tile index - bcs collision_code_0_check ; pattern table tile is not collision code 1, check to see if collision code 0 + bcs collision_code_0_check ; branch if pattern table tile is not collision code 1, check to see if collision code 0 lda #$01 ; set collision code to 1 (floor) bne collision_continue ; continue ; check if empty collision code collision_code_0_check: cmp COLLISION_CODE_0_TILE_INDEX - bcs collision_code_2_check ; tile index is greater than collision code 2 limit, check if collision code 03 + bcs collision_code_2_check ; tile index is greater than collision code 0 limit, check if collision code 2 set_collision_code_0: lda #$00 ; set collision code to 0 (empty) @@ -6208,7 +6211,7 @@ collision_continue: asl asl asl - asl ; shift the tile code (2 bits) all the way to the left 2 bits + asl ; shift the collision code (2 bits) all the way to the left 2 bits sta $15 ; store modified collision code for super-tile into $15 ldy $12 ; load BG_COLLISION_DATA write offset lda BG_COLLISION_DATA,y ; load existing collision byte (each byte contains collision data for 2 super-tiles) @@ -6221,7 +6224,7 @@ set_collision_tile_col_2: asl asl asl - asl ; shift the tile code (2 bits) all the way to the bits 5 and 4 (..xx ....) + asl ; shift the collision code (2 bits) all the way to the bits 5 and 4 (..xx ....) sta $15 ; store shifted collision code for super-tile into $15 ldy $12 ; load BG_COLLISION_DATA write offset lda BG_COLLISION_DATA,y ; load existing collision byte (each byte contains collision data for 2 super-tiles) @@ -6232,7 +6235,7 @@ set_collision_tile_col_3: dey ; see if second column by subtracting stored write offset bne set_collision_tile_col_4 ; if not the second column, branch to see if 4th asl - asl ; shift the tile code (2 bits) to the bits 2 and 2 (.... xx..) + asl ; shift the collision code (2 bits) to the bits 2 and 2 (.... xx..) sta $15 ; store collision code for super-tile into $15 ldy $12 ; load BG_COLLISION_DATA write offset lda BG_COLLISION_DATA,y ; load existing collision byte (each byte contains collision data for 2 super-tiles) @@ -6537,6 +6540,7 @@ load_next_next_supertiles_screen_indexes: adc #$02 ; add #$02 to load screen in the future bne load_supertiles_screen_indexes ; decompress and load super-tile indexes into LEVEL_SCREEN_SUPERTILES +; load the super tile indexes for the upcoming screen into memory at LEVEL_SCREEN_SUPERTILES load_next_supertiles_screen_indexes: lda LEVEL_SCREEN_NUMBER ; load current screen number within the level clc ; clear carry in preparation for addition diff --git a/src/constants.asm b/src/constants.asm index 363ff1b..a30151d 100644 --- a/src/constants.asm +++ b/src/constants.asm @@ -86,7 +86,8 @@ PPU_WRITE_ADDRESS_LOW_BYTE = $62 ; used to populate the PPU write address i PPU_WRITE_ADDRESS_HIGH_BYTE = $63 ; used to populate the PPU write address in the CPU_GRAPHICS_BUFFER LEVEL_SCREEN_NUMBER = $64 ; the screen number of the current level (how many screens into the level) LEVEL_SCREEN_SCROLL_OFFSET = $65 ; the number of pixels into LEVEL_SCREEN_NUMBER the level has scrolled. Goes from $00-$ff for each screen (256 pixels) - ; for horizontal levels, this is how many pixels scrolled to the right, for vertical levels, this is how many pixels up scrolled + ; for horizontal levels, this is how many pixels scrolled to the right + ; for vertical levels, this is how many pixels up scrolled, note this value is equal to #$f0 - VERTICAL_SCROLL ; for indoor levels, after defeating a wall, increases from #$00 to #03 ATTRIBUTE_TBL_WRITE_LOW_BYTE = $66 ; the low byte of the attribute table write address to write to (always #$c0, never read) ATTRIBUTE_TBL_WRITE_HIGH_BYTE = $67 ; the high byte of the attribute table write address to write to @@ -220,8 +221,8 @@ CONTROLLER_STATE_DIFF = $f5 ; stores the difference between the contro CTRL_KNOWN_GOOD = $f9 ; used in input-reading code to know the last known valid read of controller input (similar to CONTROLLER_STATE) VERTICAL_SCROLL = $fc ; the number of pixels to vertically scroll down ; (y component of PPUSCROLL) (see level_vert_scroll_and_song for initial values) - ; outdoor levels are always #$e0 (224 pixels or 28 tiles down), indoor/base are always #$e8 (232 or 29 tiles down) - ; waterfall level starts at #$00 and decrements as players move up screen (wrapping) + ; horizontal levels are always #$e0 (224 pixels or 28 tiles down), indoor/base are always #$e8 (232 or 29 tiles down) + ; waterfall level (vertical level) starts at #$00 and decrements as players move up screen (wrapping) HORIZONTAL_SCROLL = $fd ; the horizontal scroll component of the PPUSCROLL, [#$0 - #$ff] PPUMASK_SETTINGS = $fe ; used to store value of PPUMASK before writing to PPU PPUCTRL_SETTINGS = $ff ; used to set PPUCTRL value for next frame