#encoding is not correctly handled for literal characters.

The following code does not produce an 'e' on the screen as it should

#reserve(0x16)
#encoding(petscii_mixed)
char[] strTemp = "v=X";
int main(void){
    strTemp[2] = 'e';
    strTemp[3] = 0;
    asm {
        ldy #0
        loop:
        lda strTemp,y
        beq done
        jsr $FFD2
        iny
        jmp loop
    done:
    }
    return 0;
}

There are three problems at play

  1. KickC calls the KickAssembler main() twice during compilation (once to check if there are any long branches that need fixing - and once more to generate the PRG). Since encoding inside KickAssembler is a global static variable the "petscii" encoding set in the first compilation is sticky and affects the second compilation. This is easily fixable by always resetting the encoding to the default "screencode_mixed" before calling KickAssembler.

  2. KickC only outputs the .encoding directive in the ASM before the ""-string at the end. It should also output it before the ''-character at the top. All literal strings inside KC has an encoding attribute used to determine whether to output an encoding directive. Literal strings do not have this. This is also quite easily fixable by adding encoding information to all literal characters.

  3. Finally it seems KickAssembler does not handle the encoding-directive when reading a literal characters 'e' during the first loadAndLex() phase. It uses the convert-code, but the encoding is never changed from the default in this phase - this only happens when entering the ScopeAndSymbolPageNode() phase. I need to talk to Mads Nielsen to find out if this is an error or intentional behavior. If it is an error he needs to make a fix for KickAssembler adding encoding-handling to literal characters.

Edited by Jesper Balman Gravgaard