From 09c566e6916d431606284a527ce373c103be39dc Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 22 Aug 2004 01:06:09 +0000 Subject: Initial working version --- tap.c | 93 +++++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 33 deletions(-) (limited to 'tap.c') diff --git a/tap.c b/tap.c index 0c9b3c7..01f7e88 100644 --- a/tap.c +++ b/tap.c @@ -55,7 +55,7 @@ static int file_no; /* ---------------------------------------- PRIVATE FUNCTIONS */ -unsigned char TapWord(unsigned w, unsigned char chk) +static unsigned char TapWord(unsigned w, unsigned char chk) { putc(w&0xff,fp); chk^=w&0xff; @@ -64,14 +64,14 @@ unsigned char TapWord(unsigned w, unsigned char chk) return chk; } -unsigned char TapByte(unsigned char c, unsigned char chk) +static unsigned char TapByte(unsigned char c, unsigned char chk) { putc(c,fp); chk^=c; return chk; } -unsigned char TapString(char *p, int len, unsigned char chk) +static unsigned char TapString(const char *p, int len, unsigned char chk) { while(len--) { @@ -81,8 +81,8 @@ unsigned char TapString(char *p, int len, unsigned char chk) return chk; } -unsigned char TapStream(const unsigned char p[0x10000], - unsigned addr, unsigned len, unsigned char chk) +static unsigned char TapStream(const unsigned char p[0x10000], + unsigned addr, unsigned len, unsigned char chk) { while(len--) { @@ -93,6 +93,19 @@ unsigned char TapStream(const unsigned char p[0x10000], return chk; } + +static const char *FileName(void) +{ + static char name[11]; + + sprintf(name,"FILE%4.4d ",file_no); + file_no=(file_no+1)%10000; + + return name; +} + + + /* ---------------------------------------- INTERFACES */ @@ -109,50 +122,64 @@ int TapOpen(const char *filename) } -void TapWrite(const unsigned char mem[0x1000], - unsigned addr, unsigned len, int is_code) +void TapBasic(const unsigned char *base, + unsigned len, unsigned run_line) { - char name[11]={0}; unsigned char chk; - sprintf(name,"%10.10d",file_no); - file_no=(file_no+1)%10000; - /* Output file header */ - chk=TapWord(19,chk); - chk=TapByte(0,chk); + TapWord(19,0); - if (is_code) - { - chk=TapByte(3,chk); - } - else - { - chk=TapByte(3,chk); - } + chk=0; - chk=TapString(name,10,chk); + chk=TapByte(0,chk); + chk=TapByte(0,chk); + chk=TapString(FileName(),10,chk); chk=TapWord(len,chk); + chk=TapWord(run_line,chk); + chk=TapWord(len,chk); /* ?? */ - if (is_code) - { - chk=TapWord(addr,chk); - chk=TapWord(32768,chk); - } - else - { - chk=TapWord(0,chk); - chk=TapWord(0,chk); - } + TapByte(chk,0); + + /* Output file data + */ + TapWord(len+2,0); + + chk=0; + + chk=TapByte(0xff,chk); + chk=TapStream(base,0,len,chk); + TapByte(chk,0); +} + + +void TapBinary(const unsigned char mem[0x1000], unsigned addr, unsigned len) +{ + unsigned char chk; + + /* Output file header + */ + TapWord(19,0); + + chk=0; + + chk=TapByte(0,chk); + chk=TapByte(3,chk); + chk=TapString(FileName(),10,chk); + chk=TapWord(len,chk); + chk=TapWord(addr,chk); + chk=TapWord(32768,chk); TapByte(chk,0); /* Output file data */ + TapWord(len+2,0); + chk=0; - chk=TapWord(len+2,chk); + chk=TapByte(0xff,chk); chk=TapStream(mem,addr,len,chk); TapByte(chk,0); } -- cgit v1.2.3