diff --git a/arena.c b/arena.c index d56e350..9616cc5 100644 --- a/arena.c +++ b/arena.c @@ -3,6 +3,9 @@ #include "arena.h" #include "system/vga.h" +#include "sprites.h" +#include + char arenaLayout[10][10] = { { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, @@ -16,36 +19,35 @@ char arenaLayout[10][10] = { { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 } }; -struct SpriteRender arenaWallTop, arenaWallSide, arenaFloor; +struct CompiledSpriteRender arenaWallTop, arenaWallSide, arenaFloor; -void setupWallSprites(struct BMPImage *spritesheetImage) { - buildSpriteFromSpritesheet( - spritesheetImage, +void setupWallSprites() { + buildCompiledSprite( + &sprite_arenaWallTop, &arenaWallTop, - 0, 0, 20, 20 + 20, 20 ); - buildSpriteFromSpritesheet( - spritesheetImage, + buildCompiledSprite( + &sprite_arenaWallSide, &arenaWallSide, - 20, 0, 20, 20 + 20, 20 ); - buildSpriteFromSpritesheet( - spritesheetImage, + buildCompiledSprite( + &sprite_arenaFloor, &arenaFloor, - 40, 0, 20, 20 + 20, 20 ); } -extern void renderFloorTile(byte *); -// push items onto stack -#pragma aux (__cdecl) renderFloorTile "renderFloorTile_" +byte *drawBuffer; void renderArenaTile(int x, int y) { char tile; - struct SpriteRender *target; - byte *drawBuffer; + struct CompiledSpriteRender *target; + + drawBuffer = getDrawBuffer(); tile = arenaLayout[y][x]; @@ -64,15 +66,7 @@ void renderArenaTile(int x, int y) { target->x = x * TILE_SIZE; target->y = y * TILE_SIZE; - if (tile == 0) { - drawBuffer = getDrawBuffer(); - - renderFloorTile( - drawBuffer + target->x + target->y * VGA_DISPLAY_WIDTH - ); - } else { - drawSprite(target); - } + drawCompiledSprite(target); } char arenaRedrawRequests[ARENA_HEIGHT_TILES][ARENA_WIDTH_TILES]; diff --git a/bin/build_spritesheet_asm.rb b/bin/build_spritesheet_asm.rb index dffed0f..b80f06b 100755 --- a/bin/build_spritesheet_asm.rb +++ b/bin/build_spritesheet_asm.rb @@ -49,14 +49,10 @@ ASM_TEMPLATE = <<~ASM <%= sprite.exported_name %>: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] <% sprite.bytes.each do |byte| %> mov BYTE PTR [eax + <%= byte.offset %>], <%= byte.data %><% end %> - pop ebx pop ebp ret @@ -65,10 +61,18 @@ ASM_TEMPLATE = <<~ASM ASM C_TEMPLATE = <<~C + #ifndef __SPRITES_H__ + #define __SPRITES_H__ + + #include "types.h" + <% sprites.each do |sprite| %> extern void <%= sprite.function_name %>(byte *); - #pragma aux (__cdecl) <%= sprite.function_name %> "<%= sprite.exported_name %>" <% end %> + + // TODO: something with bounds checking here + + #endif C class AssemblerSprite diff --git a/game.c b/game.c index 286b13c..cbd3f83 100644 --- a/game.c +++ b/game.c @@ -4,6 +4,7 @@ #include #include +#include "sprites.h" #include "system/vga.h" #include "system/keyboard.h" #include "system/mouse_io.h" @@ -334,10 +335,15 @@ clock_t startTime; // non cdecl is put params into eax, ebx, and ecx int main(void) { + byte *drawBuffer; int keepRunning = 1; + void (*code)(byte *); + if (setupGame()) return 1; + drawBuffer = getDrawBuffer(); + maybeSpawnEnemy(); while (keepRunning) { diff --git a/makefile b/makefile index 6aafbe6..32aab2c 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -obj = game.o bmpload.o arena.o movement.o test.o +obj = game.o bmpload.o arena.o movement.o sprites.o all: system/system.lib game.exe .SYMBOLIC diff --git a/sprites.asm b/sprites.asm index b47b482..79140ea 100644 --- a/sprites.asm +++ b/sprites.asm @@ -16,221 +16,8 @@ PUBLIC sprite_enemy_ sprite_arenaWallTop_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] - mov BYTE PTR [eax + -3210], 2 - mov BYTE PTR [eax + -3209], 2 - mov BYTE PTR [eax + -3208], 2 - mov BYTE PTR [eax + -3207], 2 - mov BYTE PTR [eax + -3206], 2 - mov BYTE PTR [eax + -3205], 2 - mov BYTE PTR [eax + -3204], 2 - mov BYTE PTR [eax + -3203], 2 - mov BYTE PTR [eax + -3202], 2 - mov BYTE PTR [eax + -3201], 2 - mov BYTE PTR [eax + -3200], 2 - mov BYTE PTR [eax + -3199], 2 - mov BYTE PTR [eax + -3198], 2 - mov BYTE PTR [eax + -3197], 2 - mov BYTE PTR [eax + -3196], 2 - mov BYTE PTR [eax + -3195], 2 - mov BYTE PTR [eax + -3194], 2 - mov BYTE PTR [eax + -3193], 2 - mov BYTE PTR [eax + -3192], 2 - mov BYTE PTR [eax + -3191], 2 - mov BYTE PTR [eax + -2890], 2 - mov BYTE PTR [eax + -2889], 2 - mov BYTE PTR [eax + -2888], 2 - mov BYTE PTR [eax + -2887], 2 - mov BYTE PTR [eax + -2886], 2 - mov BYTE PTR [eax + -2885], 2 - mov BYTE PTR [eax + -2884], 2 - mov BYTE PTR [eax + -2883], 2 - mov BYTE PTR [eax + -2882], 2 - mov BYTE PTR [eax + -2881], 2 - mov BYTE PTR [eax + -2880], 2 - mov BYTE PTR [eax + -2879], 2 - mov BYTE PTR [eax + -2878], 2 - mov BYTE PTR [eax + -2877], 2 - mov BYTE PTR [eax + -2876], 2 - mov BYTE PTR [eax + -2875], 2 - mov BYTE PTR [eax + -2874], 2 - mov BYTE PTR [eax + -2873], 2 - mov BYTE PTR [eax + -2872], 2 - mov BYTE PTR [eax + -2871], 2 - mov BYTE PTR [eax + -2570], 2 - mov BYTE PTR [eax + -2569], 2 - mov BYTE PTR [eax + -2568], 2 - mov BYTE PTR [eax + -2567], 2 - mov BYTE PTR [eax + -2566], 2 - mov BYTE PTR [eax + -2565], 2 - mov BYTE PTR [eax + -2564], 2 - mov BYTE PTR [eax + -2563], 2 - mov BYTE PTR [eax + -2562], 2 - mov BYTE PTR [eax + -2561], 2 - mov BYTE PTR [eax + -2560], 2 - mov BYTE PTR [eax + -2559], 2 - mov BYTE PTR [eax + -2558], 2 - mov BYTE PTR [eax + -2557], 2 - mov BYTE PTR [eax + -2556], 2 - mov BYTE PTR [eax + -2555], 2 - mov BYTE PTR [eax + -2554], 2 - mov BYTE PTR [eax + -2553], 2 - mov BYTE PTR [eax + -2552], 2 - mov BYTE PTR [eax + -2551], 2 - mov BYTE PTR [eax + -2250], 2 - mov BYTE PTR [eax + -2249], 2 - mov BYTE PTR [eax + -2248], 2 - mov BYTE PTR [eax + -2247], 2 - mov BYTE PTR [eax + -2246], 2 - mov BYTE PTR [eax + -2245], 2 - mov BYTE PTR [eax + -2244], 2 - mov BYTE PTR [eax + -2243], 2 - mov BYTE PTR [eax + -2242], 2 - mov BYTE PTR [eax + -2241], 2 - mov BYTE PTR [eax + -2240], 2 - mov BYTE PTR [eax + -2239], 2 - mov BYTE PTR [eax + -2238], 2 - mov BYTE PTR [eax + -2237], 2 - mov BYTE PTR [eax + -2236], 2 - mov BYTE PTR [eax + -2235], 2 - mov BYTE PTR [eax + -2234], 2 - mov BYTE PTR [eax + -2233], 2 - mov BYTE PTR [eax + -2232], 2 - mov BYTE PTR [eax + -2231], 2 - mov BYTE PTR [eax + -1930], 2 - mov BYTE PTR [eax + -1929], 2 - mov BYTE PTR [eax + -1928], 2 - mov BYTE PTR [eax + -1927], 2 - mov BYTE PTR [eax + -1926], 2 - mov BYTE PTR [eax + -1925], 2 - mov BYTE PTR [eax + -1924], 2 - mov BYTE PTR [eax + -1923], 2 - mov BYTE PTR [eax + -1922], 2 - mov BYTE PTR [eax + -1921], 2 - mov BYTE PTR [eax + -1920], 2 - mov BYTE PTR [eax + -1919], 2 - mov BYTE PTR [eax + -1918], 2 - mov BYTE PTR [eax + -1917], 2 - mov BYTE PTR [eax + -1916], 2 - mov BYTE PTR [eax + -1915], 2 - mov BYTE PTR [eax + -1914], 2 - mov BYTE PTR [eax + -1913], 2 - mov BYTE PTR [eax + -1912], 2 - mov BYTE PTR [eax + -1911], 2 - mov BYTE PTR [eax + -1610], 2 - mov BYTE PTR [eax + -1609], 2 - mov BYTE PTR [eax + -1608], 2 - mov BYTE PTR [eax + -1607], 2 - mov BYTE PTR [eax + -1606], 2 - mov BYTE PTR [eax + -1605], 2 - mov BYTE PTR [eax + -1604], 2 - mov BYTE PTR [eax + -1603], 2 - mov BYTE PTR [eax + -1602], 2 - mov BYTE PTR [eax + -1601], 2 - mov BYTE PTR [eax + -1600], 2 - mov BYTE PTR [eax + -1599], 2 - mov BYTE PTR [eax + -1598], 2 - mov BYTE PTR [eax + -1597], 2 - mov BYTE PTR [eax + -1596], 2 - mov BYTE PTR [eax + -1595], 2 - mov BYTE PTR [eax + -1594], 2 - mov BYTE PTR [eax + -1593], 2 - mov BYTE PTR [eax + -1592], 2 - mov BYTE PTR [eax + -1591], 2 - mov BYTE PTR [eax + -1290], 2 - mov BYTE PTR [eax + -1289], 2 - mov BYTE PTR [eax + -1288], 2 - mov BYTE PTR [eax + -1287], 2 - mov BYTE PTR [eax + -1286], 2 - mov BYTE PTR [eax + -1285], 2 - mov BYTE PTR [eax + -1284], 2 - mov BYTE PTR [eax + -1283], 2 - mov BYTE PTR [eax + -1282], 2 - mov BYTE PTR [eax + -1281], 2 - mov BYTE PTR [eax + -1280], 2 - mov BYTE PTR [eax + -1279], 2 - mov BYTE PTR [eax + -1278], 2 - mov BYTE PTR [eax + -1277], 2 - mov BYTE PTR [eax + -1276], 2 - mov BYTE PTR [eax + -1275], 2 - mov BYTE PTR [eax + -1274], 2 - mov BYTE PTR [eax + -1273], 2 - mov BYTE PTR [eax + -1272], 2 - mov BYTE PTR [eax + -1271], 2 - mov BYTE PTR [eax + -970], 2 - mov BYTE PTR [eax + -969], 2 - mov BYTE PTR [eax + -968], 2 - mov BYTE PTR [eax + -967], 2 - mov BYTE PTR [eax + -966], 2 - mov BYTE PTR [eax + -965], 2 - mov BYTE PTR [eax + -964], 2 - mov BYTE PTR [eax + -963], 2 - mov BYTE PTR [eax + -962], 2 - mov BYTE PTR [eax + -961], 2 - mov BYTE PTR [eax + -960], 2 - mov BYTE PTR [eax + -959], 2 - mov BYTE PTR [eax + -958], 2 - mov BYTE PTR [eax + -957], 2 - mov BYTE PTR [eax + -956], 2 - mov BYTE PTR [eax + -955], 2 - mov BYTE PTR [eax + -954], 2 - mov BYTE PTR [eax + -953], 2 - mov BYTE PTR [eax + -952], 2 - mov BYTE PTR [eax + -951], 2 - mov BYTE PTR [eax + -650], 2 - mov BYTE PTR [eax + -649], 2 - mov BYTE PTR [eax + -648], 2 - mov BYTE PTR [eax + -647], 2 - mov BYTE PTR [eax + -646], 2 - mov BYTE PTR [eax + -645], 2 - mov BYTE PTR [eax + -644], 2 - mov BYTE PTR [eax + -643], 2 - mov BYTE PTR [eax + -642], 2 - mov BYTE PTR [eax + -641], 2 - mov BYTE PTR [eax + -640], 2 - mov BYTE PTR [eax + -639], 2 - mov BYTE PTR [eax + -638], 2 - mov BYTE PTR [eax + -637], 2 - mov BYTE PTR [eax + -636], 2 - mov BYTE PTR [eax + -635], 2 - mov BYTE PTR [eax + -634], 2 - mov BYTE PTR [eax + -633], 2 - mov BYTE PTR [eax + -632], 2 - mov BYTE PTR [eax + -631], 2 - mov BYTE PTR [eax + -330], 2 - mov BYTE PTR [eax + -329], 2 - mov BYTE PTR [eax + -328], 2 - mov BYTE PTR [eax + -327], 2 - mov BYTE PTR [eax + -326], 2 - mov BYTE PTR [eax + -325], 2 - mov BYTE PTR [eax + -324], 2 - mov BYTE PTR [eax + -323], 2 - mov BYTE PTR [eax + -322], 2 - mov BYTE PTR [eax + -321], 2 - mov BYTE PTR [eax + -320], 2 - mov BYTE PTR [eax + -319], 2 - mov BYTE PTR [eax + -318], 2 - mov BYTE PTR [eax + -317], 2 - mov BYTE PTR [eax + -316], 2 - mov BYTE PTR [eax + -315], 2 - mov BYTE PTR [eax + -314], 2 - mov BYTE PTR [eax + -313], 2 - mov BYTE PTR [eax + -312], 2 - mov BYTE PTR [eax + -311], 2 - mov BYTE PTR [eax + -10], 2 - mov BYTE PTR [eax + -9], 2 - mov BYTE PTR [eax + -8], 2 - mov BYTE PTR [eax + -7], 2 - mov BYTE PTR [eax + -6], 2 - mov BYTE PTR [eax + -5], 2 - mov BYTE PTR [eax + -4], 2 - mov BYTE PTR [eax + -3], 2 - mov BYTE PTR [eax + -2], 2 - mov BYTE PTR [eax + -1], 2 mov BYTE PTR [eax + 0], 2 mov BYTE PTR [eax + 1], 2 mov BYTE PTR [eax + 2], 2 @@ -241,16 +28,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 7], 2 mov BYTE PTR [eax + 8], 2 mov BYTE PTR [eax + 9], 2 - mov BYTE PTR [eax + 310], 2 - mov BYTE PTR [eax + 311], 2 - mov BYTE PTR [eax + 312], 2 - mov BYTE PTR [eax + 313], 2 - mov BYTE PTR [eax + 314], 2 - mov BYTE PTR [eax + 315], 2 - mov BYTE PTR [eax + 316], 2 - mov BYTE PTR [eax + 317], 2 - mov BYTE PTR [eax + 318], 2 - mov BYTE PTR [eax + 319], 2 + mov BYTE PTR [eax + 10], 2 + mov BYTE PTR [eax + 11], 2 + mov BYTE PTR [eax + 12], 2 + mov BYTE PTR [eax + 13], 2 + mov BYTE PTR [eax + 14], 2 + mov BYTE PTR [eax + 15], 2 + mov BYTE PTR [eax + 16], 2 + mov BYTE PTR [eax + 17], 2 + mov BYTE PTR [eax + 18], 2 + mov BYTE PTR [eax + 19], 2 mov BYTE PTR [eax + 320], 2 mov BYTE PTR [eax + 321], 2 mov BYTE PTR [eax + 322], 2 @@ -261,16 +48,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 327], 2 mov BYTE PTR [eax + 328], 2 mov BYTE PTR [eax + 329], 2 - mov BYTE PTR [eax + 630], 2 - mov BYTE PTR [eax + 631], 2 - mov BYTE PTR [eax + 632], 2 - mov BYTE PTR [eax + 633], 2 - mov BYTE PTR [eax + 634], 2 - mov BYTE PTR [eax + 635], 2 - mov BYTE PTR [eax + 636], 2 - mov BYTE PTR [eax + 637], 2 - mov BYTE PTR [eax + 638], 2 - mov BYTE PTR [eax + 639], 2 + mov BYTE PTR [eax + 330], 2 + mov BYTE PTR [eax + 331], 2 + mov BYTE PTR [eax + 332], 2 + mov BYTE PTR [eax + 333], 2 + mov BYTE PTR [eax + 334], 2 + mov BYTE PTR [eax + 335], 2 + mov BYTE PTR [eax + 336], 2 + mov BYTE PTR [eax + 337], 2 + mov BYTE PTR [eax + 338], 2 + mov BYTE PTR [eax + 339], 2 mov BYTE PTR [eax + 640], 2 mov BYTE PTR [eax + 641], 2 mov BYTE PTR [eax + 642], 2 @@ -281,16 +68,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 647], 2 mov BYTE PTR [eax + 648], 2 mov BYTE PTR [eax + 649], 2 - mov BYTE PTR [eax + 950], 2 - mov BYTE PTR [eax + 951], 2 - mov BYTE PTR [eax + 952], 2 - mov BYTE PTR [eax + 953], 2 - mov BYTE PTR [eax + 954], 2 - mov BYTE PTR [eax + 955], 2 - mov BYTE PTR [eax + 956], 2 - mov BYTE PTR [eax + 957], 2 - mov BYTE PTR [eax + 958], 2 - mov BYTE PTR [eax + 959], 2 + mov BYTE PTR [eax + 650], 2 + mov BYTE PTR [eax + 651], 2 + mov BYTE PTR [eax + 652], 2 + mov BYTE PTR [eax + 653], 2 + mov BYTE PTR [eax + 654], 2 + mov BYTE PTR [eax + 655], 2 + mov BYTE PTR [eax + 656], 2 + mov BYTE PTR [eax + 657], 2 + mov BYTE PTR [eax + 658], 2 + mov BYTE PTR [eax + 659], 2 mov BYTE PTR [eax + 960], 2 mov BYTE PTR [eax + 961], 2 mov BYTE PTR [eax + 962], 2 @@ -301,16 +88,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 967], 2 mov BYTE PTR [eax + 968], 2 mov BYTE PTR [eax + 969], 2 - mov BYTE PTR [eax + 1270], 2 - mov BYTE PTR [eax + 1271], 2 - mov BYTE PTR [eax + 1272], 2 - mov BYTE PTR [eax + 1273], 2 - mov BYTE PTR [eax + 1274], 2 - mov BYTE PTR [eax + 1275], 2 - mov BYTE PTR [eax + 1276], 2 - mov BYTE PTR [eax + 1277], 2 - mov BYTE PTR [eax + 1278], 2 - mov BYTE PTR [eax + 1279], 2 + mov BYTE PTR [eax + 970], 2 + mov BYTE PTR [eax + 971], 2 + mov BYTE PTR [eax + 972], 2 + mov BYTE PTR [eax + 973], 2 + mov BYTE PTR [eax + 974], 2 + mov BYTE PTR [eax + 975], 2 + mov BYTE PTR [eax + 976], 2 + mov BYTE PTR [eax + 977], 2 + mov BYTE PTR [eax + 978], 2 + mov BYTE PTR [eax + 979], 2 mov BYTE PTR [eax + 1280], 2 mov BYTE PTR [eax + 1281], 2 mov BYTE PTR [eax + 1282], 2 @@ -321,16 +108,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 1287], 2 mov BYTE PTR [eax + 1288], 2 mov BYTE PTR [eax + 1289], 2 - mov BYTE PTR [eax + 1590], 2 - mov BYTE PTR [eax + 1591], 2 - mov BYTE PTR [eax + 1592], 2 - mov BYTE PTR [eax + 1593], 2 - mov BYTE PTR [eax + 1594], 2 - mov BYTE PTR [eax + 1595], 2 - mov BYTE PTR [eax + 1596], 2 - mov BYTE PTR [eax + 1597], 2 - mov BYTE PTR [eax + 1598], 2 - mov BYTE PTR [eax + 1599], 2 + mov BYTE PTR [eax + 1290], 2 + mov BYTE PTR [eax + 1291], 2 + mov BYTE PTR [eax + 1292], 2 + mov BYTE PTR [eax + 1293], 2 + mov BYTE PTR [eax + 1294], 2 + mov BYTE PTR [eax + 1295], 2 + mov BYTE PTR [eax + 1296], 2 + mov BYTE PTR [eax + 1297], 2 + mov BYTE PTR [eax + 1298], 2 + mov BYTE PTR [eax + 1299], 2 mov BYTE PTR [eax + 1600], 2 mov BYTE PTR [eax + 1601], 2 mov BYTE PTR [eax + 1602], 2 @@ -341,16 +128,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 1607], 2 mov BYTE PTR [eax + 1608], 2 mov BYTE PTR [eax + 1609], 2 - mov BYTE PTR [eax + 1910], 2 - mov BYTE PTR [eax + 1911], 2 - mov BYTE PTR [eax + 1912], 2 - mov BYTE PTR [eax + 1913], 2 - mov BYTE PTR [eax + 1914], 2 - mov BYTE PTR [eax + 1915], 2 - mov BYTE PTR [eax + 1916], 2 - mov BYTE PTR [eax + 1917], 2 - mov BYTE PTR [eax + 1918], 2 - mov BYTE PTR [eax + 1919], 2 + mov BYTE PTR [eax + 1610], 2 + mov BYTE PTR [eax + 1611], 2 + mov BYTE PTR [eax + 1612], 2 + mov BYTE PTR [eax + 1613], 2 + mov BYTE PTR [eax + 1614], 2 + mov BYTE PTR [eax + 1615], 2 + mov BYTE PTR [eax + 1616], 2 + mov BYTE PTR [eax + 1617], 2 + mov BYTE PTR [eax + 1618], 2 + mov BYTE PTR [eax + 1619], 2 mov BYTE PTR [eax + 1920], 2 mov BYTE PTR [eax + 1921], 2 mov BYTE PTR [eax + 1922], 2 @@ -361,16 +148,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 1927], 2 mov BYTE PTR [eax + 1928], 2 mov BYTE PTR [eax + 1929], 2 - mov BYTE PTR [eax + 2230], 2 - mov BYTE PTR [eax + 2231], 2 - mov BYTE PTR [eax + 2232], 2 - mov BYTE PTR [eax + 2233], 2 - mov BYTE PTR [eax + 2234], 2 - mov BYTE PTR [eax + 2235], 2 - mov BYTE PTR [eax + 2236], 2 - mov BYTE PTR [eax + 2237], 2 - mov BYTE PTR [eax + 2238], 2 - mov BYTE PTR [eax + 2239], 2 + mov BYTE PTR [eax + 1930], 2 + mov BYTE PTR [eax + 1931], 2 + mov BYTE PTR [eax + 1932], 2 + mov BYTE PTR [eax + 1933], 2 + mov BYTE PTR [eax + 1934], 2 + mov BYTE PTR [eax + 1935], 2 + mov BYTE PTR [eax + 1936], 2 + mov BYTE PTR [eax + 1937], 2 + mov BYTE PTR [eax + 1938], 2 + mov BYTE PTR [eax + 1939], 2 mov BYTE PTR [eax + 2240], 2 mov BYTE PTR [eax + 2241], 2 mov BYTE PTR [eax + 2242], 2 @@ -381,16 +168,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 2247], 2 mov BYTE PTR [eax + 2248], 2 mov BYTE PTR [eax + 2249], 2 - mov BYTE PTR [eax + 2550], 2 - mov BYTE PTR [eax + 2551], 2 - mov BYTE PTR [eax + 2552], 2 - mov BYTE PTR [eax + 2553], 2 - mov BYTE PTR [eax + 2554], 2 - mov BYTE PTR [eax + 2555], 2 - mov BYTE PTR [eax + 2556], 2 - mov BYTE PTR [eax + 2557], 2 - mov BYTE PTR [eax + 2558], 2 - mov BYTE PTR [eax + 2559], 2 + mov BYTE PTR [eax + 2250], 2 + mov BYTE PTR [eax + 2251], 2 + mov BYTE PTR [eax + 2252], 2 + mov BYTE PTR [eax + 2253], 2 + mov BYTE PTR [eax + 2254], 2 + mov BYTE PTR [eax + 2255], 2 + mov BYTE PTR [eax + 2256], 2 + mov BYTE PTR [eax + 2257], 2 + mov BYTE PTR [eax + 2258], 2 + mov BYTE PTR [eax + 2259], 2 mov BYTE PTR [eax + 2560], 2 mov BYTE PTR [eax + 2561], 2 mov BYTE PTR [eax + 2562], 2 @@ -401,16 +188,16 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 2567], 2 mov BYTE PTR [eax + 2568], 2 mov BYTE PTR [eax + 2569], 2 - mov BYTE PTR [eax + 2870], 2 - mov BYTE PTR [eax + 2871], 2 - mov BYTE PTR [eax + 2872], 2 - mov BYTE PTR [eax + 2873], 2 - mov BYTE PTR [eax + 2874], 2 - mov BYTE PTR [eax + 2875], 2 - mov BYTE PTR [eax + 2876], 2 - mov BYTE PTR [eax + 2877], 2 - mov BYTE PTR [eax + 2878], 2 - mov BYTE PTR [eax + 2879], 2 + mov BYTE PTR [eax + 2570], 2 + mov BYTE PTR [eax + 2571], 2 + mov BYTE PTR [eax + 2572], 2 + mov BYTE PTR [eax + 2573], 2 + mov BYTE PTR [eax + 2574], 2 + mov BYTE PTR [eax + 2575], 2 + mov BYTE PTR [eax + 2576], 2 + mov BYTE PTR [eax + 2577], 2 + mov BYTE PTR [eax + 2578], 2 + mov BYTE PTR [eax + 2579], 2 mov BYTE PTR [eax + 2880], 2 mov BYTE PTR [eax + 2881], 2 mov BYTE PTR [eax + 2882], 2 @@ -421,8 +208,217 @@ sprite_arenaWallTop_: mov BYTE PTR [eax + 2887], 2 mov BYTE PTR [eax + 2888], 2 mov BYTE PTR [eax + 2889], 2 + mov BYTE PTR [eax + 2890], 2 + mov BYTE PTR [eax + 2891], 2 + mov BYTE PTR [eax + 2892], 2 + mov BYTE PTR [eax + 2893], 2 + mov BYTE PTR [eax + 2894], 2 + mov BYTE PTR [eax + 2895], 2 + mov BYTE PTR [eax + 2896], 2 + mov BYTE PTR [eax + 2897], 2 + mov BYTE PTR [eax + 2898], 2 + mov BYTE PTR [eax + 2899], 2 + mov BYTE PTR [eax + 3200], 2 + mov BYTE PTR [eax + 3201], 2 + mov BYTE PTR [eax + 3202], 2 + mov BYTE PTR [eax + 3203], 2 + mov BYTE PTR [eax + 3204], 2 + mov BYTE PTR [eax + 3205], 2 + mov BYTE PTR [eax + 3206], 2 + mov BYTE PTR [eax + 3207], 2 + mov BYTE PTR [eax + 3208], 2 + mov BYTE PTR [eax + 3209], 2 + mov BYTE PTR [eax + 3210], 2 + mov BYTE PTR [eax + 3211], 2 + mov BYTE PTR [eax + 3212], 2 + mov BYTE PTR [eax + 3213], 2 + mov BYTE PTR [eax + 3214], 2 + mov BYTE PTR [eax + 3215], 2 + mov BYTE PTR [eax + 3216], 2 + mov BYTE PTR [eax + 3217], 2 + mov BYTE PTR [eax + 3218], 2 + mov BYTE PTR [eax + 3219], 2 + mov BYTE PTR [eax + 3520], 2 + mov BYTE PTR [eax + 3521], 2 + mov BYTE PTR [eax + 3522], 2 + mov BYTE PTR [eax + 3523], 2 + mov BYTE PTR [eax + 3524], 2 + mov BYTE PTR [eax + 3525], 2 + mov BYTE PTR [eax + 3526], 2 + mov BYTE PTR [eax + 3527], 2 + mov BYTE PTR [eax + 3528], 2 + mov BYTE PTR [eax + 3529], 2 + mov BYTE PTR [eax + 3530], 2 + mov BYTE PTR [eax + 3531], 2 + mov BYTE PTR [eax + 3532], 2 + mov BYTE PTR [eax + 3533], 2 + mov BYTE PTR [eax + 3534], 2 + mov BYTE PTR [eax + 3535], 2 + mov BYTE PTR [eax + 3536], 2 + mov BYTE PTR [eax + 3537], 2 + mov BYTE PTR [eax + 3538], 2 + mov BYTE PTR [eax + 3539], 2 + mov BYTE PTR [eax + 3840], 2 + mov BYTE PTR [eax + 3841], 2 + mov BYTE PTR [eax + 3842], 2 + mov BYTE PTR [eax + 3843], 2 + mov BYTE PTR [eax + 3844], 2 + mov BYTE PTR [eax + 3845], 2 + mov BYTE PTR [eax + 3846], 2 + mov BYTE PTR [eax + 3847], 2 + mov BYTE PTR [eax + 3848], 2 + mov BYTE PTR [eax + 3849], 2 + mov BYTE PTR [eax + 3850], 2 + mov BYTE PTR [eax + 3851], 2 + mov BYTE PTR [eax + 3852], 2 + mov BYTE PTR [eax + 3853], 2 + mov BYTE PTR [eax + 3854], 2 + mov BYTE PTR [eax + 3855], 2 + mov BYTE PTR [eax + 3856], 2 + mov BYTE PTR [eax + 3857], 2 + mov BYTE PTR [eax + 3858], 2 + mov BYTE PTR [eax + 3859], 2 + mov BYTE PTR [eax + 4160], 2 + mov BYTE PTR [eax + 4161], 2 + mov BYTE PTR [eax + 4162], 2 + mov BYTE PTR [eax + 4163], 2 + mov BYTE PTR [eax + 4164], 2 + mov BYTE PTR [eax + 4165], 2 + mov BYTE PTR [eax + 4166], 2 + mov BYTE PTR [eax + 4167], 2 + mov BYTE PTR [eax + 4168], 2 + mov BYTE PTR [eax + 4169], 2 + mov BYTE PTR [eax + 4170], 2 + mov BYTE PTR [eax + 4171], 2 + mov BYTE PTR [eax + 4172], 2 + mov BYTE PTR [eax + 4173], 2 + mov BYTE PTR [eax + 4174], 2 + mov BYTE PTR [eax + 4175], 2 + mov BYTE PTR [eax + 4176], 2 + mov BYTE PTR [eax + 4177], 2 + mov BYTE PTR [eax + 4178], 2 + mov BYTE PTR [eax + 4179], 2 + mov BYTE PTR [eax + 4480], 2 + mov BYTE PTR [eax + 4481], 2 + mov BYTE PTR [eax + 4482], 2 + mov BYTE PTR [eax + 4483], 2 + mov BYTE PTR [eax + 4484], 2 + mov BYTE PTR [eax + 4485], 2 + mov BYTE PTR [eax + 4486], 2 + mov BYTE PTR [eax + 4487], 2 + mov BYTE PTR [eax + 4488], 2 + mov BYTE PTR [eax + 4489], 2 + mov BYTE PTR [eax + 4490], 2 + mov BYTE PTR [eax + 4491], 2 + mov BYTE PTR [eax + 4492], 2 + mov BYTE PTR [eax + 4493], 2 + mov BYTE PTR [eax + 4494], 2 + mov BYTE PTR [eax + 4495], 2 + mov BYTE PTR [eax + 4496], 2 + mov BYTE PTR [eax + 4497], 2 + mov BYTE PTR [eax + 4498], 2 + mov BYTE PTR [eax + 4499], 2 + mov BYTE PTR [eax + 4800], 2 + mov BYTE PTR [eax + 4801], 2 + mov BYTE PTR [eax + 4802], 2 + mov BYTE PTR [eax + 4803], 2 + mov BYTE PTR [eax + 4804], 2 + mov BYTE PTR [eax + 4805], 2 + mov BYTE PTR [eax + 4806], 2 + mov BYTE PTR [eax + 4807], 2 + mov BYTE PTR [eax + 4808], 2 + mov BYTE PTR [eax + 4809], 2 + mov BYTE PTR [eax + 4810], 2 + mov BYTE PTR [eax + 4811], 2 + mov BYTE PTR [eax + 4812], 2 + mov BYTE PTR [eax + 4813], 2 + mov BYTE PTR [eax + 4814], 2 + mov BYTE PTR [eax + 4815], 2 + mov BYTE PTR [eax + 4816], 2 + mov BYTE PTR [eax + 4817], 2 + mov BYTE PTR [eax + 4818], 2 + mov BYTE PTR [eax + 4819], 2 + mov BYTE PTR [eax + 5120], 2 + mov BYTE PTR [eax + 5121], 2 + mov BYTE PTR [eax + 5122], 2 + mov BYTE PTR [eax + 5123], 2 + mov BYTE PTR [eax + 5124], 2 + mov BYTE PTR [eax + 5125], 2 + mov BYTE PTR [eax + 5126], 2 + mov BYTE PTR [eax + 5127], 2 + mov BYTE PTR [eax + 5128], 2 + mov BYTE PTR [eax + 5129], 2 + mov BYTE PTR [eax + 5130], 2 + mov BYTE PTR [eax + 5131], 2 + mov BYTE PTR [eax + 5132], 2 + mov BYTE PTR [eax + 5133], 2 + mov BYTE PTR [eax + 5134], 2 + mov BYTE PTR [eax + 5135], 2 + mov BYTE PTR [eax + 5136], 2 + mov BYTE PTR [eax + 5137], 2 + mov BYTE PTR [eax + 5138], 2 + mov BYTE PTR [eax + 5139], 2 + mov BYTE PTR [eax + 5440], 2 + mov BYTE PTR [eax + 5441], 2 + mov BYTE PTR [eax + 5442], 2 + mov BYTE PTR [eax + 5443], 2 + mov BYTE PTR [eax + 5444], 2 + mov BYTE PTR [eax + 5445], 2 + mov BYTE PTR [eax + 5446], 2 + mov BYTE PTR [eax + 5447], 2 + mov BYTE PTR [eax + 5448], 2 + mov BYTE PTR [eax + 5449], 2 + mov BYTE PTR [eax + 5450], 2 + mov BYTE PTR [eax + 5451], 2 + mov BYTE PTR [eax + 5452], 2 + mov BYTE PTR [eax + 5453], 2 + mov BYTE PTR [eax + 5454], 2 + mov BYTE PTR [eax + 5455], 2 + mov BYTE PTR [eax + 5456], 2 + mov BYTE PTR [eax + 5457], 2 + mov BYTE PTR [eax + 5458], 2 + mov BYTE PTR [eax + 5459], 2 + mov BYTE PTR [eax + 5760], 2 + mov BYTE PTR [eax + 5761], 2 + mov BYTE PTR [eax + 5762], 2 + mov BYTE PTR [eax + 5763], 2 + mov BYTE PTR [eax + 5764], 2 + mov BYTE PTR [eax + 5765], 2 + mov BYTE PTR [eax + 5766], 2 + mov BYTE PTR [eax + 5767], 2 + mov BYTE PTR [eax + 5768], 2 + mov BYTE PTR [eax + 5769], 2 + mov BYTE PTR [eax + 5770], 2 + mov BYTE PTR [eax + 5771], 2 + mov BYTE PTR [eax + 5772], 2 + mov BYTE PTR [eax + 5773], 2 + mov BYTE PTR [eax + 5774], 2 + mov BYTE PTR [eax + 5775], 2 + mov BYTE PTR [eax + 5776], 2 + mov BYTE PTR [eax + 5777], 2 + mov BYTE PTR [eax + 5778], 2 + mov BYTE PTR [eax + 5779], 2 + mov BYTE PTR [eax + 6080], 2 + mov BYTE PTR [eax + 6081], 2 + mov BYTE PTR [eax + 6082], 2 + mov BYTE PTR [eax + 6083], 2 + mov BYTE PTR [eax + 6084], 2 + mov BYTE PTR [eax + 6085], 2 + mov BYTE PTR [eax + 6086], 2 + mov BYTE PTR [eax + 6087], 2 + mov BYTE PTR [eax + 6088], 2 + mov BYTE PTR [eax + 6089], 2 + mov BYTE PTR [eax + 6090], 2 + mov BYTE PTR [eax + 6091], 2 + mov BYTE PTR [eax + 6092], 2 + mov BYTE PTR [eax + 6093], 2 + mov BYTE PTR [eax + 6094], 2 + mov BYTE PTR [eax + 6095], 2 + mov BYTE PTR [eax + 6096], 2 + mov BYTE PTR [eax + 6097], 2 + mov BYTE PTR [eax + 6098], 2 + mov BYTE PTR [eax + 6099], 2 - pop ebx pop ebp ret @@ -430,9 +426,6 @@ sprite_arenaWallTop_: sprite_arenaWallSide_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] mov BYTE PTR [eax + 0], 3 @@ -836,7 +829,6 @@ sprite_arenaWallSide_: mov BYTE PTR [eax + 6098], 3 mov BYTE PTR [eax + 6099], 3 - pop ebx pop ebp ret @@ -844,9 +836,6 @@ sprite_arenaWallSide_: sprite_arenaFloor_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] mov BYTE PTR [eax + 0], 4 @@ -1250,7 +1239,6 @@ sprite_arenaFloor_: mov BYTE PTR [eax + 6098], 4 mov BYTE PTR [eax + 6099], 4 - pop ebx pop ebp ret @@ -1258,9 +1246,6 @@ sprite_arenaFloor_: sprite_rabbit_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] mov BYTE PTR [eax + -1921], 1 @@ -1314,7 +1299,6 @@ sprite_rabbit_: mov BYTE PTR [eax + 1918], 1 mov BYTE PTR [eax + 1921], 1 - pop ebx pop ebp ret @@ -1322,9 +1306,6 @@ sprite_rabbit_: sprite_mouse_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] mov BYTE PTR [eax + -1281], 5 @@ -1344,7 +1325,6 @@ sprite_mouse_: mov BYTE PTR [eax + 959], 5 mov BYTE PTR [eax + 960], 5 - pop ebx pop ebp ret @@ -1352,9 +1332,6 @@ sprite_mouse_: sprite_bullet_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] mov BYTE PTR [eax + 0], 5 @@ -1362,7 +1339,6 @@ sprite_bullet_: mov BYTE PTR [eax + 320], 5 mov BYTE PTR [eax + 321], 5 - pop ebx pop ebp ret @@ -1370,9 +1346,6 @@ sprite_bullet_: sprite_enemy_: push ebp mov ebp, esp - push ebx - - mov eax, [ebp + 8] mov BYTE PTR [eax + -1921], 1 @@ -1426,7 +1399,6 @@ sprite_enemy_: mov BYTE PTR [eax + 1918], 1 mov BYTE PTR [eax + 1921], 1 - pop ebx pop ebp ret diff --git a/sprites.h b/sprites.h index f2d86c5..4beed32 100644 --- a/sprites.h +++ b/sprites.h @@ -1,22 +1,24 @@ +#ifndef __SPRITES_H__ +#define __SPRITES_H__ + +#include "types.h" + extern void sprite_arenaWallTop(byte *); -#pragma aux (__cdecl) sprite_arenaWallTop "sprite_arenaWallTop_" extern void sprite_arenaWallSide(byte *); -#pragma aux (__cdecl) sprite_arenaWallSide "sprite_arenaWallSide_" extern void sprite_arenaFloor(byte *); -#pragma aux (__cdecl) sprite_arenaFloor "sprite_arenaFloor_" extern void sprite_rabbit(byte *); -#pragma aux (__cdecl) sprite_rabbit "sprite_rabbit_" extern void sprite_mouse(byte *); -#pragma aux (__cdecl) sprite_mouse "sprite_mouse_" extern void sprite_bullet(byte *); -#pragma aux (__cdecl) sprite_bullet "sprite_bullet_" extern void sprite_enemy(byte *); -#pragma aux (__cdecl) sprite_enemy "sprite_enemy_" + +// TODO: something with bounds checking here + +#endif diff --git a/spritesheet.yml b/spritesheet.yml index a1b6bdc..596a9a7 100644 --- a/spritesheet.yml +++ b/spritesheet.yml @@ -8,7 +8,7 @@ files: arenaWallTop: position: [0, 0] dimensions: [20, 20] - offset: [10, 10] + offset: [0, 0] arenaWallSide: position: [20, 0] dimensions: [20, 20] diff --git a/system/vga.c b/system/vga.c index 17ab604..1ff251c 100644 --- a/system/vga.c +++ b/system/vga.c @@ -50,6 +50,17 @@ void buildSpriteFromSpritesheet( spriteRender->transparentColor = spritesheetImage->transparentColor; } +void buildCompiledSprite( + void (*code)(byte *), + struct CompiledSpriteRender *compiledSpriteRender, + int width, + int height +) { + compiledSpriteRender->code = code; + compiledSpriteRender->width = width; + compiledSpriteRender->height = height; +} + void drawPixel(int x, int y, int color) { drawBuffer[y * VGA_DISPLAY_WIDTH + x] = color; } @@ -83,6 +94,13 @@ void drawSprite(struct SpriteRender* sprite) { } } +void drawCompiledSprite(struct CompiledSpriteRender* compiledSprite) { + byte *drawBufferPos = drawBuffer + + compiledSprite->x + compiledSprite->y * VGA_DISPLAY_WIDTH; + + compiledSprite->code(drawBufferPos); +} + void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds) { bounds->top = sprite->y - sprite->offsetY; bounds->bottom = bounds->top + sprite->height; diff --git a/system/vga.h b/system/vga.h index 29db2bd..0619c4e 100644 --- a/system/vga.h +++ b/system/vga.h @@ -28,6 +28,14 @@ struct SpriteRender { int offsetY; }; +struct CompiledSpriteRender { + void (*code)(byte *); + int x; + int y; + unsigned int width; + unsigned int height; +}; + struct SpriteBounds { int top; int right; @@ -38,7 +46,9 @@ struct SpriteBounds { void drawPixel(int x, int y, int color); void drawSprite(struct SpriteRender *sprite); +void drawCompiledSprite(struct CompiledSpriteRender *compiledSprite); void buildSpriteFromSpritesheet(struct BMPImage*, struct SpriteRender*, int, int, int, int); +void buildCompiledSprite(void (*)(byte *), struct CompiledSpriteRender*, int width, int height); void getSpriteBounds(struct SpriteRender *sprite, struct SpriteBounds *bounds); byte *initializeDrawBuffer();