944,080 Members | Top Members by Rank

Ad:
0

A86 draw shape

by on Sep 8th, 2009
compile using A86 assembler however you can adapt it for any other one easily... It just draws out a 3D like shape. It was annoying to get the angles right but suggestions on improvement to code is appreciated.

Adequately commented so it is understandable not fully as it is very repetitive..

NOTE: To use on vista DOSbox is required to enter graphical mode

~Jon~
Last edited by jhouns; Sep 8th, 2009 at 12:54 pm.
Assembly Code Snippet (Toggle Plain Text)
  1. ; ***********************************
  2. ; * *
  3. ; * A program that will draw a 3D'ish *
  4. ; * shape *
  5. ; * *
  6. ; ***********************************
  7.  
  8. jmp start ;start command
  9.  
  10. ;================================================
  11.  
  12. mode db 18 ;Resolution/Graphical mode
  13. colour db 1 ;1 = Blue
  14. a_x dw 100 ;Point a x coord
  15. a_y dw 100 ;Point a y coord
  16. b_x dw 100
  17. b_y dw 300
  18. c_x dw 180
  19. c_y dw 380
  20. d_x dw 250
  21. d_y dw 25
  22. e_x dw 332
  23. e_y dw 300
  24.  
  25. ;================================================
  26.  
  27. start:
  28. mov ah,00
  29. mov al,mode ;set graphic mode
  30. int 10h ;enter graphic mode
  31. mov ah,0Ch ;set write dot mode
  32. mov al,colour ;set the colour
  33. mov cx,a_x ;set point a
  34. mov dx,a_y
  35.  
  36. draw_a_b: ;draw line ab
  37. int 10h
  38. inc dx
  39. cmp dx,b_y
  40. jnz draw_a_b
  41.  
  42. prep_b_c: ;setup line bc
  43. mov cx,b_x
  44. mov dx,b_y
  45.  
  46. draw_b_c: ;draw line bc
  47. int 10h
  48. inc cx
  49. inc dx
  50. cmp cx,c_x
  51. jnz draw_b_c
  52. cmp dx,c_y
  53. jnz draw_b_c
  54.  
  55. prep_c_a: ;setup line ca
  56. mov cx,c_x
  57. mov dx,c_y
  58.  
  59. draw_c_a: ;draw line ca
  60. int 10h
  61. sub dx,7
  62. sub cx,2
  63. cmp dx,a_y
  64. jnz draw_c_a
  65. cmp cx,a_x
  66. jnz draw_c_a
  67.  
  68. prep_a_d: ;setup line ad
  69. mov cx,a_x
  70. mov dx,a_y
  71.  
  72. draw_a_d: ;draw line ad
  73. int 10h
  74. add cx,2
  75. sub dx,1
  76. cmp cx,d_x
  77. jnz draw_a_d
  78.  
  79. prep_c_e: ;setup line de
  80. mov cx,c_x
  81. mov dx,c_y
  82.  
  83. draw_c_e: ;draw line ce
  84. int 10h
  85. add cx,2
  86. sub dx,1
  87. cmp cx,e_x
  88. jnz draw_c_e
  89.  
  90. prep_d_e: ;setup line dw
  91. mov cx,d_x
  92. mov dx,d_y
  93.  
  94. draw_d_e:
  95. int 10h
  96. add dx,7
  97. add cx,2
  98. cmp cx,e_x
  99. jnz draw_d_e
  100.  
  101. GetKey:
  102. mov ah,00
  103. int 16h
  104.  
  105. end:
  106. mov ah,00
  107. mov al,03
  108. int 10h
  109. mov ah,04Ch
  110. mov al,00
  111. int 21h
Comments on this Code Snippet
Sep 8th, 2009
0

Re: A86 draw shape

Can you explain exactly what you want? Or what your problem is!

You are precarious, you draw a diagonal line but step +x,+y, check for x reaching the next waypoint axis exactly (zero flag check), but then check y. If y2-y1 is not equal to x2-x1 then you have a runaway. x is now past the axis and will continue until way off the screen and comes around again!

Instead of what you're doing, how about creating a function.
DrawLine( x1,y1, x2,y2 ). You can then create cool algorithms like a DDA
Assembly Syntax (Toggle Plain Text)
  1. dx = |x2-x1| dy=|y2-y1|
  2. if (dx < dy)
  3. // step dy
  4. else
  5. // step dx
Step on the longest axis and error correct on the sortest axis. Simple Binary math, and no wierd stepping logic.

If you track last x,y then you can also have a
DrawLineTo( x2, y2 )
Last edited by wildgoose; Sep 8th, 2009 at 2:39 pm.
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Sep 9th, 2009
0

Re: A86 draw shape

Hmm, interesting stuff there, i'll look at it for improvement. It wasn't that there was a problem but it was more made available for reference to those who are learning as it could be helpful
Newbie Poster
jhouns is offline Offline
8 posts
since Sep 2009
Message:
Previous Thread in Assembly Forum Timeline: i need help with getting started
Next Thread in Assembly Forum Timeline: Phases of Compilation on Compilers and Interpreters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC