SHOW:
|
|
- or go back to the newest paste.
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 | ||
21 | .segment "CODE" | |
22 | ; Procedures | |
23 | ; ----------------------------------------------------------------------------- | |
24 | ||
25 | .proc reset | |
26 | ; Disable Interrupts | |
27 | SEI | |
28 | ||
29 | ; Basic Initialization | |
30 | LDX #0 | |
31 | STX $2000 ; General init state; NMIs (bit 7) disabled. | |
32 | STX $2001 ; Disable rendering, i.e. turn off background & sprites. | |
33 | ||
34 | ; PPU Warmup (29658 Cycles) | |
35 | BIT $2002 ; Clear the VPL Flag if it was set at reset time. | |
36 | vwait1: | |
37 | BIT $2002 ; 27384 Cycles has passed. | |
38 | BPL vwait1 | |
39 | vwait2: | |
40 | BIT $2002 ; 57165 Cycles has passed. | |
41 | BPL vwait2 | |
42 | ||
43 | ; Clear lingering interrupts since before reset. | |
44 | ; BIT $2002 ; Ack VBLANK NMI (if one was left over after reset); bit 7. | |
45 | ||
46 | LDA #%00100000 ; Intensify reds | |
47 | STA $2001 | |
48 | ||
49 | LDA #%10000000 | |
50 | STA $2000 | |
51 | ||
52 | ||
53 | ||
54 | waitfora: | |
55 | ; call subroutine to read current button state | |
56 | JSR readjoy | |
57 | ||
58 | ; check if bit 7 of buttons is set | |
59 | LDA #$80 | |
60 | BIT buttons | |
61 | ||
62 | - | BNE waitfora |
62 | + | |
63 | BEQ waitfora | |
64 | ||
65 | LDA #%01000000 ; Intensify greens | |
66 | STA $2001 | |
67 | ||
68 | LDA #%10000000 | |
69 | STA $2000 | |
70 | ||
71 | LDX #30 | |
72 | JSR waitxframes | |
73 | ||
74 | LDA #%10000000 ; Intensify blues | |
75 | STA $2001 | |
76 | ||
77 | LDA #%10000000 | |
78 | STA $2000 | |
79 | ||
80 | LDX #30 | |
81 | JSR waitxframes | |
82 | ||
83 | forever: | |
84 | JMP forever ; Infinite loop | |
85 | .endproc | |
86 | ||
87 | .proc readjoy | |
88 | LDA #$01 | |
89 | STA $4016 | |
90 | STA buttons ; We use our variable! | |
91 | LSR A | |
92 | STA $4016 | |
93 | ||
94 | loop: | |
95 | LDA $4016 | |
96 | LSR A ; Bit 0 -> Carry | |
97 | ROL buttons ; Carry -> Bit 0; Bit 7 -> Carry | |
98 | BCC loop ; Branch if Carry Clear | |
99 | RTS | |
100 | .endproc | |
101 | ||
102 | .proc nmi | |
103 | INC xframes | |
104 | RTI | |
105 | .endproc | |
106 | ||
107 | .proc irq | |
108 | RTI | |
109 | .endproc | |
110 | ||
111 | .proc waitxframes | |
112 | wait: ; Wait for a frame | |
113 | LDA xframes | |
114 | waitonce: | |
115 | CMP xframes | |
116 | BEQ waitonce | |
117 | DEX ; X = X - 1 | |
118 | BNE wait ; if X is not zero, keep going... | |
119 | RTS | |
120 | .endproc |