Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; // Summary
  2. ; // A Very Basic NES ROM that displays 1 color: Blue
  3.  
  4. .segment "INESHDR"
  5.   .byt "NES",$1A
  6.   .byt 1                ; 1 x 16kB PRG block.
  7.   .byt 1                ; 1 x 8kB CHR block.
  8.  
  9. .segment "VECTORS"
  10.   .addr nmi, reset, irq
  11.  
  12. .segment "ZEROPAGE"
  13.   retraces:        .res 1
  14.  
  15. ; Variables
  16. .segment "BSS"
  17.   xframes: .res 1
  18.   buttons: .res 1 ; Reserve 1 byte for storing the data read from controller.
  19.  
  20. .segment "CODE"
  21.   ; Procedures
  22.   ; -----------------------------------------------------------------------------
  23.  
  24.   .proc reset
  25.     ; Disable Interrupts
  26.     SEI
  27.  
  28.     ; Basic Initialization
  29.     LDX #0
  30.     STX $2000       ; General init state; NMIs (bit 7) disabled.
  31.     STX $2001       ; Disable rendering, i.e. turn off background & sprites.
  32.  
  33.     ; PPU Warmup (29658 Cycles)
  34.     BIT $2002   ; Clear the VPL Flag if it was set at reset time.
  35.   vwait1:
  36.     BIT $2002   ; 27384 Cycles has passed.
  37.     BPL vwait1
  38.   vwait2:
  39.     BIT $2002   ; 57165 Cycles has passed.
  40.     BPL vwait2
  41.  
  42.     ; Clear lingering interrupts since before reset.
  43.     ; BIT $2002     ; Ack VBLANK NMI (if one was left over after reset); bit 7.
  44.  
  45.     LDA #%00100000 ; Intensify reds
  46.     STA $2001
  47.  
  48.     LDA #%10000000
  49.     STA $2000
  50.  
  51.  
  52.  
  53.   waitfora:
  54.     ; call subroutine to read current button state
  55.     JSR readjoy
  56.  
  57.     ; check if bit 7 of buttons is set
  58.     LDA #$80
  59.     BIT buttons
  60.  
  61.     ; if not, loop to wait
  62.     BNE waitfora
  63.  
  64.  
  65.  
  66.  
  67.     LDA #%01000000 ; Intensify greens
  68.     STA $2001
  69.  
  70.     LDA #%10000000
  71.     STA $2000
  72.  
  73.     LDX #30
  74.     JSR waitxframes
  75.  
  76.     LDA #%10000000 ; Intensify blues
  77.     STA $2001
  78.  
  79.     LDA #%10000000
  80.     STA $2000
  81.  
  82.     LDX #30
  83.     JSR waitxframes
  84.  
  85.     forever:
  86.       JMP forever     ; Infinite loop
  87.   .endproc
  88.  
  89.   .proc readjoy
  90.     LDA #$01
  91.     STA $4016
  92.     STA buttons ; We use our variable!
  93.     LSR A
  94.     STA $4016
  95.  
  96.   loop:
  97.     LDA $4016
  98.     LSR A       ; Bit 0 -> Carry
  99.     ROL buttons ; Carry -> Bit 0; Bit 7 -> Carry
  100.     BCC loop    ; Branch if Carry Clear
  101.     RTS
  102.   .endproc
  103.  
  104.   .proc nmi
  105.     INC xframes
  106.     RTI
  107.   .endproc
  108.  
  109.   .proc irq
  110.     RTI
  111.   .endproc
  112.  
  113.   .proc waitxframes
  114.     wait:       ; Wait for a frame
  115.       LDA xframes
  116.     waitonce:
  117.       CMP xframes
  118.       BEQ waitonce
  119.       DEX       ; X = X - 1
  120.       BNE wait  ; if X is not zero, keep going...
  121.       RTS
  122.   .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement