Create a basic hello world

And it has begun. It has some problems, but worse, it seems I broke
qfprogs and maybe pr_debug.c.
This commit is contained in:
Bill Currie 2020-02-27 01:18:38 +09:00
parent 126f8502bd
commit edde4bad15
4 changed files with 204 additions and 11 deletions

View file

@ -1,15 +1,25 @@
AUTOMAKE_OPTIONS= foreign
QWAQ_LIBS=@QWAQ_LIBS@
QWAQ_DEPS=@QWAQ_DEPS@
QWAQ_INCS=@QWAQ_INCS@
AM_CPPFLAGS= -I$(top_srcdir)/include $(QWAQ_INCS) $(PTHREAD_CFLAGS)
noinst_PROGRAMS=@QWAQ_TARGETS@ qwaq-app.dat$(EXEEXT)
QFCC_DEP=$(top_builddir)/tools/qfcc/source/qfcc$(EXEEXT)
QFCC=$(top_builddir)/tools/qfcc/source/qfcc
QCFLAGS=-qq -O -g -Werror --advanced --no-default-paths
noinst_PROGRAMS=@QWAQ_TARGETS@
noinst_DATA= #qwaq.dat
QCFLAGS=-qq -O -g -Werror
QCPPFLAGS=--no-default-paths -I$(top_srcdir)/ruamoko/include
QCOMPILE=$(QFCC) $(QCFLAGS) $(QCPPFLAGS)
SUFFIXES=.o .r
.r.o:
$(QCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tqo -c -o $@ $<
sed -i -e '1s@:@: $(QFCC_DEP)@' $(DEPDIR)/$*.Tqo
$(am__mv) $(DEPDIR)/$*.Tqo $(DEPDIR)/$*.Qo
qwaq_dat_src= \
$e
@ -45,8 +55,21 @@ qwaq_x11_LDADD= $(qwaq_x11_libs) $(QWAQ_LIBS) \
qwaq_x11_LDFLAGS=
qwaq_x11_DEPENDENCIES= $(qwaq_x11_libs) $(QWAQ_DEPS)
#qwaq.dat: $(qwaq_dat_src) $(QFCC_DEP) $(top_srcdir)/ruamoko/lib/Object.r
# $(QFCC) $(QCFLAGS) -I$(top_srcdir)/ruamoko/include
r_depfiles_remade=
qwaq_app_dat_SOURCES=qwaq-app.r
qwaq_app_obj=$(qwaq_app_dat_SOURCES:.r=.o)
qwaq_app_dep=$(addprefix ./$(DEPDIR)/,$(qwaq_app_obj:.o=.Qo))
qwaq-app.dat$(EXEEXT): $(qwaq_app_obj) $(QFCC_DEP)
$(QFCC) $(QCFLAGS) -o $@ $(qwaq_app_obj)
include $(qwaq_app_dep) # am--include-marker
r_depfiles_remade += $(qwaq_app_dep)
$(r_depfiles_remade):
@$(MKDIR_P) $(@D)
@echo '# dummy' >$@-t && $(am__mv) $@-t $@
am--depfiles: $(am__depfiles_remade) $(r_depfiles_remade)
EXTRA_PROGRAMS=qwaq-curses qwaq-x11
EXTRA_DIST=$(qwaq_dat_src) qwaq.h

View file

@ -152,7 +152,7 @@ main (int argc, const char **argv)
{
dfunction_t *dfunc;
func_t main_func = 0;
const char *name = "qwaq.dat";
const char *name = "qwaq-app.dat";
string_t *pr_argv;
int pr_argc = 1, i;
@ -162,8 +162,9 @@ main (int argc, const char **argv)
if (argc > 1)
name = argv[1];
if (!load_progs (name))
if (!load_progs (name)) {
Sys_Error ("couldn't load %s", name);
}
PR_PushFrame (&pr);
if (argc > 2)
@ -185,5 +186,6 @@ main (int argc, const char **argv)
pr.pr_argc = 2;
PR_ExecuteProgram (&pr, main_func);
PR_PopFrame (&pr);
Sys_Shutdown ();
return R_INT (&pr);
}

23
tools/qwaq/qwaq-app.r Normal file
View file

@ -0,0 +1,23 @@
typedef struct window_s *window_t;
void initialize (void) = #0;
window_t create_window (int xpos, int ypos, int xlen, int ylen) = #0;
void destroy_window (window_t win) = #0;
void wprintf (window_t win, string fmt, ...) = #0;
int wgetch (window_t win) = #0;
int main (int argc, string *argv)
{
int ch;
initialize ();
window_t win = create_window (20, 5, 50, 10);
wprintf (win, "Hi there!\n");
do {
ch = wgetch (win);
if (ch) {
wprintf (win, "%d\n", ch);
}
} while (ch != 27);
return 0;
}

View file

@ -31,24 +31,169 @@
# include "config.h"
#endif
#include <curses.h>
#include <stdlib.h>
#include <string.h>
#include "QF/dstring.h"
#include "QF/progs.h"
#include "QF/sys.h"
#include "qwaq.h"
static builtin_t builtins[] = {
{0}
};
#define always_inline inline __attribute__((__always_inline__))
typedef struct window_s {
WINDOW *win;
} window_t;
typedef struct qwaq_resources_s {
progs_t *pr;
int initialized;
dstring_t *print_buffer;
PR_RESMAP (window_t) window_map;
} qwaq_resources_t;
static window_t *
window_new (qwaq_resources_t *res)
{
PR_RESNEW (window_t, res->window_map);
}
static void
window_free (qwaq_resources_t *res, window_t *win)
{
PR_RESFREE (window_t, res->window_map, win);
}
static void
window_reset (qwaq_resources_t *res)
{
PR_RESRESET (window_t, res->window_map);
}
static inline window_t *
window_get (qwaq_resources_t *res, unsigned index)
{
PR_RESGET(res->window_map, index);
}
static inline int
window_index (qwaq_resources_t *res, window_t *win)
{
PR_RESINDEX (res->window_map, win);
}
static always_inline window_t *
get_window (qwaq_resources_t *res, const char *name, int handle)
{
window_t *window = window_get (res, handle);
if (!window || !window->win) {
PR_RunError (res->pr, "invalid window passed to %s", name + 3);
}
return window;
}
static int need_endwin;
static void
bi_shutdown (void)
{
if (need_endwin) {
endwin ();
}
}
static void
bi_initialize (progs_t *pr)
{
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
initscr ();
need_endwin = 1;
res->initialized = 1;
raw ();
keypad (stdscr, TRUE);
noecho ();
nonl ();
}
static void
bi_create_window (progs_t *pr)
{
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
int xpos = P_INT (pr, 0);
int ypos = P_INT (pr, 1);
int xlen = P_INT (pr, 2);
int ylen = P_INT (pr, 3);
window_t *window = window_new (res);
window->win = newwin (ylen, xlen, ypos, xpos);
keypad (window->win, TRUE);
R_INT (pr) = window_index (res, window);
}
static void
bi_destroy_window (progs_t *pr)
{
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
window_t *window = get_window (res, __FUNCTION__, P_INT (pr, 0));
delwin (window->win);
window->win = 0;
window_free (res, window);
}
static void
bi_wprintf (progs_t *pr)
{
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
window_t *window = get_window (res, __FUNCTION__, P_INT (pr, 0));
const char *fmt = P_GSTRING (pr, 1);
int count = pr->pr_argc - 2;
pr_type_t **args = pr->pr_params + 2;
PR_Sprintf (pr, res->print_buffer, "bi_wprintf", fmt, count, args);
waddstr (window->win, res->print_buffer->str);
wrefresh (window->win);
}
static void
bi_wgetch (progs_t *pr)
{
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
window_t *window = get_window (res, __FUNCTION__, P_INT (pr, 0));
R_INT (pr) = wgetch (window->win);
}
static void
bi_qwaq_clear (progs_t *pr, void *data)
{
__auto_type res = (qwaq_resources_t *) data;
if (res->initialized) {
endwin ();
}
need_endwin = 0;
window_reset (res);
}
static builtin_t builtins[] = {
{"initialize", bi_initialize, -1},
{"create_window", bi_create_window, -1},
{"destroy_window", bi_destroy_window, -1},
{"wprintf", bi_wprintf, -1},
{"wgetch", bi_wgetch, -1},
{0}
};
void
BI_Init (progs_t *pr)
{
PR_RegisterBuiltins (pr, builtins);
qwaq_resources_t *res = calloc (sizeof (*res), 1);
res->pr = pr;
res->print_buffer = dstring_newstr ();
PR_Resources_Register (pr, "qwaq", res, bi_qwaq_clear);
PR_RegisterBuiltins (pr, builtins);
Sys_RegisterShutdown (bi_shutdown);
}