|
Miellaby
|
Voici une doc sur Vogue que j'ai écrite dans mon
anglais-franchouillard. Tu y trouveras tout ce que
moi j'ai compris:
Introduction to VOGUE
=====================
VOGUE is a compiler for a C-like structured language.
It's designed for PC-E500 Sharp Pocket Computers serie.
The VOGUE language is a simplified C language with
added features like parallel processing, screen
functions, or float computing (through inlined
functions inside the compiler).
Usage
=====
VOGUE needs 25kb memory!
poke &bfe03,&1a,&fd,&b,0,&64,0
call &fffd8
Note it won't work with COMMAND.BAS basic shell : Too large!
I (sgarden@club-internet) did a CMD.BAS reduced release
(email me!).
Considering VOGUE is currently loaded in the pocket computer,
you may type a program in "text" mode (see manual for
TEXT and BASIC instructions).
Your first program
=============
10 {
20 printf ("Hello to WORLD^M^J");
30 }
To compile your source program:
call &b9800
To execute the produced binary:
call &b9803
In this case, the compiled object coexists
with the VOGUE compiler in memory.
VOGUE can handle separate input and output
files via commands like:
call &b9800 "-sFOO.VOG
and even:
call &b9800 "-sFOO.VOG -oFOO
or
call &b9800 "-sFOO.VOG -fFOO
(I don't know the difference, email me
if you do!)
A FOO.VOG input file needn't to be line-numbered
("neednt" or "musn't" I don't know ?).
The produced file is a binary file "à la" SAVEM.
You can LOADM it then execute it with "call &b9800"
";" separator
=============
10 {
20 printf ("Hello to WORLD^M^J");
30 printf ("Welcome to the WORLD^M^J");
40 }
is equivalent to:
10 {printf ("Hello to WORLD^M^J"); printf ("Welcome to the WORLD^M^J");}
Loop example
============
10 char i;
20 {
30 i=1;
40 do {
50 printf("%d ", i);
60 i=i+1;
70 } until (i <= 100);
80 }
Function call, local variables example
=====================
10 func int sum(int x):
20 int summary, i;
30 {
40 summary=0;
50 i=1;
60 do {
70 summary=summary+i;
80 i=i+1;
90 } until (i > x);
100 return summary;
110 }
120 {
130 printf("summary 10 =%dc^M^J", sum (10));
140 printf("summary 100 =%dc^M^J", sum (100));
150 }
Recurrent call example
======================
10 func int sum (int x):
20 {
30 if (x == 1) return 1 ;
40 else return x+sum(x-1);
50 }
120 {
130 printf("sum(10)=%d^M^J",sum(10));
140 printf("sum(100)=%d^M^J",sum(100));
150 }
I/O example
===========
char fd;
{ fd = fopen("E:ABC.TXT", 3);
fprintf(fd, "Hello to World");
}
better and complete example:
---------------------------
int fd;
char name[10];
char adrs[30];
pnt age;
{ fd = fopen("E:ABC.TXT", 3);
if (fd == -1)
{ printf("FILE not opened.");
exit;
};
fd = char fd;
do
{ scanf("%s", &name);
scanf("%s", &adrs);
scanf("%d", &age);
fwrite(fd, &name, 10);
fwrite(fd, &adrs, 30);
fwrite(fd, &age, 3);
puts("Continue?");
} until (getc != 'Y');
}
Screen handling example
=======================
note you firstly have to build a RAM hidded image
(higher, lower or equal to the actual screen size)
via a well-formed char array :
{x.low,x.high,y.low,y.high,pixmap...}
then you project it on the screen
1000 const eof -1;
1010 char scrn[964]={239,0,31,0};
1020 char ball[12]={7,0,7,0,$3c,$7e,$ff,$ff,$ff,$ff,$7e,$3c};
1030 {
1040 while ( kscan == eof ) {
1050 s_clear(&scrn);
1060 s_proj(&scrn,&ball,rand % 247 - 7,rand % 39 - 7,1);
1070 s_real(&scrn,15);
1080 };
1090 }
Sprites may be handled by the same kind of structure!
Equivalency between screen structures
=====================================
1000 char scrn[964]={239,0,31,0};
1010 char subscrn[244]={119,0,15,0};
1020 int x;
1030 {
1040 x = 0;
1050 s_clear(&subscrn);
1060 do {
1070 s_line(&subscrn,x,0,119-x,15,1);
1080 s_proj(&scrn,&subscrn,0,0,0);
1090 s_proj(&scrn,&subscrn,120,0,0);
1100 s_proj(&scrn,&subscrn,0,16,0);
1110 s_proj(&scrn,&subscrn,120,16,0);
1120 s_real(&scrn,15);
1130 } until ( (x += 1) == 120 );
1140 }
Pixel-step scrolling example
============================
1000 char scrn[964]={239,0,31,0},c;
1010 int i;
1020 {
1030 i=0;
1040 do
1050 scrn[i+4]=rand
1060 until ( (i+=1) ==960);
1070 do {
1080 c = kscan;
1090 if ( c == '2')
1100 s_shift(&scrn,0,1)
1110 else if ( c=='4')
1120 s_shift(&scrn,-1,0)
1130 else if (c =='6')
1140 s_shift(&scrn,1,0)
1150 else if (c=='8')
1160 s_shift(&scrn,0,-1);
1170 s_real(&scrn,15);
1180 } until( c== ' ');
1190 }
Multiprocess example
====================
warning : no time sharing
1000 pnt x[2];
1010 {
1020 fork(256);
1030 printf("Input number=");
1040 scanf("%d",&x[pid]);
1050 puts(""); ];
1060 if (x[pid] == 0) {
1070 printf("x[%d] is zero^M^J",pid);
1080 } else {
1090 printf("x[%d] is non-zero^M^J",pid);
1100 };
1110 }
a scenario for this example:
Input number=0
Input number=1
x is zero.
x is non-zero.
Multiprocess + screen big example
=================================
1000 char scrn[964]={239,0,31,0};
1010 char ball[8]={3,0,3,0,6,15,15,6};
1020 char ball2[8]={3,0,3,0,0,0,0,0};
1040 func char main1:
1050 int x,y,dx,dy,sx,dsx;
1060 char subscrn[412];
1070 {
1080 *(&subscrn)[0] = 101;
1090 *(&subscrn)[1] = 31;
1110 s_clear(&subscrn);
1120 s_box(&subscrn,1,0,100,31,1);
1130 x = 2;
1140 y = dx = dy = dsx = 1;
1150 sx = 0;
1160 do {
1170 s_proj(&subscrn,&ball,x,y,0);
1180 s_proj(&scrn,&subscrn,sx / 5,0,0);
1190 s_real(&scrn,3);
1200 s_proj(&subscrn,&ball2,x,y,0);
1210 x += dx;
1220 y += dy;
1230 if ( ( x < 2 ) | ( x > 96 ) ) {
1240 dx = -dx;
1250 x += dx * 2;
1260 };
1270 if ( ( y < 2 ) | ( y > 27 ) ) {
1280 dy = -dy;
1290 y += dy * 2;
1300 };
1310 sx += dsx;
1320 if ( ( sx < 0 ) | ( sx > 18*5 ) ) {
1330 dsx = -dsx;
1340 sx += dsx * 2;
1350 };
1360 } until (0);
1370 }
1390 func char main2:
1400 char subscrn[964];
1410 int x,y,sy,c;
1420 {
1430 *(&subscrn)[0] = 119;
1440 *(&subscrn)[1] = 63;
1450 s_clear(&subscrn);
1460 x = y = sy = 0;
1470 do {
1480 s_proj(&subscrn,&ball,x,y+sy,0);
1490 s_proj(&scrn,&subscrn,120,-sy,0);
1500 s_real(&scrn,12);
1510 while ( ( c = kscan ) == -1 ){};
1520 c = char c;
1530 if ( c == '2' ) {
1540 y += 1;
1550 if ( y > 28 ) {
1560 y -= 1;
1570 sy += 1;
1580 if ( ( sy + y ) > 60 ) {
1590 beep(100,10);
1600 sy -= 1;
1610 };
1620 };
1630 };
1640 if ( c == '4' ) {
1650 x -= 1;
1660 if ( x < 0 ) {
1670 beep(100,10);
1680 x = 0;
1690 };
1700 };
1710 if ( c == '6' ) {
1720 x += 1;
1730 if ( x > 116 ) {
1740 beep(100,10);
1750 x = 117;
1760 };
1770 };
1780 if ( c == '8' ) {
1790 y -= 1;
1800 if ( y < 0 ) {
1810 y += 1;
1820 sy -= 1;
1830 if ( ( sy + y ) < 0 ) {
1840 beep(100,10);
1850 sy += 1;
1860 };
1870 };
1880 };
1890 } until (0);
1900 }
1910 {
1920 s_clear(&scrn);
1930 fork(2048);
1940 if ( pid == 0 )
1950 main1
1960 else
1970 main2;
1980 }
The 3 VOGUE data type:
=====================
Type : size : range
: (byte)
------- : ---- : -----
char : 1 : 0..255
int : 2 : -32768..32767
pnt : 3 : 0..1048575
Note pnt is a kind of "long" too.
The compiler doesn't keep pointer type.
You must type the value under a pointer :
=============
* @... Operator in order to create char type variable...
* *... Operator in order to create int type variable
* ^... Operator in order to create pnt type variable
example :
-------
10 char a;
20 { a=1; }
is equivalent to:
10 char a;
20 { @(&a)=1; }
other example:
------------
@($bf800) = 1;
You may have to declare functions
when you can't sort them by call levels :
=============
[..]
1020 proto int expr:
[..]
1170 func int term:
1180 int e;
1190 {
[..]
1290 e = expr;
[..]
1450 }
1620 func int expr:
[..]
1630 int t;
1640 {
[..]
1650 t = term;
[..]
1770 }
Math and Float handling
=============
1000 const mode 1;
1010 const fsin $4d;
1020 const fmult $49;
1030 char scrn[964]={239,0,31,0},float1[15],float2[15];
1040 int x,y,z,w,sin[360],x1,y1,x2,y2,x3,y3,x4,y4;
1050 pnt p;
1060 {
1070 x = 0;
1080 putc('^L');
1090 atof(&float2,"16");
1100 do {
1110 itof(&float1,x);
1120 _math1(&float1,&float1,fsin);
1130 _math2(&float1,&float1,&float2,fmult);
1140 sin[x] = ftoi(&float1);
1150 locate(0,0);
1160 printf("Making table...[%d/360]",x);
1170 x += 1;
1180 } until ( x == 360 );
1190 x = x % 360;
1200 y = y % 360;
1210 z = z % 360;
1220 w = w % 360;
1230 do [
1240 s_clear(&scrn);
1250 x1 = 120 + sin[x] * 7; y1 = 16 + sin[(x+90) % 360];
1260 x2 = 120 + sin[y] ; y2 = 16 + sin[(y+70) % 360];
1270 x3 = 120 + sin[z] * 4; y3 = 16 + sin[(z+90) % 360];
1280 x4 = 120 + sin[w] * 2; y4 = 16 + sin[(w+60) % 360];
1290 s_line(&scrn,x1,y1,x2,y2,mode);
1300 s_line(&scrn,x2,y2,x3,y3,mode);
1310 s_line(&scrn,x3,y3,x1,y1,mode);
1320 s_line(&scrn,x1,y1,x4,y4,mode);
1330 s_line(&scrn,x2,y2,x4,y4,mode);
1340 s_line(&scrn,x3,y3,x4,y4,mode);
1350 s_real(&scrn,15);
1360 x = (x+7) %360;
1370 y = (y+13)%360;
1380 z = (z+11)%360;
1390 w = (w+9) %360;
1400 ] until (0);
1410 }
--------------------------------------------------------------------
Standards functions
=============
* string functions
---------
int strcmp(pnt str1,str2)
pnt strlen(pnt str)
pnt strcpy(pnt str1,str2)
pnt strcat(pnt str1,str2)
pnt strup(pnt str)
pnt strdown(pnt str)
pnt strchr(pnt str, char c)
pnt strrchr(pnt str, char c)
* char functions
---------
char isdigit(char c)
char isalpha(char c)
char upcase(char c)
* I/O file functions
---------
char sprintf(pnt str,format,arg1,arg2,...)
- d : as a int
- u : as a pnt
- x : as a short
- c : as a character
- f : as a float
- s : as string
int fprintf(char fd;pnt format,arg1,arg2,...)
int printf(pnt format,arg1,arg2,...) = fprintf(0,format,arg1,arg2,...)
char sscanf(pnt str,format,arg1,arg2,...)
int fscanf(char fd;pnt format,arg1,arg2,...)
int scanf(pnt format,arg1,arg2,...)
int fgetc(char fd)
int getc=fgetc(1)
int fputc(char fd,c)
int putc(char c)=fputc(0, c)
pnt fgets(char fd; pnt str)
pnt gets(pnt str)=fgets(0, pnt str)
CTRL+L($0c) CTRL+H($08) ?
int fputs(char fd; pnt str)
int puts(pnt str)
int fcreat(pnt name; char attr)
bit0 bit1
int fopen(pnt name; char mode)
int fclose(char fd)
int remove(pnt name)
pnt fseek(char fd; pnt offset; char mode)
pnt fread(char fd; pnt buffer, size)
pnt fwrite(char fd; pnt buffer, size)
* integer
---------
int abs (int x)
int sgn (int x)
pnt atod (pnt str)
pnt atox (pnt str)
* system functions
---------
char _fname (pnt str1,str2)
5+1+8+1+3+1=19byte
what's this?
int fcntl (pnt reg)
-> get a register
*(reg) BA
*(reg+2) I
^(reg+4) X
^(reg+7) Y
*(reg+10) (bx)
*(reg+12) (cx)
*(reg+14) (dx)
^(reg+16) (si)
^(reg+19) (di)
int iocs (pnt reg)
call a Sharp IOCS api function
pnt sbrk (pnt size)
reserve memory
pnt sbrk2 (pnt size)
I don't know the difference
* miscelaneous
------------
int rand
result from 0 to 32767
char srand (pnt seed)
int kscan
-1 no pressed key
char errnum
------------------------------------------------------------
0 ?n[?h?I?G??[?ª?¶?µAabort ?µ?½
1 ?p???[?^?ª?Í?Í?O?Å? ?é
2 ?w?è?µ?½?t?@?C???ª?È?¢
3 ?w?è?µ?½?p?X?¼?ª?È?¢
4 open ?µ?Ä?¢?é?t?@?C???ª?½?ß?¬?é
5 ?»?Ì???ª???³?ê?Ä?¢?È?¢?t?@?C???Å? ?é
6 ?³?ø?Ì?t?@?C??E?n???h???ð?g?p?µ?½
7 ?»?Ì???Í open ?Å?w?è?³?ê?Ä?¢?È?¢
8 ?t?@?C???ª open ???Å? ?é
9 ?t?@?C???¼?ªd?¡?µ?Ä?¢?é
10 ?w?è?µ?½?h???C?u?ª?È?¢
11 ?x???t?@?C?G??[
12 ?w?è?µ?½?o?C?g??Ì???ð?®?¹?µ?È?©?Á?½
254 ?v?½?I?È low battery
255 ???ð???f?µ?½ibreak key ?ª???³?ê?½j
------------------------------------------------------------
char getram (char adrs)
char setram (char adrs,data)
char locate (char x,y)
SCRN
pnt move (pnt dest,src;int length)
return src+length
pnt movez (pnt dest,src;int length)
return src+length
pnt argp
pnt argpf
a = ^(argpf)[2];
b = ^(argpf)[1];
c = ^(argpf)[0];
char beep (int tone;pnt length)
f * ( 60 + 6 * tone ) = clock
s * f = length
char key (int output)
(11bits)
<-MSB LSB
10 9 8 7 6 5 4 3 2 1 0bit
+---+---+---+---+---+---+---+---+---+---+---+
|P |) |1 |CA |STO|RCL|I |Y |R |W |2 |bit0
+---+---+---+---+---+---+---+---+---+---+---+
|2dF|FSE|tan|cos|sin|hyp| O| U| T| E| Q|bit1
+---+---+---+---+---+---+---+---+---+---+---+
|PF5|1/x|log|ln |DEG|HEX| K| H| F| S|MENU|bit2
+---+---+---+---+---+---+---+---+---+---+---+
|PF4| (|x^2| 3|y^x|EXP| L| J| G| D| A|bit3
+---+---+---+---+---+---+---+---+---+---+---+
|PF3|DEL| /| 9| 8| 7| .| N| V| X|BAS|bit4
+---+---+---+---+---+---+---+---+---+---+---+
|PF2|BS | *| 6| 5| 4| ;| M| B| C| Z|bit5
+---+---+---+---+---+---+---+---+---+---+---+
|PF1|INS| -| 3| 2| 1 |dro|ho |Spc|Cps|Shf|bit6
+---+---+---+---+---+---+---+---+---+---+---+
| | =| +| ,|+/-| 0|RET|gch|bas|???|CTR|bit7
+---+---+---+---+---+---+---+---+---+---+---+
(8bits)
char miditx (pnt data)
don't play music! just send some midi events
on an external port.
char cbreak
int setjmp( pnt work )
char nearjmp( int adrs )
char exec( pnt result , proc , arg , argc )
?
Screen functions
================
char s_clear (pnt scrn)
int s_copy (pnt scrn1,scrn2)
int s_proj (pnt scrn1,scrn2;int x,y;char mode)
int s_putc (pnt scrn;char chr;int x,y;char mode)
int s_puts (pnt scrn,str;int x,y;char mode)
int s_real (pnt scrn;char pattern)
bit0 (0,0)-(63,31)
bit1 (64,0)-(119,31)
bit2 (120,0)-(175,31)
bit3 (176,0)-(239,31)
int s_take (pnt scrn)
int s_shift (pnt scrn;int x,y)
int s_pixel (pnt scrn;int x,y;char mode)
nt s_line (pnt scrn;int x1,y1,x2,y2;char mode)
int s_box (pnt scrn;int x1,y1,x2,y2;char mode)
int s_fill (pnt scrn;int x1,y1,x2,y2;char mode)
int s_point (pnt scrn;int x,y)
Float functions
===============
VOGUE has only integer types. But it's possible
to compute float numbers via 15 bytes width
structures (which correspond to Sharp internal
representation of double precision floats).
pnt atof (pnt float,str)
pnt ftoa (pnt str,float)
pnt _math1 (pnt dest,source;char fnum)
= execute 1 parameter function:
fnum:
$4c exp
$4d sin
$4e cos
$4f tan
$50 asn opposite sin
$51 acs opposite cos
$52 atn opposite tan
$53 deg
$54 dms
$55 abs
$56 int
$57 sgn
$58 rnd
$59 sqr
$5a log
$5b ln
pnt _math2 (pnt dest,source1,source2;char fnum)
execute 2 parameters functions:
fnum:
$41 != not equal
$42 <
$43 >
$44 =
$45 <=
$46 >=
$47 +
$48 -
$49 *
$4a /
$4b ^
pnt itof (pnt float;int bin)
int ftoi (pnt float)
Parallel processing functions
=============================
int fork (pnt size)
char pid
pnt free
int sleep(char pid)
int wakeup (char pid)
int kill(char pid)
int pstat(char pid)
char latest
pnt alarmf (pnt count)
pnt alarms (pnt count)
More functions via libraries
===================
(I don't know how to make/use libraries)
pnt eval( pnt result , expr , array )
pnt left( pnt dest , source , length )
pnt right( pnt dest , source , length )
pnt mid(pnt dest,source,pos,length)
int instr(pnt source,keyword)
int split( pnt source, arg )
pnt ptof (pnt float, p)
pnt ftop (pnt float)
char argchk( pnt cmdln, argc, argv )
pnt malloc( pnt size )
pnt memfree( pnt adrs )
Language differences :
====================
WRONG
char a[10];
{
a="VOGUE";
}
RIGHT
char a[10];
{
strcpy(&a, "VOGUE");
}
WRONG
char buffer[256];
{
strcpy(buffer, "Hello to WORLD");
puts(buffer);
}
RIGHT
char buffer[256];
{
strcpy(&buffer , "Hello to WORLD");
puts(&buffer);
}
WRONG
char c;
{
scanf("%d", &c);
printf("%d", c);
}
RIGHT
pnt dummy
char c;
{
scanf("%d", &dummy);
c=dummy;
printf("%d", c);
}
WRONG
int x[10];
func char foo(pnt p):
{
*(p + 3) = -123;
}
{
foo(&x);
printf( "%d" , x[3] );
}
RIGHT
char x[10];
func char foo(pnt p):
{
*(p)[3] = -123;
}
{
foo(&x);
printf("%d", x[3]);
}
WRONG
char a[5][10];
{
a[3][4] = 1;
}
RIGHT
char a[5 * 10];
{
a[3 * 5 + 4] = 1;
}
Plan : Set PC-E500 for VOGUE
============
* Encode VOGUE with UUENCODE
* Load COMMAND.BAS to simplify work
(COMMAND.BAS needs to be reduced
to get 25k free memory)
* Reserve memory:
poke &bfe03,&1a,&fd,&b,0,&64,0
call &fffd8
or TPA with COMMAND.BAS
* Install UUDECODE
download and execute UUDECODE.UU
please correct the output filename bug
* download VOGUE
You can type UUDECODE "COM:"
then download VOGUE.UU
* Want an editor? download TRED
type UUDECODE "COM:"
then download TRED.UU
* Write code with TRED
TRED HELLO.VOG
>>>>>>>
{puts("Hello word^M^J");}
<<<<<<<
* compile
VOGUE -sHELLO.VOG -o HELLO
HELLO is >6kb arg!
|
à 10:29