Changes

Jump to: navigation, search

FIOLIB

3,276 bytes added, 19:05, 3 June 2015
With [[Category:C]][[Category:Extended RAM Software]][[Category:FutureOS]][[Category:Programming]][[Category:Programming software]]The '''FIOLIB''' is like a strongly expanded IOLIB library, it's needed to use the programming [[:Category:C|language C]] for [[FutureOS]] it also possible to use C as a programming language. There is a are [[CP/M version ]] versions of Small-C and also Windows-based cross-compilers of the C language. You have to use Use FIOLIB.C instead of IOLIB.C. becase The FIOLIB.C contains all needed C functions to use FutureOS system-calls.
You can use take a normal C program compile it, assemble it, link the object-code with FIOLIB (an and all other needed libraries) and , then add a header to the *.COM file with COMFU.COM.  To start such an C-program under FutureOS you have to start the RUNC-environmentpreviously. RUNC expands the features of FIOLIB. With RUNC it is possible to store functions in E-expansion RAM, leaving more main memory free for C applications.
<pre>
cpcstart()
This function prepares [[FutureOS]] for running Small-C programs. It is only used by FIOLIB.C itself. The user doesn't and shouldn't use that function.
byebye()
This function is used to end a Small-C program under FutureOS. You can use this function or just end the program. Both has the same effect. The function byebye displays the message "Press any key to return to the Desktop." , then it waits for a pressed key and finally jumps back to the Desktop of FutureOS.
oscall(adr,regpack)
int adr;
int *regpack; /* af,hl,de,bc */
This function is used to call a subroutine of the OS. The contents of "regpack" are loaded in the Z80 registers, then the OS-routine "adr" at the address "adr" is called. And then the Z80 registers are written back in "regpack". Beginning at regpack the 16 Bit registers AF, HL, DE and BC follow:
regs[0]=a; /* AF */
regs[1]=b; /* HL */
mode(n)
int n;
Set the screen MODE to 0, 1, 2 or 3. Mode 0, 1 and 2 are the same as with the MODE command under Basic. Don't use Mode 3! The mode is changed and the screen will be cleared, the cursor is set to the most left, most upper position.
cls()
This is the same as the BASIC command CLS. It clears the screen and the cursor is set to the most left, most upper position.
s80x25()
Sets the format of the screen to 80 columns and 25 lines (in Mode 2), or to 40 columns and 25 lines (in Mode 1). Only the screen format is changed, NO cls!
s64x32()
Sets the format of the screen to 64 columns and 32 lines (screen Mode 2), or 32 columns and 32 lines (in Mode 1). Only the screen format is changed, NO cls!
pen0(n)
int n;
Changes the PEN for MODE 0. This type of PEN selection is needed if you want to paint dots ( with plot(x,y) ) under SCREEN MODE 0. You can use PEN 1 - 15. It's the same like the command PEN in Basic, when using MODE 0. Only the PEN of MODE 0 is changed. The PEN selections of Mode 1 and 2 aren't changed!
pen1(n)
int n;
Changes the PEN for MODE 1. You can use PEN 1, 2 or 3. It's the same like the command PEN in Basic. If you select PEN 0 then the two-color PEN is selected.
Only the PEN of MODE 1 is changed. The PEN's for Mode 0 and 2 aren't changed!
ink(p,c)
int p,c;
The INK function changes the COLOR of a PEN. It's the same like the INK command of Basic. Attention: You can only give ONE colour to the PEN. PEN 16 is BORDER!
locate(x,y)
int x,y;
Function LOCATE is nearly the same like the Basic command LOCATE, you give the column (x) and the line (y) where the cursor should be positioned. You have 80 columns in Mode 2 and 40 columns in Mode 1 (if the screnn has 80x25 format).
plot(x,y)
int x,y;
The function PLOT allows to set a POINT on the screen. You can use SCREEN MODEs 0, 1 or 2. Unter Mode 2, PEN 1 is always used. Under the MODEs 0 and 1 the used PEN depends on the functions pen0(n) and pen1(n), which preselect the PEN. MODE 2 screen format should be 64*32. The screen format (rows, lines) for MODE 0 and 1 can be selected freely. The coordinate position 0,0 is the upper left corner.
move(x,y)
int x,y;
The function MOVE allows to set the graphic cursor (start coordinates of a line for example) to X and Y. The coordinate position 0, 0 is the upper left corner.
draw(x,y)
int x,y;
DRAWs a line form the actual graphic cursor position (use MOVE to set it!) to the coordinates X and Y. The coordinate position 0, 0 is the upper left corner.
You can use this function in all screen-MODEs, -formats and with all PENs.
circle(r)
int r;
CIRCLEs can be created by this routine. The center of the CIRCLE should be set before through the MOVE(X,Y) function, else the actual X and Y coordinates will be used. The variable r contains the RADIUS of the CIRCLE. (Use under Mode 1)!!
lscr(s)
char *s;
Loads a 16 KB screen to address &C000. Do not load pictures with file-header!!!
To define the picture / screen which should be loaded, a string with the format "DUU:filenameEXT" has to be given to the function. "D" is the DRIVE "a".."m" or "A".."M", UU is the USER-number in hexadezimal "00".."FE", "filename" and "EXT" define the name of the file and the extension. You must type in every "space"!!
Between the "filename" and the "EXT" is _NO_ point!!! And _NEVER_ use User &FF!
fopen(name,mode)
char *name,*mode;
Opens a file to read or to write. A file-name must be provided in the format: "DUU:FilenameExt". D ist is the Drive-letter (A..M), U is the User-number in a hexadezimal view. Between the Name and the Extension of the file, there is NO Dot! An example: "B00:Role-Play-D". The string "filename" isn't allowed to be located between &4000 and &7FFF, there it can't be read!!!The File-mode "mode" can be "r"/"R", "w"/"W", "a"/"A". "R" opens a file to be read. "W" opens a file to be written. (("A" appends a file-not finished yet))You can access every byte of every file everytime. But a file can't be longer than 16 KB. If you need more space, just open another 16 KB file!If fopen(name,mode) is successfull the number of the file is given back, this number is between 32 and 63 (&20-&3F). Else "EOF" is given back!
fclose(f)
int f;
Close an previously opened file with the File-number "f". Whereas "f" must lie between 32 and 63 (&20-&3F). The file "f" is written back to disc.
sfile(f)
int f;
Select file to read/write from/to. The File-number "f" must lie between 32 and 63 (&20-&3F). The file is selected for all future read/write operations, until sfile(f) is used again or a new file is opened with fopen(name,mode).
sfico(c)
int c;
Set File-Counter of the actual selected File. The File-Couter must be an value between &4000 and &7FFF. The File-Counter defines where to read from, or where to write to (inside the file).
err(s)
char *s;
Returns the message "Error: " and displays an error number. Can be used to give an error-message to the user.
putchar(c)
getkey(n)
int *n;
GETKEY reads the actual pressed key from the keyboard. It waits until a key is pressed. The pressed key is returned in "n".
getchar()
The Function waits until no key is pressed, then it reads the first pressed key from the keyboard. It waits for a pressed key, then returns. Uses getc(stdin);
getc(unit)
rnd(n)
int n;
rnd(n) returns an integer value between 0 and n. If n is 0 the value will lie within + / - 32 kB. Based on suggestions in Hamming's book on Numerical Methods for Scientists and Engineers. A seed is multiplied by a large number causing an overflow.
exit()
avail()
avail() returns the number of bytes between top of heap (HEAPTOP) and the end of the TPA (heapend). Remember that this includes the stack!
hex(x)
strcmp(str1,str2)
char *str1,*str2;
Compares two strings. This function returns an integer: less than, equal to, or greater than zero depending on whether the string at 'str1' is less than, equal to, or greater than the string at 'str2'.
strncmp(str1,str2,n)
char *src,*tar;
int n;
Copy string of n-bytes from "src" to "tar". Works like strcpy(), except that n characters are transferred - regardless of the length of the source string. If the source string is too long it is truncated and a null character is placed at the end of the destination string.
strlen(s)
char *s;
Returns the length of a given string, the count of the number of characters in the string 's'. The null character at the end of the string is not included in the count.
strcat(dest,sour)
Converts character to upper case.
</pre>
 
 
This is a small example program, that shows how to use the '''FIOLIB''':
 
<pre>
/*
 
FTEST.C - 03.02.2005 - 174 Lines
 
FTEST.C is to show how to write programs for
the Amstrad CPC under FutureOS in Small-C.
 
Compile (under CP/M):
 
A>cc -M ftest
A>zmac ftest=ftest
A>zlink ftest=fiolib,ftest,printf1
A>comfu ftest
 
COMFU.COM converts FTEST.COM to FTEST.SMC
by appending an 128 byte FutureOS header.
 
 
Start (under FutureOS):
 
RUN the RUNC.64K file, then
RUN any .SMC application, like FTEST.SMC (this here)
 
*/
 
 
#include fiolib.h
#include printf1.h
 
main()
{
 
char s[80];
int n,l,h;
 
mode(1);
pen1(1);
ink(16,068);
 
plot(270,040);
plot(279,043);
plot(288,046);
plot(297,049);
plot(306,052);
plot(315,055);
 
move(018,180);
draw(306,153);
 
pen1(2);
 
draw(072,135);
 
plot(270,033);
plot(279,028);
plot(288,024);
plot(297,021);
plot(306,019);
plot(315,018);
 
move(009,009);
draw(019,192);
move(029,009);
draw(039,192);
move(049,009);
draw(059,192);
move(069,009);
draw(079,192);
move(089,009);
draw(099,192);
move(109,009);
draw(119,192);
move(129,009);
draw(139,192);
move(149,009);
draw(159,192);
 
move(160,100);
circle(12);
move(200,110);
circle(18);
move(240,120);
circle(24);
move(280,130);
circle(30);
 
pen1(1);
 
printf("Hello, world\n\nThis is a test");
printf(" for the\nCPC Small-C library\n");
printf("\nby TFM of FutureSoft\n");
 
pen1(2);
printf("\nlet's write ... in pen 2\n");
printf("\nLook at variables H and L: high=%d, low=%d\n",h,l);
 
pen1(3);
printf("\nPress a KEY to continue\n");
getchar();
 
pen1(0);
printf("\nHi, this is a number: %d\n",12345);
 
pen1(1);
puts("This is a 0 terminated string.");
printf("\nPress any key to show 64 x 32 mode 2");
 
getkey(&n);
 
mode(2);
s64x32();
 
pen2(2);
printf("The pressed KEY was: %d\n",n);
 
pen2(3);
printf("\nPress a key again");
 
getkey(&n);
 
pen2(4);
printf("\nThe pressed KEY was: %d\n",n);
 
move(018,198);
draw(504,180);
draw(072,153);
 
printf("\nNow the screen has 64 columns");
printf(" in every line.....................");
 
pen2(1);
printf("And there are 99 lines");
 
pen2(0);
printf("\nAnd there are 32 lines");
 
locate(36,9);
printf("X <-- function: LOCATE(36,9)\n\n");
 
puts("Please enter a text string: ");
gets(s);
 
puts("\n\n\nAnd now edit the string: ");
edst(s);
 
printf("\n\n\nPress any key to resize to 80 x 25 mode 2\n\n");
 
plot(190,090);
plot(199,093);
plot(208,096);
plot(217,099);
plot(226,102);
plot(235,105);
 
plot(190,081);
plot(199,082);
plot(208,083);
plot(217,084);
plot(226,085);
plot(235,086);
 
move(160,100);
circle(12);
move(200,110);
circle(18);
move(240,120);
circle(24);
move(280,130);
circle(30);
 
getchar();
 
cls();
s80x25();
ink(16,084);
 
printf("Well, that's the END for today...\n\n");
 
}
</pre>
 
 
== Weblinks ==
* FIOLIB and demo applications: http://futureos.cpc-live.com/files/FIO.zip
* How to start a Small C program under FutuerOS using the RUNC framework: http://www.youtube.com/watch?v=6vWZeZpNYjg
2,002
edits