@@ -92,6 +92,18 @@ def int_in_range(arg, low, high, what, radix=0):
92
92
f"{ what } must be at least { low } and no greater than { high } , got { result } "
93
93
)
94
94
95
+ def parse_rxfifo_brackets (arg , fifo_dir ):
96
+ require_version (1 , line )
97
+ if ( # pylint: disable=consider-using-in
98
+ fifo_type != "putget" and fifo_type != fifo_dir
99
+ ):
100
+ raise RuntimeError (
101
+ f"FIFO must be configured for '{ fifo_dir } ' or 'putget' for { line } "
102
+ )
103
+ if arg .endswith ("[y]" ):
104
+ return 0b1000
105
+ return int_in_range (arg [7 :- 1 ], 0 , 8 , "rxfifo index" )
106
+
95
107
for i , line in enumerate (text_program .split ("\n " )):
96
108
line = line .split (";" )[0 ].strip ()
97
109
if not line :
@@ -212,7 +224,11 @@ def int_in_range(arg, low, high, what, radix=0):
212
224
for line in instructions :
213
225
instruction = splitter (line .strip ())
214
226
delay = 0
215
- if len (instruction ) > 1 and instruction [- 1 ].endswith ("]" ): # Delay
227
+ if (
228
+ len (instruction ) > 1
229
+ and instruction [- 1 ].startswith ("[" )
230
+ and instruction [- 1 ].endswith ("]" )
231
+ ): # Delay
216
232
delay = int (instruction [- 1 ].strip ("[]" ), 0 )
217
233
if delay < 0 :
218
234
raise RuntimeError ("Delay negative:" , delay )
@@ -303,33 +319,43 @@ def int_in_range(arg, low, high, what, radix=0):
303
319
assembled [- 1 ] |= 0x40
304
320
elif instruction [0 ] == "mov" :
305
321
# instr delay dst op src
306
- assembled .append (0b101_00000_000_00_000 )
307
- assembled [- 1 ] |= MOV_DESTINATIONS .index (instruction [1 ]) << 5
308
- source = instruction [- 1 ]
309
- source_split = mov_splitter (source )
310
- if len (source_split ) == 1 :
311
- try :
312
- assembled [- 1 ] |= MOV_SOURCES .index (source )
313
- except ValueError as exc :
314
- raise ValueError (f"Invalid mov source '{ source } '" ) from exc
322
+ if instruction [1 ].startswith ("rxfifo[" ): # mov rxfifo[], isr
323
+ assembled .append (0b100_00000_0001_0_000 )
324
+ if instruction [2 ] != "isr" :
325
+ raise ValueError ("mov rxfifo[] source must be isr" )
326
+ assembled [- 1 ] |= parse_rxfifo_brackets (instruction [1 ], "put" )
327
+ elif instruction [2 ].startswith ("rxfifo[" ): # mov osr, rxfifo[]
328
+ assembled .append (0b100_00000_1001_0_000 )
329
+ if instruction [1 ] != "osr" :
330
+ raise ValueError ("mov ,rxfifo[] target must be osr" )
331
+ assembled [- 1 ] |= parse_rxfifo_brackets (instruction [2 ], "get" )
315
332
else :
316
- assembled [- 1 ] |= MOV_SOURCES .index (source_split [1 ])
317
- if source [:1 ] == "!" :
318
- assembled [- 1 ] |= 0x08
319
- elif source [:1 ] == "~" :
320
- assembled [- 1 ] |= 0x08
321
- elif source [:2 ] == "::" :
322
- assembled [- 1 ] |= 0x10
333
+ assembled .append (0b101_00000_000_00_000 )
334
+ assembled [- 1 ] |= MOV_DESTINATIONS .index (instruction [1 ]) << 5
335
+ source = instruction [- 1 ]
336
+ source_split = mov_splitter (source )
337
+ if len (source_split ) == 1 :
338
+ try :
339
+ assembled [- 1 ] |= MOV_SOURCES .index (source )
340
+ except ValueError as exc :
341
+ raise ValueError (f"Invalid mov source '{ source } '" ) from exc
323
342
else :
324
- raise RuntimeError ("Invalid mov operator:" , source [:1 ])
325
- if len (instruction ) > 3 :
326
- assembled [- 1 ] |= MOV_OPS .index (instruction [- 2 ]) << 3
343
+ assembled [- 1 ] |= MOV_SOURCES .index (source_split [1 ])
344
+ if source [:1 ] == "!" :
345
+ assembled [- 1 ] |= 0x08
346
+ elif source [:1 ] == "~" :
347
+ assembled [- 1 ] |= 0x08
348
+ elif source [:2 ] == "::" :
349
+ assembled [- 1 ] |= 0x10
350
+ else :
351
+ raise RuntimeError ("Invalid mov operator:" , source [:1 ])
352
+ if len (instruction ) > 3 :
353
+ assembled [- 1 ] |= MOV_OPS .index (instruction [- 2 ]) << 3
327
354
elif instruction [0 ] == "irq" :
328
355
# instr delay z c w tp/idx
329
356
assembled .append (0b110_00000_0_0_0_00000 )
330
357
331
358
irq_type = 0
332
- print (f"check prev/next/rel { instruction = } " )
333
359
if instruction [- 1 ] == "prev" :
334
360
irq_type = 1
335
361
require_version (1 , "irq prev" )
0 commit comments