from picshell.ui.debug.DrawWindow import DrawWindow
from wx._core import BoxSizer
from picshell.engine.util.Format import Format

import wx
class DebugView :
    COL_ADR = 0
    COL_RUN = 1
    COL_BP = 2
    COL_CODE = 3
    COL_COM = 4
    def __init__(self,parent,uiManager):
        
        # debug view
        self.mainSplitter = wx.SplitterWindow(parent, -1,style=wx.NO_BORDER)
        topSplitter = wx.SplitterWindow(self.mainSplitter, -1) # jal / asm splitter
        bottomSplitter = wx.SplitterWindow(self.mainSplitter, -1)
        uiManager.bottomSplitter = bottomSplitter
        uiManager.topSplitter = topSplitter

        self.oldWatchedValues={} # to save watched value so that we can color value that changed
        self.oldWatchedVars = {}
        self.listWatchVars = None
        self.listWatchRegs = None
        self.watchedReg = set()

       
        # -------------------------------------------------------
        # ASM Debug list  panel
        #
        panelAsm = wx.Panel(topSplitter, -1, style=wx.NO_BORDER)
        vboxAsm = wx.BoxSizer(wx.VERTICAL)
        panelAsm.SetSizer(vboxAsm)

        self.listAsm =  wx.ListCtrl(panelAsm, -1, style=wx.LC_REPORT|wx.LC_SINGLE_SEL)
        self.listAsm.InsertColumn(self.COL_RUN, ' ')
        self.listAsm.InsertColumn(self.COL_BP, 'BP')
        self.listAsm.InsertColumn(self.COL_ADR, 'Addr')
        self.listAsm.InsertColumn(self.COL_CODE, 'ASM Code')
        self.listAsm.InsertColumn(self.COL_COM, '')
        self.listAsm.SetColumnWidth(self.COL_RUN, 20)
        self.listAsm.SetColumnWidth(self.COL_BP, 30)
        self.listAsm.SetColumnWidth(self.COL_ADR, 60)
        self.listAsm.SetColumnWidth(self.COL_CODE, 200)
        self.listAsm.SetColumnWidth(self.COL_COM, 600)
        self.listAsm.Bind(wx.EVT_LEFT_DCLICK, uiManager.OnBreakPointAsm)
        vboxAsm.Add(self.listAsm, -1,wx.EXPAND, 0 )
        bNextAsm = wx.Button(panelAsm,id=500, label='Next [F5]')
        
        vboxAsm.Add(bNextAsm)

        # -------------------------------------------------------
        # JAL Debug code list  panel
        #
        panelLang = wx.Panel(topSplitter, -1, style=wx.NO_BORDER)
        vboxLang  = wx.BoxSizer(wx.VERTICAL)
        self.listLang =  wx.ListCtrl(panelLang, -1, style=wx.LC_REPORT)
        self.listLang.InsertColumn(self.COL_RUN, '')
        self.listLang.InsertColumn(self.COL_BP, 'BP')
        self.listLang.InsertColumn(self.COL_ADR, 'Addr')
        self.listLang.InsertColumn(self.COL_CODE, 'Code')
        self.listLang.SetColumnWidth(self.COL_RUN, 20)
        self.listLang.SetColumnWidth(self.COL_BP, 30)
        self.listLang.SetColumnWidth(self.COL_ADR, 60)
        self.listLang.SetColumnWidth(self.COL_CODE, 600)
        self.listLang.Bind(wx.EVT_LEFT_DCLICK, uiManager.OnBreakPointLang)
        self.listLang.Bind(wx.EVT_LIST_ITEM_SELECTED, uiManager.OnListLangSelected)
        
        vboxLang.Add(self.listLang, -1,wx.EXPAND, 0 )
        
        panelButtonLang = wx.Panel(panelLang, -1, style=wx.NO_BORDER)
        vBoxLangButton = wx.BoxSizer(wx.HORIZONTAL)
        panelButtonLang.SetSizer(vBoxLangButton)
        bNextLang = wx.Button(panelButtonLang,id=501,label='Next [F6]')
        # bNextLangStepOver = wx.Button(panelButtonLang,id=502,label='Step over')
        vBoxLangButton.Add(bNextLang,0)
        #vBoxLangButton.Add(bNextLangStepOver,0) # not woking good enougth for now
        
        vboxLang.Add(panelButtonLang,0)
        
        
        panelLang.SetSizer(vboxLang)
                
        # -------------------------------------------------------
        # REG WATCH Panel
        #
        watchTab = wx.Notebook(bottomSplitter,-1,style=wx.NO_BORDER)
        # adr panel 
        panelRegs = wx.Panel(watchTab, -1 ,  style=wx.NO_BORDER)
        panelRegs.SetBackgroundColour(wx.WHITE)
        vboxRegs  = wx.BoxSizer(wx.VERTICAL)
        panelRegs.SetSizer(vboxRegs)
        self.regFilter =  wx.TextCtrl(panelRegs, -1, "")
        self.regFilter.SetToolTip(wx.ToolTip("Register filter, use , separtor to show several expression.\nuse .. to display a range of register. example : 2..5\nuse *nb to cumulate byte, example: 0x30*2"))
        self.regFilter.Bind(wx.EVT_TEXT, self.OnRegFilterKeyDown)
        vboxRegs.Add(self.regFilter, 0, wx.EXPAND)
        
        self.listWatchRegs =  wx.ListCtrl(panelRegs, -1, style=wx.LC_REPORT)
        self.listWatchRegs.InsertColumn(0, 'Reg')
        self.listWatchRegs.InsertColumn(1, 'Values')
        self.listWatchRegs.InsertColumn(2, 'Comment')
        self.listWatchRegs.SetColumnWidth(0, 100)
        self.listWatchRegs.SetColumnWidth(1, 150)
        self.listWatchRegs.SetColumnWidth(2, 250)
        
        vboxRegs.Add(self.listWatchRegs, -1,wx.EXPAND, 0 )

        # vars panel
        panelVars = wx.Panel(watchTab, -1, style=wx.NO_BORDER)
        panelVars.SetBackgroundColour(wx.WHITE)
        vboxVars  = wx.BoxSizer(wx.VERTICAL)
        panelVars.SetSizer(vboxVars)
        self.varFilter =  wx.TextCtrl(panelVars, -1, "")
        self.varFilter.SetToolTip(wx.ToolTip("Variable filter, use , separtor to show several vars"))
        self.varFilter.Bind(wx.EVT_TEXT, self.OnVarFilterKeyDown)
        vboxVars.Add(self.varFilter, 0, wx.EXPAND)
        uiManager.varFilter = self.varFilter
        self.listWatchVars =  wx.ListCtrl(panelVars, -1, style=wx.LC_REPORT)
        self.listWatchVars.InsertColumn(0, 'Vars')
        self.listWatchVars.InsertColumn(1, 'Type')
        self.listWatchVars.InsertColumn(2, 'Values')
        self.listWatchVars.InsertColumn(3, 'Addr.')
        self.listWatchVars.SetColumnWidth(0, 150)
        vboxVars.Add(self.listWatchVars, -1,wx.EXPAND, 0 )
        
        # data eeprom panel
        panelDataEEProm = wx.Panel(watchTab, -1, style=wx.NO_BORDER)
        panelDataEEProm.SetBackgroundColour(wx.WHITE)
        vboxEEProm  = wx.BoxSizer(wx.VERTICAL)
        panelDataEEProm.SetSizer(vboxEEProm)
        self.dataEEPromFilter =  wx.TextCtrl(panelDataEEProm, -1, "")
        self.dataEEPromFilter.SetToolTip(wx.ToolTip("Use , separtor to show several expression.\nuse .. to display a range. example : 2..5"))
        self.dataEEPromFilter.Bind(wx.EVT_TEXT, self.OnEEPromFilterKeyDown)
        vboxEEProm.Add(self.dataEEPromFilter, 0, wx.EXPAND)

        self.listWatchDataEEProm =  wx.ListCtrl(panelDataEEProm, -1, style=wx.LC_REPORT)
        self.listWatchDataEEProm.InsertColumn(0, 'Addr.')
        self.listWatchDataEEProm.InsertColumn(1, 'Values')
        vboxEEProm.Add(self.listWatchDataEEProm, -1,wx.EXPAND, 0 )
        
        # Breakpoints
        bpPanel = wx.Panel(watchTab, -1 ,  style=wx.NO_BORDER)
        bpPanel.SetBackgroundColour(wx.WHITE)
        bpSizer  = wx.BoxSizer(wx.VERTICAL)
        bpPanel.SetSizer(bpSizer)
        self.listBreakpoint =  wx.ListCtrl(bpPanel, -1, style=wx.LC_REPORT)
        self.listBreakpoint.InsertColumn(0, 'Addr.')
        self.listBreakpoint.InsertColumn(1, 'Line')
        self.listBreakpoint.SetColumnWidth(1, 280)
        #self.listBreakpoint.Bind(wx.EVT_LEFT_DCLICK, self.OnlistBreakPointDClick)
        self.listBreakpoint.Bind(wx.EVT_LIST_ITEM_SELECTED, uiManager.OnlistBreakPointSelected)
        uiManager.listBreakpoint = self.listBreakpoint
        bpSizer.Add(self.listBreakpoint, -1,wx.EXPAND, 0 )        
        bpRemoveAll = wx.Button(bpPanel,-1,"Remove all")
        bpRemoveAll.Bind(wx.EVT_BUTTON, uiManager.OnRemoveAllBreakpoints)
        bpSizer.Add(bpRemoveAll, 0, 0)

        #Unit Test
        unitTestPanel = wx.Panel(watchTab, -1 ,  style=wx.NO_BORDER)
        listUnitTest =  wx.ListCtrl(unitTestPanel, -1, style=wx.LC_REPORT)
        listUnitTest.InsertColumn(0, 'Test name')
        listUnitTest.InsertColumn(1, 'Status')
        listUnitTest.InsertColumn(2, 'Comment')
        
        listUnitTest.SetColumnWidth(1, 50)
        listUnitTest.SetColumnWidth(2, 400)
        
        unitTestSizer  = wx.BoxSizer(wx.VERTICAL)
        unitTestPanel.SetSizer(unitTestSizer)
        unitTestSizer.Add(listUnitTest, -1,wx.EXPAND, 0 )     

        drawWindow = DrawWindow(watchTab)
        uiManager.drawWindow = drawWindow
        
        panelAsmExplain = wx.Panel(watchTab, -1 ,  style=wx.NO_BORDER)
        explainAsmText = wx.TextCtrl(panelAsmExplain,style=wx.TE_MULTILINE);
        panelAsmExplainSizer = wx.BoxSizer(wx.VERTICAL);
        panelAsmExplain.SetSizer(panelAsmExplainSizer);
        panelAsmExplainSizer.Add(explainAsmText,-1,wx.EXPAND)
        explainAsmText.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        uiManager.explainAsmText =  explainAsmText
        
        watchTab.AddPage(panelVars,"Vars")
        watchTab.AddPage(panelRegs,"Regs")
        watchTab.AddPage(panelDataEEProm,"Data EEPROM")
        watchTab.AddPage(unitTestPanel,"Unit Testing")
        watchTab.AddPage(bpPanel,"Breakpoints")
        watchTab.AddPage(drawWindow,"Devices")
        watchTab.AddPage(panelAsmExplain,"ASM Explainer")
        

        # -------------------------------------------------------
        # IN / OUT Panel
        #
        
        panelInOut = wx.ScrolledWindow(bottomSplitter, -1,  style=wx.NO_BORDER)  
        vboxInOut  = wx.FlexGridSizer(vgap = 0, hgap = 20 )
        vboxInOut.SetCols(2)
        panelInOut.SetSizerAndFit(vboxInOut)
        panelInOut.SetScrollRate(1,1)
        panelInOut.SetBackgroundColour(wx.WHITE)
        panelInOut.SetSizerAndFit(vboxInOut)
        uiManager.inOutPanel = panelInOut
        uiManager.inOutSizer = vboxInOut 

        # -------------------------------------------------------
        # Split both windows 
        #
        topSplitter.SplitVertically(panelAsm, panelLang)
        bottomSplitter.SplitVertically(watchTab, panelInOut)
        
        self.mainSplitter.SplitHorizontally(topSplitter,bottomSplitter)
        
        self.listAsm.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        self.listLang.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        
        self.listWatchRegs.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        self.listWatchVars.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL)) 
        self.listWatchDataEEProm.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL)) 
        self.listBreakpoint.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL)) 
        
        uiManager.listAsm = self.listAsm
        uiManager.listLang = self.listLang
        uiManager.listWatchVars = self.listWatchVars
        uiManager.listWatchRegs = self.listWatchRegs
        uiManager.listUnitTest = listUnitTest
        
        uiManager.bNextLang = bNextLang
        uiManager.bNextAsm = bNextAsm
        
        self.mainSplitter.SetMinimumPaneSize(100)
        topSplitter.SetMinimumPaneSize(100)
        bottomSplitter.SetMinimumPaneSize(100)
        bottomSplitter.SetSashGravity(0.5)
        topSplitter.SetSashGravity(0.5)
        self.mainSplitter.SetSashGravity(0.5)
        
        
    
                            
    def getView(self):
        return self.mainSplitter
        

    def Clear( self ):   
        self.oldWatchedValues={} # to save watched value so that we can color value that changed
        self.oldWatchedVars = {}
        self.watchedReg =set()
        self.listWatchVars.DeleteAllItems()
        self.listWatchRegs.DeleteAllItems()
        self.listWatchDataEEProm.DeleteAllItems()

    #----------------------------------------------------------------
    # Watched Regs / Vars
    #
    def updateWatchVarView( self ):   
        format4 ="%4d"
        format2 = "0x%02X"
        self.listWatchVars.DeleteAllItems()
    
        # display var list
        self.listWatchVars.InsertStringItem(0,"PC")
        self.listWatchVars.SetStringItem(0,2, format2  %self.emu.state.getPc())
        
        font = self.listWatchVars.GetItemFont(0)
        font.SetWeight(wx.BOLD)
        self.listWatchVars.InsertStringItem(1,"W")
        self.listWatchVars.SetStringItem(1,2, format2 % self.emu.state.getW())
        self.listWatchVars.InsertStringItem(2,"STATUS")
        self.listWatchVars.SetStringItem(2,2, Format.binf(self.emu.state.getStatus()))
        self.listWatchVars.SetItemFont(0,font)
        self.listWatchVars.SetItemFont(1,font)
        self.listWatchVars.SetItemFont(2,font)
        index = 3
        if hasattr(self,"langParser"):
            for var in sorted(self.langParser.varAdrMapping):
                varDispType ="h:"
                varName = var.replace("v_","")
                show = False
                filters = self.varFilter.GetValue()
                if (filters.strip() != ""):
                    for filter in filters.split(","):
                        filter = filter.strip()
                        filter = filter.upper()
                        
                        if filter.startswith("B:"):
                            filter = filter[2:]
                            varDispType="b:"
                        elif filter.startswith("H:") or filter.startswith("0X"):
                            filter = filter[2:]
                            varDispType="h:"
                        elif filter.startswith("D:"):
                            filter = filter[2:]
                            varDispType="d:"
                        
                        if varName.upper().startswith(filter):
                            show = True
                else:
                    show =True
                
                if (show):
                    self.listWatchVars.InsertStringItem(index,varName)
                    adr = self.langParser.varAdrMapping[var]
                    
                    type= ""

                    if hasattr(self, "varTypeDict") and self.varTypeDict != None and self.varTypeDict.has_key(varName):
                        type = self.varTypeDict[varName]
                    else:
                        type = "? (byte)"
                    type = type.upper()  
                    self.listWatchVars.SetStringItem(index,1,type )
                    
                    # BIT - 1 bit
                    # BYTE - 8 bit, unsigned
                    # SBYTE - 8 bit, signed
                    # WORD - 16 bit, unsigned
                    # SWORD - 16 bit, signed
                    # DWORD - 32 bit, unsigned
                    # SDWORD - 32 bit, signed
                    # user defined : [S]BYTE*n, creates an n-BYTE signed            
                    
                    val = self.emu.varValue(adr,type)  
                    valAsStr = str(val)
                    if (varDispType =="b:") :
                        valAsStr = Format.binf(val)
                    if (varDispType =="h:") :
                        valAsStr = "0x%X" % val
                    
                        
                    self.listWatchVars.SetStringItem(index,2,valAsStr )
                    self.listWatchVars.SetStringItem(index,3,format2 % adr )
                    
                    # Highlight changes
                    changed = True
                    if self.oldWatchedVars.has_key(var):
                        if val != self.oldWatchedVars[var]:
                            changed = True
                        else:
                            changed = False
                    if changed :
                        self.listWatchVars.SetItemTextColour(index,"#FF0000")
                    else:
                        self.listWatchVars.SetItemTextColour(index,"#000000")
                    self.oldWatchedVars[var] = val
                    index +=1

    # -------------------------------------------------------------------------
    #
    #
    def updateWatchRegView(self):
        self.listWatchRegs.DeleteAllItems()
        format4 ="%4d"
        format2 = "0x%02X"
        self.listWatchRegs.InsertStringItem(0,"PC")
        self.listWatchRegs.SetStringItem(0,1, "0x%X"  % self.emu.state.getPc())
        self.listWatchRegs.SetStringItem(0,2, "%d"  % self.emu.state.getPc())
        
        font = self.listWatchRegs.GetItemFont(0)
        font.SetWeight(wx.BOLD)
        self.listWatchRegs.InsertStringItem(1,"W")
        self.listWatchRegs.SetStringItem(1,1, format2 % self.emu.state.getW())
        self.listWatchRegs.SetStringItem(1,2, format4 % self.emu.state.getW())
        
        self.listWatchRegs.InsertStringItem(2,"STATUS")        
        statusValue = self.emu.state.getStatus()
        self.listWatchRegs.SetStringItem(1,2, format4 % statusValue )
        
        bs = Format.bin(statusValue)
        status="IRP=%s, RP1=%s, RP0=%s, TO=%s" %(bs[0],bs[1],bs[2],bs[3])
        status2="PD=%s, Z=%s, DC=%s, C=%s" %(bs[4],bs[5],bs[6],bs[7])
        self.listWatchRegs.SetStringItem(2,2, status)
        self.listWatchRegs.InsertStringItem(3,"")
        self.listWatchRegs.SetStringItem(3,2, status2)
        
        self.listWatchRegs.SetItemFont(0,font)
        self.listWatchRegs.SetItemFont(1,font)
        self.listWatchRegs.SetItemFont(2,font)
        self.listWatchRegs.SetItemFont(3,font)
        index = 4

        regs = set()
        regsType = {}
        filters = self.regFilter.GetValue()
        regTxt = []
        if (filters.strip() != ""):
            regTxt = filters.split(",")
        
        
        #--------------------------------------
        # Main reg param loop
        
        for reg in regTxt :
            if reg != "":
                if reg.upper().startswith("B:"):
                    reg = reg[2:]
                    try:
                        parts = reg.split("..")
                        regsType[Format.toNumber(parts[0])] ="b:"
                    except : pass
                elif reg.upper().startswith("H:"):
                    reg = reg[2:]
                    try:
                        parts = reg.split("..")
                        regsType[Format.toNumber(parts[0])] ="h:"
                    except : pass
                elif reg.upper().startswith("D:"):
                    reg = reg[2:]
                    try:
                        parts = reg.split("..")
                        regsType[Format.toNumber(parts[0])] ="d:"
                    except : pass
                else :
                    try:
                        parts = reg.split("..")
                        regsType[Format.toNumber(parts[0])] ="h:"
                    except : pass
                try :
                    if ".." in reg:
                        parts = reg.split("..")
                        n1 = Format.toNumber(parts[0])
                        n2 = Format.toNumber(parts[1])+1
                        for val in range (n1,n2):
                            if val <= (0x1FF):
                                regs.add(val)
                                regsType[val] =regsType[n1]
                                
                    elif "*" in reg :
                        regs.add(reg)
                    else:
                        val = Format.toNumber(reg)
                        if val <= (0x1FF):
                            regs.add(val)
                except  :
                    #print sys.exc_info()[0]
                    pass # something wrong entred ? TODO : message
        regs = list(regs)
        regs.sort()
        wregs = list(self.watchedReg)
        wregs.sort()
        regs += ["-"]+wregs       
        for reg in regs :
            
            if reg == "-":
                self.listWatchRegs.InsertStringItem(index,"-"*10)
                self.listWatchRegs.SetStringItem(index,1, "-"*10)
                self.listWatchRegs.SetStringItem(index,2, "-"*20)
            else:
                
                # multi byte mode
                parts = str(reg).split("*")
                nReg = 0
                if (len(parts)==2) and parts[1] != "":
                    
                    startReg= Format.toNumber(parts[0])
                    nbBytes = int(parts[1])
                    vReg ="b"
                    if nbBytes == 0:
                        nbBytes = 1   
                    for i in range(startReg+nbBytes-1,startReg-1,-1):
                        vReg += Format.bin(self.emu.state.absreg(i))
                    format ="%d"
                    if parts[0].startswith("0x"):
                        format = "0x%X"
                    nReg = Format.toNumber(vReg)
                    vReg = format  % nReg
                    regStr = reg
                else :
                    nReg = self.emu.state.absreg(Format.toNumber(parts[0]))
                    vReg =  format2 % nReg
                    regStr = "%4d 0x%03X" % (Format.toNumber(parts[0]),Format.toNumber(parts[0]))
                
                # if prefix avaiable("b:"), override default display
                
                if (regsType.has_key(reg)):
                    if(regsType[reg]=="d:"):
                        vReg =str(nReg)
                    elif(regsType[reg]=="b:"):
                        vReg =Format.binf(nReg)
                    elif(regsType[reg]=="h:"):
                        vReg = "0x%X"  % nReg    
                    
                #---------------------------
                # display
                
                self.listWatchRegs.InsertStringItem(index,regStr)
                self.listWatchRegs.SetStringItem(index,1, vReg)
                comment =""
                
                if hasattr(self, "langParser") and (self.langParser.adrVarMapping.has_key(reg)):
                    comment =self.langParser.adrVarMapping[reg]
                    comment = comment.replace("v_","")
                tmp = "?"
                try:
                    tmp = regStr.strip().split(" ")[0]
                    nReg = int(tmp)
                    #if (Format.spAdrReg.has_key(nReg)) :
                    #    comment = Format.spAdrReg[nReg]
                    if ( self.emu.state.spAdrReg.has_key(nReg)) :
                        comment = self.emu.state.spAdrReg[nReg]
                except :
                    #print "UIManager.updateWatchRegView : ["+tmp+"]"
                    pass
                self.listWatchRegs.SetStringItem(index,2, comment)
                changed = True
                if self.oldWatchedValues.has_key(str(reg)):
                    if vReg != self.oldWatchedValues[str(reg)]:
                        changed = True
                    else:
                        changed = False
                if changed :
                    self.listWatchRegs.SetItemTextColour(index,"#FF0000")
                else:
                    self.listWatchRegs.SetItemTextColour(index,"#000000")
                self.oldWatchedValues[str(reg)] = vReg
            index += 1

    def OnVarFilterKeyDown(self,event):
        if self.listWatchVars.GetItemCount() > 0:
            self.updateWatchVarView()


    def OnRegFilterKeyDown(self,event):
        if self.listWatchRegs.GetItemCount() > 0:
            self.updateWatchRegView()
        
    def OnEEPromFilterKeyDown(self,event):
        if hasattr(self.emu, "state") :
            self.updateWatchDataEEPromView()
        
        
    # -----------------------------------------------------------------------------
    #
    #
    def updateWatchDataEEPromView(self):
        #format4 ="%4d"
        format2 = "0x%02X"
        #--------------------------------------------
        # display regs to watch
        # reg get added when state.regWrite() by the RegisterUpdater class
        self.listWatchDataEEProm.DeleteAllItems()
        addrs = set()
        filters = self.dataEEPromFilter.GetValue()
        addrTxt = []
        if (filters.strip() != ""):
            addrTxt = filters.split(",")
        else:
            if hasattr( self.emu.pic, "eeprom_size" ):
                addrTxt= ["0..%d" % (self.emu.pic.eeprom_size-1) ]
    
        for addr in addrTxt :
            if addr != "":
                try :
                    if ".." in addr:
                        parts = addr.split("..")
                        n1 = Format.toNumber(parts[0])
                        n2 = Format.toNumber(parts[1])+1
                        for val in range (n1,n2):
                            if val <= (0xFF):
                                addrs.add(val)    
                    else:
                        val = Format.toNumber(addr)
                        if val <= (0xFF):
                            addrs.add(val)
                except : pass # something wrong entred ? TODO : message
        addrs = list(addrs)
        addrs.sort()
        
        try:
            for i,adr in enumerate(addrs) :
                self.listWatchDataEEProm.InsertStringItem(i,str(adr))
                val = format2  % self.emu.state.eeData[adr]
                self.listWatchDataEEProm.SetStringItem(i,1,val)
        except : pass # something wrong entred ? TODO : message
        
    def updateViews(self):
        self.updateWatchRegView()
        self.updateWatchVarView()
        self.updateWatchDataEEPromView()
        