Skip navigation
NintendoAge
Welcome, Guest! Please Login or Join
Loading...

Homebrew Declaring Variables and Constants where and how do i declare them?

Jul 02 at 4:30:19 AM
oleSchool (0)
avatar
(Jonathon Wright) < Little Mac >
Posts: 72 - Joined: 11/02/2011
Hawaii
Profile
Well, back again, and yup I'm stuck haha. 
So I read through nerdy nights #7 which had the variables and constants, unfortunately they do not show what variables / constants I'm trying to declare, or where they need to be put. 

I thought I'd start small, so I was gonna make a single byte constant called "player_default" which I was gonna use for the attributes. In this case $0202 for sprite 1. Here's what I got and it wont compile, just gives unknown instruction:

---------------
  .inesprg    1 ;1 16K prg banks
  .ineschr    1 ;1 8k CHR-ROM bank
  .inesmir    1 ;Vertical Mirroring (for horizontal scrolling)
  .inesmap    0 ;mapper 0 to be used

;Setup your programming bank (PRG-ROM ).NESASM arranges everything in 8KB code and 8KB graphics banks.  To fill the 16KB PRG space 2 banks are needed.
; This is first bank. 
  .bank 0
  .org $C000 ; I've seen $8000...why?

  player_default = #00000011  ; no flipping, foreground tile, use palette 4. 
...
LDA player_default
STA $0202
....
-------

So if I take out the player_default declaration and hard code the value it works. Definitely need to know where and how to make constants would help as I get down the road and get more constants.  
So where and how do I declare variables and constants?  

Little side note of something I just noticed. I need a '#' in the beginning for binaries to work when I hard code them (no constants) to the sprites attribute (LDA #00000011 STA $0202). But when I'm setting something like the PPU Control Register for enabling sprites at $2001 I need a '#%' before the binary (LDA #%00010000 STA $2001), not sure what thats all about. 

Thanks again gang for the help!
OleSchool

-------------------------
"It's Dangerous to go alone. Take This!"
The Old Man

https://www.youtube.com/channel/U...


Edited: 07/02/2019 at 04:33 AM by oleSchool

Jul 02 at 7:28:28 AM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8124 - Joined: 06/21/2007
Florida
Profile
If you look at the code from Nerdy Nights 7, you will see where to declare variables and constants. It says DECLARE SOME VARIABLES HERE and DECLARE SOME CONSTANTS HERE with many examples of different variables and constants. You would just add player_default .rs 1 after score2 .rs 1 if you wanted it to be a variable, or add player_default = %00000011 at the end of the constant list there if you wanted it to be a constant. (Binary/hex constants don't need the # signifier.)

As for writing binary and hex numbers, I've never NOT used #%xxxxxxxx in front of a binary number. I know for hex numbers #$xx is required, and if you want to write a decimal number, #xx is the format. My guess is when you're writing #xxxxxxxx it is interpreting that as a decimal number and not a binary number. % signifies binary and $ signifies hex.

Banks are typically started at $8000, $A000, $C000, or $E000. The "fixed" banks are typically at $C000 and $E000, but I wouldn't concern yourself with this information just yet. Get a feel for writing code and the syntax of writing in assembly with a basic mapper and we'll get there down the road.  

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin



Edited: 07/02/2019 at 08:05 AM by KHAN Games

Jul 02 at 7:29:23 AM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8124 - Joined: 06/21/2007
Florida
Profile
Also, I created this thread many years ago for questions like these, as to not clutter up the forum with individual questions, so feel free to use it in the future:

http://nintendoage.com/forum/mess...

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin


Jul 02 at 1:50:18 PM
oleSchool (0)
avatar
(Jonathon Wright) < Little Mac >
Posts: 72 - Joined: 11/02/2011
Hawaii
Profile
-----------------EDIT---------------
Nevermind...omg I see it now... I need to take a break, lol... VERY sorry for the hassle... At least I got the binary info  
-------------------------------------

Hmm... At the end of Nerdy Nights #7 post it did say to download the pong.zip, but I never could find it yesterday which is why I ended up posting my question.
Do I have rights to see the file or has it been removed? I just checked again, I don't see the file attachment, but I'm new so its probably in a location I'm not looking, haha.

So I see what your saying, yeah player_default goes at the end of the list, I'm stuck on where the list goes, and don't have the pong.zip example unfortunately.
Here is where I've tried and failed:
-----------------------
<---VARIABLE LIST HERE? 
  .inesprg    1 ;1 16K prg banks


  .ineschr    1 ;1 8k CHR-ROM bank


  .inesmir    1 ;Vertical Mirroring (for horizontal scrolling)


  .inesmap    0 ;mapper 0 to be used


<---OR HERE? 


  .bank 0


  .org $C000 


<---OR HERE? 


... 
I've tried all 3 locations and no dice. 

Thanks for the binary explanation, guess I just got lucky that it works, I changed em to start with #% and from now on I will always use #%xxxxxxxx, thanks!

Banks are definitely eluding me, I keep seeing some folks with $C000 and others with $8000 for bank 0 and like you said, I'm gonna leave that one for the future and just keep moving forward haha!

Appreciate the info on the programming questions thread, I'll start using that (after this one is done), apologies for the clutter    Maybe the admins can get a folder created at the top level where Homebrew is called "Programming Questions", just a thought. That way we can subscribe to our posts instead of one that gets updated by folks with their own questions, food for thought.


 

-------------------------
"It's Dangerous to go alone. Take This!"
The Old Man

https://www.youtube.com/channel/U...


Edited: 07/02/2019 at 02:16 PM by oleSchool

Jul 02 at 11:08:51 PM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8124 - Joined: 06/21/2007
Florida
Profile
Haha. Asking the moderators to do any work here is a tall order.  

I'm glad you found the file. Finding attachments in this new forum layout isn't easy, so definitely don't feel bad. It isn't obvious at all!

And keep the questions coming. Super happy that you're interested and making progress!

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin


Jul 02 at 11:51:35 PM
Mog (140)
avatar
(Mr Mog) < King Solomon >
Posts: 4728 - Joined: 05/02/2009
Federated States of Micronesia
Profile
Originally posted by: oleSchool


Hmm... At the end of Nerdy Nights #7 post it did say to download the pong.zip, 

The link to the download is the word "pong.zip"

Here is the link itself

http://www.nespowerpak.com/nesasm...


Jul 03 at 1:06:55 AM
oleSchool (0)
avatar
(Jonathon Wright) < Little Mac >
Posts: 72 - Joined: 11/02/2011
Hawaii
Profile
Yeah, new to the forums, I basically scrolled to the bottom and looked for a section for “attachments”, didn’t see anything and nothing was underlined or linked so posted the question. 

They should really make attachments / linked files much more obvious. 

And definitely interested in growing in this knowledge, it seems like it’s growing and I’m diving in. 

Thanks for for the help, I’m sure we’ll be talking again soon 😁

-------------------------
"It's Dangerous to go alone. Take This!"
The Old Man

https://www.youtube.com/channel/U...

Jul 03 at 1:08:53 AM
oleSchool (0)
avatar
(Jonathon Wright) < Little Mac >
Posts: 72 - Joined: 11/02/2011
Hawaii
Profile
Originally posted by: Mog
 
Originally posted by: oleSchool


Hmm... At the end of Nerdy Nights #7 post it did say to download the pong.zip, 

The link to the download is the word "pong.zip"

Here is the link itself

http://www.nespowerpak.com/nesasm/pong1.zip
 

Thanks Mog, I already got the file, but much appreciated! 

Like Ike I told KHAN, they really need to make attachments more obvious. It wasn’t until I rolled over the word pong that it underlined and I saw that it was a link. 

Anyway, I’m good now, thanks for looking out!

 

-------------------------
"It's Dangerous to go alone. Take This!"
The Old Man

https://www.youtube.com/channel/U...