pikuma_6502_nes/clearmem.asm

65 lines
2.4 KiB
NASM
Raw Normal View History

2022-11-28 16:19:19 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The iNES Header contains a total of 16 bytes with
;; flags at $7FF0
;; https://www.nesdev.org/wiki/INES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.segment "HEADER"
.org $7FF0
.byte $4E,$45,$53,$1A ; 4 bytes with chars NES\n
.byte $02 ; 1 byte how many 16kb in pgm-rom
.byte $01 ; 1 byte how many 8kb chr-rom
.byte %00000000 ; Horiz mirroring, nothing else
.byte %00000000 ; Flags 7 - nothing
.byte $00 ; Flags 8 - no PGM-RAM
.byte $00 ; NTSC
.byte $00 ; no PGM-RAM
.byte $00,$00,$00,$00,$00 ; unused padding to complete 16bytes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PGM-ROM code located at $8000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.segment "CODE"
.org $8000 ; start of program rom
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RESET:
sei ; set interrupt disable - disable all IRQ
cld ; clear decimal mode BCD flag (unused)
ldx #$FF ;
txs ; initialize stack pointer at $01FF
;;;;; LOOP ALL MEMORY POSITIONS FROM 00 to FF clearing
lda #$0 ; A = $0
inx ; increment X from $FF to $0
MemLoop:
sta $0,x ; store the value of A (zero) into $0 + X
dex ; X--
bne MemLoop ; loop back to MemLoop if X is not 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NMI Handler - executed every time NMI interrupt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
NMI:
rti ;return from interrupt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; IRQ Handler - executed every time IRQ interrupt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IRQ:
rti ;return from interrupt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SEGMENTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.segment "VECTORS"
.org $FFFA ; 6502 will always start at $FFFA
.word NMI ; address of the NMI Handler label
.word RESET ; address of the RESET Handler label
.word IRQ ; address of the IRQ Handler label