English Amiga Board Evaluate a location on floppy disk by offset? (t/h/s)
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 21 June 2005, 18:28 #1 andreas Zone Friend   Join Date: Jun 2001 Location: Germany Age: 45 Posts: 5,857 Evaluate a location on floppy disk by offset? (c/h/s) I wonder if something like this exists on aminet, but if I don't know the name ... Usually, I'm cross-working on both Windows and WinUAE (Amiga), hence this would come in handy: comfortably edit disk images on WinHex (Windows), then using it back on the Amiga. Problem is a Windows tool will only give me a raw offset number like \$B1E00. Is there any tool available that will compute the track, head and sector from the offset, so I can see where exactly I am on the disk image? A formula would come in handy too; then I'd write it myself as a little console app on (Turbo) C Win32. Last edited by andreas; 21 June 2005 at 21:42.
 21 June 2005, 18:40 #2 IFW Moderator   Join Date: Jan 2003 Location: ... Age: 47 Posts: 1,838 c*0x2c00+h*0x1600+s*0x200 c: 0...79 (or upto 83) h: 0...1 s: 0...10
 21 June 2005, 21:38 #3 andreas Zone Friend   Join Date: Jun 2001 Location: Germany Age: 45 Posts: 5,857 Umm thanks, but this doesn't OUTPUT me the track header or sector if an offset is given. Anyway, I'm a bit further now. (NOTE: I will calculate with real cylinders 0 .. 79, not "tracks" 0..159 as this always confuses me a lot ) [DIV = integer division] given is: offset in hex (0x00000 .. 0xDBFFF) cylinder = offset DIV 0x2c00 head = (offset DIV 0x1600) MOD 0x02 { odd or even; result is equal to head # } sector = (offset >> 9) MOD 0x0B long word # = (offset >> 2) MOD 0x80 { only for logical reasons: offset MOD 0x80 works too! } This works, looks a bit complicated, though. Moreover, pity I cannot use shift with the other half here because the divisors are no powers of 2 Last edited by andreas; 23 June 2005 at 03:23.
 22 June 2005, 13:05 #4 IFW Moderator   Join Date: Jan 2003 Location: ... Age: 47 Posts: 1,838 Well if you think this is complex... oh dear Anyway if you are so much concerned you shouldn't have used MOD which is the remainder of a division and such is performed by using a division. For two numbers there you can use an AND operation instead.
22 June 2005, 19:54   #5
andreas
Zone Friend

Join Date: Jun 2001
Location: Germany
Age: 45
Posts: 5,857
Quote:
 Originally Posted by IFW Well if you think this is complex... oh dear
*bzzzt* Wrong! I said this is complicated, which is not the same!
If I think it is complicated, it means that it's me who is probably thinking too complicated and that any other people might find a simpler way!
Though it looks it's a working and not-considered-too-complicated way.
So I will keep this.

Quote:
 Anyway if you are so much concerned
You ALWAYS should. This is good programming; as it doesn't get you into this "bahh, we have 3 ghz machines - who cares!" thinking.
I still use *unsigned short* whenever possible, although by average, no machine might care about this nowadays. But -- sorry I'm getting a bit OT -- this is what makes WinFellow run on low-end machines: only using CPU and memory hogs if really necessary; all other techniques follow the "use the LEAST you require" rule. And I think this is good practice, and I'm very happy to see this in all those GPL applications coded for Linux. Rant over.

Quote:
 you shouldn't have used MOD which is the remainder of a division and such is performed by using a division. For two numbers there you can use an AND operation instead.
AND? Well you should know about that! Thanks!
When thinking a formula in my head, I usually use MOD because that way, it is easier to predict results. For AND, I will usually have to write the value down in binary (yes, even on paper ) as well as AND it by hand, so I can assure the result is the one I wanted.
OR is usually predictable; but AND does a lot of modifications...
But well, if AND really works exactly as MOD with two binary numbers, this is even better

Last edited by andreas; 22 June 2005 at 20:19.

 22 June 2005, 20:47 #6 IFW Moderator   Join Date: Jan 2003 Location: ... Age: 47 Posts: 1,838 NP As for using short vs int I have sad news for you: modern cpus - anything from PII/PPro class..., or PPC, G3+, MIPS, Cell, etc - only process their native instruction size fast and struggle with shorter types. At best they just stall the cache at worst the memory bus. Also to prevent stalls you should put your variables aligned for cpu memory access. Ie never use an odd address (major speed penalty) or an address that is not divisible by the data size without modulo. - like say address 2, 6, .... for a a 4 byte value is bad, but 0, 4, 8 etc is good, same logic with quads, ie only addresses ending on 0 and 8 in hex are acceptable without a stall. The same is also true for graphics, framebuffers and so on. So if speed is your concern you are better off learning cpu stuff, if size you are fine with unnatural (non-cpu native) data sizes. Sorry
22 June 2005, 21:25   #7
andreas
Zone Friend

Join Date: Jun 2001
Location: Germany
Age: 45
Posts: 5,857
Quote:
 Originally Posted by IFW NP As for using short vs int I have sad news for you: modern cpus - anything from PII/PPro class..., or PPC, G3+, MIPS, Cell, etc - only process their native instruction size fast and struggle with shorter types. At best they just stall the cache at worst the memory bus.
Ooaahh.

Quote:
 Also to prevent stalls you should put your variables aligned for cpu memory access. Ie never use an odd address (major speed penalty) or an address that is not divisible by the data size without modulo. - like say address 2, 6, .... for a a 4 byte value is bad, but 0, 4, 8 etc is good, same logic with quads, ie only addresses ending on 0 and 8 in hex are acceptable without a stall. The same is also true for graphics, framebuffers and so on.
Yeah..

BTW your (binary) MOD = (bitwise) AND did not work for any formula

Quote:
 sector = (offset >> 9) MOD 0x0B
With ... AND 0x0B, you will get crap, e. g. sector = 11 which doesn't exist at all. I will keep to MOD for now...

 22 June 2005, 21:29 #8 IFW Moderator   Join Date: Jan 2003 Location: ... Age: 47 Posts: 1,838 Since when 11 is a well divisible binary number to use for ANDing...? *Two* of the numbers above are good for optimisation you picked the wrong one. C'mon you can do better that that
 23 June 2005, 00:32 #9 dlfrsilver CaptainM68K-SPS France   Join Date: Dec 2004 Location: Melun nearby Paris/France Age: 41 Posts: 7,915 try hexedit, it give the right offset on an ADF, for example when an adf is 901120 it's \$DC000 ? well hexedit gives you the right length..... Hexedit is a simple and nice hexadécimal editor ^^
 23 June 2005, 03:19 #10 andreas Zone Friend   Join Date: Jun 2001 Location: Germany Age: 45 Posts: 5,857 Why doesn't anyone understand me, hey? The offset is the input, the output is cyl xx, head xx, sector xx, optionally block xx. As in my tool I've just finished. Should compile fine on BOTH (!) unix and msdos/win32. Or someone can even manage to port this to Amiga. Good luck! Last edited by andreas; 23 June 2005 at 13:04.
 23 June 2005, 09:07 #11 Codetapper 2 contact me: email only!   Join Date: May 2001 Location: Auckland / New Zealand Posts: 3,153 Your compiler is not particularly strict. It is good style to declare all variables before calling any functions. For the hell of it I ran it through GCC and got these: Code: ```locate.c: In function `menuSelect': locate.c:192: parse error before `unsigned' locate.c:195: `ch' undeclared (first use in this function) locate.c:195: (Each undeclared identifier is reported only once locate.c:195: for each function it appears in.) locate.c: In function `pressKey': locate.c:253: parse error before `unsigned' locate.c:255: `d' undeclared (first use in this function) locate.c:258: `ch' undeclared (first use in this function)``` You could probably write a PHP page or javascript to output the data you need in about 10 lines btw... 200+ lines for this program seems overkill to me! Also there is no need to give this file a CPP extension when it's 100% C...
23 June 2005, 13:03   #12
andreas
Zone Friend

Join Date: Jun 2001
Location: Germany
Age: 45
Posts: 5,857
I used gcc on cygwin (Win32 unix layer) which usually behaves almost exactly like Linux gcc. I could reveal some of your errors by using gcc -pedantic. I now know what you mean: ISO C90! I must not use any declaration after a statement. Thanks. I've fixed this - should compile fine now.

About CPP: Tell that to the others too. I found zillions of source code with cpp extension but not even 'cout' used inside.

About why no Javascript/PHP: Sir, I want a standalone application! Why do I want to program server-side when I require a server for it? *That* is overkill, to require a web server running for PHP or a HTML page as a container to run (client-side, mind you!) JavaScript!

About the number of lines: I do like a good user interface!! And also I like to tell what the program does instead of people having to look for extra readme files...
That's what takes most of it, not the calculation!
It's not me who caused all that problems with echoing characters, etc! getch() works so well on MSDOS, but is incompatible. And getchar() just lets me run off but not stop while waiting for input. User I/O is really a major annoyance in C, if you want to write *portable* code. Well as in FAQs, you get told to use system interrupts (!) for requesting user input without pressing RETURN, this is tough stuff.
Attached Files
 LOCATEPO.zip (14.3 KB, 121 views)

Last edited by andreas; 23 June 2005 at 15:19.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 Similar Threads Thread Thread Starter Forum Replies Last Post Jherek Carnelia Coders. General 26 21 March 2011 11:49 blitter1 support.Apps 3 20 March 2010 16:18 Anubis project.WHDLoad 4 27 January 2010 22:20 stef80 project.Sprites 2 06 July 2007 20:59 dreamkatcha New to Emulation or Amiga scene 33 24 July 2004 15:25

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE         project.AmigaLive     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.EAB File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     Collections     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic     Coders. Contest         Coders. Entries Off Topic     OT - General     OT - Entertainment     OT - Sports     OT - Technical     OT - Gaming

All times are GMT +2. The time now is 20:46.

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top