main.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. #
  3. # AWL simulator - Debug 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 = "debug"
  28. paramDescs = [
  29. HwParamDesc_bool("dummyParam",
  30. description = "Unused dummy parameter"),
  31. ]
  32. def __init__(self, sim, parameters={}):
  33. AbstractHardwareInterface.__init__(self,
  34. sim = sim,
  35. parameters = parameters)
  36. def doStartup(self):
  37. pass # Do nothing
  38. def doShutdown(self):
  39. pass # Do nothing
  40. def readInputs(self):
  41. # Get the first input dword and write it back.
  42. dword = self.sim.cpu.fetch(AwlOperator(AwlOperator.MEM_E,
  43. 32,
  44. AwlOffset(self.inputAddressBase)))
  45. dwordBytes = bytearray( ( ((dword >> 24) & 0xFF),
  46. ((dword >> 16) & 0xFF),
  47. ((dword >> 8) & 0xFF),
  48. (dword & 0xFF) ) )
  49. self.sim.cpu.storeInputRange(self.inputAddressBase,
  50. dwordBytes)
  51. def writeOutputs(self):
  52. # Fetch a data range, but don't do anything with it.
  53. outData = self.sim.cpu.fetchOutputRange(self.outputAddressBase,
  54. 512)
  55. assert(outData)
  56. def directReadInput(self, accessWidth, accessOffset):
  57. if accessOffset < self.inputAddressBase:
  58. return None
  59. # Just read the current value from the CPU and return it.
  60. return self.sim.cpu.fetch(AwlOperator(AwlOperator.MEM_E,
  61. accessWidth,
  62. AwlOffset(accessOffset)))
  63. def directWriteOutput(self, accessWidth, accessOffset, data):
  64. if accessOffset < self.outputAddressBase:
  65. return False
  66. # Just pretend we wrote it somewhere.
  67. return True