I need a piece of code...

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
IvanDSM
Posts: 44
Joined: Fri Aug 19, 2011 4:34 pm
Location: Santos, SP - Brazil

I need a piece of code...

Post by IvanDSM »

Could someone send me a piece of code that would read the A button and then change to a nametable called "ntable1"? I'm using NESICIDE1 as this is my last project on the old NESICIDE. I'm a complete newbie since i don't know a little of assembly!
I can't think of something cool to put here.
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Did you mean to ask for code that makes the switch to use nametable "ntable1" as soon as someone presses the A button?
IvanDSM
Posts: 44
Joined: Fri Aug 19, 2011 4:34 pm
Location: Santos, SP - Brazil

Post by IvanDSM »

Yes, that's it! I'm trying to make a demo...
I can't think of something cool to put here.
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Would be something like this:

jsr ReadJoyPad1
lda joypad1
and #A_BUTTON
beq +
lda #$80
sta wantNameTable1
+
...

;Somewhere in your NMI handler:

lda PPUSTAT
bit wantNameTable1
bpl +
lda #$10
bne ++
+
lda #$00
++
sta PPUADDR
lda #$00
sta PPUADDR
sta PPUSCROLL
sta PPUSCROLL

Fill in the blanks, provide your own ReadJoyPad1 routine, and equate for A_BUTTON, and equates for PPUSTAT (2002), PPUADDR (2006).
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
unregistered
Posts: 1193
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

This code will read all of your controller's buttons and store each one of them in a byte called currControllerButtons.

Code: Select all

ldx #$08
-Loop:
lda $4016
and #$03
cmp #$01

rol currControllerButtons
dex
bne -Loop
Next, this code should help you to know if the A button was just pressed.

Code: Select all

lda currControllerButtons
and #$80
beq abuttonNotPressed

 ; we're here because the A button was just pressed


abuttonNotPressed:
I could explain this code more if you would like that. :)
Hopefully one of the experienced programmers here could help you with the code that chooses your nametable.
IvanDSM
Posts: 44
Joined: Fri Aug 19, 2011 4:34 pm
Location: Santos, SP - Brazil

Post by IvanDSM »

Guys, you are my heroes! Also, i would like to ask: Any tip how i can learn assembler?

Also, what software do you guys recommend for compiling the games?
User avatar
booker
Posts: 10
Joined: Sun Jul 31, 2011 11:53 am
Location: Canada

Post by booker »

ASM6 for a "simple" but flexible assembler. The next logical suggestion is ca65. I haven't really used that one though.
IvanDSM
Posts: 44
Joined: Fri Aug 19, 2011 4:34 pm
Location: Santos, SP - Brazil

Now my last question...

Post by IvanDSM »

I'm trying to learn ASM by trial and error with NESASM. I used Famitracker to make a rendition of Yellow Submarine (very bad rendition, by the way :lol:), and exported as a .bin file, how i use it on my code now?
I can't think of something cool to put here.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Using music from FamiTracker in a program is not very suitable task for a beginner.

The simplest way is probably just to use NSF, as I did in NY2011 intro. You need to know where to load it, which addresses you need to call and which memory location it uses - you can learn that from export log, with NSF Tool, and with NSF format doc. In NESASM it will look like this:

Code: Select all

  ;in beginning you need to init music

 lda #0
 jsr $ac00 ;this is init routine in NSF

 ;then you need to update sound every TV frame by calling player

 jsr $ac03
 
 ;here you include your NSF file in your code as binary, complete with headers etc

 .bank 1
 .org $a2e2-$80
 .incbin "music.nsf"
In this example player uses first 18 bytes of zero page and $01f6..$02ed (as reported by NSF Tool).


Other way (that involves the bin you have) would require to adapt source code of FamiTracker to your assembler first.
Post Reply