Advertisement
Guest User

Untitled

a guest
May 14th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. P8086
  2.  
  3. MyStack segment stack
  4.   DB 64 dup('12345678')
  5. MyStack endS
  6. MyData segment
  7.   ; --- Declare your variables here ---
  8.   prompt1 DB "Which background? (0-31): $"
  9.   prompt2 db "Which palette? (0-1): $"
  10.   back db 01h
  11.   pal db 01h
  12.   cpixl db 0c0h
  13.   cmask db 03fh
  14.   xpos dw 160
  15.   ypos dw 100
  16.   color db 03h
  17.   MyData endS
  18. MyCode segment                                  ; Sets up the segment names for
  19.  Assume CS:MyCode,ES:MyData    
  20. include CONIO.INC
  21. include time.inc
  22.  
  23.  
  24. GetMask proc
  25. mov ax,xpos
  26. mov bl,04h
  27. div bl
  28. mov cl,3
  29. sub cl,ah
  30. mov ah,color
  31. shl ah,cl
  32. shl ah,cl
  33. mov cpixl,ah
  34. mov ah,03h
  35. shl ah,cl
  36. shl ah,cl
  37. not ah
  38. mov cmask,ah
  39. ret
  40. GetMask endp
  41.  
  42. CheckKeys proc
  43. mov ah,08h
  44. int 21h
  45. cmp al,48h
  46. je up
  47. cmp al,4bh
  48. je left
  49. cmp al,4dh
  50. je right
  51. cmp al,50h
  52. je down
  53. jmp keysEnd
  54. ;We can butcher ax now. Yay.
  55. up:
  56. cmp ypos,00h
  57. jle keysEnd
  58. dec ypos
  59. mov ax,ypos
  60. mov bl,02h
  61. div bl
  62. cmp ah,0
  63. je evenUp
  64. add di,02000h
  65. sub di,80 ; 320/4
  66. jmp keysEnd
  67. evenUp:
  68. sub di,02000h
  69. jmp keysEnd
  70.  
  71.  
  72. left:
  73. cmp xpos,0
  74. jle keysEnd
  75. dec xpos
  76. mov ax,xpos
  77. mov bl,04h
  78. div bl
  79. cmp ah,3
  80. jne keysEnd
  81. sub di,1
  82. jmp keysEnd
  83.  
  84. right:
  85. cmp xpos,319
  86. jge keysEnd
  87. inc xpos
  88. mov ax,xpos
  89. mov bl,04h
  90. div bl
  91. cmp ah,0
  92. jne keysEnd
  93. add di,1
  94. jmp keysEnd
  95.  
  96. down:
  97. cmp ypos,199
  98. jge keysEnd
  99. inc ypos
  100. mov ax,ypos
  101. mov bl,02h
  102. div bl
  103. cmp ah,0
  104. je evenDown
  105. add di,02000h
  106. jmp keysEnd
  107. evenDown:
  108. sub di,02000h
  109. add di,80 ; 320/4
  110. keysEnd:
  111. ret
  112. CheckKeys endp
  113.  
  114. clearscreen proc
  115. push di
  116. mov di,0
  117. MOV CX,320*200         
  118.  
  119. FillScreenLoop:
  120.      MOV BYTE PTR [DI],00h 
  121.  inc di    
  122.  LOOP FillScreenLoop
  123. pop di
  124. ret
  125. clearscreen endp
  126.  
  127. sketch proc
  128. mov ah,0
  129.   mov al,04h
  130.   int 10h
  131.   mov ah,0Bh
  132.   mov bh,0
  133.   mov bl,back
  134.   int 10h
  135.   mov ah,0Bh
  136.   mov bh,1
  137.   mov bl,pal
  138.   int 10h
  139.   MOV AX,0B800h
  140.   MOV DS,AX
  141.   mov di,0fc8h
  142.  
  143.  
  144.  loopy:
  145.  mov bl,BYTE PTR [DI]
  146.  and bl,cmask
  147.  or bl,cpixl
  148.  mov BYTE PTR [DI],bl
  149.  MOV AH,08h
  150.  INT 21h   
  151.  cmp al,1bh
  152.  je quit
  153.  cmp al,09h
  154.  jne noTab
  155.  inc color
  156.  cmp color,3
  157.  jle noTab
  158.  mov color,0
  159.  noTab:
  160.  cmp al,20h
  161.  jne noClear
  162.  call clearScreen
  163.  noClear:
  164.  cmp al,00h
  165.  jne ender
  166.  call checkKeys
  167.  call getMask
  168.  ender:
  169.  
  170.  jmp loopy
  171.  quit:
  172.  MOV AH,0
  173.       MOV AL,03h                    ;Restore the screen mode to 03h (the text screen).
  174.       INT 10h
  175. ret
  176. sketch endp
  177.  
  178. Main PROC                                      ; Main procedure
  179.   Start:    
  180.   MOV AX, MyData                              
  181.   MOV ES, AX  
  182.   mov DS, AX
  183.   enterBG:
  184.   MOV AH,9
  185.  
  186.   LEA DX,ES:prompt1             ; Let DS:DX = offset of "prompt" within DS.
  187.   INT 21h
  188.   CALL InputDecWord
  189.   cmp al,31
  190.   jg enterBG
  191.   cmp al,0
  192.   jl enterBG
  193.   mov back,al
  194.   enterPal:
  195.   MOV AH,9
  196.   LEA DX,ES:prompt2             ; Let DS:DX = offset of "prompt" within DS.
  197.   INT 21h
  198.   CALL InputDecWord
  199.   cmp al,1
  200.   jg enterPal
  201.   cmp al,0
  202.   jl enterpal  
  203.   mov pal,al
  204.  
  205.  
  206.   call sketch
  207.   mov ah, 4ch
  208.   xor al, al
  209.   int 21h  
  210. Main ENDP
  211.  
  212. MyCode endS
  213. End Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement