2007-01-13: Updated to version 42

Signed-off-by: Gwenhael Le Moine <gwenhael.le.moine@gmail.com>
This commit is contained in:
Gwenhael Le Moine 2024-03-20 07:41:14 +01:00
commit 390c734a61
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
54 changed files with 30991 additions and 0 deletions

313
DEBUGGER.TXT Normal file
View file

@ -0,0 +1,313 @@
Debugger in Emu48/Tools/Debugger...
-----------------------------------
This is a short description of the internal assembly debugger of Emu48.
The debugger was designed to help customers inspecting assembler code objects, a part that cannot be handled satisfactorily by the JAZZ package. Thanks to Mika Heiskanen and all the others supporting this great program.
After starting the debugger the emulation will stop at the current program counter position. The emulation will continue after closing the debugger window. Please remember that the clock now shows the wrong time.
1.) Menu Debug
- Run F5
Continue calculator emulation under debugger control. The emulation will stop at a breakpoint. Please remember that the emulation speed is slower than without debugger control.
- Run to Cursor F6
Execute program until address at cursor position is reached. Breakpoints are still active and may stop execution before.
- Step Into F7
Execute one code instruction.
- Step Over F8
Execute a GOSUB, GOSUBL or GOSBVL as one instruction. Normally the instruction cursor will set to the position behind the GOSUB instruction.
But this makes trouble in the following code part:
GOSUB +
NIBASC /Hello world/
+ C=RSTK
The program counter will never reach the address behind the GOSUB instruction. The debugger solve this problem by breaking the emulation when the stack has the same level before the GOSUB instruction. In this example the single step execution will continue after the C=RSTK instruction.
- Step Out F9
Continue the program until a RTI, RTN, RTNC, RTNCC, RTNNC, RTNSC, RTNSXN, RTNYES instruction is found above the current stack level.
At some code constructions (mostly used to save space on the hardware stack) like
C=RSTK
PC=C
and
C=RSTK
RSTK=C
RTN
the stop address will be wrong. The problem in both code fragments is the C=RSTK opcode. In the first example there is no RTN instruction to stop. In the second one the C=RSTK instruction purge the original return address and then the RSTK=C instruction is interpreted as a GOSUB instruction.
In opposite the following code will work fine:
RSTK=C
..
code <- F9 was pressed here
..
GOSUB -
C=RSTK
RTN <- emulation will stop after this instruction
- RTN
So be careful using the F9 key.
- Break F11
Stops the emulation at the current program counter position.
2.) Menu Breakpoints
- Set Breakpoint F2
Toggle a code breakpoint at the cursor position in the Code window.
- Edit Breakpoints...
You get a sorted list of all current breakpoints. When the breakpoint is checked it's enabled otherwise it's disabled. With "Add" you can add a new or enable an existing breakpoint, with "Delete" you can delete the selected ones. Addresses greater than #FFFFF are cut after the fifths nibble. When adding a new breakpoint, you must select if this is a "Code", "RPL", "Memory Access", "Memory Read" or "Memory Write" breakpoint.
- "Code" stop before opcode execution on this address
- "RPL" stop on the first opcode of the selected RPL address
- "Memory Access" stop before reading or writing to the selected address
- "Memory Read" stop before reading the selected address
- "Memory Write" stop before writing to the selected address
With a left mouse button double click on a breakpoint you can toggle the check box inside. When you use the space key instead, on all selected breakpoints the check box is toggled.
- Clear All Breakpoints
Clear all address specific breakpoints.
- NOP3 Code Breakpoints
What are NOP3 code breakpoints? As you know user programs are loaded somewhere in memory and can be moved after a garbage collection. So it's very difficult to break a user program at a hard set breakpoint with F2. To solve this problem the debugger will stop emulation at a NOP3 opcode. So you can easily add a NOP3 command into your sources to force a break condition. To enable this you have to check this item.
NOP3 and NOP3, what's the difference? The Saturn CPU has no NOP command, so NOP3 is an opcode that is three nibbles long and doesn't change a register. In the HP SASM.DOC document two different opcodes are defined for NOP3:
Opcode 820 for HST=0 0
and
Opcode 420 for GOC + (next line)
In the assembler of the HPTOOLS 3.x package NOP3 is defined as opcode 820. The advantage of the opcode is that the execution time is always the same, independent from the carry flag. This code is used in the HP48 ROM as well. So I decided to use the GOC opcode for a code breakpoint condition.
A short example how to use a NOP3 Code breakpoint:
ASSEMBLE
NIBASC /HPHP48-E/
BREAK MACRO
CON(3) #024 NOP3
ENDM
RPL
CODE
BREAK code breakpoint
GOSBVL =SAVPTR save register
GOSUB + problem for step over
NIBASC /Hello world/
+ C=RSTK
GOVLNG =GETPTRLOOP
ENDCODE
- CODE Object Breakpoints
If this item is checked, the debugger stops program execution at the first instruction of every DOCODE object which isn't located in ROM. For inspecting DOCODE objects in ROM use address CODE breakpoints instead please.
- RPL Breakpoints
If this item is checked, the debugger stops program execution on every instruction called after a PC=(A) or PC=(C) opcode. This is normally the begin of a new RPL command. RPL breakpoints use a "-R" marker instead of the assembler "->" PC position marker.
3.) Menu Interrupts
- Step Over Interrupts
If this item is checked, interrupt handler code will be skipped. This option is useful when you don't want to debug the interrupt handler. But be careful, when you disable the interrupts all code until interrupt enable belong to the interrupt handler code and couldn't executed in single step any more. Enabled breakpoints are still active.
You can also use this option if you want to quit the interrupt handler. Just check this option, press F7 for "Step Into" for stopping the debugger behind the RTI instruction, and uncheck this option again.
4.) Menu Info
- Last Instructions...
This is a short viewer for the last 255 executed CPU addresses. The disassembled opcode maybe wrong, because only the CPU address of each command was saved and memory mapping may have changed meanwhile. In the "Last Instructions" dialog you can copy selected lines to the clipboard or clear this list.
- Profiler...
This opens a small toolbox window which shows the number of CPU cycles and the corresponding execution time of the instruction sequence between the last two breakpoints. The CPU cycles are only approximate values, the real cycles are depending mostly on the used ROM to Saturn CPU core interface.
- Write Only Registers...
Some of the display registers have a different meaning on reading and writing. This dialog shows the data written to the write only I/O registers.
5.) Code window
This windows shows you the disassembled code. The line with the current PC is marked with a "->" or "-R" between the address and the disassembly.
You can use the UP, PAGE UP, DOWN and PAGE DOWN keys to scroll the window content. There is one strange behavior, when you move to higher addresses the debugger is able to disassemble the next line correctly, but when you move to cursor to lower addresses the debugger does not know if this address is at the begin or inside of an opcode. In result you get wrong disassembled lines.
Context menu pressing the right mouse button:
- Go to address... G
Moves the cursor to the specified code address.
- Go to PC
Sets the cursor to the actual position of the PC.
- Set breakpoint F2
Toggle a code breakpoint at the cursor position in the Code window.
- Set PC to selection
Set the PC to the cursor position. Be careful with this command, you change the execution order of the commands!
6.) Register window
Here you can see the actual contents of the CPU registers. The values are only updated at a program execution stop. All changed CPU registers are highlighted.
With the left mouse button you change the content of the register. On bit registers, like CY and Mode, the state change immediately without any request.
7.) Memory window
This windows shows the memory content in the selected context.
You can use the arrow, PAGE UP and PAGE DOWN keys to move the cursor to a memory position. With a double click on the left mouse button (only in Map mode) you can change the content of the two addresses. When the memory position is read only (ROM or write protected RAM) the content wouldn't change.
Context menu pressing the right mouse button:
- Go to address... G
Moves the cursor to the specified memory address.
- Go to PC
Sets the cursor to the actual position of the PC.
- Go to D0
Sets the cursor to the actual position of the D0 register.
- Go to D1
Sets the cursor to the actual position of the D1 register.
- Go to Stack
Sets the cursor to the return address placed in the top level of the stack.
- Follow
Follow is a Pop-up menu to change the address behavior of the memory window. Normally the address of the memory window is static and only change by entering a new address. With Follow the memory window view follow the content of a selected address or register. In follow mode the memory window is only updated after an emulation step.
- Follow none
This is the default mode. The address of the memory window is static.
- Follow Address Content
This is a special mode of indirect addressing. You can specify an address which content will we interpreted as memory pointer. The memory window follow this memory pointer.
- Follow Register PC/D0/D1
The memory window follow the content of the selected register.
- Find... F
Calls the "Find" dialog box, allowing you to search for a data sequence in hexadecimal or ASCII mode. The search area is selected by the memory view Mapping mode described in the following section. When you close the "Find" dialog box, you will loose all saved strings in the data combo box.
- Mapping
Mapping is a Pop-up menu to select the memory view of the Memory window. Normally the CPU see only 512KB of the total memory, the rest is banked or covered by other modules. The following menu entries select the memory chip connected with the chosen Chip Select signal of the MMU. The connections are calculator model dependent.
- Mapping Map
This is the default mode. Here the Memory window shows what the CPU see. In this mode you can also change the memory content of writeable memory.
- Mapping NCE1/NCE2/CE1/CE2/NCE3
Here the Memory window shows the content of the selected Chip Select signal. The content is showed in a linear address model and it's content can't be changed in this mode.
Here's a comparison of the mapping of the emulated calculator models:
Abbreviations: ROM = Read Only Memory
RAM = Random Access Memory
Flash = electrical reprogramming ROM
Slt = Memory Card Slot
BS = Bank Switcher (no memory)
nc. = not connected
| HP38G | HP39/40G | HP48S/SX | HP48G/G+/GX | HP49G
-----------------------------------------------------------------------------
NCE1 | ROM 512KB | ROM 1024KB | ROM 256KB | ROM 512KB | Flash 2048KB
NCE2 | RAM 32KB | RAM 128KB | RAM 32KB | RAM 32/128KB | RAM 256KB
CE1 | nc. | BS | Slt1 32/128KB | BS | BS
CE2 | nc. | nc. | Slt2 32/128KB | Slt1 32/128KB | RAM 128KB
NCE3 | nc. | RAM 128KB | nc. | Slt2 32KB-4MB | RAM 128KB
8.) Stack window
The content of the hardware stack is viewed here. In "1:" is the current return address. A double click on an item shows the address content in the Code window.
Context menu pressing the right mouse button:
- Push
Push a new element before the current selection onto the stack.
- Pop
Pop the selected element from the stack.
- Modify
Modifies the stack content of the current selection.
9.) MMU window
The configuration of the memory controllers is viewed here. The viewed addresses are the first address of each module area and may differ from the given address in the CONFIG command.
This example
LC(5) #C0000 128KB size
CONFIG
LC(5) #98765 start address of module
CONFIG
will config a 128KB module at address #80000 and not at the given address. So the MMU viewer will show you the address #80000.
10.) Miscellaneous window
The Miscellaneous window show you the internal state of the interrupt flag, the 1ms keyboard handler and the contents of the Bank Switcher latch. The Bank Switcher item is only enabled on calculators with a latch inside. You see the loaded value of the address lines A6-A0. You have to ignore the last bit (A0), because it isn't wired to the six bit latch.
You can change the values by pressing the left mouse button over the old content.
02/24/06 (c) by Christoph Gießelink

BIN
EMU48.EXE Normal file

Binary file not shown.

460
EMU48.TXT Normal file
View file

@ -0,0 +1,460 @@
Emu48 - A freeware HP38/39/40/48/49 Emulator
for Windows 9x, ME, NT, 2000 and XP
********************
* OPERATING SYSTEM *
********************
This version of Emu48 should work with all Intel Win32 platforms. You may
recompile the sources to run Emu48 with Windows NT on a DEC Alpha.
****************
* INSTALLATION *
****************
Emu48 is distributed in 1 archive:
- Emu48-1_35.zip All files and sources
To install Emu48, just unzip Emu48-1_35.zip into an empty directory. When you
first run Emu48, it will detect the directory in which you installed it, and
will write its configuration to a file named Emu48.ini in your Windows
directory. If you move the Emu48 directory to another place you have to change
the directory path inside the Emu48.ini file manually or have to delete the
Emu48.ini file.
You can also update your current version with the Unofficial Service Packs:
- E48BP3x.ZIP New EXE-File
- E48SP3x.ZIP Sources of the Service Pack
Replace the original EXE file please.
************************
* YOU NEED A ROM IMAGE *
************************
Emu48 needs an image of a calculator ROM to be able to run. Since fall 2000 the
emulator ROM's for the HP38, 39, 40, 48 and 49 are freely available on different
internet sites. Because there's no license for the distribution of the ROM
images, they aren't included in the Emu48 package. You can still use the classic
way extracting them from your own calculator. But in mostly all cases you have
to convert the ROM files into the Emu48 ROM format.
- HP38:
To upload the ROM of your HP38G, you will need a special aplet called "ROM
UPLOAD", available at http://www.epita.fr/~avenar_j/hp. Once you've uploaded the
ROM, you have to convert it using the Convert utility.
To do that, start a Command Prompt while running Windows, and type:
Convert <rom-file> ROM.38G
Where <rom-file> is the path to your ROM image. This will create a file named
ROM.38G. This tool will also check its validity.
- HP39/40:
To upload the ROM of your HP39G/HP40G, you will need a special aplet called "ROM
UPLOAD", available at http://privat.swol.de/ChristophGiesselink/emu48.htm. Once
you've uploaded the ROM, you have to convert it using the Rom2emu utility.
To do that, start a Command Prompt while running Windows, and type:
Rom2emu <rom-file> ROM.39G
There's also a HP39G/HP40G beta ROM for emulators at
http://www.epita.fr/~avenar_j/hp/39.htm for download.
- HP48:
If you have already used another HP48 emulator, you can convert the ROM using
the Convert utility.
To do that, start a Command Prompt while running Windows, and type:
Convert <rom-file> ROM.48G
or Convert <rom-file> ROM.48S
Where <rom-file> is the path to your old ROM image. This will create a file
named ROM.48G or ROM.48S, depending on the version you own. This tool should be
able to read any style of ROM image, and will also check its validity. Note that
if you run it with only one parameter, no file will be written, but it will
still check the validity of the ROM.
If you have never used an HP48 emulator, and don't have a ROM dump, you can
either use Jean-Yves Avenard's ROMUPL.BIN or the ROMDump Wizard V1.x, which will
almost automatically get the ROM from your HP48. After the download you may have
to convert your dump with the CONVERT utility into the Emu48 format.
You can find the latest version of the ROM dump programs on:
ROMUPL.BIN http://www.epita.fr/~avenar_j/hp/calcen.html
ROMDump Wizard http://privat.swol.de/ChristophGiesselink/index.htm
- HP49:
There's no ROM download program available so far. But you can find a HP49G ROM
for emulators in the YorkeM emulator package or in the HP49G SDK on
http://www.hpcalc.org in the HP49 section.
****************
* HOW TO START *
****************
When Emu48 is installed and you have put the ROM image(s), which must be in the
Emu48 ROM format, into the Emu48 directory, you can start Emu48. You'll see a
"Choose Your KML Script" box.
KML Scripts in fact define the visual aspect of Emu48, the behavior of the
buttons, of the keyboard, ... It's a GREAT way to customize your copy of Emu48.
Check that the path in the "Emu48 Directory" text area is correct. Modify it if
the directory in which you installed Emu48 is not the directory displayed. Click
the refresh button ("V") after modifying it to update the list box or use the
("...") button to start the directory browser.
Choose a KML script in the list box for your calculator ROM you put into Emu48's
directory.
Several HP48 scripts are included in the Emu48 archive:
* Emu48's Default Faceplate for HP48G/GX
* Emu48's Default Faceplate for HP48S/SX
These two are simple scripts, good for 800x600 display resolution.
* Casey's Gx with Toolbar and Touch Screen
* Casey's Sx with Toolbar and Touch Screen
These script uses many advanced features, and is a good demonstration of
the power of Emu48's scripting language KML. Try it, it is really great!
* Floating buttons
This one looks really great.
* Small but realistic HP48 Gx
This one has been designed for small resolutions such as 640x480.
Note: some things in this script have to be fixed.
If you want other great scripts, visit Rechlin's great HP archive
http://www.hpcalc.org/
And if you are interested in writing new scripts, get the KML 2.0 documentation
from Christoph's page at http://privat.swol.de/ChristophGiesselink/emu48.htm
Once you have selected a script, press OK to start the emulator. In most cases,
when Emu48 crash after pressing the OK button, you forgot to convert the ROM
image into the emulator format. While it's running, you can use the View/Change
KML Script... command to change the visual aspect of Emu48.
***************
* KML SCRIPTS *
***************
Don't use TRUELCD.KMI for emulating display contrast in your scripts. It's not
fully correct. The hardware contrast values are in the area from 0 to 31. But
the ROMs bounds them to useful values. The HP48 S(X) ROM use only display
contrast values between 3 and 19 and the HP48 G(X) ROM values between 9 and 24.
Maybe you have to adjust the "Rom" filename in the "Global" section. This mostly
happen with the HP49G ROM name. Some KML files use the name ROM.E49, that's the
name of the emulator ROM file published by HP. But Emu48 state files for the
HP49G have the same file extension, so the use of ROM.49G is preferred now.
****************
* COMMAND LINE *
****************
The command line syntax is "Emu48 [E48file [Port2file]]". The first parameter
sets the filename for the emulation data, the second parameter the Port2 file.
You're not able to set a Port 2 file without setting the emulation data file.
The arguments are optional.
*******************
* LOAD/SAVE FILES *
*******************
There are two ways to transfer files from or to the emulator. The one way is to
use the serial port to transfer the data directly from your HP to the emulator.
The second way is to load data, saved on your PC, into the stack of the
emulator. You can do this by using the Edit/Load Object... command or with the
file Drag and Drop feature. But there's one important restriction, the data must
a HP binary file (begin with HPHP48- or HPHP49-, this depends on your emulated
calculator)! If not, the data is load as string. The Edit/Save Object... command
will save the data in stack level 1 on the PC (always binary mode). Be sure,
when you use the second way for data transfer, that no program is running on the
emulator. The second way doesn't work on a HP38, because he has no stack. So you
can load aplets only from the serial port.
*****************
* DRAG AND DROP *
*****************
Dropping HP objects over the emulator window will load program files (like the
command "Load object...") on the stack. Be sure that the emulator isn't busy
before doing this.
*******************
* SHARED RAM CARD *
*******************
You can add a SHARED (explained below) RAM card of up to 4MB to a HP48. By
default, no such card will be created when you start Emu48. The MkShared.exe
utility will allow you to create it.
To create a Port 2 RAM Card, call the program, select the RAM Card size, enter
the card file name and press the 'Create' button. That's it. Please remember,
this program replace the destination file without any request!
If you use RAM cards greater than 128 KB in a HP48SX, you can only see the first
128 KB of the card. Please remember, the firmware of all HP48GX versions has a
bug when using a 4MB RAM card. You always get the message "Warning: Invalid Card
Data" at startup and Port 33 is unaccessible. This is not a bug of the emulator!
When you have created this file, run Emu48, and use the Close menu item to close
the calculator state. Now select File/Settings. In the "Port 2" text area, type
the name of the file you created (if you don't include a path, it will be
searched for in Emu48's directory).
You can also tick the check box "Port 2 Is Shared". When the box is cleared,
only the first instance of Emu48 will allow you to use the RAM card in Port 2.
When this box is checked, the first instance of Emu48 will give you both read
and write access to this RAM card. If you start Emu48 in another instance, the
RAM card in Port 2 will be write-protected. Thus you can transfer files very
easily between two calculators. This RAM card is used by both S/SX and G/GX
types.
***********************
* FLASH ROM EMULATION *
***********************
The HP49G save the operation system in a reprogramable memory, a so called flash
memory. The flash memory is divided into two parts, into the Operating System
and into a User Data area. The User Data area is viewed as Port 2 in the HP49G.
Emu48 saves the Port 2 data in the ROM file (normally ROM.49G). As default
setting the ROM file is writeable in the first instance of Emu48. When you open
another instance of a HP49G emulation the Port 2 area is READ ONLY, that mean
all changes in Port 2 are lost when you exit this instance. If you don't want to
save data in Port 2 and want to protect the operating systems from overwriting,
you're able protect the ROM file. To do this, close all Emu48 instances and set
the variable 'Writeable' defined in the Emu48.ini file, section [ROM] to zero.
***********************
* COPY / PASTE STRING *
***********************
With the menu items "Copy String" and "Paste String" in the "Edit" menu you're
able to copy HP string objects from the stack to the PC clipboard and vice
versa.
**********
* BACKUP *
**********
Emu48 includes a backup feature (in the Edit menu). It save the complete state
of the calculator (excepting the ROM and Port 2 content) in the computer's
memory. You might want to use it before doing something risky, and if you don't
want to save to the disk. It provides some kind of Undo feature. It is also used
by Emu48 when you want to save or load a new document, to restore its old state
if you cancel the operation or of something goes wrong.
************
* KEYBOARD *
************
To enter a character to the emulator use the PC keyboard (key translation
depends on the used KML script) or the mouse. If you press the left mouse
button, the emulator key is pressed as long as you press the mouse button or
leaving the area of the emulator button. Sometimes you need to press more then
one key (contrast setting, warmstart, ...). To do this, press the right mouse
button. All "locked" buttons are released after enter a key with the left mouse
button.
*********
* CLOCK *
*********
The emulator time is synchronized with the PC time at startup of the emulator.
This may cause problems with other non original operating systems running on the
HP. On HP48 S(X) calculators the address area #00052-#00070, on all other
emulated calculators the address area #00058-#00076 in System RAM are rewritten
with the actual time information.
*************
* EMU48.INI *
*************
The section [Timers] in the Emu48.ini file isn't used any more. The variable
values are replaced by useful constants. You may delete this section if you
want. Starting an old version of Emu48 (V1.07 and earlier) will add this section
again. If you move the Emu48 directory to another place, you have to adjust the
variable 'Emu48Directory' in the [Files] section.
************************
* REAL SPEED EMULATION *
************************
As you recognized the speed of the emulated HP is much faster than an original
one. The reason is, the assembler commands are emulated faster than the original
CPU can execute them. On one side this is a big advantage (faster execution of
programs) on the other side this cause many trouble. In Emu48 only the timers
work with the original speed. In result all commands like User-RPL WAIT wait
more or less the correct time. But many programs like shells or editors use an
own key handler to realize an autorepeat implementation. Normally these programs
use the execution time of each assembler command for waiting. On Emu48 this time
is much shorter, so the time between each key read is shorter as well and you
get a very fast key repetition. The editor ED from the JAZZ package hasn't this
problem, because the key input is synchronized with one of the timers. To solve
this problem Emu48 generally slow down emulation if a key is pressed. To solve
some other speed depending problems you are able to slow down the whole
emulation speed. There are two variables 'SXCycles=82' and 'GXCycles=123'
defined in the Emu48.ini file, section [Emulator] which control the "real" speed
and key repetition slow down for each calculator type. Each numeric value is
representing the allowed CPU cycles in a 16384Hz time frame. Because the used
cycle statements (from SASM.DOC) in Emu48 doesn't correspond to the real values
of the CPU, the saved values are estimated by comparing the execution time of a
program to the real calculator. Increasing the value fitting to your ROM will
make the "real speed" HP faster and vice versa. No warranty to the functionality
of Emu48 when you go below the default values.
*************************
* SERIAL PORT EMULATION *
*************************
The serial ports are emulated as well now. You may choose the same serial port
for wire and IR. Remember that the IR port only work with 2400 Baud. If you want
to change the serial port settings, but they are disabled, close the serial port
with the command CLOSEIO or power cycle the HP first.
Now it's possible to make transfers between the real calculator and Emu48. If
you have problems with the connection please try the following. There's a simple
way to check if your serial port is used by another program. First disable the
serial settings in both combo boxes and very important close the settings
dialog. Reopen the settings dialog and choose the COM port in the wire combo box
to the port the HP is connected with. When you open this combo box you only see
valid (unused) serial ports. Don't use the IR combo box, it only works with 2400
Baud. The next important thing are the serial settings of the real calculator
and Emu48, they must be equal. If this doesn't work then mostly there's a
hardware or a resource problem of the serial port. Check this with connecting
the HP with a transfer program you like on the same serial port.
****************
* DISASSEMBLER *
****************
With the internal disassembler you're able to disassemble the Saturn chip
address area. With the default Map setting the disassembler always see the
mapped memory address. If for example you configured the RAM at #00000 you will
see the RAM and not the ROM at this address. With the other module settings you
specify a special module for disassembly. Each module use a linear address mode,
beginning at address #00000 and will not overlapped by other modules. So, for
example, you can access the second port of a HP48 RAM card greater than 128KB at
address #40000 (128 * 1024 * 2). The "Copy Data" button copies the selected
disassembler lines to the PC clipboard.
**************
* DDE SERVER *
**************
I implemented a DDE server in Emu48 to transmit data from and to the HP stack
with DDE. You have the same restrictions like with the commands "Load object..."
and "Save Object...", that a running program may corrupt memory. Take care to
transmit data only after the acknowledge of the last DDE transaction.
Technical data:
Servername: Emu48
Topicname: Stack
Item: - (ignored, must be a nonzero string)
Clipboardformat: "CF_HPOBJ" (user defined)
The DDE commands CONNECT, POKE and REQUEST are supported.
The structure of the clipboard format "CF_HPOBJ":
+--------+------------------------------------+
| 4 Byte | HP object |
+--------+------------------------------------+
\ \
\ +--- normal HP object
+----------- length of object (LSB first)
********************
* TROUBLE SHOOTING *
********************
Visit the Emu48 FAQ site at http://privat.swol.de/ChristophGiesselink/index.htm
to get more information please.
***********
* SUPPORT *
***********
We cannot provide any individual support for Emu48. All informations about Emu48
will be on the Emu48 Official Homepage on the Web:
http://www.epita.fr/~sebc/Emu48/index.html
or on the Emu48 FAQ at
http://privat.swol.de/ChristophGiesselink/index.htm
***************
* LEGAL STUFF *
***************
Emu48 - An HP38/39/40/48/49 Emulator
Copyright (C) 2005 Sebastien Carlier & Christoph Gießelink
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
***************
* The Authors *
***************
Paper Mail:
Sebastien Carlier
10 Allee des bergeronnettes
35340 LIFFRE
FRANCE
E-Mail:
sebc@epita.fr
Homepage:
http://www.epita.fr/~sebc/Emu48/index.html
Paper Mail:
Christoph Giesselink
GERMANY
E-Mail:
c dot giesselink at gmx dot de
Homepage:
http://privat.swol.de/ChristophGiesselink/index.htm

29
EMU48PLUS.TXT Normal file
View file

@ -0,0 +1,29 @@
Emu48 1.42+
Emu48+ is a modified version of Emu48 to add support for the ARM-based
calculators. It does not emulate the ARM CPU, but it enhances the
Saturn emulation to more closely match the emulation provided by the
Saturn emulator on the ARM-based calculators.
Emu48+ adds support for many of the Saturn+ instructions, including
some of the BUSCC instructions, and it also adds support for the 80-line
display used on the 49G+ and 50G.
At present, the additional calculators supported in Emu48+ are the
49G+, 48GII (hardware revision 1), 50G, and 39G+.
To create KML scripts for the additional calculator models, use the
following model codes:
39G+: Model "P"
49G+: Model "Q"
48GII: Model "2"
50G: Model "Q"
Class 50
Most of the code that was changed in Emu48+ over Emu48 was provided by
Cyrille de Brebisson of Hewlett-Packard.

56
PROBLEMS.TXT Normal file
View file

@ -0,0 +1,56 @@
Known bugs and restrictions of Emu48 V1.42
------------------------------------------
- the following I/O bits aren't emulated (incomplete)
DTEST (0x102) [VDIG LID TRIM]
DSPCTL (0x103) [LRT LRTD LRTC BIN]
LPD (0x108) [LB2 LB1 LB0 VLBI]
LPE (0x109) [ELBI EVLBI GRST RST]
CMODE (0x10A) Mode register
IOC (0x110) [ERBZ]
RCS (0x111) [RX RER RBZ]
SRQ1 (0x118) [ISQR VSRQ]
SRQ2 (0x119) [LSRQ]
IRC (0x11A) [IRI EIRU EIRI IRE]
LCR (0x11C) [LED ELBE LBZ LBF]
LBR (0x11D) [LBO]
- the baudrates 1920, 3840, 7680 and 15360 aren't emulated on most
operating systems
Windows 95a 1920, 3840, 7680 work, 15360 fail
Windows 98, NT4.0, 2000, XP all baudrates fail
- problems when receiving a break signal on the serial port
Windows 98, NT4.0 SP4 no retrigger on port open
Windows 98 timing problems setting the RER bit
Windows 2000 SP2 no known problems
- System-RPL commands VERYVERYSLOW, VERYSLOW and SLOW depends on PC
speed (are realized as simple down counter in ROM)
- display updating differs from the real machine
- screen VBL counter values may skip after large display operations
like turning on or updating the whole display
- executing an opcode over a MMU boundary will fail
- read on an unconfigured address (open data bus) will not show the
same value like a real calculator
- the Yorke hardware signals BEN and DA19 aren't fully supported,
because the emulator don't use a multiplexed AR18 / NCE3 data line
-> all programs that run on a real calculator will run as well,
programs with incorrect DA19 / BEN handling may run on the
emulator but will crash on a real calculator
- incomplete reset logic of the bank switcher FF, on real
calculators a reset happen after about 4s in deep sleep, in the
emulator this happens immediately
- no MP interrupt on card control circuit or timer restart
- no beeper support with OUT command -> all programs that aren't
use the "=makebeep" subroutine, like alarm wake up, have no sound
- beeper emulation, ATTN key doesn't work
- no infrared printer support
- Shell OS: clock isn't synchronized with real time
- HP49G: the flash memory is emulated now with some restrictions
- no flash programming times, the flash state machine returns
immediately the ready signal
- only one write buffer, second not needed because of prior reason
- not fully tested, especially the status byte may return
incorrect values (error bits)
- quitting the emulator while programming the flash isn't allowed,
because the content of flash state machine isn't saved so far
08/22/06 (c) by Christoph Gießelink, c dot giesselink at gmx dot de

239
SOURCE/APPLE.C Normal file
View file

@ -0,0 +1,239 @@
/*
* apple.c
*
* This file is part of Emu48
*
* Copyright (C) 2005 CdB for HP
* Copyright (C) 2006 Christoph Gießelink
*
*/
#include "pch.h"
#include "Emu48.h"
#include "Opcodes.h"
#include "apple.h"
#include "io.h" // I/O register definitions
#include "i28f160.h"
#define w Chipset
#define _KB(s) ((s) * 1024 * 2)
#pragma intrinsic(memset,memcpy)
#include "Ops.h"
static QWORD DecodeReg64(LPBYTE R, BYTE byNF)
{
QWORD qwVal = Npack64(R,16); // generate 64bit number from register
switch (byNF) // field selector
{
case 0: return (qwVal >> (w.P*4)) & 0xf; // P
case 1: return qwVal & ~((QWORD)~0 << ((w.P+1)*4));// WP
case 2: return (qwVal >> 8) & 0xf; // XS
case 3: return qwVal & 0xfff; // X
case 4: return (qwVal >> 60) & 0xf; // S
case 5: return (qwVal >> 12) & 0x0000ffffffffffff; // M
case 6: return qwVal & 0xff; // B
case 7: return qwVal; // W
case 15: return qwVal & 0xfffff; // A
// default: return qwVal & w.fld[I[6]-8]; // F1-F7
default: return qwVal;
}
}
static QWORD o80BReg164(LPBYTE I)
{
switch (I[5] & 3)
{
case 0: return DecodeReg64(w.A, I[6]);
case 1: return DecodeReg64(w.B, I[6]);
case 2: return DecodeReg64(w.C, I[6]);
case 3: return DecodeReg64(w.D, I[6]);
default: return 0;
}
}
static QWORD o80BReg264(LPBYTE I)
{
switch ((I[5]>>2) & 3)
{
case 0: return DecodeReg64(w.A, I[6]);
case 1: return DecodeReg64(w.B, I[6]);
case 2: return DecodeReg64(w.C, I[6]);
case 3: return DecodeReg64(w.D, I[6]);
default: return 0;
}
}
static void EncodeReg64(QWORD v, LPBYTE R, BYTE byNF)
{
if (byNF > 7 && byNF < 15) // user mask area F1-F7
byNF = 7; // use W area
Nunpack64(R+F_s[byNF], v, F_l[byNF]);
return;
}
static void o80BRegWrite(QWORD v, LPBYTE I)
{
switch (I[5] & 3)
{
case 0: EncodeReg64(v, w.A, I[6]); break;
case 1: EncodeReg64(v, w.B, I[6]); break;
case 2: EncodeReg64(v, w.C, I[6]); break;
case 3: EncodeReg64(v, w.D, I[6]); break;
}
}
// setup basic memory configuration
static VOID o80B04(VOID)
{
DWORD a;
a = Npack(w.C,5); // save C[A]
Reset(); // unconfig all devices
Nunpack(w.C,0x100,5); // IO: 0x00100
Config(); // addr
Nunpack(w.C,0x80000,5); // RAM: 0x80000 size 256KB
Config(); // size
Config(); // addr
Nunpack(w.C,a,5); // restore C[A]
w.P = 0;
PCHANGED;
return;
}
// erase flash bank
static VOID o80B14(VOID)
{
DWORD dwStart,dwStop;
BYTE byBank = w.C[15]; // C[S] = bank to erase
_ASSERT(FALSE); // not tested so far
// ROM is logically organized in 16 banks with 128KB
dwStart = byBank * _KB(128); // start address
dwStop = dwStart + _KB(128); // last address
if (byBank == 0) dwStart += _KB(64); // skip boot loader
// clear bank
FillMemory(&pbyRom[dwStart],dwStop-dwStart,0x0F);
w.carry = FALSE; // no error
return;
}
// write bytes to flash
static VOID o80B24(VOID)
{
DWORD dwNib,dwAddr,dwSize;
dwNib = Npack(w.C,5) * 2; // no. of nibbles to copy
dwAddr = FlashROMAddr(w.d1); // linear addr in flash chip
dwSize = dwRomSize - dwAddr; // remaining memory size in flash
if (dwNib > dwSize) dwNib = dwSize; // prevent buffer overflow
Npeek(pbyRom+dwAddr,w.d0,dwNib); // copy data
w.d0 += dwNib; // update source register
w.d1 += dwNib; // update destination register
w.carry = FALSE; // no error
return;
}
// CdB for HP: add apples BUSCC commands
VOID o80BExt(LPBYTE I) // Saturnator extentions
{
DWORD a;
w.pc+=2;
switch (I[3]+(I[4]<<4))
{
case 0x00: break; // RPL2 not implemented
case 0x05: External(&w); PCHANGED; break; // BEEP2 implemented using Emu48's beep
case 0x06: break; // MOVEDN not implemented
case 0x07: break; // MOVEUP not implemented
case 0x08: break; // CRTEMP not implemented
case 0x0A: break; // KEYDN not implemented
case 0x0B: break; // no doslow implemented
case 0x10: // simulate off function
{
BOOL bShutdn = TRUE; // shut down
// only shut down when no timer wake up
if (w.IORam[TIMER1_CTRL]&WKE) // WKE bit of timer1 is set
{
if (ReadT1()&0x08) // and MSB of timer1 is set
{
w.IORam[TIMER1_CTRL] &= ~WKE; // clear WKE
bShutdn = FALSE; // don't shut down
}
}
if (w.IORam[TIMER2_CTRL]&WKE) // WKE bit of timer2 is set
{
if (ReadT2()&0x80000000) // and MSB of timer2 is set
{
w.IORam[TIMER2_CTRL] &= ~WKE; // clear WKE
bShutdn = FALSE; // don't shut down
}
}
if (w.in==0 && bShutdn) // shut down only when enabled
{
w.Shutdn = TRUE; // set mode before exit emulation loop
bInterrupt = TRUE;
}
}
break;
case 0x11: w.pc+=2; break; // do not do gettime, just skip the RTN after it to fall in the normal gettime function (only valid in untouched ROM)
case 0x12: break; // do not do settime, fall in the normal settime function (only valid in untouched ROM)
case 0x13: break; // RESETOS not implemented
case 0x14: break; // AUTOTEST not implemented
case 0x15: break; // NATIVE? not implemented
case 0x17: break; // SERIAL not implemented
case 0x28: w.HST |= I[5]; w.pc+=1; break; // HST=1.x
case 0x29: w.A[4]= w.A[3]= w.A[2]= w.A[0]= 0; if (cCurrentRomType=='Q') w.A[1]=5; else w.A[1]=4; break; // screen height = 0x50 = 80
case 0x2A: w.A[4]= w.A[3]= w.A[2]= 0; w.A[1]=8; w.A[0]=3; break; // screen width = 0x83 = 131
case 0x2B: w.carry = (cCurrentRomType == '2'); break; // it is medium apple
case 0x2C: w.carry = (cCurrentRomType == 'Q'); break; // it is big apple
case 0x2E: w.carry = (nCurrentClass == 50); break; // it is big apple V2
case 0x30: w.d0address= Npack(w.C,5)>>12; Map(0,0xff); break; //config_disp0 Ca:address 4K data
case 0x31: w.d0address=0; Map(0,0xff); RefreshDisp0(); break; //unconfig_disp0 does the refresh
case 0x32: RefreshDisp0(); break; //refresh_disp0 force refresh
case 0x33: a= Npack(w.C,2); if (a>(DWORD)SCREENHEIGHT) a= SCREENHEIGHT; /* w.lcounter = (SCREENHEIGHT-a) */; w.d0size= a; RefreshDisp0(); break; //set_lines_disp0 nb in Cb
case 0x34: w.d0offset= Npack(w.C,5); w.d0offset &= 0x7FF; break; //set_offset_disp0 offset to disp in disp0
case 0x35: Nunpack(w.C,w.d0offset,5); break; // native_get_line_disp0
case 0x38: w.HST |= I[5]; w.pc+=3; break; // ?HST=1.x not implemented
case 0x40: o80B04(); break; // setup basic memory configuration
// case 0x41: o80B14(); break; // erase flash bank
case 0x42: o80B24(); break; // write bytes into flash
// case 0x43: ??? // format flash bank
case 0x50: break; // REMON not implemented
case 0x51: break; // REMOFF not implemented
case 0x56: break; // OUTBYT not implemented
case 0x57: w.D[0]= w.D[1]= 0; break;
case 0x60: break; // ACCESSSD not implemented
case 0x61: break; // PORTTAG? not implemented
case 0x64: w.carry= FALSE; break; // no SD card inserted
case 0x66: w.carry= FALSE; break; // simulate format fail card inserted
case 0x7F: w.pc+=1; break; // SETFLDn not implemented
case 0x80: { QWORD b = o80BReg264(I); o80BRegWrite(b, I); w.pc+=2; break; } // R=R=R
case 0x81: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a+b, I); w.pc+=2; break; } // R=R+R
case 0x82: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a-b, I); w.pc+=2; break; } // R=R-R
case 0x83: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a*b, I); w.pc+=2; break; } // R=R*R
case 0x84: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a/b, I); w.pc+=2; break; } // R=R/R
case 0x85: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a%b, I); w.pc+=2; break; } // R=R%R
case 0x86: { QWORD b = o80BReg264(I); o80BRegWrite(~b, I); w.pc+=2; break; } // R=-R-1
case 0x87: { QWORD b = o80BReg264(I); o80BRegWrite((QWORD)(-(__int64)b), I); w.pc+=2; break; } // R=-R
case 0x88: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a<<b, I); w.pc+=2; break; } // R=R<R
case 0x89: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a>>b, I); w.pc+=2; break; } // R=R>R
case 0x8A: { QWORD a = o80BReg164(I); QWORD b = o80BReg264(I); o80BRegWrite(a^b, I); w.pc+=2; break; } // R=R^R
case 0x90: w.pc+=2; break; // do not do RCKBp, just skip the RTN after it to fall in the normal function (only valid in untouched ROM)
case 0xEE: break; // ARMFLUSH not implemented
case 0xEF: break; // ARMSYS not implemented
case 0xFF: break; // ARMSAT not implemented
default: w.pc-= 2;
}
return;
}

10
SOURCE/APPLE.H Normal file
View file

@ -0,0 +1,10 @@
/*
* apple.h
*
* This file is part of Emu48
*
* Copyright (C) 2006 Christoph Gießelink
*
*/
extern VOID o80BExt(LPBYTE I); // Saturnator extentions

3265
SOURCE/CHANGES.TXT Normal file

File diff suppressed because it is too large Load diff

BIN
SOURCE/CHECKBOX.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

27
SOURCE/COLOR.H Normal file
View file

@ -0,0 +1,27 @@
/*
* color.h
*
* This file is part of Emu48
*
* Copyright (C) 1999 Christoph Gießelink
*
*/
#define COLOR_BLACK 0x00000000
#define COLOR_MAROON 0x00000080
#define COLOR_GREEN 0x00008000
#define COLOR_OLIVE 0x00008080
#define COLOR_NAVY 0x00800000
#define COLOR_PURPLE 0x00800080
#define COLOR_TEAL 0x00808000
#define COLOR_GRAY 0x00808080
#define COLOR_SILVER 0x00C0C0C0
#define COLOR_RED 0x000000FF
#define COLOR_LIME 0x0000FF00
#define COLOR_YELLOW 0x0000FFFF
#define COLOR_BLUE 0x00FF0000
#define COLOR_FUCHSIA 0x00FF00FF
#define COLOR_AQUA 0x00FFFF00
#define COLOR_LTGRAY 0x00C0C0C0
#define COLOR_DKGRAY 0x00808080
#define COLOR_WHITE 0x00FFFFFF

89
SOURCE/CURSOR.C Normal file
View file

@ -0,0 +1,89 @@
/*
* Cursor.c
*
* This file is part of Emu48
*
* Copyright (C) 2004 Christoph Gießelink
*
*/
#include "pch.h"
#include "Emu48.h"
// hand cursor AND mask
static CONST BYTE ANDmaskCursor[] =
{
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xF3, 0xFF, 0xFF, // 1111 1111 1111 0011 1111 1111 1111 1111
0xFF, 0xE1, 0xFF, 0xFF, // 1111 1111 1110 0001 1111 1111 1111 1111
0xFF, 0xE1, 0xFF, 0xFF, // 1111 1111 1110 0001 1111 1111 1111 1111
0xFF, 0xE1, 0xFF, 0xFF, // 1111 1111 1110 0001 1111 1111 1111 1111
0xFF, 0xE1, 0xFF, 0xFF, // 1111 1111 1110 0001 1111 1111 1111 1111
0xFF, 0xE0, 0x7F, 0xFF, // 1111 1111 1110 0000 0111 1111 1111 1111
0xFF, 0xE0, 0x0F, 0xFF, // 1111 1111 1110 0000 0000 1111 1111 1111
0xFF, 0xE0, 0x03, 0xFF, // 1111 1111 1110 0000 0000 0011 1111 1111
0xFF, 0xE0, 0x01, 0xFF, // 1111 1111 1110 0000 0000 0001 1111 1111
0xFE, 0x20, 0x00, 0xFF, // 1111 1110 0010 0000 0000 0000 1111 1111
0xFE, 0x00, 0x00, 0xFF, // 1111 1110 0000 0000 0000 0000 1111 1111
0xFE, 0x00, 0x00, 0xFF, // 1111 1110 0000 0000 0000 0000 1111 1111
0xFF, 0x00, 0x00, 0xFF, // 1111 1111 0000 0000 0000 0000 1111 1111
0xFF, 0x80, 0x00, 0xFF, // 1111 1111 1000 0000 0000 0000 1111 1111
0xFF, 0x80, 0x00, 0xFF, // 1111 1111 1000 0000 0000 0000 1111 1111
0xFF, 0xC0, 0x00, 0xFF, // 1111 1111 1100 0000 0000 0000 1111 1111
0xFF, 0xC0, 0x01, 0xFF, // 1111 1111 1100 0000 0000 0001 1111 1111
0xFF, 0xE0, 0x01, 0xFF, // 1111 1111 1110 0000 0000 0001 1111 1111
0xFF, 0xE0, 0x01, 0xFF, // 1111 1111 1110 0000 0000 0001 1111 1111
0xFF, 0xF0, 0x03, 0xFF, // 1111 1111 1111 0000 0000 0011 1111 1111
0xFF, 0xF0, 0x03, 0xFF, // 1111 1111 1111 0000 0000 0011 1111 1111
0xFF, 0xF0, 0x03, 0xFF, // 1111 1111 1111 0000 0000 0011 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF, // 1111 1111 1111 1111 1111 1111 1111 1111
0xFF, 0xFF, 0xFF, 0xFF // 1111 1111 1111 1111 1111 1111 1111 1111
};
// hand cursor XOR mask
static CONST BYTE XORmaskCursor[] =
{
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x0C, 0x00, 0x00, // 0000 0000 0000 1100 0000 0000 0000 0000
0x00, 0x0C, 0x00, 0x00, // 0000 0000 0000 1100 0000 0000 0000 0000
0x00, 0x0C, 0x00, 0x00, // 0000 0000 0000 1100 0000 0000 0000 0000
0x00, 0x0C, 0x00, 0x00, // 0000 0000 0000 1100 0000 0000 0000 0000
0x00, 0x0C, 0x00, 0x00, // 0000 0000 0000 1100 0000 0000 0000 0000
0x00, 0x0D, 0x80, 0x00, // 0000 0000 0000 1101 1000 0000 0000 0000
0x00, 0x0D, 0xB0, 0x00, // 0000 0000 0000 1101 1011 0000 0000 0000
0x00, 0x0D, 0xB4, 0x00, // 0000 0000 0000 1101 1011 0100 0000 0000
0x00, 0x0D, 0xB6, 0x00, // 0000 0000 0000 1101 1011 0110 0000 0000
0x00, 0xCF, 0xF6, 0x00, // 0000 0000 1100 1111 1111 0110 0000 0000
0x00, 0xEF, 0xFE, 0x00, // 0000 0000 1110 1111 1111 1110 0000 0000
0x00, 0x6F, 0xFE, 0x00, // 0000 0000 0110 1111 1111 1110 0000 0000
0x00, 0x2F, 0xFE, 0x00, // 0000 0000 0010 1111 1111 1110 0000 0000
0x00, 0x3F, 0xFE, 0x00, // 0000 0000 0011 1111 1111 1110 0000 0000
0x00, 0x1F, 0xFE, 0x00, // 0000 0000 0001 1111 1111 1110 0000 0000
0x00, 0x1F, 0xFC, 0x00, // 0000 0000 0001 1111 1111 1100 0000 0000
0x00, 0x0F, 0xFC, 0x00, // 0000 0000 0000 1111 1111 1100 0000 0000
0x00, 0x0F, 0xFC, 0x00, // 0000 0000 0000 1111 1111 1100 0000 0000
0x00, 0x07, 0xF8, 0x00, // 0000 0000 0000 0111 1111 1000 0000 0000
0x00, 0x07, 0xF8, 0x00, // 0000 0000 0000 0111 1111 1000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00, // 0000 0000 0000 0000 0000 0000 0000 0000
0x00, 0x00, 0x00, 0x00 // 0000 0000 0000 0000 0000 0000 0000 0000
};
HCURSOR CreateHandCursor(VOID)
{
return CreateCursor(hApp,12,5,32,32,ANDmaskCursor,XORmaskCursor);
}

BIN
SOURCE/DBGTOOL.BMP Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

169
SOURCE/DDESERV.C Normal file
View file

@ -0,0 +1,169 @@
/*
* DdeServ.c
*
* This file is part of Emu48
*
* Copyright (C) 1998 Christoph Gießelink
*
*/
#include "pch.h"
#include "Emu48.h"
#include "io.h"
HDDEDATA CALLBACK DdeCallback(UINT iType,UINT iFmt,HCONV hConv,
HSZ hsz1,HSZ hsz2,HDDEDATA hData,
DWORD dwData1,DWORD dwData2)
{
TCHAR *psz,szBuffer[32];
HDDEDATA hReturn;
LPBYTE lpData,lpHeader;
DWORD dwAddress,dwSize,dwLoop,dwIndex;
UINT nStkLvl;
BOOL bSuccess;
// disable stack loading items on HP38G, HP39/40G
BOOL bStackEnable = cCurrentRomType!='6' && cCurrentRomType!='A' && cCurrentRomType!='E' && cCurrentRomType!='P'; // CdB for HP: add P type
switch (iType)
{
case XTYP_CONNECT:
// get service name
DdeQueryString(idDdeInst,hsz2,szBuffer,ARRAYSIZEOF(szBuffer),0);
if (0 != lstrcmp(szBuffer,szAppName))
return (HDDEDATA) FALSE;
// get topic name
DdeQueryString(idDdeInst,hsz1,szBuffer,ARRAYSIZEOF(szBuffer),0);
return (HDDEDATA) (INT_PTR) (0 == lstrcmp(szBuffer,szTopic));
case XTYP_POKE:
// quit on models without stack or illegal data format or not in running state
if (!bStackEnable || iFmt != uCF_HpObj || nState != SM_RUN)
return (HDDEDATA) DDE_FNOTPROCESSED;
// get item name
DdeQueryString(idDdeInst,hsz2,szBuffer,ARRAYSIZEOF(szBuffer),0);
nStkLvl = _tcstoul(szBuffer,&psz,10);
if (*psz != 0 || nStkLvl < 1) // invalid number format
return (HDDEDATA) DDE_FNOTPROCESSED;
DdeAccessData(hData,&dwSize); // fetch data size
DdeUnaccessData(hData);
// reserve memory
if ((lpData = HeapAlloc(hHeap,0,dwSize * 2)) == NULL)
return (HDDEDATA) DDE_FNOTPROCESSED;
SuspendDebugger(); // suspend debugger
bDbgAutoStateCtrl = FALSE; // disable automatic debugger state control
if (!(Chipset.IORam[BITOFFSET]&DON)) // HP off
{
// turn on HP
KeyboardEvent(TRUE,0,0x8000);
KeyboardEvent(FALSE,0,0x8000);
}
if (WaitForSleepState()) // wait for cpu SHUTDN then sleep state
{
HeapFree(hHeap,0,lpData); // free memory
hReturn = DDE_FNOTPROCESSED;
goto cancel;
}
while (nState!=nNextState) Sleep(0);
_ASSERT(nState==SM_SLEEP);
// fetch data and write to stack
DdeGetData(hData,(LPBYTE) &dwIndex,sizeof(DWORD),0L);
if (dwIndex <= dwSize - sizeof(DWORD))
dwSize = dwIndex;
dwSize = DdeGetData(hData,lpData+dwSize,dwSize,sizeof(DWORD));
bSuccess = (WriteStack(nStkLvl,lpData,dwSize) == S_ERR_NO);
HeapFree(hHeap,0,lpData); // free memory
SwitchToState(SM_RUN); // run state
while (nState!=nNextState) Sleep(0);
_ASSERT(nState==SM_RUN);
if (bSuccess == FALSE)
{
hReturn = DDE_FNOTPROCESSED;
goto cancel;
}
KeyboardEvent(TRUE,0,0x8000);
KeyboardEvent(FALSE,0,0x8000);
// wait for sleep mode
while(Chipset.Shutdn == FALSE) Sleep(0);
hReturn = (HDDEDATA) DDE_FACK;
cancel:
bDbgAutoStateCtrl = TRUE; // enable automatic debugger state control
ResumeDebugger();
return hReturn;
case XTYP_REQUEST:
// quit on models without stack or illegal data format or not in running state
if (!bStackEnable || iFmt != uCF_HpObj || nState != SM_RUN)
return NULL;
// get item name
DdeQueryString(idDdeInst,hsz2,szBuffer,ARRAYSIZEOF(szBuffer),0);
nStkLvl = _tcstoul(szBuffer,&psz,10);
if (*psz != 0 || nStkLvl < 1) // invalid number format
return NULL;
if (WaitForSleepState()) // wait for cpu SHUTDN then sleep state
return NULL;
while (nState!=nNextState) Sleep(0);
_ASSERT(nState==SM_SLEEP);
dwAddress = RPL_Pick(nStkLvl); // pick address of stack level "item" object
if (dwAddress == 0)
{
SwitchToState(SM_RUN); // run state
return NULL;
}
dwLoop = dwSize = (RPL_SkipOb(dwAddress) - dwAddress + 1) / 2;
lpHeader = (Chipset.type == 'X' || Chipset.type == 'Q' || Chipset.type == '2') ? BINARYHEADER49 : BINARYHEADER48;
// length of binary header
dwIndex = (DWORD) strlen(lpHeader);
// size of objectsize + header + object
dwSize += dwIndex + sizeof(DWORD);
// reserve memory
if ((lpData = HeapAlloc(hHeap,0,dwSize)) == NULL)
{
SwitchToState(SM_RUN); // run state
return NULL;
}
// save data length
*(DWORD *)lpData = dwLoop + dwIndex;
// copy header
memcpy(lpData + sizeof(DWORD),lpHeader,dwIndex);
// copy data
for (dwIndex += sizeof(DWORD);dwLoop--;++dwIndex,dwAddress += 2)
lpData[dwIndex] = Read2(dwAddress);
// write data
hReturn = DdeCreateDataHandle(idDdeInst,lpData,dwSize,0,hsz2,iFmt,0);
HeapFree(hHeap,0,lpData);
SwitchToState(SM_RUN); // run state
while (nState!=nNextState) Sleep(0);
_ASSERT(nState==SM_RUN);
return hReturn;
}
return NULL;
UNREFERENCED_PARAMETER(hConv);
UNREFERENCED_PARAMETER(dwData1);
UNREFERENCED_PARAMETER(dwData2);
}

1082
SOURCE/DEBUGDLL.C Normal file

File diff suppressed because it is too large Load diff

2927
SOURCE/DEBUGGER.C Normal file

File diff suppressed because it is too large Load diff

37
SOURCE/DEBUGGER.H Normal file
View file

@ -0,0 +1,37 @@
/*
* debugger.h
*
* This file is part of Emu48
*
* Copyright (C) 1999 Christoph Gießelink
*
*/
// breakpoint type definitions
#define BP_EXEC 0x01 // code breakpoint
#define BP_READ 0x02 // read memory breakpoint
#define BP_WRITE 0x04 // write memory breakpoint
#define BP_RPL 0x08 // RPL breakpoint
#define BP_ACCESS (BP_READ|BP_WRITE) // read/write memory breakpoint
// breakpoint notify definitions
#define BN_ASM 0 // ASM breakpoint
#define BN_RPL 1 // RPL breakpoint
#define BN_ASM_BT 2 // ASM and RPL breakpoint
// debugger state definitions
#define DBG_SUSPEND -1
#define DBG_OFF 0
#define DBG_RUN 1
#define DBG_STEPINTO 2
#define DBG_STEPOVER 3
#define DBG_STEPOUT 4
// debugger.c
extern VOID UpdateDbgCycleCounter(VOID);
extern BOOL CheckBreakpoint(DWORD dwAddr, DWORD wRange, UINT nType);
extern VOID NotifyDebugger(INT nType);
extern VOID DisableDebugger(VOID);
extern LRESULT OnToolDebug(VOID);
extern VOID LoadBreakpointList(HANDLE hFile);
extern VOID SaveBreakpointList(HANDLE hFile);

1937
SOURCE/DISASM.C Normal file

File diff suppressed because it is too large Load diff

674
SOURCE/DISPLAY.C Normal file
View file

@ -0,0 +1,674 @@
/*
* display.c
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
* Copyright (C) 2002 Christoph Gießelink
*
*/
#include "pch.h"
#include "resource.h"
#include "Emu48.h"
#include "io.h"
#include "kml.h"
// #define DEBUG_DISPLAY // switch for DISPLAY debug purpose
#define NOCOLORSGRAY 8
#define NOCOLORSBW 2
#define B 0x00000000 // black
#define W 0x00FFFFFF // white
#define I 0xFFFFFFFF // ignore
#define LCD_ROW (36*4) // max. pixel per line
#define GRAYMASK(c) (((((c)-1)>>1)<<24) \
|((((c)-1)>>1)<<16) \
|((((c)-1)>>1)<<8) \
|((((c)-1)>>1)))
#define DIBPIXEL(d,p) *(((DWORD*)(d))++) = ((*((DWORD*)(d)) & dwGrayMask) << 1) | (p)
BOOL bGrayscale = FALSE; // Default is to not emulate grayscale
UINT nBackgroundX = 0;
UINT nBackgroundY = 0;
UINT nBackgroundW = 0;
UINT nBackgroundH = 0;
UINT nLcdX = 0;
UINT nLcdY = 0;
UINT nLcdZoom = 1;
LPBYTE pbyLcd;
HDC hLcdDC = NULL;
HDC hMainDC = NULL;
static HBITMAP hLcdBitmap;
static HBITMAP hMainBitmap;
static DWORD Pattern[16];
static BYTE Buf[36];
static DWORD dwGrayMask;
static DWORD dwKMLColor[64] = // color table loaded by KML script
{
W,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,
B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,
I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,
I,I,I,I,I,I,I,I,I,I,I,I,I,I,I,I
};
static struct
{
BITMAPINFOHEADER Lcd_bmih;
RGBQUAD bmiColors[NOCOLORSGRAY];
} bmiLcd =
{
{0x28,0/*x*/,0/*y*/,1,8,BI_RGB,0,0,0,NOCOLORSGRAY,0}
};
static __inline VOID BuildPattern(VOID)
{
WORD i,j;
for (i=0; i<16; ++i)
{
Pattern[i] = 0;
for (j=8; j>0; j>>=1)
{
Pattern[i] = (Pattern[i] << 8) | ((i&j) != 0);
}
}
return;
}
VOID UpdateContrast(BYTE byContrast)
{
RGBQUAD c,b;
INT i,nColors;
// table for max. 8 colors
const INT nCAdj[] = { 0, 1, 1, 2, 1, 2, 2, 3 };
// when display is off use contrast 0
if ((Chipset.IORam[BITOFFSET] & DON) == 0) byContrast = 0;
c = *(RGBQUAD*)&dwKMLColor[byContrast]; // pixel on color
b = *(RGBQUAD*)&dwKMLColor[byContrast+32]; // pixel off color
// if background color is undefined, use color 0 for compatibility
if (I == *(DWORD*)&b) b = *(RGBQUAD*)&dwKMLColor[0];
nColors = bGrayscale ? (NOCOLORSGRAY-1) : (NOCOLORSBW-1);
_ASSERT(nColors <= ARRAYSIZEOF(nCAdj)); // no. of colors must be smaller than entries in the gray color table
// fill color palette of bitmap
for (i = 0; i <= nColors; ++i)
{
bmiLcd.bmiColors[i] = b;
bmiLcd.bmiColors[i].rgbRed += ((INT) c.rgbRed - (INT) b.rgbRed) * nCAdj[i] / nCAdj[nColors];
bmiLcd.bmiColors[i].rgbGreen += ((INT) c.rgbGreen - (INT) b.rgbGreen) * nCAdj[i] / nCAdj[nColors];
bmiLcd.bmiColors[i].rgbBlue += ((INT) c.rgbBlue - (INT) b.rgbBlue) * nCAdj[i] / nCAdj[nColors];
}
// update palette information
_ASSERT(hLcdDC);
SetDIBColorTable(hLcdDC,0,ARRAYSIZEOF(bmiLcd.bmiColors),bmiLcd.bmiColors);
// recalculate update mask for online gray <-> bw switching
dwGrayMask = bGrayscale ? GRAYMASK(NOCOLORSGRAY) : GRAYMASK(NOCOLORSBW);
return;
}
VOID SetLcdColor(UINT nId, UINT nRed, UINT nGreen, UINT nBlue)
{
dwKMLColor[nId&0x3F] = ((nRed&0xFF)<<16)|((nGreen&0xFF)<<8)|(nBlue&0xFF);
return;
}
VOID CreateLcdBitmap(VOID)
{
// create LCD bitmap
bmiLcd.Lcd_bmih.biWidth = LCD_ROW;
bmiLcd.Lcd_bmih.biHeight = -SCREENHEIGHT; // CdB for HP: add 64/80 ligne display for apples
_ASSERT(hLcdDC == NULL);
hLcdDC = CreateCompatibleDC(hWindowDC);
_ASSERT(hLcdDC != NULL);
hLcdBitmap = CreateDIBSection(hWindowDC,(BITMAPINFO*)&bmiLcd,DIB_RGB_COLORS,(VOID **)&pbyLcd,NULL,0);
hLcdBitmap = SelectObject(hLcdDC,hLcdBitmap);
_ASSERT(hPalette != NULL);
SelectPalette(hLcdDC,hPalette,FALSE); // set palette for LCD DC
RealizePalette(hLcdDC); // realize palette
BuildPattern(); // build Nibble -> DIB mask pattern
dwGrayMask = bGrayscale ? GRAYMASK(NOCOLORSGRAY) : GRAYMASK(NOCOLORSBW);
UpdateContrast(Chipset.contrast);
return;
}
VOID DestroyLcdBitmap(VOID)
{
// set contrast palette to startup colors
WORD i = 0; dwKMLColor[i++] = W;
while(i < 32) dwKMLColor[i++] = B;
while(i < 64) dwKMLColor[i++] = I;
if (hLcdDC != NULL)
{
// destroy LCD bitmap
DeleteObject(SelectObject(hLcdDC,hLcdBitmap));
DeleteDC(hLcdDC);
hLcdDC = NULL;
hLcdBitmap = NULL;
}
return;
}
BOOL CreateMainBitmap(LPCTSTR szFilename)
{
HPALETTE hAssertPalette;
_ASSERT(hWindowDC != NULL);
hMainDC = CreateCompatibleDC(hWindowDC);
_ASSERT(hMainDC != NULL);
if (hMainDC == NULL) return FALSE; // quit if failed
hMainBitmap = LoadBitmapFile(szFilename);
if (hMainBitmap == NULL)
{
DeleteDC(hMainDC);
hMainDC = NULL;
return FALSE;
}
hMainBitmap = SelectObject(hMainDC,hMainBitmap);
_ASSERT(hPalette != NULL);
hAssertPalette = SelectPalette(hMainDC,hPalette,FALSE);
_ASSERT(hAssertPalette != NULL);
RealizePalette(hMainDC);
return TRUE;
}
VOID DestroyMainBitmap(VOID)
{
if (hMainDC != NULL)
{
// destroy Main bitmap
DeleteObject(SelectObject(hMainDC,hMainBitmap));
DeleteDC(hMainDC);
hMainDC = NULL;
hMainBitmap = NULL;
}
return;
}
//****************
//*
//* LCD functions
//*
//****************
VOID UpdateDisplayPointers(VOID)
{
EnterCriticalSection(&csLcdLock);
{
#if defined DEBUG_DISPLAY
{
TCHAR buffer[256];
wsprintf(buffer,_T("%.5lx: Update Display Pointer\n"),Chipset.pc);
OutputDebugString(buffer);
}
#endif
// calculate display width
Chipset.width = (34 + Chipset.loffset + (Chipset.boffset / 4) * 2) & 0xFFFFFFFE;
Chipset.end1 = Chipset.start1 + MAINSCREENHEIGHT * Chipset.width;
if (Chipset.end1 < Chipset.start1)
{
// calculate first address of main display
Chipset.start12 = Chipset.end1 - Chipset.width;
// calculate last address of main display
Chipset.end1 = Chipset.start1 - Chipset.width;
}
else
{
Chipset.start12 = Chipset.start1;
}
Chipset.end2 = Chipset.start2 + MENUHEIGHT * 34;
}
LeaveCriticalSection(&csLcdLock);
return;
}
VOID UpdateMainDisplay(VOID)
{
UINT x, y;
DWORD d = Chipset.start1;
BYTE *p = pbyLcd+(Chipset.d0size*LCD_ROW); // CdB for HP: add 64/80 ligne display for apples
#if defined DEBUG_DISPLAY
{
TCHAR buffer[256];
wsprintf(buffer,_T("%.5lx: Update Main Display\n"),Chipset.pc);
OutputDebugString(buffer);
}
#endif
if (!(Chipset.IORam[BITOFFSET]&DON))
{
ZeroMemory(pbyLcd, LCD_ROW * SCREENHEIGHT);
}
else
{
for (y = 0; y < MAINSCREENHEIGHT; ++y)
{
Npeek(Buf,d,36);
for (x=0; x<36; ++x) // every 4 pixel
{
DIBPIXEL(p,Pattern[Buf[x]]);
// check for display buffer overflow
_ASSERT(p <= pbyLcd + LCD_ROW * SCREENHEIGHT);
}
d+=Chipset.width;
}
}
EnterCriticalSection(&csGDILock); // solving NT GDI problems
{
// CdB for HP: add 64/80 ligne display for apples
StretchBlt(hWindowDC,
nLcdX, nLcdY+Chipset.d0size*nLcdZoom,
131*nLcdZoom, MAINSCREENHEIGHT*nLcdZoom,
hLcdDC,
Chipset.boffset, Chipset.d0size,
131, MAINSCREENHEIGHT,
SRCCOPY);
GdiFlush();
}
LeaveCriticalSection(&csGDILock);
return;
}
VOID UpdateMenuDisplay(VOID)
{
UINT x, y;
BYTE *p;
DWORD d = Chipset.start2;
#if defined DEBUG_DISPLAY
{
TCHAR buffer[256];
wsprintf(buffer,_T("%.5lx: Update Menu Display\n"),Chipset.pc);
OutputDebugString(buffer);
}
#endif
if (!(Chipset.IORam[BITOFFSET]&DON)) return;
if (MENUHEIGHT==0) return; // menu disabled
// calculate bitmap offset
p = pbyLcd + ((Chipset.d0size+MAINSCREENHEIGHT)*LCD_ROW); // CdB for HP: add 64/80 ligne display for apples
for (y = 0; y < MENUHEIGHT; ++y)
{
Npeek(Buf,d,34); // 34 nibbles are viewed
for (x=0; x<34; ++x) // every 4 pixel
{
DIBPIXEL(p,Pattern[Buf[x]]);
// check for display buffer overflow
_ASSERT(p <= pbyLcd + LCD_ROW * SCREENHEIGHT);
}
// adjust pointer to 36 DIBPIXEL drawing calls
p += (36-34) * sizeof(DWORD);
d+=34;
}
EnterCriticalSection(&csGDILock); // solving NT GDI problems
{
// CdB for HP: add 64/80 ligne display for apples
StretchBlt(hWindowDC,
nLcdX, nLcdY+(MAINSCREENHEIGHT+Chipset.d0size)*nLcdZoom,
131*nLcdZoom, MENUHEIGHT*nLcdZoom,
hLcdDC,
0, (MAINSCREENHEIGHT+Chipset.d0size),
131, MENUHEIGHT,
SRCCOPY);
GdiFlush();
}
LeaveCriticalSection(&csGDILock);
return;
}
// CdB for HP: add header management
VOID RefreshDisp0()
{
UINT x, y;
BYTE *p;
BYTE* d = Chipset.d0memory;
#if defined DEBUG_DISPLAY
{
TCHAR buffer[256];
wsprintf(buffer,_T("%.5lx: Update header Display\n"),Chipset.pc);
OutputDebugString(buffer);
}
#endif
if (!(Chipset.IORam[BITOFFSET]&DON)) return;
// calculate bitmap offset
p = pbyLcd;
for (y = 0; y<Chipset.d0size; ++y)
{
memcpy(Buf,d,34); // 34 nibbles are viewed
for (x=0; x<36; ++x) // every 4 pixel
{
DIBPIXEL(p,Pattern[Buf[x]]);
}
d+=34;
}
EnterCriticalSection(&csGDILock); // solving NT GDI problems
{
StretchBlt(hWindowDC,
nLcdX, nLcdY,
131*nLcdZoom, Chipset.d0size*nLcdZoom,
hLcdDC,
Chipset.d0offset, 0,
131, Chipset.d0size,
SRCCOPY);
GdiFlush();
}
LeaveCriticalSection(&csGDILock);
return;
}
VOID WriteToMainDisplay(LPBYTE a, DWORD d, UINT s)
{
UINT x0, x;
UINT y0, y;
DWORD *p;
INT lWidth = abs(Chipset.width); // display width
if (bGrayscale)
{
return;
}
#if defined DEBUG_DISPLAY
{
TCHAR buffer[256];
wsprintf(buffer,_T("%.5lx: Write Main Display %x,%u\n"),Chipset.pc,d,s);
OutputDebugString(buffer);
}
#endif
if (!(Chipset.IORam[BITOFFSET]&DON)) return; // display off
if (MAINSCREENHEIGHT == 0) return; // menu disabled
d -= Chipset.start1; // nibble offset to DISPADDR (start of display)
y0 = y = (d / lWidth) + Chipset.d0size; // bitmap row
x0 = x = d % lWidth; // bitmap coloumn
p = (DWORD*)(pbyLcd + y0*LCD_ROW + x0*sizeof(*p));
// outside main display area
// _ASSERT(y0 >= (INT)Chipset.d0size && y0 < (INT)(MAINSCREENHEIGHT+Chipset.d0size));
if (!(y0 >= (INT)Chipset.d0size && y0 < (INT)(MAINSCREENHEIGHT+Chipset.d0size))) return;
while (s--) // loop for nibbles to write
{
if (x<36) // only fill visible area
{
*p = Pattern[*a];
}
a++; // next value to write
x++; // next x position
if (((INT) x==lWidth)&&s) // end of display line
{
x = 0; // first coloumn
y++; // next row
if (y == (INT) MAINSCREENHEIGHT+Chipset.d0size) break;
// recalculate bitmap memory position of new line
p = (DWORD*) (pbyLcd+y*LCD_ROW); // CdB for HP: add 64/80 ligne display for apples
} else p++;
}
if (y==y0) y++;
EnterCriticalSection(&csGDILock); // solving NT GDI problems
{
StretchBlt(hWindowDC,
nLcdX, nLcdY+y0*nLcdZoom,
131*nLcdZoom, (y-y0)*nLcdZoom,
hLcdDC,
Chipset.boffset, y0,
131, y-y0,
SRCCOPY); // CdB for HP: add 64/80 ligne display for apples
GdiFlush();
}
LeaveCriticalSection(&csGDILock);
return;
}
VOID WriteToMenuDisplay(LPBYTE a, DWORD d, UINT s)
{
UINT x0, x;
UINT y0, y;
DWORD *p;
if (bGrayscale)
{
return;
}
#if defined DEBUG_DISPLAY
{
TCHAR buffer[256];
wsprintf(buffer,_T("%.5lx: Write Menu Display %x,%u\n"),Chipset.pc,d,s);
OutputDebugString(buffer);
}
#endif
if (!(Chipset.IORam[BITOFFSET]&DON)) return; // display off
if (MENUHEIGHT == 0) return; // menu disabled
d -= Chipset.start2; // nibble offset to DISPADDR (start of display)
y0 = y = (d / 34) + MAINSCREENHEIGHT+Chipset.d0size; // bitmap row
x0 = x = d % 34; // bitmap coloumn
p = (DWORD*)(pbyLcd + y0*LCD_ROW + x0*sizeof(*p));
// outside menu display area
// _ASSERT(y0 >= (INT)(Chipset.d0size+MAINSCREENHEIGHT) && y0 < (INT)(SCREENHEIGHT));
if (!(y0 >= (UINT)(Chipset.d0size+MAINSCREENHEIGHT) && y0 < (UINT)(SCREENHEIGHT))) return;
while (s--) // loop for nibbles to write
{
if (x<36) // only fill visible area
{
*p = Pattern[*a];
}
a++; // next value to write
x++; // next x position
if ((x==34)&&s) // end of display line
{
x = 0; // first coloumn
y++; // next row
if (y == SCREENHEIGHTREAL) break;
// recalculate bitmap memory position of new line
p=(DWORD*)(pbyLcd+y*LCD_ROW); // CdB for HP: add 64/80 ligne display for apples
} else p++;
}
if (y==y0) y++;
EnterCriticalSection(&csGDILock); // solving NT GDI problems
{
StretchBlt(hWindowDC,
nLcdX, nLcdY+y0*nLcdZoom,
131*nLcdZoom, (y-y0)*nLcdZoom,
hLcdDC,
0, y0,
131, y-y0,
SRCCOPY); // CdB for HP: add 64/80 ligne display for apples
GdiFlush();
}
LeaveCriticalSection(&csGDILock);
return;
}
VOID UpdateAnnunciators(VOID)
{
BYTE c;
c = (BYTE)(Chipset.IORam[ANNCTRL] | (Chipset.IORam[ANNCTRL+1]<<4));
// switch annunciators off if timer stopped
if ((c & AON) == 0 || (Chipset.IORam[TIMER2_CTRL] & RUN) == 0)
c = 0;
DrawAnnunciator(1,c&LA1);
DrawAnnunciator(2,c&LA2);
DrawAnnunciator(3,c&LA3);
DrawAnnunciator(4,c&LA4);
DrawAnnunciator(5,c&LA5);
DrawAnnunciator(6,c&LA6);
return;
}
VOID ResizeWindow(VOID)
{
RECT rectWindow;
RECT rectClient;
if (hWnd == NULL) return; // return if window closed
rectWindow.left = 0;
rectWindow.top = 0;
rectWindow.right = nBackgroundW;
rectWindow.bottom = nBackgroundH;
AdjustWindowRect(&rectWindow, WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED, TRUE);
SetWindowPos (hWnd, (HWND)NULL, 0, 0,
rectWindow.right - rectWindow.left,
rectWindow.bottom - rectWindow.top,
SWP_NOMOVE | SWP_NOZORDER);
GetClientRect(hWnd, &rectClient);
AdjustWindowRect(&rectClient, WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED, TRUE);
if (rectClient.bottom < rectWindow.bottom)
{
rectWindow.bottom += (rectWindow.bottom - rectClient.bottom);
SetWindowPos (hWnd, (HWND)NULL, 0, 0,
rectWindow.right - rectWindow.left,
rectWindow.bottom - rectWindow.top,
SWP_NOMOVE | SWP_NOZORDER);
}
_ASSERT(hWindowDC); // move destination window
SetWindowOrgEx(hWindowDC, nBackgroundX, nBackgroundY, NULL);
InvalidateRect(hWnd,NULL,TRUE);
return;
}
#define DISPLAY_FREQ 19 // display update 1/frequency (1/64) in ms
static LARGE_INTEGER lLcdRef; // reference time for VBL counter
static UINT uLcdTimerId = 0;
static BYTE byVblRef = 0; // VBL stop reference
// LCD line counter calculation
static BYTE F4096Hz(VOID) // get a 6 bit 4096Hz down counter value
{
LARGE_INTEGER lLC;
QueryPerformanceCounter(&lLC); // get counter value
// calculate 4096 Hz frequency down counter value
return -(BYTE)(((lLC.QuadPart - lAppStart.QuadPart) << 12) / lFreq.QuadPart) & 0x3F;
}
static VOID CALLBACK LcdProc(UINT uEventId, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
EnterCriticalSection(&csLcdLock);
{
UpdateMainDisplay(); // update display
UpdateMenuDisplay();
RefreshDisp0(); // CdB for HP: add header management
}
LeaveCriticalSection(&csLcdLock);
QueryPerformanceCounter(&lLcdRef); // actual time
return;
UNREFERENCED_PARAMETER(uEventId);
UNREFERENCED_PARAMETER(uMsg);
UNREFERENCED_PARAMETER(dwUser);
UNREFERENCED_PARAMETER(dw1);
UNREFERENCED_PARAMETER(dw2);
}
// LCD line counter calculation
BYTE GetLineCounter(VOID)
{
LARGE_INTEGER lLC;
BYTE byTime;
if (!bGrayscale)
{
_ASSERT(byVblRef < 0x40);
return (0x40 + F4096Hz() - byVblRef) & 0x3F;
}
if (uLcdTimerId == 0) // display off
return ((Chipset.IORam[LINECOUNT+1] & (LC5|LC4)) << 4) | Chipset.IORam[LINECOUNT];
QueryPerformanceCounter(&lLC); // get elapsed time since display update
// elapsed ticks so far
byTime = (BYTE) (((lLC.QuadPart - lLcdRef.QuadPart) << 12) / lFreq.QuadPart);
if (byTime > 0x3F) byTime = 0x3F; // all counts made
return 0x3F - byTime; // update display between VBL counter 0x3F-0x3E
}
VOID StartDisplay(BYTE byInitial)
{
if (!bGrayscale)
{
// get positive VBL difference between now and stop time
byVblRef = (0x40 + F4096Hz() - byInitial) & 0x3F;
return;
}
if (uLcdTimerId) // LCD update timer running
return; // -> quit
if (Chipset.IORam[BITOFFSET]&DON) // display on?
{
QueryPerformanceCounter(&lLcdRef); // actual time of top line
// adjust startup counter to get the right VBL value
_ASSERT(byInitial <= 0x3F); // line counter value 0 - 63
lLcdRef.QuadPart -= ((LONGLONG) (0x3F - byInitial) * lFreq.QuadPart) >> 12;
uLcdTimerId = timeSetEvent(DISPLAY_FREQ,0,(LPTIMECALLBACK)&LcdProc,0,TIME_PERIODIC);
_ASSERT(uLcdTimerId); // test if display update timer started
}
return;
}
VOID StopDisplay(VOID)
{
BYTE a[2];
ReadIO(a,LINECOUNT,2,TRUE); // update VBL at display off time
if (!bGrayscale)
return;
if (uLcdTimerId == 0) // timer stopped
return; // -> quit
timeKillEvent(uLcdTimerId); // stop display update
uLcdTimerId = 0; // set flag display update stopped
EnterCriticalSection(&csLcdLock); // update to last condition
{
UpdateMainDisplay(); // update display
UpdateMenuDisplay();
RefreshDisp0(); // CdB for HP: add header management
}
LeaveCriticalSection(&csLcdLock);
return;
}

1615
SOURCE/EMU48.C Normal file

File diff suppressed because it is too large Load diff

347
SOURCE/EMU48.H Normal file
View file

@ -0,0 +1,347 @@
/*
* Emu48.h
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#include "types.h"
#define HARDWARE "Yorke" // emulator hardware
#define MODELS "26AEGPQSX" // valid calculator models
#define ARRAYSIZEOF(a) (sizeof(a) / sizeof(a[0]))
// cards status
#define PORT1_PRESENT ((cCurrentRomType=='S')?P1C:P2C)
#define PORT1_WRITE ((cCurrentRomType=='S')?P1W:P2W)
#define PORT2_PRESENT ((cCurrentRomType=='S')?P2C:P1C)
#define PORT2_WRITE ((cCurrentRomType=='S')?P2W:P1W)
#define BINARYHEADER48 "HPHP48-W"
#define BINARYHEADER49 "HPHP49-W"
#define CF_HPOBJ "CF_HPOBJ" // clipboard format for DDE
// CPU cycles in 16384 Hz time frame
#define T2CYCLES ((cCurrentRomType=='S')?dwSXCycles:(cCurrentRomType=='G')?dwGXCycles:(cCurrentRomType=='P')?dwGPCycles:(cCurrentRomType=='Q')?dwGPCycles:dwG2Cycles) // CdB for HP: add apples
#define SM_RUN 0 // states of cpu emulation thread
#define SM_INVALID 1
#define SM_RETURN 2
#define SM_SLEEP 3
#define S_ERR_NO 0 // stack errorcodes
#define S_ERR_BINARY 1
#define S_ERR_ASCII 2
#define NO_SERIAL "disabled" // port not open
#define HP_MNEMONICS FALSE // disassembler mnenomics mode
#define CLASS_MNEMONICS TRUE
#define MEM_MAP 0 // memory module definition
#define MEM_ROM 1
#define MEM_RAM 2
#define MEM_PORT1 3
#define MEM_PORT2 4
#define VIEW_SHORT FALSE // view of disassembler output
#define VIEW_LONG TRUE
#define MACRO_OFF 0 // macro recorder off
#define MACRO_NEW 1
#define MACRO_PLAY 2
#define DISP_POINTER 0x01 // defines for display area
#define DISP_MAIN 0x02
#define DISP_MENUE 0x04
#define DISP_ANNUN 0x08
// macro to check for valid calculator model
#define isModelValid(m) (m != 0 && strchr(MODELS,m) != NULL)
// values for mapping area
enum MMUMAP { M_IO, M_ROM, M_RAM, M_P1, M_P2, M_BS };
// Emu48.c
extern HPALETTE hPalette;
extern HPALETTE hOldPalette;
extern HANDLE hEventShutdn;
extern LPTSTR szAppName;
extern LPTSTR szTopic;
extern LPTSTR szTitle;
extern CRITICAL_SECTION csGDILock;
extern CRITICAL_SECTION csLcdLock;
extern CRITICAL_SECTION csKeyLock;
extern CRITICAL_SECTION csIOLock;
extern CRITICAL_SECTION csT1Lock;
extern CRITICAL_SECTION csT2Lock;
extern CRITICAL_SECTION csTxdLock;
extern CRITICAL_SECTION csRecvLock;
extern CRITICAL_SECTION csSlowLock;
extern INT nArgc;
extern LPCTSTR *ppArgv;
extern LARGE_INTEGER lFreq;
extern LARGE_INTEGER lAppStart;
extern DWORD idDdeInst;
extern UINT uCF_HpObj;
extern HANDLE hHeap;
extern HINSTANCE hApp;
extern HWND hWnd;
extern HWND hDlgDebug;
extern HWND hDlgFind;
extern HWND hDlgProfile;
extern HDC hWindowDC;
extern HCURSOR hCursorArrow;
extern HCURSOR hCursorHand;
extern BOOL bClassicCursor;
extern BOOL bAutoSave;
extern BOOL bAutoSaveOnExit;
extern BOOL bSaveDefConfirm;
extern BOOL bAlwaysDisplayLog;
extern BOOL bLoadObjectWarning;
extern HANDLE hThread;
extern DWORD lThreadId;
extern VOID SetWindowTitle(LPCTSTR szString);
extern VOID CopyItemsToClipboard(HWND hWnd);
extern VOID UpdateWindowStatus(VOID);
// Settings.c
extern VOID ReadSettings(VOID);
extern VOID WriteSettings(VOID);
extern VOID ReadLastDocument(LPTSTR szFileName, DWORD nSize);
extern VOID WriteLastDocument(LPCTSTR szFilename);
// Display.c
extern UINT nBackgroundX;
extern UINT nBackgroundY;
extern UINT nBackgroundW;
extern UINT nBackgroundH;
extern UINT nLcdX;
extern UINT nLcdY;
extern UINT nLcdZoom;
extern LPBYTE pbyLcd;
extern HDC hLcdDC;
extern HDC hMainDC;
extern VOID UpdateContrast(BYTE byContrast);
extern VOID SetLcdColor(UINT nId, UINT nRed, UINT nGreen, UINT nBlue);
extern VOID CreateLcdBitmap(VOID);
extern VOID DestroyLcdBitmap(VOID);
extern BOOL CreateMainBitmap(LPCTSTR szFilename);
extern VOID DestroyMainBitmap(VOID);
extern VOID UpdateDisplayPointers(VOID);
extern VOID UpdateMainDisplay(VOID);
extern VOID UpdateMenuDisplay(VOID);
extern VOID RefreshDisp0(); // CdB for HP: add apples display management
extern VOID WriteToMainDisplay(LPBYTE a, DWORD d, UINT s);
extern VOID WriteToMenuDisplay(LPBYTE a, DWORD d, UINT s);
extern VOID UpdateAnnunciators(VOID);
extern VOID ResizeWindow(VOID);
extern BYTE GetLineCounter(VOID);
extern VOID StartDisplay(BYTE byInitial);
extern VOID StopDisplay(VOID);
// Engine.c
extern BOOL bInterrupt;
extern UINT nState;
extern UINT nNextState;
extern BOOL bRealSpeed;
extern BOOL bKeySlow;
extern BOOL bCommInit;
extern BOOL bGrayscale;
extern CHIPSET Chipset;
extern TCHAR szSerialWire[16];
extern TCHAR szSerialIr[16];
extern DWORD dwSXCycles;
extern DWORD dwGXCycles;
extern DWORD dwGPCycles; // CdB for HP: add apples speed
extern DWORD dwG2Cycles; // CdB for HP: add apples speed
extern HANDLE hEventDebug;
extern BOOL bDbgAutoStateCtrl;
extern INT nDbgState;
extern BOOL bDbgNOP3;
extern BOOL bDbgCode;
extern BOOL bDbgRPL;
extern BOOL bDbgSkipInt;
extern DWORD dwDbgStopPC;
extern DWORD dwDbgRplPC;
extern DWORD dwDbgRstkp;
extern DWORD dwDbgRstk;
extern DWORD *pdwInstrArray;
extern WORD wInstrSize;
extern WORD wInstrWp;
extern WORD wInstrRp;
extern VOID SuspendDebugger(VOID);
extern VOID ResumeDebugger(VOID);
extern VOID CheckSerial(VOID);
extern VOID AdjKeySpeed(VOID);
extern VOID SetSpeed(BOOL bAdjust);
extern VOID UpdateKdnBit(VOID);
extern BOOL WaitForSleepState(VOID);
extern UINT SwitchToState(UINT nNewState);
extern UINT WorkerThread(LPVOID pParam);
// Fetch.c
extern VOID EvalOpcode(LPBYTE I);
// Files.c
extern TCHAR szEmuDirectory[MAX_PATH];
extern TCHAR szCurrentDirectory[MAX_PATH];
extern TCHAR szCurrentKml[MAX_PATH];
extern TCHAR szBackupKml[MAX_PATH];
extern TCHAR szCurrentFilename[MAX_PATH];
extern TCHAR szBackupFilename[MAX_PATH];
extern TCHAR szBufferFilename[MAX_PATH];
extern TCHAR szPort2Filename[MAX_PATH];
extern LPBYTE pbyRom;
extern DWORD dwRomSize;
extern BYTE cCurrentRomType;
extern UINT nCurrentClass;
extern BOOL bRomWriteable;
extern LPBYTE pbyPort2;
extern BOOL bPort2Writeable;
extern BOOL bPort2IsShared;
extern DWORD dwPort2Size;
extern DWORD dwPort2Mask;
extern BOOL bBackup;
extern VOID SetWindowLocation(HWND hWnd,INT nPosX,INT nPosY);
extern DWORD GetCutPathName(LPCTSTR szFileName,LPTSTR szBuffer,DWORD dwBufferLength,INT nCutLength);
extern VOID SetWindowPathTitle(LPCTSTR szFileName);
extern VOID UpdatePatches(BOOL bPatch);
extern BOOL PatchRom(LPCTSTR szFilename);
extern BOOL MapRom(LPCTSTR szFilename);
extern VOID UnmapRom(VOID);
extern WORD CrcPort2(VOID);
extern BOOL MapPort2(LPCTSTR szFilename);
extern VOID UnmapPort2(VOID);
extern VOID ResetDocument(VOID);
extern BOOL NewDocument(VOID);
extern BOOL OpenDocument(LPCTSTR szFilename);
extern BOOL SaveDocument(VOID);
extern BOOL SaveDocumentAs(LPCTSTR szFilename);
extern BOOL SaveBackup(VOID);
extern BOOL RestoreBackup(VOID);
extern BOOL ResetBackup(VOID);
extern BOOL GetOpenFilename(VOID);
extern BOOL GetSaveAsFilename(VOID);
extern BOOL GetLoadObjectFilename(VOID);
extern BOOL GetSaveObjectFilename(VOID);
extern WORD WriteStack(UINT nStkLevel,LPBYTE lpBuf,DWORD dwSize);
extern BOOL LoadObject(LPCTSTR szFilename);
extern BOOL SaveObject(LPCTSTR szFilename);
extern HBITMAP LoadBitmapFile(LPCTSTR szFilename);
// Timer.c
extern VOID SetHP48Time(VOID);
extern VOID StartTimers(VOID);
extern VOID StopTimers(VOID);
extern DWORD ReadT2(VOID);
extern VOID SetT2(DWORD dwValue);
extern BYTE ReadT1(VOID);
extern VOID SetT1(BYTE byValue);
// Mops.c
extern BOOL bFlashRomArray;
extern BYTE disp;
extern LPBYTE RMap[256];
extern LPBYTE WMap[256];
extern VOID Map(BYTE a, BYTE b);
extern VOID RomSwitch(DWORD adr);
extern VOID Config(VOID);
extern VOID Uncnfg(VOID);
extern VOID Reset(VOID);
extern VOID C_Eq_Id(VOID);
extern enum MMUMAP MapData(DWORD d);
extern VOID CpuReset(VOID);
extern VOID Npeek(BYTE *a, DWORD d, UINT s);
extern VOID Nread(BYTE *a, DWORD d, UINT s);
extern VOID Nwrite(BYTE *a, DWORD d, UINT s);
extern BYTE Read2(DWORD d);
extern DWORD Read5(DWORD d);
extern VOID Write5(DWORD d, DWORD n);
extern VOID Write2(DWORD d, BYTE n);
extern VOID IOBit(DWORD d, BYTE b, BOOL s);
extern VOID ReadIO(BYTE *a, DWORD b, DWORD s, BOOL bUpdate);
extern VOID WriteIO(BYTE *a, DWORD b, DWORD s);
// Keyboard.c
extern VOID ScanKeyboard(BOOL bActive, BOOL bReset);
extern VOID KeyboardEvent(BOOL bPress, UINT out, UINT in);
// Keymacro.c
extern INT nMacroState;
extern INT nMacroTimeout;
extern BOOL bMacroRealSpeed;
extern VOID KeyMacroRecord(BOOL bPress, UINT out, UINT in);
extern LRESULT OnToolMacroNew(VOID);
extern LRESULT OnToolMacroPlay(VOID);
extern LRESULT OnToolMacroStop(VOID);
extern LRESULT OnToolMacroSettings(VOID);
// Stack.c
extern LRESULT OnStackCopy(VOID);
extern LRESULT OnStackPaste(VOID);
// RPL.c
extern BOOL RPL_GetSystemFlag(INT nFlag);
extern DWORD RPL_SkipOb(DWORD d);
extern DWORD RPL_ObjectSize(BYTE *o);
extern DWORD RPL_CreateTemp(DWORD l);
extern UINT RPL_Depth(VOID);
extern DWORD RPL_Pick(UINT l);
extern VOID RPL_Replace(DWORD n);
extern VOID RPL_Push(UINT l,DWORD n);
// External.c
extern BOOL bWaveBeep;
extern DWORD dwWaveVol;
extern VOID External(CHIPSET* w);
// DDEserv.c
extern HDDEDATA CALLBACK DdeCallback(UINT, UINT, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD);
// Disasm.c
extern BOOL disassembler_mode;
extern WORD disassembler_map;
extern DWORD disassemble (DWORD addr, LPTSTR out, BOOL view);
// Serial.c
extern BOOL CommOpen(LPTSTR strWirePort,LPTSTR strIrPort);
extern VOID CommClose(VOID);
extern VOID CommSetBaud(VOID);
extern BOOL UpdateUSRQ(VOID);
extern VOID CommTxBRK(VOID);
extern VOID CommTransmit(VOID);
extern VOID CommReceive(VOID);
// Cursor.c
extern HCURSOR CreateHandCursor(VOID);
#if defined _USRDLL // DLL version
// Emu48dll.c
extern VOID (CALLBACK *pEmuDocumentNotify)(LPCTSTR lpszFilename);
extern BOOL DLLCreateWnd(LPCTSTR lpszFilename, LPCTSTR lpszPort2Name);
extern BOOL DLLDestroyWnd(VOID);
#endif
// Message Boxes
static __inline int InfoMessage(LPCTSTR szMessage) {return MessageBox(hWnd, szMessage, szTitle, MB_APPLMODAL|MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND);}
static __inline int AbortMessage(LPCTSTR szMessage) {return MessageBox(hWnd, szMessage, szTitle, MB_APPLMODAL|MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);}
static __inline int YesNoMessage(LPCTSTR szMessage) {return MessageBox(hWnd, szMessage, szTitle, MB_APPLMODAL|MB_YESNO|MB_ICONEXCLAMATION|MB_SETFOREGROUND);}
static __inline int YesNoCancelMessage(LPCTSTR szMessage,UINT uStyle) {return MessageBox(hWnd, szMessage, szTitle, MB_APPLMODAL|MB_YESNOCANCEL|MB_ICONEXCLAMATION|MB_SETFOREGROUND|uStyle);}
// Missing Win32 API calls
static __inline LPTSTR DuplicateString(LPCTSTR szString)
{
UINT uLength = lstrlen(szString) + 1;
LPTSTR szDup = HeapAlloc(hHeap,0,uLength*sizeof(szDup[0]));
lstrcpy(szDup,szString);
return szDup;
}
#define SCREENHEIGHT (cCurrentRomType=='Q' ? 80 : 64) // CdB for HP: add apples display management
#define SCREENHEIGHTREAL ((cCurrentRomType=='Q') ? (80-Chipset.d0size) : 64)
#define MAINSCREENHEIGHT (((Chipset.lcounter) == 0) ? SCREENHEIGHTREAL : SCREENHEIGHTREAL-64+((Chipset.lcounter)+1))
#define MENUHEIGHT (Chipset.lcounter==0?0:64-(Chipset.lcounter+1))

BIN
SOURCE/EMU48.ICO Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

833
SOURCE/EMU48.RC Normal file
View file

@ -0,0 +1,833 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_WRITEONLYREG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 173
TOPMARGIN, 7
BOTTOMMARGIN, 75
END
IDD_FIND, DIALOG
BEGIN
LEFTMARGIN, 6
RIGHTMARGIN, 190
TOPMARGIN, 7
BOTTOMMARGIN, 40
END
IDD_PROFILE, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 171
TOPMARGIN, 7
BOTTOMMARGIN, 24
END
IDD_BREAKEDIT, DIALOG
BEGIN
LEFTMARGIN, 5
RIGHTMARGIN, 113
TOPMARGIN, 5
BOTTOMMARGIN, 95
END
IDD_ABOUT, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 254
TOPMARGIN, 6
BOTTOMMARGIN, 145
END
IDD_SETTINGS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 160
TOPMARGIN, 4
BOTTOMMARGIN, 256
END
IDD_CHOOSEKML, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 188
TOPMARGIN, 7
BOTTOMMARGIN, 59
END
IDD_KMLLOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 294
TOPMARGIN, 7
BOTTOMMARGIN, 160
END
IDD_DISASM, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 248
TOPMARGIN, 5
BOTTOMMARGIN, 158
END
IDD_DEBUG, DIALOG
BEGIN
LEFTMARGIN, 5
RIGHTMARGIN, 274
TOPMARGIN, 17
BOTTOMMARGIN, 264
END
IDD_NEWVALUE, DIALOG
BEGIN
LEFTMARGIN, 8
RIGHTMARGIN, 168
TOPMARGIN, 7
BOTTOMMARGIN, 43
END
IDD_ENTERADR, DIALOG
BEGIN
LEFTMARGIN, 8
RIGHTMARGIN, 149
TOPMARGIN, 7
BOTTOMMARGIN, 43
END
IDD_ENTERBREAK, DIALOG
BEGIN
LEFTMARGIN, 8
RIGHTMARGIN, 149
TOPMARGIN, 7
BOTTOMMARGIN, 79
END
IDD_INSTRUCTIONS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 179
TOPMARGIN, 7
BOTTOMMARGIN, 162
END
IDD_MACROSET, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 149
TOPMARGIN, 7
BOTTOMMARGIN, 74
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_WRITEONLYREG DIALOG DISCARDABLE 0, 0, 180, 82
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Write Only Registers"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "20-24 (Display Start Address)",IDC_STATIC,11,11,131,8
RTEXT "00000",IDC_ADDR20_24,144,11,25,8
LTEXT "25-27 (Display Line Offset)",IDC_STATIC,11,21,131,8
RTEXT "000",IDC_ADDR25_27,144,21,25,8
LTEXT "28-29 (Display Line Counter)",IDC_STATIC,11,31,131,8
RTEXT "00",IDC_ADDR28_29,144,31,25,8
LTEXT "30-34 (Display Secondary Start Address)",IDC_STATIC,11,
41,131,8
RTEXT "00000",IDC_ADDR30_34,144,41,25,8
DEFPUSHBUTTON "OK",IDOK,65,61,50,14
END
IDD_FIND DIALOGEX 0, 0, 197, 47
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Find"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Find &what:",IDC_STATIC,7,9,34,8
COMBOBOX IDC_FIND_DATA,46,7,88,41,CBS_DROPDOWN | CBS_AUTOHSCROLL |
WS_VSCROLL | WS_TABSTOP
CONTROL "Find &ASCII",IDC_FIND_ASCII,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,46,30,49,10
DEFPUSHBUTTON "&Find Next",IDOK,140,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,140,26,50,14
END
IDD_PROFILE DIALOGEX 0, 0, 178, 31
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Profiler"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Last Instruction Cycles:",IDC_STATIC,7,7,74,8,NOT
WS_GROUP
LTEXT "",IDC_PROFILE_LASTCYCLES,84,7,87,8,NOT WS_GROUP
LTEXT "Last Instruction Time:",IDC_STATIC,7,16,68,8,NOT
WS_GROUP
LTEXT "",IDC_PROFILE_LASTTIME,84,16,87,8,NOT WS_GROUP
END
IDD_BREAKEDIT DIALOG DISCARDABLE 0, 0, 118, 100
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Edit Breakpoints"
FONT 8, "Courier New"
BEGIN
DEFPUSHBUTTON "OK",IDCANCEL,83,81,30,14
LTEXT "Current breakpoints:",IDC_STATIC_BREAKPOINT,5,5,82,8
LISTBOX IDC_BREAKEDIT_WND,5,17,108,58,LBS_SORT |
LBS_OWNERDRAWFIXED | LBS_HASSTRINGS |
LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT |
LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Add...",IDC_BREAKEDIT_ADD,5,81,30,14
PUSHBUTTON "&Delete",IDC_BREAKEDIT_DELETE,44,81,30,14
END
IDD_ABOUT DIALOG DISCARDABLE 0, 0, 261, 160
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Emu48"
FONT 8, "MS Sans Serif"
BEGIN
ICON IDI_EMU48,IDC_STATIC,7,6,20,20,SS_REALSIZEIMAGE
LTEXT "",IDC_VERSION,29,6,151,8,NOT WS_GROUP
LTEXT "Copyright © 2007 Sébastien Carlier && Christoph Gießelink",
IDC_STATIC,29,18,181,8
DEFPUSHBUTTON "OK",IDOK,215,12,39,14
EDITTEXT IDC_LICENSE,7,33,247,112,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY
END
IDD_SETTINGS DIALOG DISCARDABLE 0, 0, 167, 263
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Settings"
FONT 8, "MS Sans Serif"
BEGIN
CONTROL "Authentic Calculator Speed",IDC_REALSPEED,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,13,100,10
CONTROL "Enable Virtual LCD Delay",IDC_GRAYSCALE,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,25,100,10
CONTROL "Automatically Save Files",IDC_AUTOSAVE,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,37,89,10
CONTROL "Automatically Save Files On Exit",IDC_AUTOSAVEONEXIT,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,49,114,10
CONTROL "Show Load Object Warning",IDC_OBJECTLOADWARNING,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,61,102,10
CONTROL "Always Show KML Compilation Result",IDC_ALWAYSDISPLOG,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,73,133,10
GROUPBOX "General",IDC_STATIC,7,4,153,83
CONTROL "HP Mnemonics",IDC_DISASM_HP,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,13,101,65,11
CONTROL "Class Mnemonics",IDC_DISASM_CLASS,"Button",
BS_AUTORADIOBUTTON,84,101,70,11
GROUPBOX "Disassembler",IDC_STATIC,7,90,153,28
LTEXT "Volume",IDC_STATIC,13,134,24,8
CONTROL "Slider1",IDC_SOUND_SLIDER,"msctls_trackbar32",
TBS_AUTOTICKS | WS_TABSTOP,39,129,68,18
CONTROL "Speaker",IDC_SOUND_SPEAKER,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,111,128,43,10
CONTROL "Wave",IDC_SOUND_WAVE,"Button",BS_AUTORADIOBUTTON,111,
139,43,10
GROUPBOX "Sound",IDC_STATIC,7,120,153,34
CONTROL "Port 1 is Plugged",IDC_PORT1EN,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,13,165,67,10
CONTROL "Port 1 is Writeable",IDC_PORT1WR,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,84,165,69,10
CONTROL "Port 2 is Shared",IDC_PORT2ISSHARED,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,13,177,65,10
CONTROL "Port 2 is Writeable",IDC_PORT2WR,"Button",
BS_AUTOCHECKBOX | WS_VISIBLE | WS_TABSTOP,84,177,69,10
LTEXT "Port 2 File :",IDC_STATIC,13,192,37,8
EDITTEXT IDC_PORT2,51,190,94,12,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_PORT2LOAD,145,190,10,12
GROUPBOX "Memory Cards",IDC_STATIC,7,156,153,51
LTEXT "Wire:",IDC_STATIC,13,221,17,8
COMBOBOX IDC_WIRE,31,219,48,42,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
LTEXT "IR:",IDC_STATIC,89,221,9,8
COMBOBOX IDC_IR,107,219,48,43,CBS_DROPDOWNLIST | WS_VSCROLL |
WS_TABSTOP
GROUPBOX "Serial Ports",IDC_STATIC,7,209,153,27
DEFPUSHBUTTON "&Ok",IDOK,9,242,50,14
PUSHBUTTON "&Cancel",IDCANCEL,107,242,50,14
END
IDD_CHOOSEKML DIALOG DISCARDABLE 0, 0, 195, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Choose Your KML Script"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,138,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,138,27,50,14
COMBOBOX IDC_KMLSCRIPT,7,47,181,120,CBS_DROPDOWNLIST |
CBS_OEMCONVERT | CBS_SORT | WS_VSCROLL | WS_TABSTOP
EDITTEXT IDC_EMUDIR,7,17,107,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_EMUDIRSEL,114,17,10,14
PUSHBUTTON "V",IDC_UPDATE,124,17,10,14
LTEXT "Emu48 Directory :",IDC_STATIC,7,7,115,8
LTEXT "Current KML Script :",IDC_STATIC,7,37,115,8
END
IDD_KMLLOG DIALOGEX 0, 0, 301, 167
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "KML Script Compilation Result"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,188,146,50,14
PUSHBUTTON "Cancel",IDCANCEL,244,146,50,14
CONTROL "Show Script compilation result next time",
IDC_ALWAYSDISPLOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
7,146,139,14
GROUPBOX "",IDC_STATIC,7,7,287,36
CTEXT "Title of the Script",IDC_TITLE,71,14,158,8
CTEXT "by",IDC_STATIC,71,22,158,8
CTEXT "The Author",IDC_AUTHOR,71,30,158,8,NOT WS_GROUP
EDITTEXT IDC_KMLLOG,7,48,287,92,ES_MULTILINE | ES_AUTOHSCROLL |
ES_OEMCONVERT | ES_READONLY | WS_VSCROLL | NOT
WS_TABSTOP
END
IDD_DISASM DIALOG DISCARDABLE 0, 0, 255, 165
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Disassembler"
FONT 8, "Courier New"
BEGIN
LTEXT "Address (HEX):",IDC_ADDRESS,7,147,46,8
EDITTEXT IDC_DISASM_ADR,56,145,36,12,ES_AUTOHSCROLL
PUSHBUTTON "&Next Address",IDC_DISASM_NEXT,99,144,47,14
PUSHBUTTON "&Copy Data",IDC_DISASM_COPY,150,144,47,14
PUSHBUTTON "Cancel",IDCANCEL,201,144,47,14
GROUPBOX "Module",IDC_DISASM_MODULE,7,5,241,26
CONTROL "Map",IDC_DISASM_MAP,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,14,16,37,10
CONTROL "ROM",IDC_DISASM_ROM,"Button",BS_AUTORADIOBUTTON,61,16,
37,10
CONTROL "RAM",IDC_DISASM_RAM,"Button",BS_AUTORADIOBUTTON,108,16,
37,10
CONTROL "Port 1",IDC_DISASM_PORT1,"Button",BS_AUTORADIOBUTTON,
155,16,37,10
CONTROL "Port 2",IDC_DISASM_PORT2,"Button",BS_AUTORADIOBUTTON,
202,16,37,10
LISTBOX IDC_DISASM_WIN,7,37,241,100,NOT LBS_NOTIFY |
LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL |
WS_TABSTOP
END
IDD_DEBUG DIALOG DISCARDABLE 0, 0, 279, 269
STYLE WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Debugger"
MENU IDR_DEBUG
FONT 8, "Courier New"
BEGIN
LISTBOX IDC_DEBUG_CODE,11,27,165,122,NOT LBS_NOTIFY |
LBS_OWNERDRAWFIXED | LBS_HASSTRINGS |
LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT |
WS_TABSTOP
GROUPBOX "Code",IDC_STATIC_CODE,5,17,177,138
LTEXT "A= 0000000000000000",IDC_REG_A,192,27,77,8
LTEXT "B= 0000000000000000",IDC_REG_B,192,34,77,8
LTEXT "C= 0000000000000000",IDC_REG_C,192,41,77,8
LTEXT "D= 0000000000000000",IDC_REG_D,192,48,77,8
LTEXT "R0=0000000000000000",IDC_REG_R0,192,58,77,8
LTEXT "R1=0000000000000000",IDC_REG_R1,192,65,77,8
LTEXT "R2=0000000000000000",IDC_REG_R2,192,72,77,8
LTEXT "R3=0000000000000000",IDC_REG_R3,192,79,77,8
LTEXT "R4=0000000000000000",IDC_REG_R4,192,86,77,8
LTEXT "D0=00000",IDC_REG_D0,192,97,33,8
LTEXT "D1=00000",IDC_REG_D1,236,97,33,8
LTEXT "P=0",IDC_REG_P,192,108,13,8
LTEXT "PC=00000",IDC_REG_PC,236,108,33,8
LTEXT "OUT=000",IDC_REG_OUT,192,119,29,8
LTEXT "IN=0000",IDC_REG_IN,240,119,29,8
LTEXT "ST=0000",IDC_REG_ST,192,130,29,8
LTEXT "CY=0",IDC_REG_CY,224,130,17,8
LTEXT "Mode=H",IDC_REG_MODE,244,130,25,8
LTEXT "MP=0",IDC_REG_MP,192,140,17,8
LTEXT "SR=0",IDC_REG_SR,212,140,17,8
LTEXT "SB=0",IDC_REG_SB,232,140,17,8
LTEXT "XM=0",IDC_REG_XM,252,140,17,8
GROUPBOX "Registers",IDC_STATIC_REGISTERS,187,17,87,138
LISTBOX IDC_DEBUG_MEM,11,166,165,52,NOT LBS_NOTIFY |
LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_DISABLED
LISTBOX IDC_DEBUG_MEM_ADDR,12,168,25,48,NOT LBS_NOTIFY |
LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_DISABLED | NOT
WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL0,40,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER | WS_TABSTOP
LISTBOX IDC_DEBUG_MEM_COL1,52,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL2,64,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL3,76,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL4,88,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL5,100,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL6,112,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_COL7,124,168,11,48,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | NOT WS_BORDER
LISTBOX IDC_DEBUG_MEM_TEXT,139,168,35,48,NOT LBS_NOTIFY |
LBS_NOINTEGRALHEIGHT | LBS_NOSEL | WS_DISABLED | NOT
WS_BORDER
GROUPBOX "Memory",IDC_STATIC_MEMORY,5,156,177,68
LISTBOX IDC_DEBUG_STACK,192,166,76,52,LBS_NOINTEGRALHEIGHT |
LBS_WANTKEYBOARDINPUT | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Stack",IDC_STATIC_STACK,187,156,87,68
LTEXT "Size Mask",IDC_STATIC,11,243,37,8
LTEXT "Address",IDC_STATIC,11,251,29,8
CTEXT "I/O",IDC_STATIC,55,235,21,8
CTEXT "NCE2",IDC_STATIC,80,235,21,8
CTEXT "CE1",IDC_STATIC,105,235,21,8
CTEXT "CE2",IDC_STATIC,130,235,21,8
CTEXT "NCE3",IDC_STATIC,155,235,21,8
CTEXT "-----",IDC_MMU_IO_S,55,243,21,8
CTEXT "-----",IDC_MMU_NCE2_S,80,243,21,8
CTEXT "-----",IDC_MMU_CE1_S,105,243,21,8
CTEXT "-----",IDC_MMU_CE2_S,130,243,21,8
CTEXT "-----",IDC_MMU_NCE3_S,155,243,21,8
CTEXT "-----",IDC_MMU_IO_A,55,251,21,8
CTEXT "-----",IDC_MMU_CE1_A,105,251,21,8
CTEXT "-----",IDC_MMU_CE2_A,130,251,21,8
CTEXT "-----",IDC_MMU_NCE2_A,80,251,21,8
CTEXT "-----",IDC_MMU_NCE3_A,155,251,21,8
GROUPBOX "MMU",IDC_STATIC_MMU,5,225,177,39
LTEXT "Interrupts =",IDC_STATIC,193,235,61,8
LTEXT "Keyboard Scan =",IDC_STATIC,193,243,61,8
LTEXT "Bank Switcher =",IDC_MISC_BS_TXT,193,251,61,8,
WS_DISABLED
LTEXT "",IDC_MISC_INT,256,235,13,8
LTEXT "",IDC_MISC_KEY,256,243,13,8
LTEXT "00",IDC_MISC_BS,256,251,13,8,WS_DISABLED
GROUPBOX "Miscellaneous",IDC_STATIC_MISC,187,225,87,39
END
IDD_NEWVALUE DIALOG DISCARDABLE 0, 0, 175, 50
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "New Value"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "New value (hexadecimal):",IDC_STATIC,8,9,81,8
EDITTEXT IDC_NEWVALUE,93,7,75,12,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,21,29,50,14
PUSHBUTTON "Cancel",IDCANCEL,103,29,50,14
END
IDD_ENTERADR DIALOG DISCARDABLE 0, 0, 156, 50
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Enter Address"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Enter address (hexadecimal):",IDC_STATIC,8,9,93,8
EDITTEXT IDC_ENTERADR,105,7,44,12,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,14,29,50,14
PUSHBUTTON "Cancel",IDCANCEL,92,29,50,14
END
IDD_ENTERBREAK DIALOG DISCARDABLE 0, 0, 156, 86
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Enter Breakpoint"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Enter breakpoint (hexadecimal):",IDC_STATIC,8,9,99,8
EDITTEXT IDC_ENTERADR,112,7,37,12,ES_AUTOHSCROLL
CONTROL "&Code",IDC_BPCODE,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,17,24,33,10
CONTROL "R&PL",IDC_BPRPL,"Button",BS_AUTORADIOBUTTON,17,50,30,10
CONTROL "Memory &Access",IDC_BPACCESS,"Button",
BS_AUTORADIOBUTTON,79,24,63,10
CONTROL "Memory &Read",IDC_BPREAD,"Button",BS_AUTORADIOBUTTON,79,
37,60,10
CONTROL "Memory &Write",IDC_BPWRITE,"Button",BS_AUTORADIOBUTTON,
79,50,59,10
DEFPUSHBUTTON "OK",IDOK,14,65,50,14
PUSHBUTTON "Cancel",IDCANCEL,92,65,50,14
END
IDD_INSTRUCTIONS DIALOG DISCARDABLE 0, 0, 186, 169
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Last Instructions"
FONT 8, "Courier New"
BEGIN
LTEXT "Instructions (disassembly maybe incorrect):",
IDC_INSTR_TEXT,7,7,173,8
LISTBOX IDC_INSTR_CODE,7,18,172,122,NOT LBS_NOTIFY |
LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL |
WS_TABSTOP
PUSHBUTTON "&Copy Data",IDC_INSTR_COPY,7,148,50,14
PUSHBUTTON "C&lear Data",IDC_INSTR_CLEAR,68,148,50,14
DEFPUSHBUTTON "Cancel",IDCANCEL,129,148,50,14
END
IDD_MACROSET DIALOG DISCARDABLE 0, 0, 156, 81
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Macro Settings"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Slow",IDC_MACRO_SLOW,12,16,16,8,WS_DISABLED
LTEXT "Fast",IDC_MACRO_FAST,78,16,14,8,WS_DISABLED
CONTROL "Slider1",IDC_MACRO_SLIDER,"msctls_trackbar32",
TBS_AUTOTICKS | WS_DISABLED | WS_TABSTOP,12,26,82,21
CONTROL "&Real",IDC_MACRO_REAL,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,103,18,39,10
CONTROL "&Manual",IDC_MACRO_MANUAL,"Button",BS_AUTORADIOBUTTON,
103,32,39,10
GROUPBOX "Replay Speed",IDC_STATIC,7,3,142,49
DEFPUSHBUTTON "OK",IDOK,13,60,50,14
PUSHBUTTON "Cancel",IDCANCEL,93,60,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_CHECKBOX BITMAP DISCARDABLE "checkbox.bmp"
IDR_DEBUG_TOOLBAR BITMAP MOVEABLE PURE "dbgtool.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Toolbar
//
IDR_DEBUG_TOOLBAR TOOLBAR DISCARDABLE 16, 15
BEGIN
BUTTON ID_DEBUG_RUN
BUTTON ID_DEBUG_CANCEL
BUTTON ID_DEBUG_BREAK
SEPARATOR
BUTTON ID_BREAKPOINTS_SETBREAK
BUTTON ID_BREAKPOINTS_CODEEDIT
SEPARATOR
BUTTON ID_DEBUG_STEP
BUTTON ID_DEBUG_STEPOVER
BUTTON ID_DEBUG_STEPOUT
BUTTON ID_DEBUG_RUNCURSOR
END
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,2,0
PRODUCTVERSION 1,4,2,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "04090000"
BEGIN
VALUE "CompanyName", "Sebastien Carlier & Christoph Gießelink\0"
VALUE "FileDescription", "HP38/39/40/48/49 Emulator\0"
VALUE "FileVersion", "1, 4, 2, 0\0"
VALUE "InternalName", "Emu48\0"
VALUE "LegalCopyright", "Copyright © 2007\0"
VALUE "OriginalFilename", "Emu48.exe\0"
VALUE "ProductName", "Emu48\0"
VALUE "ProductVersion", "1, 4, 2, 0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 0
END
END
#endif // !_MAC
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_EMU48 ICON DISCARDABLE "Emu48.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New...", ID_FILE_NEW
MENUITEM "&Open...", ID_FILE_OPEN
MENUITEM "&Save", ID_FILE_SAVE, GRAYED
MENUITEM "Save &As...", ID_FILE_SAVEAS, GRAYED
MENUITEM "&Close", ID_FILE_CLOSE, GRAYED
MENUITEM SEPARATOR
MENUITEM "S&ettings...", ID_VIEW_SETTINGS
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Edit"
BEGIN
MENUITEM "&Load Object...", ID_OBJECT_LOAD
MENUITEM "&Save Object...", ID_OBJECT_SAVE
MENUITEM SEPARATOR
MENUITEM "C&opy Screen", ID_VIEW_COPY
MENUITEM "&Copy Stack", ID_STACK_COPY
MENUITEM "&Paste Stack", ID_STACK_PASTE
MENUITEM SEPARATOR
MENUITEM "&Reset Calculator", ID_VIEW_RESET, GRAYED
POPUP "&Backup"
BEGIN
MENUITEM "&Save", ID_BACKUP_SAVE, GRAYED
MENUITEM "&Restore", ID_BACKUP_RESTORE
, GRAYED
MENUITEM "&Delete", ID_BACKUP_DELETE, GRAYED
END
END
POPUP "&View"
BEGIN
MENUITEM "Change &KML Script...", ID_VIEW_SCRIPT
END
POPUP "&Tools"
BEGIN
MENUITEM "D&isassembler...", ID_TOOL_DISASM
MENUITEM "&Debugger...", ID_TOOL_DEBUG
MENUITEM SEPARATOR
POPUP "&Macro"
BEGIN
MENUITEM "&Record...", ID_TOOL_MACRO_RECORD
, GRAYED
MENUITEM "&Play...", ID_TOOL_MACRO_PLAY
, GRAYED
MENUITEM "&Stop", ID_TOOL_MACRO_STOP
, GRAYED
MENUITEM "S&ettings...", ID_TOOL_MACRO_SETTINGS
END
END
POPUP "&Help"
BEGIN
MENUITEM "&About Emu48...", ID_ABOUT
END
END
IDR_DEBUG MENU DISCARDABLE
BEGIN
POPUP "&Debug"
BEGIN
MENUITEM "&Run\tF5", ID_DEBUG_RUN
MENUITEM "Run to &Cursor\tF6", ID_DEBUG_RUNCURSOR
MENUITEM "&Step Into\tF7", ID_DEBUG_STEP
MENUITEM "Step &Over\tF8", ID_DEBUG_STEPOVER
MENUITEM "Step O&ut\tF9", ID_DEBUG_STEPOUT
MENUITEM "&Break\tF11", ID_DEBUG_BREAK
END
POPUP "&Breakpoints"
BEGIN
MENUITEM "Set &Breakpoint\tF2", ID_BREAKPOINTS_SETBREAK
MENUITEM "&Edit Breakpoints...", ID_BREAKPOINTS_CODEEDIT
MENUITEM "&Clear All Breakpoints", ID_BREAKPOINTS_CLEARALL
MENUITEM SEPARATOR
MENUITEM "&NOP3 Code Breakpoints", ID_BREAKPOINTS_NOP3
MENUITEM "CODE &Object Breakpoints", ID_BREAKPOINTS_DOCODE
MENUITEM SEPARATOR
MENUITEM "&RPL Breakpoints", ID_BREAKPOINTS_RPL
END
POPUP "I&nterrupts"
BEGIN
MENUITEM "&Step Over Interrupts", ID_INTR_STEPOVERINT
END
POPUP "&Info"
BEGIN
MENUITEM "&Last Instructions...", ID_INFO_LASTINSTRUCTIONS
MENUITEM "&Profiler...", ID_INFO_PROFILE
MENUITEM "&Write Only Registers...", ID_INFO_WRITEONLYREG
END
END
IDR_DEBUG_CODE MENU DISCARDABLE
BEGIN
POPUP ""
BEGIN
MENUITEM "&Go to address...\tG", ID_DEBUG_CODE_GOADR
MENUITEM "Go to &PC", ID_DEBUG_CODE_GOPC
MENUITEM "Set &breakpoint\tF2", ID_BREAKPOINTS_SETBREAK
MENUITEM "&Set PC to selection", ID_DEBUG_CODE_SETPCTOSELECT
END
END
IDR_DEBUG_MEM MENU DISCARDABLE
BEGIN
POPUP ""
BEGIN
MENUITEM "&Go to address...\tG", ID_DEBUG_MEM_GOADR
MENUITEM "Go to &PC", ID_DEBUG_MEM_GOPC
MENUITEM "Go to D&0", ID_DEBUG_MEM_GOD0
MENUITEM "Go to D&1", ID_DEBUG_MEM_GOD1
MENUITEM "Go to &Stack", ID_DEBUG_MEM_GOSTACK
POPUP "Follo&w"
BEGIN
MENUITEM "&none", ID_DEBUG_MEM_FNONE
MENUITEM SEPARATOR
MENUITEM "&Address Content", ID_DEBUG_MEM_FADDR
MENUITEM "Register &PC", ID_DEBUG_MEM_FPC
MENUITEM "Register D&0", ID_DEBUG_MEM_FD0
MENUITEM "Register D&1", ID_DEBUG_MEM_FD1
END
MENUITEM SEPARATOR
MENUITEM "&Find...\tF", ID_DEBUG_MEM_FIND
MENUITEM SEPARATOR
POPUP "&Mapping"
BEGIN
MENUITEM "Map", ID_DEBUG_MEM_MAP
MENUITEM SEPARATOR
MENUITEM "NCE1", ID_DEBUG_MEM_NCE1
, GRAYED
MENUITEM "NCE2", ID_DEBUG_MEM_NCE2
, GRAYED
MENUITEM "CE1", ID_DEBUG_MEM_CE1, GRAYED
MENUITEM "CE2", ID_DEBUG_MEM_CE2, GRAYED
MENUITEM "NCE3", ID_DEBUG_MEM_NCE3
, GRAYED
END
END
END
IDR_DEBUG_STACK MENU DISCARDABLE
BEGIN
POPUP ""
BEGIN
MENUITEM "&Push", ID_DEBUG_STACK_PUSH
MENUITEM "P&op", ID_DEBUG_STACK_POP
MENUITEM "&Modify", ID_DEBUG_STACK_MODIFY
END
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// 24
//
1 24 MOVEABLE PURE "Emu48.xml"
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MENU ACCELERATORS DISCARDABLE
BEGIN
"C", ID_STACK_COPY, VIRTKEY, CONTROL, NOINVERT
"V", ID_STACK_PASTE, VIRTKEY, CONTROL, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE DISCARDABLE
BEGIN
ID_DEBUG_RUN "Run"
ID_DEBUG_RUNCURSOR "Run to Cursor"
ID_DEBUG_STEP "Step Into"
ID_DEBUG_STEPOVER "Step Over"
ID_DEBUG_BREAK "Break Execution"
END
STRINGTABLE DISCARDABLE
BEGIN
ID_DEBUG_STEPOUT "Step Out"
ID_DEBUG_CANCEL "Stop Debugging"
ID_BREAKPOINTS_SETBREAK "Insert/Remove Breakpoint"
ID_BREAKPOINTS_CODEEDIT "Breakpoint List"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

22
SOURCE/EMU48.XML Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="Emu48"
type="win32"
/>
<description>Emu48</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>

585
SOURCE/EMU48DLL.C Normal file
View file

@ -0,0 +1,585 @@
/*
* Emu48Dll.c
*
* This file is part of Emu48
*
* Copyright (C) 2000 Christoph Gießelink
*
*/
#include "pch.h"
#include "resource.h"
#include "Emu48.h"
#include "io.h"
#include "kml.h"
#include "debugger.h"
#include "Emu48Dll.h"
static LPCTSTR pArgv[3]; // command line memory
static HACCEL hAccel; // accelerator table
static HSZ hszService, hszTopic; // variables for DDE server
extern LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
// callback function notify document filename
VOID (CALLBACK *pEmuDocumentNotify)(LPCTSTR lpszFilename) = NULL;
// callback function notify Emu48 closed
static VOID (CALLBACK *pEmuClose)(VOID) = NULL;
//################
//#
//# Public internal functions
//#
//################
//
// DLLCreateWnd
//
BOOL DLLCreateWnd(LPCTSTR lpszFilename, LPCTSTR lpszPort2Name)
{
WNDCLASS wc;
RECT rectWindow;
BOOL bFileExist = FALSE; // state file don't exist
hApp = GetModuleHandle(_T("EMU48.DLL"));
if (hApp == NULL) return TRUE;
hHeap = GetProcessHeap(); // get process heap
if (hHeap == NULL) return TRUE;
nArgc = 1; // no argument
if (lpszFilename[0])
{
// try to open given filename
HANDLE hFile = CreateFile(lpszFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (bFileExist = (hFile != INVALID_HANDLE_VALUE))
CloseHandle(hFile);
ppArgv = pArgv; // command line arguments
nArgc = 2; // one argument: state file, no port2 file
pArgv[1] = lpszFilename; // name of state file
if (lpszPort2Name) // port2 filename
{
nArgc = 3; // two arguments: state file, port2 file
pArgv[2] = lpszPort2Name; // name of port2 file
}
}
wc.style = CS_BYTEALIGNCLIENT;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hApp;
wc.hIcon = LoadIcon(hApp, MAKEINTRESOURCE(IDI_EMU48));
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = _T("CEmu48");
RegisterClass(&wc);
// Create window
rectWindow.left = 0;
rectWindow.top = 0;
rectWindow.right = 256;
rectWindow.bottom = 0;
AdjustWindowRect(&rectWindow, WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED, TRUE);
hWnd = CreateWindow(_T("CEmu48"), _T("Emu48"),
WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED,
CW_USEDEFAULT, CW_USEDEFAULT,
rectWindow.right - rectWindow.left,
rectWindow.bottom - rectWindow.top,
NULL,NULL,hApp,NULL
);
if (hWnd == NULL)
{
UnregisterClass(_T("CEmu48"),hApp);
return TRUE;
}
VERIFY(hAccel = LoadAccelerators(hApp,MAKEINTRESOURCE(IDR_MENU)));
// remove debugger menu entry from resource
DeleteMenu(GetMenu(hWnd),ID_TOOL_DEBUG,MF_BYCOMMAND);
// initialization
EmuClearAllBreakpoints();
QueryPerformanceFrequency(&lFreq); // init high resolution counter
GetCurrentDirectory(sizeof(szCurrentDirectory), szCurrentDirectory);
szCurrentKml[0] = 0; // no KML file selected
ReadSettings();
UpdateWindowStatus();
// create shutdown auto event handle
hEventShutdn = CreateEvent(NULL,FALSE,FALSE,NULL);
if (hEventShutdn == NULL)
{
DestroyWindow(hWnd);
return TRUE;
}
// create debugger auto event handle
hEventDebug = CreateEvent(NULL,FALSE,FALSE,NULL);
if (hEventDebug == NULL)
{
CloseHandle(hEventShutdn); // close shutdown event handle
DestroyWindow(hWnd);
return TRUE;
}
nState = SM_RUN; // init state must be <> nNextState
nNextState = SM_INVALID; // go into invalid state
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&WorkerThread, NULL, CREATE_SUSPENDED, &lThreadId);
if (hThread == NULL)
{
CloseHandle(hEventDebug); // close debugger event handle
CloseHandle(hEventShutdn); // close event handle
DestroyWindow(hWnd);
return TRUE;
}
// on multiprocessor machines for QueryPerformanceCounter()
SetThreadAffinityMask(hThread,1);
ResumeThread(hThread); // start thread
while (nState!=nNextState) Sleep(0); // wait for thread initialized
idDdeInst = 0; // initialize DDE server
if (DdeInitialize(&idDdeInst,(PFNCALLBACK) &DdeCallback,
APPCLASS_STANDARD |
CBF_FAIL_EXECUTES | CBF_FAIL_ADVISES |
CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS,0))
{
TerminateThread(hThread, 0); // kill emulation thread
CloseHandle(hEventDebug); // close debugger event handle
CloseHandle(hEventShutdn); // close event handle
DestroyWindow(hWnd);
return TRUE;
}
_ASSERT(hWnd != NULL);
_ASSERT(hWindowDC != NULL);
szBufferFilename[0] = 0;
if (bFileExist) // open existing file
{
lstrcpyn(szBufferFilename,ppArgv[1],ARRAYSIZEOF(szBufferFilename));
}
if (nArgc == 1) // no argument
{
ReadLastDocument(szBufferFilename,ARRAYSIZEOF(szBufferFilename));
}
if (szBufferFilename[0]) // given default document
{
TCHAR szTemp[MAX_PATH+8] = _T("Loading ");
RECT rectClient;
_ASSERT(hWnd != NULL);
VERIFY(GetClientRect(hWnd,&rectClient));
GetCutPathName(szBufferFilename,&szTemp[8],MAX_PATH,rectClient.right/10-8);
SetWindowTitle(szTemp);
if (OpenDocument(szBufferFilename))
goto start;
}
SetWindowTitle(_T("New Document"));
if (NewDocument())
{
if (nArgc >= 2)
SaveDocumentAs(ppArgv[1]);
else
SetWindowTitle(_T("Untitled"));
goto start;
}
DestroyWindow(hWnd); // clean up system
return TRUE;
start:
// init clipboard format and name service
uCF_HpObj = RegisterClipboardFormat(_T(CF_HPOBJ));
hszService = DdeCreateStringHandle(idDdeInst,szAppName,0);
hszTopic = DdeCreateStringHandle(idDdeInst,szTopic,0);
DdeNameService(idDdeInst,hszService,NULL,DNS_REGISTER);
ShowWindow(hWnd, SW_SHOW);
if (pbyRom) SwitchToState(SM_RUN);
return FALSE;
}
//
// DLLDestroyWnd
//
BOOL DLLDestroyWnd(VOID)
{
// clean up DDE server
DdeNameService(idDdeInst, hszService, NULL, DNS_UNREGISTER);
DdeFreeStringHandle(idDdeInst, hszService);
DdeFreeStringHandle(idDdeInst, hszTopic);
DdeUninitialize(idDdeInst);
WriteSettings(); // save variable settings
CloseHandle(hThread); // close emulation thread handle
CloseHandle(hEventShutdn); // close shutdown event handle
CloseHandle(hEventDebug); // close debugger event handle
_ASSERT(nState == SM_RETURN); // emulation thread down?
ResetDocument();
ResetBackup();
_ASSERT(pbyRom == NULL); // rom file unmapped
_ASSERT(pbyPort2 == NULL); // port2 file unmapped
_ASSERT(pKml == NULL); // KML script not closed
_ASSERT(szTitle == NULL); // freed allocated memory
_ASSERT(hPalette == NULL); // freed resource memory
if (pEmuClose) pEmuClose(); // call notify function
return FALSE;
}
//################
//#
//# Public external functions
//#
//################
/****************************************************************************
* EmuCreate
*****************************************************************************
*
* @func start Emu48 and load Ram file into emulator, if Ram file don't
* exist create a new one and save it under the given name
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuCreate(
LPCTSTR lpszFilename) // @parm String with RAM filename
{
return DLLCreateWnd(lpszFilename, NULL);
}
/****************************************************************************
* EmuCreateEx
*****************************************************************************
*
* @func start Emu48 and load Ram and Port2 file into emulator, if Ram file
* don't exist create a new one and save it under the given name
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuCreateEx(
LPCTSTR lpszFilename, // @parm String with RAM filename
LPCTSTR lpszPort2Name) // @parm String with Port2 filename
// or NULL for using name inside INI file
{
return DLLCreateWnd(lpszFilename, lpszPort2Name);
}
/****************************************************************************
* EmuDestroy
*****************************************************************************
*
* @func close Emu48, free all memory
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuDestroy(VOID)
{
if (hWnd == NULL) return TRUE; // Emu48 closed
// close Emu48 via exit
SendMessage(hWnd,WM_SYSCOMMAND,SC_CLOSE,0);
return FALSE;
}
/****************************************************************************
* EmuAcceleratorTable
*****************************************************************************
*
* @func load accelerator table of emulator
*
* @xref none
*
* @rdesc HACCEL: handle of the loaded accelerator table
*
****************************************************************************/
DECLSPEC HACCEL CALLBACK EmuAcceleratorTable(
HWND *phEmuWnd) // @parm return of emulator window handle
{
*phEmuWnd = hWnd;
return hAccel;
}
/****************************************************************************
* EmuCallBackClose
*****************************************************************************
*
* @func init CallBack handler to notify caller when Emu48 window close
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
DECLSPEC VOID CALLBACK EmuCallBackClose(
VOID (CALLBACK *EmuClose)(VOID)) // @parm CallBack function notify caller Emu48 closed
{
pEmuClose = EmuClose; // set new handler
return;
}
/****************************************************************************
* EmuCallBackDocumentNotify
*****************************************************************************
*
* @func init CallBack handler to notify caller for actual document file
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
DECLSPEC VOID CALLBACK EmuCallBackDocumentNotify(
VOID (CALLBACK *EmuDocumentNotify)(LPCTSTR lpszFilename)) // @parm CallBack function notify document filename
{
pEmuDocumentNotify = EmuDocumentNotify; // set new handler
return;
}
/****************************************************************************
* EmuLoadRamFile
*****************************************************************************
*
* @func load Ram file into emulator
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error (old file reloaded)
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuLoadRamFile(
LPCTSTR lpszFilename) // @parm String with RAM filename
{
BOOL bErr;
if (pbyRom) SwitchToState(SM_INVALID); // stop emulation thread
bErr = !OpenDocument(lpszFilename); // load state file
if (pbyRom) SwitchToState(SM_RUN); // restart emulation thread
return bErr;
}
/****************************************************************************
* EmuSaveRamFile
*****************************************************************************
*
* @func save the current emulator Ram to file
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error (old file reloaded)
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuSaveRamFile(VOID)
{
BOOL bErr;
if (pbyRom == NULL) return TRUE; // fail
SwitchToState(SM_INVALID); // stop emulation thread
bErr = !SaveDocument(); // save current state file
SwitchToState(SM_RUN); // restart emulation thread
return bErr;
}
/****************************************************************************
* EmuLoadObject
*****************************************************************************
*
* @func load object file to stack
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuLoadObject(
LPCTSTR lpszObjectFilename) // @parm String with object filename
{
HANDLE hFile;
DWORD dwFileSizeLow;
DWORD dwFileSizeHigh;
LPBYTE lpBuf;
WORD wError = S_ERR_BINARY; // set into error state
SuspendDebugger(); // suspend debugger
bDbgAutoStateCtrl = FALSE; // disable automatic debugger state control
if (!(Chipset.IORam[BITOFFSET]&DON)) // calculator off, turn on
{
KeyboardEvent(TRUE,0,0x8000);
Sleep(200);
KeyboardEvent(FALSE,0,0x8000);
Sleep(200);
// wait for sleep mode
while(Chipset.Shutdn == FALSE) Sleep(0);
}
if (nState != SM_RUN) goto cancel; // emulator must run to load on object
if (WaitForSleepState()) goto cancel; // wait for cpu SHUTDN then sleep state
_ASSERT(nState == SM_SLEEP);
hFile = CreateFile(lpszObjectFilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
SwitchToState(SM_RUN); // run state
goto cancel;
}
dwFileSizeLow = GetFileSize(hFile, &dwFileSizeHigh);
if (dwFileSizeHigh != 0)
{ // file is too large.
SwitchToState(SM_RUN); // run state
CloseHandle(hFile);
goto cancel;
}
lpBuf = HeapAlloc(hHeap,0,dwFileSizeLow*2);
if (lpBuf == NULL)
{
SwitchToState(SM_RUN); // run state
CloseHandle(hFile);
goto cancel;
}
ReadFile(hFile, lpBuf+dwFileSizeLow, dwFileSizeLow, &dwFileSizeHigh, NULL);
CloseHandle(hFile);
wError = WriteStack(1,lpBuf,dwFileSizeLow);
HeapFree(hHeap,0,lpBuf);
SwitchToState(SM_RUN); // run state
while (nState!=nNextState) Sleep(0);
_ASSERT(nState == SM_RUN);
KeyboardEvent(TRUE,0,0x8000);
Sleep(200);
KeyboardEvent(FALSE,0,0x8000);
while(Chipset.Shutdn == FALSE) Sleep(0);
cancel:
bDbgAutoStateCtrl = TRUE; // enable automatic debugger state control
ResumeDebugger();
return wError != S_ERR_NO;
}
/****************************************************************************
* EmuSaveObject
*****************************************************************************
*
* @func save object on stack to file
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
DECLSPEC BOOL CALLBACK EmuSaveObject(
LPCTSTR lpszObjectFilename) // @parm String with object filename
{
BOOL bErr;
if (nState != SM_RUN) return TRUE; // emulator must run to load on object
if (WaitForSleepState()) return TRUE; // wait for cpu SHUTDN then sleep state
_ASSERT(nState == SM_SLEEP);
bErr = !SaveObject(lpszObjectFilename);
SwitchToState(SM_RUN);
return bErr;
}
/****************************************************************************
* EmuCalculatorType
*****************************************************************************
*
* @func get ID of current calculator type
*
* @xref none
*
* @rdesc BYTE: '6' = HP38G with 64KB RAM
* 'A' = HP38G
* 'E' = HP39/40G
* 'S' = HP48SX
* 'G' = HP48GX
* 'X' = HP49G
* 'P' = HP39G+
* '2' = HP48GII
* 'Q' = HP49G+
*
****************************************************************************/
DECLSPEC BYTE CALLBACK EmuCalculatorType(VOID)
{
return Chipset.type;
}
/****************************************************************************
* EmuSimulateKey
*****************************************************************************
*
* @func simulate a key action
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
DECLSPEC VOID CALLBACK EmuSimulateKey(
BOOL bKeyState, // @parm TRUE = pressed, FALSE = released
UINT out, // @parm key out line
UINT in) // @parm key in line
{
KeyboardEvent(bKeyState,out,in);
}
/****************************************************************************
* EmuPressOn
*****************************************************************************
*
* @func press On key (emulation must run)
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
DECLSPEC VOID CALLBACK EmuPressOn(
BOOL bKeyState) // @parm TRUE = pressed, FALSE = released
{
KeyboardEvent(bKeyState,0,0x8000);
}

256
SOURCE/EMU48DLL.DSP Normal file
View file

@ -0,0 +1,256 @@
# Microsoft Developer Studio Project File - Name="Emu48" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=Emu48 - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "EMU48DLL.MAK".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "EMU48DLL.MAK" CFG="Emu48 - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Emu48 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Emu48 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Emu48 - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /c
# ADD CPP /nologo /Gr /MT /W3 /GX /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "_MBCS" /D "_USRDLL" /D "REGISTRY" /Yu"pch.h" /FD /D REGISTRYKEY=\"Software\\Hewlett-Packard\\Debug4x\\Emu48\" /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib advapi32.lib /nologo /dll /machine:I386 /out:".\Release/Emu48.dll"
!ELSEIF "$(CFG)" == "Emu48 - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "_MBCS" /D "_USRDLL" /D "REGISTRY" /FR /Yu"pch.h" /FD /D REGISTRYKEY=\"Software\\Hewlett-Packard\\Debug4x\\Emu48\" /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib advapi32.lib /nologo /dll /debug /machine:I386 /out:".\Debug/Emu48.dll"
!ENDIF
# Begin Target
# Name "Emu48 - Win32 Release"
# Name "Emu48 - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\apple.c
# End Source File
# Begin Source File
SOURCE=.\cursor.c
# End Source File
# Begin Source File
SOURCE=.\ddeserv.c
# End Source File
# Begin Source File
SOURCE=.\debugdll.c
# End Source File
# Begin Source File
SOURCE=.\disasm.c
# End Source File
# Begin Source File
SOURCE=.\display.c
# End Source File
# Begin Source File
SOURCE=.\Emu48.c
# End Source File
# Begin Source File
SOURCE=.\Emu48.rc
# End Source File
# Begin Source File
SOURCE=.\Emu48dll.c
# End Source File
# Begin Source File
SOURCE=.\engine.c
# End Source File
# Begin Source File
SOURCE=.\external.c
# End Source File
# Begin Source File
SOURCE=.\fetch.c
# End Source File
# Begin Source File
SOURCE=.\files.c
# End Source File
# Begin Source File
SOURCE=.\i28f160.c
# End Source File
# Begin Source File
SOURCE=.\keyboard.c
# End Source File
# Begin Source File
SOURCE=.\keymacro.c
# End Source File
# Begin Source File
SOURCE=.\kml.c
# End Source File
# Begin Source File
SOURCE=.\mops.c
# End Source File
# Begin Source File
SOURCE=.\opcodes.c
# End Source File
# Begin Source File
SOURCE=.\pch.c
# ADD CPP /Yc"pch.h"
# End Source File
# Begin Source File
SOURCE=.\rpl.c
# End Source File
# Begin Source File
SOURCE=.\serial.c
# End Source File
# Begin Source File
SOURCE=.\settings.c
# End Source File
# Begin Source File
SOURCE=.\stack.c
# End Source File
# Begin Source File
SOURCE=.\timer.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
# Begin Source File
SOURCE=.\apple.h
# End Source File
# Begin Source File
SOURCE=.\color.h
# End Source File
# Begin Source File
SOURCE=.\debugger.h
# End Source File
# Begin Source File
SOURCE=.\Emu48.h
# End Source File
# Begin Source File
SOURCE=.\Emu48dll.h
# End Source File
# Begin Source File
SOURCE=.\i28f160.h
# End Source File
# Begin Source File
SOURCE=.\io.h
# End Source File
# Begin Source File
SOURCE=.\kml.h
# End Source File
# Begin Source File
SOURCE=.\opcodes.h
# End Source File
# Begin Source File
SOURCE=.\ops.h
# End Source File
# Begin Source File
SOURCE=.\pch.h
# End Source File
# Begin Source File
SOURCE=.\types.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\Emu48.ico
# End Source File
# End Group
# End Target
# End Project

29
SOURCE/EMU48DLL.DSW Normal file
View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Emu48"=".\EMU48DLL.DSP" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

642
SOURCE/EMU48DLL.H Normal file
View file

@ -0,0 +1,642 @@
/*
* Emu48Dll.h
*
* This file is part of Emu48
*
* Copyright (C) 2000 Christoph Gießelink
*
*/
#define DECLSPEC __declspec(dllexport)
//////////////////////////////////
//
// breakpoint type definitions
//
//////////////////////////////////
#define BP_EXEC 0x01 // code breakpoint
#define BP_READ 0x02 // read memory breakpoint
#define BP_WRITE 0x04 // write memory breakpoint
#define BP_RPL 0x08 // RPL breakpoint
#define BP_ACCESS (BP_READ|BP_WRITE) // read/write memory breakpoint
#define BP_ROM 0x8000 // absolute ROM adress breakpoint
//////////////////////////////////
//
// REGISTER ACCESS API
//
//////////////////////////////////
#define EMU_REGISTER_PC 0
#define EMU_REGISTER_D0 1
#define EMU_REGISTER_D1 2
#define EMU_REGISTER_DUMMY 3
#define EMU_REGISTER_AL 4
#define EMU_REGISTER_AH 5
#define EMU_REGISTER_BL 6
#define EMU_REGISTER_BH 7
#define EMU_REGISTER_CL 8
#define EMU_REGISTER_CH 9
#define EMU_REGISTER_DL 10
#define EMU_REGISTER_DH 11
#define EMU_REGISTER_R0L 12
#define EMU_REGISTER_R0H 13
#define EMU_REGISTER_R1L 14
#define EMU_REGISTER_R1H 15
#define EMU_REGISTER_R2L 16
#define EMU_REGISTER_R2H 17
#define EMU_REGISTER_R3L 18
#define EMU_REGISTER_R3H 19
#define EMU_REGISTER_R4L 20
#define EMU_REGISTER_R4H 21
#define EMU_REGISTER_R5L 22
#define EMU_REGISTER_R5H 23
#define EMU_REGISTER_R6L 24
#define EMU_REGISTER_R6H 25
#define EMU_REGISTER_R7L 26
#define EMU_REGISTER_R7H 27
#define EMU_REGISTER_FLAGS 28
#define EMU_REGISTER_OUT 29
#define EMU_REGISTER_IN 30
#define EMU_REGISTER_VIEW1 31
#define EMU_REGISTER_VIEW2 32
#define EMU_REGISTER_RSTKP 63
#define EMU_REGISTER_RSTK0 64
#define EMU_REGISTER_RSTK1 65
#define EMU_REGISTER_RSTK2 66
#define EMU_REGISTER_RSTK3 67
#define EMU_REGISTER_RSTK4 68
#define EMU_REGISTER_RSTK5 69
#define EMU_REGISTER_RSTK6 70
#define EMU_REGISTER_RSTK7 71
#define EMU_REGISTER_CLKL 72
#define EMU_REGISTER_CLKH 73
#define EMU_REGISTER_CRC 74
/**
* "FLAGS" register format :
*
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ST |S|x|x|x|K|I|C|M| HST | P |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* M : Mode (0:Hex, 1:Dec)
* C : Carry
* I : Interrupt pending
* K : KDN Interrupts Enabled
* S : Shutdn Flag (read only)
* x : reserved
*/
/****************************************************************************
* EmuCreate
*****************************************************************************
*
* @func start Emu48 and load Ram file into emulator, if Ram file don't
* exist create a new one and save it under the given name
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuCreate(
LPCTSTR lpszFilename); // @parm String with RAM filename
/****************************************************************************
* EmuCreateEx
*****************************************************************************
*
* @func start Emu48 and load Ram and Port2 file into emulator, if Ram file
* don't exist create a new one and save it under the given name
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuCreateEx(
LPCTSTR lpszFilename, // @parm String with RAM filename
LPCTSTR lpszPort2Name); // @parm String with Port2 filename
// or NULL for using name inside INI file
/****************************************************************************
* EmuDestroy
*****************************************************************************
*
* @func close Emu48, free all memory
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuDestroy(VOID);
/****************************************************************************
* EmuAcceleratorTable
*****************************************************************************
*
* @func load accelerator table of emulator
*
* @xref none
*
* @rdesc HACCEL: handle of the loaded accelerator table
*
****************************************************************************/
EXTERN_C DECLSPEC HACCEL CALLBACK EmuAcceleratorTable(
HWND *phEmuWnd); // @parm return of emulator window handle
/****************************************************************************
* EmuCallBackClose
*****************************************************************************
*
* @func init CallBack handler to notify caller when Emu48 window close
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuCallBackClose(
VOID (CALLBACK *EmuClose)(VOID)); // @parm CallBack function notify caller Emu48 closed
/****************************************************************************
* EmuCallBackDocumentNotify
*****************************************************************************
*
* @func init CallBack handler to notify caller for actual document file
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuCallBackDocumentNotify(
VOID (CALLBACK *EmuDocumentNotify)(LPCTSTR lpszFilename)); // @parm CallBack function notify document filename
/****************************************************************************
* EmuLoadRamFile
*****************************************************************************
*
* @func load Ram file into emulator
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error (old file reloaded)
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuLoadRamFile(
LPCTSTR lpszFilename); // @parm String with RAM filename
/****************************************************************************
* EmuSaveRamFile
*****************************************************************************
*
* @func save the current emulator Ram to file
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error (old file reloaded)
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuSaveRamFile(VOID);
/****************************************************************************
* EmuLoadObject
*****************************************************************************
*
* @func load object file to stack
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuLoadObject(
LPCTSTR lpszObjectFilename); // @parm String with object filename
/****************************************************************************
* EmuSaveObject
*****************************************************************************
*
* @func save object on stack to file
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuSaveObject(
LPCTSTR lpszObjectFilename); // @parm String with object filename
/****************************************************************************
* EmuCalculatorType
*****************************************************************************
*
* @func get ID of current calculator type
*
* @xref none
*
* @rdesc BYTE: '6' = HP38G with 64KB RAM
* 'A' = HP38G
* 'E' = HP39/40G
* 'S' = HP48SX
* 'G' = HP48GX
* 'X' = HP49G
* 'P' = HP39G+
* '2' = HP48GII
* 'Q' = HP49G+
*
****************************************************************************/
EXTERN_C DECLSPEC BYTE CALLBACK EmuCalculatorType(VOID);
/****************************************************************************
* EmuSimulateKey
*****************************************************************************
*
* @func simulate a key action
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuSimulateKey(
BOOL bKeyState, // @parm TRUE = pressed, FALSE = released
UINT out, // @parm key out line
UINT in); // @parm key in line
/****************************************************************************
* EmuPressOn
*****************************************************************************
*
* @func press On key (emulation must run)
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuPressOn(
BOOL bKeyState); // @parm TRUE = pressed, FALSE = released
/****************************************************************************
* EmuInitLastInstr
*****************************************************************************
*
* @func init a circular buffer area for saving the last instruction
* addresses
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuInitLastInstr(
WORD wNoInstr, // @parm number of saved instructions,
// 0 = frees the memory buffer
DWORD *pdwArray); // @parm pointer to linear array
/****************************************************************************
* EmuGetLastInstr
*****************************************************************************
*
* @func return number of valid entries in the last instruction array,
* each entry contents a PC address, array[0] contents the oldest,
* array[*pwNoEntries-1] the last PC address
*
* @xref none
*
* @rdesc BOOL: FALSE = OK, TRUE = Error
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuGetLastInstr(
WORD *pwNoEntries); // @parm return number of valid entries in array
/****************************************************************************
* EmuRun
*****************************************************************************
*
* @func run emulation
*
* @xref none
*
* @rdesc BOOL: FALSE = OK
* TRUE = Error, Emu48 is running
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuRun(VOID);
/****************************************************************************
* EmuRunPC
*****************************************************************************
*
* @func run emulation until stop address
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuRunPC(
DWORD dwAddressPC); // @parm breakpoint address
/****************************************************************************
* EmuStep
*****************************************************************************
*
* @func execute one ASM instruction and return to caller
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuStep(VOID);
/****************************************************************************
* EmuStepOver
*****************************************************************************
*
* @func execute one ASM instruction but skip GOSUB, GOSUBL, GOSBVL
* subroutines
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuStepOver(VOID);
/****************************************************************************
* EmuStepOut
*****************************************************************************
*
* @func run emulation until a RTI, RTN, RTNC, RTNCC, RTNNC, RTNSC, RTNSXN,
* RTNYES instruction is found above the current stack level
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuStepOut(VOID);
/****************************************************************************
* EmuStop
*****************************************************************************
*
* @func break emulation
*
* @xref none
*
* @rdesc BOOL: FALSE = OK
* TRUE = Error, no debug notify handler
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuStop(VOID);
/****************************************************************************
* EmuCallBackDebugNotify
*****************************************************************************
*
* @func init CallBack handler to notify caller on debugger breakpoint
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuCallBackDebugNotify(
VOID (CALLBACK *EmuDbgNotify)(INT nBreaktype)); // @parm CallBack function notify Debug breakpoint
/****************************************************************************
* EmuCallBackStackNotify
*****************************************************************************
*
* @func init CallBack handler to notify caller on hardware stack change;
* if the CallBack function return TRUE, emulation stops behind the
* opcode changed hardware stack content, otherwise, if the CallBack
* function return FALSE, no breakpoint is set
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuCallBackStackNotify(
BOOL (CALLBACK *EmuStackNotify)(VOID)); // @parm CallBack function notify stack changed
/****************************************************************************
* EmuGetRegister
*****************************************************************************
*
* @func read a 32 bit register
*
* @xref none
*
* @rdesc DWORD: 32 bit value of register
*
****************************************************************************/
EXTERN_C DECLSPEC DWORD CALLBACK EmuGetRegister(
UINT uRegister); // @parm index of register
/****************************************************************************
* EmuSetRegister
*****************************************************************************
*
* @func write a 32 bit register
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuSetRegister(
UINT uRegister, // @parm index of register
DWORD dwValue); // @parm new 32 bit value
/****************************************************************************
* EmuGetMem
*****************************************************************************
*
* @func read one nibble from the specified mapped address
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuGetMem(
DWORD dwMapAddr, // @parm mapped address of Saturn CPU
BYTE *pbyValue); // @parm readed nibble
/****************************************************************************
* EmuSetMem
*****************************************************************************
*
* @func write one nibble to the specified mapped address
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuSetMem(
DWORD dwMapAddr, // @parm mapped address of Saturn CPU
BYTE byValue); // @parm nibble to write
/****************************************************************************
* EmuGetRom
*****************************************************************************
*
* @func return size and base address of mapped ROM
*
* @xref none
*
* @rdesc LPBYTE: base address of ROM (pointer to original data)
*
****************************************************************************/
EXTERN_C DECLSPEC LPBYTE CALLBACK EmuGetRom(
DWORD *pdwRomSize); // @parm return size of ROM in nibbles
/****************************************************************************
* EmuSetBreakpoint
*****************************************************************************
*
* @func set ASM code/data breakpoint
*
* @xref none
*
* @rdesc BOOL: TRUE = Error, Breakpoint table full
* FALSE = OK, Breakpoint set
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuSetBreakpoint(
DWORD dwAddress, // @parm breakpoint address to set
UINT nBreakpointType); // @parm breakpoint type to set
/****************************************************************************
* EmuClearBreakpoint
*****************************************************************************
*
* @func clear ASM code/data breakpoint
*
* @xref none
*
* @rdesc BOOL: TRUE = Error, Breakpoint not found
* FALSE = OK, Breakpoint cleared
*
****************************************************************************/
EXTERN_C DECLSPEC BOOL CALLBACK EmuClearBreakpoint(
DWORD dwAddress, // @parm breakpoint address to clear
UINT nBreakpointType); // @parm breakpoint type to clear
/****************************************************************************
* EmuClearAllBreakpoints
*****************************************************************************
*
* @func clear all breakpoints
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuClearAllBreakpoints(VOID);
/****************************************************************************
* EmuEnableNop3Breakpoint
*****************************************************************************
*
* @func enable/disable NOP3 breakpoint
* stop emulation at Opcode 420 for GOC + (next line)
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuEnableNop3Breakpoint(
BOOL bEnable); // @parm stop on NOP3 opcode
/****************************************************************************
* EmuEnableDocodeBreakpoint
*****************************************************************************
*
* @func enable/disable DOCODE breakpoint
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuEnableDoCodeBreakpoint(
BOOL bEnable); // @parm stop on DOCODE entry
/****************************************************************************
* EmuEnableRplBreakpoint
*****************************************************************************
*
* @func enable/disable RPL breakpoint
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuEnableRplBreakpoint(
BOOL bEnable); // @parm stop on RPL exit
/****************************************************************************
* EmuEnableSkipInterruptCode
*****************************************************************************
*
* @func enable/disable skip single step execution inside the interrupt
* handler, this option has no effect on code and data breakpoints
*
* @xref none
*
* @rdesc VOID
*
****************************************************************************/
EXTERN_C DECLSPEC VOID CALLBACK EmuEnableSkipInterruptCode(
BOOL bEnable); // @parm TRUE = skip code instructions
// inside interrupt service routine

632
SOURCE/ENGINE.C Normal file
View file

@ -0,0 +1,632 @@
/*
* engine.c
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#include "pch.h"
#include "Emu48.h"
#include "Opcodes.h"
#include "io.h"
#include "debugger.h"
#define SAMPLE 16384 // speed adjust sample frequency
BOOL bInterrupt = FALSE;
UINT nState = SM_INVALID;
UINT nNextState = SM_RUN;
BOOL bRealSpeed = FALSE;
BOOL bKeySlow = FALSE; // slow down for key emulation
BOOL bCommInit = FALSE; // COM port not open
CHIPSET Chipset;
TCHAR szSerialWire[16]; // devicename for wire port
TCHAR szSerialIr[16]; // devicename for IR port
DWORD dwSXCycles = 82; // SX cpu cycles in interval
DWORD dwGXCycles = 123; // GX cpu cycles in interval
DWORD dwGPCycles = 123*3; // G+ cpu cycles in interval // CdB for HP: add apples display management
DWORD dwG2Cycles = 123*2; // Gii cpu cycles in interval // CdB for HP: add apples display management
// variables for debugger engine
HANDLE hEventDebug; // event handle to stop cpu thread
BOOL bDbgAutoStateCtrl = TRUE; // debugger suspend control by SwitchToState()
INT nDbgState = DBG_OFF; // state of debugger
BOOL bDbgNOP3 = FALSE; // halt on NOP3 (#420 opcode)
BOOL bDbgRPL = FALSE; // halt on RPL entry
BOOL bDbgCode = FALSE; // halt on DOCODE entry
BOOL bDbgSkipInt = FALSE; // execute interrupt handler
DWORD dwDbgStopPC = -1; // stop address for goto cursor
DWORD dwDbgRplPC = -1; // stop address for RPL breakpoint
DWORD dwDbgRstkp; // stack recursion level of step over end
DWORD dwDbgRstk; // possible return address
DWORD *pdwInstrArray = NULL; // last instruction array
WORD wInstrSize; // size of last instruction array
WORD wInstrWp; // write pointer of instruction array
WORD wInstrRp; // read pointer of instruction array
static INT nDbgRplBreak = BN_ASM; // flag for RPL breakpoint detection
static INT nDbgOldState = DBG_OFF; // old state of debugger for suspend/resume
static BOOL bCpuSlow = FALSE; // enable/disable real speed
static DWORD dwEDbgT2 = 0; // debugger timer2 emulation
static DWORD dwEDbgCycles = 0; // debugger cycle counter
static DWORD dwOldCyc; // cpu cycles at last event
static DWORD dwSpeedRef; // timer value at last event
static DWORD dwTickRef; // sample timer ticks
#include "Ops.h"
// save last instruction in circular instruction buffer
static __inline VOID SaveInstrAddr(DWORD dwAddr)
{
if (pdwInstrArray) // circular buffer allocated
{
pdwInstrArray[wInstrWp] = dwAddr;
wInstrWp = (wInstrWp + 1) % wInstrSize;
if (wInstrWp == wInstrRp)
wInstrRp = (wInstrRp + 1) % wInstrSize;
}
return;
}
static __inline VOID Debugger(VOID) // debugger part
{
LARGE_INTEGER lDummyInt; // sample timer ticks
BOOL bStopEmulation;
LPBYTE I = FASTPTR(Chipset.pc); // get opcode stream
UpdateDbgCycleCounter(); // update 64 bit cpu cycle counter
SaveInstrAddr(Chipset.pc); // save pc in last instruction buffer
nDbgRplBreak = BN_ASM; // notify ASM breakpoint
// check for code breakpoints
bStopEmulation = CheckBreakpoint(Chipset.pc, 1, BP_EXEC);
// check for memory breakpoints, opcode #14x or #15x
if (I[0] == 0x1 && (I[1] == 0x4 || I[1] == 0x5))
{
DWORD dwData = (I[2] & 0x1) ? Chipset.d1 : Chipset.d0;
UINT nType = (I[2] & 0x2) ? BP_READ : BP_WRITE;
DWORD dwRange;
if (I[1] == 0x4) // B,A
{
dwRange = (I[2] & 0x8) ? 2 : 5;
}
else // number of nibbles, (P,WP,XS,X,S,M,W)
{
dwRange = (I[2] & 0x8) ? (I[3]+1) : (F_l[I[3]]);
}
#if defined DEBUG_DEBUGGER
{
TCHAR buffer[256];
wsprintf(buffer,_T("Memory breakpoint %.5lx, %u\n",dwData,dwRange));
OutputDebugString(buffer);
}
#endif
bStopEmulation |= CheckBreakpoint(dwData, dwRange, nType);
}
// check for step cursor
bStopEmulation |= (dwDbgStopPC == Chipset.pc);
// NOP3, opcode #420 (GOC)
if (bDbgNOP3 && I[0] == 0x4 && I[1] == 0x2 && I[2] == 0x0)
bStopEmulation = TRUE;
// stop on first instruction of DOCODE object
if (bDbgCode && (Chipset.pc == 0x02DDE || Chipset.pc == 0x02E3C))
{
// return address
DWORD dwAddr = Chipset.rstk[(Chipset.rstkp-1)&7];
_ASSERT(I[0] == 0 && I[1] == 1); // stopped at RTN opcode
if (MapData(dwAddr) != M_ROM) // address not in ROM
dwDbgStopPC = dwAddr; // then stop
}
// check for RPL breakpoint
if (dwDbgRplPC == Chipset.pc)
{
dwDbgRplPC = -1;
nDbgRplBreak = bStopEmulation ? BN_ASM_BT : BN_RPL;
bStopEmulation = TRUE;
}
// RPL breakpoints, PC=(A), opcode #808C or PC=(C), opcode #808E
if (I[0] == 0x8 && I[1] == 0x0 && I[2] == 0x8 && (I[3] == 0xC || I[3] == 0xE ))
{
// get next RPL entry
DWORD dwAddr = Npack((I[3] == 0xC) ? Chipset.A : Chipset.C,5);
if (bDbgRPL || CheckBreakpoint(dwAddr, 1, BP_RPL))
{
BYTE byRplPtr[5];
Npeek(byRplPtr,dwAddr,5); // get PC address of next opcode
dwDbgRplPC = Npack(byRplPtr,5); // set RPL breakpoint
}
}
// step over interrupt execution
if (bDbgSkipInt && !bStopEmulation && !Chipset.inte)
return;
// check for step into
bStopEmulation |= (nDbgState == DBG_STEPINTO);
// check for step over
bStopEmulation |= (nDbgState == DBG_STEPOVER) && dwDbgRstkp == Chipset.rstkp;
// check for step out, something was popped from hardware stack
if (nDbgState == DBG_STEPOUT && dwDbgRstkp == Chipset.rstkp)
{
_ASSERT(bStopEmulation == FALSE);
if ((bStopEmulation = (Chipset.pc == dwDbgRstk)) == FALSE)
{
// it was C=RSTK, check for next object popped from hardware stack
dwDbgRstkp = (Chipset.rstkp-1)&7;
dwDbgRstk = Chipset.rstk[dwDbgRstkp];
}
}
if (bStopEmulation) // stop condition
{
StopTimers(); // hold timer values when emulator is stopped
if (Chipset.IORam[TIMER2_CTRL]&RUN) // check if timer running
{
if (dwEDbgT2 == Chipset.t2)
{
// cpu cycles for one timer2 tick elapsed
if ((DWORD) (Chipset.cycles & 0xFFFFFFFF) - dwEDbgCycles
>= (SAMPLE / 8192) * (DWORD) T2CYCLES)
{
--Chipset.t2;
// adjust cycles reference
dwEDbgCycles += (SAMPLE / 8192) * T2CYCLES;
}
}
else // new timer2 value
{
// new cycle reference
dwEDbgCycles = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
}
// check rising edge of Bit 8 of timer2
if ((dwEDbgT2 & 0x100) == 0 && (Chipset.t2 & 0x100) != 0)
Chipset.t1 = (Chipset.t1 - 1) & 0xF;
}
dwEDbgT2 = Chipset.t2; // timer2 check reference value
// redraw debugger window and stop
NotifyDebugger(nDbgRplBreak);
WaitForSingleObject(hEventDebug,INFINITE);
StartTimers(); // continue timers
if (nDbgState >= DBG_OFF) // if debugger is active
{
Chipset.Shutdn = FALSE;
Chipset.bShutdnWake = FALSE;
}
// init slow down part
dwOldCyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
QueryPerformanceCounter(&lDummyInt);
dwSpeedRef = lDummyInt.LowPart;
}
return;
}
VOID SuspendDebugger(VOID)
{
// auto control enabled, emulation halted by debugger
if (bDbgAutoStateCtrl && nDbgState > DBG_OFF)
{
nDbgOldState = nDbgState; // save old state
nDbgState = DBG_SUSPEND; // suspend state
SetEvent(hEventDebug); // exit debugger
}
return;
}
VOID ResumeDebugger(VOID)
{
// auto control enabled, debugger is suspended
if (bDbgAutoStateCtrl && nDbgState == DBG_SUSPEND)
{
// active RPL breakpoint
if (nDbgRplBreak) dwDbgRplPC = Chipset.pc;
nDbgState = nDbgOldState; // set to old debugger state
if (Chipset.Shutdn) // inside shutdown
SetEvent(hEventShutdn); // leave it to call debugger
}
return;
}
static __inline VOID CheckDisp(BOOL bSync)
{
if (disp == 0) return; // no display update need
// update display when drawing top line or display is off
if (bSync && GetLineCounter() != 0x3F && (Chipset.IORam[0x00]&8))
return;
_ASSERT((disp & DISP_POINTER) == 0); // display pointer already updated
if (disp & DISP_MAIN) UpdateMainDisplay();
if (disp & DISP_MENUE) UpdateMenuDisplay();
_ASSERT((disp & DISP_ANNUN) == 0); // annunciators already updated
disp = 0; // display updated
return;
}
static __inline VOID AdjustSpeed(VOID) // adjust emulation speed
{
if (bCpuSlow || bKeySlow) // emulation slow down
{
DWORD dwCycles,dwTicks;
EnterCriticalSection(&csSlowLock);
{
// cycles elapsed for next check
if ((dwCycles = (DWORD) (Chipset.cycles & 0xFFFFFFFF)-dwOldCyc) >= (DWORD) T2CYCLES)
{
LARGE_INTEGER lAct;
do
{
VERIFY(QueryPerformanceCounter(&lAct));
// get time difference
dwTicks = lAct.LowPart - dwSpeedRef;
}
// ticks elapsed or negative number (workaround for QueryPerformanceCounter() in Win2k)
while(dwTicks <= dwTickRef || (dwTicks & 0x80000000) != 0);
dwOldCyc += T2CYCLES; // adjust cycles reference
dwSpeedRef += dwTickRef; // adjust reference time
}
}
LeaveCriticalSection(&csSlowLock);
}
return;
}
VOID CheckSerial(VOID)
{
// COM port closed and serial on
if (bCommInit == FALSE && (Chipset.IORam[IOC] & SON) != 0)
{
bCommInit = CommOpen(szSerialWire,szSerialIr); // open COM ports
}
// COM port opened and serial off
if (bCommInit == TRUE && (Chipset.IORam[IOC] & SON) == 0)
{
CommClose(); // close COM port
bCommInit = FALSE;
}
return;
}
VOID AdjKeySpeed(VOID) // slow down key repeat
{
WORD i;
BOOL bKey;
if (bCpuSlow) return; // no need to slow down
bKey = FALSE; // search for a pressed key
for (i = 0;i < ARRAYSIZEOF(Chipset.Keyboard_Row) && !bKey;++i)
bKey = (Chipset.Keyboard_Row[i] != 0);
EnterCriticalSection(&csSlowLock);
{
if (!bKeySlow && bKey) // key pressed, init variables
{
LARGE_INTEGER lTime; // sample timer ticks
// save reference cycles
dwOldCyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
QueryPerformanceCounter(&lTime); // get timer ticks
dwSpeedRef = lTime.LowPart; // save reference time
}
bKeySlow = bKey; // save new state
}
LeaveCriticalSection(&csSlowLock);
return;
}
VOID SetSpeed(BOOL bAdjust) // set emulation speed
{
EnterCriticalSection(&csSlowLock);
{
if (bAdjust) // switch to real speed
{
LARGE_INTEGER lTime; // sample timer ticks
// save reference cycles
dwOldCyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
QueryPerformanceCounter(&lTime); // get timer ticks
dwSpeedRef = lTime.LowPart; // save reference time
}
bCpuSlow = bAdjust; // save emulation speed
}
LeaveCriticalSection(&csSlowLock);
return;
}
VOID UpdateKdnBit(VOID) // update KDN bit
{
if ( Chipset.intk
&& (Chipset.IORam[TIMER2_CTRL]&RUN) != 0
&& (DWORD) (Chipset.cycles & 0xFFFFFFFF) - Chipset.dwKdnCycles > (DWORD) T2CYCLES * 16)
IOBit(SRQ2,KDN,Chipset.in != 0);
return;
}
BOOL WaitForSleepState(VOID) // wait for cpu SHUTDN then sleep state
{
DWORD dwRefTime;
SuspendDebugger(); // suspend debugger
dwRefTime = timeGetTime();
// wait for the SHUTDN command with 1.5 sec timeout
while (timeGetTime() - dwRefTime < 1500L && !Chipset.Shutdn)
Sleep(0);
if (Chipset.Shutdn) // not timeout, cpu is down
SwitchToState(SM_SLEEP); // go to sleep state
else
ResumeDebugger(); // timeout, resume to debugger
return SM_SLEEP != nNextState; // state not changed, emulator was busy
}
UINT SwitchToState(UINT nNewState)
{
UINT nOldState = nState;
if (nState == nNewState) return nOldState;
switch (nState)
{
case SM_RUN: // Run
switch (nNewState)
{
case SM_INVALID: // -> Invalid
nNextState = SM_INVALID;
if (Chipset.Shutdn)
SetEvent(hEventShutdn);
else
bInterrupt = TRUE;
SuspendDebugger(); // suspend debugger
while (nState!=nNextState) Sleep(0);
UpdateWindowStatus();
break;
case SM_RETURN: // -> Return
DisableDebugger(); // disable debugger
nNextState = SM_INVALID;
if (Chipset.Shutdn)
SetEvent(hEventShutdn);
else
bInterrupt = TRUE;
while (nState!=nNextState) Sleep(0);
nNextState = SM_RETURN;
SetEvent(hEventShutdn);
WaitForSingleObject(hThread,INFINITE);
UpdateWindowStatus();
break;
case SM_SLEEP: // -> Sleep
nNextState = SM_SLEEP;
bInterrupt = TRUE; // exit main loop
SuspendDebugger(); // suspend debugger
SetEvent(hEventShutdn); // exit shutdown
while (nState!=nNextState) Sleep(0);
bInterrupt = FALSE;
ResetEvent(hEventDebug);
ResetEvent(hEventShutdn);
break;
}
break;
case SM_INVALID: // Invalid
switch (nNewState)
{
case SM_RUN: // -> Run
nNextState = SM_RUN;
// don't enter opcode loop on interrupt request
bInterrupt = Chipset.Shutdn || Chipset.SoftInt;
ResumeDebugger();
SetEvent(hEventShutdn);
while (nState!=nNextState) Sleep(0);
UpdateWindowStatus();
break;
case SM_RETURN: // -> Return
DisableDebugger(); // disable debugger
nNextState = SM_RETURN;
SetEvent(hEventShutdn);
WaitForSingleObject(hThread,INFINITE);
break;
case SM_SLEEP: // -> Sleep
nNextState = SM_SLEEP;
SetEvent(hEventShutdn);
while (nState!=nNextState) Sleep(0);
UpdateWindowStatus();
break;
}
break;
case SM_SLEEP: // Sleep
switch (nNewState)
{
case SM_RUN: // -> Run
nNextState = SM_RUN;
// don't enter opcode loop on interrupt request
bInterrupt = (nDbgState == DBG_OFF) && (Chipset.Shutdn || Chipset.SoftInt);
ResumeDebugger();
SetEvent(hEventShutdn); // leave sleep state
break;
case SM_INVALID: // -> Invalid
nNextState = SM_INVALID;
SetEvent(hEventShutdn);
while (nState!=nNextState) Sleep(0);
UpdateWindowStatus();
break;
case SM_RETURN: // -> Return
DisableDebugger(); // disable debugger
nNextState = SM_INVALID;
SetEvent(hEventShutdn);
while (nState!=nNextState) Sleep(0);
nNextState = SM_RETURN;
SetEvent(hEventShutdn);
WaitForSingleObject(hThread,INFINITE);
UpdateWindowStatus();
break;
}
break;
}
return nOldState;
}
UINT WorkerThread(LPVOID pParam)
{
LARGE_INTEGER lDummyInt; // sample timer ticks
QueryPerformanceFrequency(&lDummyInt); // init timer ticks
lDummyInt.QuadPart /= SAMPLE; // calculate sample ticks
dwTickRef = lDummyInt.LowPart; // sample timer ticks
_ASSERT(dwTickRef); // tick resolution error
loop:
while (nNextState == SM_INVALID) // go into invalid state
{
OnToolMacroStop(); // close open keyboard macro handler
CommClose(); // close COM port
bCommInit = FALSE; // COM port not open
nState = SM_INVALID; // in invalid state
WaitForSingleObject(hEventShutdn,INFINITE);
if (nNextState == SM_RETURN) // go into return state
{
nState = SM_RETURN; // in return state
return 0; // kill thread
}
CheckSerial(); // test if UART on
}
while (nNextState == SM_RUN)
{
if (nState != SM_RUN)
{
nState = SM_RUN;
// clear port2 status bits
Chipset.cards_status &= ~(PORT2_PRESENT | PORT2_WRITE);
if (pbyPort2 || Chipset.Port2) // card plugged in port2
{
Chipset.cards_status |= PORT2_PRESENT;
if (bPort2Writeable) // is card writeable
Chipset.cards_status |= PORT2_WRITE;
}
// card detection off and timer running
if ((Chipset.IORam[CARDCTL] & ECDT) == 0 && (Chipset.IORam[TIMER2_CTRL] & RUN) != 0)
{
BOOL bNINT2 = Chipset.IORam[SRQ1] == 0 && (Chipset.IORam[SRQ2] & LSRQ) == 0;
BOOL bNINT = (Chipset.IORam[CARDCTL] & SMP) == 0;
// state of CDT2
bNINT2 = bNINT2 && (Chipset.cards_status & (P2W|P2C)) != P2C;
// state of CDT1
bNINT = bNINT && (Chipset.cards_status & (P1W|P1C)) != P1C;
IOBit(SRQ2,NINT2,bNINT2);
IOBit(SRQ2,NINT,bNINT);
}
RomSwitch(Chipset.Bank_FF); // select HP49G ROM bank and update memory mapping
UpdateContrast(Chipset.contrast);
UpdateDisplayPointers();
UpdateMainDisplay();
UpdateMenuDisplay();
RefreshDisp0(); // CdB for HP: add apples display management
UpdateAnnunciators();
// init speed reference
dwOldCyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
QueryPerformanceCounter(&lDummyInt);
dwSpeedRef = lDummyInt.LowPart;
SetHP48Time(); // update HP48 time & date
StartTimers();
// start display counter/update engine
StartDisplay((BYTE)(((Chipset.IORam[LINECOUNT+1]<<4)|Chipset.IORam[LINECOUNT])&0x3F));
}
PCHANGED;
while (!bInterrupt)
{
if (nDbgState > DBG_OFF) // debugger active
{
Debugger();
// if suspended skip next opcode execution
if (nDbgState == DBG_SUSPEND)
{
if (Chipset.Shutdn) break;
continue;
}
}
EvalOpcode(FASTPTR(Chipset.pc)); // execute opcode
if (!bGrayscale)
CheckDisp(!Chipset.Shutdn); // check for display update
AdjustSpeed(); // adjust emulation speed
}
bInterrupt = FALSE; // be sure to reenter opcode loop
// enter SHUTDN handler only in RUN mode
if (Chipset.Shutdn && !(nDbgState == DBG_STEPINTO || nDbgState == DBG_STEPOVER))
{
if (!Chipset.SoftInt) // ignore SHUTDN on interrupt request
WaitForSingleObject(hEventShutdn,INFINITE);
else
Chipset.bShutdnWake = TRUE; // waked by interrupt
if (Chipset.bShutdnWake) // waked up by timer, keyboard or serial
{
Chipset.bShutdnWake = FALSE;
Chipset.Shutdn = FALSE;
// init speed reference
dwOldCyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
QueryPerformanceCounter(&lDummyInt);
dwSpeedRef = lDummyInt.LowPart;
}
}
if (Chipset.SoftInt)
{
Chipset.SoftInt = FALSE;
if (Chipset.inte)
{
Chipset.inte = FALSE;
rstkpush(Chipset.pc);
Chipset.pc = 0xf;
}
}
}
_ASSERT(nNextState != SM_RUN);
StopDisplay(); // stop display counter/update
StopTimers();
while (nNextState == SM_SLEEP) // go into sleep state
{
nState = SM_SLEEP; // in sleep state
WaitForSingleObject(hEventShutdn,INFINITE);
}
goto loop;
UNREFERENCED_PARAMETER(pParam);
}

188
SOURCE/EXTERNAL.C Normal file
View file

@ -0,0 +1,188 @@
/*
* external.c
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#include "pch.h"
#include "Emu48.h"
#include "ops.h"
#define MUSIC_FREQ 11025 // this can be adjusted for quality
//| 38G | 39G | 40G | 48SX | 48GX | 49G | Name
//#F0E4F #80F0F #80F0F #706D2 #80850 #80F0F =SFLAG53_56
// memory address for flags -53 to -56
// CdB for HP: add apples beep management
#define SFLAG53_56 ( (cCurrentRomType=='6') \
? 0xE0E4F \
: ( (cCurrentRomType=='A') \
? 0xF0E4F \
: ( (cCurrentRomType!='E' && cCurrentRomType!='X' && cCurrentRomType!='P' && cCurrentRomType!='2' && cCurrentRomType!='Q') \
? ( (cCurrentRomType=='S') \
? 0x706D2 \
: 0x80850 \
) \
: 0x80F0F \
) \
) \
)
BOOL bWaveBeep = FALSE; // PC speaker
DWORD dwWaveVol = 64; // wave sound volume
static __inline VOID BeepWave(DWORD dwFrequency,DWORD dwDuration)
{
HWAVEOUT hSoundDevice;
WAVEFORMATEX wf;
WAVEHDR wh;
HANDLE hEventSound;
DWORD i;
if (dwFrequency == 0) // this is just a delay
{
Sleep(dwDuration);
return;
}
hEventSound = CreateEvent(NULL,FALSE,FALSE,NULL);
wf.wFormatTag = WAVE_FORMAT_PCM;
wf.nChannels = 1;
wf.nSamplesPerSec = MUSIC_FREQ;
wf.nAvgBytesPerSec = MUSIC_FREQ;
wf.nBlockAlign = 1;
wf.wBitsPerSample = 8;
wf.cbSize = 0;
if (waveOutOpen(&hSoundDevice,WAVE_MAPPER,&wf,(DWORD_PTR)hEventSound,0,CALLBACK_EVENT) != 0)
{
CloseHandle(hEventSound); // no sound available
return;
}
// (samp/sec) * msecs * (secs/msec) = samps
wh.dwBufferLength = (DWORD) ((QWORD) MUSIC_FREQ * dwDuration / 1000);
VERIFY(wh.lpData = HeapAlloc(hHeap,0,wh.dwBufferLength));
wh.dwBytesRecorded = 0;
wh.dwUser = 0;
wh.dwFlags = 0;
wh.dwLoops = 0;
for (i = 0; i < wh.dwBufferLength; ++i) // generate square wave
{
wh.lpData[i] = (BYTE) ((((QWORD) 2 * dwFrequency * i / MUSIC_FREQ) & 1) * dwWaveVol);
}
VERIFY(waveOutPrepareHeader(hSoundDevice,&wh,sizeof(wh)) == MMSYSERR_NOERROR);
ResetEvent(hEventSound); // prepare event for finishing
VERIFY(waveOutWrite(hSoundDevice,&wh,sizeof(wh)) == MMSYSERR_NOERROR);
WaitForSingleObject(hEventSound,INFINITE); // wait for finishing
VERIFY(waveOutUnprepareHeader(hSoundDevice,&wh,sizeof(wh)) == MMSYSERR_NOERROR);
VERIFY(waveOutClose(hSoundDevice) == MMSYSERR_NOERROR);
HeapFree(hHeap,0,wh.lpData);
CloseHandle(hEventSound);
return;
}
static __inline VOID BeepWin9x(DWORD dwFrequency,DWORD dwDuration)
{
#if !defined _WIN64
#define PIT8254_CNT2 0x42
#define PIT8254_MCR 0x43
#define PPI8255_PBO 0x61
BYTE bySpk = _inp(PPI8255_PBO); // get current status
if (dwFrequency != 0)
{
WORD wCount;
// limit low frequency
if (lFreq.QuadPart / 65535 >= dwFrequency)
dwFrequency = (DWORD) (lFreq.QuadPart / 65535) + 1;
// determine the timer frequency
wCount = (WORD) (lFreq.QuadPart / dwFrequency);
_outp(PIT8254_MCR,0xB6); // set up the timer
_outp(PIT8254_CNT2,wCount&0xff);
_outp(PIT8254_CNT2,wCount>>8);
_outp(PPI8255_PBO,bySpk | 0x03); // turn on the speaker
}
Sleep(dwDuration);
_outp(PPI8255_PBO,bySpk & 0xFC); // turn off the speaker
return;
#undef PIT8254_CNT2
#undef PIT8254_MCR
#undef PPI8255_PBO
#endif
}
static __inline VOID Return(CHIPSET* w)
{
w->rstkp=(w->rstkp-1)&7;
w->pc = w->rstk[w->rstkp];
w->rstk[w->rstkp] = 0;
return;
}
VOID External(CHIPSET* w) // Beep patch
{
BYTE fbeep;
DWORD freq,dur;
freq = Npack(w->D,5); // frequency in Hz
dur = Npack(w->C,5); // duration in ms
Nread(&fbeep,SFLAG53_56,1); // fetch system flags -53 to -56
w->carry = TRUE; // setting of no beep
if (!(fbeep & 0x8) && freq) // bit -56 clear and frequency > 0 Hz
{
if (freq > 4400) freq = 4400; // high limit of HP (SX)
if (bWaveBeep)
{
BeepWave(freq,dur); // wave output over sound card
}
else
{
OSVERSIONINFO version;
version.dwOSVersionInfoSize = sizeof(version);
GetVersionEx(&version);
if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
BeepWin9x(freq,dur); // do it the hard way on '9x / Me
}
else // VER_PLATFORM_WIN32_NT
{
if (freq < 37) freq = 37; // low limit of freqency (NT)
_ASSERT(freq >= 0x25 && freq <= 0x7FFF);
Beep(freq,dur); // NT: ok, Windows 95: default sound or standard system beep
}
}
// estimate cpu cycles for beeping time (2MHz / 4MHz)
w->cycles += dur * ((cCurrentRomType=='S') ? 2000 : 4000);
// original routine return with...
w->P = 0; // P=0
w->intk = TRUE; // INTON
w->carry = FALSE; // RTNCC
}
Return(w);
return;
}

372
SOURCE/Emu48.dsp Normal file
View file

@ -0,0 +1,372 @@
# Microsoft Developer Studio Project File - Name="Emu48" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Emu48 - Win32 DebugRegDebug4x
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Emu48.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Emu48.mak" CFG="Emu48 - Win32 DebugRegDebug4x"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Emu48 - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Emu48 - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE "Emu48 - Win32 Release Unicode" (based on "Win32 (x86) Application")
!MESSAGE "Emu48 - Win32 Debug Unicode" (based on "Win32 (x86) Application")
!MESSAGE "Emu48 - Win32 DebugRegDebug4x" (based on "Win32 (x86) Application")
!MESSAGE "Emu48 - Win32 ReleaseRegDebug4x" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Emu48 - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /Gr /MT /W3 /GX /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /Yu"pch.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "Emu48 - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /FR /Yu"pch.h" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /debug /machine:I386
!ELSEIF "$(CFG)" == "Emu48 - Win32 Release Unicode"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Emu48___"
# PROP BASE Intermediate_Dir "Emu48___"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\ReleaseUnicode"
# PROP Intermediate_Dir ".\ReleaseUnicode"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /Gr /MT /W3 /GX /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /Yu"pch.h" /FD /c
# ADD CPP /nologo /Gr /MT /W3 /GX /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "_UNICODE" /D "UNICODE" /Yu"pch.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "Emu48 - Win32 Debug Unicode"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Emu48__0"
# PROP BASE Intermediate_Dir "Emu48__0"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\DebugUnicode"
# PROP Intermediate_Dir ".\DebugUnicode"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /FR /Yu"pch.h" /FD /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "_UNICODE" /D "UNICODE" /FR /Yu"pch.h" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /debug /machine:I386
!ELSEIF "$(CFG)" == "Emu48 - Win32 DebugRegDebug4x"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Emu48___Win32_DebugRegDebug4x"
# PROP BASE Intermediate_Dir "Emu48___Win32_DebugRegDebug4x"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\DebugRegDebug4x"
# PROP Intermediate_Dir ".\DebugRegDebug4x"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /FR /Yu"pch.h" /FD /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "REGISTRY" /FR /Yu"pch.h" /FD /D REGISTRYKEY=\"Software\\Hewlett-Packard\\Debug4x\\Emu48\" /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "_DEBUG"
# ADD RSC /l 0x40c /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /debug /machine:I386
!ELSEIF "$(CFG)" == "Emu48 - Win32 ReleaseRegDebug4x"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Emu48___Win32_ReleaseRegDebug4x"
# PROP BASE Intermediate_Dir "Emu48___Win32_ReleaseRegDebug4x"
# PROP BASE Ignore_Export_Lib 0
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\ReleaseRegDebug4x"
# PROP Intermediate_Dir ".\ReleaseRegDebug4x"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /Gr /MT /W3 /GX /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /Yu"pch.h" /FD /c
# ADD CPP /nologo /Gr /MT /W3 /GX /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "STRICT" /D "REGISTRY" /Yu"pch.h" /FD /D REGISTRYKEY=\"Software\\Hewlett-Packard\\Debug4x\\Emu48\" /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x40c /d "NDEBUG"
# ADD RSC /l 0x40c /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib comdlg32.lib shell32.lib winmm.lib comctl32.lib advapi32.lib /nologo /subsystem:windows /machine:I386
!ENDIF
# Begin Target
# Name "Emu48 - Win32 Release"
# Name "Emu48 - Win32 Debug"
# Name "Emu48 - Win32 Release Unicode"
# Name "Emu48 - Win32 Debug Unicode"
# Name "Emu48 - Win32 DebugRegDebug4x"
# Name "Emu48 - Win32 ReleaseRegDebug4x"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\apple.c
# End Source File
# Begin Source File
SOURCE=.\cursor.c
# End Source File
# Begin Source File
SOURCE=.\ddeserv.c
# End Source File
# Begin Source File
SOURCE=.\debugger.c
# End Source File
# Begin Source File
SOURCE=.\disasm.c
# End Source File
# Begin Source File
SOURCE=.\display.c
# End Source File
# Begin Source File
SOURCE=.\Emu48.c
# End Source File
# Begin Source File
SOURCE=.\Emu48.rc
# End Source File
# Begin Source File
SOURCE=.\engine.c
# End Source File
# Begin Source File
SOURCE=.\external.c
# End Source File
# Begin Source File
SOURCE=.\fetch.c
# End Source File
# Begin Source File
SOURCE=.\files.c
# End Source File
# Begin Source File
SOURCE=.\i28f160.c
# End Source File
# Begin Source File
SOURCE=.\keyboard.c
# End Source File
# Begin Source File
SOURCE=.\keymacro.c
# End Source File
# Begin Source File
SOURCE=.\kml.c
# End Source File
# Begin Source File
SOURCE=.\mops.c
# End Source File
# Begin Source File
SOURCE=.\opcodes.c
# End Source File
# Begin Source File
SOURCE=.\pch.c
# ADD CPP /Yc"pch.h"
# End Source File
# Begin Source File
SOURCE=.\rpl.c
# End Source File
# Begin Source File
SOURCE=.\serial.c
# End Source File
# Begin Source File
SOURCE=.\settings.c
# End Source File
# Begin Source File
SOURCE=.\stack.c
# End Source File
# Begin Source File
SOURCE=.\timer.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
# Begin Source File
SOURCE=.\apple.h
# End Source File
# Begin Source File
SOURCE=.\color.h
# End Source File
# Begin Source File
SOURCE=.\debugger.h
# End Source File
# Begin Source File
SOURCE=.\Emu48.h
# End Source File
# Begin Source File
SOURCE=.\i28f160.h
# End Source File
# Begin Source File
SOURCE=.\io.h
# End Source File
# Begin Source File
SOURCE=.\kml.h
# End Source File
# Begin Source File
SOURCE=.\opcodes.h
# End Source File
# Begin Source File
SOURCE=.\ops.h
# End Source File
# Begin Source File
SOURCE=.\pch.h
# End Source File
# Begin Source File
SOURCE=.\types.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\CHECKBOX.BMP
# End Source File
# Begin Source File
SOURCE=.\DBGTOOL.BMP
# End Source File
# Begin Source File
SOURCE=.\Emu48.ico
# End Source File
# End Group
# End Target
# End Project

29
SOURCE/Emu48.dsw Normal file
View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Emu48"=".\Emu48.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

778
SOURCE/FETCH.C Normal file
View file

@ -0,0 +1,778 @@
/*
* fetch.c
*
* This file is part of Emu48
*
* Copyright (C) 1999 Christoph Gießelink
*
*/
#include "pch.h"
#include "Opcodes.h"
#define F 0xFF // F = function
typedef struct
{
const VOID *pLnk;
const DWORD dwTyp;
} JMPTAB;
// jump tables
static const JMPTAB oF_[] =
{
oF0, F,
oF1, F,
oF2, F,
oF3, F,
oF4, F,
oF5, F,
oF6, F,
oF7, F,
oF8, F,
oF9, F,
oFA, F,
oFB, F,
oFC, F,
oFD, F,
oFE, F,
oFF, F
};
static const JMPTAB oE_[] =
{
oE0, F,
oE1, F,
oE2, F,
oE3, F,
oE4, F,
oE5, F,
oE6, F,
oE7, F,
oE8, F,
oE9, F,
oEA, F,
oEB, F,
oEC, F,
oED, F,
oEE, F,
oEF, F
};
static const JMPTAB oD_[] =
{
oD0, F,
oD1, F,
oD2, F,
oD3, F,
oD4, F,
oD5, F,
oD6, F,
oD7, F,
oD8, F,
oD9, F,
oDA, F,
oDB, F,
oDC, F,
oDD, F,
oDE, F,
oDF, F
};
static const JMPTAB oC_[] =
{
oC0, F,
oC1, F,
oC2, F,
oC3, F,
oC4, F,
oC5, F,
oC6, F,
oC7, F,
oC8, F,
oC9, F,
oCA, F,
oCB, F,
oCC, F,
oCD, F,
oCE, F,
oCF, F
};
static const JMPTAB oBb_[] =
{
oBb0, F,
oBb1, F,
oBb2, F,
oBb3, F,
oBb4, F,
oBb5, F,
oBb6, F,
oBb7, F,
oBb8, F,
oBb9, F,
oBbA, F,
oBbB, F,
oBbC, F,
oBbD, F,
oBbE, F,
oBbF, F
};
static const JMPTAB oBa_[] =
{
oBa0, F,
oBa1, F,
oBa2, F,
oBa3, F,
oBa4, F,
oBa5, F,
oBa6, F,
oBa7, F,
oBa8, F,
oBa9, F,
oBaA, F,
oBaB, F,
oBaC, F,
oBaD, F,
oBaE, F,
oBaF, F
};
static const JMPTAB oB_[] =
{
oBa_, 2,
oBa_, 2,
oBa_, 2,
oBa_, 2,
oBa_, 2,
oBa_, 2,
oBa_, 2,
oBa_, 2,
oBb_, 2,
oBb_, 2,
oBb_, 2,
oBb_, 2,
oBb_, 2,
oBb_, 2,
oBb_, 2,
oBb_, 2
};
static const JMPTAB oAb_[] =
{
oAb0, F,
oAb1, F,
oAb2, F,
oAb3, F,
oAb4, F,
oAb5, F,
oAb6, F,
oAb7, F,
oAb8, F,
oAb9, F,
oAbA, F,
oAbB, F,
oAbC, F,
oAbD, F,
oAbE, F,
oAbF, F
};
static const JMPTAB oAa_[] =
{
oAa0, F,
oAa1, F,
oAa2, F,
oAa3, F,
oAa4, F,
oAa5, F,
oAa6, F,
oAa7, F,
oAa8, F,
oAa9, F,
oAaA, F,
oAaB, F,
oAaC, F,
oAaD, F,
oAaE, F,
oAaF, F
};
static const JMPTAB oA_[] =
{
oAa_, 2,
oAa_, 2,
oAa_, 2,
oAa_, 2,
oAa_, 2,
oAa_, 2,
oAa_, 2,
oAa_, 2,
oAb_, 2,
oAb_, 2,
oAb_, 2,
oAb_, 2,
oAb_, 2,
oAb_, 2,
oAb_, 2,
oAb_, 2
};
static const JMPTAB o9b_[] =
{
o9b0, F,
o9b1, F,
o9b2, F,
o9b3, F,
o9b4, F,
o9b5, F,
o9b6, F,
o9b7, F,
o9b8, F,
o9b9, F,
o9bA, F,
o9bB, F,
o9bC, F,
o9bD, F,
o9bE, F,
o9bF, F
};
static const JMPTAB o9a_[] =
{
o9a0, F,
o9a1, F,
o9a2, F,
o9a3, F,
o9a4, F,
o9a5, F,
o9a6, F,
o9a7, F,
o9a8, F,
o9a9, F,
o9aA, F,
o9aB, F,
o9aC, F,
o9aD, F,
o9aE, F,
o9aF, F
};
static const JMPTAB o9_[] =
{
o9a_, 2,
o9a_, 2,
o9a_, 2,
o9a_, 2,
o9a_, 2,
o9a_, 2,
o9a_, 2,
o9a_, 2,
o9b_, 2,
o9b_, 2,
o9b_, 2,
o9b_, 2,
o9b_, 2,
o9b_, 2,
o9b_, 2,
o9b_, 2
};
static const JMPTAB o8B_[] =
{
o8B0, F,
o8B1, F,
o8B2, F,
o8B3, F,
o8B4, F,
o8B5, F,
o8B6, F,
o8B7, F,
o8B8, F,
o8B9, F,
o8BA, F,
o8BB, F,
o8BC, F,
o8BD, F,
o8BE, F,
o8BF, F
};
static const JMPTAB o8A_[] =
{
o8A0, F,
o8A1, F,
o8A2, F,
o8A3, F,
o8A4, F,
o8A5, F,
o8A6, F,
o8A7, F,
o8A8, F,
o8A9, F,
o8AA, F,
o8AB, F,
o8AC, F,
o8AD, F,
o8AE, F,
o8AF, F
};
static const JMPTAB o81B_[] =
{
o_invalid4, F,
o81B1, F, // normally o_invalid4, beep patch
o81B2, F,
o81B3, F,
o81B4, F,
o81B5, F,
o81B6, F,
o81B7, F,
o_invalid4, F,
o_invalid4, F,
o_invalid4, F,
o_invalid4, F,
o_invalid4, F,
o_invalid4, F,
o_invalid4, F,
o_invalid4, F
};
static const JMPTAB o81Af2_[] =
{
o81Af20, F,
o81Af21, F,
o81Af22, F,
o81Af23, F,
o81Af24, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o81Af28, F,
o81Af29, F,
o81Af2A, F,
o81Af2B, F,
o81Af2C, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F
};
static const JMPTAB o81Af1_[] =
{
o81Af10, F,
o81Af11, F,
o81Af12, F,
o81Af13, F,
o81Af14, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o81Af18, F,
o81Af19, F,
o81Af1A, F,
o81Af1B, F,
o81Af1C, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F
};
static const JMPTAB o81Af0_[] =
{
o81Af00, F,
o81Af01, F,
o81Af02, F,
o81Af03, F,
o81Af04, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o81Af08, F,
o81Af09, F,
o81Af0A, F,
o81Af0B, F,
o81Af0C, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F
};
static const JMPTAB o81A_[] =
{
o81Af0_, 5,
o81Af1_, 5,
o81Af2_, 5,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F
};
static const JMPTAB o819_[] =
{
o819f0, F,
o819f1, F,
o819f2, F,
o819f3, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F
};
static const JMPTAB o818_[] =
{
o818f0x, F,
o818f1x, F,
o818f2x, F,
o818f3x, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o818f8x, F,
o818f9x, F,
o818fAx, F,
o818fBx, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F,
o_invalid6, F
};
static const JMPTAB o81_[] =
{
o810, F,
o811, F,
o812, F,
o813, F,
o814, F,
o815, F,
o816, F,
o817, F,
o818_, 4,
o819_, 4,
o81A_, 4,
o81B_, 3,
o81C, F,
o81D, F,
o81E, F,
o81F, F
};
static const JMPTAB o8081_[] =
{
o80810, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F,
o_invalid5, F
};
static const JMPTAB o808_[] =
{
o8080, F,
o8081_, 4,
o8082X, F,
o8083, F,
o8084n, F,
o8085n, F,
o8086n, F,
o8087n, F,
o8088n, F,
o8089n, F,
o808An, F,
o808Bn, F,
o808C, F,
o808D, F,
o808E, F,
o808F, F
};
static const JMPTAB o80_[] =
{
o800, F,
o801, F,
o802, F,
o803, F,
o804, F,
o805, F,
o806, F,
o807, F,
o808_, 3,
o809, F,
o80A, F,
o80B, F,
o80Cn, F,
o80Dn, F,
o80E, F,
o80Fn, F
};
static const JMPTAB o8_[] =
{
o80_, 2,
o81_, 2,
o82n, F,
o83n, F,
o84n, F,
o85n, F,
o86n, F,
o87n, F,
o88n, F,
o89n, F,
o8A_, 2,
o8B_, 2,
o8Cd4, F,
o8Dd5, F,
o8Ed4, F,
o8Fd5, F
};
static const JMPTAB o15_[] =
{
o150a, F,
o151a, F,
o152a, F,
o153a, F,
o154a, F,
o155a, F,
o156a, F,
o157a, F,
o158x, F,
o159x, F,
o15Ax, F,
o15Bx, F,
o15Cx, F,
o15Dx, F,
o15Ex, F,
o15Fx, F
};
static const JMPTAB o14_[] =
{
o140, F,
o141, F,
o142, F,
o143, F,
o144, F,
o145, F,
o146, F,
o147, F,
o148, F,
o149, F,
o14A, F,
o14B, F,
o14C, F,
o14D, F,
o14E, F,
o14F, F
};
static const JMPTAB o13_[] =
{
o130, F,
o131, F,
o132, F,
o133, F,
o134, F,
o135, F,
o136, F,
o137, F,
o138, F,
o139, F,
o13A, F,
o13B, F,
o13C, F,
o13D, F,
o13E, F,
o13F, F
};
static const JMPTAB o12_[] =
{
o120, F,
o121, F,
o122, F,
o123, F,
o124, F,
o_invalid3, F,
o_invalid3, F,
o_invalid3, F,
o128, F,
o129, F,
o12A, F,
o12B, F,
o12C, F,
o_invalid3, F,
o_invalid3, F,
o_invalid3, F
};
static const JMPTAB o11_[] =
{
o110, F,
o111, F,
o112, F,
o113, F,
o114, F,
o_invalid3, F,
o_invalid3, F,
o_invalid3, F,
o118, F,
o119, F,
o11A, F,
o11B, F,
o11C, F,
o_invalid3, F,
o_invalid3, F,
o_invalid3, F
};
static const JMPTAB o10_[] =
{
o100, F,
o101, F,
o102, F,
o103, F,
o104, F,
o_invalid3, F,
o_invalid3, F,
o_invalid3, F,
o108, F,
o109, F,
o10A, F,
o10B, F,
o10C, F,
o_invalid3, F,
o_invalid3, F,
o_invalid3, F
};
static const JMPTAB o1_[] =
{
o10_, 2,
o11_, 2,
o12_, 2,
o13_, 2,
o14_, 2,
o15_, 2,
o16x, F,
o17x, F,
o18x, F,
o19d2, F,
o1Ad4, F,
o1Bd5, F,
o1Cx, F,
o1Dd2, F,
o1Ed4, F,
o1Fd5, F
};
static const JMPTAB o0E_[] =
{
o0Ef0, F,
o0Ef1, F,
o0Ef2, F,
o0Ef3, F,
o0Ef4, F,
o0Ef5, F,
o0Ef6, F,
o0Ef7, F,
o0Ef8, F,
o0Ef9, F,
o0EfA, F,
o0EfB, F,
o0EfC, F,
o0EfD, F,
o0EfE, F,
o0EfF, F
};
static const JMPTAB o0_[] =
{
o00, F,
o01, F,
o02, F,
o03, F,
o04, F,
o05, F,
o06, F,
o07, F,
o08, F,
o09, F,
o0A, F,
o0B, F,
o0C, F,
o0D, F,
o0E_, 3,
o0F, F
};
static const JMPTAB o_[] =
{
o0_, 1,
o1_, 1,
o2n, F,
o3X, F,
o4d2, F,
o5d2, F,
o6d3, F,
o7d3, F,
o8_, 1,
o9_, 1,
oA_, 1,
oB_, 1,
oC_, 1,
oD_, 1,
oE_, 1,
oF_, 1
};
// opcode dispatcher
VOID EvalOpcode(LPBYTE I)
{
DWORD dwTemp,dwIndex = 0;
JMPTAB const *pJmpTab = o_;
do
{
dwTemp = I[dwIndex]; // table entry
_ASSERT(dwTemp <= 0xf); // found packed data
dwIndex = pJmpTab[dwTemp].dwTyp; // next pointer type
pJmpTab = pJmpTab[dwTemp].pLnk; // next pointer to table/function
}
while (dwIndex != F); // reference to table? -> again
((VOID (*)(LPBYTE)) pJmpTab)(I); // call function
return;
}

1553
SOURCE/FILES.C Normal file

File diff suppressed because it is too large Load diff

716
SOURCE/I28F160.C Normal file
View file

@ -0,0 +1,716 @@
/*
* i28f160.c
*
* This file is part of Emu48
*
* Copyright (C) 2000 Christoph Gießelink
*
*/
#include "pch.h"
#include "Emu48.h"
#include "i28f160.h"
#define ARRAYSIZEOF(a) (sizeof(a) / sizeof(a[0]))
// Flash Command Set
#define READ_ARRAY 0xFF
#define READ_ID_CODES 0x90
#define READ_QUERY 0x98
#define READ_STATUS_REG 0x70
#define CLEAR_STATUS_REG 0x50
#define WRITE_BUFFER 0xE8
#define WORD_BYTE_PROG1 0x40
#define WORD_BYTE_PROG2 0x10
#define BLOCK_ERASE 0x20
#define BLOCK_ERASE_SUSPEND 0xB0
#define BLOCK_ERASE_RESUME 0xD0
#define STS_CONFIG 0xB8
#define SET_CLR_BLOCK_LOCK 0x60
#define FULL_CHIP_ERASE 0x30
#define CONFIRM 0xD0
// Status Register Definition
#define WSMS 0x80 // WRITE STATE MACHINE STATUS
#define ESS 0x40 // ERASE SUSPEND STATUS
#define ECLBS 0x20 // ERASE AND CLEAR LOCK-BIT STATUS
#define BWSLBS 0x10 // PROGRAM AND SET LOCK-BIT STATUS
#define VPPS 0x08 // Vpp STATUS
#define BWSS 0x04 // PROGRAM SUSPEND STATUS
#define DPS 0x02 // DEVICE PROTECT STATUS
// Extended Status Register Definition
#define WBS 0x80 // WRITE BUFFER STATUS
// write state defines
#define WRS_DATA 0 // idle state
#define WRS_WR_BUFFER_N 1 // write buffer no. of data
#define WRS_WR_BUFFER_D 2 // write buffer data
#define WRS_WR_BUFFER_C 3 // write buffer confirm
#define WRS_WR_BYTE 4 // write byte/word
#define WRS_BLOCK_ERASE 5 // block erase
#define WRS_CHIP_ERASE 6 // full chip erase
#define WRS_STS_PIN_CONFIG 7 // STS pin Configuration
#define WRS_LOCK_BITS 8 // Set/Clear Block Lock-Bits
// read state defines
#define RDS_DATA 0 // data read
#define RDS_ID 1 // read identifier codes
#define RDS_QUERY 2 // read query
#define RDS_SR 3 // read status register
#define RDS_XSR 4 // read extended status register
// global data
WSMSET WSMset;
BOOL bWP = FALSE; // WP# = low, locked blocks cannot be erased
// function prototypes
// write function WSM state
static VOID WrStateIdle(BYTE a, DWORD d);
static VOID WrStateE8(DWORD d);
static VOID WrStateE8N(BYTE a, DWORD d);
static VOID WrStateE8D(BYTE a, DWORD d);
static VOID WrStateE8C(BYTE a, DWORD d);
static VOID WrState40(DWORD d);
static VOID WrState40D(BYTE a, DWORD d);
static VOID WrState20(DWORD d);
static VOID WrState20C(BYTE a, DWORD d);
static VOID WrState30(DWORD d);
static VOID WrState30C(BYTE a, DWORD d);
static VOID WrStateB8(DWORD d);
static VOID WrStateB8D(BYTE a, DWORD d);
static VOID WrState60(DWORD d);
static VOID WrState60D(BYTE a, DWORD d);
static VOID (*CONST fnWrState[])(BYTE a, DWORD d) =
{
WrStateIdle,
WrStateE8N, WrStateE8D, WrStateE8C,
WrState40D,
WrState20C,
WrState30C,
WrStateB8D,
WrState60D
};
// read function WSM state
static BYTE RdStateData(DWORD d);
static BYTE RdStateId(DWORD d);
static BYTE RdStateQuery(DWORD d);
static BYTE RdStateSR(DWORD d);
static BYTE RdStateXSR(DWORD d);
static BYTE (*CONST fnRdState[])(DWORD d) =
{
RdStateData, RdStateId, RdStateQuery, RdStateSR, RdStateXSR
};
// read query table
// device address A16-A1, A0 unused
static CONST BYTE byQueryTab[] =
{
// access with "Read Identifier Codes" command
// Identifier codes
0xB0, // 00, Manufacturer Code
0xD0, // 01, Device Code (16 Mbit)
0x00, // 02, Block Lock Configuration
0x02, // 03, ??
0x00, // 04, Reserved for vendor-specific information
0x00, // 05, "
0x00, // 06, "
0x00, // 07, "
0x00, // 08, "
0x00, // 09, "
0x00, // 0A, "
0x00, // 0B, "
0x00, // 0C, "
0x00, // 0D, "
0x00, // 0E, "
0x00, // 0F, "
// access with "Read Query" command
// CFI query identification string
0x51, // 10, Query-Unique ASCII string "Q"
0x52, // 11, Query-Unique ASCII string "R"
0x59, // 12, Query-Unique ASCII string "Y"
0x01, // 13, Primary Vendor Command Set and Control Interface ID CODE
0x00, // 14, "
0x31, // 15, Address for Primary Algorithm Extended Query Table
0x00, // 16, "
0x00, // 17, Alternate Vendor Command Set and Control Interface ID Code
0x00, // 18, "
0x00, // 19, Address for Secondary Algorithm Extended Query Table
0x00, // 1A, "
// System interface information
0x30, // 1B, Vcc Logic Supply Minimum Program/Erase Voltage (0x27 intel doc, 0x30 real chip)
0x55, // 1C, Vcc Logic Supply Maximum Program/Erase Voltage
0x30, // 1D, Vpp [Programming] Supply Minimum Program/Erase Voltage (0x27 intel doc, 0x30 real chip)
0x55, // 1E, Vpp [Programming] Supply Maximum Program/Erase Voltage
0x03, // 1F, Typical Time-Out per Single Byte/Word Program
0x06, // 20, Typical Time-Out for Max. Buffer Write
0x0A, // 21, Typical Time-Out per Individual Block Erase
0x0F, // 22, Typical Time-Out for Full Chip Erase
0x04, // 23, Maximum Time-Out for Byte/Word Program
0x04, // 24, Maximum Time-Out for Buffer Write
0x04, // 25, Maximum Time-Out per Individual Block Erase
0x04, // 26, Maximum Time-Out for Full Chip Erase
0x15, // 27, Device Size
0x02, // 28, Flash Device Interface Description
0x00, // 29, "
0x05, // 2A, Maximum Number of Bytes in Write Buffer
0x00, // 2B, "
0x01, // 2C, Number of Erase Block Regions within Device
0x1F, // 2D, Erase Block Region Information
0x00, // 2E, "
0x00, // 2F, "
0x01, // 30, "
// Intel-specific extended query table
0x50, // 31, Primary Extended Query Table, Unique ASCII string "P"
0x52, // 32, Primary Extended Query Table, Unique ASCII string "R"
0x49, // 33, Primary Extended Query Table, Unique ASCII string "I"
0x31, // 34, Major Version Number, ASCII
0x30, // 35, Minor Version Number, ASCII
0x0F, // 36, Optional Feature & Command Support
0x00, // 37, "
0x00, // 38, "
0x00, // 39, "
0x01, // 3A, Supported Functions after Suspend
0x03, // 3B, Block Status Register Mask
0x00, // 3C, "
0x50, // 3D, Vcc Logic Supply Optimum Program/Erase voltage
0x50, // 3E, Vpp [Programming] Supply Optimum Program/Erase voltage
0x00 // 3F, ??
};
//
// write state functions
//
static VOID WrStateIdle(BYTE a, DWORD d)
{
WSMset.bRomArray = FALSE; // register access
switch(a)
{
case READ_ARRAY: // read array mode, normal operation
WSMset.bRomArray = TRUE; // data array access
WSMset.uWrState = WRS_DATA;
WSMset.uRdState = RDS_DATA;
break;
case READ_ID_CODES: // read identifier codes register
WSMset.uRdState = RDS_ID;
break;
case READ_QUERY: // read query register
WSMset.uRdState = RDS_QUERY;
break;
case READ_STATUS_REG: // read status register
WSMset.uRdState = RDS_SR;
break;
case CLEAR_STATUS_REG: // clear status register
WSMset.byStatusReg = 0;
break;
case WRITE_BUFFER: // write to buffer
WrStateE8(d);
break;
case WORD_BYTE_PROG1:
case WORD_BYTE_PROG2: // byte/word program
WrState40(d);
break;
case BLOCK_ERASE: // block erase
WrState20(d);
break;
case BLOCK_ERASE_SUSPEND: // block erase, word/byte program suspend
WSMset.byStatusReg |= WSMS; // operation suspended
WSMset.byStatusReg &= ~ESS; // block erase completed (because no timing emulation)
WSMset.byStatusReg &= ~BWSS; // program completed (because no timing emulation)
WSMset.uRdState = RDS_SR;
break;
case BLOCK_ERASE_RESUME: // block erase, word/byte program resume
WSMset.byStatusReg &= ~WSMS; // operation in progress
WSMset.byStatusReg &= ~ESS; // block erase in progress
WSMset.byStatusReg &= ~BWSS; // program in progress
WSMset.byStatusReg |= WSMS; // operation completed (because no timing emulation)
WSMset.uRdState = RDS_SR;
break;
case STS_CONFIG:
WSMset.bRomArray = bFlashRomArray; // old access mode
WrStateB8(d);
break;
case SET_CLR_BLOCK_LOCK: // set/clear block lock-bits
WrState60(d);
break;
case FULL_CHIP_ERASE: // full chip erase
WrState30(d);
break;
default: // wrong command
WSMset.bRomArray = bFlashRomArray; // old access mode
break;
}
if(bFlashRomArray != WSMset.bRomArray) // new access mode
{
bFlashRomArray = WSMset.bRomArray; // change register access
Map(0x00,0xFF); // update memory mapping
UpdatePatches(bFlashRomArray); // patch/unpatch ROM again
}
return;
}
// write to buffer initial command
static VOID WrStateE8(DWORD d)
{
// @todo add 2nd write buffer implementation
// @todo add program timing implementation
WSMset.byExStatusReg = 0; // no write buffer
if (WSMset.byWrite1No == 0) // buffer1 available
{
WSMset.byWrite1No = 1; // buffer1 in use
WSMset.dwWrite1Addr = d; // byte block address of buffer1
WSMset.byExStatusReg = WBS; // write buffer available
// fill write buffer
FillMemory(WSMset.pbyWrite1,ARRAYSIZEOF(WSMset.pbyWrite1),0xFF);
WSMset.uWrState = WRS_WR_BUFFER_N; // set state machine
WSMset.uRdState = RDS_XSR;
}
return;
}
// write to buffer number of byte
static VOID WrStateE8N(BYTE a, DWORD d)
{
if (a < (1 << byQueryTab[0x2A])) // byte is length information
{
WSMset.byWrite1No += a; // save no. of byte to program
WSMset.byWrite1Size = a; // save size to check write buffer boundaries
WSMset.dwWrite1Addr = d; // byte block address of buffer1
WSMset.byStatusReg &= ~WSMS; // state machine busy
WSMset.uWrState = WRS_WR_BUFFER_D;
}
else
{
WSMset.byWrite1No = 0; // free write buffer
// improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
WSMset.byStatusReg |= WSMS; // data written
WSMset.uWrState = WRS_DATA;
}
WSMset.uRdState = RDS_SR;
return;
}
// write to buffer data
static VOID WrStateE8D(BYTE a, DWORD d)
{
// first data byte
if (WSMset.byWrite1No == WSMset.byWrite1Size + 1)
{
DWORD dwBlockMask = ~(((byQueryTab[0x30] << 8) | byQueryTab[0x2F]) * 256 - 1);
// same block
if ((WSMset.dwWrite1Addr & dwBlockMask) == (d & dwBlockMask))
{
WSMset.dwWrite1Addr = d; // byte block address of buffer1
WSMset.pbyWrite1[0] = a; // save byte
}
else
{
WSMset.byWrite1No = 0; // free write buffer
// improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
WSMset.byStatusReg |= WSMS; // data written
WSMset.uWrState = WRS_DATA;
return;
}
}
else
{
// write address within buffer
if (d >= WSMset.dwWrite1Addr && d <= WSMset.dwWrite1Addr + WSMset.byWrite1Size)
{
// save byte in buffer
WSMset.pbyWrite1[d-WSMset.dwWrite1Addr] = a;
}
else
{
WSMset.byWrite1No = 0; // free write buffer
// improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
WSMset.byStatusReg |= WSMS; // data written
WSMset.uWrState = WRS_DATA;
return;
}
}
if (--WSMset.byWrite1No == 0) // last byte written
WSMset.uWrState = WRS_WR_BUFFER_C; // goto confirm state
return;
}
// write to buffer confirm
static VOID WrStateE8C(BYTE a, DWORD d)
{
if (CONFIRM == a) // write buffer confirm?
{
BYTE byPos;
d = WSMset.dwWrite1Addr << 1; // nibble start address
for (byPos = 0; byPos <= WSMset.byWrite1Size; ++byPos)
{
a = WSMset.pbyWrite1[byPos]; // get char from buffer
_ASSERT(d+1 < dwRomSize); // address valid?
// no error set in BWSLBS, because I could alway program a "0"
*(pbyRom+d++) &= (a & 0x0F); // write LSB
*(pbyRom+d++) &= (a >> 4); // write MSB
}
}
else
{
WSMset.byWrite1No = 0; // free write buffer
// improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
}
WSMset.byStatusReg |= WSMS; // data written
WSMset.uWrState = WRS_DATA;
return;
}
// byte/word program initial command
static VOID WrState40(DWORD d)
{
WSMset.byStatusReg &= ~WSMS; // state machine busy
WSMset.uWrState = WRS_WR_BYTE;
WSMset.uRdState = RDS_SR;
return;
UNREFERENCED_PARAMETER(d);
}
// byte/word program data
static VOID WrState40D(BYTE a, DWORD d)
{
d <<= 1; // nibble start address
_ASSERT(d+1 < dwRomSize); // address valid?
// no error set in BWSLBS, because I could alway program a "0"
*(pbyRom+d++) &= (a & 0x0F); // write LSB
*(pbyRom+d) &= (a >> 4); // write MSB
WSMset.byStatusReg |= WSMS; // data written
WSMset.uWrState = WRS_DATA;
return;
}
// block erase initial command
static VOID WrState20(DWORD d)
{
WSMset.byStatusReg &= ~WSMS; // state machine busy
WSMset.uWrState = WRS_BLOCK_ERASE;
WSMset.uRdState = RDS_SR;
return;
UNREFERENCED_PARAMETER(d);
}
// block erase data & confirm
static VOID WrState20C(BYTE a, DWORD d)
{
if (CONFIRM == a) // block erase confirm?
{
_ASSERT((d>>16) < ARRAYSIZEOF(WSMset.byLockCnfg));
if (WSMset.byLockCnfg[d>>16] & 1) // lock bit of block is set
{
WSMset.byStatusReg |= ECLBS; // error in block erasure
WSMset.byStatusReg |= DPS; // lock bit detected
}
else
{
DWORD dwBlockSize = ((byQueryTab[0x30] << 8) | byQueryTab[0x2F]) * 256;
d &= ~(dwBlockSize-1); // start of block
dwBlockSize *= 2; // block size in nibbles
_ASSERT(d+dwBlockSize <= dwRomSize); // address valid?
// write 128K nibble
FillMemory(pbyRom + (d << 1),dwBlockSize,0x0F);
}
}
else
{
// improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
}
WSMset.byStatusReg |= WSMS; // block erased
WSMset.uWrState = WRS_DATA;
return;
}
// full chip erase initial command
static VOID WrState30(DWORD d)
{
WSMset.byStatusReg &= ~WSMS; // state machine busy
WSMset.uWrState = WRS_CHIP_ERASE;
WSMset.uRdState = RDS_SR;
return;
UNREFERENCED_PARAMETER(d);
}
// full chip erase confirm
static VOID WrState30C(BYTE a, DWORD d)
{
if (CONFIRM == a) // chip erase confirm?
{
UINT i;
WORD wNoOfBlocks = (byQueryTab[0x2E] << 8) | byQueryTab[0x2D];
DWORD dwBlockSize = ((byQueryTab[0x30] << 8) | byQueryTab[0x2F]) * 256;
LPBYTE pbyBlock = pbyRom;
dwBlockSize *= 2; // block size in nibbles
for (i = 0; i <= wNoOfBlocks; ++i) // check all blocks
{
_ASSERT((i+1)*dwBlockSize <= dwRomSize);
_ASSERT(i < ARRAYSIZEOF(WSMset.byLockCnfg));
// lock bit of block is set & WP# = low, locked blocks cannot be erased
if ((WSMset.byLockCnfg[i] & 1) == 0 || bWP != FALSE)
{
WSMset.byLockCnfg[i] = 0; // clear block lock bit
// write 128K nibble
FillMemory(pbyBlock,dwBlockSize,0x0F);
}
pbyBlock += dwBlockSize; // next block
}
}
else
{
// improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
}
WSMset.byStatusReg |= WSMS; // chip erased
WSMset.uWrState = WRS_DATA;
return;
UNREFERENCED_PARAMETER(d);
}
// STS pin Configuration initial command
static VOID WrStateB8(DWORD d)
{
WSMset.uWrState = WRS_STS_PIN_CONFIG;
return;
UNREFERENCED_PARAMETER(d);
}
// STS pin Configuration data
static VOID WrStateB8D(BYTE a, DWORD d)
{
// no emulation of STS pin Configuration
WSMset.uWrState = WRS_DATA;
return;
UNREFERENCED_PARAMETER(a);
UNREFERENCED_PARAMETER(d);
}
// Set/Clear block Lock-Bits initial command
static VOID WrState60(DWORD d)
{
WSMset.byStatusReg &= ~WSMS; // state machine busy
WSMset.uWrState = WRS_LOCK_BITS;
WSMset.uRdState = RDS_SR;
return;
UNREFERENCED_PARAMETER(d);
}
// Set/Clear block Lock-Bits confirm
static VOID WrState60D(BYTE a, DWORD d)
{
UINT i;
switch(a)
{
case 0x01: // set block lock bit
_ASSERT((d>>16) < ARRAYSIZEOF(WSMset.byLockCnfg));
if (bWP) // WP# = high, can change block lock status
WSMset.byLockCnfg[d>>16] = 1; // set block lock bit
else
WSMset.byStatusReg |= (BWSLBS | DPS); // device protect detect, WP# = low
break;
case CONFIRM: // clear block lock bits
if (bWP) // WP# = high, can change block lock status
{
WORD wNoOfBlocks = (byQueryTab[0x2E] << 8) | byQueryTab[0x2D];
for (i = 0; i <= wNoOfBlocks; ++i) // clear all lock bits
{
_ASSERT(i < ARRAYSIZEOF(WSMset.byLockCnfg));
WSMset.byLockCnfg[i] = 0; // clear block lock bit
}
}
else
{
WSMset.byStatusReg |= (ECLBS | DPS); // device protect detect, WP# = low
}
break;
default: // improper command sequence
WSMset.byStatusReg |= (ECLBS | BWSLBS);
}
WSMset.byStatusReg |= WSMS; // block lock-bit changed
WSMset.uWrState = WRS_DATA;
return;
}
//
// read state functions
//
// read array
static BYTE RdStateData(DWORD d)
{
d <<= 1; // nibble address
_ASSERT(d+1 < dwRomSize); // address valid?
return *(pbyRom+d)|(*(pbyRom+d+1)<<4); // get byte
}
// read identifier codes
static BYTE RdStateId(DWORD d)
{
BYTE byData;
d >>= 1; // A0 is not connected, ignore it
if ((d & 0x03) != 0x02) // id code request
{
d &= 0x03; // data repetition
byData = byQueryTab[d]; // get data from first 4 bytes id/query table
}
else // block lock table
{
UINT uIndex = d >> 15; // index into lock table
_ASSERT(uIndex < ARRAYSIZEOF(WSMset.byLockCnfg));
byData = WSMset.byLockCnfg[uIndex]; // get data from block lock table
d &= 0x1F; // data repetition
if (d >= 4) byData |= 0x02; // set bit 1 on wrong ID adresses
}
return byData;
}
// read query
static BYTE RdStateQuery(DWORD d)
{
BYTE byData;
d >>= 1; // A0 is not connected, ignore it
if ((d & 0x7F) != 0x02) // query request
{
d &= 0x7F; // data repetition
// get data from id/query table
byData = (d >= 0x40 && d < 0x50) ? 0 : byQueryTab[d&0x3F];
}
else // block lock table
{
UINT uIndex = d >> 15; // index into lock table
_ASSERT(uIndex < ARRAYSIZEOF(WSMset.byLockCnfg));
byData = WSMset.byLockCnfg[uIndex]; // get data from block lock table
}
return byData;
}
// read status register
static BYTE RdStateSR(DWORD d)
{
return WSMset.byStatusReg;
UNREFERENCED_PARAMETER(d);
}
// read extended status register
static BYTE RdStateXSR(DWORD d)
{
return WSMset.byExStatusReg;
UNREFERENCED_PARAMETER(d);
}
//
// public functions
//
VOID FlashInit(VOID)
{
ZeroMemory(&WSMset,sizeof(WSMset));
strcpy(WSMset.byType,"WSM"); // Write State Machine header
WSMset.uSize = sizeof(WSMset); // size of this structure
WSMset.byVersion = WSMVER; // version of flash implementation structure
// factory setting of locking bits
WSMset.byLockCnfg[0] = 0x01; // first 64KB block is locked
WSMset.uWrState = WRS_DATA;
WSMset.uRdState = RDS_DATA;
// data mode of ROM
WSMset.bRomArray = bFlashRomArray = TRUE;
return;
}
VOID FlashRead(BYTE *a, DWORD d, UINT s)
{
BYTE v;
while (s) // each nibble
{
// output muliplexer
_ASSERT(WSMset.uRdState < ARRAYSIZEOF(fnRdState));
v = fnRdState[WSMset.uRdState](d>>1);
if ((d & 1) == 0) // even address
{
*a++ = v & 0xf; ++d; --s;
}
if (s && (d & 1)) // odd address
{
*a++ = v >> 4; ++d; --s;
}
}
return;
}
VOID FlashWrite(BYTE *a, DWORD d, UINT s)
{
BYTE v;
DWORD p;
while (s) // each nibble
{
p = d >> 1; // byte address
if (s > 1 && (d & 1) == 0) // more than one byte on even address
{
v = *a++; // LSB
v |= *a++ << 4; // MSB
d += 2; s -= 2;
}
else
{
// get byte from output muliplexer
_ASSERT(WSMset.uRdState < ARRAYSIZEOF(fnRdState));
v = fnRdState[WSMset.uRdState](p);
if (d & 1) // odd address
v = (v & 0x0F) | (*a << 4); // replace MSB
else // even address
v = (v & 0xF0) | *a; // replace LSB
++a; ++d; --s;
}
_ASSERT(WSMset.uWrState < ARRAYSIZEOF(fnWrState));
fnWrState[WSMset.uWrState](v,p); // WSM
}
return;
}

41
SOURCE/I28F160.H Normal file
View file

@ -0,0 +1,41 @@
/*
* i28f160.h
*
* This file is part of Emu48
*
* Copyright (C) 2000 Christoph Gießelink
*
*/
#define WSMVER 0 // version of flash implementation structure
#define WSMSET WSMset_t
typedef struct
{
BYTE byType[4]; // "WSM"
UINT uSize; // size of this structure
BYTE byVersion; // WSM version
BOOL bRomArray; // copy of bFlashRomArray
BYTE byLockCnfg[32]; // block lock table
UINT uWrState; // state of write function WSM
UINT uRdState; // state of read function WSM
BYTE byStatusReg; // status register
BYTE byExStatusReg; // extended status register
BYTE byWrite1No; // no. of written data in write buffer1
BYTE byWrite1Size; // no. of valid data in write buffer1
DWORD dwWrite1Addr; // destination address of buffer1
BYTE pbyWrite1[32]; // write buffer1
// BYTE byWrite2No; // no. of written data in write buffer2
// BYTE byWrite2Size; // no. of valid data in write buffer2
// DWORD dwWrite2Addr; // destination address of buffer2
// BYTE pbyWrite2[32]; // write buffer2
} WSMset_t;
// i28f160.h
extern WSMSET WSMset;
extern BOOL bWP;
extern VOID FlashInit(VOID);
extern VOID FlashRead(BYTE *a, DWORD d, UINT s);
extern VOID FlashWrite(BYTE *a, DWORD d, UINT s);
extern DWORD FlashROMAddr(DWORD d); // CdB for HP: add apples

150
SOURCE/IO.H Normal file
View file

@ -0,0 +1,150 @@
/*
* io.h
*
* This file is part of Emu48
*
* Copyright (C) 1999 Christoph Gießelink
*
*/
// I/O addresses without mapping offset
#define BITOFFSET 0x00 // Display bit offset and DON
#define CRC 0x04 // Crc (16 bit, LSB first)
#define LPD 0x08 // Low Power Detection
#define LPE 0x09 // Low Power detection Enable
#define ANNCTRL 0x0b // Annunciator Control (2 nibble)
#define BAUD 0x0d // Baudrate (Bit 2-0)
#define CARDCTL 0x0e // card control
#define CARDSTAT 0x0f // card status
#define IOC 0x10 // IO CONTROL
#define RCS 0x11 // RCS
#define TCS 0x12 // TCS
#define CRER 0x13 // CRER
#define RBR_LSB 0x14 // RBR low nibble
#define RBR_MSB 0x15 // RBR high nibble
#define TBR_LSB 0x16 // TBR low nibble
#define TBR_MSB 0x17 // TBR high nibble
#define SRQ1 0x18 // SRQ1
#define SRQ2 0x19 // SRQ2
#define IR_CTRL 0x1a // IR CONTROL
#define LCR 0x1c // Led Control Register
#define DISP1CTL 0x20 // Display Start Address
#define LINENIBS 0x25 // Display Line Offset
#define LINECOUNT 0x28 // Display Line Counter
#define TIMER1_CTRL 0x2e // Timer1 Control
#define TIMER2_CTRL 0x2f // Timer2 Control
#define DISP2CTL 0x30 // Display Secondary Start Address
#define TIMER1 0x37 // Timer1 (4 bit)
#define TIMER2 0x38 // Timer2 (32 bit, LSB first)
// 0x00 Display bit offset and DON [DON OFF2 OFF1 OFF0]
#define DON 0x08 // Display On
#define OFF2 0x04 // Display OFFset Bit2
#define OFF1 0x02 // Display OFFset Bit1
#define OFF0 0x01 // Display OFFset Bit0
// 0x08 Low Power Detection [LB2 LB1 LB0 VLBI]
#define LB2 0x08 // Low Battery indicator memory port 2
#define LB1 0x04 // Low Battery indicator memory port 1
#define LB0 0x02 // Low Battery indicator system battery
#define VLBI 0x01 // Very Low Battery Indicator
// 0x09 Low Power detection Enable [ELBI EVLBI GRAM RST]
#define ELBI 0x08 // Enable Low Battery Indicator
#define EVLBI 0x04 // Enable Very Low Battery Indicator
#define GRAM 0x02 // Glitch sensitive RAM
#define RST 0x01 // ReSeT
// 0x0b Annunciator Control [AON XTRA LA6 LA5] [LA4 LA3 LA2 LA1]
#define AON 0x80 // Annunciators on
#define LXTRA 0x40 // does nothing
#define LA6 0x20 // LA6 - Transmitting
#define LA5 0x10 // LA5 - Busy
#define LA4 0x08 // LA4 - Alert
#define LA3 0x04 // LA3 - Alpha
#define LA2 0x02 // LA2 - ALT Shift
#define LA1 0x01 // LA1 - Shift
// 0x0d SERIAL Baud Rate [UCK BD2 BD1 BD0]
#define UCK 0x08 // Uart ClocK
#define BD2 0x04 // BauDrate Bit2
#define BD1 0x02 // BauDrate Bit1
#define BD0 0x01 // BauDrate Bit0
// 0x0e Card Control [ECDT RCDT SMP SWINT]
#define ECDT 0x08 // Enable Card Detect
#define RCDT 0x04 // Run Card Detect
#define SMP 0x02 // Set module pulled
#define SWINT 0x01 // Software Interrupt
// 0x0f Card Status [P2W P1W P2C P1C]
#define P2W 0x08 // High when Port2 writeable
#define P1W 0x04 // High when Port1 writeable
#define P2C 0x02 // High when Card in Port2 inserted
#define P1C 0x01 // High when Card in Port1 inserted
// 0x10 Serial I/O Control [SON ETBE ERBF ERBZ]
#define SON 0x08 // Serial on
#define ETBE 0x04 // Interrupt on transmit buffer empty
#define ERBF 0x02 // Interrupt on receive buffer full
#define ERBZ 0x01 // Interrupt on receiver busy
// 0x11 Serial Receive Control/Status [RX RER RBZ RBF]
#define RX 0x08 // Rx pin state (read-only)
#define RER 0x04 // Receiver error
#define RBZ 0x02 // Receiver busy
#define RBF 0x01 // Receive buffer full
// 0x12 Serial Transmit Control/Status [BRK LPB TBZ TBF]
#define BRK 0x08 // Break
#define LPB 0x04 // Loopback
#define TBZ 0x02 // Transmitter busy
#define TBF 0x01 // Transmit buffer full
// 0x18 Service Request Register 1 [ISRQ TSRQ USRQ VSRQ]
#define ISRQ 0x08 // IR receiver pulls NINT2
#define TSRQ 0x04 // Timer pulls NINT2
#define USRQ 0x02 // UART pulls NINT2
#define VSRQ 0x01 // VLBI pulls NINT2
// 0x19 Service Request Register 2 [KDN NINT2 NINT LSRQ]
#define KDN 0x08 // Bit set when ON Key or Key Interrupt
#define NINT2 0x04 // State of NINT2
#define NINT 0x02 // State of NINT
#define LSRQ 0x01 // LED driver pulls NINT2
// 0x1a IR Control Register [IRI EIRU EIRI IRE]
#define IRI 0x08 // IR input (read-only)
#define EIRU 0x04 // Enable IR UART mode
#define EIRI 0x02 // Enable IR interrupt
#define IRE 0x01 // IR event
// 0x1c Led Control Register [LED ELBE LBZ LBF]
#define LED 0x08 // Turn on LED
#define ELBE 0x04 // Enable Interrupt on Led Buffer empty
#define LBZ 0x02 // Led Port Busy
#define LBF 0x01 // Led Buffer Full
// 0x28 Display Line Counter LSB [LC3 LC2 LC1 LC0]
#define LC3 0x08 // LC3 - Line Counter Bit3
#define LC2 0x04 // LC2 - Line Counter Bit2
#define LC1 0x02 // LC1 - Line Counter Bit1
#define LC0 0x01 // LC0 - Line Counter Bit0
// 0x29 Display Line Counter MSB [DA19 M32 LC5 LC4]
#define DA19 0x08 // Drive A[19]
#define M32 0x04 // Multiplex 32 way
#define LC5 0x02 // LC5 - Line Counter Bit5
#define LC4 0x01 // LC4 - Line Counter Bit4
// 0x2e Timer1 Control [SRQ WKE INT XTRA]
#define SRQ 0x08 // Service request
#define WKE 0x04 // Wake up
#define INTR 0x02 // Interrupt
#define XTRA 0x01 // Extra function
// 0x2f Timer2 Control [SRQ WKE INT RUN]
#define SRQ 0x08 // Service request
#define WKE 0x04 // Wake up
#define INTR 0x02 // Interrupt
#define RUN 0x01 // Timer run

129
SOURCE/KEYBOARD.C Normal file
View file

@ -0,0 +1,129 @@
/*
* keyboard.c
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#include "pch.h"
#include "Emu48.h"
#include "io.h" // I/O definitions
static WORD Keyboard_GetIR(VOID)
{
WORD r = 0;
// OR[0:8] are wired on Clarke/Yorke chip
if (Chipset.out==0) return 0;
if (Chipset.out&0x001) r|=Chipset.Keyboard_Row[0];
if (Chipset.out&0x002) r|=Chipset.Keyboard_Row[1];
if (Chipset.out&0x004) r|=Chipset.Keyboard_Row[2];
if (Chipset.out&0x008) r|=Chipset.Keyboard_Row[3];
if (Chipset.out&0x010) r|=Chipset.Keyboard_Row[4];
if (Chipset.out&0x020) r|=Chipset.Keyboard_Row[5];
if (Chipset.out&0x040) r|=Chipset.Keyboard_Row[6];
if (Chipset.out&0x080) r|=Chipset.Keyboard_Row[7];
if (Chipset.out&0x100) r|=Chipset.Keyboard_Row[8];
return r;
}
VOID ScanKeyboard(BOOL bActive, BOOL bReset)
{
// bActive = TRUE -> function called by direct read (A=IN, C=IN, RSI)
// FALSE -> function called by 1ms keyboard poll simulation
// bReset = TRUE -> Reset Chipset.in interrupt state register
// FALSE -> generate interrupt only for new pressed keys
// keyboard read not active?
if (!( bActive || Chipset.Shutdn || Chipset.IR15X
|| (Chipset.intk && (Chipset.IORam[TIMER2_CTRL]&RUN) != 0)))
{
EnterCriticalSection(&csKeyLock);
{
Chipset.in &= ~0x8000; // remove ON key
}
LeaveCriticalSection(&csKeyLock);
return;
}
EnterCriticalSection(&csKeyLock); // synchronize
{
BOOL bKbdInt;
WORD wOldIn = Chipset.in; // save old Chipset.in state
UpdateKdnBit(); // update KDN bit
Chipset.dwKdnCycles = (DWORD) (Chipset.cycles & 0xFFFFFFFF);
Chipset.in = Keyboard_GetIR(); // update Chipset.in register
Chipset.in |= Chipset.IR15X; // add ON key
// interrupt for any new pressed keys?
bKbdInt = (Chipset.in && (wOldIn & 0x1FF) == 0) || Chipset.IR15X || bReset;
// update keyboard interrupt pending flag when 1ms keyboard scan is disabled
Chipset.intd = Chipset.intd || (bKbdInt && !Chipset.intk);
// keyboard interrupt enabled?
bKbdInt = bKbdInt && Chipset.intk;
// interrupt at ON key pressed
bKbdInt = bKbdInt || Chipset.IR15X != 0;
// no interrupt if still inside interrupt service routine
bKbdInt = bKbdInt && Chipset.inte;
if (Chipset.in != 0) // any key pressed
{
if (bKbdInt) // interrupt enabled
{
Chipset.SoftInt = TRUE; // interrupt request
bInterrupt = TRUE; // exit emulation loop
}
if (Chipset.Shutdn) // cpu sleeping
{
Chipset.bShutdnWake = TRUE; // wake up from SHUTDN mode
SetEvent(hEventShutdn); // wake up emulation thread
}
}
else
{
Chipset.intd = FALSE; // no keyboard interrupt pending
}
}
LeaveCriticalSection(&csKeyLock);
return;
}
VOID KeyboardEvent(BOOL bPress, UINT out, UINT in)
{
if (nState != SM_RUN) // not in running state
return; // ignore key
KeyMacroRecord(bPress,out,in); // save all keyboard events
if (in == 0x8000) // ON key ?
{
Chipset.IR15X = bPress?0x8000:0x0000; // refresh special ON key flag
}
else
{
// "out" is outside Keyboard_Row
if (out >= ARRAYSIZEOF(Chipset.Keyboard_Row)) return;
// in &= 0x1FF; // only IR[0:8] are wired on Clarke/Yorke chip
_ASSERT(out < ARRAYSIZEOF(Chipset.Keyboard_Row));
if (bPress) // key pressed
Chipset.Keyboard_Row[out] |= in; // set key marker in keyboard row
else
Chipset.Keyboard_Row[out] &= (~in); // clear key marker in keyboard row
}
AdjKeySpeed(); // adjust key repeat speed
ScanKeyboard(FALSE,FALSE); // update Chipset.in register by 1ms keyboard poll
Sleep(50); // hold key state for a definite time
return;
}

339
SOURCE/KEYMACRO.C Normal file
View file

@ -0,0 +1,339 @@
/*
* Keymacro.c
*
* This file is part of Emu48
*
* Copyright (C) 2004 Christoph Gießelink
*
*/
#include "pch.h"
#include "resource.h"
#include "Emu48.h"
#include "kml.h"
#define KEYMACROHEAD "Emu-KeyMacro" // macro signature
#define KEYHOLDTIME 50
#define MIN_SPEED 0
#define MAX_SPEED 500
typedef struct
{
DWORD dwTime; // elapsed time
DWORD dwKeyEvent; // key code
} KeyData;
INT nMacroState = MACRO_OFF;
INT nMacroTimeout = MIN_SPEED;
BOOL bMacroRealSpeed = TRUE;
static DWORD dwTimeRef;
static HANDLE hMacroFile = INVALID_HANDLE_VALUE;
static HANDLE hEventPlay = NULL;
static HANDLE hThreadEv = NULL;
static VOID InitializeOFN(LPOPENFILENAME ofn)
{
ZeroMemory((LPVOID)ofn, sizeof(OPENFILENAME));
ofn->lStructSize = sizeof(OPENFILENAME);
ofn->hwndOwner = hWnd;
ofn->Flags = OFN_EXPLORER|OFN_HIDEREADONLY;
return;
}
//
// thread playing keys
//
static DWORD WINAPI EventThread(LPVOID pParam)
{
DWORD dwRead = 0;
DWORD dwData,dwTime = 0;
while (WaitForSingleObject(hEventPlay,dwTime) == WAIT_TIMEOUT)
{
if (dwRead != 0) // data read
{
UINT nIn = (dwData >> 0) & 0xFFFF;
UINT nOut = (dwData >> 16) & 0xFF;
BOOL bPress = (dwData >> 24) & 0xFF;
PlayKey(nOut,nIn,bPress);
// KeyboardEvent(bPress,nOut,nIn);
}
dwTime = nMacroTimeout; // set default speed
while (TRUE)
{
// read next data element
if ( !ReadFile(hMacroFile,&dwData,sizeof(dwData),&dwRead,NULL)
|| dwRead != sizeof(dwData))
{
// play record empty -> quit
PostMessage(hWnd,WM_COMMAND,ID_TOOL_MACRO_STOP,0);
return 0; // exit on file end
}
if ((dwData & 0x80000000) != 0) // time information
{
if (bMacroRealSpeed) // realspeed from data
{
dwTime = dwData & 0x7FFFFFFF;
}
continue;
}
break; // got key information
}
}
return 0; // exit on stop
UNREFERENCED_PARAMETER(pParam);
}
//
// callback function for recording keys
//
VOID KeyMacroRecord(BOOL bPress, UINT out, UINT in)
{
if (nMacroState == MACRO_NEW) // save key event
{
KeyData Data;
DWORD dwWritten;
dwWritten = GetTickCount(); // time reference
Data.dwTime = (dwWritten - dwTimeRef - KEYHOLDTIME);
// set negative number to zero
if ((Data.dwTime & 0x80000000) != 0) Data.dwTime = 0;
Data.dwTime |= 0x80000000; // set time marker
dwTimeRef = dwWritten;
Data.dwKeyEvent = (bPress & 0xFF);
Data.dwKeyEvent = (Data.dwKeyEvent << 8) | (out & 0xFF);
Data.dwKeyEvent = (Data.dwKeyEvent << 16) | (in & 0xFFFF);
// save key event in file
WriteFile(hMacroFile,&Data,sizeof(Data),&dwWritten,NULL);
_ASSERT(dwWritten == sizeof(Data));
}
return;
}
//
// message handler for save new keyboard macro
//
LRESULT OnToolMacroNew(VOID)
{
TCHAR szMacroFile[MAX_PATH];
OPENFILENAME ofn;
DWORD dwExtensionLength,dwWritten;
// get filename for saving
InitializeOFN(&ofn);
ofn.lpstrFilter =
_T("Keyboard Macro Files (*.MAC)\0*.MAC\0")
_T("All Files (*.*)\0*.*\0")
_T("\0\0");
ofn.lpstrDefExt = _T("MAC");
ofn.nFilterIndex = 1;
ofn.lpstrFile = szMacroFile;
ofn.lpstrFile[0] = 0;
ofn.nMaxFile = ARRAYSIZEOF(szMacroFile);
ofn.Flags |= OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT;
if (GetSaveFileName(&ofn) == FALSE) return 0;
// open file for writing
hMacroFile = CreateFile(szMacroFile,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hMacroFile == INVALID_HANDLE_VALUE) return 0;
// write header
WriteFile(hMacroFile,KEYMACROHEAD,sizeof(KEYMACROHEAD) - 1,&dwWritten,NULL);
_ASSERT(dwWritten == (DWORD) strlen(KEYMACROHEAD));
// write extension length
dwExtensionLength = 0; // no extension
WriteFile(hMacroFile,&dwExtensionLength,sizeof(dwExtensionLength),&dwWritten,NULL);
_ASSERT(dwWritten == sizeof(dwExtensionLength));
nMacroState = MACRO_NEW;
UpdateWindowStatus();
MessageBox(hWnd,
_T("Press OK to begin to record the Macro."),
_T("Macro Recorder"),
MB_OK|MB_ICONINFORMATION);
dwTimeRef = GetTickCount() + KEYHOLDTIME; // time reference
return 0;
}
//
// message handler for play keyboard macro
//
LRESULT OnToolMacroPlay(VOID)
{
BYTE byHeader[sizeof(KEYMACROHEAD)-1];
TCHAR szMacroFile[MAX_PATH];
OPENFILENAME ofn;
DWORD dwExtensionLength,dwRead,dwThreadId;
InitializeOFN(&ofn);
ofn.lpstrFilter =
_T("Keyboard Macro Files (*.MAC)\0*.MAC\0")
_T("All Files (*.*)\0*.*\0")
_T("\0\0");
ofn.lpstrDefExt = _T("MAC");
ofn.nFilterIndex = 1;
ofn.lpstrFile = szMacroFile;
ofn.lpstrFile[0] = 0;
ofn.nMaxFile = ARRAYSIZEOF(szMacroFile);
ofn.Flags |= OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
if (GetOpenFileName(&ofn) == FALSE) return 0;
// open file for Reading
hMacroFile = CreateFile(szMacroFile,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hMacroFile == INVALID_HANDLE_VALUE) return 0;
// read header
ReadFile(hMacroFile,byHeader,sizeof(byHeader),&dwRead,NULL);
if ( dwRead != sizeof(byHeader)
|| memcmp(byHeader,KEYMACROHEAD,dwRead) != 0)
{
MessageBox(hWnd,
_T("Wrong keyboard macro file format."),
_T("Macro Recorder"),
MB_OK|MB_ICONSTOP);
CloseHandle(hMacroFile);
return 0;
}
// read extension length
ReadFile(hMacroFile,&dwExtensionLength,sizeof(dwExtensionLength),&dwRead,NULL);
if (dwRead != sizeof(dwExtensionLength))
{
CloseHandle(hMacroFile);
return 0;
}
// read extension
while (dwExtensionLength-- > 0)
{
BYTE byData;
ReadFile(hMacroFile,&byData,sizeof(byData),&dwRead,NULL);
if (dwRead != sizeof(byData))
{
CloseHandle(hMacroFile);
return 0;
}
}
// event for quit playing
hEventPlay = CreateEvent(NULL,FALSE,FALSE,NULL);
nMacroState = MACRO_PLAY;
UpdateWindowStatus();
// start playing thread
VERIFY(hThreadEv = CreateThread(NULL,0,&EventThread,NULL,0,&dwThreadId));
return 0;
}
//
// message handler for stop recording/playing
//
LRESULT OnToolMacroStop(VOID)
{
if (nMacroState != MACRO_OFF)
{
if (hEventPlay) // playing keys
{
// stop playing thread
SetEvent(hEventPlay); // quit play loop
WaitForSingleObject(hThreadEv,INFINITE);
CloseHandle(hThreadEv);
hThreadEv = NULL;
CloseHandle(hEventPlay); // close playing keys event
hEventPlay = NULL;
}
// macro file open
if (hMacroFile != INVALID_HANDLE_VALUE) CloseHandle(hMacroFile);
nMacroState = MACRO_OFF;
UpdateWindowStatus();
}
return 0;
}
//
// activate/deactivate slider
//
static VOID SliderEnable(HWND hDlg,BOOL bEnable)
{
EnableWindow(GetDlgItem(hDlg,IDC_MACRO_SLOW),bEnable);
EnableWindow(GetDlgItem(hDlg,IDC_MACRO_FAST),bEnable);
EnableWindow(GetDlgItem(hDlg,IDC_MACRO_SLIDER),bEnable);
return;
}
//
// Macro settings dialog
//
static INT_PTR CALLBACK MacroProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
// set slider
SendDlgItemMessage(hDlg,IDC_MACRO_SLIDER,TBM_SETRANGE,FALSE,MAKELONG(0,MAX_SPEED-MIN_SPEED));
SendDlgItemMessage(hDlg,IDC_MACRO_SLIDER,TBM_SETTICFREQ,MAX_SPEED/10,0);
SendDlgItemMessage(hDlg,IDC_MACRO_SLIDER,TBM_SETPOS,TRUE,MAX_SPEED-nMacroTimeout);
// set button
CheckDlgButton(hDlg,bMacroRealSpeed ? IDC_MACRO_REAL : IDC_MACRO_MANUAL,BST_CHECKED);
SliderEnable(hDlg,!bMacroRealSpeed);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_MACRO_REAL:
SliderEnable(hDlg,FALSE);
return TRUE;
case IDC_MACRO_MANUAL:
SliderEnable(hDlg,TRUE);
return TRUE;
case IDOK:
// get macro data
nMacroTimeout = MAX_SPEED - SendDlgItemMessage(hDlg,IDC_MACRO_SLIDER,TBM_GETPOS,0,0);
bMacroRealSpeed = IsDlgButtonChecked(hDlg,IDC_MACRO_REAL);
// no break
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
}
break;
}
return FALSE;
UNREFERENCED_PARAMETER(lParam);
}
LRESULT OnToolMacroSettings(VOID)
{
if (DialogBox(hApp, MAKEINTRESOURCE(IDD_MACROSET), hWnd, (DLGPROC)MacroProc) == -1)
AbortMessage(_T("Macro Dialog Box Creation Error !"));
return 0;
}

2269
SOURCE/KML.C Normal file

File diff suppressed because it is too large Load diff

125
SOURCE/KML.H Normal file
View file

@ -0,0 +1,125 @@
/*
* kml.h
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#define LEX_BLOCK 0
#define LEX_COMMAND 1
#define LEX_PARAM 2
typedef enum eTokenId
{
TOK_NONE, //0
TOK_ANNUNCIATOR, //1
TOK_BACKGROUND, //2
TOK_IFPRESSED, //3
TOK_RESETFLAG, //4
TOK_SCANCODE, //5
TOK_HARDWARE, //6
TOK_MENUITEM, //7
TOK_INTEGER, //8
TOK_SETFLAG, //9
TOK_RELEASE, //10
TOK_VIRTUAL, //11
TOK_INCLUDE, //12
TOK_STRING, //13
TOK_GLOBAL, //14
TOK_AUTHOR, //15
TOK_BITMAP, //16
TOK_OFFSET, //17
TOK_BUTTON, //18
TOK_IFFLAG, //19
TOK_ONDOWN, //20
TOK_NOHOLD, //21
TOK_TOPBAR, //22
TOK_TITLE, //23
TOK_OUTIN, //24
TOK_PATCH, //25
TOK_PRINT, //26
TOK_DEBUG, //27
TOK_COLOR, //28
TOK_MODEL, //29
TOK_CLASS, //30
TOK_PRESS, //31
TOK_TYPE, //32
TOK_SIZE, //33
TOK_DOWN, //34
TOK_ZOOM, //35
TOK_ELSE, //36
TOK_ONUP, //37
TOK_EOL, //38
TOK_MAP, //39
TOK_ROM, //40
TOK_VGA, //41
TOK_LCD, //42
TOK_NOTFLAG, //43
TOK_END //44
} TokenId;
#define TYPE_NONE 00
#define TYPE_INTEGER 01
#define TYPE_STRING 02
typedef struct KmlToken
{
TokenId eId;
DWORD nParams;
DWORD nLen;
TCHAR szName[20];
} KmlToken;
typedef struct KmlLine
{
struct KmlLine* pNext;
TokenId eCommand;
DWORD_PTR nParam[6];
} KmlLine;
typedef struct KmlBlock
{
TokenId eType;
DWORD nId;
struct KmlLine* pFirstLine;
struct KmlBlock* pNext;
} KmlBlock;
#define BUTTON_NOHOLD 0x0001
#define BUTTON_VIRTUAL 0x0002
typedef struct KmlButton
{
UINT nId;
BOOL bDown;
UINT nType;
DWORD dwFlags;
UINT nOx, nOy;
UINT nDx, nDy;
UINT nCx, nCy;
UINT nOut, nIn;
KmlLine* pOnDown;
KmlLine* pOnUp;
} KmlButton;
typedef struct KmlAnnunciator
{
UINT nOx, nOy;
UINT nDx, nDy;
UINT nCx, nCy;
} KmlAnnunciator;
extern KmlBlock* pKml;
extern BOOL DisplayChooseKml(CHAR cType);
extern VOID FreeBlocks(KmlBlock* pBlock);
extern VOID DrawAnnunciator(UINT nId, BOOL bOn);
extern VOID ReloadButtons(BYTE *Keyboard_Row, UINT nSize);
extern VOID RefreshButtons(RECT *rc);
extern VOID MouseButtonDownAt(UINT nFlags, DWORD x, DWORD y);
extern VOID MouseButtonUpAt(UINT nFlags, DWORD x, DWORD y);
extern VOID MouseMovesTo(UINT nFlags, DWORD x, DWORD y);
extern VOID RunKey(BYTE nId, BOOL bPressed);
extern VOID PlayKey(UINT nOut, UINT nIn, BOOL bPressed);
extern BOOL InitKML(LPCTSTR szFilename, BOOL bNoLog);
extern VOID KillKML(VOID);

1762
SOURCE/MOPS.C Normal file

File diff suppressed because it is too large Load diff

2482
SOURCE/OPCODES.C Normal file

File diff suppressed because it is too large Load diff

445
SOURCE/OPCODES.H Normal file
View file

@ -0,0 +1,445 @@
/*
* opcodes.h
*
* This file is part of Emu48
*
* Copyright (C) 1999 Christoph Gießelink
*
*/
#define PCHANGED ((void)(F_s[0]=Chipset.P,F_l[1]=Chipset.P+1))
#define INTERRUPT ((void)(Chipset.SoftInt=TRUE,bInterrupt=TRUE))
extern UINT F_s[16];
extern UINT F_l[16];
extern VOID o00(LPBYTE I); // RTNSXM
extern VOID o01(LPBYTE I); // RTN
extern VOID o02(LPBYTE I); // RTNSC
extern VOID o03(LPBYTE I); // RTNCC
extern VOID o04(LPBYTE I); // SETHEX
extern VOID o05(LPBYTE I); // SETDEC
extern VOID o06(LPBYTE I); // RSTK=C
extern VOID o07(LPBYTE I); // C=RSTK
extern VOID o08(LPBYTE I); // CLRST
extern VOID o09(LPBYTE I); // C=ST
extern VOID o0A(LPBYTE I); // ST=C
extern VOID o0B(LPBYTE I); // CSTEX
extern VOID o0C(LPBYTE I); // P=P+1
extern VOID o0D(LPBYTE I); // P=P-1
extern VOID o0Ef0(LPBYTE I); // A=A&B f
extern VOID o0Ef1(LPBYTE I); // B=B&C f
extern VOID o0Ef2(LPBYTE I); // C=C&A f
extern VOID o0Ef3(LPBYTE I); // D=D&C f
extern VOID o0Ef4(LPBYTE I); // B=B&A f
extern VOID o0Ef5(LPBYTE I); // C=C&B f
extern VOID o0Ef6(LPBYTE I); // A=A&C f
extern VOID o0Ef7(LPBYTE I); // C=C&D f
extern VOID o0Ef8(LPBYTE I); // A=A!B f
extern VOID o0Ef9(LPBYTE I); // B=B!C f
extern VOID o0EfA(LPBYTE I); // C=C!A f
extern VOID o0EfB(LPBYTE I); // D=D!C f
extern VOID o0EfC(LPBYTE I); // B=B!A f
extern VOID o0EfD(LPBYTE I); // C=C!B f
extern VOID o0EfE(LPBYTE I); // A=A!C f
extern VOID o0EfF(LPBYTE I); // C=C!D f
extern VOID o0F(LPBYTE I); // RTI
extern VOID o100(LPBYTE I); // R0=A W
extern VOID o101(LPBYTE I); // R1=A W
extern VOID o102(LPBYTE I); // R2=A W
extern VOID o103(LPBYTE I); // R3=A W
extern VOID o104(LPBYTE I); // R4=A W
extern VOID o108(LPBYTE I); // R0=C W
extern VOID o109(LPBYTE I); // R1=C W
extern VOID o10A(LPBYTE I); // R2=C W
extern VOID o10B(LPBYTE I); // R3=C W
extern VOID o10C(LPBYTE I); // R4=C W
extern VOID o110(LPBYTE I); // A=R0 W
extern VOID o111(LPBYTE I); // A=R1 W
extern VOID o112(LPBYTE I); // A=R2 W
extern VOID o113(LPBYTE I); // A=R3 W
extern VOID o114(LPBYTE I); // A=R4 W
extern VOID o118(LPBYTE I); // C=R0 W
extern VOID o119(LPBYTE I); // C=R1 W
extern VOID o11A(LPBYTE I); // C=R2 W
extern VOID o11B(LPBYTE I); // C=R3 W
extern VOID o11C(LPBYTE I); // C=R4 W
extern VOID o120(LPBYTE I); // AR0EX W
extern VOID o121(LPBYTE I); // AR1EX W
extern VOID o122(LPBYTE I); // AR2EX W
extern VOID o123(LPBYTE I); // AR3EX W
extern VOID o124(LPBYTE I); // AR4EX W
extern VOID o128(LPBYTE I); // CR0EX W
extern VOID o129(LPBYTE I); // CR1EX W
extern VOID o12A(LPBYTE I); // CR2EX W
extern VOID o12B(LPBYTE I); // CR3EX W
extern VOID o12C(LPBYTE I); // CR4EX W
extern VOID o130(LPBYTE I); // D0=A
extern VOID o131(LPBYTE I); // D1=A
extern VOID o132(LPBYTE I); // AD0EX
extern VOID o133(LPBYTE I); // AD1EX
extern VOID o134(LPBYTE I); // D0=C
extern VOID o135(LPBYTE I); // D1=C
extern VOID o136(LPBYTE I); // CD0EX
extern VOID o137(LPBYTE I); // CD1EX
extern VOID o138(LPBYTE I); // D0=AS
extern VOID o139(LPBYTE I); // D1=AS
extern VOID o13A(LPBYTE I); // AD0XS
extern VOID o13B(LPBYTE I); // AD1XS
extern VOID o13C(LPBYTE I); // D0=CS
extern VOID o13D(LPBYTE I); // D1=CS
extern VOID o13E(LPBYTE I); // CD0XS
extern VOID o13F(LPBYTE I); // CD1XS
extern VOID o140(LPBYTE I); // DAT0=A A
extern VOID o141(LPBYTE I); // DAT0=A A
extern VOID o144(LPBYTE I); // DAT0=C A
extern VOID o145(LPBYTE I); // DAT1=C A
extern VOID o148(LPBYTE I); // DAT0=A B
extern VOID o149(LPBYTE I); // DAT1=A B
extern VOID o14C(LPBYTE I); // DAT0=C B
extern VOID o14D(LPBYTE I); // DAT1=C B
extern VOID o142(LPBYTE I); // A=DAT0 A
extern VOID o143(LPBYTE I); // A=DAT1 A
extern VOID o146(LPBYTE I); // C=DAT0 A
extern VOID o147(LPBYTE I); // C=DAT1 A
extern VOID o14A(LPBYTE I); // A=DAT0 B
extern VOID o14B(LPBYTE I); // A=DAT1 B
extern VOID o14E(LPBYTE I); // C=DAT0 B
extern VOID o14F(LPBYTE I); // C=DAT0 B
extern VOID o150a(LPBYTE I); // DAT0=A a
extern VOID o151a(LPBYTE I); // DAT1=A a
extern VOID o154a(LPBYTE I); // DAT0=C a
extern VOID o155a(LPBYTE I); // DAT1=C a
extern VOID o152a(LPBYTE I); // A=DAT0 a
extern VOID o153a(LPBYTE I); // A=DAT1 a
extern VOID o156a(LPBYTE I); // C=DAT0 a
extern VOID o157a(LPBYTE I); // C=DAT1 a
extern VOID o158x(LPBYTE I); // DAT0=A x
extern VOID o159x(LPBYTE I); // DAT1=A x
extern VOID o15Cx(LPBYTE I); // DAT0=C x
extern VOID o15Dx(LPBYTE I); // DAT1=C x
extern VOID o15Ax(LPBYTE I); // A=DAT0 x
extern VOID o15Bx(LPBYTE I); // A=DAT1 x
extern VOID o15Ex(LPBYTE I); // C=DAT0 x
extern VOID o15Fx(LPBYTE I); // C=DAT1 x
extern VOID o16x(LPBYTE I); // D0=D0+ (n+1)
extern VOID o17x(LPBYTE I); // D1=D1+ (n+1)
extern VOID o18x(LPBYTE I); // D0=D0- (n+1)
extern VOID o19d2(LPBYTE I); // D0=(2) #dd
extern VOID o1Ad4(LPBYTE I); // D0=(4) #dddd
extern VOID o1Bd5(LPBYTE I); // D0=(5) #ddddd
extern VOID o1Cx(LPBYTE I); // D1=D1- (n+1)
extern VOID o1Dd2(LPBYTE I); // D1=(2) #dd
extern VOID o1Ed4(LPBYTE I); // D1=(4) #dddd
extern VOID o1Fd5(LPBYTE I); // D1=(5) #ddddd
extern VOID o2n(LPBYTE I); // P= n
extern VOID o3X(LPBYTE I); // LCHEX
extern VOID o4d2(LPBYTE I); // GOC #dd
extern VOID o5d2(LPBYTE I); // GONC
extern VOID o6d3(LPBYTE I); // GOTO
extern VOID o7d3(LPBYTE I); // GOSUB
extern VOID o800(LPBYTE I); // OUT=CS
extern VOID o801(LPBYTE I); // OUT=C
extern VOID o802(LPBYTE I); // A=IN
extern VOID o803(LPBYTE I); // C=IN
extern VOID o804(LPBYTE I); // UNCNFG
extern VOID o805(LPBYTE I); // CONFIG
extern VOID o806(LPBYTE I); // C=ID
extern VOID o807(LPBYTE I); // SHUTDN
extern VOID o8080(LPBYTE I); // INTON
extern VOID o80810(LPBYTE I); // RSI
extern VOID o8082X(LPBYTE I); // LA
extern VOID o8083(LPBYTE I); // BUSCB
extern VOID o8084n(LPBYTE I); // ABIT=0 n
extern VOID o8085n(LPBYTE I); // ABIT=1 n
extern VOID o8086n(LPBYTE I); // ?ABIT=0 n
extern VOID o8087n(LPBYTE I); // ?ABIT=1 n
extern VOID o8088n(LPBYTE I); // CBIT=0 n
extern VOID o8089n(LPBYTE I); // CBIT=1 n
extern VOID o808An(LPBYTE I); // ?CBIT=0 n
extern VOID o808Bn(LPBYTE I); // ?CBIT=1 n
extern VOID o808C(LPBYTE I); // PC=(A)
extern VOID o808D(LPBYTE I); // BUSCD
extern VOID o808E(LPBYTE I); // PC=(C)
extern VOID o808F(LPBYTE I); // INTOFF
extern VOID o809(LPBYTE I); // C+P+1 - HEX MODE
extern VOID o80A(LPBYTE I); // RESET
extern VOID o80B(LPBYTE I); // BUSCC
extern VOID o80Cn(LPBYTE I); // C=P n
extern VOID o80Dn(LPBYTE I); // P=C n
extern VOID o80E(LPBYTE I); // SREQ?
extern VOID o80Fn(LPBYTE I); // CPEX n
extern VOID o810(LPBYTE I); // ASLC
extern VOID o811(LPBYTE I); // BSLC
extern VOID o812(LPBYTE I); // CSLC
extern VOID o813(LPBYTE I); // DSLC
extern VOID o814(LPBYTE I); // ASRC
extern VOID o815(LPBYTE I); // BSRC
extern VOID o816(LPBYTE I); // CSRC
extern VOID o817(LPBYTE I); // DSRC
extern VOID o818f0x(LPBYTE I); // A=A+x+1 f
extern VOID o818f1x(LPBYTE I); // B=B+x+1 f
extern VOID o818f2x(LPBYTE I); // C=C+x+1 f
extern VOID o818f3x(LPBYTE I); // D=D+x+1 f
extern VOID o818f8x(LPBYTE I); // A=A-x-1 f
extern VOID o818f9x(LPBYTE I); // B=B-x-1 f
extern VOID o818fAx(LPBYTE I); // C=C-x-1 f
extern VOID o818fBx(LPBYTE I); // D=D-x-1 f
extern VOID o819f0(LPBYTE I); // ASRB.F
extern VOID o819f1(LPBYTE I); // BSRB.F
extern VOID o819f2(LPBYTE I); // CSRB.F
extern VOID o819f3(LPBYTE I); // DSRB.F
extern VOID o81Af00(LPBYTE I); // R0=A.F f
extern VOID o81Af01(LPBYTE I); // R1=A.F f
extern VOID o81Af02(LPBYTE I); // R2=A.F f
extern VOID o81Af03(LPBYTE I); // R3=A.F f
extern VOID o81Af04(LPBYTE I); // R4=A.F f
extern VOID o81Af08(LPBYTE I); // R0=C.F f
extern VOID o81Af09(LPBYTE I); // R1=C.F f
extern VOID o81Af0A(LPBYTE I); // R2=C.F f
extern VOID o81Af0B(LPBYTE I); // R3=C.F f
extern VOID o81Af0C(LPBYTE I); // R4=C.F f
extern VOID o81Af10(LPBYTE I); // A=R0.F f
extern VOID o81Af11(LPBYTE I); // A=R1.F f
extern VOID o81Af12(LPBYTE I); // A=R2.F f
extern VOID o81Af13(LPBYTE I); // A=R3.F f
extern VOID o81Af14(LPBYTE I); // A=R4.F f
extern VOID o81Af18(LPBYTE I); // C=R0.F f
extern VOID o81Af19(LPBYTE I); // C=R1.F f
extern VOID o81Af1A(LPBYTE I); // C=R2.F f
extern VOID o81Af1B(LPBYTE I); // C=R3.F f
extern VOID o81Af1C(LPBYTE I); // C=R4.F f
extern VOID o81Af20(LPBYTE I); // AR0EX.F f
extern VOID o81Af21(LPBYTE I); // AR1EX.F f
extern VOID o81Af22(LPBYTE I); // AR2EX.F f
extern VOID o81Af23(LPBYTE I); // AR3EX.F f
extern VOID o81Af24(LPBYTE I); // AR4EX.F f
extern VOID o81Af28(LPBYTE I); // CR0EX.F f
extern VOID o81Af29(LPBYTE I); // CR1EX.F f
extern VOID o81Af2A(LPBYTE I); // CR2EX.F f
extern VOID o81Af2B(LPBYTE I); // CR3EX.F f
extern VOID o81Af2C(LPBYTE I); // CR4EX.F f
extern VOID o81B2(LPBYTE I); // PC=A
extern VOID o81B3(LPBYTE I); // PC=C
extern VOID o81B4(LPBYTE I); // A=PC
extern VOID o81B5(LPBYTE I); // C=PC
extern VOID o81B6(LPBYTE I); // APCEX
extern VOID o81B7(LPBYTE I); // CPCEX
extern VOID o81C(LPBYTE I); // ASRB
extern VOID o81D(LPBYTE I); // BSRB
extern VOID o81E(LPBYTE I); // CSRB
extern VOID o81F(LPBYTE I); // DSRB
extern VOID o82n(LPBYTE I); // HST=0 m
extern VOID o83n(LPBYTE I); // ?HST=0 m
extern VOID o84n(LPBYTE I); // ST=0 n
extern VOID o85n(LPBYTE I); // ST=1 n
extern VOID o86n(LPBYTE I); // ?ST=0 n
extern VOID o87n(LPBYTE I); // ?ST=1 n
extern VOID o88n(LPBYTE I); // ?P# n
extern VOID o89n(LPBYTE I); // ?P= n
extern VOID o8A0(LPBYTE I); // ?A=B A
extern VOID o8A1(LPBYTE I); // ?B=C A
extern VOID o8A2(LPBYTE I); // ?C=A A
extern VOID o8A3(LPBYTE I); // ?D=C A
extern VOID o8A4(LPBYTE I); // ?A#B A
extern VOID o8A5(LPBYTE I); // ?B#C A
extern VOID o8A6(LPBYTE I); // ?C#A A
extern VOID o8A7(LPBYTE I); // ?D#C A
extern VOID o8A8(LPBYTE I); // ?A=0 A
extern VOID o8A9(LPBYTE I); // ?B=0 A
extern VOID o8AA(LPBYTE I); // ?C=0 A
extern VOID o8AB(LPBYTE I); // ?D=0 A
extern VOID o8AC(LPBYTE I); // ?A#0 A
extern VOID o8AD(LPBYTE I); // ?B#0 A
extern VOID o8AE(LPBYTE I); // ?C#0 A
extern VOID o8AF(LPBYTE I); // ?D#0 A
extern VOID o8B0(LPBYTE I); // ?A>B A
extern VOID o8B1(LPBYTE I); // ?B>C A
extern VOID o8B2(LPBYTE I); // ?C>A A
extern VOID o8B3(LPBYTE I); // ?D>C A
extern VOID o8B4(LPBYTE I); // ?A<B A
extern VOID o8B5(LPBYTE I); // ?B<C A
extern VOID o8B6(LPBYTE I); // ?C<A A
extern VOID o8B7(LPBYTE I); // ?D<C A
extern VOID o8B8(LPBYTE I); // ?A>=B A
extern VOID o8B9(LPBYTE I); // ?B>=C A
extern VOID o8BA(LPBYTE I); // ?C>=A A
extern VOID o8BB(LPBYTE I); // ?D>=C A
extern VOID o8BC(LPBYTE I); // ?A<=B A
extern VOID o8BD(LPBYTE I); // ?B<=C A
extern VOID o8BE(LPBYTE I); // ?C<=A A
extern VOID o8BF(LPBYTE I); // ?D<=C A
extern VOID o8Cd4(LPBYTE I); // GOLONG #dddd
extern VOID o8Dd5(LPBYTE I); // GOVLNG #ddddd
extern VOID o8Ed4(LPBYTE I); // GOSUBL #dddd
extern VOID o8Fd5(LPBYTE I); // GOSBVL #ddddd
extern VOID o9a0(LPBYTE I); // ?A=B f
extern VOID o9a1(LPBYTE I); // ?B=C f
extern VOID o9a2(LPBYTE I); // ?C=A f
extern VOID o9a3(LPBYTE I); // ?D=C f
extern VOID o9a4(LPBYTE I); // ?A#B f
extern VOID o9a5(LPBYTE I); // ?B#C f
extern VOID o9a6(LPBYTE I); // ?C#A f
extern VOID o9a7(LPBYTE I); // ?D#C f
extern VOID o9a8(LPBYTE I); // ?A=0 f
extern VOID o9a9(LPBYTE I); // ?B=0 f
extern VOID o9aA(LPBYTE I); // ?C=0 f
extern VOID o9aB(LPBYTE I); // ?D=0 f
extern VOID o9aC(LPBYTE I); // ?A#0 f
extern VOID o9aD(LPBYTE I); // ?B#0 f
extern VOID o9aE(LPBYTE I); // ?C#0 f
extern VOID o9aF(LPBYTE I); // ?D#0 f
extern VOID o9b0(LPBYTE I); // ?A>B f
extern VOID o9b1(LPBYTE I); // ?B>C f
extern VOID o9b2(LPBYTE I); // ?C>A f
extern VOID o9b3(LPBYTE I); // ?D>C f
extern VOID o9b4(LPBYTE I); // ?A<B f
extern VOID o9b5(LPBYTE I); // ?B<C f
extern VOID o9b6(LPBYTE I); // ?C<A f
extern VOID o9b7(LPBYTE I); // ?D<C f
extern VOID o9b8(LPBYTE I); // ?A>=B f
extern VOID o9b9(LPBYTE I); // ?B>=C f
extern VOID o9bA(LPBYTE I); // ?C>=A f
extern VOID o9bB(LPBYTE I); // ?D>=C f
extern VOID o9bC(LPBYTE I); // ?A<=B f
extern VOID o9bD(LPBYTE I); // ?B<=C f
extern VOID o9bE(LPBYTE I); // ?C<=A f
extern VOID o9bF(LPBYTE I); // ?D<=C f
extern VOID oAa0(LPBYTE I); // A=A+B f
extern VOID oAa1(LPBYTE I); // B=B+C f
extern VOID oAa2(LPBYTE I); // C=C+A f
extern VOID oAa3(LPBYTE I); // D=D+C f
extern VOID oAa4(LPBYTE I); // A=A+A f
extern VOID oAa5(LPBYTE I); // B=B+B f
extern VOID oAa6(LPBYTE I); // C=C+C f
extern VOID oAa7(LPBYTE I); // D=D+D f
extern VOID oAa8(LPBYTE I); // B=B+A f
extern VOID oAa9(LPBYTE I); // C=C+B f
extern VOID oAaA(LPBYTE I); // A=A+C f
extern VOID oAaB(LPBYTE I); // C=C+D f
extern VOID oAaC(LPBYTE I); // A=A-1 f
extern VOID oAaD(LPBYTE I); // B=B-1 f
extern VOID oAaE(LPBYTE I); // C=C-1 f
extern VOID oAaF(LPBYTE I); // D=D-1 f
extern VOID oAb0(LPBYTE I); // A=0 f
extern VOID oAb1(LPBYTE I); // B=0 f
extern VOID oAb2(LPBYTE I); // C=0 f
extern VOID oAb3(LPBYTE I); // D=0 f
extern VOID oAb4(LPBYTE I); // A=B f
extern VOID oAb5(LPBYTE I); // B=C f
extern VOID oAb6(LPBYTE I); // C=A f
extern VOID oAb7(LPBYTE I); // D=C f
extern VOID oAb8(LPBYTE I); // B=A f
extern VOID oAb9(LPBYTE I); // C=B f
extern VOID oAbA(LPBYTE I); // A=C f
extern VOID oAbB(LPBYTE I); // C=D f
extern VOID oAbC(LPBYTE I); // ABEX f
extern VOID oAbD(LPBYTE I); // BCEX f
extern VOID oAbE(LPBYTE I); // CAEX f
extern VOID oAbF(LPBYTE I); // DCEX f
extern VOID oBa0(LPBYTE I); // A=A-B f
extern VOID oBa1(LPBYTE I); // B=B-C f
extern VOID oBa2(LPBYTE I); // C=C-A f
extern VOID oBa3(LPBYTE I); // D=D-C f
extern VOID oBa4(LPBYTE I); // A=A+1 f
extern VOID oBa5(LPBYTE I); // B=B+1 f
extern VOID oBa6(LPBYTE I); // C=C+1 f
extern VOID oBa7(LPBYTE I); // D=D+1 f
extern VOID oBa8(LPBYTE I); // B=B-A f
extern VOID oBa9(LPBYTE I); // C=C-B f
extern VOID oBaA(LPBYTE I); // A=A-C f
extern VOID oBaB(LPBYTE I); // C=C-D f
extern VOID oBaC(LPBYTE I); // A=B-A f
extern VOID oBaD(LPBYTE I); // B=C-B f
extern VOID oBaE(LPBYTE I); // C=A-C f
extern VOID oBaF(LPBYTE I); // D=C-D f
extern VOID oBb0(LPBYTE I); // ASL f
extern VOID oBb1(LPBYTE I); // BSL f
extern VOID oBb2(LPBYTE I); // CSL f
extern VOID oBb3(LPBYTE I); // DSL f
extern VOID oBb4(LPBYTE I); // ASR f
extern VOID oBb5(LPBYTE I); // BSR f
extern VOID oBb6(LPBYTE I); // CSR f
extern VOID oBb7(LPBYTE I); // DSR f
extern VOID oBb8(LPBYTE I); // A=-A f
extern VOID oBb9(LPBYTE I); // B=-B f
extern VOID oBbA(LPBYTE I); // C=-C f
extern VOID oBbB(LPBYTE I); // D=-D f
extern VOID oBbC(LPBYTE I); // A=-A-1 f
extern VOID oBbD(LPBYTE I); // B=-B-1 f
extern VOID oBbE(LPBYTE I); // C=-C-1 f
extern VOID oBbF(LPBYTE I); // D=-D-1 f
extern VOID oC0(LPBYTE I); // A=A+B A
extern VOID oC1(LPBYTE I); // B=B+C A
extern VOID oC2(LPBYTE I); // C=C+A A
extern VOID oC3(LPBYTE I); // D=D+C A
extern VOID oC4(LPBYTE I); // A=A+A A
extern VOID oC5(LPBYTE I); // B=B+B A
extern VOID oC6(LPBYTE I); // C=C+C A
extern VOID oC7(LPBYTE I); // D=D+D A
extern VOID oC8(LPBYTE I); // B=B+A A
extern VOID oC9(LPBYTE I); // C=C+B A
extern VOID oCA(LPBYTE I); // A=A+C A
extern VOID oCB(LPBYTE I); // C=C+D A
extern VOID oCC(LPBYTE I); // A=A-1 A
extern VOID oCD(LPBYTE I); // B=B-1 A
extern VOID oCE(LPBYTE I); // C=C-1 A
extern VOID oCF(LPBYTE I); // D=D-1 A
extern VOID oD0(LPBYTE I); // A=0 A
extern VOID oD1(LPBYTE I); // B=0 A
extern VOID oD2(LPBYTE I); // C=0 A
extern VOID oD3(LPBYTE I); // D=0 A
extern VOID oD4(LPBYTE I); // A=B A
extern VOID oD5(LPBYTE I); // B=C A
extern VOID oD6(LPBYTE I); // C=A A
extern VOID oD7(LPBYTE I); // D=C A
extern VOID oD8(LPBYTE I); // B=A A
extern VOID oD9(LPBYTE I); // C=B A
extern VOID oDA(LPBYTE I); // A=C A
extern VOID oDB(LPBYTE I); // C=D A
extern VOID oDC(LPBYTE I); // ABEX
extern VOID oDD(LPBYTE I); // BCEX
extern VOID oDE(LPBYTE I); // CAEX
extern VOID oDF(LPBYTE I); // DCEX
extern VOID oE0(LPBYTE I); // A=A-B A
extern VOID oE1(LPBYTE I); // B=B-C A
extern VOID oE2(LPBYTE I); // C=C-A A
extern VOID oE3(LPBYTE I); // D=D-C A
extern VOID oE4(LPBYTE I); // A=A+1 A
extern VOID oE5(LPBYTE I); // B=B+1 A
extern VOID oE6(LPBYTE I); // C=C+1 A
extern VOID oE7(LPBYTE I); // D=D+1 A
extern VOID oE8(LPBYTE I); // B=B-A A
extern VOID oE9(LPBYTE I); // C=C-B A
extern VOID oEA(LPBYTE I); // A=A-C A
extern VOID oEB(LPBYTE I); // C=C-D A
extern VOID oEC(LPBYTE I); // A=B-A A
extern VOID oED(LPBYTE I); // B=C-B A
extern VOID oEE(LPBYTE I); // C=A-C A
extern VOID oEF(LPBYTE I); // D=C-D A
extern VOID oF0(LPBYTE I); // ASL A
extern VOID oF1(LPBYTE I); // BSL A
extern VOID oF2(LPBYTE I); // CSL A
extern VOID oF3(LPBYTE I); // DSL A
extern VOID oF4(LPBYTE I); // ASR A
extern VOID oF5(LPBYTE I); // BSR A
extern VOID oF6(LPBYTE I); // CSR A
extern VOID oF7(LPBYTE I); // DSR A
extern VOID oF8(LPBYTE I); // A=-A A
extern VOID oF9(LPBYTE I); // B=-B A
extern VOID oFA(LPBYTE I); // C=-C A
extern VOID oFB(LPBYTE I); // D=-D A
extern VOID oFC(LPBYTE I); // A=-A-1 A
extern VOID oFD(LPBYTE I); // B=-B-1 A
extern VOID oFE(LPBYTE I); // C=-C-1 A
extern VOID oFF(LPBYTE I); // D=-D-1 A
extern VOID o_invalid3(LPBYTE I);
extern VOID o_invalid4(LPBYTE I);
extern VOID o_invalid5(LPBYTE I);
extern VOID o_invalid6(LPBYTE I);
extern VOID o_goyes3(LPBYTE I);
extern VOID o_goyes5(LPBYTE I);
extern VOID o81B1(LPBYTE I); // beep patch

488
SOURCE/OPS.H Normal file
View file

@ -0,0 +1,488 @@
/*
* ops.h
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#define NFunpack(a, b, f) Nunpack((a)+F_s[f], b, F_l[f])
#define NFread(a, b, f) Nread((a)+F_s[f], b, F_l[f])
#define NFwrite(a, b, f) Nwrite((a)+F_s[f], b, F_l[f])
#define NFcopy(a, b, f) memcpy((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFxchg(a, b, f) Nxchg((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFadd(a, b, f) Nadd((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFsub(a, b, f) Nsub((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFrsub(a, b, f) Nrsub((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFand(a, b, f) Nand((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFor(a, b, f) Nor((a)+F_s[f], (b)+F_s[f], F_l[f])
#define NFzero(a,f) memset((a)+F_s[f], 0, F_l[f])
#define NFpack(a, f) Npack((a)+F_s[f], F_l[f])
#define NFinc(a, f) Ninc(a, F_l[f], F_s[f])
#define NFdec(a, f) Ndec(a, F_l[f], F_s[f])
#define NFnot(a, f) Nnot((a)+F_s[f], F_l[f])
#define NFneg(a, f) Nneg((a)+F_s[f], F_l[f])
#define NFsl(a, f) Nsl((a)+F_s[f], F_l[f])
#define NFsr(a, f) Nsr((a)+F_s[f], F_l[f])
#define NFsrb(a, f) Nsrb((a)+F_s[f], F_l[f])
#define TFe(a, b, f) Te((a)+F_s[f], (b)+F_s[f], F_l[f])
#define TFa(a, b, f) Ta((a)+F_s[f], (b)+F_s[f], F_l[f])
#define TFb(a, b, f) Tb((a)+F_s[f], (b)+F_s[f], F_l[f])
#define TFz(a, f) Tz((a)+F_s[f], F_l[f])
#define TFne(a, b, f) Tne((a)+F_s[f], (b)+F_s[f], F_l[f])
#define TFae(a, b, f) Tae((a)+F_s[f], (b)+F_s[f], F_l[f])
#define TFbe(a, b, f) Tbe((a)+F_s[f], (b)+F_s[f], F_l[f])
#define TFnz(a, f) Tnz((a)+F_s[f], F_l[f])
static __inline LPBYTE FASTPTR(DWORD d)
{
static BYTE pbyNULL[16];
LPBYTE lpbyPage;
d &= 0xFFFFF; // handle address overflows
if ((Chipset.IOCfig)&&((d&0xFFFC0)==Chipset.IOBase))
return Chipset.IORam+d-Chipset.IOBase;
if((lpbyPage = RMap[d>>12]) != NULL) // page valid
{
lpbyPage += d & 0xFFF; // full address
}
else
{
lpbyPage = pbyNULL; // memory allocation
Npeek(lpbyPage, d, 13); // fill with data (LA(8) = longest opcode)
}
return lpbyPage;
}
static __inline void rstkpush(DWORD d)
{
Chipset.rstk[Chipset.rstkp] = d;
Chipset.rstkp=(Chipset.rstkp+1)&7;
}
static __inline DWORD rstkpop()
{
DWORD r;
Chipset.rstkp=(Chipset.rstkp-1)&7;
r = Chipset.rstk[Chipset.rstkp];
Chipset.rstk[Chipset.rstkp] = 0;
return r;
}
static __inline DWORD Npack(BYTE *a, UINT s)
{
DWORD r = 0;
while (s--) r = (r<<4)|a[s];
return r;
}
static __inline VOID Nunpack(BYTE *a, DWORD b, UINT s)
{
UINT i;
for (i=0; i<s; i++) { a[i] = (BYTE)(b&0xf); b>>=4; }
}
static __inline QWORD Npack64(BYTE *a, UINT s)
{
QWORD r = 0;
while (s--) r = (r<<4)|a[s];
return r;
}
static __inline VOID Nunpack64(BYTE *a, QWORD b, UINT s)
{
UINT i;
for (i=0; i<s; i++) { a[i] = (BYTE)(b&0xf); b>>=4; }
}
static __inline void Nxchg(BYTE *a, BYTE *b, UINT s)
{
BYTE X[16];
memcpy(X, b, s);
memcpy(b, a, s);
memcpy(a, X, s);
}
static __inline void Ninc(BYTE *a, UINT s, UINT d)
{
UINT i;
if (Chipset.mode_dec)
{
BYTE c = 1;
for (i=d; i<s+d; ++i)
{
// no register wrap
_ASSERT(i < ARRAYSIZEOF(((CHIPSET *) NULL)->A));
// illegal number in dec mode
if (a[i] >= 10) a[i] &= 0x7;
a[i] += c;
c = (a[i] >= 10);
if (c) a[i] -= 10;
}
Chipset.carry = (c==1);
}
else
{
for (i=d; i<s+d; ++i)
{
// no register wrap
_ASSERT(i < ARRAYSIZEOF(((CHIPSET *) NULL)->A));
a[i]++;
if (a[i] < 16)
{
Chipset.carry = FALSE;
return;
}
a[i] -= 16;
}
Chipset.carry = TRUE;
}
}
static __inline void Ninc16(BYTE *a, UINT s, UINT d)
{
UINT i;
for (i=d; i<s+d; ++i)
{
a[i&0xf]++;
if (a[i&0xf] < 16)
{
Chipset.carry = FALSE;
return;
}
a[i&0xf] -= 16;
}
Chipset.carry = TRUE;
}
static __inline void Nincx(BYTE *a, UINT s)
{
UINT i;
for (i=0; i<s; ++i)
{
a[i]++;
if (a[i] < 16)
{
Chipset.carry = FALSE;
return;
}
a[i] -= 16;
}
Chipset.carry=TRUE;
}
static __inline void Ndec(BYTE *a, UINT s, UINT d)
{
UINT i;
BYTE cBase = Chipset.mode_dec ? 10 : 16;
for (i=d; i<s+d; ++i)
{
// no register wrap
_ASSERT(i < ARRAYSIZEOF(((CHIPSET *) NULL)->A));
a[i]--;
if ((a[i] & 0xF0) == 0) // check overflow
{
Chipset.carry = FALSE;
return;
}
a[i] += cBase;
}
Chipset.carry = TRUE;
}
static __inline void Ndec16(BYTE *a, UINT s, UINT d)
{
UINT i;
for (i=d; i<s+d; ++i)
{
a[i&0xf]--;
if (a[i&0xf] < 16)
{
Chipset.carry = FALSE;
return;
}
a[i&0xf] += 16;
}
Chipset.carry = TRUE;
}
static __inline void Nadd(BYTE *a, BYTE *b, UINT s)
{
UINT i;
BYTE c = 0;
BYTE cBase = Chipset.mode_dec ? 10 : 16;
for (i=0; i<s; ++i)
{
// illegal number in dec mode
if (a[i] >= cBase) a[i] &= 0x7;
a[i] += b[i] + c;
if (a[i] >= cBase)
{
a[i] -= cBase;
c = 1;
}
else
c = 0;
}
Chipset.carry = (c==1);
}
static __inline void Nsub(BYTE *a, BYTE *b, UINT s)
{
UINT i;
BYTE c = 0;
BYTE cBase = Chipset.mode_dec ? 10 : 16;
for (i=0; i<s; ++i)
{
a[i] = a[i] - b[i] - c;
if ((a[i] & 0xF0) != 0) // check overflow
{
a[i] += cBase;
// illegal number in dec mode
if ((a[i] & 0xF0) != 0) a[i] &= 0x7;
c = 1;
}
else
c = 0;
}
Chipset.carry = (c==1);
}
static __inline void Nrsub(BYTE *a, BYTE *b, UINT s)
{
UINT i;
BYTE c = 0;
BYTE cBase = Chipset.mode_dec ? 10 : 16;
for (i=0; i<s; ++i)
{
a[i] = b[i] - a[i] - c;
if ((a[i] & 0xF0) != 0) // check overflow
{
a[i] += cBase;
// illegal number in dec mode
if ((a[i] & 0xF0) != 0) a[i] &= 0x7;
c = 1;
}
else
c = 0;
}
Chipset.carry = (c==1);
}
static __inline void Nand(BYTE *a, BYTE *b, UINT s)
{
while (s--) a[s] &= b[s];
}
static __inline void Nor(BYTE *a, BYTE *b, UINT s)
{
while (s--) a[s] |= b[s];
}
static __inline void Nnot(BYTE *a, UINT s)
{
BYTE cBase = Chipset.mode_dec ? 9 : 15;
while (s--)
{
a[s] = cBase - a[s];
if ((a[s] & 0xF0) != 0) // check overflow (dec mode only)
a[s] &= 0x7;
}
Chipset.carry = FALSE;
}
static __inline void Nneg(BYTE *a, UINT s)
{
UINT i;
for (i=0; i<s && a[i]==0; ++i) { } // search for non-zero digit
if ((Chipset.carry = (i!=s))) // value was non-zero
{
BYTE cBase = Chipset.mode_dec ? 9 : 15;
_ASSERT(a[i] > 0); // check for non-zero digit
for (--a[i]; i<s; ++i)
{
a[i] = cBase - a[i];
if ((a[i] & 0xF0) != 0) // check overflow (dec mode only)
a[i] &= 0x7;
}
}
}
static __inline void Nsl(BYTE *a, UINT s)
{
while (--s) a[s] = a[s-1];
*a = 0;
}
static __inline void Nslc(BYTE *a, UINT s)
{
BYTE c = a[s-1];
while (--s) a[s] = a[s-1];
*a = c;
}
static __inline void Nsr(BYTE *a, UINT s)
{
if (*a) Chipset.HST |= SB;
while (--s) { *a = a[1]; a++; }
*a = 0;
}
static __inline void Nsrc(BYTE *a, UINT s)
{
BYTE c = *a;
if (c) Chipset.HST |= SB;
while (--s) { *a = a[1]; a++; }
*a = c;
}
static __inline void Nsrb(BYTE *a, UINT s)
{
if (*a & 1) Chipset.HST |= SB;
while (--s)
{
*a >>= 1;
*a |= ((a[1] & 1) << 3);
a++;
}
*a >>= 1;
}
static __inline void Nbit0(BYTE *a, UINT b)
{
a[b>>2] &= ~(1<<(b&3));
}
static __inline void Nbit1(BYTE *a, UINT b)
{
a[b>>2] |= 1<<(b&3);
}
static __inline void Tbit0(BYTE *a, UINT b)
{
if (a[b>>2] & (1<<(b&3)))
Chipset.carry = FALSE;
else
Chipset.carry = TRUE;
}
static __inline void Tbit1(BYTE *a, UINT b)
{
if (a[b>>2] & (1<<(b&3)))
Chipset.carry = TRUE;
else
Chipset.carry = FALSE;
}
static __inline void Te(BYTE *a, BYTE *b, UINT s)
{
while (s--)
{
if (a[s]!=b[s])
{
Chipset.carry = FALSE;
return;
}
}
Chipset.carry = TRUE;
}
static __inline void Tne(BYTE *a, BYTE *b, UINT s)
{
while (s--)
{
if (a[s]!=b[s])
{
Chipset.carry = TRUE;
return;
}
}
Chipset.carry = FALSE;
}
static __inline void Tz(BYTE *a, UINT s)
{
while (s--)
{
if (a[s]!=0)
{
Chipset.carry = FALSE;
return;
}
}
Chipset.carry = TRUE;
}
static __inline void Tnz(BYTE *a, UINT s)
{
while (s--)
{
if (a[s]!=0)
{
Chipset.carry = TRUE;
return;
}
}
Chipset.carry = FALSE;
}
static __inline void Ta(BYTE *a, BYTE *b, UINT s)
{
while (--s) if (a[s]!=b[s]) break;
if (a[s]>b[s])
Chipset.carry = TRUE;
else
Chipset.carry = FALSE;
}
static __inline void Tb(BYTE *a, BYTE *b, UINT s)
{
while (--s) if (a[s]!=b[s]) break;
if (a[s]<b[s])
Chipset.carry = TRUE;
else
Chipset.carry = FALSE;
}
static __inline void Tae(BYTE *a, BYTE *b, UINT s)
{
while (--s) if (a[s]!=b[s]) break;
if (a[s]>=b[s])
Chipset.carry = TRUE;
else
Chipset.carry = FALSE;
}
static __inline void Tbe(BYTE *a, BYTE *b, UINT s)
{
while (--s) if (a[s]!=b[s]) break;
if (a[s]<=b[s])
Chipset.carry = TRUE;
else
Chipset.carry = FALSE;
}

5
SOURCE/PCH.C Normal file
View file

@ -0,0 +1,5 @@
//
// PCH.C
//
#include "pch.h"

33
SOURCE/PCH.H Normal file
View file

@ -0,0 +1,33 @@
//
// PCH.H
//
#define _WIN32_IE 0x0200
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include <tchar.h>
#include <shellapi.h>
#include <commctrl.h>
#include <shlobj.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <direct.h>
#include <conio.h>
#include <crtdbg.h>
#if !defined VERIFY
#if defined _DEBUG
#define VERIFY(f) _ASSERT(f)
#else // _DEBUG
#define VERIFY(f) ((VOID)(f))
#endif // _DEBUG
#endif // _VERIFY
#if !defined IDC_HAND // Win2k specific definition
#define IDC_HAND MAKEINTRESOURCE(32649)
#endif
// missing type definition in the MSVC6.0 SDK
typedef SIZE_T DWORD_PTR, *PDWORD_PTR;

225
SOURCE/RESOURCE.H Normal file
View file

@ -0,0 +1,225 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Emu48.rc
//
#define IDI_EMU48 100
#define IDR_MENU 101
#define IDR_DEBUG 102
#define IDR_DEBUG_TOOLBAR 103
#define IDR_DEBUG_CODE 104
#define IDR_DEBUG_MEM 105
#define IDR_DEBUG_STACK 106
#define IDB_CHECKBOX 107
#define IDD_ABOUT 108
#define IDD_SETTINGS 109
#define IDD_CHOOSEKML 110
#define IDD_KMLLOG 111
#define IDD_DISASM 112
#define IDD_DEBUG 113
#define IDD_NEWVALUE 114
#define IDD_ENTERADR 115
#define IDD_BREAKEDIT 116
#define IDD_ENTERBREAK 117
#define IDD_INSTRUCTIONS 118
#define IDD_WRITEONLYREG 119
#define IDD_FIND 120
#define IDD_PROFILE 121
#define IDD_MACROSET 122
#define IDC_REALSPEED 1000
#define IDC_GRAYSCALE 1001
#define IDC_AUTOSAVE 1002
#define IDC_AUTOSAVEONEXIT 1003
#define IDC_OBJECTLOADWARNING 1004
#define IDC_ALWAYSDISPLOG 1005
#define IDC_PORT1EN 1006
#define IDC_PORT1WR 1007
#define IDC_PORT2ISSHARED 1008
#define IDC_PORT2WR 1009
#define IDC_PORT2 1010
#define IDC_PORT2LOAD 1011
#define IDC_WIRE 1012
#define IDC_IR 1013
#define IDC_EMUDIR 1014
#define IDC_EMUDIRSEL 1015
#define IDC_UPDATE 1016
#define IDC_KMLSCRIPT 1017
#define IDC_AUTHOR 1018
#define IDC_TITLE 1019
#define IDC_KMLLOG 1020
#define IDC_VERSION 1021
#define IDC_LICENSE 1022
#define IDC_DISASM_WIN 1023
#define IDC_DISASM_MAP 1024
#define IDC_DISASM_ROM 1025
#define IDC_DISASM_RAM 1026
#define IDC_DISASM_PORT1 1027
#define IDC_DISASM_PORT2 1028
#define IDC_DISASM_MODULE 1029
#define IDC_DISASM_HP 1030
#define IDC_DISASM_CLASS 1031
#define IDC_ADDRESS 1032
#define IDC_DISASM_ADR 1033
#define IDC_DISASM_NEXT 1034
#define IDC_DISASM_COPY 1035
#define IDC_DEBUG_CODE 1036
#define IDC_STATIC_CODE 1037
#define IDC_STATIC_REGISTERS 1038
#define IDC_STATIC_MEMORY 1039
#define IDC_STATIC_STACK 1040
#define IDC_REG_A 1041
#define IDC_REG_B 1042
#define IDC_REG_C 1043
#define IDC_REG_D 1044
#define IDC_REG_R0 1045
#define IDC_REG_R1 1046
#define IDC_REG_R2 1047
#define IDC_REG_R3 1048
#define IDC_REG_R4 1049
#define IDC_REG_D0 1050
#define IDC_REG_D1 1051
#define IDC_REG_P 1052
#define IDC_REG_PC 1053
#define IDC_REG_OUT 1054
#define IDC_REG_IN 1055
#define IDC_REG_ST 1056
#define IDC_REG_CY 1057
#define IDC_REG_MODE 1058
#define IDC_REG_MP 1059
#define IDC_REG_SR 1060
#define IDC_REG_SB 1061
#define IDC_REG_XM 1062
#define IDC_MISC_INT 1063
#define IDC_MISC_KEY 1064
#define IDC_MISC_BS 1065
#define IDC_NEWVALUE 1066
#define IDC_ENTERADR 1067
#define IDC_DEBUG_MEM 1068
#define IDC_DEBUG_MEM_ADDR 1069
#define IDC_DEBUG_MEM_COL0 1070
#define IDC_DEBUG_MEM_COL1 1071
#define IDC_DEBUG_MEM_COL2 1072
#define IDC_DEBUG_MEM_COL3 1073
#define IDC_DEBUG_MEM_COL4 1074
#define IDC_DEBUG_MEM_COL5 1075
#define IDC_DEBUG_MEM_COL6 1076
#define IDC_DEBUG_MEM_COL7 1077
#define IDC_DEBUG_MEM_TEXT 1078
#define IDC_DEBUG_STACK 1079
#define IDC_STATIC_BREAKPOINT 1080
#define IDC_BREAKEDIT_ADD 1081
#define IDC_BREAKEDIT_DELETE 1082
#define IDC_BREAKEDIT_WND 1083
#define IDC_STATIC_MMU 1084
#define IDC_MMU_IO_A 1085
#define IDC_MMU_NCE2_A 1086
#define IDC_MMU_CE1_A 1087
#define IDC_MMU_CE2_A 1088
#define IDC_MMU_NCE3_A 1089
#define IDC_MMU_IO_S 1090
#define IDC_MMU_CE1_S 1091
#define IDC_MMU_CE2_S 1092
#define IDC_MMU_NCE2_S 1093
#define IDC_MMU_NCE3_S 1094
#define IDC_STATIC_MISC 1095
#define IDC_MISC_BS_TXT 1096
#define IDC_INSTR_TEXT 1097
#define IDC_INSTR_CODE 1098
#define IDC_INSTR_COPY 1099
#define IDC_INSTR_CLEAR 1100
#define IDC_PROFILE_LASTCYCLES 1101
#define IDC_PROFILE_LASTTIME 1102
#define IDC_BPCODE 1103
#define IDC_BPRPL 1104
#define IDC_BPACCESS 1105
#define IDC_BPREAD 1106
#define IDC_BPWRITE 1107
#define IDC_FIND_DATA 1108
#define IDC_FIND_ASCII 1109
#define IDC_FIND_CASE 1110
#define IDC_ADDR20_24 1111
#define IDC_ADDR25_27 1112
#define IDC_ADDR28_29 1113
#define IDC_ADDR30_34 1114
#define IDC_MACRO_SLOW 1115
#define IDC_MACRO_FAST 1116
#define IDC_MACRO_SLIDER 1117
#define IDC_MACRO_REAL 1118
#define IDC_MACRO_MANUAL 1119
#define IDC_SOUND_SLIDER 1120
#define IDC_SOUND_SPEAKER 1121
#define IDC_SOUND_WAVE 1122
#define ID_FILE_NEW 40001
#define ID_FILE_OPEN 40002
#define ID_FILE_SAVE 40003
#define ID_FILE_SAVEAS 40004
#define ID_FILE_EXIT 40005
#define ID_VIEW_COPY 40006
#define ID_VIEW_SETTINGS 40007
#define ID_VIEW_RESET 40008
#define ID_OBJECT_LOAD 40009
#define ID_OBJECT_SAVE 40010
#define ID_ABOUT 40011
#define ID_FILE_CLOSE 40013
#define ID_BACKUP_SAVE 40014
#define ID_BACKUP_RESTORE 40015
#define ID_BACKUP_DELETE 40016
#define ID_VIEW_SCRIPT 40017
#define ID_STACK_COPY 40019
#define ID_STACK_PASTE 40020
#define ID_TOOL_DISASM 40021
#define ID_TOOL_DEBUG 40022
#define ID_TOOL_MACRO_RECORD 40023
#define ID_TOOL_MACRO_PLAY 40024
#define ID_TOOL_MACRO_STOP 40025
#define ID_TOOL_MACRO_SETTINGS 40026
#define ID_DEBUG_RUN 40027
#define ID_DEBUG_RUNCURSOR 40028
#define ID_DEBUG_STEP 40029
#define ID_DEBUG_STEPOVER 40030
#define ID_DEBUG_BREAK 40031
#define ID_DEBUG_STEPOUT 40032
#define ID_DEBUG_CANCEL 40033
#define ID_BREAKPOINTS_SETBREAK 40034
#define ID_BREAKPOINTS_CODEEDIT 40035
#define ID_BREAKPOINTS_CLEARALL 40036
#define ID_BREAKPOINTS_NOP3 40037
#define ID_BREAKPOINTS_DOCODE 40038
#define ID_BREAKPOINTS_RPL 40039
#define ID_DEBUG_CODE_GOADR 40040
#define ID_DEBUG_CODE_GOPC 40041
#define ID_DEBUG_CODE_SETPCTOSELECT 40042
#define ID_DEBUG_MEM_GOADR 40043
#define ID_DEBUG_MEM_GOPC 40044
#define ID_DEBUG_MEM_GOD0 40045
#define ID_DEBUG_MEM_GOD1 40046
#define ID_DEBUG_MEM_GOSTACK 40047
#define ID_DEBUG_MEM_FNONE 40048
#define ID_DEBUG_MEM_FADDR 40049
#define ID_DEBUG_MEM_FPC 40050
#define ID_DEBUG_MEM_FD0 40051
#define ID_DEBUG_MEM_FD1 40052
#define ID_DEBUG_MEM_FIND 40053
#define ID_DEBUG_MEM_MAP 40054
#define ID_DEBUG_MEM_NCE1 40055
#define ID_DEBUG_MEM_NCE2 40056
#define ID_DEBUG_MEM_CE1 40057
#define ID_DEBUG_MEM_CE2 40058
#define ID_DEBUG_MEM_NCE3 40059
#define ID_DEBUG_STACK_PUSH 40060
#define ID_DEBUG_STACK_POP 40061
#define ID_DEBUG_STACK_MODIFY 40062
#define ID_INTR_STEPOVERINT 40063
#define ID_INFO_LASTINSTRUCTIONS 40064
#define ID_INFO_PROFILE 40065
#define ID_INFO_WRITEONLYREG 40066
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 123
#define _APS_NEXT_COMMAND_VALUE 40067
#define _APS_NEXT_CONTROL_VALUE 1123
#define _APS_NEXT_SYMED_VALUE 108
#endif
#endif

419
SOURCE/RPL.C Normal file
View file

@ -0,0 +1,419 @@
/*
* rpl.c
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#include "pch.h"
#include "Emu48.h"
#include "ops.h"
#include "io.h"
//| 38G | 39G | 40G | 48SX | 48GX | 49G | Name
//#F0688 #806E9 #806E9 #7056A #806E9 #806E9 =TEMPOB
//#F068D #806EE #806EE #7056F #806EE #806EE =TEMPTOP
//#F0692 #806F3 #806F3 #70574 #806F3 #806F3 =RSKTOP (B)
//#F0697 #806F8 #806F8 #70579 #806F8 #806F8 =DSKTOP (D1)
//#F069C #806FD #806FD #7057E #806FD #806FD =EDITLINE
//#F0DEA #80E9B #80E9B #7066E #807ED #80E9B =AVMEM (D)
//#F0705 #8076B #8076B #705B0 #8072F #8076B =INTRPPTR (D0)
//#F0E42 #80F02 #80F02 #706C5 #80843 #80F02 =SystemFlags
#define TEMPOB ((cCurrentRomType=='S')?0x7056A:0x806E9)
#define TEMPTOP ((cCurrentRomType=='S')?0x7056F:0x806EE)
#define RSKTOP ((cCurrentRomType=='S')?0x70574:0x806F3)
#define DSKTOP ((cCurrentRomType=='S')?0x70579:0x806F8)
#define EDITLINE ((cCurrentRomType=='S')?0x7057E:0x806FD)
// CdB for HP: add apples
#define AVMEM ((cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q')?((cCurrentRomType=='S')?0x7066E:0x807ED):0x80E9B)
#define INTRPPTR ((cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q')?((cCurrentRomType=='S')?0x705B0:0x8072F):0x8076B)
#define SYSTEMFLAGS ((cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q')?((cCurrentRomType=='S')?0x706C5:0x80843):0x80F02)
#define DOINT 0x02614 // Precision Integer (HP49G)
#define DOLNGREAL 0x0263A // Precision Real (HP49G)
#define DOLNGCMP 0x02660 // Precision Complex (HP49G)
#define DOMATRIX 0x02686 // Symbolic matrix (HP49G)
#define DOFLASHP 0x026AC // Flash PTR (HP49G)
#define DOAPLET 0x026D5 // Aplet (HP49G)
#define DOMINIFONT 0x026FE // Mini Font (HP49G)
#define DOBINT 0x02911 // System Binary
#define DOREAL 0x02933 // Real
#define DOEREAL 0x02955 // Long Real
#define DOCMP 0x02977 // Complex
#define DOECMP 0x0299D // Long Complex
#define DOCHAR 0x029BF // Character
#define DOARRY 0x029E8 // Array
#define DOLNKARRY 0x02A0A // Linked Array
#define DOCSTR 0x02A2C // String
#define DOHSTR 0x02A4E // Binary Integer
#define DOLIST 0x02A74 // List
#define DORRP 0x02A96 // Directory
#define DOSYMB 0x02AB8 // Algebraic
#define DOTAG 0x02AFC // Tagged
#define DOEXT1 0x02BAA // Extended Pointer
#define DOEXT 0x02ADA // Unit
#define DOGROB 0x02B1E // Graphic
#define DOLIB 0x02B40 // Library
#define DOBAK 0x02B62 // Backup
#define DOEXT0 0x02B88 // Library Data
#define DOEXT2 0x02BCC // Reserved 1, Font (HP49G)
#define DOEXT3 0x02BEE // Reserved 2
#define DOEXT4 0x02C10 // Reserved 3
#define DOCOL 0x02D9D // Program
#define DOCODE 0x02DCC // Code
#define DOIDNT 0x02E48 // Global Name
#define DOLAM 0x02E6D // Local Name
#define DOROMP 0x02E92 // XLIB Name
#define SEMI 0x0312B // ;
#define GARBAGECOL 0x0613E // =GARBAGECOL entry for HP48S/G/GII and HP49G(+)
// check for Metakernel version
#define METAKERNEL Metakernel()
// search for "MDGKER:MK2.30" or "MDGKER:PREVIE" in port1 of a HP48GX
static BOOL Metakernel(VOID)
{
BOOL bMkDetect = FALSE;
// card in slot1 of a HP48GX enabled
if (cCurrentRomType=='G' && Chipset.Port1 && Chipset.cards_status & PORT1_PRESENT)
{
// check for Metakernel string "MDGKER:"
if (!strncmp(&Chipset.Port1[12],"\xD\x4\x4\x4\x7\x4\xB\x4\x5\x4\x2\x5\xA\x3",14))
{
bMkDetect = TRUE; // Metakernel detected
// check for "MK"
if (!strncmp(&Chipset.Port1[26],"\xD\x4\xB\x4",4))
{
// get version number
WORD wVersion = ((Chipset.Port1[30] * 10) + Chipset.Port1[34]) * 10
+ Chipset.Port1[36];
// version newer then V2.30, then compatible with HP OS
bMkDetect = (wVersion <= 230);
}
}
}
return bMkDetect;
}
static DWORD RPL_GarbageCol(VOID) // RPL variables must be in system RAM
{
CHIPSET OrgChipset;
DWORD dwAVMEM;
// only for HP48SX, HP48GX, HP49G, HP48GII and HP49G+
_ASSERT( cCurrentRomType == 'S' || cCurrentRomType == 'G' || cCurrentRomType == 'X'
|| cCurrentRomType == '2' || cCurrentRomType == 'Q');
OrgChipset = Chipset; // save original chipset
// entry for =GARBAGECOL
Chipset.P = 0; // P=0
Chipset.mode_dec = FALSE; // hex mode
Chipset.pc = GARBAGECOL; // =GARBAGECOL entry
rstkpush(0xFFFFF); // return address for stopping
while (Chipset.pc != 0xFFFFF) // wait for stop address
{
EvalOpcode(FASTPTR(Chipset.pc)); // execute opcode
}
dwAVMEM = Npack(Chipset.C,5); // available AVMEM
Chipset = OrgChipset; // restore original chipset
return dwAVMEM;
}
BOOL RPL_GetSystemFlag(INT nFlag)
{
DWORD dwAddr;
BYTE byMask,byFlag;
_ASSERT(nFlag > 0); // first flag is 1
// calculate memory address and bit mask
dwAddr = SYSTEMFLAGS + (nFlag - 1) / 4;
byMask = 1 << ((nFlag - 1) & 0x3);
Npeek(&byFlag,dwAddr,sizeof(byFlag));
return (byFlag & byMask) != 0;
}
DWORD RPL_SkipOb(DWORD d)
{
BYTE X[8];
DWORD n, l;
Npeek(X,d,5);
n = Npack(X, 5); // read prolog
switch (n)
{
case DOFLASHP: l = (cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') ? 5 : 12; break; // Flash PTR (HP49G) // CdB for HP: add apples
case DOBINT: l = 10; break; // System Binary
case DOREAL: l = 21; break; // Real
case DOEREAL: l = 26; break; // Long Real
case DOCMP: l = 37; break; // Complex
case DOECMP: l = 47; break; // Long Complex
case DOCHAR: l = 7; break; // Character
case DOEXT1: l = 15; break; // Extended Pointer
case DOROMP: l = 11; break; // XLIB Name
case DOMATRIX: // Symbolic matrix (HP49G)
if (cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l = 5;
break;
}
case DOLIST: // List
case DOSYMB: // Algebraic
case DOEXT: // Unit
case DOCOL: // Program
n=d+5;
do
{
d=n; n=RPL_SkipOb(d);
} while (d!=n);
return n+5;
case SEMI: return d; // SEMI
case DOIDNT: // Global Name
case DOLAM: // Local Name
case DOTAG: // Tagged
Npeek(X,d+5,2); n = 7 + Npack(X,2)*2;
return RPL_SkipOb(d+n);
case DORRP: // Directory
d+=8;
n = Read5(d);
if (n==0)
{
return d+5;
}
else
{
d+=n;
Npeek(X,d,2);
n = Npack(X,2)*2 + 4;
return RPL_SkipOb(d+n);
}
case DOINT: // Precision Integer (HP49G)
case DOAPLET: // Aplet (HP49G)
case DOMINIFONT: // Mini Font (HP49G)
if (cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l = 5;
break;
}
case DOARRY: // Array
case DOLNKARRY: // Linked Array
case DOCSTR: // String
case DOHSTR: // Binary Integer
case DOGROB: // Graphic
case DOLIB: // Library
case DOBAK: // Backup
case DOEXT0: // Library Data
case DOEXT2: // Reserved 1, Font (HP49G)
case DOEXT3: // Reserved 2
case DOEXT4: // Reserved 3
case DOCODE: // Code
l = 5+Read5(d+5);
break;
case DOLNGREAL: // Precision Real (HP49G)
l = 5;
if (cCurrentRomType=='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l += Read5(d+l);
l += Read5(d+l);
}
break;
case DOLNGCMP: // Precision Complex (HP49G)
l = 5;
if (cCurrentRomType=='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l += Read5(d+l);
l += Read5(d+l);
l += Read5(d+l);
l += Read5(d+l);
}
break;
default: return d+5;
}
return d+l;
}
DWORD RPL_ObjectSize(BYTE *o)
{
DWORD n, l = 0;
n = Npack(o, 5); // read prolog
switch (n)
{
case DOFLASHP: l = (cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') ? 5 : 12; break; // Flash PTR (HP49G) // CdB for HP: add apples
case DOBINT: l = 10; break; // System Binary
case DOREAL: l = 21; break; // Real
case DOEREAL: l = 26; break; // Long Real
case DOCMP: l = 37; break; // Complex
case DOECMP: l = 47; break; // Long Complex
case DOCHAR: l = 7; break; // Character
case DOEXT1: l = 15; break; // Extended Pointer
case DOROMP: l = 11; break; // XLIB Name
case DOMATRIX: // Symbolic matrix (HP49G)
if (cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l = 5;
break;
}
case DOLIST: // List
case DOSYMB: // Algebraic
case DOEXT: // Unit
case DOCOL: // Program
n=5;
do { l+=n; o+=n; n=RPL_ObjectSize(o); } while (n);
l += 5;
break;
case SEMI: l = 0; break; // SEMI
case DOIDNT: // Global Name
case DOLAM: // Local Name
case DOTAG: // Tagged
n = 7 + Npack(o+5,2)*2;
l = n + RPL_ObjectSize(o+n);
break;
case DORRP: // Directory
n = Npack(o+8,5);
if (n==0) // empty dir
{
l=13;
}
else
{
l = 8+n;
n = Npack(o+l,2)*2 + 4;
l += n;
l += RPL_ObjectSize(o+l);
}
break;
case DOINT: // Precision Integer (HP49G)
case DOAPLET: // Aplet (HP49G)
case DOMINIFONT: // Mini Font (HP49G)
if (cCurrentRomType!='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l = 5;
break;
}
case DOARRY: // Array
case DOLNKARRY: // Linked Array
case DOCSTR: // String
case DOHSTR: // Binary Integer
case DOGROB: // Graphic
case DOLIB: // Library
case DOBAK: // Backup
case DOEXT0: // Library Data
case DOEXT2: // Reserved 1, Font (HP49G)
case DOEXT3: // Reserved 2
case DOEXT4: // Reserved 3
case DOCODE: // Code
l = 5 + Npack(o+5,5);
break;
case DOLNGREAL: // Precision Real (HP49G)
l = 5;
if (cCurrentRomType=='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l += Npack(o+l,5);
l += Npack(o+l,5);
}
break;
case DOLNGCMP: // Precision Complex (HP49G)
l = 5;
if (cCurrentRomType=='X' && cCurrentRomType!='2' && cCurrentRomType!='Q') // CdB for HP: add apples
{
l += Npack(o+l,5);
l += Npack(o+l,5);
l += Npack(o+l,5);
l += Npack(o+l,5);
}
break;
default: l=5;
}
return l;
}
DWORD RPL_CreateTemp(DWORD l)
{
DWORD a, b, c;
BYTE *p;
l += 6; // memory for link field (5) + marker (1) and end
b = Read5(RSKTOP); // tail address of rtn stack
c = Read5(DSKTOP); // top of data stack
if ((b+l)>c) // there's not enough memory to move DSKTOP
{
RPL_GarbageCol(); // do a garbage collection
b = Read5(RSKTOP); // reload tail address of rtn stack
c = Read5(DSKTOP); // reload top of data stack
}
if ((b+l)>c) return 0; // check if now there's enough memory to move DSKTOP
a = Read5(TEMPTOP); // tail address of top object
Write5(TEMPTOP, a+l); // adjust new end of top object
Write5(RSKTOP, b+l); // adjust new end of rtn stack
Write5(AVMEM, (c-b-l)/5); // calculate free memory (*5 nibbles)
p = HeapAlloc(hHeap,0,b-a); // move down rtn stack
Npeek(p,a,b-a);
Nwrite(p,a+l,b-a);
HeapFree(hHeap,0,p);
Write5(a+l-5,l); // set object length field
return (a+1); // return base address of new object
}
UINT RPL_Depth(VOID)
{
return (Read5(EDITLINE) - Read5(DSKTOP)) / 5 - 1;
}
DWORD RPL_Pick(UINT l)
{
DWORD stkp;
_ASSERT(l > 0); // first stack element is one
if (l == 0) return 0;
if (METAKERNEL) ++l; // Metakernel support
if (RPL_Depth() < l) return 0; // not enough elements on stack
stkp = Read5(DSKTOP) + (l-1)*5;
return Read5(stkp); // return object address
}
VOID RPL_Replace(DWORD n)
{
DWORD stkp;
stkp = Read5(DSKTOP);
if (METAKERNEL) stkp+=5; // Metakernel support
Write5(stkp,n);
return;
}
VOID RPL_Push(UINT l,DWORD n)
{
UINT i;
DWORD stkp, avmem;
if (l > RPL_Depth() + 1) return; // invalid stack level
avmem = Read5(AVMEM); // amount of free memory
if (avmem == 0) return; // no memory free
avmem--; // fetch memory
Write5(AVMEM,avmem); // save new amount of free memory
if (METAKERNEL) ++l; // Metakernel, save MK object on stack level 1
stkp = Read5(DSKTOP) - 5; // get pointer of new stack level 1
Write5(DSKTOP,stkp); // save it
for (i = 1; i < l; ++i) // move down stack level entries before insert pos
{
Write5(stkp,Read5(stkp+5)); // move down stack level entry
stkp += 5; // next stack entry
}
Write5(stkp,n); // save pointer of new object on given stack level
return;
}

383
SOURCE/SERIAL.C Normal file
View file

@ -0,0 +1,383 @@
/*
* Serial.c
*
* This file is part of Emu48
*
* Copyright (C) 1998 Christoph Gießelink
*
*/
#include "pch.h"
#include "Emu48.h"
#include "io.h"
#define INTERRUPT ((void)(Chipset.SoftInt=TRUE,bInterrupt=TRUE))
// state of USRQ
#define NINT2ERBZ ((Chipset.IORam[IOC] & (SON | ERBZ)) == (SON | ERBZ) && (Chipset.IORam[RCS] & RBZ) != 0)
#define NINT2ERBF ((Chipset.IORam[IOC] & (SON | ERBF)) == (SON | ERBF) && (Chipset.IORam[RCS] & RBF) != 0)
#define NINT2ETBE ((Chipset.IORam[IOC] & (SON | ETBE)) == (SON | ETBE) && (Chipset.IORam[TCS] & TBF) == 0)
#define NINT2USRQ (NINT2ERBZ || NINT2ERBF || NINT2ETBE)
static HANDLE hComm = NULL;
static HANDLE hCThreadTxd;
static HANDLE hCThreadEv;
static HANDLE hEventTxd;
static BOOL bWriting;
static BYTE tbr;
static BOOL bReading;
static BYTE cBuffer[32];
static WORD nRp;
static DWORD dwBytesRead;
static DWORD WINAPI TransmitThread(LPVOID pParam)
{
OVERLAPPED osWr = { 0 };
osWr.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
while (bWriting)
{
WaitForSingleObject(hEventTxd,INFINITE);
if (bWriting)
{
DWORD dwWritten;
if (!WriteFile(hComm,(LPCVOID) &tbr,1,&dwWritten,&osWr))
if (GetLastError() == ERROR_IO_PENDING)
GetOverlappedResult(hComm,&osWr,&dwWritten,TRUE);
}
}
CloseHandle(osWr.hEvent); // close write event handle
return 0;
UNREFERENCED_PARAMETER(pParam);
}
static DWORD WINAPI EventThread(LPVOID pParam)
{
DWORD dwEvent;
bReading = TRUE; // flag for SerialThread started
while (bReading)
{
_ASSERT(hComm != NULL);
WaitCommEvent(hComm,&dwEvent,NULL); // wait for serial event
if (dwEvent & EV_RXCHAR) // signal char received
{
CommReceive(); // get data
// interrupt request and emulation thread down
if (Chipset.SoftInt && Chipset.Shutdn)
{
Chipset.bShutdnWake = TRUE; // wake up from SHUTDN mode
SetEvent(hEventShutdn); // wake up emulation thread
}
}
if (dwEvent & EV_TXEMPTY) // signal transmit buffer empty
{
IOBit(TCS,TBZ,FALSE); // clear transmitter busy bit
CommTransmit(); // check for new char to transmit
}
if (dwEvent & EV_ERR) // signal error received
{
DWORD dwError;
ClearCommError(hComm,&dwError,NULL);
if (dwError & (CE_FRAME | CE_OVERRUN | CE_BREAK))
IOBit(RCS,RER,TRUE); // receiver error
}
}
return 0;
UNREFERENCED_PARAMETER(pParam);
}
BOOL CommOpen(LPTSTR strWirePort,LPTSTR strIrPort)
{
COMMTIMEOUTS CommTimeouts = { MAXDWORD, 0L, 0L, 0L, 0L };
LPCTSTR strPort = (Chipset.IORam[IR_CTRL] & EIRU) ? strIrPort : strWirePort;
_ASSERT(Chipset.IORam[IOC] & SON); // UART on
CommClose(); // close port if already open
if (lstrcmp(strPort, _T(NO_SERIAL))) // port defined
{
TCHAR szDevice[16] = _T("\\\\.\\");
// check if device buffer is big enough
_ASSERT(lstrlen(szDevice) + lstrlen(strPort) < ARRAYSIZEOF(szDevice));
if (lstrlen(szDevice) + lstrlen(strPort) >= ARRAYSIZEOF(szDevice))
return hComm != NULL;
_tcscat(szDevice,strPort); // device name
hComm = CreateFile(szDevice,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
if(hComm != INVALID_HANDLE_VALUE)
{
DWORD dwThreadId;
nRp = 0; // reset receiver state
dwBytesRead = 0L;
SetCommTimeouts(hComm,&CommTimeouts);
CommSetBaud();
CommTxBRK(); // update BRK condition
// event to transmit character
hEventTxd = CreateEvent(NULL,FALSE,FALSE,NULL);
// create char transmit handler
bWriting = TRUE;
hCThreadTxd = CreateThread(NULL,0,&TransmitThread,NULL,CREATE_SUSPENDED,&dwThreadId);
_ASSERT(hCThreadTxd);
SetThreadPriority(hCThreadTxd,THREAD_PRIORITY_ABOVE_NORMAL);
ResumeThread(hCThreadTxd); // start thread
// create Comm event handler
bReading = FALSE;
SetCommMask(hComm,EV_RXCHAR | EV_TXEMPTY | EV_ERR); // event on RX, TX, error
hCThreadEv = CreateThread(NULL,0,&EventThread,NULL,CREATE_SUSPENDED,&dwThreadId);
_ASSERT(hCThreadEv);
SetThreadPriority(hCThreadEv,THREAD_PRIORITY_ABOVE_NORMAL);
ResumeThread(hCThreadEv); // start thread
while (!bReading) Sleep(0); // wait for SerialThread started
}
else
hComm = NULL;
}
#if defined DEBUG_SERIAL
{
TCHAR buffer[256];
wsprintf(buffer,_T("COM port %s.\n"),hComm ? _T("opened"): _T("open error"));
OutputDebugString(buffer);
}
#endif
return hComm != NULL;
}
VOID CommClose(VOID)
{
if (hComm != NULL) // port open
{
// workaround to fix problems with some Kermit server programs
// reason: on one hand we have the character transmitting time base on the
// selected baudrate, on the other hand the time between sending the last
// character and closing the port. The last time is much longer on the real
// calculator than on the emulator running at full speed, therefore the
// slow down time on the emulator
Sleep(25); // slow down time
bReading = FALSE; // kill event thread
SetCommMask(hComm,0L); // clear all events and force WaitCommEvent to return
WaitForSingleObject(hCThreadEv,INFINITE);
CloseHandle(hCThreadEv);
bWriting = FALSE; // kill write thread
SetEvent(hEventTxd); // continue write thread
WaitForSingleObject(hCThreadTxd,INFINITE);
CloseHandle(hCThreadTxd);
CloseHandle(hEventTxd); // close Txd event
CloseHandle(hComm); // close port
hComm = NULL;
#if defined DEBUG_SERIAL
OutputDebugString(_T("COM port closed.\n"));
#endif
}
return;
}
VOID CommSetBaud(VOID)
{
if (hComm != NULL)
{
const DWORD dwBaudrates[] = { 1200, 1920, 2400, 3840, 4800, 7680, 9600, 15360 };
// const DWORD dwAppleBaudrates[] = { 1200, 1920, 2400, 3840, 4800, 7680, 9600, 14400, 15360, 19200, 38400, 57600, 115200 };
DCB dcb;
ZeroMemory(&dcb,sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = dwBaudrates[Chipset.IORam[BAUD] & 0x7];
dcb.fBinary = TRUE;
dcb.fParity = TRUE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE; // may changed in further implementations
dcb.ByteSize = 8;
dcb.Parity = NOPARITY; // no parity check, emulated by software
dcb.StopBits = TWOSTOPBITS;
#if defined DEBUG_SERIAL
{
TCHAR buffer[256];
wsprintf(buffer,_T("CommsetBaud: %ld\n"),dcb.BaudRate);
OutputDebugString(buffer);
}
#endif
SetCommState(hComm,&dcb);
}
return;
}
BOOL UpdateUSRQ(VOID) // USRQ handling
{
BOOL bUSRQ = NINT2USRQ;
IOBit(SRQ1,USRQ,bUSRQ); // update USRQ bit
return bUSRQ;
}
VOID CommTxBRK(VOID)
{
if (Chipset.IORam[TCS] & BRK) // BRK condition
{
if (hComm != NULL) // com port open
{
// abort data transfer
PurgeComm(hComm,PURGE_TXABORT | PURGE_TXCLEAR);
SetCommBreak(hComm); // set into BRK state
}
// TBF and TBZ bits of TCS are undefined
if (Chipset.IORam[TCS] & LPB) // is loopback bit set
{
dwBytesRead = nRp = 0; // clear receive buffer
cBuffer[dwBytesRead++] = 0; // save character in receive buffer
CommReceive(); // receive available byte
IOBit(RCS,RER,TRUE); // receiver error (no stop bit)
}
}
else
{
if (hComm != NULL) // com port open
{
ClearCommBreak(hComm); // clear BRK state
}
}
return;
}
VOID CommTransmit(VOID)
{
BOOL bTxChar = FALSE;
EnterCriticalSection(&csTxdLock);
if ( (Chipset.IORam[TCS] & TBZ) == 0 // transmitter not busy
&& (Chipset.IORam[TCS] & TBF) != 0) // transmit buffer full
{
tbr = (Chipset.IORam[TBR_MSB] << 4) | Chipset.IORam[TBR_LSB];
IOBit(TCS,TBF,FALSE); // clear transmit buffer full bit
IOBit(TCS,TBZ,TRUE); // set transmitter busy bit
bTxChar = TRUE;
}
LeaveCriticalSection(&csTxdLock);
if (bTxChar) // character to transmit
{
#if defined DEBUG_SERIAL
{
TCHAR buffer[256];
if (isprint(tbr))
wsprintf(buffer,_T("-> '%c'\n"),tbr);
else
wsprintf(buffer,_T("-> %02X\n"),tbr);
OutputDebugString(buffer);
}
#endif
if (Chipset.IORam[TCS] & LPB) // is loopback bit set
{
if (dwBytesRead == 0) nRp = 0; // no character received, reset read pointer
cBuffer[nRp+dwBytesRead] = tbr; // save character in receive buffer
++dwBytesRead;
CommReceive(); // receive available byte
}
if (hComm != NULL) // com port open
{
SetEvent(hEventTxd); // write TBR byte
}
else
{
IOBit(TCS,TBZ,FALSE); // clear transmitter busy bit
}
}
if (UpdateUSRQ()) // update USRQ bit
INTERRUPT;
return;
}
VOID CommReceive(VOID)
{
OVERLAPPED os = { 0 };
if (!(Chipset.IORam[IOC] & SON)) // UART off
{
dwBytesRead = 0L; // no bytes received
return;
}
EnterCriticalSection(&csRecvLock);
do
{
if (Chipset.IORam[RCS] & RBF) // receive buffer full
break;
// reject reading if com port is closed and not whole operation
if (hComm && dwBytesRead == 0L) // com port open and buffer empty
{
if(ReadFile(hComm,&cBuffer,sizeof(cBuffer),&dwBytesRead,&os) == FALSE)
dwBytesRead = 0L;
else // bytes received
nRp = 0; // reset read pointer
}
if(dwBytesRead == 0L) // receive buffer empty
break;
#if defined DEBUG_SERIAL
{
TCHAR buffer[256];
if (isprint(cBuffer[nRp]))
wsprintf(buffer,_T("<- '%c'\n"),cBuffer[nRp]);
else
wsprintf(buffer,_T("<- %02X\n"),cBuffer[nRp]);
OutputDebugString(buffer);
}
#endif
Chipset.IORam[RBR_MSB] = (cBuffer[nRp] >> 4);
Chipset.IORam[RBR_LSB] = (cBuffer[nRp] & 0x0f);
++nRp;
--dwBytesRead;
Chipset.IORam[RCS] |= RBF; // receive buffer full
if(UpdateUSRQ()) // update USRQ bit
INTERRUPT;
}
while(0);
LeaveCriticalSection(&csRecvLock);
return;
}

222
SOURCE/SETTINGS.C Normal file
View file

@ -0,0 +1,222 @@
/*
* settings.c
*
* This file is part of Emu48
*
* Copyright (C) 2000 Christoph Gießelink
*
*/
#include "pch.h"
#include "Emu48.h"
#include "i28f160.h"
// #define REGISTRY // use registry instead of *.ini file
//################
//#
//# Low level subroutines
//#
//################
#if !defined REGISTRY
// INI-file handling
#if !defined EMU48_INI
#define EMU48_INI "Emu48.ini"
#endif
#define ReadString(sec,key,dv,v,sv) GetPrivateProfileString(sec,key,dv,v,sv,_T(EMU48_INI))
#define ReadInt(sec,key,dv) GetPrivateProfileInt(sec,key,dv,_T(EMU48_INI));
#define WriteString(sec,key,v) WritePrivateProfileString(sec,key,v,_T(EMU48_INI))
#define WriteInt(sec,key,v) WritePrivateProfileInt(sec,key,v,_T(EMU48_INI))
static BOOL WritePrivateProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue, LPCTSTR lpszFilename)
{
TCHAR s[16];
wsprintf(s,_T("%i"),nValue);
return WritePrivateProfileString(lpszSection, lpszEntry, s, lpszFilename);
}
#else
// registry handling
#if !defined REGISTRYKEY
#define REGISTRYKEY "Software\\Emu48"
#endif
#define ReadString(sec,key,dv,v,sv) GetRegistryString(sec,key,dv,v,sv)
#define ReadInt(sec,key,dv) GetRegistryInt(sec,key,dv)
#define WriteString(sec,key,v) WriteReg(sec,key,REG_SZ,(BYTE *) v,(lstrlen(v)+1) * sizeof(*v))
#define WriteInt(sec,key,v) WriteReg(sec,key,REG_DWORD,(BYTE *) &v,sizeof(int))
static VOID ReadReg(LPCTSTR lpSubKey, LPCTSTR lpValueName, LPBYTE lpData, DWORD *pdwSize)
{
TCHAR lpKey[256] = _T(REGISTRYKEY) _T("\\");
DWORD retCode,dwType;
HKEY hKey;
lstrcat(lpKey, lpSubKey); // full registry key
retCode = RegOpenKeyEx(HKEY_CURRENT_USER,
lpKey,
0,
KEY_QUERY_VALUE,
&hKey);
if (retCode == ERROR_SUCCESS)
{
retCode = RegQueryValueEx(hKey,lpValueName,NULL,&dwType,lpData,pdwSize);
RegCloseKey(hKey);
}
if (retCode != ERROR_SUCCESS) // registry entry not found
*pdwSize = 0; // return zero size
return;
}
static VOID WriteReg(LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
{
TCHAR lpKey[256] = _T(REGISTRYKEY) _T("\\");
DWORD retCode;
HKEY hKey;
DWORD dwDisposition;
lstrcat(lpKey, lpSubKey); // full registry key
retCode = RegCreateKeyEx(HKEY_CURRENT_USER,
lpKey,
0,_T(""),
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey,
&dwDisposition);
_ASSERT(retCode == ERROR_SUCCESS);
RegSetValueEx(hKey,lpValueName,0,dwType,lpData,cbData);
RegCloseKey(hKey);
return;
}
static DWORD GetRegistryString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpDefault, LPTSTR lpData, DWORD dwSize)
{
dwSize *= sizeof(*lpData); // buffer size in bytes
ReadReg(lpszSection,lpszEntry,(LPBYTE) lpData,&dwSize);
if (dwSize == 0)
{
lstrcpy(lpData,lpDefault);
dwSize = lstrlen(lpData);
}
else
{
dwSize = (dwSize / sizeof(*lpData)) - 1;
}
return dwSize;
}
static INT GetRegistryInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, INT nDefault)
{
UINT nValue;
DWORD dwSize = sizeof(nValue);
ReadReg(lpszSection,lpszEntry,(LPBYTE) &nValue,&dwSize);
return dwSize ? nValue : nDefault;
}
#endif
//################
//#
//# Public functions
//#
//################
VOID ReadSettings(VOID)
{
// Files
ReadString(_T("Files"),_T("Emu48Directory"),szCurrentDirectory,szEmuDirectory,ARRAYSIZEOF(szEmuDirectory));
bAutoSave = ReadInt(_T("Files"),_T("AutoSave"),bAutoSave);
bAutoSaveOnExit = ReadInt(_T("Files"),_T("AutoSaveOnExit"),bAutoSaveOnExit);
bSaveDefConfirm = ReadInt(_T("Files"),_T("SaveDefaultConfirm"),bSaveDefConfirm);
bLoadObjectWarning = ReadInt(_T("Files"),_T("LoadObjectWarning"),bLoadObjectWarning);
// Port2
bPort2IsShared = ReadInt(_T("Port2"),_T("IsShared"),bPort2IsShared);
ReadString(_T("Port2"),_T("Filename"),_T("SHARED.BIN"),szPort2Filename,ARRAYSIZEOF(szPort2Filename));
// KML
bAlwaysDisplayLog = ReadInt(_T("KML"),_T("AlwaysDisplayLog"),bAlwaysDisplayLog);
bClassicCursor = ReadInt(_T("KML"),_T("ClassicCursor"),bClassicCursor);
// Disassembler
disassembler_mode = ReadInt(_T("Disassembler"),_T("Mnemonics"),disassembler_mode);
// Emulator
bRealSpeed = ReadInt(_T("Emulator"),_T("RealSpeed"),bRealSpeed);
dwSXCycles = ReadInt(_T("Emulator"),_T("SXCycles"),dwSXCycles);
dwGXCycles = ReadInt(_T("Emulator"),_T("GXCycles"),dwGXCycles);
dwGPCycles = ReadInt(_T("Emulator"),_T("GPCycles"),dwGPCycles); // CdB for HP: add apples
dwG2Cycles = ReadInt(_T("Emulator"),_T("G2Cycles"),dwG2Cycles); // CdB for HP: add apples
bGrayscale = ReadInt(_T("Emulator"),_T("Grayscale"),bGrayscale);
bWaveBeep = ReadInt(_T("Emulator"),_T("WaveBeep"),bWaveBeep);
dwWaveVol = ReadInt(_T("Emulator"),_T("WaveVolume"),dwWaveVol);
SetSpeed(bRealSpeed); // set speed
// Macro
bMacroRealSpeed = ReadInt(_T("Macro"),_T("RealSpeed"),bMacroRealSpeed);
nMacroTimeout = ReadInt(_T("Macro"),_T("ReplayTimeout"),nMacroTimeout);
// Serial
ReadString(_T("Serial"),_T("Wire"),_T(NO_SERIAL),szSerialWire,ARRAYSIZEOF(szSerialWire));
ReadString(_T("Serial"),_T("Ir"),_T(NO_SERIAL),szSerialIr,ARRAYSIZEOF(szSerialIr));
// ROM
bRomWriteable = ReadInt(_T("ROM"),_T("Writeable"),bRomWriteable);
bWP = ReadInt(_T("ROM"),_T("WP#"),bWP);
return;
}
VOID WriteSettings(VOID)
{
// Files
WriteString(_T("Files"),_T("Emu48Directory"),szEmuDirectory);
WriteInt(_T("Files"),_T("AutoSave"),bAutoSave);
WriteInt(_T("Files"),_T("AutoSaveOnExit"),bAutoSaveOnExit);
WriteInt(_T("Files"),_T("AutoSaveOnExit"),bAutoSaveOnExit);
WriteInt(_T("Files"),_T("LoadObjectWarning"),bLoadObjectWarning);
// Port2
WriteInt(_T("Port2"),_T("IsShared"),bPort2IsShared);
WriteString(_T("Port2"),_T("Filename"),szPort2Filename);
// KML
WriteInt(_T("KML"),_T("AlwaysDisplayLog"),bAlwaysDisplayLog);
WriteInt(_T("KML"),_T("ClassicCursor"),bClassicCursor);
// Disassembler
WriteInt(_T("Disassembler"),_T("Mnemonics"),disassembler_mode);
// Emulator
WriteInt(_T("Emulator"),_T("RealSpeed"),bRealSpeed);
WriteInt(_T("Emulator"),_T("SXCycles"),dwSXCycles);
WriteInt(_T("Emulator"),_T("GXCycles"),dwGXCycles);
WriteInt(_T("Emulator"),_T("GPCycles"),dwGPCycles); // CdB for HP: add apples
WriteInt(_T("Emulator"),_T("G2Cycles"),dwG2Cycles); // CdB for HP: add apples
WriteInt(_T("Emulator"),_T("Grayscale"),bGrayscale);
WriteInt(_T("Emulator"),_T("WaveBeep"),bWaveBeep);
WriteInt(_T("Emulator"),_T("WaveVolume"),dwWaveVol);
// Macro
WriteInt(_T("Macro"),_T("RealSpeed"),bMacroRealSpeed);
WriteInt(_T("Macro"),_T("ReplayTimeout"),nMacroTimeout);
// Serial
WriteString(_T("Serial"),_T("Wire"),szSerialWire);
WriteString(_T("Serial"),_T("Ir"),szSerialIr);
// ROM
WriteInt(_T("ROM"),_T("Writeable"),bRomWriteable);
return;
}
VOID ReadLastDocument(LPTSTR szFilename, DWORD nSize)
{
ReadString(_T("Files"),_T("LastDocument"),_T(""),szFilename,nSize);
return;
}
VOID WriteLastDocument(LPCTSTR szFilename)
{
WriteString(_T("Files"),_T("LastDocument"),szFilename);
return;
}

674
SOURCE/STACK.C Normal file
View file

@ -0,0 +1,674 @@
/*
* stack.c
*
* This file is part of Emu48
*
* Copyright (C) 2005 Christoph Gießelink
*
*/
#include "pch.h"
#include "resource.h"
#include "Emu48.h"
#include "io.h"
#define fnRadix 51 // fraction mark
#define fnApprox 105 // exact / approx. mode (HP49G)
#define DOINT 0x02614 // Precision Integer (HP49G)
#define DOREAL 0x02933 // Real
#define DOCSTR 0x02A2C // String
//################
//#
//# Low level subroutines
//#
//################
static INT RPL_GetZInt(BYTE CONST *pbyNum,INT nIntLen,LPTSTR cp,INT nSize)
{
INT i = 0; // character counter
_ASSERT(nSize > 0); // target buffer size
if (nIntLen > 1) // has sign nibble
{
--nIntLen; // remove sign from digit length
// check for valid sign
_ASSERT(pbyNum[nIntLen] == 0 || pbyNum[nIntLen] == 9);
if (pbyNum[nIntLen] == 9) // negative number
{
*cp++ = _T('-'); // add sign
--nSize; // dec dest buffer size
++i; // wrote one character
}
}
if (nIntLen >= nSize) return 0; // dest buffer overflow
i += nIntLen; // adjust character counter
while (nIntLen-- > 0) // write all digits
{
// check for valid digit
_ASSERT(pbyNum[nIntLen] >= 0 && pbyNum[nIntLen] <= 9);
*cp++ = _T('0') + pbyNum[nIntLen]; // and write
}
*cp = 0; // set EOS
return i;
}
static INT RPL_SetZInt(LPCTSTR cp,LPBYTE pbyNum,INT nSize)
{
BYTE bySign;
INT nStrLen,nNumSize;
_ASSERT(nSize > 0); // target buffer size
nStrLen = lstrlen(cp); // source string length
if ( nStrLen == 0 // empty string
// precisition integer contain only these numbers
|| _tcsspn(cp,_T("0123456789+-")) != (SIZE_T) nStrLen)
return 0;
bySign = (*cp != _T('-')) ? 0 : 9; // set sign nibble
if (*cp == _T('-') || *cp == _T('+')) // skip sign character
{
++cp;
--nStrLen;
}
if (nStrLen == 1 && *cp == _T('0')) // special code for zero
{
*pbyNum = 0; // zero data
return 1; // finish
}
// nStrLen = no. of digits without sign
if (nStrLen >= nSize) // destination buffer too small
return 0;
nNumSize = nStrLen + 1; // no. of written data
while (--nStrLen >= 0) // eval all digits
{
TCHAR c = cp[nStrLen];
// only '0' .. '9' are valid here
if (!((c >= _T('0')) || (c <= _T('9'))))
return 0;
c -= _T('0');
*pbyNum++ = (BYTE) c;
}
*pbyNum = bySign; // add sign
return nNumSize;
}
static INT RPL_GetBcd(BYTE CONST *pbyNum,INT nMantLen,INT nExpLen,CONST TCHAR cDec,LPTSTR cp,INT nSize)
{
BYTE byNib;
LONG v,lExp;
BOOL bPflag,bExpflag;
INT i;
lExp = 0;
for (v = 1; nExpLen--; v *= 10) // fetch exponent
{
lExp += (LONG) *pbyNum++ * v; // calc. exponent
}
if (lExp > v / 2) lExp -= v; // negative exponent
lExp -= nMantLen - 1; // set decimal point to end of mantissa
i = 0; // first character
bPflag = FALSE; // show no decimal point
// scan mantissa
for (v = (LONG) nMantLen - 1; v >= 0 || bPflag; v--)
{
if (v >= 0L) // still mantissa digits left
byNib = *pbyNum++;
else
byNib = 0; // zero for negativ exponent
if (!i) // still delete zeros at end
{
if (byNib == 0 && lExp && v > 0) // delete zeros
{
lExp++; // adjust exponent
continue;
}
// TRUE at x.E
bExpflag = v + lExp > 14 || v + lExp < -nMantLen;
bPflag = !bExpflag && v < -lExp; // decimal point flag at neg. exponent
}
// set decimal point
if ((bExpflag && v == 0) || (!lExp && i))
{
if (i >= nSize) return 0; // dest buffer overflow
cp[i++] = cDec; // write decimal point
if (v < 0) // no mantissa digits any more
{
if (i >= nSize) return 0; // dest buffer overflow
cp[i++] = _T('0'); // write heading zero
}
bPflag = FALSE; // finished with negativ exponents
}
if (v >= 0 || bPflag)
{
if (i >= nSize) return 0; // dest buffer overflow
cp[i++] = (TCHAR) byNib + _T('0'); // write character
}
lExp++; // next position
}
if (*pbyNum == 9) // negative number
{
if (i >= nSize) return 0; // dest buffer overflow
cp[i++] = _T('-'); // write sign
}
if (i >= nSize) return 0; // dest buffer overflow
cp[i] = 0; // set EOS
for (v = 0; v < (i / 2); v++) // reverse string
{
TCHAR cNib = cp[v]; // swap chars
cp[v] = cp[i-v-1];
cp[i-v-1] = cNib;
}
// write number with exponent
if (bExpflag)
{
if (i + 5 >= nSize) return 0; // dest buffer overflow
i += wsprintf(&cp[i],_T("E%d"),lExp-1);
}
return i;
}
static INT RPL_SetBcd(LPCTSTR cp,INT nMantLen,INT nExpLen,CONST TCHAR cDec,LPBYTE pbyNum,INT nSize)
{
TCHAR cVc[] = _T(".0123456789eE+-");
BYTE byNum[80];
INT i,nIp,nDp,nMaxExp;
LONG lExp;
cVc[0] = cDec; // replace decimal char
if ( nMantLen + nExpLen >= nSize // destination buffer too small
|| !*cp // empty string
|| _tcsspn(cp,cVc) != (SIZE_T) lstrlen(cp) // real contain only these numbers
|| lstrlen(cp) >= ARRAYSIZEOF(byNum)) // ignore too long reals
return 0;
byNum[0] = (*cp != _T('-')) ? 0 : 9; // set sign nibble
if (*cp == _T('-') || *cp == _T('+')) // skip sign character
cp++;
// only '.', '0' .. '9' are valid here
if (!((*cp == cDec) || (*cp >= _T('0')) || (*cp <= _T('9'))))
return 0;
nIp = 0; // length of integer part
if (*cp != cDec) // no decimal point
{
// count integer part
while (*cp >= _T('0') && *cp <= _T('9'))
byNum[++nIp] = *cp++ - _T('0');
if (!nIp) return 0;
}
// only '.', 'E', 'e' or end are valid here
if (!(!*cp || (*cp == cDec) || (*cp == _T('E')) || (*cp == _T('e'))))
return 0;
nDp = 0; // length of decimal part
if (*cp == cDec) // decimal point
{
cp++; // skip '.'
// count decimal part
while (*cp >= _T('0') && *cp <= _T('9'))
byNum[nIp + ++nDp] = *cp++ - _T('0');
}
// count number of heading zeros in mantissa
for (i = 0; byNum[i+1] == 0 && i + 1 < nIp + nDp; ++i) { }
if (i > 0) // have to normalize
{
INT j;
nIp -= i; // for later ajust of exponent
for (j = 1; j <= nIp + nDp; ++j) // normalize mantissa
byNum[j] = byNum[j + i];
}
if(byNum[1] == 0) // number is 0
{
ZeroMemory(pbyNum,nMantLen + nExpLen + 1);
return nMantLen + nExpLen + 1;
}
for (i = nIp + nDp; i < nMantLen;) // fill rest of mantissa with 0
byNum[++i] = 0;
// must be 'E', 'e' or end
if (!(!*cp || (*cp == _T('E')) || (*cp == _T('e'))))
return 0;
lExp = 0;
if (*cp == _T('E') || *cp == _T('e'))
{
cp++; // skip 'E'
i = FALSE; // positive exponent
if (*cp == _T('-') || *cp == _T('+'))
{
i = (*cp++ == _T('-')); // adjust exponent sign
}
// exponent symbol must be followed by number
if (*cp < _T('0') || *cp > _T('9')) return 0;
while (*cp >= _T('0') && *cp <= _T('9'))
lExp = lExp * 10 + *cp++ - _T('0');
if(i) lExp = -lExp;
}
if (*cp != 0) return 0;
// adjust exponent value with exponent from normalized mantissa
lExp += nIp - 1;
// calculate max. posive exponent
for (nMaxExp = 5, i = 1; i < nExpLen; ++i)
nMaxExp *= 10;
// check range of exponent
if ((lExp < 0 && -lExp >= nMaxExp) || (lExp >= nMaxExp))
return 0;
if (lExp < 0) lExp += 2 * nMaxExp; // adjust negative offset
for (i = nExpLen; i > 0; --i) // convert number into digits
{
byNum[nMantLen + i] = (BYTE) (lExp % 10);
lExp /= 10;
}
// copy to target in reversed order
for (i = nMantLen + nExpLen; i >= 0; --i)
*pbyNum++ = byNum[i];
return nMantLen + nExpLen + 1;
}
//################
//#
//# Object subroutines
//#
//################
#if 0
static INT IsRealNumber(LPCTSTR cp,INT nMantLen,INT nExpLen,CONST TCHAR cDec,LPBYTE pbyNum,INT nSize)
{
LPTSTR lpszNumber;
INT nLength = 0;
if ((lpszNumber = DuplicateString(cp)) != NULL)
{
LPTSTR p = lpszNumber;
INT i;
// cut heading whitespaces
for (; *p == _T(' ') || *p == _T('\t'); ++p) { }
// cut tailing whitespaces
for (i = lstrlen(p); --i >= 0;)
{
if (p[i] != _T(' ') && p[i] != _T('\t'))
break;
}
p[++i] = 0; // new EOS
nLength = RPL_SetBcd(p,nMantLen,nExpLen,cDec,pbyNum,nSize);
HeapFree(hHeap,0,lpszNumber);
}
return nLength;
}
#endif
static TCHAR GetRadix(VOID)
{
// get locale decimal point
// GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SDECIMAL,&cDecimal,1);
return RPL_GetSystemFlag(fnRadix) ? _T(',') : _T('.');
}
static INT DoInt(DWORD dwAddress,LPTSTR cp,INT nSize)
{
LPBYTE lpbyData;
INT nLength,nIntLen;
nIntLen = Read5(dwAddress) - 5; // no. of digits
if (nIntLen <= 0) return 0; // error in calculator object
nLength = 0;
if ((lpbyData = HeapAlloc(hHeap,0,nIntLen)))
{
// get precisition integer object content and decode it
Npeek(lpbyData,dwAddress+5,nIntLen);
nLength = RPL_GetZInt(lpbyData,nIntLen,cp,nSize);
HeapFree(hHeap,0,lpbyData);
}
return nLength;
}
static INT DoReal(DWORD dwAddress,LPTSTR cp,INT nSize)
{
BYTE byNumber[16];
// get real object content and decode it
Npeek(byNumber,dwAddress,ARRAYSIZEOF(byNumber));
return RPL_GetBcd(byNumber,12,3,GetRadix(),cp,nSize);
}
//################
//#
//# Stack routines
//#
//################
//
// ID_STACK_COPY
//
LRESULT OnStackCopy(VOID) // copy data from stack
{
TCHAR cBuffer[128];
HANDLE hClipObj;
LPBYTE lpbyData;
DWORD dwAddress,dwObject,dwSize;
UINT uClipboardFormat;
_ASSERT(nState == SM_RUN); // emulator must be in RUN state
if (WaitForSleepState()) // wait for cpu SHUTDN then sleep state
{
InfoMessage(_T("The emulator is busy."));
return 0;
}
_ASSERT(nState == SM_SLEEP);
if ((dwAddress = RPL_Pick(1)) == 0) // pick address of level1 object
{
MessageBeep(MB_OK); // error beep
goto error;
}
switch (dwObject = Read5(dwAddress)) // select object
{
case DOINT: // Precision Integer (HP49G)
case DOREAL: // real object
dwAddress += 5; // object content
switch (dwObject)
{
case DOINT: // Precision Integer (HP49G)
// get precision integer object content and decode it
dwSize = DoInt(dwAddress,cBuffer,ARRAYSIZEOF(cBuffer));
break;
case DOREAL: // real object
// get real object content and decode it
dwSize = DoReal(dwAddress,cBuffer,ARRAYSIZEOF(cBuffer));
break;
}
// calculate buffer size
dwSize = (dwSize + 1) * sizeof(*cBuffer);
// memory allocation for clipboard data
if ((hClipObj = GlobalAlloc(GMEM_MOVEABLE,dwSize)) == NULL)
goto error;
if ((lpbyData = GlobalLock(hClipObj)))
{
// copy data to memory
CopyMemory(lpbyData,cBuffer,dwSize);
GlobalUnlock(hClipObj); // unlock memory
}
#if defined _UNICODE
uClipboardFormat = CF_UNICODETEXT;
#else
uClipboardFormat = CF_TEXT;
#endif
break;
case DOCSTR: // string
dwAddress += 5; // address of string length
dwSize = (Read5(dwAddress) - 5) / 2; // length of string
// memory allocation for clipboard data
if ((hClipObj = GlobalAlloc(GMEM_MOVEABLE,dwSize + 1)) == NULL)
goto error;
if ((lpbyData = GlobalLock(hClipObj))) // lock memory
{
// copy data into clipboard buffer
for (dwAddress += 5;dwSize-- > 0;dwAddress += 2,++lpbyData)
*lpbyData = Read2(dwAddress);
*lpbyData = 0; // set EOS
GlobalUnlock(hClipObj); // unlock memory
uClipboardFormat = CF_TEXT; // always text
}
break;
default:
MessageBeep(MB_OK); // error beep
goto error;
}
if (OpenClipboard(hWnd))
{
if (EmptyClipboard())
SetClipboardData(uClipboardFormat,hClipObj);
else
GlobalFree(hClipObj);
CloseClipboard();
}
else // clipboard open failed
{
GlobalFree(hClipObj);
}
error:
SwitchToState(SM_RUN);
return 0;
}
//
// ID_STACK_PASTE
//
LRESULT OnStackPaste(VOID) // paste data to stack
{
#if defined _UNICODE
#define CF_TEXTFORMAT CF_UNICODETEXT
#else
#define CF_TEXTFORMAT CF_TEXT
#endif
HANDLE hClipObj;
BOOL bSuccess = FALSE;
// check if clipboard format is available
if (!IsClipboardFormatAvailable(CF_TEXTFORMAT))
{
MessageBeep(MB_OK); // error beep
return 0;
}
SuspendDebugger(); // suspend debugger
bDbgAutoStateCtrl = FALSE; // disable automatic debugger state control
// calculator off, turn on
if (!(Chipset.IORam[BITOFFSET]&DON))
{
KeyboardEvent(TRUE,0,0x8000);
KeyboardEvent(FALSE,0,0x8000);
// wait for sleep mode
while(Chipset.Shutdn == FALSE) Sleep(0);
}
_ASSERT(nState == SM_RUN); // emulator must be in RUN state
if (WaitForSleepState()) // wait for cpu SHUTDN then sleep state
{
InfoMessage(_T("The emulator is busy."));
goto cancel;
}
_ASSERT(nState == SM_SLEEP);
if (OpenClipboard(hWnd))
{
if ((hClipObj = GetClipboardData(CF_TEXTFORMAT)))
{
LPCTSTR lpstrClipdata;
LPBYTE lpbyData;
if ((lpstrClipdata = GlobalLock(hClipObj)))
{
BYTE byNumber[128];
DWORD dwAddress;
INT s;
do
{
// HP49G or HP49G+ in exact mode
if ( (cCurrentRomType == 'X' || cCurrentRomType == 'Q')
&& !RPL_GetSystemFlag(fnApprox))
{
// try to convert string to HP49 precision integer
s = RPL_SetZInt(lpstrClipdata,byNumber,sizeof(byNumber));
if (s > 0) // is a real number for exact mode
{
// get TEMPOB memory for HP49 precision integer object
dwAddress = RPL_CreateTemp(s+5+5);
if ((bSuccess = (dwAddress > 0)))
{
Write5(dwAddress,DOINT); // prolog
Write5(dwAddress+5,s+5); // size
Nwrite(byNumber,dwAddress+10,s); // data
// push object to stack
RPL_Push(1,dwAddress);
}
break;
}
}
// try to convert string to real format
s = RPL_SetBcd(lpstrClipdata,12,3,GetRadix(),byNumber,sizeof(byNumber));
if (s > 0) // is a real number
{
// get TEMPOB memory for real object
dwAddress = RPL_CreateTemp(16+5);
if ((bSuccess = (dwAddress > 0)))
{
Write5(dwAddress,DOREAL); // prolog
Nwrite(byNumber,dwAddress+5,s); // data
// push object to stack
RPL_Push(1,dwAddress);
}
break;
}
// any other format
{
DWORD dwSize = lstrlen(lpstrClipdata);
if ((lpbyData = HeapAlloc(hHeap,0,dwSize * 2)))
{
LPBYTE lpbySrc,lpbyDest;
DWORD dwLoop;
#if defined _UNICODE
// copy data UNICODE -> ASCII
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK,
lpstrClipdata, dwSize,
lpbyData+dwSize, dwSize, NULL, NULL);
#else
// copy data
memcpy(lpbyData+dwSize,lpstrClipdata,dwSize);
#endif
// unpack data
lpbySrc = lpbyData+dwSize;
lpbyDest = lpbyData;
dwLoop = dwSize;
while (dwLoop-- > 0)
{
BYTE byTwoNibs = *lpbySrc++;
*lpbyDest++ = (BYTE) (byTwoNibs & 0xF);
*lpbyDest++ = (BYTE) (byTwoNibs >> 4);
}
dwSize *= 2; // size in nibbles
// get TEMPOB memory for string object
dwAddress = RPL_CreateTemp(dwSize+10);
if ((bSuccess = (dwAddress > 0)))
{
Write5(dwAddress,DOCSTR); // String
Write5(dwAddress+5,dwSize+5); // length of String
Nwrite(lpbyData,dwAddress+10,dwSize); // data
// push object to stack
RPL_Push(1,dwAddress);
}
HeapFree(hHeap,0,lpbyData);
}
}
}
while(FALSE);
GlobalUnlock(hClipObj);
}
}
CloseClipboard();
}
SwitchToState(SM_RUN); // run state
while (nState!=nNextState) Sleep(0);
_ASSERT(nState == SM_RUN);
if (bSuccess == FALSE) // data not copied
goto cancel;
KeyboardEvent(TRUE,0,0x8000);
KeyboardEvent(FALSE,0,0x8000);
// wait for sleep mode
while(Chipset.Shutdn == FALSE) Sleep(0);
cancel:
bDbgAutoStateCtrl = TRUE; // enable automatic debugger state control
ResumeDebugger();
return 0;
#undef CF_TEXTFORMAT
}

439
SOURCE/TIMER.C Normal file
View file

@ -0,0 +1,439 @@
/*
* timer.c
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
#include "pch.h"
#include "Emu48.h"
#include "ops.h"
#include "io.h" // I/O definitions
#define AUTO_OFF 10 // Time in minutes for 'auto off'
// Ticks for 01.01.1970 00:00:00
#define UNIX_0_TIME ((ULONGLONG) 0x0001cf2e8f800000)
// Ticks for 'auto off'
#define OFF_TIME ((ULONGLONG) (AUTO_OFF * 60) << 13)
// memory address for clock and auto off
// S(X) = 0x70052-0x70070, G(X) = 0x80058-0x80076, 49G = 0x80058-0x80076
#define RPLTIME ((cCurrentRomType=='S')?0x52:0x58)
#define T1_FREQ 62 // Timer1 1/frequency in ms
#define T2_FREQ 8192 // Timer2 frequency
static BOOL bStarted = FALSE;
static BOOL bOutRange = FALSE; // flag if timer value out of range
static UINT uT1TimerId = 0;
static UINT uT2TimerId = 0;
static BOOL bNINT2T1 = FALSE; // state of NINT2 affected from timer1
static BOOL bNINT2T2 = FALSE; // state of NINT2 affected from timer2
static BOOL bAccurateTimer; // flag if accurate timer is used
static LARGE_INTEGER lT2Ref; // counter value at timer2 start
static TIMECAPS tc; // timer information
static UINT uT2MaxTicks; // max. timer2 ticks handled by one timer event
static DWORD dwT2Ref; // timer2 value at last timer2 access
static DWORD dwT2Cyc; // cpu cycle counter at last timer2 access
static void CALLBACK TimeProc(UINT uEventId, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
static DWORD CalcT2(VOID) // calculate timer2 value
{
DWORD dwT2 = Chipset.t2; // get value from chipset
if (bStarted) // timer2 running
{
LARGE_INTEGER lT2Act;
DWORD dwT2Dif;
// timer should run a little bit faster (10%) than maschine in authentic speed mode
DWORD dwCycPerTick = (9 * T2CYCLES) / 5;
QueryPerformanceCounter(&lT2Act); // actual time
// calculate realtime timer2 ticks since reference point
dwT2 -= (DWORD)
(((lT2Act.QuadPart - lT2Ref.QuadPart) * T2_FREQ)
/ lFreq.QuadPart);
dwT2Dif = dwT2Ref - dwT2; // timer2 ticks since last request
// checking if the MSB of dwT2Dif can be used as sign flag
_ASSERT((DWORD) tc.wPeriodMax < ((1<<(sizeof(dwT2Dif)*8-1))/8192)*1000);
// 2nd timer call in a 32ms time frame or elapsed time is negative (Win2k bug)
if (!Chipset.Shutdn && ((dwT2Dif > 0x01 && dwT2Dif <= 0x100) || (dwT2Dif & 0x80000000) != 0))
{
DWORD dwT2Ticks = ((DWORD) (Chipset.cycles & 0xFFFFFFFF) - dwT2Cyc) / dwCycPerTick;
// estimated < real elapsed timer2 ticks or negative time
if (dwT2Ticks < dwT2Dif || (dwT2Dif & 0x80000000) != 0)
{
// real time too long or got negative time elapsed
dwT2 = dwT2Ref - dwT2Ticks; // estimated timer2 value from CPU cycles
dwT2Cyc += dwT2Ticks * dwCycPerTick; // estimated CPU cycles for the timer2 ticks
}
else
{
// reached actual time -> new synchronizing
dwT2Cyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF) - dwCycPerTick;
}
}
else
{
// valid actual time -> new synchronizing
dwT2Cyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF) - dwCycPerTick;
}
// check if timer2 interrupt is active -> no timer2 value below 0xFFFFFFFF
if ( Chipset.inte
&& (dwT2 & 0x80000000) != 0
&& (!Chipset.Shutdn || (Chipset.IORam[TIMER2_CTRL]&WKE))
&& (Chipset.IORam[TIMER2_CTRL]&INTR)
)
{
dwT2 = 0xFFFFFFFF;
dwT2Cyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF) - dwCycPerTick;
}
dwT2Ref = dwT2; // new reference time
}
return dwT2;
}
static VOID CheckT1(BYTE nT1)
{
// implementation of TSRQ
bNINT2T1 = (Chipset.IORam[TIMER1_CTRL]&INTR) != 0 && (nT1&8) != 0;
IOBit(SRQ1,TSRQ,bNINT2T1 || bNINT2T2);
if ((nT1&8) == 0) // timer1 MSB not set
{
Chipset.IORam[TIMER1_CTRL] &= ~SRQ; // clear SRQ bit
return;
}
_ASSERT((nT1&8) != 0); // timer1 MSB set
// timer MSB and INT or WAKE bit is set
if ((Chipset.IORam[TIMER1_CTRL]&(WKE|INTR)) != 0)
Chipset.IORam[TIMER1_CTRL] |= SRQ; // set SRQ
// cpu not sleeping and T1 -> Interrupt
if ( (!Chipset.Shutdn || (Chipset.IORam[TIMER1_CTRL]&WKE))
&& (Chipset.IORam[TIMER1_CTRL]&INTR))
{
Chipset.SoftInt = TRUE;
bInterrupt = TRUE;
}
// cpu sleeping and T1 -> Wake Up
if (Chipset.Shutdn && (Chipset.IORam[TIMER1_CTRL]&WKE))
{
Chipset.IORam[TIMER1_CTRL] &= ~WKE; // clear WKE bit
Chipset.bShutdnWake = TRUE; // wake up from SHUTDN mode
SetEvent(hEventShutdn); // wake up emulation thread
}
return;
}
static VOID CheckT2(DWORD dwT2)
{
// implementation of TSRQ
bNINT2T2 = (Chipset.IORam[TIMER2_CTRL]&INTR) != 0 && (dwT2&0x80000000) != 0;
IOBit(SRQ1,TSRQ,bNINT2T1 || bNINT2T2);
if ((dwT2&0x80000000) == 0) // timer2 MSB not set
{
Chipset.IORam[TIMER2_CTRL] &= ~SRQ; // clear SRQ bit
return;
}
_ASSERT((dwT2&0x80000000) != 0); // timer2 MSB set
// timer MSB and INT or WAKE bit is set
if ((Chipset.IORam[TIMER2_CTRL]&(WKE|INTR)) != 0)
Chipset.IORam[TIMER2_CTRL] |= SRQ; // set SRQ
// cpu not sleeping and T2 -> Interrupt
if ( (!Chipset.Shutdn || (Chipset.IORam[TIMER2_CTRL]&WKE))
&& (Chipset.IORam[TIMER2_CTRL]&INTR))
{
Chipset.SoftInt = TRUE;
bInterrupt = TRUE;
}
// cpu sleeping and T2 -> Wake Up
if (Chipset.Shutdn && (Chipset.IORam[TIMER2_CTRL]&WKE))
{
Chipset.IORam[TIMER2_CTRL] &= ~WKE; // clear WKE bit
Chipset.bShutdnWake = TRUE; // wake up from SHUTDN mode
SetEvent(hEventShutdn); // wake up emulation thread
}
return;
}
static VOID RescheduleT2(BOOL bRefPoint)
{
UINT uDelay;
_ASSERT(uT2TimerId == 0); // timer2 must stopped
if (bRefPoint) // save reference time
{
dwT2Ref = Chipset.t2; // timer2 value at last timer2 access
dwT2Cyc = (DWORD) (Chipset.cycles & 0xFFFFFFFF); // cpu cycle counter at last timer2 access
QueryPerformanceCounter(&lT2Ref); // time of corresponding Chipset.t2 value
uDelay = Chipset.t2; // timer value for delay
}
else // called without new refpoint, restart t2 with actual value
{
uDelay = CalcT2(); // actual timer value for delay
}
if ((bOutRange = uDelay > uT2MaxTicks)) // delay greater maximum delay
uDelay = uT2MaxTicks; // wait maximum delay time
uDelay = (uDelay * 125 + 1023) / 1024; // timer delay in ms (1000/8192 = 125/1024)
uDelay = __max(tc.wPeriodMin,uDelay); // wait minimum delay of timer
_ASSERT(uDelay <= tc.wPeriodMax); // inside maximum event delay
// start timer2; schedule event, when Chipset.t2 will be zero
VERIFY(uT2TimerId = timeSetEvent(uDelay,0,&TimeProc,2,TIME_ONESHOT));
return;
}
static VOID AbortT2(VOID)
{
_ASSERT(uT2TimerId);
timeKillEvent(uT2TimerId); // kill event
uT2TimerId = 0; // then reset var
return;
}
static void CALLBACK TimeProc(UINT uEventId, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
{
_ASSERT(uEventId); // illegal EventId
if (uEventId == uT1TimerId) // called from timer1 event (default period 16 Hz)
{
EnterCriticalSection(&csT1Lock);
{
Chipset.t1 = (Chipset.t1-1)&0xF;// decrement timer value
CheckT1(Chipset.t1); // test timer1 control bits
}
LeaveCriticalSection(&csT1Lock);
return;
}
if (uEventId == uT2TimerId) // called from timer2 event, Chipset.t2 should be zero
{
EnterCriticalSection(&csT2Lock);
{
uT2TimerId = 0; // single shot timer timer2 stopped
if (!bOutRange) // timer event elapsed
{
// timer2 overrun, test timer2 control bits else restart timer2
Chipset.t2 = CalcT2(); // calculate new timer2 value
CheckT2(Chipset.t2); // test timer2 control bits
}
RescheduleT2(!bOutRange); // restart timer2
}
LeaveCriticalSection(&csT2Lock);
return;
}
return;
UNREFERENCED_PARAMETER(uMsg);
UNREFERENCED_PARAMETER(dwUser);
UNREFERENCED_PARAMETER(dw1);
UNREFERENCED_PARAMETER(dw2);
}
VOID SetHP48Time(VOID) // set date and time
{
SYSTEMTIME ts;
ULONGLONG ticks, time;
DWORD dw;
WORD crc, i;
BYTE p[4];
_ASSERT(sizeof(ULONGLONG) == 8); // check size of datatype
GetLocalTime(&ts); // local time, _ftime() cause memory/resource leaks
// calculate days until 01.01.1970
dw = (DWORD) ts.wMonth;
if (dw > 2)
dw -= 3L;
else
{
dw += 9L;
--ts.wYear;
}
dw = (DWORD) ts.wDay + (153L * dw + 2L) / 5L;
dw += (146097L * (((DWORD) ts.wYear) / 100L)) / 4L;
dw += (1461L * (((DWORD) ts.wYear) % 100L)) / 4L;
dw -= 719469L;
// convert into seconds and add time
dw = dw * 24L + (DWORD) ts.wHour;
dw = dw * 60L + (DWORD) ts.wMinute;
dw = dw * 60L + (DWORD) ts.wSecond;
// create timerticks = (s + ms) * 8192
ticks = ((ULONGLONG) dw << 13) | (((ULONGLONG) ts.wMilliseconds << 10) / 125);
ticks += UNIX_0_TIME; // add offset ticks from year 0
ticks += Chipset.t2; // add actual timer2 value
time = ticks; // save for calc. timeout
time += OFF_TIME; // add 10 min for auto off
dw = RPLTIME; // HP addresses for clock in port0
crc = 0x0; // reset crc value
for (i = 0; i < 13; ++i, ++dw) // write date and time
{
*p = (BYTE) ticks & 0xf;
crc = (crc >> 4) ^ (((crc ^ ((WORD) *p)) & 0xf) * 0x1081);
Chipset.Port0[dw] = *p; // always store in port0
ticks >>= 4;
}
Nunpack(p,crc,4); // write crc
memcpy(Chipset.Port0+dw,p,4); // always store in port0
dw += 4; // HP addresses for timeout
for (i = 0; i < 13; ++i, ++dw) // write time for auto off
{
// always store in port0
Chipset.Port0[dw] = (BYTE) time & 0xf;
time >>= 4;
}
Chipset.Port0[dw] = 0xf; // always store in port0
return;
}
VOID StartTimers(VOID)
{
if (bStarted) // timer running
return; // -> quit
if (Chipset.IORam[TIMER2_CTRL]&RUN) // start timer1 and timer2 ?
{
bStarted = TRUE; // flag timer running
// initialisation of NINT2 lines
bNINT2T1 = (Chipset.IORam[TIMER1_CTRL]&INTR) != 0 && (Chipset.t1 & 8) != 0;
bNINT2T2 = (Chipset.IORam[TIMER2_CTRL]&INTR) != 0 && (Chipset.t2 & 0x80000000) != 0;
timeGetDevCaps(&tc,sizeof(tc)); // get timer resolution
// max. timer2 ticks that can be handled by one timer event
uT2MaxTicks = __min((0xFFFFFFFF / 1024),tc.wPeriodMax);
uT2MaxTicks = __min((0xFFFFFFFF - 1023) / 125,uT2MaxTicks * 1024 / 125);
CheckT1(Chipset.t1); // check for timer1 interrupts
CheckT2(Chipset.t2); // check for timer2 interrupts
// set timer resolution to greatest possible one
bAccurateTimer = (timeBeginPeriod(tc.wPeriodMin) == TIMERR_NOERROR);
// set timer1 with given period
VERIFY(uT1TimerId = timeSetEvent(T1_FREQ,0,&TimeProc,1,TIME_PERIODIC));
RescheduleT2(TRUE); // start timer2
}
return;
}
VOID StopTimers(VOID)
{
if (!bStarted) // timer stopped
return; // -> quit
if (uT1TimerId != 0) // timer1 running
{
// Critical Section handler may cause a dead lock
timeKillEvent(uT1TimerId); // stop timer1
uT1TimerId = 0; // set flag timer1 stopped
}
if (uT2TimerId != 0) // timer2 running
{
EnterCriticalSection(&csT2Lock);
{
Chipset.t2 = CalcT2(); // update chipset timer2 value
}
LeaveCriticalSection(&csT2Lock);
AbortT2(); // stop timer2 outside critical section
}
bStarted = FALSE;
if (bAccurateTimer) // "Accurate timer" running
{
timeEndPeriod(tc.wPeriodMin); // finish service
}
return;
}
DWORD ReadT2(VOID)
{
DWORD dwT2;
EnterCriticalSection(&csT2Lock);
{
dwT2 = CalcT2(); // calculate timer2 value or if stopped last timer value
CheckT2(dwT2); // update timer2 control bits
}
LeaveCriticalSection(&csT2Lock);
return dwT2;
}
VOID SetT2(DWORD dwValue)
{
// calling AbortT2() inside Critical Section handler may cause a dead lock
if (uT2TimerId != 0) // timer2 running
AbortT2(); // stop timer2
EnterCriticalSection(&csT2Lock);
{
Chipset.t2 = dwValue; // set new value
CheckT2(Chipset.t2); // test timer2 control bits
if (bStarted) // timer running
RescheduleT2(TRUE); // restart timer2
}
LeaveCriticalSection(&csT2Lock);
return;
}
BYTE ReadT1(VOID)
{
BYTE nT1;
EnterCriticalSection(&csT1Lock);
{
nT1 = Chipset.t1; // read timer1 value
CheckT1(nT1); // update timer1 control bits
}
LeaveCriticalSection(&csT1Lock);
return nT1;
}
VOID SetT1(BYTE byValue)
{
BOOL bEqual;
_ASSERT(byValue < 0x10); // timer1 is only a 4bit counter
EnterCriticalSection(&csT1Lock);
{
bEqual = (Chipset.t1 == byValue); // check for same value
}
LeaveCriticalSection(&csT1Lock);
if (bEqual) return; // same value doesn't restart timer period
if (uT1TimerId != 0) // timer1 running
{
timeKillEvent(uT1TimerId); // stop timer1
uT1TimerId = 0; // set flag timer1 stopped
}
EnterCriticalSection(&csT1Lock);
{
Chipset.t1 = byValue; // set new timer1 value
CheckT1(Chipset.t1); // test timer1 control bits
}
LeaveCriticalSection(&csT1Lock);
if (bStarted) // timer running
{
// restart timer1 to get full period of frequency
VERIFY(uT1TimerId = timeSetEvent(T1_FREQ,0,&TimeProc,1,TIME_PERIODIC));
}
return;
}

110
SOURCE/TYPES.H Normal file
View file

@ -0,0 +1,110 @@
/*
* types.h
*
* This file is part of Emu48
*
* Copyright (C) 1995 Sebastien Carlier
*
*/
// HST bits
#define XM 1
#define SB 2
#define SR 4
#define MP 8
#define SWORD SHORT // signed 16 Bit variable
#define QWORD ULONGLONG // unsigned 64 Bit variable
#define CHIPSET Chipset_t
typedef struct
{
SWORD nPosX; // position of window
SWORD nPosY;
BYTE type; // calculator type
DWORD Port0Size; // real size of module in KB
DWORD Port1Size; // real size of module in KB
DWORD Port2Size; // real size of module in KB (HP49G only)
LPBYTE Port0;
LPBYTE Port1;
LPBYTE Port2;
DWORD pc;
DWORD d0;
DWORD d1;
DWORD rstkp;
DWORD rstk[8];
BYTE A[16];
BYTE B[16];
BYTE C[16];
BYTE D[16];
BYTE R0[16];
BYTE R1[16];
BYTE R2[16];
BYTE R3[16];
BYTE R4[16];
BYTE ST[4];
BYTE HST;
BYTE P;
WORD out;
WORD in;
BOOL SoftInt;
BOOL Shutdn;
BOOL mode_dec;
BOOL inte; // interrupt status flag (FALSE = int in service)
BOOL intk; // 1 ms keyboard scan flag (TRUE = enable)
BOOL intd; // keyboard interrupt pending (TRUE = int pending)
BOOL carry;
WORD crc;
WORD wPort2Crc; // fingerprint of port2
WORD wRomCrc; // fingerprint of ROM
#if defined _USRDLL // DLL version
QWORD cycles; // oscillator cycles
#else // EXE version
DWORD cycles; // oscillator cycles
DWORD cycles_reserved; // reserved for MSB of oscillator cycles
#endif
DWORD dwKdnCycles; // cpu cycles at start of 1ms key handler
UINT Bank_FF; // save state of HP48GX port2 or state of HP49G ROM FF
UINT FlashRomState; // WSM state of flash memory (unused)
BYTE cards_status;
BYTE IORam[64]; // I/O hardware register
UINT IOBase; // address of I/O modules page
BOOL IOCfig; // I/O module configuration flag
BYTE P0Base, BSBase, P1Base, P2Base; // address of modules first 2KB page
BYTE P0Size, BSSize, P1Size, P2Size; // mapped size of module in 2KB
BYTE P0End, BSEnd, P1End, P2End; // address of modules last 2KB page
BOOL P0Cfig, BSCfig, P1Cfig, P2Cfig; // module address configuration flag
BOOL P0Cfg2, BSCfg2, P1Cfg2, P2Cfg2; // module size configuration flag
BYTE t1;
DWORD t2;
BOOL bShutdnWake; // flag for wake up from SHUTDN mode
BYTE Keyboard_Row[9];
WORD IR15X;
UINT Keyboard_State; // not used
signed short loffset;
signed int width;
UINT boffset;
UINT lcounter;
UINT sync; // not used
BYTE contrast;
BOOL dispon; // not used
DWORD start1;
DWORD start12;
DWORD end1;
DWORD start2, end2;
// CdB for HP: add apples header
DWORD d0size; // no. of header display lines
BYTE d0memory[4096*2]; // memory for header display area
DWORD d0offset; // offset inside the header display for the content
DWORD d0address; // address in saturn addr area for d0memory (2 pages)
// BOOL d0Cfig; // modul configured
} Chipset_t;

340
SOURCE/gpl.txt Normal file
View file

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.