mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +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);
|
||||
return 10;
|
||||
}
|
||||
let stubHead = "let mx="+memsize+";"+
|
||||
"let fmod=function(a,b){return Number((a-(Math.floor(a/b)*b)).toPrecision(8));};"+
|
||||
"let ip=function(){p=fmod(p+1,mx)};"+
|
||||
"let dp=function(){p=fmod(p-1,mx)};"+
|
||||
"let iv=function(){sys.poke(p,fmod(sys.peek(p)+1,256))};"+
|
||||
"let dv=function(){sys.poke(p,fmod(sys.peek(p)-1,256))};"+
|
||||
"let p="+nativePtr+";"
|
||||
let stubHead = "let x="+memsize+";"+
|
||||
"let a=()=>sys.print(String.fromCharCode(sys.peek(t)));"+
|
||||
"let k=(b)=>sys.poke(t,b);"+
|
||||
"let b=()=>k(sys.readKey());"+
|
||||
"let e=()=>sys.peek(t);"+
|
||||
"let m=(a,b)=>Number((a-(Math.floor(a/b)*b)).toPrecision(8));"+
|
||||
"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 = {
|
||||
62: "ip();",
|
||||
60: "dp();",
|
||||
43: "iv();",
|
||||
45: "dv();",
|
||||
46: "sys.print(String.fromCharCode(sys.peek(p)));",
|
||||
44: "sys.poke(p,sys.readKey());",
|
||||
91: "while(sys.peek(p)!=0){",
|
||||
62: "p();",
|
||||
60: "q();",
|
||||
43: "v();",
|
||||
45: "w();",
|
||||
46: "a();",
|
||||
44: "b();",
|
||||
91: "while(e()){",
|
||||
93: "}"
|
||||
};
|
||||
if (exec_args[1] === undefined) {
|
||||
@@ -32,8 +36,8 @@ if (exec_args[1] === undefined) {
|
||||
}
|
||||
let bfprg = "";
|
||||
try {
|
||||
filesystem.open(_G.shell.getCurrentDrive(), exec_args[1], "R");
|
||||
bfprg = filesystem.readAll(_G.shell.getCurrentDrive());
|
||||
let f = files.open(_G.shell.resolvePathInput(exec_args[1]).full);
|
||||
bfprg = f.sread();
|
||||
}
|
||||
catch(e) {
|
||||
printerrln(e);
|
||||
@@ -53,7 +57,7 @@ try {
|
||||
}
|
||||
|
||||
// run
|
||||
execApp(tprg);
|
||||
eval(tprg);
|
||||
}
|
||||
catch (e) {
|
||||
printerrln(e);
|
||||
|
||||
@@ -17,6 +17,26 @@ const LIST_HEIGHT = HEIGHT - 3
|
||||
const FILESIZE_WIDTH = 7
|
||||
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 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++) {
|
||||
let file = dirFileList[windowMode][i+s]
|
||||
let sizestr = (file) ? bytesToReadable(file.size) : ''
|
||||
let filename = (file) ? file.name : ''
|
||||
let fileext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase()
|
||||
|
||||
// set bg colour
|
||||
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)
|
||||
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
|
||||
let filename = (file) ? file.name : ''
|
||||
con.color_pair(foreCol, backCol)
|
||||
con.move(wo.y + 2+i, wo.x + 1)
|
||||
print(((file && file.isDirectory) ? '\\' : ' ') + filename)
|
||||
@@ -254,12 +275,19 @@ function drawOpPanel() {
|
||||
}
|
||||
|
||||
function redraw() {
|
||||
con.clear()
|
||||
clearScr()
|
||||
drawTitle()
|
||||
drawFilePanel()
|
||||
drawOpPanel()
|
||||
}
|
||||
|
||||
function clearScr() {
|
||||
con.clear()
|
||||
graphics.setBackground(34,51,68)
|
||||
graphics.clearPixels(255)
|
||||
graphics.setGraphicsMode(0)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
con.curs_set(0)
|
||||
@@ -315,8 +343,24 @@ while (!exit) {
|
||||
cursor[windowMode] = 0; scroll[windowMode] = 0
|
||||
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) {
|
||||
path[windowMode].pop()
|
||||
cursor[windowMode] = 0; scroll[windowMode] = 0
|
||||
|
||||
Reference in New Issue
Block a user