NES Programming Tutorial : Source Code Structure

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

Post Reply
User avatar
FARID
Posts: 502
Joined: Wed Apr 07, 2010 1:14 am
Location: Iran
Contact:

NES Programming Tutorial : Source Code Structure

Post by FARID »

Binary, Decimal, Hexadecimal numbers :

* We use decimal numbers (0 ~ 9) in our usual usage to count : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ...

* Computers use binary numbers (0 and 1) : 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, ...

* Long series of binary numbers are not pleasant for human eye, so we force computers to show us hexadecimal numbers (0 ~ F) : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, ...

Image

* You can use windows calculator to convert Binary, Decimal and Hexadecimal numbers to each other :

Image

* Need more info then read this : Hexadecimal

/////////////////////////////////////////////////////////////////////////////////////////////////

Code: Select all

;NES Programming Tutorial
;Level 1 : Source Code Structure
;+++++++++++++++++++++++++++++++++++++++++++++++++++++
;Constants
;+++++++++++++++++++++++++++++++++++++++++++++++++++++
;Variables
;+++++++++++++++++++++++++++++++++++++++++++++++++++++
;iNES header data (16bytes)
;+++++++++++++++++++++++++++++++++++++++++++++++++++++
;PRG Bank0 $8000 ~ $BFFF (16KB)
;---------------------------;
;PRG Bank1 $C000 ~ $FFFF (16KB)
;+++++++++++++++++++++++++++++++++++++++++++++++++++++
;CHR Bank0 $0000 ~ $1FFF (8KB)
Explanation :

* Download Notepad++ and start NES programming!

* Here is a user defined syntax highlighting in Notepad++ for ASM6 (Language --> User Defined Language --> Define your language --> Import --> npp_6502_asm6.xml --> Language --> 6502 assembly)

Image

* Lines starting with ; are just comment

* Save the file with the name of : "Game.asm"

* Game.asm is called source code, because it has codes, right?

That's all for today!

/////////////////////////////////////////////////////////////////////////////////////////////////

Exercise :

Write your name inside of the source code as a comment!

/////////////////////////////////////////////////////////////////////////////////////////////////

Files :
Game.asm

/////////////////////////////////////////////////////////////////////////////////////////////////

Former Level : NES Programming Tutorial : Intro
Next Level : NES Programming Tutorial : iNES Header
Last edited by FARID on Thu May 30, 2024 5:06 am, edited 15 times in total.
Garth
Posts: 246
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: NES Programming Tutorial : Source Code Structure

Post by Garth »

Chapter 18 of my 6502 primer is "Program-Writing: Where Do I Start?", at http://wilsonminesco.com/6502primer/PgmWrite.html . I wrote it in response to a 6502.org forum post years ago which was typical of several such posts. It said, "and no one really ever tells you in what program do you put the code." It's not NES-specific, but it should be very helpful.

There's also chapter 20 of the same 6502 primer, on programming tips, at http://wilsonminesco.com/6502primer/PgmTips.html . There are a lot of suggestions to improve code efficiency, readability, and productivity.

There are plenty of other relevant 6502-oriented articles on the same site for when the person reaches an intermediate programming level, for example the 6502 stacks treatise in 19 sections plus appendices, at http://wilsonminesco.com/stacks/, and the one on forming program structures in assembly language by using macros, at http://wilsonminesco.com/StructureMacros/index.html, and the one on simple ways to do multitasking without a multitasking OS, at http://wilsonminesco.com/multitask/index.html .
http://WilsonMinesCo.com/ lots of 6502 resources
Post Reply