Advertisement
Guest User

pasta

a guest
Nov 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; -------------------------------------------------------------------
  2. ; 80386
  3. ; 32-bit x86 assembly language
  4. ; TASM
  5. ;
  6. ; author:   Jarne Arnouts, Minh Tai Nguyen
  7. ; date:     28/10/2019
  8. ; program:  Video mode 13h
  9. ; -------------------------------------------------------------------
  10.  
  11. IDEAL
  12. P386
  13. MODEL FLAT, C
  14. ASSUME cs:_TEXT,ds:FLAT,es:FLAT,fs:FLAT,gs:FLAT
  15.  
  16. ; compile-time constants (with macros)
  17. VMEMADR EQU 0A0000h ; video memory address
  18. SCRWIDTH EQU 320    ; screen witdth
  19. SCRHEIGHT EQU 200   ; screen height
  20. FRAMECOUNT EQU 288
  21.  
  22. ; -------------------------------------------------------------------
  23. CODESEG
  24. ; wait for @@framecount frames
  25. proc wait_VBLANK
  26.     ARG @@framecount: word
  27.     USES eax, ecx, edx
  28.     mov dx, 03dah                   ; Wait for screen refresh
  29.     movzx ecx, [@@framecount]
  30.    
  31.         @@VBlank_phase1:
  32.         in al, dx
  33.         and al, 8
  34.         jnz @@VBlank_phase1
  35.         @@VBlank_phase2:
  36.         in al, dx
  37.         and al, 8
  38.         jz @@VBlank_phase2
  39.     loop @@VBlank_phase1
  40.    
  41.     ret
  42. endp wait_VBLANK
  43.  
  44. proc check_for_input
  45.     ARG @@keyL:byte , @@keyR:byte , @@keyU:byte , @@keystop:byte
  46.     USES    eax
  47.    
  48.     mov ah, 01h
  49.     int 16h
  50.     test1:
  51.     cmp al,[@@keyL]
  52.     jne test2
  53.     call go_left
  54.    
  55.     test2:
  56.     cmp al, [@@keyR]
  57.     jne test3
  58.     call go_right
  59.    
  60.     test3:
  61.     cmp al, [@@keyU]
  62.     jne test4
  63.     call go_up
  64.    
  65.     test4:
  66.     cmp al, [@@keystop]
  67.     jne @@continue
  68.     call terminateProcess
  69.    
  70.     @@continue:
  71.     ret
  72.  
  73. ENDP check_for_input
  74.  
  75. PROC go_up
  76.     USES eax
  77.     mov eax, [y_pos]
  78.     sub al, 40
  79.     mov [y_pos], eax
  80.    
  81.     ret
  82. ENDP go_up
  83.    
  84. PROC go_left
  85.     USES eax
  86.     mov eax, [x_pos]
  87.     sub eax, 5
  88.     mov [x_pos], eax
  89.    
  90.     ret
  91. ENDP go_left
  92.  
  93. PROC gravity
  94.     USES eax
  95.     mov eax, [y_pos]
  96.     cmp eax, 150
  97.     jle vallen
  98.     jmp niks
  99.     vallen:
  100.     add eax, 5
  101.     mov [y_pos], eax
  102.    
  103.     niks:
  104.     ret
  105. ENDP gravity
  106.  
  107. PROC go_right
  108.     USES eax
  109.     mov eax, [x_pos]
  110.     add eax, 5
  111.     mov [x_pos], eax
  112.     ret
  113. ENDP go_right
  114.  
  115. ; Set the video mode
  116. PROC setVideoMode
  117.     ARG @@A:byte
  118.     USES eax
  119.  
  120.     movzx ax, [@@A]
  121.     int 10h
  122.     ret
  123. ENDP setVideoMode
  124.  
  125. ; ; Fill the background (for mode 13h)
  126. PROC fillBackground
  127.     ARG @@fillcolor: byte
  128.     USES eax, ecx, edi
  129.  
  130.     mov edi, VMEMADR
  131.  
  132.     mov ecx, SCRWIDTH*SCRHEIGHT
  133.     mov al, [@@fillcolor]
  134.     rep stosb
  135.  
  136.     ret
  137.  
  138. ENDP fillBackground
  139.  
  140. ; ; Draw a rectangle (video mode 13h)
  141. PROC drawRectangle
  142.     ARG @@x0:word, @@y0:word, @@w:word, @@h:word, @@col:byte
  143.     USES eax, ecx, edx, edi
  144.  
  145.     mov edi, VMEMADR
  146.  
  147.     mov eax, SCRWIDTH
  148.     mul [@@y0]
  149.     add ax, [@@x0]
  150.     add edi, eax
  151.     push edi
  152.  
  153. drawhorizontal:
  154.     mov cx, [@@w]
  155.     mov al, [@@col]
  156.     rep stosb
  157.  
  158.     mov cx, [@@h]
  159.     pop edi
  160.  
  161. drawvertical:
  162.     stosb
  163.     add di, [@@w]
  164.     stosb
  165.     add edi, SCRWIDTH-2
  166.     sub di, [@@w]
  167.     loop drawvertical
  168.    
  169.     mov cx, [@@w]
  170.     mov al, [@@col]
  171.     rep stosb
  172.  
  173.     ret
  174. ENDP drawRectangle
  175.  
  176. PROC filledRectangle
  177.     ARG @@x0:word, @@y0:word, @@w:word, @@h:word, @@col:byte
  178.     USES eax, ecx, edx, edi
  179.  
  180.     mov edi, VMEMADR ;destpointer
  181.  
  182.     mov eax, SCRWIDTH
  183.     mul [@@y0]
  184.     add ax, [@@x0];juistzetten coördinaat
  185.     add edi, eax;coördinaat toevoegen aan de destpointer
  186.     push edi; bijhouden van de juiste startcoödinaat
  187.     mov cx, [@@h]; aantal benodigde interaties
  188.     @@draw:
  189.     push cx
  190.         @@drawline: ; opvullen van de rechthoek door steeds een lijn te tekken
  191.         pop edi; juiste startcoördinaat vastnemen
  192.         push edi; juiste startcoördinaat bijhouden
  193.         mov cx, [@@w]
  194.         mov al, [@@col]
  195.         rep stosb
  196.         loop @@drawline
  197.     pop cx
  198.     loop @@draw
  199.     ret
  200. ENDP
  201.  
  202. ; Terminate the program.
  203. PROC terminateProcess
  204.     USES eax
  205.     call setVideoMode, 03h
  206.     mov ax,04C00h
  207.     int 21h
  208.     ret
  209. ENDP terminateProcess
  210.  
  211.  
  212. PROC main
  213.     sti
  214.     cld
  215.  
  216.     push ds
  217.     pop es
  218.    
  219.     mov ecx, 5000
  220.     call    setVideoMode, 13h
  221.  
  222. @@drawloop:
  223.     mov ah, 0Ch
  224.     int 21h
  225.     call gravity
  226.     call fillBackground, 00FH
  227.     ;call filledRectangle, 0, [y_base], SCRWIDTH, 20, 0
  228.     call drawRectangle,[x_pos],[y_pos],10,20, 32
  229.  
  230.     call wait_VBLANK, 3
  231.     call check_for_input, 0071h,0064h, 007Ah , 001BH
  232.     loop @@drawloop
  233.    
  234.  
  235. ENDP main
  236.  
  237. ; -------------------------------------------------------------------
  238. DATASEG
  239.     palette     db 768 dup (?)
  240.     x_pos       dd 60
  241.     y_pos       dd 60
  242.     y_base      dd 180
  243.    
  244. ; -------------------------------------------------------------------
  245. ; STACK
  246. ; -------------------------------------------------------------------
  247. STACK 100h
  248.  
  249. END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement