ASM inquiry?

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:
    ;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:
3v8uYvC.gif
 

chronosv2

New member
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:
    ;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:
    ;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.
 

jorotroid

Member
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.
 

chronosv2

New member
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.
 
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)
 

jorotroid

Member
chronosv2 said:
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 said:
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.
 
So in the setup ASM files, there are variables called bg and sprite pal (or something along those lines). if i directly load those and store to them, could i achieve the same effect?
 
Top Bottom