71 lines
2.1 KiB
C
71 lines
2.1 KiB
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include <ntlite/syscall.h>
|
|
|
|
static int u64_to_string(uint64_t n, char* buf) {
|
|
int i = 0;
|
|
if (n == 0) {
|
|
buf[i++] = '0';
|
|
buf[i] = '\0';
|
|
return i;
|
|
}
|
|
char rev[24];
|
|
int r_idx = 0;
|
|
while (n > 0) {
|
|
rev[r_idx++] = (char)('0' + (n % 10));
|
|
n /= 10;
|
|
}
|
|
while (r_idx > 0) {
|
|
buf[i++] = rev[--r_idx];
|
|
}
|
|
buf[i] = '\0';
|
|
return i;
|
|
}
|
|
|
|
int main(void) {
|
|
SYS_CONSOLE_INFO console;
|
|
SYS_MEMORY_STATUS mem;
|
|
char metricsBuf[128];
|
|
|
|
while (true) {
|
|
if (SysGetConsoleInfo(&console) == SYS_STATUS_SUCCESS &&
|
|
SysGetMemoryStatus(&mem) == SYS_STATUS_SUCCESS) {
|
|
|
|
// If the system isn't reporting columns correctly, default to a safe standard width
|
|
int columns = (console.Columns > 0) ? (int)console.Columns : 80;
|
|
|
|
char freeStr[24], poolStr[24], heapStr[24];
|
|
u64_to_string(mem.FreePhysicalBytes / 1024u, freeStr);
|
|
u64_to_string(mem.KernelPoolBytes / 1024u, poolStr);
|
|
u64_to_string(mem.UserHeapBytes / 1024u, heapStr);
|
|
|
|
metricsBuf[0] = '\0';
|
|
strcat(metricsBuf, "[ Free: ");
|
|
strcat(metricsBuf, freeStr);
|
|
strcat(metricsBuf, "K | Pool: ");
|
|
strcat(metricsBuf, poolStr);
|
|
strcat(metricsBuf, "K | Heap: ");
|
|
strcat(metricsBuf, heapStr);
|
|
strcat(metricsBuf, "K ]");
|
|
|
|
size_t textLen = strlen(metricsBuf);
|
|
int targetX = columns - (int)textLen;
|
|
int targetY = 0;
|
|
|
|
if (targetX >= 0) {
|
|
size_t written = 0;
|
|
|
|
// Loop through the string and use the console's dedicated text filling API
|
|
// This utilizes the console's native font configuration instead of drawing raw screen bits
|
|
for (size_t i = 0; i < textLen; i++) {
|
|
SysFillConsoleCharacter(metricsBuf[i], targetX + (int)i, targetY, 1, &written);
|
|
}
|
|
}
|
|
}
|
|
|
|
SysSleep(500);
|
|
}
|
|
return 0;
|
|
} |