• Please review our updated Terms and Rules here

Writing an emulator: some ideas needed.

Ruud

Veteran Member
Joined
Nov 30, 2009
Messages
1,414
Location
Heerlen, NL
A long time ago Roland Leurs developed his ATOM-in-PC (sorry, site is in Dutch). I traded one of his cards against a real Acorn Atom with the idea of changing the ROM and PC software and creating a kind of CBM8032-in-PC. But I had some wishes and I also rather prefer to work on a project of my own so I decided to build my own version, 6502-in-PC. Main differences: extra RAM, extra ROM and a 65816 instead of a 6502. Then why not "65816-ini-PC"? The 6502 is well known, the 65816 is not.

So far it are just ideas, schematics and a PCB design because of a renovation I had hardly access to various hardware. So I decided to build an emulator of this project. I have built an Elektor Junior emulator and a MicroProfessor MPF-1B emulator before, including the use of the timer of the PC to mimic interrupts. But this is different: I have to emulate two systems. They talk to each other, each using a 8255, so the communication is direct. Most of the time they have to wait for eachother, but not always. If the 65816 wants to have a directory, it has to wait for the PC to send the data. But for clearing the screen, it does not have to wait and can continue. During clearing the screen, the PC sets an Hold flag to signal the 65816 that it is not ready for another task yet.

A solution is to let the 65816 wait anyway, read: don't give the 65816 part any program time and let the PC finish its part upon which the 65816 gets all attention until the next command. But I forsee troubles in jumping from the 65816 part to the PC part and back again. In assembly I think I know how to solve that but I want to write this program in Free Pascal or Lazarus.
My objection: in reality both systems run parallel.

Another solution: time slicing. Give each part its own share of time. But with the same objection as above.

My, so far, last solution: write two programs. The PC part should start up, reserves some memory and tells the second program using a file (?) where this memory can be found and let both programs run parallel to eachother. With a multi-core system there is a chance that each program is run by its own core.
The problem: I have never done this and I have the bad feeling that Windows will prevent the second program to access the memory reserved by the first program.

Every idea, suggestion, help and criticism is welcome. Thanks in advance!

Edit: I intend to run the 65816 part on an altered ROM of the CBM 8032.
 
Multi tasking - where two (or more) threads share the same memory space.

Things to be aware of - more than one task manipulating the memory at the same time (use critical sections or semaphores to prevent simultaneous access) and smart 'C/C++' compilers caching the memory contents in a register (use the C/C++ keyword 'volatile' to force the compiler to load/save the value from/to memory rather than 'holding on to it' itself).

You can also use two programs (as you have proposed). Windows can make memory shared (with a named region) BUT you have the same issue regarding two (or more) programs concurrently accessing and modifying memory concurrently. You will still have to use a critical region or semaphore.

Dave
 
As long as you included a critical section (or similar) you should be good to go. If not depending upon the interface between the two threads, you may get some strange behaviour.

Dave
 
Back
Top