Skip to content
This repository was archived by the owner on Sep 15, 2023. It is now read-only.

Commit 499ba9b

Browse files
committed
keyhandling
sub if not
1 parent 4d9f65d commit 499ba9b

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

code

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
set @img1
22
v2 0
33
v1 0
4+
v4 1
45
label start
56
sprite v1 v2 1
6-
add v1 1
7-
add v2 2
87
key v3
8+
skip if v3 not 05
9+
exec @top
10+
skip if v3 not 07
11+
exec @left
12+
skip if v3 not 08
13+
exec @bottom
14+
skip if v3 not 09
15+
exec @right
916
jump @start
17+
label left
18+
sub v1 v4
19+
return
20+
label right
21+
add v1 1
22+
return
23+
label top
24+
sub v2 v4
25+
return
26+
label bottom
27+
add v2 1
28+
return
1029
label img1
11-
ff
12-
ff
13-
88
14-
00
15-
00
16-
00
30+
80

compile.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
from typing import Dict
33
import re
44

5+
def hexa(i):
6+
h = hex(i)
7+
if len(h) == 3:
8+
return "0" + h[2]
9+
else:
10+
return h[2:]
11+
512
MNEMS = [
6-
("0(...)", lambda x: "Deprecated (Machine Exec)"),
713
("00E0" , lambda : "Clear"),
814
("00EE" , lambda : "Return"),
15+
("0(...)", lambda x: "Deprecated (Machine Exec)"),
916
("1(...)" , lambda x: f"Jump {x}"),
1017
("2(...)" , lambda x: f"Exec {x}"),
1118
("3(.)(..)" , lambda x, y: f"Skip v{x}=={y}"),
@@ -65,7 +72,8 @@ def location(s):
6572
l = labels[s[1:]]
6673
else:
6774
l = int(s, 16)
68-
return l // 0xff, l % 0xff
75+
h = hexa(l)
76+
return int(h[::-1][2:4][::-1], 16), int(h[::-1][0:2][::-1], 16)
6977

7078
for line in lines:
7179
l = line.split(" ")
@@ -74,6 +82,8 @@ def location(s):
7482
fake("A" + l[1])
7583
elif l[0] == "jump":
7684
fake("1"+ l[1])
85+
elif l[0] == "exec":
86+
fake("2"+ l[1])
7787
elif l[0] == "label":
7888
labels[l[1]] = counter
7989
elif l[0][0] == "v":
@@ -92,29 +102,39 @@ def location(s):
92102
elif l[0] == "add":
93103
op("7" + l[1][1])
94104
op(l[2])
105+
elif l[0] == "sub":
106+
op("8" + l[1][1])
107+
op(l[2][1] + "5")
108+
elif l[0] == "return":
109+
op("00")
110+
op("EE")
111+
elif l[0] == "skip" and l[1] == "if" and l[3] == "not":
112+
op("4" + l[2][1])
113+
op(l[4])
95114
else:
96115
op(l[0])
97116

98117
codes = []
99118

119+
def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
120+
return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])
121+
100122
for c in out:
101123
if type(c) == str:
102124
l1, l2 = location(c[1:])
125+
print(c[1:])
126+
print(hexa(l1))
127+
print(hexa(l2))
128+
103129
codes.append(int(c[0] + hex(l1)[2:], 16))
104130
codes.append(l2)
105131
else:
106132
codes.append(c)
107133

108134
for label in labels:
109-
print(f"{label}: {labels[label]}")
135+
print(f"{label}: {baseN(labels[label], 16)}")
110136

111137

112-
def hexa(i):
113-
h = hex(i)
114-
if len(h) == 3:
115-
return "0" + h[2]
116-
else:
117-
return h[2:]
118138

119139

120140
def get_mem(code):
@@ -126,9 +146,15 @@ def get_mem(code):
126146

127147

128148
for i in range(0, len(codes), 2):
129-
h1, h2 = hexa(codes[i]).upper(), hexa(codes[i+1]).upper()
130-
mem = get_mem(h1+h2)
131-
print(f"{i+512} {h1} {h2} {mem}")
149+
if i < len(codes)-1:
150+
h1, h2 = hexa(codes[i]).upper(), hexa(codes[i+1]).upper()
151+
mem = get_mem(h1+h2)
152+
print(f"{hexa(i+512)} {h1} {h2} {mem}")
153+
else:
154+
h1, h2 = hexa(codes[i]).upper(), "00"
155+
mem = get_mem(h1+h2)
156+
print(f"{hexa(i+512)} {h1} {h2} {mem}")
157+
132158

133159

134160
with open("template.html") as f:

out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- Standalone Generated By Octo (octo-ide.com) -->
22
<script>data={"program":"","options":{},
33
"rom":[
4-
162,18,98,0,97,0,209,33,113,1,114,2,243,10,18,8,255,255,136,0,0,0
4+
162,46,98,0,97,0,100,1,209,33,243,10,67,5,34,38,67,7,34,30,67,8,34,42,67,9,34,34,18,8,129,69,0,238,113,1,0,238,130,69,0,238,114,1,0,238,128
55
]}</script
66
>
77
<script>"use strict";

0 commit comments

Comments
 (0)