Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem2 mbed
Fork of manworm_tv_raster by
Revision 9:2a47b9ff8911, committed 2018-03-10
- Comitter:
- dicarloj
- Date:
- Sat Mar 10 05:09:55 2018 +0000
- Parent:
- 8:caeb6582cdc1
- Child:
- 10:1163fb31b0a7
- Commit message:
- before buffer switch
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gfx.cpp Sat Mar 10 05:09:55 2018 +0000
@@ -0,0 +1,287 @@
+#define N_PTS 500
+#define N_LNS 2000
+#define N_HEIGHTS 100
+#define N_SIDE 10
+
+#include "gfx.h"
+#include "mbed.h"
+#include "main.h"
+
+int n_pts = 0;
+int n_lns = 0;
+int n_frame = 0;
+int n_cubes = 0;
+
+char gfx_stat[40];
+
+point_t* pts;
+line_t* lns;
+cube_t* cubes;
+
+float heights[N_HEIGHTS];
+
+float c_i[3] = {-.1, -.1, -.1};
+float c1i[3] = {.1, -.1, -.1};
+float c2i[3] = {-.1, .1, -.1};
+float c3i[3] = {-.1, -.1, .1};
+float c_j[3] = {.1, .1, .1};
+float c1j[3] = {.1, .1, -.1};
+float c2j[3] = {-.1, .1, .1};
+float c3j[3] = {.1, -.1, .1};
+float x_rotmat[3][3] = {{1, 0, 0}, {0, cos(.02), -sin(.02)}, {0, sin(.02), cos(.02)}};
+float y_rotmat[3][3] = {{cos(.02), 0, sin(.02)}, {0, 1, 0}, { -sin(.02), 0, cos(.02)}};
+float z_rotmat[3][3] = {{cos(.02), -sin(.02), 0}, {sin(.02), cos(.02), 0}, {0, 0, 1}};
+float temp[3] = {0, 0, 0};
+float temp2[3] = {0, 0, 0};
+
+unsigned int m_z=12434,m_w=33254;
+void draw_lines();
+
+unsigned int rnd() {
+ m_z = 36969 * (m_z & 65535) + (m_z >>16);
+ m_w = 18000 * (m_w & 65535) + (m_w >>16);
+ return ((m_z <<16) + m_w);
+}
+
+
+
+void mat_vec_mult(float a[][3], float *b, float *c, uint8_t inv) {
+ for (int i = 0; i < 3; i++) {
+ if(inv)
+ c[i] = (a[0][i] * b[0] + a[1][i] * b[1] + a[2][i] * b[2]);
+ else
+ c[i] = (a[i][0] * b[0] + a[i][1] * b[1] + a[i][2] * b[2]);
+ }
+}
+
+void point_mult(float a[][3], point_t* b, float* c, uint8_t inv)
+{
+ for (int i = 0; i < 3; i++) {
+ if(inv)
+ {
+ c[i] = (a[0][i] * b->x + a[1][i] * b->y + a[2][i] * b->z);
+ }
+ else
+ {
+ c[i] = (a[i][0] * b->x + a[i][1] * b->y + a[i][2] * b->z);
+ }
+ }
+}
+
+
+
+void add_cube()
+{
+
+}
+
+char* get_gfx_stat()
+{
+ n_frame++;
+ sprintf(gfx_stat,"%d/%d, %d/%d, %d",n_lns,N_LNS,n_pts,N_PTS,n_frame%1000);
+ return gfx_stat;
+}
+
+point_t* new_point()
+{
+ if(n_pts >= N_PTS - 1) return NULL;
+ return &pts[n_pts++];
+}
+
+line_t* new_linet()
+{
+ if(n_lns >= N_LNS - 1) return NULL;
+ return &lns[n_lns++];
+}
+
+void rotate_cube(uint8_t x, uint8_t y, uint8_t z,uint8_t inv);
+
+
+void new_frame(char c)
+{
+ draw_lines();
+ if(c == 'w')
+ rotate_cube(1,0,0,0);
+ if(c == 's')
+ rotate_cube(1,0,0,1);
+ if(c == 'a')
+ rotate_cube(0,1,0,0);
+ if(c == 'd')
+ rotate_cube(0,1,0,1);
+ if(c == 'q')
+ rotate_cube(0,0,1,0);
+ if(c == 'e')
+ rotate_cube(0,0,1,1);
+ else
+ rotate_cube(1,0,0,1);
+ draw_gfx_line(c_i[0],c_i[1],c1i[0],c1i[1]);
+ draw_gfx_line(c_i[0],c_i[1],c2i[0],c2i[1]);
+ draw_gfx_line(c_i[0],c_i[1],c3i[0],c3i[1]);
+
+ draw_gfx_line(c_j[0],c_j[1],c1j[0],c1j[1]);
+ draw_gfx_line(c_j[0],c_j[1],c2j[0],c2j[1]);
+ draw_gfx_line(c_j[0],c_j[1],c3j[0],c3j[1]);
+
+ draw_gfx_line(c3i[0],c3i[1],c3j[0],c3j[1]);
+ draw_gfx_line(c3i[0],c3i[1],c2j[0],c2j[1]);
+
+ draw_gfx_line(c1i[0],c1i[1],c1j[0],c1j[1]);
+ draw_gfx_line(c1i[0],c1i[1],c3j[0],c3j[1]);
+
+ draw_gfx_line(c2i[0],c2i[1],c2j[0],c2j[1]);
+ draw_gfx_line(c2i[0],c2i[1],c1j[0],c1j[1]);
+}
+
+void rotate_cube(uint8_t x, uint8_t y, uint8_t z, uint8_t inv)
+{
+ if (x) {
+ //multiply the cube point by the rotation matrix and store the array in temp
+ mat_vec_mult(x_rotmat, c_i, temp,inv);
+ //copy temp vector into point vector, updating it.
+ memcpy(c_i, temp, sizeof(c_i));
+ mat_vec_mult(x_rotmat, c1i, temp,inv);
+ memcpy(c1i, temp, sizeof(c1i));
+ mat_vec_mult(x_rotmat, c2i, temp,inv);
+ memcpy(c2i, temp, sizeof(c2i));
+ mat_vec_mult(x_rotmat, c3i, temp,inv);
+ memcpy(c3i, temp, sizeof(c3i));
+ mat_vec_mult(x_rotmat, c_j, temp,inv);
+ memcpy(c_j, temp, sizeof(c_j));
+ mat_vec_mult(x_rotmat, c1j, temp,inv);
+ memcpy(c1j, temp, sizeof(c1j));
+ mat_vec_mult(x_rotmat, c2j, temp,inv);
+ memcpy(c2j, temp, sizeof(c2j));
+ mat_vec_mult(x_rotmat, c3j, temp,inv);
+ memcpy(c3j, temp, sizeof(c3j));
+ }
+ if (y) {
+
+ mat_vec_mult(y_rotmat, c_i, temp,inv);
+ memcpy(c_i, temp, sizeof(c_i));
+ mat_vec_mult(y_rotmat, c1i, temp,inv);
+ memcpy(c1i, temp, sizeof(c1i));
+ mat_vec_mult(y_rotmat, c2i, temp,inv);
+ memcpy(c2i, temp, sizeof(c2i));
+ mat_vec_mult(y_rotmat, c3i, temp,inv);
+ memcpy(c3i, temp, sizeof(c3i));
+ mat_vec_mult(y_rotmat, c_j, temp,inv);
+ memcpy(c_j, temp, sizeof(c_j));
+ mat_vec_mult(y_rotmat, c1j, temp,inv);
+ memcpy(c1j, temp, sizeof(c1j));
+ mat_vec_mult(y_rotmat, c2j, temp,inv);
+ memcpy(c2j, temp, sizeof(c2j));
+ mat_vec_mult(y_rotmat, c3j, temp,inv);
+ memcpy(c3j, temp, sizeof(c3j));
+ }
+ //
+ if (z) {
+ mat_vec_mult(z_rotmat, c_i, temp,inv);
+ memcpy(c_i, temp, sizeof(c_i));
+ mat_vec_mult(z_rotmat, c1i, temp,inv);
+ memcpy(c1i, temp, sizeof(c1i));
+ mat_vec_mult(z_rotmat, c2i, temp,inv);
+ memcpy(c2i, temp, sizeof(c2i));
+ mat_vec_mult(z_rotmat, c3i, temp,inv);
+ memcpy(c3i, temp, sizeof(c3i));
+ mat_vec_mult(z_rotmat, c_j, temp,inv);
+ memcpy(c_j, temp, sizeof(c_j));
+ mat_vec_mult(z_rotmat, c1j, temp,inv);
+ memcpy(c1j, temp, sizeof(c1j));
+ mat_vec_mult(z_rotmat, c2j, temp,inv);
+ memcpy(c2j, temp, sizeof(c2j));
+ mat_vec_mult(z_rotmat, c3j, temp,inv);
+ memcpy(c3j, temp, sizeof(c3j));
+ }
+}
+
+void init_gfx()
+{
+ new_line();
+ draw_vincent_string("GFX START!");
+ pts = (point_t*)malloc(N_PTS * sizeof(point_t));
+ lns = (line_t*)malloc(N_LNS * sizeof(line_t));
+ cubes = (cube_t*)malloc(10 * sizeof(cube_t));
+
+ for(int i = 0; i < N_HEIGHTS; i++)
+ {
+ uint32_t a = rnd();
+ heights[i] = .2f * (float)a / (float)INT_MAX;
+ new_point();
+ pts[i].z = heights[i];
+ pts[i].y = 0.001f;
+ pts[i].x = 0.001f;
+ //sprintf("%f\n",heights[i]);
+ }
+
+
+ for(int xi = 0; xi < N_SIDE; xi++)
+ {
+ for(int yi = 0; yi < N_SIDE; yi++)
+ {
+ // base
+ int pti = xi + N_SIDE*yi;
+ pts[pti].x = -.5f + ( (float) (xi) )/( (float) (N_SIDE) );
+ pts[pti].y = -.5f + ( (float) (yi) )/( (float) (N_SIDE) );
+ // go x+?
+ if( (xi < (N_SIDE - 1)))
+ {
+ int ptn = (xi+1) + N_SIDE*yi;
+ line_t* lin = new_linet();
+ lin->a = pts + pti;
+ lin->b = pts + ptn;
+ }
+ // go x-?
+ if( (xi > 0))
+ {
+ int ptn = (xi-1) + N_SIDE*yi;
+ line_t* lin = new_linet();
+ lin->a = pts + pti;
+ lin->b = pts + ptn;
+ }
+
+ // go y+
+ if( (yi < (N_SIDE - 1)))
+ {
+ int ptn = (xi) + N_SIDE*(1+yi);
+ line_t* lin = new_linet();
+ lin->a = pts + pti;
+ lin->b = pts + ptn;
+ }
+
+ // go y-?
+ if( (yi > 0))
+ {
+ int ptn = (xi) + N_SIDE*(yi - 1);
+ line_t* lin = new_linet();
+ lin->a = pts + pti;
+ lin->b = pts + ptn;
+ }
+
+
+ }
+ }
+}
+
+void draw_lines()
+{
+ for(int i = 0; i < n_pts; i++)
+ {
+ point_mult(x_rotmat,pts + i,temp,0);
+ pts[i].x = temp[0];
+ pts[i].y = temp[1];
+ pts[i].z = temp[2];
+ point_mult(y_rotmat,pts + i,temp,0);
+ pts[i].x = temp[0];
+ pts[i].y = temp[1];
+ pts[i].z = temp[2];
+ }
+
+ for(int i = 0; i < n_lns; i++)
+ {
+ line_t* l = lns + i;
+ //printf("i: %d, a: %d, b: %d\n",i,l->a,l->b);
+ //printf("%.3f, %.3f, %.3f, %.3f\n",l->a->x,l->a->y,l->b->x,l->b->y);
+ draw_gfx_line(l->a->x,l->a->y,l->b->x,l->b->y);
+
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gfx.h Sat Mar 10 05:09:55 2018 +0000
@@ -0,0 +1,22 @@
+#ifndef _gfx
+#define _gfx
+struct point_t
+{
+ float x,y,z;
+};
+
+struct line_t
+{
+ point_t *a, *b;
+};
+
+struct cube_t
+{
+ point_t* points[8];
+ line_t* lines[12];
+};
+
+void init_gfx();
+char* get_gfx_stat();
+void new_frame(char c);
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lisp.cpp Sat Mar 10 05:09:55 2018 +0000
@@ -0,0 +1,580 @@
+///* A minimal Lisp interpreter
+// Copyright 2004 Andru Luvisi
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License , or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, write to the Free Software
+// Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+// */
+//
+//
+//#include <stdio.h>
+//#include <stdlib.h>
+//#include <stdarg.h>
+//#include <string.h>
+//#include <ctype.h>
+//#include "main.h"
+//
+//#define error(X) do { printf("ERROR: %s\n", X); } while (0)
+//#define out_buf_size 5000
+//#define in_buf_size 5000
+//
+//int out_counter = 0;
+//int in_counter = 0;
+//char out_buf[out_buf_size];
+//char in_buf [in_buf_size];
+//
+//char lisp_exit = 0;
+//
+//void init_buf()
+//{
+// for(int i = 0; i < out_buf_size; i++)
+// out_buf[i] = 0;
+//
+// for(int i = 0; i < in_buf_size; i++)
+// in_buf[i] = 0;
+//
+// out_buf[out_buf_size - 1] = 0;
+// out_counter = 0;
+// in_counter = 0;
+//}
+//
+//char getc_2()
+//{
+// //draw_vincent_string("getc2");
+// in_counter++;
+// if(in_counter >= in_buf_size)
+// {
+// lisp_exit = 1;
+// return EOF;
+// }
+//
+// char next_char = in_buf[in_counter - 1];
+//
+// if(next_char == 0)
+// {
+// lisp_exit = 1;
+// return EOF;
+// }
+//
+// return in_buf[in_counter-1];
+//}
+//
+//void ungetc_2(char c)
+//{
+// in_counter--;
+//}
+//
+//
+//char* strdup_2(char* in)
+//{
+// char* new_string = (char*)malloc(strlen(in));
+// strcpy(new_string,in);
+// return new_string;
+//}
+//
+//void write_out(char* str)
+//{
+// printf("write_out: %s\n",str);
+//
+// int len = strlen(str);
+//
+// if(len + out_counter < out_buf_size)
+// {
+// printf("BUUFER OVERLFOW!\n");
+// return;
+// }
+//
+// memcpy(out_buf + out_counter, str, len);
+//}
+//
+//int line_num = 1;
+//int total_malloc = 0;
+//
+///*** List Structured Memory ***/
+//enum otype { INT, SYM, CONS, PROC, PRIMOP };
+//typedef struct obj {
+// enum otype type;
+// int line_num;
+// struct obj *p[1];
+//} obj;
+//typedef obj * (*primop)(obj *);
+//obj *all_symbols, *top_env, *nil, *tee, *quote,
+// *s_if, *s_lambda, *s_define, *s_setb, *s_begin;
+//
+//#define cons(X, Y) omake(CONS, 2, (X), (Y))
+//
+//obj *car(obj *X) {
+// if(X == 0) {
+// sprintf(out_buf + strlen(out_buf),"warning: car argument null on line %d\n", line_num);
+// return nil;
+// }
+// if(X == nil)
+// return nil;
+// if(X->type != CONS) {
+// sprintf(out_buf + strlen(out_buf),"warning: car argument not a list (%d) on line %d\n", X->p[0], X->line_num);
+// return nil;
+// }
+// return X->p[0];
+//}
+//
+//obj *cdr(obj *X) {
+// if(X == nil)
+// return nil;
+// if(X->type != CONS) {
+// sprintf(out_buf + strlen(out_buf),"warning: cdr argument not a list on line %d\n", X->line_num);
+// return nil;
+// }
+// if(X->p[1] == 0) {
+// sprintf(out_buf + strlen(out_buf),"error: cdr list element is zero-pointer at %d\n", X->line_num);
+// return nil;
+// }
+// return X->p[1];
+//}
+//
+//#define setcar(X,Y) (((X)->p[0]) = (Y))
+//#define setcdr(X,Y) (((X)->p[1]) = (Y))
+//#define mkint(X) omake(INT, 1, (obj *)(X))
+//#define intval(X) ((int)((X)->type == INT ? (X)->p[0] : 0)) // intval for INT only
+//#define mksym(X) omake(SYM, 1, (obj *)(X))
+//#define symname(X) ((char *)((X)->p[0]))
+//#define mkprimop(X) omake(PRIMOP, 1, (obj *)(X))
+//#define primopval(X) ((primop)(X)->p[0])
+//#define mkproc(X,Y,Z) omake(PROC, 3, (X), (Y), (Z))
+//#define procargs(X) ((X)->p[0])
+//#define proccode(X) ((X)->p[1])
+//#define procenv(X) ((X)->p[2])
+//#define isnil(X) ((X) == nil)
+//
+//obj *omake(enum otype type, int count, ...) {
+// obj *ret;
+// va_list ap;
+// int i;
+// va_start(ap, count);
+// int object_size = sizeof(obj) + (count - 1)*sizeof(obj *);
+// total_malloc += object_size;
+// if(type == INT)
+// printf("malloc %d bytes for INT\r\n",object_size);
+// if(type == SYM)
+// printf("malloc %d bytes for SYM\r\n",object_size);
+// if(type == CONS)
+// printf("malloc %d bytes for CONS\r\n",object_size);
+// if(type == SYM)
+// printf("malloc %d bytes for PROC\r\n",object_size);
+// if(type == PRIMOP)
+// printf("malloc %d bytes for PRIMOP\r\n",object_size);
+//
+////enum otype { INT, SYM, CONS, PROC, PRIMOP };
+// ret = (obj *) malloc(object_size);
+// ret->type = type;
+// ret->line_num = line_num;
+// for(i = 0; i < count; i++) ret->p[i] = va_arg(ap, obj *);
+// va_end(ap);
+// return ret;
+//}
+//
+//obj *findsym(char *name) {
+// obj *symlist;
+// for(symlist = all_symbols; !isnil(symlist); symlist = cdr(symlist))
+// if(!strcmp(name, symname(car(symlist))))
+// return symlist;
+// return nil;
+//}
+//
+//obj *intern(char *name) {
+// obj *op = findsym(name);
+// if(!isnil(op)) return car(op);
+// op = mksym(name);
+// all_symbols = cons(op, all_symbols);
+// return op;
+//}
+//
+///*** Environment ***/
+//#define extend(ENV, SYM, VAL) (cons(cons((SYM), (VAL)), (ENV)))
+//
+//obj *multiple_extend(obj *env, obj *syms, obj *vals) {
+// return isnil(syms) ?
+// env :
+// multiple_extend(extend(env, car(syms), car(vals)),
+// cdr(syms), cdr(vals));
+//}
+//
+//obj *extend_top(obj *sym, obj *val) {
+// setcdr(top_env, cons(cons(sym, val), cdr(top_env)));
+// return val;
+//}
+//
+//obj *assoc(obj *key, obj *alist) {
+// if(isnil(alist)) return nil;
+// if(car(car(alist)) == key) return car(alist);
+// return assoc(key, cdr(alist));
+//}
+//
+///*** Input/Output ***/
+////FILE *ifp;
+//char *token_la;
+//int la_valid = 0;
+//#define MAXLEN 100
+//char buf[MAXLEN];
+//int bufused;
+//
+//void add_to_buf(char ch) { if(bufused < MAXLEN - 1) buf[bufused++] = ch; }
+//char *buf2str() { buf[bufused++] = '\0'; return strdup_2(buf); }
+////void setinput(FILE *fp) { ifp = fp; }
+//void putback_token(char *token) { token_la = token; la_valid = 1; }
+//
+//void myexit(int code);
+//
+//char *gettoken() {
+// int ch;
+// char comment=0;
+//
+// bufused = 0;
+// if(la_valid) { la_valid = 0; return token_la; }
+// do {
+// if((ch = getc_2()) == EOF) {myexit(0); return NULL;} // replace with serial
+// //draw_vincent_string("gettoken");
+// if(ch == ';') comment = 1;
+// if(ch == '\n') {
+// comment = 0;
+// line_num++;
+// }
+//
+// } while(isspace(ch) || comment);
+//
+//
+// add_to_buf(ch);
+// if(strchr("()\'", ch)) return buf2str();
+// for(;;) {
+// if(lisp_exit) { return NULL; }
+// if((ch = getc_2()) == EOF) {myexit(0); return NULL;}
+// if(strchr("()\'", ch) || isspace(ch)) {
+// ungetc_2(ch);
+// return buf2str();
+// }
+// add_to_buf(ch);
+// }
+//}
+//
+//obj *readlist();
+//
+//obj *readobj() {
+// char *token;
+//
+// token = gettoken();
+// if(token == NULL) return NULL;
+// if(!strcmp(token, "(")) return readlist();
+// if(!strcmp(token, "\'")) return cons(quote, cons(readobj(), nil));
+//
+// if(token[strspn(token, "0123456789")] == '\0'
+// || (token[0] == '-' && strlen(token) > 1))
+// return mkint(atoi(token));
+// return intern(token);
+//}
+//
+//obj *readlist() {
+// char *token = gettoken();
+// if(token == NULL) return NULL;
+// obj *tmp;
+// if(!strcmp(token, ")")) return nil;
+// if(!strcmp(token, ".")) {
+// tmp = readobj();
+// if(strcmp(gettoken(), ")")) myexit(1);
+// return tmp;
+// }
+// putback_token(token);
+// tmp = readobj(); /* Must force evaluation order */
+// return cons(tmp, readlist());
+//}
+//
+//void writeobj(obj *op) {
+//
+// if(op == NULL) { return; }
+// switch(op->type) {
+// case INT: sprintf(out_buf + strlen(out_buf),"%d", intval(op)); break;
+// case CONS:
+// //draw_vincent_string(" write_cons ");
+// sprintf(out_buf + strlen(out_buf),"(");
+// for(;;) {
+// writeobj(car(op));
+// if(isnil(cdr(op))) {
+// sprintf(out_buf + strlen(out_buf),")");
+// break;
+// }
+// op = cdr(op);
+// if(op->type != CONS) {
+// sprintf(out_buf + strlen(out_buf)," . ");
+// writeobj(op);
+// sprintf(out_buf + strlen(out_buf),")");
+// break;
+// }
+// sprintf(out_buf + strlen(out_buf)," ");
+// }
+// break;
+// case SYM:
+//
+// if(isnil(op)) sprintf(out_buf + strlen(out_buf),"()");
+// else sprintf(out_buf + strlen(out_buf),"%s", symname(op));
+// break;
+// case PRIMOP: sprintf(out_buf + strlen(out_buf),"#<PRIMOP>"); break;
+// case PROC: sprintf(out_buf + strlen(out_buf),"#<PROC>"); break;
+// default: myexit(1);
+// }
+//}
+//
+///*** Evaluator (Eval/no Apply) ***/
+//obj *evlis(obj *exps, obj *env);
+//
+//obj *eval(obj *exp, obj *env) {
+// if(lisp_exit) return NULL;
+// obj *tmp, *proc, *vals;
+//
+// eval_start:
+//
+// if(exp == NULL) return nil;
+// if(exp == nil) return nil;
+//
+//
+// switch(exp->type) {
+// case INT: return exp;
+// case SYM: tmp = assoc(exp, env);
+//
+// if(tmp == nil) {
+// sprintf(out_buf + strlen(out_buf), "Unbound symbol ");
+// writeobj(exp);
+// sprintf(out_buf + strlen(out_buf), "\n");
+// return nil;
+// }
+// return cdr(tmp);
+//
+//
+//
+// case CONS:
+// if(car(exp) == s_if) {
+// if(eval(car(cdr(exp)), env) != nil)
+// return eval(car(cdr(cdr(exp))), env);
+// else
+// return eval(car(cdr(cdr(cdr(exp)))), env);
+// }
+// if(car(exp) == s_lambda)
+// return mkproc(car(cdr(exp)), cdr(cdr(exp)), env);
+// if(car(exp) == quote)
+// return car(cdr(exp));
+// if(car(exp) == s_define)
+// return(extend_top(car(cdr(exp)),
+// eval(car(cdr(cdr(exp))), env)));
+// if(car(exp) == s_setb) {
+// obj *pair = assoc(car(cdr(exp)), env);
+// obj *newval = eval(car(cdr(cdr(exp))), env);
+// setcdr(pair, newval);
+// return newval;
+// }
+// if(car(exp) == s_begin) {
+// exp = cdr(exp);
+// if(exp == nil) return nil;
+// for(;;) {
+// if(cdr(exp) == nil) {
+// exp = car(exp);
+// goto eval_start;
+// }
+// eval(car(exp), env);
+// exp = cdr(exp);
+// }
+// }
+// proc = eval(car(exp), env);
+// vals = evlis(cdr(exp), env);
+// if(proc->type == PRIMOP)
+// return (*primopval(proc))(vals);
+// if(proc->type == PROC) {
+// /* For dynamic scope, use env instead of procenv(proc) */
+// env = multiple_extend(procenv(proc), procargs(proc), vals);
+// exp = cons(s_begin, proccode(proc));
+// goto eval_start;
+// }
+// sprintf(out_buf + strlen(out_buf),"Bad PROC type\n");
+// return nil;
+// case PRIMOP: return exp;
+// case PROC: return exp;
+// }
+// /* Not reached */
+// return exp;
+//}
+//
+//obj *evlis(obj *exps, obj *env) {
+// if(exps == nil) return nil;
+// return cons(eval(car(exps), env),
+// evlis(cdr(exps), env));
+//}
+//
+///*** Primitives ***/
+//obj *prim_sum(obj *args) {
+// int sum;
+// for(sum = 0; !isnil(args); sum += intval(car(args)), args = cdr(args));
+// return mkint(sum);
+//}
+//
+//obj *prim_sub(obj *args) {
+// int sum;
+// for(sum = intval(car(args)), args = cdr(args);
+// !isnil(args);
+// sum -= intval(car(args)), args = cdr(args));
+// return mkint(sum);
+//}
+//
+//obj *prim_prod(obj *args) {
+// int prod;
+// for(prod = 1; !isnil(args); prod *= intval(car(args)), args = cdr(args));
+// return mkint(prod);
+//}
+//obj *prim_divide(obj *args) {
+// int prod = intval(car(args));
+// args = cdr(args);
+// while(!isnil(args)) {
+// prod /= intval(car(args));
+// args = cdr(args);
+// }
+//
+// return mkint(prod);
+//}
+//
+//obj *prim_gt(obj *args) {
+// return intval(car(args)) > intval(car(cdr(args))) ? tee : nil;
+//}
+//
+//obj *prim_lt(obj *args) {
+// return intval(car(args)) < intval(car(cdr(args))) ? tee : nil;
+//}
+//obj *prim_ge(obj *args) {
+// return intval(car(args)) >= intval(car(cdr(args))) ? tee : nil;
+//}
+//obj *prim_le(obj *args) {
+// return intval(car(args)) <= intval(car(cdr(args))) ? tee : nil;
+//}
+//obj *prim_numeq(obj *args) {
+// return intval(car(args)) == intval(car(cdr(args))) ? tee : nil;
+//}
+//
+//obj *prim_cons(obj *args) { return cons(car(args), car(cdr(args))); }
+//obj *prim_car(obj *args) { return car(car(args)); }
+//obj *prim_cdr(obj *args) { return cdr(car(args)); }
+//
+//
+///*** Helpers *****/
+//
+//obj *prim_print(obj *args) {
+// while(!isnil(args)) {
+// writeobj(car(args));
+// args = cdr(args);
+// sprintf(out_buf + strlen(out_buf)," ");
+// }
+// sprintf(out_buf + strlen(out_buf),"\n");
+// return nil;
+//}
+//
+///*** Initialization ***/
+//void init_sl3() {
+// nil = mksym("nil");
+// all_symbols = cons(nil, nil);
+// top_env = cons(cons(nil, nil), nil);
+// tee = intern("t");
+// extend_top(tee, tee);
+// quote = intern("quote");
+// s_if = intern("if");
+// s_lambda = intern("lambda");
+// s_define = intern("define");
+// s_setb = intern("set!");
+// s_begin = intern("begin");
+// extend_top(intern("+"), mkprimop(prim_sum));
+// extend_top(intern("-"), mkprimop(prim_sub));
+// extend_top(intern("*"), mkprimop(prim_prod));
+// extend_top(intern("/"), mkprimop(prim_divide));
+// extend_top(intern("="), mkprimop(prim_numeq));
+//
+// extend_top(intern(">"), mkprimop(prim_gt));
+// extend_top(intern(">="), mkprimop(prim_ge));
+//
+// extend_top(intern("<"), mkprimop(prim_lt));
+// extend_top(intern("<="), mkprimop(prim_le));
+//
+// extend_top(intern("cons"), mkprimop(prim_cons));
+// extend_top(intern("car"), mkprimop(prim_car));
+// extend_top(intern("cdr"), mkprimop(prim_cdr));
+//
+// extend_top(intern("print"), mkprimop(prim_print));
+//}
+//
+//char* get_output()
+//{
+// return out_buf;
+//}
+//
+//int lisp_init = 0;
+//
+///*** Main Driver ***/
+//int run_lisp(char* input) {
+// if(!lisp_init)
+// {
+// init_sl3();
+// lisp_init = 1;
+// }
+//
+// init_buf();
+//
+//
+// lisp_exit = 0;
+// strcpy(in_buf, input);
+// if(!strncmp(input,"clear",4)){ clear_all_text(); return 0; }
+// if(!strncmp(input,"mem",3))
+// {
+// char memuse[40];
+// sprintf(memuse,"MEM: %d bytes",total_malloc);
+// draw_vincent_string(memuse);
+// return;
+// }
+// in_buf[in_buf_size - 1] = 0;
+// //new_line();
+// //draw_vincent_string(in_buf);
+// //new_line();
+// //print_vincent_string(in_buf);
+//// if(argc == 2)
+//// {
+//// memcpy(in_buf,argv[1],strlen(argv[1]));
+//// printf("%s\n",in_buf);
+//// }
+//// else
+// //sprintf(in_buf,"(+ 2 2)\n");
+//// char test_in[] = "(+ 2 2)\n";
+//// FILE* input_stream = open_memstream(test_in,8);
+//// fprintf(input_stream,"(+ 2 3)\n");
+//// char test_out[50];
+//// FILE* output_stream = fmemopen(test_out,50,"w");
+// //setinput(input_stream);
+// int lisp_count = 0;
+// while(!lisp_exit) {
+// writeobj(eval(readobj(), top_env));
+// //fflush(output_stream);
+// printf("\n");
+// printf("%s\n",out_buf);
+//
+// lisp_count++;
+// if(lisp_count > 500) break;
+// //printf("outstream: %s\n",test_out);
+// }
+// draw_vincent_string(out_buf);
+// //draw_vincent_string("done!");
+// return 0;
+//}
+//
+//void myexit(int code) {
+// printf("%d bytes left hanging\n", total_malloc);
+// lisp_exit = 1;
+//}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp.h Sat Mar 10 05:09:55 2018 +0000 @@ -0,0 +1,12 @@ +//#ifndef _lisp +//#define _lisp +// +// +// +//void run_lisp(char* input); +// +//char* get_output(); +// +// +// +//#endif \ No newline at end of file
--- a/main.cpp Sat Mar 03 18:05:36 2018 +0000
+++ b/main.cpp Sat Mar 10 05:09:55 2018 +0000
@@ -1,36 +1,190 @@
#include "mbed.h"
-#define V_RES 220
-#define H_RES 100
#include <math.h>
-#define X_MIN 24
-#define X_MAX (76+18)
-#define Y_MIN 7
-#define Y_MAX (V_RES/4 - 15)
+#include "lisp.h"
+#include "main.h"
+#include "gfx.h"
+// Resolution, including porches
+#define V_RES 200
+#define H_RES 300
+
+
+// old shit
#define SX_MIN 30
#define SX_MAX 95
#define SY_MIN 10
#define SY_MAX 48
-
-#define Y_0 ( (Y_MIN + Y_MAX)/2 )
-#define X_0 ( (X_MIN + X_MAX)/2 )
-#define SIDE 8
-#define HSIDE 8
-#define SIN_V (0.03)
-#define COS_V (0.99955f)
#define BX_0 30
#define BY_0 (V_RES/4 - 15)
#define BX 42
#define BY 15
#define BY2 9
-#define DEMO_LENGTH 600
+
+// good new stuff
+#define X0 75 // start of image in X
+#define Y0 30 // start of image in Y
+#define XL 220 // 25 chars
+#define YL 165 // 20 chars
+
+#define TX 24 // number of characters in X
+#define TY 18 // number of characters in Y
+#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+uint8_t char_col = 0; // current column counter
+uint8_t char_row = 0; // current row counter
+uint8_t text_buffer_counter = 0; // current index in text buffer counter
+char most_recent_char = '0';
+
+char text_buffer[TX*TY]; // input text buffer for lisp
+
+uint8_t want_gfx = 0;
+
+Serial pc(USBTX, USBRX);
-DigitalOut sout(D8); //sync
-DigitalOut vout(D7); //video
+// font
+char vincent_data[128][8] = {
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x3E, 0x41, 0x55, 0x41, 0x55, 0x49, 0x3E },
+ { 0x00, 0x3E, 0x7F, 0x6B, 0x7F, 0x6B, 0x77, 0x3E },
+ { 0x00, 0x22, 0x77, 0x7F, 0x7F, 0x3E, 0x1C, 0x08 },
+ { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08 },
+ { 0x00, 0x08, 0x1C, 0x2A, 0x7F, 0x2A, 0x08, 0x1C },
+ { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x08, 0x1C },
+ { 0x00, 0x00, 0x1C, 0x3E, 0x3E, 0x3E, 0x1C, 0x00 },
+ { 0xFF, 0xFF, 0xE3, 0xC1, 0xC1, 0xC1, 0xE3, 0xFF },
+ { 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00 },
+ { 0xFF, 0xFF, 0xE3, 0xDD, 0xDD, 0xDD, 0xE3, 0xFF },
+ { 0x00, 0x0F, 0x03, 0x05, 0x39, 0x48, 0x48, 0x30 },
+ { 0x00, 0x08, 0x3E, 0x08, 0x1C, 0x22, 0x22, 0x1C },
+ { 0x00, 0x18, 0x14, 0x10, 0x10, 0x30, 0x70, 0x60 },
+ { 0x00, 0x0F, 0x19, 0x11, 0x13, 0x37, 0x76, 0x60 },
+ { 0x00, 0x08, 0x2A, 0x1C, 0x77, 0x1C, 0x2A, 0x08 },
+ { 0x00, 0x60, 0x78, 0x7E, 0x7F, 0x7E, 0x78, 0x60 },
+ { 0x00, 0x03, 0x0F, 0x3F, 0x7F, 0x3F, 0x0F, 0x03 },
+ { 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x08 },
+ { 0x00, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66 },
+ { 0x00, 0x3F, 0x65, 0x65, 0x3D, 0x05, 0x05, 0x05 },
+ { 0x00, 0x0C, 0x32, 0x48, 0x24, 0x12, 0x4C, 0x30 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F },
+ { 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x3E },
+ { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x1C, 0x1C, 0x1C },
+ { 0x00, 0x1C, 0x1C, 0x1C, 0x7F, 0x3E, 0x1C, 0x08 },
+ { 0x00, 0x08, 0x0C, 0x7E, 0x7F, 0x7E, 0x0C, 0x08 },
+ { 0x00, 0x08, 0x18, 0x3F, 0x7F, 0x3F, 0x18, 0x08 },
+ { 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x7F, 0x7F },
+ { 0x00, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00 },
+ { 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x3E, 0x7F, 0x7F },
+ { 0x00, 0x7F, 0x7F, 0x3E, 0x3E, 0x1C, 0x1C, 0x08 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18 },
+ { 0x00, 0x36, 0x36, 0x14, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36 },
+ { 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08 },
+ { 0x00, 0x60, 0x66, 0x0C, 0x18, 0x30, 0x66, 0x06 },
+ { 0x00, 0x3C, 0x66, 0x3C, 0x28, 0x65, 0x66, 0x3F },
+ { 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00 },
+ { 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60 },
+ { 0x00, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06 },
+ { 0x00, 0x00, 0x36, 0x1C, 0x7F, 0x1C, 0x36, 0x00 },
+ { 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60 },
+ { 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60 },
+ { 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00 },
+ { 0x00, 0x3C, 0x66, 0x6E, 0x76, 0x66, 0x66, 0x3C },
+ { 0x00, 0x18, 0x18, 0x38, 0x18, 0x18, 0x18, 0x7E },
+ { 0x00, 0x3C, 0x66, 0x06, 0x0C, 0x30, 0x60, 0x7E },
+ { 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C },
+ { 0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x7E, 0x0C, 0x0C },
+ { 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C },
+ { 0x00, 0x3C, 0x66, 0x60, 0x7C, 0x66, 0x66, 0x3C },
+ { 0x00, 0x7E, 0x66, 0x0C, 0x0C, 0x18, 0x18, 0x18 },
+ { 0x00, 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C },
+ { 0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C },
+ { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00 },
+ { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30 },
+ { 0x00, 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06 },
+ { 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00 },
+ { 0x00, 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60 },
+ { 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x18, 0x00, 0x18 },
+ { 0x00, 0x38, 0x44, 0x5C, 0x58, 0x42, 0x3C, 0x00 },
+ { 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 },
+ { 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C },
+ { 0x00, 0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C },
+ { 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C },
+ { 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E },
+ { 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60 },
+ { 0x00, 0x3C, 0x66, 0x60, 0x60, 0x6E, 0x66, 0x3C },
+ { 0x00, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 },
+ { 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C },
+ { 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 },
+ { 0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66 },
+ { 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E },
+ { 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63 },
+ { 0x00, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63 },
+ { 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C },
+ { 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60 },
+ { 0x00, 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x06 },
+ { 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66 },
+ { 0x00, 0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C },
+ { 0x00, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x18 },
+ { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E },
+ { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18 },
+ { 0x00, 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63 },
+ { 0x00, 0x63, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x63 },
+ { 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18 },
+ { 0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E },
+ { 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E },
+ { 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00 },
+ { 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78 },
+ { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F },
+ { 0x00, 0x0C, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E },
+ { 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C },
+ { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C },
+ { 0x00, 0x06, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E },
+ { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C },
+ { 0x00, 0x1C, 0x36, 0x30, 0x30, 0x7C, 0x30, 0x30 },
+ { 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C },
+ { 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66 },
+ { 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C },
+ { 0x00, 0x0C, 0x00, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 },
+ { 0x00, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66 },
+ { 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 },
+ { 0x00, 0x00, 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x6B },
+ { 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66 },
+ { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C },
+ { 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60 },
+ { 0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x3C, 0x0D, 0x0F },
+ { 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x60, 0x60 },
+ { 0x00, 0x00, 0x00, 0x3E, 0x40, 0x3C, 0x02, 0x7C },
+ { 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18 },
+ { 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3E },
+ { 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18 },
+ { 0x00, 0x00, 0x00, 0x63, 0x6B, 0x6B, 0x6B, 0x3E },
+ { 0x00, 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66 },
+ { 0x00, 0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C },
+ { 0x00, 0x00, 0x00, 0x3C, 0x0C, 0x18, 0x30, 0x3C },
+ { 0x00, 0x0E, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0E },
+ { 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18 },
+ { 0x00, 0x70, 0x18, 0x18, 0x0C, 0x18, 0x18, 0x70 },
+ { 0x00, 0x00, 0x00, 0x3A, 0x6C, 0x00, 0x00, 0x00 },
+ { 0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x41, 0x7F }
+};
+
+DigitalOut sout(D8); //sync PA_9
+DigitalOut vout(D7); //video PA_8
+
+// trigger horizontal line draw
Ticker t;
+
uint8_t draw_line_inv = 0;
-//9x42
+
+// miters logo bitmap
uint8_t miters[] = {
1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@@ -50,327 +204,53 @@
};
-uint8_t tv[] = {
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0};
-uint8_t chr_A[] = {
-0,0,1,1,0,0,
-0,1,0,0,1,0,
-1,0,0,0,0,1,
-1,1,1,1,1,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,};
-
-uint8_t chr_D[] = {
-1,1,1,1,1,0,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,1,1,1,1,0,};
-
-uint8_t chr_F[] = {
-1,1,1,1,1,1,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,1,1,1,1,1,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,};
-uint8_t chr_G[] = {
-0,1,1,1,1,0,
-1,0,0,0,0,1,
-1,0,0,0,0,0,
-1,0,0,1,1,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-0,1,1,1,1,0,};
-uint8_t chr_H[] = {
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,1,1,1,1,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,};
-
-uint8_t chr_L[] = {
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,1,1,1,1,1,};
-
-uint8_t chr_M[] = {
-1,0,0,0,0,1,
-1,1,0,0,1,1,
-1,0,1,1,0,1,
-1,0,1,1,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,};
-
-uint8_t chr_N[] = {
-1,0,0,0,0,1,
-1,1,0,0,0,1,
-1,0,1,0,0,1,
-1,0,0,1,0,1,
-1,0,0,0,1,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,};
-uint8_t chr_O[] = {
-0,1,1,1,1,0,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-0,1,1,1,1,0,};
-
-uint8_t chr_P[] = {
-1,1,1,1,1,0,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,1,1,1,1,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-1,0,0,0,0,0,};
-
-uint8_t chr_R[] = {
-1,1,1,1,1,0,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,1,0,
-1,0,0,1,0,0,
-1,0,0,0,1,0,
-1,0,0,0,0,1,};
-
-uint8_t chr_S[] = {
-0,1,1,1,1,1,
-1,0,0,0,0,0,
-1,0,0,0,0,0,
-0,1,1,1,1,0,
-0,0,0,0,0,1,
-0,0,0,0,0,1,
-1,1,1,1,1,0,};
-
-uint8_t chr_V[] = {
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-0,1,0,0,1,0,
-0,1,0,0,1,0,
-0,1,0,0,1,0,
-0,0,1,1,0,0,};
-
-uint8_t chr_W[] = {
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,0,0,0,1,
-1,0,1,1,0,1,
-1,0,1,1,0,1,
-1,1,0,0,1,1,
-1,0,0,0,0,1,};
-
-uint8_t sprite_tree[] = {
-0,0,0,1,0,0,0,
-0,0,1,1,1,0,0,
-0,1,1,1,1,1,0,
-1,1,1,1,1,1,1,
-0,1,1,1,1,1,0,
-1,1,1,1,1,1,1,
-0,0,0,1,0,0,0,
-0,0,0,1,0,0,0,};
-
-uint8_t sprite_man[] = {
-0,0,0,1,0,0,0,
-0,0,1,1,1,0,0,
-0,0,0,1,0,0,1,
-0,1,1,1,1,1,0,
-1,0,1,1,1,0,0,
-0,0,1,1,1,0,0,
-0,1,0,0,0,1,0,
-0,1,0,0,0,1,0};
-
-uint8_t sprite_manl[] = {
-0,0,0,1,0,0,0,
-0,0,1,1,1,0,0,
-1,0,0,1,0,0,0,
-0,1,1,1,1,1,0,
-0,0,1,1,1,0,1,
-0,0,1,1,1,0,0,
-0,1,0,0,0,1,0,
-0,1,0,0,0,0,0};
-
-uint8_t sprite_manr[] = {
-0,0,0,1,0,0,0,
-0,0,1,1,1,0,0,
-0,0,0,1,0,0,1,
-0,1,1,1,1,1,0,
-1,0,1,1,1,0,0,
-0,0,1,1,1,0,0,
-0,1,0,0,0,1,0,
-0,0,0,0,0,1,0};
-
-uint8_t *menu[] = {
-chr_P,chr_A,chr_N,chr_G,
-chr_F,chr_A,chr_S,chr_H,
-chr_D,chr_A,chr_M,chr_O,
-chr_D,chr_R,chr_A,chr_V,
-chr_W,chr_A,chr_L,chr_F,
-};
+uint8_t bl_line_s[H_RES]; //blank line sync buffer
+uint8_t bl_line_v[H_RES]; //blank line video buffer
+uint8_t vb_line_s[H_RES]; //vertical sync, sync buffer
+uint8_t vb_line_v[H_RES]; //vertical sync, video buffer
+uint8_t im_line_s[H_RES]; //image sync buffer
+uint8_t im_line_va_1[H_RES*V_RES];
+uint8_t im_line_va_2[H_RES*V_RES];
+uint8_t* im_line_va; // active image buff
+//uint8_t im_line_va[H_RES*V_RES]; //image video buffer
uint16_t l=0; //current line of scan
-uint8_t im_line_s[H_RES]; //image sync buffer
-
-uint8_t bl_line_s[H_RES]; //lower 1/4 of screen sync buffer
-uint8_t bl_line_v[H_RES]; //lower 1/4 of screen video buffer
-uint8_t vb_line_s[H_RES]; //vertical sync, sync buffer
-uint8_t vb_line_v[H_RES]; //vertical sync, video buffer
-
-float cube_a[3] = {15.f, 0.f, 0.f};
-
-
-float cube_pts[8][3] = { {SIDE,SIDE,HSIDE},
- {-SIDE,SIDE,HSIDE},
- {-SIDE,-SIDE,HSIDE},
- {SIDE,-SIDE,HSIDE},
- {SIDE,-SIDE,-HSIDE},
- {-SIDE,-SIDE,-HSIDE},
- {-SIDE,SIDE,-HSIDE},
- {SIDE,SIDE,-HSIDE} };
-
-float x_rot[3][3] = { {1.f, 0.f, 0.f},
- {0.f, COS_V, -SIN_V},
- {0.f, SIN_V, COS_V} };
-
-float y_rot[3][3] = { {COS_V, 0.f, SIN_V},
- {0.f, 1.f, 0.f},
- {-SIN_V, 0, COS_V} };
-
-float z_rot[3][3] = { {COS_V, -SIN_V, 0.f},
- {SIN_V, COS_V, 0.f},
- {0.f, 0.f, 1.f} };
-
-
-uint8_t im_line_va[H_RES*V_RES]; //image buffer
-
-//pong variables
-#define PADDLE_LEN 10
-float p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2;
-float p1v = 0.1, p2v = -0.1;
-
-float bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
-float bxv = 0.03, byv = 0.03;
-
-int s1 = 0, s2 = 0;
-
-//fish variables
-#define FDEATH_RESET 30000
-float fx = (SX_MAX+SX_MIN)/2.f, fy = (SY_MIN+SY_MAX)/2.f, fv = 0.02f, ftheta = 0.0, fa = 0.002;
-float uv = 0.005;
-float ux[8] = {53,70,78,78,70,53,45,45};
-float uy[8] = {10,10,20,35,50,50,35,20};
-float uvx[8] = {-1,1,1,1,1,-1,-1,-1};
-float uvy[8] = {1,1,1,-1,-1,-1,-1,1};
-int ulive[8] = {1,1,1,1,1,1,1,1};
-
-int fdeath_ticker = FDEATH_RESET;
-float fs = 0;
-
-//tunnel variables
-#define TUN_LEN (SY_MAX - SY_MIN)
-uint8_t tunnel[TUN_LEN];
-float tunnp = 50;
-int tundir = 1;
-int leg_ctr = 0;
-
-//raycaster variables
-#define mapWidth 24
-#define mapHeight 24
-
-uint8_t worldMap[mapWidth][mapHeight]=
+// positive or negative?
+int16_t sign(int16_t a)
{
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,2,2,2,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1},
- {1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,3,0,0,0,3,0,0,0,1},
- {1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,2,2,0,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,0,0,0,0,5,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,0,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
-};
-
-float posX = 12, posY = 12;
-float dirX = -1, dirY = 0;
-float planeX = 0, planeY = 0.66;
-float rc_cos = cosf(0.03f);
-float rc_sin = sinf(0.03f);
-
-//mode7 variables
-float m7_theta = 0.8f;
-float m7_x = mapWidth/2, m7_y=mapHeight/2;
-
-DigitalIn p1_in(A1);
-DigitalIn p2_in(A0);
-
-void make_checkerboard()
-{
- for(int i = 0; i < H_RES; i++)
- for(int j = 0; j < V_RES; j++)
- im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard
-
+ if(a > 0) return 1;
+ if(a < 0) return -1;
+ return 0;
}
+// clear the text buffer
+void clr_text_buff()
+{
+ text_buffer_counter = 0;
+ for(int i = 0; i < TX*TY; i++)
+ text_buffer[i] = 0;
+}
+
+// clear the screen and the text buffer
void clr()
{
for(int i = 0; i < H_RES; i++)
for(int j = 0; j < V_RES; j++)
im_line_va[i+j*H_RES] = 0;
+
+ clr_text_buff();
}
+// initialize video buffers
void init_buffers()
{
- clr();
+ clr(); // zero buffers
for(int i = 0; i < H_RES; i++)
{
im_line_s[i] = 1;
@@ -382,85 +262,103 @@
im_line_s[0] = 0;
im_line_s[1] = 0;
im_line_s[2] = 0;
+ im_line_s[3] = 0;
+
+ for(int i = 0; i < 15; i++)
+ im_line_s[i] = 0;
+
+
bl_line_s[0] = 0;
vb_line_s[0] = 1;
bl_line_s[1] = 0;
vb_line_s[1] = 1;
-
-
+ bl_line_s[3] = 0;
+ vb_line_s[3] = 1;
+ bl_line_s[2] = 0;
+ vb_line_s[2] = 1;
}
+
+// video interrupt
void isr()
{
uint8_t nop = 0; //use nops or use wait_us
uint8_t* sptr; //pointer to sync buffer for line
uint8_t* vptr; //pointer to video buffer for line
- if(l < V_RES){ vptr = im_line_va + ((l/4)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers
+ if(l < V_RES){ vptr = im_line_va + ((l)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers
else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; }
else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1;}
- uint8_t lmax = nop?H_RES:12; //number of columns
- for(uint8_t i = 0; i < lmax; i++) //loop over each column
+ uint16_t lmax = nop?H_RES:12; //number of columns
+ for(uint16_t i = 0; i < lmax; i++) //loop over each column
{
- vout = vptr[i]; //set output pins
- sout = sptr[i];
+ nop = 1;
+ if(sptr[i])
+ GPIOA->ODR |= (1 << 9);
+ else
+ GPIOA->ODR &= ~(1 << 9);
+
+ if(vptr[i])
+ GPIOA->ODR |= (1 << 8);
+ else
+ GPIOA->ODR &= ~(1 << 8);
+
+
if(nop) //nop delay
{
- asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");//asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
+ asm("nop");asm("nop");//asm("nop");asm("nop");//asm("nop");asm("nop");asm("nop");//asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
}
- else {wait_us(1); if(i > 2) i++;} //wait delay
-
-
+ else {wait_us(1); if(i > 2) i+=1;} //wait delay
}
//move to next line
l++;
if(l > 255) l = 0;
}
-//coordinates for bouncing ball
-
-
-
-int k = 0;
-uint16_t px = X_0*10;
-uint16_t py = Y_0*10;
-uint16_t vx = 10;
-uint16_t vy = 10;
-uint16_t px2 = X_0*10 + 80;
-uint16_t py2 = Y_0*10 - 40;
-uint16_t vx2 = 3;
-uint16_t vy2 = -4;
-
-int16_t sign(int16_t a)
+// draw checkerboard pattern
+void write_test_pattern(int x_in, int y_in,int k)
{
- if(a > 0) return 1;
- if(a < 0) return -1;
- return 0;
+ int x_max = MIN(H_RES,x_in);
+ int y_max = MIN(V_RES,y_in);
+
+ // x 50 to 245
+ for(int x = 65; x < x_max; x++)
+ {
+ for(int y = 30; y < y_max; y++)
+ {
+ im_line_va[y*H_RES + x] = ((y/k)%2)^((x/k)%2);
+ }
+ }
}
+// draw miters logo
+void draw_miters_at(int xx, int yy)
+{
+ int bmi = 0;
+ for(int y = yy; y < BY2+yy; y++)
+ {
+ for(int x = xx; x < BX+xx; x++)
+ {
+ im_line_va[H_RES*y + x] = miters[bmi];
+ bmi++;
+ }
+ }
+}
+
+// draw vertical line
void draw_vert(int16_t y0, int16_t y1, int16_t x0)
{
for(int16_t i = y0; i < y1; i++)
im_line_va[H_RES*i + x0] = 1;
}
+// draw horizonal line
void draw_horiz(int16_t x0, int16_t x1, int16_t y0)
{
for(int16_t i = x0; i < x1; i++)
im_line_va[H_RES*y0 + i] = 1;
}
-int16_t imin(int16_t a, int16_t b)
-{
- if(a<b) return a;
- return b;
-}
-
-int16_t imax(int16_t a, int16_t b)
-{
- if(a>b) return a;
- return b;
-}
-
+// draw line between points
void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
{
if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; }
@@ -485,632 +383,318 @@
}
}
-void draw_cube(float cp[][3])
-{
- for(uint8_t i = 0; i < 7; i++)
- {
- draw_line((int16_t)cp[i][0]+cube_a[0]+X_0,(int16_t)cp[i][1]+cube_a[1]+Y_0,(int16_t)cp[i+1][0]+cube_a[0]+X_0,(int16_t)cp[i+1][1]+cube_a[1]+Y_0);
- }
- draw_line((int16_t)cp[0][0]+cube_a[0]+X_0,(int16_t)cp[0][1]+cube_a[1]+Y_0,(int16_t)cp[3][0]+cube_a[0]+X_0,(int16_t)cp[3][1]+cube_a[1]+Y_0);
- draw_line((int16_t)cp[4][0]+cube_a[0]+X_0,(int16_t)cp[4][1]+cube_a[1]+Y_0,(int16_t)cp[7][0]+cube_a[0]+X_0,(int16_t)cp[7][1]+cube_a[1]+Y_0);
- draw_line((int16_t)cp[0][0]+cube_a[0]+X_0,(int16_t)cp[0][1]+cube_a[1]+Y_0,(int16_t)cp[7][0]+cube_a[0]+X_0,(int16_t)cp[7][1]+cube_a[1]+Y_0);
- draw_line((int16_t)cp[1][0]+cube_a[0]+X_0,(int16_t)cp[1][1]+cube_a[1]+Y_0,(int16_t)cp[6][0]+cube_a[0]+X_0,(int16_t)cp[6][1]+cube_a[1]+Y_0);
- draw_line((int16_t)cp[2][0]+cube_a[0]+X_0,(int16_t)cp[2][1]+cube_a[1]+Y_0,(int16_t)cp[5][0]+cube_a[0]+X_0,(int16_t)cp[5][1]+cube_a[1]+Y_0);
-}
-
-void apply_rot(float cp[][3], float r[][3])
-{
- for(uint8_t pti = 0; pti < 8; pti++)
- {
- float* cpt = cp[pti];
- float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2];
- float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2];
- float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2];
- cpt[0] = xn;
- cpt[1] = yn;
- cpt[2] = zn;
- }
-}
-
-void apply_xf_rot(float cpt[], float r[][3])
-{
- float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2];
- float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2];
- float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2];
- cpt[0] = xn;
- cpt[1] = yn;
- cpt[2] = zn;
-}
-
-void draw_v_check(int8_t r,uint8_t tt)
+// draw letter
+void draw_vincent(uint16_t x0, uint16_t y0, uint8_t c)
{
- for(int i = 0; i < H_RES; i++)
- for(int j = 0; j < V_RES; j++)
- im_line_va[i+j*H_RES] = (((i > 20) && (i < 98)) && ( tt ^(((j%(r*2))>=r) ^ ((i%(r*2)))>=r))); //checkerboard
-}
-
-
-int jjj = 0;
-int f_count = DEMO_LENGTH + 10;
-void draw_cube_spin(int kkkk);
-//update bouncing balls
-
-void draw_blank()
-{
- for(uint16_t h = X_MIN; h < X_MAX; h++)
- {
- for(uint16_t v = Y_MIN; v < Y_MAX+15; v++)
- {
- im_line_va[v*H_RES + h] = 0;
- }
- }
-}
-
-void wipe();
-
-void update_image()
-{
- //delay
- k++;
- if(k%4000) return;
- f_count++;
- if(f_count < DEMO_LENGTH/2)
- {
- draw_cube_spin(0);
- }
- else if(f_count < DEMO_LENGTH)
- {
- draw_cube_spin(0);
- }
- else if(f_count < DEMO_LENGTH * 1.22)
+ if(c == 40) c = 41;
+ else if(c == 41) c = 40;
+ char* letter = vincent_data[c];
+ for(uint16_t xp = 0; xp < 8; xp++)
{
- for(int k = 1; k < 10; k++)
- //for(int kk = 1; kk < 3; kk++)
- {
- draw_v_check(k,1);
- draw_v_check(k,1);
- draw_v_check(k,0);
- draw_v_check(k,0);
- }
-
- draw_v_check(1,0);
- wipe();
- f_count = 0;
- }
-}
-
-void wipe()
-{
- for(int v = Y_MIN; v < Y_MAX+15; v++)
- {
- for(uint16_t h = X_MIN; h < X_MAX; h++)
- {
- im_line_va[v*H_RES+h] = 1;
- }
- wait(.01);
- }
-
- for(int v = Y_MAX+15; v > Y_MIN; v--)
- {
- for(uint16_t h = X_MIN; h < X_MAX; h++)
- {
- im_line_va[v*H_RES+h] = 0;
- }
- wait(.005);
- }
-
- for(uint16_t h = X_MIN; h < X_MAX; h++)
- {
- for(uint16_t v = Y_MIN; v < Y_MAX+15; v++)
- {
- im_line_va[v*H_RES + h] = 1;
- }
- wait(.005);
- }
-
- for(uint16_t h = X_MIN; h < X_MAX; h++)
+ for(uint16_t yp = 0; yp < 8; yp++)
{
- for(uint16_t v = Y_MIN; v < Y_MAX+15; v++)
- {
- im_line_va[v*H_RES + h] = 0;
- }
- wait(.005);
- }
-
- for(int v = Y_MIN; v < Y_MAX+15; v++)
- {
- for(uint16_t h = X_MIN; h < X_MAX; h++)
- {
- im_line_va[v*H_RES+h] = 0;
- }
- }
-}
-
-void draw_cube_spin(int kkkk)
-{
- draw_line_inv = kkkk;
- //blank
- for(uint16_t h = X_MIN; h < X_MAX; h++)
- {
- for(uint16_t v = Y_MIN; v < Y_MAX; v++)
- {
- if( (h > 22) && (h < 76+18))
- im_line_va[v*H_RES + h] = kkkk;
- }
- }
- apply_xf_rot(cube_a,y_rot);
- apply_xf_rot(cube_a,y_rot);
- apply_rot(cube_pts,x_rot);
- apply_rot(cube_pts,x_rot);
- apply_rot(cube_pts,y_rot);
- apply_rot(cube_pts,y_rot);
- apply_rot(cube_pts,z_rot);
- //draw ball
- im_line_va[(py/10)*H_RES + (px/10)] = 1;
- draw_line(X_0,Y_0,(px/10),(py/10));
- draw_cube(cube_pts);
-
- //update position/check for bounces
- px += vx;
- py += vy;
- px2 += vx2;
- py2 += vy2;
- if(px/10 > (X_MAX-2) || px/10 < (X_MIN+1)) vx = -vx;
- if(py/10 > (Y_MAX-2) || py/10 < (Y_MIN+1)) vy = -vy;
- if(px2/10 > (X_MAX-2) || px2/10 < (X_MIN+1)) vx2 = -vx2;
- if(py2/10 > (Y_MAX-2) || py2/10 < (Y_MIN+1)) vy2 = -vy2;
- if(k%(8000*50)) return;
-
- jjj = !jjj;
- int bmi = 0;
- for(int y = BY_0; y < BY_0 + BY; y++)
- {
- for(int x = BX_0; x < BX_0 + BX; x++)
- {
- im_line_va[H_RES*y + x] = kkkk^(miters[bmi]*jjj + (!jjj)*tv[bmi]);
- bmi++;
+ im_line_va[H_RES*(yp+y0) + xp + x0] = CHECK_BIT(letter[yp],8-xp);
}
}
}
-int flappy_pong() {
-
- //clear frame
- for(int y = 0; y < PADDLE_LEN; y++) {
- im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0;
- im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0;
+// go to new line
+void new_line()
+{
+ char_col = 0;
+ char_row++;
+ if(char_row >= TY)
+ {
+ char_row = 0;
}
- im_line_va[H_RES*(int)by+(int)bx] = 0;
- //read inputs
- int cmd1 = p1_in.read();
- int cmd2 = p2_in.read();
- if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f;
- if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f;
-
- p1 += p1v;
- p2 += p2v;
- bx += bxv;
- by += byv;
-
- if (p1 < SY_MIN) p1 = SY_MIN;
- if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN;
- if (p2 < SY_MIN) p2 = SY_MIN;
- if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN;
-
- if (bx < SX_MIN) {
- bxv = -bxv;
- bx = SX_MIN;
- if (by < p1 - 3 || by > p1 + PADDLE_LEN + 3) {
- im_line_va[H_RES*(SY_MIN-2)+2*s1+SX_MIN] = 1;
- bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
- s1++;
- if (s1>14) return 0;
- }
- }
- if (bx > SX_MAX) {
- bxv = -bxv;
- bx = SX_MAX;
- if (by < p2 - 3 || by > p2 + PADDLE_LEN + 3) {
- im_line_va[H_RES*(SY_MAX+2)+2*s2+SX_MIN] = 1;
- bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2;
- s2++;
- if (s2>14) return 0;
- }
- }
- if (by < SY_MIN) {byv = -byv; by = SY_MIN;}
- if (by > SY_MAX) {byv = -byv; by = SY_MAX;}
-
- for(int y = 0; y < PADDLE_LEN; y++) {
- im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1;
- im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1;
- }
- im_line_va[H_RES*(int)by+(int)bx] = 1;
-
- wait(1/1200.0f);
- return 1;
}
-int fishy() {
- uint16_t xstart, ystart, xend, yend;
- float s = sinf(ftheta);
- float c = cosf(ftheta);
-
- xstart = (uint16_t) fx;
- ystart = (uint16_t) fy;
-
-
- for(int x = xstart-5; x < xstart + 5; x++) {
- for (int y = ystart - 5; y < ystart + 5; y++) {
- im_line_va[H_RES*y+x] = 0;
- }
+// draw string
+void draw_vincent_string(char* str)
+{
+ for(int i = 0; i < strlen(str); i++)
+ {
+ if(str[i] == 0 || str[i] == EOF) return;
+ char_col++;
+ if(char_col >= TX)
+ {
+ char_col = 0;
+ char_row++;
}
- for (int i = 0; i < 8; i++) {
- int index = H_RES*(int)uy[i]+(int)ux[i];
- im_line_va[index] = 0;
- }
-
- float fx_old = fx, fy_old = fy;
- fx += fv * s;
- fy += fv * c;
- int cmd = p1_in.read();
- if (cmd) ftheta += fa; else ftheta -= fa;
- if (ftheta >= 2 * 3.1415926) ftheta -= 2 * 3.1415926;
- if (ftheta < 0) ftheta += 2 * 3.1415926;
-
- s = sinf(ftheta);
- c = cosf(ftheta);
-
- xstart = (uint16_t)fx;
- ystart = (uint16_t)fy;
- xend = (uint16_t)(fx+s*4);
- yend = (uint16_t)(fy+c*4);
+ if(char_row >= TY)
+ {
+ char_row = 0;
+ }
- if (xstart < SX_MIN || xstart > SX_MAX ||
- ystart < SY_MIN || ystart > SY_MAX ||
- xend < SX_MIN || xend > SX_MAX ||
- yend < SY_MIN || yend > SY_MAX) {
- fx = fx_old;
- fy = fy_old;
- xstart = (uint16_t)fx;
- ystart = (uint16_t)fy;
- xend = (uint16_t)(fx+s*4);
- yend = (uint16_t)(fy+c*4);
+ draw_vincent(X0 +2 + 8*char_col, Y0 + 14 + 8*char_row,
+ str[i]);
}
-
- draw_line(xstart, ystart, xend, yend);
- for (int i = 0; i < 8; i++) {
- if (!ulive[i]) continue;
- if (xstart == (int)ux[i] && ystart == (int)uy[i]) {
- fdeath_ticker = FDEATH_RESET;
- fs+=1;
- ulive[i] = 0;
- }
- ux[i]+= uv*uvx[i];
- uy[i]+= uv*uvy[i];
- if (ux[i] < SX_MIN) {ux[i] = SX_MIN; uvx[i] = -uvx[i];}
- if (ux[i] > SX_MAX) {ux[i] = SX_MAX; uvx[i] = -uvx[i];}
- if (uy[i] < SY_MIN) {uy[i] = SY_MIN; uvy[i] = -uvy[i];}
- if (uy[i] > SY_MAX) {uy[i] = SY_MAX; uvy[i] = -uvy[i];}
-
- int index = H_RES*(int)uy[i]+(int)ux[i];
- im_line_va[index] = 1;
- }
- for (int i = 0; i < 8; i++) {
- im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 0;
- }
- for (int i = 0; i < fs; i++) {
- im_line_va[H_RES*(SY_MAX+6)+2*(int)i+SX_MIN] = 1;
- }
- fdeath_ticker--;
- if (fdeath_ticker < 0) fs -= 0.0001f;
- if (fs < 0) fs = 0;
-
- return 1;
}
-void dispchr(int x0, int y0, uint8_t* chr) {
- int bmi = 0;
- for(int y = SY_MIN + y0; y < SY_MIN + y0 + 7; y++)
+//void draw_text_buffer()
+//{
+// for(int yc = 0; yc < TY; yc++)
+// {
+// for(int xc = 0; xc < TX; xc++)
+// {
+// draw_vincent(X0 + 10 + 8*xc, Y0 + 10 + 8*yc,
+// text_buffer[TX*yc + xc]%128);
+// }
+// }
+//}
+
+// should the lisp interpreter run?
+int want_lisp = 0;
+
+void backspace()
+{
+ text_buffer[text_buffer_counter] = 0;
+ if(text_buffer_counter > 0)
+ text_buffer_counter--;
+
+ draw_vincent(X0 +2 + 8*char_col, Y0 + 14 + 8*char_row, ' ');
+ if(char_col > 0)
+ char_col--;
+ else
{
- for(int x = SX_MIN + x0; x < SX_MIN + x0 + 6; x++)
- {
- im_line_va[H_RES*y + x] = chr[bmi];
- bmi++;
- }
+ char_row--;
+ char_col = TX - 1;
}
}
-void dispsprite(int x0, int y0, uint8_t* chr) {
- int bmi = 0;
- for(int y = SY_MIN + y0; y < SY_MIN + y0 + 8; y++)
+void clear_all_text()
+{
+ char_col = 0;
+ char_row = 0;
+ clr_text_buff();
+ clr();
+ // startup animation
+ int miter_x_final = XL/2 + 20*cos(.11f*MAX(XL,YL)) + 80;
+ int miter_y_final = YL/2 + 20*sin(.11f*MAX(XL,YL)) + 80;
+
+ int x_correct = -miter_x_final + X0 + 6;
+ int y_correct = -miter_y_final + Y0;
+ for(int i = MAX(XL,YL) - 1; i < MAX(XL,YL); i++)
{
- for(int x = SX_MIN + x0; x < SX_MIN + x0 + 7; x++)
+ wait_us(10000);
+ clr();
+ int xp = MIN(XL,i);
+ int yp = MIN(YL,i);
+ draw_line(X0, Y0, X0 + xp, Y0);
+ draw_line(X0+xp,Y0,X0+xp,Y0+yp);
+
+ draw_line(X0, Y0+yp, X0 +xp, Y0+yp);
+ draw_line(X0,Y0,X0,Y0+yp);
+ float phase = (float)(i) / (float)MAX(XL,YL);
+ draw_miters_at(xp/2 + 20*cos(.11f*i) + 80 + (x_correct * phase),yp/2 + 20*sin(.11f*i) + 80 + (y_correct * phase));
+ //draw_vincent(100,100,15);
+ }
+
+ // draw prompt
+ draw_vincent_string(">");
+}
+
+void set_status_string(char* str)
+{
+ uint8_t char_col_backup = char_col;
+ uint8_t char_row_backup = char_row;
+ char_col = 0;
+ char_row = TY - 1;
+
+ draw_vincent_string(str);
+
+ char_col = char_col_backup;
+ char_row = char_row_backup;
+}
+
+// on each serial char received
+void serial_callback()
+{
+ // get characeter and store in text_buffer
+ char new_char = pc.getc();
+ most_recent_char = new_char;
+
+ if(new_char == '^')
+ {
+ want_gfx = 1;
+ return;
+ }
+ //char cn[8];
+ //sprintf(cn,"[%d]",new_char);
+ //draw_vincent_string(cn);
+ if(new_char == 127)
+ {
+ backspace();
+ return;
+ }
+
+ text_buffer[text_buffer_counter++] = new_char;
+
+ // if it's <enter>, request lisp
+ if(new_char == 13)
+ {
+ want_lisp = 1;
+ return;
+ }
+
+
+ // increment rows/cols as needed
+ char_col++;
+ if(char_col >= TX)
+ {
+ char_col = 0;
+ char_row++;
+ }
+ if(char_row >= TY)
+ {
+ char_row = 0;
+ }
+
+ // draw new character
+ draw_vincent(X0 +2 + 8*char_col, Y0 + 14 + 8*char_row,
+ new_char%128);
+
+}
+
+void spin_for_a_while(volatile int a)
+{
+ volatile int k = a;
+ for(int i = 0; i < k; i++)
+ {
+ for(int j = 0; j < k; j++)
{
- if (chr[bmi]) im_line_va[H_RES*y + x] = chr[bmi];
- bmi++;
+ a++;
}
}
}
-void disp_tunnel() {
- for (int y = SY_MIN; y < SY_MAX; y++) {
- int tunw = 30 * (y) / TUN_LEN;
- int yy = SY_MAX-(SY_MAX-y)*3/4;
- for (int x = SX_MIN; x < SX_MIN + tunnel[y - SY_MIN]; x++) im_line_va[H_RES*yy+x] = (x&1)^(y&1);
- for (int x = SX_MIN + tunnel[y - SY_MIN]; x < SX_MIN + tunnel[y - SY_MIN] + tunw; x++) im_line_va[H_RES*yy+x] = 0;
- for (int x = SX_MIN + tunnel[y - SY_MIN] + tunw; x < SX_MAX; x++) im_line_va[H_RES*yy+x] = (x&1)^(y&1);
- }
+uint8_t gfx_is_init = 0;
+
+// screen goes from -.5 to .5 on both axes
+void draw_gfx_line(float x0, float y0, float x1, float y1)
+{
+ float x_width = (XL);
+ float y_height = (YL);
+
+ // want to rescale to 0 to 1
+ x0 += 0.5f;
+ y0 += 0.5f;
+
+ x1 += 0.5f;
+ y1 += 0.5f;
+ //printf("x0: %.3f, y0: %.3f\r\n",x0,y0);
+ int xx = x0 * x_width + X0;
+ if(xx > (X0 + XL)) xx = (X0 + XL);
+ if(xx < X0) xx = X0;
+ int yy = y0 * y_height + Y0;
+ if(yy > (Y0 + YL)) yy = (Y0 + YL);
+ if(yy < Y0) yy = Y0;
+
+ int xx1 = x1 * x_width + X0;
+ if(xx1 > (X0 + XL)) xx1 = (X0 + XL);
+ if(xx1 < X0) xx1 = X0;
+ int yy1 = y1 * y_height + Y0;
+ if(yy1 > (Y0 + YL)) yy1 = (Y0 + YL);
+ if(yy1 < Y0) yy1 = Y0;
+
+ draw_line(xx,yy,xx1,yy1);
+
}
-
-void init_tunnel() {
- for (int i = 0; i < TUN_LEN; i++) tunnel[i] = 20;
- disp_tunnel();
+//void swap_buffers()
+//{
+// if(im_line_va == im_line_va_1)
+// im_line_va = im_line_va_2;
+// else
+// im_line_va = im_line_va_1;
+//}
+int main()
+{
+ im_line_va = im_line_va_1;
+ // init serial
+ pc.baud(115200);
+ pc.attach(&serial_callback);
+ pc.printf("derp!\r\n");
+
+ // init buffers
+ init_buffers();
+ // init timer
+ t.attach_us(&isr,64);
- int bmi = 0;
+ wait_us(200000);
+ int miter_x_final = XL/2 + 20*cos(.11f*MAX(XL,YL)) + 80;
+ int miter_y_final = YL/2 + 20*sin(.11f*MAX(XL,YL)) + 80;
+ int x_correct = -miter_x_final + X0 + 6;
+ int y_correct = -miter_y_final + Y0;
- for(int y = SY_MIN; y < SY_MIN + BY; y++)
+ for(int i = 0; i < MAX(XL,YL); i+=3)
{
- for(int x = SX_MIN; x < SX_MIN + BX; x++)
- {
- im_line_va[H_RES*y + x + 10] = tv[bmi];
- bmi++;
- }
- }
- dispsprite(1,2,sprite_tree);
- dispsprite(50,2,sprite_tree);
- dispsprite(11,2,sprite_tree);
-}
-
-void update_tunnel() {
- for (int j = TUN_LEN-1; j > 0; j--) tunnel[j] = tunnel[j-1];
-
- int x = rand() % 48;
- if (x == 0) tundir = -tundir;
- if (x > 24) tunnel[0] = tunnel[0]+tundir;
-
- if (tunnel[0] < 1) {
- tunnel[0] = 1;
- tundir = 1;
- }
- if (SX_MIN + tunnel[0] + 30 + 1 > SX_MAX) {
- tunnel[0] = SX_MAX-SX_MIN-30-1;
- tundir = -1;
+ char stat_buff[30];
+ sprintf(stat_buff,"f: %d",i);
+ set_status_string(stat_buff);
+ //wait_us(10000);
+
+ spin_for_a_while(200);
+ clr();
+ int xp = MIN(XL,i);
+ int yp = MIN(YL,i);
+ draw_line(X0, Y0, X0 + xp, Y0);
+ draw_line(X0+xp,Y0,X0+xp,Y0+yp);
+
+ draw_line(X0, Y0+yp, X0 +xp, Y0+yp);
+ draw_line(X0,Y0,X0,Y0+yp);
+ float phase = (float)(i) / (float)MAX(XL,YL);
+ draw_miters_at(xp/2 + 20*cos(.11f*i) + 80 + (x_correct * phase),yp/2 + 20*sin(.11f*i) + 80 + (y_correct * phase));
+ //draw_vincent(100,100,15);
}
- disp_tunnel();
-
- int cmd1 = p1_in.read();
- int cmd2 = p2_in.read();
- if (cmd1) tunnp+=1.0f;
- if (cmd2) tunnp-=1.0f;
- if (tunnp<SX_MIN+8) tunnp = SX_MIN+8;
- if (tunnp>SX_MAX-8) tunnp = SX_MAX-8;
- leg_ctr++;
- if (leg_ctr == 50) leg_ctr = 0;
- if (leg_ctr < 25) dispsprite((int)(tunnp-SX_MIN), 31, sprite_manl);
- else dispsprite((int)(tunnp-SX_MIN), 31, sprite_manr);
-
- wait(0.01);
-}
-
-void update_rc() {
- int cmd1 = p1_in.read();
- int cmd2 = p2_in.read();
- if (!cmd1) {
- float oldDirX = dirX;
- dirX = dirX * rc_cos - dirY * rc_sin;
- dirY = oldDirX * rc_sin + dirY * rc_cos;
- float oldPlaneX = planeX;
- planeX = planeX * rc_cos - planeY * rc_sin;
- planeY = oldPlaneX * rc_sin + planeY * rc_cos;
- }
- if (!cmd2) {
- float oldDirX = dirX;
- dirX = dirX * rc_cos + dirY * rc_sin;
- dirY = -oldDirX * rc_sin + dirY * rc_cos;
- float oldPlaneX = planeX;
- planeX = planeX * rc_cos + planeY * rc_sin;
- planeY = -oldPlaneX * rc_sin + planeY * rc_cos;
- }
- if(worldMap[int(posX + dirX * 0.01f)][int(posY)] == false) posX += dirX * 0.01f;
- if(worldMap[int(posX)][int(posY + dirY * 0.01f)] == false) posY += dirY * 0.01f;
-
- int w = SX_MAX-SX_MIN;
- int h = SY_MAX-SY_MIN;
- for (int x = 0; x < SX_MAX - SX_MIN; x++) {
- float cameraX = 2 * x / float(w) - 1; //x-coordinate in camera space
- float rayPosX = posX;
- float rayPosY = posY;
- float rayDirX = dirX + planeX * cameraX;
- float rayDirY = dirY + planeY * cameraX;
-
- int mapX = int(rayPosX);
- int mapY = int(rayPosY);
-
- float sideDistX, sideDistY;
-
- float deltaDistX = sqrtf(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
- float deltaDistY = sqrtf(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
- float perpWallDist;
-
- int stepX, stepY;
- int hit = 0, side;
- if (rayDirX < 0) {
- stepX = -1;
- sideDistX = (rayPosX - mapX) * deltaDistX;
- } else {
- stepX = 1;
- sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
- }
- if (rayDirY < 0) {
- stepY = -1;
- sideDistY = (rayPosY - mapY) * deltaDistY;
- } else {
- stepY = 1;
- sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
+ clear_all_text();
+ draw_vincent_string("Welcome to LISP MACHINE");
+ new_line();
+ draw_vincent_string("Connect over USB serial");
+ new_line();
+ draw_vincent_string("115200 baud");
+ new_line();
+ draw_vincent_string("use 'clear' to clear");
+ new_line();
+ draw_vincent_string("use '^' to use 3D MODE");
+ new_line();
+ draw_vincent_string(">");
+ // main loop
+ for(;;)
+ {
+ if(want_lisp)
+ {
+ new_line();
+ // runs interpreter and prints answer
+// run_lisp(text_buffer);
+// want_lisp = 0;
+// new_line();
+// clr_text_buff();
+ //draw_vincent_string(">");
}
- while (hit == 0)
+ if(want_gfx)
{
- //jump to next map square, OR in x-direction, OR in y-direction
- if (sideDistX < sideDistY)
- {
- sideDistX += deltaDistX;
- mapX += stepX;
- side = 0;
- }
- else
+ if(!gfx_is_init)
{
- sideDistY += deltaDistY;
- mapY += stepY;
- side = 1;
- }
- //Check if ray has hit a wall
- if (worldMap[mapX][mapY] > 0) hit = 1;
- }
- //Calculate distance projected on camera direction (oblique distance will give fisheye effect!)
- if (side == 0) perpWallDist = (mapX - rayPosX + (1 - stepX) / 2) / rayDirX;
- else perpWallDist = (mapY - rayPosY + (1 - stepY) / 2) / rayDirY;
-
- //Calculate height of line to draw on screen
- int drawStart,drawEnd;
- int lineHeight = (int)(h / perpWallDist);
- if (lineHeight > h) {
- drawStart = 0;
- drawEnd = h;
- } else {
- drawStart = -lineHeight / 2 + h / 2;
- drawEnd = lineHeight / 2 + h / 2;
- }
- if (side == 0) {
- for(int y = 0; y < drawStart; y++) {
- im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0;
- }
- for(int y = drawStart;y < drawEnd;y++) {
- im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 1;
- }
- for(int y = drawEnd; y < h; y++) {
- im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0;
- }
- } else {
- for(int y = 0; y < h; y++) im_line_va[H_RES*(y+SY_MIN)+x+SX_MIN] = 0;
- im_line_va[H_RES*(drawStart+SY_MIN)+x+SX_MIN] = 1;
- im_line_va[H_RES*(drawEnd-1+SY_MIN)+x+SX_MIN] = 1;
+ init_gfx();
+ gfx_is_init = 1;
+ }
+ new_frame(most_recent_char);
+ most_recent_char = '0';
+ spin_for_a_while(100);
+ clr();
+ draw_line(X0, Y0, X0 + XL, Y0);
+ draw_line(X0+XL,Y0,X0+XL,Y0+YL);
+ draw_line(X0, Y0+YL, X0 +XL, Y0+YL);
+ draw_line(X0,Y0,X0,Y0+YL);
+ //draw_gfx_line(-0.01,-0.01,0.01,0.01);
+
+ set_status_string(get_gfx_stat());
+ //swap_buffers();
+
}
}
}
-void update_m7() {
- int w = SX_MAX-SX_MIN;
- int h = SY_MAX-SY_MIN;
- float c = cosf(m7_theta);
- float s = sinf(m7_theta);
- for (int y = 0; y < h; y++) {
- for (int x = 0; x < w; x++) {
- float xx, yy;
- yy = y;
- xx = (x-w/2)*(h-yy)/h+w/2;
- xx = xx * (float) mapWidth / w - m7_x;
- yy = yy * (float) mapHeight / h - 2*m7_y;
-
- float xx_old = xx;
- float yy_old = yy;
- xx = xx_old*c-yy_old*s;
- yy = xx_old*s+yy_old*c;
- xx *= 1.0f;
- yy *= 1.0f;
-
- xx += m7_x;
- yy += m7_y;
-
- if (xx < 0 || xx >= mapWidth+1 || yy < 0 || yy > mapHeight+1) {
- im_line_va[H_RES*(SY_MIN+y)+x+SX_MIN] = 0;
- } else if (worldMap[(int)yy][(int)xx] == 0) {
- im_line_va[H_RES*(SY_MIN+y)+x+SX_MIN] = 0;
- } else {
- im_line_va[H_RES*(SY_MIN+y)+x+SX_MIN] = 1;
- }
- }
- }
- int cmd1 = p1_in.read();
- int cmd2 = p2_in.read();
- if (!cmd1) m7_theta+=0.03f;
- if (!cmd2) m7_theta-=0.03f;
-}
-
-int main() {
- potato:
- init_buffers();
- t.attach_us(&isr,63);
-
- //for(;;){update_m7();}
-
- int bmi = 0;
-
- for(int y = SY_MIN; y < SY_MIN + BY2; y++)
- {
- for(int x = SX_MIN; x < SX_MIN + BX; x++)
- {
- im_line_va[H_RES*y + x] = miters[bmi];
- bmi++;
- }
- }
-
- int cursor_pos = 0;
- int menu_offs = 0;
-
- for (;;) {
- int cmd1 = p1_in.read();
- int cmd2 = p2_in.read();
-
- int cursor_x = SX_MIN;
- int cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5;
-
- if (cmd1 || cmd2) im_line_va[H_RES*cursor_y+cursor_x] = 0;
-
- if (!cmd1) cursor_pos++;
- if (!cmd2) cursor_pos--;
- if (!cmd1 && !cmd2) break;
-
- if (cursor_pos < 0) cursor_pos = 0;
- if (cursor_pos > 4) cursor_pos = 4;
- if (cursor_pos > 3) menu_offs = cursor_pos - 3; else menu_offs = 0;
-
- cursor_x = SX_MIN;
- if (cursor_pos < 4) cursor_y = SY_MIN + 8*cursor_pos + BY2 + 5;
- else cursor_y = SY_MIN + 8*3 + BY2 + 5;
-
- for(int y = 0; y < 4; y++) {
- for(int x = 0; x < 4; x++) {
- dispchr(4+7*x,BY2+1+8*y,menu[4*(y+menu_offs)+x]);
- }
- }
-
- im_line_va[H_RES*cursor_y+cursor_x] = 1;
-
- wait(0.1);
- }
-
- init_buffers();
-
- if (cursor_pos == 0) {
- for (;;) {
- if (!flappy_pong()) break;
- }
- } else if (cursor_pos == 1) {
- for (;;) fishy();
- } else if (cursor_pos == 2) {
- for (;;) update_image();
- } else if (cursor_pos == 3) {
- init_tunnel();
- for (;;)
- {
- update_tunnel();
- }
- } else if (cursor_pos == 4) {
- for (;;) {
- update_rc();
- }
- }
- goto potato;
-}
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Sat Mar 10 05:09:55 2018 +0000 @@ -0,0 +1,8 @@ +#ifndef _mainh +#define _mainh + +void draw_vincent_string(char* str); +void new_line(); +void clear_all_text(); +void draw_gfx_line(float x0, float y0, float x1, float y1); +#endif \ No newline at end of file
