English Amiga Board


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

 
 
Thread Tools
Old 24 March 2010, 11:29   #141
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,517
Quote:
Originally Posted by StingRay View Post
I know but exactly this "goes nowhere" is what I didn't like (what's ciabicr+1?). Also, AFAIK CIA regs should only be written .b, not .w.
Yes, I know. I did say it "technically works"

EDITQUOTE:

Quote:
what's ciabicr+1?
CIA-A (CIA-B 8-bit data lines are connected to CPU data line bits 8-15, CIA-A = data line bits 0-7) but nothing happens because CIA-A chip select is inactive. (not so simple on 68020+ Amigas but basically same) Still, don't do that

Last edited by Toni Wilen; 24 March 2010 at 11:36.
Toni Wilen is offline  
Old 24 March 2010, 19:26   #142
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Hello boys.

Please see the attached *fixed* trackloader.

This one works correctly no matter what start track is used - any valid track number, even *or* odd will work OK.

The length increased slightly but is still a nice and small 408 bytes.

All other shorter versions in this thread will work only if the start track is an even number so please use this one if you want one that works from any start track.

Thanks to phx for putting a foot in my arse and making me test my code properly!

EDIT: Code removed - get the fixed fixed version below.

Last edited by pmc; 24 March 2010 at 20:30.
pmc is offline  
Old 24 March 2010, 20:04   #143
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Hmm... I'm sorry to annoy you again, but the seek-code still looks suspicious to me.
Code:
.move_to_start:	btst.l	#0,d4
	bne.s	.odd_track
	bsr.s	.lower_head
	bra.s	.step_to_start
.odd_track:	bsr.s	.upper_head
	subq.b	#1,d4
.step_to_start:	addq.b	#1,d5
	cmp.b	d5,d4
	beq.s	.at_start
	bsr.s	.step_heads
	bra.s	.step_to_start
Now you successfully made it work with track 3. But IMHO track 1 would fail.
Example:
d5 = 0 (current track)
d4 = 1 (start track to seek)
Your function calls .upper_head and then decrements d4, which becomes 0.
Then you increment d5 and compare it with d4 to see if the destination is reached. It will fail (for the next 255 steps )!

Unless I'm completely confused (which might be possible) I think that this part of the trackloader will never work, because you still increment the current-track counter d5 by just *one* when you make a step to the next cylinder (which equals *two* tracks).
phx is offline  
Old 24 March 2010, 20:11   #144
zaz
Registered User
 
Join Date: Mar 2010
Location: Lkpg/Swe
Posts: 12
Quote:
Originally Posted by StingRay View Post
Nowadays you seem to be more interested in 6510 coding though. Greetings to B ;D
6510 is nice but recently I'm also interested in 68000 Will forward to B!
Quote:
Originally Posted by StingRay View Post
Yes, this will work and save 2 bytes but it is, as you said, bootblock specific. And if we are going to apply "bootblock optimizations" we can as well remove the step to track zero, switch directions and check if drive is ready routines.
Well this is all an educational exercise anyway, right? For practical applications I'd use trackdisk.device in the bootblock to load the first track and use a hard loader from there. IIRC the first track is already buffered in trackdisk.device.

The bootblock checksum etc was included in the size measurement, so I included that optimization, while pmc said the load routine should be possible to use standalone so I didn't remove that stuff.
zaz is offline  
Old 24 March 2010, 20:22   #145
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
@ phx - you're right about the track 1 thing - I forgot to include my little check for that - I'll sort it at some point - thanks for pointing it out.

Regarding d5 - although it's called "current track" in the code, I regard it as more of a "current cylinder" counter - for example, to get to track two *or* three from the start point of cylinder 0, the code steps the heads just once. Hence d5 == 1 when track == 2 or 3.

Quote:
Originally Posted by phx
Hmm... I'm sorry to annoy you again
It never annoys me if people to look at my code and ask questions or point out mistakes. It helps me look at things from different perspectives and, in the case of a mistake (something I make a lot of! ), learn something in the process.

So, I say - keep annoying me!

Edit: fixed fixed version (412 bytes), works for track 1 starts - thanks again to phx for giving me another kick.

Last edited by pmc; 24 March 2010 at 22:08.
pmc is offline  
Old 24 March 2010, 20:59   #146
zaz
Registered User
 
Join Date: Mar 2010
Location: Lkpg/Swe
Posts: 12
This could work, yes?

Code:
.move_to_start:
    lsr.b #1,d4
    bcc.s    .step_to_start
    bsr.s    .upper_head
.step_to_start:    
    cmp.b    d5,d4
    beq.s    .at_start
    bsr.s    .step_heads
    addq.b  #1,d5
    bra.s    .step_to_start
and something for the trackloader loop:
Code:
.trackloader:
    bsr.s    .read_trk
    bchg    #2,(a6)
    bne.s   .do_next
    bsr.s    .step_heads
.do_next:    
    dbra    d3,.trackloader
Also now .upper_head and .lower_head are only called once each so you can save more by removing the subroutine calls.
zaz is offline  
Old 24 March 2010, 21:40   #147
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by pmc View Post
Regarding d5 - although it's called "current track" in the code, I regard it as more of a "current cylinder" counter - for example, to get to track two *or* three from the start point of cylinder 0, the code steps the heads just once. Hence d5 == 1 when track == 2 or 3.
Ok. But then d4 must be the start-cylinder and not the start-track. Otherwise you cannot compare the two.

Quote:
So, I say - keep annoying me!
Will do!
phx is offline  
Old 24 March 2010, 21:43   #148
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by zaz View Post
This could work, yes?
Yes. Looks much better to me, and is very similar to the "lsr-bcc" approach which I posted yesterday. It's even shorter (and I still had a bug in it)!
phx is offline  
Old 24 March 2010, 21:45   #149
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Hey zaz - I thought you said you were out of practice!
pmc is offline  
Old 24 March 2010, 21:56   #150
zaz
Registered User
 
Join Date: Mar 2010
Location: Lkpg/Swe
Posts: 12
I hope you assembled & tested my suggestions before saying that -- I didn't
zaz is offline  
Old 24 March 2010, 22:10   #151
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Funny you should say that zaz - I just amended, assembled and tested the source including your code in place of mine and it works like an absolute charm and is also now only 380 bytes!

Legendary work fella.

I love seeing how really good coders think about and solve things in contrast to my decidedly amateur efforts.

A richly deserved credit to you is now in the source too.

Last edited by pmc; 03 June 2010 at 09:01.
pmc is offline  
Old 25 March 2010, 00:34   #152
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Very nice!

But something is missing. Although both stack pointers were relocated you didn't care to relocate the trackloader itself to a safe location. As you don't know where the OS had written the boot block there is always the danger that you overwrite it while reading from disk.

This will bring you near to 400 bytes again. But you can delete the Forbid() call, because the interrupts are disabled anyway.
phx is offline  
Old 25 March 2010, 07:32   #153
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by phx
But something is missing. Although both stack pointers were relocated you didn't care to relocate the trackloader itself to a safe location. As you don't know where the OS had written the boot block there is always the danger that you overwrite it while reading from disk.

This will bring you near to 400 bytes again. But you can delete the Forbid() call, because the interrupts are disabled anyway.
Yeah, this is as Toni mentioned previously in this thread. That and some cache flushing after relocating the code, as per some additional advice from StingRay, now needs to be added to make the code more safe and friendly.
pmc is offline  
Old 25 March 2010, 09:40   #154
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by zaz View Post
6510 is nice but recently I'm also interested in 68000 Will forward to B!
I think I remember some trainers you made back in the day. If you are the same zaz that was in Dual Crew on Amiga too that is ;D

Quote:
Originally Posted by zaz View Post
Well this is all an educational exercise anyway, right? For practical applications I'd use trackdisk.device in the bootblock to load the first track and use a hard loader from there. IIRC the first track is already buffered in trackdisk.device.
Yes that's what I'd do too, though, it's not always possible to use trackdisk.device, f.e. if you need to load very low into memory for whatever reason a custom trackloader is needed (well, you could of course use trackdisk to load to a "safe" location and then copy the code around but... ;D)


Quote:
Originally Posted by zaz View Post
The bootblock checksum etc was included in the size measurement, so I included that optimization, while pmc said the load routine should be possible to use standalone so I didn't remove that stuff.
I see where you are coming from but it still is a bootblock specific optimization, i.e. you can't use the loader as is anymore once you applied it. It is a nice little trick though which I thought of too (usually I use the "rootblock offset" as ID for my own stuff) but didn't post it due to aforementioned reasons. It would be interesting to see what the smallest "use any trick in the book" bootblock trackloader would look like, if I'm bored enough I might code one.



Quote:
Originally Posted by phx View Post
But you can delete the Forbid() call, because the interrupts are disabled anyway.
I removed that already but seems PMC didn't use any of my optimizations (the lea dsklen(a5),a0 etc is gone too) in the latest version of his trackloader.

Quote:
Originally Posted by Toni Wilen View Post
Yes, I know. I did say it "technically works"
I know!

Quote:
Originally Posted by Toni Wilen View Post
CIA-A (CIA-B 8-bit data lines are connected to CPU data line bits 8-15, CIA-A = data line bits 0-7) but nothing happens because CIA-A chip select is inactive. (not so simple on 68020+ Amigas but basically same) Still, don't do that
Thanks for the info! Still not an optimization I'd ever use.


Quote:
Originally Posted by pmc View Post
Funny you should say that zaz - I just amended, assembled and tested the source including your code in place of mine and it works like an absolute charm and is also now only 380 bytes!
Could be even smaller (look above)

Last edited by StingRay; 25 March 2010 at 09:51.
StingRay is offline  
Old 25 March 2010, 11:45   #155
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Just had a look at the new version of the trackloader and this is my version of the "move_to_start" routine:

Code:
.move_to_start:
	lsr.b	#1,d4
	beq.b	.at_start
	bcc.s	.step_to_start
	bclr.b	#2,(a6)		;select upper disk head
.step_to_start:
	bsr.b	.step_heads
	subq.b	#1,d4
	bne.b	.step_to_start
Didn't test it but I think it should work. I also did some other optimizations and also added the "copy code to safe location and flush cache" stuff. Size: 400 bytes (my magic number ;P). Not tested at all but *might* still work.

Edit: optimized the "copy to safe location" routine, 398 bytes now. ;D
Attached Files
File Type: 68k opt_bb_trkldr_sting.68k (9.5 KB, 226 views)

Last edited by StingRay; 25 March 2010 at 13:59. Reason: 2 more bytes killed :)
StingRay is offline  
Old 25 March 2010, 12:18   #156
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
I have questions. What is exactly happen when disk is inserted right after reboot ? Is there any documentation about it ?
When OS want to load bootblock somewhere then how he choose the place ( OS do AllocMem for bootblock or something ??? ).
Asman is offline  
Old 25 March 2010, 19:19   #157
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,517
Quote:
Originally Posted by Asman View Post
I have questions. What is exactly happen when disk is inserted right after reboot ? Is there any documentation about it ?
When OS want to load bootblock somewhere then how he choose the place ( OS do AllocMem for bootblock or something ??? ).
Identifier (dostype) is checked, memory allocated normally (afaik it is always from chip ram), boot block loaded, checksum checked and finally boot block code is executed with following register contents:

A1 = trackdisk.device io request
A6 = execbase

I don't know if official documentation exists.
Toni Wilen is offline  
Old 25 March 2010, 19:24   #158
zaz
Registered User
 
Join Date: Mar 2010
Location: Lkpg/Swe
Posts: 12
There's at least this from Devices:
http://amigadev.elowar.com/read/ADCD.../node007D.html
zaz is offline  
Old 25 March 2010, 19:25   #159
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by zaz
Well this is all an educational exercise anyway, right? For practical applications I'd use trackdisk.device in the bootblock to load the first track and use a hard loader from there. IIRC the first track is already buffered in trackdisk.device.
Quote:
Originally Posted by StingRay
Yes that's what I'd do too, though, it's not always possible to use trackdisk.device, f.e. if you need to load very low into memory for whatever reason a custom trackloader is needed (well, you could of course use trackdisk to load to a "safe" location and then copy the code around but... ;D)
You guys would use the trackdisk.device instead of getting hardcore and bashing the hardware directly...?

The OS is for wimps - I thought you were real men!

Quote:
Originally Posted by StingRay
I removed that already but seems PMC didn't use any of my optimizations (the lea dsklen(a5),a0 etc is gone too) in the latest version of his trackloader.
Sorry dude - I didn't mean to be disrespectful to your optimisations.

Quote:
Originally Posted by StingRay
Could be even smaller (look above)
When you're around and hunting for optimisations, I don't doubt it.

Quote:
Originally Posted by StingRay
I also did some other optimizations and also added the "copy code to safe location and flush cache" stuff.
Great work Stinger.

Quote:
Originally Posted by Asman
I have questions. What is exactly happen when disk is inserted right after reboot ? Is there any documentation about it ?
When OS want to load bootblock somewhere then how he choose the place ( OS do AllocMem for bootblock or something ??? ).
I'd like to know these type of things too - I know next to *nothing* about the OS or OS type functions and calls.

EDIT - too slow posting - Toni and zaz to the rescue.
pmc is offline  
Old 25 March 2010, 19:57   #160
zaz
Registered User
 
Join Date: Mar 2010
Location: Lkpg/Swe
Posts: 12
372 bytes now.

Using dsklen as base register was discussed before; this version has it and keeps readability by using asmone/phxass/vasm BASEREG.

Also some bset/bclr to CIA is collapsed to move/ori but should be in a safe manner.

But what happens if $60000 is allocated already? Even with AllocAbs() the loader will fail if that happens...

After the system is killed we could copy the loader to $c0 or some low address and just assume the bootblock is not loaded there (like with the stack relocations), but then it's no longer safe to use library calls to flush the cache...

opt_bb_trkldr_zaz.68k
zaz 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 03:50.

Top

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