Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BITS 16
- ;;;;;;;;;;;;;;
- ; CONSTANTS
- ;;;;;;;;;;;;;;
- stacksize EQU 0200h
- ; starting address of video memory
- videobase EQU 0a000h
- ; some colors
- black EQU 0
- green EQU 00110000b
- blue EQU 00001001b
- red EQU 00000100b
- white EQU 00001111b
- grey EQU 00000111b
- yellow EQU 00001110b
- transparent EQU 11111111b ;Note: this is our convention for this exercise - see the bitmap copy later...
- ; screen width in pixels, in the graphics mode 320x200
- scrwidth EQU 320
- ;;;;;;;;;;;;;;
- ; DATA AND STACK SEGMENTS
- ;;;;;;;;;;;;;;
- segment memscreen data
- resb 320*200
- segment background data
- resb 320*200
- segment mystack stack
- resb stacksize
- stacktop:
- segment mydata data
- ; DEFINE YOUR VARIABLES HERE
- foo resw 1
- pressesc dw 0
- oldintseg resw 1
- oldintoff resw 1
- delay dw 2
- oldgramod resw 1
- move dw 6
- pacmanloc dw 32160
- toofast dw 0
- segment bitmaps data
- PacmanMap db transparent,transparent,transparent,transparent,yellow,yellow,yellow,transparent,transparent,transparent,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,transparent,transparent,yellow,yellow,yellow,yellow,transparent,transparent,transparent,transparent,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,yellow,yellow,yellow,yellow,yellow,yellow,yellow,transparent,transparent,transparent,transparent,transparent,transparent,yellow,yellow,yellow,transparent,transparent,transparent,transparent
- ;;;;;;;;;;;;;;
- ; The code segment - YOUR CODE HERE
- ;;;;;;;;;;;;;;
- segment mycode code
- ; Subroutines here
- KeybInt:
- push ds ; push the value of ds and ax to safety
- push ax
- mov ax,mydata ; Re-initialisation of
- mov ds,ax ; the data segment
- cli ; Disable other interrupts
- ; during this one
- .getstatus:
- in al, 64h
- test al, 02h
- loopnz .getstatus ; wait until the port is ready
- in al,60h ; Get the scan code of the pressed/released key
- ; here begins the actual key scanning
- cmp al, 01h ; 1 is the 'make code' for ESC
- jne .cplus ; if ESC was not pressed, continue
- mov word [pressesc], 1
- jmp .kbread
- .cplus:
- cmp al, 04Eh ; 4E is the 'make code' for keypad plus
- jne .cminus
- add word [delay], 1
- jmp .kbread
- .cminus:
- cmp al, 04Ah ; 4A is the 'make code' for keypad minus
- jne .cright
- sub word [delay], 1
- jmp .kbread
- .cright
- cmp al, 04Dh
- jne .cleft
- mov word [move], 6
- jmp .kbread
- .cleft
- cmp al, 04Bh
- jne .cup
- mov word [move], -6
- jmp .kbread
- .cup
- cmp al, 048h
- jne .cdown
- mov word [move], -1920
- jmp .kbread
- .cdown
- cmp al, 050h
- jne .kbread
- mov word [move], 1920
- .kbread:
- in al,61h ; Send acknowledgment without
- or al,10000000b ; modifying the other bits.
- out 61h,al ;
- and al,01111111b ;
- out 61h,al ;
- mov al,20h ; Send End-of-Interrupt signal
- out 20h,al ;
- sti ; Enable interrupts again
- pop ax
- pop ds ; Regain the ds,ax from stack
- iret ; Return from interrupt
- movePacman:
- mov word ax, [move]
- add word [pacmanloc], ax
- ret
- copybitmap:
- ;PARAMETERS:
- ; SI contains the offset address of the bitmap
- ; DI contains the target coordinate
- ; ES contains the target segment
- ; CX contains the bitmap row count
- ; DX contains the bitmap col count
- push ds
- pusha
- ;Segment registers to correct locations
- mov ax, bitmaps
- mov ds, ax
- .rowloop:
- push cx
- push di
- mov cx, dx
- .colloop:
- mov byte bl, [ds:si]
- cmp byte bl, transparent
- je .skip
- mov byte [es:di], bl
- .skip:
- inc di
- inc si
- loop .colloop
- pop di
- add di, 320
- pop cx
- loop .rowloop
- popa
- pop ds
- ret
- drawPacman:
- push cx
- push dx
- mov si, 1
- mov di, [pacmanloc]
- mov ax, memscreen
- mov es, ax
- mov dx, 11
- mov cx, 11
- call copybitmap
- pop cx
- pop dx
- ret
- initBackground:
- mov ax, background ; test draw for pixels
- mov es, ax ; move video memory address to ES
- mov di, 0 ; move the desired offset address to DI
- hyppy1:
- mov byte [es:di], blue ; Move the constant 'blue' (hopefully corresponding to blue colour) to the video memory at offset DI
- inc di ; Change the offset address
- cmp di, 320
- jne hyppy1
- mov di, 63680
- hyppy2:
- mov byte [es:di], blue ; Move the constant 'blue' (hopefully corresponding to blue colour) to the video memory at offset DI
- inc di ; Change the offset address
- cmp di, 64000
- jne hyppy2
- mov di, 0
- hyppy3:
- mov byte [es:di], blue
- add di, 320
- cmp di, 64000
- jne hyppy3
- mov di, 319
- hyppy4:
- mov byte [es:di], blue
- add di, 320
- cmp di, 64319
- jne hyppy4
- ret
- draw:
- call copybackground
- call drawPacman
- call copymemscreen
- ret
- copybackground:
- push ds
- pusha
- ;Pointers
- mov word si, 0
- mov word di, 0
- mov cx, 64000
- ;Segment registers to correct locations
- mov ax, memscreen
- mov es, ax
- mov ax, background
- mov ds, ax
- ;REPEAT COPY!
- rep movsb
- popa
- pop ds
- ret
- copymemscreen:
- push ds
- pusha
- ;Pointers
- mov word si, 0
- mov word di, 0
- mov cx, 64000
- ;Segment registers to correct locations
- mov ax, videobase
- mov es, ax
- mov ax, memscreen
- mov ds, ax
- ;REPEAT COPY!
- rep movsb
- popa
- pop ds
- ret
- iscolour:
- push di
- push cx
- push dx
- mov ax, 0
- .rowloop:
- push cx
- push di
- mov cx, dx
- .colloop:
- cmp byte [es:di], bl
- jne .ok
- inc ax
- .ok:
- inc di
- loop .colloop
- pop di
- add di, 320
- pop cx
- loop .rowloop
- pop dx
- pop cx
- pop di
- ret
- respectwall:
- mov word di, [move]
- add word di, [pacmanloc]
- mov cx, 11
- mov dx, 11
- mov ax, bitmaps
- mov es, ax
- call iscolour
- ret
- ..start:
- mov ax, 3509h ;saving the old interrupt address
- int 21h
- mov word [oldintseg], es
- mov word [oldintoff], bx
- mov ax, mydata
- mov ds, ax
- mov ax, mystack
- mov ss, ax
- mov sp, stacktop
- push ds
- mov ax, mycode ;setting the new interrupt
- mov ds, ax
- mov dx, KeybInt
- mov ax, 2509h
- int 21h
- pop ds
- mov ah, 0fh ; fetching the old graphics mode and storing it to a variable
- int 10h
- mov word [oldgramod], ax
- mov ax, 0013h ; setting the new graphics mode
- int 10h
- call initBackground
- .mainloop:
- mov word dx, [delay] ; delay for game speed
- .pause1:
- mov cx, 65535
- .pause2:
- dec cx
- jne .pause2
- dec dx
- jne .pause1
- call draw
- call respectwall ;pacman should recognize the wall...
- cmp ax, 0
- jne .jumppi
- add word [toofast], 1 ;if pacman moves too fast
- cmp word [toofast], 2
- jne .jumppi
- call movePacman
- mov word [toofast], 0
- .jumppi:
- cmp word [pressesc], 1; check if pressed esc
- jne .mainloop
- .dosexit:
- mov word ax, [oldgramod] ; setting the old graphics mode back
- mov ah, 00h
- int 10h
- push ds
- mov word dx, [oldintoff] ; Move VALUE at address oldintoff to DX (not the address!) restoring the old interrupt here!!!
- mov word ax, [oldintseg]; Move VALUE at address oldintseg to DS, step 1 (remember you cannot move directly to segment registers)
- mov ds, ax; Move VALUE at address oldintseg to DS, step 2
- mov ax, 2509h ; Move parameters to AH and AL (or both together by moving to AX). Interrupt number is still 9 and AH should be 25h (note hexadecimal)
- int 21h ; Finally, set the interrupt vector by calling int 21H
- pop ds
- mov al, 0 ; ending the program with INT 21,4c
- mov ah, 4ch
- int 21h
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement