Yay my first program.

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

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

Yay my first program.

Post by Jeroen » Tue Feb 26, 2008 5:04 pm

Got of my lazy ass and started programming. 15-30 min later I had a program that could display green (had some problems) special thanks to the guy that made the init code on the wiki BOOdaw and Bunnyboy.

code is here: http://rafb.net/p/J1kgB593.html

edit: slightly more noob friendly code here: http://rafb.net/p/jugLRR33.html

User avatar
Jeroen
Posts: 982
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen » Wed Feb 27, 2008 6:28 pm

sorry they took it down, put it up as soon as I have acces to the computer that has it stored.

User avatar
Jeroen
Posts: 982
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen » Mon Mar 03, 2008 1:14 pm

Code: Select all

        .inesprg    1
        .ineschr    0
        .inesmir    1
        .inesmap  0
	
	.org $8000
	.bank 0

reset:
    sei        ; ignore 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

    ; Optional (omitted):
    ; Set up mapper and jmp to further init code here.

    ; First of two waits for vertical blank to make sure that the
    ; PPU has stabilized
vblankwait1:  
    bit $2002
    bpl vblankwait1

    ; We now have about 30,000 cycles to burn before the PPU stabilizes.
    ; Use it to clear RAM.  X is still 0...
    txa
clrmem:
    sta $000,x
    sta $100,x
    sta $200,x
    sta $300,x
    sta $400,x
    sta $500,x
    sta $600,x
    sta $700,x  ; Remove this if you're storing reset-persistent data
    inx
    bne clrmem
   
vblankwait2:
    bit $2002
    bpl vblankwait2

chngbkr:
   lda #$3F 
   sta $2006 ;first we write the upper byte of the ppu adress we want to ;write to in this case $3F00
   lda #$00
   sta $2006 ;now we write the lower byte #$00
   lda #$2a ;value green = #$2a
   sta $2007 ;ppudata
   lda #%00001000
   sta $2001 ;main screen turn on

loop:

   jmp loop

		;!The Vector Table!
    	.bank 1
	.org	$FFFA
	.dw		0 ;(NMI_Routine)
	.dw		reset  ;(Reset_Routine)
	.dw		0 ;(IRQ_Routine)



Last edited by Jeroen on Fri Sep 17, 2010 5:33 am, edited 1 time in total.

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Mon Mar 03, 2008 3:14 pm

Good work as your first program. Now try and do something with graphics or sound.

User avatar
Jeroen
Posts: 982
Joined: Tue Jul 03, 2007 1:49 pm

Post by Jeroen » Tue Mar 04, 2008 2:47 pm

I did actually. As the people on the irc channel know. I made a program with a moveable sprite. kinda confused on sound though :-/

Celius
Posts: 2157
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius » Tue Mar 04, 2008 4:00 pm

Yeah, sound really confused me at first. There are still things I don't quite understand about sound. But if you just mess around with it, you will eventually figure it out. Here, look at this code:

Code: Select all

	lda #$01
	sta $4015
	lda #$1F
	sta $4000
	lda #$08
	sta $4001
	lda #$4D
	sta $4002
	lda #$55
	sta $4003
You can place this somewhere to make a short low tone. You can edit the value of what's going into $4002 and bits 0-2 of what's going into $4003 to make the pitch different. If you want to see the values you can store into the registers to get pitch perfect notes, refer to my document:

http://www.freewebs.com/the_bott/NotesTable.txt

Post Reply