mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 22:54:03 +09:00
zfm: simple exec with enter key
This commit is contained in:
@@ -9,21 +9,25 @@ catch (e) {
|
|||||||
printerrln("Could not allocate memory with size "+memsize);
|
printerrln("Could not allocate memory with size "+memsize);
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
let stubHead = "let mx="+memsize+";"+
|
let stubHead = "let x="+memsize+";"+
|
||||||
"let fmod=function(a,b){return Number((a-(Math.floor(a/b)*b)).toPrecision(8));};"+
|
"let a=()=>sys.print(String.fromCharCode(sys.peek(t)));"+
|
||||||
"let ip=function(){p=fmod(p+1,mx)};"+
|
"let k=(b)=>sys.poke(t,b);"+
|
||||||
"let dp=function(){p=fmod(p-1,mx)};"+
|
"let b=()=>k(sys.readKey());"+
|
||||||
"let iv=function(){sys.poke(p,fmod(sys.peek(p)+1,256))};"+
|
"let e=()=>sys.peek(t);"+
|
||||||
"let dv=function(){sys.poke(p,fmod(sys.peek(p)-1,256))};"+
|
"let m=(a,b)=>Number((a-(Math.floor(a/b)*b)).toPrecision(8));"+
|
||||||
"let p="+nativePtr+";"
|
"let p=()=>{t=m(t+1,x)};"+
|
||||||
|
"let q=()=>{t=m(t-1,x)};"+
|
||||||
|
"let v=()=>k(m(e()+1,256));"+
|
||||||
|
"let w=()=>k(m(e()-1,256));"+
|
||||||
|
"let t="+nativePtr+";"
|
||||||
let translation = {
|
let translation = {
|
||||||
62: "ip();",
|
62: "p();",
|
||||||
60: "dp();",
|
60: "q();",
|
||||||
43: "iv();",
|
43: "v();",
|
||||||
45: "dv();",
|
45: "w();",
|
||||||
46: "sys.print(String.fromCharCode(sys.peek(p)));",
|
46: "a();",
|
||||||
44: "sys.poke(p,sys.readKey());",
|
44: "b();",
|
||||||
91: "while(sys.peek(p)!=0){",
|
91: "while(e()){",
|
||||||
93: "}"
|
93: "}"
|
||||||
};
|
};
|
||||||
if (exec_args[1] === undefined) {
|
if (exec_args[1] === undefined) {
|
||||||
@@ -32,8 +36,8 @@ if (exec_args[1] === undefined) {
|
|||||||
}
|
}
|
||||||
let bfprg = "";
|
let bfprg = "";
|
||||||
try {
|
try {
|
||||||
filesystem.open(_G.shell.getCurrentDrive(), exec_args[1], "R");
|
let f = files.open(_G.shell.resolvePathInput(exec_args[1]).full);
|
||||||
bfprg = filesystem.readAll(_G.shell.getCurrentDrive());
|
bfprg = f.sread();
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
printerrln(e);
|
printerrln(e);
|
||||||
@@ -53,7 +57,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
execApp(tprg);
|
eval(tprg);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
printerrln(e);
|
printerrln(e);
|
||||||
|
|||||||
@@ -17,6 +17,26 @@ const LIST_HEIGHT = HEIGHT - 3
|
|||||||
const FILESIZE_WIDTH = 7
|
const FILESIZE_WIDTH = 7
|
||||||
const FILELIST_WIDTH = WIDTH - SIDEBAR_WIDTH - 3 - FILESIZE_WIDTH
|
const FILELIST_WIDTH = WIDTH - SIDEBAR_WIDTH - 3 - FILESIZE_WIDTH
|
||||||
|
|
||||||
|
const COL_HL_EXT = {
|
||||||
|
"js": 215,
|
||||||
|
"bas": 215,
|
||||||
|
"bat": 215,
|
||||||
|
"wav": 31,
|
||||||
|
"adpcm": 32,
|
||||||
|
"mov": 213,
|
||||||
|
"ipf1": 190,
|
||||||
|
"ipf2": 191,
|
||||||
|
"txt": 223,
|
||||||
|
"md": 223,
|
||||||
|
}
|
||||||
|
|
||||||
|
const EXEC_FUNS = {
|
||||||
|
"wav": (f) => { _G.shell.execute(`playwav ${f}`) },
|
||||||
|
"adpcm": (f) => { _G.shell.execute(`playwav ${f}`) },
|
||||||
|
"mov": (f) => { _G.shell.execute(`playmov ${f}`) },
|
||||||
|
"bas": (f) => { _G.shell.execute(`basic ${f}`) }
|
||||||
|
}
|
||||||
|
|
||||||
let windowMode = 0 // 0 == left, 1 == right
|
let windowMode = 0 // 0 == left, 1 == right
|
||||||
let windowFocus = 0 // 0,2: files panel, 1: operation panel, -1: a wild popup message appeared
|
let windowFocus = 0 // 0,2: files panel, 1: operation panel, -1: a wild popup message appeared
|
||||||
|
|
||||||
@@ -89,14 +109,15 @@ let filesPanelDraw = (wo) => {
|
|||||||
for (let i = 0; i < LIST_HEIGHT; i++) {
|
for (let i = 0; i < LIST_HEIGHT; i++) {
|
||||||
let file = dirFileList[windowMode][i+s]
|
let file = dirFileList[windowMode][i+s]
|
||||||
let sizestr = (file) ? bytesToReadable(file.size) : ''
|
let sizestr = (file) ? bytesToReadable(file.size) : ''
|
||||||
|
let filename = (file) ? file.name : ''
|
||||||
|
let fileext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase()
|
||||||
|
|
||||||
// set bg colour
|
// set bg colour
|
||||||
let backCol = (i == cursor[windowMode] - s) ? COL_BACK_SEL : COL_BACK
|
let backCol = (i == cursor[windowMode] - s) ? COL_BACK_SEL : COL_BACK
|
||||||
// set fg colour (if there are more at the top/bottom, dim the colour)
|
// set fg colour (if there are more at the top/bottom, dim the colour)
|
||||||
let foreCol = (i == 0 && s > 0 || i == LIST_HEIGHT - 1 && i + s < filesCount - 1) ? COL_DIMTEXT : COL_TEXT
|
let foreCol = (i == 0 && s > 0 || i == LIST_HEIGHT - 1 && i + s < filesCount - 1) ? COL_DIMTEXT : (COL_HL_EXT[fileext] || COL_TEXT)
|
||||||
|
|
||||||
// print filename
|
// print filename
|
||||||
let filename = (file) ? file.name : ''
|
|
||||||
con.color_pair(foreCol, backCol)
|
con.color_pair(foreCol, backCol)
|
||||||
con.move(wo.y + 2+i, wo.x + 1)
|
con.move(wo.y + 2+i, wo.x + 1)
|
||||||
print(((file && file.isDirectory) ? '\\' : ' ') + filename)
|
print(((file && file.isDirectory) ? '\\' : ' ') + filename)
|
||||||
@@ -254,12 +275,19 @@ function drawOpPanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function redraw() {
|
function redraw() {
|
||||||
con.clear()
|
clearScr()
|
||||||
drawTitle()
|
drawTitle()
|
||||||
drawFilePanel()
|
drawFilePanel()
|
||||||
drawOpPanel()
|
drawOpPanel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearScr() {
|
||||||
|
con.clear()
|
||||||
|
graphics.setBackground(34,51,68)
|
||||||
|
graphics.clearPixels(255)
|
||||||
|
graphics.setGraphicsMode(0)
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
con.curs_set(0)
|
con.curs_set(0)
|
||||||
@@ -315,8 +343,24 @@ while (!exit) {
|
|||||||
cursor[windowMode] = 0; scroll[windowMode] = 0
|
cursor[windowMode] = 0; scroll[windowMode] = 0
|
||||||
drawFilePanel()
|
drawFilePanel()
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
let fileext = selectedFile.name.substring(selectedFile.name.lastIndexOf(".") + 1).toLowerCase()
|
||||||
|
let execfun = EXEC_FUNS[fileext] || ((f) => { _G.shell.execute(f) })
|
||||||
|
|
||||||
|
con.curs_set(1);clearScr();con.move(1,1)
|
||||||
|
try {
|
||||||
|
serial.println(selectedFile.fullPath)
|
||||||
|
execfun(selectedFile.fullPath)
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// TODO popup error
|
||||||
|
serial.println(e)
|
||||||
|
}
|
||||||
|
con.curs_set(0);clearScr()
|
||||||
|
redraw()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (keyJustHit && keysym == 'u') {
|
else if (keyJustHit && (keysym == 'u' || keycode == 67)) { // bksp
|
||||||
if (path[windowMode].length > 1) {
|
if (path[windowMode].length > 1) {
|
||||||
path[windowMode].pop()
|
path[windowMode].pop()
|
||||||
cursor[windowMode] = 0; scroll[windowMode] = 0
|
cursor[windowMode] = 0; scroll[windowMode] = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user