Candyman.pink
Home
Back
C Code
// ********************* // * Ball bouncing program // * By: Scrooge'Mc'Cat himself // * At: Sep 1st 2025 7:25 PM // * // * NOTE: // * When first running this program you may experience // * quite a long delay. This is completely expected due to // * the inefficiency of my MCU simulator and compiler code. // * The program's code itself is fine. Trust me. // ********************* #include stdout.asm byte strlen(string text) { // Create a copy because the compiler is broken (sorry) string cpy = text; // Keep on incrementing cpy until a 0 is reached while (*cpy) { cpy = cpy + 1; } // cpy is end of string, text is start, so length = end - start return cpy - text; } void main() { // Customizable features string ballText = "DVD"; // The text of the ball (I know, not really a ball...) string trailChar = " "; // The trail the "ball" leaves behind (only first char is accounted for, set to space for no trail. byte ballTextLen = strlen(ballText); // Position of the ball byte x = 0; byte y = 0; // Velocity of the ball (1 is 1, 2 is -1, other is at rest) byte vx = 1; byte vy = 1; // The ball's previous position byte prevX = x; byte prevY = y; // Someplace the program won't reach to store spaces (like an unsafe heap) word spaces = 32768; // Add spaces equal to the text byte i = 0; word ptr = spaces; for (i = 0; i < ballTextLen; i = i + 1) { ptr = ptr + 1; *ptr = *trailChar; } // Make sure it's null terminated ptr = ptr + 1; *ptr = 0; while (1) { // Update loop // Update X-coordinate if (vx == 1) { x = x + 1; } if (vx == 2) { x = x - 1; } // Update Y-coordinate if (vy == 1) { y = y + 1; } if (vy == 2) { y = y - 1; } // Check for bounces, adjusting velocity accordingly if (y == 20) { vy = 2; } if (y == 0) { vy = 1; } if (x == 41) { vx = 2; } if (x == 0) { vx = 1; } // Draw the ball moveCursor(x, y); print(ballText); // Erase the previous render of the ball moveCursor(prevX, prevY); print(spaces); // Update the previous position for the next "frame" prevX = x; prevY = y; } }
Assembly
// If you are stuck, try clicking "Compile" to fill // this box up with assembly code and then click // "Assemble" to fill up memory with machine code, // and then "Execute" to run your program. Give it a while // to initialize if you're using the DVD sample. // // I recommend the following article for understanding // how all this works: // // https://medium.com/@fivemoreminix/understanding-compilers-for-humans-ba970e045877 // // Basically, C code -> Assembly -> Machine code
Memory
Output
Compile
Assemble
Execute
Pause
Continue
Reset
Registers
General Purpose
AX:
0
BX:
0
CX:
0
DX:
0
EX:
0
FX:
0
FL
FL:
0
Instruction
IP:
0
Stack Pointer
SP:
0
Base Pointer
BP:
0