Previous Thread
Next Thread
Print Thread
Printing a binary number in the debugger #115757 08/25/19 05:04 PM
Joined: Feb 2014
Posts: 311
G
Golden Child Offline OP
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 311
One of the things I wanted to do was to print a binary number so I wrote a little lua function to make a print string for me which I can then paste into the debugger.

I wish there'd be the ability to call lua from the debugger, then you could really do fancy printing if you wanted.

Code
function makeprintstr(...) 
local arg={...} local formatstr,argstr,loc,descr,style 
formatstr="" argstr="" 
for a=3,#arg,3 do 
  loc=arg[a+0] descr=arg[a+1] style=arg[a+2] 
  formatstr=formatstr..descr..": "..loc..'=%02x '
  argstr=argstr..iif(a>3,",","")..loc.."," 
  for i=arg[2]-1,0,-1 do 
   formatstr=formatstr..'%x' 
   argstr=argstr.."(".."("..loc..")"..iif(i>=4,">>"..string.format("%x",(4*math.floor(i/4))),"").." & "..string.format("%x",math.floor(2^i)>>(4*math.floor(i/4)))..")"..iif(style=="1111","!=0","")..iif(i>0,",","")
  end 
  formatstr=formatstr..' '
end 
return arg[1]..' "'..formatstr..'",'..argstr..";" 
end


-- you can print a byte in "1111" style or "8421"


print(makeprintstr("printf",8,"a","ACC","1111"))
print(makeprintstr("printf",8,"ff","test","8421"))

-- and more than one per line

print(makeprintstr("printf",8,"b@F1","byte at f1","8421","b@F2","byte at f2","1111"))

-- and print 16 bits

print(makeprintstr("printf",16,"fedc","test","8421","w@0","word at zero","1111"))

-- or make a tracelog string

print(makeprintstr("tracelog",8,"b@f1","test","8421"))





and sample output after pasting into the debugger:

printf "byte at f1: b@F1=%02x %x%x%x%x%x%x%x%x byte at f2: b@F2=%02x %x%x%x%x%x%x%x%x ",b@F1,((b@F1)>>4 & 8),((b@F1)>>4 & 4),((b@F1)>>4 & 2),((b@F1)>>4 & 1),((b@F1) & 8),((b@F1) & 4),((b@F1) & 2),((b@F1) & 1),b@F2,((b@F2)>>4 & 8)!=0,((b@F2)>>4 & 4)!=0,((b@F2)>>4 & 2)!=0,((b@F2)>>4 & 1)!=0,((b@F2) & 8)!=0,((b@F2) & 4)!=0,((b@F2) & 2)!=0,((b@F2) & 1)!=0;

byte at f1: b@F1=ED 84208401 byte at f2: b@F2=00 00000000

printf "test: fedc=%02x %x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x word at zero: w@0=%02x %x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x ",fedc,((fedc)>>c & 8),((fedc)>>c & 4),((fedc)>>c & 2),((fedc)>>c & 1),((fedc)>>8 & 8),((fedc)>>8 & 4),((fedc)>>8 & 2),((fedc)>>8 & 1),((fedc)>>4 & 8),((fedc)>>4 & 4),((fedc)>>4 & 2),((fedc)>>4 & 1),((fedc) & 8),((fedc) & 4),((fedc) & 2),((fedc) & 1),w@0,((w@0)>>c & 8)!=0,((w@0)>>c & 4)!=0,((w@0)>>c & 2)!=0,((w@0)>>c & 1)!=0,((w@0)>>8 & 8)!=0,((w@0)>>8 & 4)!=0,((w@0)>>8 & 2)!=0,((w@0)>>8 & 1)!=0,((w@0)>>4 & 8)!=0,((w@0)>>4 & 4)!=0,((w@0)>>4 & 2)!=0,((w@0)>>4 & 1)!=0,((w@0) & 8)!=0,((w@0) & 4)!=0,((w@0) & 2)!=0,((w@0) & 1)!=0;

test: fedc=FEDC 8421842084018400 word at zero: w@0=47F3 0100011111110011


and I can make a print string for the processor status bits:

print(makeprintstr("printf",8,"p","status","8421"))

Code
printf "status:      NV__DIZC";printf "status: p=%02x %x%x%x%x%x%x%x%x ",p,((p)>>4 & 8),((p)>>4 & 4),((p)>>4 & 2),((p)>>4 & 1),((p) & 8),((p) & 4),((p) & 2),((p) & 1);
status:      NV__DIZC
status: p=B0 80210000

Re: Printing a binary number in the debugger [Re: Golden Child] #115758 08/25/19 05:25 PM
Joined: Mar 2001
Posts: 16,300
R
R. Belmont Online Content
Very Senior Member
Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 16,300
It is possible to call Lua functions from C++, we do it all the time at work. I don't know if MAME is setup for that though.

Re: Printing a binary number in the debugger [Re: Golden Child] #115761 08/25/19 11:08 PM
Joined: Nov 1999
Posts: 655
B
Bletch Offline
Senior Member
Offline
Senior Member
B
Joined: Nov 1999
Posts: 655
Its probably just a question of creating a bridge between the debugger's expression engine and luaengine.cpp


Who's Online Now
2 registered members (Edstrom, 1 invisible), 145 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,683
Posts114,012
Members4,863
Most Online510
Aug 26th, 2019
Powered by UBB.threads™ PHP Forum Software 7.7.3