English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 13 October 2022, 14:22   #1
sandruzzo
Registered User
 
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
64k ram pointers boundary

Is there a way to be sure to have bitplanes and other pointers inside the 64k ram boundary, to speed up pointers' set-up, with allocated or reserved memory on ocs/ecs and Aga too?
sandruzzo is offline  
Old 13 October 2022, 14:33   #2
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,053
I allocate extra 64KB and then ptr = (ptr+$ffff)&(~$ffff). You can also try AllocAbs() in a loop and see if you can get it.

Also, make sure that you don't under/over-flow (e.g. blitter in decrement mode, blits the last line and then mods get "added" and you drop down to the previous 64KB bank, so the next blit will have bad upper words).
a/b is offline  
Old 13 October 2022, 14:48   #3
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,302
Not from the operating system, but you can allocate the bitmap yourself and fill the plane pointers, and pass the bitmap structure over to OpenScreen with a tag.

To allocate memory aligned, the usual way of doing this is first a Forbid(), then an AllocMem() of the memory block with the size increased by 64K, then round up the start address to the next 64K boundary, then FreeMem(), and then AllocAbs() of the block you need, then finally Permit().

Or, mmulib/AllocAligned(), which does quite the same.
Thomas Richter is offline  
Old 13 October 2022, 14:53   #4
sandruzzo
Registered User
 
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
@a/b , @Thomas Richter

Thanks
sandruzzo is offline  
Old 13 October 2022, 15:27   #5
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,053
That's a nice way of doing it, with AllocMem I mean, but what could work better is get exec->MaxLocMem and then loop downwards in 64KB decrements. Leaves no gaps and if you are still multitasking it can reduce segmentation.
a/b is offline  
Old 13 October 2022, 16:37   #6
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 389
On the A500 for a game or demo it seems fragile to rely on the OS for multiple allocations.

I just allocate one big chunk that's as big as I need for the whole program and then manage that myself with a stack allocator.

My allocator has calls that will align to some size or make sure to fit inside some alignment. I'm then able to allocate buffers that are within a 64k page without wasting too much space.

My main point is maybe that buffers don't need to be 64k aligned for you to only update the lower 16bits. They just need to be limited to within some 64k page.

Maybe there are other ways of making such an allocation that could be clearer but I found the concept of keeping "inside" an alignment was the best I came up with.
Jobbo is offline  
Old 13 October 2022, 17:47   #7
sandruzzo
Registered User
 
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
Is it possible to do the same with assemblers' directives like ds.b or rs.b and like that?
sandruzzo is offline  
Old 13 October 2022, 17:54   #8
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,636
Quote:
Originally Posted by sandruzzo View Post
Is it possible to do the same with assemblers' directives like ds.b or rs.b and like that?
Hmm.. You could reserve a bss_c block like explained with AllocMem above, but the trouble is that it is tricky to free the unneeded part of the block yourself (assuming that you want to do that as soon as you've got your 64k aligned block).
hooverphonique is offline  
Old 13 October 2022, 18:32   #9
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,182
If you mean something like
Code:
buffer:
  ds.b buffersize+65336
  ...
  dc.l (buffer+$ffff)&(~$ffff)
Then no, as such a complex relocation isn't possible.

By the way you only need to allocate twice the needed size. Either the allocation already fits or you can move the buffer start to the next 64K boundary. Slightly more complicated but could be useful in low mem situations. I.e. something like:
Code:
    move.l  #bufferbytes,a0
    move.l  a0,d0
    add.w   #buffersize-1,d0
    bcc.b   .ok
    clr.w   d0
    add.l   #1<<16,d0
    move.l  d0,a0
.ok
    ; buffer in a0


bufferbytes:
    ds.b    buffersize*2

Last edited by paraj; 13 October 2022 at 18:39.
paraj is offline  
Old 13 October 2022, 19:36   #10
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,029
Quote:
Originally Posted by paraj View Post
If you mean something like
Code:
buffer:
  ds.b buffersize+65336
  ...
  dc.l (buffer+$ffff)&(~$ffff)
Then no, as such a complex relocation isn't possible.

By the way you only need to allocate twice the needed size. Either the allocation already fits or you can move the buffer start to the next 64K boundary. Slightly more complicated but could be useful in low mem situations. I.e. something like:
Code:
    move.l  #bufferbytes,a0
    move.l  a0,d0
    add.w   #buffersize-1,d0
    bcc.b   .ok
    clr.w   d0
    add.l   #1<<16,d0
    move.l  d0,a0
.ok
    ; buffer in a0


bufferbytes:
    ds.b    buffersize*2
I dont coded long time, but for me this routine will be dont works correctly if .ok is reached from branch. Still missing is clr.w D0. Perhaps something like this can works.

Code:
    move.l  #bufferbytes,a0
    move.l  a0,d0
    add.w   #buffersize-1,d0
    bcc.b   .ok
    add.l   #$10000,d0
.ok
    clr.w D0
    move.l D0,A0
    ; buffer in a0


bufferbytes:
    ds.b    buffersize*2
Anyway if Sandruzzo can waste up to $10000 bytes of memory then the shortest version can looks next:

Code:
    move.l  #Buffy+$10000,D0
    clr.w   D0
    move.l  D0,A0   ; buffer in a0


Buffy
    ds.b    $10000+buffersize
Don_Adan is offline  
Old 13 October 2022, 20:14   #11
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,182
I could have made a mistake (and code wasn't tested), but if understood it correctly sandruzzo wants a buffer that doesn't cross a 64K boundary (such that only updates of the l(ow) pointer registers are necessary). I.e. that the whole buffer fits inside a single 64K region (note the caveats that a/b mentioned though), but it is not required that it start at a 64K block (address $XXXX00000). If that is required, disregard my post.
Unconditionally clearing the low part of the buffer address would potentially result in an address before the allocated memory.

The idea is that we have a buffer (of twice the needed size). If ((buffer + buffersize - 1) >> 16) == (buffer>>16), the ".ok" case then all bytes of the buffer are in the same 64K region (easy case). Otherwise we know that the distance to the next 64K boundary must be less than buffersize (otherwise the buffer would have fit), and we can move the start address there (and know that we have enough room, since we moved the pointer at most buffersize-1).

As an example consider buffersize=4, all addresses of bufferbytes up to including $xxxxfffc are ok, when we reach $xxxxfffd through $xxxxffff we get ($xxxx0000 + (1<<16)) (which is less than the buffer end address).
paraj is offline  
Old 13 October 2022, 20:19   #12
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,029
Perhaps you right. I understand wrong.
Don_Adan is offline  
Old 13 October 2022, 20:30   #13
sandruzzo
Registered User
 
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
It could be a nightmare to have every bitplanes' pointers inside 64k limits..
sandruzzo is offline  
Old 13 October 2022, 20:40   #14
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,182
Quote:
Originally Posted by sandruzzo View Post
It could be a nightmare to have every bitplanes' pointers inside 64k limits..
Absolutely, but what you're usually trying to ensure is hopefully more constrained than everything in one 64K blocks, more like bltXpth/bltptXpth in this copperlist/long blit.
paraj is offline  
Old 13 October 2022, 21:07   #15
sandruzzo
Registered User
 
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
@paraj.

That's the key: to do less copper works by optimizing memory usage
sandruzzo is offline  
Old 13 October 2022, 21:37   #16
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,157
I did once write some custom allocation routines for this kind of thing. To avoid wasting the "offcuts", it kept a record of them and would use them for future allocations where possible.
It's written in C, so probably of limited interest here, but I can dig them out if anyone's interested.
robinsonb5 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
Allocating memory within a 64K boundary deimos Coders. General 5 30 October 2019 12:14
GoldenGate Bridgecard 64K Software? ahandyman59 support.Hardware 7 05 April 2017 08:58
64k Amiga ECS Intro 4pLaY Amiga scene 1 16 July 2012 09:31
Looking for 18pin 64k DRAM chips 90ns + Smiley support.Hardware 6 15 April 2006 04:26
Two mouse pointers! mlft support.WinUAE 16 21 December 2002 02:52

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 11:34.

Top

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