Programming guide: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(→‎Tutorials: creating new article: Sprite size)
(Programming techniques: Cycle counting)
(48 intermediate revisions by 8 users not shown)
Line 1: Line 1:
This programming guide is the complement to the [[NES reference guide]].  You will find more in-depth documentation about specific topics, tutorials on the most common problems encountered,  a list of existing tools that will assist you during you development phase and more. If you're new to NES development, you should give a look to the "[[Getting started]]" section first.
This programming guide is the complement to the [[NES reference guide]].  You will find more in-depth documentation about specific topics, tutorials on the most common problems encountered,  a list of existing tools that will assist you during you development phase and more. If you're new to NES development, you should give a look to the "[[#Getting started|getting started]]" section first.


=== Getting started ===
*[[Before the basics]]
*[[Installing CC65]]
*[[Programming Basics]]


=== General reference ===
=== General reference ===
* [[Getting started]] (not done yet)
* [[Registers]]
* [[PPU power up state#Best practice|Waiting for the PPU to power on]]
* [[PPU power up state#Best practice|Waiting for the PPU to power on]]
* [[CHR-ROM vs CHR-RAM]] and how to switch an NROM project from the former to the latter
* [[CHR-ROM vs CHR-RAM]] and how to switch an NROM project from the former to the latter
* [[Emulation Libraries]]
* [[Emulation Libraries]]
* [[Catch-up]] technique used by emulators
* [[Catch-up]] technique used by emulators
* [[Buggy_PowerPak_Mappers|Buggy PowerPak mappers]]
* [[PowerPak]] / [[Everdrive N8]]
* [[Music]]: [[NES Audio|Audio expansion]], [[Music tools|tools]]
* [[Music]]: [[:Category:Expansion audio|Expansion audio]]
* [[Tools]]
* [[Tools]] — includes assemblers, disassemblers, graphics, music/audio, and emulator-related utilities
* Graphic tools
* [[Battery holder]] (note: must find proper section for this)


=== Tutorials ===  
=== Tutorials ===  
* [[CPU|CPU basics]]
* [[CPU|CPU basics]]
* [[PPU|PPU reference]]
* [[APU basics]]
* [[APU basics]]
* [[Compression]]
* [[Compression]]
Line 24: Line 27:
* Programming Techniques
* Programming Techniques
** [[6502 assembly optimisations]]
** [[6502 assembly optimisations]]
** [[Cycle counting]]
** [[RTS Trick]]
** [[RTS Trick]]
** [[Jump Table]]
** [[Jump Table]]
Line 32: Line 36:
** [[Pointer table]]s
** [[Pointer table]]s
** [[Divide by 3]]
** [[Divide by 3]]
** [[Multibyte constant]]
* [[Limitations]]
* [[Limitations]]
* [[Emulation Tutorials]]
* [[Emulation Tutorials]]
* How to organize data (interleaved, column based, screen based compressed etc)
* [[Sample RAM map]]
* [[Sample RAM map]]
* [[PPU scrolling]]
* [[PPU scrolling]]
Line 42: Line 46:
** How to do parallax scrolling with the scroll register
** How to do parallax scrolling with the scroll register
* [[Sprite size]]
* [[Sprite size]]
* [[How to make raster effects]] by Bregalad ([http://jonathan.microclub.ch/NES_raster/nes_raster.txt external link])
* [http://story.monoroch.net/nes_raster.html How to make raster effects] by Bregalad
* How to keep state
* Frame based algorithm
* [[The frame and NMIs]] by Disch
* [[The frame and NMIs]] by Disch
** [[NMI thread]]: Make your status bar rock-solid
** [[NMI thread]]: Make your status bar rock-solid
* Trick of the trade from well known commercial games
* [[Nerdy Nights sound]]
* Music, how to make, to play, sound fx
* [[Palette change mid frame]]
** [[Nerdy Nights sound]]
* [[Don't hardcode OAM addresses]]
* Do and don't


=== Libraries and samples ===
=== Libraries and samples ===
* [[Programming Libraries]]
 
==== System ====
* [[Init code]]
 
==== Input ====
* [[Controller reading]]
* [[Controller reading code]]
 
==== Graphics ====
* [[Detecting video standard]]
* [[Placeholder graphics]]
* [[Placeholder graphics]]
* [http://forums.nesdev.org/viewtopic.php?p=142703#p142703 RLE decompression code for CHR] by [[User:Koitsu|koitsu]]
==== Math ====
* [[Multiplication by a constant integer]]
* [[Division by a constant integer]]
* [[16-bit BCD|An efficient 16-bit binary to decimal converter]]
* [[8-bit Multiply|Multiplies two 8-bit integers to a 16-bit result]]
* [[8-bit Divide|Divide two 8-bit integers to a 16-bit result]]
* [[Fast signed multiply|Fast table driven multiplication]]
* [[Random number generator]]
==== Audio ====
* [[APU period table]]
* [[Audio drivers]]
* [[Nerdtracker player in NESASM]]
* [[Nerdtracker player in NESASM]]


=== Reverse engineered rechniques ===
==== Misc ====
* [//forums.nesdev.org/viewtopic.php?p=194826#p194826 Skipping the FDS license screen]
 
==== Examples ====
* [[Projects]] - includes many useful open-source examples.
* [http://nintendoage.com/pub/faq/NA/index.html?load=nerdy_nights_out.html Nerdy Nights Out (aka: Learning 6502)] by BunnyBoy
* [https://shiru.untergrund.net/articles/programming_nes_games_in_c.htm Programming NES Games in C] by Shiru
* [https://nesdoug.com/ How to Program an NES game in C] by dougeff
* [https://cppchriscpp.github.io/nes-starter-kit Simple game and editing guide (in C)] by cppchriscpp
* [https://pineight.com/nes/#template Project template] by tepples
* [//forums.nesdev.org/viewtopic.php?t=11151 Minimal NES example using ca65] by rainwarrior
 
=== Reverse engineered techniques ===
* [[Bad Apple]] video compression
* [[Bad Apple]] video compression
* [http://forums.nesdev.org/viewtopic.php?t=5860 Codemasters tile compression]
* [//forums.nesdev.org/viewtopic.php?t=5860 Codemasters tile compression]
* [http://forums.nesdev.org/viewtopic.php?t=8675 Big Bird's Hide and Speak sample compression]
* [//forums.nesdev.org/viewtopic.php?t=8675 Big Bird's Hide and Speak sample compression]
* [http://forums.nesdev.org/viewtopic.php?t=8609 Battletoads text compression] (Huffman coding)
* [//forums.nesdev.org/viewtopic.php?t=8609 Battletoads text compression] (Huffman coding)
* [http://forums.nesdev.org/viewtopic.php?t=8588 Rad Racer rendering]
* [//forums.nesdev.org/viewtopic.php?t=8588 Rad Racer rendering]


=== Useful reference materials ===
=== Useful reference materials ===
==== Books ====
==== Books ====
* Cady, Fredrick M. (1997). ''Microcontrollers and Microcomputers: Principles of Software and Hardware Engineering''. New York: Oxford University Press. ISBN 0-19-511008-0.
* Cady, Fredrick M. (1997). ''Microcontrollers and Microcomputers: Principles of Software and Hardware Engineering''. New York: Oxford University Press. ISBN 0-19-511008-0.
* Eyes, David; Lichty, Ron (1986). ''Programming the 65816 including the 6502, 65C02, and 65802''. New York: Brady Books/Prentice Hall Press (Simon & Schuster, Inc). ISBN 0-89303-789-3.
* Eyes, David; Lichty, Ron (1986). ''Programming the 65816 including the 6502, 65C02, and 65802''. New York: Brady Books/Prentice Hall Press (Simon & Schuster, Inc). ISBN 0-89303-789-3. Rights later purchased by Western Design Center.
* Fernandez, Judi N. (1983). ''6502 Assembly Language Programming (Self-teaching Guides)''. John Wiley & Sons Inc. ISBN 978-0471861201.
* Leventhal, Lance A. (1986). ''6502 Assembly Language Programming 2nd Edition''. Osborne/McGraw-Hill. ISBN 0-07-881216-X.
* Leventhal, Lance A. (1986). ''6502 Assembly Language Programming 2nd Edition''. Osborne/McGraw-Hill. ISBN 0-07-881216-X.
* Zaks, Rodnay (1983). ''Programming the 6502 (Fourth Edition)''. Sybex, Inc. ISBN 0-89588-135-7.
* Zaks, Rodnay (1983). ''Programming the 6502 (Fourth Edition)''. Sybex, Inc. ISBN 0-89588-135-7.
Line 75: Line 111:


==== Online ====
==== Online ====
* ''Programming the 65816'' by Western Design Center[http://www.westerndesigncenter.com/wdc/datasheets/Programmanual.pdf PDF version]
* [http://wdc65xx.com/Programming-Manual/ Programming the 65816 (including the 6502, 65C02, and 65802)] by Western Design Center
*# [http://www.westerndesigncenter.com/wdc/documentation/Programmingthe65816_ProgManual.pdf Programmingthe65816_ProgManual.pdf] — 54MBytes, created 2015/03/27.
*#* This is a full scan of the original Eyes/Lichty book using full images for each page, with the added bonus of OCR being applied so that text is searchable and copy-paste-able.  Accurate/reliable given the nature of the scan.
*#**[https://drive.google.com/file/d/1cMzhGjAZPkxlkJxS7c6cRtRO53KC9v1s/view?usp=sharing backup copy] via [[User:Koitsu|Koitsu]] (primary)
*#**[https://jdc.koitsu.org/lj/Programmingthe65816_ProgManual.pdf backup copy] via [[User:Koitsu|Koitsu]] (secondary)
*#**[http://alle.fi/mirror/Programmingthe65816_ProgManual.pdf backup copy] via [[User:Qalle|Qalle]]
*# [[Media:Programmanual.pdf|Programmanual.pdf]] (a.k.a. WDC65C816_Program_Manual.pdf) — 1.7MBytes, created 2007/04/16.
*#* This is a "pure text" version of the Eyes/Lichty book, however it is rife with very dangerous typos (wrong opcodes, etc.) in many areas, and contains a large number of formatting/layout mistakes not present in the original book.  Bill Mensch (6502/65C02/65816 architect/designer) [http://forums.nesdev.org/viewtopic.php?p=142722#p142722 confirmed these mistakes], stating WDC is in the process of fixing them.  If at all possible, use the newer PDF mentioned above.
*#* It is suspected that WDC has pulled this PDF entirely from [http://65xx.com/Products/Programming_and_Hardware-Manuals/ their website], instead advocating purchasing a "redone" version of the Lichty/Eyes book via Amazon.  Kindle and paperback versions are available, but I ([[User:Koitsu|Koitsu]]) have not reviewed it.


=== Links ===
=== Links ===
*[http://www.zophar.net/documents/6502/6502-txt.html The infamous 6502.txt]: allegedly complete info on the 6502 instructions
*[http://www.zophar.net/documents/6502/6502-txt.html The infamous 6502.txt]: allegedly complete info on the 6502 instructions
*[http://www.atariarchives.org/mlb/ Machine Language for Beginners]: a 1983 introduction to 6502 assembly language
*[http://www.atariarchives.org/mlb/ Machine Language for Beginners]: a 1983 introduction to 6502 assembly language

Revision as of 06:35, 11 October 2020

This programming guide is the complement to the NES reference guide. You will find more in-depth documentation about specific topics, tutorials on the most common problems encountered, a list of existing tools that will assist you during you development phase and more. If you're new to NES development, you should give a look to the "getting started" section first.

Getting started

General reference

Tutorials

Libraries and samples

System

Input

Graphics

Math

Audio

Misc

Examples

Reverse engineered techniques

Useful reference materials

Books

  • Cady, Fredrick M. (1997). Microcontrollers and Microcomputers: Principles of Software and Hardware Engineering. New York: Oxford University Press. ISBN 0-19-511008-0.
  • Eyes, David; Lichty, Ron (1986). Programming the 65816 including the 6502, 65C02, and 65802. New York: Brady Books/Prentice Hall Press (Simon & Schuster, Inc). ISBN 0-89303-789-3. Rights later purchased by Western Design Center.
  • Fernandez, Judi N. (1983). 6502 Assembly Language Programming (Self-teaching Guides). John Wiley & Sons Inc. ISBN 978-0471861201.
  • Leventhal, Lance A. (1986). 6502 Assembly Language Programming 2nd Edition. Osborne/McGraw-Hill. ISBN 0-07-881216-X.
  • Zaks, Rodnay (1983). Programming the 6502 (Fourth Edition). Sybex, Inc. ISBN 0-89588-135-7.
  • Zaks, Rodnay (1982). Advanced 6502 Programming. Sybex, Inc. ISBN 0-89588-089-X.
  • Zaks, Rodnay (1980). Programming the 6502 (Third Edition). Sybex, Inc. ISBN 0-89588-046-6.

Online

  • Programming the 65816 (including the 6502, 65C02, and 65802) by Western Design Center
    1. Programmingthe65816_ProgManual.pdf — 54MBytes, created 2015/03/27.
      • This is a full scan of the original Eyes/Lichty book using full images for each page, with the added bonus of OCR being applied so that text is searchable and copy-paste-able. Accurate/reliable given the nature of the scan.
    2. Programmanual.pdf (a.k.a. WDC65C816_Program_Manual.pdf) — 1.7MBytes, created 2007/04/16.
      • This is a "pure text" version of the Eyes/Lichty book, however it is rife with very dangerous typos (wrong opcodes, etc.) in many areas, and contains a large number of formatting/layout mistakes not present in the original book. Bill Mensch (6502/65C02/65816 architect/designer) confirmed these mistakes, stating WDC is in the process of fixing them. If at all possible, use the newer PDF mentioned above.
      • It is suspected that WDC has pulled this PDF entirely from their website, instead advocating purchasing a "redone" version of the Lichty/Eyes book via Amazon. Kindle and paperback versions are available, but I (Koitsu) have not reviewed it.

Links