More questions/concerns:
-Getting error: initializer element is not constant, on char *buffer = malloc(256);
-Getting error: invalid initializer, on buffer[0]='\0';
-The cursor blinks for key input but it won't detect any key presses
Code:
#include <display_syscalls.h>
#include <keyboard_syscalls.h>
#include "color.h"
#include <keyboard_syscalls.h>
#include <keyboard.h>
#include <keyboard.hpp>
#include <string.h>
#include <system.h>
#include <stdlib.h>
#include <stdio.h>
//Different modes of opening and creating files
#define CREATEMODE_FILE 1
#define CREATEMODE_FOLDER 5
#define READ 0
#define READ_SHARE 1
#define WRITE 2
#define READWRITE 3
#define READWRITE_SHARE 4
#define RETURN_SUCCESS 0
#define RETURN_ERROR -1
unsigned short filebuffer[] = {'\\','\\','f','l','s','0','\\','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0','\0'}; //the 16-bit buffer where the filename will be stored, Note: the \ is escaped so it looks like \\
char *buffer = malloc(256); // Some string length
//char buffer[256];
int start = 0; // Used for scrolling left and right
int cursor = 0; // Cursor position
buffer[0] = '\0'; // This sets the first character to \0, also represented by "", an empty string
void keymenu();
int PRGM_GetKey();
int inMenu=0;
int Counter=0;
int x=72;
int y=173;
int update=1;
int key;
int CursorX=1;
int CursorY=1;
int main(void) {
int fh;
char* filename = "new.lua"; //the name of the file
while(1) {
if(PRGM_GetKey() == KEY_PRGM_MENU) {
keymenu();
}
if (update==1) {
update=0;
DisplayMBString( buffer, start, cursor, 1, 1);
}
if (keydown(KEY_PRGM_F5) & (inMenu==1)) {
PrintCXY( 55, 173, " ", TEXT_MODE_NORMAL, -1, COLOR_BLACK, COLOR_WHITE, 1, 0 );
while (keydown(KEY_PRGM_EXIT)==0) {
GetKey(&key);
EditMBStringCtrl( buffer, 256, &start, &cursor, &key, 1, 1); Bdisp_PutDisp_DD();
}
update=1;
}
if (keydown(KEY_PRGM_F1)) {
if ((inMenu==0) & (Counter==0)) {
inMenu=1;
Counter=15;
y=173;
x=72;
PrintMini( &x, &y, "New Save Open Edit", 0, 0xffffffff, 0, 0, COLOR_BLACK, COLOR_WHITE, 1, 0);
}
if ((inMenu==1) & (Counter==0)) {
inMenu=0;
Counter=15;
PrintCXY( 55, 173, " ", TEXT_MODE_NORMAL, -1, COLOR_BLACK, COLOR_WHITE, 1, 0 );
}
}
if ((keydown(KEY_PRGM_F2)) & (inMenu==1)) {
Bfile_StrToName_ncpy(filebuffer+(7), filename, strlen(filename)); //copy the filename to the filebuffer after "\\fls0\"
//Actually create the file
int size = 256;
if (0 > (fh = Bfile_OpenFile_OS(filebuffer,READWRITE))) {
if (Bfile_CreateEntry_OS(filebuffer, CREATEMODE_FILE, &size) < 0)
return RETURN_ERROR;
}
}
if (Counter!=0) Counter--;
Bdisp_PutDisp_DD();
}
free(buffer);
return 0;
}
int PRGM_GetKey(){
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
void keymenu(void) {
int key = KEY_PRGM_MENU;
GetKey(&key);
}
int keydown(int basic_keycode) {
const unsigned short* lastkey = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (lastkey[word] & 1<<bit));
}