A86 draw shape

jhouns 0 Tallied Votes 2K Views Share

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~

; ***********************************
; *                                                                  *
; *       A program that will draw a 3D'ish       *
; *                            shape                            *
; *                                                                  *
; ***********************************

jmp start			;start command

;================================================

mode	db	18		;Resolution/Graphical mode
colour	db	1		;1 = Blue
a_x	dw	100		;Point a x coord
a_y	dw	100		;Point a y coord
b_x	dw	100
b_y	dw	300
c_x	dw	180
c_y	dw	380
d_x	dw	250
d_y	dw	25
e_x	dw	332
e_y	dw	300

;================================================

start:
 mov ah,00
 mov al,mode			;set graphic mode
 int 10h			;enter graphic mode
 mov ah,0Ch		        ;set write dot mode
 mov al,colour			;set the colour
 mov cx,a_x			;set point a
 mov dx,a_y			

draw_a_b:			;draw line ab
 int 10h
 inc dx
 cmp dx,b_y
 jnz draw_a_b

prep_b_c:			;setup line bc
 mov cx,b_x
 mov dx,b_y

draw_b_c:			;draw line bc
 int 10h
 inc cx
 inc dx
 cmp cx,c_x
 jnz draw_b_c
 cmp dx,c_y
 jnz draw_b_c 

prep_c_a:			;setup line ca
 mov cx,c_x
 mov dx,c_y

draw_c_a:			;draw line ca
 int 10h
 sub dx,7
 sub cx,2
 cmp dx,a_y
 jnz draw_c_a
 cmp cx,a_x
 jnz draw_c_a
 
prep_a_d:			;setup line ad
 mov cx,a_x
 mov dx,a_y

draw_a_d:			;draw line ad
 int 10h
 add cx,2
 sub dx,1
 cmp cx,d_x
 jnz draw_a_d

prep_c_e:			;setup line de
 mov cx,c_x
 mov dx,c_y

draw_c_e:			;draw line ce
 int 10h
 add cx,2 
 sub dx,1
 cmp cx,e_x
 jnz draw_c_e

prep_d_e:			;setup line dw
 mov cx,d_x
 mov dx,d_y

draw_d_e:
 int 10h
 add dx,7
 add cx,2
 cmp cx,e_x
 jnz draw_d_e

GetKey:
 mov ah,00
 int 16h

end:
 mov ah,00
 mov al,03
 int 10h
 mov ah,04Ch
 mov al,00
 int 21h
wildgoose 420 Practically a Posting Shark

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

dx = |x2-x1|      dy=|y2-y1|
if (dx < dy)
    // step dy
else
   // 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 )

jhouns 0 Newbie Poster

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.