home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 107 / EnigmaAmiga107CD.iso / Software / Emulatori / snes9x / HARDWARE.TXT < prev    next >
Text File  |  1999-09-29  |  23KB  |  502 lines

  1. This document gives a brief description of the known hardware features of the
  2. SNES giving you some idea what SNES emulation authors are up against.
  3.  
  4. Quick Overview
  5. --------------
  6.  
  7. o 65c816 CPU running at up to 3.58MHz.
  8.  
  9. o SPC700 CPU core running at 2.48MHz with built-in custom sound digital
  10.   signal processor.
  11.  
  12. o Two custom graphics processors used to produce displays of up to 512x478
  13.   pixels with up to 32768 colours, 128 sprites, scaling, rotation, and mosaic
  14.   effects, scrolling over a virtual screen, transparency, coloured lens and
  15.   window effects and raster effects.
  16.  
  17. o 128k work RAM, 64k sound CPU RAM and 64k video RAM.
  18.  
  19. Game packs can include:
  20.  
  21. o Up to 6Mb (or more) of ROM containing the game code, graphics and sound
  22.   data.
  23.  
  24. o Additional, battery-backed RAM (S-RAM) used to save game positions.
  25.  
  26. o 10.5/21MHz RISC CPU (Super FX) used to implement some 3D games and add
  27.   special effects to games.
  28.  
  29. o A maths co-processor (DSP1) used by some games with lots of physics
  30.   calculations involved (Pilot Wings) or mainly as a protection device
  31.   (Mario Kart).
  32.  
  33. o Other custom chips produced by some software companies to help speed up
  34.   games, fit more graphics into a given sized ROM or act as a protection
  35.   device.
  36.  
  37. Users could buy:
  38.  
  39. o A five player adapter, allowing up to five people to play at once on games
  40.   that supported it.
  41.  
  42. o A 2-button mouse, originally supplied with a paint program.
  43.  
  44. o A light-gun that looked like riffle; it used infra-red to provide wire-less
  45.   communication between the gun and the console unit. About 10 games
  46.   supported it.
  47.  
  48. o A GameBoy adapter that allowed the owners to play GameBoy games on their
  49.   SNES, some in colour.
  50.  
  51. o Copier units that plugged into the cartridge slot on the SNES and allowed
  52.   game pak ROMs to be downloaded into RAM on the copier and saved onto
  53.   disk. The game could then be played without the original ROM being present
  54.   - unless the game pack contained additional hardware, or the game ROM code
  55.   tried to detect the copier being present and deliberately crashed the game.
  56.  
  57. More Detail
  58. -----------
  59.  
  60. 65c816
  61. ------
  62.  
  63. The 65c816 is an 8/16-bit CPU that is basically an enhanced 6502: it even
  64. has an emulation mode to make it behave almost exactly like a real 6502. No
  65. doubt Nintendo were hoping to provide a compatibility mode for old NES
  66. games, but failed.
  67.  
  68. The CPU features a 24-bit address bus and 8-bit data bus allowing a 16Mb
  69. address space. It has an accumulator and two index registers, all can be
  70. switch to either 8 or 16-bit mode.
  71.  
  72. The address space is broken up into 256 banks, each bank being 64k in size,
  73. although there are addressing modes to treat the entire address space as one
  74. continuous block. Bank 0 is special in that the stack, a few addressing
  75. modes and the interrupt and reset vectors all reside there. The stack
  76. pointer is 16-bits wide.
  77.  
  78. The 6502 has an addressing mode called zero-page, where the 1-byte address
  79. specified in the instruction refers to a location in the first 256 bytes of
  80. memory, allowing for 2-byte instructions and increased execution speed. The
  81. 65c816 extends this idea by allowing the 'zero-page' to be moved anywhere
  82. inside bank 0 by use of the 16-bit direct page register.
  83.  
  84. There are other addressing modes available that use the bank specified in
  85. the data bank register, again to help reduce code size and speed up
  86. execution.
  87.  
  88. Code normally executes in single bank at a time, the current bank number
  89. being specified by the 8-bit program bank register.  There are instructions
  90. available to call subroutines in other banks or just jump to code in other
  91. banks.
  92.  
  93. The 65c816 internally runs at 3.58MHz, but other SNES hardware can temporality
  94. slow it down to 2.58MHz or even 1.56MHz when the CPU attempts read from them
  95. or write to them. In particular, there are a mixture of fast and slow ROMs
  96. inside game packs, slow ROMs can only be accessed at 2.58MHz.
  97.  
  98. The 65c816 has direct access to 128k of work RAM plus any additional RAM that
  99. might be in the game pack. Video RAM and sound RAM cannot be accessed
  100. directly.
  101.  
  102. SPC700
  103. ------
  104.  
  105. The SPC700 is an 8-bit CPU core, very similar to a 6502, but with some
  106. different addressing modes and multiple and divide instructions, together
  107. with a custom sound digital signal processor, all contained inside one module.
  108.  
  109. The SPC700 and the 65c816 communicate via 4 bi-directional, 8-bit I/O ports.
  110. The SPC700 has its own 64k RAM used to store a program downloaded from 65c816
  111. and sound sample data. 
  112.  
  113. The CPU has a built-in, small, 64 byte ROM used as boot-strap code to
  114. download a more complex program and sample data from the game ROM via the
  115. 65c816. The ROM can be switched off and replaced with 64 bytes of RAM once
  116. the boot-strap code has done its work.
  117.  
  118. The sound DSP can only play compresses sound samples, compressed using a
  119. custom fixed-ratio compression algorithm that compresses 16 16-bit samples
  120. into 8 bytes plus a one byte header. The minimum unit of a sample is one
  121. block. The block header byte contains a shift and filter value (algorithm
  122. decompression information) plus a last block flag and a loop flag; the loop
  123. flag is only used if the last block flag is also set.
  124.  
  125. There are 8 separate sound channels allowing up to 8 samples to be played
  126. simultaneously. Each sound channel has a left and right volume setting and
  127. frequency setting. A hardware volume envelope can be defined for each
  128. channel, and echo effects can be turned on and off individually for each
  129. channel. The combined echo waveform can be subjected to an 8-tap FIR
  130. digital filter. The wave output of a channel can be used to modulate the
  131. frequency of the next sound channel, in numerical order.
  132.  
  133. The DSP also has a white noise source that can played on a sound channel
  134. instead of sample data. All 8 channels, and any echo sound data, are mixed
  135. together and subjected to a left and right master volume control.
  136.  
  137. The DSP also provides 3 interval timers, the first two running at 8kHz and
  138. the last at 64kHz; games normally only use one of them to provide a constant
  139. music playback rate.
  140.  
  141. Interrupts
  142. ----------
  143.  
  144. The 65c816 provides two external interrupt sources: IRQ, which can be masked,
  145. and NMI, which cannot. 
  146.  
  147. The IRQ line is connected to an output on one of the graphics chips, that,
  148. it turn can be programmed to generate an IRQ at the start of a scanline, at
  149. a particular position on a scanline or at a particular position of every
  150. scanline. The IRQ line also is connected to one of the pins on the ROM
  151. connector, so additional hardware inside the ROM game pak, such as the Super FX
  152. and SA-1 chips, can also generate interrupts.
  153.  
  154. The NMI line is connected to another output of one of the graphics chips and
  155. it can be programmed to generate an interrupt when the vertical blank period
  156. starts.
  157.  
  158. The SPC700 chip can also generate interrupts, but they are not used on the
  159. SNES and probably physically not connected.
  160.  
  161. Joypad Reading
  162. --------------
  163.  
  164. Data from the SNES joy-pads is sent serially between the pad and the console.
  165. Games can choose to read each bit in, one at a time or allow hardware inside
  166. one of the custom chips to automatically read the joy-pad values once every
  167. frame. The game can then read the values from registers.
  168.  
  169. SNES joy-pads themselves have direction controls and 8 other buttons named
  170. A, B, X, Y, Left, Right, Start and Select.
  171.  
  172. Colour Palette
  173. --------------
  174.  
  175. The SNES has a 256 entry 15-bit colour palette, allowing for 256 colours on
  176. screen out of a total palette of 32768. However, games can and do change
  177. colour entries during a frame, this combined with hardware colour value
  178. addition and subtraction and an overall brightness setting, can easily boost
  179. the number of colours on screen to several thousand!
  180.  
  181. Tiles
  182. -----
  183.  
  184. All SNES graphics data is made up of tiles, a tile being an 8x8 block of
  185. pixels, with each pixel made up of 2, 4 or 8 bits, allowing for 4, 16 or 256
  186. colours per pixel.
  187.  
  188. To complicate matters, the SNES hardware stores tile data in planar format,
  189. that is all the bit 1's of all the pixels of a tile are stored together,
  190. then all the bit 2's and so on. Its like a sequence of 1-bit deep 8x8 pixel
  191. blocks.
  192.  
  193. When a tile is used as background data, a 3-bit palette start address is
  194. associated with each tile, allowing the programmer to choose a different
  195. block of colours for each tile from the larger SNES colour palette. Sprites
  196. can only use tiles of depth 4 (16 colours), but each sprite has a palette
  197. start address.
  198.  
  199. Background Graphic Modes
  200. ------------------------
  201.  
  202. The SNES has eight background graphics modes, each mode varies the number of
  203. individual background layers available, the depth of each layer and what
  204. other features are available. Programmers can change the background mode
  205. during a frame.
  206.  
  207. The two most commonly used modes are mode 1, which allows two 16-colour
  208. background layers and one 4-colour layer and mode 7, which allows one 256-
  209. colour layer, but the layer can be rotated, stretched, squashed, sheared and
  210. generally messed around with.
  211.  
  212. Each background is made up 32x32 8x8 tiles. However, the number of tiles in
  213. each direction can be double as can the individual tile size. This allows for
  214. a virtual background size of 256x256 up to 1024x1024. Switching to 16x16 tile
  215. size actually just groups four 8x8 tiles together, there is no true 16x16 tile
  216. on the SNES.
  217.  
  218. Backgrounds have a pre-defined priority order - when pixels from one
  219. background layer overlap on the screen pixels from another background layer,
  220. the pixels from the lower numbered background are displayed.
  221.  
  222. Each tile can be flipped horizontally or vertically, has a 3-bit "palette
  223. number" and a priority bit.  The priority bit is used to make all the pixels
  224. in the tile appear in front of pixels from another background layer or
  225. sprite that would otherwise normally appear in front of them. Colour 0 from
  226. each tile is special and means "transparent", allowing non-transparent
  227. pixels from background layers or sprites "underneath" to be visible.
  228.  
  229. Normally only 256x224 or 256x239 pixels are visible on screen and backgrounds
  230. have a scroll setting that allows the screen to act as a window onto any
  231. portion of their virtual size.
  232.  
  233. Two background modes are available that can display up to 512x478 pixels,
  234. but they're not used by many games because the flicker, caused by the
  235. interlace used display the image on a standard television, would give game
  236. players headaches.
  237.  
  238. Sprites
  239. -------
  240.  
  241. The SNES has 128 hardware sprites, each sprite can be made up of one or
  242. several 16-colour, 8x8 tiles. Each sprite is assigned a number which defines
  243. its pixel priority when two sprites overlap on screen, it also has a separate
  244. sprite-to-background priority value which defines whether the sprite should
  245. appear in front or behind of the various background layers. Each sprite also
  246. has a 3-bit palette number, horizontal and vertical flip flags, a start tile
  247. number and, of course, an X and Y position.
  248.  
  249. There's no way to turn off a sprite - if you don't want it to be visible you
  250. have to place the sprite at off-screen position.
  251.  
  252. The SNES hardware seems to impose limits on the number of sprites that can
  253. appear on each scanline; there are one or two games out there that rely on
  254. this 'feature' to hide sprites they don't want visible.
  255.  
  256. Mosaic
  257. ------
  258.  
  259. The SNES has a hardware mosaic effect. The upper left-hand pixel from a block
  260. of pixels up to 16 pixels wide can be made to cover the area of the other
  261. 15; the pixel appears up to 16 times its original size. The effect can only
  262. be used on the background layers, not sprites. All backgrounds share the
  263. same size setting but the effect can be turned on and off per background
  264. layer.
  265.  
  266. Many ROMs combine the mosaic effect with a brightness fade to zoom out of one
  267. game screen then zoom on to the next.
  268.  
  269. Offset Per Tile
  270. ---------------
  271.  
  272. Three of the background screen modes reduce the number of visible background
  273. layers by one, and use its screen data as per-tile background scroll data
  274. for the remaining visible layers.
  275.  
  276. The background modes vary as to whether the vertical and horizontal scroll
  277. values can both be altered, or just one of them. Tetris Attack uses the
  278. effect to allow different parts of the screen to scroll vertically at
  279. different rates.
  280.  
  281. The horizontal per-tile offset feature is very limited and only allows
  282. adjustment in steps of 8 pixels.
  283.  
  284. Mode 7
  285. ------
  286.  
  287. Nintendo use this background screen mode to really show off the SNES compared
  288. to the Sega's Mega Drive.
  289.  
  290. By specifying a centre of rotation and a 2 by 2 transformation matrix, the
  291. mode 7 screen can be rotated, scaled, stretched, squashed, etc. just by
  292. writing to a few PPU registers. By varying the values on each scanline, some
  293. very interesting effects can be produced, these include a perspective
  294. effect, shears, split-screen zooms, etc.
  295.  
  296. Each pixel is 8-bit (256 colours per pixel) and the screen itself has a
  297. virtual screen size of 1024x1024.
  298.  
  299. Mode 7 has another feature where the number of colours are reduced to 128
  300. and the spare bit is used to swap a pixel between background layer 0 and 1,
  301. thus altering the sprite to background priority. This allows some pixels to
  302. be appear in front of sprites and others appear behind.
  303.  
  304. Colour Addition / Subtraction
  305. -----------------------------
  306.  
  307. The pixels of background layers and sprites can be directed to one of two
  308. places, the main-screen or the sub-screen. The sub-screen is like a virtual
  309. screen that cannot normally be seen, but the SNES has hardware that can add
  310. or subtract the RGB colour palette values of each pixel on the sub-screen to
  311. or from RGB values of pixels on the main-screen. The effect is that
  312. background layers on the on the main-screen appear translucent, allowing the
  313. sub-screen partly to show through. Examples are cloud, mist and water effects.
  314.  
  315. The effect can be turned on and off for each background layer on the
  316. main-screen. There's a master switch for sprites as well, but when turned
  317. on, only sprites with certain colour palette numbers actually have their
  318. pixel values added to or subtracted from.
  319.  
  320. The SNES also has a separate fixed colour value; if colour addition or
  321. subtraction is enabled and there's nothing on the sub-screen, the fixed
  322. colour is added or subtracted instead. I've seen it used by games to darken
  323. an area of the screen then overlay a menu on top, to implement a
  324. fade-to-white effect and to tint an area of the screen a particular colour.
  325.  
  326. Windows
  327. -------
  328.  
  329. The SNES provides two "clip windows". Each window is just an area defined by
  330. a left and right position. A background layer or all sprites can be selected
  331. to appear only inside or outside the window.
  332.  
  333. If both windows are enabled on the same background layer or for all sprites,
  334. the areas they define are combined using one of four logical combination
  335. modes: OR, AND, XOR and N-XOR.
  336.  
  337. If the left and/or right values are altered on each scanline (normally using
  338. H-DMA), many different shaped windows can be created; I've seen circles,
  339. pentagons, wavy lines, doughnuts, G's, etc.
  340.  
  341. There's also the colour window. Each window or both windows can be used to
  342. define the area of the colour window. When the colour window is enabled for
  343. the sub-screen, transparency effects occur only inside or outside the colour
  344. window. When the colour window is enabled for the main-screen, it acts like
  345. a master clip window, clipping all background layers and sprites and even
  346. the back-drop colour to the area either inside or outside the colour window;
  347. in the clipped areas, the sub-screen is displayed or just black.
  348.  
  349. Direct Colour Mode
  350. ------------------
  351.  
  352. On the 256 colour background modes, the otherwise unused 3-bit per-tile
  353. colour palette number can be used in combination with the 8-bit tile pixel
  354. data to form an 11-bit colour value (2048 colours) without using the SNES
  355. colour palette registers.
  356.  
  357. Mode 7 has the same feature, but since mode 7 uses a different tile layout
  358. with no 3-bit colour palette number, a fixed 256 colours are available
  359. instead, again without using the SNES colour palette registers.
  360.  
  361. Interlace
  362. ---------
  363.  
  364. The SNES normally generates a non-interlaced picture. Interlace can turned
  365. on and the only thing that happens is that the screen appears to flicker
  366. slightly due to the way a television works.  However, in the two hi-res.
  367. background screen modes, if interlace is turned on the vertical resolution
  368. doubles from 512x224 to 512x448 (or 512x478 if the expand vertical flag is
  369. also set).
  370.  
  371. Not many games use the feature due to the flicker introduced by the
  372. interlace, so its use is normally limited to title screens. However, one
  373. game I know of, RPM Racing, uses the effect during the game.
  374.  
  375. DMA
  376. ---
  377.  
  378. The SNES provides 8 DMA (direct-memory-access) channels, although only one can
  379. be active at once. Without any intervention of the 65c816 CPU, up to 64K of
  380. data can be transferred from RAM or ROM to any PPU (picture processing unit)
  381. register. Since V-RAM, colour palette and sprite position and display data can
  382. only be written to via PPU registers, DMA provides a very convenient method of
  383. transferring data faster than the CPU alone could provide. There are PPU
  384. registers to read or write to the 128k work RAM, so DMA could be used to copy
  385. data from ROM to RAM as well.
  386.  
  387. There is also a DMA read mode, where data is transferred from PPU registers
  388. to RAM.
  389.  
  390. There are various limitations on DMA - if multiple DMA channels are started
  391. at once, they execute in order, the numerically lowest one first, then the
  392. next highest and so on. The 65c816 is stopped while DMA takes place. Each
  393. DMA operation can only access one 64k bank at once. However, the biggest
  394. limitation is that DMA can only take place when the graphics chips aren't
  395. also performing graphics data DMA, i.e. DMA can only be used during the
  396. v-blank period or when the screen is forcible blanked.
  397.  
  398. H-DMA
  399. -----
  400.  
  401. H-DMA is like DMA in that data is transferred from ROM or RAM to PPU
  402. registers without the intervention of the CPU. However, instead of all the
  403. data being transferred in one block, a few bytes are transferred at a time,
  404. just before the start of the each scanline. 
  405.  
  406. H-DMA shares the same channels as normal DMA, so each channel can be set up
  407. for DMA or H-DMA, but since normal DMA only occurs during v-blank and H-DMA
  408. is disabled during this time, its actually easy to reuse a channel for both
  409. types of DMA.
  410.  
  411. There are various H-DMA modes that define how many bytes should be
  412. transferred each scanline, whether the destination PPU register is 8-bit or
  413. 16-bit, should new data be transferred each scanline, or can the same data
  414. be reused if a count value hasn't reached zero, etc.
  415.  
  416. H-DMA gives a very powerful weapon to programmers, it allows PPU register
  417. values to be easily changed each scanline, so many games can and do use it
  418. to change screen colours, background scroll values, window shape values,
  419. mode 7 matrix values, transparency effects, etc. during the frame.
  420.  
  421. Extra Chips Used by the SNES Inside Some Game Paks
  422. ==================================================
  423.  
  424. Super FX
  425. --------
  426.  
  427. The Super FX is just a fast integer RISC-type processor but with a built-in
  428. plot instruction that can draw a single pixel in the SNES' planar format into
  429. a virtual screen very quickly, very handy for 3d polygon rendering. Its a
  430. strange chip though - no stack, a 512 byte cache and a one stage pipe-line
  431. that causes the instruction following a branch instruction to be executed.
  432. Instructions fetched from the cache often execute in a single cycle.
  433.  
  434. Super FX games came with additional RAM inside the game pak that is used as
  435. work RAM for the 'FX chip and as save-game positions, if the ROM supports it.
  436.  
  437. The 'FX chip has 16 16-bit registers and built-in fast integer multiply.
  438. Although the Super FX and the 65c816 can run in parallel, the 'FX chip can't
  439. access the game pack ROM or RAM at the same time as the main SNES CPU, so most
  440. games just get the SNES CPU to execute a wait loop in the SNES work RAM. 
  441.  
  442. The 'FX can't access the SNES custom hardware chips, so if the 'FX has
  443. rendered a screen image in its work RAM, it has to go to sleep while the SNES
  444. CPU copies the screen to video RAM, usually using DMA. The SNES CPU can pass
  445. parameters to 'FX routines either by writing them into the 'FX work RAM or
  446. writing directly into the 'FX registers, which it can be accessed by the CPU 
  447. only when the 'FX chip is sleeping.
  448.  
  449. There are two versions of the 'FX chip, the original 10MHz chip used in Star
  450. Fox and limited to 1Mb of ROM access and 64K RAM and a newer version used in
  451. Yoshi's Island, Doom, Vortex, Winter Gold, Star Fox 2, etc. which can be
  452. clocked at 21MHz and can access twice as much ROM and RAM.
  453.  
  454. DSP1
  455. ----
  456.  
  457. The DSP1 is an early digital signal processor with an on-board ROM,
  458. manufactured by NEC. The on-board ROM was loaded with a program developed
  459. by Nintendo to turn the chip into a 3d maths co-processor, able to perform
  460. most primitive, but time-consuming, calculations required when manipulating
  461. objects in a 3d coordinate system relatively quickly, compared to the
  462. speed of the 65c816 CPU alone, that is.
  463.  
  464. Most of the calculations supported seemed to be those required by a simple
  465. flight simulator, i.e. the calculations available were choosen with Pilot
  466. Wings in mind.
  467.  
  468. The DSP1 has been used in several other games, may be as many as 20, though
  469. most ignore a lot of the available features. The games include Mario Kart, Top
  470. Gear 3000, Battle Racers, Super Air Diver and Bases Loaded 2.
  471.  
  472. SA-1
  473. ----
  474.  
  475. The SA-1 is a fast, custom 65c816 8/16-bit processor, the same as inside the
  476. SNES itself, but clocked at 10MHz compared to a maximum of 3.58MHz for the CPU
  477. inside the SNES.
  478.  
  479. The SA-1 isn't just a CPU, it also contains some extra circuits developed by
  480. Nintendo which includes some very fast RAM, a memory mapper, DMA, several
  481. real-time timers, and the region lock-out chip.
  482.  
  483. The SNES (or ROM copiers) can only access the ROM inside the game pak via the
  484. SA-1; and the SA-1 only enables access to the ROM once its internal region
  485. lock-out chip has verified it has successfully communicated with a lock-out
  486. chip inside the SNES. This very effectively prevents SNES ROM copiers from
  487. being able to copy the ROM.
  488.  
  489. The SA-1 is used in Mario RPG and seems to be used in several other games
  490. that Nintendo released in 1996 and beyond.
  491.  
  492. S-DD1
  493. -----
  494.  
  495. Very little is known about this chip. It seems to be another digital signal
  496. processor, possibly made by Texas Instruments, dedicated to decompressing
  497. graphics data. Only two games I know of use the chip, Street Fighter Alpha 2
  498. and Star Ocean.
  499.  
  500. Like the SA-1, the SNES and ROM copiers can only access the ROM via the S-DD1,
  501. again preventing ROM copiers from dumping the ROM image.
  502.