Author Topic: As simple as it gets  (Read 4276 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
As simple as it gets
« on: September 23, 2007 »
I searched to find some tutorials on the internet to do the most basic thing of all.. Plot a single pixel.

I could not find anything and I realise that a lot of people here like me have either a very basic understanding of asm and would like to know more.

So here is some code that just plots a dot :)

It's written with Fasm.
Now you can plot a dot you can do anything :)

Code: [Select]
;-------------------------------------------------------------------------------------------
;       How to plot a pixel in assembly language.
;       Written in Fasm by shockwave ^ s!p
;       This is just a very, very basic tutorial
;       Yes, it's simple but it needed doing :P
;       To help newbies to get something actually drawn on screen.
;-------------------------------------------------------------------------------------------

        org  100h       ; Set up mode 13h (VGA 320 X 200 ).
        mov  ax,13h
        int  10h

;-------------------------------------------------------------------------------------------

        colour  db   10  ; Colour number (byte).
        xposi   dw   120 ; Xpos to plot  (word).
        yposi   dw   120 ; Ypos to plot  (word).

main:                  ; Main Loop.

;-------------------------------------------------------------------------------------------

plot:
        mov ah,0ch       ; We need to put 0ch into ah to tell it it's plotting a pixel.
        mov al,[colour]  ; The square brackets indicate that we load the contents and NOT the address.
        mov bh,0         ; Page number.
        mov cx,[xposi]   ; Put the Xpos to plot into cx.
        mov dx,[yposi]   ; And the Ypos into dx.
        int 10h


;-------------------------------------------------------------------------------------------

        in al,60h      ; Escape Pressed?
        dec al
        jnz main       ; If not, go back to main.


;-------------------------------------------------------------------------------------------

        mov ax, 4c00h  ; Put things back to normal so we don't get an error on exit.
        int 21h
Shockwave ^ Codigos
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1398
  • Karma: 108
    • View Profile
    • http://www.secretly.de
Re: As simple as it gets
« Reply #1 on: September 23, 2007 »
please note that its old 16 bit coding... and 13h screenmode, which is not up to date... its nothing you can use for DX, OGL or something... so i think its nearly useless today...  probally only usefull if someone still code DOS 13h mode related stuff...
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: As simple as it gets
« Reply #2 on: September 23, 2007 »
You are wrong there. Plenty of 256 byte intros are released in 13h.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: As simple as it gets
« Reply #3 on: September 23, 2007 »
And in fact it's something I am very interested in doing for myself... Ok, the best tiny code intros use GL + DX, but unless I am mistaked, there is absolutely no way to initialise DX or GL in 256 bytes and it's this discipline of code that I am really interested in exploring.

If you think it is outdated, go to intro-inferno and search for anything by wamma.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1398
  • Karma: 108
    • View Profile
    • http://www.secretly.de
Re: As simple as it gets
« Reply #4 on: September 23, 2007 »
ah, if its for 256 byte intro then i have nothing said ^^
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: As simple as it gets
« Reply #5 on: September 23, 2007 »
I really think that Tiny code is having a huge revival.

The cutting edge stuff at 1-4kb is being done by guys like Chris, Mentor and Rbraz, there is a whole culture of sceneres who write things in <512 bytes, like yObi, Pirx, Tigrou, etc etc..

For me, it seems logical to explore this, because I have a lot of interest in pixel bashing :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: As simple as it gets
« Reply #6 on: September 23, 2007 »
I agree there is plenty of life left in DOS tiny code is the only way to get demos down to tiny size. I was very impressed by the tiny code over at Intro Inferno

Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: As simple as it gets
« Reply #7 on: September 28, 2007 »
OK on this subject, lets say I've decided to dance with the devil and would like to spend the next year learning assembler. Specifically I want to add 32 bit (windows) ASM to my windows C programs. OK given that...can anyone recommend a _good_ book on learning ASM? The top rated book at amazon is geared towards GCC which is not my interest right now.

Chris
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4380
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: As simple as it gets
« Reply #8 on: September 28, 2007 »
@Chris:
Some years ago I also tried to learn some assembly and searched in our library
for some printed books. Didn't really find something interesting. Here are some
tutorials in the internet - which I bookmarked. The best thing I can recommend
is the e-book by Dr.Paul Carter. This was really useful for me and I printed this
out. But I guess this might be far too basic (especially the first chapters) for you.

Anyway, here are some links :

http://www.drpaulcarter.com/pcasm/

http://www.df.lth.se/~john_e/fr_contrib.html

http://www.csn.ul.ie/~darkstar/assembler/
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: As simple as it gets
« Reply #9 on: September 28, 2007 »
Download the manuals from Intel. http://www.intel.com/products/processor/manuals/index.htm
Intel® 64 and IA-32 Architectures Software Developer's Manual, Volumes 1,2A,2B,3A,3B contain everything about the Intel CPUs.

Next thing then is to look up Windows ABI, so you can call the functions in there.
You're looking for stdcall if you want to call Windows stuff.
http://www.programmersheaven.com/2/Calling-conventions

Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17376
  • Karma: 497
  • evil/good
    • View Profile
    • My Homepage
Re: As simple as it gets
« Reply #10 on: September 29, 2007 »
All I have done is look at a few simple tutorials about the registers and interrupts, I guess I'll be looking at the manuals that jim suggested myself as a next step.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: As simple as it gets
« Reply #11 on: September 30, 2007 »
Interrupts, all of them http://www.ctyme.com/rbrown.htm :)

Jim
Challenge Trophies Won:

Offline donvito

  • n00bzor
  • ZX 81
  • *
  • Posts: 15
  • Karma: 1
  • programming <3
    • View Profile
Re: As simple as it gets
« Reply #12 on: March 03, 2008 »
sweet shockwave!

i have a wierd issue though, maybe its just something that isnt supposed to be done...

if i add,

add [colour], 1
and/or
inc [xposi]

it works, but i cannot exit.  is that because its looping too much or overflowing the memory or something?

thanks for the help guys
donvito

Offline Agent Smith

  • ZX 81
  • *
  • Posts: 24
  • Karma: 3
    • View Profile
Re: As simple as it gets
« Reply #13 on: March 03, 2008 »
I can't see how that program works at all  ???
Won't the data variables be interpreted as opcodes, and executed as such when control returns from initial int 10h ?

I think maybe a jmp over them is needed, or locate them after the executable code.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: As simple as it gets
« Reply #14 on: March 03, 2008 »
Well spotted Smith I think you got it

Challenge Trophies Won:

Offline donvito

  • n00bzor
  • ZX 81
  • *
  • Posts: 15
  • Karma: 1
  • programming <3
    • View Profile
Re: As simple as it gets
« Reply #15 on: March 03, 2008 »
hmm thats wierd...

i dont really fully understand the code, but if you inc the color or coords, it will make a cool looking "bars" effect.  its just wierd because i was in class and i tried that and it worked without a lockup, but on my comp at home, it locked up hard, and i had to do a hard-reboot.

donvito

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: As simple as it gets
« Reply #16 on: March 03, 2008 »
There's a bug in there as Agent Smith says.  You need to add 'jmp main' after 'int 10h', and then you need to make sure you modify the colour in the right place ie.
Code: [Select]
;-------------------------------------------------------------------------------------------
;       How to plot a pixel in assembly language.
;       Written in Fasm by shockwave ^ s!p
;       This is just a very, very basic tutorial
;       Yes, it's simple but it needed doing :P
;       To help newbies to get something actually drawn on screen.
;-------------------------------------------------------------------------------------------

        org  100h       ; Set up mode 13h (VGA 320 X 200 ).
        mov  ax,13h
        int  10h

        jmp main        ;Jim added this else it executes the data below as instructions!

;-------------------------------------------------------------------------------------------

        colour  db   10  ; Colour number (byte).
        xposi   dw   120 ; Xpos to plot  (word).
        yposi   dw   120 ; Ypos to plot  (word).

main:                  ; Main Loop.

;-------------------------------------------------------------------------------------------

plot:
        mov ah,0ch       ; We need to put 0ch into ah to tell it it's plotting a pixel.
        mov al,[colour]  ; The square brackets indicate that we load the contents and NOT the address.
        mov bh,0         ; Page number.
        mov cx,[xposi]   ; Put the Xpos to plot into cx.
        mov dx,[yposi]   ; And the Ypos into dx.
        int 10h

;Jim - modify the colour values here.  If you do it later you will not be able to exit properly.

;-------------------------------------------------------------------------------------------

        in al,60h      ; Escape Pressed?
        dec al
        jnz main       ; If not, go back to main.


;-------------------------------------------------------------------------------------------

        mov ax, 4c00h  ; Put things back to normal so we don't get an error on exit.
        int 21h

Jim
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: As simple as it gets
« Reply #17 on: March 03, 2008 »
If you just wanna have a look at asm I suggest looking up emu8086
http://www.emu8086.com/

comes with lotsa examples and a great debugger (one of the best debugger around) sadly it doesnt support 32bit instructions but its a nice easy sandbox to learn basic asm stuff. If you still like it try FASM.
The advantage with emu8086 for learning is that you can run each instruction examine what has happened then run the next instruction so you will soon see what is going wrong

Challenge Trophies Won: