This commit is contained in:
olikraus 2017-07-18 20:20:59 +02:00
parent 3f8715327c
commit 8c636d4abd
3 changed files with 143 additions and 1 deletions

View File

@ -1,4 +1,4 @@
CFLAGS = -g -Wall -Wpointer-arith -I. -I../../../csrc/. -I../../tga/mapgen/. -I../../../tools/ugl/ `sdl-config --cflags`
CFLAGS = -g -Wall -Wpointer-arith -I. -I../../../csrc/. -I../../tga/mapgen/. `sdl-config --cflags`
GMSRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c )
GMSRC += map.c main.c item.c

57
sys/sdl/gm2/ugl.h Normal file
View File

@ -0,0 +1,57 @@
/*
proc <name>
*/
#ifndef _UGL_H
#define _UGL_H
#include <stdint.h>
#include <stdarg.h>
#include <stdio.h>
#define UGL_MAX_IDENTIFIER_LEN 63
/* ugl_error.c */
extern int ugl_current_input_line;
extern int ugl_is_suppress_log;
void ugl_err(const char *fmt, ...) __attribute__ ((noreturn));
void ugl_plog(const char *fmt, ...);
void ugl_glog(const char *fmt, ...);
/* ugl_arrays.c */
extern uint16_t ugl_bytecode_len;
void ugl_InitBytecode(void);
void ugl_AddBytecode(uint8_t x);
void ugl_ExecBytecode(void);
void ugl_ResolveSymbols(void);
void ugl_WriteBytecodeCArray(FILE *fp, const char *name);
int ugl_GetLabel(const char *name);
void ugl_SetLabelBytecodePos(const char *name, uint16_t bytecode_pos);
uint16_t ugl_GetLabelBytecodePos(int idx);
/* ugl_parse.c */
uint16_t uglStartNamelessProc(int args);
int ugl_read_line(const char **s);
int uglReadLine(const char **s);
/* ugl_main.c */
int ugl_read_fp(void);
int ugl_read_filename(const char *name);
#endif

85
sys/sdl/gm2/ugl_bc.h Normal file
View File

@ -0,0 +1,85 @@
/*
ugl_bc.h
bytecode interpreter
*/
#ifndef _UGL_BC_H
#define _UGL_BC_H
#include <stdint.h>
#define BC_STACK_SIZE 64
#define BC_RETURN_STACK_SIZE 6
struct bc_struct
{
uint8_t *code;
uint16_t code_pos;
uint8_t arg_stack_pointer; /* starts at 0 and grows */
uint8_t return_stack_pointer; /* starts at 0 and grows */
uint16_t arg_stack[BC_STACK_SIZE]; /* parameter and return value stack */
uint16_t return_stack[BC_RETURN_STACK_SIZE]; /* return from procedure stack */
};
typedef struct bc_struct bc_t;
typedef void (*bc_buildin_fn)(bc_t *bc);
extern bc_buildin_fn bc_buildin_list[];
/* lower 4 bit: 0, upper 4 bit + next byte --> 12 bit value */
#define BC_CMD_LOAD_12BIT (0x00)
/* lower 4 bit: 1, upper 4 bit + next byte --> 12 bit value */
#define BC_CMD_CALL_BUILDIN (0x01)
/* lower 4 bit: 2, upper 4 bit + next byte --> 12 bit value (toplevel call, return value will be removed) */
#define BC_CMD_CALL_BUILDIN_POP_STACK (0x02)
/* lower 4 bit: 3, upper 4 bit + next byte --> 12 bit relative adr */
#define BC_CMD_BRANCH (0x03)
/* lower 4 bit: 4, upper 4 bit: 0..15, pop 1..16 bytes from the arg stack */
/* only used to remove one byte, so could be moved to different section */
#define BC_CMD_POP_ARG_STACK (0x04)
/* lower 4 bit: 5, upper 4 bit: 0..15, push 1..16 bytes on the arg stack */
/* not used any more */
#define BC_CMD_PUSH_ARG_STACK (0x05)
/* lower 4 bit: 5, upper 4 bit: 0..15, push 1..16 arguments, then two bytes for destination adr*/
#define BC_CMD_CALL_PROCEDURE (0x06)
/* lower 4 bit: 15, upper 4 bit: 0 --> put 0 on stack */
#define BC_CMD_LOAD_0 (0x0f)
/* lower 4 bit: 15, upper 4 bit: 1 --> put 1 on stack */
#define BC_CMD_LOAD_1 (0x1f)
/* lower 4 bit: 15, upper 4 bit: 2 --> but 16 bit value on stack, order: high byte, low byte */
#define BC_CMD_LOAD_16BIT (0x2f)
/* lower 4 bit: 15, upper 4 bit: 3 */
#define BC_CMD_RETURN_FROM_PROCEDURE (0x3f)
/* lower 4 bit: 15, upper 4 bit: 4 --> adr are next 16 bit*/
#define BC_CMD_JUMP_NOT_ZERO (0x4f)
/* lower 4 bit: 15, upper 4 bit: 5 --> adr are next 16 bit*/
#define BC_CMD_JUMP_ZERO (0x05f)
/* lower 4 bit: 15, upper 4 bit: 6 --> adr are next 16 bit */
//#define BC_CMD_CALL_PROCEDURE (0x06f)
/* lower 4 bit: 15, upper 4 bit: 7 --> adr are next 16 bit, third byte are the number of arguments */
//#define BC_CMD_POP_ARG_STACK (0x07f)
void bc_exec(bc_t *bc, uint8_t *code, uint16_t pos);
/*======================================================*/
#endif