blob: fdb9e0b5ad26599a72b83e8e7a9ca6cdffda46db (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sokoban Bitmap Editor</title>
<script type="text/javascript">
var grid = new Array(0);
function Init() {
grid = InitGrid();
DisplayGrid();
}
function InitGrid() {
var _grid = new Array(16);
for (i=0; i<16; i++) {
_grid[i] = new Array(16);
for (j=0; j<16; j++) {
_grid[i][j]=false;
}
}
return _grid;
}
function RotateBitmapRight() {
var _grid = InitGrid();
for (i=0; i<16; i++) {
for (j=0; j<16; j++) {
_grid[j][15-i]=grid[i][j];
}
}
grid = _grid;
DisplayGrid();
}
function MirrorBitmap() {
var _grid = InitGrid();
for (i=0; i<16; i++) {
for (j=0; j<16; j++) {
_grid[i][15-j]=grid[i][j];
}
}
grid = _grid;
DisplayGrid();
}
function DisplayGrid() {
var str = "<table border=1 cellspacing=0>";
var i,j, backgroundColor;
for (i=-1; i<16; i++) {
str=str+"<tr>";
for (j=-1; j<16; j++) {
if (i == -1 && j != -1) {
str=str+"<td>" + (j+1) + "</td>";
} else if (i != -1 && j == -1) {
str=str+"<td>" + (i+1) + "</td>";
} else if (i ==-1 && j == -1) {
str=str+"<td/>";
} else {
if (grid[i][j] == true)
backgroundColor = "black";
else
backgroundColor = "white";
str=str+"<td onclick=\"OnCellClicked(this)\" id="; str=str+(i*16+j); str=str+" width=16 height=16 bgcolor=" + backgroundColor + "></td>";
}
}
str=str+"</tr>";
}
str=str+"</table>"
gridElement = document.getElementById('grid');
gridElement.innerHTML = str;
GenerateBitMap() ;
}
function OnCellClicked(cell) {
var i = cell.id / 16 |0;
var j = cell.id - i*16;
grid[i][j] = !grid[i][j];
if (grid[i][j])
cell.style.backgroundColor = "black";
else
cell.style.backgroundColor = "white";
GenerateBitMap();
}
function GenerateBitMap() {
var i, j;
var value;
var functionTypeSelect = document.getElementById('functionType');
methodType = functionTypeSelect.options[functionTypeSelect.selectedIndex].value;
generateCode = document.getElementById('generatedCode');
generateCode.value = methodType + " void " +
document.getElementById('functionName').value +
"(int location) {\n\tlet memAddress = 16384+location;\n";
for (i=0; i<16; i++) {
//get grid binary representation
binary = "";
for (j=0; j<16; j++) {
if (grid[i][j])
binary = "1" + binary;
else
binary = "0" + binary;
}
isNegative = false;
//if number is negative, get its one's complement
if (binary[0] == "1") {
isNegative = true;
oneComplement = "";
for (k=0; k<16; k++) {
if (binary[k] == "1")
oneComplement = oneComplement + "0";
else
oneComplement = oneComplement + "1";
}
binary = oneComplement;
}
//calculate one's complement decimal value
value = 0;
for (k=0; k<16; k++) {
value = value * 2;
if (binary[k] == "1")
value=value+1;
}
//two's complement value if it is a negative value
if (isNegative == true)
value = -(value + 1)
generateCode.value = generateCode.value + GenerateCodeLine(i, value);
}
generateCode.value = generateCode.value + "\treturn;\n}";
}
function GenerateCodeLine(row, value) {
str = "\tdo Memory.poke(memAddress+" + row*32 + ", " + value + ");\n";
return str;
}
</script>
</head>
<body onload="Init();">
<h4><i>IDC Herzliya / Efi Arazi School of Computer Science / Digital Systems Construction, Spring 2011 / Project 09 / Golan Parashi</i></h4>
<h1>Sokoban Bitmap Editor</h1>
<p>This javascript applicaiton is used to generate highly optimized jack code for drawing a 16x16 bitmap to the screen.</p>
<p>Using the mouse, click the desired cell to mark/unmark it. You may use 90 degrees rotation and vertical mirroring by<br>
clicking the appropriate buttons.</p>
<p>When you are finished drawing, you may select function type and enter function's name.</p>
<p>
<table>
<thead>
<tr>
<th align="left">Bitmap</th>
<th align="left"></th>
<th align="left">Generated Jack Code</th>
</tr>
</thead>
<tr>
<td><div id="grid"/></td>
<td>
<form action="javascript:GenerateBitMap();">
<table>
<tr><td align="left">Function Type:</td></tr>
<tr><td align="center">
<select id="functionType" onChange="GenerateBitMap()">
<option value="function" selected="selected">function</option>
<option value="method">method</option>
</select>
</td></tr>
<tr><td align="left">Function Name:</td></tr>
<tr><td align="left"><input type="text" value="draw" id="functionName" onkeyup="GenerateBitMap()"/></td></tr>
<tr><td></td></tr>
<tr><td align="center"><input type="button" value="Generate Code >>" onclick="GenerateBitMap()"/></td></tr>
</table>
</form>
</td>
<td><textarea id="generatedCode" cols="50" rows="20" readonly="read-only"></textarea></td>
</tr>
<tr>
<table>
<tr>
<td align="center"><input type="button" value="Rotate right" onclick="RotateBitmapRight()"/></td>
<td align="center"><input type="button" value="Vertical Mirror" onclick="MirrorBitmap()"/></td>
</tr>
</table>
</tr>
</table>
</body>
</html>
|