diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 3730386..265dda1 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -4897,7 +4897,7 @@ int NativeCodeBasicBlock::ShortMultiply(InterCodeProcedure* proc, NativeCodeProc else { mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ABSOLUTE_X, 0, nproc->mGenerator->AllocateShortMulTable(mul, ins->mSrc[index].mRange.mMaxValue + 1, true))); - mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, dreg)); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, dreg + 1)); } return dreg; diff --git a/samples/games/breakout.c b/samples/games/breakout.c new file mode 100644 index 0000000..d1e19bf --- /dev/null +++ b/samples/games/breakout.c @@ -0,0 +1,169 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Character set +char charset[2048] = { + #embed "../resources/breakoutchars.bin" +}; + +char spriteset[2048] = { + #embed "../resources/breakoutsprites.bin" +}; + +byte * const Screen = (byte *)0xc800; +byte * const Font = (byte *)0xd000; +byte * const Color = (byte *)0xd800; +byte * const Sprites = (byte *)0xd800; + + +inline void brick_put(char x, char y, char c) +{ + Screen[40 * y + x + 0] = 96; Color[40 * y + x + 0] = c; + Screen[40 * y + x + 1] = 97; Color[40 * y + x + 1] = c; + Screen[40 * y + x + 2] = 98; Color[40 * y + x + 2] = c; + Screen[40 * y + x + 40] = 99; Color[40 * y + x + 40] = c; + Screen[40 * y + x + 41] = 100; Color[40 * y + x + 41] = c; + Screen[40 * y + x + 42] = 101; Color[40 * y + x + 42] = c; +} + +void brick_init(void) +{ + for(char y=0; y<6; y++) + { + for(char x=0; x<12; x++) + { + brick_put(3 * x + 2, 2 * y + 2, 8 + y); + } + } +} + +void brick_clr(char x, char y) +{ + char c = Screen[40 * y + x + 0]; + + if (c >= 96 && c < 102) + { + c -= 96; + + if (c >= 3) + { + y --; + c -= 3; + } + + x -= c; + + Screen[40 * y + x + 0] = 32; + Screen[40 * y + x + 1] = 32; + Screen[40 * y + x + 2] = 32; + Screen[40 * y + x + 40] = 32; + Screen[40 * y + x + 41] = 32; + Screen[40 * y + x + 42] = 32; + } +} + + +int main(void) +{ + mmap_trampoline(); + + // Install character set + mmap_set(MMAP_RAM); + memcpy(Font, charset, 2048); + memcpy(Sprites, spriteset, 256); + mmap_set(MMAP_NO_BASIC); + + // Switch screen + vic_setmode(VICM_TEXT_MC, Screen, Font); + + spr_init(Screen); + + // Change colors + vic.color_border = VCOL_BLACK; + vic.color_back = VCOL_BLUE; + vic.color_back1 = VCOL_WHITE; + vic.color_back2 = VCOL_DARK_GREY; + + memset(Screen, ' ', 1000); + + brick_init(); + + float sx = 100, sy = 180, vx = 3.2, vy = -4.0; + + spr_set(0, true, 200, 200, 96, 1, false, false, false); + + for(;;) + { + vic.color_border++; + + for(char i=0; i<4; i++) + { + sx += vx; + sy += vy; + // vy += 0.01; + + bool mirrorX = false, mirrorY = false; + + if (sx + 6 > 320 || sx < 0) + mirrorX = true; + if (sy + 6 > 200 || sy < 0) + mirrorY = true; + + int x0 = (int)sx >> 3; + int y0 = (int)sy >> 3; + int x1 = (int)(sx + 6) >> 3; + int y1 = (int)(sy + 6) >> 3; + + bool c00 = y0 >= 0 && Screen[40 * y0 + x0] >= 96; + bool c01 = y0 >= 0 && Screen[40 * y0 + x1] >= 96; + bool c10 = y1 < 24 && Screen[40 * y1 + x0] >= 96; + bool c11 = y1 < 24 && Screen[40 * y1 + x1] >= 96; + + if (vx < 0 && (c00 && !c01 || c10 && !c11)) + mirrorX = true; + else if (vx > 0 && (c01 && !c00 || c11 && !c10)) + mirrorX = true; + + if (vy < 0 && (c00 && !c10 || c01 && !c11)) + mirrorY = true; + else if (vy > 0 && (c10 && !c00 || c11 && !c01)) + mirrorY = true; + + if (c00 || c01 || c10 || c11) + { + brick_clr(x0, y0); + brick_clr(x1, y0); + brick_clr(x0, y1); + brick_clr(x1, y1); + } + + if (mirrorY) + { + vy = -vy; + sy += 2 * vy; + // vy *= 0.99; + } + if (mirrorX) + { + vx = -vx; + sx += 2 * vx; + // vx *= 0.99; + } + } + + spr_move(0, sx + 24, sy + 50); + + vic.color_border--; + + vic_waitFrame(); + } + + return 0; +} diff --git a/samples/games/make.bat b/samples/games/make.bat index 77ee061..cf03125 100644 --- a/samples/games/make.bat +++ b/samples/games/make.bat @@ -2,3 +2,4 @@ call ..\..\bin\oscar64 snake.c call ..\..\bin\oscar64 -n lander.c call ..\..\bin\oscar64 -n maze3d.c call ..\..\bin\oscar64 -n -O3 missile.c +call ..\..\bin\oscar64 -n breakout.c diff --git a/samples/resources/breakoutchars.bin b/samples/resources/breakoutchars.bin new file mode 100644 index 0000000..15f8687 Binary files /dev/null and b/samples/resources/breakoutchars.bin differ diff --git a/samples/resources/breakoutsprites.bin b/samples/resources/breakoutsprites.bin new file mode 100644 index 0000000..efe0641 Binary files /dev/null and b/samples/resources/breakoutsprites.bin differ