diff --git a/move b/move new file mode 100755 index 0000000..f21cee5 --- /dev/null +++ b/move @@ -0,0 +1,2 @@ +#!/bin/bash +cp *.nes /Volumes/USB\ DRIVE/ diff --git a/plat.nes b/plat.nes index d118ea3..d7c9069 100644 Binary files a/plat.nes and b/plat.nes differ diff --git a/plat.s b/plat.s index 954594b..aeef160 100644 --- a/plat.s +++ b/plat.s @@ -327,10 +327,10 @@ gamepad_poll: .segment "RODATA" level: -.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -.byte 0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0 -.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -.byte 0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0 +.byte 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1 +.byte 0,1,0,0,1,0,0,0,0,0,0,0,1,1,1,1 +.byte 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1 +.byte 0,1,0,0,1,0,0,0,0,0,0,0,1,1,1,1 .byte 0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 @@ -343,6 +343,10 @@ level: .byte 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +metatiles: +.byte 0,0,0,0,0 +.byte 3,4,5,6,1 + example_palette: .byte $0F,$00,$3D,$20 ; greyscale .byte $0F,$09,$1A,$16 ; grass @@ -371,6 +375,8 @@ var_n: .res 1 var_o: .res 1 var_p: .res 1 +jump_pressed_last_frame: .res 1 + frame_counter: .res 1 .segment "CODE" @@ -488,12 +494,21 @@ movement: @end: ; Jump - jsr btn_up + jsr btn_a cmp #0 - beq :+ - lda #250 - sta vel_y - : + beq @fail_jump ; If jump not pressed, forget it + lda jump_pressed_last_frame + cmp #1 + beq @fail_jump ; If jump last frame, forget it + + ; Jump newly pressed this frame + lda #250 + sta vel_y + + @fail_jump: + + jsr btn_a + sta jump_pressed_last_frame ; Gravity @@ -522,6 +537,16 @@ movement: sta oam+0 : + ; Bonk + lda #8 + cmp oam+0 + bcc :+ + lda #0 + sta vel_y + lda #8 + sta oam+0 + : + ; Apply X velocity lda oam+3 clc @@ -549,6 +574,107 @@ update_background: rts setup_background: + lda $2002 ; reset latch + lda #$20 + sta $2006 + lda #$00 + sta $2006 + ; empty nametable + lda #0 + ldy #30 ; 30 rows + : + ldx #32 ; 32 columns + : + sta $2007 + dex + bne :- + dey + bne :-- + + lda $2002 + lda #$20 + sta $2006 + lda #$00 + sta $2006 + ldy #0 + @row_start: + ldx #0 + : + txa + pha + + ; index is (Y * 16) + X + stx temp_x + lda #16 + jsr mul_y + clc + adc temp_x + tax + + lda level, X + ldx #5 + jsr mul_x + tax + + lda metatiles+0, X + sta $2007 + lda metatiles+1, X + sta $2007 + + pla + tax + inx + cpx #16 + bne :- + + ; again + ldx #0 + : + txa + pha + + ; index is (Y * 16) + X + stx temp_x + lda #16 + jsr mul_y + clc + adc temp_x + tax + + lda level, X + ldx #5 + jsr mul_x + tax + + lda metatiles+2, X + sta $2007 + lda metatiles+3, X + sta $2007 + + pla + tax + inx + cpx #16 + bne :- + iny + cpy #15 + bne @row_start + + + ; clear attributes + lda #0 + ldx #64 ; 64 bytes + : + lda #%11100100 + + sta $2007 + dex + bne :- + + rts + + + lda $2002 ; reset latch lda #$20 sta $2006 @@ -587,19 +713,6 @@ setup_background: - lda $2002 - lda $20 - sta $2006 - lda $00 - sta $2006 - ldy #0 - : - lda level, Y - lda #4 - sta $2007 - iny - cpy #240 - bne :- ; fill in an area in the middle with 1/2 checkerboard @@ -661,23 +774,55 @@ setup_background: rts mul_x: + cmp #0 + beq @zero + cpx #0 + beq @zero + sta temp_mul + + txa + pha lda #0 : clc adc temp_mul dex bne :- + sta temp_mul + pla + tax + lda temp_mul + rts + + @zero: + lda #0 rts mul_y: + cmp #0 + beq @zero + cpy #0 + beq @zero + sta temp_mul + + tya + pha lda #0 : clc adc temp_mul dey bne :- + sta temp_mul + pla + tay + lda temp_mul + rts + + @zero: + lda #0 rts controller: