; History:
; The first versions of CPE were developed on a Commodore Amiga 500, 7MHz.
; They were quite slow! I converted it to Intel assembler after I bought a PC
; in June 93. I derived some ideas for the Z80 emulation from a public domain
; CP/M emulator by Charlie Gibbs called SIMCPM for the Amiga. I had to rewrite
; it completely since it supported neither banking nor interrupts. The only
; remains of SimCPM are some labels in the Z80 section and the opcode tables.
;
; v0.0:  910602 Basic emulation of z80 instructions
;               Some emulation of CPC's Mode 1 is done (SLOOOOOOW!)
; v0.1:  910605 Added some I/O support
; v0.2:  910607 increased speed about 10 times, but it's still slow
;               probably the best way to speed the whole thing up
;               is a 68040 board
; v0.3:  920504 fixed bug in GA memory management, so upper rom is called
;               now; added primitive interrupts (every 1000 Z80 instructions)
; v0.4:  920505 keyboard emulation added; exit now possible with both ALT keys
; v0.5:  920506 fixed bugs in Z80 XOR A, SBC and ADC commands; frame fly
;               interrupts; keymap (there were two Z keys)
;               most OS and BASIC functions are now working properly
;               added colors and video mode 2 support
;               still not working: scrolling, floating point arithmetics
; v0.6:  920507 completely rewrote code for Z80 DAA and ADD,SUB,SBC,ADC
;               instructions. Result: BASIC arithmetics are now working
;               almost correctly, but occasionally there are still some
;               problems. Added scrolling (sloooooow!)
; v0.7:  920509 now supporting multiple roms; added rom 7 (floppy control)
;               no floppy hardware emulation right now
;               added some optimizations
; v0.8:  920512 implemented floppy emulation by redirecting subroutines in
;               the CPC's floppy ROM to 68000 code. Except formatting, all
;               major disk operations are emulated. The file DriveA.dat
;               contains the data of the emulated CPC drive. CP/M can be
;               started and will work properly (I tested it with
;               INFOCOM's ENCHANTER). Currently only standard disk formats
;               (9 secs/track, 512 bytes/sec) are emulated
; v1.0:  920513 implemented video mode 0. In this version, all major functions
;               of the CPC should be working (I didn't test all of them,
;               though).
;               on startup not only the current directory is checked for ROM
;               files, but also a volume called "CPemul:"
; v1.1:  920515 found two bugs in Z80 simulation code, a minor one
;               in the LD (HL),H instruction and a rather nasty one which
;               prevented the DAA command from working when a PUSH/POP AF
;               occurred before it. Since the 68000 does not implement BCD
;               arithmetics by a halfcarry and an add/subtract indicator, but
;               has instructions for adding and subtracting BCD bytes, a Z80
;               emulator has to find a workaround. This is done by saving
;               both operands of each add operation. When a DAA occurs, these
;               operands are restored and added with the 68000 Add BCD command
;               The result is written in the accumulator. This is fine as long
;               as there is nothing like PUSH AF/ADD A,C/POP AF in the code.
;               But exactly this happens when an interrupt occurs between the
;               ADD and the DAA commands. Solution in this version: have an
;               extra stack for the BCD operands. The number of errors has
;               been reduced, but there are still occasional errors.
;               Improved interrupt emulation, TETRIS now works.
;               CRTC emulation now supports variable screen widths
;               added primitive form of Z80 debugging (regs printout)
; v1.2:  920517 almost complete Z80 disassembler (except DDs&FDs)
;               simple Z80 singlestep debugger implemented
; v1.25: 920519 fixed bug in debugger's (f)orward command, added (z)ip
;               added (c)olor mode command
; v1.3:  920521 more bugs fixed in cpe2.asm; RR (HL) didn't write back
;               (HL) contents after the operation. The M flag is now set
;               correctly after a BIT instruction (even Z80 experts may be
;               surprised to learn that this flag should be set although
;               even the official Z80 documentation says the flag contents is
;               unknown after BIT. I didn't find out until some program used
;               a JP M,xxxx after a BIT 7,(HL) instruction). The result of
;               all this: the game "The Sentinel" now displays 3D gfx
;               correctly.
;               also new this version: mode 0 scrolling without ugly stripes,
;               better emulation of IN instruction, undocumented opcodes
;               DD/FD 67/6F
; v1.4:  920527 found out why ELITE was crashing: the time between
;               interrupts was too small.
;               Fixed some more bugs: EX (SP),IX / EX (SP),IY
;               increased speed of LDIR instruction, added debugger commands
;               i1-i3 (interrupt speeds, for ELITE mainly)
; v1.5:  920529 fixed bug in calcind macro, which was responsible for the
;               errors in Turbo Pascal numeric output (offsets to IX were
;               always positive, although 80..FF must be interpreted as
;               negative numbers. This one may have been left over from SIMCPM.
;               I am not sure though, and can't find out since I deleted the
;               SIMCPM files
;               added debugger 'm' command
; v1.6:  920602 'm' command now working correctly
;               corrected bugs in keymap, added joystick emulation
;               did some research on the floppy controller IO addresses
;               FA7E/FB7E/FB7F. I think I have quite a good idea about what
;               is happening when the floppy rom accesses those addresses.
; v1.7:  920603 implemented some elements of floppy emulation; some rom7
;               routines no longer have to be replaced by special 68000
;               routines. Hardware emulation for track selection and sector
;               ID information now replaces old 68000 routines
; v1.8:  920604 implemented floppy controller $46/$66 commands
; v1.9:  920609 implemented Z80 (R)efresh register. It is used by some games
;               as an instruction counter for decoding parts of their
;               memory. "Certain games" means Bard's Tale, which nevertheless
;               does not feel like working right now.
;               Also fixed a bug in OUT (C),D --> Starglider now
;               displays gfx correctly
; v1.9b: 921019 now Kickstart 2.0 compatible (how could I mess up OpenWindow
;               like that !?!)
; v2.0:  950212 RELEASED
;               changed volume name from CPEmul: to CPE:
;               commented out the 68000 native emulation parts, because they
;               only work for 664 ROMs.
; v2.0a: 950219 made a 680x0 version, for x >= 1. Also new: a small utility
;               to convert .DSK files to the old .DAT format
;               Oops, there seems to be a bug left in the Z80 emulation.
;               'Labyrinth' from CPCPD1.DSK doesn't work as it should.
;
; ***************************************************************************
;
; v2.00: 930926 first version for IBM-AT and "100% compatible"...
;               first version that is working at least a bit, that is.
;               Some mode 1 support, colors work, no floppy disk emulation
;               Strange behaviour though from the emulated keyboard (in fact,
;               it is not emulated, but produces characters anyway...)
;               This is my first program in 80386 assembler which is longer
;               than ten lines.
; v2.01: 930927 another bug bites the dust - in fact, hundreds of them!
;               the result: working support of all cpc gfx modes
;               (incl. scrolling & weird modes & colors & blinking)
;               working keyboard emulation (PC/XT compatible keyboard)
;               other hardware requirements: VGA, 80386
;               trouble with BASIC's NEXT command (FPO stuff)
; v2.05: 930928 fixed bugs in (BIT 2,whatever) --> no trouble with testing
;               the ESC key. Also fixed: flags were often killed when AX
;               had to be PUSHed to do an operation (DD/FD adds...)
; v2.10: 931027 floppy load is now emulated. Elite & Tetris work!
;               complete crash for Bard's Tale, though
;               Starglider: same problem as on the Amiga
; v2.11: 931028 corrected some flag settings --> correct hex output from
;               BASIC
; v2.12: 931225 more bug corrections: better R register implementation, so
;               Bard's Tale now loads
;               no problem now when screen width is set to 0, so Bard's Tale
;               no longer crashes immediately after loading - it WORKS!!!!
;               multiple sector read now works (BT did not even get to the
;               R register part on the INTeL version until now)
;               DD6F/DD67 were reversed - that was Starglider's problem.
;               Now gfx were displayed.. until the machine crashed: I had
;               forgotten a POP CX in DD22/FD22... oops. Starglider now works!
;               something incredible happened: I had nowhere in the INTeL version
;               used the dozmf macro for BIT 7 instructions, but Sentinel showed
;               its gfx correctly nevertheless, I have no idea why it failed
;               to do so on the Amiga version. And I have no idea why it keeps
;               saying "wrong secret code" (aarggh)!
; v2.2:  940206 Received Marco Vieth's emulator two days ago. Amazed by the
;               speed of his screen refresh I realized that there must be a
;               faster method than the one I used, so I improved my routines quite
;               a bit. I no longer have three separate routines for screen refresh,
;               but only one universal routine which handles all modes and is
;               significantly faster than the old three ones.
;               ldir has been sped up quite a bit (same method as in Amiga version)
;               poor lddr is still the same...
; v2.21: 940207 FINALLY!! I have found the bug which caused Sentinel to fail...
;               it was, as usual, one wrong character: "gbhl AX" instead of
;               "gbhl AL" in CB16. It Is NoW wOrKiNg!!!
; v2.3:  940209 implemented better interrupt emulation. Interrupts are now called
;               almost precisely 300 times a second. Problem: LDIR, LDDR and
;               other time-consuming operations may delay an interrupt. I may
;               have to use another routine in the future. Currently I use
;               BIOS interrupt 15h, function 83h
; v2.4:  940213 G.A.Lunter's documentation to his ZX Spectrum emulator helped
;               me find 8 missing opcodes in my code: CB30..CB37 (SLL A..(HL))
;               Gigacad now works. Implemented sector save by bypassing rom 7
;               code
; v2.41: 940214 corrected HALT which did not work with the new interrupt model
;               better emulation of 8255, so AIRBALLS now works - but no overscan :-(
;               At least, the keyboard interrupt now works as it should - and
;               it was about time! Also: slightly faster screen refresh
; v2.42: 940220 many little optimizations resulting in a nice speed increase:
;               ELITE now works at normal interrupt frequency
;               Screen redraw routines have been improved: they are a lot faster
;               now and more friendly to the eye (the pointer to the PC screen
;               is now used as loop variable, so screen is refreshed from top
;               to bottom instead of draw the first line of all characters...)
;               Disk write corrected (working again!). None of my programs
;               have any difficulties now. Problems though with MV's disk:
;               I suspect he uses RAM-Banking, which I have not implemented
;               Almost nothing from this disk works!
; v2.43: 940221 fixed a bug that was introduced in the last version: screen
;               width 40 height 0 crashed the machine (a table of 256 lines was
;               generated instead of one with no lines)
; v2.5:  940223 OVERSCAN! Muri & Airballs now display their full screens!
;               better interrupt emulation (now 292 ints/sec instead of 256)
;               The problem is the PC's RTC which can only generate interrupt
;               frequencies like 1024 or 2048Hz etc.
; v2.6:  940225 this version implements what I have always dreamed of: colored
;               stripes! I am incredibly happy with these, even if they don't
;               always start at the exact line. In fact, there is a lot of
;               room for improvements, but the most important thing is that
;               ELITE now has correctly colored zones.
; v2.7:  940303 This version introduces double buffering support - AIRBALLS
;               is significantly faster than on an older version. Everything
;               else works as usual, only Starglider did not like the change
;               and crashes a bit more often - but I am used to having nothing
;               but trouble with this program.
; v2.71: 940312 implemented diskchange feature and corrected some bugs.
;               most of MVs programs now work, DD7D changed F instead of A!
; v2.8:  940317 this version uses the timer instead of the RTC and has the
;               correct interrupt speed of 300.4Hz, exactly the same screen
;               refresh rate in PCRTC mode 2 and thus better color stripes.
; v2.9:  940320 many little speedups and a major one: R emulation can now
;               be switched off via a different opcode table. Not quite enough
;               for troublemaker Starglider though, it still has to run with
;               half the interrupt speed.
;               implemented a nice little menu to control various aspects of
;               the emulation: R register, FF synchronization, double buffering,
;               interrupt omission, ffly bit reset
; v2.91: 940331 corrected the bug in scroll routines, it is now possible to use
;               8 bit access instead of 16 bit. Screen widths up to 255 no longer
;               crash both CPC and PC. FDC emulation improved, no crashes after
;               diskchanges any more
; v2.92: 940401 corrected bug in RR (IX+d); better emulation of illegal FDs;
;               FDC can now write without patch. Cassette emulation! Loads
;               from the DOS directory TAPE\. Can't write and is quite slow
; v2.93: 940402 corrected some in/out bugs, so the 'Last Demo' now works.
;               patched CAS IN OPEN to speed up the process
; v3.0:  940403 SOUND! quality ranges from very good (TETRIS) to poor
;               (everything which uses noise generator). Makes ELITE crash,
;               probably too slow.
; v3.01: 940404 corrected bug: huge overscan screens became very small, because
;               the VGA card did not get a MSB. Now FULLSCR and Sounddemo work
;               better.
; v3.1:  940414 some slight speedups; some obsolete code removed
;               more undocumented DDCBs, IM2 implemented for Boulder Dash (works!)
;               Also a little RAM-banking (in a very early stage: incorrect
;               screen refresh, slow)
; v3.11: 940415 faster scrolling by moving VGA screenstart, emulation is slowed
;               down a bit though. New also: INI, OUTI, OUTD, IND
; v3.12: 940416 added feature to CAS IN OPEN, spaces in names are now deleted
;               when necessary. Also corrected CAS IN OPEN patch in 6128 ROM
;               increased scrolling speed by faster offset table generation
; v3.2:  940420 new in this version: multimode. It works... sometimes. There
;               is still a lot of room for improvements. Better joystick
;               emulation for Devil's Crown, which crashes when the emulated
;               joystick is simultaneously pushed left and right.
; v3.3:  940422 improved SetPCsCRTC, which now no longer interferes with the
;               timer interrupt, so that the picture is restored without
;               trouble in displaymode 2. CPE can now load snapshot files
;               in Marco Vieth's format. Corrected a huge bug in RethinkRAMState
;               (ES was not saved, I wonder why it worked at all until now!)
;               There was an error in my hardware documentation concerning the
;               8255 control register; this is now fixed. Caps and Num Lock
;               LEDs are controlled by the keyboard interrupt. Speed has been
;               increased quite a bit by replacing the JMP simz80l at the end
;               of each instruction by a short sequence which either jumps to
;               the next opcode or to the interrupt and other stuff handler
; v3.31: 940423 better port emulation; as on a real CPC you can now address
;               several chips with one OUT. I hardly think that anyone ever
;               used that feature, though. Corrected a HUGE bug in LDD: it
;               did not set the flag register, it changed the accumulator.
;               Oooops! Wonderboy now works. Also improved FDC emulation,
;               @ now works.
; v4.0:  940426 Yes, that's version FOUR, although there have only been two
;               bug corrections since version 3.31, but these were *HUGE* bugs,
;               which had been in CPE since the beginning.
;               Rule No.1: Never be sure that the stack segment is always the
;               same in your interrupts. DOS functions may modify SS, so you
;               get nice crashes when your interrupt is called while DOS is
;               active and you try to reach your data via the BP register
;               (ASSUMEd: SS=DS=DATA). This bug caused lots of trouble and
;               was incredibly hard to find.
;               The second bug only crashed the CPC: I never knew that when
;               an interrupt occurred, all further interrupts were disabled.
;               Hardly any program depends on this, since they do a DI command
;               anyway at the start of the interrupt routine, but Hardball and
;               Overlander crashed in the old version.
;               So much for bug hunting!
; v4.1:  940501 corrected bugs in multimodes, almost all programs now work
;               EMS can be used to emulate RAM banking. CP/M Plus does not
;               work very well, though.
; v4.11: 940507 printer support
; v4.2:  940514 new diskfile format, diskfiles can now be crunched. Minor
;               bugs removed
; v4.3:  940522 corrected bugs in PIO: Antiriad and Barbarian now work.
;               multimodes are a little more stable when there are changes in
;               one frame caused by timing problems. Corrected R emulation,
;               Mission Elevator now works
; v4.4:  940605 new: packed tape archives
; v4.5:  940707 realtime cpc (more or less), compatibility to other graphics
;               cards than OAK.
; v4.6:  950223 enhanced compatibility to CPCEMU: CPE can now read V2
;               snapshots, .DSK files and CPCEMU style ROM files.
;               .DSK file support is currently write protected.
;               made a second version that uses 256 color 320x256 mode, runs
;               realtime and has almost perfect color/multimode emulation.
;               fixed the 'clear interrupt' feature of the Gate Array
; v4.7:  950308 Bug fixes. Enhanced joystick support. Refresh rate for CPE2
;               can now be configured in CPESETUP
; v4.8:  950802 Added Ulrich's GUS support. Included the ROMs and STRIPES.BAS.
; v4.81: 950825 Made CPE2.EXE handle overscan screens better. Horizontal
;               scrolling is possible with the F11/F12 keys.
;               Cleaned up CPESETUP. New option to disable cassette messages
;               by patching the ROM.
;               New menu option in CPE2 to force a display height of 200
;               lines.
; v4.82: 950826 cleaned up the screen part in CPE2. Better display for
;               many programs. Beginnings of an emulation for the 'split
;               screen' or 'rupture' technique (quite buggy yet).
; v4.83: 950828 fixed a bug in OUT decoding.
; v4.84: 950829 fudged the FDC emulation to get Logon's "The Demo" working.
;               Finally found the bug in the EMS part in CPE2.EXE: The
;               documentation (Data Becker...) had a DI where a SI was needed.
; v4.85: 950830 moved some more common code into top directory.
;               It should no longer be possible to crash CPE with an
;               uncalibrated joystick.
;               Cleaned up the menus a little.
; v4.86: 950831 Re-enabled VESA mode support in CPE2. It's possible to use
;               a 800x600x256 screen. Borders can be enabled in the menu.
; v4.87: 950901 Menus can now be painted on the CPC screen instead of
;               switching back to a text mode. This saves some pain for the
;               monitor. (Only implemented in CPE2)
;               Changed a few bits and pieces in the CRTC emulation (in CPE2)
;               The Voyage 93 Demo now identifies the CRTC as type 2 (used to
;               be type 1). Some programs work better, others have new
;               problems :-/ The "Advanced" Demo now works.
; v4.88: 950902 Implemented the CRTC's 32K screen size feature (seems to
;               work). Only for CPE2, 800x600, EMS.
;               Centering now works in 800x600 with borders.
;               Returned to CRTC type 1, because type 2 breaks some programs,
;               although I believe it is the Right Thing to use type 2. The
;               choice can now be made at compile time.
; v4.89: 950905 Finally wrote a better snapshot filename prompting routine.
;               A list of files is shown, and the filename you type can be
;               edited.
;               When you select a diskfile or a snapshot, the next time you
;               enter the menu again the pointer will be on the last file you
;               selected.
;               Apparently, when an interrupt occurs, the next interrupt can
;               happen only after 52 further scan lines. Changed CPE2
;               accordingly (and what I have to do in ResetInterruptCounter
;               finally makes sense)
; v4.9:  950908 Hmm... now I can make Voyage 93 detect a CRTC 0, but no longer
;               a CRTC 2 - the "CRTC 2" setting now produces type 1 as well.
;               But the "CRTC 2" setting seems to work best, so I think I'll
;               leave it at that.
;               Fixed interrupt behaviour - at least, a little test program
;               gives the same results now as on the real CPC. However, "real"
;               programs are sometimes not quite as happy about the change
; v4.91: 950909 Fixed a few problems with CRTC emulation. Many parts of "The
;               Demo" or "Voyage 93" now work fine.
; v4.92: 950910 Fixed some more problems with the CRTC. Most demos now work
;               great, with some little problems occasionally.
;               Finally figured out how to pretend the different CRTC types
;               correctly:
;               CRTC 0: Short frame fly interval ( <9 scanlines)
;               CRTC 1: Long frame fly interval  ( 17 scanlines?)
;               CRTC 2: Like CRTC 1, but buggy: No frame fly generated when
;                       screen width is 50.
;               Reordered most of the main loop to clean things up.
; v4.93: 950911 Made 32k screens possible in "small VESA mode".
;               In the menus, you can jump to a specific diskfile group by
;               pressing the first letter from the name.
;               Fixed a stupid bug in the CPE2 320x200 scrolling routines.
; v4.94: 950913 Improved interrupt generation. Some programs work again, and
;               my little "INTTEST.BAS" gives correct answers in all tested
;               cases. However, the "Turn Disk" part of The Demo and some
;               other stuff is broken now :-{
; v5.00: 950914 Some more correct answers from INTTEST, and the Face Hugger
;               demo seems to work all the way. "Turn Disk" from The Demo is
;               still broken, but apparently nothing else.
; v5.01: 951005 Fixed the "Clear Interrupt Counter" feature - it's only
;               supposed to clear the high bit.
;               Fixed some extremely silly bugs in the 8255 emulation. This
;               should really work now.
;               Removed the 'R emulation' setting from CPE2, it's pointless
;               for fast machines that CPE2 is supposed to run on.
;               Implemented automatic refresh rate calculation for CPE2. If
;               the PC is too slow, no screen will ever be drawn.
; v5.02: 951006 Attempt to implement directory changing for the disk
;               selection menu. Crashes sometimes.
; v5.03: 960204 New GUS code from Ulrich. Trying to fix directory changing.
; v5.04: 960418 New FDC code from Ulrich.
; v5.05: 960530 Final version of FDC code. Bug fix from Brad Thomas. Updated
;               documentation.
; v5.06: 960??? SB code from Ulrich.
; v5.07: 960805 Updated documentation.
; v5.08: 960907 Use SB_Pause and SB_continue where appropriate. SB_Sound
;               v1.04 added. New setup item DMAblocklen.
; v5.09: 960923 Added French keyboard patches from Thierry Dymon
; v5.10: 960929 ROM 5 and 6 can now be loaded, and ROM 7 is optional, too.

Versions released by Ulrich Doewich:

; v5.20: 970421 Sorry.. didn't keep a detailed, _separate_ log of what
                changed from build to build. Please refer to the
                WHATSNEW.TXT file and the source package for the complete
                low-down.
