SNES.DOC 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. =-=-=
  2. SNES Documentation v1.3: Written by Yoshi of Digital Exodus.
  3. =-=-=
  4. 1) Memory Map.
  5. i) "Main" memory map.
  6. ii) Additional info.
  7. 2) SNES Color explaination.
  8. 3) SNES DMA Memory Map and explaination.
  9. 4) SNES Graphics (tiles) explaination.
  10. 5) SNES Screen mode definitions.
  11. 6) SNES OAM/Sprite explaination.
  12. 7) Magicom Disk registers and Memory controller locations.
  13. 69) About the author...
  14. FF) Greetings, Thanx, etc...
  15. =-=-=
  16. 1) Memory Map.
  17. i) "Main" memory map.
  18. -----------
  19. Just so you know... the R and/or W's on the left side before the
  20. memory location mean [R]eadable and/or [W]riteable. I don't know
  21. what happens if you try to read from the write-only registers:
  22. I think you get bogus data, but that's about it.
  23. -----------
  24. W |$2100: Screen display register.
  25. x000bbbb
  26. x: 0 = Screen on.
  27. 1 = Screen off.
  28. bbbb: 0-$F = Brightness of screen.
  29. *** If you increment $2100 so the register goes up
  30. to $xF (x being whatever), you can make the
  31. screen "fade in". Make -SURE- you do this only
  32. during the VBlank period! If you don't, the screen
  33. goes totally wacko! The 'GS programmers like myself
  34. call it "Syncing to the VBL".
  35. -----------
  36. W |$2101: OAM (Sprite) sizes.
  37. sssnnbbb
  38. s: Size.
  39. n: Name selection (upper 4k word address).
  40. b: Base selection (8k word segment address).
  41. *** The sizes are defined as follows:
  42. 000: 8x8 or 16x16
  43. 001: 8x8 or 32x32
  44. *** I've never used this register, nor sprites.
  45. Check Section 6 for information
  46. which was not done by me: If you understand
  47. it better than I do, good deal.
  48. -----------
  49. W |$2102: Address of OAM (Sprites).
  50. ???????? | ????????
  51. *** This register i've never used. All I know is
  52. that it's a -WORD- in length, not a byte.
  53. -----------
  54. W |$2104: Data for OAM (Sprites).
  55. ????????
  56. *** I've never used this register. It's like $210D:
  57. You have to store a value in it twice.
  58. -----------
  59. W |$2105: Screen mode.
  60. abcdfeee
  61. a: Plane 3 tile size.
  62. b: Plane 2 tile size.
  63. c: Plane 1 tile size.
  64. d: Plane 0 tile size.
  65. 0 = 8x8 tiles.
  66. 1 = 16x16 tiles.
  67. e: MODE definition.
  68. f: Make Plane 2 take highest priority.
  69. -----------
  70. W |$2106: Screen pixelation (aka. MOSAIC) register.
  71. xxxxabcd
  72. x: 0-$F = Pixel size.
  73. a: Affect plane 3.
  74. b: Affect plane 2.
  75. c: Affect plane 1.
  76. d: Affect plane 0.
  77. *** Just like $2100, this only works during VBlank.
  78. I recommend you setup what planes you want to
  79. affect at the start of the program, then to
  80. make them change, do the following:
  81. LDA #$03 ; Affect planes 0 and 1.
  82. STA TempReg1
  83. STA $2106
  84. JSR WaitVBlank
  85. LDA TempReg1
  86. Loop STA $2106
  87. CLC
  88. ADC #$10
  89. CMP #$F3
  90. BNE Loop
  91. -----------
  92. W |$2107: Plane 0 VRAM location register.
  93. xxxxxxab
  94. x: Address of VRAM location.
  95. ab: Virtual screen size selection.
  96. *** The virtual screen size dealy goes like this:
  97. 32x32 to 32x64 to 64x32 to 64x64. Visually,
  98. you only see 32x32(x25) at once unless you
  99. change the ACTUAL screen size.
  100. *** The way I use this register is pretty simple.
  101. Lets say the VRAM is in $2000... Therefore,
  102. we'd go like this:
  103. LDA #$20
  104. STA $2107
  105. -----------
  106. W |$2108: Plane 1 VRAM location register.
  107. W |$2109: Plane 2 VRAM location register.
  108. W |$210A: Plane 3 VRAM location register.
  109. *** All of these follow the same definition as $2107.
  110. -----------
  111. W |$210B: Tile VRAM location register.
  112. aaaabbbb
  113. a: Location of tiles for Plane 1.
  114. b: Location of tiles for Plane 0.
  115. *** The way you use this register is fairly neat.
  116. Since you only have a nybble to work with (which
  117. ranges from $0-F only) your Tile location can
  118. only be $0000 to $F000. You can't have an address
  119. such as $5F91 or $1C4A which holds your tile
  120. data. You just can't have it. :-)
  121. -----------
  122. W |$210C: Tile VRAM location register.
  123. ccccdddd
  124. c: Location of tiles for Plane 3.
  125. d: Location of tiles for Plane 2.
  126. *** Same stats for $210B go for this one; 'cept the
  127. plane registers are different.
  128. -----------
  129. W |$210D: Plane 0 X-scroll register.
  130. *** This register is really funky. You have to write
  131. to it twice in a row (each piece of data being
  132. 1 byte). The register is setup as the following:
  133. - You store the first 8 bits (the first byte) which
  134. ranges from $00 to $FF. After you store this
  135. value, you have to store the next 3 bits in the
  136. same register.
  137. *** The following code demonstrates how to move plane 0
  138. left:
  139. LDA Plane0X
  140. DEC
  141. STA Plane0X
  142. STA $210D
  143. STZ $210D
  144. If you make that into a loop by itself, the result
  145. is the plane keeps scrolling left forever; it even
  146. wraps around back to the start.
  147. *** Note: I've been told this is a nasty way to do it
  148. because MODE 7 uses 13 bits of the above,
  149. while the rest use 10. I'm not taking care of
  150. the MSB. :-(
  151. -----------
  152. W |$210E: Plane 0 Y-Scroll register.
  153. W |$210F: Plane 1 X-Scroll register.
  154. W |$2110: Plane 1 Y-Scroll register.
  155. W |$2111: Plane 2 X-Scroll register.
  156. W |$2112: Plane 2 Y-Scroll register.
  157. W |$2113: Plane 3 X-Scroll register.
  158. W |$2114: Plane 3 Y-Scroll register.
  159. *** All of these follow the same definition as $210D.
  160. -----------
  161. W |$2115: Video port control.
  162. *** If you store the following listed values in this register,
  163. the following happens:
  164. $80: H/L increment which determines if the address will be
  165. incremented after it reads/writes to/from $2118 and
  166. $2139, or $2119 and $213A.
  167. W |$2116: Video port address.
  168. *** 16 bit VRAM address.
  169. $2117: Video port address (continued, due to 16 bits).
  170. W |$2118: Video port data.
  171. *** Data register for writing VRAM data.
  172. $2119: Video port data.
  173. *** Same as above.
  174. -----------
  175. W |$211A: MODE 7 Information register.
  176. xy????ab
  177. a: Horizontal or Vertical flip.
  178. b: Horizontal or Vertical flip.
  179. x: Landscape repeat type.
  180. y: Landscape repeat type.
  181. *** I have not the SLIGHTEST idea what the hell
  182. the original author means by this. If someone
  183. can explain it, tell me.
  184. -----------
  185. W |$211B: COS (COSIN) rotate angle / X Expansion.
  186. W |$211C: SIN (SIN) rotate angle / X Expansion.
  187. W |$211D: SIN (SIN) rotate angle / Y Expansion.
  188. W |$211E: COS (COSIN) rotate angle / Y Expansion.
  189. W |$211F: 13 bit address for the center of Rotate X.
  190. W |$2120: 13 bit address for the center of Rotate Y.
  191. *** All above things i've never used, nor do I
  192. have any explainations on them. Use them at
  193. your own risk, or until I get info on 'em.
  194. *** $211F and $2120 are like $210D: You have to
  195. write a byte to them twice.
  196. -----------
  197. W |$2121: Color # (or pallete) selection register.
  198. xxxxxxxx
  199. x: Color # ($00-$FF).
  200. *** This register is probably one of the most simple
  201. registers I know of to use. You simply store the
  202. # of the color you want to modify before writing
  203. to $2122. This register is autoincrementing, so
  204. you don't have to "LDA #$01, STA $2121, LDA #$02,
  205. STA $2121, LDA #$03..." and so on...
  206. Code is as follows:
  207. STZ $2121 ; Start at color 0.
  208. STZ $2122 ; Color #0 = 00 00
  209. STZ $2122
  210. LDA #$FF ; Color #1 = 7F FF (white).
  211. STA $2122
  212. LDA #$7F
  213. STA $2122
  214. LDA #$1F ; Color #2 = 00 1F (red).
  215. STA $2122
  216. STZ $2122
  217. -----------
  218. W |$2122: Color data register.
  219. xxxxxxxx
  220. x: Value of color.
  221. *** Color on the SNES is trippy; it's 15 bit. Check
  222. Section 2 on how the SNES colors are setup. Some
  223. example code I listed for $2121... Anyways, this
  224. register is like $210D (plane X-scroll) and those
  225. types: You have to store the value in it twice.
  226. For instance: If you wanted the color white (which
  227. is $7FFF in SNES-color), you would have to do the
  228. following:
  229. LDA [whatever color #]
  230. STA $2121
  231. LDA #$FF ; We first store the "lower half"
  232. STA $2122
  233. LDA #$7F ; Then the upper...
  234. STA $2122
  235. It's really not that hard, but it'll take some
  236. getting used to :-) Remember, check Section 2 on
  237. how the SNES does it's color, and for tile-setup,
  238. check Section 4.
  239. -----------
  240. W |$212C: Playfield/Sprite-enable register.
  241. abcdefgh
  242. a: Plane 3 enable (for Sprites).
  243. b: Plane 2 enable (for Sprites).
  244. c: Plane 1 enable (for Sprites).
  245. d: Plane 0 enable (for Sprites).
  246. e: Enable plane 3.
  247. f: Enable plane 2.
  248. g: Enable plane 1.
  249. h: Enable plane 0.
  250. *** This register allows you to enable which planes
  251. you want to put sprites on (to move or etc.) and
  252. to scroll, or other neato things. If you wanna
  253. use all 4 planes, but no sprites, shove $0F into
  254. this register. If you want to use all the planes,
  255. but want sprites on planes 1 and 3, you would shove
  256. $AF into this register. It's very easy to do.
  257. -----------
  258. W |$2133: Screen mode register.
  259. ????ab?c
  260. a: Interlace Y.
  261. b: Overscan.
  262. c: Interlace X.
  263. *** To be blatently honest, I have -NO IDEA- what
  264. this register does; I don't understand what
  265. Corsair & Dax meant by Interlace and Overscan.
  266. If someone can explain this register to me, i'd
  267. be very grateful :-).
  268. -----------
  269. R |$2139: VRAM port data (reading).
  270. $213A: " "
  271. -----------
  272. ?? |$2140 *** These are the audio registers. 'never used 'em.
  273. ?? |$2141 Try shoving data into them; who knows, if you get
  274. ?? |$2142 music sometime, then you know you're on the right
  275. ?? |$2143 track. :-)
  276. -----------
  277. ?? |$4200: Counter Enable.
  278. ??yx???a
  279. a: Joypad-read Enable (1 = Readable).
  280. x: Horizontal Counter Enable.
  281. y: Vertical Counter Enable.
  282. -----------
  283. ?? |$4201: 8 bit parallel data.
  284. *** This is the expansion bus for the Famicom.
  285. -----------
  286. RW |$420B: DMA enable register.
  287. abcdefgh
  288. a: DMA #7.
  289. b: DMA #6.
  290. c: DMA #5.
  291. d: DMA #4.
  292. e: DMA #3.
  293. f: DMA #2.
  294. g: DMA #1.
  295. h: DMA #0.
  296. *** I've personally never used DMA for anything. I hope
  297. someone out there has, and can tell me how to use
  298. it. :-)
  299. -----------
  300. ?? |$420D: Memory select.
  301. ???????x
  302. x: Fast/Normal ROM flip.
  303. 0 = Normal.
  304. 1 = Fast.
  305. -----------
  306. R |$4210: VBL register.
  307. x???????
  308. x: VBlank period
  309. 1 = On.
  310. 0 = Off.
  311. *** This is probably the most important register
  312. you should work with. Without it, you die,
  313. and other things happen. :-) The following
  314. routine allows you to sync to the VBL/wait
  315. for the VBL to pass by so you can do your work:
  316. - LDA $4210
  317. AND #$80
  318. BEQ -
  319. LDA $4210
  320. From a programmers' standpoint, the following
  321. code should do the EXACT SAME as the above,
  322. but faster. NOTE thou, that it doesn't. I
  323. think the timing is off, that's why it doesn't
  324. work right. But, here-goes:
  325. - LDA $4210
  326. BPL -
  327. LDA $4210
  328. -----------
  329. ?? |$4211: ?????.
  330. x???????
  331. x: IRQ Enable flag (1: Enabled).
  332. *** I don't even know the DESCRIPTION of the reg-
  333. ister! :-)
  334. -----------
  335. RW |$4212: Joypad-ready register.
  336. ???????x
  337. x: Ready-state bit (1: Ready).
  338. *** I'm not sure how this register is setup; all I know
  339. is how to use it. Code is as follows:
  340. PadLoop LDA $4212
  341. AND #$01
  342. BNE PadLoop
  343. This waits for the joypad to become ready to read.
  344. -----------
  345. RW |$4218: Joypad #0 register (1 out of 2).
  346. abcd0000
  347. a: 0 = A button not pressed.
  348. 1 = A button pressed.
  349. b: 0 = X button not pressed.
  350. 1 = X button pressed.
  351. c: 0 = Top-left button not pressed.
  352. 1 = Top-left button pressed.
  353. d: 0 = Top-right button not pressed.
  354. 1 = Top-right button pressed.
  355. *** These are self-explainitory. To find out the
  356. status of each bit, just AND #$ for that bit...
  357. The code for checking is the following:
  358. LDA $4218
  359. AND #$80 ; Is the A button pressed?
  360. BNE YesA ; Button pressed (bit is 1).
  361. LDA $4218
  362. AND #$40 ; Is button X pressed?
  363. BNE YesX ; Button pressed (bit is 1).
  364. LDA $4218
  365. AND #$10 ; Is the top-right button pressed?
  366. BNE YesTopR ; Button pressed (bit is 1).
  367. ...and so on. It's very simple.
  368. *** Note: The Corsair & Dax document was -WRONG-.
  369. It took me a good hour or two to find this
  370. out, so I decided i'd better write down the
  371. CORRECT way to do things).
  372. -----------
  373. RW |$4219: Joypad #0 register (2 out of 2).
  374. abcdefgh
  375. a: 0 = B button not pressed.
  376. 1 = B button pressed.
  377. b: 0 = Y button not pressed.
  378. 1 = Y button pressed.
  379. c: 0 = Select button not pressed.
  380. 1 = Select button pressed.
  381. d: 0 = Start button not pressed.
  382. 1 = Start button pressed.
  383. e: 0 = Up not pressed.
  384. 1 = Up pressed.
  385. f: 0 = Down not pressed.
  386. 1 = Down pressed.
  387. g: 0 = Left not pressed.
  388. 1 = Left pressed.
  389. h: 0 = Right not pressed.
  390. 1 = Right pressed.
  391. *** Same as $4218... Some demo code follows:
  392. LDA $4219
  393. AND #$80 ; Is the B button pressed?
  394. BNE YesB ; Button pressed (bit is 1).
  395. LDA $4219
  396. AND #$04 ; Is Down pressed?
  397. BNE YesDown ; Button pressed (bit is 1).
  398. LDA $4219
  399. AND #$02 ; Is Left pressed?
  400. BNE YesLeft ; Button pressed (bit is 1).
  401. -----------
  402. RW |$421A: Joypad #1 register (1 out of 2).
  403. RW |$421B: Joypad #1 register (2 out of 2).
  404. RW |$421C: Joypad #2 register (1 out of 2).
  405. RW |$421D: Joypad #2 register (2 out of 2).
  406. RW |$421E: Joypad #3 register (2 out of 2).
  407. RW |$421F: Joypad #3 register (2 out of 2).
  408. *** Setup is the same as $4218 and $4219.
  409. =-=-=
  410. 1) Memory Map
  411. ii) Additional info.
  412. -----------
  413. RW |$FFC0: Cartridge title.
  414. RW |$FFD6: ROM/RAM Info on cart..
  415. RW |$FFD7: ROM Size.
  416. RW |$FFD8: RAM Size.
  417. RW |$FFD9: Maker ID Code.
  418. RW |$FFDB: Version #.
  419. RW |$FFDC: Checksum complement.
  420. RW |$FFDE: Checksum.
  421. RW |$FFEA: NMI vector/VBL Interrupt.
  422. RW |$FFEC: Reset vector.
  423. *** With SMC (Magicom) files the offset is $7e00 less
  424. than above.
  425. *** I've never actually used this information before:
  426. This could be SMC header only; but then why would
  427. there be memory locations for such? Strange. I'll
  428. leave the information I put in up to SNESASM v1.05.
  429. I use the psuedo-ops NAM, VER, and other things.
  430. =-=-=
  431. 2) SNES Color explaination.
  432. -----------
  433. Oh BOY! So you're interested in finding out how the SNES does
  434. it's color (via $2122), right? Well here ya go...
  435. The SNES has a strange way of doing color (atleast that i've
  436. seen in my lifetime). Color is 15 bit; each "RGB" value (red,
  437. green, and blue) has 5 bits a piece.
  438. When it comes to putting data into $2122, the format (in binary)
  439. is the following (I put them into each byte):
  440. 0bbbbbgg gggrrrrr
  441. |
  442. |_ Someone needs to tell me what this bit
  443. -REALLY- is. I've just been told to set
  444. it to 0...
  445. We guess that the Japanese didn't like the idea of putting them
  446. in the "standard" order of R, G, then B: but instead wanted them
  447. in alphabetical order. Silly! :-).
  448. The way -I- do my color conversions is on a calculator... Just
  449. plug in the bits you want to set in binary, then let the calc.
  450. convert it into hexadecimal. It's pretty easy; or you can be
  451. a Studly Programmer (hehehe) and do it in your head.
  452. A quick color chart: $7FFF: White (0111 1111 1111 1111)
  453. $001F: Red (0000 0000 0001 1111)
  454. $03E0: Green (0000 0011 1110 0000)
  455. $7C00: Blue (0111 1100 0000 0000)
  456. $7C1F: Purple (0111 1100 0001 1111)
  457. $7FE0: Aqua (0111 1111 1110 0000)
  458. $03FF: Yellow (0000 0011 1111 1111);
  459. Well there you have it. It's pretty simple after you get the hang
  460. of it; when using the SNES, you get REALLY good with binary math:
  461. You'll find this out after working with the machine for awhile.
  462. =-=-=
  463. 3) DMA Memory Map and explaination.
  464. -----------
  465. ?? |$43x0: DMA Control register (??? Not sure ???).
  466. W |$43x1: DMA Destination register.
  467. $18 = Video Port access.
  468. $22 = Color pallete access.
  469. *** This gives access to only some of the video chip.
  470. registers. Hell if I know which ones.
  471. -----------
  472. W |$43x2: Source address.
  473. *** THIS REGISTER IS A WORD IN LENGTH ***
  474. *** The document I have says:
  475. "lo-hi 16 lowest bits". Who knows...
  476. -----------
  477. W |$43x4: Source bank address.
  478. *** The document I have says:
  479. "8 highest bits".
  480. -----------
  481. W |$43x5: Transfer size register.
  482. *** Same as above:
  483. "lo-hi".
  484. -----------
  485. All the "x"s represent the DMA # (ranging from 0 to 7).
  486. DMA #0: $4300-$4305.
  487. DMA #1: $4310-$4315.
  488. ......
  489. DMA #7: $4370-$4375.
  490. =-=-=
  491. 4) SNES Graphics (tiles) explaination.
  492. -----------
  493. This is probably the most requested section of the document for
  494. people whom are starting out on the SNES and want to learn just
  495. how in the hell the SNES -DOES- do it's graphics.
  496. There's so much to explain!!!
  497. The SNES does it's graphics in tiles (surprise surprise!).
  498. There are different MODEs on the SNES; the most famous being
  499. is MODE 7. Alas: Most people think using $2106 is MODE 7 ($2106
  500. is for screen pixelation: Where the pixels get "larger". Look
  501. in Section 1 for an explaination of this register).
  502. *** THIS IS NOT MODE 7!!! ***.
  503. So the next time the pixels get really "big" (almost making them
  504. look like IBM PC 320x200x256 mode :-)), and your friend says "WOW!
  505. MODE 7 is COOL," punch 'em in the nose for me. Just kidding.
  506. Also, another thing I should mention: Bitplanes are NOT THE SAME
  507. AS PLANES. Planes are like "screens." You can scroll a plane, but
  508. not a bitplane. Bitplanes are put ONTO a plane, which can be
  509. scrolled any direction.
  510. I'll be explaining MODE 1. MODE 7 is too tough for me to
  511. explain, since you end up losing colors and other screwy things...
  512. Check Section-5 for a mode-# list.
  513. MODE #/Playfields MaxColor/Tile Palettes Colors
  514. ---------------------------------------------------------------------------
  515. 0 4 4 8 16
  516. 1 3 16/16/4 (HUH?) 8 128
  517. MODE 0 is good for geometric shapes (if you were going to rotate
  518. a wireframe cube), basic star scrolls, or a very "bland" text
  519. scroller.
  520. Let's start with MODE 1.
  521. MODE 1 is best for really basic things: Star scrollers, text
  522. scrolls, geometric (non detailed) art, or line drawings; it's
  523. only 16 colors/bitplane, and there's only 4 bitplanes to play
  524. with.
  525. What you need is 4 bitplanes of data. You don't -HAVE- to
  526. use 4 bitplanes... You can use 1 bitplane if you want, but
  527. you only get 16 colors (NO!!! :-)).
  528. You also need a plane map: You can't just have the predefined
  529. graphics data and thats it: You have to "setup the plane" to
  530. tell it what tile goes where.
  531. For demonstration purposes, i'll use code to explain it.
  532. -----------
  533. The "lda #$0000" "tcd" transfers the DP location pointer to
  534. where the scratchpad RAM is. This makes things go much faster,
  535. because DP is always faster than normal RAM (yay for DP!!!)
  536. The other part puts where the location of the data in the
  537. binary/image is into two DP locations: font and font2.
  538. font equ $00 ; Direct page equates.
  539. font2 equ font+1
  540. sei
  541. phk
  542. plb
  543. clc
  544. xce
  545. rep #$30
  546. lda #$0000
  547. tcd
  548. lda #charset
  549. sta font
  550. lda #charset2
  551. sta font2
  552. -----------
  553. The following code tells the SNES where the actual data
  554. is in VRAM memory.
  555. lda #$10 ; Plane 0 text @ VRAM $1000.
  556. sta $2107
  557. lda #$02 ; Tiles for Plane 0 @ VRAM $2000.
  558. sta $210b
  559. -----------
  560. The following code actually MOVES the data in the binary/image
  561. into the SNES's VRAM.
  562. sep #$20
  563. ldx #$2000 ; This puts the data sent thru $2118 and
  564. ; $2119 into VRAM $2000.
  565. stx $2116
  566. ldy #$0000
  567. - lda (font),y ; Get bitplane 0 data (font)
  568. sta $2118 ; ... and store it in bitplane 0.
  569. lda (font2),y ; Get bitplane 1 data (font2)
  570. sta $2119 ; ... and store it in bitplane 1...
  571. stz $2118 ; I don't want to use bitplane 2 and 3,
  572. stz $2119 ; so I store zeros here. You could put
  573. ; more font data in there if you wanted.
  574. iny
  575. cpy #$0200
  576. bne -
  577. ldx #$1000 ; This puts the data sent thru $2118 and
  578. stx $2116 ; $2119 into VRAM $1000.
  579. ldx #$0000
  580. - lda TEXT,x ; Get the character from TEXT...
  581. and #$3f ; AND #$3F because we only want the first
  582. ; 64 characters in the font.
  583. sta $2118 ;
  584. stz $2119 ; Check near the end of this Section for
  585. ; an explaination on what the actual bits
  586. ; do instead of just storing 0 there all
  587. ; the time.
  588. inx
  589. cpx #$0400
  590. bne -
  591. -----------
  592. Here's the actual data names (charset, charset2, and TEXT).
  593. My new source has them in dcb % statements to make the font
  594. more readable: The first time I did this, I had to convert
  595. the binary stuff I wrote on paper into hex, then put them
  596. into decent hex statements in an orderly fashion.
  597. charset
  598. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'@'
  599. dcb $00,$3c,$66,$7e,$66,$66,$66,$00 ;'A'
  600. dcb $00,$7c,$66,$7c,$66,$66,$7c,$00 ;'B'
  601. dcb $00,$3c,$66,$60,$60,$66,$3c,$00 ;'C'
  602. dcb $00,$78,$6c,$66,$66,$6c,$78,$00 ;'D'
  603. dcb $00,$7e,$60,$78,$60,$60,$7e,$00 ;'E'
  604. dcb $00,$7e,$60,$78,$60,$60,$60,$00 ;'F'
  605. dcb $00,$3c,$66,$60,$6e,$66,$3c,$00 ;'G'
  606. dcb $00,$66,$66,$7e,$66,$66,$66,$00 ;'H'
  607. dcb $00,$3c,$18,$18,$18,$18,$3c,$00 ;'I'
  608. dcb $00,$1e,$0c,$0c,$0c,$6c,$38,$00 ;'J'
  609. dcb $00,$6c,$78,$70,$78,$6c,$66,$00 ;'K'
  610. dcb $00,$60,$60,$60,$60,$60,$7e,$00 ;'L'
  611. dcb $00,$63,$77,$7f,$6b,$63,$63,$00 ;'M'
  612. dcb $00,$66,$76,$7e,$7e,$6e,$66,$00 ;'N'
  613. dcb $00,$3c,$66,$66,$66,$66,$3c,$00 ;'O'
  614. dcb $00,$7c,$66,$66,$7c,$60,$60,$00 ;'P'
  615. dcb $00,$3c,$66,$66,$66,$3c,$0e,$00 ;'Q'
  616. dcb $00,$7c,$66,$66,$7c,$6c,$66,$00 ;'R'
  617. dcb $00,$3e,$60,$3c,$06,$66,$3c,$00 ;'S'
  618. dcb $00,$7e,$18,$18,$18,$18,$18,$00 ;'T'
  619. dcb $00,$66,$66,$66,$66,$66,$3c,$00 ;'U'
  620. dcb $00,$66,$66,$66,$66,$3c,$18,$00 ;'V'
  621. dcb $00,$63,$63,$6b,$7f,$77,$63,$00 ;'W'
  622. dcb $00,$66,$3c,$18,$3c,$66,$66,$00 ;'X'
  623. dcb $00,$66,$66,$3c,$18,$18,$18,$00 ;'Y'
  624. dcb $00,$7e,$0c,$18,$30,$60,$7e,$00 ;'Z'
  625. dcb $08,$00,$00,$00,$00,$00,$00,$00 ;'['
  626. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'\'
  627. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;']'
  628. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'^'
  629. dcb $00,$08,$00,$00,$00,$00,$00,$00 ;'_'
  630. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;' '
  631. dcb $00,$7E,$7E,$3C,$18,$00,$18,$00 ;'!'
  632. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'"'
  633. dcb $80,$80,$80,$80,$80,$80,$80,$80 ;'#'
  634. dcb $FC,$FE,$FF,$F7,$F7,$FF,$FE,$FC ;'$'
  635. dcb $3E,$42,$4E,$5C,$5C,$4E,$42,$3E ;'%'
  636. dcb $00,$00,$00,$00,$00,$00,$00,$01 ;'&'
  637. dcb $00,$00,$00,$07,$00,$00,$00,$00 ;'''
  638. dcb $00,$04,$08,$08,$08,$08,$04,$00 ;'('
  639. dcb $00,$20,$10,$10,$10,$10,$20,$00 ;')'
  640. dcb $08,$08,$08,$F8,$08,$08,$08,$08 ;'*'
  641. dcb $10,$10,$10,$1F,$10,$10,$10,$10 ;'+'
  642. dcb $10,$10,$20,$C0,$00,$00,$00,$00 ;','
  643. dcb $00,$00,$00,$FF,$00,$00,$00,$00 ;'-'
  644. dcb $00,$00,$00,$00,$00,$18,$18,$00 ;'.'
  645. dcb $00,$00,$00,$FF,$80,$80,$80,$80 ;'/'
  646. dcb $00,$3c,$66,$6e,$76,$66,$3c,$00 ;'0'
  647. dcb $00,$18,$38,$18,$18,$18,$7e,$00 ;'1'
  648. dcb $00,$7c,$06,$0c,$30,$60,$7e,$00 ;'2'
  649. dcb $00,$7e,$06,$1c,$06,$66,$3c,$00 ;'3'
  650. dcb $00,$0e,$1e,$36,$7f,$06,$06,$00 ;'4'
  651. dcb $00,$7e,$60,$7c,$06,$66,$3c,$00 ;'5'
  652. dcb $00,$3e,$60,$7c,$66,$66,$3c,$00 ;'6'
  653. dcb $00,$7e,$06,$0c,$0c,$0c,$0c,$00 ;'7'
  654. dcb $00,$3c,$66,$3c,$66,$66,$3c,$00 ;'8'
  655. dcb $00,$3c,$66,$3e,$06,$66,$3c,$00 ;'9'
  656. dcb $00,$00,$00,$03,$04,$08,$08,$08 ;':'
  657. dcb $00,$80,$80,$F0,$80,$80,$00,$00 ;';'
  658. dcb $80,$80,$80,$FF,$00,$00,$00,$00 ;'<'
  659. dcb $00,$00,$00,$C0,$20,$10,$10,$10 ;'='
  660. dcb $08,$08,$04,$03,$00,$00,$00,$00 ;'>'
  661. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'?'
  662. charset2
  663. dcb $00,$3C,$4E,$5E,$5E,$40,$3C,$00 ;'@'
  664. dcb $00,$3c,$66,$7e,$66,$66,$66,$00 ;'A'
  665. dcb $00,$7c,$66,$7c,$66,$66,$7c,$00 ;'B'
  666. dcb $00,$3c,$66,$60,$60,$66,$3c,$00 ;'C'
  667. dcb $00,$78,$6c,$66,$66,$6c,$78,$00 ;'D'
  668. dcb $00,$7e,$60,$78,$60,$60,$7e,$00 ;'E'
  669. dcb $00,$7e,$60,$78,$60,$60,$60,$00 ;'F'
  670. dcb $00,$3c,$66,$60,$6e,$66,$3c,$00 ;'G'
  671. dcb $00,$66,$66,$7e,$66,$66,$66,$00 ;'H'
  672. dcb $00,$3c,$18,$18,$18,$18,$3c,$00 ;'I'
  673. dcb $00,$1e,$0c,$0c,$0c,$6c,$38,$00 ;'J'
  674. dcb $00,$6c,$78,$70,$78,$6c,$66,$00 ;'K'
  675. dcb $00,$60,$60,$60,$60,$60,$7e,$00 ;'L'
  676. dcb $00,$63,$77,$7f,$6b,$63,$63,$00 ;'M'
  677. dcb $00,$66,$76,$7e,$7e,$6e,$66,$00 ;'N'
  678. dcb $00,$3c,$66,$66,$66,$66,$3c,$00 ;'O'
  679. dcb $00,$7c,$66,$66,$7c,$60,$60,$00 ;'P'
  680. dcb $00,$3c,$66,$66,$66,$3c,$0e,$00 ;'Q'
  681. dcb $00,$7c,$66,$66,$7c,$6c,$66,$00 ;'R'
  682. dcb $00,$3e,$60,$3c,$06,$66,$3c,$00 ;'S'
  683. dcb $00,$7e,$18,$18,$18,$18,$18,$00 ;'T'
  684. dcb $00,$66,$66,$66,$66,$66,$3c,$00 ;'U'
  685. dcb $00,$66,$66,$66,$66,$3c,$18,$00 ;'V'
  686. dcb $00,$63,$63,$6b,$7f,$77,$63,$00 ;'W'
  687. dcb $00,$66,$3c,$18,$3c,$66,$66,$00 ;'X'
  688. dcb $00,$66,$66,$3c,$18,$18,$18,$00 ;'Y'
  689. dcb $00,$7e,$0c,$18,$30,$60,$7e,$00 ;'Z'
  690. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'['
  691. dcb $09,$09,$00,$00,$00,$00,$00,$00 ;'\'
  692. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;']'
  693. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'^'
  694. dcb $00,$08,$00,$00,$00,$00,$00,$00 ;'_'
  695. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;' '
  696. dcb $00,$7E,$7E,$3C,$18,$00,$18,$00 ;'!'
  697. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'"'
  698. dcb $80,$80,$80,$80,$80,$80,$80,$80 ;'#'
  699. dcb $FC,$FE,$FF,$F7,$F7,$FF,$FE,$FC ;'$'
  700. dcb $3E,$42,$4E,$5C,$5C,$4E,$42,$3E ;'%'
  701. dcb $00,$00,$00,$00,$00,$00,$00,$01 ;'&'
  702. dcb $00,$00,$00,$07,$00,$00,$00,$00 ;'''
  703. dcb $00,$04,$08,$08,$08,$08,$04,$00 ;'('
  704. dcb $00,$20,$10,$10,$10,$10,$20,$00 ;')'
  705. dcb $08,$08,$08,$F8,$08,$08,$08,$08 ;'*'
  706. dcb $10,$10,$10,$1F,$10,$10,$10,$10 ;'+'
  707. dcb $10,$10,$20,$C0,$00,$00,$00,$00 ;','
  708. dcb $00,$00,$00,$FF,$00,$00,$00,$00 ;'-'
  709. dcb $00,$00,$00,$00,$00,$18,$18,$00 ;'.'
  710. dcb $00,$00,$00,$FF,$80,$80,$80,$80 ;'/'
  711. dcb $00,$3c,$66,$6e,$76,$66,$3c,$00 ;'0'
  712. dcb $00,$18,$38,$18,$18,$18,$7e,$00 ;'1'
  713. dcb $00,$7c,$06,$0c,$30,$60,$7e,$00 ;'2'
  714. dcb $00,$7e,$06,$1c,$06,$66,$3c,$00 ;'3'
  715. dcb $00,$0e,$1e,$36,$7f,$06,$06,$00 ;'4'
  716. dcb $00,$7e,$60,$7c,$06,$66,$3c,$00 ;'5'
  717. dcb $00,$3e,$60,$7c,$66,$66,$3c,$00 ;'6'
  718. dcb $00,$7e,$06,$0c,$0c,$0c,$0c,$00 ;'7'
  719. dcb $00,$3c,$66,$3c,$66,$66,$3c,$00 ;'8'
  720. dcb $00,$3c,$66,$3e,$06,$66,$3c,$00 ;'9'
  721. dcb $00,$00,$00,$03,$04,$08,$08,$08 ;':'
  722. dcb $00,$80,$80,$F0,$80,$80,$00,$00 ;';'
  723. dcb $80,$80,$80,$FF,$00,$00,$00,$00 ;'<'
  724. dcb $00,$00,$00,$C0,$20,$10,$10,$10 ;'='
  725. dcb $08,$08,$04,$03,$00,$00,$00,$00 ;'>'
  726. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'?'
  727. TEXT dcb " THIS IS YOUR ENTIRE SCREEN "
  728. dcb " HERE... IF YOU REMOVE ONE OF "
  729. dcb " THE LINES WHICH IS BLANK, THE "
  730. dcb " SCREEN ENDS UP BEING FUNKY "
  731. dcb " DOWN AT THE BOTTOM OF THE "
  732. dcb " SCREEN. "
  733. dcb " "
  734. dcb " SO MAKE SURE YOU ALWAYS LEAVE "
  735. dcb " ALL OF THIS TEXT THINGS IN! "
  736. dcb " "
  737. dcb " "
  738. dcb " "
  739. dcb " YOSHI THE DINO "
  740. dcb " "
  741. dcb " "
  742. dcb " "
  743. dcb " "
  744. dcb " "
  745. dcb " "
  746. dcb " "
  747. dcb " "
  748. dcb " "
  749. dcb " "
  750. dcb " "
  751. dcb " "
  752. dcb " "
  753. dcb " "
  754. dcb " "
  755. dcb " "
  756. dcb "********************************"
  757. dcb " "
  758. dcb " "
  759. -----------
  760. Well there's some code for those whom want to rip it :-).
  761. I hope I haven't confused you yet: If I have, go back and re-read
  762. the code. I've been working with the SNES for awhile, so I under-
  763. stand a little more than a beginner.
  764. You're probably wondering how the heck the following line ends
  765. up being an "@" on your TV, or whatever you have your SNES
  766. hooked up to.
  767. Lets look at charset and charset2.
  768. charset
  769. dcb $00,$00,$00,$00,$00,$00,$00,$00 ;'@'
  770. charset2
  771. dcb $00,$3C,$4E,$5E,$5E,$40,$3C,$00 ;'@'
  772. Convert charsets hex-statements into binary. Consider each
  773. new "$xx" statement a new pixel line. Tile size is 8x8.
  774. 00000000 = $00
  775. 00000000 = $00
  776. 00000000 = $00
  777. 00000000 = $00
  778. 00000000 = $00
  779. 00000000 = $00
  780. 00000000 = $00
  781. 00000000 = $00
  782. Convert charset2s hex-statements into binary.
  783. 00000000 = $00
  784. 00111100 = $3C
  785. 01001110 = $4E
  786. 01011110 = $5E
  787. 01011110 = $5E
  788. 01000000 = $40
  789. 00111100 = $3C
  790. 00000000 = $00
  791. *NOW* do you see the at-symbol? (and yes, I -DID- draw all
  792. of the font by hand. It took me HOURS, but I did it).
  793. You're probably now asking: "Well, that tells me how to define
  794. where a pixel IS: but how do I define it's color?"
  795. This is the fun part. It's sort-of hard to explain:
  796. If you have a 0 for bitplane 0, a 0 for bitplane 1, a 0 for
  797. bitplane 2, and a 0 for bitplane 3, you get the color 0.
  798. i.e.: 0000 = Color #0
  799. ||||___________Bitplane 0
  800. |||__________Bitplane 1
  801. ||_________Bitplane 2
  802. |________Bitplane 3
  803. So, think about a 0 for bitplane 0, a 1 for bitplane 1 & 2
  804. and a 0 for bitplane 3.
  805. i.e.: 0110 = Color #6
  806. ||||___________Bitplane 0
  807. |||__________Bitplane 1
  808. ||_________Bitplane 2
  809. |________Bitplane 3
  810. This is probably the best explaination i've ever seen done about
  811. SNES pixel-color definition, so don't plan on seeing one any
  812. better anytime soon :-).
  813. Anyway, the result above gives you the color # per pixel; it's
  814. fairly interesting... it's like an "overlay" type of method.
  815. I mentioned in the source above that you should check near the
  816. end of the Section for info on why I "stz $2119". Well, here's
  817. why: The bits in the tile-data are fairly "silly": The tile
  818. "character" itself is 10 bits, while the other 6 are "fun bits,"
  819. as I call them. Here's the explaination:
  820. yx?cccNN | NNNNNNNN
  821. y: Flip the tile vertically.
  822. x: Flip the tile horiztonally.
  823. ?: Dunno! Set it to 1 and find out.
  824. c: Pallete # (0-7).
  825. N: Character itself.
  826. So, I STZ there: Yes, I leave the top bits "unset," which means
  827. you could get messed up data, but as far as I have checked, the
  828. SNES has "clear memory" when you start it up: So the bits I don't
  829. zero-out should be zeros anyways! :-) If you want to set them,
  830. feel free to do so! The results of flipping Y and X are sortof
  831. fun to play with. "To read this scrolly, you must stand on your
  832. head" :-)
  833. =-=-=
  834. 5) SNES Screen mode definitions.
  835. -----------
  836. MODE # of bitplanes Colors per plane Palletes Max. # of colors
  837. ---------------------------------------------------------------------------
  838. 0 2 4 8 32
  839. 1 4 16 8 128
  840. 2 ? ??? ? ???
  841. 3 8 256 1 256
  842. 4 ? ??? ? ???
  843. 5 ? ??? ? ???
  844. 6 ? 16 8 128 (Interlaced mode)
  845. 7 ? 256 1 256 (Yes, MODE 7)
  846. ---------------------------------------------------------------------------
  847. The parms which have "?" or "???" mean I don't know what they REALLY
  848. are: I got a document which explained them, but it was bogus: It
  849. said a 16 color mode had -1- bitplane. Weird... I'm not even sure
  850. about MODE 6. But, we know what MODE 7 is, even if I'm not sure how
  851. many bitplanes it DOES use (the doc says 1, I say 8).
  852. I've tested MODE 0 and 1 myself. MODE 3 I might test in the future,
  853. but i've never had the desire to draw up 8 bitplanes of data by
  854. hand ( I don't have a SNES-graphics-generator for the PC! :-( ).
  855. =-=-=
  856. 6) SNES OAM/Sprite explaination.
  857. -----------
  858. The sprites use a lookup table that contains info on their X and
  859. Y position on the screen, their size, if they're flipped horizontally
  860. or vertically, their color, and the actual character.
  861. The format you need to make the table in is as follows:
  862. Size Address/Offset Explaination
  863. ---------------------------------------------------------------------------
  864. *** SPRITE 0 ***
  865. BYTE 0
  866. xxxxxxxx
  867. x: X location.
  868. BYTE 1
  869. yyyyyyyy
  870. y: Y location.
  871. WORD 2+3
  872. abcdeeex | xxxxxxxx
  873. a: Vertical flip.
  874. b: Horizontal flip.
  875. c: Playfield priority.
  876. d: Playfield priority.
  877. e: Pallete #.
  878. x: Character #.
  879. *** SPRITE 0 ***
  880. BYTE 4
  881. xxxxxxxx
  882. x: X location.
  883. BYTE 5
  884. yyyyyyyy
  885. y: Y location.
  886. ....... and so on .......
  887. ---------------------------------------------------------------------------
  888. Continue this table all the way down to sprite #127 (the 128th
  889. sprite).
  890. Don't think you're