Welcome, Guest. Please login or register.

Author Topic: I made my first demoscene effect in assembler!  (Read 6975 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline balrogsoftTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2006
  • Posts: 186
    • Show only replies by balrogsoft
    • http://www.amigaskoolnet
I made my first demoscene effect in assembler!
« on: November 26, 2006, 01:12:55 AM »
Hi, i made my first demoscene effect in assembler, i made little things in assembler some years ago, but now i'm learning a lot. I decided to make my first assembler effect this weekend, and i got it! I made a Chunky to Copper routine, and a rotozoomer effect. On my A600 is very slow, but on my A1200 with a 060, it runs very smoothly. I'm not very good with assembler (i'm a newbie), if somebody can give some suggestions to optimize my code, i will share my code:

ASM Source code

Executable

Thanks in advance.
Balrog Software · http://www.amigaskool.net
Mac Mini G4 1,5ghz · MorphOS 2.7 · Ati Radeon 9200 64Mb · 1 Gb RAM · 80 GB HD
Efika · MorphOS 2.7 · Ati Radeon 9250 128Mb · 120 Gb WD HD
Amiga 1200T · OS 3.9 · Voodoo3 · Blizzard 603e/240mhz 060/50mhz · 98 Mb RAM · 40 GB HD
Amiga 600 · OS 3.1 · ACA 630/25mhz 32 Mb RAM · 4Gb CF
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I made my first demoscene effect in assembler!
« Reply #1 on: November 26, 2006, 01:31:25 AM »
*** Interlude. A specialist from Finland will be along shortly  to answer all your questions ***


;-)
int p; // A
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: I made my first demoscene effect in assembler!
« Reply #2 on: November 26, 2006, 01:37:16 AM »
I'm a bit too drunk atm to make any detailed analysis, but I'll check it out later.

[EDIT]

But even when wasted I can give some ideas how to make it much faster (at least on older systems):

- Inline the innerloop (.NextX) subroutine calls.
- Use registers to store variables instead of memory. Do this at least for variables used in innerloop.
- Move out any 'y' related calculation from the .NextX loop, calculate these values before entering the X loop (this appears to have been done mostly, however).

[/EDIT]
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I made my first demoscene effect in assembler!
« Reply #3 on: November 26, 2006, 01:40:46 AM »
:lol:
int p; // A
 

Offline humppa

  • Hero Member
  • *****
  • Join Date: Oct 2005
  • Posts: 959
    • Show only replies by humppa
Re: I made my first demoscene effect in assembler!
« Reply #4 on: November 26, 2006, 01:45:54 AM »
Quote

Piru wrote:
I'm a bit too drunk atm to make any detailed analysis, but I'll check it out later.


:crazy:  :roflmao:  
 

Offline amiga92570

  • Hero Member
  • *****
  • Join Date: Aug 2006
  • Posts: 1005
    • Show only replies by amiga92570
Re: I made my first demoscene effect in assembler!
« Reply #5 on: November 26, 2006, 01:50:36 AM »
 :pint:  :pint:  I think it helps!

 :-o
Amiga92570
==========================
(1) 4000T/040 (2)3000t CS 060/233ppc Picasso IV video, (2)D-box 1200 blizzard 060/200ppc Mediator fastATA, (1)amiga 1200 Power tower, (1)amiga 1200 EZ tower with mediator,1200/030/50mhz, (3) amiga 500 with CSA Mega Midget Racer and Trump card AT, (2) amiga 600 one with M-tec 030, (3) CD32 one sx32, two sx32-pro, More accessories and parts than I want to admit to
 

Offline DamageX

  • Sr. Member
  • ****
  • Join Date: Jun 2005
  • Posts: 339
    • Show only replies by DamageX
    • http://www.hyakushiki.net/
Re: I made my first demoscene effect in assembler!
« Reply #6 on: November 26, 2006, 07:29:07 AM »
Instead of calculating the coordinates of the source pixel in the texture every time you write a pixel to the copper list, I think it is faster to maintain a set of coordinates and modify them with predetermined values.

so your inner loop could look something like:

NextY:
move #30,d2 ; width of screen
NextX:
add.w d4,d0 ; modify source x coordinate (for every change
add.w d5,d1 ; modify source y coordinate  in x direction)
move.w #$07C0,d3 ; mask for y coordinate (32x32 texture?)
and.w d1,d3
lea Texture,a1 ; pointer to texture
add.w d3,a1
move.w #$07C0,d3 ; mask for x coordinate
and.w d0,d3
lsr.w #5,d3
add.w d3,a1 ; now we have the correct address
move.w (a1),(a0)+ ; copy a pixel from texture to screen
subq.b #1,d2
bne NextX
add.w d6,d0 ; modify source x coordinate (for every change
add.w d7,d1 ; modify source y coordinate  in y direction)
; probably something needs to be added to copperlist
; pointer in a0 so it points to next line
subq.b #1,LineY
bne NextY

hope that makes some sense and hasn't too many bugs...

for calculating the magic numbers in d4,d5,d6,d7
d4 = x_scale * cos(angle)
d5 = x_scale * -sin(angle)
d6 = y_scale * sin(angle)
d7 = y_scale * cos(angle)
(in my example code I use fixed-point math with 6 bits of fraction so multiply by 64)
 

Offline motorollin

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: I made my first demoscene effect in assembler!
« Reply #7 on: November 26, 2006, 08:16:43 AM »
I bet you guys don't even need to run the executable. You can probably see the effect just by reading the code :lol:

jk

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10
 

Offline McVenco

  • Hero Member
  • *****
  • Join Date: Feb 2006
  • Posts: 1428
    • Show only replies by McVenco
    • http://www.amigascene.nl
Re: I made my first demoscene effect in assembler!
« Reply #8 on: November 26, 2006, 09:45:24 AM »
Quote
You can probably see the effect just by reading the code


:roflmao: :laughing:
| A4000 | CS-MK3 060@50 | Picasso IV |
| Member of Team Amiga (tm) | FidoNet 2:286/414.18 (long ago) |
| SysOp The Missing Channel BBS | Member of AGA BBS Intl. |
 

Offline LawlessPPC

  • Full Member
  • ***
  • Join Date: Dec 2005
  • Posts: 176
    • Show only replies by LawlessPPC
    • http://search.ebay.co.uk/_W0QQfgtpZ1QQfrppZ25QQsassZlawlessppc
Re: I made my first demoscene effect in assembler!
« Reply #9 on: November 26, 2006, 01:15:44 PM »
very nice to see the word assembler these days
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I made my first demoscene effect in assembler!
« Reply #10 on: November 26, 2006, 01:56:09 PM »
Try to find a use for d3, d4, d5, d6 and d7. It seems you are only using d0 to d2. There are various frequently constants and variables in your code you could put into these registers to improve access times, at least on slower machines. Even on faster ones, a read from the datacache is not as fast as a direct register access.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: I made my first demoscene effect in assembler!
« Reply #11 on: November 26, 2006, 02:03:10 PM »
Quote

motorollin wrote:
I bet you guys don't even need to run the executable. You can probably see the effect just by reading the code :lol:

jk

--
moto


You don't see the (rotating) girl in a red dress? :lol:
int p; // A
 

Offline neuroflip

  • Full Member
  • ***
  • Join Date: Apr 2006
  • Posts: 200
    • Show only replies by neuroflip
    • http://a1200.wordpress.com
Re: I made my first demoscene effect in assembler!
« Reply #12 on: November 26, 2006, 02:12:42 PM »
Nice roto!!! but it's too slow on my a1200/030 :D
it would be nice to see it with some optimizations... ride on!

 :-D  :-D  :-D
[http://a1200.wordpress.com (spanish)
a1200 + Bliz1260/50Mhz/64Mb + HD10Gb + a520 svideo mod + Wireless PCMCIA Elsa MC-11 + PCMCIA CF + Adaptator + CF 256Mb + a500 + 512Kb]
 

Offline balrogsoftTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2006
  • Posts: 186
    • Show only replies by balrogsoft
    • http://www.amigaskoolnet
Re: I made my first demoscene effect in assembler!
« Reply #13 on: November 27, 2006, 12:42:01 PM »
Thanks a lot for your help, i decided to recode the routine, now i calculate the rotation of 3 points, with this 3 points i calculate the increment for every horizontal and vertical step, in ADA forum, an user gave me a link with a tutorial to make this effect as i explained. Now my routine works at decent speed on a plain A1200. I uploaded the new source and executable with the same name.
Balrog Software · http://www.amigaskool.net
Mac Mini G4 1,5ghz · MorphOS 2.7 · Ati Radeon 9200 64Mb · 1 Gb RAM · 80 GB HD
Efika · MorphOS 2.7 · Ati Radeon 9250 128Mb · 120 Gb WD HD
Amiga 1200T · OS 3.9 · Voodoo3 · Blizzard 603e/240mhz 060/50mhz · 98 Mb RAM · 40 GB HD
Amiga 600 · OS 3.1 · ACA 630/25mhz 32 Mb RAM · 4Gb CF
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: I made my first demoscene effect in assembler!
« Reply #14 on: November 27, 2006, 04:34:30 PM »
Okay, took a look at the code and optimized it couple of cycles. It should be slightly faster, but not much. I also fixed some small bugs from the startup code, made it render as fast as possible (it's much slower than vertical blank, so rendering from VBL doesn't make much sense), removed chipmem allocation, fixed random returncode etc.

ROTOZOOM.S
ROTOZOOM.exe