This commit is contained in:
Tyrel Souza 2022-11-28 11:19:19 -05:00
commit fc0bf0edb7
13 changed files with 381 additions and 0 deletions

64
clearmem.asm Normal file
View File

@ -0,0 +1,64 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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

18
exercises/blank.asm Normal file
View File

@ -0,0 +1,18 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
; Load the A register with the literal hexadecimal value $82
; Load the X register with the literal decimal value 82
; Load the Y register with the value that is inside memory position $82
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

19
exercises/exercise01.asm Normal file
View File

@ -0,0 +1,19 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
lda #$82 ; Load the A register with the literal hexadecimal value $82
ldx #82 ; Load the X register with the literal decimal value 82
ldy $82 ; Load the Y register with the value that is inside memory position $82
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

23
exercises/exercise02.asm Normal file
View File

@ -0,0 +1,23 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
lda #$A
ldx %11111111
sta $80
stx $81
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

28
exercises/exercise03.asm Normal file
View File

@ -0,0 +1,28 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
lda #15
tax
tay
txa
tya
ldx #6
txa
tay
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

29
exercises/exercise04.asm Normal file
View File

@ -0,0 +1,29 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
cld
lda #100
clc
adc #5
sec
sbc #10 ; 95 5F BUT ITS 5E?
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

36
exercises/exercise05.asm Normal file
View File

@ -0,0 +1,36 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
cld
lda #$A
ldx #%1010
sta $80
stx $81
lda #10
clc
adc $80
adc $81
sta $82
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

37
exercises/exercise06.asm Normal file
View File

@ -0,0 +1,37 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset: ; TODO:
cld
lda #1
ldx #2
ldy #3
inx
iny
clc
adc #1
dex
dey
sec
sbc #1
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

32
exercises/exercise07.asm Normal file
View File

@ -0,0 +1,32 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset:
cld
lda #10
sta $80
inc $80
dec $80
jmp Reset
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
;.org $FFFC
;.word Start
;.word Start
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

32
exercises/exercise08.asm Normal file
View File

@ -0,0 +1,32 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset:
ldy #10
Loop:
tya
sta $80,Y
dey
bpl Loop
jmp Reset
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

31
exercises/exercise09.asm Normal file
View File

@ -0,0 +1,31 @@
.segment "HEADER" ; Dont forget to always add the iNES header to your ROM files
.org $7FF0
.byte $4E,$45,$53,$1A,$02,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.segment "CODE" ; Define a segment called "CODE" for the PRG-ROM at $8000
.org $8000
Reset:
ldy #1
Loop:
clc
adc #1
cmp #10
bne Loop
NMI: ; NMI handler
rti ; doesn't do anything
IRQ: ; IRQ handler
rti ; doesn't do anything
.segment "VECTORS" ; Add addresses with vectors at $FFFA
.org $FFFA
.word NMI ; Put 2 bytes with the NMI address at memory position $FFFA
.word Reset ; Put 2 bytes with the break address at memory position $FFFC
.word IRQ ; Put 2 bytes with the IRQ address at memory position $FFFE

16
exercises/nes.cfg Normal file
View File

@ -0,0 +1,16 @@
MEMORY {
ZP: start = $0000, size = $0100, type = rw, file = "";
OAM: start = $0200, size = $0100, type = rw, file = "";
RAM: start = $0300, size = $0500, type = rw, file = "";
HDR: start = $7FF0, size = $0010, type = ro, file = %O, fill = yes, fillval = $00;
PRG: start = $8000, size = $8000, type = ro, file = %O, fill = yes, fillval = $00;
CHR: start = $0000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp;
HEADER: load = HDR, type = ro;
CODE: load = PRG, type = ro, start = $8000;
CHARS: load = CHR, type = ro, optional = yes;
VECTORS: load = PRG, type = ro, start = $FFFA;
}

16
nes.cfg Normal file
View File

@ -0,0 +1,16 @@
MEMORY {
ZP: start = $0000, size = $0100, type = rw, file = "";
OAM: start = $0200, size = $0100, type = rw, file = "";
RAM: start = $0300, size = $0500, type = rw, file = "";
HDR: start = $7FF0, size = $0010, type = ro, file = %O, fill = yes, fillval = $00;
PRG: start = $8000, size = $8000, type = ro, file = %O, fill = yes, fillval = $00;
CHR: start = $0000, size = $2000, type = ro, file = %O, fill = yes, fillval = $00;
}
SEGMENTS {
ZEROPAGE: load = ZP, type = zp;
HEADER: load = HDR, type = ro;
CODE: load = PRG, type = ro, start = $8000;
CHARS: load = CHR, type = ro, optional = yes;
VECTORS: load = PRG, type = ro, start = $FFFA;
}