3

I'm hoping someone may be able to help with the program dd which can do lots of things to files.

First of all, I use this program to cut a NES ROM into 2 files, graphics and code (1024 Kb for code, 512 Kb for graphics). It has a header at the start which is 16 bytes. And I have to remove that header first, before I put it into the "NESASM" assembler.

So that's where dd comes in. I have this setup which works.

dd if=MMC5 EXAtt MegaMan3.nes of=PRGrom.bin bs=16 skip=1 count=64k
dd if=MMC5 EXAtt MegaMan3.nes of=CHRgfx.bin bs=16 skip=65537 count=32k

It skips the first 16 bytes as I wanted. However, it's slow though, to complete. I've searched for MANY hours on google, seen tons of threads on stackexchange here, about using iflag=skip_bytes ... to do this in bytes and not blocks. But the version of dd I have does not seem to support it.

I'm really hoping somebody here has a version of dd they can upload that has that "skip bytes" command supported. What I wanted to do was

  • skip the first 16 bytes only
  • and split it into 512 KB chunks so it would do this much faster than just 16 bytes at a time.

One method I tried was putting the bs=16 skip=1 at start of the input file line, then bs=512k on the output file line, but that doesn't work, it still only did it 16 bytes at a time. (I've tried tons of different ways like this)

I got dd from this page originally which does not have those "count bytes" or "skip bytes" options.

I don't want to go through the trouble of downloading Visual Studio 2010 or whatever is required to get the new dd version. Because everywhere I look, there's only source code files available to download on github and other places. I don't want all those GNU tools, just dd only.

I am on Windows XP, not Linux or other type of OS if that helps. I apologize if this is the wrong forum to ask. Most threads I have seen about dd were on this one specifically.

  • It looks like this GUI tool would also do the job? – Freddy Jan 31 at 12:24
  • dd.exe in this one has seek/count/skip_bytes: packages.msys2.org/package/coreutils?repo=msys&variant=i686 – frostschutz Jan 31 at 15:12
  • @frostschutz - yea i appreciate it. I posted down that i got it now from that 2.10 link stephane posted in his edit. here's a screenshot :) i.imgur.com/4ro89m8.png – kuja killer Jan 31 at 15:21
  • How slow are we talking about? These operations takes between 200 and 400 ms on my 10 year old core2 computer with rotating platter disks. Doing it on my 1600 ROM collection would have been faster than searching for hours! I'm thinking maybe there is a different problem to solve than what you ask for. – pipe Jan 31 at 21:05
8

You could use GNU coreutils head instead:

{
  head -c 16   > /dev/null
  head -c 1m   > PRGrom.bin
  head -c 512k > CHRgfx.bin
} < 'MMC5 EXAtt MegaMan3.nes'

(that's Unix shell syntax, you may need to adapt if using a Microsoft command-line interpreter).

You may want to consider cygwin instead of that ancient gnuwin32 on Windows which will give you something closer to a proper modern GNU-like environment (Linux is not an OS btw, just the kernel found in a few Unix-like and non-Unix-like OSes).

skip_bytes was added to GNU dd in 2012 (coreutils 8.16). The latest version of that gnuwin32 is from 2005 (though I suppose that's contemporary to your Windows XP). You can find compiled versions of modern versions of GNU coreutils including dd in Cygwin and Git for Windows at least, both of which also come with POSIX shell interpreters. Cygwin has stopped supporting Windows XP circa 2016, but you should still be able to download versions from around that time from there for instance. Git for Windows dropped support for Windows XP after version 2.10.0, but it's still available online, and both postdate the coretutils 8.16 release.

| improve this answer | |
  • Hmm, i havent heard of that program "head" ever before. Is it faster than dd ?? And i remember seeing that "dev/null" thing before a few times, and i tried that on the dd program, but it doesnt recgonize it. So i dont know what the equivalent is on the windows XP command prompt. I use a regular notepad "batch" script to do this with the Command Prompt by the way. – kuja killer Jan 31 at 12:13
  • 1
    @kujakiller, unless you want to go the full POSIX way and do it in a POSIX-like shell script (using Cygwin or WSL or a GNU/Linux virtual machine...), I'd suggest you do it with the native Windows tools and ask for help on superuser for instance. I'd expect Microsoft PowerShell would be able to do it. – Stéphane Chazelas Jan 31 at 12:16
  • @kujakiller /dev/null is the "black hole" on a linux system. In Windows (atleast batch scripts), the equivalent is NUL. – Panki Jan 31 at 12:20
  • Oh i see. Yea i figured that was a linux thing. And i just kinda figured something out actually. It seemed if i did "ibs" and not "bs" -- it goes a little bit faster. This is an example "before" 1048576 bytes (1.0 MB) copied, 0.51 seconds, -0.0 MB/s 524288 bytes (524 kB) copied, 0.1875 seconds, -0.0 MB/s that's with "bs" ..and if i do "ibs" it looks more like this: 1048576 bytes (1.0 MB) copied, 0.125 seconds, 8.4 MB/s 524288 bytes (524 kB) copied, 0.07 seconds – kuja killer Jan 31 at 12:56
  • 1
    @Stéphane Chazelas woa that 2.10 you linked worked. it had the updated dd. :) And now the skipbytes worked, and faster. :) so i did this: bs=512k count=2 skip=16 iflag=skip_bytes - for the first part, and bs=512k skip=1048592 iflag=skip_bytes - for the 2nd part, and the result was 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.009 s, 115 MB/s 524288 bytes (524 kB, 512 KiB) copied, 0.004 s, 108 MB/s NES Assembler (v2.51+autozp beta3) pass 1 – kuja killer Jan 31 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.