[hatari-devel] Native feature proposal |
[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]
Hi, here's a proposal for two very handy NF calls I've patched into my Hatari branch for a while now: NF_STDERR_NUM: output a number without the need to convert it to a string on the ST. I often output internal state variables of a running programm using NF_STDERR (e.g. taken frames per render, clock-cycles of specific parts, control variables etc.). This way printing these taking almost no cpu time and the developed programs run-time behaviour isn't changed too much. NF_FRAMEPOSITION: copies frame info (nVBLs, nHBL, nScanlinesPerFrame, nCyclesPerLine and CyclesPerVBL) into a memory area given by the guest program. This makes it very easy to time code parts cycle-exact at runtime and do a quick check on optimizations as well as the average time a code part takes between frames. Also it's easier to check where exactly a code runs (relative to the frame start). Any objections? |
>From d541bb8fe9fae20c6ce3e25a5cca4b3c1ed0eb70 Mon Sep 17 00:00:00 2001 From: tin <tin> Date: Mon, 30 Apr 2018 18:37:01 +0200 Subject: [PATCH] -added new natfeats: NF_FRAMEPOSITION (guest can check current video position values), NF_STDERR_NUM (guest can output a numerical value directly instead of having to convert to a string) --- src/debug/natfeats.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/debug/natfeats.c b/src/debug/natfeats.c index c130f1a..e891a27 100644 --- a/src/debug/natfeats.c +++ b/src/debug/natfeats.c @@ -23,8 +23,14 @@ const char Natfeats_fileid[] = "Hatari natfeats.c : " __DATE__ " " __TIME__; #include "debugui.h" #include "nf_scsidrv.h" #include "log.h" - - +#include "cycles.h" + +extern int nVBLs; /* VBL Counter */ +extern int nHBL; /* HBL line */ +extern int nScanlinesPerFrame; /* Number of scan lines per frame */ +extern int nCyclesPerLine; /* Cycles per horizontal line scan */ +static int CyclesPerVBL; /* Number of cycles per VBL */ + /* whether to allow XBIOS(255) style * Hatari command line parsing with "command" NF */ @@ -163,6 +169,57 @@ static bool nf_fastforward(Uint32 stack, Uint32 subid, Uint32 *retval) return true; } +/** + * NF_FRAMEPOSITION - allow emulated programm to query exact beam position (scanline+position in scanline) and frame no. since emulation start + * Stack arguments are: + * - pointer to buffer for + * framenumber.l, + * scanline.l, + * current cycle in frame.l + * cycles per frame.l, + * cycles per line.l, + * scanlines per frame.l + */ +static bool nf_frameinfo(Uint32 stack, Uint32 subid, Uint32 *retval) +{ + Uint32 ptr; + + ptr = STMemory_ReadLong(stack); + + if ( !STMemory_CheckAreaType ( ptr, 6*4, ABFLAG_RAM | ABFLAG_ROM ) ) { + M68000_BusError(ptr, BUS_ERROR_READ, BUS_ERROR_SIZE_BYTE, BUS_ERROR_ACCESS_DATA); + return false; + } + LOG_TRACE(TRACE_NATFEATS, "NF_FRAMEPOSITION(0x%x)\n", ptr); + + int FrameCycles = Cycles_GetCounter(CYCLES_COUNTER_VIDEO); + STMemory_WriteLong(ptr+SIZE_LONG*0, nVBLs); + STMemory_WriteLong(ptr+SIZE_LONG*1, nHBL); + STMemory_WriteLong(ptr+SIZE_LONG*2, FrameCycles); + STMemory_WriteLong(ptr+SIZE_LONG*3, CyclesPerVBL); + STMemory_WriteLong(ptr+SIZE_LONG*4, nCyclesPerLine); + STMemory_WriteLong(ptr+SIZE_LONG*5, nScanlinesPerFrame); + + return true; +} + +/** + * NF_STDERR_NUM - print numeric value to stderr + * Stack arguments are: + * - pointer to buffer containing the value (long) + */ +static bool nf_stderr_num(Uint32 stack, Uint32 subid, Uint32 *retval) +{ + Uint32 value; + + value = STMemory_ReadLong(stack); + LOG_TRACE(TRACE_NATFEATS, "NF_STDERR_NUM(0x%x)\n", value); + + *retval = fprintf(stderr, "%d ", value); + fflush(stderr); + return true; +} + #if NF_COMMAND /** * NF_COMMAND - execute Hatari (cli / debugger) command @@ -206,7 +263,9 @@ static const struct { { "NF_SHUTDOWN", true, nf_shutdown }, { "NF_EXIT", false, nf_exit }, { "NF_DEBUGGER", false, nf_debugger }, - { "NF_FASTFORWARD", false, nf_fastforward } + { "NF_FASTFORWARD", false, nf_fastforward }, + { "NF_FRAMEINFO", false, nf_frameinfo }, + { "NF_STDERR_NUM", false, nf_stderr_num }, #if defined(__linux__) ,{ "NF_SCSIDRV", true, nf_scsidrv } #endif -- 2.10.1
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |