News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Placing a pixel on the screen

Started by jamesadrian, October 01, 2017, 11:37:17 AM

Previous topic - Next topic

jamesadrian

I would like to specify one pixel at a time to be placed on the video monitor either absolutely on the physical screen or in a defined movable window.  I would like to specify its color with a number for each of red, green, and blue and specify its location with an x and y coordinate pair of numbers.  Is this possible in MASM?

Thank you for your help.

Jim Adrian
jim@futurebeacon.com

jj2007

Hi Jim,

SetPixel is what you need. Here is a very simple example (source & exe attached):

include \masm32\MasmBasic\Res\MbGui.asm         ; install the library
Event Paint
  For_ count=0 To 900
        invoke SetPixel, PtDC, count, 100, RgbCol(0, 0, count)     ; horizontal line
        invoke SetPixel, PtDC, count, count, RgbCol(count, 0, 0)   ; diagonal
        invoke SetPixel, PtDC, 100, count, RgbCol(0, count, 0)     ; vertical
  Next
GuiEnd


The program draws three coloured lines in a window. It may not look like "real" assembly, but it assembles fine with Masm 6.15 and higher or, better, UAsm.

felipe

Nice work jj! I will start looking closer your masmbasic work.  :bgrin:

aw27

Quote from: jj2007 on October 01, 2017, 12:08:53 PM
It may not look like "real" assembly
It looks a lot like Visual Basic, it may even compile with a VB compiler with small changes.

jj2007

Quote from: aw27 on October 01, 2017, 10:25:21 PM
Quote from: jj2007 on October 01, 2017, 12:08:53 PM
It may not look like "real" assembly
It looks a lot like Visual Basic, it may even compile with a VB compiler with small changes.

Syntax- and structure-wise MasmBasic is much closer to GfaBasic, Pascal resp. Delphi and, maybe, FORTRAN. Plus, it is assembly by definition, since you need MASM or its clones to translate it to machine code.

You seem not very familiar with the BASIC family. VB is an object oriented language, and far from the mainstream. IMHO it is underrated by the nerds - it is actually a fine dialect, and has Millions of satisfied users, mostly among those who are professionals (economists, scientists) but not professional coders.

aw27

Quote from: jj2007 on October 02, 2017, 01:18:39 AM
Quote from: aw27 on October 01, 2017, 10:25:21 PM
Quote from: jj2007 on October 01, 2017, 12:08:53 PM
It may not look like "real" assembly
It looks a lot like Visual Basic, it may even compile with a VB compiler with small changes.

Syntax- and structure-wise MasmBasic is much closer to GfaBasic, Pascal resp. Delphi and, maybe, FORTRAN. Plus, it is assembly by definition, since you need MASM or its clones to translate it to machine code.

You seem not very familiar with the BASIC family. VB is an object oriented language, and far from the mainstream. IMHO it is underrated by the nerds - it is actually a fine dialect, and has Millions of satisfied users, mostly among those who are professionals (economists, scientists) but not professional coders.
I was familiar with VB6 and can find my way with VB.net, I really never looked at GfaBasic. I like Delphi very much, even more than C/C++, although I recognize that Delphi can not beat them in speed and size it is as powerful and 10 times more productive (RAD).

jj2007

During my engineer's career, FORTRAN was the language of choice - and it still is for many people. I know some top notch economists who continue to use Fortran for their modelling work.

Fortran, Basic (FB, VB, ..., MB), Python and Pascal and Delphi have in common that you don't have to be a professional coder to use them. Therefore scientists use them for the programming aspects of their work, since they don't want to waste their time diving into the jungle of C++ and friends. Most scientists do not have a budget to hire a professional coder, and/or the time and energy to explain a complex scientific task to a nerd. That is why the two families of programming languages, "hobby" vs "professional", will probably co-exist forever.

aw27

Quote from: jj2007 on October 02, 2017, 02:00:45 AM
That is why the two families of programming languages, "hobby" vs "professional", will probably co-exist forever.
There is more to it.
What they tell you to use is not necessarily what they use themselves. Microsoft does not use C# in any serious internal development and never used the MFC (Microsoft Foundation Classes) in serious C++ development. Even these days, people confuse C++ with MFC and hate it for that.
However, C# gained ground with "professional" programmers, not only hobbyists, who work inside organizations because allow them to show results fast and time is money in most cases.

hutch--

From what I have seen over the years, both C and C++ without the consumer level crap produce high quality binaries if they are written properly but as soon as you start trying to buy into layers of abstraction with OOP(S), your code turns to bloated crap full of unfixable bugs. I have seen applications over time that are a massive size, slow as a wet week, full of bugs and with very limited functionality and it is the consequence of junky development environments cobbled together by amateurs. I have also seen apps that were written in C that turned to junk when the later versions were written in C++.

I have a favourite image application that dates from 2001, Micrografx Picture Publisher has been a good performer for many years but as Microsoft keep changing the rules, it is becoming harder and harder to keep it going. Corel bought them out in about 2001 and trashed the product line.

A friend of mine from PowerBASIC coined the phrase HOP (hardware oriented programming) as the viable alternative to OOP(S) and its a view I hold. I use a couple of 32 bit basic compilers as they have a very good inline assembler in them where I can port 32 bit assembler back and forth between MASM and PowerBASIC but to date it looks like a very long time until they produce a 64 bit version so I just write 64 bit in MASM.