@ -115,32 +115,42 @@ void compiler::compileFunction(const unsigned int& pos) {
}
void compiler : : appendGraphicsData ( ) {
uint16_t pStart = baseOffset + currentAddr ;
auto hchrtoi = [ & ] ( const char chr ) { switch ( chr ) { case ' 0 ' : return 0 ; case ' 1 ' : return 1 ; case ' 2 ' : return 2 ; case ' 3 ' : return 3 ; case ' 4 ' : return 4 ; case ' 5 ' : return 5 ; case ' 6 ' : return 6 ; case ' 7 ' : return 7 ; case ' 8 ' : return 8 ; case ' 9 ' : return 9 ; case ' a ' : case ' A ' : return 10 ; case ' b ' : case ' B ' : return 11 ; case ' c ' : case ' C ' : return 12 ; case ' d ' : case ' D ' : return 13 ; case ' e ' : case ' E ' : return 14 ; case ' f ' : case ' F ' : return 15 ; default : return 0 ; } } ;
auto hstrtoi = [ & ] ( const std : : string & str ) { return hchrtoi ( str [ 2 ] ) * 16 + hchrtoi ( str [ 3 ] ) ; } ;
auto byteoff = [ & ] ( const unsigned int & i ) { switch ( i ) { case 7 : return 1 ; case 6 : return 2 ; case 5 : return 4 ; case 4 : return 8 ; case 3 : return 16 ; case 2 : return 32 ; case 1 : return 64 ; case 0 : return 128 ; default : return 0 ; } ; } ;
auto bstrtoi = [ & ] ( const std : : string & str ) { int retval = 0x00 ; for ( auto i = 2 ; i < 10 ; i + + ) { if ( str [ i ] = = ' 1 ' ) { retval + = byteoff ( i ) ; } } return retval ; } ;
auto strtoi = [ & ] ( const std : : string & str ) { if ( str [ 0 ] = = ' 0 ' & & str [ 1 ] = = ' x ' ) { return hstrtoi ( str ) ; } else if ( str [ 0 ] = = ' 0 ' & & str [ 1 ] = = ' b ' ) { return bstrtoi ( str ) ; } else if ( str [ 0 ] ! = ' 0 ' ) { return hstrtoi ( str . substr ( 5 , 4 ) ) ; } else { return std : : stoi ( str ) ; } } ;
uint16_t pStart = ( baseOffset & 0x00ff ) + currentAddr ;
codeVEC [ 8 ] = pStart & 0x00ff ;
codeVEC [ 11 ] = pStart > > 8 ;
std : : ifstream pFile ( paletteFname ) ;
if ( ! pFile . is_open ( ) ) return ;
std : : string line ;
std : : ifstream imgfile ( imageFname ) ;
if ( ! imgfile . is_open ( ) ) return ;
nlohmann : : json json ;
imgfile > > json ;
imgfile . close ( ) ;
while ( getline ( pFile , line ) ) {
codeVEC . push_back ( std : : stoi ( line ) ) ;
currentAddr + + ;
const unsigned int pcount = json [ " palette " ] [ " count " ] . get < unsigned int > ( ) ;
const unsigned int scount = json [ " segments " ] [ " count " ] . get < unsigned int > ( ) ;
for ( auto i = 0 ; i < pcount ; i + + ) {
auto ident = " color_ " + std : : to_string ( i ) ;
auto cs = json [ " palette " ] [ ident ] . get < std : : array < std : : string , 3 > > ( ) ;
for ( auto & c : cs ) {
codeVEC . push_back ( strtoi ( c ) ) ; currentAddr + + ;
}
}
pFile . close ( ) ;
pStart = baseOffset + currentAddr ;
pStart = ( baseOffset & 0x00ff ) + currentAddr ;
codeVEC [ 2 ] = pStart & 0x00ff ;
codeVEC [ 5 ] = pStart > > 8 ;
std : : ifstream sFile ( paletteFname ) ;
if ( ! sFile . is_open ( ) ) return ;
while ( getline ( sFile , line ) ) {
codeVEC . push_back ( std : : stoi ( line ) ) ;
currentAddr + + ;
for ( auto i = 0 ; i < scount ; i + + ) {
auto ident = " segment_ " + std : : to_string ( i ) ;
auto ss = json [ " segments " ] [ ident ] . get < std : : array < std : : string , 16 > > ( ) ;
for ( auto & s : ss ) {
codeVEC . push_back ( strtoi ( s ) ) ; currentAddr + + ;
}
}
sFile . close ( ) ;
}