8x16 and whatever else unreg wants to know

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

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Fri Jul 29, 2011 6:25 am

tokumaru wrote:You are not saving the current button status anywhere after reading. Just put "sta currControllerButtons" right below "BNE -Loop". OR replace the whole loop with the following:

Code: Select all

-Loop:
	lda $4016
	and #$03
	cmp #$01
	rol currControllerButtons
	dex
	bne - Loop
I see absolutely no reason for you to be monkeying around with the stack.

I must remind you that copying and pasting code around just to "see if it works" is a terrible way to program. Things end up working by pure luck, meaning you don't learn anything (because you don't know why they worked) and your programs aren't reliable at all, since different circumstances could easily break them.

EDIT: I just want to add that what I meant in my previous messages is that for some game events you should use currControllerButtons (walking, jumping - if you have variable jump heights -, etc.), but for others you should use newControllerButtons (menu navigation, shooting, etc.).
tokumaru, thank you for the information and thank you for the advice. : )
blessings,
unregistered (matthew)
Last edited by unregistered on Thu Aug 04, 2011 7:04 pm, edited 1 time in total.

User avatar
tokumaru
Posts: 11692
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru » Fri Jul 29, 2011 7:12 am

Oh, I just noticed a mistake in my code... it's obviously $4016, not #4016. :oops:

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Thu Aug 04, 2011 7:16 pm

tokumaru wrote:Oh, I just noticed a mistake in my code... it's obviously $4016, not #4016. :oops:
It's ok... :) Edited mine to have the correct code too.

Also, have a question:
In the Trace box on Nintendulator's Debugger screen... it has LDA $01 = 0F. I understand that $01 means $0001. What does the = 0F mean? I don't understand what that is for. : (

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru » Thu Aug 04, 2011 7:21 pm

It just shows content of memory at the address. I.e. $01 contains $0f.

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Thu Aug 04, 2011 8:05 pm

Shiru wrote:It just shows content of memory at the address. I.e. $01 contains $0f.
How does it know the future content of everything? There are instructions with = signs all the way to the bottom of the Trace window. The instruction to execute next is at the top of the Trace window, right?

edit: Shiru, thanks for your answer! :)
Last edited by unregistered on Thu Aug 04, 2011 8:53 pm, edited 1 time in total.

User avatar
Dwedit
Posts: 4306
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Thu Aug 04, 2011 8:21 pm

It goes by what's currently there, not the future. Numbers shown in a disassembly view will change as the registers or memory changes. (or even RAM code modified)

The = X isn't part of the instruction, it's just the debugger helping you out by telling you what's at that memory address.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Thu Aug 04, 2011 8:24 pm

Ah! :D Thank you very much Dwedit!

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Fri Aug 05, 2011 12:06 pm

:lol: at myself... hahahaha - i'm dumb. :oops: But God is not dumb and he is so loving!! :D :) : )

ok, so this is what happened... Memblers wrote earlier, in this thread:
Memblers wrote:Just a minor point, but I would suggest to avoid doing .equ #00000000 and would do .equ 00000000 instead, then put the # in your code. I know it should work either way, but it's helpful to have your code be as clear as possible that immediate mode is being used (in addition to using all caps for defined constants, like you're doing already).
and I didn't understand what he ment by ", then put the # in your code."

Today, just a little while, ago I read these wise words from Tepples
[color=orange][url=http://nesdev.com/bbs/viewtopic.php?p=72005#72005]here,[/url][/color] tepples wrote:

Code: Select all

load_font:
	lda #font&255
	sta addy
	lda #font/256
	sta addy+1
	ldx #3
	ldy #0
What do the first two lda's do? I don't understand the #font& and #font/ parts. Does a preceding # mean? Can that character be left out?
# means the following value is a number to put directly into A, not an address from which to load the value into A. Look at the "immediate" addressing mode.
And so in my head # started to make sense. I was running and stepping through my "game" with a break everytime there was a write to $0000 through $0002. That's where i placed the three variables
0) currControllerButtons
1) lastControllerButtons
2) newControllerButtons
that I had been watching and thinking about. For some reason the top line of the Memory box started with 0F 0F 00 and that didn't make sense. Why would it be thinking someone had pressed every direction all at the same time? And so I tried the break (same one as i mentioned earlier) to find out. And finally it all started making sense! Each line was missing a # and so that ment that it was an address from which to load the value into A!! So I quickly went to the top of my prg file to this code

Code: Select all

BUTTON_RIGHT .equ 00000001b
BUTTON_LEFT  .equ 00000010b
BUTTON_DOWN  .equ 00000100b
BUTTON_UP    .equ 00001000b
BUTTON_START .equ 00010000b
BUTTON_SELECT equ 00100000b
BUTTON_B     .equ 01000000b
BUTTON_A     .equ 10000000b
and I started to add a # in front of each binary number... but quit and undid that and quickly went to my vblank file to my code where it says

Code: Select all

		lda newControllerButtons    ; Is the A button down?
      and #BUTTON_A ;10000000b
		beq @b
		inc aFrame        ;run only once per press.
        		
@b:		lda newControllerButtons		;Is the B button down?
		  and #BUTTON_B ;01000000b
and as you can see, I added a # right before each use of my constants. "and Button_A" became "and #Button_A". :shock: It works better than it used to!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Memblers, I'm so sorry that I didn't write and ask you what you were trying to say! The question that remains unasked is dumb. I agree. : )
Last edited by unregistered on Sat Aug 06, 2011 2:44 pm, edited 1 time in total.

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Sat Aug 06, 2011 10:45 am

!!!!!!!!!!!!!!!!!!!!!!!! I pressed select and the music played until i pressed start and it stopped!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :D I needed to add a # to

Code: Select all

		ldx #<musicA_module
		ldy #>musicA_module		
		jsr FamiToneMusicStart
The music plays but there is something unsteady about it. :?
edit: Only the first square channel plays... I used the first 4 channels. I can't listen to the song because I lost that file... :( But, I have the asm file...

User avatar
Memblers
Site Admin
Posts: 3833
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Sat Aug 06, 2011 4:18 pm

I'm glad that fix helped, actually I'm surprised it changed the functionality because I thought EQU is supposed to be a simple text-replacement. I guess it ignored the # then, I didn't expect that.
unregistered wrote: The music plays but there is something unsteady about it. :?
edit: Only the first square channel plays... I used the first 4 channels. I can't listen to the song because I lost that file... :( But, I have the asm file...
I would check that the song was made with a version that the playback engine is compatible with (there had been a lot of Famitracker updates, so that's always a possible problem). Next I would check that the RAM locations used by the playback engine aren't being used by your program. Then last is probably not necessary, but I'd make sure the engine is setting the right bits in $4015, and doesn't depend on the user to set those (I'm pretty sure the engine would handle those, it really should).

tepples
Posts: 21973
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sat Aug 06, 2011 6:06 pm

Memblers wrote:I'm glad that fix helped, actually I'm surprised it changed the functionality because I thought EQU is supposed to be a simple text-replacement.
The assignment operator (=, :=, or EQU depending on the assembler's dialect) creates a symbol. The following lines are equivalent:*

Code: Select all

label:
label = *
For text replacement, use #define in the C preprocessor or .define in ca65 2.5 or later.
I guess it ignored the # then, I didn't expect that.
I expected it to give an error message.


* ca65 actually supports two kinds of symbols: labels and nonlabels. ld65 treats these identically, but a debugger might treat them differently. To force a symbol to be a label, use := instead of = .

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Wed Aug 10, 2011 3:46 pm

Memblers wrote:I'm glad that fix helped
Thanks. Me too :D
Memblers wrote:, actually I'm surprised it changed the functionality because I thought EQU is supposed to be a simple text-replacement. I guess it ignored the # then, I didn't expect that.
What ignored the # ? :? I must be missing something. :(
Memblers wrote:
unregistered wrote: The music plays but there is something unsteady about it. :?
edit: Only the first square channel plays... I used the first 4 channels. I can't listen to the song because I lost that file... :( But, I have the asm file...
I would check that the song was made with a version that the playback engine is compatible with (there had been a lot of Famitracker updates, so that's always a possible problem).
think so... think it was made with Famitracker 0.3.6. It was released in Jan 2011... i dont believe I've used Famitracker before January.
Memblers wrote:Next I would check that the RAM locations used by the playback engine aren't being used by your program.
Thanks for having me check those! :) They are ok now, I think. Well, this helped with some of the problem: the screen doesnt jump up and down very much anymore. The lady meta-sprite is still moved over to the left side of the screen... this always happens after select is pressed - character moves over to left side of screen, the screen scrolls down a little, the screen slowly mildly jumps up and down, our lady meta-sprite is trapped... she cant move anywhere else. Except when after pressing start and the music stops and normal game like state works... unless you press select again.

The song plays through the first part ok; it only sounds like 1 square channel is working. Then it's quiet for a while...
Memblers wrote: Then last is probably not necessary, but I'd make sure the engine is setting the right bits in $4015, and doesn't depend on the user to set those (I'm pretty sure the engine would handle those, it really should).
$4015 starts out with a setting of $0f. Then further down in the code it changes to $1f. It says ;start DMC next to that.

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru » Wed Aug 10, 2011 11:02 pm

Make sure your music pay respect to all the requirements of the player, you can't just take a random FTM and use it.

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered » Thu Aug 11, 2011 9:47 pm

Shiru wrote:Make sure your music pay respect to all the requirements of the player, you can't just take a random FTM and use it.
Yes, soI get the same problems after I changed it to play your danger streets. The screen shakes up and down... maybe in beat with the music. Our lady meta-sprite is shoved over to the left of the screen where she stays trapped until I press start. It sounds weird, the same way my song sounds weird. I'm going to try to make a mp3 recording of the sound so you can hear and maybe help me some more. :)
edit: What is a good recording software for me to use?

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru » Thu Aug 11, 2011 10:15 pm

If you screen is shaking in beat with the music, you probably call music update before VRAM update. It should be vice versa, because you only can update VRAM in short period of time after NMI, and calling music first you waste part or all of that time.

Post Reply