/*
    * main.cpp
    * uptime - Show system uptime
    * Copyright (c) 2025-2026 Daniel Hammer
*/

#include <montauk/syscall.h>

static void print_int(uint64_t n) {
    if (n == 0) {
        montauk::putchar('0');
        return;
    }
    char buf[20];
    int i = 0;
    while (n > 0) {
        buf[i++] = '0' + (n % 10);
        n /= 10;
    }
    for (int j = i - 1; j >= 0; j--) {
        montauk::putchar(buf[j]);
    }
}

extern "C" void _start() {
    uint64_t ms = montauk::get_milliseconds();
    uint64_t secs = ms / 1000;
    uint64_t mins = secs / 60;
    secs %= 60;
    ms %= 1000;

    montauk::print("Uptime: ");
    print_int(mins);
    montauk::print("m ");
    print_int(secs);
    montauk::print("s ");
    print_int(ms);
    montauk::print("ms\n");
    montauk::exit(0);
}
