2 Commits
v1.0 ... v2.0

Author SHA1 Message Date
1c7ab48330 Simplify build by adapting checksum program
This now prepends length bytes as well as adding checksum
2024-11-11 10:17:34 +00:00
a6698e3ead Add a custom entry point to the user code
The routine does not have to start from the first byte of machine code
2024-11-10 19:17:37 +00:00
9 changed files with 100 additions and 64 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
*.tap
*bin
*bincs
ac
ttttt

View File

@ -1,33 +1,28 @@
program.tap: program.asm headerbincs body.tap
pasmo program.asm program.tap
program.tap: header.block body.block
cat header.block body.block > program.tap
headerbincs: headerbin ac
cp headerbin headerbincs
./ac headerbincs
header.block: header ttttt
./ttttt header
headerbin: header.tap
dd if=header.tap of=headerbin bs=1 count=18
header: header.asm body.block
pasmo header.asm headerlong
dd if=headerlong of=header bs=18 count=1
rm -f headerlong
header.tap: header.asm body.tap
pasmo header.asm header.tap
body.block: body ttttt
./ttttt body
body.tap: body.asm bodybincs
pasmo body.asm body.tap
body: remload.asm code.asm
pasmo remload.asm body
bodybincs: bodybin ac
cp bodybin bodybincs
./ac bodybincs
bodybin: remload.asm code.asm
pasmo remload.asm bodybin
ac: append_checksum.c
cc append_checksum.c -o ac
ttttt: ttttt.c
cc ttttt.c -o ttttt
clean:
rm -f *.tap
rm -f *bin
rm -f *bincs
rm -f ac
rm -f *.block
rm -f body
rm -f header
rm -f ttttt
.PHONY: clean

View File

@ -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;
}

View File

@ -1,7 +0,0 @@
bodylength:
dw bodyend - bodycontent
bodycontent:
INCBIN bodybincs
bodyend:

View File

@ -1,2 +1,12 @@
; This is the main file you will edit to add your machine code to the REM statement.
; You _must_ include the "entry_point" tag to point to the address which will called by the BASIC "PRINT USR" statement.
; The default code below is for illustration only, and can be deleted.
; But REMEMBER TO ADD THE entry_point TAG TO YOUR OWN CODE!
data_start: ;if your routine starts here, move the entry_point tag here too
ld bc, 42
ret
entry_point: ;move this tag to the start point of your code
jr data_start

View File

@ -20,5 +20,5 @@ checksum:
db 0
bodytap:
INCBIN body.tap
INCBIN body.block
endbodytap:

View File

@ -1,5 +0,0 @@
headlength:
dw 19
INCBIN headerbincs
INCBIN body.tap

View File

@ -45,7 +45,7 @@ printusr:
db "0" ;don't know if actual value is important
db #0e
db 0,0
dw code ;actual call to REM statement code
dw entry_point ;actual call to REM statement code
db 0
db ':'

69
ttttt.c Normal file
View 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;
}