Skip to content

Commit 5776a34

Browse files
Deep Thoughtmarijnh
authored andcommitted
Add z80 mode
1 parent 6f25579 commit 5776a34

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

doc/compress.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
115115
<option value="http://codemirror.net/mode/xml/xml.js">xml.js</option>
116116
<option value="http://codemirror.net/mode/xquery/xquery.js">xquery.js</option>
117117
<option value="http://codemirror.net/mode/yaml/yaml.js">yaml.js</option>
118+
<option value="http://codemirror.net/mode/z80/z80.js">z80.js</option>
118119
</optgroup>
119120
<optgroup label="Utilities and add-ons">
120121
<option value="http://codemirror.net/lib/util/overlay.js">overlay.js</option>

doc/realworld.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ <h1><span class="logo-braces">{ }</span> <a href="http://codemirror.net/">CodeMi
5252
<li><a href="http://www.chris-granger.com/2012/04/12/light-table---a-new-ide-concept/">Light Table</a> (experimental IDE)</li>
5353
<li><a href="http://www.mergely.com/">Mergely</a> (interactive diffing)</li>
5454
<li><a href="https://notex.ch">NoTex</a> (rST authoring)</li>
55+
<li><a href="http://clrhome.org/asm/">ORG</a> (z80 assembly IDE)</li>
5556
<li><a href="https://github.com/mamacdon/orion-codemirror">Orion-CodeMirror integration</a> (running CodeMirror modes in Orion)</li>
5657
<li><a href="http://paperjs.org/">Paper.js</a> (graphics scripting)</li>
5758
<li><a href="http://prose.io/">Prose.io</a> (github content editor)</li>

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ <h2 style="margin-top: 0">Supported modes:</h2>
8787
<li><a href="mode/xml/index.html">XML/HTML</a></li>
8888
<li><a href="mode/xquery/index.html">XQuery</a></li>
8989
<li><a href="mode/yaml/index.html">YAML</a></li>
90+
<li><a href="mode/z80/index.html">Z80</a></li>
9091
</ul>
9192

9293
</div><div class="left2 blk">

mode/z80/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>CodeMirror: Z80 assembly mode</title>
6+
<link rel="stylesheet" href="../../lib/codemirror.css">
7+
<script src="../../lib/codemirror.js"></script>
8+
<script src="z80.js"></script>
9+
<link rel="stylesheet" href="../../doc/docs.css">
10+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
11+
</head>
12+
<body>
13+
<h1>CodeMirror: Z80 assembly mode</h1>
14+
15+
<div><textarea id="code" name="code">
16+
#include "ti83plus.inc"
17+
#define progStart $9D95
18+
.org progStart-2
19+
.db $BB,$6D
20+
bcall(_ClrLCDFull)
21+
ld HL, 0
22+
ld (PenCol), HL
23+
ld HL, Message
24+
bcall(_PutS) ; Displays the string
25+
bcall(_NewLine)
26+
ret
27+
Message:
28+
.db "Hello world!",0
29+
</textarea></div>
30+
31+
<script>
32+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
33+
lineNumbers: true
34+
});
35+
</script>
36+
37+
<p><strong>MIME type defined:</strong> <code>text/x-z80</code>.</p>
38+
</body>
39+
</html>

mode/z80/z80.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
CodeMirror.defineMode('z80', function()
2+
{
3+
var keywords1 = /^(exx?|(ld|cp|in)([di]r?)?|pop|push|ad[cd]|cpl|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr]c?a?|r[lr]d|s[lr]a|srl|djnz|nop|rst|[de]i|halt|im|ot[di]r|out[di]?)\b/i;
4+
var keywords2 = /^(call|j[pr]|ret[in]?)\b/i;
5+
var keywords3 = /^b_?(call|jump)\b/i;
6+
var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i;
7+
var variables2 = /^(n?[zc]|p[oe]?|m)\b/i;
8+
var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i;
9+
var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+)\b/i;
10+
11+
return {startState: function()
12+
{
13+
return {context: 0};
14+
}, token: function(stream, state)
15+
{
16+
if (!stream.column())
17+
state.context = 0;
18+
19+
if (stream.eatSpace())
20+
return null;
21+
22+
var w;
23+
24+
if (stream.eatWhile(/\w/))
25+
{
26+
w = stream.current();
27+
28+
if (stream.indentation())
29+
{
30+
if (state.context == 1 && variables1.test(w))
31+
return 'variable-2';
32+
33+
if (state.context == 2 && variables2.test(w))
34+
return 'variable-3';
35+
36+
if (keywords1.test(w))
37+
{
38+
state.context = 1;
39+
return 'keyword';
40+
}
41+
else if (keywords2.test(w))
42+
{
43+
state.context = 2;
44+
return 'keyword';
45+
}
46+
else if (keywords3.test(w))
47+
{
48+
state.context = 3;
49+
return 'keyword';
50+
}
51+
52+
if (errors.test(w))
53+
return 'error';
54+
}
55+
else if (numbers.test(w))
56+
{
57+
return 'number';
58+
}
59+
else
60+
{
61+
return null;
62+
}
63+
}
64+
else if (stream.eat(';'))
65+
{
66+
stream.skipToEnd();
67+
return 'comment';
68+
}
69+
else if (stream.eat('"'))
70+
{
71+
while (w = stream.next())
72+
{
73+
if (w == '"')
74+
break;
75+
76+
if (w == '\\')
77+
stream.next();
78+
}
79+
80+
return 'string';
81+
}
82+
else if (stream.eat('\''))
83+
{
84+
if (stream.match(/\\?.'/))
85+
return 'number';
86+
}
87+
else if (stream.eat('.') || stream.sol() && stream.eat('#'))
88+
{
89+
state.context = 4;
90+
91+
if (stream.eatWhile(/\w/))
92+
return 'def';
93+
}
94+
else if (stream.eat('$'))
95+
{
96+
if (stream.eatWhile(/[\da-f]/i))
97+
return 'number';
98+
}
99+
else if (stream.eat('%'))
100+
{
101+
if (stream.eatWhile(/[01]/))
102+
return 'number';
103+
}
104+
else
105+
{
106+
stream.next();
107+
}
108+
109+
return null;
110+
}};
111+
});
112+
113+
CodeMirror.defineMIME("text/x-z80", "z80");

0 commit comments

Comments
 (0)