pikuma_6502_nes/clearmem.asm

52 lines
2.4 KiB
NASM
Raw Normal View History

2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PRG-ROM code located at $8000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2022-11-28 16:19:19 +00:00
.segment "CODE"
2022-11-28 18:15:40 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Reset handler (called when the NES resets/powers-on)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Reset:
sei ; Disable all IRQ interrupts
cld ; Clear the decimal mode (unsupported by the NES)
ldx #$FF
txs ; Initialize the stack pointer at $01FF
2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
inx ; Increment X, causing a roll-off from $FF to $00
2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
txa ; A = 0
ClearRAM:
sta $0000,x ; Zero RAM addresses from $0000 to $00FF
sta $0100,x ; Zero RAM addresses from $0100 to $01FF
sta $0200,x ; Zero RAM addresses from $0200 to $02FF
sta $0300,x ; Zero RAM addresses from $0300 to $03FF
sta $0400,x ; Zero RAM addresses from $0400 to $04FF
sta $0500,x ; Zero RAM addresses from $0500 to $05FF
sta $0600,x ; Zero RAM addresses from $0600 to $06FF
sta $0700,x ; Zero RAM addresses from $0700 to $07FF
inx ; X++
bne ClearRAM ; Loops until X reaches 0 again (after roll-off)
2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
LoopForever:
jmp LoopForever ; Forces an infinite loop
2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NMI interrupt handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2022-11-28 16:19:19 +00:00
NMI:
2022-11-28 18:15:40 +00:00
rti ; Return from interrupt
2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; IRQ interrupt handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2022-11-28 16:19:19 +00:00
IRQ:
2022-11-28 18:15:40 +00:00
rti ; Return from interrupt
2022-11-28 16:19:19 +00:00
2022-11-28 18:15:40 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Vectors with the addresses of the handlers that we always add at $FFFA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2022-11-28 16:19:19 +00:00
.segment "VECTORS"
2022-11-28 18:15:40 +00:00
.word NMI ; Address (2 bytes) of the NMI handler
.word Reset ; Address (2 bytes) of the Reset handler
.word IRQ ; Address (2 bytes) of the IRQ handler