Bank monitor .. lil present
BlitzPlus Forums/BlitzPlus Programming/Bank monitor .. lil present
| ||
| Once in a while you'll pull your hair out while debugging when working with banks .. On one such day I decided to the stuff below .. perhaps not the cleanest code in terms of optimization or var naming.. but it works, and doesn't require globals.. Mousewheel and right mousebutton are supported. opinions! does it suck? is it handy? If someone makes use of it, well, I guess I didn't waste my afternoon then :)
Function ViewBank(bank)
FlushEvents()
BankMonitor=CreateWindow("Bank Monitor (by CS^TBL)",32,32,706,584,0,1)
BankHome=CreateButton("Home",656,8,40,24,BankMonitor)
Bank16m=CreateButton("-16",656,48,40,24,BankMonitor)
Bank16p=CreateButton("+16",656,76,40,24,BankMonitor)
Bank512m=CreateButton("-512",656,112,40,24,BankMonitor)
Bank512p=CreateButton("+512",656,140,40,24,BankMonitor)
HighliteNotZero=CreateButton(">0",656,170,40,24,BankMonitor,2)
ViewtypePanel=CreatePanel(652,200,44,40,BankMonitor)
ViewHex=CreateButton("HEX",0,0,44,16,ViewtypePanel,3):SetButtonState ViewHex,True
ViewDec=CreateButton("DEC",0,24,44,16,ViewtypePanel,3)
ViewVarPanel=CreatePanel(652,260,44,60,BankMonitor)
ViewShort=CreateButton("Short",0,0,44,16,ViewVarPanel,3)
ViewInt=CreateButton("Int",0,20,44,16,ViewVarPanel,3):SetButtonState ViewInt,True
ViewFloat=CreateButton("Float",0,40,44,16,ViewVarPanel,3)
Drawselector=False
BankCanvas=CreateCanvas(8,8,512+130,512+32,BankMonitor)
SetCanvas BankCanvas
ClsColor 0,0,80:Cls
size=BankSize(bank)
offset=0
redrawBankView=True
quitBankMonitor=False
Repeat
If redrawBankView
Cls
redrawBankView=False
For y=0 To 31
For x=0 To 15
index=x+(y*16)+(offset*16)
If index<size And index=>0 ; inside bank
; >0 highlite
byte=PeekByte(bank,index)
If byte
If ButtonState(HighliteNotZero)
Color 0,0,160
Rect x*32,y*16,32,16,True
Rect 512+x*8,y*16,8,16,True
EndIf
EndIf
; txt
Color 255,255,255
If ButtonState(ViewHex) ; hex
Text x*32,y*16,RSet(Right$(Hex(PeekByte(bank,index)),2),3)
Else ; dec
Text x*32,y*16,RSet(PeekByte(bank,index),3)
EndIf
; right column
Text 512+(x*8),y*16,Chr(PeekByte(bank,index))
Else ; outside bank
Color 255,255,255
Text x*32,y*16,RSet(".",3)
Text 512+(x*8),y*16,"."
EndIf
Next
Next
Color 0,0,180:Line 256,0,256,511
Line 0,514,511,514
If Drawselector
If ButtonState(ViewShort)
For t=0 To 1
y=((DrawselectorValue+t) / 16)-offset
If y<32
x=(DrawselectorValue+t) Mod 16
Color 255,160,0
Rect x*32,y*16,32,16,False
EndIf
Next
EndIf
If ButtonState(ViewInt)
For t=0 To 3
y=((DrawselectorValue+t) / 16)-offset
If y<32
x=(DrawselectorValue+t) Mod 16
Color 255,160,0
Rect x*32,y*16,32,16,False
EndIf
Next
EndIf
If ButtonState(ViewFloat)
For t=0 To 7
y=((DrawselectorValue+t) / 16)-offset
If y<32
x=(DrawselectorValue+t) Mod 16
Color 255,160,0
Rect x*32,y*16,32,16,False
EndIf
Next
EndIf
EndIf
Color 255,255,255
If DrawselectorValue<size
Text 208,520,"Mem adres: "+DrawselectorValue+" ("+Hex(DrawselectorValue)+")"
Else
Text 208,520,"Mem adres: out of range!"
EndIf
Text 480,520,"View: "+(offset*16)+".."+(511+offset*16)
If ButtonState(ViewShort)
If DrawselectorValue<(size-1)
Text 4,520,"Short: "+PeekShort(bank,DrawselectorValue)
EndIf
EndIf
If ButtonState(ViewInt)
If DrawselectorValue<(size-3)
Text 4,520,"Int : "+PeekInt(bank,DrawselectorValue)
EndIf
EndIf
If ButtonState(ViewFloat)
If DrawselectorValue<(size-7)
Text 4,520,"Float: "+PeekFloat(bank,DrawselectorValue)
EndIf
EndIf
FlipCanvas BankCanvas
EndIf
;----------------------------------------------------------------
WaitEvent()
If EventID()=$401
If EventSource()=BankHome ; home
offset=0:redrawBankView=True
EndIf
If EventSource()=Bank16m ; 16--
offset=offset-1
If offset<0 offset=0
redrawBankView=True
EndIf
If EventSource()=Bank16p ; 16++
offset=offset+1:redrawBankView=True
EndIf
If EventSource()=Bank512m ; 512--
offset=offset-32
If offset<0 offset=0
redrawBankView=True
EndIf
If EventSource()=Bank512p ; 512++
offset=offset+32:redrawBankView=True
EndIf
If EventSource()=HighliteNotZero ; >0
redrawBankView=True
EndIf
If EventSource()=ViewHex ; hex
redrawBankView=True
EndIf
If EventSource()=ViewDec ; dec
redrawBankView=True
EndIf
EndIf
If EventID()=$803
quitBankMonitor=True
EndIf
If EventID()=$201
If EventData()=2
If ButtonState(ViewFloat)
SetButtonState(ViewFloat),False
SetButtonState ViewShort,True
ElseIf ButtonState(ViewInt)
SetButtonState(ViewInt),False
SetButtonState ViewFloat,True
ElseIf ButtonState(ViewShort)
SetButtonState(ViewShort),False
SetButtonState ViewInt,True
EndIf
redrawBankView=True
EndIf
EndIf
If EventID()=$203 ; mouse move
If EventX()<512 And EventY()<512
DrawselectorValue=(EventX()/32)+(((EventY()/16)+offset)*16)
Drawselector=True
; check for da boundaries when reading out short/int/float
If ButtonState(ViewShort)
If DrawselectorValue>(size-2)
Drawselector=False
EndIf
EndIf
If ButtonState(ViewInt)
If DrawselectorValue>(size-4)
Drawselector=False
EndIf
EndIf
If ButtonState(ViewFloat)
If DrawselectorValue>(size-8)
Drawselector=False
EndIf
EndIf
redrawBankView=True
Else
Drawselector=False:redrawBankView=True
EndIf
EndIf
If EventID()=$204 ; wheel
offset=offset-EventData()
If offset<0 offset=0
redrawBankView=True
EndIf
If EventID()=$206 ; leave
Drawselector=False:redrawBankView=True
EndIf
Until quitBankMonitor
FlushEvents()
FreeGadget BankMonitor
End Function
my 2ct. |
| ||
darn I knew I forgot a part of my 'lazy.bb' :)Function SetCanvas(bla) SetBuffer CanvasBuffer(bla) End Function I guess you'll know how to modify the code if you don't want this lazy-ass function (I've tons of them lazy stuff) |