Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mega Man 6 Randomizer (patch with xkas-plus)
arch nes.cpu
header
banksize $2000
; robot master weaknesses
bank $31
; blizzard
org $9A4A
db $02, $02, $01, $04, $02, $02, $02, $02
; wind
org $9A5A
db $02, $01, $02, $02, $02, $02, $02, $04
; plant
org $9A6A
db $02, $02, $04, $02, $01, $02, $02, $02
; flame
org $9A7A
db $02, $04, $02, $01, $02, $02, $02, $02
; yamato
org $9A8A
db $01, $02, $02, $02, $02, $02, $04, $02
; tomahawk
org $9A9A
db $02, $02, $02, $02, $04, $02, $01, $02
; knight
org $9AAA
db $04, $02, $02, $02, $02, $01, $02, $02
; centaur
org $9ABA
db $02, $02, $02, $02, $02, $04, $02, $01
; disable pause, infinite ammo & lives
bank $38
org $8E8A
NOP
NOP
org $924F
AND #$00
org $932F
NOP
NOP
org $933F
NOP
NOP
org $9EA2
NOP
NOP
NOP
bank $3E
org $C049
JSR weapon_graphics
org $CD30
LDA #$1B
org $CE32
NOP
NOP
NOP
org $DC2E
NOP
NOP
; randomize entry points
org $CE1E
JSR random_2
org $D4B7
JSR random_1
org $D578
JSR screen_switch
org $D5C2
JSR screen_switch
org $D603
JSR screen_switch
org $D644
JSR screen_switch
org $D6A4
JSR screen_switch
org $D6E6
JSR screen_switch
; refight
bank $39
org $8EB6
JSR random_3
bank $3F
org $FB18
; each entry is 2 bytes, format: form, weapon ID
weapon_table:
db $00, $00 ; buster
db $01, $00 ; jet
db $02, $00 ; pow
db $00, $01 ; yamato
db $00, $02 ; wind
db $00, $03 ; blizz
db $00, $04 ; flame
db $00, $05 ; plant
db $00, $06 ; knight
db $00, $07 ; tomahawk
db $00, $08 ; centaur
db $00, $09 ; beat
random_1:
LDA #$01
JSR $D430
JMP randomize
random_2:
STA $0486
JMP randomize
random_3:
STA $04CB
JMP randomize
screen_switch:
PLA
CLC
ADC #$01
PHA
randomize:
; preserve X and status
PHP
TXA
PHA
; loop through white/blacklist table
LDX #$00
stage_whitelist_loop:
; read level # until found or end
LDA stage_whitelists,x
BMI check_out_of_bounds
; compare to current level
CMP $51
BNE next_in_list
; if match found, compare screen #
LDA stage_whitelists+1,x
CMP $046F
BNE next_in_list
; if match found, grab offset
LDA stage_whitelists+2,x
STA $06C1
; roll RNG until matching whitelist
RNG_whitelist_loop:
LDA $DF
CLC
ADC #$01
ADC $F3
STA $DF
LDX $06C1
LDA $DF
AND #$1E
STA $06C2
check_whitelist_loop:
; if we reached end, reroll
LDA whitelist_tables,x
BMI RNG_whitelist_loop
; match? break out and use this roll
LDA $06C2
CMP whitelist_tables,x
BEQ choose_weapon
INX
JMP check_whitelist_loop
next_in_list:
INX
INX
INX
JMP stage_whitelist_loop
check_out_of_bounds:
LDA $DF
AND #$1E
CMP #$17
BCC choose_weapon
; change RNG value and reroll
LDA $DF
CLC
ADC #$01
ADC $F3
STA $DF
JMP check_out_of_bounds
choose_weapon:
; index, store into form & weapon
TAX
LDA weapon_table,x
STA $9B
LDA weapon_table+1,x
STA $0699
; set flag to load graphics
LDA #$01
STA $06C0
; restore X and status
PLA
TAX
PLP
SEC
RTS
weapon_graphics:
; check if we have a weapon's graphics to load
LDA $06C0
BEQ ret
; if so, clear the flag
LDA #$00
STA $06C0
; take care of form
LDX $009B
LDA form_graphics_1,x
STA $06AB
LDA form_graphics_2,x
JSR $CAA4
LDA form_graphics_3,x
STA $00AE
JSR $C9EF
LDX $0699
BEQ cleanup
; replace JSR with just code in it
LDA #$FF
STA $00A5
LDA #$00
STA $009E
LDY #$01
LDA #$00
STA $0021,y
; load weapon stuff
LDA $F708,x
JSR $CAA4
LDA weapon_graphics_table,x
STA $00AE
JSR $C9EF
cleanup:
; LDA #$00
; STA $03A1
; PLA
; STA $06A0
; LDA $0094
; LDX #$00
; JSR $E0FD
ret:
; hijacked
LDA $2002
RTS
form_graphics_1:
db $5A, $3C, $3C
form_graphics_2:
db $00, $02, $03
form_graphics_3:
db $09, $0A, $0A
weapon_graphics_table:
db $09, $B0, $B1, $B2, $B3, $B4, $B5, $B6, $B7, $09
; STAGE WHITELIST FORMAT:
; $ll, $ss, $oo, ll = level # ($FF ends), ss = stage #
; oo = offset into whitelist tables
stage_whitelists:
db $04, $09, $00 ; yamato tunnel
db $04, $0C, $11 ; yamato bottom path
db $03, $07, $0B ; flame rolands
db $06, $18, $11 ; knight letter entrance
db $05, $18, $0F ; tomahawk top path
db $05, $1D, $0F ; tomahawk top path
db $08, $04, $0F ; X1
db $08, $07, $0F ; X1
db $08, $08, $0F ; X1
db $08, $09, $0F ; X1
db $08, $06, $13 ; X1 window
db $09, $05, $0F ; X2 spike pit
db $0A, $00, $0F ; X3
db $0A, $01, $0F ; X3
db $0A, $02, $0F ; X3
db $0A, $0B, $0F ; X3
db $0B, $02, $16 ; X4 sliding tunnels/pow blocks
db $0C, $00, $0F ; W1
db $0C, $0C, $0F ; W1
db $0C, $13, $22 ; mechazaurus
db $0D, $04, $00 ; W2 ice block room
db $0E, $06, $0F ; W3 just before refights
db $FF
whitelist_tables:
; format: $ww, $ww... ends with $FF, ww = weapon index (predoubled)
; 00: no jet / pow
db $00, $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $FF
; 0B: buster, jet, pow
db $00, $02, $04, $FF
; 0F: jet only
db $02, $FF
; 11: pow only
db $04, $FF
; 13: jet or pow
db $02, $04, $FF
; 16: no jet
db $00, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $FF
; 22: no wind & plant
db $00, $02, $04, $06, $0A, $0C, $10, $12, $14, $16, $FF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment