Re: Writing an emulator in python - implementation questions (for performance)

2009-11-15 Thread Baptiste Lepilleur
I think you can use python itself for "pre-processing". Here is an (shortened) example from PyPy RPython paper: # operators: the docstrings contain the # symbol associated with each operator class Op_Add(BinaryExpr): ’+’ class Op_Sub(BinaryExpr): ’-’ # INIT-TIME only: build the table of #

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-13 Thread greg
Santiago Romero wrote: Can the above be easily done with another already-existing application? (example: can m4 do this job)? The problem you're going to have with something like m4 is indentation. When you inline a function call, somehow the inserted code has to be shifted to the same indent

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-13 Thread Bearophile
Try creation an extension module with ShedSkin. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-13 Thread Gabriel Genellina
En Thu, 12 Nov 2009 23:29:03 -0300, greg escribió: Carl Banks wrote: You can define constants to access specific registers: R1L = 1 R1H = 2 R1 = 1 breg[R1H] = 2 print wreg[R1] But keep in mind that named "constants" at the module level are really global variables, and therefore incur a dic

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-13 Thread Santiago Romero
I'm going to quote all the answers in a single post, if you all don't mind: > [greg] > But keep in mind that named "constants" at the module level > are really global variables, and therefore incur a dictionary > lookup every time they're used. > > For maximum speed, nothing beats writing the nu

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-13 Thread Santiago Romero
> How about >     page, index = divmod(address, 16384) Surely, much better and faster :-) Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Carl Banks
On Nov 12, 6:29 pm, greg wrote: > I would be taking a different approach -- develop a prototype > in Python, concentrating on clarity rather than speed, and > later reimplement the core of the emulator as an extension > module, using Pyrex or Cython or otherwise. But keep in mind he said he was d

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Carl Banks
On Nov 12, 6:37 am, Santiago Romero wrote: > > >  I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > > > ASpectrum, from C to Python + pygame. > > > The answer to your question is, "Use numpy".  More details below. > >  Let's see :-) > > > >  How can I implement this in Python

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Steven D'Aprano
On Fri, 13 Nov 2009 15:33:53 +1300, greg wrote: > Santiago Romero wrote: >>>How about >>>page, index = divmod(address, 16384) >> >> Surely, much better and faster :-) > > Not necessarily, because it involves a function call, and constructing > and deconstructing a result tuple. If you time t

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Steven D'Aprano
On Fri, 13 Nov 2009 15:29:03 +1300, greg wrote: > Generally, I think you're going to have quite a battle on your hands to > get a pure Python implementation to run as fast as a real Z80, if it's > even possible at all. And if you do succeed, the code will be pretty > awful (due to things such as n

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread greg
Santiago Romero wrote: How about page, index = divmod(address, 16384) Surely, much better and faster :-) Not necessarily, because it involves a function call, and constructing and deconstructing a result tuple. If you time them, you may well find that the explicit shift and mask operation

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread greg
Carl Banks wrote: You can define constants to access specific registers: R1L = 1 R1H = 2 R1 = 1 breg[R1H] = 2 print wreg[R1] But keep in mind that named "constants" at the module level are really global variables, and therefore incur a dictionary lookup every time they're used. For maximum s

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Santiago Romero
Oops, numpy arrays start with index=0 :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Santiago Romero
> You can do clever memory slicing like this with numpy.  For instance: > > breg = numpy.zeros((16,),numpy.uint8) > wreg = numpy.ndarray((8,),numpy.uint16,breg) > > This causes breg and wreg to share the same 16 bytes of memory.  You > can define constants to access specific registers: What I'm d

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Dave Angel
Santiago Romero wrote: I'm trying to port (just for fun), my old Sinclair Spectrum emulator, A Do you mean: page =ddress / 16384 index =ddress MOD 16384 ? Or, better, with: page =ddress >> 14 index =ddress & 16383 ? How about page, index = divmod(address, 16384)

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Santiago Romero
> >  I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > > ASpectrum, from C to Python + pygame. > > The answer to your question is, "Use numpy".  More details below. Let's see :-) > >  How can I implement this in Python, I mean, define a 16 byte variable > > so that high and

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Carl Banks
On Nov 12, 4:35 am, Santiago Romero wrote: >  Hi. > >  I'm trying to port (just for fun), my old Sinclair Spectrum emulator, > ASpectrum, from C to Python + pygame. The answer to your question is, "Use numpy". More details below. [snip] >  Should I start writing all the code with a Z80CPU obj

Writing an emulator in python - implementation questions (for performance)

2009-11-12 Thread Santiago Romero
Hi. I'm trying to port (just for fun), my old Sinclair Spectrum emulator, ASpectrum, from C to Python + pygame. Although the Sinclair Spectrum has a simple Z80 8 bit 3.5Mhz microprocessor, and no aditional hardware (excluding the +2/+3 model's AYsound chip), I'm not sure if my loved scripted