28 October 2014, 23:58 | #1 |
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 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 |
29 October 2014, 00:56 | #2 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Yep, it's 8(a6). Really. Who knows what's in a6... Probably Photon
Last edited by Thorham; 29 October 2014 at 01:03. |
29 October 2014, 01:14 | #3 |
Registered User
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
|
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. |
29 October 2014, 05:14 | #4 |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,182
|
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) |
29 October 2014, 10:19 | #5 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
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 ... |
29 October 2014, 20:02 | #6 |
Posts: n/a
|
|
30 October 2014, 22:33 | #7 | |
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
|
Quote:
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. |
|
30 October 2014, 23:11 | #8 |
Registered User
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
|
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 Code:
.loop move.w $dff006,d0 cmp.w #$4300,d0 blo.s .loop |
01 November 2014, 08:55 | #9 | |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Quote:
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. |
|
01 November 2014, 10:03 | #10 |
Registered User
Join Date: May 2014
Location: inside the emulator
Posts: 377
|
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.
|
01 November 2014, 22:44 | #11 | ||
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
|
Quote:
Quote:
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. |
||
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 |
|
|