Changeset View
Changeset View
Standalone View
Standalone View
stand/ficl/loader.c
Show All 40 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#else | #else | ||||
#include <stand.h> | #include <stand.h> | ||||
#endif | #endif | ||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
#include <string.h> | #include <string.h> | ||||
#include <uuid.h> | #include <uuid.h> | ||||
#include <gfx_fb.h> | |||||
#include <pnglite.h> | |||||
#include "ficl.h" | #include "ficl.h" | ||||
/* FreeBSD's loader interaction words and extras | /* FreeBSD's loader interaction words and extras | ||||
* | * | ||||
* setenv ( value n name n' -- ) | * setenv ( value n name n' -- ) | ||||
* setenv? ( value n name n' flag -- ) | * setenv? ( value n name n' flag -- ) | ||||
* getenv ( addr n -- addr' n' | -1 ) | * getenv ( addr n -- addr' n' | -1 ) | ||||
* unsetenv ( addr n -- ) | * unsetenv ( addr n -- ) | ||||
* copyin ( addr addr' len -- ) | * copyin ( addr addr' len -- ) | ||||
* copyout ( addr addr' len -- ) | * copyout ( addr addr' len -- ) | ||||
* findfile ( name len type len' -- addr ) | * findfile ( name len type len' -- addr ) | ||||
* pnpdevices ( -- addr ) | * pnpdevices ( -- addr ) | ||||
* pnphandlers ( -- addr ) | * pnphandlers ( -- addr ) | ||||
* ccall ( [[...[p10] p9] ... p1] n addr -- result ) | * ccall ( [[...[p10] p9] ... p1] n addr -- result ) | ||||
* uuid-from-string ( addr n -- addr' ) | * uuid-from-string ( addr n -- addr' ) | ||||
* uuid-to-string ( addr' -- addr n ) | * uuid-to-string ( addr' -- addr n ) | ||||
* .# ( value -- ) | * .# ( value -- ) | ||||
*/ | */ | ||||
#ifndef TESTMAIN | |||||
/* ( flags x1 y1 x2 y2 -- flag ) */ | |||||
void | void | ||||
ficl_term_putimage(FICL_VM *pVM) | |||||
{ | |||||
char *namep, *name; | |||||
int names; | |||||
unsigned long ret = FICL_FALSE; | |||||
uint32_t x1, y1, x2, y2, f; | |||||
png_t png; | |||||
int error; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 7, 1); | |||||
#endif | |||||
names = stackPopINT(pVM->pStack); | |||||
namep = (char *) stackPopPtr(pVM->pStack); | |||||
y2 = stackPopINT(pVM->pStack); | |||||
x2 = stackPopINT(pVM->pStack); | |||||
y1 = stackPopINT(pVM->pStack); | |||||
x1 = stackPopINT(pVM->pStack); | |||||
f = stackPopINT(pVM->pStack); | |||||
x1 = gfx_state.tg_origin.tp_col + x1 * gfx_state.tg_font.vf_width; | |||||
y1 = gfx_state.tg_origin.tp_row + y1 * gfx_state.tg_font.vf_height; | |||||
if (x2 != 0) { | |||||
x2 = gfx_state.tg_origin.tp_col + | |||||
x2 * gfx_state.tg_font.vf_width; | |||||
} | |||||
if (y2 != 0) { | |||||
y2 = gfx_state.tg_origin.tp_row + | |||||
y2 * gfx_state.tg_font.vf_height; | |||||
} | |||||
name = ficlMalloc(names + 1); | |||||
if (!name) | |||||
vmThrowErr(pVM, "Error: out of memory"); | |||||
(void) strncpy(name, namep, names); | |||||
name[names] = '\0'; | |||||
if ((error = png_open(&png, name)) != PNG_NO_ERROR) { | |||||
if (f & FL_PUTIMAGE_DEBUG) | |||||
printf("%s\n", png_error_string(error)); | |||||
} else { | |||||
if (gfx_fb_putimage(&png, x1, y1, x2, y2, f) == 0) | |||||
ret = FICL_TRUE; /* success */ | |||||
(void) png_close(&png); | |||||
} | |||||
ficlFree(name); | |||||
stackPushUNS(pVM->pStack, ret); | |||||
} | |||||
/* ( flags x1 y1 x2 y2 -- flag ) */ | |||||
void | |||||
ficl_fb_putimage(FICL_VM *pVM) | |||||
{ | |||||
char *namep, *name; | |||||
int names; | |||||
unsigned long ret = FICL_FALSE; | |||||
uint32_t x1, y1, x2, y2, f; | |||||
png_t png; | |||||
int error; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 7, 1); | |||||
#endif | |||||
names = stackPopINT(pVM->pStack); | |||||
namep = (char *) stackPopPtr(pVM->pStack); | |||||
y2 = stackPopINT(pVM->pStack); | |||||
x2 = stackPopINT(pVM->pStack); | |||||
y1 = stackPopINT(pVM->pStack); | |||||
x1 = stackPopINT(pVM->pStack); | |||||
f = stackPopINT(pVM->pStack); | |||||
name = ficlMalloc(names + 1); | |||||
if (!name) | |||||
vmThrowErr(pVM, "Error: out of memory"); | |||||
(void) strncpy(name, namep, names); | |||||
name[names] = '\0'; | |||||
if ((error = png_open(&png, name)) != PNG_NO_ERROR) { | |||||
if (f & FL_PUTIMAGE_DEBUG) | |||||
printf("%s\n", png_error_string(error)); | |||||
} else { | |||||
if (gfx_fb_putimage(&png, x1, y1, x2, y2, f) == 0) | |||||
ret = FICL_TRUE; /* success */ | |||||
(void) png_close(&png); | |||||
} | |||||
ficlFree(name); | |||||
stackPushUNS(pVM->pStack, ret); | |||||
} | |||||
void | |||||
ficl_fb_setpixel(FICL_VM *pVM) | |||||
{ | |||||
FICL_UNS x, y; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 2, 0); | |||||
#endif | |||||
y = stackPopUNS(pVM->pStack); | |||||
x = stackPopUNS(pVM->pStack); | |||||
gfx_fb_setpixel(x, y); | |||||
} | |||||
void | |||||
ficl_fb_line(FICL_VM *pVM) | |||||
{ | |||||
FICL_UNS x0, y0, x1, y1, wd; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 5, 0); | |||||
#endif | |||||
wd = stackPopUNS(pVM->pStack); | |||||
y1 = stackPopUNS(pVM->pStack); | |||||
x1 = stackPopUNS(pVM->pStack); | |||||
y0 = stackPopUNS(pVM->pStack); | |||||
x0 = stackPopUNS(pVM->pStack); | |||||
gfx_fb_line(x0, y0, x1, y1, wd); | |||||
} | |||||
void | |||||
ficl_fb_bezier(FICL_VM *pVM) | |||||
{ | |||||
FICL_UNS x0, y0, x1, y1, x2, y2, width; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 7, 0); | |||||
#endif | |||||
width = stackPopUNS(pVM->pStack); | |||||
y2 = stackPopUNS(pVM->pStack); | |||||
x2 = stackPopUNS(pVM->pStack); | |||||
y1 = stackPopUNS(pVM->pStack); | |||||
x1 = stackPopUNS(pVM->pStack); | |||||
y0 = stackPopUNS(pVM->pStack); | |||||
x0 = stackPopUNS(pVM->pStack); | |||||
gfx_fb_bezier(x0, y0, x1, y1, x2, y2, width); | |||||
} | |||||
void | |||||
ficl_fb_drawrect(FICL_VM *pVM) | |||||
{ | |||||
FICL_UNS x1, x2, y1, y2, fill; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 5, 0); | |||||
#endif | |||||
fill = stackPopUNS(pVM->pStack); | |||||
y2 = stackPopUNS(pVM->pStack); | |||||
x2 = stackPopUNS(pVM->pStack); | |||||
y1 = stackPopUNS(pVM->pStack); | |||||
x1 = stackPopUNS(pVM->pStack); | |||||
gfx_fb_drawrect(x1, y1, x2, y2, fill); | |||||
} | |||||
void | |||||
ficl_term_drawrect(FICL_VM *pVM) | |||||
{ | |||||
FICL_UNS x1, x2, y1, y2; | |||||
#if FICL_ROBUST > 1 | |||||
vmCheckStack(pVM, 4, 0); | |||||
#endif | |||||
y2 = stackPopUNS(pVM->pStack); | |||||
x2 = stackPopUNS(pVM->pStack); | |||||
y1 = stackPopUNS(pVM->pStack); | |||||
x1 = stackPopUNS(pVM->pStack); | |||||
gfx_term_drawrect(x1, y1, x2, y2); | |||||
} | |||||
#endif /* TESTMAIN */ | |||||
void | |||||
ficlSetenv(FICL_VM *pVM) | ficlSetenv(FICL_VM *pVM) | ||||
{ | { | ||||
#ifndef TESTMAIN | #ifndef TESTMAIN | ||||
char *name, *value; | char *name, *value; | ||||
#endif | #endif | ||||
char *namep, *valuep; | char *namep, *valuep; | ||||
int names, values; | int names, values; | ||||
▲ Show 20 Lines • Show All 785 Lines • ▼ Show 20 Lines | void ficlCompilePlatform(FICL_SYSTEM *pSys) | ||||
dictAppendWord(dp, "unsetenv", ficlUnsetenv, FW_DEFAULT); | dictAppendWord(dp, "unsetenv", ficlUnsetenv, FW_DEFAULT); | ||||
dictAppendWord(dp, "copyin", ficlCopyin, FW_DEFAULT); | dictAppendWord(dp, "copyin", ficlCopyin, FW_DEFAULT); | ||||
dictAppendWord(dp, "copyout", ficlCopyout, FW_DEFAULT); | dictAppendWord(dp, "copyout", ficlCopyout, FW_DEFAULT); | ||||
dictAppendWord(dp, "findfile", ficlFindfile, FW_DEFAULT); | dictAppendWord(dp, "findfile", ficlFindfile, FW_DEFAULT); | ||||
dictAppendWord(dp, "ccall", ficlCcall, FW_DEFAULT); | dictAppendWord(dp, "ccall", ficlCcall, FW_DEFAULT); | ||||
dictAppendWord(dp, "uuid-from-string", ficlUuidFromString, FW_DEFAULT); | dictAppendWord(dp, "uuid-from-string", ficlUuidFromString, FW_DEFAULT); | ||||
dictAppendWord(dp, "uuid-to-string", ficlUuidToString, FW_DEFAULT); | dictAppendWord(dp, "uuid-to-string", ficlUuidToString, FW_DEFAULT); | ||||
#ifndef TESTMAIN | #ifndef TESTMAIN | ||||
dictAppendWord(dp, "fb-setpixel", ficl_fb_setpixel, FW_DEFAULT); | |||||
dictAppendWord(dp, "fb-line", ficl_fb_line, FW_DEFAULT); | |||||
dictAppendWord(dp, "fb-bezier", ficl_fb_bezier, FW_DEFAULT); | |||||
dictAppendWord(dp, "fb-drawrect", ficl_fb_drawrect, FW_DEFAULT); | |||||
dictAppendWord(dp, "fb-putimage", ficl_fb_putimage, FW_DEFAULT); | |||||
dictAppendWord(dp, "term-drawrect", ficl_term_drawrect, FW_DEFAULT); | |||||
dictAppendWord(dp, "term-putimage", ficl_term_putimage, FW_DEFAULT); | |||||
dictAppendWord(dp, "isvirtualized?",ficlIsvirtualizedQ, FW_DEFAULT); | dictAppendWord(dp, "isvirtualized?",ficlIsvirtualizedQ, FW_DEFAULT); | ||||
#endif | #endif | ||||
SET_FOREACH(fnpp, Xficl_compile_set) | SET_FOREACH(fnpp, Xficl_compile_set) | ||||
(*fnpp)(pSys); | (*fnpp)(pSys); | ||||
#if defined(__i386__) | #if defined(__i386__) | ||||
ficlSetEnv(pSys, "arch-i386", FICL_TRUE); | ficlSetEnv(pSys, "arch-i386", FICL_TRUE); | ||||
ficlSetEnv(pSys, "arch-powerpc", FICL_FALSE); | ficlSetEnv(pSys, "arch-powerpc", FICL_FALSE); | ||||
#elif defined(__powerpc__) | #elif defined(__powerpc__) | ||||
ficlSetEnv(pSys, "arch-i386", FICL_FALSE); | ficlSetEnv(pSys, "arch-i386", FICL_FALSE); | ||||
ficlSetEnv(pSys, "arch-powerpc", FICL_TRUE); | ficlSetEnv(pSys, "arch-powerpc", FICL_TRUE); | ||||
#endif | #endif | ||||
return; | return; | ||||
} | } |