| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "gui.h" |
| 21 |
#include <fmt/printf.h> |
| 22 |
#include "imgui.h" |
| 23 |
#include "guiConst.h" |
| 24 |
|
| 25 |
String disasmCmd(unsigned char* buf, size_t bufLen, unsigned int addr, unsigned char* speedDial) { |
| 26 |
if (addr>=bufLen) return "???"; |
| 27 |
|
| 28 |
if (buf[addr]<0xb4) { |
| 29 |
return fmt::sprintf("note %s",noteNames[buf[addr]]); |
| 30 |
} else switch (buf[addr]) { |
| 31 |
case 0xb4: |
| 32 |
return "note null"; |
| 33 |
break; |
| 34 |
case 0xb5: |
| 35 |
return "off"; |
| 36 |
break; |
| 37 |
case 0xb6: |
| 38 |
return "offrel"; |
| 39 |
break; |
| 40 |
case 0xb7: |
| 41 |
return "mrel"; |
| 42 |
break; |
| 43 |
case 0xb8: |
| 44 |
if (addr+1>=bufLen) return "???"; |
| 45 |
return fmt::sprintf("ins $%.2x",(int)buf[addr+1]); |
| 46 |
break; |
| 47 |
case 0xc0: |
| 48 |
if (addr+1>=bufLen) return "???"; |
| 49 |
return fmt::sprintf("preporta $%.2x",(int)buf[addr+1]); |
| 50 |
break; |
| 51 |
case 0xc2: |
| 52 |
if (addr+1>=bufLen) return "???"; |
| 53 |
return fmt::sprintf("vib $%.2x",(int)buf[addr+1]); |
| 54 |
break; |
| 55 |
case 0xc3: |
| 56 |
if (addr+1>=bufLen) return "???"; |
| 57 |
return fmt::sprintf("vibrange %d",(int)buf[addr+1]); |
| 58 |
break; |
| 59 |
case 0xc4: |
| 60 |
if (addr+1>=bufLen) return "???"; |
| 61 |
return fmt::sprintf("vibshape %d",(int)buf[addr+1]); |
| 62 |
break; |
| 63 |
case 0xc5: |
| 64 |
if (addr+1>=bufLen) return "???"; |
| 65 |
return fmt::sprintf("pitch $%.2x",(int)buf[addr+1]); |
| 66 |
break; |
| 67 |
case 0xc6: |
| 68 |
if (addr+1>=bufLen) return "???"; |
| 69 |
return fmt::sprintf("arp $%.2x",(int)buf[addr+1]); |
| 70 |
break; |
| 71 |
case 0xc7: |
| 72 |
if (addr+1>=bufLen) return "???"; |
| 73 |
return fmt::sprintf("vol $%.2x",(int)buf[addr+1]); |
| 74 |
break; |
| 75 |
case 0xc8: |
| 76 |
if (addr+2>=bufLen) return "???"; |
| 77 |
return fmt::sprintf("volslide %d",(int)((short)(buf[addr+1]|(buf[addr+2]<<8)))); |
| 78 |
break; |
| 79 |
case 0xc9: |
| 80 |
if (addr+2>=bufLen) return "???"; |
| 81 |
return fmt::sprintf("porta %d, %d",(int)buf[addr+1],(int)buf[addr+2]); |
| 82 |
break; |
| 83 |
case 0xca: |
| 84 |
if (addr+1>=bufLen) return "???"; |
| 85 |
return fmt::sprintf("legato %d",(int)buf[addr+1]); |
| 86 |
break; |
| 87 |
case 0xcb: |
| 88 |
if (addr+4>=bufLen) return "???"; |
| 89 |
return fmt::sprintf("volporta %d, %d",(int)((short)(buf[addr+1]|(buf[addr+2]<<8))),(int)((short)(buf[addr+3]|(buf[addr+4]<<8)))); |
| 90 |
break; |
| 91 |
case 0xcc: |
| 92 |
if (addr+1>=bufLen) return "???"; |
| 93 |
return fmt::sprintf("tremolo $%.2x",(int)buf[addr+1]); |
| 94 |
break; |
| 95 |
case 0xcd: |
| 96 |
if (addr+1>=bufLen) return "???"; |
| 97 |
return fmt::sprintf("panbrello $%.2x",(int)buf[addr+1]); |
| 98 |
break; |
| 99 |
case 0xce: |
| 100 |
if (addr+1>=bufLen) return "???"; |
| 101 |
return fmt::sprintf("panslide %d",(signed char)buf[addr+1]); |
| 102 |
break; |
| 103 |
case 0xcf: |
| 104 |
if (addr+2>=bufLen) return "???"; |
| 105 |
return fmt::sprintf("pan $%x, $%x",(int)buf[addr+1],(int)buf[addr+2]); |
| 106 |
break; |
| 107 |
case 0xe0: case 0xe1: case 0xe2: case 0xe3: |
| 108 |
case 0xe4: case 0xe5: case 0xe6: case 0xe7: |
| 109 |
case 0xe8: case 0xe9: case 0xea: case 0xeb: |
| 110 |
case 0xec: case 0xed: case 0xee: case 0xef: { |
| 111 |
unsigned char cmd=speedDial[buf[addr]&15]; |
| 112 |
int cmdLen=DivCS::getCmdLength(cmd); |
| 113 |
if ((addr+cmdLen)>=bufLen) return "???"; |
| 114 |
String ret=fmt::sprintf("qcmd%d %s",buf[addr]-0xd0,(cmd<DIV_CMD_MAX)?cmdName[cmd]:"INVALID"); |
| 115 |
for (int i=0; i<cmdLen; i++) { |
| 116 |
ret+=fmt::sprintf(", %.2x",buf[addr+1+i]); |
| 117 |
} |
| 118 |
return ret; |
| 119 |
break; |
| 120 |
} |
| 121 |
case 0xf0: case 0xf1: case 0xf2: case 0xf3: |
| 122 |
case 0xf4: case 0xf5: case 0xf6: case 0xf7: |
| 123 |
case 0xf8: case 0xf9: case 0xfa: case 0xfb: |
| 124 |
case 0xfc: case 0xfd: case 0xfe: case 0xff: |
| 125 |
return fmt::sprintf("qwait (%d)",(int)(buf[addr]-0xe0)); |
| 126 |
break; |
| 127 |
case 0xd0: |
| 128 |
if (addr+3>=bufLen) return "???"; |
| 129 |
return fmt::sprintf("opt $%.2x%.2x%.2x",(int)buf[addr+1],(int)buf[addr+2],(int)buf[addr+3]); |
| 130 |
break; |
| 131 |
case 0xd1: |
| 132 |
return "nop"; |
| 133 |
break; |
| 134 |
case 0xd4: |
| 135 |
if (addr+2>=bufLen) return "???"; |
| 136 |
return fmt::sprintf("callsym $%.4x",(int)(buf[addr+1]|(buf[addr+2]<<8))); |
| 137 |
break; |
| 138 |
case 0xd5: |
| 139 |
if (addr+4>=bufLen) return "???"; |
| 140 |
return fmt::sprintf("call $%.8x",(unsigned int)(buf[addr+1]|(buf[addr+2]<<8)|(buf[addr+3]<<16)|(buf[addr+4]<<24))); |
| 141 |
break; |
| 142 |
case 0xd6: |
| 143 |
return "offwait"; |
| 144 |
break; |
| 145 |
case 0xd7: { |
| 146 |
if (addr+1>=bufLen) return "???"; |
| 147 |
int cmdLen=DivCS::getCmdLength(buf[addr+1]); |
| 148 |
if ((addr+1+cmdLen)>=bufLen) return "???"; |
| 149 |
String ret=fmt::sprintf("cmd %s",(buf[addr+1]<DIV_CMD_MAX)?cmdName[buf[addr+1]]:"INVALID"); |
| 150 |
for (int i=0; i<cmdLen; i++) { |
| 151 |
ret+=fmt::sprintf(", %.2x",buf[addr+2+i]); |
| 152 |
} |
| 153 |
return ret; |
| 154 |
break; |
| 155 |
} |
| 156 |
case 0xd8: |
| 157 |
if (addr+2>=bufLen) return "???"; |
| 158 |
return fmt::sprintf("call $%.4x",(unsigned int)(buf[addr+1]|(buf[addr+2]<<8))); |
| 159 |
break; |
| 160 |
case 0xd9: |
| 161 |
return "ret"; |
| 162 |
break; |
| 163 |
case 0xda: |
| 164 |
return fmt::sprintf("jmp $%.8x",(unsigned int)(buf[addr+1]|(buf[addr+2]<<8)|(buf[addr+3]<<16)|(buf[addr+4]<<24))); |
| 165 |
break; |
| 166 |
case 0xdb: |
| 167 |
return fmt::sprintf("rate $%.8x",(unsigned int)(buf[addr+1]|(buf[addr+2]<<8)|(buf[addr+3]<<16)|(buf[addr+4]<<24))); |
| 168 |
break; |
| 169 |
case 0xdc: |
| 170 |
if (addr+2>=bufLen) return "???"; |
| 171 |
return fmt::sprintf("waits %d",(int)(buf[addr+1]|(buf[addr+2]<<8))); |
| 172 |
break; |
| 173 |
case 0xdd: |
| 174 |
if (addr+1>=bufLen) return "???"; |
| 175 |
return fmt::sprintf("waitc %d",(int)buf[addr+1]); |
| 176 |
break; |
| 177 |
case 0xde: |
| 178 |
return "wait 1"; |
| 179 |
break; |
| 180 |
case 0xdf: |
| 181 |
return "stop"; |
| 182 |
break; |
| 183 |
default: |
| 184 |
return "ill"; |
| 185 |
break; |
| 186 |
} |
| 187 |
return "TODO"; |
| 188 |
} |
| 189 |
|
| 190 |
void FurnaceGUI::drawCSPlayer() { |
| 191 |
if (nextWindow==GUI_WINDOW_CS_PLAYER) { |
| 192 |
csPlayerOpen=true; |
| 193 |
ImGui::SetNextWindowFocus(); |
| 194 |
nextWindow=GUI_WINDOW_NOTHING; |
| 195 |
} |
| 196 |
if (!csPlayerOpen) return; |
| 197 |
if (ImGui::Begin("Command Stream Player",&csPlayerOpen,globalWinFlags,_("Command Stream Player"))) { |
| 198 |
if (ImGui::Button(_("Load"))) { |
| 199 |
openFileDialog(GUI_FILE_CMDSTREAM_OPEN); |
| 200 |
} |
| 201 |
ImGui::SameLine(); |
| 202 |
if (ImGui::Button(_("Kill"))) { |
| 203 |
if (!e->killStream()) { |
| 204 |
showError(_("Kikai wa mou shindeiru!")); |
| 205 |
} |
| 206 |
} |
| 207 |
ImGui::SameLine(); |
| 208 |
if (ImGui::Button(_("Burn Current Song"))) { |
| 209 |
e->killStream(); |
| 210 |
exportCmdStream(true,""); |
| 211 |
} |
| 212 |
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { |
| 213 |
ImGui::OpenPopup("CSOptions"); |
| 214 |
} |
| 215 |
ImGui::SameLine(); |
| 216 |
if (e->isHalted()) { |
| 217 |
if (ImGui::Button("Resume")) e->resume(); |
| 218 |
} else { |
| 219 |
if (ImGui::Button("Pause")) e->halt(); |
| 220 |
} |
| 221 |
ImGui::SameLine(); |
| 222 |
ImGui::Button(_("Burn Options")); |
| 223 |
if (ImGui::BeginPopupContextItem("CSOptions",ImGuiPopupFlags_MouseButtonLeft)) { |
| 224 |
commandExportOptions(); |
| 225 |
ImGui::EndPopup(); |
| 226 |
} |
| 227 |
|
| 228 |
DivCSPlayer* cs=e->getStreamPlayer(); |
| 229 |
if (cs) { |
| 230 |
if (ImGui::BeginTabBar("CSOptions")) { |
| 231 |
int chans=e->getTotalChannelCount(); |
| 232 |
if (ImGui::BeginTabItem(_("Status"))) { |
| 233 |
if (ImGui::BeginTable("CSStat",13,ImGuiTableFlags_SizingStretchSame|ImGuiTableFlags_ScrollX|ImGuiTableFlags_Borders)) { |
| 234 |
ImGui::TableSetupScrollFreeze(1,1); |
| 235 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 236 |
ImGui::TableNextColumn(); |
| 237 |
ImGui::Text(_("channel")); |
| 238 |
ImGui::TableNextColumn(); |
| 239 |
ImGui::Text(_("start")); |
| 240 |
ImGui::TableNextColumn(); |
| 241 |
ImGui::Text(_("PC")); |
| 242 |
ImGui::TableNextColumn(); |
| 243 |
ImGui::Text(_("wait")); |
| 244 |
ImGui::TableNextColumn(); |
| 245 |
ImGui::Text(_("SP")); |
| 246 |
ImGui::TableNextColumn(); |
| 247 |
ImGui::Text(_("note")); |
| 248 |
ImGui::TableNextColumn(); |
| 249 |
ImGui::Text(_("pitch")); |
| 250 |
ImGui::TableNextColumn(); |
| 251 |
ImGui::Text(_("vol")); |
| 252 |
ImGui::TableNextColumn(); |
| 253 |
ImGui::Text(_("vols")); |
| 254 |
ImGui::TableNextColumn(); |
| 255 |
ImGui::Text(_("volst")); |
| 256 |
ImGui::TableNextColumn(); |
| 257 |
ImGui::Text(_("vib")); |
| 258 |
ImGui::TableNextColumn(); |
| 259 |
ImGui::Text(_("porta")); |
| 260 |
ImGui::TableNextColumn(); |
| 261 |
ImGui::Text(_("arp")); |
| 262 |
|
| 263 |
for (int i=0; i<chans; i++) { |
| 264 |
DivCSChannelState* state=cs->getChanState(i); |
| 265 |
ImGui::TableNextRow(); |
| 266 |
ImGui::TableNextColumn(); |
| 267 |
ImGui::Text("%d",i); |
| 268 |
ImGui::TableNextColumn(); |
| 269 |
ImGui::Text("$%.4x",state->startPos); |
| 270 |
ImGui::TableNextColumn(); |
| 271 |
ImGui::Text("$%.4x",state->readPos); |
| 272 |
ImGui::TableNextColumn(); |
| 273 |
ImGui::Text("%d/%d",state->waitTicks,state->lastWaitLen); |
| 274 |
ImGui::TableNextColumn(); |
| 275 |
ImGui::Text("%d",state->callStackPos); |
| 276 |
ImGui::TableNextColumn(); |
| 277 |
ImGui::Text("%d",state->note); |
| 278 |
ImGui::TableNextColumn(); |
| 279 |
ImGui::Text("%d",state->pitch); |
| 280 |
ImGui::TableNextColumn(); |
| 281 |
ImGui::Text("$%.4X",state->volume); |
| 282 |
ImGui::TableNextColumn(); |
| 283 |
ImGui::Text("%+d",state->volSpeed); |
| 284 |
ImGui::TableNextColumn(); |
| 285 |
ImGui::Text("%+d",state->volSpeedTarget); |
| 286 |
ImGui::TableNextColumn(); |
| 287 |
ImGui::Text("%d/%d (%d)",state->vibratoDepth,state->vibratoRate,state->vibratoPos); |
| 288 |
ImGui::TableNextColumn(); |
| 289 |
ImGui::Text("-> %d (%d)",state->portaTarget,state->portaSpeed); |
| 290 |
ImGui::TableNextColumn(); |
| 291 |
ImGui::Text("$%.2X",state->arp); |
| 292 |
} |
| 293 |
|
| 294 |
ImGui::EndTable(); |
| 295 |
} |
| 296 |
ImGui::EndTabItem(); |
| 297 |
} |
| 298 |
if (ImGui::BeginTabItem(_("Trace"))) { |
| 299 |
ImGui::PushFont(patFont); |
| 300 |
if (ImGui::BeginTable("CSTrace",chans,ImGuiTableFlags_SizingFixedSame|ImGuiTableFlags_Borders|ImGuiTableFlags_ScrollX)) { |
| 301 |
char tempID[32]; |
| 302 |
for (int i=0; i<chans; i++) { |
| 303 |
snprintf(tempID,31,"c%d",i); |
| 304 |
ImGui::TableSetupColumn(tempID,ImGuiTableColumnFlags_WidthFixed,200.0*dpiScale); |
| 305 |
} |
| 306 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 307 |
for (int i=0; i<chans; i++) { |
| 308 |
DivCSChannelState* state=cs->getChanState(i); |
| 309 |
ImGui::TableNextColumn(); |
| 310 |
ImGui::Text("%d: $%.4x (>>%d)",i,state->readPos,state->callStackPos); |
| 311 |
} |
| 312 |
|
| 313 |
ImGui::TableNextRow(); |
| 314 |
unsigned char* buf=cs->getData(); |
| 315 |
size_t bufSize=cs->getDataLen(); |
| 316 |
for (int i=0; i<chans; i++) { |
| 317 |
DivCSChannelState* state=cs->getChanState(i); |
| 318 |
ImGui::TableNextColumn(); |
| 319 |
int maxItems=(ImGui::GetContentRegionAvail().y/MAX(ImGui::GetTextLineHeightWithSpacing(),1.0f)); |
| 320 |
if (maxItems>=DIV_MAX_CSTRACE) maxItems=DIV_MAX_CSTRACE-1; |
| 321 |
|
| 322 |
int tracePos=state->tracePos; |
| 323 |
|
| 324 |
for (int j=(tracePos-maxItems)&(DIV_MAX_CSTRACE-1); j!=tracePos; j=(j+1)&(DIV_MAX_CSTRACE-1)) { |
| 325 |
if (state->trace[j]==0) { |
| 326 |
ImGui::TextUnformatted("..."); |
| 327 |
} else { |
| 328 |
String dis=disasmCmd(buf,bufSize,state->trace[j],cs->getFastCmds()); |
| 329 |
ImGui::Text("%.4x: %s",state->trace[j],dis.c_str()); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
ImGui::EndTable(); |
| 335 |
} |
| 336 |
ImGui::PopFont(); |
| 337 |
ImGui::EndTabItem(); |
| 338 |
} |
| 339 |
if (ImGui::BeginTabItem(_("Disassemble"))) { |
| 340 |
bool mustProceed=false; |
| 341 |
ImGui::AlignTextToFramePadding(); |
| 342 |
ImGui::Text("Address"); |
| 343 |
ImGui::SameLine(); |
| 344 |
ImGui::InputScalar("##DisAsmAddr",ImGuiDataType_U32,&csDisAsmAddr,0,0,"%.8X",ImGuiInputTextFlags_CharsHexadecimal); |
| 345 |
ImGui::SameLine(); |
| 346 |
if (ImGui::Button("Go")) { |
| 347 |
mustProceed=true; |
| 348 |
} |
| 349 |
|
| 350 |
if (mustProceed) { |
| 351 |
csDisAsm.clear(); |
| 352 |
unsigned char* buf=cs->getData(); |
| 353 |
for (size_t i=csDisAsmAddr; i<cs->getDataLen();) { |
| 354 |
int insLen=DivCS::getInsLength(buf[i],(((i+1)<cs->getDataLen())?buf[i+1]:0),cs->getFastCmds()); |
| 355 |
if (insLen<1) { |
| 356 |
logE("INS %x NOT IMPLEMENTED...",buf[i]); |
| 357 |
break; |
| 358 |
} |
| 359 |
|
| 360 |
CSDisAsmIns ins; |
| 361 |
ins.addr=i; |
| 362 |
memcpy(ins.data,&buf[i],insLen); |
| 363 |
ins.len=insLen; |
| 364 |
csDisAsm.push_back(ins); |
| 365 |
|
| 366 |
i+=insLen; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
if (!csDisAsm.empty()) { |
| 371 |
ImGui::PushFont(patFont); |
| 372 |
if (ImGui::BeginTable("CSDisAsm",chans,ImGuiTableFlags_SizingFixedFit|ImGuiTableFlags_ScrollY)) { |
| 373 |
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,oneChar.x*2.0f); |
| 374 |
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,oneChar.x*9.0f); |
| 375 |
ImGui::TableSetupColumn("c3",ImGuiTableColumnFlags_WidthFixed,oneChar.x*3.0f*6.0f); |
| 376 |
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch); |
| 377 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 378 |
ImGui::TableNextColumn(); |
| 379 |
ImGui::Text("pc"); |
| 380 |
ImGui::TableNextColumn(); |
| 381 |
ImGui::Text("addr"); |
| 382 |
ImGui::TableNextColumn(); |
| 383 |
ImGui::Text("hex"); |
| 384 |
ImGui::TableNextColumn(); |
| 385 |
ImGui::Text("ins"); |
| 386 |
|
| 387 |
for (CSDisAsmIns& i: csDisAsm) { |
| 388 |
ImGui::TableNextRow(0,oneChar.y); |
| 389 |
ImGui::TableNextColumn(); |
| 390 |
// this is the "PC is here row"... |
| 391 |
|
| 392 |
|
| 393 |
ImGui::TableNextColumn(); |
| 394 |
ImGui::Text("%.8x",i.addr); |
| 395 |
|
| 396 |
ImGui::TableNextColumn(); |
| 397 |
for (int j=0; j<i.len; j++) { |
| 398 |
ImGui::Text("%.2x",i.data[j]); |
| 399 |
ImGui::SameLine(); |
| 400 |
} |
| 401 |
|
| 402 |
ImGui::TableNextColumn(); |
| 403 |
String dis=disasmCmd(i.data,8,0,cs->getFastCmds()); |
| 404 |
ImGui::Text("%s",dis.c_str()); |
| 405 |
|
| 406 |
// jmp/ret separator |
| 407 |
if (i.data[0]==0xd9 || i.data[0]==0xda) { |
| 408 |
ImGui::TableNextRow(0,oneChar.y); |
| 409 |
ImGui::TableNextColumn(); |
| 410 |
ImGui::Separator(); |
| 411 |
ImGui::TableNextColumn(); |
| 412 |
ImGui::Separator(); |
| 413 |
ImGui::TableNextColumn(); |
| 414 |
ImGui::Separator(); |
| 415 |
ImGui::TableNextColumn(); |
| 416 |
ImGui::Separator(); |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
ImGui::EndTable(); |
| 421 |
} |
| 422 |
ImGui::PopFont(); |
| 423 |
} |
| 424 |
ImGui::EndTabItem(); |
| 425 |
} |
| 426 |
if (ImGui::BeginTabItem(_("Hex"))) { |
| 427 |
ImGui::PushFont(patFont); |
| 428 |
if (ImGui::BeginTable("CSHexPos",chans,ImGuiTableFlags_SizingStretchSame)) { |
| 429 |
ImGui::TableNextRow(); |
| 430 |
for (int i=0; i<chans; i++) { |
| 431 |
ImGui::TableNextColumn(); |
| 432 |
ImGui::Text("%d",i); |
| 433 |
} |
| 434 |
ImGui::TableNextRow(); |
| 435 |
for (int i=0; i<chans; i++) { |
| 436 |
DivCSChannelState* state=cs->getChanState(i); |
| 437 |
ImGui::TableNextColumn(); |
| 438 |
ImGui::Text("$%.4x",state->readPos); |
| 439 |
} |
| 440 |
ImGui::EndTable(); |
| 441 |
} |
| 442 |
|
| 443 |
float oneCharSize=ImGui::CalcTextSize("A").x; |
| 444 |
float threeCharSize=ImGui::CalcTextSize("AA").x; |
| 445 |
float charViewSize=ImGui::CalcTextSize("0123456789ABCDEF").x; |
| 446 |
float fiveCharSize=ImGui::CalcTextSize("AAAAA").x; |
| 447 |
|
| 448 |
if (ImGui::BeginTable("CSHexView",19,ImGuiTableFlags_ScrollY)) { |
| 449 |
char charView[17]; |
| 450 |
ImGui::TableSetupScrollFreeze(1,1); |
| 451 |
ImGui::TableSetupColumn("addr",ImGuiTableColumnFlags_WidthFixed,fiveCharSize); |
| 452 |
ImGui::TableSetupColumn("d0",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 453 |
ImGui::TableSetupColumn("d1",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 454 |
ImGui::TableSetupColumn("d2",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 455 |
ImGui::TableSetupColumn("d3",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 456 |
ImGui::TableSetupColumn("d4",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 457 |
ImGui::TableSetupColumn("d5",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 458 |
ImGui::TableSetupColumn("d6",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 459 |
ImGui::TableSetupColumn("d7",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 460 |
ImGui::TableSetupColumn("d8",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 461 |
ImGui::TableSetupColumn("d9",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 462 |
ImGui::TableSetupColumn("d10",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 463 |
ImGui::TableSetupColumn("d11",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 464 |
ImGui::TableSetupColumn("d12",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 465 |
ImGui::TableSetupColumn("d13",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 466 |
ImGui::TableSetupColumn("d14",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 467 |
ImGui::TableSetupColumn("d15",ImGuiTableColumnFlags_WidthFixed,threeCharSize); |
| 468 |
ImGui::TableSetupColumn("spacer",ImGuiTableColumnFlags_WidthFixed,oneCharSize); |
| 469 |
ImGui::TableSetupColumn("char",ImGuiTableColumnFlags_WidthFixed,charViewSize); |
| 470 |
|
| 471 |
// header |
| 472 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 473 |
ImGui::TableNextColumn(); |
| 474 |
for (int i=0; i<16; i++) { |
| 475 |
ImGui::TableNextColumn(); |
| 476 |
ImGui::Text("%X",i); |
| 477 |
} |
| 478 |
|
| 479 |
// content |
| 480 |
unsigned char* buf=cs->getData(); |
| 481 |
unsigned short* accessTS=cs->getDataAccess(); |
| 482 |
unsigned int csTick=cs->getCurTick(); |
| 483 |
const float fadeTime=64.0f; |
| 484 |
size_t bufSize=cs->getDataLen(); |
| 485 |
csClipper.Begin((bufSize+15)>>4,ImGui::GetTextLineHeightWithSpacing()); |
| 486 |
while (csClipper.Step()) { |
| 487 |
for (int i=csClipper.DisplayStart; i<csClipper.DisplayEnd; i++) { |
| 488 |
ImGui::TableNextRow(); |
| 489 |
ImGui::TableNextColumn(); |
| 490 |
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg,ImGui::GetColorU32(ImGuiCol_TableHeaderBg)); |
| 491 |
ImGui::Text("%.4X",i<<4); |
| 492 |
|
| 493 |
for (int j=0; j<16; j++) { |
| 494 |
int pos=(i<<4)|j; |
| 495 |
ImGui::TableNextColumn(); |
| 496 |
if (pos>=(int)bufSize) continue; |
| 497 |
float cellAlpha=(float)(fadeTime-(((short)(csTick&0xffff))-(short)accessTS[pos]))/fadeTime; |
| 498 |
if (cellAlpha>0.0f) { |
| 499 |
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg,ImGui::GetColorU32(ImGuiCol_HeaderActive,cellAlpha)); |
| 500 |
} |
| 501 |
ImGui::Text("%.2X",buf[pos]); |
| 502 |
} |
| 503 |
|
| 504 |
ImGui::TableNextColumn(); |
| 505 |
ImGui::TableNextColumn(); |
| 506 |
for (int j=0; j<16; j++) { |
| 507 |
int pos=(i<<4)|j; |
| 508 |
if (pos>=(int)bufSize) { |
| 509 |
charView[j]=' '; |
| 510 |
} else if (buf[pos]>=0x20 && buf[pos]<=0x7e) { |
| 511 |
charView[j]=buf[pos]; |
| 512 |
} else { |
| 513 |
charView[j]='.'; |
| 514 |
} |
| 515 |
} |
| 516 |
charView[16]=0; |
| 517 |
|
| 518 |
ImGui::TextUnformatted(charView); |
| 519 |
} |
| 520 |
} |
| 521 |
csClipper.End(); |
| 522 |
|
| 523 |
ImGui::EndTable(); |
| 524 |
} |
| 525 |
ImGui::PopFont(); |
| 526 |
ImGui::EndTabItem(); |
| 527 |
} |
| 528 |
if (ImGui::BeginTabItem(_("Data Access Visualizer"))) { |
| 529 |
ImGui::Text("%d bytes",(int)cs->getDataLen()); |
| 530 |
|
| 531 |
ImGui::PushFont(patFont); |
| 532 |
if (ImGui::BeginTable("CSHexPos",chans,ImGuiTableFlags_SizingStretchSame)) { |
| 533 |
ImGui::TableNextRow(); |
| 534 |
for (int i=0; i<chans; i++) { |
| 535 |
ImGui::TableNextColumn(); |
| 536 |
ImGui::Text("%d",i); |
| 537 |
} |
| 538 |
ImGui::TableNextRow(); |
| 539 |
for (int i=0; i<chans; i++) { |
| 540 |
DivCSChannelState* state=cs->getChanState(i); |
| 541 |
ImGui::TableNextColumn(); |
| 542 |
ImGui::Text("$%.4x",state->readPos); |
| 543 |
} |
| 544 |
ImGui::EndTable(); |
| 545 |
} |
| 546 |
ImGui::PopFont(); |
| 547 |
|
| 548 |
if (csTex==NULL || !rend->isTextureValid(csTex)) { |
| 549 |
logD("recreating command stream data texture."); |
| 550 |
csTex=rend->createTexture(true,256,256,false,GUI_TEXFORMAT_ABGR32); |
| 551 |
if (csTex==NULL) { |
| 552 |
logE("error while creating command stream data texture! %s",SDL_GetError()); |
| 553 |
} |
| 554 |
} |
| 555 |
if (csTex!=NULL) { |
| 556 |
unsigned int* dataT=NULL; |
| 557 |
int pitch=0; |
| 558 |
if (!rend->lockTexture(csTex,(void**)&dataT,&pitch)) { |
| 559 |
logE("error while locking command stream data texture! %s",SDL_GetError()); |
| 560 |
} else { |
| 561 |
unsigned short* accessTS=cs->getDataAccess(); |
| 562 |
unsigned int csTick=cs->getCurTick(); |
| 563 |
const float fadeTime=64.0f; |
| 564 |
size_t bufSize=cs->getDataLen(); |
| 565 |
if (bufSize>65536) bufSize=65536; |
| 566 |
|
| 567 |
for (size_t i=0; i<bufSize; i++) { |
| 568 |
float cellAlpha=(float)(fadeTime-(((short)(csTick&0xffff))-(short)accessTS[i]))/fadeTime; |
| 569 |
if (cellAlpha>0.0f) { |
| 570 |
dataT[i]=ImGui::GetColorU32(ImGuiCol_HeaderActive,cellAlpha); |
| 571 |
} else { |
| 572 |
dataT[i]=0; |
| 573 |
} |
| 574 |
} |
| 575 |
for (size_t i=bufSize; i<65536; i++) { |
| 576 |
dataT[i]=0; |
| 577 |
} |
| 578 |
|
| 579 |
for (int i=0; i<e->getTotalChannelCount(); i++) { |
| 580 |
unsigned int pos=cs->getChanState(i)->readPos; |
| 581 |
if (pos<65536) { |
| 582 |
ImVec4 col=ImVec4(1.0f,1.0f,1.0f,1.0f); |
| 583 |
ImGui::ColorConvertHSVtoRGB((float)i/(float)e->getTotalChannelCount(),0.8f,1.0f,col.x,col.y,col.z); |
| 584 |
dataT[pos]=ImGui::GetColorU32(col); |
| 585 |
} |
| 586 |
} |
| 587 |
rend->unlockTexture(csTex); |
| 588 |
} |
| 589 |
|
| 590 |
ImGui::Image(rend->getTextureID(csTex),ImVec2(768.0*dpiScale,768.0*dpiScale)); |
| 591 |
} |
| 592 |
ImGui::EndTabItem(); |
| 593 |
} |
| 594 |
if (ImGui::BeginTabItem(_("Stream Info"))) { |
| 595 |
ImGui::Text("%d bytes",(int)cs->getDataLen()); |
| 596 |
ImGui::Text("%u channels",cs->getFileChans()); |
| 597 |
ImGui::Text("preset delays:"); |
| 598 |
for (int i=0; i<16; i++) { |
| 599 |
ImGui::SameLine(); |
| 600 |
ImGui::Text("%d",cs->getFastDelays()[i]); |
| 601 |
} |
| 602 |
ImGui::Text("speed dial commands:"); |
| 603 |
for (int i=0; i<16; i++) { |
| 604 |
ImGui::SameLine(); |
| 605 |
ImGui::Text("%d",cs->getFastCmds()[i]); |
| 606 |
} |
| 607 |
ImGui::Text("stack sizes:"); |
| 608 |
for (unsigned int i=0; i<cs->getFileChans(); i++) { |
| 609 |
ImGui::SameLine(); |
| 610 |
ImGui::Text("%d",cs->getChanState(i)->callStackSize); |
| 611 |
} |
| 612 |
ImGui::Text("ticks: %u",cs->getCurTick()); |
| 613 |
ImGui::EndTabItem(); |
| 614 |
} |
| 615 |
if (ImGui::BeginTabItem(_("Call Stack"))) { |
| 616 |
ImGui::PushFont(patFont); |
| 617 |
if (ImGui::BeginTable("CSCallStack",chans,ImGuiTableFlags_SizingFixedFit|ImGuiTableFlags_ScrollX)) { |
| 618 |
char tempID[32]; |
| 619 |
for (int i=0; i<chans; i++) { |
| 620 |
snprintf(tempID,31,"c%d",i); |
| 621 |
ImGui::TableSetupColumn(tempID,ImGuiTableColumnFlags_WidthFixed,oneChar.x*10.0f); |
| 622 |
} |
| 623 |
ImGui::TableNextRow(ImGuiTableRowFlags_Headers); |
| 624 |
for (int i=0; i<chans; i++) { |
| 625 |
DivCSChannelState* state=cs->getChanState(i); |
| 626 |
ImGui::TableNextColumn(); |
| 627 |
ImGui::Text("%d (>>%d)",i,state->callStackPos); |
| 628 |
} |
| 629 |
ImGui::TableNextRow(); |
| 630 |
for (int i=0; i<chans; i++) { |
| 631 |
DivCSChannelState* state=cs->getChanState(i); |
| 632 |
ImGui::TableNextColumn(); |
| 633 |
for (int j=0; j<state->callStackPos; j++) { |
| 634 |
ImGui::Text("$%.4x",state->callStack[j]); |
| 635 |
} |
| 636 |
ImGui::Text("$%.4x",state->readPos); |
| 637 |
} |
| 638 |
ImGui::EndTable(); |
| 639 |
} |
| 640 |
ImGui::PopFont(); |
| 641 |
ImGui::EndTabItem(); |
| 642 |
} |
| 643 |
ImGui::EndTabBar(); |
| 644 |
} |
| 645 |
} |
| 646 |
} |
| 647 |
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_CS_PLAYER; |
| 648 |
ImGui::End(); |
| 649 |
} |