commit 1a6dfc60b01d74673edc7fb653a0c4c3489692f2 Author: Zev Averbach Date: Mon Feb 20 18:42:26 2023 +0100 first diff --git a/background/background.asm b/background/background.asm new file mode 100644 index 0000000..b5e9bf3 --- /dev/null +++ b/background/background.asm @@ -0,0 +1,76 @@ + .inesprg 1 ; 1x 16KB PRG code + .ineschr 1 ; 1x 8KB CHR data + .inesmap 0 ; mapper 0 = NROM, no bank swapping + .inesmir 1 ; background mirroring + + +;;;;;;;;;;;;;;; + + + .bank 0 + .org $C000 +RESET: + SEI ; disable IRQs + CLD ; disable decimal mode + LDX #$40 + STX $4017 ; disable APU frame IRQ + LDX #$FF + TXS ; Set up stack + INX ; now X = 0 + STX $2000 ; disable NMI + STX $2001 ; disable rendering + STX $4010 ; disable DMC IRQs + +vblankwait1: ; First wait for vblank to make sure PPU is ready + BIT $2002 + BPL vblankwait1 + +clrmem: + LDA #$00 + STA $0000, x + STA $0100, x + STA $0200, x + STA $0400, x + STA $0500, x + STA $0600, x + STA $0700, x + LDA #$FE + STA $0300, x + INX + BNE clrmem + +vblankwait2: ; Second wait for vblank, PPU is ready after this + BIT $2002 + BPL vblankwait2 + + + LDA #%11111111 ;intensify blues + STA $2001 + +Forever: + JMP Forever ;jump back to Forever, infinite loop + + + +NMI: + RTI + +;;;;;;;;;;;;;; + + + + .bank 1 + .org $FFFA ;first of the three vectors starts here + .dw NMI ;when an NMI happens (once per frame if enabled) the + ;processor will jump to the label NMI: + .dw RESET ;when the processor first turns on or is reset, it will jump + ;to the label RESET: + .dw 0 ;external interrupt IRQ is not used in this tutorial + + +;;;;;;;;;;;;;; + + + .bank 2 + .org $0000 + .incbin "mario.chr" ;includes 8KB graphics file from SMB1 diff --git a/background/background.bat b/background/background.bat new file mode 100644 index 0000000..8bb24ac --- /dev/null +++ b/background/background.bat @@ -0,0 +1,2 @@ +NESASM3 background.asm +pause \ No newline at end of file diff --git a/background/background.fns b/background/background.fns new file mode 100644 index 0000000..39a9463 --- /dev/null +++ b/background/background.fns @@ -0,0 +1,7 @@ +; background.asm +Forever = $C042 +vblankwait1 = $C014 +vblankwait2 = $C038 +clrmem = $C019 +RESET = $C000 +NMI = $C045 diff --git a/background/background.nes b/background/background.nes new file mode 100644 index 0000000..bbcfe3a Binary files /dev/null and b/background/background.nes differ diff --git a/mario.chr b/mario.chr new file mode 100644 index 0000000..d150ccc Binary files /dev/null and b/mario.chr differ diff --git a/palette/palette.asm b/palette/palette.asm new file mode 100644 index 0000000..5c1bb9e --- /dev/null +++ b/palette/palette.asm @@ -0,0 +1,92 @@ + .inesprg 1 ; 1x 16KB PRG code + .ineschr 1 ; 1x 8KB CHR data + .inesmap 0 ; mapper 0 = NROM, no bank swapping + .inesmir 1 ; background mirroring + + +;;;;;;;;;;;;;;; + + + .bank 0 + .org $C000 +RESET: + SEI ; disable IRQs + CLD ; disable decimal mode + LDX #$40 + STX $4017 ; disable APU frame IRQ + LDX #$FF + TXS ; Set up stack + INX ; now X = 0 + STX $2000 ; disable NMI + STX $2001 ; disable rendering + STX $4010 ; disable DMC IRQs + +vblankwait1: ; First wait for vblank to make sure PPU is ready + BIT $2002 + BPL vblankwait1 + +clrmem: + LDA #$00 + STA $0000, x + STA $0100, x + STA $0200, x + STA $0400, x + STA $0500, x + STA $0600, x + STA $0700, x + LDA #$FE + STA $0300, x + INX + BNE clrmem + +vblankwait2: ; Second wait for vblank, PPU is ready after this + BIT $2002 + BPL vblankwait2 + + ; get ready to write to the palettes in the PPU + LDA $2002 ; read PPU status to reset the high/low byte + LDA #$3F ; load the high byte of the addres #3F10 + STA $2006 ; store that high byte + LDA #$10 ; load the low byte of the addres #3F10 + STA $2006 ; store that low byte + + ; a succinct way of defining colors for pushing into the palettes +PaletteData: + .db $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F + .db $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C + ; using a loop, load the values stored in PaletteData into the background and sprite palettes + LDX #$00 +LoadPalettesLoop: + LDA PaletteData, x + STA $2007 ; store the value of the Accumulator in the next memory slot in the PPU (referred to by this 'port' located at $2007) + INX ; incrementing + CPX #$20 ; is X == 32? + BNE LoadPalettesLoop + +Forever: + JMP Forever ;jump back to Forever, infinite loop + + + +NMI: + RTI + +;;;;;;;;;;;;;; + + + + .bank 1 + .org $FFFA ;first of the three vectors starts here + .dw NMI ;when an NMI happens (once per frame if enabled) the + ;processor will jump to the label NMI: + .dw RESET ;when the processor first turns on or is reset, it will jump + ;to the label RESET: + .dw 0 ;external interrupt IRQ is not used in this tutorial + + +;;;;;;;;;;;;;; + + + .bank 2 + .org $0000 + .incbin "mario.chr" ;includes 8KB graphics file from SMB1 diff --git a/palette/palette.fns b/palette/palette.fns new file mode 100644 index 0000000..2c110ac --- /dev/null +++ b/palette/palette.fns @@ -0,0 +1,9 @@ +; palette.asm +Forever = $C077 +LoadPalettesLoop = $C06C +PaletteData = $C04A +vblankwait1 = $C014 +vblankwait2 = $C038 +clrmem = $C019 +RESET = $C000 +NMI = $C07A diff --git a/palette/palette.nes b/palette/palette.nes new file mode 100644 index 0000000..35b65af Binary files /dev/null and b/palette/palette.nes differ