I need a piece of code...
Moderator: Moderators
I need a piece of code...
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
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).
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
This code will read all of your controller's buttons and store each one of them in a byte called currControllerButtons.
Next, this code should help you to know if the A button was just pressed.
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.
Code: Select all
ldx #$08
-Loop:
lda $4016
and #$03
cmp #$01
rol currControllerButtons
dex
bne -Loop
Code: Select all
lda currControllerButtons
and #$80
beq abuttonNotPressed
; we're here because the A button was just pressed
abuttonNotPressed:
Hopefully one of the experienced programmers here could help you with the code that chooses your nametable.
Now my last question...
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
), and exported as a .bin file, how i use it on my code now?
I can't think of something cool to put here.
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:
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.
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"Other way (that involves the bin you have) would require to adapt source code of FamiTracker to your assembler first.