diff --git a/include/c64/charwin.c b/include/c64/charwin.c index 79a2c7f..f29939e 100644 --- a/include/c64/charwin.c +++ b/include/c64/charwin.c @@ -199,14 +199,12 @@ void cwin_write_string(CharWin * win, const char * buffer) { for(char x=0; xwx; x++) { - char c = *buffer; - if (c) + char ch = *buffer; + if (ch) { - c &= 0xbf; - if (c & 0x80) - c ^= 0xc0; + ch = (ch & 0x3f) | ((ch & 0x80) >> 1); - dp[x] = c; + dp[x] = ch; buffer++; } else @@ -254,9 +252,7 @@ void cwin_putat_char(CharWin * win, char x, char y, char ch, char color) { int offset = mul40[y] + x; - ch &= 0xbf; - if (ch & 0x80) - ch ^= 0xc0; + ch = (ch & 0x3f) | ((ch & 0x80) >> 1); win->sp[offset] = ch; win->cp[offset] = color; @@ -275,9 +271,7 @@ void cwin_putat_chars(CharWin * win, char x, char y, const char * chars, char nu { char ch = chars[i]; - ch &= 0xbf; - if (ch & 0x80) - ch ^= 0xc0; + ch = (ch & 0x3f) | ((ch & 0x80) >> 1); sp[i] = ch; cp[i] = color; @@ -296,9 +290,7 @@ char cwin_putat_string(CharWin * win, char x, char y, const char * str, char col char i = 0; while (char ch = str[i]) { - ch &= 0xbf; - if (ch & 0x80) - ch ^= 0xc0; + ch = (ch & 0x3f) | ((ch & 0x80) >> 1); sp[i] = ch; cp[i] = color; diff --git a/include/crt.c b/include/crt.c index 0a6a73f..79b127f 100644 --- a/include/crt.c +++ b/include/crt.c @@ -131,6 +131,7 @@ w2: // All native code jsr main pexec: +tyexec: yexec: zexec: exec: @@ -146,32 +147,27 @@ exec: sta ip + 1 pexec: - ldy #$ff + ldy #0 + beq exec +tyexec: + ldy tmpy yexec: iny exec: -#if 0 - tya - clc - adc ip - sta ip - bcc W1 - inc ip + 1 -W1: ldy #0 -#endif lda (ip), y sta execjmp + 1 iny execjmp: jmp (0x0900) zexec: - tya + tya + ldy #0 clc adc ip sta ip - bcc pexec + bcc exec inc ip + 1 - bne pexec + bne exec bcode: byt BC_CALL_ABS * 2 byt
PutByte(mRegister); break; + case BC_LOAD_ABS_ADDR: + block->PutCode(generator, mCode); + if (mRelocate) + { + LinkerReference rl; + rl.mOffset = block->mCode.Size(); + rl.mFlags = LREF_HIGHBYTE | LREF_LOWBYTE; + rl.mRefObject = mLinkerObject; + rl.mRefOffset = mValue; + block->mRelocations.Push(rl); + block->PutWord(0); + } + else + block->PutWord(mValue); + break; + case BC_LEA_ABS: case BC_LEA_ABS_INDEX: case BC_LEA_ABS_INDEX_U8: @@ -4816,19 +4835,19 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase) mIns[i + 2].mCode = BC_NOP; progress = true; } - + else if ( mIns[i + 0].mCode == BC_LOAD_REG_8 && mIns[i + 1].mCode == BC_STORE_REG_16 && mIns[i + 2].mCode == BC_LEA_ABS_INDEX && mIns[i + 2].mRegister == mIns[i + 1].mRegister && !(mIns[i + 2].mLive & LIVE_ACCU) && mIns[i + 2].mRegisterFinal) - { - mIns[i + 2].mCode = BC_LEA_ABS_INDEX_U8; - mIns[i + 2].mRegister = mIns[i + 0].mRegister; - mIns[i + 2].mRegisterFinal = mIns[i + 0].mRegisterFinal; - mIns[i + 0].mCode = BC_NOP; - mIns[i + 1].mCode = BC_NOP; - progress = true; - } + { + mIns[i + 2].mCode = BC_LEA_ABS_INDEX_U8; + mIns[i + 2].mRegister = mIns[i + 0].mRegister; + mIns[i + 2].mRegisterFinal = mIns[i + 0].mRegisterFinal; + mIns[i + 0].mCode = BC_NOP; + mIns[i + 1].mCode = BC_NOP; + progress = true; + } else if ( mIns[i + 0].mCode == BC_STORE_REG_16 && @@ -4872,7 +4891,7 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase) progress = true; } else if ( - mIns[i + 0].mCode == BC_LOAD_REG_8 && + mIns[i + 0].mCode == BC_LOAD_REG_8 && mIns[i + 1].mCode == BC_BINOP_SHRI_U16 && mIns[i + 2].mCode == BC_LOAD_REG_8 && mIns[i + 2].mRegister == BC_REG_ACCU) { @@ -4913,9 +4932,19 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase) mIns[i + 2].mCode = BC_BINOP_ADDA_16; progress = true; } + else if ( + mIns[i + 0].mCode == BC_LOAD_REG_16 && + mIns[i + 1].mCode == BC_BINOP_SHLI_16 && mIns[i + 1].mValue == 1 && + mIns[i + 2].mCode == BC_STORE_REG_16 && mIns[i + 0].mRegister == mIns[i + 2].mRegister && !(mIns[i + 2].mLive & LIVE_ACCU)) + { + mIns[i + 0].mRegisterFinal = false; + mIns[i + 1].mCode = BC_NOP; + mIns[i + 2].mCode = BC_BINOP_ADDA_16; + progress = true; + } else if ( (mIns[i + 0].mCode == BC_LOAD_LOCAL_16 || mIns[i + 0].mCode == BC_LOAD_ABS_16 || mIns[i + 0].mCode == BC_LOAD_ADDR_16 || - mIns[i + 0].mCode == BC_LOAD_LOCAL_U8 || mIns[i + 0].mCode == BC_LOAD_ABS_U8 || mIns[i + 0].mCode == BC_LOAD_ADDR_U8) && + mIns[i + 0].mCode == BC_LOAD_LOCAL_U8 || mIns[i + 0].mCode == BC_LOAD_ABS_U8 || mIns[i + 0].mCode == BC_LOAD_ADDR_U8) && mIns[i + 1].mCode == BC_BINOP_ADDR_16 && mIns[i + 0].mRegister == mIns[i + 1].mRegister && mIns[i + 1].mRegisterFinal && mIns[i + 2].mCode == BC_STORE_REG_16 && !(mIns[i + 2].mLive & LIVE_ACCU)) { @@ -4936,6 +4965,18 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase) mIns[i + 1].mLive |= LIVE_ACCU; progress = true; } + + else if ( + mIns[i + 0].mCode == BC_LEA_ABS && + mIns[i + 1].mCode == BC_BINOP_ADDA_16 && mIns[i + 0].mRegister == mIns[i + 1].mRegister && + mIns[i + 2].mCode == BC_ADDR_REG && mIns[i + 0].mRegister == mIns[i + 2].mRegister && mIns[i + 2].mRegisterFinal) + { + mIns[i + 0].mCode = BC_LEA_ABS_INDEX; + mIns[i + 0].mRegister = BC_REG_ACCU; + mIns[i + 1].mCode = BC_NOP; + mIns[i + 2].mCode = BC_NOP; + progress = true; + } #if 1 else if ( i + 3 == mIns.Size() && mFalseJump && @@ -5283,7 +5324,26 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase) mIns[i + 0].mCode = BC_NOP; progress = true; } + else if ( + mIns[i + 0].mCode == BC_BINOP_ADDA_16 && + mIns[i + 1].mCode == BC_ADDR_REG && mIns[i + 0].mRegister == mIns[i + 1].mRegister && mIns[i + 1].mRegisterFinal) + { + mIns[i + 1].mCode = BC_LEA_ACCU_INDEX; + mIns[i + 0].mCode = BC_NOP; + progress = true; + } #endif +#if 1 + else if ( + mIns[i + 0].mCode == BC_LOAD_ABS_16 && + mIns[i + 1].mCode == BC_ADDR_REG && mIns[i + 0].mRegister == mIns[i + 1].mRegister && mIns[i + 1].mRegisterFinal) + { + mIns[i + 0].mCode = BC_LOAD_ABS_ADDR; + mIns[i + 1].mCode = BC_NOP; + progress = true; + } +#endif + #if 1 else if ( i + 2 == mIns.Size() && mFalseJump && diff --git a/oscar64/ByteCodeGenerator.h b/oscar64/ByteCodeGenerator.h index 7e1cbf3..ddca152 100644 --- a/oscar64/ByteCodeGenerator.h +++ b/oscar64/ByteCodeGenerator.h @@ -27,6 +27,7 @@ enum ByteCode BC_LOAD_ABS_U8, BC_LOAD_ABS_16, BC_LOAD_ABS_32, + BC_LOAD_ABS_ADDR, BC_STORE_ABS_8, BC_STORE_ABS_16, diff --git a/oscar64/Disassembler.cpp b/oscar64/Disassembler.cpp index d3fbd34..8daa508 100644 --- a/oscar64/Disassembler.cpp +++ b/oscar64/Disassembler.cpp @@ -155,6 +155,10 @@ void ByteCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int star fprintf(file, "MOVD\t%s, %s", TempName(memory[start + i + 2], tbuffer, proc), AddrName(uint16(memory[start + i + 0] + 256 * memory[start + i + 1]), abuffer, linker)); i += 3; break; + case BC_LOAD_ABS_ADDR: + fprintf(file, "MOV\tADDR, %s", AddrName(uint16(memory[start + i + 0] + 256 * memory[start + i + 1]), abuffer, linker)); + i += 2; + break; case BC_LEA_ABS: fprintf(file, "LEA\t%s, %s", TempName(memory[start + i + 0], tbuffer, proc), AddrName(uint16(memory[start + i + 1] + 256 * memory[start + i + 2]), abuffer, linker));