English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 28 October 2014, 23:58   #1
Hop
 
Posts: n/a
Addressing mode syntax question

Can anyone explain this indirect addressing mode syntax I have come across a couple of times? Example:

Code:
ChkMouse: move.w $a-2(a6),d3
(This example from one of Photon's old snippets)

It looks like the hardware register base address $dff000 is expected to be in a6 prior to calling this subroutine, and I would expect JOY0DAT ($dff00a) to be read given the purpose of the code. So what is the -2 for? To me it looks like it would read $dff008 (DISKDATR) which cannot be correct!

I think Photon may have tried to explain this briefly in one of his (excellent) YouTube videos, but I didn't get it.

Last edited by Hop; 28 October 2014 at 23:58. Reason: Typo
 
Old 29 October 2014, 00:56   #2
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 43
Posts: 3,088
Yep, it's 8(a6). Really. Who knows what's in a6... Probably Photon

Last edited by Thorham; 29 October 2014 at 01:03.
Thorham is offline  
Old 29 October 2014, 01:14   #3
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 224
a6 is intended to point to $dff002 (DMACONR).

The code in question wants to read from $dff00a (JOY0DAT) which contains the current mouse cursor position.


... and setting a6 to $dff002 instead of $dff000 is a micro-optimization: there are probably a couple of places in your program where you want to access $dff002 but none where you want to access $dff000. Therefore your program will become a couple of bytes smaller by using $dff002 as your base pointer... although, as you already noticed, the sourcecode becomes a tad more confusing. Whether or not it's worth it is up to you.
Kalms is offline  
Old 29 October 2014, 05:14   #4
Codetapper
2 contact me: email only!

Codetapper's Avatar
 
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,162
In that case, it would be cleaner to make up your own custom.i with values such as:

OFFSET equ 2
custom equ $dff000+OFFSET
dmaconr equ $2-OFFSET
joy0dat equ $a-OFFSET
bltsize equ $58-OFFSET

etc. Then you could still use bltsize(a6) in your code rather than bltsize-2(a6)
Codetapper is offline  
Old 29 October 2014, 10:19   #5
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,265
I agree that hard-coded magical numbers is something you should avoid. I use this:
Code:
               ifnd HARDWARE_I

HARDWARE_I = 1

               ifnd hw_base
hw_base = $dff000
               endif
hw_rel = hw_base-$dff000

;------------- Hardware registers and bits -------------------------------------

bltddat  = 0-hw_rel
dmaconr  = 2-hw_rel
vposr    = 4-hw_rel
vhposr   = 6-hw_rel
...
Leffmann is offline  
Old 29 October 2014, 20:02   #6
Hop
 
Posts: n/a
Quote:
Originally Posted by Kalms View Post
... setting a6 to $dff002 instead of $dff000 is a micro-optimization
That explains all. I guess smaller offsets = smaller instruction lengths = shorter processing time. I should maybe read the optimisation sticky thread before posting again! Thanks.
 
Old 30 October 2014, 22:33   #7
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 40
Posts: 1,923
Quote:
Originally Posted by Leffmann View Post
I agree that hard-coded magical numbers is something you should avoid. I use this:
Code:
               ifnd HARDWARE_I

HARDWARE_I = 1

               ifnd hw_base
hw_base = $dff000
               endif
hw_rel = hw_base-$dff000

;------------- Hardware registers and bits -------------------------------------

bltddat  = 0-hw_rel
dmaconr  = 2-hw_rel
vposr    = 4-hw_rel
vhposr   = 6-hw_rel
...

Why? I thought all Amiga hardware registers were in the same place for all classic models. The only current exception I am aware of is the interrupt pointers which can be offset using the VBR register on computers using 68020+.

I do tend to code specifically for the A600 (as it's the only real one I own), but try to make my software compatible with other models where possible.
Lonewolf10 is offline  
Old 30 October 2014, 23:11   #8
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 224
Many programmers find it easier to understand the intent of this piece of code:

Code:
.wait_for_colorful_effect_start
	move.w	vhposr,d0
	cmp.w	#COLOURFUL_EFFECT_START_Y<<8,d0
	blo.s	.wait_for_colorful_effect_start
... than the intent of this piece of code:

Code:
.loop	
	move.w	$dff006,d0
	cmp.w	#$4300,d0
	blo.s	.loop
Kalms is offline  
Old 01 November 2014, 08:55   #9
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,265
Quote:
Originally Posted by Lonewolf10 View Post
Why? I thought all Amiga hardware registers were in the same place for all classic models. The only current exception I am aware of is the interrupt pointers which can be offset using the VBR register on computers using 68020+.
They're in the same place on all models. If you look you'll see it always translates to the correct address, no matter how hw_base is defined. I usually ignore these micro-optimizations and just go with "dmacon" instead of "(dmacon, a6)" etc.

And like Kalms points out, it's about getting cleaner code. It doesn't make sense writing M68K code and Copper programs as lumps and blobs of hexadecimal digits. It's what people had to do in the 70's on their MOS 6502 computer kits, and I don't think it's something that should be taught to people who look to these tutorials for getting into Amiga programming.
Leffmann is offline  
Old 01 November 2014, 10:03   #10
Megol
Registered User

Megol's Avatar
 
Join Date: May 2014
Location: inside the emulator
Posts: 374
Using more verbose code with defined names also reduces the risk of errors - it's very easy to write the wrong hexadecimal digit unnoticed while spelling a defined name wrong will likely result in an error message.
Megol is offline  
Old 01 November 2014, 22:44   #11
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 40
Posts: 1,923
Quote:
Originally Posted by Leffmann View Post
They're in the same place on all models. If you look you'll see it always translates to the correct address, no matter how hw_base is defined.
Ahh, yes I see that now.


Quote:
Originally Posted by Leffmann View Post
And like Kalms points out, it's about getting cleaner code. It doesn't make sense writing M68K code and Copper programs as lumps and blobs of hexadecimal digits. It's what people had to do in the 70's on their MOS 6502 computer kits, and I don't think it's something that should be taught to people who look to these tutorials for getting into Amiga programming.

I have started to clean up my code a bit in recent months (e.g using macro's more), but I still have a lot to learn

Thanks guys.
Lonewolf10 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
Mac OS X fullscreen mode question MrGimper support.FS-UAE 2 12 October 2013 11:03
question on resourcing relative addressing ara Coders. Asm / Hardware 5 04 February 2012 23:42
Memory addressing CmdrVimes Coders. General 7 25 October 2010 22:20
question about a glitch in window mode sink support.WinUAE 5 15 December 2009 20:54
Addressing modes BippyM Coders. General 17 03 February 2005 09:57

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 12:50.


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