Skip to content

Commit

Permalink
chore(wip): start work on buffer support
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves committed Mar 10, 2024
1 parent c39e323 commit 3d237af
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 84 deletions.
1 change: 1 addition & 0 deletions examples/basics/blink-alternating.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
330527000000430302020143030002000805e8030000430302020043030002010805e80300000a04060000000d0a0406000000
11 changes: 11 additions & 0 deletions examples/basics/blink-alternating.esp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn loop {
io_write #2, 1
io_write #0, 0
delay 1000
io_write #2, 0
io_write #0, 1
delay 1000
loop()
}

loop()
Binary file added examples/basics/blinky.bin
Binary file not shown.
File renamed without changes.
Binary file added examples/basics/hello.bin
Binary file not shown.
File renamed without changes.
2 changes: 2 additions & 0 deletions examples/io/using-4-pins.esp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
io_all_output

151 changes: 77 additions & 74 deletions examples/ssd-1306-display.esp
Original file line number Diff line number Diff line change
Expand Up @@ -43,83 +43,86 @@ byte SET_VCOM_DETECT = dbh
byte NOP = e3h
byte SELECT_PAGE = b0h

int is128_64 = screenHeight == 64;
bool is128_64 = false
int lineDrift = 0;

is128_64 = screenHeight == 64;

// some display models need extra padding bytes after a page buffer
int lineDrift = is128_64 ? 4 : 0
lineDrift = is128_64 ? 4 : 0

buffer data = [
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 C0 80 00 00 00 00 00 00 00 06
0A 05 0D 01 01 03 87 FE FE FC F8 F0 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 80 80 80 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 80 C0 C0 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 0E
08 0C 0C 0C 0E 0F 0F 07 07 03 03 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 80 E0 30
98 DE E6 E7 F7 D7 D6 56 56 D7 D7 5F DF 3F 3F 2F
9F D7 DF 6F 6B 6B 7F F7 F3 F3 E0 EC 98 30 E0 80
00 00 00 00 00 00 00 00 00 00 80 80 60 70 70 60
40 60 E0 E0 E0 E0 E0 E0 E0 C0 C0 E0 F0 E0 40 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 03 FB E0
DF B1 EF 5F B9 B0 A0 E6 6E 2E B6 B9 9F AF A0 A7
BF 99 B6 B6 A6 A6 B0 B0 A9 DF CF F0 7F 77 FD 01
80 80 80 00 00 00 00 08 EE B3 7D BE 7F C7 87 B7
B7 B7 CD 7D 83 93 FB CD B5 35 A5 87 CE FE 1C F9
C3 1C 10 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 0F 1F 3F 3C 73
EF 9E 7E FD FD ED AD FD DD FF BF FF 5F DF EF FF
FF FF 6F FF DF EF FD DD FD BC FE 7E BF EF 7B 3E
1F 0F 07 00 00 0E 1F 3C 77 5F 3D 7D FB FB 7A FA
FE FE FE FE FF FF 7E FE BF FD F5 F5 F6 FA FB DF
67 78 3C 1C 00 00 00 00 00 00 00 00 80 80 00 00
60 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 C0 80 00 00 80 80 00 00 00 00 00 00 00
00 40 00 10 38 80 00 00 80 C0 C0 00 00 00 00 00
00 00 01 00 00 81 83 83 87 E7 EF EF EB FF F7 DF
FA FE FF EB EE EE E7 67 63 61 60 60 60 E0 E0 E0
60 60 60 60 60 60 70 70 70 70 70 70 70 71 73 7B
7F 7F 7F 7F 7F 7E 7F 77 76 73 73 71 71 70 71 70
70 70 70 70 F0 F0 F0 F0 F0 F0 F0 F1 F1 F1 E0 E0
E8 EC EE E7 E2 E4 E8 D0 E0 E0 C0 C0 C0 C0 C0 C0

10 10 10 10 1F 13 A1 AD C8 49 47 42 40 C0 DC 78
60 60 20 21 31 30 11 1A 1B 0B 0D 0C 04 06 06 06
03 03 03 13 31 71 71 61 81 81 41 20 26 0C 1C 30
78 00 00 84 C4 84 84 0C 04 02 02 01 01 07 0E 0E
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 60 E0 E0 C0 80 00 00 00 00 00
00 00 00 00 00 60 E0 C0 C0 00 00 81 81 81 41 41
21 21 13 13 13 03 0B 0B 0B 0F 0F 07 07 07 07 07

00 00 00 00 00 00 03 01 01 00 00 06 07 03 03 00
00 00 00 00 00 00 00 00 00 00 00 08 0C 40 EE 79
35 02 08 08 04 04 02 1F 3D 3C 00 00 00 00 00 04
04 24 00 0D 30 31 01 03 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 82 C6 C6 36 68 44
B4 A0 52 62 02 02 02 00 01 03 32 7A 3E 1A 02 02
02 02 02 02 02 00 1D 3D 1D 01 01 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 C0 80 00 00 00 00 00 00 00 06
0A 05 0D 01 01 03 87 FE FE FC F8 F0 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 80 80 80 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 80 C0 C0 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 0E
08 0C 0C 0C 0E 0F 0F 07 07 03 03 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 80 E0 30
98 DE E6 E7 F7 D7 D6 56 56 D7 D7 5F DF 3F 3F 2F
9F D7 DF 6F 6B 6B 7F F7 F3 F3 E0 EC 98 30 E0 80
00 00 00 00 00 00 00 00 00 00 80 80 60 70 70 60
40 60 E0 E0 E0 E0 E0 E0 E0 C0 C0 E0 F0 E0 40 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 03 FB E0
DF B1 EF 5F B9 B0 A0 E6 6E 2E B6 B9 9F AF A0 A7
BF 99 B6 B6 A6 A6 B0 B0 A9 DF CF F0 7F 77 FD 01
80 80 80 00 00 00 00 08 EE B3 7D BE 7F C7 87 B7
B7 B7 CD 7D 83 93 FB CD B5 35 A5 87 CE FE 1C F9
C3 1C 10 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 0F 1F 3F 3C 73
EF 9E 7E FD FD ED AD FD DD FF BF FF 5F DF EF FF
FF FF 6F FF DF EF FD DD FD BC FE 7E BF EF 7B 3E
1F 0F 07 00 00 0E 1F 3C 77 5F 3D 7D FB FB 7A FA
FE FE FE FE FF FF 7E FE BF FD F5 F5 F6 FA FB DF
67 78 3C 1C 00 00 00 00 00 00 00 00 80 80 00 00
60 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00 00 00 C0 80 00 00 80 80 00 00 00 00 00 00 00
00 40 00 10 38 80 00 00 80 C0 C0 00 00 00 00 00
00 00 01 00 00 81 83 83 87 E7 EF EF EB FF F7 DF
FA FE FF EB EE EE E7 67 63 61 60 60 60 E0 E0 E0
60 60 60 60 60 60 70 70 70 70 70 70 70 71 73 7B
7F 7F 7F 7F 7F 7E 7F 77 76 73 73 71 71 70 71 70
70 70 70 70 F0 F0 F0 F0 F0 F0 F0 F1 F1 F1 E0 E0
E8 EC EE E7 E2 E4 E8 D0 E0 E0 C0 C0 C0 C0 C0 C0

10 10 10 10 1F 13 A1 AD C8 49 47 42 40 C0 DC 78
60 60 20 21 31 30 11 1A 1B 0B 0D 0C 04 06 06 06
03 03 03 13 31 71 71 61 81 81 41 20 26 0C 1C 30
78 00 00 84 C4 84 84 0C 04 02 02 01 01 07 0E 0E
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 60 E0 E0 C0 80 00 00 00 00 00
00 00 00 00 00 60 E0 C0 C0 00 00 81 81 81 41 41
21 21 13 13 13 03 0B 0B 0B 0F 0F 07 07 07 07 07

00 00 00 00 00 00 03 01 01 00 00 06 07 03 03 00
00 00 00 00 00 00 00 00 00 00 00 08 0C 40 EE 79
35 02 08 08 04 04 02 1F 3D 3C 00 00 00 00 00 04
04 24 00 0D 30 31 01 03 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 82 C6 C6 36 68 44
B4 A0 52 62 02 02 02 00 01 03 32 7A 3E 1A 02 02
02 02 02 02 02 00 1D 3D 1D 01 01 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
]

function initDisplay() {
Expand Down Expand Up @@ -194,7 +197,7 @@ function writeStream(bytes) {
return i2cGetAck();
}

async function writeDataByPage(bytes) {
fun writeDataByPage(bytes) {
const slices = 8;
const sliceLength = Math.round(bytes.length / slices);

Expand Down
14 changes: 12 additions & 2 deletions src/include/vm_instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ Value _readValue(Program *p)
p->counter += os_strlen((const char *)ref) + 1;
value.update(type, (void *)ref);
break;

case vt_blob:
byteref ref = p->bytes;
ref += p->counter;
int length = *((int *)ref);
ref += 4;
Buffer *b = (Buffer *)os_zalloc(sizeof(Buffer));
b->load(ref, length);
value.update(type, b, true);
}

return value;
Expand Down Expand Up @@ -160,7 +169,8 @@ void _onInterruptTriggered(void *arg, byte pin)
{
p->counter = p->interruptHandlers[pin];
p->paused = false;
vm_tick(p);
os_timer_disarm(&p->timer);
os_timer_arm(&p->timer, 1, 0);
}
}

Expand Down Expand Up @@ -611,7 +621,7 @@ void MOVE_TO_FLASH vm_i2cread(Program *p)
_debug(p, "i2cread %d\n", value);
}

void MOVE_TO_FLASH vm_load(Program *program, byteref _bytes, int length)
void MOVE_TO_FLASH program_load(Program *program, byteref _bytes, int length)
{
if (program->bytes != nullptr && program->endOfTheProgram < length)
{
Expand Down
Loading

0 comments on commit 3d237af

Please sign in to comment.