how2code.txt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. BASELINE 2091 Presents The First Guide To Coding The SNES
  2. Guide and Source Code by -Pan-
  3. Released on 4/20/93
  4. Welcome to the first installment of "How to code SNES"
  5. This first volume will show you how to make a simple text intro. It uses
  6. mode 0 graphics with no DMAs (Horizontal or General) and is the simplest
  7. type of intro you can make. We're starting small so you can easily understand
  8. what to do. Other future volumes will contain other graphic modes,
  9. Horizontal DMA (HDMA, the SNES version of an amiga copperlist), General DMA,
  10. Interrupts, and a brief section on Sound. Originally we were going to release
  11. the full Super Famicom Programmer's Manual but believe it or not, this manual
  12. a pile of garbage. Contrary to the popular belief that we always had the
  13. manual, this is NOT true. The White Knight happened to meet a very cool
  14. guy at the CEBIT in Germany and has gotten the manual 2 weeks ago!
  15. Yes! What you have seen from us before was true coding. We started out
  16. by hacking and working our way to the top. We didn't wait until we bought
  17. a manual. In fact, the manual was sent to us for FREE! This book isn't
  18. worth paying for!
  19. Let's clear up a few misunderstandings about that SNES manual!
  20. 1) This book does NOT teach you assembly language!!
  21. It would help if you knew a little before trying to code this machine!
  22. 2) This book was not written such as other reference guides you can find in
  23. a store, like Mapping the Amiga, or even Mapping the C64.
  24. It tells you barely and confusingly what the registers do. Period.
  25. 3) This book is about 148 pages long and that includes the Sound Section.
  26. Some have said it was the size of a phone book. Unless live in
  27. Mud Hole, Kentucky this is NOT the case!
  28. So much for the introduction. I personally feel that experience is better
  29. than a reference guide. Reading a text file does not give you the feel of the
  30. machine. In the included source file, you will notice that almost every line
  31. has a description of what it is doing. This is better than telling you the
  32. registers and letting you fiddle around. You know what it will do, and you
  33. can see it in action in the assembled output (also included). I suggest
  34. you examine the source code right after reading this brief introduction on
  35. how the SNES system operates.
  36. The SNES runs on a 65816 processor. This is similar to the 6502, but many
  37. new instructions are available. You will use the most popular commands
  38. like LDA, LDX, STA, PHA, PLA, RTS, JMP.. etc etc. There are some new
  39. ones but we will get into that subject in the next volume as it is not
  40. very important right now.
  41. The 65816 is a 16 bit processor that does 24 bit addressing.
  42. You can load and store 16 bit numbers, as well as 8 bit. The addressing is
  43. is different than the 6502 in that it includes a bank. If you have coded on
  44. the C64 you know that the addressing on the C64 was from $0000-$FFFF.
  45. That is 16 bit addressing. 24 bit includes 1 extra byte. This one byte
  46. is the BANK number. The SNES memory is broken down into fragments of
  47. 32k blocks each. They are addressed from $8000-$FFFF and are stored into
  48. banks sequentially. If you wanted to access the first ROM byte in memory,
  49. the address would be $008000. The first $00 is the bank number, the first
  50. bank you can access. The $8000 is the 16 bit address. All banks (unless in
  51. high rom 64k bank memory) start at $8000!
  52. Remember that you can not write ROM. If you have coded on a C64 you have
  53. written a routine that looked like this:
  54. lda #$00
  55. sta $c000
  56. You cannot do this! $c000 is ROM and you can not write to ROM!
  57. To write to ram, simply write to any address between $0000-$1fff.
  58. If you need more memory you will find plenty at bank $7e and $7f
  59. These 2 banks contain memory from $0000-$ffff. These 2 banks each contain
  60. 64k ofram totalling 128k for your own use!
  61. If you need to write to these directly, just use the LONG STA command
  62. example:
  63. sta $7ec000
  64. This will write to bank $7e at address $c000!
  65. Fair enough. This was only a brief lecture on how the memory works.
  66. The SNES hardware registers and how the work:
  67. You will notice when looking at the source code something very strange.
  68. Some registers are written to twice in a row! This because some registers
  69. need more than one 8 bit info, such as the scroll X registers. In these
  70. registers you can enter any number between $0-$07ff, but they are written
  71. as two 8 bit numbers, one right after another.
  72. example:
  73. lda #$07
  74. sta $210d
  75. lda #$00
  76. sta $210d
  77. This writes #$0007 to $210d, plane 0 scroll x register.
  78. Using 16 bit data storage will not work for this type of register!
  79. example:
  80. lda #$0007
  81. sta $210d
  82. This will not work because it will write #$07 to $210d, then a #$00 to $210e.
  83. Another strange register is the self-incrementing register such as the VRAM
  84. address registers $2116 and $2117.
  85. After writing to $2119 (or $2118 in another setting) the VRAM address in
  86. $2116 and $2117 will be increased. You do not have to do it yourself.
  87. This can be seen in the Character set (font set) transfer routine in the
  88. source code.
  89. Introduction to Video RAM (VRAM)
  90. The Super NES system has it own graphics processor. This requires its own
  91. ram to read/write graphics data. This ram can only be accessed through
  92. certain registers such as $2118 + $2119. To access Video Ram you MUST
  93. turn off the video or you must be in screen blank (horizontal or vertical).
  94. This is one of the downsides of the SNES.
  95. Video Ram allows the storage of map planes and tile graphics.
  96. VRAM is only 64k long and can not be used as regular ram. You can not
  97. program in it, it is a separate unit!
  98. In this volume we show you how to make a text screen in Mode 0. There are
  99. 8 graphic modes numbered from Mode 0 to Mode 7. Mode 0 is the most
  100. simplistic. It allows only 4 colors per tile, but allows all four
  101. planes to be used.
  102. A normal video screen on the SNES is 32*32 tiles, which comes out to an
  103. even 1024 tiles. You can widen the screen but you still may only have
  104. 1024 tiles. There are 2 parts to displaying a graphic on the screen.
  105. There is the tile graphic data which gives the tile its picture. Then there
  106. is the Map data. These are individually placed tiles placed on the screen
  107. to produce an image.
  108. example:
  109. BBBBB SSSSS LL
  110. BB BB SS LL
  111. BBBBB SSSS LL
  112. BB BB SS LL
  113. BBBBB SSSSS LLLLLLL
  114. Notice that all the small B's are the same. These woulds be drawn as
  115. Tile Graphics. They all form together to create the large B image.
  116. These B's together would be the Map data. The same would go for the S and L.
  117. This is enough info to understand the basics of this 2 color intro.
  118. This next installment on "How to code SNES" will feature more interesting
  119. subjects as:
  120. - How the color works
  121. - 16 color graphic mode
  122. - the entire 65816 instruction set with op-codes
  123. - more info on the joypad