<s> from ast import Num , List <EOL> class NesType ( object ) : <EOL> def __init__ ( self , * args , ** kw ) : <EOL> self . instance_name = None <EOL> self . is_used = False <EOL> self . is_attrib = False <EOL> if '<STR_LIT:size>' in kw : <EOL> self . size = kw [ '<STR_LIT:size>' ] <EOL> else : <EOL> self . size = <NUM_LIT:1> <EOL> self . lineno = <NUM_LIT:0> <EOL> class NesRs ( NesType ) : <EOL> def __init__ ( self , size = <NUM_LIT:1> ) : <EOL> super ( NesRs , self ) . __init__ ( size = size ) <EOL> class NesSprite ( NesType ) : <EOL> def __init__ ( self , x , y , tile , attrib , width = <NUM_LIT:2> ) : <EOL> super ( NesSprite , self ) . __init__ ( ) <EOL> self . is_used = True <EOL> self . x = x <EOL> self . y = y <EOL> self . tile = tile <EOL> self . attrib = attrib <EOL> self . width = width <EOL> def __len__ ( self ) : <EOL> if isinstance ( self . tile , List ) : <EOL> return len ( self . tile ) <EOL> return <NUM_LIT:1> <EOL> def to_asm ( self ) : <EOL> if isinstance ( self . tile , int ) : <EOL> return ( <EOL> '<STR_LIT>' % <EOL> ( <EOL> self . y , <EOL> self . tile , <EOL> self . attrib , <EOL> self . x <EOL> ) ) <EOL> else : <EOL> asmcode = '<STR_LIT>' <EOL> x = <NUM_LIT:0> <EOL> for t in self . tile : <EOL> i = x % self . width <EOL> j = x / self . width <EOL> asmcode += ( '<STR_LIT>' % <EOL> ( <EOL> self . y + ( j * <NUM_LIT:8> ) , <EOL> t , <EOL> self . attrib , <EOL> self . x + ( i * <NUM_LIT:8> ) <EOL> ) ) <EOL> x += <NUM_LIT:1> <EOL> return asmcode <EOL> class NesArray ( NesType , List ) : <EOL> def __init__ ( self , elts ) : <EOL> super ( NesArray , self ) . __init__ ( elts = elts ) <EOL> self . lst = [ l . n if isinstance ( l , Num ) else l for l in elts ] <EOL> self . is_used = True <EOL> self . locked = False <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , list ) : <EOL> return other == self . lst <EOL> def __len__ ( self ) : <EOL> return len ( self . lst ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . lst ) <EOL> def to_asm ( self ) : <EOL> self . locked = True <EOL> hexes = [ "<STR_LIT>" % v for v in self . lst ] <EOL> asm = '<STR_LIT>' <EOL> length = ( len ( hexes ) / <NUM_LIT:16> ) <EOL> if len ( hexes ) % <NUM_LIT:16> : <EOL> length += <NUM_LIT:1> <EOL> for i in range ( length ) : <EOL> asm += '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( hexes [ i * <NUM_LIT:16> : i * <NUM_LIT:16> + <NUM_LIT:16> ] ) + '<STR_LIT:\n>' <EOL> if len ( asm ) > <NUM_LIT:0> : <EOL> return asm <EOL> return False <EOL> class NesInt ( int , NesType ) : <EOL> def __init__ ( self , number ) : <EOL> super ( NesInt , self ) . __init__ ( number ) <EOL> class NesString ( str , NesType ) : <EOL> def __init__ ( self , string ) : <EOL> super ( NesString , self ) . __init__ ( ) <EOL> str . __init__ ( self , string ) <EOL> self . locked = False <EOL> def to_asm ( self ) : <EOL> s = "<STR_LIT>" <EOL> start = <NUM_LIT:0> <EOL> bytes = [ ( s . index ( c ) + start ) for c in self . upper ( ) ] <EOL> bytes . append ( <NUM_LIT> ) <EOL> hexes = [ "<STR_LIT>" % v for v in bytes ] <EOL> asm = '<STR_LIT>' <EOL> length = ( len ( hexes ) / <NUM_LIT:16> ) <EOL> if len ( hexes ) % <NUM_LIT:16> : <EOL> length += <NUM_LIT:1> <EOL> for i in range ( length ) : <EOL> asm += '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( hexes [ i * <NUM_LIT:16> : i * <NUM_LIT:16> + <NUM_LIT:16> ] ) + '<STR_LIT:\n>' <EOL> if len ( asm ) > <NUM_LIT:0> : <EOL> return asm <EOL> return False <EOL> class NesChrFile ( NesType ) : <EOL> def __init__ ( self , filename ) : <EOL> super ( NesChrFile , self ) . __init__ ( ) <EOL> self . filename = filename </s>
