Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDEAL
- MODEL small
- STACK 100h
- DATASEG
- filehandle dw ?
- Header db 54 dup (0)
- Palette db 256*4 dup (0)
- ScrLine db 320 dup (0)
- ErrorMsg db 'Error', 13, 10,'$'
- Firstpic db 'Scrn1.bmp', 0
- Ship db 'Ship5.bmp',0
- filename db 'testfile.txt',0
- filehandle2 dw ?
- Message db ' $'
- ErrorMsg2 db 'Error', 10, 13,'$'
- buffer db 100 dup(0),'$'
- presskeycunt db 13,10,"press any key to continue! $"
- cuber db 'cube3.bmp',0
- deleter db 'Cube4.bmp',0
- deleter2 db 'Cube5.bmp',0
- ok db 0
- mona db" _____ _ _ ____ ______ ______ _____ ______ _ _____ ",13,10
- db " / ____| | | | _ \| ____| | ____|_ _| ____| | | __ \ ",13,10
- db " | | | | | | |_) | |__ | |__ | | | |__ | | | | | |",13,10
- db " | | | | | | _ <| __| | __| | | | __| | | | | | |",13,10
- db " | |____| |__| | |_) | |____ | | _| |_| |____| |____| |__| |",13,10
- db " \_____|\____/|____/|______| |_| |_____|______|______|_____/",13,10
- db" __ _ __ _____ ___ ___ _ ___ __ ",13,10
- db" | _| / | |_ | |_ _/ _ \ | _ \ | /_\ \ / /",13,10
- db" | | | | | | | || (_) | | _/ |__ / _ \ V /",13,10
- db" | | |_| | | |_| \___/ |_| |____/_/ \_\_|",13,10
- db" |__| ___|__|_ ___ ___ ___ ___ _ _ ___ ___",13,10
- db" | _| |_ ) |_ | | __/ _ \| _ \ |_ _| \| | __/ _ |",13,10
- db" | | / / | | | _| (_) | / | || .` | _| (_)|",13,10
- db" | | /___| | | |_| \___/|_|_\ |___|_|\_|_| \___/",13,10
- db" |__| ____ |__| ___ ___ ___ ___ ___ ___ ___ ___ ___",13,10
- db" | _| |__ / |_ | | __/ _ \| _ \ / __|/ __/ _ \| _ \ __/ __|",13,10
- db" | | |_ \ | | | _| (_) | / \__ \ (_| (_) | / _|\__ |",13,10
- db" | | |___/ | | |_| \___/|_|_\ |___/\___\___/|_|_\___|___/",13,10
- db" |__| |__|$"
- level db "Choose a level str:",13,10
- db "Press E For Easy ",13,10
- db "Press M For Meduim",13,10
- db "Press H For Hard",13,10
- db "Press B To Go Back To The Menu",13,10,"$"
- mon2 db "The Game Start With Only 1 Cube Falling From Above$"
- mon3 db "NO SCORES LOSER!$"
- Right db 4dh
- Left db 4bh
- key1 db 31h
- key2 db 32h
- key3 db 33h
- key4 db 34h
- keyEasy db 65h
- keyMed db 6dh
- keyHard db 68h
- keyBack db 62h
- y dw 190
- x dw 150
- ycheck dw ?
- xcheck dw ?
- x2 dw 0
- y2 dw 0
- x3 dw 0
- ycube dw 0
- colorCube db 4
- x4 dw ?
- y4 dw ?
- ydeath dw 0
- xdeath dw ?
- colorDearh db 10
- ycube2 dw 0
- ycube3 dw 0
- ycube4 dw 0
- isprintcube db 1
- isprintcube2 db 0
- isprintcube3 db 0
- isprintcube4 db 0
- hits db 0
- speed dw 0
- ; --------------------------
- CODESEG
- proc CloseFile ;The procedure closes the opened file
- push bp
- mov bp, sp
- mov bx, [filehandle]
- mov ah, 3eh
- int 21h
- pop bp
- ret
- endp CloseFile
- ;======================================================================
- ; This proc wiil pop al registers when "PushAll" is written in the code=
- ;======================================================================
- macro PushAll ;Macros that are used in procs
- push ax
- push bx
- push cx
- push dx
- push di
- push si
- endm PushAll
- ;======================================================================
- ; This proc wiil pop al registers when "PopAll" is written in the code=
- ;======================================================================
- macro PopAll
- pop si
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- endm PopAll
- ;---------------------------------------------------------------------------
- proc OpenFile ;The procedure gets an offset of a file
- ;The procedure opens for reading the sent file
- ; Open file
- push bp
- mov bp, sp
- mov ah, 3Dh
- mov al, 2
- mov dx, [bp+4]
- int 21h
- jc openerror
- mov [filehandle], ax ;Success
- pop bp
- ret 2
- openerror:
- mov dx, offset ErrorMsg
- mov ah, 9h
- int 21h
- pop bp
- ret 2
- endp OpenFile
- ;-----------------------------------------------------------------------
- proc ReadHeader ;The procedure reads BMP file header, 54 bytes
- mov ah, 3fh
- mov bx, [filehandle]
- mov cx, 54
- mov dx, offset Header
- int 21h
- ret
- endp ReadHeader
- proc ReadPalette
- ; Read BMP file color palette, 256 colors * 4 bytes (400h)
- mov ah,3fh
- mov cx,400h
- mov dx,offset Palette
- int 21h
- ret
- endp ReadPalette
- ;----------------------------------------------------------------------
- proc CopyPal
- ; Copy the colors palette to the video memory registers
- ; The number of the first color should be sent to port 3C8h
- ; The palette is sent to port 3C9h
- mov si,offset Palette
- mov cx,256
- mov dx,3C8h
- mov al,0
- ; Copy starting color to port 3C8h
- out dx,al
- ; Copy palette itself to port 3C9h
- inc dx
- PalLoop:
- ; Note: Colors in a BMP file are saved as BGR values rather than RGB.
- mov al,[si+2] ; Get red value.
- shr al,2 ; Max. is 255, but video palette maximal
- ; value is 63. Therefore dividing by 4.
- out dx,al ; Send it.
- mov al,[si+1] ; Get green value.
- shr al,2
- out dx,al ; Send it.
- mov al,[si] ; Get blue value.
- shr al,2
- out dx,al ; Send it.
- add si,4 ; Point to next color.
- ; (There is a null chr. after every color.)
- loop PalLoop
- ret
- endp CopyPal
- ;------------------------------------------------------------------------------
- proc PrintCharacter;First is Length-Second is Width-
- ;after push X- and after push Y / SUB-y-x-אורך-רוחב
- ; BMP graphics are saved upside-down.
- ; Read the graphic line by line (200 lines in VGA format),
- ; displaying the lines from bottom to top.
- push bp
- mov bp, sp
- PushAll
- mov ax, 0A000h
- mov es, ax
- mov cx,[bp+10];Length
- PrintBMPLoop:
- push cx
- ;=====UP======
- add cx, [bp+4];y
- dec cx
- ;=============
- mov di,cx
- shl cx,6
- shl di,8
- add di,cx
- ; Read one line
- mov ah,3fh
- mov cx,[bp+8];Width
- mov dx,offset ScrLine
- int 21h
- ; Copy one line into video memory
- cld ; Clear direction flag, for movsb
- mov cx,[bp+8];Width
- ;=====SIDES=====
- mov si, offset ScrLine
- add di, [bp+6];x
- sub cx, [bp+12]
- ;===============
- repe movsb ; Copy line to the screen
- pop cx
- loop PrintBMPLoop
- PopAll
- pop bp
- ret 10
- endp PrintCharacter
- ;-------------------------------------------------------------------------------
- proc PrintPic ;The procedure gets an offset, a subber number, length, width, x and y
- ;The procedure prints a bmp file picture on the screen.
- push bp
- mov bp, sp
- PushAll
- push [bp+14]
- call OpenFile
- call ReadHeader
- call ReadPalette
- push [bp+12]
- push [bp+10]
- push [bp+8]
- push [bp+6]
- push [bp+4]
- call PrintCharacter
- call CloseFile
- PopAll
- pop bp
- ret 12
- endp PrintPic
- ;======================================================
- ; this proc sets the DOS for video mode 320*200 pixels=
- ;======================================================
- proc SetVideoMode
- push ax
- mov ax,0013h
- int 10h
- pop ax
- ret
- endp
- proc settextmode
- mov ah, 0
- mov al, 2
- int 10h
- ret
- endp
- proc MenuPrint
- call settextmode
- mov ah,9h
- mov dx,offset mona
- int 21h
- ret
- endp
- proc infoDis
- call settextmode
- mov ah,9h
- mov dx,offset mon2
- int 21h
- call disAnyKey
- mov ah,0h
- int 16h
- ret
- endp
- proc menuDis
- checks:
- call MenuPrint
- mov ah,07h
- int 21h
- cmp al,[key1]
- je exitMenu
- cmp al,[key2]
- je infoDisCheck
- cmp al,[key3]
- je scorescheck
- jmp checks
- scorescheck:
- call scoresDis
- jmp checks
- infoDisCheck:
- call infoDis
- jmp checks
- exitMenu:
- call levelStr
- endp
- proc levelStr
- call settextmode
- mov ah,9h
- mov dx,offset level
- int 21h
- KeysWait:
- mov ah,07h
- int 21h
- cmp al,[keyEasy]
- je EasyLevel
- cmp al,[keyMed]
- je MedLevel
- cmp al,[keyHard]
- je HardLevel
- cmp al,[keyBack]
- je goBack
- jmp KeysWait
- EasyLevel:
- mov [speed],3
- call play
- MedLevel:
- mov [speed],6
- call play
- HardLevel:
- mov[speed],12
- call play
- goBack:
- call menuDis
- endp
- proc scoresDis
- call settextmode
- call OpenFileText
- call ReadFile
- call CloseFileText
- mov ah,9h
- mov dx,offset buffer
- int 21h
- call disAnyKey
- mov ah,0h
- int 16h
- ret
- endp
- ;================================
- ; movement of the player
- ;================================
- proc printsTheCubes
- cmp [hits],5
- je hitsUpdate
- cmp [hits],6
- je hitsUpdate2
- cmp [hits],7
- je hitsUpdate3
- jmp prints
- hitsUpdate:
- mov cl,[hits]
- mov [message],cl
- call OpenFileText
- call WriteToFile
- call CloseFileText
- mov [isprintcube2],1
- jmp prints
- hitsUpdate2:
- mov [isprintcube3],1
- jmp prints
- hitsUpdate3:
- mov [isprintcube4],1
- jmp prints
- prints:
- cmp [isprintcube],1
- je ToPrintcube
- isPrintableCube2:
- cmp [isprintcube2],1
- je ToPrintcube2
- isPrintableCube3:
- cmp [isprintcube3],1
- je ToPrintcube3
- isPrintableCube4:
- cmp [isprintcube4],1
- je ToPrintcube4
- ret
- ToPrintcube:
- call printcube
- jmp isPrintableCube2
- ToPrintcube2:
- call printcube2
- jmp isPrintableCube3
- ToPrintcube3:
- call printcube3
- jmp isPrintableCube4
- ToPrintcube4:
- call printcube4
- ret
- endp
- proc printcube
- mov [x3],0
- cmp [ycube],190
- jae resetThings
- mov cx,[ycube]
- mov [ydeath],cx
- call play2
- call play4
- mov bx,[speed]
- add [ycube],bx
- ret
- resetThings:
- inc [hits]
- mov cx,[ycube]
- sub cx,10
- mov [ydeath],cx
- call play3
- call checkDeath
- mov [ycube],0
- ret
- endp
- proc printcube2
- mov [x3],60
- cmp [ycube2],180
- je resetThings2
- mov cx,[ycube2]
- mov [ydeath],cx
- call play2
- call play4
- mov bx,[speed]
- add [ycube2],bx
- ret
- resetThings2:
- mov cx,[ycube2]
- sub cx,10
- mov [ydeath],cx
- call play3
- call checkDeath
- mov [ycube2],0
- ret
- endp
- proc printcube3
- mov [x3],120
- cmp [ycube3],180
- je resetThings3
- mov cx,[ycube3]
- mov [ydeath],cx
- call play2
- call play4
- mov bx,[speed]
- add [ycube3],bx
- ret
- resetThings3:
- mov cx,[ycube3]
- sub cx,10
- mov [ydeath],cx
- call play3
- call checkDeath
- mov [ycube3],0
- ret
- endp
- proc printcube4
- mov [x3],180
- cmp [ycube4],180
- je resetThings4
- mov cx,[ycube4]
- mov [ydeath],cx
- call play2
- call play4
- mov bx,[speed]
- add [ycube4],bx
- ret
- resetThings4:
- mov cx,[ycube4]
- sub cx,10
- mov [ydeath],cx
- call play3
- call checkDeath
- mov [ycube4],0
- ret
- endp
- proc resetValues
- mov [x3],0
- mov [ydeath],0
- mov [ycube],0
- mov [ycube2],0
- mov [ycube3],0
- mov [ycube4],0
- mov [x],150
- mov [y],190
- mov [isprintcube2],0
- mov [isprintcube3],0
- mov [isprintcube4],0
- mov [hits],0
- ret
- endp
- proc checkDeath
- mov cx,28
- mov bx,[x]
- cmp bx,[x3]
- jl checkkkk
- add [x3],20
- checkkkk:
- cmp [x3],bx
- je gameOver
- inc bx
- loop checkkkk
- ret
- gameOver:
- call resetValues
- call fillscrn
- call menuDis
- ret
- endp
- proc movement
- push bp
- mov bp,sp
- PushAll
- Waitagain:
- call w8time
- call printsTheCubes
- in al,64h
- cmp al,10b
- je Waitagain
- in al,60h
- cmp al,[Right]
- je RightMov
- cmp al,[Left]
- je LeftMov
- cmp al,27
- je ENDOF
- call deleteLeft
- jmp Waitagain
- ENDOF:
- pop bp
- ret
- RightMov:
- cmp [x],300
- je chngright
- add [x],5
- push offset Ship
- push 0
- push 10
- push 20
- push [word ptr x]
- push [word ptr y]
- call deleteLeft
- call PrintPic
- jmp Waitagain
- chngright:
- sub [x],5
- jmp Waitagain
- LeftMov:
- cmp [x],0
- je chngleft
- sub [x],5
- push offset Ship
- push 0
- push 10
- push 20
- push [word ptr x]
- push [word ptr y]
- call PrintPic
- call deleteRight
- jmp Waitagain
- chngleft:
- add [x],5
- jmp Waitagain
- endp
- ;================================
- ; files
- ;================================
- proc ReadFile
- ; Read file
- mov ah,3Fh
- mov bx, [filehandle2]
- mov cx, 100
- mov dx,offset buffer
- int 21h
- ret
- endp
- proc OpenFileText
- ; Open file for reading and writing
- mov ah, 3Dh
- mov al, 2
- mov dx, offset filename
- int 21h
- jc openerror2
- mov [filehandle2], ax
- ret
- openerror2:
- mov dx, offset ErrorMsg2
- mov ah, 9h
- int 21h
- ret
- endp
- proc WriteToFile
- ; Write message to file
- mov ah,40h
- mov bx, [filehandle2]
- mov cx,24
- mov dx,offset Message
- int 21h
- ret
- endp WriteToFile
- proc CloseFileText
- ; Close file
- mov ah,3Eh
- mov bx, [filehandle2]
- int 21h
- ret
- endp
- proc disAnyKey
- mov ah,9h
- mov dx, offset presskeycunt
- int 21h
- ret
- endp
- proc play
- xor ah,ah
- xor al,al
- xor dx,dx
- call SetVideoMode
- call fillscrn
- push offset Ship
- call OpenFile
- call ReadHeader
- call ReadPalette
- call CopyPal
- push 0
- push 10
- push 20
- push [word ptr x]
- push [word ptr y]
- call PrintCharacter
- call CloseFile
- call movement
- ret
- endp
- proc w8time
- mov cx ,20000
- loosoos:
- mov [y4],cx
- call w82
- loop loosoos
- mov cx, [x4]
- ret
- endp
- proc w82
- mov cx, 1
- asdsad:
- loop asdsad
- mov cx,[y4]
- ret
- endp
- proc fillscrn
- line2:
- cmp [x2],320
- je fixthea
- mov al,[colorCube]
- mov bl,0
- mov cx,[x2]
- mov dx,[y2]
- mov ah,0ch
- int 10h
- inc [x2]
- jmp line2
- fixthea:
- cmp [y2],200
- je finishthat
- inc [y2]
- mov [x2],0
- jmp line2
- finishthat:
- mov [x2],0
- mov [y2],0
- ret
- endp
- proc play2
- push offset cuber
- call OpenFile
- call ReadHeader
- call ReadPalette
- call CopyPal
- push 0
- push 20
- push 20
- push [x3]
- push [ydeath]
- call PrintCharacter
- call CloseFile
- ret
- endp
- proc play3
- push offset deleter
- call OpenFile
- call ReadHeader
- call ReadPalette
- call CopyPal
- push 0
- push 20
- push 20
- push [x3]
- push [ydeath]
- call PrintCharacter
- call CloseFile
- ret
- endp
- proc play4
- sub [ydeath],10
- push offset deleter2
- call OpenFile
- call ReadHeader
- call ReadPalette
- call CopyPal
- push 0
- push 10
- push 20
- push [x3]
- push [ydeath]
- call PrintCharacter
- call CloseFile
- add [ydeath],10
- ret
- endp
- proc deleteRight
- mov bx,[x]
- mov [x3],bx
- add [x3],20
- push offset deleter
- call OpenFile
- call ReadHeader
- call ReadPalette
- call CopyPal
- push 0
- push 20
- push 20
- push [x3]
- push 190
- call PrintCharacter
- call CloseFile
- ret
- endp
- proc deleteLeft
- mov bx,[x]
- mov [x3],bx
- sub [x3],20
- push offset deleter
- call OpenFile
- call ReadHeader
- call ReadPalette
- call CopyPal
- push 0
- push 20
- push 20
- push [x3]
- push 190
- call PrintCharacter
- call CloseFile
- xor bx,bx
- ret
- endp
- start:
- mov ax, @data
- mov ds, ax
- call menuDis
- exit:
- mov ax, 4c00h
- int 21h
- END start
- ;mov cx,6
- ;losos:
- ;cmp [x3],300
- ;je losos2
- ;call play2
- ;add [x3],50
- ;loop losos
- ;losos2:
- ;mov [x3],0
- ;losos33:
- ;cmp [y3],160
- ;je losos4
- ;call play2
- ; call w8time
- ; call play3
- ; add [y3],2
- ; jmp losos33
- ;losos4:
- ;call play3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement