News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

drawing

Started by nrdev, May 25, 2009, 04:51:58 PM

Previous topic - Next topic

nrdev

it is ok I don't want anyone to write entire program for me, I need this code working so I can get started.

nrdev

Quote
LINE
       Function         Draw a straight line between two points

       Entry            SI      Address of LINE parameter block
                        [SI]     X1
                        [SI+2]   Y1
                        [SI+4]   X2
                        [SI+6]   Y2
                        [SI+8]   BYTE,   Colour
                        [SI+14]   Address of dot plotting routine
                        [SI+16]   Number of pixels/line
                        [SI+18]   Number of bytes/line
                        [SI+20]   Number of lines/screen
                        [SI+22] 0 = pixel replace; 2 = XOR pixel
                        [SI+24] DWORD Address of the memory bank select routine
                         ES     Address of start of video memory

This is what is written in GLIB library that tried to use but I'am very confused by these definitions, how should I use this command for example with masm

dedndave

honestly, i don't think i would try to use that library directly
you might, however, look at the asx files and see how some of the routines work
having looked at a few of them - not sure what you'd gain from it
drawing a line is a fun project

the first thing a line-draw routine should do is to test for special cases
if X length is 0, it is a straight up and down line - very simple
if Y length is 0, it is a straight left and right line - even simpler

next, see whether the X axis is longer than the Y axis
if X is longer, calculate a Y pixel address for each X in the line
if Y is longer, calculate a X pixel address for each Y in the line
if X length is the same as the Y length (45, 135, 225, 315 degrees), you can use either loop to draw the line
you could even make a special loop for these lines if you want it to be faster

to calculate points, use the formulas

Y = mX+b
X = (Y-b)/m

then - calculate the pixel address as i outlined in the earlier post


http://www.wtamu.edu/academic/anns/mps/math/mathlab/int_algebra/int_alg_tut15_slope.htm

Jimg

Quote from: nrdev on May 26, 2009, 10:34:54 AM
QuotePerhaps you can get some hints from this.

It is what I want but the code doesn't work, I see that it is slightly different from other source codes that I was able to see. What I need to do to make this code work

Taking a quick look, I think it's in Tasm.  You'd have to convert it to Masm if that's what you are using.  I assumed if you were going to try something this complicated, you would be more advanced (than me even, I wouldn't try it).  So I think this is all way beyond your skill level at this point.  I still don't understand why you are doing this, but good luck.

FORTRANS

Hi,

   Well, for a simple example, here is a program to draw circles.  Just
to show why people use Bresenham's algorithm, I guess.

Steve N.


        PAGE ,132
TITLE Circle16
NAME  Circle16
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Example of drawing a circle, SRN 26 May 2009.
; Draw a circle using the equation:  R*R =  X*X + Y*Y.  No trig.

; MASM Circle16;
; LINK Circle16;
; EXE2BIN Circle16.EXE Circle16.COM

CODE    SEGMENT
        ASSUME  CS:CODE,DS:CODE
        ORG     100H ; COM file opening
START:
        MOV     AX,CS   ;\ If run as an EXE...
        MOV     DS,AX   ;/
        JMP     Setup

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Data for main program and circle routine.

CenterX DW      319     ; Center of circle
CenterY DW      239
Radius  DW      200     ; Initial size of circle.
Radius2 DW      40000, 0

MinX    DW      119     ; Area to scan.
MaxX    DW      519
MinY    DW      39
MaxY    DW      439

ColorIn DW      2       ; Choose your colors.
ColorOn DW      15      ; Try 15 and 3, to go with 1 and 2.
ColorOut DW     1       ; 15 seems fun, 3 looks smoother.

usX     DW      ?       ; Work temporaries
usY     DW      ?
Hello   DB      ' Hit a key. $'

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Main program, setup and scan over area calling the plot circle routine.
Setup:
        MOV     AH,0    ; BIOS Set Video Mode function
        MOV     AL,12H  ; 640x480x16 video mode
        INT     10H     ; Video BIOS interrupt

; Wait for things to settle down, get user to hit a key.
        MOV     DX,OFFSET Hello
        MOV     AH,9    ; DOS Out String Fn
        INT     21H

        MOV     AH,10H  ; Read Extended Keyboard Input.
        INT     16H     ; {Just used for a pause.}

; - - - MAIN LOOP OF PROGRAM - - -
; Could make a loop to reduce radius.
Main1:

; - - - Y / Row loop - - -
        MOV     CX,[MaxY]
        SUB     CX,[MinY]
        INC     CX      ; Count of rows.
        MOV     AX,[MinY]
        MOV     [usY],AX
Main2:
        PUSH    CX

; - - - X / Column loop - - -
        MOV     CX,[MaxX]
        SUB     CX,[MinX]
        INC     CX      ; Count of columns.
        MOV     AX,[MinX]
        MOV     [usX],AX
Main3:
        PUSH    CX
        CALL    CirclePl

        INC     [usX]
        POP     CX
        LOOP    Main3   ; X loop

        INC     [usY]
        POP     CX
        LOOP    Main2   ; Y loop

; Wait for user to hit a key.
        MOV     AH,10H  ; Read Extended Keyboard Input.
        INT     16H     ; AL = ASCII, AH = Scan code

        CMP     AL,27   ; An attempt to leave early?
        JE      Reset_Vid ; Escape!

; - - - What the heck... - - -
; Reduce radius, update Radius2, test, and loop to Main1.
        MOV     AX,[Radius]
        DEC     AX
        JL      Reset_Vid
        MOV     [Radius],AX
        MUL     AX
        MOV     [Radius2],AX
        MOV     [Radius2+2],DX
        JMP     Main1

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Exit processing, DON'T leave in graphics mode under Win2k or XP.
RESET_VID:
        MOV     AH,0
        MOV     AL,3    ; = Standard video mode 3
        INT     10H ; Set Video mode

        MOV     AH,4CH
        MOV     AL,0
        INT     21H     ; Exit to DOS

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Circle plotting the _SLOW_ way.
CirclePl:
        MOV     AX,[usX]
        SUB     AX,[CenterX]    ; Delta X
        IMUL    AX              ; dX * dX
        MOV     BX,AX
        MOV     CX,DX

        MOV     AX,[usY]
        SUB     AX,[CenterY]    ; Delta Y
        IMUL    AX              ; dY * dY

        ADD     BX,AX           ; Form R * R in CX:BX.
        ADC     CX,DX
; - - -
        MOV     AX,[ColorOut]
        CMP     CX,[Radius2+2]  ; Compare R*R to Radius2.
        JE      Circ1           ; Always for initial version of code.
        JA      Circ3           ; Confirm out.
        MOV     AX,[ColorIn]    ; It's inside.
        JMP     Circ3

; - - -
Circ1:  ; High word equal, test low word.
        CMP     BX,[Radius2]
        JA      Circ3           ; Confirm out.
        JE      Circ2           ; It's on the circle?
        MOV     AX,[ColorIn]    ; Else it is inside.
        JMP     Circ3
Circ2:
        MOV     AX,[ColorOn]

; - - - And plot the pixel - - -
Circ3:
        AND     AL,0FH  ; Ensure valid color.
        MOV     DX,[usY]
        MOV     CX,[usX]
        MOV     BX,0    ; Page #
        MOV     AH,0CH  ; Write pixel BIOS function
        INT     10H     ; Video BIOS interrupt

        RET     ; End CirclePl

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CODE    ENDS
        END START

nrdev

 :(
I have tried to do something about this but unfortinetually I give up, this is too hard for me to do, and understand.
I could make much better success in 32-bit programming then in 16-bit.

Jimg

You'll never regret it. :U

PBrennick

nrdev,

Actually, I think you are confused as to what is the difference between a 16-bit dos program that will run in a dos window and a 32-bit console program. They are apples and oranges.  Both run in a console box, only one of those console boxes is a dos box.

Paul
The GeneSys Project is available from:
The Repository or My crappy website