Here's the erasing and programming code from the Squeedo BIOS.
Of course you also need some way to load the program, I use RS232 (it works ok on the controller port and also through the PIC I use on Squeedo). You also need the /Write signal for PRG from the NES. And well, if there's a mapper at $8000-$FFFF that'll complicate things too.
Code:
sector_erase:
lda #$AA
ldy #$55
ldx #$80
sta $8555
sty $82AA
stx $8555
sta $8555
sty $82AA
lda #$30
sta $8000
:
lda $8000
cmp #$FF
bne :-
rts
byte_program:
stx temp2
ldx #$AA
stx $8555
ldx #$55
stx $82AA
ldx #$A0
stx $8555
sta (ptr),y ;(ptr),y
sta temp_lo
@program_wait:
lda (ptr),y
sta count_lo
lda (ptr),y
sta count_hi
and #%01000000
sta temp3
lda count_lo
and #%01000000
cmp temp3
beq @program_done
lda count_hi
and #%00100000
and count_lo
beq @program_wait
lda (ptr),y
sta count_lo
lda (ptr),y
sta count_hi
and #%01000000
sta temp3
lda count_lo
and #%01000000
cmp temp3
beq @program_done
lda #$F0
sta (ptr),y
ldx temp2
rts
@program_done:
; beep
ldx temp2
rts