=================================================================
 NESticle                                   Version 0.31 (5/4/97)
 by Bloodlust Software
             "The only NES emu with elephantitus" (TM)
=================================================================

Here it is. A new version, albeit tainted.
I know you waited in moist anticipation.
Death to the defiler.

Do not ask about SNESticle.

---------------------
     What it is
---------------------

NESticle is a DOS/Win95 based emulator for the Nintendo
Entertainment System written in C++/Assembly. The core
is essentially the product of 2 weeks of boredom and 
a smattering of effort. 

It is freeware and it is not to be distributed with game
ROMs and it is not to be sold. If you like it, or have
bug reports/questions/comments send me email to the 
address below. 

The CPU emulation is based on a modified version of
Neil Bradley's (neil@synthcom.com) assembly m6502 core.

A majority of the NES technical information used to create this
came from Marat Fayzullin's (fms@freeflight.com) great NES.DOC
and a lot of 'hacking' on my own. 

Sound information was provided by Y0SHi (yoshi@parodius.com) from
his NES technical document. His doc did not exist until recently,
but it is updated quite often. 

---------------------
    What's New
---------------------


Version 0.31:
 - Some changes in Netplay, default ports changed to reflect this.
    v.31 will not netplay correctly with older versions
 - Big resynching problem fixed when a reset occurs in netplay
 - Spacebar key does nothing now, ESC hides gui and maximizes game window
 - Some iNES Mapper #7 support added (Wizards & Warriors 1/2)
    The mirroring isn't quite right, but at least they run for now.
    Ensure that their headers contain the # of 16k banks, NOT 32k
 - Finally, long fucking file names under DOS (MSDOS 7.x under 95)
    If they cause problems, disable with '-disablelfn'
 - Log wave output feature added (Win95 only)
   Written to a signed 16-bit mono RAW file (no header) 
 - Uses asynchronous functions to resolve local host 
    (no more hanging under win95 w/o being connected to internet)
 - Calibrate button actually calibrates the joystick (who would have thought)
    Center it then push the button...calibrate under win95 with the control panel
 - BRK instruction fixed (DW1 works again)
 - Louder triangle wave (normalized sound constant as well)
 - Seperate dirs for different file types (see command line options)
 - "Read only" roms now load
 - Longer default VBlank interval (fixes many games)
 - Reverted to using DOS4GW, apparently some people were having problems
    with the PMODE/W extender so DOS4GW was put back in. If you liked 
    PMODE/W better you can always download it and bind it to the EXE

Version 0.3:
 - PPU mem address wrapped around now
 - Sound settings dialog added (soundconstants fixed)
 - GUS support
 - Pattern editor 
 - Resorted to multi-threading under 95 to compensate for 
    DirectSound being such a living pile of shit (still not fixed totally)
 - Fixed sprite clippings
 - Triangle wave channel fixed
 - Noise channel implemented
 - Enter/Tab work when GUI disabled or game window has input focus
 - Cycle timings fixed
 - Hitflag/Split screen improved
 - PCX snapshots saved to 'snap??.pcx'
 - Netplay TCP/IP or IPX (Win95 only)
 - 'sndconstant' command line option added
 - 'swapbut' command line option replaced by 'remapbut'
 - Ctrl/Alt now mappable to keyboard input devices
 - Default keys for keyboard #1 are B/A=Ctrl/Alt
 - Command line now read from 'default.w95' and 'default.dos'
 - Dumb bug in MMC1 fixed (Zelda 2 works)
 - IRQ's for MMC3 fixed
 - DOS4GW replaced by PMODE/W (its a little faster and its a lot smaller)
    If it causes problems, DOS4GW can still be used (run "dos4gw nesticle")
    If you get a "Unable to allocate framebuffer selector" error, use DOS4GW.

Version 0.21:
 - You can change directories now when you load roms.
 - Sound cards under DOS that do not support auto-initialized
    DMA transfer have been fixed, i hope.
 - Now uses a secondary sound buffer for mixing as opposed to using
   the primary one (under Win95 DirectSound). This should make it
   more compatible. Also is using a timer callback to update the buffer,
   should eliminate some static. DirectSound is atrocious.
 - 'swapbut' command line option added.  Swaps the A&B joystick buttons
 - 'palfile' command line option added.  Now you can use multiple-palettes.
 - The new palette was thankfully provided by Loopy (loopy@itsnet.com).

Version 0.2: 
 - Initial release

---------------------
    What it does
---------------------

NESticle emulates the basic NES hardware, along with several of
the memory mapping chips used by various games. As of now,
it runs a majority of games although there are still
a few bugs and glitches here and there.

What's emulated:

   -6502 CPU
   -PPU
   -VRAM/VROM 
   -Horizontal/Vertical mirroring
   -Scrolling
   -Multiple split screens (although some glitches still)
   -8x8 and 8x16 Sprites
   -Dual joypads
   -iNES Memory mappers 0,1,2,3,4,7(partial)
   -Battery backed RAM
   -Sound emulation  

Other neat features:

   -Multiple save states
   -Joystick support
   -Network play (Win95 exe only)
   -"Friendly" GUI
   -VESA/DirectDraw support
   -Fullscreen 256x224 VGA mode (DOS only)
   -Save .pcx snapshots
   -Editable pattern tables (CHR/tile/vrom)
   -iNES single cart format 
   -Virtual frame speed not system dependant
   -Wave output loggable
   -Editable palette (I dont have the correct colors)
   

---------------------
 What it doesn't do
---------------------
All of the sound channels are not emulated entirely correctly.
Lots of tweaking needs to be done. Particularly the frequency
sweeps which are responsible for most sound effects. The sound
mixer still needs to be rewritten in assembly as well.
You can turn the sound off if it gets on your nerves.
If you notice the sound "breaking up" or becoming staticy, 
try lowering the sampling rate. If you want to change the pitch
of the notes played (if you think the music is an octave too high
or too low or whatever) change the soundconstant setting on the
command line or with the dialog box.
My empathy to those who "can't get sound at all." I hate sound
programming myself, and if you let me know your sound card
and the DSP version (in the messages window) I'll try to fix it.
I'm not sure how the PCM channel works exactly.

GUS support is preliminary.

Any memory mapper other than the first 5. This includes, most
notably, Castlevania 3. I'd appreciate any info on this mapper.

I'll put in turbo/autofire settings later.

Lightgun support.

Better pattern editor.

Game genie codes (help?)

Native Ensoniq support (help?)

---------------------
  What you get
---------------------

There are 6 files:

  DOS4gw.exe       : 32-bit DOS extender
  NESticle.exe     : The 32-bit DOS version
  NEStcl95.exe     : The Win95/NT Directdraw version
  NESticle.pal     : The NES palette (256 colors in RGB format)
  gui.vol          : Extra graphics stuff for the gui
  readme.txt       : This file

Note that it does not come with ROMs.
It will never come with ROMs.
And it must never be distributed with ROMs.
Distribute it with ROMs and you die.
Ask me for ROMs and you die.


---------------------
  What you need
---------------------

A 486 or Pentium running DOS or Windows 95/NT.

For the Windows version you MUST HAVE DirectX Version 3.0.
It's available somewhere on Microsoft's labyrinth of a website.
I'd recommend at least 16MB of memory for the Win95 version.

NESticle can take advantage of VESA 2.0 support if it exists.
If it does not exist, NESticle will resort to only the
video modes 320x200 and 256x224. You need about 8MB of memory
for the DOS version, maybe less.

The DOS version currently supports 8-bit or 16-bit Soundblasters
or compatible, or the Gravis Ultrasound. 16-bit preferred, of course. 
The Win95 version utilizes DirectSound for digital output (which
sucks horribly).

---------------------
 How to work it good
---------------------

If you can figure out the japanese version of Pasofami
then you can figure out this.

Most of the menu options are self explanitory.
Load up a .NES rom from the File/Load ROM.
Execute the rom from CPU/Reset.

If you're running in a high-res mode (>320x240), the NES
game screen will appear in a window. You can maximize the window
with the LEFT button in the title bar. You close the window with
the RIGHT button. I know the buttons aren't marked and they should 
be but I'm lazy and this aint win95. 

You can toggle the GUI on and off by pressing ESC.

You change the input devices from the Settings/RedefineInput menu(s).
No matter what the settings are, Enter/Tab are always Start/Select in order
to accomodate 2 button joysticks. Enter/Tab only work if the game window
has input focus (click on it) or the gui is disabled.

F5/F7 saves and loads your games. Essentially it stores the entire NES state
in a state file. Pressing the keyboard keys 0-9 (not the numeric keypad ones)
will change the current state slot for subsequent saves/loads:
   0 = "xxxx.STA"        (xxxx is the rom file name)
   1 = "xxxx.ST1"
   2 = "xxxx.ST2"
     ... etc, you get the idea.
The default slot whenever a rom is loaded is 0 (ie "xxxx.STA")

To edit patterns, View/Pattern tables, then click on a pattern and edit it.
Right clicking on a pattern will change its attribute (palette), to aid
in drawing. If you wish, you can save the changes with File/Write VROM, and the
VROM will be written directly to the .NES file, so beware.


---------------------
  ROMS and stuff
---------------------

NESticle currently uses the iNES single file cart format (*.NES). 
It will support the pasowing format in the future.
The ROMs must be stored in the same dir as the .exe.

Here's a description of a sample cart 'ZELDA' and some possible extensions:

 - ZELDA.NES         
    The actual ROM/VROM data preceded by a 16-byte header

 - ZELDA.HDR         
    An alternate 16-byte header file. If NESticle encounters this in the dir
    of the ROM, it will use this header instead of the one present in the
    NES file.

 - ZELDA.SAV
    8K file representing the contents of the battery backed memory used
    in some games. This file is automagically saved and loaded as needed.

 - ZELDA.ST?
    It's the 'state' file used by saved games. 

 - ZELDA.Dxx    It's a dump of the 64k cpu address space. For debug purposes.
 - ZELDA.Rxx    It's a dump of all 16k rom banks. For debug purposes.
    

Selecting 'Write ROM Header' from the file menu will write the header stored
in memory to the .NES rom file. Essentially, this lets you use an alternate
rom header file (*.hdr) and load and test the rom, then if it works you can 
write it permanently. I put this in for those of you without hex editors.

Numerous roms floating around out there have incorrect headers.
Having an incorrect memory mapper type in the header will most likely cause
the game to crash. Having an incorrect mirroring bit will cause the background
to appear jumbled, or split, while scrolling. You can flip the mirroring bit
from the settings menu. If changing the mirroring fixes the game, you can then
write the ROM header as described above. 


---------------------
Command line options
---------------------

DOS & WIN95:
------------

-res <xw> <yw>  : Sets the resolution to xw,yw on startup.
                : Use this if 256x224 doesn't work or you get a
                : "Unable to init DDraw: invalid mode" error

-setinput <num> <type>
                : Sets input device <num> to <type>
                   ex. '-setinput 1 GRAVIS'

-remapbut <device> <b> <a> <sel> <start>
                : Remaps buttons for <device>
                : <device> can be JOY1, JOY2 or GRAVIS
                : <b>,<a>,<sel>,<start> are the joystick button #'s for each NES button
                : The old 'swapbut' is now obselete, instead use "-remapbut JOY1 1 0"

-waitvsync      : Wait for the vertical sync to draw frames (see Performance)
-showfps        : Show FPS on startup
-hidegui        : Hide GUI on startup

-load <rom>     : Load <rom>
-run <rom>      : Load & Run <rom>
-restore <rom>  : Load & Run & Restore state for <rom>

-sndrate <rate> : Sets the sound sampling rate (8000-44100)
-nosound        : Bypasses the initialization of any sound hardware
-force8bit      : Forces 8-bit sound output (even if 16-bit exists)
-sndconstant <channel> <x>
                : Sets the NES sound constant for <channel> to <x> in hexadecimal 
                : <channel> can be from 1 to 5
                : Changing this will change the relative pitch of the notes played
                : For the technically inclined, the formula is:
                :            freq=SOUNDCONSTANT/D   where D is the NES data written
                : You can edit these during the game in the sound dialog.

-romdir <dir>   : Sets the startup dir for .NES roms
-savedir <dir>  : Sets the directory for .SAV and .STA files
-pcxdir <dir>   : Sets the directory for saving snapshots
-logdir <dir>   : Sets the directory for logging and debug files
         Hint: Use default.cmd for storing these options

DOS only:
---------
-? or -h        : Display command line help
-disablelfn     : Disables long file name support
-novesa         : Don't use VESA extensions
-linear         : Force linear video mode
-banked         : Force banked video mode

-sb   <port> <irq> <dma8>  : Forces 8-bit soundblaster settings (ex -sb 220 7 1)
-sb16 <port> <irq> <dma16> : Forces 16-bit soundblaster settings (ex -sb16 220 5 5)
      (if soundblaster settings are not supplied, they will
        be extracted from the BLASTER environment variable,
       GUS settings are extracted from the ULTRASND variable)


Frequently used command line options can be put in the 
file "default.cmd" which is automatically parsed anytime
either the Win95 or Dos version of NESticle loads. 
"default.dos" is also parsed everytime the Dos version loads.
"default.w95" is also parsed everytime the Win95 version loads.


---------------------
     Netplay
---------------------

Netplay at this point is very preliminary.
It is still quite buggy.

Netplay is only available with the Win95 version (using Winsock),
over either the TCP/IP or the IPX protocols.
In the future, the DOS version may support the IPX protocol.

One person must start a server (Net/Start server) and select
a protocol to use as well as the port. The person's name
must be entered as well. The opponent must connect to this
server (Net/Connect), and for the TCP/IP protocol he must
supply the server's IP address. Only one person can be
connected to a server at once. Do not try to run more than 
one NESticle server on the same port on the same
network, the results will be unpredictable.

After the connection has been made, the connection status 
window may be closed and the connection will remain active. 
Select Net/Disconnect to close the connection.
You can chat with the other player by opening the chat
window with Net/Chatwindow.

After you are connected, one person can load up a ROM, and
if the remote player also has the ROM his/her side will
load it as well. If the remote player does not have the
ROM or has an incompatible ROM (ie wrong size) then the
game will abort and an error will appear in the message window.
The person who last loaded the ROM or last reset the ROM
will be player 1. The game is played using each computer's 
input device 1.

Now for the complex stuff:
In order for netplay to work at all, both sides need
to be syncronized at all times. This is no problem for a low
latency LAN running over ethernet for example. However this
spells trouble for internet connections. In the connection window,
the ping times of all the nodes are shown. The ping time number
is measured in virtual frames. The NES normally runs at 60 frames
per second, so a ping time of '30' would be about 500ms. The
lower the ping time the better. The bandwidth that NESticle uses 
is negligable, less than 100bytes/sec.

Anyway, adjusting the 'vframe latency' number will affect how
lagged each player's input is. It essentially controls
how often game update packets are sent.....
A low vframe latency number will result in a very responsive game 
if your network can handle it. A high vframe latency
setting will result in a 'lagged game', but it may be necessary
for high latency connections (such as the internet).
If you have your vframe latency set too low, you will notice that the
game will 'freeze' periodically as it waits for the other computer
to respond. If you have it set too high, your game input will be
severely lagged, but the game will not 'freeze'. 

The default setting is 5, I highly recommend changing it.
On a LAN, where the connections are fast and reliable, a vframe 
latency of about 2 will result in great gameplay and performance.
On the internet, the best setting is about half of your pingtime.
I left the setting adjustable so you can mess with it to see whats
best. As far as internet play goes, personally i don't think
it runs very well, but that's not my fault as much as it is the
internet's and there's nothing I can do about it. 

Some last things: the vframe latency setting is not adjustable 
while in the middle of a game. You must free the ROM, change it, 
then reload. Also, save games will not work while connected and 
you cannot restore saved states. 

After this harangue still I repeat: netplay is still very preliminary, 
there are no guarantees, if it doesn't work right then fuck it. 
Just play with yourself instead.

---------------------
 Performance Issues
---------------------

This section has lots of technical crap.
Read at your discretion.

The DOS and Win95 versions vary greatly in the performance they achieve.
It all depends on the video hardware you have and the video acceleration
available. The Win95 DirectDraw version of NESticle takes advantage of hardware
blitting to improve performance tremendously. If your card does not support
hardware blitting then performance will most likely be worse than the DOS
version. You can tell if your card supports this by selecting
Misc/DirectDrawInfo from the menu.

There's one big catch: Most drivers written for Win95 do not inherently
support low res modes like 320x200 and 320x240. The ones that don't support
them have to substitute by using notoriously slow ModeX modes for these
resolutions. Not only do the ModeX modes not have hardware blitting, they
also have much slower page flips because of additional conversions necessary.
The DOS version will be significantly faster in cases like these.

The DOS version starts up in 256x224 mode by default. It's a resolution
perfect for the NES. The DOS version requires VESA 2.0 extensions to run
at 320x240 or above...if your video card does not have this built
in you can get Univbe from http://www.scitechsoft.com. Why would you want to
run at anything above 256x224 if the NES res is 256x224? Well, there's
two reasons: A 320x240 linear frame buffer VESA 2.0 mode on a PCI bus will
most likely be faster than the 256x224 mode. And secondly, Scitech's Univbe
allows you to pump up the refresh rate of low resolution modes which
makes things look a lot nicer. 

You can show the fps counter by selecting ShowFPS from the Misc menu.
To squeeze the most fps out of your system, make sure the GUI is disabled and 
the NES game window is maximized (ie hit ESC). This eliminates a lot
of overhead. Having WaitVsync turned on waits for vertical syncs before
drawing frames, this slows the frame rate to the refresh rate of the video
card (thats why it's a good reason to increase the refresh rate with Univbe).
WaitVsync is off by default.

You can see the % of CPU utilization in an option in the misc menu. I dunno what it's
good for, just looks neat. Anything besides the NES rendering and the 6502 Emulation 
bars is purely overhead. Interesting to note that under Win95, that all of the CPU
utilization bars never add up to 100% showing how much CPU time is sucked out by the OS. 

If a game ever 'slows down', it's most likely because it would have slowed
down at that part on a real NES too, and it isn't an emulator problem. 
Increasing the vblank/hblank intervals may alleviate that though.

---------------------
     Contact
---------------------

Bloodlust Software
bldlust@southwind.net
http://www2.southwind.net/~bldlust/NESticle.html

Email me about ROMs and your suffering will be legendary.

---------------------
  Acknowledgements
---------------------

Marat Fayzullin for his priceless NES.DOC and iNES emulator.

Multi-6502 CPU emulator by Neil Bradley (neil@synthcom.com)

Y0SHi for taking the time to maintain his 'nestech.doc'

Y0SHi, Marat and FanWen for supplying valuable information on NES sound.

Additional help by Neill Corlett, if you haven't gotten MGE yet 
then you suck: http://www4.ncsu.edu/eos/users/n/nscorlet/mge/

Additional info:
FanWen (yangfanw@ms4.hinet.net)
Andrew Davie (adavie@comcen.com.au)
Matthew J Richey (mr6v+@andrew.cmu.edu)
DeceiverX, Loopy, Vectriff

Scrotum-art and testing by digger.

Nesticular name idea by _Dsk_.

The creators of PMODE/W, a great DOS4GW replacement.

---------------------
     Disclaimer
---------------------

NESticle Copyright 1997 Bloodlust Software
Nintendo Entertainment System (NES) is a registered trademark of Nintendo.
Neither Bloodlust Software nor the author are affiliated with Nintendo
 nor advocate the piracy of NES games.
NESticle is freeware and can be distributed freely as long as it is not
 modified and ROMs are not packaged with the program.
The source code and any resources used to create NESticle are NOT freeware
 and cannot be redistributed, modified or used in ANY other projects
 as prohibited by their respective copyrights.
When you use this software you do so at your own risk. The author is 
 not responsible for any loss or damage resulting from the use or 
 misuse of this software.
If you do not agree with these terms than NESticle is not for you.
