25
25
MOV_OPS = [None , "~" , "::" , None ]
26
26
SET_DESTINATIONS = ["pins" , "x" , "y" , None , "pindirs" , None , None , None ]
27
27
28
+
28
29
def assemble (text_program ):
29
30
"""Converts pioasm text to encoded instruction bytes"""
30
31
assembled = []
@@ -60,7 +61,7 @@ def assemble(text_program):
60
61
print (instruction )
61
62
instruction = instruction .split ()
62
63
delay = 0
63
- if instruction [- 1 ].endswith ("]" ): # Delay
64
+ if instruction [- 1 ].endswith ("]" ): # Delay
64
65
delay = int (instruction [- 1 ].strip ("[]" ))
65
66
if delay > max_delay :
66
67
raise RuntimeError ("Delay too long:" , delay )
@@ -100,23 +101,23 @@ def assemble(text_program):
100
101
raise RuntimeError ("Wait num out of range" )
101
102
assembled [- 1 ] |= num
102
103
if instruction [- 1 ] == "rel" :
103
- assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
104
+ assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
104
105
elif instruction [0 ] == "in" :
105
106
# instr delay src count
106
107
assembled .append (0b010_00000_000_00000 )
107
108
assembled [- 1 ] |= IN_SOURCES .index (instruction [1 ]) << 5
108
109
count = int (instruction [- 1 ])
109
- if not 1 <= count <= 32 :
110
+ if not 1 <= count <= 32 :
110
111
raise RuntimeError ("Count out of range" )
111
- assembled [- 1 ] |= ( count & 0x1f ) # 32 is 00000 so we mask the top
112
+ assembled [- 1 ] |= count & 0x1F # 32 is 00000 so we mask the top
112
113
elif instruction [0 ] == "out" :
113
114
# instr delay dst count
114
115
assembled .append (0b011_00000_000_00000 )
115
116
assembled [- 1 ] |= OUT_DESTINATIONS .index (instruction [1 ]) << 5
116
117
count = int (instruction [- 1 ])
117
- if not 1 <= count <= 32 :
118
+ if not 1 <= count <= 32 :
118
119
raise RuntimeError ("Count out of range" )
119
- assembled [- 1 ] |= ( count & 0x1f ) # 32 is 00000 so we mask the top
120
+ assembled [- 1 ] |= count & 0x1F # 32 is 00000 so we mask the top
120
121
elif instruction [0 ] == "push" or instruction [0 ] == "pull" :
121
122
# instr delay d i b zero
122
123
assembled .append (0b100_00000_0_0_0_00000 )
@@ -137,13 +138,13 @@ def assemble(text_program):
137
138
# instr delay z c w index
138
139
assembled .append (0b110_00000_0_0_0_00000 )
139
140
if instruction [- 1 ] == "rel" :
140
- assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
141
+ assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
141
142
instruction .pop ()
142
143
num = int (instruction [- 1 ])
143
144
if not 0 <= num <= 7 :
144
145
raise RuntimeError ("Interrupt index out of range" )
145
146
assembled [- 1 ] |= num
146
- if len (instruction ) == 3 : # after rel has been removed
147
+ if len (instruction ) == 3 : # after rel has been removed
147
148
if instruction [1 ] == "wait" :
148
149
assembled [- 1 ] |= 0x20
149
150
elif instruction [1 ] == "clear" :
@@ -154,7 +155,7 @@ def assemble(text_program):
154
155
assembled .append (0b111_00000_000_00000 )
155
156
assembled [- 1 ] |= SET_DESTINATIONS .index (instruction [1 ]) << 5
156
157
value = int (instruction [- 1 ])
157
- if not 0 <= value <= 31 :
158
+ if not 0 <= value <= 31 :
158
159
raise RuntimeError ("Set value out of range" )
159
160
assembled [- 1 ] |= value
160
161
else :
0 commit comments