22 January 2020, 01:21 | #1 |
Registered User
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
|
Basic ASM Pointer Table Help
Hey! I'm back again with some simple questions that my C and Swift orientated brain can't get around!
I've successfully got an AGA screen up and running with 64bit fetch and 16 colour 64bit wide attached sprites. All good so far, works great. Now I'm trying to animate said sprites and have the sprite data in one file, with offsets calculated by hand for now. One step at a time :-) The code below should show how I've got that all set up: Code:
move.l #SpriteTableOffsets,a2 ; load first address into a2 move.l 4(a2),d2 ; move 4 bytes in from start of table in a2 into d2, effectively the 2nd offset add.l #SpritePointer,d2 ; add start sprite address to offset value in d2 move.l d2,a0 ; move d2 into a0 and we'll all good! ******************************************************************************* SpriteTableOffsets: dc.l $00000000,$00000640 SpritePointer: INCLUDE "data/sprite.ctl.64x48x4.asm" ; sprite with control words and termination Code:
move.l 4(a2),d2 Say, I have Code:
frame dc.w 0 I've tried Code:
move.l frame*4(a2),d2 Any help would be appreciated. Thanks. |
22 January 2020, 02:01 | #2 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Code:
lea frame(pc),a0 ; or without (pc) if it's in a different section move.w (a0),d0 eor.w #4,(a0) ; this will cycle 0,4,0,4,... use addq.w #4,(a0) to increment 0,4,8,... move.l SpriteTableOffsets-frame(a0,d0.w),d2 SpriteTableOffsets: dc.l $00000000,$00000640 frame: dc.w 0 |
22 January 2020, 09:45 | #3 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
As an alternative to the code above, you can also consider using something like
Code:
move.w frame(pc),d1 move.w 0(a0,d1),d0 ; now simply update the contents of frame as needed ; etc frame: dc.w 0 |
22 January 2020, 11:08 | #4 |
Registered User
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
|
Thanks for the answers lads. I guess off the back of that I have a couple of simple ASM questions. I always like to know how, or why something does what it does instead of just slamming working code in there :-)
Code:
move.w frame(pc),d1 Code:
move.w 0(a0,d1) Thanks again! |
22 January 2020, 11:20 | #5 | |||
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
Quote:
(there are some other reasons to use PC relative code as well, but they're probably not be relevant right now) Quote:
Quote:
|
|||
22 January 2020, 11:27 | #6 | ||
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
Quote:
Code:
move.w (0,a0,d1) |
||
22 January 2020, 12:16 | #7 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
You can use .b only on registers data usage. |
|
22 January 2020, 12:51 | #8 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Also, don't forget that as you are on AGA you can use multiples in the indexed addessing.
for example... Code:
lea Table(pc),a0 moveq #1,d0 move.b (a0,d0*4),d1 Table: dc.b 0,2,4,6,8,10,12,14 You can multiply up to *8 and this is extremely useful on AGA. Geezer |
22 January 2020, 13:41 | #9 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
It's not related to AGA, but to the CPU. I think 68020+ probably.
Is there some good M68k instruction manual? The one I currently use (M68000PRM.pdf) doesn't seem to mention this multiplier even though it mentions some additional MC68020+ modes. |
22 January 2020, 13:49 | #10 | |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
Quote:
|
|
22 January 2020, 13:55 | #11 | |
Registered User
Join Date: Jun 2015
Location: Germany
Posts: 1,918
|
Quote:
There isn't a thing about 68k that isn't in the PRM. It just takes a little getting used to... |
|
22 January 2020, 14:10 | #12 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
I had a recent case where I needed to move the low byte to a clear register to use the low byte only as index - like this: Code:
move.w (a0)+,d0 moveq #0,d1 move.b d0,d1 move.w (0,a1,d1.w),d2 .. do something else with the rest of d0 |
|
22 January 2020, 14:13 | #13 | |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
Quote:
Same reason I avoid using odd addresses on 020+ and longwords. Yes the 020 can read them, but its not optimal processor performance for it to do so. |
|
22 January 2020, 14:47 | #14 | ||
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
Quote:
And small arrays in memory are an added value. |
||
22 January 2020, 14:47 | #15 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
If I was doing it properly on 020/AGA I would have a CNOP 0,4 to align it. Byte size tables are useful though, an example being sine / cosine where you can just cycle through the byte space for sine and +64 for the cosine. |
|
22 January 2020, 17:07 | #16 |
Registered User
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
|
Many thanks to all of you who've contributed to this thread and the other ones to aid in my ASM learning. You're all very welcoming and patient with us beginners :-)
I've gone from this manky white line and green screen: to this: It might not look like much to you veterans but I'm well chuffed. Especially in the space of a month! Now I'm slightly more motivated, I'm sure this will just be the start of many more questions over the coming months. Thanks again |
22 January 2020, 17:12 | #17 |
Registered User
Join Date: Sep 2019
Location: Essen/Germany
Age: 55
Posts: 463
|
Cool! Your are farther than me. I'm working on helper functions, but drawing a line and going to an animated BLOB from there, is next on my list.
|
22 January 2020, 17:52 | #18 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
If you are starting to learn asm, here's a random advice (since I noticed it in some of the examples above): if there's more than one possible operand size, always specify what you want.
For example (this is my opinion, of course): Code:
move d0,d1 ; bad (.b/.w/.l? usually ends up being move.w) move.b d0,d1 ; ok move.w (a0,d0),d1 ; bad (d0 is .w/.l?) move.w (a0,d0.l),d1 ; ok moveq.l #42,d0 ; it works, but .l is not need since it's always .l |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tool to convert asm to gnu asm (gas) | Asman | Coders. Asm / Hardware | 13 | 30 December 2020 11:57 |
very basic C/ASM/Visual Studio hand holding | Sephnroth | Coders. C/C++ | 2 | 08 March 2016 20:15 |
Pimp up your Basic skills ! BASIC Tenliner Competition 2016 ! | SkulleateR | Retrogaming General Discussion | 6 | 09 February 2016 23:58 |
Manuals for GFA Basic and Hi-Soft Basic 2 | ricky500 | request.Apps | 20 | 12 February 2013 21:06 |
Full table pinball | spiff | Retrogaming General Discussion | 0 | 21 December 2006 23:46 |
|
|