[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C# or C++ for Emulator?
- Subject: C# or C++ for Emulator?
- From: "Bryan Parkoff" <nospam@nospam.com>
- Date: Sun, 12 Aug 2007 12:54:03 -0500
- Newsgroups: comp.sys.apple2
- Organization: Road Runner High Speed Online http://www.rr.com
- Xref: g2news2.google.com comp.sys.apple2:2276
I can't tell which C# or C++ is better programming language. C# is
better than C++ for readable code, but C++ is better than C# for tuning
optimization. I would be surprised that C# has high performance when C++'s
optimization was tuned. Have you tried written either C# and C++ in Apple
II Emulator project? Did you test them? Did the results show the
difference of performance?
I prefer fast code without error trapping. The error trapping is an
example below.
Example 1:
unsigned short PC = 0;
unsigned char Byte = Mem[PC];
PC++;
It is C++ source code. It has fast code without error trapping. PC has
16 bits and Byte has 8 bits.
Example 2:
unsigned long PC = 0;
unsigned long Byte = Mem[PC];
PC++;
PC &= 0xFFFF; // or if (PC == 0x10000) PC = 0;
It is again C++ source code. It has less fast code within error
trapping. Both PC and Byte are 32 bits or 64 bits. You need error trapping
to clear all bits except 15th through 0th bit on PC using mask or if then.
All registers with 32 bits or 64 bits are better for performance, but they
have to live with error trapping. If error trapping is not used, Byte will
read and load data from garbage memory before crash or illegal message may
occur.
It sounds like C# uses C++ Example 2. Do you agree? I wonder that C#
is not portable to other machines?
The dynamic recompilation is not a good practice, but opcode interpreter
is better practice for emulator. Opcode interpreter is little slower than
dynamic recompilation. If you choose dynamic recompilation, ROM image and
DSK image must be converted from 6502 code machine into 80x86 code machine
once before ROM image and DSK image with 80x86 code machine can be run. The
problem is that you write Applesoft BASIC language or 6502 assembly language
while they are already native 80x86 code machine in RAM. It can give wrong
size length when they needed to be converted from 80x86 code machine back to
6502 code machine before they can be written back to ROM image or DSK image.
Please comment what you think.
Bryan Parkoff