From 46fe117f1fb6bf0be0aaed2ebc77741b9f92b927 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 15 May 2022 10:53:58 +0200 Subject: [PATCH] add alias _Bool for bool --- include/gfx/mcbitmap.c | 2 ++ include/gfx/vector3d.c | 6 ++++++ include/gfx/vector3d.h | 2 ++ include/stdbool.h | 8 +++++--- oscar64/InterCode.cpp | 24 ++++++++++++++++++++++++ oscar64/NativeCodeGenerator.cpp | 26 ++++++++++++++++++++------ oscar64/Scanner.cpp | 2 +- 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/include/gfx/mcbitmap.c b/include/gfx/mcbitmap.c index 0385545..b114c6e 100644 --- a/include/gfx/mcbitmap.c +++ b/include/gfx/mcbitmap.c @@ -914,3 +914,5 @@ void bmmc_flood_fill(const Bitmap * bm, const ClipRect * clip, int x, int y, cha } } } + +#pragma native(bmmc_flood_fill) diff --git a/include/gfx/vector3d.c b/include/gfx/vector3d.c index 3830f50..96088a5 100644 --- a/include/gfx/vector3d.c +++ b/include/gfx/vector3d.c @@ -2,6 +2,12 @@ #include #include +void vec2_set(Vector2 * vd, float x, float y) +{ + vd->v[0] = x; + vd->v[1] = y; +} + void vec2_sum(Vector2 * vd, const Vector2 * v1, const Vector2 * v2) { vd->v[0] = v1->v[0] + v2->v[0]; diff --git a/include/gfx/vector3d.h b/include/gfx/vector3d.h index 68da27c..3c79b3e 100644 --- a/include/gfx/vector3d.h +++ b/include/gfx/vector3d.h @@ -6,6 +6,8 @@ struct Vector2 float v[2]; }; +inline void vec2_set(Vector2 * vd, float x, float y); + void vec2_sum(Vector2 * vd, const Vector2 * v1, const Vector2 * v2); void vec2_diff(Vector2 * vd, const Vector2 * v1, const Vector2 * v2); diff --git a/include/stdbool.h b/include/stdbool.h index 7e9bd37..7d4eea2 100644 --- a/include/stdbool.h +++ b/include/stdbool.h @@ -1,9 +1,11 @@ #ifndef STDBOOL_H #define STDBOOL_H -#define bool bool -#define true true -#define false false +#define bool _Bool +#define true (0 == 0) +#define false (0 != 0) + +#define __bool_true_false_are_defined 1 #endif diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index a5e47de..ea0bf2d 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -5045,6 +5045,30 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(void) { case IC_LOAD: vr = ins->mDst.mRange; + + if (i > 0 && + mInstructions[i - 1]->mCode == IC_LEA && mInstructions[i - 1]->mDst.mTemp == ins->mSrc[0].mTemp && + mInstructions[i - 1]->mSrc[1].mTemp < 0 && mInstructions[i - 1]->mSrc[1].mMemory == IM_GLOBAL && (mInstructions[i - 1]->mSrc[1].mLinkerObject->mFlags & LOBJF_CONST)) + { + if (ins->mDst.mType == IT_INT8) + { + LinkerObject* lo = mInstructions[i - 1]->mSrc[1].mLinkerObject; + int mi = 0, ma = 0; + + for (int j = 0; j < lo->mSize; j++) + { + int v = lo->mData[j]; + if (v & 0x80) + mi = -128; + if (v > ma) + ma = v; + } + + vr.LimitMax(ma); + vr.LimitMin(mi); + } + } + break; case IC_CONSTANT: vr.mMaxState = vr.mMinState = IntegerValueRange::S_BOUND; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 70a13aa..0575c41 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -6280,13 +6280,27 @@ int NativeCodeBasicBlock::ShortMultiply(InterCodeProcedure* proc, NativeCodeProc default: if (mul & 0xff00) { - mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, mul & 0xff)); - mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_WORK + 0)); - mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, mul >> 8)); - mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_WORK + 1)); + if (ins->mSrc[index].IsUByte()) + { + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU)); + mIns.Push(NativeCodeInstruction(ASMIT_LDX, ASMIM_IMMEDIATE, mul & 0xff)); + mIns.Push(NativeCodeInstruction(ASMIT_STX, ASMIM_ZERO_PAGE, BC_REG_ACCU + 0)); + mIns.Push(NativeCodeInstruction(ASMIT_LDX, ASMIM_IMMEDIATE, mul >> 8)); + mIns.Push(NativeCodeInstruction(ASMIT_STX, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1)); - NativeCodeGenerator::Runtime& frt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16"))); - mIns.Push(NativeCodeInstruction(ASMIT_JSR, ASMIM_ABSOLUTE, frt.mOffset, frt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER)); + NativeCodeGenerator::Runtime& rt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16by8"))); + mIns.Push(NativeCodeInstruction(ASMIT_JSR, ASMIM_ABSOLUTE, rt.mOffset, rt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER | NCIF_USE_CPU_REG_A)); + } + else + { + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, mul & 0xff)); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_WORK + 0)); + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, mul >> 8)); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_WORK + 1)); + + NativeCodeGenerator::Runtime& frt(nproc->mGenerator->ResolveRuntime(Ident::Unique("mul16"))); + mIns.Push(NativeCodeInstruction(ASMIT_JSR, ASMIM_ABSOLUTE, frt.mOffset, frt.mLinkerObject, NCIF_RUNTIME | NCIF_LOWER | NCIF_UPPER)); + } } else { diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index bc2a23f..ff7c829 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -1269,7 +1269,7 @@ void Scanner::NextRawToken(void) mToken = TK_INT; else if (!strcmp(tkident, "float")) mToken = TK_FLOAT; - else if (!strcmp(tkident, "bool")) + else if (!strcmp(tkident, "bool") || !strcmp(tkident, "_Bool")) mToken = TK_BOOL; else if (!strcmp(tkident, "char")) mToken = TK_CHAR;