Author Topic: Assembly Language - 2D  (Read 5286 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17426
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Assembly Language - 2D
« on: May 02, 2006 »
Original post by Coder, taken from DBF ezboard forum.

Assembly Language - 2D 
Is there any way to do 2D directly in asm without using an external dll?
I haven't been able to find much on this kind of stuff. Obviously, I just want
some way to plot a coloured pixel. Nothing more really, actually :P

But thanks to rbraz with all his help on OpenGL 3D stuff in Assembly
Language. :) I pulled together a little test after studying his tutorial for a
while :D Its a little thing thats like Face from Nickelodeon. :P (A picture of
face can be found here: www.danelle.blogspot.com/images.jpg - just
a random google search for a pic, I don't know the site XD)

Yeah, I've been looking for this kind of thing for a while, wanting to put out
a mini 256b or some kind less than 1k just for fun :P Its seems like a nice little
challenge.

By the way, I'm using t0a as an assembler. (Actually, the funny thing is that
I'm developing on Linux, and using WINE to run the assembler and my
binaries :P)

Thanks :)

Edited by: coder at: 18/3/06 2:26
rbraz
CBM 128

Posts: 143
(18/3/06 18:37)
Reply
   Re: Assembly Language - 2D No problems dude :)

For doing 256 byte in assembly, the best way is using DOS VGA Mode X (try to find more info about it using Mr. Google)

I've coded a simple sample for you and other people that start learning asm language, compile with "t0a sample.asm +com"

Good luck!


Code: [Select]
.CPU 386
.BITS 16
.ENTRYPOINT
;---------------------------------------------------

 mov al,13h    ; VGA mode X
 int 10h       ; 320x200x256

 push 0a000h   ;  Vga memory
 pop es        ;
 xor di,di     ;  di = offset

;-------------- Palette
  mov    dx,3c8h
  mov    al,32 ;[col]
  out    dx,al
  inc    dx
  mov    al,63 ; [ r ]
  out    dx,al
  mov    al,40 ; [ g ]
  out    dx,al
  mov    al,0  ; [ b ]
  out    dx,al
;--------------

 mov cx,319  ; loop 319 times

lp1:

 mov ax,100  ; y = 100

 mov bx,cx   ; bx = cx

 ;-----------------------------------------------------
 ;WritePixelFast :)   
 ;vgamemory[x + (y*320)] = color ; bx=x, ax=y, cl=color
 imul ax,320
 add ax,bx
 mov di,ax
 mov byte [es:di],32    ; color = 32 or cl
 mov ax,0               ; clear ax
 mov bx,0               ; clear bx
 ;----------------------------------------------------

loop lp1


 sub     ah,ah       ; Wait any key...
 int     16h         ;


;-----------Exit to DOS
mov ax,4c00h
int 21h



Edited by: rbraz at: 18/3/06 18:40
coder
ATARI 2600

Posts: 19
(18/3/06 18:40)
Reply    RE Thanks a lot rbraz! :)

Had been sitting here patiently seeing your name at the bottom
crossing my fingers hoping you would post here :P

I'll try that out. :) Is there any cheat-sheet or something you know
of where it explains what all the registers hold and stuff like that?

I think I'm getting the hang of asm with t0a, which is a nice assembler :)


Thanks in advance. :D


EDIT:
Maybe by getting some prods out in the showcase and some code in the
code arcs, this place can be revived to its former glory, at least as a demo
coding community for anyone any level :)

Edited by: coder at: 18/3/06 18:42
coder
ATARI 2600

Posts: 20
(18/3/06 18:47)
Reply    Re: RE Ohhh! I can use t0a in Linux now but for Windows! Yay!

What I do:
- Code in vi in Linux (My favorite)
- Use WINE to "emulate" t0a compiling
- Use DosBOX to emulate the final product
Yay!!!!


EDIT: Sorry for double post! I was excited :P

Edited by: coder at: 18/3/06 18:48
rbraz
CBM 128

Posts: 146
(18/3/06 19:08)
Reply
   Re: RE No probs !

It's too difficult to tell you a best place to learn Asm, try to find some good tutorials using Google.

I'm not good teaching people, but if you have some troubles ask here, and maybe other people start learning too and share all their knowledge :)

rbraz
CBM 128

Posts: 148
(19/3/06 16:37)
Reply
   Re: RE I found a webpage with useful information about asm:

www.dd.chalmers.se/~f99la...nload.html

Take a look at "General graphics tutorials..." section.

The tutorial by Adam's is very good, one of the best.
www.dd.chalmers.se/~f99la...smtuts.zip

Edited by: rbraz at: 19/3/06 16:42
coder
ATARI 2600

Posts: 22
(19/3/06 20:08)
Reply    Re: RE Wow! Thanks! :) Some nice stuff there! :)

Thygrion
DBF: Coder

Posts: 354
(10/4/06 3:00)
Reply
   Re: RE As far as I know, I prefer using VGA Mode 13h (X as RBraz calls it), but it is only 256 colors and requires a palette generator (unless you like ugly effects ;) ), but if I were you I'd research tinyptc or openptc - yes, openptc is a dll, but tinyptc is very easy to use and doesn't require one. I use tinyptc for 64 and 32 k intros in freebasic and it's blazing as far as speed.

But I'm very surprised you jumped straight from blitz to assembly - you should try C++, as it's basicly just a high-level assembly language first.


Finally 14!!

Thygrion
DBF: Coder

Posts: 355
(10/4/06 3:05)
Reply
   Re: Assembly Language - 2D I wrote an overhead voxel routine in assembly for use in a tinyintro awhile back, but I'll need a better texture to fill in the rest of the 256 bytes.

Anyway I thought you may want to have a look - hope it helps you.

NASM (netwide assembler [32-bit DOS binaries]) compiles.

Code: [Select]
; Overhead Voxels

[org 100h]
[section .text]
                mov al,13h
                int 10h
               
                push 0a000h
                pop es
                mov ax,cs
                add ah,10h
                mov fs,ax
               
                mov dx,3c8h
                xor ax,ax
                out dx,al
                inc dx
PAL                push ax
                shr al,3
                add al,31
                out dx,al
                out dx,al
                mov al,63
                out dx,al
                pop ax
                inc al
                jnz PAL
               
                mov cl,192
                xor bx,bx
TEX                mov al,bl
                and al,bh
                shr al,4
                and al,1
                mul cl
                add al,60
                mov [fs:bx],al
                inc bx
                jnz TEX
               
MAIN        push bx
                xor di,di
                mov dx,-100
YLOOP        mov bp,-160
XLOOP        fninit
                mov [si],word 160
                fild word [si]
                mov [si],dx
                fild word [si]
                fdiv st0,st1
                mov [si],bp
                fild word [si]
                fdiv st0,st2
                pop bx
                push bx
                mov [si],bx
                fild word [si]
                fild word [si]
                mov [si],word 128
                fidiv word [si]
                fldpi
                fmulp st1
                fsin
                mov [si],word 64
                fimul word [si]
                mov al,255
RAYC        fld st3
                faddp st2,st0
                fadd st0,st2
                fld st1
                fistp word [si]
                mov bx,[si]
                mov bh,bl
                fist word [si]
                mov cx,[si]
                mov bl,cl
                mov cl,[fs:bx]
                cmp al,cl
                jbe RAYH
                dec al
                jnz RAYC
RAYH        mov ah,255
                sub ah,al
                mov [es:di],ah
                inc di
                inc bp
                cmp bp,160
                jnz XLOOP
                inc dx
                cmp dx,100
                jnz YLOOP
                pop bx
                dec bl
                mov ah,01
                int 16h
                jz MAIN
               
                mov ax,4c00h
                int 21h


contact me if you need any explanations [PM] .


Finally 14!!

Edited by: Thygrion  at: 10/4/06 3:11
rbraz
CBM 128

Posts: 161
(10/4/06 19:39)
Reply
   Re: Assembly Language - 2D Run extremely slow here, dunno why, but nice visual anyway.

Thygrion
DBF: Coder

Posts: 356
(11/4/06 1:13)
Reply
   Re: Assembly Language - 2D it is a very slow routine, since it's per-pixel raycasting. with a better texture that can be improved, but not much.


Finally 14!!

relsoft
VIC 20

Posts: 6
(27/4/06 12:00)
Reply    Re: Assembly Language - 2D Try FASM

Flatassembler.net

Here are 3 asm 256 demos I made one afternoon and night.

board.flatassembler.net/topic.php?t=5121

5H0CKW4VE
*Administrator*

Posts: 8054
(27/4/06 15:44)
Reply
ezSupporter

   Re: Assembly Language - 2D Nice stuff :)



¤´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·`¤... SHOCKWAVE / DBF...¤

VISIT DARK BIT FACTORY INTERACTIVE! (please!)

rbraz
ATARI ST

Posts: 209
(27/4/06 15:45)
Reply
   Re: Assembly Language - 2D Yeah, very good !
Shockwave ^ Codigos
Challenge Trophies Won:

Offline coder_

  • ZX 81
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: Assembly Language - 2D
« Reply #1 on: May 20, 2006 »
Quote
But I'm very surprised you jumped straight from blitz to assembly - you should try C++, as it's basicly just a high-level assembly language first.
Actually, I'm coder, different from Coder.  We are two different people :]  And yes, I've used C for a bit now, but loved C#, Boo, and Python.  Because .NET/mono owns.  Good thing I read that.  Now to see if you can use tinyptc on Linux with fasm.  Or if it is possible in t0a.

But thanks for the tips rbraz and everyone. :]

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Assembly Language - 2D
« Reply #2 on: August 31, 2006 »
I tried compiling this - which works fine but the com runs really slowly - I can see each line being drawn.
Am I doing something wrong? It takes about 2-3 seconds to draw a frame.
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Assembly Language - 2D
« Reply #3 on: September 01, 2006 »
Same here, I hope Thygrion can speed it up, it's a nice effect in ASM.
Challenge Trophies Won: