;--------------------------------------------------------------------------- ; simple example that demonstrates how to write to the flash ROM ;--------------------------------------------------------------------------- !src "../include/gmod3.inc" * = $0801 !word nextline !word 2016 !byte $9e !byte $32, $30, $36, $31 nextline: !byte 0,0,0 jmp start !src "../lib/gmod3.asm" NOERASE = 0 ONEPAGE = 0 ;------------------------------------------------------------------------------- start: ;sei ; clear screen ldx #0 - lda #$20 sta $0400,x sta $0500,x sta $0600,x sta $0700,x lda #$01 sta $d800,x sta $d900,x sta $da00,x sta $db00,x inx bne - ; erase one 64k page inc $0404 ; to indicate progress !if NOERASE = 0 { lda #$00 jsr flash_erase } ; before we can write to the flash, we must erase it ; inc $0400 ; to indicate progress ; jsr flash_chiperase ; inc $0401 ; to indicate progress ; ldy #0 ;-- ldx #0 - ; tya ; pha txa pha inc $0405 ; to indicate progress ; set byte program command and flash address pla pha tax lda #0 sta addr2 ;ldx #0 stx addr1 ;lda #0 ;sta addr0 inc $0406 ; to indicate progress lda #cart_file_start ; program one 256byte page jsr flash_writepage lda cadd+1 pha lsr lsr lsr lsr tay lda hexdigits,y sta $0400 pla and #$0f tay lda hexdigits,y sta $0401 pla tax ; pla ; tay inc cadd+1 !if ONEPAGE = 0 { inx cpx #$20 ; number of pages bne - } ; iny ; cpy #$20 ; bne -- - inc $d020 dec $d020 jmp - failure: lda #2 sta $d020 jmp * hexdigits: !scr "0123456789abcdef" ;------------------------------------------------------------------------------- ; align to page boundary so we only have to compare the highbyte of the ; source address in the above loop !align 255,0 !if ONEPAGE = 1 { cart_file_start: !for i,0,255 { !byte i } } else { !if FX = 1 { cart_file_start: !binary "../cartridge-skeleton/gamecart1.bin",$2000 } !if FX = 2 { cart_file_start: !binary "../cartridge-skeleton/gamecart2.bin",$2000 } !if FX = 0 { cart_file_start = $4000 } }