WARNING
--------------------------------------------------------------
This program does some very low level things to your computer.
Use totally at your own risk.
--------------------------------------------------------------

This is the protected mode version of my atari 800XL-emulator.

This source was my way to get acquainted with the full capabilities of
a to me new processor. (I changed from a 68000 in an atari ST). I'm
distributing it, as it is now, because I'll stop working on it until
I can get hold of a protected mode debugger. It's quite hard to debug
code without single stepping through it. There are some code bits left
of my tries to debug it. (The si register gets written to 0000:01e0
every time before the emulator reads an instruction, so I could see
where to program was, when it crashed. And if you comment the routines
which switch screen modes, you get a small message on screen which
interrupt produces a crash. All interrupts I don't use point to a
stub function, which writes this message. You will not see these if
you let the program switch to 320x240 mode).

When you use the program you will have to remove DISPLAY.SYS and
EMM386.EXE from your config.sys.  DISPLAY.SYS collides with my screen
drawing routines and you can't have EMM386.EXE up because it uses the
paging unit and the processor runs in Virtual 86 mode. But don't
remove HIMEM.SYS).

The bank switching of an atari is achieved by setting the atari memory
space for the ROM memory to read-only and when a page fault is triggered,
setting it to read/write and letting it point to nowhere and then set a
breakpoint to the end of that 6502 instruction, where it is set back
to read-only and to the ROM memory space. (This could be simplified by
rewriting the part of the code which emulates the 6502 instructions to
set si which is used as the program counter to the next instruction before
it writes, and just change the return address in the page fault routine,
and so ignoring the 6502 instruction).

The read/write memory is simulated by setting its memory space permanently
to read-only and check witch memory location has triggered the page fault,
then you can react to it in the proper way. The so far implemented code
only reacts to writes to memory 54017 of the atari, which manages the
bank switching. When a write to read/write memory occurs, the appropriate
thing is done, the memory is set back to read/write and a breakpoint is
set, where it is set back to read-only to trigger another page fault at
the next write to it.

All of this might sound pretty complicated, but believe me, it was at lot
more complicated to code.

You may try this be starting emulator.exe with the file atari.5 in the same
directory, then write.

DOS (to get to ATARI DOS)
L
ROMRAM.COM (This is a 6502-machine language program which copies the BASIC and
            OS ROM parts of the atari to ram.)
B (To get back to basic, you needn't do a M A000 in the protected mode version)
?USR(1536) (This calls the machine language program from ATARI BASIC)

Then you can change from RAM to ROM by poking to 54017 from ATARI BASIC.
Try to write something to the ROMS and then check what you got.

54017:

Bit0: 1 = $C000-$FFFF OS-ROM
      0 = $C000-$FFFF RAM

Bit1: 1 = $A000-$BFFF RAM
      0 = $A000-$BFFF ATARI-BASIC-ROM

Bit2-6: unused      

Bit 7: 1 $5000-$57FF RAM          > not implemented
       0 $5000-$57FF Selftest-ROM > in the emulator

BUGS
----
It might be that it isn't working at all in your environment, because
I coded it on a 80386SX and didn't have any opportunity to test it on a
pentium. (I think it should work on the pentium too, because the page
fault is triggered in ring 3 code, so the WP bit isn't needed anyway).
The other thing which might prevent it to run is, that I used a nonstandard
video mode. So I can't tell, whether it will run on all SVGA-cards.

But it should in my opinion by possible to get it to run in every
environment by just slightly changing the code.

CREDITS

TRAN          Who wrote a dos-extender which made the skeleton of my protected
              mode code. There isn't much left of the original code now, but
              it tremendously helped me to build my first global and interrupt
              descriptor tables.

ADAM SEYCHELL I took over his way to comment the global descriptor table,
              which made it much easier to set it up. And I gleamed from
              his code, that you have to flush the instruction prefix cue,
              which made my first ring 3 code working.

ROBERT SCHMIDT
              Thanks for his article INTRODUCTION TO MODE X
              which made it easy to set up the 320x240x256 screen mode.

COPYING

The code is copyrighted by the GNU-General Public License.
See the file copying for details.
