|
|
 |
 |
 |
 |
8085 simulator in C
Hi everyone, Can anyone give some idea about developing an 8085 simulator program in C? What techniques can be handled to develop this?
In article <1180980953.503669.203@x35g2000prf.googlegroups.com>, activearun @gmail.com <activearun @gmail.com> wrote: > Can anyone give some idea about developing an 8085 simulator >program in C? What techniques can be handled to develop this? -Personally-, I wouldn't bother unless it was an assignment or a pet learning project (and even then, I'd reconsider whether 8085 was the right choice of processors.) If you wanted an 8085 simulator, I'd look around and try out http://sourceforge.net/projects/sim85 or Vaneet Singla's 8085 simulator (available in a wide variety of places) -- If you lie to the compiler, it will get its revenge. -- Henry Spencer
On Jun 4, 11:15 am, "activearun@gmail.com" <activearun @gmail.com> wrote: > Hi everyone, > Can anyone give some idea about developing an 8085 simulator > program in C? What techniques can be handled to develop this?
http://www.google.com/search?hl=en&q=8085+simulator+program+in+C&btnG...
On Jun 4, 1:30 pm, rober@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote: > In article <1180980953.503669.203 @x35g2000prf.googlegroups.com>, > activearun@gmail.com <activearun@gmail.com> wrote: > > Can anyone give some idea about developing an 8085 simulator > >program in C? What techniques can be handled to develop this? > -Personally-, I wouldn't bother unless it was an assignment or > a pet learning project (and even then, I'd reconsider whether > 8085 was the right choice of processors.)
I don't think 8085 is such a bad choice. Very simple instruction set. I did this one weekend about 20 years ago just for the heck of it. I had an old single board PC I wanted to emulate on a VAX. The OP wanted suggestions on techniques to do this. As I recall, the upper nibble of the opcode pretty much tells you what the instruction will do, so I made an array of 16 functions and used the upper nibble to index into the array. Then I had 16 individual functions to handle the operations. The lower nibble is mostly for addressing, so that too can index into an array for the correct register. Setting the flags properly was the trickiest part.
mstork @yahoo.com writes: > The OP wanted suggestions on techniques to do this. As I recall, the > upper nibble of the opcode pretty much tells you what the instruction > will do, so I made an array of 16 functions and used the upper nibble > to index into the array. Then I had 16 individual functions to handle > the operations. The lower nibble is mostly for addressing, so that too > can index into an array for the correct register. Setting the flags > properly was the trickiest part. This sounds like a fun instruction set on which to practice writing a (static or dynamic) binary translator. (Of course, there's no way to actually run the translated code without invoking undefined behavior, from a comp.lang.c point of view.) -- Ben Pfaff http://benpfaff.org
In article <1181057388.694969.70@w5g2000hsg.googlegroups.com>, mstork@yahoo.com writes >On Jun 4, 1:30 pm, rober @ibd.nrc-cnrc.gc.ca (Walter Roberson) >wrote: >> In article <1180980953.503669.203 @x35g2000prf.googlegroups.com>, >> activearun@gmail.com <activearun@gmail.com> wrote: >> > Can anyone give some idea about developing an 8085 simulator >> >program in C? What techniques can be handled to develop this? >> -Personally-, I wouldn't bother unless it was an assignment or >> a pet learning project (and even then, I'd reconsider whether >> 8085 was the right choice of processors.) >I don't think 8085 is such a bad choice.
It is if you want o buy one... I am certain the are obsolete these days,. > Very simple instruction set. >I did this one weekend about 20 years ago just for the heck of it. I >had an old single board PC I wanted to emulate on a VAX.
Exactly....20 years ago It might be technically nice but getting the HW is another matter. As for the tools.... i will dust of the compiler on the 5.25" floppies..... -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ c@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
On Jun 5, 10:45 am, Chris Hills <c@phaedsys.org> wrote:
> In article <1181057388.694969.70 @w5g2000hsg.googlegroups.com>, > mstork @yahoo.com writes>On Jun 4, 1:30 pm, rober @ibd.nrc-cnrc.gc.ca (Walter Roberson) > >wrote: > >> In article <1180980953.503669.203 @x35g2000prf.googlegroups.com>, > >> activearun@gmail.com <activearun@gmail.com> wrote: > >> > Can anyone give some idea about developing an 8085 simulator > >> >program in C? What techniques can be handled to develop this? > >> -Personally-, I wouldn't bother unless it was an assignment or > >> a pet learning project (and even then, I'd reconsider whether > >> 8085 was the right choice of processors.) > >I don't think 8085 is such a bad choice. > It is if you want o buy one... I am certain the are obsolete these > days,. > > Very simple instruction set. > >I did this one weekend about 20 years ago just for the heck of it. I > >had an old single board PC I wanted to emulate on a VAX. > Exactly....20 years ago It might be technically nice but getting the HW > is another matter. As for the tools.... i will dust of the compiler on > the 5.25" floppies.....
You can still get the Z80 at DigiKey. Same instruction set, even easier to connect up (the address and data bus are not multiplexed like on the 8085). But then the OP just wants to emulate it, not build one (but I would suggest doing so anyway). And since he wants to do it in C, if he has trouble along the way his questions will likely be on topic for this group. As to the rest of this discussion...
mstork @yahoo.com writes: > You can still get the Z80 at DigiKey. Same instruction set, even > easier to connect up (the address and data bus are not multiplexed > like on the 8085). I think you are confusing 8080 and 8085. -- Jean-Marc, who has programmed both but could be the one doing the confusion
On Jun 5, 11:28 am, Jean-Marc Bourguet <j@bourguet.org> wrote: > mstork @yahoo.com writes: > > You can still get the Z80 at DigiKey. Same instruction set, even > > easier to connect up (the address and data bus are not multiplexed > > like on the 8085). > I think you are confusing 8080 and 8085. > -- > Jean-Marc, who has programmed both but could be the one doing the confusion
Nope, the 8080 used an external clock generator (8224) and system controller (8228) that were built into the 8085. There are a couple of undefined opcodes in the 8080/8085 that the Z80 defined to extend the architecture of the 8080/8085. It doubled the number of registers, demuxed the IO, and added a few new registers. However, as long as you don't use those undefined opcodes, it is 100% software compatible (only the timing is different).
Ben Pfaff wrote: > mstork@yahoo.com writes: > > The OP wanted suggestions on techniques to do this. As I recall, the > > upper nibble of the opcode pretty much tells you what the instruction > > will do, so I made an array of 16 functions and used the upper nibble > > to index into the array. Then I had 16 individual functions to handle > > the operations. The lower nibble is mostly for addressing, so that too > > can index into an array for the correct register. Setting the flags > > properly was the trickiest part. > This sounds like a fun instruction set on which to practice > writing a (static or dynamic) binary translator. (Of course, > there's no way to actually run the translated code without > invoking undefined behavior, from a comp.lang.c point of view.)
How so? You have a struct holding the emulator's CPU registers, and a 64K unsigned char array (or two 32K arrays, since I seem to recall the standard not requiring support for 64K arrays) representing the memory. Now, emulating the hardware which might be surrounding the CPU is another story. (Though you're probably more likely to run into "implementation defined" or "unspecified" behavior than actual UB.) :-) -- +-------------------------+--------------------+-----------------------+ | Kenneth J. Brody | www.hvcomputer.com | #include | | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> | +-------------------------+--------------------+-----------------------+ Don't e-mail me at: <mailto:ThisIsASpamT@gmail.com>
In article <4665B928.A1A9D@spamcop.net>, Kenneth Brody <kenbr@spamcop.net> wrote: >Ben Pfaff wrote: >> This sounds like a fun instruction set on which to practice >> writing a (static or dynamic) binary translator. (Of course, >> there's no way to actually run the translated code without >> invoking undefined behavior, from a comp.lang.c point of view.) >How so? You have a struct holding the emulator's CPU registers, and a >64K unsigned char array (or two 32K arrays, since I seem to recall the >standard not requiring support for 64K arrays) representing the memory.
Ben is talking about binary *translator* -- i.e., that the 8085 binary code be examined and converted to code native to the hosting system and run directly as native code instead of by emulating each 8085 instruction. And he is correct that you can't actually run the translated code without undefined behaviour, as C does not offer any mechanism to compute native code and set that code into execution. For example, C does *not* offer unsigned char object_code[SomeSizeOrOther]; object_code[SomeLocationOrOther] = SomeNativeOpcodeOrOther; ((void(*)()) object_code)(); /* undefined behaviour! */ There is no C facility to convert an object pointer into a function pointer. -- Is there any thing whereof it may be said, See, this is new? It hath been already of old time, which was before us. -- Ecclesiastes
<mstork @yahoo.com> wrote in message news:1181062169.821917.316620@w5g2000hsg.googlegroups.com...
> On Jun 5, 11:28 am, Jean-Marc Bourguet <j @bourguet.org> wrote: >> mstork @yahoo.com writes: >> > You can still get the Z80 at DigiKey. Same instruction set, even >> > easier to connect up (the address and data bus are not multiplexed >> > like on the 8085). >> I think you are confusing 8080 and 8085. >> -- >> Jean-Marc, who has programmed both but could be the one doing the >> confusion > Nope, the 8080 used an external clock generator (8224) and system > controller (8228) that were built into the 8085. There are a couple of > undefined opcodes in the 8080/8085 that the Z80 defined to extend the > architecture of the 8080/8085. It doubled the number of registers, > demuxed the IO, and added a few new registers. However, as long as you > don't use those undefined opcodes, it is 100% software compatible > (only the timing is different).
Oops, only 99.99% software compatible -- if you did an 8 bit add or subtract, the 8080/8085 would save the parity of the result into the 'parity flag', while the Z80 would save whether the operation overflowed into the parity flag. That generally came up only if you were deliberately writing code that would work differently on the different processors, but it is a difference. -- poncho
mstork @yahoo.com wrote: > rober @ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote: >> activearun @gmail.com <activearun @gmail.com> wrote: >>> Can anyone give some idea about developing an 8085 simulator >>> program in C? What techniques can be handled to develop this? >> -Personally-, I wouldn't bother unless it was an assignment or >> a pet learning project (and even then, I'd reconsider whether >> 8085 was the right choice of processors.) > I don't think 8085 is such a bad choice. Very simple instruction set. > I did this one weekend about 20 years ago just for the heck of it. I > had an old single board PC I wanted to emulate on a VAX. > The OP wanted suggestions on techniques to do this. As I recall, the > upper nibble of the opcode pretty much tells you what the instruction > will do, so I made an array of 16 functions and used the upper nibble > to index into the array. Then I had 16 individual functions to handle > the operations. The lower nibble is mostly for addressing, so that too > can index into an array for the correct register. Setting the flags > properly was the trickiest part.
He is better off simulating the 8080 instruction set, which can then be expanded into the Z80 set, which in turn can be expanded into the 64180 set. The 8085 is a dead end. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com
Walter Roberson wrote: > In article <4665B928.A1A9D@spamcop.net>, > Kenneth Brody <kenbr@spamcop.net> wrote: > >Ben Pfaff wrote: > >> This sounds like a fun instruction set on which to practice > >> writing a (static or dynamic) binary translator. (Of course, > >> there's no way to actually run the translated code without > >> invoking undefined behavior, from a comp.lang.c point of view.) > >How so? You have a struct holding the emulator's CPU registers, and a > >64K unsigned char array (or two 32K arrays, since I seem to recall the > >standard not requiring support for 64K arrays) representing the memory. > Ben is talking about binary *translator* -- i.e., that the 8085 binary > code be examined and converted to code native to the hosting system > and run directly as native code instead of by emulating each 8085 > instruction.
Ah. I was thinking "emulator" rather than "translator". Of course, something that generates (portable) C source code which is to be compiled elsewhere could qualify as a "translator". > And he is correct that you can't actually run the translated code > without undefined behaviour, as C does not offer any mechanism to > compute native code and set that code into execution. > For example, C does *not* offer > unsigned char object_code[SomeSizeOrOther]; > object_code[SomeLocationOrOther] = SomeNativeOpcodeOrOther; > ((void(*)()) object_code)(); /* undefined behaviour! */ > There is no C facility to convert an object pointer into a function > pointer.
Is this actually UB, or is it "implementation defined"? Also, isn't a compiler allowed to define the behavior which is UB according to the standard? In other words, a compiler _could_ explicitly allow such a construct, with the caveat (of course) that the pointer must point to valid machine code, to allow things similar to Java's JIT[1] compiler. [1] JIT == "Just In Time". As I understand it, the Java bytecode is compiled into native machine code as the program runs. -- +-------------------------+--------------------+-----------------------+ | Kenneth J. Brody | www.hvcomputer.com | #include | | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> | +-------------------------+--------------------+-----------------------+ Don't e-mail me at: <mailto:ThisIsASpamT@gmail.com>
On Jun 5, 5:01 pm, CBFalconer <cbfalco@yahoo.com> wrote: > He is better off simulating the 8080 instruction set, which can > then be expanded into the Z80 set, which in turn can be expanded > into the 64180 set. The 8085 is a dead end.
I think you are confusing 8085 and 8086/8088.
mstork @yahoo.com wrote: > CBFalconer <cbfalco @yahoo.com> wrote: >> He is better off simulating the 8080 instruction set, which can >> then be expanded into the Z80 set, which in turn can be expanded >> into the 64180 set. The 8085 is a dead end. > I think you are confusing 8085 and 8086/8088.
No, I am not. You are. You can also expand 8080 code into 8085 code, but that is the end. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com
"Kenneth Brody" <kenbr @spamcop.net> wrote in message news:4666AB1B.D981B3A1@spamcop.net...
> Walter Roberson wrote: >> In article <4665B928.A1A9D@spamcop.net>, >> Kenneth Brody <kenbr@spamcop.net> wrote: >> >Ben Pfaff wrote: >> >> This sounds like a fun instruction set on which to practice >> >> writing a (static or dynamic) binary translator. (Of course, >> >> there's no way to actually run the translated code without >> >> invoking undefined behavior, from a comp.lang.c point of view.) >> >How so? You have a struct holding the emulator's CPU registers, and a >> >64K unsigned char array (or two 32K arrays, since I seem to recall the >> >standard not requiring support for 64K arrays) representing the memory. >> Ben is talking about binary *translator* -- i.e., that the 8085 binary >> code be examined and converted to code native to the hosting system >> and run directly as native code instead of by emulating each 8085 >> instruction. > Ah. I was thinking "emulator" rather than "translator". Of > course, something that generates (portable) C source code which > is to be compiled elsewhere could qualify as a "translator". >> And he is correct that you can't actually run the translated code >> without undefined behaviour, as C does not offer any mechanism to >> compute native code and set that code into execution. >> For example, C does *not* offer >> unsigned char object_code[SomeSizeOrOther]; >> object_code[SomeLocationOrOther] = SomeNativeOpcodeOrOther; >> ((void(*)()) object_code)(); /* undefined behaviour! */ >> There is no C facility to convert an object pointer into a function >> pointer. > Is this actually UB, or is it "implementation defined"?
Undefined Behavior. "Implementation defined" means that the implementation is required to document it, and the Standard places no such requirement. > Also, isn't a compiler allowed to define the behavior which is UB > according to the standard?
Of course. Undefined Behavior means the Standard places no requirements, and so the implementation is free to do whatever it wants. If it wants to define the behavior in a particular way, and additionally to document what this behavior is, that's just fine.
> In other words, a compiler _could_ > explicitly allow such a construct, with the caveat (of course) > that the pointer must point to valid machine code, to allow > things similar to Java's JIT[1] compiler. > [1] JIT == "Just In Time". As I understand it, the Java bytecode is > compiled into native machine code as the program runs. > -- > +-------------------------+--------------------+-----------------------+ > | Kenneth J. Brody | www.hvcomputer.com | #include | > | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> | > +-------------------------+--------------------+-----------------------+ > Don't e-mail me at: <mailto:ThisIsASpamT@gmail.com>
<mstork @yahoo.com> wrote in message news:1181059721.088150.89610@o5g2000hsb.googlegroups.com... > You can still get the Z80 at DigiKey. Same instruction set, even > easier to connect up (the address and data bus are not multiplexed > like on the 8085).
Not the same instruction set. The common denominator is the 8080. The Z80 adds a lot of new instructions. The 8085 added a few new instructions. Some of those new ones for the 8085 use the same op-codes as new ones for the Z80, but do entirely different things. There were also a few flags which responded differently on the 8085 than they did on the 8080 or Z80. When we wanted a single executable to run on two or three of these devices, we used to write "detector code" which nudged at these flags and instructions to figure out which machine the code was running on. If one want's to use other processors "based" at 8080 there's also the 64180, the Z180 (Z80's with MMUs and a few other new features) and the processor in the original Game Boy, which included some, but not all, of the Z80 additional instructions and, as I recall, a few of it's own, and I seem to remember an Intel 8080 or 8085 based CPU intended specifically for the embedded market which had a few other additional instructions specifically intended to cut down on external I/O hardware. - Bill
Kenneth Brody wrote: > Walter Roberson wrote: >> For example, C does *not* offer >> unsigned char object_code[SomeSizeOrOther]; >> object_code[SomeLocationOrOther] = SomeNativeOpcodeOrOther; >> ((void(*)()) object_code)(); /* undefined behaviour! */ >> There is no C facility to convert an object pointer into a function >> pointer. > Is this actually UB, or is it "implementation defined"?
The C standard does not define the behaviour, therefor it is UB. This does not preclude other standards (like POSIX), or the compiler writers themselves to specify what behaviour will happen. UB merely means that the C standard does not restrict the behaviour of the construct. Therefor, you should not use such constructs in code that must be portable to all possible C implementations, as you can't know what the behaviour will be. In practice do compilers also implement other standards, like POSIX, or have people come to rely on certain behaviours which all may indicate a certain behaviour for constructs that are UB under the C standard alone. Due to the topicality of this group, we only look to the C standard to see what behaviour we will get, so we will mark thing as undesirable (due to UB) which are fairly common in other environments. > Also, isn't a compiler allowed to define the behavior which is UB > according to the standard? In other words, a compiler _could_ > explicitly allow such a construct, with the caveat (of course) > that the pointer must point to valid machine code, to allow > things similar to Java's JIT[1] compiler.
Yes, and other standards may even require that the compiler does so. Bart v Ingen Schenau -- a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
|
 |
 |
 |
 |
|