Hey all! I sat down to try and figure out a basic way to do some controller codes that people could use to do things like the Konami code. I thought I'd share what I ended up using, and ask how some of you might've or have handled it. This is what I came up with:
EDIT: Here's a ROM with it working on the title screen.
EDIT: Here's a ROM with it working on the title screen.
Code:
code_count: .res 1 ; Number of frames between each button press
code_offset: .res 1 ; Which byte to check in the code_check table
code_check:
.byte up_punch, up_punch, down_punch, down_punch
.byte left_punch, right_punch, left_punch, right_punch
.byte b_punch, a_punch
test_code:
ldx code_offset ; Get the offset ready
lda control_pad ; Check buttons for only one
eor control_old ; button press at a time
and control_pad ;
and code_check, x ; Check the button press against
beq :+ ; the code_check table
lda #$10 ; When buttons match, reset the
sta code_count ; code count and increase the
lda code_offset ; offset by one.
clc ;
adc #$01 ;
sta code_offset ;
cmp #$0a ; Compare accumulator to max
bne :+ ; offset in code_check table
jsr PPU_off ; Do successful code input stuff
; here. Be sure to jump over
; everything else to the end
; of the routine when you
; actually implement this.
: lda code_count ; If code_count is NOT zero...
beq :+ ;
sec ; ... then subtract it by one
sbc #$01 ; and return.
sta code_count ;
rts ;
: lda #$00 ; If code_count was zero then
sta code_offset ; set code_offset back to zero,
rts ; which means the code input
; failed, and must start from
; the beginning.
[/url]code_offset: .res 1 ; Which byte to check in the code_check table
code_check:
.byte up_punch, up_punch, down_punch, down_punch
.byte left_punch, right_punch, left_punch, right_punch
.byte b_punch, a_punch
test_code:
ldx code_offset ; Get the offset ready
lda control_pad ; Check buttons for only one
eor control_old ; button press at a time
and control_pad ;
and code_check, x ; Check the button press against
beq :+ ; the code_check table
lda #$10 ; When buttons match, reset the
sta code_count ; code count and increase the
lda code_offset ; offset by one.
clc ;
adc #$01 ;
sta code_offset ;
cmp #$0a ; Compare accumulator to max
bne :+ ; offset in code_check table
jsr PPU_off ; Do successful code input stuff
; here. Be sure to jump over
; everything else to the end
; of the routine when you
; actually implement this.
: lda code_count ; If code_count is NOT zero...
beq :+ ;
sec ; ... then subtract it by one
sbc #$01 ; and return.
sta code_count ;
rts ;
: lda #$00 ; If code_count was zero then
sta code_offset ; set code_offset back to zero,
rts ; which means the code input
; failed, and must start from
; the beginning.