-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmads-strings.html
77 lines (68 loc) · 1.87 KB
/
mads-strings.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
<head>
<title>Mads Assembler - String Utility</title>
<!-- Converts ASCII string to sequence of char for usage in FPC -->
</head>
<script>
function convertToCode(){
var inTextArea = document.getElementById("in");
var outTextArea = document.getElementById("out");
var inValue = inTextArea.value;
var code = "";
var firstInCode = true;
var line = "";
var firstInLine = true;
for(var i=0;i<inValue.length;i++) {
var c=inValue.charAt(i);
var newLine = false;
if (c == '\n') {
newLine = true;
}
var textEnd = false;
if (i==inValue.length-1){
textEnd = true;
}
if (firstInLine && !firstInCode){
line = " ";
}
var cString = "'"+c+"'";
if (firstInCode) {
cString = "chr(ord("+cString+") + $80)";
firstInCode = false;
}
if (newLine) {
cString = "#13,#10";
} else if (c == '\t') {
cString = "#9";
}
line += cString+",";
firstInLine=false;
if (newLine==true || textEnd==true){
code += line+"\n";
line = "";
firstInLine = true;
}
}
outTextArea.value = code;
logMessage("Text converted to code.");
};
function convertToText(){
};
function logMessage(message){
var logTextArea = document.getElementById("log");
logTextArea.value = new Date().toString()+": "+message
};
</script>
<body>
<textarea id="in" cols="132" rows="20" placeholder="Your text">Example	Tab Text
</textarea>
<br>
<button id="convterToCodeButton" onclick="convertToCode();">Convert to Code</button>
<br><br>
<textarea id="out" cols="160" rows="20" placeholder="Your code"></textarea>
<br>
<!-- <button id="convterToTextButton" onclick="convertToText();">Convert to Text</button> -->
<br><br>
<textarea id="log" cols="132" placeholder="Log"></textarea>
</body>
</html>