diff --git a/part12-wgt/Makefile b/part12-wgt/Makefile index 4e43900..251e5f7 100644 --- a/part12-wgt/Makefile +++ b/part12-wgt/Makefile @@ -14,11 +14,14 @@ bin/wgt1pal.o: bin/wgt1.pal bin/wgt1blk.o: bin/wgt1.blk $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ +bin/wgt2blk.o: bin/wgt2.blk + $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ + %.o: %.c $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ -kernel8.img: boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o - $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o -T boot/link.ld -o kernel8.elf +kernel8.img: boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o + $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot/boot.o $(OFILES) bin/wgt1pal.o bin/wgt1blk.o bin/wgt2blk.o -T boot/link.ld -o kernel8.elf $(LLVMPATH)/llvm-objcopy -O binary kernel8.elf kernel8.img clean: diff --git a/part12-wgt/bin/wgt2.blk b/part12-wgt/bin/wgt2.blk new file mode 100644 index 0000000..c4b437c Binary files /dev/null and b/part12-wgt/bin/wgt2.blk differ diff --git a/part12-wgt/examples/wgt21.c b/part12-wgt/examples/wgt21.c new file mode 100644 index 0000000..8dddc18 --- /dev/null +++ b/part12-wgt/examples/wgt21.c @@ -0,0 +1,98 @@ +#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= 0; q -= dir) + { + wvertres (0, 0, q, b1); + wvertres (0, q, 199, b2); + } +} + +void wgt21() +{ + set_clock_rate(get_max_clock()); + mem_init(); + vga256 (); + + extern unsigned char _binary_bin_wgt1_pal_start[]; + wloadpalette (&_binary_bin_wgt1_pal_start[0], pal); + wsetpalette (0, 255, pal); + + extern unsigned char _binary_bin_wgt1_blk_start[]; + screen1 = wloadblock (&_binary_bin_wgt1_blk_start[0]); + + extern unsigned char _binary_bin_wgt2_blk_start[]; + screen2 = wloadblock (&_binary_bin_wgt2_blk_start[0]); + + wputblock (0, 0, screen1, 0); + + do { + crush (screen1, screen2, 2); + crush (screen2, screen1, 2); + } while (1); + + wfreeblock (screen1); /* remember to free that memory */ + wfreeblock (screen2); +} + +void main() +{ + wgt21(); + while (1); +} diff --git a/part12-wgt/wgt.h b/part12-wgt/wgt.h index 3a80e10..82d6ba6 100644 --- a/part12-wgt/wgt.h +++ b/part12-wgt/wgt.h @@ -115,3 +115,4 @@ void wresize (short x, short y, short x2, short y2, block image, short mode); void wdissolve (block sourceimage, short *pattern, short speed); void wsetscreen (block image); void wnormscreen (void); +void wvertres (short x, short y, short y2, block image); diff --git a/part12-wgt/wmiscb.c b/part12-wgt/wmiscb.c index 53a86f8..930c2e9 100644 --- a/part12-wgt/wmiscb.c +++ b/part12-wgt/wmiscb.c @@ -10,11 +10,11 @@ void wfreeblock (block ptr) short wgetblockwidth (block ptr) { - return *ptr; /* Width is first 2 bytes of data */ + return *(short *)ptr; /* Width is first 2 bytes of data */ } short wgetblockheight (block ptr) { ptr ++; /* Skip width */ - return *ptr; /* Height is second 2 bytes of data */ + return *(short *)ptr; /* Height is second 2 bytes of data */ } diff --git a/part12-wgt/wvertres.c b/part12-wgt/wvertres.c new file mode 100644 index 0000000..6dd82dc --- /dev/null +++ b/part12-wgt/wvertres.c @@ -0,0 +1,50 @@ +#include "wgt.h" + +void wvertres (short x, short y, short y2, block image) +{ + short width,height,base,yy,temp; + int fy,ctr2; + int same2,incr2; + + width = wgetblockwidth (image); + height = wgetblockheight (image); /* store width and height */ + + if (y > y2) /* swap y's if needed */ + { + temp = y; + y = y2; + y2 = temp; + } + + incr2 = (y2 - y + 1) * (2000 / height); + + /* find increment */ + fy = y2; + yy = y; + ctr2 = 0; + same2 = 0; + base = 0; + while (yy <= fy) + { + if (incr2 >= 2000) + while ((same2 - ctr2 > 999) & (yy < fy)) + { + memcpy (&abuf[(yy)*WGT_SYS.xres + x], &image[(base)*width + 2], width); + yy ++; + ctr2 += 2000; + } + else + while (same2 < ctr2) + { + same2 += incr2; + base ++; + } + if (yy < fy) + memcpy (&abuf[(yy)*WGT_SYS.xres + x], &image[(base)*width + 2], width); + same2 += incr2; + ctr2 += 2000; + base ++; + yy ++; + } + +}