main.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. #
  3. # AWL simulator - Dummy hardware interface
  4. #
  5. # Copyright 2013-2014 Michael Buesch <m@bues.ch>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. from __future__ import division, absolute_import, print_function, unicode_literals
  22. from awlsim.common.compat import *
  23. from awlsim.core.hardware import *
  24. from awlsim.core.operators import AwlOperator
  25. from awlsim.core.datatypes import AwlOffset
  26. class HardwareInterface(AbstractHardwareInterface):
  27. name = "dummy"
  28. def __init__(self, sim, parameters={}):
  29. AbstractHardwareInterface.__init__(self,
  30. sim = sim,
  31. parameters = parameters)
  32. def doStartup(self):
  33. pass # Do nothing
  34. def doShutdown(self):
  35. pass # Do nothing
  36. def readInputs(self):
  37. pass # Do nothing
  38. def writeOutputs(self):
  39. pass # Do nothing
  40. def directReadInput(self, accessWidth, accessOffset):
  41. if accessOffset < self.inputAddressBase:
  42. return None
  43. # Just read the current value from the CPU and return it.
  44. return self.sim.cpu.fetch(AwlOperator(AwlOperator.MEM_E,
  45. accessWidth,
  46. AwlOffset(accessOffset)))
  47. def directWriteOutput(self, accessWidth, accessOffset, data):
  48. if accessOffset < self.outputAddressBase:
  49. return False
  50. # Just pretend we wrote it somewhere.
  51. return True