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