various fixes; new interpreter library

master
Clyne Sullivan 7 years ago
parent c27af361fe
commit 8275c9cac1

@ -10,7 +10,6 @@
/**
* Sets HCLK (system clock) to 80MHz, the maximum.
* @param none
*/
extern void clock_init(void);

@ -1,18 +1,55 @@
/*
* @file display.h
* Display library for ILI9481 display.
*/
#ifndef DISPLAY_H_
#define DISPLAY_H_
#include <stdint.h>
/**
* The screen's width, in pixels.
*/
#define LCD_WIDTH 480
#define LCD_HEIGHT 320
#define COLOR_MAX 31
/**
* The screen's height, in pixels.
*/
#define LCD_HEIGHT 320
/**
* Returns the color integer for the given RGB values.
* Converts 8RGB to 5-6-5.
* @param r red value, 0-255
* @param g green value, 0-255
* @param b blue value, 0-255
* @return the 5-6-5 color value
*/
uint16_t dsp_color(uint8_t r, uint8_t g, uint8_t b);
/**
* Sets the direction of IO, for reading or writing to the screen.
* @param mode INPUT or OUPUT (defined in gpio.h)
*/
void dsp_dmode(int mode);
/**
* Writes the command byte to the display.
* @param data the command to write
*/
void dsp_write_cmd(uint8_t data);
/**
* Writes the data byte to the display.
* @param data the data to write
*/
void dsp_write_data(uint8_t data);
/**
* Reads a byte of data from the display.
* @return the data byte
*/
uint8_t dsp_read_data(void);
void dsp_set_addr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);

@ -1,16 +1,65 @@
/**
* @file display_draw.h
* Provides functions for drawing to the display
*/
#ifndef DISPLAY_DRAW_H_
#define DISPLAY_DRAW_H_
#include <stdint.h>
/**
* Starts the task for a blinking text cursor.
*/
void dsp_cursoron(void);
/**
* Sets the chosen pixel to the given color.
* @param x x-coord of the pixel
* @param y y-coord of the pixel
* @param color the color to use (5-6-5)
*/
void dsp_pixel(int x, int y, uint16_t color);
/**
* Draws a line between the two coordinates.
* @param x start x-coord
* @param y start y-coord
* @param i end x-coord
* @param j end y-coord
* @param color the color to use (5-6-5)
*/
void dsp_line(int x, int y, int i, int j, uint16_t color);
/**
* Draws a rectangle with the given dimensions.
* @param x top left x-coord
* @param y top left y-coord
* @param w width of the rectangle
* @param h height of the rectangle
* @param color the color to use (5-6-5)
*/
void dsp_rect(int x, int y, int w, int h, uint16_t color);
/**
* Sets the text cursor's position, in characters NOT pixels.
* @param x text column to move to
* @param y text row to move to
*/
void dsp_cpos(int x, int y);
/**
* Sets the pixel offset of the text cursor.
* @param x x-pixel offset from (0, 0)
* @param y y-pixel offset from (0, 0)
*/
void dsp_coff(int x, int y);
/**
* Puts a string to the screen. Text position if kept track of internally, so
* multiple calls will print the strings in one line.
* @param s the string to print
*/
void dsp_puts(const char *s);
#endif // DISPLAY_DRAW_H_

@ -1 +1 @@
../../interpreter
../../interpreter3

@ -12,6 +12,6 @@
* Loads the library for the given interpreter.
* @param it the interpreter to use
*/
void script_loadlib(interpreter *it);
void script_loadlib(instance *it);
#endif // SCRIPT_H_

@ -1,69 +1,67 @@
# graph area
set plotx 50
set ploty 50
set plotw 380
set ploth 220
set cx (plotx + (plotw / 2))
set cy (ploty + (ploth / 2))
plotx = 50
ploty = 50
plotw = 380
ploth = 220
cx = plotx + plotw / 2
cy = ploty + ploth / 2
# graph range
set xmin (0 - 10)
set xmax 10
set ymin (0 - 10)
set ymax 10
xmin = 0 - 10
xmax = 10
ymin = 0 - 10
ymax = 10
set xinc (plotw / (xmax - xmin))
set yinc (ploth / (ymax - ymin))
xinc = plotw / (xmax - xmin)
yinc = ploth / (ymax - ymin)
color 3 3 3 > mlines
mlines = color(3, 3, 3)
# print axis
func(makegrid) {
rect(plotx, ploty, plotw, ploth, 0)
func makegrid
rect plotx ploty plotw ploth 0
x = plotx
while (x <= plotx + plotw) {
line(x, ploty, x, ploty + ploth, mlines)
x = x + xinc
}
set x plotx
do
line x ploty x (ploty + ploth) mlines
set x (x + xinc)
while (x <= plotx + plotw)
y = ploty
while (y <= ploty + ploth) {
line(plotx, y, plotx + plotw, y, mlines)
y = y + yinc
}
set y ploty
do
line plotx y (plotx + plotw) y mlines
set y (y + yinc)
while (y <= ploty + ploth)
line cx ploty cx (ploty + ploth) 32767
line plotx cy (plotx + plotw) cy 32767
end
line(cx, ploty, cx, ploty + ploth, 32767)
line(plotx, cy, plotx + plotw, cy, 32767)
}
#
# BIG LOOP - ask for equ, graph it
#
makegrid
set clearcmd "clear"
do
rect 0 0 480 40
print "f(x) = "
gets > Fx
makegrid()
clearcmd = "clear"
while (1) {
rect(0, 0, 480, 40, 0)
print("f(x) = ")
Fx = gets()
if (Fx == clearcmd)
makegrid
else
if (Fx == clearcmd) {
makegrid()
} else {
# do function
set x xmin
do
solve Fx > y
set y (0 - y)
if ((y >= ymin) & (y <= ymax))
pixel (cx + x * xinc) (cy + y * yinc) 511
end
set x (x + 1 / xinc)
while (x < xmax)
end
x = xmin
while (x < xmax) {
y = solve(Fx)
y = 0 - y
if ((y >= ymin) & (y <= ymax)) {
pixel(cx + x * xinc, cy + y * yinc, 511)
}
x = x + 1 / xinc
}
}
ppos(0, 0)
}
ppos 0 0
while (1)

Binary file not shown.

@ -76,6 +76,8 @@ void free(void *buf)
return;
alloc_t *alloc = (alloc_t *)((uint8_t *)buf - sizeof(alloc_t));
if (alloc->next != 0)
return;
heap_used -= alloc->size;
alloc->next = free_blocks;
free_blocks = alloc;

@ -82,9 +82,8 @@ void kmain(void)
void task_interpreter(void)
{
interpreter it;
iinit(&it);
script_loadlib(&it);
instance *it = inewinstance();
script_loadlib(it);
char *s = initrd_getfile("init");
if (s == 0) {
@ -105,7 +104,7 @@ void task_interpreter(void)
}
strncpy(linebuf, s + prev, lc + 1);
linebuf[lc] = '\0';
ret = idoline(&it, linebuf);
ret = idoline(it, linebuf);
if (ret < 0)
break;
prev = ++i;

@ -7,23 +7,25 @@
#include <heap.h>
#include <random.h>
#include <serial.h>
#include <stack.h>
#include <stdlib.h>
#include <keypad.h>
#include <string.h>
int script_puts(interpreter *it);
int script_gets(interpreter *it);
int script_delay(interpreter *it);
int script_rect(interpreter *it);
int script_ppos(interpreter *it);
int script_line(interpreter *it);
int script_color(interpreter *it);
int script_rand(interpreter *it);
int script_getkey(interpreter *it);
int script_pixel(interpreter *it);
void script_loadlib(interpreter *it)
#define igetarg_integer(it, n) ((int)igetarg(it, n)->value.f)
int script_puts(instance *it);
int script_gets(instance *it);
int script_delay(instance *it);
int script_rect(instance *it);
int script_ppos(instance *it);
int script_line(instance *it);
int script_color(instance *it);
int script_rand(instance *it);
int script_getkey(instance *it);
int script_pixel(instance *it);
void script_loadlib(instance *it)
{
inew_cfunc(it, "print", script_puts);
inew_cfunc(it, "gets", script_gets);
@ -37,14 +39,20 @@ void script_loadlib(interpreter *it)
inew_cfunc(it, "pixel", script_pixel);
}
int script_puts(interpreter *it)
int script_puts(instance *it)
{
const char *s = igetarg_string(it, 0);
dsp_puts(s);
variable *v = igetarg(it, 0);
if (v->type == NUMBER) {
char buf[33];
snprintf(buf, 33, "%f", v->value.f);
dsp_puts(buf);
} else if (v->type == STRING) {
dsp_puts((const char *)v->value.p);
}
return 0;
}
int script_gets(interpreter *it)
int script_gets(instance *it)
{
char *s = malloc(64);
char c[2] = {0, 0};
@ -66,20 +74,19 @@ int script_gets(interpreter *it)
s[index] = '\0';
variable *r = make_vars(0, s);
iret(it, r);
ipush(it, (uint32_t)r);
free(s);
free(r);
return 0;
}
int script_delay(interpreter *it)
int script_delay(instance *it)
{
int ms = igetarg_integer(it, 0);
int ms = (int)igetarg(it, 0)->value.f;
delay(ms);
return 0;
}
int script_rect(interpreter *it)
int script_rect(instance *it)
{
dsp_rect(igetarg_integer(it, 0), igetarg_integer(it, 1),
igetarg_integer(it, 2), igetarg_integer(it, 3),
@ -87,7 +94,7 @@ int script_rect(interpreter *it)
return 0;
}
int script_line(interpreter *it)
int script_line(instance *it)
{
int x = igetarg_integer(it, 0);
int y = igetarg_integer(it, 1);
@ -98,42 +105,42 @@ int script_line(interpreter *it)
return 0;
}
int script_ppos(interpreter *it)
int script_ppos(instance *it)
{
dsp_cpos(0, 0);
dsp_coff(igetarg_integer(it, 0), igetarg_integer(it, 1));
return 0;
}
int script_color(interpreter *it)
int script_color(instance *it)
{
uint16_t c = dsp_color(igetarg_integer(it, 0), igetarg_integer(it, 1),
igetarg_integer(it, 2));
variable *v = make_varn(0, (float)c);
iret(it, v);
variable *v = make_varf(0, (float)c);
ipush(it, (uint32_t)v);
free(v);
return 0;
}
int script_rand(interpreter *it)
int script_rand(instance *it)
{
unsigned int mod = igetarg_integer(it, 0);
unsigned int val = random_get();
variable *v = make_varn(0, (float)(mod % val));
iret(it, v);
variable *v = make_varf(0, (float)(mod % val));
ipush(it, (uint32_t)v);
free(v);
return 0;
}
int script_getkey(interpreter *it)
int script_getkey(instance *it)
{
variable *v = make_varn(0, (float)keypad_get());
iret(it, v);
variable *v = make_varf(0, (float)keypad_get());
ipush(it, (uint32_t)v);
free(v);
return 0;
}
int script_pixel(interpreter *it)
int script_pixel(instance *it)
{
dsp_pixel(igetarg_integer(it, 0), igetarg_integer(it, 1),
igetarg_integer(it, 2));

Loading…
Cancel
Save