mirror of
https://frontier.innolan.net/github/AmigaExamples.git
synced 2025-12-08 16:52:44 +00:00
Converted makeadf to be consistent with imagecon
This commit is contained in:
BIN
tools/makeadf
BIN
tools/makeadf
Binary file not shown.
16
tools/makeadf/Makefile
Normal file
16
tools/makeadf/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
MAKEADF=./bin/makeadf
|
||||
SRCS=makeadf.c
|
||||
HOST_WARNINGS=-pedantic-errors -Wfatal-errors -Wall -Werror -Wextra -Wno-unused-parameter -Wshadow
|
||||
HOST_CFLAGS=$(HOST_WARNINGS)
|
||||
|
||||
$(MAKEADF): out bin $(SRCS)
|
||||
gcc $(HOST_CFLAGS) $(SRCS) -o $(MAKEADF)
|
||||
|
||||
out:
|
||||
mkdir out
|
||||
|
||||
bin:
|
||||
mkdir bin
|
||||
|
||||
clean:
|
||||
rm -r out bin
|
||||
64
tools/makeadf/makeadf.c
Normal file
64
tools/makeadf/makeadf.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* http://eab.abime.net/showpost.php?p=895070&postcount=6
|
||||
* Makes a disk image of 901120 (0xdc000) bytes.
|
||||
* Calculates boot block checksum.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define DISKSIZE (0xdc000)
|
||||
|
||||
uint8_t image[DISKSIZE];
|
||||
|
||||
|
||||
static void boot_chksum(uint8_t *p)
|
||||
{
|
||||
uint32_t oldchk,chk=0;
|
||||
int i;
|
||||
|
||||
memset(p+4,0,4);
|
||||
for (i=0; i<1024; i+=4) {
|
||||
oldchk = chk;
|
||||
chk += ((uint32_t)p[i+0] << 24) | ((uint32_t)p[i+1] << 16) |
|
||||
((uint32_t)p[i+2] << 8) | p[i+3];
|
||||
if (chk < oldchk)
|
||||
++chk; /* carry */
|
||||
}
|
||||
|
||||
chk = ~chk;
|
||||
p[4] = (uint8_t)((chk >> 24) & 0xff);
|
||||
p[5] = (uint8_t)((chk >> 16) & 0xff);
|
||||
p[6] = (uint8_t)((chk >> 8) & 0xff);
|
||||
p[7] = (uint8_t)(chk & 0xff);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
int rc = 1;
|
||||
size_t len;
|
||||
|
||||
if (argc == 2) {
|
||||
if ((f = fopen(argv[1],"rb"))) {
|
||||
len = fread(image,1,DISKSIZE,f);
|
||||
if (len > 0) {
|
||||
if (len < DISKSIZE)
|
||||
memset(image+len,0,DISKSIZE-len);
|
||||
boot_chksum(image);
|
||||
fwrite(image,1,DISKSIZE,stdout);
|
||||
rc = 0;
|
||||
}
|
||||
else
|
||||
fprintf(stderr,"Image read error!\n");
|
||||
}
|
||||
else
|
||||
fprintf(stderr,"Cannot open '%s'!\n",argv[0]);
|
||||
}
|
||||
else
|
||||
fprintf(stderr,"Usage: %s <image data>\n",argv[0]);
|
||||
|
||||
return rc;
|
||||
}
|
||||
Reference in New Issue
Block a user