From 7d3a82f1730671bc68d271c3fc8c04feebf70081 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 2 Oct 2014 12:37:39 -0400 Subject: refactor --- test.s | 88 ++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/test.s b/test.s index 4d7705b..9dffb26 100644 --- a/test.s +++ b/test.s @@ -1,14 +1,15 @@ .MEMORYMAP SLOTSIZE $2000 DEFAULTSLOT 0 -SLOT 0 $C000 +SLOT 0 $8000 SLOT 1 $E000 +SLOT 2 $0000 .ENDME .ROMBANKMAP -BANKSTOTAL 2 +BANKSTOTAL 3 BANKSIZE $2000 -BANKS 2 +BANKS 3 .ENDRO @@ -51,52 +52,65 @@ vblankwait2: ; Second wait for vblank, PPU is ready after this LDA #%10000000 ;intensify blues STA $2001 - LDX #$00 +loop: + ; read the controller state + JSR read_controller1 -read_controller1: - ; latch - LDA #$01 - STA $4016 - LDA #$00 - STA $4016 - - ; clock - LDA $4016 ; A - AND #%00000001 - TAY - LDA $4016 ; B - LDA $4016 ; Select - LDA $4016 ; Start - LDA $4016 ; Up - LDA $4016 ; Down - LDA $4016 ; Left - LDA $4016 ; Right + ; if A is not pressed, return + LDX #$00 + LDA buttons_pressed.w, X + CMP #$00 + BEQ loop + LDY current_state.w CPY #$00 - BEQ read_controller1 - - CPX #$00 BEQ turn_green - CPX #$01 + CPY #$01 BEQ turn_red turn_blue: LDA #%10000000 STA $2001 - LDX #$00 - JMP read_controller1 - + LDA #$00 + STA current_state.w + JMP color_set turn_green: LDA #%01000000 STA $2001 - LDX #$01 - JMP read_controller1 - + LDA #$01 + STA current_state.w + JMP color_set turn_red: LDA #%00100000 STA $2001 - LDX #$02 - JMP read_controller1 + LDA #$02 + STA current_state.w + JMP color_set + +color_set: + JMP loop + +read_controller1: + ; latch + LDA #$01 + STA $4016 + LDA #$00 + STA $4016 + + ; clock + LDX #$00 +read_controller1_values: + CPX #$07 + BPL end_read_controller1 + + LDA $4016 + AND #%00000001 + STA buttons_pressed.w, X + INX + JMP read_controller1_values + +end_read_controller1: + RTS NMI: @@ -110,3 +124,9 @@ NMI: .dw RESET ;when the processor first turns on or is reset, it will jump ;to the label RESET: .dw 0 ;external interrupt IRQ is not used in this tutorial + + + .bank 2 slot 2 + .org $0000 +buttons_pressed: .ds 8, $00 +current_state: .ds 1, $00 -- cgit v1.2.3