Added wgt45.c to load space.spr sprites and display them

This commit is contained in:
Adam Greenwood-Byrne 2021-03-20 16:36:08 +00:00
parent c6033ac356
commit 4ca24f9693
3 changed files with 85 additions and 2 deletions

View file

@ -20,11 +20,14 @@ bin/wgt2blk.o: bin/wgt2.blk
bin/lettersspr.o: bin/letters.spr bin/lettersspr.o: bin/letters.spr
$(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@
bin/spacespr.o: bin/space.spr
$(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@
%.o: %.c %.o: %.c
$(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@
kernel8.img: boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o kernel8.img: boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o -T boot/link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o bin/lettersspr.o bin/spacespr.o -T boot/link.ld -o kernel8.elf
$(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img
clean: clean:

BIN
part12-wgt/bin/space.spr Normal file

Binary file not shown.

View file

@ -0,0 +1,80 @@
#include "wgt.h"
#include "include/mem.h"
// ######## REQUIRED FUNCTIONS ########
unsigned long state0 = 1000;
unsigned long state1 = 2000;
unsigned long rand(void)
{
unsigned long s1 = state0;
unsigned long s0 = state1;
state0 = s0;
s1 ^= s1 << 23;
s1 ^= s1 >> 17;
s1 ^= s0;
s1 ^= s0 >> 26;
state1 = s1;
return state0 + state1;
}
void wait_msec(unsigned int n)
{
register unsigned long f, t, r;
// Get the current counter frequency
asm volatile ("mrs %0, cntfrq_el0" : "=r"(f));
// Read the current counter
asm volatile ("mrs %0, cntpct_el0" : "=r"(t));
// Calculate expire value for counter
t+=((f/1000)*n)/1000;
do{asm volatile ("mrs %0, cntpct_el0" : "=r"(r));}while(r<t);
}
// ######## STUB FUNCTIONS ########
unsigned int kb = 0;
unsigned int kbhit(void) {
kb++;
return kb / 500;
}
void getch(void) {
wait_msec(0x500000);
kb = 0;
}
// ######## WGT EXAMPLES ########
void wgt45()
{
block sprites[10]; /* An array of blocks to load the sprites into.
Version 5.0 allows for any number to be
loaded in, as long as you pass the same size
of the array to the wloadsprites and wfreesprites
commands. */
short i;
color palette[256];
set_clock_rate(get_max_clock());
mem_init();
vga256 (); /* Initializes WGT system */
extern unsigned char _binary_bin_space_spr_start[];
wloadsprites (palette, &_binary_bin_space_spr_start[0], sprites, 0, 9);
/* loads the first 10 sprites */
wsetpalette (0, 255, palette);
for (i = 0; i < 10; i++) /* Display them */
wputblock (i * 30, 0, sprites[i], NORMAL);
}
void main()
{
wgt45();
while (1);
}