Skip to content

Instantly share code, notes, and snippets.

@PachUp
Created June 10, 2020 18:55
Show Gist options
  • Save PachUp/0d824f291db45571e6789d981c9563ca to your computer and use it in GitHub Desktop.
Save PachUp/0d824f291db45571e6789d981c9563ca to your computer and use it in GitHub Desktop.
IDEAL
MODEL small
STACK 100h
DATASEG
whatiswhat db 'if you go to gray you will start a game if you go to red you will leave the game draw for fun! :)$'
youlost db 'you lost! go to the gray buttom to start again!$' ;
filename db 'scarymonster.bmp',0 ;scary proc
filehandle dw ? ;holds the file details
;------------------------------------------------------------------------------------------------------------------------------------------
note dw 2394h ; for noise
Header db 54 dup (0) ;
Palette db 256*4 dup (0) ; -these are used to upload the picture
ScrLine db 320 dup (0) ;
;colors
white2 equ 15d
white equ 31d
gray equ 8d
red equ 40d
red2 equ 4d
black equ 0d
green equ 2d
color db ? ;tells the mouse/menumouse what are the colors that are steppable and the colors that are not
color2 db ? ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lastx dw 0 ;helps thee mouse/menumouse to know what was their last x,y so the proc could cover it with the color of the background
lasty dw 0 ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
x dw ? ;used in the graphic procs to define the x of the printed pixel
y dw ? ;used in the graphic procs to define the y of the printed pixel
height dw ? ;defines the height of the printed square
length0 dw ? ;defines the length of the printed square
firstx dw ? ;var that is used when the square or line has vertical increasement
lengthnheiht dw ? ;tells the slant proc when to stop (in which height and length)
CODESEG
proc OpenFile
; Open file
mov ah, 3Dh
xor al, al
mov dx, offset filename
int 21h
mov [filehandle], ax
ret
endp OpenFile
proc ReadHeader
; Read 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
; 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 CopyBitmap
; BMP graphics are saved upside-down.
; Read the graphic line by line (200 lines in VGA format),
; displaying the lines from bottom to top.
mov ax, 0A000h
mov es, ax
mov cx,199
PrintBMPLoop:
push cx
mov di,cx
shl cx,6
shl di,8
add di,cx
; Read one line
mov ah,3fh
mov cx,320
mov dx,offset ScrLine
int 21h
; Copy one line into video memory
cld ; Clear direction flag, for movsb
mov cx,320
mov si,offset ScrLine
rep movsb ; Copy line to the screen
;rep movsb is same as the following code:
;mov es:di, ds:si
;inc si
;inc di
;dec cx
;loop until cx=0
pop cx
dec cx
cmp cx, 0
jnl PrintBMPLoop
ret
endp CopyBitmap
proc noise
push bp
mov bp, sp
; open speaker
;in al, 61h
;or al, 00000011b
;out 61h, al
; send control word to change frequency
;mov al, 0B6h
;out 43h, al
; play frequency 131Hz
;mov ax, [note]
;out 42h, al ; Sending lower byte
;mov al, ah
;out 42h, al ; Sending upper byte
; wait for any key
;mov ah, 9h
;int 21h
;close the speaker
;in al, 61h
;and al, 11111100b
;out 61h, al
pop bp
ret
endp noise
proc scary
;if the player has made all the way up to the end of the third level the moster will appear
push bp
mov bp, sp
mov ax, 13h
int 10h
; Process BMP file
call OpenFile
call ReadHeader
call ReadPalette
call CopyPal
call CopyBitmap
; call noise
pop bp
ret
;monster picture + sound
endp scary
proc wipe
;none
mov ax, 2
mov bx, 3
int 10
ret
;makes the screen become black
endp wipe
proc blockwvalue ; blocks with value - they acculy do something rather than just being blocks they do that if you get in the wall
; then something happends if you get to the red spot the lv is changing etc
;x ,y ,height ,length0 ,color, color2(if its a square)
push bp
mov bp, sp
linee:
mov bl, 0
mov cx, [length0]
add [length0], 1d
push ax
mov ax, [x]
mov [firstx], ax
pop ax
linee1:
push cx ;---------------------------------
mov cx, [x] ;comparing between the color at the given x,gray
mov dx, [y] ;and the 2 colors that are given to the proc
mov ah, 0Dh ;the x increases which means one pixel to the right
int 10h ;this action repeats over and over again as the value of length0
cmp al, [color] ;
je iwanttoplayyy ;
cmp al, [color2] ;
je idontwantoplay ;
cmp al, white2 ;
je jumpscare ;
inc [x] ;
pop cx ;
loop linee1 ;----------------------------------
inc [y] ;y is increased in order to go over the same function again
push ax ;but one line below
mov ax, [firstx] ;
mov [x], ax ;
pop ax ;
mov cx, [length0] ;
push ax ;
mov ax, [height] ;checks if the wanted heights was achived
cmp ax,[y] ;
je finishh ;
pop ax ;
loop linee1
finishh:
jmp finishgood
idontwantoplay: ;fail
; you can add messages but it will stop the game
mov bl, 1d ;if the mouse is on black color bl = 1
jmp realend
iwanttoplayyy:
mov bl, 3d ;if the mouse is on red color bl = 3
jmp realend
finishgood:
pop ax
jmp then
realend:
pop cx
jmp then
jumpscare: ;if the mouse is on white2 color bl = 8
pop ax
mov bl, 8d
call scary
jmp then
then:
pop bp
ret
endp blockwvalue
proc menumouse
;none
push bp
mov bp, sp
printthemes: ;printing
mov dx, offset whatiswhat
mov ah, 9
int 21h
mov dl, 0d
mov ah, 2 ;;;;;;;;;;;;;;;
int 21h ;string output;
mov dl, 0ah ;;;;;;;;;;;;;;;
mov ah, 2
int 21h
reset1:
mov ax,3h; where is the mouse
int 33h
shr cx,1 ; where is the mouse
push cx
push dx
push [x]
push [y]
push [length0]
push [height]
mov [x], cx
mov [y], dx
mov bl, 0
mov [length0], 2d
push dx
add dx, 2
mov [height], dx
pop dx
mov [color], gray
mov [color2], red
call blockwvalue
pop [height]
pop [length0]
pop [y]
pop [x]
pop dx
pop cx
cmp bl, 1d ;compares between bl to 3 or 1 to check what was the result from from the check proc
je noplay12
cmp bl, 3d
je gj1
yo1:
cmp cx, [lastx] ;------------------------
je checkday1 ;checks if the mouse x,y is one the same spot from last time checked
jmp duo1 ;
checkday1: ;
cmp dx, [lasty] ;
je reset1 ;
jmp duo1 ;------------------------
duo1:
push cx
push dx
mov cx, [lastx];uses the x and the y from last loop
mov dx, [lasty];
mov [x], cx ;----------------------
mov [y], dx ;
mov [color], white;
mov [length0], 2d ;
push dx ;saves dx in the stuck and then calls for block
add dx, 2 ;
mov [height], dx ;
pop dx ;
call block ;----------------------
pop dx
pop cx
mov [lastx], cx ;keeps the x and the y for the next loop
mov [lasty], dx ;
mov [x], cx ;----------------------
mov [y], dx ;
mov [color], green ;
mov [length0], 2d ;
push dx ;saves dx in the stuck and then calls for block
add dx, 2 ;
mov [height], dx ;
pop dx ;
call block ;----------------------
jmp reset1
noplay12:
mov bl, 1d ;if bl = 1 means that exit was pressed
jmp decided
gj1:
mov bl, 0d ;if bl = 0 means that play was pressed
decided:
pop bp
ret
;if the player pressed the exit button bl = 1 if not bl = 0
endp menumouse
proc mouse
;none
push bp
mov bp, sp
reset:
mov ax,3h; where is the mouse
int 33h
shr cx,1; where is the mouse
push cx
push dx
push [x]
push [y]
push [length0]
push [height]
mov [x], cx
mov [y], dx
mov bl, 0
mov [length0], 2d
push dx
add dx, 2
mov [height], dx
pop dx
mov [color], red2
mov [color2], black
call blockwvalue
pop [height]
pop [length0]
pop [y]
pop [x]
pop dx
pop cx
cmp bl, 1d
je noplay1
cmp bl, 3d
je bridge
cmp bl, 8d
je monsterrr
cmp cx, [lastx]
je checkday
jmp duo
checkday:
cmp dx, [lasty]
je reset
jmp duo
duo:
push cx
push dx
mov cx, [lastx]
mov dx, [lasty]
mov [x], cx
mov [y], dx
mov [color], white
mov [length0], 2d
push dx
add dx, 2
mov [height], dx
pop dx
call block
pop dx
pop cx
mov [lastx], cx
mov [lasty], dx
jmp skipped
bridge:
call level2
jmp gj
skipped:
mov [x], cx
mov [y], dx
mov [color], green
mov [length0], 2d
push dx
add dx, 2
mov [height], dx
pop dx
call block
jmp reset
monsterrr:
mov bl, 8d
jmp decided1
noplay1:
mov bl, 1d
mov [lastx], 320d ;if you lost the menumouse is going to print a pixel at the lastx and lasty
mov [lasty], 200d ;from this proc
jmp decided1
gj:
mov bl, 0d
decided1:
pop bp
ret
endp mouse
proc block
;x ,y ,height ,length , firstx(if its a square)
push bp
mov bp, sp
line:
mov al, [color] ;----------------------
mov bl, 0 ;moves the parameters into registers
mov cx, [length0] ;
add [length0], 1d ;
push ax ;
mov ax, [x] ;
mov [firstx], ax ;
pop ax ;----------------------
line1:
push cx ;----------------------
mov cx, [x] ;pixel print
mov dx, [y] ;
mov ah,0ch ;
int 10h ;
inc [x] ;x increased to make a line
pop cx ;loop the action as the value of the given length0
loop line1 ;----------------------
inc [y] ;y is increased in order to go over the same function again
push ax ;but one line below
mov ax, [firstx] ;
mov [x], ax ;
pop ax ;
mov cx, [length0] ;
push ax ;
mov ax, [height] ;
cmp ax,[y] ;checks if the wanted heights was achived
je done ;
pop ax ;
loop line1 ;-----------------------
done:
pop ax
pop bp
ret
;square/line with the chosen color
endp block
proc rulesnstart
push bp
mov bp, sp
mov ax, 13h
int 10h
startthegame:
mov [x], 114d ;call for block proc
mov [y], 157d
mov [color], gray
mov [length0], 49d
mov [height], 190d
call block ;P end
leavethegame: ;;call for block proc
mov [x], 150d
mov [y], 157d
mov [color], red
mov [length0], 36d
mov [height], 190d
call block
mov ax,0h ;installing the mouse
int 33h
call menumouse
pop bp
ret
endp rulesnstart
proc level
push bp
mov bp, sp
mov ax, 13h
int 10h
wipe2:
call wipe
lv1f1:
mov [x], 100d ;call for block proc
mov [y], 140d
mov [color], white
mov [length0], 49d
mov [height], 190d
call block
lv1f2:
mov [x], 100d ;call for block proc
mov [y], 110d
mov [color], white
mov [length0], 75d
mov [height], 145d
call block
lv1f3:
mov [x], 145d ;call for block proc
mov [y], 110d
mov [color], white
mov [length0], 75d
mov [height], 145d
call block
lv1f10:
mov [x], 160d ;call for block proc
mov [y], 140d
mov [color], red2
mov [length0], 49d
mov [height], 148d
call block
idk1:
call mouse
pop bp
ret
endp level
proc level2
push bp
mov bp, sp
mov ax, 13h
int 10h
wipe22:
call wipe
lv2f1:
mov [x], 155d ;call for block proc
mov [y], 102d
mov [color], white
mov [length0], 23d
mov [height], 145d
call block
lv2f2:
mov [x], 85d ;call for block proc
mov [y], 80d
mov [color], white
mov [length0], 75d
mov [height], 102d
call block
lv2f3:
mov [x], 85d ;call for block proc
mov [y], 60d
mov [color], white
mov [length0], 22d
mov [height], 80d
call block
lv2f4:
mov [x], 85d ;call for block proc
mov [y], 60d
mov [color], white
mov [length0], 44d
mov [height], 67d
call block
lv2f5:
mov [x], 124d ;call for block proc
mov [y], 40d
mov [color], white
mov [length0], 5d
mov [height], 60d
call block
lv2f6:
mov [x], 105d ;call for block proc
mov [y], 35d
mov [color], white
mov [length0], 24d
mov [height], 40d
call block
lv2f7:
mov [x], 105d ;call for block proc
mov [y], 28d
mov [color], white2
mov [length0], 5d
mov [height], 36d
call block
lv2f8:
mov [x], 93d ;call for block proc
mov [y], 8d
mov [color], red2
mov [length0], 30d
mov [height], 28d
call block
lv2f9:
mov [x], 124d ;call for block proc
mov [y], 45d
mov [color], white
mov [length0], 5d
mov [height], 46d
call block
thatsit:
call mouse
pop bp
ret
endp level2
start:
mov ax, @data
mov ds, ax
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
mov ax, 13h
int 10h
restart:
call rulesnstart
cmp bl, 1;checks if the play or exit button was pressed
je beforeexit
call level
cmp bl, 1d;checks if you met the monster or lost/failed and then sends you to the menu
je restart
jumppscare:
call scary
jmp restart
beforeexit:
mov ah, 0
int 10h
exit:
mov ax, 4c00h
int 21h
END start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment