Videopac / Odyssey2 forum
August 06, 2021, 05:44:04 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Join Rafael's Haunted Woods contest and win a copy of the game!
 
   Home   Help Login Register links videopac.nl  
Pages: 1 [2]   Go Down
  Print  
Author Topic: C7420 basic stuff  (Read 8154 times)
manopac
Game & App Development
Give this man a Jopac!
*
Posts: 1157



« Reply #15 on: May 03, 2011, 10:53:50 AM »

I think it is easier to connect the C7420 to your PC and let that do the recording and playback. That way you can even get the source back from the audio file you record on the PC with the migration tool at http://www.ifs.tuwien.ac.at/dp/hc_audio_migration/
Ren? can tell if it is also possible to create wave files from a given basic source with that tool. That would save a lot of typing.

I somehow missed this message - yes, of course its possible ... you can just create a new file (File -> New -> Basic Program, and give it a name, e.g. spacei), copy the source from the first post in, and export it as a wav-file (or do a direct Audio-playback, if you have your C7420 connected) ...

btw: gertk: it can also export it as a raw-binary for use on your SD-card ...
Logged

sex, lies, and videopac
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #16 on: May 03, 2011, 10:29:16 PM »

btw: gertk: it can also export it as a raw-binary for use on your SD-card ...

Yes, I have been playing a bit with this already.
I have found out that syntax checking/keyword recognition  is working only if you put spaces around the keywords (?)
Other thing is: if I save it in raw binary format the 0xFF padding is still in the file (in front of the header and in front of the program itself) which in this day and age with GBytes to spare is not really a problem anymore but my emulated CSAVE only saves the 24 byte header, a zero byte and then programdata. With a few lines of shell scripting this could be converted easily though.

My second mbed has arrived with another prototyping board so I hope to find the time to make this into the 'universal rom and other addons emulation cartridge' prototype. Someone also made a lowcost version of the mbed module (without Ethernet and without the direct option to compile and upload to the module from the 'cloud' compiler)
That module might be usable for an affordable 'production' model, that is: if my theory works...


 
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #17 on: May 17, 2011, 09:21:04 PM »

Some more fiddling to make programming a bit easier:

This converter program converts an ASCII (text) Basic program into the binary form the C7420 uses. It produces no header yet, maybe Ren? can help me out in filling in the header bytes. This program differs from Ren?'s converter in so far that it also recognizes basic commands which are not seperated by spaces:

for example:

10PRINTSPC(10);"Hello World!":PRINTSTICK(0)

This program is meant to be a backend to a kind of pre-processor I have made (years ago for a 8052AH Basic processor) in which you can write a basic program using labels instead of linenumbers. The pre-processor converts the source then into a standard line numbered basic program but still in ASCII form. After pre-processing the converter generates the binary form.

Code:
// Tokenizer program for converting BASIC 80 source code to
// tokenized (binary) form data
// by Gert van der Knokke (c)2011

#include <stdio.h>
#include <string.h>
#define DEBUG   false


// my pseudo ram space
unsigned char ramspace[16384];
#define RAMEND 2048

#define MAXTOKENS 91
static char token[MAXTOKENS][10]={"END","FOR","NEXT","DATA","INPUT","DIM","READ","LET",
"GOTO","RUN","IF","RESTORE","GOSUB","RETURN","REM",
"STOP","ON","LPRINT","DEF","POKE","PRINT","CONT",
"LIST","LLIST","CLEAR","CLOAD","CSAVE","TX","GR",
"SCREEN","LINE","DISPLAY","STORE","INIT","CURSORX",
"CURSORY","SCROLL","PAGE","BRIGHT","SOUND","DELIM",
"SETET","SETEG","ET","EG","NEW","TAB(","TO","FN",
"SPC(","THEN","NOT","STEP","+","-","*","/","^","AND",
"OR",">","=","<","SGN","INT","ABS","USR","FRE","LPOS",
"POS","SQR","RND","LOG","EXP","COS","SIN","TAN","ATN",
"PEEK","LEN","STR$","VAL","ASC","STICKX","STICKY",
"ACTION","KEY","CHR$","LEFT$","RIGHT$","MID$"};

#define BASICOFFSET 0x88C1
#define TAPEOFFSET 25

// This functions compares all tokens with given string
// and returns a token number or NULL if no token is found
// Since it compares the exact length of the token even tokens
// not seperated by spaces are recognized (from left to right)
int checktoken(char *string)
{
int t=0,s=0;

// scan for all tokens
while (s<MAXTOKENS && !t)
{
#if DEBUG
printf("comparing %s with token %s\n",string,token[s]);
#endif
// no use comparing strings of smaller size
if (strlen(string)>=strlen(token[s]))
{
// if a token compares to tokenlength characters of the string
// a token is positively found and the loop is finished
if (!strncmp(token[s],string,strlen(token[s]))) t=s+0x80;
}
s++;
}
// return token value or NULL if no token found
return t;
}

// hexdump ramspace to standard output in 'hexdump -C' style
void hexdump(int limit)
{
char ascbuf[16];
int n,m;
int c;

if (!limit) limit=RAMEND;

for (n=0; n<limit; n+=16)
{
printf("%08x  ",n+TAPEOFFSET);
for (m=0; m<16; m++)
{
c=ramspace[n+m] & 0xff;
printf("%02x ",c & 0xff);
// hexdump -C style
if (m==7) printf(" ");
if (c>31 && c<128) ascbuf[m]=c;else ascbuf[m]='.';
}
ascbuf[m]=0;
printf(" |%s|\n",ascbuf);
}
}

// the main event
int main(int argc,char *argv[],char *envp[])
{
  FILE *fp;
  char inbuf[256];
char temp[256];
int c;
int quoteflag,ignoreflag;
int n,m,r,t,pos,startpos;
char *valid;

// pointer in my ram space
pos=0;
 
// try to open the input file...
fp=fopen(argv[1],"r");

// if it worked, then start the process
if (fp)
{
// loop until end of file
do
{
// first reset offsetpointers and flags
n=0;
quoteflag=0;
ignoreflag=0;

// make inbuf a zero length string
inbuf[n]=0;

// read one line of input
valid=fgets(inbuf,255,fp);

// if a line is succesfully read
if (valid)
{
// get rid of the 0x0a at the end of the line
if (inbuf[strlen(inbuf)-1]==0x0a) inbuf[strlen(inbuf)-1]=0;

#if DEBUG
// show original line
printf("%s\n",inbuf);
#endif
// now scan for linenumber
while (isdigit(inbuf[n])) temp[n]=inbuf[n++];

// close temporary string
temp[n]=0;


// read value from string in 'r'
sscanf(temp,"%d",&r);
#if DEBUG
printf("read linenumber %d from %s\n",r,temp);
#endif
// save current position
startpos=pos;

// reserve 2 bytes for offset
ramspace[pos++]=0x00;
ramspace[pos++]=0x00;

// store binary linenumber in rambuffer
ramspace[pos++]=(r & 0xff);
ramspace[pos++]=(r >> 8);


// skip spaces after linenumber
while (inbuf[n]==0x20) n++;

// now proces this line character by character until end of string (NULL)
while (inbuf[n])
{
t=0; // clear token number

//  toggle quoteflag if quotes are found (string start or end)
if (inbuf[n]==0x22) quoteflag=!quoteflag;

// check for tokens if quoteflag and ignoreflag are not set
if (!quoteflag && !ignoreflag)
{
// check for tokens at current offset (n)
t=checktoken(inbuf+n);
if (t) // we've found a token
{
// now skip tokenlength characters in inputbuffer
n+=strlen(token[t & 0x7f]);
// write token code into output buffer
ramspace[pos++]=t;
// set ignoreflag to ignore all (!) tokens
// until end of line if token was a REM (0x8e)
if (t==0x8e) ignoreflag=1;
} // end if (t)
} // end if (!quoteflag && !ignoreflag)

// if no token found or in ignore or string mode...
if (!t)
{
// copy literally to ramspace and advance pointer(s)
// convert some special chars to Videopac's equivalent
c=inbuf[n];
switch (c)
{
case '$':c=0x04; break;
case '#':c=0x06; break;
case '^':c=0x7f; break;
case 0xa3:c=0x03; break;
case 0xa8:c=0x7e; break;
}
ramspace[pos++]=c;
n++;
} // end if (!t)
} // end while (inbuf[n])

// write a NULL byte at the end of this tokenized line
ramspace[pos++]=0x00;

// fill in the current offset in the reserved offset bytes
ramspace[startpos]=(pos + BASICOFFSET) & 0xff;
ramspace[startpos+1]=(pos + BASICOFFSET) >> 8;
} // end if valid
}
while (valid);

// close the file
fclose(fp);

// show the result in hex
hexdump(pos);
}
else
{
// error...
printf("could not open %s!\n",argv[1]);
return 1;
}
 
}


Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #18 on: May 17, 2011, 09:35:23 PM »

An example of the ASCII text which the pre-processor uses for input (this file is edited on a PC):

Code:
\ -------------------------------------------------------
\ - Pipepanic for Basic 80 Videopac Basic / VG 5000
\ -------------------------------------------------------
~start
                INIT 7
                DEF FNTK(N)=TI
\ ------------------------------------------------
\               Startup
\ ------------------------------------------------
                BH=10:BW=10
                DIM HB(5,BW*BH):DIM HT(5)
                DIM BA(BH,BW):DIM PA(105)
                DIM DP(BH*BW+1,3):DIM PR(3)
                DIM PO(75,4)
                FOR C=0 TO 4:FOR C2=0 TO (BW*BH)-1
                        HB(C,C2)=255
                NEXT C2:NEXT C
\ ------------------------------------------------
\               * init bitmaps *
\ ------------------------------------------------
                GOSUB ~initbitmaps
\ ------------------------------------------------
\               * initialise new game *
\ ------------------------------------------------
                GOSUB ~initnewgame
~mainloop
\ ------------------------------------------------
\               main loop
\ ------------------------------------------------
                IF QT THEN END
                TI=TI+1
\ ------------------------------------------------
\               * GAMESHOWHELP *
\ ------------------------------------------------
~testhelp
                IF GM<>5 THEN ~testgameon
                GOSUB ~drawgame

\ ------------------------------------------------
\               * GAMEON *
\ ------------------------------------------------
~testgameon
                IF GM<>4 THEN ~testcleardeadpipes
                IF ABS(FNTK(0)-GI)<25 THEN ~testcleardeadpipes
                RD=RD OR 16
                GI=FNTK(0):GT=GT-1
                IF GT<=0 THEN GT=0:GOSUB ~createdeadpipesarray
                GOSUB ~drawgame

\ ------------------------------------------------
\               * GAMECLEARDEADPIPES *
\ ------------------------------------------------
~testcleardeadpipes
                IF GM<>3 THEN ~testgamefillpipes
                IF ABS(FNTK(0)-CD)<5 THEN ~skipcdset
                CD=FNTK(0):GOSUB ~cleardeadpipes
~skipcdset
                GOSUB ~drawgame

The pre-processor on the PC then generates this:

Code:
10 INIT 7
20 DEF FNTK(N)=TI
30 BH=10:BW=10
40 DIM HB(5,BW*BH):DIM HT(5)
50 DIM BA(BH,BW):DIM PA(105)
60 DIM DP(BH*BW+1,3):DIM PR(3)
70 DIM PO(75,4)
80 FOR C=0 TO 4:FOR C2=0 TO (BW*BH)-1
90 HB(C,C2)=255
100 NEXT C2:NEXT C
110 GOSUB 1230
120 GOSUB 1240
130 IF QT THEN END
140 TI=TI+1
150 IF GM<>5 THEN 170
160 GOSUB 1730
170 IF GM<>4 THEN 230
180 IF ABS(FNTK(0)-GI)<25 THEN 230
190 RD=RD OR 16
200 GI=FNTK(0):GT=GT-1
210 IF GT<=0 THEN GT=0:GOSUB 400
220 GOSUB 1730
230 IF GM<>3 THEN 270
240 IF ABS(FNTK(0)-CD)<5 THEN 260
250 CD=FNTK(0):GOSUB 1040
260 GOSUB 1730

All linenumbers and GOSUBS/GOTO's are calculated by the pre-processor. But you still need to type it in.. So now it needs to be converted to binary form (or WAV/MP3 for use on the original C7420 module) and that is where you need Ren?'s converter (or mine...)
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
Pages: 1 [2]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!