diff --git a/duckyscript3_beta_test.md b/duckyscript3_beta_test.md index ee66915a..7f17e381 100644 --- a/duckyscript3_beta_test.md +++ b/duckyscript3_beta_test.md @@ -513,6 +513,14 @@ Returns 0 if no key is pressed. 1 to 17 otherwise. Get how many times the current key has been pressed. +#### `$_CURSORX` (RO) + +Returns current X position of cursor on OLED screen. + +#### `$_CURSORY` (RO) + +Returns current Y position of cursor on OLED screen. + ## Reading Buttons Reading the reserved variable `$_READKEY` returns the currently pressed key. diff --git a/firmware/code_duckyscript3/Inc/ds3_vm.h b/firmware/code_duckyscript3/Inc/ds3_vm.h index 2728ef9a..b0ccef24 100644 --- a/firmware/code_duckyscript3/Inc/ds3_vm.h +++ b/firmware/code_duckyscript3/Inc/ds3_vm.h @@ -89,6 +89,8 @@ #define _LOOP_SIZE (0xffff - 8) #define _KEYPRESS_COUNT (0xffff - 9) #define _NEEDS_EPILOGUE (0xffff - 10) +#define _CURSORX (0xffff - 11) +#define _CURSORY (0xffff - 12) typedef struct { diff --git a/firmware/code_duckyscript3/Inc/ssd1306.h b/firmware/code_duckyscript3/Inc/ssd1306.h index 37795aa6..167bb350 100644 --- a/firmware/code_duckyscript3/Inc/ssd1306.h +++ b/firmware/code_duckyscript3/Inc/ssd1306.h @@ -63,5 +63,6 @@ void ssd1306_SetCursor(uint8_t x, uint8_t y); void ssd1306_dim(uint8_t is_dim); static void ssd1306_WriteCommand(uint8_t command); +extern SSD1306_t SSD1306; #endif diff --git a/firmware/code_duckyscript3/Src/ds3_vm.c b/firmware/code_duckyscript3/Src/ds3_vm.c index de84fc5a..1a9f27db 100644 --- a/firmware/code_duckyscript3/Src/ds3_vm.c +++ b/firmware/code_duckyscript3/Src/ds3_vm.c @@ -22,6 +22,9 @@ uint16_t charjitter_value; uint16_t rand_min, rand_max; uint16_t loop_size; uint8_t epilogue_actions; +uint8_t cursor_x; +uint8_t cursor_y; +extern SSD1306_t SSD1306; typedef struct { @@ -159,6 +162,10 @@ void write_var(uint16_t addr, uint16_t value) ; // this is read only, so do nothing else if (addr == _NEEDS_EPILOGUE) epilogue_actions = value; // this is read only, so do nothing + else if (addr == _CURSORX) + cursor_x = value; // this is read only, so do nothing + else if (addr == _CURSORY) + cursor_y = value; // this is read only, so do nothing else if(addr < VAR_BUF_SIZE) store_uint16_as_two_bytes_at(addr, value); } @@ -189,6 +196,10 @@ uint16_t read_var(uint16_t addr) return key_press_count[current_key]; else if (addr == _NEEDS_EPILOGUE) return epilogue_actions; + else if (addr == _CURSORX) + return SSD1306.CurrentX; + else if (addr == _CURSORY) + return SSD1306.CurrentY; else if(addr < VAR_BUF_SIZE) return make_uint16(var_buf[addr], var_buf[addr+1]); return 0; diff --git a/firmware/code_duckyscript3/Src/ssd1306.c b/firmware/code_duckyscript3/Src/ssd1306.c index 73d0592e..cd47c913 100644 --- a/firmware/code_duckyscript3/Src/ssd1306.c +++ b/firmware/code_duckyscript3/Src/ssd1306.c @@ -33,7 +33,7 @@ static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8]; // Een scherm-object om lokaal in te werken -static SSD1306_t SSD1306; +SSD1306_t SSD1306; uint8_t i2c_status; uint8_t last_dim; diff --git a/pc_software/duckyscript3/keywords.py b/pc_software/duckyscript3/keywords.py index 0e9e74a6..f4784eff 100644 --- a/pc_software/duckyscript3/keywords.py +++ b/pc_software/duckyscript3/keywords.py @@ -389,4 +389,6 @@ def replace_DEFINE(pgm_line, dd): "_LOOP_SIZE": (0xffff - 8), "_KEYPRESS_COUNT": (0xffff - 9), "_NEEDS_EPILOGUE": (0xffff - 10), -} \ No newline at end of file + "_CURSORX": (0xffff - 11), + "_CURSORY": (0xffff - 12) +}