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"""
31+ # pylint: disable=too-many-branches,too-many-statements
3032 assembled = []
3133 program_name = None
3234 labels = {}
@@ -60,7 +62,7 @@ def assemble(text_program):
6062 print (instruction )
6163 instruction = instruction .split ()
6264 delay = 0
63- if instruction [- 1 ].endswith ("]" ): # Delay
65+ if instruction [- 1 ].endswith ("]" ): # Delay
6466 delay = int (instruction [- 1 ].strip ("[]" ))
6567 if delay > max_delay :
6668 raise RuntimeError ("Delay too long:" , delay )
@@ -100,23 +102,23 @@ def assemble(text_program):
100102 raise RuntimeError ("Wait num out of range" )
101103 assembled [- 1 ] |= num
102104 if instruction [- 1 ] == "rel" :
103- assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
105+ assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
104106 elif instruction [0 ] == "in" :
105107 # instr delay src count
106108 assembled .append (0b010_00000_000_00000 )
107109 assembled [- 1 ] |= IN_SOURCES .index (instruction [1 ]) << 5
108110 count = int (instruction [- 1 ])
109- if not 1 <= count <= 32 :
111+ if not 1 <= count <= 32 :
110112 raise RuntimeError ("Count out of range" )
111- assembled [- 1 ] |= ( count & 0x1f ) # 32 is 00000 so we mask the top
113+ assembled [- 1 ] |= count & 0x1F # 32 is 00000 so we mask the top
112114 elif instruction [0 ] == "out" :
113115 # instr delay dst count
114116 assembled .append (0b011_00000_000_00000 )
115117 assembled [- 1 ] |= OUT_DESTINATIONS .index (instruction [1 ]) << 5
116118 count = int (instruction [- 1 ])
117- if not 1 <= count <= 32 :
119+ if not 1 <= count <= 32 :
118120 raise RuntimeError ("Count out of range" )
119- assembled [- 1 ] |= ( count & 0x1f ) # 32 is 00000 so we mask the top
121+ assembled [- 1 ] |= count & 0x1F # 32 is 00000 so we mask the top
120122 elif instruction [0 ] == "push" or instruction [0 ] == "pull" :
121123 # instr delay d i b zero
122124 assembled .append (0b100_00000_0_0_0_00000 )
@@ -137,13 +139,13 @@ def assemble(text_program):
137139 # instr delay z c w index
138140 assembled .append (0b110_00000_0_0_0_00000 )
139141 if instruction [- 1 ] == "rel" :
140- assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
142+ assembled [- 1 ] |= 0x10 # Set the high bit of the irq value
141143 instruction .pop ()
142144 num = int (instruction [- 1 ])
143145 if not 0 <= num <= 7 :
144146 raise RuntimeError ("Interrupt index out of range" )
145147 assembled [- 1 ] |= num
146- if len (instruction ) == 3 : # after rel has been removed
148+ if len (instruction ) == 3 : # after rel has been removed
147149 if instruction [1 ] == "wait" :
148150 assembled [- 1 ] |= 0x20
149151 elif instruction [1 ] == "clear" :
@@ -154,7 +156,7 @@ def assemble(text_program):
154156 assembled .append (0b111_00000_000_00000 )
155157 assembled [- 1 ] |= SET_DESTINATIONS .index (instruction [1 ]) << 5
156158 value = int (instruction [- 1 ])
157- if not 0 <= value <= 31 :
159+ if not 0 <= value <= 31 :
158160 raise RuntimeError ("Set value out of range" )
159161 assembled [- 1 ] |= value
160162 else :
0 commit comments