Knight.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. ## Copyright (C) 2016 Jeremiah Orians
  2. ## This file is part of stage0.
  3. ##
  4. ## stage0 is free software: you an redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## stage0 is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. import os, os.path
  17. import string
  18. import array
  19. import time
  20. import cherrypy
  21. import User_Interface as UI
  22. import sys
  23. class StringGenerator(object):
  24. @cherrypy.expose
  25. def index(self):
  26. return UI.returnPage()
  27. @cherrypy.expose
  28. def Memory(self, col=8, row=8, value=0):
  29. if 0 > int(col) or 0 > int(row):
  30. return "Out of range"
  31. if int(value, 16) > 255:
  32. return "Too big"
  33. UI.Set_Memory(int(col)+(int(row) * 16) + UI.Current_Page , int(value, 16))
  34. return UI.returnPage()
  35. @cherrypy.expose
  36. def Register(self, Reg="", value=0):
  37. UI.Set_Register(int(Reg[1:]), int(value, 16))
  38. return UI.returnPage()
  39. @cherrypy.expose
  40. def RUN(self):
  41. UI.Step_lilith()
  42. if UI.Current_IP in UI.Watchpoints:
  43. raise cherrypy.HTTPRedirect("/")
  44. return UI.returnPage()
  45. @cherrypy.expose
  46. def STEP(self):
  47. UI.Step_lilith()
  48. return UI.returnPage()
  49. @cherrypy.expose
  50. def STOP(self):
  51. print("Stopping after: " + str(UI.Count) + " Instructions" )
  52. return UI.returnPage()
  53. @cherrypy.expose
  54. def RESET(self):
  55. UI.Reset_lilith()
  56. return UI.returnPage()
  57. @cherrypy.expose
  58. def DEBUG(self, Inst=""):
  59. if int(Inst, 16) in UI.Watchpoints:
  60. UI.Watchpoints.remove(int(Inst, 16))
  61. print("Watchpoint Deleted: " + Inst)
  62. else:
  63. UI.Watchpoints.add(int(Inst, 16))
  64. return UI.returnPage()
  65. @cherrypy.expose
  66. def PAGEDOWN(self):
  67. UI.Current_Page = UI.Current_Page + 4096
  68. return UI.returnPage()
  69. @cherrypy.expose
  70. def PAGEUP(self):
  71. UI.Current_Page = UI.Current_Page - 4096
  72. if 0 > UI.Current_Page:
  73. UI.Current_Page = 0
  74. return UI.returnPage()
  75. @cherrypy.expose
  76. def WINDOW(self, Window=0):
  77. UI.Current_Page = int(Window, 16)
  78. return UI.returnPage()
  79. @cherrypy.expose
  80. def SPEEDBREAKPOINT(self):
  81. UI.Step_lilith()
  82. while UI.Current_IP not in UI.Watchpoints:
  83. UI.Step_lilith()
  84. if UI.Count == UI.Debug_Point:
  85. break
  86. return UI.returnPage()
  87. if __name__ == '__main__':
  88. UI.main(sys.argv[1:])
  89. conf = {
  90. '/': {
  91. 'tools.sessions.on': True,
  92. 'tools.staticdir.root': os.path.abspath(os.getcwd())
  93. },
  94. '/generator': {
  95. 'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
  96. 'tools.response_headers.on': True,
  97. 'tools.response_headers.headers': [('Content-Type', 'text/plain')],
  98. },
  99. '/static': {
  100. 'tools.staticdir.on': True,
  101. 'tools.staticdir.dir': './public'
  102. }
  103. }
  104. webapp = StringGenerator()
  105. webapp.generator = StringGenerator()
  106. cherrypy.quickstart(webapp, '/', conf)