Skip to content

Instantly share code, notes, and snippets.

@jenca-adam
Last active January 10, 2026 14:31
Show Gist options
  • Select an option

  • Save jenca-adam/7135d4de029f69dded119f6337c3979b to your computer and use it in GitHub Desktop.

Select an option

Save jenca-adam/7135d4de029f69dded119f6337c3979b to your computer and use it in GitHub Desktop.
A simple example of HolyC - Raylib integration
class Color {
U8 r;
U8 g;
U8 b;
U8 a;
};
extern "c" U0 InitWindow(I32 width, I32 height, U8 *title);
extern "c" U8 WindowShouldClose();
extern "c" U0 BeginDrawing();
extern "c" U0 EndDrawing();
extern "c" U0 CloseWindow();
extern "c" U0 DrawRectangleV(F64 position, F64 size, Color color);
extern "c" U0 DrawRectangle(I32 x, I32 y, I32 w, I32 h, Color color);
extern "c" U0 ClearBackground(Color color);
extern "c" I32 GetScreenWidth();
extern "c" I32 GetScreenHeight();
extern "c" F64 GetFrameTime();
asm {
// since holy c doesn't have 32-bit floats
_F642F32::
CVTSD2SS XMM0, XMM0
RET
_F322F64::
CVTSS2SD XMM0, XMM0
RET
// holy c doesn't know how to do this.
_I322F64::
MOVD XMM0, RDI
CVTDQ2PD XMM0, XMM0
RET
// holy c doesn't know how to compare f64s
_F64LTF64::
CMPLTPS XMM0, XMM1
//CVTTSD2SI RAX, XMM0 // can't do this!
RET
_PACK2F32S::
// XMM0 XMM1
// A. B.
MOVLHPS XMM0, XMM1
// AB ..
CVTPD2PS XMM0, XMM0
// ab.. ..
RET
}
public _extern _F642F32 F64 F642F32(F64 in);
public _extern _PACK2F32S F64 PACK2F32S(F64 a, F64 b);
public _extern _F322F64 F64 F322F64(F64 in);
public _extern _I322F64 F64 I322F64(I32 in);
public _extern _F64LTF64 F64 F64LTF64(F64 a, F64 b);
U0 main(I32 argc, U8 **argv)
{
InitWindow(800, 600, "HolyC Raylib example");
Color red;
red.r = 255;
red.g = 0;
red.b = 0;
red.a = 255;
Color black;
black.r = 0;
black.g = 0;
black.b = 0;
black.a = 255;
F64 posx = 10;
F64 posy = 10;
F64 sizex = 100.0;
F64 sizey = 100.0;
F64 velx = 100.0;
F64 vely = 100.0;
F64 size = PACK2F32S(sizex, sizey);
F64 screenw = I322F64(GetScreenWidth());
F64 screenh = I322F64(GetScreenHeight());
while (!WindowShouldClose()) {
F64 dt = F322F64(GetFrameTime());
BeginDrawing();
ClearBackground(black);
F64 new_posx = posx + velx*dt;
F64 new_posy = posy + vely*dt;
if (F64LTF64(new_posx,0.0)(U64) || F64LTF64(screenw, new_posx+sizex)(U64)){
velx=-velx;
}
else{
posx=new_posx;
}
if (F64LTF64(new_posy, 0.0)(U64) || F64LTF64(screenh, new_posy+sizey)(U64)){
vely=-vely;
}
else{
posy = new_posy;
}
F64 position = PACK2F32S(posx, posy);
DrawRectangleV(position, size, red);
EndDrawing();
}
CloseWindow();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment