From dd4fdad4be0daf4772a4e8a47c832cced2de868b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 28 Feb 2024 21:07:35 -0500 Subject: [PATCH] no more bitmap loading --- bin/build_spritesheet_asm.rb | 34 +++++++++++++++++++++++++++++++--- game.c | 10 ++-------- sprites.h | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/bin/build_spritesheet_asm.rb b/bin/build_spritesheet_asm.rb index 3d6fdab..6881fd3 100755 --- a/bin/build_spritesheet_asm.rb +++ b/bin/build_spritesheet_asm.rb @@ -60,11 +60,18 @@ ASM_TEMPLATE = <<~ASM end ASM -C_TEMPLATE = <<~C +H_TEMPLATE = <<~H #ifndef __SPRITES_H__ #define __SPRITES_H__ #include "types.h" + #include "system/vga.h" + + #define PALETTE_COLOR_COUNT (<%= palette.length %>) + + struct VGAColor palette[<%= palette.length %>] = { + <%= palette.map(&:to_struct).join(",\n") %> + }; <% sprites.each do |sprite| %> extern void <%= sprite.function_name %>(byte *); @@ -74,7 +81,7 @@ C_TEMPLATE = <<~C <% end %> #endif -C +H class AssemblerSprite def initialize( @@ -144,9 +151,29 @@ screen = Screen.new( sprite_data = [] +palette = nil + +VGAColor = Data.define(:red, :green, :blue) do + def to_struct + "{ #{red}, #{green}, #{blue} }" + end +end + data["files"].each do |spritesheet| image = Magick::Image.read(spritesheet["file"]).first + unless palette + palette = image.colors.times.map do |i| + pixel = Magick::Pixel.from_color(image.colormap(i)) + + VGAColor.new( + red: pixel.red >> 10, + green: pixel.green >> 10, + blue: pixel.blue >> 10 + ) + end + end + spritesheet["sprites"].each do |name, details| sprite_data << SpriteData.new( image:, @@ -179,12 +206,13 @@ sprites = sprite_data.map do |sd| ) end + File.open('sprites.asm', 'w') do |fh| fh.puts ERB.new(ASM_TEMPLATE).result_with_hash(sprites:) end File.open('sprites.h', 'w') do |fh| - fh.puts ERB.new(C_TEMPLATE).result_with_hash(sprites:) + fh.puts ERB.new(H_TEMPLATE).result_with_hash(sprites:, palette:) end puts "sprites.{asm,h} written" diff --git a/game.c b/game.c index e3e602c..ddac22a 100644 --- a/game.c +++ b/game.c @@ -368,12 +368,6 @@ int setupGame() { installKeyboardHandler(); initializeDrawBuffer(); - fh = fopen("sprtsht.bmp", "rb"); - if (readBMPIntoNewMemory(fh, &spritesheetImage)) return 1; - fclose(fh); - - spritesheetImage.transparentColor = 0; - setupWallSprites(); setupRabbitSprites(); setupRabbitBullets(); @@ -384,8 +378,8 @@ int setupGame() { setupPowerupSprites(); setVideoMode(VIDEO_MODE_VGA_256); - bmp256ColorPaletteToVGAColorPalette(&spritesheetImage, vgaColors); - setVGAColors(vgaColors, 256); + + setVGAColors(palette, PALETTE_COLOR_COUNT); activateMouse(&mouseStatus); diff --git a/sprites.h b/sprites.h index 20ce927..5f221ce 100644 --- a/sprites.h +++ b/sprites.h @@ -2,6 +2,29 @@ #define __SPRITES_H__ #include "types.h" +#include "system/vga.h" + +#define PALETTE_COLOR_COUNT (17) + +struct VGAColor palette[17] = { + { 63, 0, 63 }, +{ 0, 0, 0 }, +{ 15, 16, 49 }, +{ 16, 16, 33 }, +{ 16, 16, 16 }, +{ 63, 63, 63 }, +{ 38, 31, 12 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 }, +{ 0, 0, 0 } +}; extern void sprite_arenaWallTop(byte *);