graphing perfection

master
Clyne Sullivan 7 years ago
parent 94a62e8a7b
commit c27af361fe

@ -58,7 +58,7 @@ do
do
solve Fx > y
set y (0 - y)
if ((y > ymin) & (y < ymax))
if ((y >= ymin) & (y <= ymax))
pixel (cx + x * xinc) (cy + y * yinc) 511
end
set x (x + 1 / xinc)

Binary file not shown.

@ -39,10 +39,15 @@ void dsp_putchar(int c)
if (++cury == 12) {
UNLOCK;
dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0);
LOCK;
cury = 0;
}
return;
} else if (c == '\b') {
if (curx > 0)
curx--;
UNLOCK;
dsp_rect(curxo + curx * 12, curyo + cury * 26, 12, 26, 0);
return;
}
unsigned int start = ((c - ' ') / 16 * 192 * 26 + (c % 16) * 12) * 2;

@ -1,7 +1,6 @@
#include <heap.h>
#include <task.h>
#define HEAP_ALIGN 16
#define HEAP_ALIGN 4
typedef struct {
uint32_t size;
@ -10,7 +9,7 @@ typedef struct {
static alloc_t *free_blocks;
static void *heap_end;
static uint32_t heap_used;
uint32_t heap_used;
void heap_init(void *buf)
{
@ -21,17 +20,29 @@ void heap_init(void *buf)
void *malloc(uint32_t size)
{
//task_hold(1);
size = (size + sizeof(alloc_t) + HEAP_ALIGN) & ~(HEAP_ALIGN - 1);
alloc_t *node = free_blocks;
alloc_t *prev = 0;
while (node != 0) {
if (node->size >= size) {
if (prev != 0)
prev->next = node->next;
else
free_blocks = node->next;
/*if (node->size > size + sizeof(alloc_t) + HEAP_ALIGN) {
alloc_t *rem = (alloc_t *)((uint8_t *)node +
sizeof(alloc_t) + size);
rem->size = node->size - size - sizeof(alloc_t);
rem->next = node->next;
if (prev != 0)
prev->next = rem;
else
free_blocks = rem;
node->size = size;
} else {*/
if (prev != 0)
prev->next = node->next;
else
free_blocks = node->next;
//}
node->next = 0;
heap_used += node->size;
return (void *)((uint8_t *)node + sizeof(alloc_t));
@ -48,7 +59,6 @@ void *malloc(uint32_t size)
heap_end = (void *)((uint8_t *)heap_end + size);
heap_used += size;
//task_hold(0);
return (void *)((uint8_t *)node + sizeof(alloc_t));
}

@ -22,7 +22,6 @@ int script_color(interpreter *it);
int script_rand(interpreter *it);
int script_getkey(interpreter *it);
int script_pixel(interpreter *it);
int script_solve(interpreter *it);
void script_loadlib(interpreter *it)
{
@ -36,7 +35,6 @@ void script_loadlib(interpreter *it)
inew_cfunc(it, "rand", script_rand);
inew_cfunc(it, "getkey", script_getkey);
inew_cfunc(it, "pixel", script_pixel);
inew_cfunc(it, "solve", script_solve);
}
int script_puts(interpreter *it)
@ -50,14 +48,21 @@ int script_gets(interpreter *it)
{
char *s = malloc(64);
char c[2] = {0, 0};
uint16_t index = 0;
int index = 0;
do {
c[0] = serial_get();
s[index] = c[0];
if (c[0] != '\r')
if (c[0] == '\b' || c[0] == 127) {
index--;
if (index > -1) {
dsp_puts("\b");
index--;
}
} else if (c[0] != '\r') {
dsp_puts(c);
} while (s[index] != '\r' && index++ < 23);
}
} while (s[index] != '\r' && index++ < 63);
s[index] = '\0';
variable *r = make_vars(0, s);
@ -135,18 +140,3 @@ int script_pixel(interpreter *it)
return 0;
}
int script_solve(interpreter *it)
{
const char *expr = igetarg_string(it, 0);
int len = strlen(expr);
char *buf = (char *)malloc(len + 2);
strcpy(buf, expr);
buf[len] = ')';
buf[len + 1] = '\0';
variable *r = idoexpr(it, buf);
if (r == 0)
r = make_varn(0, 0.0f);
iret(it, r);
free(r);
return 0;
}

@ -67,15 +67,49 @@ float strtof(const char *s, char **endptr)
{
(void)s;
(void)endptr;
return 0.0f;
float res = 0.0f;
char neg = 0;
unsigned int i = 0;
if (s[0] == '-') {
neg = 1;
i++;
}
for (; isdigit(s[i]); i++) {
res *= 10.0f;
res += (s[i] - '0');
}
if (s[i] != '.')
goto end;
float div = 0.1f;
for (i++; isdigit(s[i]); i++) {
res += div * (s[i] - '0');
div /= 10.0f;
}
end:
return (neg == 0) ? res : -res;
}
int atoi(const char *s)
{
unsigned int i = 0;
char neg = 0;
int n = 0;
for (unsigned int i = 0; isdigit(s[i]); i++) {
if (s[0] == '-') {
neg = 1;
i = 1;
}
for (; isdigit(s[i]); i++) {
n *= 10;
n += s[i] - '0';
}
return n;
return (neg == 0) ? n : -n;
}

@ -12,12 +12,16 @@ void serial_puts(const char *s)
void perror(const char *s)
{
//extern task_t *current;
extern uint32_t heap_used;
serial_puts(s);
//char buf[200];
//snprintf(buf, 200, "xPSR: %x\r\nPC: %x\r\nLR: %x\r\n", current->sp[0],
// current->sp[1], current->sp[2]);
//serial_puts(buf);
static char buf[200];
uint32_t *psp;
asm("mrs %0, psp" : "=r"(psp));
snprintf(buf, 200, "\r\nPC: %x\r\nLR: %x\r\nmemused: %db\r\n",
psp[6], psp[5], heap_used);
serial_puts(buf);
}
__attribute__ ((naked))

Loading…
Cancel
Save