English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 08 February 2006, 22:41   #1
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Understanding the Copper

The Amiga has a fantastic co-processor (The Copper) that can control many different areas of the Amiga (like the display and those lovely rainbows).

The copper to me is an extremely complex beast.. not because I can't understand the 3 commands (yes that's right 3 commands Move, Wait and Skip but because those commands are not used like a normal asm command.

MOVE
the move command can move data into a register. It consists of two words.

The first word contains the address of the destination register (Example $180) and also the MOVE switch bit (bit 0 is set to 0)

The second word contains the data that is to be transferred into the register

Here are a couple of examples

Code:
dc.w $180,$0000 - Background colour to black
dc.w $180,$0f00 - Background colour to red
dc.w $182,$000f - Colour 1 to blue
A breakdown of the 2 word instructions is as follows

Word One

Bit 0 - Always set to 0 (Setting this to 1 changes it to the WAIT instruction)
Bits 8-1 Register destination address
Bits 15-9 Not used, but should be set to 0

Word Two

Bits 15-0 16 bits of data to be transferred (moved) to register destination as specified in the first word.


WAIT
The wait instruction causes the copper to wait until the video beam encounters or is greater than the screen co-ordinates specified in the instruction.

Like the MOVE command 2 Word instructions are used and the 16 bits of each word have specific commands

Word One

Bit 0 - Set this to 1 (if it is left as 0 thje copper treats it as a MOVE instruction)
Bits 15-8 - Vertical beam position (VP)
Bits 7-1 - Horizontal beam position (HP)

Word Two

Bit 0 - Always set to 0
Bit 15 - Blitter finished disable bit (not too sure yet!!) (Normally set to a 1)
Bits 14-8 - Vertical position compare enable bits (VE)
Bits 7-1 - Horizontal position compare enable bits (HE)

The wait instruction is a little more complex than the move instruction as you might need to convert the hex to binary to understand how it is working.

here is an example

Code:
dc.w $9601,$FF00  - Wait for line 150, ignore horizontal counters
Lets break that down into the different bits/sections

First Word

$9601 lets break this down into it's binary form

bits 15-8:
$9=1001
$6=0110

That is the line on the screen ($96 = %1001 0110 = 150dec) (uses bits 15-8)

bits 7-0:
$0 (0000)
$1 (0001)

Now the horizontal beam position only uses bits 7-1 so only 0000 000 is used (position 0 in this case) the last bit in that word is the 1. That signifies we are using the wait command.

Second Word

$FF00

$F=1111 (Bit 15-12 - bit 15 is normally always a 1)
$F=1111 (Bit 11-8 - used with bits 12-14 gives vertical beam compare enable bits)


now this is where I start to lose understanding.. can someone explain a little more how this works (masks beam position etc) and I'll finish this off!!
BippyM is offline  
Old 10 February 2006, 14:01   #2
Joe Maroni
Moderator
 
Joe Maroni's Avatar
 
Join Date: Feb 2003
Location: Germany
Age: 44
Posts: 1,303
Send a message via MSN to Joe Maroni
First Word:

15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
VP7 VP6 VP5 VP4 VP3 VP2 VP1 VP0 HP8 HP7 HP6 HP5 HP4 HP3 HP2 001


Second Word:

15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
BFD VM6 VM5 VM4 VM3 VM2 VM1 VM0 HM8 HM7 MH6 HM5 HM4 HM3 HM2 000

VPx = vertical beam position
HPx = horizontal beam position
VMx = vertical mask
HMx = horizontal mask
BFD = Blitter Finish Disable (0 = wait until Blitter finished)


if a maskbit is enabled the bit in the first word that belongs to the enabled maskbit is accepted by the copper.
Joe Maroni is offline  
Old 10 February 2006, 23:11   #3
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
I remember you'd write

dc.w $3fdf,$fffe

to wait for line $40, i.e. you'd wait until the raster got off-screen on the previous line, and then you'd have more raster time available to change palettes etc.

To make the copper continue beyond raster line 256 on PAL Amigas you'd write

dc.w $ffdf,$fffe

otherwise you'd get nothing below NTSC "screen window", even though that seems to have been "fixed" in WinUAE?
Photon is offline  
Old 08 June 2006, 22:42   #4
HCF
Zone Friend
 
Join Date: Oct 2004
Location: here
Age: 54
Posts: 97
I think it is not so much the Copper that is a problem when it comes to the Amiga but the hardware registers and their use. Good reference though when looking at copper lists in memory...
HCF is offline  
Old 08 June 2006, 23:49   #5
musashi5150
move.w #$4489,$dff07e
 
musashi5150's Avatar
 
Join Date: Sep 2005
Location: Norfolk, UK
Age: 42
Posts: 2,351
It's not so hard. Just read the Hardware Reference manual through twice before you start and you'll be ok - I did
musashi5150 is offline  
Old 09 June 2006, 00:48   #6
HCF
Zone Friend
 
Join Date: Oct 2004
Location: here
Age: 54
Posts: 97
My problem is that I know how to program the PC but have a hard time with the Amiga since it seems there is an endless amount of different components that need to be worked together.
Would be really cool if we could post simple stuff here and then dissect the source, advancing to more complicated topics. Sadly not many of the people involved (at least the ones I knew) are even owning an Amiga anymore let alone remember much...
How about we find some old school intro like the HQC bootblock intros and examine them line by line ?!
HCF is offline  
Old 09 June 2006, 01:10   #7
Ray Norrish
Registered User
 
Ray Norrish's Avatar
 
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
Quote:
Originally Posted by Photon
I remember you'd write

dc.w $3fdf,$fffe

to wait for line $40, i.e. you'd wait until the raster got off-screen on the previous line, and then you'd have more raster time available to change palettes etc.

To make the copper continue beyond raster line 256 on PAL Amigas you'd write

dc.w $ffdf,$fffe

otherwise you'd get nothing below NTSC "screen window", even though that seems to have been "fixed" in WinUAE?
You mean line 200? That was actually a pain in the arse when you had to have that extra bit in, cos it messed up all your loops for processing full screen fx into the PAL area

Last edited by Ray Norrish; 09 June 2006 at 01:23.
Ray Norrish is offline  
Old 09 June 2006, 01:22   #8
Ray Norrish
Registered User
 
Ray Norrish's Avatar
 
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
A thing about copperlists..

I started my coding by using a mc monitor (the excellent Rossi monitor) to reverse engineer other people's demos and code.

Making a simple copperlist to do the various things like, setting bpl pointers, sprites and whatnot by the book is a good start.

Experimenting is the key.. change stuff.. see what it does... don`t get too bogged down on any "clever" stuff at the start.

A lot of the early demos are made using "generated" copperlists, in the way that the basic initialisation is static, but the body that does the work (line by line color regs, bpl pointers etc) are filled in by code loops.

Also, remember that it's no sweat to make as many copperlists as you need and switch between them.

Worrying too much about wait bits and such is not required for beginning to code stuff on the amiga. A nice simple copper list can allow you to get on with other experimentation and learning about the instruction set.
Ray Norrish is offline  
Old 09 June 2006, 01:25   #9
Ray Norrish
Registered User
 
Ray Norrish's Avatar
 
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
Quote:
Originally Posted by HCF
How about we find some old school intro like the HQC bootblock intros and examine them line by line ?!
Probably not a good idea, because this will be highly optimised and difficult code for a novice to understand.
Ray Norrish is offline  
Old 09 June 2006, 06:26   #10
HCF
Zone Friend
 
Join Date: Oct 2004
Location: here
Age: 54
Posts: 97
But I think it would be a good place to start. A bootblock is small and doesn't allow much room for the actual program.
Also more fun to see what somebody else did and go from there. Tutorial programs are good but just not as much fun. The main problem is that not much of the code available has been documented or it would be much less of a mystery.
Anybody interested in doing the work, I'd appreciate it and I am sure many people beside me would benefit...
HCF is offline  
Old 09 June 2006, 09:55   #11
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
As Ray has said, bootblock code whilst small, is difficult for the novice coder to read. Because of the small space to write a program, coders will employ all manner of space saving tricks to ensure it will fit, and the code because of that has the potential to be far more complex.
Galahad/FLT is offline  
Old 09 June 2006, 10:11   #12
musashi5150
move.w #$4489,$dff07e
 
musashi5150's Avatar
 
Join Date: Sep 2005
Location: Norfolk, UK
Age: 42
Posts: 2,351
I agree with Galahad and Ray that most bootblocks aren't the best way to start - but if you really want to then go ahead.

I think a good way to start would be to get the copper to display a simple country flag - like Germany or Holland etc. This is a pretty easy copperlist to write and you will actually have something to look at too Once you can do that ok then you can move on to flags with vertical bars in like Sweden or the English flag as they are a little harder...
musashi5150 is offline  
Old 09 June 2006, 11:01   #13
HCF
Zone Friend
 
Join Date: Oct 2004
Location: here
Age: 54
Posts: 97
It depends, displaying a flag like the Abacus Amiga Intern example is pretty lame. Not only does that particular program do nothing, it also uses the graphics library (if I remember correctly, it didn't even work). Funny how this program seems to be the "Hello World" program for the Amiga..lol

Will take a look at some short BB programs as soon as I can figure out how to export the source from WinUAE to my printer...lol
The only reason I suggested the idea is the small amount of space we have here and discussing a program is easier if you don't need to look through thousands of lines.
HCF is offline  
Old 10 June 2006, 11:11   #14
redblade
Zone Friend
 
redblade's Avatar
 
Join Date: Mar 2004
Location: Middle Earth
Age: 40
Posts: 2,127
I gave up dissassembling the XCOPY2 boot block.

But I found a different boot block source and managed to AGA fix it so that it would run.
redblade is offline  
Old 22 September 2006, 16:31   #15
Doc Mindie
In deep Trouble
 
Join Date: Sep 2004
Location: Manchester, Made in Norway
Age: 51
Posts: 841
What if we take just the standard Workbench bootblock?

as in, stuff a disk in DF0: format it, and the "install df0:?

Would that bootblock be as complex as say... Penomena's dem "Enigma" bootblock?
Doc Mindie is offline  
Old 22 September 2006, 18:56   #16
blade002
Zone Friend
 
blade002's Avatar
 
Join Date: Dec 2005
Location: Australia
Age: 50
Posts: 2,616
All im gonna say is that the Amiga Copper was one of the BEST things it ever had!. It was an amazing trick.
blade002 is offline  
Old 22 September 2006, 19:34   #17
musashi5150
move.w #$4489,$dff07e
 
musashi5150's Avatar
 
Join Date: Sep 2005
Location: Norfolk, UK
Age: 42
Posts: 2,351
Quote:
Originally Posted by Doc Mindie
Would that bootblock be as complex as say... Penomena's dem "Enigma" bootblock?
No, but there is nothing interesting to find there - just a very few lines of code that don't do much. But disassemble it if you want to and see for yourself.

I did my first copper coding by reading a good chapter in 'Mastering Amiga Programming Secrets' by Paul Overaa:

http://www.amazon.co.uk/Mastering-Am...e=UTF8&s=books

Oh... I wonder who wrote that review hehe
musashi5150 is offline  
Old 27 September 2006, 08:42   #18
jaycee
Registered User
 
Join Date: Sep 2006
Location: Norwich, UK
Posts: 57
I did mine by setting up screens in AMOS, and then dumping the copper list from it (there was some variable that allowed you to get the base address of AMOS's copper ist). I just dumped longs until I got "FFFFFFFE" ie the finish instruction.
jaycee is offline  
Old 15 February 2010, 10:31   #19
JackAsser
Registered User
 
Join Date: Jul 2006
Location: Lund / Sweden
Age: 45
Posts: 171
Sorry for wakeing up such an old thread... Quick question though, I simply want to let the copper wait for the next scanline, independant from current vertical position. I'm trying:

dc.w $0001,$80fe

It doesn't work though. I thought I was smart by telling the copper to wait for horizontal position 0 and ignore vertical position, but aparantly I wasn't...
JackAsser is offline  
Old 15 February 2010, 11:29   #20
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
JackAsser of Instinct...?

Howdy.

Just quickly scanned the HRM and what you tried seems logical - it certainly would've been my guess too.

You say it doesn't work - what does happen when you do that wait...?
pmc is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining copper scrolling with copper background phx Coders. Asm / Hardware 16 13 February 2021 12:41
Understanding DIWHIGH register jman Coders. Tutorials 6 11 June 2011 12:29
Anyone like to help understanding this bootblock ??? Joe Maroni Coders. Tutorials 2 15 February 2007 17:33
Understanding ASM Routine Crackersixx Coders. Tutorials 13 10 February 2006 02:58
understanding the COLORXX regs... Joe Maroni Coders. General 2 14 February 2005 07:50

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:48.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09697 seconds with 13 queries