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  
Pages: 1 [2]   Go Down
Author Topic: C7420 basic stuff  (Read 8154 times)
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
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 ...

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

« 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...


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

« 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.

// 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",

#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)
printf("comparing %s with token %s\n",string,token[s]);
// 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;
// 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]='.';
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
// try to open the input file...

// if it worked, then start the process
if (fp)
// loop until end of file
// first reset offsetpointers and flags

// make inbuf a zero length string

// read one line of input

// 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;

// show original line
// now scan for linenumber
while (isdigit(inbuf[n])) temp[n]=inbuf[n++];

// close temporary string

// read value from string in 'r'
printf("read linenumber %d from %s\n",r,temp);
// save current position

// reserve 2 bytes for offset

// 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)
if (t) // we've found a token
// now skip tokenlength characters in inputbuffer
n+=strlen(token[t & 0x7f]);
// write token code into output buffer
// 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
switch (c)
case '$':c=0x04; break;
case '#':c=0x06; break;
case '^':c=0x7f; break;
case 0xa3:c=0x03; break;
case 0xa8:c=0x7e; break;
} // end if (!t)
} // end while (inbuf[n])

// write a NULL byte at the end of this tokenized line

// 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

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


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

« 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):

\ -------------------------------------------------------
\ - Pipepanic for Basic 80 Videopac Basic / VG 5000
\ -------------------------------------------------------
                INIT 7
                DEF FNTK(N)=TI
\ ------------------------------------------------
\               Startup
\ ------------------------------------------------
                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
                NEXT C2:NEXT C
\ ------------------------------------------------
\               * init bitmaps *
\ ------------------------------------------------
                GOSUB ~initbitmaps
\ ------------------------------------------------
\               * initialise new game *
\ ------------------------------------------------
                GOSUB ~initnewgame
\ ------------------------------------------------
\               main loop
\ ------------------------------------------------
                IF QT THEN END
\ ------------------------------------------------
\               * GAMESHOWHELP *
\ ------------------------------------------------
                IF GM<>5 THEN ~testgameon
                GOSUB ~drawgame

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

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

The pre-processor on the PC then generates this:

10 INIT 7
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
110 GOSUB 1230
120 GOSUB 1240
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...)

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

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