NES Programming Tutorial : Source Code Structure

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
NES Programming Tutorial : Source Code Structure
by on (#190907)
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:
;NES Programming Tutorial
;Level 1 : Source Code Structure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;iNES header data (16bytes)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;PRG codes $8000 ~ $FFFF (32KB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;CHR data $0000 ~ $1FFF (8KB)


Explanation :

* Download Notepad++ and start NES programming!

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
Re: NES Programming Tutorial : Source Code Structure
by on (#190984)
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 .