ASM inquiry?

Having trouble compiling code? Getting an unexpected error? Player not appearing on screen? Seeking answers on how to do a particular thing? This is the forum you're looking for, to ask other NESmaker users for assistance.
Post Reply
User avatar
Karakara | Karetro
Posts: 13
Joined: Sun Sep 16, 2018 12:34 am

ASM inquiry?

Post by Karakara | Karetro » Wed Oct 10, 2018 11:04 pm

Hey everyone!
Ive been working on a small puzzle game using the adventure module and slowly modifying the underlying code.
Anyways, that's beside the point.
So to create a start screen with options on it, I wanted to spawn a game object that is used to give the screen a bit of life.
To do this, I made a loop using the Input Editor, having a custom ASM script be called every time 'Any' or 'None' buttons are pressed.
This is my code.

Code: Select all

    
    ;Start Screen
    LDA MenuState
    AND #$00
    BEQ spawnIdle
    JMP dontSpawnIdle

spawnIdle:
	CreateObject #$D0, #$B0, #$07, #$00
	LDA #$01
	STA MenuState
	+
	ShowSprites
	RTS

dontSpawnIdle:
	rts
So basically, this is supposed to take the 'MenuState' user variable and then test if it is equal to zero. If true, go to 'spawnIdle'. Otherwise, go to 'dontSpawnIdle'. 'Idle' referring to that the object is using players idle animation.
However, when I run it in game, there is major sprite flicker. Any suggestions?
Gif of what I mean:
Image
User avatar
chronosv2
Posts: 153
Joined: Wed Aug 08, 2018 9:30 pm
Location: KY, USA
Contact:

Re: ASM inquiry?

Post by chronosv2 » Thu Oct 11, 2018 12:02 am

I think the "AND #$00" is doing it. You're AND-ing MenuState with #%00000000, which is going to always return #%00000000 because AND only returns a 1 for a bit if both the source bit AND the desired bit are both 1.

First run

Code: Select all

    ;Start Screen
    LDA MenuState ;First run, returns #$00
    AND #$00 ;First run, returns #$00.
    BEQ spawnIdle ;Jump because Zero flag is set
    JMP dontSpawnIdle

spawnIdle:
	CreateObject #$D0, #$B0, #$07, #$00
	LDA #$01
	STA MenuState
	+
	ShowSprites
	RTS

dontSpawnIdle:
	rts
Second Run:

Code: Select all

    ;Start Screen
    LDA MenuState ;Second run, gives #$01
    AND #$00 ;#%00000001 AND #%00000000 = #%00000000 (#$00)
    BEQ spawnIdle ;Jump because Zero flag is set
    JMP dontSpawnIdle

spawnIdle:
	CreateObject #$D0, #$B0, #$07, #$00
	LDA #$01
	STA MenuState
	+
	ShowSprites
	RTS

dontSpawnIdle:
	rts
Also you have an extra RTS after ShowSprites. The RTS after the dontSpawnIdle label will get run even without that first RTS because the code will still step through line by line.
Back on topic, though, I think you're spawning the object repeatedly. No idea if that'll fix this particular problem, but this could be one potential snag in the code.
User avatar
jorotroid
Posts: 85
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: ASM inquiry?

Post by jorotroid » Thu Oct 11, 2018 1:46 am

I completely agree with chronosv2, and am pretty confident that you are repeatedly spawning a new instance of the object. It looks like you want to use CMP instead of AND. Also that + is not necessary. And I don't think that ShowSprites is necessary either, but I haven't messed around with the start screen yet, so I don't know if it would be needed there.

Also I want to say that you idea to make a piece of code run when and any or none buttons are being pressed is and interesting idea for injecting some code without having to dive through the text files. I'm not sure if that is a best way of doing that, but it might be a quick and easy way to move some functionality to bank 14 (where the input scripts are held) to save some room on static bank.
User avatar
Karakara | Karetro
Posts: 13
Joined: Sun Sep 16, 2018 12:34 am

Re: ASM inquiry?

Post by Karakara | Karetro » Thu Oct 11, 2018 2:28 pm

jorotroid wrote:
Thu Oct 11, 2018 1:46 am
It looks like you want to use CMP instead of AND
Ah, thanks! Will try this later today when I get home.
jorotroid wrote:
Thu Oct 11, 2018 1:46 am
And I don't think that ShowSprites is necessary either
Also, I added the ShowSprites after I saw that it wasn't drawing.
Thanks again!
User avatar
chronosv2
Posts: 153
Joined: Wed Aug 08, 2018 9:30 pm
Location: KY, USA
Contact:

Re: ASM inquiry?

Post by chronosv2 » Thu Oct 11, 2018 2:47 pm

Technically you don't even need to CMP to #$00.
From the Obelisk 6502 reference ( http://www.obelisk.me.uk/6502/reference.html#LDA ), the zero flag is set on LDA when the number loaded is equal to zero. So CMP #$00 is actually doing nothing, and actually uses two extra bytes for no gain.
C - Carry Flag - Not affected
Z - Zero Flag - Set if A = 0
I - Interrupt Disable - Not affected
D - Decimal Mode Flag - Not affected
B - Break Command - Not affected
V - Overflow Flag - Not affected
N - Negative Flag - Set if bit 7 of A is set

Though at this point it's more an optimization than anything -- if you would feel more comfortable using CMP #$00 it does no harm, it just doesn't actually do anything either. If you run out of space it might be something to consider.
User avatar
Karakara | Karetro
Posts: 13
Joined: Sun Sep 16, 2018 12:34 am

Re: ASM inquiry?

Post by Karakara | Karetro » Thu Oct 11, 2018 9:34 pm

Eyy! i got it working now. however, when trying to use LoadBackgroundPalette and giving either the name of the palette or the number it is on the all palettes list it crashes?
(like the nes crash sound plays)
User avatar
jorotroid
Posts: 85
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: ASM inquiry?

Post by jorotroid » Sat Oct 13, 2018 9:22 am

chronosv2 wrote:
Thu Oct 11, 2018 2:47 pm
Technically you don't even need to CMP to #$00.
That's an awesome insight. I definitely will be able to clean up some code with that. Thanks for sharing.

Karakara | Karetro wrote:
Thu Oct 11, 2018 9:34 pm
Eyy! i got it working now. however, when trying to use LoadBackgroundPalette and giving either the name of the palette or the number it is on the all palettes list it crashes?
(like the nes crash sound plays)
Oh, I'm pretty sure I know what is happening because it happened to me. First a quick refresher: there are two banks that the NES can see at the same time and the code that comes with NESmaker has it so one bank never changes and the other bank can be swapped out. The input scripts are located on the swappable bank and the LoadBackgroundPalette macro uses bank switch. Switching out the bank that you are currently running code in is sort of like pulling the rug out from underneath it and that causes the game to freeze up. I have an idea that maybe you can write a label to JSR to in the unchanging (static) bank, preform the bank switching code there, switch the banks back, and then return to the input script. The issue I was having is pretty low on my priority list for my game, so I haven't gotten around to testing the idea out.
Post Reply