A request for a noob/newb.

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Jeroen
Posts: 1048
Joined: Tue Jul 03, 2007 1:49 pm

A request for a noob/newb.

Post by Jeroen »

Ok I have a (simple) request. I've been reading on nesdocs, but can someone make some good (good commented) code for just turning on a green backround? If so you would be a great help. Thanks for reading.

Edit: Also it doesn't have to be super effiecient code. Just has to run and be simple.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

Code: Select all

lda #$3f
sta $2006
lda #$00
sta $2006   ;PPU adress $3f00
lda #$19
sta $2007   ;Set BG/transparant color to $19 (green)
lda #$0e
sta $2001   ;Turn background on
User avatar
Jeroen
Posts: 1048
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen »

Sorry forgot a part. (altough stil thanks for the above code) I meant really the entire program. That way I can learn some more asm ect. (well that is the plan)
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

This program is untested, and it is incomplete because it needs a linker script to tell ld65 where in memory to put each segment, but it should give you an idea of what needs to be done to set up the NES hardware:

Code: Select all

PPUCTRL = $2000
PPUMASK = $2001
PPUSTATUS = $2002
PPUADDR = $2006
PPUDATA = $2007

.segment "CODE"
nmi:
irq:
  rti

reset:
  sei  ; turn off most interrupts
  ldx #0
  stx PPUCTRL  ; turn off PPU interrupts
  stx PPUMASK  ; turn off PPU rendering
  cld  ; turn off 6502 decimal mode
       ; the NES doesn't have it but some famiclones and debuggers do
  dex  ; set up the stack pointer
  txs

; before writing anything to PPU registers $2003 through $2007
; we must wait for PPUSTATUS bit 7 (the "sign bit") to be set twice
:
  lda PPUSTATUS
  bpl :-
; usually there will be about 30,000 CPU cycles between the first two
; times it is set, so use that time to clear out the RAM or something
; (omitted here)
:
  lda PPUSTATUS
  bpl :-

; set the VRAM write cursor to $3F00 (start of palette area)
  lda #$3F
  sta PPUADDR
  lda #$00
  sta PPUADDR

; write a green value to color 0, which is ordinarily displayed
; on the whole screen when rendering is turned off
  lda #$1A
  sta PPUDATA

; set the VRAM write cursor to $0000, which is outside the palette area
; otherwise, garbage will appear on the screen
  lda #$00
  sta PPUADDR
  sta PPUADDR

; freeze the CPU so that you can see the green screen
:
  jmp :-

.segment "VECTORS"
  .addr nmi, reset, irq
User avatar
Jeroen
Posts: 1048
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen »

Thanks that really helps alot :o .
Post Reply