Advertisement
Guest User

Change BG Code (not working) 6502 NES

a guest
Oct 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. ;------------------------------------
  2. ; Constants
  3. ;------------------------------------
  4. PRG_COUNT = 1 ; 2 = 32KB
  5. MIRRORING = %0001 ; %0000 = horizontal, %0001 = vertical, %1000 = four-screen
  6.  
  7. ;------------------------------------
  8. ; Variables
  9. ;------------------------------------
  10. .enum $0000
  11.  
  12. ; Variables are declared using DSB/DSW i.e.:
  13. ;myVar0 .dsb 1
  14. ;myVar1 .dsb 3
  15.  
  16. .ende
  17.  
  18. ;------------------------------------
  19. ; iNES Header (NROM)
  20. ;------------------------------------
  21. .db "NES", $1a ; identification of the iNES header
  22. .db PRG_COUNT ; number of 16KB PRG-ROM pages
  23. .db $01 ; number of 8KB CHR-ROM pages
  24. .db $00 | MIRRORING ; mapper 0 and mirroring
  25. .dsb 9, $00 ; clear the remaining bytes
  26.  
  27. ;------------------------------------
  28. ; Program Bank(s)
  29. ;------------------------------------
  30. .base $10000 - (PRG_COUNT * $4000)
  31. RESET: ; RESET subroutine.
  32. sei ; disable interrupts
  33. cld ; disable decimal mode
  34.  
  35. ldx #$40
  36. stx $4017 ; disable APU frame interrupt
  37.  
  38. ldx #$FF
  39. txs ; initialize stack
  40.  
  41. inx ; X = 0
  42. stx $2000 ; disable NMI
  43. stx $2001 ; disable rendering
  44. stx $4010 ; disable DMC interrupts
  45.  
  46. @vblankWait1:
  47. bit $2002
  48. bpl @vblankWait1 ; first wait for vblank to make sure PPU is ready
  49.  
  50. @resetClearMem:
  51. lda #$00
  52. sta $0000, x
  53. sta $0100, x
  54. sta $0200, x
  55. sta $0400, x
  56. sta $0500, x
  57. sta $0600, x
  58. sta $0700, x
  59. lda #$FE
  60. sta $0300, x ; clear working RAM
  61. inx
  62. bne @resetClearMem
  63.  
  64. @vblankWait2:
  65. bit $2002
  66. bpl @vblankWait2 ; second wait for vblank, PPU will be ready at this point
  67.  
  68. LoadPalettes:
  69. lda $2002 ; read PPU status to reset the high/low latch
  70.  
  71. lda #$3F ; write $3F00 into VRAM address
  72. sta $2006 ; low byte
  73. lda #$00
  74. sta $2006 ; high byte
  75.  
  76. lda $25
  77. sta $2007
  78.  
  79. ; ldx #$00
  80. ;@LoadPalettesLoop:
  81. ; lda bg_palette, x
  82. ; sta $2007 ; write to PPU
  83. ; inx
  84. ; cpx #$10 ; $10 = 16, copying 16 bytes = 4 sprites
  85. ; bne @LoadPalettesLoop
  86.  
  87. INFLOOP: ; Game waits here forever so we can get NMIs 60 times a second.
  88. jmp INFLOOP
  89.  
  90. NMI: ; Game loop (called from interrupt)
  91.  
  92. rti
  93.  
  94. IRQ: ; External interrupt requests handled here
  95.  
  96. rti
  97.  
  98. .base $E000 ; WAS: $10000 - ((PRG_COUNT - 1) * $4000)
  99. bg_palette:
  100. .db $22,$29,$1A,$0F
  101. .db $22,$36,$17,$0F
  102. .db $22,$30,$21,$0F
  103. .db $22,$27,$17,$0F
  104. sprite_palette:
  105. .db $22,$16,$27,$18
  106. .db $22,$1A,$30,$27
  107. .db $22,$16,$30,$27
  108. .db $22,$0F,$36,$17
  109.  
  110. .org $FFFA ; location of interrupt vectors
  111. ;;; Interrupt Vectors ;;;
  112. .dw NMI ; once per frame
  113. .dw RESET ; when processor turns on or is reset
  114. .dw IRQ ; external interrupt IRQ unused so far.
  115. ;;;;;;;;;;;;;;;;;;;;;;;;;
  116.  
  117. ;------------------------------------
  118. ; CHR-ROM bank
  119. ;------------------------------------
  120. .incbin mario.chr ; include graphics
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement