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

When you were doing an 16 bit dos application (other forum members) it is very possible that is has graphics in it, so what have you done to make that.

jj2007

Now I am getting curious :bg

This assembles and links fine (with Link16.exe) but refuses to show me a line. Since I am an absolute noob in DOS, that is probably my fault. But maybe it serves to overcome the first hurdle... see a pixxxxel :wink

.model tiny

.data?
MyX dw ?
MyY dw ?

.code
org 100h
start:

mov AX,13H ; 320 x 200 x 256 colors
; mov AX,12H ; 640 x 480 x 16 colors
INT 10H ; Video interrupt.

and MyX, 0
and MyY, 0

@@: mov AH, 0Ch ; Set pixel function.
mov AL, 1 ; [Color] ; Pixel value or color
mov BH, 0 ; Page for some modes.
mov CX, MyX ; [Column] ; X-coordinate
mov DX, MyY ; [Row] ; Y-coordinate
INT 10H
inc MyX
inc MyY
cmp MyX, 200
jne @B

mov AX, 3 ; = Standard video mode 3, reset to text at the end.
INT 10H

ret
end start


I have a suspicion that JimG and Dave could help out ;-)

nrdev

You wrote the basic VGA tutorial done on the hard way

I have found this tutorial that I have modified to work on masm, but it donesn't help me to know how to make line, rectangle, filled rectangle, and a single point.



.model small
.dosseg
.stack 512
.code
.186

; --- main program loop ---
_main   proc    near

           mov  ax,0012h                    ; set mode to 640x480x16
           int  10h

           mov  ax,0A000h
           mov  es,ax
           
           ; start line from (0,0) to (639,479)
           mov  X,0001h                     ; top most pixel (0,0)
           mov  Y,0001h                     ;
           mov  Color,02h                   ; start with color 0
           mov  cx,480                      ; 480 pixels
DrawLine:  call putpixel                    ; put the pixel
           inc  X                           ; move down a row and inc col
           inc  Y                           ;
           ;inc  Color                      ; next color
           ;and  Color,0Fh                  ; 00h - 0Fh only
           loop DrawLine                    ; do it

           
           xor  ah,ah                       ; wait for key press
           int  16h

           mov  ax,3                     ; return to screen 3 (text)
           int  10h

_main endp


; on entry X,Y = location and C = color (0-15)
putpixel   proc near uses ax bx cx dx

; byte offset = Y * (horz_res / 8) + int(X / 8)

           mov  ax,Y                        ; calculate offset
           mov  dx,80                       ;
           mul  dx                          ; ax = y * 80
           mov  bx,X                        ;
           mov  cl,bl                       ; save low byte for below
           shr  bx,03                       ; div by 8
           add  bx,ax                       ; bx = offset this group of 8 pixels

           mov  dx,03CEh                    ; set to video hardware controller

           and  cl,07h                      ; Compute bit mask from X-coordinates
           xor  cl,07h                      ;  and put in ah
           mov  ah,01h                      ;
           shl  ah,cl                       ;
           mov  al,08h                      ; bit mask register
           out  dx,ax                       ;

           mov  ax,0205h                    ; read mode 0, write mode 2
           out  dx,ax                       ;
           
           mov  al,es:[bx]                  ; load to latch register
           mov  al,Color
           mov  es:[bx],al                  ; write to register

           ret
putpixel   endp

X          dw 00h
Y          dw 00h
Color      db 00h

end


Jimg

Okay, I see, that's using dos 16m protected mode run-time.

The real question is, why would you want to subject yourself to that much pain?

How many people still have non-windows hardware that would be your target audience?

Anyway, I'm just going to slink out of here now.  Good luck with everything.


FORTRANS

Hello jj2007,

   Your program works for me.  Diagonal blue line.
I had to run it in DEBUG to stop it from exiting and
reseting to text mode.

Steve N.

FORTRANS

Quote from: nrdev on May 25, 2009, 08:38:53 PM
I have found this tutorial that I have modified to work on masm, but it donesn't help me to know how to make line, rectangle, filled rectangle, and a single point.

Hi,

   Probably the best way to learn all that is the book "Programmer's
Guide to PC Video Systems", second edition, by Richard Wilton, ISBN
1-55615-641-3.  Very good code explained well.  I found a ZIP file
of the first edition somewhere.  But the figures were missing.

Regards,

Steve N.

MichaelW

#21
Ron Thomas has a nice tutorial that covers the basics.

http://www.ronthomas.plus.com/

Navigate to the downloads page and click the Gbook.zip link.

And in case there is a problem, here is a direct link:

http://www.ronthomas.plus.com/Downloads.html
eschew obfuscation

dedndave

with mode 13h, it is easier and much faster to update the video buffer directly

the buffer for 13h (the one i used) is A000:0000-F9FF
one byte = one pixel
there are 256 palette registers - 3 bytes each (r,g,b) - each byte is 0-3Fh (only 6 bits used for each color)
the function to set the palette registers is int 10h, function 1002h
so - set up the palette as you like - then the pixel byte values are indexes into the palette

Addr = 320 * Y + X
(x,y 0,0 = upper left corner of screen)
set the ES register to A000h and away you go

Jimg

I really had to dig into some old archives for this, but it looks like what you were asking for, circles, filled recs, etc.

Heres a sample out of of an example program-


;****************** Main Loops

loop1:      call do_rand            ;Pixels
            lcall putpix ax,bx
            lnk loop1
            lcall cls

loop2:      call do_rand            ;Lines
            lcall line ax,bx,cx,dx
            lnk loop2
            lcall cls

loop3:      call do_rand            ;Rectangles
            lcall rect ax,bx,cx,dx
            lnk loop3
            lcall cls

loop4:      call do_rand            ;Filled Rectangles
            lcall frect ax,bx,cx,dx
            lnk loop4
            lcall cls

loop5:      call do_rand            ;Circles
            lcall circle ax,bx,si
            lnk loop5
            lcall cls

loop6:      call do_rand            ;Ellipses
            lcall ellipse ax,bx,si,di
            lnk loop6
            lcall cls

loop7:      call do_rand            ;Filled Circles
            lcall fcircle ax,bx,si
            lnk loop7
            lcall cls

loop8:      call do_rand            ;Filled Ellipses
            lcall fellipse ax,bx,si,di
            lnk loop8
            lcall cls

loop9:      call do_rand            ;Triangles
            push ax bx cx dx
            call do_rand
            lcall triangle ax,bx
            lnk loop9
            lcall cls


Comes with full source code for the library.  Perhaps you can get some hints from this.


[attachment deleted by admin]

sinsi

jj, you need an 'inkey' before you switch back to text mode otherwise you won't see anything -

;wait for a keypress
  sub ah,ah
  int 16h
;back to text mode
  mov ax,3
  int 10h
;quit to DOS - this is better than 'ret'
  mov ah,4ch
  int 21h

Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

wow Jim - that is an interesting library
they do trig fuctions in fixed-point
i have one i wrote years ago
it uses floating point - but the format does not match that of intel float
about that time, 486's came out and everyone had fpu's built in so i abandoned the project
if i were to continue it, i would want to go through the entire library and convert it to intel float

jj2007

Quote from: sinsi on May 26, 2009, 02:44:28 AM

jj, you need an 'inkey' before you switch back to text mode otherwise you won't see anything -


Yep, that's it - I knew you are my friend!! :U

sinsi

Quote from: jj2007 on May 26, 2009, 05:59:28 AMYep, that's it - I knew you are my friend!! :U
heh heh
Light travels faster than sound, that's why some people seem bright until you hear them.

nrdev

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

dedndave

QuoteWhat I need to do to make this code work

we will help you in many ways
we can point you in the right direction to get going
but, we aren't going to write the code for you
and - you aren't going to become an expert programmer in 3 days
i started writing assembly language programs before IBM made PCs
when it comes to 32-bit code and the windows API, i am a newbie
although, i will learn faster than most because of experience

start out, as most of us did, by reading tutorials and making simple programs
then, expand on your knowledge by trying different things
we have given you a number of resources from which to learn - use them