2525MOV_OPS = [None , "~" , "::" , None ]
2626SET_DESTINATIONS = ["pins" , "x" , "y" , None , "pindirs" , None , None , None ]
2727
28+
2829def assemble (text_program ):
2930 """Converts pioasm text to encoded instruction bytes"""
3031 assembled = []
@@ -60,7 +61,7 @@ def assemble(text_program):
6061 print (instruction )
6162 instruction = instruction .split ()
6263 delay = 0
63- if instruction [- 1 ].endswith ("]" ): # Delay
64+ if instruction [- 1 ].endswith ("]" ): # Delay
6465 delay = int (instruction [- 1 ].strip ("[]" ))
6566 if delay > max_delay :
6667 raise RuntimeError ("Delay too long:" , delay )
@@ -100,23 +101,23 @@ def assemble(text_program):
100101 raise RuntimeError ("Wait num out of range" )
101102 assembled [- 1 ] |= num
102103 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
104105 elif instruction [0 ] == "in" :
105106 # instr delay src count
106107 assembled .append (0b010_00000_000_00000 )
107108 assembled [- 1 ] |= IN_SOURCES .index (instruction [1 ]) << 5
108109 count = int (instruction [- 1 ])
109- if not 1 <= count <= 32 :
110+ if not 1 <= count <= 32 :
110111 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
112113 elif instruction [0 ] == "out" :
113114 # instr delay dst count
114115 assembled .append (0b011_00000_000_00000 )
115116 assembled [- 1 ] |= OUT_DESTINATIONS .index (instruction [1 ]) << 5
116117 count = int (instruction [- 1 ])
117- if not 1 <= count <= 32 :
118+ if not 1 <= count <= 32 :
118119 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
120121 elif instruction [0 ] == "push" or instruction [0 ] == "pull" :
121122 # instr delay d i b zero
122123 assembled .append (0b100_00000_0_0_0_00000 )
@@ -137,13 +138,13 @@ def assemble(text_program):
137138 # instr delay z c w index
138139 assembled .append (0b110_00000_0_0_0_00000 )
139140 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
141142 instruction .pop ()
142143 num = int (instruction [- 1 ])
143144 if not 0 <= num <= 7 :
144145 raise RuntimeError ("Interrupt index out of range" )
145146 assembled [- 1 ] |= num
146- if len (instruction ) == 3 : # after rel has been removed
147+ if len (instruction ) == 3 : # after rel has been removed
147148 if instruction [1 ] == "wait" :
148149 assembled [- 1 ] |= 0x20
149150 elif instruction [1 ] == "clear" :
@@ -154,7 +155,7 @@ def assemble(text_program):
154155 assembled .append (0b111_00000_000_00000 )
155156 assembled [- 1 ] |= SET_DESTINATIONS .index (instruction [1 ]) << 5
156157 value = int (instruction [- 1 ])
157- if not 0 <= value <= 31 :
158+ if not 0 <= value <= 31 :
158159 raise RuntimeError ("Set value out of range" )
159160 assembled [- 1 ] |= value
160161 else :
0 commit comments