Guest User

Untitled

a guest
Jan 12th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BITS 16
  2.  
  3. stacksize       EQU 0200h       ;Määritellään pinon koko
  4.  
  5. ; Constants here
  6. delay                   EQU 1200        ;viive
  7.  
  8. ; starting address of video memory
  9. videobase       EQU 0a000h
  10.  
  11. ; starting position of the ball
  12.  
  13. xcoord          EQU 250
  14. ycoord          EQU 100
  15.  
  16. ; some colors
  17.  
  18. black           EQU 0
  19. green           EQU 00110000b
  20. blue            EQU 00001001b
  21. red             EQU 00000100b
  22. white           EQU 00001111b
  23.  
  24. ; screen width in pixels, in the graphics mode 320x200
  25.  
  26. scrwidth        EQU 320
  27.  
  28. segment mystack stack           ;Määritellään mystack-niminen pino
  29.         resb stacksize                  ;jolle varataan tilaa stacksizen verran
  30. stacktop:
  31.  
  32. segment mydata data             ;Määritellään mydata-niminen datasegmentti
  33.  
  34. ; Variables here
  35.  
  36. foo     resw    1                               ;Varataan muistia yhden sanan verran foo-muuttujalle
  37. pressesc dw 0                           ;Määritellään muuttuja pressesc (sanan pituinen), jonka alkuarvo on 0
  38. oldintseg resw 1                        ;Määritellään kaksi muuttuja, joille varataan yhden
  39. oldintoff resw 1                        ;sanan verran muistia kullekin
  40. prevmode resb   1                       ;Edellinen video mode, 1 tavu
  41. hormov dw -320                          ;horisontaalinen liike, alustetaan -320
  42. vermov db  1                            ;vertikaalinen liike, alustetaan 1
  43.                                                         ;assarin mielestä tulee ongelmia myöhemmin
  44.  
  45. segment mycode code             ;Määritellään mycode-niminen koodisegmentti
  46.  
  47. ;MoveBall-alirutiini siirtää palloa
  48. MoveBall:
  49.         mov    byte [es:di], black      ;Muutetaan pallo mustaksi
  50.         add di, 960                                             ;Siirretään palloa kolme riviä alaspäin
  51.         mov    byte [es:di], white      ;Muutetaan pallo valkoiseksi
  52.         ret
  53.  
  54. KeybInt:
  55.     push    ds              ; put the value of ds,ax to safety
  56.     push    ax
  57.  
  58.     mov     ax,mydata       ; Re-initialisation of
  59.     mov     ds,ax           ; the data segment
  60.  
  61.     cli                     ; Disable other interrupts
  62.                                                         ; during this one
  63.  
  64. .getstatus:
  65.     in      al, 64h
  66.     test        al, 02h
  67.     loopnz      .getstatus      ; wait until the port is ready
  68.  
  69.     in      al,60h          ; Get the scan code of
  70.                                                         ; the pressed/released key
  71.  
  72.                                 ; scan codes can be found in helppc
  73.                                 ; interrupt services ->
  74.                                 ; keyboard interrupt -> make codes
  75.  
  76.                                 ; here begins the actual key scanning
  77.  
  78.     cmp     al, 01h             ; 1 is the scan code for ESC
  79.     jne     .kbread             ; if ESC was not pressed, continue
  80.  
  81.     mov     word [pressesc], 1
  82.  
  83. .kbread:
  84.     in al,61h                   ; Send acknowledgment without
  85.         or al,10000000b                 ; modifying the other bits.
  86.     out 61h,al                  ;
  87.     and al,01111111b            ;
  88.     out 61h,al                  ;
  89.     mov al,20h                  ; Send End-of-Interrupt signal
  90.     out 20h,al                  ;
  91.  
  92.     sti                     ; Enable interrupts again
  93.  
  94.     pop ax
  95.         pop     ds                                      ; Regain the ds,ax from stack
  96.  
  97.     iret                        ; Return from interrupt
  98.  
  99.  
  100. ..start:
  101.         ;Initialisation of segment registers
  102.         mov     ax, mydata                      ;Siirretään muuttujat ax:ään
  103.         mov     ds, ax                          ;ja siitä edelleen datasegmenttirekisteriin
  104.         mov     ax, mystack                     ;Ja sama homma pinolle
  105.     mov     ss, ax                              ;ss=pinosegmenttirekisteri
  106.     mov     sp, stacktop                ;pino-osoitin osoittamaan pinon alkuun
  107.  
  108.         ;Saving the old interrupt adress
  109.         mov al, 9                                       ;interrupt number of keyboard is 9
  110.         mov ah, 35h                                     ;35h = get interrupt vector
  111.         int 21h                                         ;kutsutaan keskeytystä
  112.         mov [oldintseg], es                     ;The returned segment address into the variable oldintseg
  113.         mov [oldintoff], bx                     ;The returned offset address into the variable oldintoff
  114.  
  115.         ;Setting new interrupt
  116.         mov ax, mycode                          ;Siirretään koodisegmentin osoite DS:ään
  117.         mov ds, ax
  118.         mov dx, KeybInt                         ;Siirretään DX:ään Keyboard hander routine address
  119.         mov al, 9                                       ;interrupt number of keyboard is 9
  120.         mov ah, 25h                                     ;25 - Set Interrupt Vector
  121.         int 21h                                         ;Kutsutaan keskeytystä
  122.  
  123.         ;Palautetaan datasegementin osoite DS:ään
  124.         mov ax, mydata
  125.         mov ds, ax
  126.  
  127.         ;Haetaan nykyinen videomode ja tallenetaan se muuttujaan prevmode
  128.         mov ah, 0Fh
  129.         int 10h
  130.         mov byte [prevmode], al
  131.  
  132.         ;Vaihdetaan videomode 320x200x256-tilaan
  133.         mov ah, 0
  134.         mov al, 13h
  135.         int 10h
  136.  
  137.         ; set extra segment address for video memory
  138.         mov    ax, videobase
  139.         mov    es, ax
  140.  
  141.         ; insert starting point coordinates
  142.         ; to the index register of video memory
  143.         mov    di, (scrwidth * ycoord) + xcoord
  144.  
  145.         ;Piirretään valkoinen pikseli di:n osoittamaan paikkaan
  146.         mov    byte [es:di], white
  147.  
  148.  
  149.         ;main-looppi esc-näppäimen tarkistukseen
  150. .main:
  151.         mov     dx, delay
  152. .pause1:
  153.     mov     cx, 65535
  154. .pause2:
  155.     dec     cx
  156.     jne     .pause2
  157.     dec     dx
  158.     jne     .pause1
  159.  
  160.         call MoveBall                           ;Siirretään palloa
  161.         cmp word [pressesc], 1          ;Tarkastetaan onko esc:iä painettu
  162.         jne .main
  163.  
  164. .dosexit:
  165.         ;Vaihdetaan videomode takaisin alkuperäiseen
  166.         mov ah, 0
  167.         mov byte al, [prevmode]
  168.         int 10h
  169.  
  170.         ;Restoring the old interrupt
  171.         mov dx, [oldintoff]                     ;The variable oldintoff to DX
  172.         mov ax, [oldintseg]                     ;The variable oldintseg to DS
  173.         mov ds, ax                                      ;-II-
  174.         mov al, 9                                       ;interrupt number of keyboard is 9
  175.         mov ah, 25h                                     ;25 - Set Interrupt Vector
  176.         int 21h                                         ;Kutsutaan keskeytystä
  177.  
  178.         ;Ending the program with INT 21,4C
  179.         mov     al, 0                                   ;Palautusarvo = 0
  180.         mov ah, 4ch                                     ;INT 21,4C - Terminate Process With Return Code
  181.         int 21h                                         ;kutsutaan keskeytystä
Add Comment
Please, Sign In to add comment