diff --git a/plat.nes b/plat.nes index 0b2ffa3..74a2636 100644 Binary files a/plat.nes and b/plat.nes differ diff --git a/plat.s b/plat.s index 534ca81..34effd2 100644 --- a/plat.s +++ b/plat.s @@ -81,11 +81,15 @@ nmi_lock: .res 1 nmi_count: .res 1 nmi_ready: .res 1 nmt_update_len: .res 1 +nmt_column: .res 1 scroll_x: .res 1 scroll_y: .res 1 scroll_nmt: .res 1 +scroll_page: .res 1 temp: .res 1 +PPUCTRL_default = %10101000 + .segment "BSS" nmt_update: .res 256 palette: .res 32 @@ -145,18 +149,73 @@ nmi: ldx #0 cpx nmt_update_len bcs @scroll + + lda PPUCTRL_default + ;ora #%00000100 + sta $2000 + + ldy #0 @nmt_update_loop: - lda nmt_update, X + lda #6 + jsr mul_y + tax + + lda $2002 + + lda nmt_update+0, X sta $2006 - inx - lda nmt_update, X + lda nmt_update+1, X sta $2006 - inx - lda nmt_update, X + + lda nmt_update+2, X sta $2007 - cpx nmt_update_len + lda nmt_update+3, X + sta $2007 + + + lda $2002 + + lda nmt_update+0, X + sta $2006 + lda nmt_update+1, X + clc + adc #32 + sta $2006 + + lda nmt_update+4, X + sta $2007 + lda nmt_update+5, X + sta $2007 + + +; lda $2002 +; lda #$20 +; sta $2006 + +; lda nmt_update, Y +; sec +; rol +; sta $2006 + +; ldx nmt_update +; lda level, X +; and #%01111111 +; ldx #5 +; jsr mul_x +; tax +; +; lda metatiles+1, X +; sta $2007 +; lda metatiles+3, X +; sta $2007 + + iny + cpy nmt_update_len bcc @nmt_update_loop + lda PPUCTRL_default + sta $2000 + lda #0 sta nmt_update_len @scroll: @@ -228,66 +287,51 @@ PAD_D = $20 PAD_L = $40 PAD_R = $80 -.segment "ZEROPAGE" -gamepad: .res 1 - -.segment "CODE" -; gamepad_poll: this reads the gamepad state into the variable labelled "gamepad" -; This only reads the first gamepad, and also if DPCM samples are played they can -; conflict with gamepad reading, which may give incorrect results. -gamepad_poll: - ; strobe the gamepad to latch current button state - lda #1 - sta $4016 - lda #0 - sta $4016 - ; read 8 bytes from the interface at $4016 - ldx #8 - : - pha - lda $4016 - ; combine low two bits and store in carry bit - and #%00000011 - cmp #%00000001 - pla - ; rotate carry into gamepad variable - ror - dex - bne :- - sta gamepad - rts - - .segment "RODATA" -level: +default_level: .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $00,$00,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 -.byte $82,$83,$00,$00,$00,$00,$00,$00,$81,$00,$0C,$00,$81,$00,$00,$00 -.byte $84,$85,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$0C,$00,$0C,$00,$0C,$00,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$81,$00,$0C,$00,$81,$00,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $0F,$8C,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80,$80 +.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +;.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +;.byte $00,$00,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 +;.byte $82,$83,$00,$00,$00,$00,$00,$00,$81,$00,$0C,$00,$81,$00,$00,$00 +;.byte $84,$85,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$0C,$00,$0C,$00,$0C,$00,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$81,$00,$0C,$00,$81,$00,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$81,$00,$81,$00,$81,$00,$81,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$8C,$87 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +;.byte $0F,$8C,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87,$87 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +;.byte $0F,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -level2: +default_level2: .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 .byte $00,$8C,$8C,$8C,$8C,$8C,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $00,$09,$0C,$0C,$0C,$8C,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $00,$8C,$8C,$8C,$0C,$06,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 -.byte $00,$09,$0C,$0C,$0C,$8C,$00,$00,$00,$00,$00,$82,$83,$00,$00,$00 +.byte $00,$09,$01,$01,$01,$8C,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$8C,$8C,$8C,$01,$06,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 +.byte $00,$09,$01,$01,$01,$8C,$00,$00,$00,$00,$00,$82,$83,$00,$00,$00 .byte $00,$8C,$8C,$8C,$8C,$8C,$00,$00,$00,$00,$00,$84,$85,$00,$00,$00 .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0F,$0E,$00,$82,$83 .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0F,$0E,$00,$84,$85 .byte $00,$00,$00,$00,$00,$00,$00,$00,$82,$83,$00,$0F,$0E,$00,$0F,$0E -.byte $00,$00,$00,$00,$00,$00,$00,$00,$84,$85,$00,$0F,$0E,$00,$0F,$0E +.byte $87,$8C,$00,$00,$00,$00,$00,$00,$84,$85,$00,$0F,$0E,$00,$0F,$0E .byte $00,$00,$00,$00,$00,$00,$00,$00,$0F,$0E,$00,$0F,$0E,$00,$0F,$0E .byte $00,$00,$00,$00,$00,$00,$00,$00,$0F,$0E,$00,$0F,$0E,$00,$0F,$0E .byte $87,$87,$87,$87,$87,$8C,$00,$00,$0F,$0E,$00,$0F,$0E,$00,$0F,$0E @@ -343,6 +387,11 @@ example_palette: ; .byte $0F,$1B,$2B,$3B ; sp2 teal ; .byte $0F,$12,$22,$32 ; sp3 marine + +terrain: +; page pos struct +.byte $00, $00, $00 + .segment "ZEROPAGE" buttons: .res 1 @@ -377,6 +426,12 @@ frame_counter: .res 1 last_frame_jumped: .res 1 last_frame_moving: .res 1 +tile_update_pos_r: .res 1 + +.segment "BSS" +level: .res 240 +level2: .res 240 + .segment "CODE" main: ldx #0 @@ -456,28 +511,8 @@ move_camera: @end: - lda camera_speed - bmi @left - clc - adc scroll_x - cmp scroll_x - sta scroll_x - bcs :+ - lda scroll_nmt - eor #%00000001 - sta scroll_nmt - : - rts - @left: - clc - adc scroll_x - cmp scroll_x - sta scroll_x - bcc :+ - lda scroll_nmt - eor #%00000001 - sta scroll_nmt - : + jsr add_scroll_x + jsr check_column_update rts draw_player: @@ -667,6 +702,7 @@ init_objects: lda #0 sta camera_speed + sta tile_update_pos_r rts @@ -961,6 +997,42 @@ movement: rts setup_background: + ldx #0 + : + lda default_level, X + sta level, X + + inx + cpx #240 + bne :- + + ldx #0 + : + lda default_level2, X + sta level2, X + + inx + cpx #240 + bne :- + + ldx #0 + : + lda default_level, X + sta level, X + + inx + cpx #240 + bne :- + + ldx #0 + : + lda default_level2, X + sta level2, X + + inx + cpx #240 + bne :- + lda $2002 ; reset latch lda #$20 sta $2006 @@ -1050,7 +1122,6 @@ setup_background: cpy #15 bne @row_start_nmt1 - ; clear attributes ;lda #0 ;ldx #64 ; 64 bytes @@ -1366,6 +1437,129 @@ setup_background: rts +add_scroll_x: + lda camera_speed + bmi @left + clc + adc scroll_x + cmp scroll_x + sta scroll_x + bcs :+ + lda scroll_nmt + eor #%00000001 + sta scroll_nmt + ldx scroll_page + inx + sta scroll_page + : + rts + @left: + clc + adc scroll_x + cmp scroll_x + sta scroll_x + bcc :+ + lda scroll_nmt + eor #%00000001 + sta scroll_nmt + ldx scroll_page + dex + sta scroll_page + : + rts + +check_column_update: + clc + lda scroll_nmt + beq :+ + sec + : + + lda scroll_x + ror + lsr + lsr + lsr + + cmp tile_update_pos_r + bne :+ + jsr update_nmt_column + lda tile_update_pos_r + clc + adc #1 + and #%00011111 + sta tile_update_pos_r + + : + + rts + +update_nmt_column: + ldx #0 + : + lda #16 + jsr mul_x + clc + adc tile_update_pos_r + tay + lda #%10000001 + sta level, Y + + and #%01111111 + ldy #5 + jsr mul_y + tay + + + txa + pha + + lda #6 + jsr mul_x + tax + + lda metatiles+0, Y + sta nmt_update+2, X + lda metatiles+1, Y + sta nmt_update+3, X + lda metatiles+2, Y + sta nmt_update+4, X + lda metatiles+3, Y + sta nmt_update+5, X + + + pla + tay + + lsr + lsr + clc + adc #$20 + sta nmt_update+0, X + + lda #64 + jsr mul_y + clc + adc tile_update_pos_r + clc + adc tile_update_pos_r + sta nmt_update+1, X + + + + tya + tax + + inx + cpx #15 + bne :- + + + lda #15 + sta nmt_update_len + + rts + mul_x: cmp #0 beq @zero