English Amiga Board


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

 
 
Thread Tools
Old 22 March 2010, 16:14   #61
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
Quote:
Originally Posted by StingRay View Post
Not really the best idea when the system is completely killed. Besides, relocating stacks is nothing bad.
I assume that if you can do Forbid then mean you can do AllocMem before it.
Asman is offline  
Old 22 March 2010, 16:16   #62
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Possible pointless "advanced" optimization: start DMA, wait for 2 wordsync interrupts, decode first sector, wait for next wordsync, decode next sector. More Amiga-like! (not that you really gain any real speed ups because waiting for stepping is still slow)

(I did it like this in Digital Disco II's track loader, not sure why..)
Toni Wilen is offline  
Old 22 March 2010, 16:18   #63
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by Asman View Post
I assume that if you can do Forbid then mean you can do AllocMem before it.
Yeah, of course. However, if you kill the system and don't ever use any system functions anymore (bad idea anyway) you can freely relocate the stackpointers as the system is "yours".
StingRay is offline  
Old 22 March 2010, 16:40   #64
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Some more optimizations:
Code:
        move.w  (a3)+,d6
        cmp.w   #$4489,d6
-->
        cmp.w   #$4489,(a3)+
Same for "move.w (a3),d6" below.

Also you may want to change "lsl.l #1,Dn" into "add.l Dn,Dn", which saves no byte but is faster on 68000.
phx is offline  
Old 22 March 2010, 17:35   #65
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by StingRay
Not really the best idea when the system is completely killed. Besides, relocating stacks is nothing bad.
Edit: As long as the system is completely killed and you don't plan to return to the OS.
That's the idea with this trackloader --> to take over the whole system and not allow any exit other than a reboot or power cycle.

Quote:
Originally Posted by StingRay
And while we are at it, also don't forget to flush caches on CPU's >=68020 after you copied your bootblock to some safe location in memory (call Exec's CacheClearU(), only works on Kick 2.0+ though).
Sting, Toni - I'll look at this more system friendly stuff. Might as well do these things right. This type of correct OS stuff is what I'm bad with - I don't really understand the OS at all - I only know (some) things about hardware bashing.

@ phx - superb stuff - thanks for those optimisations.

Thanks to those, here's a 420 byte version of the trackloader. I also fixed the timer offsets so that they're more readable.

EDIT: 420 byte version removed.

Last edited by pmc; 23 March 2010 at 11:06.
pmc is offline  
Old 22 March 2010, 18:01   #66
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
It still does not handle condition when the very first word isn't $4489 (cmp.w #$4489,(a3)+ always skips first word) but also remember extra words in gap when fixing this.
Toni Wilen is offline  
Old 22 March 2010, 18:14   #67
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Toni - the comparison for $4489 steps through the MFM buffer one word at a time until it hits a $4489 and then makes sure it hits a second $4489 word before decoding the sector header.

I thought cmp.w $4489,(a3)+ didn't skip the first word - it's post increment isn't it? - as in check what's in (a3) then increment + .w

As disk read is triggered at $4489 (as set in the dsksync register) would there ever actually be a situation where this routine won't sync properly?

I'm just trying to avoid adding any code I can get away with not adding if at all possible.
pmc is offline  
Old 22 March 2010, 18:15   #68
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by pmc View Post
That's the idea with this trackloader --> to take over the whole system and not allow any exit other than a reboot or power cycle.
I know. As otherwise you wouldn't really need a trackloader. :P

Quote:
Originally Posted by pmc View Post
Sting, Toni - I'll look at this more system friendly stuff. Might as well do these things right. This type of correct OS stuff is what I'm bad with - I don't really understand the OS at all - I only know (some) things about hardware bashing.
This is not too complex, actually, the only thing that's important is that you copy your code to some safe location so it can't be trashed. Doing that is simple:

- use AllocMem to allocate memory for your bootblock code (you could also use absolute addresses but I don't really like this)
- copy the code into the just allocated memory space
- check if your code is running on a OS2.0+ machine and if so, call Exec's CacheClearU to flush caches
- execute the code you just copied to the safe location code
- have fun

Quote:
Originally Posted by pmc View Post
Thanks to those, here's a 420 byte version of the trackloader. I also fixed the timer offsets so that they're more readable.
420 bytes is quite cool, I'm waiting for your first bootblock intro. =)

Last edited by StingRay; 22 March 2010 at 18:21. Reason: typo
StingRay is offline  
Old 22 March 2010, 18:19   #69
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
@ Stinger - thanks for that explanation mate.

Just out of further curiosity what's the cache flush for...?

I've seen stuff from you before where you've admonished people for not clearing caches.

Yeah, 420 bytes is nice.

A bootblock intro is something I'll surely attempt at some point.
pmc is offline  
Old 22 March 2010, 18:27   #70
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by pmc View Post
@ Stinger - thanks for that explanation mate.

Just out of further curiosity what's the cache flush for...?

I've seen stuff from you before where you've admonished people for not clearing caches.
I'm sure you're referring to a certain demo that was recently released. But there it wasn't about flushing cache, it was about disabling cache as that's required once you use SMC (self modifying code). Flushing cache would have the same effect but disabling cache completely is the better solution in case you're gonna use lots of SMC.

Flushing cache is required on CPU's with cache (yeah, hard to guess eh? ) once you modified code so the CPU won't execute stuff that's still in the cache as that's surely not what you want (good example was a "Check Config" routine in the game Manchester United Europe, it copied code around and on my A4060 the game crashed once it tried to execute that very code). More info can be found here.
StingRay is offline  
Old 22 March 2010, 18:31   #71
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
OK cool.

Quote:
Originally Posted by StingRay
I'm sure you're referring to a certain demo that was recently released.
LOL. Yeah, that's what I was referring to.

Last edited by pmc; 22 March 2010 at 18:36. Reason: Some text removed - didn't want to stir too much... :)
pmc is offline  
Old 22 March 2010, 18:44   #72
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by pmc View Post
I thought cmp.w $4489,(a3)+ didn't skip the first word - it's post increment isn't it? - as in check what's in (a3) then increment + .w
That's correct, the cmp.w #$4489,(a3)+ is fine.

Quote:
Originally Posted by pmc View Post
As disk read is triggered at $4489 (as set in the dsksync register) would there ever actually be a situation where this routine won't sync properly?
Only reason I can think of would be a corrupt sector or smth, e.g. wrong/no sync markers.
StingRay is offline  
Old 22 March 2010, 18:59   #73
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Yeah, I thought so - nice one Stinger.

I know I *could* check for errors (bad syncs, bad checksums etc.) but it seems like overkill to me - even if I do check for errors a disk won't load or be read properly under those conditions so I'm not really too bothered if something corrupt == crash.
pmc is offline  
Old 22 March 2010, 19:44   #74
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by StingRay View Post
That's correct, the cmp.w #$4489,(a3)+ is fine.
No, it isn't, if first word isn't 4489 (it isn't a special case), first sector data is completely skipped. It still technically works fine if DMA length is big enough (first sector repeats completely at the end) but...
Toni Wilen is offline  
Old 22 March 2010, 20:04   #75
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
What would be a better (ie.works in all cases) solution for the sector start comparison Toni...?
pmc is offline  
Old 22 March 2010, 20:16   #76
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by Toni Wilen View Post
No, it isn't, if first word isn't 4489 (it isn't a special case), first sector data is completely skipped. It still technically works fine if DMA length is big enough (first sector repeats completely at the end) but...
I don't really get this, $4489 is the SYNC marker so why is it wrong to search for it? Also, I suppose about 99% of all trackloaders are buggy then as I can hardly remember one that doesn't do a cmp.w #SYNC,(ax)+. =) Can you explain a bit more please?
StingRay is offline  
Old 22 March 2010, 21:15   #77
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
Quote:
Originally Posted by StingRay View Post
I don't really get this, $4489 is the SYNC marker so why is it wrong to search for it? Also, I suppose about 99% of all trackloaders are buggy then as I can hardly remember one that doesn't do a cmp.w #SYNC,(ax)+. =) Can you explain a bit more please?
Technically they are buggy but practically it never causes any problems because standard read length is long enough. (I just tested Digital Disco 2 track loader, which also has same issue, and it still worked fine even if first word was always non-4489 = first sector was "lost")

btw, I was wrong, no 4489 at the start is very rare condition, it can only happen if dma is started when disk position is just after first bit of first 4489 and before start of next 4489.
Toni Wilen is offline  
Old 23 March 2010, 08:42   #78
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
size optimization: instead of $8000 you should choose something like $7fffe then you can use lea $7fffe.w,a4 instead of lea $8000.l,a4.

Last edited by Asman; 23 March 2010 at 08:42. Reason: typo
Asman is offline  
Old 23 March 2010, 09:12   #79
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by Asman View Post
size optimization: instead of $8000 you should choose something like $7fffe then you can use lea $7fffe.w,a4 instead of lea $8000.l,a4.
This is not very useful because load address is not constant, i.e. I consider it the same kind of optimization that I mentioned earlier, I'd only do that for some kind of "code the shortest trackloader" compo as it limits the functionality (you can only load to addresses <$8000). And 2 bytes aren't worth it.

Last edited by StingRay; 23 March 2010 at 09:53. Reason: some more info added
StingRay is offline  
Old 23 March 2010, 09:51   #80
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Toni Wilen View Post
btw, I was wrong, no 4489 at the start is very rare condition, it can only happen if dma is started when disk position is just after first bit of first 4489 and before start of next 4489.
Sorry to join this conversation, but AFAICS not even this special case poses any problem to pmc's source. He wrote:
Code:
.decode_header: movea.l a2,a4           ;restore start of this track's decode b
        cmp.w   #$4489,(a3)+
        bne.s   .decode_header
        cmp.w   #$4489,(a3)
        beq.s   .decode_header
Which IMHO accepts either one sync or more, but requires at least one.

EDIT: Or is the first detected sync skipped by the hardware and not written into the buffer? I cannot remember ATM. In this case you're right, of course!
phx 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
HD loader example st! Coders. General 4 16 October 2012 21:56
Game loader stuck on certain track after save state restore andreas support.WinUAE 2 26 March 2011 19:59
Can't transfer Supaplex cause of CSL track loader ! Vollldo support.Games 4 12 March 2011 21:51
Hardware File Loader h0ffman Coders. General 9 02 December 2010 16:40
mfm/custom regs/track loader snyp Coders. General 9 06 June 2006 19:42

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 21:53.

Top

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