Bayley Wang
/
manworm_tv_raster
cube
Fork of manworm_tv_gpu by
main.cpp@12:e99cc1e9d928, 2018-05-04 (annotated)
- Committer:
- dicarloj
- Date:
- Fri May 04 01:45:05 2018 +0000
- Revision:
- 12:e99cc1e9d928
- Parent:
- 11:537cde55b27f
- Child:
- 13:9cf720873bf6
lol it works;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dicarloj | 0:7757ab3f7206 | 1 | #include "mbed.h" |
dicarloj | 0:7757ab3f7206 | 2 | #include <math.h> |
dicarloj | 9:2a47b9ff8911 | 3 | #include "lisp.h" |
dicarloj | 9:2a47b9ff8911 | 4 | #include "main.h" |
dicarloj | 9:2a47b9ff8911 | 5 | #include "gfx.h" |
dicarloj | 12:e99cc1e9d928 | 6 | #include "face.h" |
dicarloj | 0:7757ab3f7206 | 7 | |
dicarloj | 9:2a47b9ff8911 | 8 | // Resolution, including porches |
dicarloj | 9:2a47b9ff8911 | 9 | #define V_RES 200 |
dicarloj | 9:2a47b9ff8911 | 10 | #define H_RES 300 |
dicarloj | 9:2a47b9ff8911 | 11 | |
dicarloj | 12:e99cc1e9d928 | 12 | #define TEXT_LEVEL 5 |
dicarloj | 12:e99cc1e9d928 | 13 | |
dicarloj | 12:e99cc1e9d928 | 14 | |
dicarloj | 9:2a47b9ff8911 | 15 | |
dicarloj | 9:2a47b9ff8911 | 16 | // old shit |
bwang | 4:02e3ae7a3aea | 17 | #define SX_MIN 30 |
bwang | 4:02e3ae7a3aea | 18 | #define SX_MAX 95 |
bwang | 4:02e3ae7a3aea | 19 | #define SY_MIN 10 |
bwang | 4:02e3ae7a3aea | 20 | #define SY_MAX 48 |
dicarloj | 0:7757ab3f7206 | 21 | #define BX_0 30 |
dicarloj | 0:7757ab3f7206 | 22 | #define BY_0 (V_RES/4 - 15) |
dicarloj | 0:7757ab3f7206 | 23 | #define BX 42 |
dicarloj | 0:7757ab3f7206 | 24 | #define BY 15 |
bwang | 4:02e3ae7a3aea | 25 | #define BY2 9 |
dicarloj | 9:2a47b9ff8911 | 26 | |
dicarloj | 9:2a47b9ff8911 | 27 | // good new stuff |
dicarloj | 9:2a47b9ff8911 | 28 | #define X0 75 // start of image in X |
dicarloj | 9:2a47b9ff8911 | 29 | #define Y0 30 // start of image in Y |
dicarloj | 9:2a47b9ff8911 | 30 | #define XL 220 // 25 chars |
dicarloj | 9:2a47b9ff8911 | 31 | #define YL 165 // 20 chars |
dicarloj | 9:2a47b9ff8911 | 32 | |
dicarloj | 9:2a47b9ff8911 | 33 | #define TX 24 // number of characters in X |
dicarloj | 9:2a47b9ff8911 | 34 | #define TY 18 // number of characters in Y |
dicarloj | 0:7757ab3f7206 | 35 | |
dicarloj | 9:2a47b9ff8911 | 36 | #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) |
dicarloj | 9:2a47b9ff8911 | 37 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
dicarloj | 9:2a47b9ff8911 | 38 | #define MAX(a,b) (((a)>(b))?(a):(b)) |
dicarloj | 9:2a47b9ff8911 | 39 | |
dicarloj | 11:537cde55b27f | 40 | #define N_COLOR 16 |
dicarloj | 11:537cde55b27f | 41 | |
dicarloj | 12:e99cc1e9d928 | 42 | // DAC stuff |
dicarloj | 12:e99cc1e9d928 | 43 | #define DAC_SYNC 2 |
dicarloj | 12:e99cc1e9d928 | 44 | |
dicarloj | 9:2a47b9ff8911 | 45 | uint8_t char_col = 0; // current column counter |
dicarloj | 9:2a47b9ff8911 | 46 | uint8_t char_row = 0; // current row counter |
dicarloj | 9:2a47b9ff8911 | 47 | uint8_t text_buffer_counter = 0; // current index in text buffer counter |
dicarloj | 9:2a47b9ff8911 | 48 | char most_recent_char = '0'; |
dicarloj | 9:2a47b9ff8911 | 49 | |
dicarloj | 12:e99cc1e9d928 | 50 | uint8_t line_intensity = 0; |
dicarloj | 12:e99cc1e9d928 | 51 | int8_t line_dir = 1; |
dicarloj | 12:e99cc1e9d928 | 52 | |
dicarloj | 9:2a47b9ff8911 | 53 | char text_buffer[TX*TY]; // input text buffer for lisp |
dicarloj | 9:2a47b9ff8911 | 54 | |
dicarloj | 12:e99cc1e9d928 | 55 | AnalogIn joy1(A1); |
dicarloj | 12:e99cc1e9d928 | 56 | AnalogIn joy2(A0); |
dicarloj | 11:537cde55b27f | 57 | |
dicarloj | 9:2a47b9ff8911 | 58 | uint8_t want_gfx = 0; |
dicarloj | 10:1163fb31b0a7 | 59 | uint8_t vsync = 0; |
dicarloj | 9:2a47b9ff8911 | 60 | |
dicarloj | 9:2a47b9ff8911 | 61 | Serial pc(USBTX, USBRX); |
dicarloj | 0:7757ab3f7206 | 62 | |
dicarloj | 9:2a47b9ff8911 | 63 | // font |
dicarloj | 9:2a47b9ff8911 | 64 | char vincent_data[128][8] = { |
dicarloj | 9:2a47b9ff8911 | 65 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 66 | { 0x00, 0x3E, 0x41, 0x55, 0x41, 0x55, 0x49, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 67 | { 0x00, 0x3E, 0x7F, 0x6B, 0x7F, 0x6B, 0x77, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 68 | { 0x00, 0x22, 0x77, 0x7F, 0x7F, 0x3E, 0x1C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 69 | { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x1C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 70 | { 0x00, 0x08, 0x1C, 0x2A, 0x7F, 0x2A, 0x08, 0x1C }, |
dicarloj | 9:2a47b9ff8911 | 71 | { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x3E, 0x08, 0x1C }, |
dicarloj | 9:2a47b9ff8911 | 72 | { 0x00, 0x00, 0x1C, 0x3E, 0x3E, 0x3E, 0x1C, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 73 | { 0xFF, 0xFF, 0xE3, 0xC1, 0xC1, 0xC1, 0xE3, 0xFF }, |
dicarloj | 9:2a47b9ff8911 | 74 | { 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 75 | { 0xFF, 0xFF, 0xE3, 0xDD, 0xDD, 0xDD, 0xE3, 0xFF }, |
dicarloj | 9:2a47b9ff8911 | 76 | { 0x00, 0x0F, 0x03, 0x05, 0x39, 0x48, 0x48, 0x30 }, |
dicarloj | 9:2a47b9ff8911 | 77 | { 0x00, 0x08, 0x3E, 0x08, 0x1C, 0x22, 0x22, 0x1C }, |
dicarloj | 9:2a47b9ff8911 | 78 | { 0x00, 0x18, 0x14, 0x10, 0x10, 0x30, 0x70, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 79 | { 0x00, 0x0F, 0x19, 0x11, 0x13, 0x37, 0x76, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 80 | { 0x00, 0x08, 0x2A, 0x1C, 0x77, 0x1C, 0x2A, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 81 | { 0x00, 0x60, 0x78, 0x7E, 0x7F, 0x7E, 0x78, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 82 | { 0x00, 0x03, 0x0F, 0x3F, 0x7F, 0x3F, 0x0F, 0x03 }, |
dicarloj | 9:2a47b9ff8911 | 83 | { 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 84 | { 0x00, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 85 | { 0x00, 0x3F, 0x65, 0x65, 0x3D, 0x05, 0x05, 0x05 }, |
dicarloj | 9:2a47b9ff8911 | 86 | { 0x00, 0x0C, 0x32, 0x48, 0x24, 0x12, 0x4C, 0x30 }, |
dicarloj | 9:2a47b9ff8911 | 87 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F }, |
dicarloj | 9:2a47b9ff8911 | 88 | { 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x2A, 0x1C, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 89 | { 0x00, 0x08, 0x1C, 0x3E, 0x7F, 0x1C, 0x1C, 0x1C }, |
dicarloj | 9:2a47b9ff8911 | 90 | { 0x00, 0x1C, 0x1C, 0x1C, 0x7F, 0x3E, 0x1C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 91 | { 0x00, 0x08, 0x0C, 0x7E, 0x7F, 0x7E, 0x0C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 92 | { 0x00, 0x08, 0x18, 0x3F, 0x7F, 0x3F, 0x18, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 93 | { 0x00, 0x00, 0x00, 0x70, 0x70, 0x70, 0x7F, 0x7F }, |
dicarloj | 9:2a47b9ff8911 | 94 | { 0x00, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 95 | { 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x3E, 0x7F, 0x7F }, |
dicarloj | 9:2a47b9ff8911 | 96 | { 0x00, 0x7F, 0x7F, 0x3E, 0x3E, 0x1C, 0x1C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 97 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 98 | { 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 99 | { 0x00, 0x36, 0x36, 0x14, 0x00, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 100 | { 0x00, 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36 }, |
dicarloj | 9:2a47b9ff8911 | 101 | { 0x00, 0x08, 0x1E, 0x20, 0x1C, 0x02, 0x3C, 0x08 }, |
dicarloj | 9:2a47b9ff8911 | 102 | { 0x00, 0x60, 0x66, 0x0C, 0x18, 0x30, 0x66, 0x06 }, |
dicarloj | 9:2a47b9ff8911 | 103 | { 0x00, 0x3C, 0x66, 0x3C, 0x28, 0x65, 0x66, 0x3F }, |
dicarloj | 9:2a47b9ff8911 | 104 | { 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 105 | { 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 106 | { 0x00, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06 }, |
dicarloj | 9:2a47b9ff8911 | 107 | { 0x00, 0x00, 0x36, 0x1C, 0x7F, 0x1C, 0x36, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 108 | { 0x00, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 109 | { 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 110 | { 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 111 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 112 | { 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 113 | { 0x00, 0x3C, 0x66, 0x6E, 0x76, 0x66, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 114 | { 0x00, 0x18, 0x18, 0x38, 0x18, 0x18, 0x18, 0x7E }, |
dicarloj | 9:2a47b9ff8911 | 115 | { 0x00, 0x3C, 0x66, 0x06, 0x0C, 0x30, 0x60, 0x7E }, |
dicarloj | 9:2a47b9ff8911 | 116 | { 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 117 | { 0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x7E, 0x0C, 0x0C }, |
dicarloj | 9:2a47b9ff8911 | 118 | { 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 119 | { 0x00, 0x3C, 0x66, 0x60, 0x7C, 0x66, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 120 | { 0x00, 0x7E, 0x66, 0x0C, 0x0C, 0x18, 0x18, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 121 | { 0x00, 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 122 | { 0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 123 | { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 124 | { 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30 }, |
dicarloj | 9:2a47b9ff8911 | 125 | { 0x00, 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06 }, |
dicarloj | 9:2a47b9ff8911 | 126 | { 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 127 | { 0x00, 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 128 | { 0x00, 0x3C, 0x66, 0x06, 0x1C, 0x18, 0x00, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 129 | { 0x00, 0x38, 0x44, 0x5C, 0x58, 0x42, 0x3C, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 130 | { 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 131 | { 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C }, |
dicarloj | 9:2a47b9ff8911 | 132 | { 0x00, 0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 133 | { 0x00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7C }, |
dicarloj | 9:2a47b9ff8911 | 134 | { 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E }, |
dicarloj | 9:2a47b9ff8911 | 135 | { 0x00, 0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 136 | { 0x00, 0x3C, 0x66, 0x60, 0x60, 0x6E, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 137 | { 0x00, 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 138 | { 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 139 | { 0x00, 0x1E, 0x0C, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 }, |
dicarloj | 9:2a47b9ff8911 | 140 | { 0x00, 0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 141 | { 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E }, |
dicarloj | 9:2a47b9ff8911 | 142 | { 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x63, 0x63, 0x63 }, |
dicarloj | 9:2a47b9ff8911 | 143 | { 0x00, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63 }, |
dicarloj | 9:2a47b9ff8911 | 144 | { 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 145 | { 0x00, 0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 146 | { 0x00, 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x06 }, |
dicarloj | 9:2a47b9ff8911 | 147 | { 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 148 | { 0x00, 0x3C, 0x66, 0x60, 0x3C, 0x06, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 149 | { 0x00, 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 150 | { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 151 | { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 152 | { 0x00, 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63 }, |
dicarloj | 9:2a47b9ff8911 | 153 | { 0x00, 0x63, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x63 }, |
dicarloj | 9:2a47b9ff8911 | 154 | { 0x00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 155 | { 0x00, 0x7E, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x7E }, |
dicarloj | 9:2a47b9ff8911 | 156 | { 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E }, |
dicarloj | 9:2a47b9ff8911 | 157 | { 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 158 | { 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78 }, |
dicarloj | 9:2a47b9ff8911 | 159 | { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 160 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F }, |
dicarloj | 9:2a47b9ff8911 | 161 | { 0x00, 0x0C, 0x0C, 0x06, 0x00, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 162 | { 0x00, 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 163 | { 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C }, |
dicarloj | 9:2a47b9ff8911 | 164 | { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 165 | { 0x00, 0x06, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 166 | { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 167 | { 0x00, 0x1C, 0x36, 0x30, 0x30, 0x7C, 0x30, 0x30 }, |
dicarloj | 9:2a47b9ff8911 | 168 | { 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 169 | { 0x00, 0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 170 | { 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 171 | { 0x00, 0x0C, 0x00, 0x0C, 0x0C, 0x6C, 0x6C, 0x38 }, |
dicarloj | 9:2a47b9ff8911 | 172 | { 0x00, 0x60, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 173 | { 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 174 | { 0x00, 0x00, 0x00, 0x63, 0x77, 0x7F, 0x6B, 0x6B }, |
dicarloj | 9:2a47b9ff8911 | 175 | { 0x00, 0x00, 0x00, 0x7C, 0x7E, 0x66, 0x66, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 176 | { 0x00, 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 177 | { 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 178 | { 0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x3C, 0x0D, 0x0F }, |
dicarloj | 9:2a47b9ff8911 | 179 | { 0x00, 0x00, 0x00, 0x7C, 0x66, 0x66, 0x60, 0x60 }, |
dicarloj | 9:2a47b9ff8911 | 180 | { 0x00, 0x00, 0x00, 0x3E, 0x40, 0x3C, 0x02, 0x7C }, |
dicarloj | 9:2a47b9ff8911 | 181 | { 0x00, 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 182 | { 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 183 | { 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3C, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 184 | { 0x00, 0x00, 0x00, 0x63, 0x6B, 0x6B, 0x6B, 0x3E }, |
dicarloj | 9:2a47b9ff8911 | 185 | { 0x00, 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66 }, |
dicarloj | 9:2a47b9ff8911 | 186 | { 0x00, 0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 187 | { 0x00, 0x00, 0x00, 0x3C, 0x0C, 0x18, 0x30, 0x3C }, |
dicarloj | 9:2a47b9ff8911 | 188 | { 0x00, 0x0E, 0x18, 0x18, 0x30, 0x18, 0x18, 0x0E }, |
dicarloj | 9:2a47b9ff8911 | 189 | { 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18 }, |
dicarloj | 9:2a47b9ff8911 | 190 | { 0x00, 0x70, 0x18, 0x18, 0x0C, 0x18, 0x18, 0x70 }, |
dicarloj | 9:2a47b9ff8911 | 191 | { 0x00, 0x00, 0x00, 0x3A, 0x6C, 0x00, 0x00, 0x00 }, |
dicarloj | 9:2a47b9ff8911 | 192 | { 0x00, 0x08, 0x1C, 0x36, 0x63, 0x41, 0x41, 0x7F } |
dicarloj | 9:2a47b9ff8911 | 193 | }; |
dicarloj | 9:2a47b9ff8911 | 194 | |
dicarloj | 9:2a47b9ff8911 | 195 | DigitalOut sout(D8); //sync PA_9 |
dicarloj | 9:2a47b9ff8911 | 196 | DigitalOut vout(D7); //video PA_8 |
dicarloj | 9:2a47b9ff8911 | 197 | |
dicarloj | 12:e99cc1e9d928 | 198 | DigitalOut dac0(PA_4); |
dicarloj | 12:e99cc1e9d928 | 199 | DigitalOut dac1(PA_5); |
dicarloj | 12:e99cc1e9d928 | 200 | DigitalOut dac2(PA_6); |
dicarloj | 12:e99cc1e9d928 | 201 | DigitalOut dac3(PA_7); |
dicarloj | 12:e99cc1e9d928 | 202 | |
dicarloj | 9:2a47b9ff8911 | 203 | // trigger horizontal line draw |
dicarloj | 0:7757ab3f7206 | 204 | Ticker t; |
dicarloj | 9:2a47b9ff8911 | 205 | |
dicarloj | 0:7757ab3f7206 | 206 | uint8_t draw_line_inv = 0; |
dicarloj | 9:2a47b9ff8911 | 207 | |
dicarloj | 9:2a47b9ff8911 | 208 | // miters logo bitmap |
dicarloj | 0:7757ab3f7206 | 209 | uint8_t miters[] = { |
dicarloj | 0:7757ab3f7206 | 210 | 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, |
dicarloj | 0:7757ab3f7206 | 211 | 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, |
dicarloj | 0:7757ab3f7206 | 212 | 1,1,0,0,1,1,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,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 213 | 1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 214 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 215 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0, |
dicarloj | 0:7757ab3f7206 | 216 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0, |
dicarloj | 0:7757ab3f7206 | 217 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 218 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 219 | 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,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 220 | 0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 221 | 1,1,1,1,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,1,0,0,0,1,1,0,1,1,0,1,1,0,1,1,0,0,0,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 222 | 1,0,1,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 223 | 1,0,1,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 224 | 1,0,1,0,1,0,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 225 | |
dicarloj | 0:7757ab3f7206 | 226 | }; |
dicarloj | 0:7757ab3f7206 | 227 | |
dicarloj | 0:7757ab3f7206 | 228 | |
bwang | 3:d9edc0575aa3 | 229 | |
bwang | 3:d9edc0575aa3 | 230 | |
bwang | 3:d9edc0575aa3 | 231 | |
dicarloj | 9:2a47b9ff8911 | 232 | uint8_t bl_line_s[H_RES]; //blank line sync buffer |
dicarloj | 9:2a47b9ff8911 | 233 | uint8_t bl_line_v[H_RES]; //blank line video buffer |
dicarloj | 9:2a47b9ff8911 | 234 | uint8_t vb_line_s[H_RES]; //vertical sync, sync buffer |
dicarloj | 9:2a47b9ff8911 | 235 | uint8_t vb_line_v[H_RES]; //vertical sync, video buffer |
dicarloj | 9:2a47b9ff8911 | 236 | uint8_t im_line_s[H_RES]; //image sync buffer |
dicarloj | 9:2a47b9ff8911 | 237 | uint8_t im_line_va_1[H_RES*V_RES]; |
dicarloj | 9:2a47b9ff8911 | 238 | uint8_t im_line_va_2[H_RES*V_RES]; |
dicarloj | 9:2a47b9ff8911 | 239 | uint8_t* im_line_va; // active image buff |
dicarloj | 9:2a47b9ff8911 | 240 | //uint8_t im_line_va[H_RES*V_RES]; //image video buffer |
bwang | 6:0a34891a82c7 | 241 | |
dicarloj | 0:7757ab3f7206 | 242 | uint16_t l=0; //current line of scan |
dicarloj | 0:7757ab3f7206 | 243 | |
dicarloj | 9:2a47b9ff8911 | 244 | // positive or negative? |
dicarloj | 9:2a47b9ff8911 | 245 | int16_t sign(int16_t a) |
bwang | 6:0a34891a82c7 | 246 | { |
dicarloj | 9:2a47b9ff8911 | 247 | if(a > 0) return 1; |
dicarloj | 9:2a47b9ff8911 | 248 | if(a < 0) return -1; |
dicarloj | 9:2a47b9ff8911 | 249 | return 0; |
dicarloj | 0:7757ab3f7206 | 250 | } |
dicarloj | 0:7757ab3f7206 | 251 | |
dicarloj | 9:2a47b9ff8911 | 252 | // clear the text buffer |
dicarloj | 9:2a47b9ff8911 | 253 | void clr_text_buff() |
dicarloj | 9:2a47b9ff8911 | 254 | { |
dicarloj | 9:2a47b9ff8911 | 255 | text_buffer_counter = 0; |
dicarloj | 9:2a47b9ff8911 | 256 | for(int i = 0; i < TX*TY; i++) |
dicarloj | 9:2a47b9ff8911 | 257 | text_buffer[i] = 0; |
dicarloj | 9:2a47b9ff8911 | 258 | } |
dicarloj | 9:2a47b9ff8911 | 259 | |
dicarloj | 9:2a47b9ff8911 | 260 | // clear the screen and the text buffer |
bwang | 3:d9edc0575aa3 | 261 | void clr() |
bwang | 3:d9edc0575aa3 | 262 | { |
bwang | 3:d9edc0575aa3 | 263 | for(int i = 0; i < H_RES; i++) |
bwang | 3:d9edc0575aa3 | 264 | for(int j = 0; j < V_RES; j++) |
bwang | 3:d9edc0575aa3 | 265 | im_line_va[i+j*H_RES] = 0; |
dicarloj | 9:2a47b9ff8911 | 266 | |
dicarloj | 9:2a47b9ff8911 | 267 | clr_text_buff(); |
bwang | 3:d9edc0575aa3 | 268 | |
bwang | 3:d9edc0575aa3 | 269 | } |
bwang | 3:d9edc0575aa3 | 270 | |
dicarloj | 9:2a47b9ff8911 | 271 | // initialize video buffers |
dicarloj | 0:7757ab3f7206 | 272 | void init_buffers() |
dicarloj | 0:7757ab3f7206 | 273 | { |
dicarloj | 9:2a47b9ff8911 | 274 | clr(); // zero buffers |
dicarloj | 0:7757ab3f7206 | 275 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 276 | { |
dicarloj | 12:e99cc1e9d928 | 277 | im_line_s[i] = DAC_SYNC; |
dicarloj | 12:e99cc1e9d928 | 278 | bl_line_s[i] = DAC_SYNC; |
dicarloj | 0:7757ab3f7206 | 279 | bl_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 280 | vb_line_s[i] = 0; |
dicarloj | 0:7757ab3f7206 | 281 | vb_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 282 | } |
dicarloj | 0:7757ab3f7206 | 283 | im_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 284 | im_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 285 | im_line_s[2] = 0; |
dicarloj | 9:2a47b9ff8911 | 286 | im_line_s[3] = 0; |
dicarloj | 9:2a47b9ff8911 | 287 | |
dicarloj | 9:2a47b9ff8911 | 288 | for(int i = 0; i < 15; i++) |
dicarloj | 9:2a47b9ff8911 | 289 | im_line_s[i] = 0; |
dicarloj | 9:2a47b9ff8911 | 290 | |
dicarloj | 9:2a47b9ff8911 | 291 | |
dicarloj | 0:7757ab3f7206 | 292 | bl_line_s[0] = 0; |
dicarloj | 12:e99cc1e9d928 | 293 | vb_line_s[0] = DAC_SYNC; |
dicarloj | 0:7757ab3f7206 | 294 | bl_line_s[1] = 0; |
dicarloj | 12:e99cc1e9d928 | 295 | vb_line_s[1] = DAC_SYNC; |
dicarloj | 0:7757ab3f7206 | 296 | |
dicarloj | 9:2a47b9ff8911 | 297 | bl_line_s[3] = 0; |
dicarloj | 12:e99cc1e9d928 | 298 | vb_line_s[3] = DAC_SYNC; |
dicarloj | 9:2a47b9ff8911 | 299 | bl_line_s[2] = 0; |
dicarloj | 12:e99cc1e9d928 | 300 | vb_line_s[2] = DAC_SYNC; |
dicarloj | 0:7757ab3f7206 | 301 | } |
dicarloj | 9:2a47b9ff8911 | 302 | |
dicarloj | 9:2a47b9ff8911 | 303 | // video interrupt |
dicarloj | 0:7757ab3f7206 | 304 | void isr() |
dicarloj | 0:7757ab3f7206 | 305 | { |
dicarloj | 0:7757ab3f7206 | 306 | uint8_t nop = 0; //use nops or use wait_us |
dicarloj | 0:7757ab3f7206 | 307 | uint8_t* sptr; //pointer to sync buffer for line |
dicarloj | 0:7757ab3f7206 | 308 | uint8_t* vptr; //pointer to video buffer for line |
dicarloj | 10:1163fb31b0a7 | 309 | if(l < V_RES){ vptr = im_line_va + ((l)*H_RES); sptr = im_line_s; nop = 1; vsync = 0;} //pick line buffers |
dicarloj | 10:1163fb31b0a7 | 310 | else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; } |
dicarloj | 10:1163fb31b0a7 | 311 | else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1; } |
dicarloj | 9:2a47b9ff8911 | 312 | uint16_t lmax = nop?H_RES:12; //number of columns |
dicarloj | 9:2a47b9ff8911 | 313 | for(uint16_t i = 0; i < lmax; i++) //loop over each column |
dicarloj | 0:7757ab3f7206 | 314 | { |
dicarloj | 9:2a47b9ff8911 | 315 | nop = 1; |
dicarloj | 12:e99cc1e9d928 | 316 | GPIOA->ODR = (vptr[i] + sptr[i]) << 4; |
dicarloj | 12:e99cc1e9d928 | 317 | // if(sptr[i]) |
dicarloj | 12:e99cc1e9d928 | 318 | // GPIOA->ODR |= (1 << 9); |
dicarloj | 12:e99cc1e9d928 | 319 | // else |
dicarloj | 12:e99cc1e9d928 | 320 | // GPIOA->ODR &= ~(1 << 9); |
dicarloj | 12:e99cc1e9d928 | 321 | // |
dicarloj | 12:e99cc1e9d928 | 322 | // if(vptr[i]) |
dicarloj | 12:e99cc1e9d928 | 323 | // GPIOA->ODR |= (1 << 8); |
dicarloj | 12:e99cc1e9d928 | 324 | // else |
dicarloj | 12:e99cc1e9d928 | 325 | // GPIOA->ODR &= ~(1 << 8); |
dicarloj | 9:2a47b9ff8911 | 326 | |
dicarloj | 9:2a47b9ff8911 | 327 | |
dicarloj | 0:7757ab3f7206 | 328 | if(nop) //nop delay |
dicarloj | 0:7757ab3f7206 | 329 | { |
dicarloj | 12:e99cc1e9d928 | 330 | 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"); |
dicarloj | 0:7757ab3f7206 | 331 | } |
dicarloj | 9:2a47b9ff8911 | 332 | else {wait_us(1); if(i > 2) i+=1;} //wait delay |
dicarloj | 0:7757ab3f7206 | 333 | } |
dicarloj | 0:7757ab3f7206 | 334 | //move to next line |
dicarloj | 0:7757ab3f7206 | 335 | l++; |
dicarloj | 10:1163fb31b0a7 | 336 | if(l == V_RES) vsync = 1; |
dicarloj | 0:7757ab3f7206 | 337 | if(l > 255) l = 0; |
dicarloj | 0:7757ab3f7206 | 338 | } |
dicarloj | 0:7757ab3f7206 | 339 | |
dicarloj | 9:2a47b9ff8911 | 340 | // draw checkerboard pattern |
dicarloj | 9:2a47b9ff8911 | 341 | void write_test_pattern(int x_in, int y_in,int k) |
dicarloj | 0:7757ab3f7206 | 342 | { |
dicarloj | 9:2a47b9ff8911 | 343 | int x_max = MIN(H_RES,x_in); |
dicarloj | 9:2a47b9ff8911 | 344 | int y_max = MIN(V_RES,y_in); |
dicarloj | 9:2a47b9ff8911 | 345 | |
dicarloj | 9:2a47b9ff8911 | 346 | // x 50 to 245 |
dicarloj | 9:2a47b9ff8911 | 347 | for(int x = 65; x < x_max; x++) |
dicarloj | 9:2a47b9ff8911 | 348 | { |
dicarloj | 9:2a47b9ff8911 | 349 | for(int y = 30; y < y_max; y++) |
dicarloj | 9:2a47b9ff8911 | 350 | { |
dicarloj | 9:2a47b9ff8911 | 351 | im_line_va[y*H_RES + x] = ((y/k)%2)^((x/k)%2); |
dicarloj | 9:2a47b9ff8911 | 352 | } |
dicarloj | 9:2a47b9ff8911 | 353 | } |
dicarloj | 0:7757ab3f7206 | 354 | } |
dicarloj | 0:7757ab3f7206 | 355 | |
dicarloj | 9:2a47b9ff8911 | 356 | // draw miters logo |
dicarloj | 9:2a47b9ff8911 | 357 | void draw_miters_at(int xx, int yy) |
dicarloj | 9:2a47b9ff8911 | 358 | { |
dicarloj | 9:2a47b9ff8911 | 359 | int bmi = 0; |
dicarloj | 9:2a47b9ff8911 | 360 | for(int y = yy; y < BY2+yy; y++) |
dicarloj | 9:2a47b9ff8911 | 361 | { |
dicarloj | 9:2a47b9ff8911 | 362 | for(int x = xx; x < BX+xx; x++) |
dicarloj | 9:2a47b9ff8911 | 363 | { |
dicarloj | 9:2a47b9ff8911 | 364 | im_line_va[H_RES*y + x] = miters[bmi]; |
dicarloj | 9:2a47b9ff8911 | 365 | bmi++; |
dicarloj | 9:2a47b9ff8911 | 366 | } |
dicarloj | 9:2a47b9ff8911 | 367 | } |
dicarloj | 9:2a47b9ff8911 | 368 | } |
dicarloj | 9:2a47b9ff8911 | 369 | |
dicarloj | 9:2a47b9ff8911 | 370 | // draw vertical line |
dicarloj | 0:7757ab3f7206 | 371 | void draw_vert(int16_t y0, int16_t y1, int16_t x0) |
dicarloj | 0:7757ab3f7206 | 372 | { |
dicarloj | 0:7757ab3f7206 | 373 | for(int16_t i = y0; i < y1; i++) |
dicarloj | 12:e99cc1e9d928 | 374 | im_line_va[H_RES*i + x0] = line_intensity; |
dicarloj | 0:7757ab3f7206 | 375 | } |
dicarloj | 0:7757ab3f7206 | 376 | |
dicarloj | 9:2a47b9ff8911 | 377 | // draw horizonal line |
dicarloj | 0:7757ab3f7206 | 378 | void draw_horiz(int16_t x0, int16_t x1, int16_t y0) |
dicarloj | 0:7757ab3f7206 | 379 | { |
dicarloj | 0:7757ab3f7206 | 380 | for(int16_t i = x0; i < x1; i++) |
dicarloj | 12:e99cc1e9d928 | 381 | im_line_va[H_RES*y0 + i] = line_intensity; |
dicarloj | 0:7757ab3f7206 | 382 | } |
dicarloj | 0:7757ab3f7206 | 383 | |
dicarloj | 9:2a47b9ff8911 | 384 | // draw line between points |
dicarloj | 0:7757ab3f7206 | 385 | void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1) |
dicarloj | 0:7757ab3f7206 | 386 | { |
dicarloj | 0:7757ab3f7206 | 387 | if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; } |
dicarloj | 0:7757ab3f7206 | 388 | if(x0 == x1){draw_vert(y0,y1,x0);} |
dicarloj | 0:7757ab3f7206 | 389 | if(y0 == y1){draw_horiz(x0,x1,y0);} |
dicarloj | 0:7757ab3f7206 | 390 | int16_t dx = x1 - x0; |
dicarloj | 0:7757ab3f7206 | 391 | int16_t dy = y1 - y0; |
dicarloj | 0:7757ab3f7206 | 392 | float derr = fabs((float)(dy)/(float)(dx)); |
dicarloj | 0:7757ab3f7206 | 393 | float err = 0.f; |
dicarloj | 0:7757ab3f7206 | 394 | int16_t y = y0; |
dicarloj | 0:7757ab3f7206 | 395 | for(int16_t x = x0; x < x1; x++) |
dicarloj | 0:7757ab3f7206 | 396 | { |
dicarloj | 0:7757ab3f7206 | 397 | //plotxy |
dicarloj | 12:e99cc1e9d928 | 398 | im_line_va[H_RES*y + x] = (!draw_line_inv)?line_intensity:0; |
dicarloj | 0:7757ab3f7206 | 399 | err += derr; |
dicarloj | 0:7757ab3f7206 | 400 | while(err >= 0.5f) |
dicarloj | 0:7757ab3f7206 | 401 | { |
dicarloj | 0:7757ab3f7206 | 402 | y += sign(dy); |
dicarloj | 12:e99cc1e9d928 | 403 | im_line_va[H_RES*y + x] = (!draw_line_inv)?line_intensity:0; |
dicarloj | 0:7757ab3f7206 | 404 | err -= 1.f; |
dicarloj | 0:7757ab3f7206 | 405 | } |
dicarloj | 0:7757ab3f7206 | 406 | } |
dicarloj | 0:7757ab3f7206 | 407 | } |
dicarloj | 0:7757ab3f7206 | 408 | |
dicarloj | 9:2a47b9ff8911 | 409 | // draw letter |
dicarloj | 9:2a47b9ff8911 | 410 | void draw_vincent(uint16_t x0, uint16_t y0, uint8_t c) |
dicarloj | 0:7757ab3f7206 | 411 | { |
dicarloj | 9:2a47b9ff8911 | 412 | if(c == 40) c = 41; |
dicarloj | 9:2a47b9ff8911 | 413 | else if(c == 41) c = 40; |
dicarloj | 9:2a47b9ff8911 | 414 | char* letter = vincent_data[c]; |
dicarloj | 9:2a47b9ff8911 | 415 | for(uint16_t xp = 0; xp < 8; xp++) |
dicarloj | 0:7757ab3f7206 | 416 | { |
dicarloj | 9:2a47b9ff8911 | 417 | for(uint16_t yp = 0; yp < 8; yp++) |
dicarloj | 0:7757ab3f7206 | 418 | { |
dicarloj | 12:e99cc1e9d928 | 419 | im_line_va[H_RES*(yp+y0) + xp + x0] = CHECK_BIT(letter[yp],8-xp)?TEXT_LEVEL:0; |
dicarloj | 0:7757ab3f7206 | 420 | } |
dicarloj | 0:7757ab3f7206 | 421 | } |
dicarloj | 0:7757ab3f7206 | 422 | } |
dicarloj | 0:7757ab3f7206 | 423 | |
dicarloj | 9:2a47b9ff8911 | 424 | // go to new line |
dicarloj | 9:2a47b9ff8911 | 425 | void new_line() |
dicarloj | 9:2a47b9ff8911 | 426 | { |
dicarloj | 9:2a47b9ff8911 | 427 | char_col = 0; |
dicarloj | 9:2a47b9ff8911 | 428 | char_row++; |
dicarloj | 9:2a47b9ff8911 | 429 | if(char_row >= TY) |
dicarloj | 9:2a47b9ff8911 | 430 | { |
dicarloj | 9:2a47b9ff8911 | 431 | char_row = 0; |
bwang | 3:d9edc0575aa3 | 432 | } |
bwang | 3:d9edc0575aa3 | 433 | } |
bwang | 3:d9edc0575aa3 | 434 | |
dicarloj | 9:2a47b9ff8911 | 435 | // draw string |
dicarloj | 9:2a47b9ff8911 | 436 | void draw_vincent_string(char* str) |
dicarloj | 9:2a47b9ff8911 | 437 | { |
dicarloj | 9:2a47b9ff8911 | 438 | for(int i = 0; i < strlen(str); i++) |
dicarloj | 9:2a47b9ff8911 | 439 | { |
dicarloj | 9:2a47b9ff8911 | 440 | if(str[i] == 0 || str[i] == EOF) return; |
dicarloj | 9:2a47b9ff8911 | 441 | char_col++; |
dicarloj | 9:2a47b9ff8911 | 442 | if(char_col >= TX) |
dicarloj | 9:2a47b9ff8911 | 443 | { |
dicarloj | 9:2a47b9ff8911 | 444 | char_col = 0; |
dicarloj | 9:2a47b9ff8911 | 445 | char_row++; |
bwang | 3:d9edc0575aa3 | 446 | } |
dicarloj | 9:2a47b9ff8911 | 447 | if(char_row >= TY) |
dicarloj | 9:2a47b9ff8911 | 448 | { |
dicarloj | 9:2a47b9ff8911 | 449 | char_row = 0; |
dicarloj | 9:2a47b9ff8911 | 450 | } |
bwang | 3:d9edc0575aa3 | 451 | |
dicarloj | 9:2a47b9ff8911 | 452 | draw_vincent(X0 +2 + 8*char_col, Y0 + 14 + 8*char_row, |
dicarloj | 9:2a47b9ff8911 | 453 | str[i]); |
bwang | 3:d9edc0575aa3 | 454 | } |
bwang | 3:d9edc0575aa3 | 455 | } |
bwang | 3:d9edc0575aa3 | 456 | |
dicarloj | 9:2a47b9ff8911 | 457 | //void draw_text_buffer() |
dicarloj | 9:2a47b9ff8911 | 458 | //{ |
dicarloj | 9:2a47b9ff8911 | 459 | // for(int yc = 0; yc < TY; yc++) |
dicarloj | 9:2a47b9ff8911 | 460 | // { |
dicarloj | 9:2a47b9ff8911 | 461 | // for(int xc = 0; xc < TX; xc++) |
dicarloj | 9:2a47b9ff8911 | 462 | // { |
dicarloj | 9:2a47b9ff8911 | 463 | // draw_vincent(X0 + 10 + 8*xc, Y0 + 10 + 8*yc, |
dicarloj | 9:2a47b9ff8911 | 464 | // text_buffer[TX*yc + xc]%128); |
dicarloj | 9:2a47b9ff8911 | 465 | // } |
dicarloj | 9:2a47b9ff8911 | 466 | // } |
dicarloj | 9:2a47b9ff8911 | 467 | //} |
dicarloj | 9:2a47b9ff8911 | 468 | |
dicarloj | 9:2a47b9ff8911 | 469 | // should the lisp interpreter run? |
dicarloj | 9:2a47b9ff8911 | 470 | int want_lisp = 0; |
dicarloj | 9:2a47b9ff8911 | 471 | |
dicarloj | 9:2a47b9ff8911 | 472 | void backspace() |
dicarloj | 9:2a47b9ff8911 | 473 | { |
dicarloj | 9:2a47b9ff8911 | 474 | text_buffer[text_buffer_counter] = 0; |
dicarloj | 9:2a47b9ff8911 | 475 | if(text_buffer_counter > 0) |
dicarloj | 9:2a47b9ff8911 | 476 | text_buffer_counter--; |
dicarloj | 9:2a47b9ff8911 | 477 | |
dicarloj | 9:2a47b9ff8911 | 478 | draw_vincent(X0 +2 + 8*char_col, Y0 + 14 + 8*char_row, ' '); |
dicarloj | 9:2a47b9ff8911 | 479 | if(char_col > 0) |
dicarloj | 9:2a47b9ff8911 | 480 | char_col--; |
dicarloj | 9:2a47b9ff8911 | 481 | else |
bwang | 1:24fd07a24094 | 482 | { |
dicarloj | 9:2a47b9ff8911 | 483 | char_row--; |
dicarloj | 9:2a47b9ff8911 | 484 | char_col = TX - 1; |
bwang | 3:d9edc0575aa3 | 485 | } |
bwang | 3:d9edc0575aa3 | 486 | } |
bwang | 3:d9edc0575aa3 | 487 | |
dicarloj | 9:2a47b9ff8911 | 488 | void clear_all_text() |
dicarloj | 9:2a47b9ff8911 | 489 | { |
dicarloj | 9:2a47b9ff8911 | 490 | char_col = 0; |
dicarloj | 9:2a47b9ff8911 | 491 | char_row = 0; |
dicarloj | 9:2a47b9ff8911 | 492 | clr_text_buff(); |
dicarloj | 9:2a47b9ff8911 | 493 | clr(); |
dicarloj | 9:2a47b9ff8911 | 494 | // startup animation |
dicarloj | 9:2a47b9ff8911 | 495 | int miter_x_final = XL/2 + 20*cos(.11f*MAX(XL,YL)) + 80; |
dicarloj | 9:2a47b9ff8911 | 496 | int miter_y_final = YL/2 + 20*sin(.11f*MAX(XL,YL)) + 80; |
dicarloj | 9:2a47b9ff8911 | 497 | |
dicarloj | 9:2a47b9ff8911 | 498 | int x_correct = -miter_x_final + X0 + 6; |
dicarloj | 9:2a47b9ff8911 | 499 | int y_correct = -miter_y_final + Y0; |
dicarloj | 9:2a47b9ff8911 | 500 | for(int i = MAX(XL,YL) - 1; i < MAX(XL,YL); i++) |
bwang | 4:02e3ae7a3aea | 501 | { |
dicarloj | 9:2a47b9ff8911 | 502 | wait_us(10000); |
dicarloj | 9:2a47b9ff8911 | 503 | clr(); |
dicarloj | 9:2a47b9ff8911 | 504 | int xp = MIN(XL,i); |
dicarloj | 9:2a47b9ff8911 | 505 | int yp = MIN(YL,i); |
dicarloj | 9:2a47b9ff8911 | 506 | draw_line(X0, Y0, X0 + xp, Y0); |
dicarloj | 9:2a47b9ff8911 | 507 | draw_line(X0+xp,Y0,X0+xp,Y0+yp); |
dicarloj | 9:2a47b9ff8911 | 508 | |
dicarloj | 9:2a47b9ff8911 | 509 | draw_line(X0, Y0+yp, X0 +xp, Y0+yp); |
dicarloj | 9:2a47b9ff8911 | 510 | draw_line(X0,Y0,X0,Y0+yp); |
dicarloj | 9:2a47b9ff8911 | 511 | float phase = (float)(i) / (float)MAX(XL,YL); |
dicarloj | 9:2a47b9ff8911 | 512 | draw_miters_at(xp/2 + 20*cos(.11f*i) + 80 + (x_correct * phase),yp/2 + 20*sin(.11f*i) + 80 + (y_correct * phase)); |
dicarloj | 9:2a47b9ff8911 | 513 | //draw_vincent(100,100,15); |
dicarloj | 9:2a47b9ff8911 | 514 | } |
dicarloj | 9:2a47b9ff8911 | 515 | |
dicarloj | 9:2a47b9ff8911 | 516 | // draw prompt |
dicarloj | 9:2a47b9ff8911 | 517 | draw_vincent_string(">"); |
dicarloj | 9:2a47b9ff8911 | 518 | } |
dicarloj | 9:2a47b9ff8911 | 519 | |
dicarloj | 9:2a47b9ff8911 | 520 | void set_status_string(char* str) |
dicarloj | 9:2a47b9ff8911 | 521 | { |
dicarloj | 9:2a47b9ff8911 | 522 | uint8_t char_col_backup = char_col; |
dicarloj | 9:2a47b9ff8911 | 523 | uint8_t char_row_backup = char_row; |
dicarloj | 9:2a47b9ff8911 | 524 | char_col = 0; |
dicarloj | 9:2a47b9ff8911 | 525 | char_row = TY - 1; |
dicarloj | 9:2a47b9ff8911 | 526 | |
dicarloj | 9:2a47b9ff8911 | 527 | draw_vincent_string(str); |
dicarloj | 9:2a47b9ff8911 | 528 | |
dicarloj | 9:2a47b9ff8911 | 529 | char_col = char_col_backup; |
dicarloj | 9:2a47b9ff8911 | 530 | char_row = char_row_backup; |
dicarloj | 9:2a47b9ff8911 | 531 | } |
dicarloj | 9:2a47b9ff8911 | 532 | |
dicarloj | 9:2a47b9ff8911 | 533 | // on each serial char received |
dicarloj | 9:2a47b9ff8911 | 534 | void serial_callback() |
dicarloj | 9:2a47b9ff8911 | 535 | { |
dicarloj | 9:2a47b9ff8911 | 536 | // get characeter and store in text_buffer |
dicarloj | 9:2a47b9ff8911 | 537 | char new_char = pc.getc(); |
dicarloj | 9:2a47b9ff8911 | 538 | most_recent_char = new_char; |
dicarloj | 9:2a47b9ff8911 | 539 | |
dicarloj | 9:2a47b9ff8911 | 540 | if(new_char == '^') |
dicarloj | 9:2a47b9ff8911 | 541 | { |
dicarloj | 9:2a47b9ff8911 | 542 | want_gfx = 1; |
dicarloj | 9:2a47b9ff8911 | 543 | return; |
dicarloj | 9:2a47b9ff8911 | 544 | } |
dicarloj | 9:2a47b9ff8911 | 545 | //char cn[8]; |
dicarloj | 9:2a47b9ff8911 | 546 | //sprintf(cn,"[%d]",new_char); |
dicarloj | 9:2a47b9ff8911 | 547 | //draw_vincent_string(cn); |
dicarloj | 9:2a47b9ff8911 | 548 | if(new_char == 127) |
dicarloj | 9:2a47b9ff8911 | 549 | { |
dicarloj | 9:2a47b9ff8911 | 550 | backspace(); |
dicarloj | 9:2a47b9ff8911 | 551 | return; |
dicarloj | 9:2a47b9ff8911 | 552 | } |
dicarloj | 9:2a47b9ff8911 | 553 | |
dicarloj | 9:2a47b9ff8911 | 554 | text_buffer[text_buffer_counter++] = new_char; |
dicarloj | 9:2a47b9ff8911 | 555 | |
dicarloj | 9:2a47b9ff8911 | 556 | // if it's <enter>, request lisp |
dicarloj | 9:2a47b9ff8911 | 557 | if(new_char == 13) |
dicarloj | 9:2a47b9ff8911 | 558 | { |
dicarloj | 9:2a47b9ff8911 | 559 | want_lisp = 1; |
dicarloj | 9:2a47b9ff8911 | 560 | return; |
dicarloj | 9:2a47b9ff8911 | 561 | } |
dicarloj | 9:2a47b9ff8911 | 562 | |
dicarloj | 9:2a47b9ff8911 | 563 | |
dicarloj | 9:2a47b9ff8911 | 564 | // increment rows/cols as needed |
dicarloj | 9:2a47b9ff8911 | 565 | char_col++; |
dicarloj | 9:2a47b9ff8911 | 566 | if(char_col >= TX) |
dicarloj | 9:2a47b9ff8911 | 567 | { |
dicarloj | 9:2a47b9ff8911 | 568 | char_col = 0; |
dicarloj | 9:2a47b9ff8911 | 569 | char_row++; |
dicarloj | 9:2a47b9ff8911 | 570 | } |
dicarloj | 9:2a47b9ff8911 | 571 | if(char_row >= TY) |
dicarloj | 9:2a47b9ff8911 | 572 | { |
dicarloj | 9:2a47b9ff8911 | 573 | char_row = 0; |
dicarloj | 9:2a47b9ff8911 | 574 | } |
dicarloj | 9:2a47b9ff8911 | 575 | |
dicarloj | 9:2a47b9ff8911 | 576 | // draw new character |
dicarloj | 9:2a47b9ff8911 | 577 | draw_vincent(X0 +2 + 8*char_col, Y0 + 14 + 8*char_row, |
dicarloj | 9:2a47b9ff8911 | 578 | new_char%128); |
dicarloj | 9:2a47b9ff8911 | 579 | |
dicarloj | 9:2a47b9ff8911 | 580 | } |
dicarloj | 9:2a47b9ff8911 | 581 | |
dicarloj | 9:2a47b9ff8911 | 582 | void spin_for_a_while(volatile int a) |
dicarloj | 9:2a47b9ff8911 | 583 | { |
dicarloj | 9:2a47b9ff8911 | 584 | volatile int k = a; |
dicarloj | 9:2a47b9ff8911 | 585 | for(int i = 0; i < k; i++) |
dicarloj | 9:2a47b9ff8911 | 586 | { |
dicarloj | 9:2a47b9ff8911 | 587 | for(int j = 0; j < k; j++) |
bwang | 4:02e3ae7a3aea | 588 | { |
dicarloj | 9:2a47b9ff8911 | 589 | a++; |
bwang | 4:02e3ae7a3aea | 590 | } |
bwang | 4:02e3ae7a3aea | 591 | } |
bwang | 4:02e3ae7a3aea | 592 | } |
bwang | 4:02e3ae7a3aea | 593 | |
dicarloj | 9:2a47b9ff8911 | 594 | uint8_t gfx_is_init = 0; |
dicarloj | 9:2a47b9ff8911 | 595 | |
dicarloj | 9:2a47b9ff8911 | 596 | // screen goes from -.5 to .5 on both axes |
dicarloj | 9:2a47b9ff8911 | 597 | void draw_gfx_line(float x0, float y0, float x1, float y1) |
dicarloj | 9:2a47b9ff8911 | 598 | { |
dicarloj | 9:2a47b9ff8911 | 599 | float x_width = (XL); |
dicarloj | 9:2a47b9ff8911 | 600 | float y_height = (YL); |
dicarloj | 9:2a47b9ff8911 | 601 | |
dicarloj | 9:2a47b9ff8911 | 602 | // want to rescale to 0 to 1 |
dicarloj | 9:2a47b9ff8911 | 603 | x0 += 0.5f; |
dicarloj | 9:2a47b9ff8911 | 604 | y0 += 0.5f; |
dicarloj | 9:2a47b9ff8911 | 605 | |
dicarloj | 9:2a47b9ff8911 | 606 | x1 += 0.5f; |
dicarloj | 9:2a47b9ff8911 | 607 | y1 += 0.5f; |
dicarloj | 9:2a47b9ff8911 | 608 | //printf("x0: %.3f, y0: %.3f\r\n",x0,y0); |
dicarloj | 9:2a47b9ff8911 | 609 | int xx = x0 * x_width + X0; |
dicarloj | 9:2a47b9ff8911 | 610 | if(xx > (X0 + XL)) xx = (X0 + XL); |
dicarloj | 9:2a47b9ff8911 | 611 | if(xx < X0) xx = X0; |
dicarloj | 9:2a47b9ff8911 | 612 | int yy = y0 * y_height + Y0; |
dicarloj | 9:2a47b9ff8911 | 613 | if(yy > (Y0 + YL)) yy = (Y0 + YL); |
dicarloj | 9:2a47b9ff8911 | 614 | if(yy < Y0) yy = Y0; |
dicarloj | 9:2a47b9ff8911 | 615 | |
dicarloj | 9:2a47b9ff8911 | 616 | int xx1 = x1 * x_width + X0; |
dicarloj | 9:2a47b9ff8911 | 617 | if(xx1 > (X0 + XL)) xx1 = (X0 + XL); |
dicarloj | 9:2a47b9ff8911 | 618 | if(xx1 < X0) xx1 = X0; |
dicarloj | 9:2a47b9ff8911 | 619 | int yy1 = y1 * y_height + Y0; |
dicarloj | 9:2a47b9ff8911 | 620 | if(yy1 > (Y0 + YL)) yy1 = (Y0 + YL); |
dicarloj | 9:2a47b9ff8911 | 621 | if(yy1 < Y0) yy1 = Y0; |
dicarloj | 9:2a47b9ff8911 | 622 | |
dicarloj | 9:2a47b9ff8911 | 623 | draw_line(xx,yy,xx1,yy1); |
dicarloj | 9:2a47b9ff8911 | 624 | |
bwang | 4:02e3ae7a3aea | 625 | } |
dicarloj | 9:2a47b9ff8911 | 626 | //void swap_buffers() |
dicarloj | 9:2a47b9ff8911 | 627 | //{ |
dicarloj | 9:2a47b9ff8911 | 628 | // if(im_line_va == im_line_va_1) |
dicarloj | 9:2a47b9ff8911 | 629 | // im_line_va = im_line_va_2; |
dicarloj | 9:2a47b9ff8911 | 630 | // else |
dicarloj | 9:2a47b9ff8911 | 631 | // im_line_va = im_line_va_1; |
dicarloj | 9:2a47b9ff8911 | 632 | //} |
dicarloj | 9:2a47b9ff8911 | 633 | int main() |
dicarloj | 9:2a47b9ff8911 | 634 | { |
dicarloj | 12:e99cc1e9d928 | 635 | // int n = 0; |
dicarloj | 12:e99cc1e9d928 | 636 | // pc.baud(115200); |
dicarloj | 12:e99cc1e9d928 | 637 | // for(;;) |
dicarloj | 12:e99cc1e9d928 | 638 | // { |
dicarloj | 12:e99cc1e9d928 | 639 | // |
dicarloj | 12:e99cc1e9d928 | 640 | // n++; |
dicarloj | 12:e99cc1e9d928 | 641 | // n = n%16; |
dicarloj | 12:e99cc1e9d928 | 642 | // GPIOA->ODR = (n<<4); |
dicarloj | 12:e99cc1e9d928 | 643 | // pc.printf("val: 0x%hhx\r\n",(n<<4)); |
dicarloj | 12:e99cc1e9d928 | 644 | // |
dicarloj | 12:e99cc1e9d928 | 645 | // } |
dicarloj | 9:2a47b9ff8911 | 646 | im_line_va = im_line_va_1; |
dicarloj | 9:2a47b9ff8911 | 647 | // init serial |
dicarloj | 9:2a47b9ff8911 | 648 | pc.baud(115200); |
dicarloj | 9:2a47b9ff8911 | 649 | pc.attach(&serial_callback); |
dicarloj | 9:2a47b9ff8911 | 650 | pc.printf("derp!\r\n"); |
dicarloj | 9:2a47b9ff8911 | 651 | |
dicarloj | 9:2a47b9ff8911 | 652 | // init buffers |
dicarloj | 9:2a47b9ff8911 | 653 | init_buffers(); |
dicarloj | 9:2a47b9ff8911 | 654 | // init timer |
dicarloj | 9:2a47b9ff8911 | 655 | t.attach_us(&isr,64); |
bwang | 4:02e3ae7a3aea | 656 | |
dicarloj | 9:2a47b9ff8911 | 657 | wait_us(200000); |
dicarloj | 9:2a47b9ff8911 | 658 | int miter_x_final = XL/2 + 20*cos(.11f*MAX(XL,YL)) + 80; |
dicarloj | 9:2a47b9ff8911 | 659 | int miter_y_final = YL/2 + 20*sin(.11f*MAX(XL,YL)) + 80; |
dicarloj | 9:2a47b9ff8911 | 660 | int x_correct = -miter_x_final + X0 + 6; |
dicarloj | 9:2a47b9ff8911 | 661 | int y_correct = -miter_y_final + Y0; |
bwang | 4:02e3ae7a3aea | 662 | |
dicarloj | 9:2a47b9ff8911 | 663 | for(int i = 0; i < MAX(XL,YL); i+=3) |
bwang | 4:02e3ae7a3aea | 664 | { |
dicarloj | 9:2a47b9ff8911 | 665 | char stat_buff[30]; |
dicarloj | 9:2a47b9ff8911 | 666 | sprintf(stat_buff,"f: %d",i); |
dicarloj | 9:2a47b9ff8911 | 667 | set_status_string(stat_buff); |
dicarloj | 9:2a47b9ff8911 | 668 | //wait_us(10000); |
dicarloj | 9:2a47b9ff8911 | 669 | |
dicarloj | 9:2a47b9ff8911 | 670 | spin_for_a_while(200); |
dicarloj | 9:2a47b9ff8911 | 671 | clr(); |
dicarloj | 9:2a47b9ff8911 | 672 | int xp = MIN(XL,i); |
dicarloj | 9:2a47b9ff8911 | 673 | int yp = MIN(YL,i); |
dicarloj | 9:2a47b9ff8911 | 674 | draw_line(X0, Y0, X0 + xp, Y0); |
dicarloj | 9:2a47b9ff8911 | 675 | draw_line(X0+xp,Y0,X0+xp,Y0+yp); |
dicarloj | 9:2a47b9ff8911 | 676 | |
dicarloj | 9:2a47b9ff8911 | 677 | draw_line(X0, Y0+yp, X0 +xp, Y0+yp); |
dicarloj | 9:2a47b9ff8911 | 678 | draw_line(X0,Y0,X0,Y0+yp); |
dicarloj | 9:2a47b9ff8911 | 679 | float phase = (float)(i) / (float)MAX(XL,YL); |
dicarloj | 9:2a47b9ff8911 | 680 | draw_miters_at(xp/2 + 20*cos(.11f*i) + 80 + (x_correct * phase),yp/2 + 20*sin(.11f*i) + 80 + (y_correct * phase)); |
dicarloj | 9:2a47b9ff8911 | 681 | //draw_vincent(100,100,15); |
bwang | 4:02e3ae7a3aea | 682 | } |
bwang | 4:02e3ae7a3aea | 683 | |
dicarloj | 9:2a47b9ff8911 | 684 | clear_all_text(); |
dicarloj | 9:2a47b9ff8911 | 685 | draw_vincent_string("Welcome to LISP MACHINE"); |
dicarloj | 9:2a47b9ff8911 | 686 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 687 | draw_vincent_string("Connect over USB serial"); |
dicarloj | 9:2a47b9ff8911 | 688 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 689 | draw_vincent_string("115200 baud"); |
dicarloj | 9:2a47b9ff8911 | 690 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 691 | draw_vincent_string("use 'clear' to clear"); |
dicarloj | 9:2a47b9ff8911 | 692 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 693 | draw_vincent_string("use '^' to use 3D MODE"); |
dicarloj | 9:2a47b9ff8911 | 694 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 695 | draw_vincent_string(">"); |
dicarloj | 9:2a47b9ff8911 | 696 | // main loop |
dicarloj | 10:1163fb31b0a7 | 697 | want_gfx = 1; |
dicarloj | 11:537cde55b27f | 698 | |
dicarloj | 12:e99cc1e9d928 | 699 | int num_iters; |
dicarloj | 9:2a47b9ff8911 | 700 | for(;;) |
dicarloj | 9:2a47b9ff8911 | 701 | { |
dicarloj | 12:e99cc1e9d928 | 702 | |
dicarloj | 9:2a47b9ff8911 | 703 | if(want_lisp) |
dicarloj | 9:2a47b9ff8911 | 704 | { |
dicarloj | 9:2a47b9ff8911 | 705 | new_line(); |
dicarloj | 9:2a47b9ff8911 | 706 | // runs interpreter and prints answer |
dicarloj | 10:1163fb31b0a7 | 707 | run_lisp(text_buffer); |
dicarloj | 10:1163fb31b0a7 | 708 | want_lisp = 0; |
dicarloj | 10:1163fb31b0a7 | 709 | new_line(); |
dicarloj | 10:1163fb31b0a7 | 710 | clr_text_buff(); |
dicarloj | 9:2a47b9ff8911 | 711 | //draw_vincent_string(">"); |
bwang | 6:0a34891a82c7 | 712 | } |
bwang | 6:0a34891a82c7 | 713 | |
dicarloj | 9:2a47b9ff8911 | 714 | if(want_gfx) |
bwang | 6:0a34891a82c7 | 715 | { |
dicarloj | 10:1163fb31b0a7 | 716 | if(!vsync) continue; |
dicarloj | 9:2a47b9ff8911 | 717 | if(!gfx_is_init) |
bwang | 6:0a34891a82c7 | 718 | { |
dicarloj | 9:2a47b9ff8911 | 719 | init_gfx(); |
dicarloj | 9:2a47b9ff8911 | 720 | gfx_is_init = 1; |
dicarloj | 9:2a47b9ff8911 | 721 | } |
dicarloj | 10:1163fb31b0a7 | 722 | clr(); |
dicarloj | 11:537cde55b27f | 723 | float j2 = joy1.read() - .5f;; |
dicarloj | 11:537cde55b27f | 724 | float j1 = joy2.read() - .5f; |
dicarloj | 12:e99cc1e9d928 | 725 | |
dicarloj | 12:e99cc1e9d928 | 726 | num_iters++; |
dicarloj | 12:e99cc1e9d928 | 727 | |
dicarloj | 12:e99cc1e9d928 | 728 | if( (num_iters % 5) == 0) |
dicarloj | 12:e99cc1e9d928 | 729 | { |
dicarloj | 12:e99cc1e9d928 | 730 | if(line_dir == 1) |
dicarloj | 12:e99cc1e9d928 | 731 | { |
dicarloj | 12:e99cc1e9d928 | 732 | line_intensity++; |
dicarloj | 12:e99cc1e9d928 | 733 | if(line_intensity >= 8) |
dicarloj | 12:e99cc1e9d928 | 734 | line_dir = -1; |
dicarloj | 12:e99cc1e9d928 | 735 | } |
dicarloj | 12:e99cc1e9d928 | 736 | else |
dicarloj | 12:e99cc1e9d928 | 737 | { |
dicarloj | 12:e99cc1e9d928 | 738 | line_intensity--; |
dicarloj | 12:e99cc1e9d928 | 739 | if(line_intensity == 0) |
dicarloj | 12:e99cc1e9d928 | 740 | line_dir = 1; |
dicarloj | 12:e99cc1e9d928 | 741 | } |
dicarloj | 12:e99cc1e9d928 | 742 | } |
dicarloj | 12:e99cc1e9d928 | 743 | |
dicarloj | 12:e99cc1e9d928 | 744 | |
dicarloj | 12:e99cc1e9d928 | 745 | for(int x = 0; x < XL-0; x++) |
dicarloj | 12:e99cc1e9d928 | 746 | { |
dicarloj | 12:e99cc1e9d928 | 747 | for(int y = 0; y < YL-0; y++) |
dicarloj | 12:e99cc1e9d928 | 748 | { |
dicarloj | 12:e99cc1e9d928 | 749 | im_line_va[H_RES*(y+Y0) + x + X0] = splash[YL - y][x] >> 4; |
dicarloj | 12:e99cc1e9d928 | 750 | //im_line_va[H_RES*y + x] = (y/6)%10; |
dicarloj | 12:e99cc1e9d928 | 751 | // im_line_va[H_RES*y + x] = ( (x-X0) + (y-Y0) )/24 - 2; |
dicarloj | 12:e99cc1e9d928 | 752 | } |
dicarloj | 12:e99cc1e9d928 | 753 | } |
dicarloj | 11:537cde55b27f | 754 | new_frame(j1,j2); |
dicarloj | 9:2a47b9ff8911 | 755 | draw_line(X0, Y0, X0 + XL, Y0); |
dicarloj | 9:2a47b9ff8911 | 756 | draw_line(X0+XL,Y0,X0+XL,Y0+YL); |
dicarloj | 9:2a47b9ff8911 | 757 | draw_line(X0, Y0+YL, X0 +XL, Y0+YL); |
dicarloj | 9:2a47b9ff8911 | 758 | draw_line(X0,Y0,X0,Y0+YL); |
dicarloj | 10:1163fb31b0a7 | 759 | most_recent_char = '0'; |
dicarloj | 10:1163fb31b0a7 | 760 | //spin_for_a_while(400); |
dicarloj | 10:1163fb31b0a7 | 761 | |
dicarloj | 11:537cde55b27f | 762 | |
dicarloj | 11:537cde55b27f | 763 | |
dicarloj | 11:537cde55b27f | 764 | // if(color) |
dicarloj | 11:537cde55b27f | 765 | // { |
dicarloj | 11:537cde55b27f | 766 | // for(int i = 0; i < XL; i++) |
dicarloj | 11:537cde55b27f | 767 | // draw_line(X0+i,Y0,X0+i,Y0+YL); |
dicarloj | 11:537cde55b27f | 768 | // color = 0; |
dicarloj | 11:537cde55b27f | 769 | // } |
dicarloj | 11:537cde55b27f | 770 | // else |
dicarloj | 11:537cde55b27f | 771 | // color = 1; |
dicarloj | 11:537cde55b27f | 772 | |
dicarloj | 11:537cde55b27f | 773 | //color = !color; |
dicarloj | 9:2a47b9ff8911 | 774 | //draw_gfx_line(-0.01,-0.01,0.01,0.01); |
dicarloj | 11:537cde55b27f | 775 | char joy_string[20]; |
dicarloj | 11:537cde55b27f | 776 | sprintf(joy_string,"1: %.2f 2: %.2f",joy1.read(),joy2.read()); |
dicarloj | 12:e99cc1e9d928 | 777 | set_status_string(joy_string); |
dicarloj | 12:e99cc1e9d928 | 778 | |
dicarloj | 12:e99cc1e9d928 | 779 | |
dicarloj | 12:e99cc1e9d928 | 780 | //im_line_va[H_RES*y0 + i] = 1; |
dicarloj | 12:e99cc1e9d928 | 781 | |
dicarloj | 12:e99cc1e9d928 | 782 | // #define X0 75 // start of image in X |
dicarloj | 12:e99cc1e9d928 | 783 | //#define Y0 30 // start of image in Y |
dicarloj | 12:e99cc1e9d928 | 784 | //#define XL 220 // 25 chars |
dicarloj | 12:e99cc1e9d928 | 785 | //#define YL 165 // 20 chars |
dicarloj | 12:e99cc1e9d928 | 786 | //set_status_string(get_gfx_stat()); |
dicarloj | 10:1163fb31b0a7 | 787 | vsync = 0; |
dicarloj | 9:2a47b9ff8911 | 788 | //swap_buffers(); |
dicarloj | 9:2a47b9ff8911 | 789 | |
bwang | 6:0a34891a82c7 | 790 | } |
bwang | 6:0a34891a82c7 | 791 | } |
bwang | 6:0a34891a82c7 | 792 | } |
bwang | 6:0a34891a82c7 | 793 | |
dicarloj | 9:2a47b9ff8911 | 794 |