From fc0bf0edb780652cfebee310949a2af4dc6c4174 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 28 Nov 2022 11:19:19 -0500 Subject: [PATCH] init --- clearmem.asm | 64 ++++++++++++++++++++++++++++++++++++++++ exercises/blank.asm | 18 +++++++++++ exercises/exercise01.asm | 19 ++++++++++++ exercises/exercise02.asm | 23 +++++++++++++++ exercises/exercise03.asm | 28 ++++++++++++++++++ exercises/exercise04.asm | 29 ++++++++++++++++++ exercises/exercise05.asm | 36 ++++++++++++++++++++++ exercises/exercise06.asm | 37 +++++++++++++++++++++++ exercises/exercise07.asm | 32 ++++++++++++++++++++ exercises/exercise08.asm | 32 ++++++++++++++++++++ exercises/exercise09.asm | 31 +++++++++++++++++++ exercises/nes.cfg | 16 ++++++++++ nes.cfg | 16 ++++++++++ 13 files changed, 381 insertions(+) create mode 100644 clearmem.asm create mode 100644 exercises/blank.asm create mode 100644 exercises/exercise01.asm create mode 100644 exercises/exercise02.asm create mode 100644 exercises/exercise03.asm create mode 100644 exercises/exercise04.asm create mode 100644 exercises/exercise05.asm create mode 100644 exercises/exercise06.asm create mode 100644 exercises/exercise07.asm create mode 100644 exercises/exercise08.asm create mode 100644 exercises/exercise09.asm create mode 100644 exercises/nes.cfg create mode 100644 nes.cfg diff --git a/clearmem.asm b/clearmem.asm new file mode 100644 index 0000000..b5c5ccc --- /dev/null +++ b/clearmem.asm @@ -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 diff --git a/exercises/blank.asm b/exercises/blank.asm new file mode 100644 index 0000000..f227c71 --- /dev/null +++ b/exercises/blank.asm @@ -0,0 +1,18 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise01.asm b/exercises/exercise01.asm new file mode 100644 index 0000000..c023198 --- /dev/null +++ b/exercises/exercise01.asm @@ -0,0 +1,19 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise02.asm b/exercises/exercise02.asm new file mode 100644 index 0000000..9b31ed6 --- /dev/null +++ b/exercises/exercise02.asm @@ -0,0 +1,23 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise03.asm b/exercises/exercise03.asm new file mode 100644 index 0000000..d6b51e0 --- /dev/null +++ b/exercises/exercise03.asm @@ -0,0 +1,28 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise04.asm b/exercises/exercise04.asm new file mode 100644 index 0000000..3e68304 --- /dev/null +++ b/exercises/exercise04.asm @@ -0,0 +1,29 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise05.asm b/exercises/exercise05.asm new file mode 100644 index 0000000..d1e8853 --- /dev/null +++ b/exercises/exercise05.asm @@ -0,0 +1,36 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise06.asm b/exercises/exercise06.asm new file mode 100644 index 0000000..c80660f --- /dev/null +++ b/exercises/exercise06.asm @@ -0,0 +1,37 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise07.asm b/exercises/exercise07.asm new file mode 100644 index 0000000..8bb712f --- /dev/null +++ b/exercises/exercise07.asm @@ -0,0 +1,32 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise08.asm b/exercises/exercise08.asm new file mode 100644 index 0000000..0a58b43 --- /dev/null +++ b/exercises/exercise08.asm @@ -0,0 +1,32 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/exercise09.asm b/exercises/exercise09.asm new file mode 100644 index 0000000..295df42 --- /dev/null +++ b/exercises/exercise09.asm @@ -0,0 +1,31 @@ +.segment "HEADER" ; Don’t 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 diff --git a/exercises/nes.cfg b/exercises/nes.cfg new file mode 100644 index 0000000..013c1b6 --- /dev/null +++ b/exercises/nes.cfg @@ -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; +} diff --git a/nes.cfg b/nes.cfg new file mode 100644 index 0000000..013c1b6 --- /dev/null +++ b/nes.cfg @@ -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; +}