Simulacron-3 (1964)
(also published as Counterfeit World), by Daniel F. Galouye, is an American science fiction novel featuring an early literary description of virtual reality.

Simulacron 3 is the story of a virtual city (total environment simulator) for marketing research, developed by a scientist to reduce the need for opinion polls. The computer-generated city simulation is so well-programmed, that, although the inhabitants have their own consciousness, they are unaware, except for one, that they are only electronic impulses in a computer.
The simulator’s lead scientist, Hannon Fuller, dies mysteriously, and a co-worker, Morton Lynch, vanishes. The protagonist, Douglas Hall, is with Lynch when he vanishes, and Hall subsequently struggles to suppress his inchoate madness. As time and events unwind, he progressively grasps that his own world is probably not “real” and might be only a computer-generated simulation.
Symbolically, the title term "Simulacron-3" refers to the just-built virtual reality simulator and ostensibly references a third attempt at "simulectronics" (the reality-simulating technology), however, the "3" also refers to the novel’s three levels of "reality," or three levels of computer simulation — if the final, "real" world is simulated. Moreover, "simulacron" is closely derivative of simulacrum, a superficial image representing a non-existent original.
To date, the novel Simulacron-3, about a counterfeit world, has twice been adapted, first as the two-part German television play Welt am Draht (1973) (World on a Wire), by Rainer Werner Fassbinder; second, cinematically, as The Thirteenth Floor (1999), by Josef Rusnak.
http://en.wikipedia.org/wiki/Simulacron-3
Welt am Draht - World on a WireDirector: Rainer Werner Fassbinder
Year: 1973

Welt am Draht (World on a Wire), is a 1973 science fiction film directed by Rainer Werner Fassbinder. Shot in 16 mm, it was made for German television and originally aired in 1973, as a two-part miniseries. Starring Klaus Löwitsch, it was based on the novel Simulacron-3 by Daniel F. Galouye
At the institute for cybernetics and future science ("Institut für Kybernetik und Zukunftsforschung, IKZ"), a new supercomputer hosts a simulation program that includes an artificial world with about 8,000 "identity units" who live as human beings, unaware that their world is just a simulacron. Professor Vollmer, who is technical director of the program, is apparently on the verge of an incredible secret discovery. He becomes increasingly agitated and anti-social before dying in a mysterious accident. His successor, Dr. Fred Stiller, has a discussion with Günther Lause, the security adviser of the institute, when the latter suddenly disappears without trace, before passing on Vollmer's secret to Stiller. More mysterious still is the fact that none of the other IKZ employees seem to have any memory of Lause.
Meanwhile, one of the identity units in the simulation attempts suicide. This unit is deleted by Stiller's colleague Walfang, to keep the simulation stable. To investigate the reasons for the suicide, Stiller contacts the contact unit of the simulated world. The unit, called Einstein, is the only identity unit who knows about the simulation, and this is necessary to run the program. In an attempt to become a real person, Einstein switches his mind into Walfang's body while the latter is in contact with the simulated world. Einstein gives Stiller an explanation for the mysteries, vanishing memories, and vanishing persons. He tells him that the real world is nothing else but a simulation of a real world one level above.
This knowledge causes Stiller to slip into insanity. The other "real" people interrogate Stiller, and he is threatened with death, incarceration, and involuntary commitment. Stiller is finally able to convince Hahn, the IKZ psychologist, of his theory. The latter soon dies in an accident that is pinned on Stiller, marking him as the suspected murderer of both Hahn and Vollmer.
Stiller flees and searches for the necessary contact unit who can connect the "real" world with the real world a level above. He survives several assassination attempts and discovers the contact is Eva, Vollmer's daughter, with whom he had once had a romance. Eva tells him he was modelled on the real Fred Stiller, a person whom Eva loved, but became mad with power from directing the simulation in the world above. While Stiller is programmed to die in an ambush, Eva switches the minds of the two Stillers and brings the simulated Stiller into the real world.
http://en.wikipedia.org/wiki/Welt_am_DrahtThe Thirteenth Floor
The Thirteenth Floor is a 1999 science fiction film directed by Josef Rusnak and loosely based upon Simulacron-3 (1964), a novel by Daniel F. Galouye (another film based on this novel is Welt am Draht (1973) (World on a Wire), a German two-part television film by Rainer Werner Fassbinder). The featured players are Craig Bierko, Gretchen Mol, Armin Mueller-Stahl, Vincent D'Onofrio, and Dennis Haysbert. In 2000, The Thirteenth Floor was nominated for the Saturn Award for Best Science Fiction Film, but The Matrix won the award.
In late 1990s Los Angeles, Hannon Fuller (Armin Mueller-Stahl) owns a multi-billion-dollar computer enterprise, and is the inventor of a newly-completed virtual reality (VR) simulation of 1937 Los Angeles. When Fuller is murdered, just as he begins premature testing of the VR system, his friend and protégé, Douglas Hall (Craig Bierko), becomes the primary suspect, and begins to doubt his own innocence.
Between questionings by LAPD Detective Larry McBain (Dennis Haysbert), Hall meets Jane Fuller (Gretchen Mol), who is the estranged daughter of the dead Hannon Fuller. Hall romances Jane, who is busy with the shut-down of the new VR system. When a local bartender (witness to a murder-night meeting between Hall and Fuller), is found murdered, Hall is imprisoned, but soon released, after Jane gives him an alibi.
Seeking answers, Hall attempts to track and find a message Fuller left in the simulation. In the VR system, Hall takes the form of a banker named John Ferguson, and even learns that bartender Jerry Ashton (Vincent D'Onofrio) has stumbled upon the truth about his artificial nature — he read the message Fuller addressed to Hall. Frightened and angry, Ashton tries to kill Hall, who barely survives to escape the virtual reality.
Now unable to find Jane, Hall discovers her double, Natasha Molinaro, working as a grocery store clerk — but Molinaro does not recognize Hall. This leads Hall to perform an experiment outside the VR system, something that Fuller’s letter instructed him to try: drive to a place where he never would have considered going otherwise. At a given point during the trip, he stops the car seeing how the area, and everything within it, are replaced with wireframe models. Finally understanding the meaning of inventor Fuller’s message, Hall grasps the truth: that 1990s Los Angeles — his world — is a simulation.
The facts: Douglas Hall's virtual world is one of thousands, but also is the only one that developed a virtual world of its own. Jane Fuller lives in the “real world” — and only participated in the 1990s simulation to assume the identity of Hannon Fuller’s daughter, gain control of the company, and shut down the simulated 1937 reality. Hall is modeled after David, Jane’s real-world husband, who, in the 1990s simulation, is seeking pleasure by murdering people. It was David who committed the murders (whilst controlling Hall’s body), on becoming jealous when his wife Jane fell in love with Hall, in the simulation.
Whitney (Vincent D’Onofrio), Hall's associate, enters the 1937 simulation, assuming the role of bartender Jerry Ashton, who has kidnapped Ferguson (Hall’s 1937 identity) and bound him in the trunk of his car. When Whitney is killed in a car crash, Ashton’s consciousness is released to Whitney’s body (in the 1990s simulation). Ashton kills a security guard, David (Bierko) assumes control of Hall, kills Ashton, and attempts to rape and murder Jane, who is saved by Det. McBain shooting and killing David.
That death releases Hall’s consciousness into David’s body; he wakes in 2024, connected to a VR system. He disconnects the system and finds Jane and her father, much resembling Hannon Fuller, the man he was accused of killing in his original reality. The film ends when Jane wants to tell Hall more about the simulation, but the film ends like a computer monitor being turned off.
http://en.wikipedia.org/wiki/The_Thirteenth_Floor