From 3a7fe80b7e931c6f395960c31051714c000aa9a7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 Apr 2019 22:08:06 +0200 Subject: [PATCH] new beep program on enter --- .boot2.asm.swp | Bin 0 -> 1024 bytes .program.asm.swp | Bin 0 -> 1024 bytes Makefile | 17 +- beep.asm | 61 +++++ beep.bin | Bin 0 -> 75 bytes boot.asm | 19 +- boot.bin | Bin 512 -> 512 bytes boot2.asm | 64 +++++ buffer.asm | 101 ++++++++ disk.img | Bin 737280 -> 737280 bytes exe.bin | Bin 0 -> 8704 bytes img/box.bin | Bin 0 -> 83 bytes img/box.png | Bin 0 -> 982 bytes img/coin_0.bin | Bin 0 -> 83 bytes img/coin_0.png | Bin 0 -> 868 bytes img/coin_1.bin | Bin 0 -> 83 bytes img/coin_1.png | Bin 0 -> 874 bytes img/coin_2.bin | Bin 0 -> 83 bytes img/coin_2.png | Bin 0 -> 868 bytes img/colors.png | Bin 0 -> 563 bytes img/image2binary.py | 47 ++++ img/map.bin | 1 + img/player_back_0.bin | Bin 0 -> 110 bytes img/player_back_0.png | Bin 0 -> 908 bytes img/player_back_1.bin | Bin 0 -> 110 bytes img/player_back_1.png | Bin 0 -> 908 bytes img/player_back_2.bin | Bin 0 -> 110 bytes img/player_back_2.png | Bin 0 -> 906 bytes img/player_front_0.bin | Bin 0 -> 110 bytes img/player_front_0.png | Bin 0 -> 912 bytes img/player_front_1.bin | Bin 0 -> 110 bytes img/player_front_1.png | Bin 0 -> 911 bytes img/player_front_2.bin | Bin 0 -> 110 bytes img/player_front_2.png | Bin 0 -> 911 bytes img/player_left_0.bin | Bin 0 -> 110 bytes img/player_left_0.png | Bin 0 -> 904 bytes img/player_left_1.bin | Bin 0 -> 110 bytes img/player_left_1.png | Bin 0 -> 907 bytes img/player_left_2.bin | Bin 0 -> 110 bytes img/player_left_2.png | Bin 0 -> 907 bytes img/player_right_0.bin | Bin 0 -> 110 bytes img/player_right_0.png | Bin 0 -> 904 bytes img/player_right_1.bin | Bin 0 -> 110 bytes img/player_right_1.png | Bin 0 -> 908 bytes img/player_right_2.bin | Bin 0 -> 110 bytes img/player_right_2.png | Bin 0 -> 908 bytes img/tile.bin | Bin 0 -> 66 bytes img/tile.png | Bin 0 -> 861 bytes program.asm | 121 ++++++++-- program.bin | Bin 482 -> 8192 bytes program3.asm | 531 +++++++++++++++++++++++++++++++++++++++++ 51 files changed, 920 insertions(+), 42 deletions(-) create mode 100644 .boot2.asm.swp create mode 100644 .program.asm.swp create mode 100644 beep.asm create mode 100644 beep.bin create mode 100644 boot2.asm create mode 100644 buffer.asm create mode 100644 exe.bin create mode 100644 img/box.bin create mode 100644 img/box.png create mode 100644 img/coin_0.bin create mode 100644 img/coin_0.png create mode 100644 img/coin_1.bin create mode 100644 img/coin_1.png create mode 100644 img/coin_2.bin create mode 100644 img/coin_2.png create mode 100644 img/colors.png create mode 100644 img/image2binary.py create mode 100644 img/map.bin create mode 100644 img/player_back_0.bin create mode 100644 img/player_back_0.png create mode 100644 img/player_back_1.bin create mode 100644 img/player_back_1.png create mode 100644 img/player_back_2.bin create mode 100644 img/player_back_2.png create mode 100644 img/player_front_0.bin create mode 100644 img/player_front_0.png create mode 100644 img/player_front_1.bin create mode 100644 img/player_front_1.png create mode 100644 img/player_front_2.bin create mode 100644 img/player_front_2.png create mode 100644 img/player_left_0.bin create mode 100644 img/player_left_0.png create mode 100644 img/player_left_1.bin create mode 100644 img/player_left_1.png create mode 100644 img/player_left_2.bin create mode 100644 img/player_left_2.png create mode 100644 img/player_right_0.bin create mode 100644 img/player_right_0.png create mode 100644 img/player_right_1.bin create mode 100644 img/player_right_1.png create mode 100644 img/player_right_2.bin create mode 100644 img/player_right_2.png create mode 100644 img/tile.bin create mode 100644 img/tile.png create mode 100644 program3.asm diff --git a/.boot2.asm.swp b/.boot2.asm.swp new file mode 100644 index 0000000000000000000000000000000000000000..d31a7988497a8558252b6768e07880042c44b73f GIT binary patch literal 1024 zcmYc?$V<%2S1{7E)H7y40=M}X7>e@qOOS+cG81)^ampb}=x5~Trs^l^R}_>c>F4E_ zV)(q!#Iyl;`Ic>lYN|rxzvW>LnKEA{#Ku9u0xf5TGOkLeVt? E0P?6Ct^fc4 literal 0 HcmV?d00001 diff --git a/Makefile b/Makefile index 47a1203..1def271 100755 --- a/Makefile +++ b/Makefile @@ -3,24 +3,27 @@ all : image compile : nasm -f bin -o boot.bin boot.asm nasm -f bin -o program.bin program.asm - nasm -f bin -o program2.bin program2.asm + nasm -f bin -o beep.bin beep.asm +# nasm -f bin -o program2.bin program2.asm image : compile sudo dd if=/dev/zero of=disk.img bs=1024 count=720 + #cat boot.bin program.bin > exe.bin sudo dd if=boot.bin of=disk.img bs=512 count=1 conv=notrunc - sudo dd if=program.bin of=disk.img bs=512 seek=1 count=1 conv=notrunc - sudo dd if=program2.bin of=disk.img bs=512 seek=2 count=1 conv=notrunc - + sudo dd if=program.bin of=disk.img bs=512 seek=1 count=2 conv=notrunc + sudo dd if=beep.bin of=disk.img bs=512 seek=3 count=1 conv=notrunc flashusb : image sudo dd if=boot.bin of=/dev/sdb bs=512 count=1 - sudo dd if=program.bin of=/dev/sdb bs=512 seek=1 count=1 - sudo dd if=program2.bin of=/dev/sdb bs=512 seek=2 count=1 + sudo dd if=program.bin of=/dev/sdb bs=512 seek=1 count=2 + sudo dd if=beep.bin of=/dev/sdb bs=512 seek=3 count=1 +# sudo dd if=exe.bin of=/dev/sdb bs=512 count=4 + run : image - qemu-system-x86_64 disk.img + qemu-system-x86_64 disk.img -soundhw pcspk clean : rm *.img diff --git a/beep.asm b/beep.asm new file mode 100644 index 0000000..6ecf832 --- /dev/null +++ b/beep.asm @@ -0,0 +1,61 @@ +[org 0x2000] + +start: + mov [bootdev], dl + mov ah, 06h ; Scroll up function + xor al, al ; Clear entire screen + xor cx, cx ; Upper left corner CH=row, CL=column + mov dx, 184FH ; lower right corner DH=row, DL=column + mov bh, 4Fh ; YellowOnBlue + int 10H ; execute interrupt + + mov al, 182 ; meaning that we're about to load + out 43h, al ; prepare speaker for output + + mov ax, 2153 ; frequency countdown value is stored in ax. It is calculated by + out 42h, al ; Output low byte. + mov al, ah ; Output high byte. + out 42h, al + + in al, 61h + or al, 00000011b + out 61h, al ; Send the new value +; mov bx, 200 ; Pause for duration of note. + +mov al, 0 +mov ah, 86h +mov cx, 1 +mov dx, 200 +int 15h + +;.pause1: +; mov cx, 65535 +;.pause2: +; dec cx +; jne .pause2 +; dec bx +; jne .pause1 +; in al, 61h ; Turn off note (get value from +; ; port 61h). +; and al, 11111100b ; Reset bits 1 and 0. +; out 61h, al ; Send new value. +jmp exit + + +waitforkey: + mov ah, 0x00 + int 0x16 + cmp ah, 01h + je exit + jmp waitforkey + +exit: + in al, 61h ; Turn off note (get value from + ; port 61h). + and al, 11111100b ; Reset bits 1 and 0. + out 61h, al ; Send new value. + mov dl, [bootdev] + jmp 0x1000 + +bootdev db 0x80 ; Boot device number + diff --git a/beep.bin b/beep.bin new file mode 100644 index 0000000000000000000000000000000000000000..ba639101fd36dc257672b33968babbad58570d44 GIT binary patch literal 75 zcmV-R0JQ&z7D^zr1~9-e$+}M%w@=Lwu(swyxM>LHLWtnzLgZl#1Lk3{0JMg=0RXzl h0L>Na3$y^u7J&Q#bOP)3IrBj^AC literal 0 HcmV?d00001 diff --git a/boot.asm b/boot.asm index 4335b0c..52f32b7 100755 --- a/boot.asm +++ b/boot.asm @@ -1,5 +1,4 @@ [org 0x7c00] - [bits 16] pre: @@ -12,14 +11,12 @@ welcome: xor ax,ax ; We want a segment of 0 for DS for this question mov ds,ax ; Set AX to appropriate segment value for your situation mov es,ax ; In this case we'll default to ES=DS - mov bx,0x8000 ; Stack segment can be any usable memory + mov bx,0x1000 ; Stack segment can be any usable memory mov ss,bx ; This places it with the top of the stack @ 0x80000. mov sp,ax ; Set SP=0 so the bottom of stack will be @ 0x8FFFF cld ; Set the direction flag to be positive direction - - - mov ah, 01h ;make cursor invisible + mov ah, 01h ;make cursor invisible mov cx, 2607h int 10h @@ -82,17 +79,17 @@ load_it_all_1: mov bx, 0x1000 ; BX = 0x1000. ES:BX=0x0:0x1000 ; ES:BX = starting address to read sector(s) into mov ah, 02 ; Int 13h/AH=2 = Read Sectors From Drive - mov al, 01 ; Sectors to read = 1 - mov ch, 00 ; CH=Cylinder. Second sector of disk + mov al, 0x10 ; Sectors to read = 1 + mov ch, 00 ; CH=Cylinder. Second sector of disk ; is at Cylinder 0 not 1 - mov cl, 02 ; Sector to read = 2 + mov cl, 02 ; Sector to read = 2 mov dh, 00 ; Head to read = 0 - ; DL hasn't been destroyed by our bootloader code and still - ; contains boot drive # passed to our bootloader by the BIOS + mov dl, [bootdev] int 13h - jc wolf_error + + jc wolf_error popf jmp 0x0:0x1000 cli diff --git a/boot.bin b/boot.bin index 0e9d01b55995e4f9a6f978adc316bc2ce7e17399..e8c72668a38a36949ba770dce7b3ac6396bc3d76 100644 GIT binary patch delta 34 qcmZo*X ah = status, al = amount read +jc errorpart +jmp 0x8000 + + +errorpart: ;if stuff went wrong you end here so let's display a message +mov si, errormsg +mov bh, 0x00 ;page 0 +mov bl, 0x07 ;text attribute +mov ah, 0x0E ;tells BIOS to print char +.part: +lodsb +sub al, 0 +jz end +int 0x10 ;interrupt +jmp .part +end: +jmp $ + +errormsg db "Failed to load...",0 +times 510-($-$$) db 0 + ;Begin MBR Signature +db 0x55 ;byte 511 = 0x55 +db 0xAA ;byte 512 = 0xAA + + diff --git a/buffer.asm b/buffer.asm new file mode 100644 index 0000000..a8220e8 --- /dev/null +++ b/buffer.asm @@ -0,0 +1,101 @@ +%ifndef CODE_BUFFER + %define CODE_BUFFER + +;set's graphic mode +initGraphics: + mov ah, 0 ;set display mode + mov al, 13h ;13h = 320x200 + int 0x10 + ret + +;resets screen to full black +resetBuffer: + pusha + mov cx, 80*60/2 + ;xor ax, ax ;this will make the background black + mov ax, 0xC3C3 ;this paints the background green + mov di, [screenPos] + rep stosw + popa + ret + +;screen has size 320x200 but buffer only 80x60 +copyBufferOver: + pusha + push es + mov es, word [graphicMemory] + xor di, di + mov cx, 200 + .loop: + mov dx, cx + mov cx, 320/4 + .innerloop: + mov si, 320 + sub si, cx ;invert x-axis + mov bx, 200 + sub bx, dx ;invert y-axis + shr bx, 2 + imul bx, 80 + add si, bx + add si, [screenPos] + lodsb ;read from buffer (ds:si) + mov ah, al + stosw ;write 4 pixel row to graphic memory (es:di) + stosw + loop .innerloop + mov cx, dx + loop .loop + pop es + popa + ret + +;si = position of image, ax = xpos, bx = ypos +;a bit messy because of all the error checks to not draw out of screen +drawImage: + pusha + xor di, di + imul di, bx, 80 ;add offset y-position + add di, [screenPos] ;make it a pixel in buffer + ;add di, ax ;add offset x-position + mov bp, ax ;backup x-position offset + xor ax, ax + lodsb + mov cx, ax ;x-size + lodsb + mov dx, ax ;y-size + .for_y: + mov bx, di + add bx, cx ;bx = offsetOnScreen + xsize + sub bx, word [screenPos] ;skip if line is out of top border screen + jl .skip_x + sub bx, cx + sub bx, 80*60 + jge .skip_x ;skip if line is out of bottom border screen + xor bx, bx + .for_x: + mov al, byte [si+bx] + add bx, bp + test al, al ;skip 0bytes as transparent + jz .skip + cmp bx, 80 ;if pixel is right out of screen, skip it + jge .skip + cmp bx, 0 ;if pixel is left out of screen, skip it + jl .skip + mov byte [di+bx], al ;write byte to buffer + .skip: + sub bx, bp + inc bx + cmp bx, cx + jl .for_x + .skip_x: + add di, 80 ;next row within buffer + add si, cx ;next row within image + dec dx + jnz .for_y ;repeat for y-length + popa + ret + +graphicMemory dw 0xA000 +screenPos dw 0x0500 ;double buffer will be at this address + +%endif \ No newline at end of file diff --git a/disk.img b/disk.img index 0fb2cc8fe6dda49e4e892ab84dd342f119255975..b709635dbf1ffcd1990deb80aa1e650d4de0c7a1 100755 GIT binary patch delta 784 zcmZ8fO=uHA6n?wi#_f+a-C$}_+BtaW!P2Z&v6o6)B34TaCg{b3YnuJKcHkG zQqvX-tw;4Bdi2oL?Iw*7169$(ol+)@y&bR_uiYG9Zl=j zwC;Az*+YEU;PNdS#PZzQT=_Zp=iW`fbQaj)e9s8u&)vMuaM@r{SYY?3g?zv1*L^E& zpg0=Hw|M(ec4rT5#j$<)6Ex4}!Dw4zO@HaQU^!445UlS|x*%9zp(G2|26zr`iKC8- zt=5O_*yqOL$GiQ!Fx^oQbXI%KxT!~m(6=_(a&L<5NEd`z(VBGhl{(zZppK4>ur<0DgTdO$k;DlX8TjVOnf@M6nk@Z z;B0g_5=A{IIvgDd!>AO;Gzedp;u8ucGEp#6#}Tr^+#$`nS_D*S9@C<;`{vkpi_9yfs_n zCpCUm)r9%vm6&@&SZn9k?sqX#kcM=8Z-TiMrEiV^OeEur^?{E)Ld7Q7D1m{ zVW9X1%)NHg_P=KcYj3Vg2c3#ELt9jhFIpzY-N|tb1xry!;l}k8K8jrwJVgUVV?M_< HE%*Had;}ZH delta 706 zcmbtRO=uHA6n?Xbo9#;5EQC}%)In5oDNQbd2Mbl(LuvlZR@9SYT$3enSCSDuRI;#& ziZmcaL2u$!YHe4yjZh;2p@-ZBvGllgFM=3K9|~5b#&X3QdC zLM>~!R5t4r>jtJw)URr!qSaX3C}~x_qO;H$lfA6VaGq3&!E~-njH8s)uaJ^i(}@g+ z6$t8hpVdBJ?6ckHN6O+ml=$}vv;TR*CiY^m@fdqU;6eW=h(`T5->$?jeuypjYsVS> z4D$fr{7<>l*_o-6YGF`@zpb4Y@8m_qATWd&!VG&DxF2DV7zP+*H!tpeacuR1xP*QI DQ-=67 diff --git a/exe.bin b/exe.bin new file mode 100644 index 0000000000000000000000000000000000000000..437c7e60e208cda8778ad8f37d6945b9b4446855 GIT binary patch literal 8704 zcmeH_O=uHA6vtndlEy-7Hi1?>)Dc8_&@}N2giHk;2?+@{lC4!qkMIZ^DSf~HXPlT;|eIuuaF zU3!+W?f}z5!9lc{w!%=lkg*2Agi5;&B|B~Pz@vSlyc+=Q4pVsPUW2@_4h!V+iq~*G z{tRw_?_Wzl(^ealJQ>Ty<^$!*$rr9NcA9M!x4pM*ua3)VOpnV5>j>Xfk|>dyP?ea3 z6~T6*I2T-!;tna;Vr zd{g0UF-;!4p@;!(SS05c16Bxf+pgRXf9kc(Op>jh#?9HPh)>yH$d=rrO`^DN$gFXRH2VF1m5IxA#XZ@W)itKC5PeHmVluJm;i0Sa zTT#kTje1H z{p30YACa5*8cu){-~>1UPJk2O1ULasfD_;ZH~~(86W|0m0ZxDu-~>1UPJk2O1ULas NfD_;ZID!91;1^GGQb+&* literal 0 HcmV?d00001 diff --git a/img/box.bin b/img/box.bin new file mode 100644 index 0000000000000000000000000000000000000000..a5c15ae9b1d7c364b08807b304ead464802bb3ef GIT binary patch literal 83 scmd<&WDth}DJT$^Vg~^!DF{P~9l`*Lf*BxL5Cg0V$bhN_G9Z8f0P=qYvH$=8 literal 0 HcmV?d00001 diff --git a/img/box.png b/img/box.png new file mode 100644 index 0000000000000000000000000000000000000000..ae23d257d87f17e36cbedbee5db7c0025df702f5 GIT binary patch literal 982 zcmb_aJ#Q015S=7M`67}VWW<+ORE8pVC`j3gOpv3CAqgiEXQd!C z_KEyEK7#efz0<4M#+ucY#j%sg%M-&h=Wo6L1gh9vtTorR9ygzFY}YATt{}!dt8bgx znVU~veK>(+yeX>@IIiij1rAdyu7}snyLDJzPc{feg@Q2 zpCj#NdZ`UBvXgb~NjDlr%f^+J;}V%t6`lUOlq1 zLp?e=@;zA50Z(4ZsnfR4P(zfPRiW@5(oWB7nx^VKq4s)ka6rnCtEV=cN_%^I9-xES zU8~h1h?yjR;)cW`)2eKhZl*A@UVv$sf zt-w7nh(oXw$_r;3u~>m zS({S`iX@66l2S@(l=Fo96NY5GEU1JznCF1!17IK$n{_ z3(gOP9C2uIo-u^lFhs-!T$K%#2Yy6T2%d~FxHA{<-^B06NJpbsECQ8CLWEL*(WDev z11JT6{PW))-MqAfu%U-{ql$hU`~3~Y^=f5deP{pC&Xuvzv!^j_zTKt$`qpH9=*G*@ kU#(i<#omK8J2m`ngoeJK`&qyEbta#uy0}{Td^_3w3xx$wfdBvi literal 0 HcmV?d00001 diff --git a/img/coin_0.bin b/img/coin_0.bin new file mode 100644 index 0000000000000000000000000000000000000000..d1cea24c6a410a61d7608519aea2b2c31169b17d GIT binary patch literal 83 dcmd<&WWWNnfdC||r2_;Y79IwJ77!qt0RYZ;1$zJh literal 0 HcmV?d00001 diff --git a/img/coin_0.png b/img/coin_0.png new file mode 100644 index 0000000000000000000000000000000000000000..87d107736d6449bd641ee1377b0c0f7a669fd8d3 GIT binary patch literal 868 zcmb_aF{=|n5FSjU4Mh;RDtAdeQ(srM;X&Oz5kSATQ z*Q5-(CR#zMv|KI|f)=yK#bQAqGfBC^T!M&?Ad|{G)DqAPP!lQ0d?rAAkUGdrgs35e zK|%yL7dT4o>$>)EnguUVp9B(N9EC~}{XB@5N-0SI$HObeI0IMTu9JCWJhe+53wL}*05vi9QfACfD8{|!44AB5E+l+$+3W_5|di= z92yKx7zVr|#w_UXgd(x?=w}QeHw+SS4@YG~!;>D?8tw}FdIxKkFTzOzP!HExxIb#%+S|2-`?>j_xpRdxBh&C Xe!X_R4-f9WEq$lwmy<6~>i2&Ef&MXS literal 0 HcmV?d00001 diff --git a/img/coin_1.bin b/img/coin_1.bin new file mode 100644 index 0000000000000000000000000000000000000000..42173aaed2d82476fef56fd2476693419b75124c GIT binary patch literal 83 kcmd<&WIzCIAOP{Sb$|fGf-|&WB5($SmKH=YLOYZN0RO-Re*gdg literal 0 HcmV?d00001 diff --git a/img/coin_1.png b/img/coin_1.png new file mode 100644 index 0000000000000000000000000000000000000000..71bb349c72ffd2cb487e4e2259b89c7862319964 GIT binary patch literal 874 zcmb_azl#$=6ngey+8! z{&@1|K2eMOsn(Z z*e;U0z;B1Px{nv)PP5W|DmQsdy0=Kqi%`uf(GnpgNG3=|q4yFO`>x z2vJQ4z4!odDsYs_RaNESH1STL-U}qaI0)q=xTzN>rBW0Rj)PYSVFIucOfLZgGE5!# zrE`$}OE6cZM3{~wbWwF>?&MsCU{p$3mL%Pp>N4Ym^Am<-yezPU*$&w9z%rXYTWmQQ zuw!GnZ@I7lm=HSW*qMTj;Y@-KBHL%fu7?FtVGS2-ivoOWrAvl;u;2m`Qxh47;@&ZX zs1lP}^z0c7P8bHfEXFM8UkC-_!l9orgxoMl#2p-!4fXbVSW^L4e-6#gJh5(ykwM2v8Q)pfIlkiq7jlCTMA93(hbq*&16I$xP?f}LH!-b=Za zjm4H*-hp82VRKhrX=Um2o5P>rvODwM_rC9YZ+7=%yr>WMAMOJ7Z%IYN$)65DG-2TI;%o4qLQ!!NK!`LkeFOSt{bk;$`eb+_89WB^gT) z=jGT-hF}?r* literal 0 HcmV?d00001 diff --git a/img/colors.png b/img/colors.png new file mode 100644 index 0000000000000000000000000000000000000000..e4eda1d9a1580b0b7a69c157a8e8112ac8beea9b GIT binary patch literal 563 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33 zJwt=FTwDi$rY`n$aSXBWFTJcQw%9=6z(*Oza8DJz!X9P5Zf+x?nbH@Ozp$-+!Z!89 zH;&S^Z*%kwurvLseCE%+L9?XR27#>YM9Bi){Q?fkqoj<!}$lK`R^pGGno(3X0Dda?dY;jiDm7qGy5k*b5xXCO7{wEQD9IF5SVz? zh2z#GV+p~D6SU*z2e`TgWV*O8bqXmRn-r3v(%<3n;JI3W>#;L+C#;kc9oLBkq|Ey1 znlr-&$eCB-c&KOPtce>MmT+qrowaFtm}#?hTeaWnGXdk2!PC{xWt~$(6979+;pzYY literal 0 HcmV?d00001 diff --git a/img/image2binary.py b/img/image2binary.py new file mode 100644 index 0000000..6416072 --- /dev/null +++ b/img/image2binary.py @@ -0,0 +1,47 @@ +from PIL import Image #Import Image from Pillow +import sys + +palleteFile = "colors.png" #pallete the BIOS uses +if len(sys.argv) < 2: + convertFile = "fox.png" #image to turn into a binary + outputFile = "fox.bin" #name of output file +elif len(sys.argv) < 3: + convertFile = sys.argv[1] + outputFile = sys.argv[1]+".bin" +elif len(sys.argv) >= 3: + convertFile = sys.argv[1] + outputFile = sys.argv[2] + +pal = Image.open(palleteFile).convert('RGB') +pallete = pal.load() #load pixels of the pallete +image = Image.open(convertFile).convert('RGB') +pixels = image.load() #load pixels of the image + +binary = open(outputFile, "wb") #open/create binary file + +list = [] #create a list for the pallete +for y in range(pal.height): + for x in range(pal.width): + list.append(pallete[x,y]) #save the pallete into an array + +binary.write(bytearray([image.width&0xFF,image.height&0xFF])) #write width and height as the first two bytes +data = [] +print(image.height) +print(image.width) +for y in range(image.height): + for x in range(image.width): + difference = 0xFFFFFFF #init difference with a high value + choice = 0 #the index of the color nearest to the original pixel color + index = 0 #current index within the pallete array + #print sum([(pixels[x,y][i])**2 for i in range(3)]) + for c in list: + dif = sum([(pixels[x,y][i] - c[i])**2 for i in range(3)]) #calculate difference for RGB values + if dif < difference: + difference = dif + choice = index + index += 1 + data = bytearray([choice&0xFF]) + print("[%d,%d] %d = %d (%d)" % (x,y,choice, difference, len(data))) + binary.write(data) #write nearest pallete index into binary file +binary.close() # close file handle +print("Done.") \ No newline at end of file diff --git a/img/map.bin b/img/map.bin new file mode 100644 index 0000000..3cad53d --- /dev/null +++ b/img/map.bin @@ -0,0 +1 @@ +00000000000000000000000000000000000000000000000000000000000000000 00000000000 X 000000000000000000000 000000000000 0000000000000000 000000000000000000000 000000000000 0000000000000000 000000000000000000000 000000000000 0000000000000000 000000000000000000 00000000 0000000000000000 000000000000000000 00000000 0000000000000000 000000000 X 00000000 0000000000000000 000000000 00000000 00000 0000000000000000 00000000 00000 0000000000000000 0000000000000000000000 X 00000000000000 0000000000000000 0000000000000000000000 00000000000000 0000000000000000 0000000000000000000000 00000000000000 00000 00000 00000000000000 00000 P X 00000 00000 000000000 X 00000 0000000000000000 0000000000000000 0000000000000000000000 0000000000000000 0000000000000000 000000 0000000000000000 000000000 000000 X 0000000000000000 X 000000 00000 000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file diff --git a/img/player_back_0.bin b/img/player_back_0.bin new file mode 100644 index 0000000000000000000000000000000000000000..d549c076220f40eb1ea690c291fd0feb9ca55c0a GIT binary patch literal 110 zcmXYou?@g55CUmj1bHd1kwsV_vOIQxeab4^Gpl+Nv9+NDw6f7Y0NEZp4k(Gr>=ANM`Om_ndRjo8*p}kH&L{b3`;= zJzH78^ANsc2S;&VUAc6ZXq3#{;>_Byg?Gj@ukP974`pvv`st6GH(ocEipAn!F!;W4 zMTAmGrIYr0J?Z+k__QxxM0QdyT})a)IwEP`OIy-TTS(F!FRgwGFtuQ|y%*ns%Z}{s z?)omIm;fg)WW`F$r|3b-#3Eq$Hc7kdB}o$Tp3r;Q+}tE#(8W^=N}*=6=~1*rtZg(J z1TvG$E>m~LIc-5Eadi_rgJpmcOUBh}4v01`Hm>FzQ9>w(t)EnupnY?Ia* z1f$4BQADngP!eT0;rxV8vB$Y^ol_u&f}=8s5I2WnnK{Dl){-gkG~{-H-FD&i9Xgr_2b^CL1aPH@ct@k6{jX&RBJ-L7R_sFS_C$Fvj+OK5!sx$MIr)T1o Ezc<%FHUIzs literal 0 HcmV?d00001 diff --git a/img/player_back_1.bin b/img/player_back_1.bin new file mode 100644 index 0000000000000000000000000000000000000000..ba7afab749bc0372d6931f934a5290d5ab93fe5a GIT binary patch literal 110 zcmd<&VJK$+g7R`8;sSzlFo4kz4g&*Nn2QUj4y1+)qy@wRYh~zYYXcd<&;evbff$Z$ PP!Wa}R#uPz2!Lb&Wm^@2 literal 0 HcmV?d00001 diff --git a/img/player_back_1.png b/img/player_back_1.png new file mode 100644 index 0000000000000000000000000000000000000000..0ad676c514204d1672e3db3ca6f969727570bbc2 GIT binary patch literal 908 zcmb_aL2DCX5FJ|-TP)4R7JA7iEtrF_d$9BaDH(0c8j-S=>X+l*3>9HO3-;m{DpGnf zilp5p2btF%CT$>H)vWI|*Q}c>X?EbX-Om7K4$Rzp^VZHU zjGa)?INONDN~Gi^2FJq7Iaddm2-1r~K!&LWKe86me+_aaN`!PIu8gUTicQuQ5R4*; zqKKrNQW_OF;rxVS3+)#yq;gEwc1V0F*Ool74;1Cj%5*dr(z_9=^B_<89vtkgO5C*(Lj4aq63OVA? zVxKXD-Y`hSB^;FvRR(%kQwW@lF*q}q@R!8z#&E}Aa&i(?nIwcMl^8=x;Wa3wgrfNT zw`*bj+gX@JwZ-eJPrl9`eH!~1o?o~#(V2O?zkB8T>zYo@-g~g!9~pWsGq={FSMSWu y)upNV&-tHoZ^!GqJ73n{U!4Da+C6?xp#OAJy$^MZVh7^5TaZ$>v||8#~ni literal 0 HcmV?d00001 diff --git a/img/player_back_2.bin b/img/player_back_2.bin new file mode 100644 index 0000000000000000000000000000000000000000..9e34896e45dea18ce63cf894336f2b8729a871e6 GIT binary patch literal 110 zcmXYp!41GL2m}4$5!9u!MiyZM)UkWG;lUjUvmRB6Dp*MY8%=jWY{}W2?I!*X%KYxQ0XTWI{gvWLa9rseDP4-n?WcJNI?(sg(?(J zM#Pha^tc64Z+nb-X^Qorr_drPC=w6}D2TW5ZSYTUNp@%6y!YmPn>>n_qmkjUVImq? zyu7f2=McW92M2K9+PwLMXn^9S)$-$sm4i60-`RH;w{?F@yV;Ki_ukdk$H&Kez25id zw^S+9OxxM<@v(M%Q+?J|uc~{Q*A6BPAZ^vG>$Ry_yQ!qvp4Ub<1DH85o8GH$!(~rf zt(NaViV1M?N=}_Ne1;yRT&xO)Z<01UUeh#H?+Lxvot+(023mEf@)wx=& zMj$gue#KRZMXUpvRH|_zF_r;J9mP_u2oM`f5=%vdC?%A!#13Fp;3$brlElKP5?g_~ zFAxV~CzLnNR%5XeDS3&(vG8)vRRAV}^x_bZVQRsTtcCPngItLcAsvY;Vrrv&leIYn zqe!ACA}OYnMmbJ6KOrRJWq~Ek!3+mH6EK@84)DmE8MbT!o(eb&05GAn*0MDr8^bvX zI*5WPHf&3{p$Y@TAqQayeh^5J43}WRAtWXxG8V(WV-8|UOd4Qk$sjl(40yR1S+GA8 za>SvIVUUOmI4T<|_4Tl(5I7lQaAq#xFNxoc;f}%R=qRcpNeELaFou-Et6xe1 zMgIA3*ZjtpQ!pzpF3hgpJv{s2XozM9=RZ!qerC(p+pl&f*OyjjFa6;&+iy;uJ8^!j zwRUaf{m&OyFH9fY|9WHX>BOhso3}T5pLee`e+@))({CSsJ3PwMEtZ!TUd|<(e*unA BJ_i5* literal 0 HcmV?d00001 diff --git a/img/player_front_0.bin b/img/player_front_0.bin new file mode 100644 index 0000000000000000000000000000000000000000..550b5f23635766397e6e5da36ee31f3fd860dfb0 GIT binary patch literal 110 zcmXYo!3n@X2n6?Yk1Tmv!1ZDqHnI%_xw4}s3eGU#bwdLBNbJ$iGE5)=ZlmoIh1K?l WM}!xF0;6Z(h*5}URsiNT0)Yxy)=6%z|?}-@?LxgE^S#` zTk~B=F#%3q$cmMwPtk*viABKhEs|E(OOhnwJ)!rqva&+Lpo^y_ltPV0!=q@4SX-~x z31lXhU8d%YbJ~JT;%X*#2Fm~?mW-=a9T06?Y+ThjqJ&TyXDq;)gQJUe9LE|?Riho$ zeSxzuwvMvK>Y8!dMMB;ga5TKEwN-$zLwaWskYTF9kFCOE(&Yf7wH1w0XO7yw{GskLUULRN}1 z5_Av+6RcPlaYGdbibD><5d0u;1yWpu1&5HRgh*)&`;HliDKSZaokfM-zxAE>D-w&E5Gr{`temYB-qV((>Nr#i2iMKOJAb`|xQc-&-6gUwY3k zPVCPe*g1Or^}E{--faABoIG3^zp}kOx99hhi!(bLXI@s${uuan=+u#^`PFuoae8vL J{OWwXunP-}KUV+% literal 0 HcmV?d00001 diff --git a/img/player_front_1.bin b/img/player_front_1.bin new file mode 100644 index 0000000000000000000000000000000000000000..bbbc7320f0b118fc1e7f6591cc8abc19b5be3776 GIT binary patch literal 110 zcmXX-!3_X02;$Snk-i+DySRpnxPj@|CvDLHf$&Wv8kzkR@~PYjNPx>|t4)UWY2p## Unqqrh-BlsyRX2f;ajGUYKcNB-brDJ>l}@_1wL zmn~_x+rA4aCcw!HS+UacDSD7{u?QGGBgwj6k|YuD3B8w%jSUh8T|Bj*6lyk`9z`Z% zZKKg3keOV5nYuI1X$vxmtDD#vECZBSGOk{8K(ukOaW&_N5<+R5u>k81jxN@59BVk$ zjCN4>1&9sp33+G0(eSd?)&Ry1>77MDhN%WW(i+l#4RXaogmmO=2~!>A zo3zd$7)36MB66jKk|@Us=O=_@yezOBb1=yPPX^3tf&)DAW|B3lfF}YD0{~1Ywbrav z$Vzcef)1i!f)(pBZm7aQamYa!f*%B~M2gF>;1Cj(5Gjpe-!TUQBC{>Hi4EBAP|vb(tS>DQYV%TIQ{t^d3_b$W%4oE=|o-#vaOk64|V KtGv1pul@yvt3d1k literal 0 HcmV?d00001 diff --git a/img/player_front_2.bin b/img/player_front_2.bin new file mode 100644 index 0000000000000000000000000000000000000000..97930f738df1a58d22dcc5344dc93c87331bc4ed GIT binary patch literal 110 zcmd<&VJI(W0D^KL%>@GGP#VZ$01JQ_azb1}a$G=VQ9?in(%~2t73B!h$lT*0xM5TE<#C|oE7-S|QkOHnaW z=|&}8&c=ee7*H@MNLxQpa1%sHK_~&yBDfTi6Ff=1Z0?6@FQy>{nsE@qC`kX;)2LT?x(;sTD!hDsehtSJOe#u%KL3;0XocVoC?FgQ4fsz?&TlnRU?rSR&M zQb3V^{@XRa@O2N&PE1dX&0YF*>fNIrI^Es%;qISD}TFtGah z(D>`4JvR>j{KR literal 0 HcmV?d00001 diff --git a/img/player_left_0.bin b/img/player_left_0.bin new file mode 100644 index 0000000000000000000000000000000000000000..4599e26617a2b15631267cf02297cc7e280bd40a GIT binary patch literal 110 zcmd<&VSs~jE-tQehVpU-AkD?qRu1Ar80AqyazGYPWt32qBbdPu6$POg7&FFFq{l6&U@v!ejEG=F3Il9H{bWo_cnRt7L&1&@ev{# zt6i!t;W>=&=#e4Z*H&*lBN`&Nusr|t?_?_(|-Q@;r;i`TN4u#`}_O9 zUfxutTyyQ_dwYA@3mpx4UxTV{bHlzDQ}s0$G5Bz003A<77)6XyXo1dfv0G)*m>>dp$( z1A%xLd!eH7w&BD|q7=k|W8vk!uLDd4>BS=;!_#~j5m_)#PkGCT zAx|7z>@$YY8wQEEgrl;d$$=i$6ayz?49?6Y{3Y?bG2AgIm&>RsBr!~>#28WruR$p# z6vgMiU2}K7ABNdnt$K0!-skfl-i^`m(YcQ=u70aMAKo~9d1~WRv%m7-VCCG8+1-W5 yqu0y+PxZJIO_eUpwvR4v6xnL?i`BQY>FQrIzdK|A literal 0 HcmV?d00001 diff --git a/img/player_left_1.bin b/img/player_left_1.bin new file mode 100644 index 0000000000000000000000000000000000000000..dd647fce303b792a247884e938abf408d3eecda0 GIT binary patch literal 110 zcmXYp!41GL2m}4eqo}V8&|O%AMZ7?SGIm@DpF7zW&x<+|pqV9QqEYr!rY7bm(=ujw U2_l-n-u(l4WuzyJUM literal 0 HcmV?d00001 diff --git a/img/player_left_1.png b/img/player_left_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3cf3f9f960e0c4321c203cc694e3f25b2b61e95b GIT binary patch literal 907 zcmb_aL2DCX5FIIkN-L?Cf|q<)(ICPuLg|MGJJ!~Px@wxfw2Z!fA#BuF<%Z)wN){^$JAB(r%RIiPWj&5#l zet&XRl`_q=oprli?f8cJtfyX8o0-=RCUqcf)vV{Wp;^13q*>Ezy_W&Z9GDI7)wki& z)b;gs-+>ep;N+E@I<5N*JxIA&6%5}XZFIb*X{z26daujN%cKmtda6UIRIAlIiiWCl z)oPVMW|I7hD-w%X2QsNt;zVLB1C%<7rBW6kHkKrovItR1C}W8oz>2_85}PE6g;P1U z0(D;?4#rL>Z=9{fVkJ`Y5`$ym<(w-6Oa$r0At1xlf*)B6>AwcK5+y=95?933M)@Xd za|lL}L{UUiOeu|WoN#_ZNXE+oOPGTR4tOG9Hsc)Nkv9`;*#tZua2Nn!LTRmKYeF`L za}snA1>Ux$N}=g&S*_Fb8DpI^OuwlaKi&2R7R&K_I2 zTRr%)aOA-8jY9Ln(Z`Fw-+z7k=;PM#>Y=UDx7(L~{oL{A&WZaQ+b>#qyqW3QsnyA3 F;V)nzyJUM literal 0 HcmV?d00001 diff --git a/img/player_left_2.png b/img/player_left_2.png new file mode 100644 index 0000000000000000000000000000000000000000..3cf3f9f960e0c4321c203cc694e3f25b2b61e95b GIT binary patch literal 907 zcmb_aL2DCX5FIIkN-L?Cf|q<)(ICPuLg|MGJJ!~Px@wxfw2Z!fA#BuF<%Z)wN){^$JAB(r%RIiPWj&5#l zet&XRl`_q=oprli?f8cJtfyX8o0-=RCUqcf)vV{Wp;^13q*>Ezy_W&Z9GDI7)wki& z)b;gs-+>ep;N+E@I<5N*JxIA&6%5}XZFIb*X{z26daujN%cKmtda6UIRIAlIiiWCl z)oPVMW|I7hD-w%X2QsNt;zVLB1C%<7rBW6kHkKrovItR1C}W8oz>2_85}PE6g;P1U z0(D;?4#rL>Z=9{fVkJ`Y5`$ym<(w-6Oa$r0At1xlf*)B6>AwcK5+y=95?933M)@Xd za|lL}L{UUiOeu|WoN#_ZNXE+oOPGTR4tOG9Hsc)Nkv9`;*#tZua2Nn!LTRmKYeF`L za}snA1>Ux$N}=g&S*_Fb8DpI^OuwlaKi&2R7R&K_I2 zTRr%)aOA-8jY9Ln(Z`Fw-+z7k=;PM#>Y=UDx7(L~{oL{A&WZaQ+b>#qyqW3QsnyA3 F;V)n4f25FQ9Z3<(@I2WjqM3QsL|3qxLaqeO#tw-BB$bUV$f6!c?n3y;@Ir+J} zs!F-$+RKlRkF_5<8uEb#RXxmu_AzM#>8a*}pdHP79VN{VgSH1bz}$n`2|+^-E{EFf zc0(UhOn_5R^6Ir6a`Ye-VpT9ghqTiVnq`@WK&L8YvetGB1&btR!I^R~Ge)?Vhv%b4o8(+KlX0*sQKf5^d{#v^A7lnp7jsO4v literal 0 HcmV?d00001 diff --git a/img/player_right_1.bin b/img/player_right_1.bin new file mode 100644 index 0000000000000000000000000000000000000000..5910571e9edb1813cf09dc83a9cc7a336b93f1a6 GIT binary patch literal 110 zcmXZU!41GL2m?SqdDQAF19TVGU=c4+MT}j?DIXt};JSkh56K2V6-@zZom*O;SptzY VYabBhj9AMLg#M8|j^2?6jt_X;4X^+J literal 0 HcmV?d00001 diff --git a/img/player_right_1.png b/img/player_right_1.png new file mode 100644 index 0000000000000000000000000000000000000000..022673c4e2c39c253b750b65b50f4e4bcfbb86d2 GIT binary patch literal 908 zcmb_a!Dl~P_y;RW1`D`P=;sHN7;3w2Rk zHFm3zE(8amf*WVyVoE`pqPPxXNx)4&q)<1myq*bufZOZG3rI&K?R&{2?PNld9(if?Q-G-jGxJ`22QEj_ zZnu3GQcQr87qVidSX>?|t;Cxihn7b6Sy zhmI_9sIgBeLa!Jk;sTD!ipm2$tSJOeN-3O~3;0XocVoC?FflQKsz@$`DHRw)O5imp zT>(Y@`ES?k`uB4%ix#RkRv&+zK7KcT5RS|)-+CQioVqi4vb?#nKYlRvG21w-u6>!m zO7C~Cv|kOGH`hN+-Tr;{=hDga?)uKzl~P_y;RW1`D`P=;sHN7;3w2Rk zHFm3zE(8amf*WVyVoE`pqPPxXNx)4&q)<1myq*bufZOZG3rI&K?R&{2?PNld9(if?Q-G-jGxJ`22QEj_ zZnu3GQcQr87qVidSX>?|t;Cxihn7b6Sy zhmI_9sIgBeLa!Jk;sTD!ipm2$tSJOeN-3O~3;0XocVoC?FflQKsz@$`DHRw)O5imp zT>(Y@`ES?k`uB4%ix#RkRv&+zK7KcT5RS|)-+CQioVqi4vb?#nKYlRvG21w-u6>!m zO7C~Cv|kOGH`hN+-Tr;{=hDga?)uKzz5Eh7nG9e5Y=OBy$*8ySx0Kt_7SO5S3 literal 0 HcmV?d00001 diff --git a/img/tile.png b/img/tile.png new file mode 100644 index 0000000000000000000000000000000000000000..6d6c46ff72a8e1127260a1df24f8ab0ab0811cbc GIT binary patch literal 861 zcmb_av1(L76g?1>5D0D;W3y9kHxDc_U9OV&5|A)TV77c=G z)hjoJg?5V|n{s;v%j=oNPw=rj@7#0GIrq-8AL2#3zxQMh!2bE!$!orM>vwmD=dbS< zUw|FNmzSq3&GN>ISz7Vj6r#1|ifmPEX@)|6RqpTaZJh_UHkQq7Su%yi7GzdtWs_~N zvKkClmf05cTPcakA!p0XDoeY&yUS}@*&&Z?NS17o3u}t1*^G)jz=n0UzV9t(u+DaK za|08~En`8a;p*xt6Aauv&F6DaEYSMInMT!+D2C}Qb{aX1RG$!aHdQhqY8Q2?3iKe1 z8WYKxGEuwGbzNZ6GzO)6YtY2tq^Ly-v#3E^L)J)5U{*?LO0rXKuZar^Lj(0~2(UR8w#mVRA-TS|H(k}S` literal 0 HcmV?d00001 diff --git a/program.asm b/program.asm index 63b5f49..87e37a5 100755 --- a/program.asm +++ b/program.asm @@ -1,6 +1,7 @@ [org 0x1000] start: + mov [bootdev], dl mov ah, 01h ;make cursor invisible mov cx, 2607h int 10h @@ -14,36 +15,45 @@ start: mov ah, 06h ;draw rect on background mov cx, 0101h - mov dx, 164Dh + mov dx, 124Dh mov bh, 3Eh int 10h mov ah, 06h ;draw shadow - mov cx, 1702h - mov dx, 174Eh + mov cx, 1302h + mov dx, 134Eh mov bh, 0Eh int 10h mov ah, 06h ;draw shadow mov cx, 024Eh - mov dx, 174Eh + mov dx, 134Eh mov bh, 0Eh int 10h + ; menu bottom + mov ah, 06h ;draw rect on background + mov cx, 1700h + mov dx, 184Fh + mov bh, 3Fh + int 10h + mov ah, 02h ;sets cursor to top to write mov bh, 0h - mov dh, 1h - mov dl, 1h + mov dh, 17h + mov dl, 2h int 10h + mov si, menuhelp + call print - mov al, 0xC9 ;draw border - mov bl, 0x03 - mov ah,0x0e - int 10h - mov al, 0xCD - mov bl, 0x03 - mov ah,0x0e - int 10h + mov si, menuselect + call print + + mov si, menuexit + call print + + mov si, menuenter + call print mov ah, 02h ;sets cursor to top to write mov bh, 0h @@ -111,6 +121,8 @@ waitforkey: je .up cmp ah, 11h je .down + cmp ah, 1Ch + je loadproject jmp waitforkey .up @@ -141,29 +153,90 @@ waitforkey: jmp print_projects + + +loadproject: + + +mov bx, [currentselection] + + pushf + stc + + mov ah,00 + int 13h + +.read_sector: + mov ax, 0x0 + mov es, ax ; ES = 0 + mov bx, 0x2000 ; BX = 0x1000. ES:BX=0x0:0x1000 + ; ES:BX = starting address to read sector(s) in$ + mov ah, 02 ; Int 13h/AH=2 = Read Sectors From Drive; + mov al, 0x10 ; Sectors to read = 1 + mov ch, 00 ; CH=Cylinder. Second sector of disk + ; is at Cylinder 0 not 1 + mov cl, 04 ; Sector to read = 2 + mov dh, 00 ; Head to read = 0 + + mov dl, [bootdev] + int 13h + + + jc wolf_error + popf + jmp 0x0:0x2000 + cli + hlt + + +wolf_error: + mov si, wolf_error_msg + call print + mov si, wolf_error_msg1 + call print + mov ah,00 + int 16h + xor ax,ax + int 19h + + + print: lodsb or al,al jz exit - ;mov bl, 0x03 mov ah,0x0e int 10h jmp print exit: ret +msg1 db "ARTIST / TITLE",0 -msg1 db " X P U B",0x0A,0 -msg2 db " NOT MY DEFAULT",0x0D,0x0A,0 - -project1 db "Alex / Poetic Software", 0x0A,0 -project2 db "Tash / Silence Making", 0x0A,0 -project3 db "Alice / F00d", 0x0A,0 -project4 db "Joca / The ghost in the speaker", 0x0A,0 -project5 db "Angeliki / Voices", 0x0A,0 -project6 db "Zalan / Phantasmagoria", 0x0A,0 +project1 db "Name / Exampletitle of this",0 +project2 db "Name2 / Silence and more",0 +project3 db "Name3 / C00l, new title and more", 0 +project4 db "Name4 / Everyon", 0 +project5 db "Name5 / Voices and more", 0 +project6 db "Name6 / Examples of titles", 0 projects dq project1, project2, project3, project4, project5, project6 +menuhelp db "F1 Help", 0 +menuselect db " W/S Select Item",0 +menuexit db 0x0D,0x0A," ESC Exit", 0 +menuenter db " Enter publication",0 + +wolf_error_msg db 'Program not found!',0x0D,0x0A,0 +wolf_error_msg1 db 'Press any key to restart..',0 + currentselection dw 0 storebx dw 0 + +bootdev db 0x80 ; Boot device number + +%assign usedMemory ($-$$) +%assign usableMemory (512*16) +%warning [usedMemory/usableMemory] Bytes used +times (512*16)-($-$$) db 0 ;kernel must have size multiple of 512 so let's pad it to the correct size + diff --git a/program.bin b/program.bin index fc414f450a5d40ea55b960223f63f36050c4cf59..601ab6295402faa937c04f311e82caabf0ce9695 100644 GIT binary patch literal 8192 zcmeH@&ubGw6vtmeh-i#8MTy*xb%^OVKKR_!^A3{w&lem=w5t7@ z{mdkfU`zYf2F)j$g# z2wwfDE3h?KLb&uE~u$~ZG^2R56{e7>b9uJxVmb10KbTOOCWa&K3rm|;~kj@pE z5Xn2aVo70K<_e=)f$|%2*{dB9#f+>lHP2{HU7xDDUsB~vr=`j@Mb78AEEc|?YuEK$k*XS}1+Aj4 z9GILCNmh23uhN^WO1Vab<~g0u&3T&|!-eri0!RP}AOR$R1dsp{Kmter2_OL^fCP{L b5-h zc68-Xf)F^|9t6>7+|nWh3HIJ~(SP~=zwi6rN49Tq_eY z=Iq@SZe_zpz}~a2zujekJFdx@!Rzj=Tc_!@`KvlhJWY=od~^%FQ(&`~apJWxcO{%e z-UZ!Nd*+yR{wB=4R0F#AxPRkmP8x@1(E2BOiv{YmUr+SXKc&lS{&s;vWyR44CWL}q&!?vcE~=eU>=A_EmD6)Dq}g1VFr~X zxxnfYr5H@b?@{%Th_Ar8R}VRC%z8%1EZ1 gD;P79Tgqja#VBl%u!bU0pRYYx&QzG diff --git a/program3.asm b/program3.asm new file mode 100644 index 0000000..a0477cc --- /dev/null +++ b/program3.asm @@ -0,0 +1,531 @@ +org 0x8000 +bits 16 + +;precompiler constant +%define entityArraySize 16 +;Let's begin by going into graphic mode +call initGraphics + +;Now let's register some custom interrupt handlers +call registerInterruptHandlers + +;init map +call initMap + +;Main game loop +gameLoop: + call resetBuffer ;reset screen to draw on empty canvas + + ;MODULAR DRAWING CODE + mov di, entityArray + add di, 2 ;skip drawing player + .nextEntity: + cmp [di], word 0 + je .skip + pusha + mov cx, [player+2] ;player x to draw relative + mov dx, [player+4] ;player z to draw relative + mov di, [di] + call drawEntity + popa + .skip: + add di, 2 + cmp di, entityArray+((entityArraySize-1)*2) ;confirm that di is still pointing into the entityArray + jl .nextEntity + + call drawMap + + ; PLAYER DRAWING CODE + mov si, [player] ;get animation + mov ax, [player+6] ;get index within animation + xor dx,dx + div word [si+2] ; animation time % time of full animation + mov ax, dx + xor dx, dx + div word [si] ; (animation time % time of full animation) / time of one frame + add ax, ax ; index*2 because image address is a word + + add si, 4 ;skip first two words of structure + add si, ax ;add the offset to the frame + mov si, [si] ;set the image parameter to the image referenced in the frame + + mov ax, 80/2 - 9/2 - 1 ;center player image + mov bx, 50/2 - 12/2 - 1 ;center player image + call drawImage + ; END OF PLAYER DRAWING CODE + + call copyBufferOver ;draw frame to screen + + call gameControls ;handle control logic + + call synchronize ;synchronize emulator and real application through delaying + +jmp gameLoop + + +jmp $ + +;di = entity cx,dx = xpos,zpos +drawEntity: + push dx + inc word [di+6] + mov ax, [di+6] ;get index within animation + mov si, [di] + xor dx,dx + div word [si+2] ; animation time % time of full animation + mov ax, dx + xor dx, dx + div word [si] ; (animation time % time of full animation) / time of one frame + add ax, ax ; index*2 because image address is a word + + add si, 4 ;skip first two words of structure + add si, ax ;add the offset to the frame + mov si, [si] ;set the image parameter to the image referenced in the frame + pop dx + + ;mov si, word [di] ;get animation + ;mov si, word [si+4] ;get first frame of animation + + mov ax, word [di+2] ;get entity x + sub ax, cx ;subtract the position of the player from the x position + add ax, 80/2 - 9/2 - 1 ;relative to screen image drawing code for x position + mov bx, word [di+4] ;get entity y + sub bx, dx ;subtract the position of the player from the z position + add bx, 50/2 - 12/2 - 1 ;relative to screen image drawing code for z position + call drawImage ;draw image to buffer + ret + +;di = entity, cx = new_xpos, dx = new_zpos, bp = new animation +;fixed for modular entity system +checkForCollision: + pusha ;save current state + mov si, entityArray ;set si to entityArray + .whileLoop: + mov bx, word [si] ;read entityArray entry + test bx, bx ;if entry is zero => end of array + jz .whileSkip + cmp bx, di ;if entity is equal to di => next entity to not collide with it self + jz .whileSkip + + mov ax, word [bx+2] ;ax = entity x + sub ax, 8 ;subtract 8 because of hitbox + cmp ax, cx ; (entityX-8 <= playerX) + jg .whileSkip + + mov ax, word [bx+2] ;ax = entity x + add ax, 8 ;add 8 because of hitbox + cmp ax, cx ; (entityX+8 > playerX) + jle .whileSkip + + mov ax, word [bx+4] ;ax = entity z + sub ax, 10 ;subtract 10 because of hitbox + cmp ax, dx ; (entityZ-10 <= playerZ) + jg .whileSkip + + mov ax, word [bx+4] ;ax = entity z + add ax, 9 ;subtract 9 because of hitbox + cmp ax, dx ; (entityZ+9 > playerZ) + jle .whileSkip + + ;if we reach this point => actual collision + ;mov cx, [di+2] ;set new x pos to current x pos => no movement + ;mov dx, [di+4] ;set new z pos to current z pos => no movement + + mov word [si], 0 + inc word [coinFound] + + ;ding ding count found + + jmp .noMapCollision + .whileSkip: + add si, 2 ;set si to the next entry in the entityArray + cmp si, entityArray+((entityArraySize-1)*2) + jl .whileLoop + .whileEnd + + pusha + mov si, cx + mov bx, dx + call collideMap + popa + jnc .noMapCollision + ;if we reach this point => actual collision + mov cx, [di+2] ;set new x pos to current x pos => no movement + mov dx, [di+4] ;set new z pos to current z pos => no movement + .noMapCollision: + mov byte [canWalk], 1 + mov word [di] ,bp ;update the animation in use + mov word [di+2] ,cx ;update x pos + mov word [di+4] ,dx ;update y pos + popa ;reload old register state + ret + +canWalk db 0 +gameControls: + mov byte [canWalk], 0 + mov di, player ;select the player as the main entity for "checkForCollision" + mov al, byte [pressA] + add al, byte [pressD] + cmp al, 0 + jz .nokeyad + mov cx, word [player_PosX] ;set cx to player x + mov dx, word [player_PosZ] ;set dx to player z + mov bp, [player] ;set bp to current animation + cmp byte [pressD], 1 ;try to move x+1 if 'd' is pressed and set animation accordingly, test other cases otherwise + jne .nd + inc cx + mov bp, playerImg_right + .nd: + cmp byte [pressA], 1 ;try to move x-1 if 'a' is pressed and set animation accordingly, test other cases otherwise + jne .na + dec cx + mov bp, playerImg_left + .na: + call checkForCollision ;check if player would collide on new position, if not change position to new position + .nokeyad: + mov al, byte [pressW] + add al, byte [pressS] + cmp al, 0 + jz .nokeyws + mov cx, word [player_PosX] ;set cx to player x + mov dx, word [player_PosZ] ;set dx to player z + mov bp, [player] ;set bp to current animation + cmp byte [pressW], 1 ;try to move z-1 if 'w' is pressed and set animation accordingly, test other cases otherwise + jne .nw + dec dx + mov bp, playerImg_back + .nw: + cmp byte [pressS], 1 ;try to move z+1 if 's' is pressed and set animation accordingly, test other cases otherwise + jne .ns + inc dx + mov bp, playerImg_front + .ns: + call checkForCollision ;check if player would collide on new position, if not change position to new position + .nokeyws: + cmp byte [canWalk], 0 + jnz .noCollision + mov word [player+6], 0 ;reset animation counter + ret + .noCollision: + inc word [player+6] ;update animation if moving + ret + +;======================================== NEW STUFF ========================================== +registerInterruptHandlers: + mov [0x0024], dword keyboardINTListener ;implements keyboardListener + ret + +;; NEW KEYBOARD EVENT BASED CODE +pressA db 0 +pressD db 0 +pressW db 0 +pressS db 0 +keyboardINTListener: ;interrupt handler for keyboard events + pusha + xor bx,bx ; bx = 0: signify key down event + inc bx + in al,0x60 ;get input to AX, 0x60 = ps/2 first port for keyboard + btr ax, 7 ;al now contains the key code without key pressed flag, also carry flag set if key up event + jnc .keyDown + dec bx ; bx = 1: key up event + .keyDown: + cmp al,0x1e ;a + jne .check1 + mov byte [cs:pressA], bl ;use cs overwrite because we don't know where the data segment might point to + .check1: + cmp al,0x20 ;d + jne .check2 + mov byte [cs:pressD], bl + .check2: + cmp al,0x11 ;w + jne .check3 + mov byte [cs:pressW], bl + .check3: + cmp al,0x1f ;s + jne .check4 + mov byte [cs:pressS], bl + .check4: + mov al, 20h ;20h + out 20h, al ;acknowledge the interrupt so further interrupts can be handled again + popa ;resume state to not modify something by accident + iret ;return from an interrupt routine + +;using interrupts instread of the BIOS is SUUPER fast which is why we need to delay execution for at least a few ms per gametick to not be too fast +synchronize: + pusha + mov si, 20 ; si = time in ms + mov dx, si + mov cx, si + shr cx, 6 + shl dx, 10 + mov ah, 86h + int 15h ;cx,dx sleep time in microseconds - cx = high word, dx = low word + popa + ret + +;cx, dx = xpos, zpos, si = animation +;eax == 0 => success, else failed +addEntity: + pusha + mov bx, cx + mov di, entityArray + xor ax, ax + mov cx, (entityArraySize-1) + repne scasw ; iterate through entity array until empty stop is found + sub di, 2 + test ecx, ecx ; abort here if at the end of the the entity array + je .failed + sub cx, (entityArraySize-1) ; calculate index within the array by using the amount of iterated entires + neg cx + shl cx, 3 + add cx, entityArrayMem + mov [di], cx + mov di, cx + mov [di], si + mov [di+2], bx ; set x position of the entity + mov [di+4], dx ; set y position of the entity + xor bx, dx ; "randomise" initial animation position + mov [di+6], bx ; set animation state + popa + xor eax, eax ; return 0 if successfully added + ret + .failed: + popa + xor eax, eax + inc eax ; return 1 if failed to find a place for the entity + ret + +;di = entity cx,dx = xpos,zpos +drawBlock: + mov ax, word [player+2] + sub ax, cx + imul ax, ax + mov bx, word [player+4] + sub bx, dx + imul bx, bx + add ax, bx + cmp ax, 3000 ;calculate distance + jge .skip + + mov ax, cx + mov bx, dx + sub ax, word [player+2] ;subtract the position of the player from the x position + add ax, 80/2 - 9/2 - 1 ;relative to screen image drawing code for x position + sub bx, word [player+4] ;subtract the position of the player from the z position + add bx, 50/2 - 12/2 - 1 ;relative to screen image drawing code for z position + call drawImage ;draw image to buffer + .skip: + clc + ret + +;set the position of the player to x=cx, z=dx +setSpawn: + mov word [player+2], cx ; set player x + mov word [player+4], dx ; set player z + add word [player+4], 3 ; offset player z + clc + ret + +;spawn the coins add set the spawn position of the player +initMap: + mov si, coinImg + mov bp, addEntity + mov ah, 'X' + call iterateMap ; iterate the map and add a coin at every 'X' on the map + call spawnPlayer ; set spawn for player + ret + +;draw the map +drawMap: + mov si, boxImg_0 + mov bp, drawBlock + mov ah, '0' + call iterateMap ; iterate the map and add a box at every '0' on the map + ;this second iteration is pretty unefficient but only optional for some ground texture + mov si, tileImg_0 + mov bp, drawBlock + mov ah, ' ' + call iterateMap ; iterate the map and add a tile at every ' ' on the map + ret + +; si = player X, bx = player Y +collideMap: + mov bp, blockCollison + mov ah, '0' + call iterateMap ; iterate the map and check for a collision with a '0' + ret + +;set the spawn of the player to the field 'P' +spawnPlayer: + mov bp, setSpawn + mov ah, 'P' + call iterateMap ; iterate the map and set the player position to the last 'P' found on the map + ret + +%define tileWidth 8 +%define ASCIImapWidth 64 +%define ASCIImapHeight 64 +;bp = function to call, ah = search for, si = parameter for bp function +iterateMap: + mov di, ASCIImap + mov cx, 0x0 ; map start x + mov dx, 0x0 ; map start y + .next: + mov al, [di] + test al, al + je .stop ; stop when null terminator found + cmp al, ah + jne .skip ; skip if the character is not the one this iteration is searching for + push ax ; save the content of ax + call bp ; call the specified function of this iteration + pop ax + jc .term ; the carry flag determines if the specified function has found what it was searching for (and thus exits) + .skip: + inc di ; point to the next character + add cx, tileWidth ; increase x pixel position + cmp cx, ASCIImapWidth*tileWidth ; check if x position is at the end of the line + jl .next + sub dx, tileWidth ; decrease y pixel position + xor cx, cx ; reset x position + jmp .next + .stop: + clc + .term: + ret + +;si = player x, bx = player z, cx = block x, dx = block z +blockCollison: + push cx + push dx + sub cx, 8 ;subtract 8 because of hitbox + cmp cx, si ; (blockX-8 <= playerX) + jg .skip + add cx, 8+8 ;add 8 because of hitbox + cmp cx, si ; (blockX+8 > playerX) + jle .skip + sub dx, 10 ;subtract 10 because of hitbox + cmp dx, bx ; (blockZ-10 <= playerZ) + jg .skip + add dx, 9+10 ;subtract 9 because of hitbox + cmp dx, bx ; (blockZ+9 > playerZ) + jle .skip + stc + jmp .end + .skip: + clc + .end: + pop dx + pop cx + ret + +%include "buffer.asm" + + +;game value + +coinFound dw 0 + +;entity array + +entityArray: + dw player + resw entityArraySize + +;player structure +player: +player_Anim dw playerImg_front ;pointer to animation +player_PosX dw 0x32 ;position of player (x) +player_PosZ dw 0x32 ;position of player (z) +player_AnimC dw 0 ;animation counter + +;entity structure +box: +box_Anim dw boxImg ;pointer to animation +box_PosX dw 0x10 ;position of box (x) +box_PosZ dw 0x10 ;position of box (z) +box_AnimC dw 0 ;animation counter + +;other entity structures: +entityArrayMem: + resw entityArraySize*4 + +;animation structure +playerImg_front: + dw 5 + dw 20 + dw playerImg_front_0 + dw playerImg_front_1 + dw playerImg_front_0 + dw playerImg_front_2 + dw 0 + +playerImg_back: + dw 5 + dw 20 + dw playerImg_back_0 + dw playerImg_back_1 + dw playerImg_back_0 + dw playerImg_back_2 + dw 0 + +playerImg_right: + dw 5 + dw 20 + dw playerImg_right_0 + dw playerImg_right_1 + dw playerImg_right_0 + dw playerImg_right_2 + dw 0 + +playerImg_left: + dw 5 + dw 20 + dw playerImg_left_0 + dw playerImg_left_1 + dw playerImg_left_0 + dw playerImg_left_2 + dw 0 + +boxImg: + dw 1 ;time per frames + dw 1 ;time of animation + dw boxImg_0 ;frames + dw 0 ;zero end frame + +coinImg: + dw 5 ;time per frames + dw 20 ;time of animation + dw coin_0 ;frames + dw coin_1 ;frames + dw coin_2 ;frames + dw coin_1 ;frames + dw 0 ;zero end frame + +playerImg_front_0 incbin "img/player_front_0.bin" +playerImg_front_1 incbin "img/player_front_1.bin" +playerImg_front_2 incbin "img/player_front_2.bin" +playerImg_back_0 incbin "img/player_back_0.bin" +playerImg_back_1 incbin "img/player_back_1.bin" +playerImg_back_2 incbin "img/player_back_2.bin" +playerImg_right_0 incbin "img/player_right_0.bin" +playerImg_right_1 incbin "img/player_right_1.bin" +playerImg_right_2 incbin "img/player_right_2.bin" +playerImg_left_0 incbin "img/player_left_0.bin" +playerImg_left_1 incbin "img/player_left_1.bin" +playerImg_left_2 incbin "img/player_left_2.bin" + +coin_0 incbin "img/coin_0.bin" +coin_1 incbin "img/coin_1.bin" +coin_2 incbin "img/coin_2.bin" + +boxImg_0 incbin "img/box.bin" +tileImg_0 incbin "img/tile.bin" + +ASCIImap incbin "img/map.bin" +db 0 + +%assign usedMemory ($-$$) +%assign usableMemory (512*16) +%warning [usedMemory/usableMemory] Bytes used +times (512*16)-($-$$) db 0 ;kernel must have size multiple of 512 so let's pad it to the correct size +;times (512*1000)-($-$$) db 0 ;toggle this to use in bochs