Simplify build by adapting checksum program
This now prepends length bytes as well as adding checksum
This commit is contained in:
parent
a6698e3ead
commit
612cf374a3
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
*.tap
|
*.tap
|
||||||
*bin
|
*bin
|
||||||
*bincs
|
*bincs
|
||||||
ac
|
ttttt
|
||||||
|
41
Makefile
41
Makefile
@ -1,33 +1,28 @@
|
|||||||
program.tap: program.asm headerbincs body.tap
|
program.tap: header.block body.block
|
||||||
pasmo program.asm program.tap
|
cat header.block body.block > program.tap
|
||||||
|
|
||||||
headerbincs: headerbin ac
|
header.block: header ttttt
|
||||||
cp headerbin headerbincs
|
./ttttt header
|
||||||
./ac headerbincs
|
|
||||||
|
|
||||||
headerbin: header.tap
|
header: header.asm body.block
|
||||||
dd if=header.tap of=headerbin bs=1 count=18
|
pasmo header.asm headerlong
|
||||||
|
dd if=headerlong of=header bs=18 count=1
|
||||||
|
rm -f headerlong
|
||||||
|
|
||||||
header.tap: header.asm body.tap
|
body.block: body ttttt
|
||||||
pasmo header.asm header.tap
|
./ttttt body
|
||||||
|
|
||||||
body.tap: body.asm bodybincs
|
body: remload.asm code.asm
|
||||||
pasmo body.asm body.tap
|
pasmo remload.asm body
|
||||||
|
|
||||||
bodybincs: bodybin ac
|
ttttt: ttttt.c
|
||||||
cp bodybin bodybincs
|
cc ttttt.c -o ttttt
|
||||||
./ac bodybincs
|
|
||||||
|
|
||||||
bodybin: remload.asm code.asm
|
|
||||||
pasmo remload.asm bodybin
|
|
||||||
|
|
||||||
ac: append_checksum.c
|
|
||||||
cc append_checksum.c -o ac
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.tap
|
rm -f *.tap
|
||||||
rm -f *bin
|
rm -f *.block
|
||||||
rm -f *bincs
|
rm -f body
|
||||||
rm -f ac
|
rm -f header
|
||||||
|
rm -f ttttt
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
unsigned char tally = 0;
|
|
||||||
unsigned char next = 0;
|
|
||||||
if (argc!=2) return -1;
|
|
||||||
|
|
||||||
fd = open(argv[1], O_RDWR|O_APPEND);
|
|
||||||
if (fd<0) return -2;
|
|
||||||
|
|
||||||
while (read(fd, &next, 1)) {
|
|
||||||
//printf("Tally: %X, next byte: %X\n", tally, next);
|
|
||||||
tally ^= next;
|
|
||||||
};
|
|
||||||
|
|
||||||
printf("Final tally: %X\n", tally);
|
|
||||||
|
|
||||||
write(fd, &tally, 1);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
7
body.asm
7
body.asm
@ -1,7 +0,0 @@
|
|||||||
bodylength:
|
|
||||||
dw bodyend - bodycontent
|
|
||||||
|
|
||||||
bodycontent:
|
|
||||||
INCBIN bodybincs
|
|
||||||
|
|
||||||
bodyend:
|
|
@ -20,5 +20,5 @@ checksum:
|
|||||||
db 0
|
db 0
|
||||||
|
|
||||||
bodytap:
|
bodytap:
|
||||||
INCBIN body.tap
|
INCBIN body.block
|
||||||
endbodytap:
|
endbodytap:
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
headlength:
|
|
||||||
dw 19
|
|
||||||
|
|
||||||
INCBIN headerbincs
|
|
||||||
INCBIN body.tap
|
|
69
ttttt.c
Normal file
69
ttttt.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* McPhail's Tip-Top TAP Top-Tailer
|
||||||
|
* Takes a raw code file as input
|
||||||
|
* Prepends data length and appends xor checksum
|
||||||
|
* Outputs to new file with .block suffix */
|
||||||
|
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int fdin, fdout;
|
||||||
|
char outfilename[PATH_MAX];
|
||||||
|
unsigned int count = 0;
|
||||||
|
unsigned char tally = 0;
|
||||||
|
unsigned char next = 0;
|
||||||
|
if (argc!=2) {
|
||||||
|
printf("Please specify file to read.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fdin = open(argv[1], O_RDONLY);
|
||||||
|
if (fdin<0) {
|
||||||
|
printf("Couldn't open %s. for reading\n", argv[1]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(outfilename, PATH_MAX, "%s.block", argv[1]);
|
||||||
|
outfilename[PATH_MAX - 1] = '\0';
|
||||||
|
if (! strcmp(argv[1], outfilename)) {
|
||||||
|
printf("Filename too long - would clobber existing.\n");
|
||||||
|
close(fdin);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fdout = open(outfilename, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
|
||||||
|
if (fdout<0) {
|
||||||
|
printf("Couldn't open %s for writing.\n", outfilename);
|
||||||
|
close(fdin);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (read(fdin, &next, 1)) {
|
||||||
|
tally ^= next;
|
||||||
|
count ++;
|
||||||
|
};
|
||||||
|
lseek(fdin, 0, SEEK_SET);
|
||||||
|
|
||||||
|
char lsb = (count+1)&255;
|
||||||
|
char msb = ((count+1)>>8)&255;
|
||||||
|
write(fdout, &lsb, 1);
|
||||||
|
write(fdout, &msb, 1);
|
||||||
|
while (read(fdin, &next, 1)) {
|
||||||
|
write(fdout, &next, 1);
|
||||||
|
}
|
||||||
|
write(fdout, &tally, 1);
|
||||||
|
|
||||||
|
close(fdout);
|
||||||
|
close(fdin);
|
||||||
|
|
||||||
|
printf("File %s written.\n", outfilename);
|
||||||
|
printf("Code length including first byte is %d (0x%.4X).\n", count, count);
|
||||||
|
printf("Removing first byte gives 0x%.4X.\n", count-1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user