/*
 * videomode_raw.c — low-level ESTEX SETVMOD / GETVMOD ($50 / $51).
 *
 * Plain getters/setters with NO mode-class validation.  Used by both
 * conio (text-validated public API) and gfx (graphics modes).  Lives
 * in its own .c so a pure graphics program does not pull in the entire
 * conio module to switch modes.
 *
 * Public conio functions in conio.c wrap these with a text-mode check;
 * gfx_init / gfx_done in gfx_core.c call them directly.
 */

#include <stdint.h>
#include <errno.h>

uint8_t _videomode_raw_get(void) __naked
{
    __asm
        push  ix
        ld    c, #0x51              ; ESTEX GETVMOD
        rst   #0x10
        pop   ix
        ;; uint8_t returns in A — ESTEX already put mode there.
        ret
    __endasm;
}

int _videomode_raw_set(uint8_t mode) __naked
{
    (void)mode;
    __asm
        ;; SDCC __sdcccall(1) passes uint8_t in A — leave it there.
        push  ix
        ld    bc, #0x0050           ; ESTEX SETVMOD (B=0 (page), C=0x50)
        rst   #0x10
        jr    c, _vmr_err
        ld    de, #0
        pop   ix
        ret
    _vmr_err:
        call  __errno_set
        ld    de, #-1
        pop   ix
        ret
    __endasm;
}
