Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import os
- from textwrap import fill
- import webbrowser
- class MainFrame(wx.Frame):
- def __init__(self, parent,id):
- wx.Frame.__init__(self, parent,id,'PRIZM Disassembler', size=(660,590))
- self.SetMinSize((400,300))
- self.inputfocus = 1
- self.outputfocus = 0
- self.AsmReadOnly = 0
- def getG3Adata(event):
- dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", 'g3a Files (*.g3a)|*.g3a', wx.OPEN)
- if dlg.ShowModal() == wx.ID_OK:
- self.filename=dlg.GetFilename()
- self.dirname=dlg.GetDirectory()
- # Open the file, read the contents and set them into
- # the text edit window
- filehandle=open(os.path.join(self.dirname, self.filename),'r')
- filehandle.close()
- self.SetTitle('PRIZM Disassembler - '+self.filename)
- hexProgram = fill(open(self.filename, "rb").read().encode("hex"),16)
- self.inputText.SetValue(self.inputText.GetValue() + hexProgram[60927:(len(hexProgram)-8)])
- def hex2dec(s): #Converts Decimal Numbers to Hexadecimal Number
- return int(s, 16)
- def OnAbout(event):
- description = "PRIZM Disassembler is a very basic disassembler for the Casio Prizm. PRIZM Disassembler is not affiliated in any way with Casio\n\nThanks to 'JosJuice' and 'Goplat' with database help."
- info = wx.AboutDialogInfo()
- info.SetName('PRIZM Disassembler')
- info.SetVersion('1.0.1')
- info.SetDescription(description)
- info.SetCopyright('(C) 2010 David Gomes')
- info.SetWebSite('http://www.davidgom.co.cc')
- info.AddDeveloper('David Gomes')
- info.AddArtist('David Gomes')
- wx.AboutBox(info)
- def OnGetOnlineHelp(event):
- webbrowser.open('http://www.omnimaga.org/index.php?board=146.0')
- self.dirname = ''
- def OnSaveASM(event):
- # Save away the edited text
- # Open the file, do an RU sure check for an overwrite!
- dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "Assembly files (*.asm)|*.asm", \
- wx.SAVE | wx.OVERWRITE_PROMPT)
- if dlg.ShowModal() == wx.ID_OK:
- # Grab the content to be saved
- itcontains = self.outputText.GetValue()
- # Open the file for write, write, close
- self.filename=dlg.GetFilename()
- self.dirname=dlg.GetDirectory()
- filehandle=open(os.path.join(self.dirname, self.filename),'w')
- filehandle.write(itcontains)
- filehandle.close()
- self.SetTitle('PRIZM Disassembler - '+self.filename)
- # Get rid of the dialog to keep things tidy
- dlg.Destroy()
- filters = 'Text files (*.txt)|*.txt|Hexadecimal files (*.hex)|*.hex'
- def OnSaveHEX(event):
- # Save away the edited text
- # Open the file, do an RU sure check for an overwrite!
- dlg = wx.FileDialog(self, "Choose a file", self.dirname,"", filters, \
- wx.SAVE | wx.OVERWRITE_PROMPT)
- if dlg.ShowModal() == wx.ID_OK:
- # Grab the content to be saved
- itcontains = self.inputText.GetValue()
- # Open the file for write, write, close
- self.filename=dlg.GetFilename()
- self.dirname=dlg.GetDirectory()
- filehandle=open(os.path.join(self.dirname, self.filename),'w')
- filehandle.write(itcontains)
- filehandle.close()
- self.SetTitle('PRIZM Disassembler - '+self.filename)
- # Get rid of the dialog to keep things tidy
- dlg.Destroy()
- def OnOpen(event):
- # In this case, the dialog is created within the method because
- # the directory name, etc, may be changed during the running of the
- # application. In theory, you could create one earlier, store it in
- # your frame object and change it when it was called to reflect
- # current parameters / values
- dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", filters, wx.OPEN)
- if dlg.ShowModal() == wx.ID_OK:
- self.filename=dlg.GetFilename()
- self.dirname=dlg.GetDirectory()
- # Open the file, read the contents and set them into
- # the text edit window
- filehandle=open(os.path.join(self.dirname, self.filename),'r')
- self.inputText.SetValue(filehandle.read())
- filehandle.close()
- # Report on name of latest file read
- self.SetTitle('PRIZM Disassembler - '+self.filename)
- # Later - could be enhanced to include a "changed" flag whenever
- # the text is actually changed, could also be altered on "save" ...
- dlg.Destroy()
- def NewFile(event):
- dial = wx.MessageDialog(None, 'Are you sure to create a new file?', 'New File',
- wx.YES_NO | wx.ICON_QUESTION)
- if dial.ShowModal() == wx.ID_YES:
- self.inputText.SetValue('')
- self.outputText.SetValue('')
- self.SetTitle('Assembly')
- def OnQuit(event):
- dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Exit PRIZM Disassembler',
- wx.YES_NO | wx.ICON_QUESTION)
- if dial.ShowModal() == wx.ID_YES:
- self.Destroy()
- def Num2Hex(event):
- DecimalInput=wx.TextEntryDialog(None, "Enter the decimal:", 'Decimal to Hexadecimal', 'Enter decimal...')
- if DecimalInput.ShowModal()==wx.ID_OK:
- Decimal=int(DecimalInput.GetValue())
- hexCode = ((hex(Decimal)).upper())[2:]
- self.inputText.SetValue(self.inputText.GetValue() + str(hexCode))
- def Hex2Num(event):
- HexInput=wx.TextEntryDialog(None, "Enter the Hexadecimal code:", 'Hexadecimal to Decimal', 'Enter hexadecimal code...')
- if HexInput.ShowModal()==wx.ID_OK:
- Hex=HexInput.GetValue()
- hexstring=hex2dec(Hex)
- self.inputText.SetValue(self.inputText.GetValue() + str(hexstring))
- def GiveInputFocus(event):
- self.inputfocus = 1
- def RemoveInputFocus(event):
- self.inputfocus = 0
- def GiveOutputFocus(event):
- self.outputfocus = 1
- def RemoveOutputFocus(event):
- self.outputfocus = 0
- def SelectAll(event):
- if self.inputfocus == 1:
- self.inputText.SelectAll()
- if self.outputfocus == 1:
- self.outputText.SelectAll()
- def Undo(event):
- if self.inputfocus == 1:
- self.inputText.Undo()
- if self.outputfocus == 1:
- self.outputText.Undo()
- def Redo(event):
- if self.inputfocus == 1:
- self.inputText.Redo()
- if self.outputfocus == 1:
- self.outputText.Redo()
- def Cut(event):
- if self.inputfocus == 1:
- self.inputText.Cut()
- if self.outputfocus == 1:
- self.outputText.Cut()
- def Copy(event):
- if self.inputfocus == 1:
- self.inputText.Copy()
- if self.outputfocus == 1:
- self.outputText.Copy()
- def Paste(event):
- if self.inputfocus == 1:
- self.inputText.Paste()
- if self.outputfocus == 1:
- self.outputText.Paste()
- def Clear(event):
- if self.inputfocus == 1:
- self.inputText.SetValue('')
- if self.outputfocus == 1:
- self.outputText.SetValue('')
- def FindReplace(event):
- textToFindInput=wx.TextEntryDialog(None,"Enter the text to be replaced","Find and Replace",'Enter text...')
- if textToFindInput.ShowModal()==wx.ID_OK:
- textToFind=textToFindInput.GetValue()
- textToReplaceInput=wx.TextEntryDialog(None,"Enter the text to replace","Find and Replace",'Enter text...')
- if textToReplaceInput.ShowModal()==wx.ID_OK:
- textToReplace = textToReplaceInput.GetValue()
- if self.inputfocus == 1:
- self.inputText.SetValue(self.inputText.GetValue().replace(textToFind,textToReplace))
- if self.outputfocus == 1:
- self.outputText.SetValue(self.outputText.GetValue().replace(textToFind,textToReplace))
- def CountWords(event):
- if self.inputfocus == 1:
- inputLength = len(self.inputText.GetValue())
- charBox = wx.MessageDialog(None, 'Characters (with spaces): '+str(inputLength),'Characters/Words', wx.OK)
- errorAnswer = charBox.ShowModal()
- charBox.Destroy()
- if self.outputfocus == 1:
- outputLength = len(self.outputText.GetValue())
- charBox = wx.MessageDialog(None, 'Characters (with spaces): '+str(outputLength),'Characters/Words', wx.OK)
- errorAnswer = charBox.ShowModal()
- charBox.Destroy()
- #START OF GUI
- panel = wx.Panel(self,size=(1366,768))
- self.inputText = wx.TextCtrl(panel,size=(715,665),style=wx.TE_MULTILINE | wx.BORDER_SUNKEN)
- self.outputText = wx.TextCtrl(panel,size=(715,665),style=wx.TE_MULTILINE | wx.BORDER_SUNKEN)
- vbox = wx.BoxSizer(wx.VERTICAL)
- hbox = wx.BoxSizer() #wx.VERTICAL or DEFAULT = wx.HORIZONTAL
- hbox.Add(self.inputText,1,wx.EXPAND)
- hbox.Add(self.outputText,1,wx.EXPAND)
- vbox.Add((0,0))
- vbox.Add(hbox,50,wx.CENTER|wx.EXPAND)
- self.SetSizer(vbox)
- global ID_CONVERT
- ID_CONVERT = 101
- self.statusbar = self.CreateStatusBar()
- self.statusbar.SetFieldsCount(3)
- self.statusbar.SetStatusWidths([-5, -2, -1])
- menuBar=wx.MenuBar()
- file=wx.Menu()
- newFileOption = file.Append(7,"New\tCtrl+N","Opens New File")
- openMenu = wx.Menu()
- openHEXOption = openMenu.Append(6,"Open Hex\tCtrl+O","Opens an Hexadecimal code")
- openG3AOption = openMenu.Append(25,"Load .g3a","Loads a .g3a file")
- file.AppendMenu(-1,"Open",openMenu)
- saveMenu = wx.Menu()
- saveASMOption = saveMenu.Append(3,"Save Assembly\tCtrl+S","Saves the Assembly File")
- saveHEXOption = saveMenu.Append(4,"Save Hex","Saves the Hexadecimal File")
- file.AppendMenu(-1,"Save",saveMenu)
- exitAction = file.Append(5,"Exit\tAlt+F4","Quits SH3 Disassembler")
- edit = wx.Menu()
- undo = edit.Append(14,'Undo\tCtrl+Z','Goes back in time')
- redo = edit.Append(15,'Redo\tCtrl+Y','Goes ahead in time')
- edit.AppendSeparator()
- findReplaceOption = edit.Append(20,'Find and Replace\tCtrl+F','Finds and replaces text in the code')
- edit.AppendSeparator()
- selectAll = edit.Append(9,'Select All\tCtrl+A', 'Selects all the text')
- edit.AppendSeparator()
- cut = edit.Append(10,'Cut\tCtrl+X','Cuts the selected text')
- copy = edit.Append(11,'Copy\tCtrl+C','Cuts the selected text')
- paste = edit.Append(12,'Paste\tCtrl+V','Pastes the copied text')
- edit.AppendSeparator()
- lengthOption = edit.Append(23,'Words','Counts the number of characters and words')
- clear = edit.Append(13,'Clear','Deletes the whole text')
- convert=wx.Menu()
- disassembleOption = convert.Append(1,"Convert\tF5","Converts Hexadecimal to Assembly")
- tools=wx.Menu()
- numToHexOption = tools.Append(18,'Decimal to Hexadecimal','Converts a decimal number to Hexadecimal')
- hexToNumOption = tools.Append(19,'Hexadecimal to Decimal','Converts Hexadecimal code to a decimal number')
- help = wx.Menu()
- aboutOption = help.Append(2,"About","Information about Assemblex")
- onlineHelpOption = help.Append(24,"Online help","Get online help at omnimaga.org")
- menuBar.Append(file,"File")
- menuBar.Append(edit,"Edit")
- menuBar.Append(convert,"Convert")
- menuBar.Append(tools,"Tools")
- menuBar.Append(help,"Help")
- self.SetMenuBar(menuBar)
- #END OF GUI
- equates = ['Enii','9ndd','Dndd','6nm3','2nm0','2nm1','2nm2','6nm0','6nm1','6nm2','2nm4','2nm5','2nm6','6nm4','6nm5','6nm6','80nd','81nd','1nmd','84md','85md','5nmd','0nm4','0nm5','0nm6','0nmC','0nmD','0nmE','C0dd','C1dd','C2dd','C4dd','C5dd','C6dd','C7dd','0n29','0n83','6nm8','6nm9','2nmD','3nmC','7nii','3nmE','3nmF','88ii','3nm0','3nm2','3nm3','3nm6','3nm7','4n11','4n15','2nmC','3nm4','2nm7','001A','3nmD','3nm5','4n10','6nmE','6nmF','6nmC','6nmD','0nmF','4nmF','0nm7','2nmF','2nmE','6nmB','6nmA','3nm8','3nmA','3nmB','2nm9','C9ii','CDii','6nm7','2nmB','CBii','CFii','4nm8','2nm8','C8ii','CCii','2nmA','CAii','CEii','4n04','4n05','4n24','4n25','4nmC','4n20','4n21','4nmD','4n00','4n01','4n08','4n09','4n18','4n19','4n28','4n29','8Bdd','8Fdd','89dd','8Ddd','Addd','0n03','Bddd','0n03','4n2B','4n0B','000B','0028','0048','0008','4m0E','4m1E','4m2E','4M3E','4m4E','4m8E','4m9E','4mAE','4mBE','4mCE','4mDE','4mEE','4mFE','4m07','4m17','4m27','4m37','4m47','4m87','4m97','4mA7','4mB7','4mC7','4mD7','4mE7','4mF7','4m0A','4m1A','4m2A','4m06','4m16','4m26','0038','0009','0n83','002B','0058','0018','001B','0n02','0n12','0n22','0n32','0n42','0n82','0n92','0nA2','0nB2','0nC2','0nD2','0nE2','0nF2','4n03','4n13','4n23','4n33','4n43','4n83','4n93','4nA3','4nB3','4nC3','4nD3','4nE3','4nF3','0n0A','0n1A','0n2A','4n02','4n12','4n22','C3ii']
- prizmInstructions = ['Mov #imm, Rn','Mov.W @(disp*2+PC),Rn','MOV.L @(disp*4+PC),Rn','Mov Rm, Rn','MOV.B Rm,@Rn','Mov.W Rm,@Rn','Mov.L Rm,@Rn','Mov.B @Rm,Rn','Mov.W @Rm,Rn','Mov.L @Rm,Rn','MOV.B Rm,@-Rn','MOV.W Rm,@-Rn','MOV.L Rm,@-Rn','MOV.B @Rm+,Rn','MOV.W @Rm+,Rn','MOV.L @Rm+,Rn','MOV.B R0,@(disp+Rn)','MOV.W R0,@(disp*2+Rn)','MOV.L Rm,@(disp*4+Rn)','MOV.B @(disp+Rm),R0','MOV.W @(disp*2+Rm),R0','MOV.L @(disp*4+Rm),Rn','MOV.B Rm,@(R0+Rn)','MOV.W Rm,@(R0+Rn)','MOV.L Rm,@(R0+Rn)','MOV.B @(R0+Rm),Rn','MOV.W @(R0+Rm),Rn','MOV.L @(R0+Rm),Rn','MOV.B R0,@(disp+GBR)','MOV.W R0,@(disp*2+GBR)','MOV.L R0,@(disp*4+GBR)','MOV.B @(disp+GBR),R0','MOV.W @(disp*2+GBR),R0','MOV.W @(disp*4+GBR),R0','MOVA @(disp*4+PC),R0','MOVT Rn','PREF @Rn','SWAP.B Rm,Rn','SWAP.W Rm,Rn','XTRCT Rm,Rn','ADD Rm,Rn','ADD #imm,Rn','ADDC Rm,Rn','ADDV Rm,Rn','CMP/EQ #imm,R0','CMP/EQ Rn,Rm','CMP/HS Rm,Rn','CMP/GE Rm,Rn','CMP/HI Rm,Rn','CMP/GT Rm,Rn','CMP/PZ Rn','CMP/PL Rn','CMP/STR Rm,Rn','DIV1 Rm,Rn','DIV0S Rm,Rn','DIV0U','DMULS.L Rm,Rn','DMULU.L Rm,Rn','DT Rn','EXTS.B Rm,Rn','EXTS.W Rm,Rn','EXTU.B Rm,Rn','EXTU.W Rm,Rn','MAC.L @Rm+,@Rn+','MAC.W @Rm+,@Rn+','MUL.L Rm,Rn','MULS.W Rm,Rn','MULU.W Rm,Rn','NEG Rm,Rn','NEGC Rm,Rn','SUB Rm,Rn','SUBC Rm,Rn','SUBV Rm,Rn','AND Rm,Rn','AND #imm,R0','AND.B #imm,@(R0+GBR)','NOT Rm,Rn','OR Rm,Rn','OR #imm,R0','OR.B #imm,@(R0+GBR)','TAS.B @Rn','TST Rm,Rn','TST #imm,R0','TST.B #imm,@(R0+GBR)','XOR Rm,Rn','XOR #imm,R0','XOR.B #imm,@(R0+GBR)','ROTL Rn','ROTR Rn','ROTCL Rn','ROTCR Rn','SHAD Rm,Rn','SHAL Rn','SHAR Rn','SHLD Rm,Rn','SHLL Rn','SHLR Rn','SHLL2 Rn','SHLR2 Rn','SHLL8 Rn','SHLR8 Rn','SHLR8 Rn','SHLR16 Rn','BF label','BF/S label','BT label','BT/S label','BRA label','BRAF Rn','BSR label','BSRF Rn','JMP @Rn','JSR @Rn','RTS','CLRMAC','CLRS','CLRT','LDC Rm,SR','LDC Rm,GBR','LDC Rm,VBR','LDC Rm,SSR','LDC Rm,SPC','LDC Rm,R0_BANK','LDC Rm,R1_BANK','LDC Rm,R2_BANK','LDC Rm,R3_BANK','LDC Rm,R4_BANK','LDC Rm,R5_BANK','LDC Rm,R6_BANK','LDC Rm,R7_BANK','LDC.L @Rm+,SR','LDC.L @Rm+,GBR','LDC.L @Rm+,VBR','LDC.L @Rm+,SSR','LDC.L @Rm+,SPC','LDC.L @Rm+,R0_BANK','LDC.L @Rm+,R1_BANK','LDC.L @Rm+,R2_BANK','LDC.L @Rm+,R3_BANK','LDC.L @Rm+,R4_BANK','LDC.L @Rm+,R5_BANK','LDC.L @Rm+,R6_BANK','LDC.L @Rm+,R7_BANK','LDS Rm,MACH','LDS Rm,MACL','LDS Rm,PR','LDS.L @Rm+,MACH','LDS.L @Rm+,MACL','LDS.L @Rm+,PR','LDTLB','NOP','PREF @Rn','RTE','SETS','SETT','SLEEP','STC SR,Rn','STC GBR,Rn','STC VBR,Rn','STC SSR,Rn','STC SPC,Rn','STC R0_BANK,Rn','STC R1_BANK,Rn','STC R2_BANK,Rn','STC R3_BANK,Rn','STC R4_BANK,Rn','STC R5_BANK,Rn','STC R6_BANK,Rn','STC R7_BANK,Rn','STC.L SR,@-Rn','STC.L GBR,@-Rn','STC.L VBR,@-Rn','STC.L SSR,@-Rn','STC.L SPC,@-Rn','STC.L R0_BANK,@-Rn','STC.L R1_BANK,@-Rn','STC.L R2_BANK,@-Rn','STC.L R3_BANK,@-Rn','STC.L R4_BANK,@-Rn','STC.L R5_BANK,@-Rn','STC.L R6_BANK,@-Rn','STC.L R7_BANK,@-Rn','STS MACH,Rn','STS MACL,Rn','STS PR,Rn','STS.L MACH,@-Rn','STS.L MACL,@-Rn','STS.L PR,@-Rn','TRAPA #imm']
- global i
- def OnUpdateInputText(event):
- c = self.inputText.GetValue()
- d = c.replace('\n', '')
- a = d.replace('\r','')
- anum = len(a)
- if a=="":
- self.outputText.SetValue("")
- if anum%4 == 0:
- b = [a[x:x+4] for x in xrange(0,anum,4)]
- program = ""
- i=0
- while i < len(b):
- if (b[i] in equates)==True:
- equateLocation = equates.index(b[i])
- if i != 0:
- program+="\n"+(prizmInstructions[equateLocation])
- else:
- program+=(prizmInstructions[equateLocation])
- i=i+1
- self.outputText.SetValue(program)
- #DEFINE EVENTS
- self.inputText.Bind(wx.EVT_SET_FOCUS,GiveInputFocus)
- self.inputText.Bind(wx.EVT_KILL_FOCUS,RemoveInputFocus)
- self.outputText.Bind(wx.EVT_SET_FOCUS,GiveOutputFocus)
- self.outputText.Bind(wx.EVT_KILL_FOCUS,RemoveOutputFocus)
- self.inputText.Bind(wx.EVT_TEXT_ENTER,OnUpdateInputText)
- self.Bind(wx.EVT_MENU,OnUpdateInputText, id=1)
- self.Bind(wx.EVT_MENU,OnSaveASM,id=3)
- self.Bind(wx.EVT_MENU,OnSaveHEX,id=4)
- self.Bind(wx.EVT_MENU,OnQuit,id=5)
- self.Bind(wx.EVT_MENU,OnOpen,id=6)
- self.Bind(wx.EVT_MENU,getG3Adata,id=25)
- self.Bind(wx.EVT_MENU,NewFile,id=7)
- self.Bind(wx.EVT_MENU,SelectAll,id=9)
- self.Bind(wx.EVT_MENU,Cut,id=10)
- self.Bind(wx.EVT_MENU,Copy,id=11)
- self.Bind(wx.EVT_MENU,Paste,id=12)
- self.Bind(wx.EVT_MENU,Clear,id=13)
- self.Bind(wx.EVT_MENU,Undo,id=14)
- self.Bind(wx.EVT_MENU,Redo,id=15)
- self.Bind(wx.EVT_MENU,FindReplace,id=20)
- self.Bind(wx.EVT_MENU,CountWords,id=23)
- self.Bind(wx.EVT_MENU,Num2Hex,id=18)
- self.Bind(wx.EVT_MENU,Hex2Num,id=19)
- self.Bind(wx.EVT_MENU,OnAbout,id=2)
- self.Bind(wx.EVT_MENU,OnGetOnlineHelp,id=24)
- if __name__=='__main__':
- app=wx.PySimpleApp()
- frame=MainFrame(parent=None, id= -1)
- frame.Show()
- frame.Maximize()
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement