Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BITS 16
- stacksize EQU 0200h ;Määritellään pinon koko
- ; Constants here
- delay EQU 1200 ;viive
- ; starting address of video memory
- videobase EQU 0a000h
- ; starting position of the ball
- xcoord EQU 250
- ycoord EQU 100
- ; some colors
- black EQU 0
- green EQU 00110000b
- blue EQU 00001001b
- red EQU 00000100b
- white EQU 00001111b
- ; screen width in pixels, in the graphics mode 320x200
- scrwidth EQU 320
- segment mystack stack ;Määritellään mystack-niminen pino
- resb stacksize ;jolle varataan tilaa stacksizen verran
- stacktop:
- segment mydata data ;Määritellään mydata-niminen datasegmentti
- ; Variables here
- foo resw 1 ;Varataan muistia yhden sanan verran foo-muuttujalle
- pressesc dw 0 ;Määritellään muuttuja pressesc (sanan pituinen), jonka alkuarvo on 0
- oldintseg resw 1 ;Määritellään kaksi muuttuja, joille varataan yhden
- oldintoff resw 1 ;sanan verran muistia kullekin
- prevmode resb 1 ;Edellinen video mode, 1 tavu
- hormov dw -320 ;horisontaalinen liike, alustetaan -320
- vermov db 1 ;vertikaalinen liike, alustetaan 1
- ;assarin mielestä tulee ongelmia myöhemmin
- segment mycode code ;Määritellään mycode-niminen koodisegmentti
- ;MoveBall-alirutiini siirtää palloa
- MoveBall:
- mov byte [es:di], black ;Muutetaan pallo mustaksi
- add di, 960 ;Siirretään palloa kolme riviä alaspäin
- mov byte [es:di], white ;Muutetaan pallo valkoiseksi
- ret
- KeybInt:
- push ds ; put the value of ds,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
- ; scan codes can be found in helppc
- ; interrupt services ->
- ; keyboard interrupt -> make codes
- ; here begins the actual key scanning
- cmp al, 01h ; 1 is the scan code for ESC
- jne .kbread ; if ESC was not pressed, continue
- mov word [pressesc], 1
- .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
- ..start:
- ;Initialisation of segment registers
- mov ax, mydata ;Siirretään muuttujat ax:ään
- mov ds, ax ;ja siitä edelleen datasegmenttirekisteriin
- mov ax, mystack ;Ja sama homma pinolle
- mov ss, ax ;ss=pinosegmenttirekisteri
- mov sp, stacktop ;pino-osoitin osoittamaan pinon alkuun
- ;Saving the old interrupt adress
- mov al, 9 ;interrupt number of keyboard is 9
- mov ah, 35h ;35h = get interrupt vector
- int 21h ;kutsutaan keskeytystä
- mov [oldintseg], es ;The returned segment address into the variable oldintseg
- mov [oldintoff], bx ;The returned offset address into the variable oldintoff
- ;Setting new interrupt
- mov ax, mycode ;Siirretään koodisegmentin osoite DS:ään
- mov ds, ax
- mov dx, KeybInt ;Siirretään DX:ään Keyboard hander routine address
- mov al, 9 ;interrupt number of keyboard is 9
- mov ah, 25h ;25 - Set Interrupt Vector
- int 21h ;Kutsutaan keskeytystä
- ;Palautetaan datasegementin osoite DS:ään
- mov ax, mydata
- mov ds, ax
- ;Haetaan nykyinen videomode ja tallenetaan se muuttujaan prevmode
- mov ah, 0Fh
- int 10h
- mov byte [prevmode], al
- ;Vaihdetaan videomode 320x200x256-tilaan
- mov ah, 0
- mov al, 13h
- int 10h
- ; set extra segment address for video memory
- mov ax, videobase
- mov es, ax
- ; insert starting point coordinates
- ; to the index register of video memory
- mov di, (scrwidth * ycoord) + xcoord
- ;Piirretään valkoinen pikseli di:n osoittamaan paikkaan
- mov byte [es:di], white
- ;main-looppi esc-näppäimen tarkistukseen
- .main:
- mov dx, delay
- .pause1:
- mov cx, 65535
- .pause2:
- dec cx
- jne .pause2
- dec dx
- jne .pause1
- call MoveBall ;Siirretään palloa
- cmp word [pressesc], 1 ;Tarkastetaan onko esc:iä painettu
- jne .main
- .dosexit:
- ;Vaihdetaan videomode takaisin alkuperäiseen
- mov ah, 0
- mov byte al, [prevmode]
- int 10h
- ;Restoring the old interrupt
- mov dx, [oldintoff] ;The variable oldintoff to DX
- mov ax, [oldintseg] ;The variable oldintseg to DS
- mov ds, ax ;-II-
- mov al, 9 ;interrupt number of keyboard is 9
- mov ah, 25h ;25 - Set Interrupt Vector
- int 21h ;Kutsutaan keskeytystä
- ;Ending the program with INT 21,4C
- mov al, 0 ;Palautusarvo = 0
- mov ah, 4ch ;INT 21,4C - Terminate Process With Return Code
- int 21h ;kutsutaan keskeytystä
Add Comment
Please, Sign In to add comment