From: John Tsiombikas Date: Sat, 5 Oct 2019 22:22:31 +0000 (+0300) Subject: foo X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=ld45_start_nothing;a=commitdiff_plain;h=6a16a1c526937ee551f968901cb949d55e35ecda foo --- diff --git a/Makefile b/Makefile index 6d20b28..90ea9da 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ src = $(wildcard src/*.asm) +data = data/sprsheet.inc bin = game QEMU_FLAGS = -fda floppy.img -serial file:serial.log -soundhw sb16 -d guest_errors @@ -9,7 +10,7 @@ all: floppy.img bootldr: src/boot/boot.asm $(bin) nasm -o $@ -f bin -DBINSIZE=`ls -l $(bin) | awk '{print $$5}'` $< -$(bin): $(src) +$(bin): $(src) $(data) nasm -o $@ -f bin -i src/ src/main.asm boot.img: bootldr $(bin) @@ -19,6 +20,9 @@ floppy.img: boot.img dd of=$@ if=/dev/zero bs=512 count=2880 dd of=$@ if=$< bs=1 conv=notrunc +data/sprsheet.inc: data/sprsheet.png + img2tiles -o $@ -n -t 32x32 $< + .PHONY: clean clean: rm -f $(bin) bootldr floppy.img boot.img diff --git a/src/gfx.asm b/src/gfx.asm index d352139..a3f2d39 100644 --- a/src/gfx.asm +++ b/src/gfx.asm @@ -28,8 +28,21 @@ init_gfx: ; video mode 13h (320x200 8bpp) mov ax, 13h int 10h - call clear + + ; setup the spritesheet palette + mov si, sprsheet_cmap + xor cl, cl +.cmaploop: + mov al, cl + mov ah, [si] + mov bl, [si + 1] + mov bh, [si + 2] + add si, 3 + call set_palette_entry + dec cl + jnz .cmaploop + ret clear: @@ -86,3 +99,51 @@ set_palette_entry: out dx, al pop dx ret + + ; slow_sprite(short id, short x, short y) + ; assumptions: 32x32, one after the other, 0 is transparent + ; XXX sprsheet needs to go to its own segment +slow_sprite: + push bp + mov bp, sp + pusha + + mov ax, FRAMEBUF_SEG + mov es, ax + mov ax, [bp + 8] ; ax <- y + sub ax, 16 ; ax <- y - 16 (center sprite vertically) + mov bx, ax + shl ax, 8 + shl bx, 6 + add ax, bx ; ax <- (y - 16) * 320 + mov di, [bp + 6] ; di <- x + sub di, 16 ; di <- x - 16 (center sprite horizontally) + add di, ax ; di <- (y - 16) * 320 + (x - 16) + + mov si, sprsheet_tiles + ; calculate sprite id offset (each spr is 32*32=1k) + mov ax, [bp + 4] + shl ax, 10 + add si, ax + + mov cx, 32 +.yloop: + xor bx, bx +.xloop: + mov al, [si] + cmp al, 0 + ;jz .skip_pixel + mov [es:di + bx], al +.skip_pixel: + inc si + inc bx + cmp bx, 32 + jnz .xloop + + add di, 320 + dec cx + jnz .yloop + + popa + pop bp + ret diff --git a/src/main.asm b/src/main.asm index 51bcbfa..c0af0ad 100644 --- a/src/main.asm +++ b/src/main.asm @@ -5,10 +5,17 @@ call init_gfx main_loop: + call clear + + push word 100 + push word 160 + push word 0 + call slow_sprite + call wait_vsync call swap_buffers jmp main_loop %include "gfx.asm" -%include "data.asm" +%include "data/sprsheet.inc"