Home
PhrozenC user guide
Contents
1. printdec i T This above example initialize the table array with 5 items that are later initialized with values Please note that the first element in an array is designed by index 0 not 1 Finally we use the io printIntln function which allows to display an integer to screen with carriage return 5 11 Switch case statement Instead of cumulating if statements it s possible to make custom code implementation depending of a condition include PRINT C void main int i switch i case 4 printstrin Value isu4 break case 2 24 PhrozenC user guide version 1 1 printstrin Value is 2 break default printstrin Valueyisynoty4ynory2 break Please note the usage of break command which indicates where custom implementation for a given result ends 5 12 Pointers New thing to cover let s deal with pointers Basically pointers are variables that refer to memory locations of variables Let s see how it works by taking back with previous example include PRINT C void main ant 1 int table 5 int ptr int templ table 0 12 table l 7565 table 2 98 table 3 5 table 4 267 ptr table for i 0 i lt 5 itt tempI ptr i printdec templ This produces exactly the same behavior than previous example 5 13 Functions declaration and usage Finally let s in
2. int x int y mode 1 border 7 ink 2 26 ink 3 15 for x 0 x lt 200 x STEP for y 0 y lt 200 y STEP pen 2 plot x y draw x STEP y STEP pen 3 plot x STEP y 11 PhrozenC user guide version 1 1 draw x y STEP 3 4 INPUT This library features functions for all input related operations 3 4 1 Declaration wait for a pressed key ASCII character is returned as output waitKey fill destination buffer with string entered by user getstr dest char dest 3 4 2 Example EXAMPLE5 C Demonstrate the INPUT library features include PRINT C include INPUT C define MAXNAMESIZE 10 static char name MAXNAMESIZE main t printstr Enter your name u u getstr name printstrin printstr Your namejis printstrin name 3 5 MEMORY This library features functions for all memory related operations 12 PhrozenC user guide version 1 1 3 5 1 Declaration copy a block of memory from src to dst with specified length memcpy src dest length char src char dst int length set bank value being 0xC0 0xC4 0xC5 0xC6 0xC7 Previous bank is returned as output bankSwitch bank char bank 3 5 2 Example EXAMPLES C Demonstrate the MEMORY library features after compilation don t forget to override ORG position to
3. Examples e user sek k RAR Bae Ae RR a leie 14 4 Compiler internal 18 4 1 Supported C features 18 4 2 Inlined assembly 18 ADA Declaration a i a see a SOO a Sat ew eae ee Fe 18 4 2 2 Registers constraints 2 on e ee 18 4 2 3 Accessing C variables from an assembly block 19 4 2 4 Creating native functions 2 nn on 19 5 Small introduction to C 20 5 1 Hello Worlds ss sage s saa Gases de det d ass Ge ea 20 5 2 Preprocessor DEFINE rv vr none nen 20 5 3 Get string from user and displays it back to user 2222 nn nennen 21 5 4 Variables declaration e 21 5 5 Loop FOR statement 22 5 6 Incrementation in Loop FOR statement e 22 5 7 Display integer iioi e i a o e e i a e E a E a a 22 5 8 Loop WHILE statement 23 5 9 Loop DO WHILE statement e 23 5 10 Arrays declaration and usage osoase RRR RRR rn kn vn 24 PhrozenC user guide version 1 1 5 11 Switch case statement e 24 G POMBETS s A ee a dk heste e a A Menes 25 5 13 Functions declaration and usage 25 5 14 Functions returning values LL Como nn 26 5 15 Including multiple C files together 27 5 16 Comments in source code 2 2 2 2m nn 27 5 17 Using global variables 2 2 2 2 oo non nn 28 5 18 Using inlined ASM 28 6 Examining ASM output 30 6 1 EE EE ua aa sad te a ll ee G seg 30 6 2 Generated ASM output listing 31 6 3 Observations mis ae kok ae EEN ee oH ea
4. b return a b Compiling MAIN C will result in succesful build The add function has been included 5 16 Comments in source code Now let s see how to add comment in a source include the IO functionalities include PRINT C main function void main declare values on stack char isError char try opening file isError io fopen readStream README TXT if isError 0 27 PhrozenC user guide version 1 1 printstrln Erroryoccuredywhileyopeningufile else display file content do c io readStream char if c 0 d io printChar c while c 0 close file io_fclose_readStream T 5 17 Using global variables It s possible to declare a variable outside a code block delimited by and Important note always use static keyword when the scope is global static int i void main for i 0 i lt 5 itt asm ld a 65 call amp BB5A endasm T That way every functions can directly access the variable without passing it through parameters 5 18 Using inlined ASM Now let s see how to use inlined ASM in a C source void main int i for i 0 i lt 5 itt asm 28 PhrozenC user guide version 1 1 ld a 65 call amp BB5A endasm The above example displays 5 characters A to screen directl
5. ptri char ptr2 PhrozenC user guide version 1 1 int len int aNumber strlen ptri ABCD1234 len strlen ptri printstr ptri printstr u u printint len printstrln characters strcpy strepy bigString I muaucopyu printstrln bigString strcat strcpy bigString This uisuau strcat bigString string uconcatenation printstrln bigString itoa aNumber 32 itoa aNumber bigString 10 printstr bigString printstr u u amp itoa aNumber bigString 16 printstrin bigString 3 3 GRAPHIC This library features functions for all screen related operations 3 3 1 Declaration set graphic mode to 0 1 or 2 mode mode char mode clear screen cls set current for drawing operations pen pen char pen set color for specified pen ink pen color char pen char color set color for border border color char color 10 PhrozenC user guide version 1 1 move current position to x y move x y int x int y get pen color at specified position x y test x y int x int y plot a pixel at x y coordinates plot x y int x int y draw a line to x y coordinates draw x y int x y 3 3 2 Example EXAMPLE3 C Demonstrate the GRAPHIC library features include GRAPHIC C define STEP 10 main
6. 9 Contact amp Closing words I tried to do my best in providing a simple and reliable C compiler to the CPC platform For any information suggestions enhancements bugfixes or whatever feel free to contact me at arnaud storq gmail com Thank you for using PhrozenC 36
7. First let s create a small C program that will display 10 times the sentence Hello World see how original it is include PRINT C void main t int i for i 0 i lt 10 i t T printstrin Hello World Edit this C source code using your favorite text editor and save it as HELLO C 2 1 Windows PC In command line mode type CC HELLO C If no errors were found during the compilation HELLO ASM will be created in the same folder than the C source file Now you can open WinAPE emulator PhrozenC user guide version 1 1 and compile that generated ASM file exactly like you would do with regular ASM source code 2 2 ROM version Execute the following RSX command type CC HELLO C If no errors were found during the compilation HELLO ASM will be created Now you can open Maxam and compile that generated ASM file exactly like you would do with regular ASM source code Amstrad Microcomputer ud gt 61985 Amstrad ple and Locomotive Software Ltd PARADOS V1 1 81997 QUANTUM Solutions PROTEXT word processor 21985 Arnor Ltd MAXAM 11 assembler 1988 Arnor Ltd Phrozent V1 8 ICCHELP for help BASIC 1 1 Read icc H r examplel c Figure 2 Compilation of a C program using ROM version 2 3 RAM version 2 3 1 64Kb compatible standalone version Execute the following program RUN CC Enter HELLO C when the program asks for a filename an empty string entere
8. PhrozenC user guide written by Arnaud Storq March 26 2010 https sourceforge net apps trac phobia wiki PhrozenC PhrozenC user guide version 1 1 Contents 1 Introduction 4 2 First compilation of a C program 5 21 Windows PO s 4 86840444 44 6 Oe eb kr Ra ae Ed 5 2 2 ROM version 2 4 2 da ee BJ GR LA Goder frie ee BS 6 2 3 RAM version 6 2 3 1 64Kb compatible standalone version 6 2 3 2 128Kb only RSX version 2 22 Coon nn 6 3 Available libraries 8 Balk BRINT Ge SE NES eier 8 Slik Declaration saa seas sa rakke G L ad Eee GS 8 3 12 Example meg h e i da GE ok be be Vb dg Me l ed 8 3 2 STRING 228 Jesse hae don BR Gk Gok BA Moe ee aoe ee 9 32 1 Declaration c sa dera 54 A k bes ae a OO EE om Gene a 9 3 22 Example s 6 rimar sale sa aan ee GAG Der r eS 9 3 3 GRAPHIC 22nd nwes Sa As ae BEDE ee boa dur dale ek a 10 dol Declaration o 4 nr r eder 2 u Oe ee eA Ge ne a A 10 3 32 Examples cacti agen es col Sad ee aD kule sd aa ak KE mek Ba 11 Bide HOT GAB armas o NE 12 341 Declarati n o a aa sag Kodak d a Geek eg 12 34 2 Example s meg eh bb 444 we FE see oder bey fee E dagl i ge ar 12 3 5 MEMORY A gare see 208 STN SEE Sk A en GS GAR GR KG EEG ENG 12 3 51 Declaration nasse na ee a me Soe 4 13 3 5 2 Example soria ic a a PEER DOR A Ya 13 30 FEL Gress See ie Be BRO YE Gee peek Ai eee es 14 3 6 1 Declaration o 2 46 4 sr ar fr Oe Cee bea de nn 14 3 62
9. World by HELLO defined by ttdefine state ment Once declared when the compiler meet HELLO next times it will replace text with the content of the define define also works with integers It s possible to undefine previously defined declarations using undef undefine Also it s possible to include blocks of code by testing defined declarations existence through ifdef if defined ifndef if NOT defined else and endif commands define OPTIMIZE 1 void main ifdef OPTIMIZE the uber optimization is here else slow code probably a version which is less buggy endif ifndef OPTIMIZE special treatment for non optimized code 20 PhrozenC user guide version 1 1 endif undef OPTIMIZE from here the compiler don t know anything about the previous OPTIMIZE declaration 5 3 Get string from user and displays it back to user Now a new example where user is asked to enter his age and displays it back to the user include PRINT C void main char ageText 30 printstr Enter your uageu u getstr ageText printstrin printstr Youruageuisu printstrin ageText In the above example we actually declared a table of characters called ageText of size 30 The getstr function is used here to let the user type a string value and output it into our ageText table Then we display it back to the us
10. a value different from 0x4000 to Ox7FFF include PRINT C include MEMORY C include GRAPHIC C include INPUT C main d int 1 int bankList 5 bankList 0 0xc0 bankList 1 0xc4 bankList 2 Oxc5 bankList 3 Oxc6 bankList 4 Oxc7 for i 0 i lt 5 i mode 2 bankSwitch bankList i memcpy 0x4000 0xc000 0x4000 printstr this is bank amp printhex bankList i printstri u waitKey 13 PhrozenC user guide version 1 1 T bankSwitch OxcO 3 6 FILE This library features functions for all file related operations 3 6 1 Declaration open a file for reading Returns 0 if a problem occurs 1 if OK openread filename readbuffer char filename char readbuffer open a file for writing Returns 0 if a problems occurs 1 if OK openwrite filename writebuffer char filename char writebuffer close file opened in read mode closeread close file opened in write mode closewrite read a char from reading file getchar returns 1 if end of current reading file has been reached iseof read the whole content of the file to ptr getbinary ptr char ptr write a char to writing file putchar c char c write a string to writing file putstr text char x text write a string with carriage return to writing file putstrln text char te
11. c char binReadData BINARYSIZE static int checksun initBinData int i checksum 0 for i 0 lt BINARYSIZE i 1 binWriteData i i checksum binWriteData i writeBinary if openwrite BINFILENAME writebuffer 0 d return T 16 PhrozenC user guide version 1 1 putbinary binWriteData BINARYSIZE 0 closewrite readBinary int 1 int readcs if openread BINFILENAME readbuffer 0 return T getbinary binReadData readcs 0 for i 0 i lt BINARYSIZE i readcs binReadData i closeread if readcs checksum printstrin Checksum 0K else printstrin Checksum FAILED 17 PhrozenC user guide version 1 1 4 Compiler internal 4 1 Supported C features Because PhrozenC is based on SmallC compiler developer has to use the K amp R style C syntax Modern compilers are ANSI C so expect many differences between PhrozenC and a full featured ANSI C compiler e all common operators are supported E E lt lt gt gt amp amp amp l res ke gt gt lt lt amp e no float with Zilog Z80 it s recommended to use fixed math anyway e no struct try reorganizing memory with indices instead e no bool use char instead e no macros macros multi lined DEFINE are not supported e n
12. d will display disc catalog If no errors were found during the compilation HELLO ASM will be created and you will be asked to press a key to reset the computer Now you can open Maxam and compile that generated ASM file exactly like you would do with regular ASM source code 2 3 2 128Kb only RSX version First make sure to initialize PhrozenC in memory To accomplish this execute the following BASIC program RUN CC RSX Now the RSX commands are installed Execute the following RSX command type CC HELLO C If no errors were found during the compilation HELLO ASM PhrozenC user guide version 1 1 will be created Now you can open Maxam and compile that generated ASM file exactly like you would do with regular ASM source code Figure 3 Generated ASM output shown under Arnor s Protext word processor PhrozenC user guide version 1 1 3 Available libraries PhrozenC is a standalone C compiler To help developer in making programs for the Amstrad CPC a set of external C source code is provided These helpers called librairies are uniquely based on Amstrad CPC s firmware It s eventually planned in a later version to extend those libraries with management of CRTC Gate Array interrupts feel free to enhance current versions and send them to me I will be happy to integrate your changes in future PhrozenC releases 3 1 PRINT This library features functions for displaying text to the user 3 1 1 Declarat
13. er through the printstrin function printstr is used here to display text without carriage return at the end where printstrln adds a carriage return at the end of the string when displaying it 5 4 Variables declaration Basically 2 types are available char which is 8 bits values from 127 to 127 and int which is 16 bits values from 32767 to 32767 You can also prefix types with unsigned statement which would give unsigned char which is 8 bits values from 0 to 256 and unsigned int which is 16 bits values from 0 to 65535 void main unsigned int memorySize unsigned char age int angle char temperature 21 PhrozenC user guide version 1 1 5 5 Loop FOR statement Now let s have fun with loops Let s say we want to display 10 times the message Loop include PRINT C void main int i for i 0 i lt 10 i printstrln Loop The above example initialize the i variable to 0 i 0 then increments it by 1 i till it reachs 10 i lt 10 So basically the format for a FOR statement is as follows for initial value condition increment instruction 5 6 Incrementation in Loop FOR statement But we could also get it incrementing by 2 instead of 1 with the following code include PRINT C void main int for i 0 i lt 10 i 2 printstrln Loop T We just changed i by i 2 5 7 Display inte
14. ger Now let s say we want to display iterator value include PRINT C void main int 1 char text 30 char textAsInt 30 for i 0 i lt 10 i 2 22 PhrozenC user guide version 1 1 printstr Loop_ printdec i printstrin It displays Loop followed by integer value 5 8 Loop WHILE statement Now let s introduce a new way of doing loop with while keyword include PRINT C void main int i i 10 while i 0 printstrln Hello i T This above example initialize the i integer to 10 displays the Hello string decrements the i value tills it reachs 0 5 9 Loop DO WHILE statement Also available the structure do while include PRINT C void main int i i 10 do d printstrin Hello i while i 0 23 PhrozenC user guide versi n 1 1 This above example initialize the i integer to 10 displays the Hello string decrements the i value tills it reachs 0 The only difference with the previous example is that the evaluation is done at the end of the code of block instead of the beginning 5 10 Arrays declaration and usage Now let s play with arrays include PRINT C void main int i int table 5 table 0 12 table 1 7565 table 2 98 table 3 5 table 4 267 for i 0 i lt 5 itt
15. ion print text to screen printstr text char x text print text to screen with line return appended to the end printstrin text char text print ASCII char to screen printchar c char c print integer to screen decimal version printdec i int i print integer to screen hexadecimal version printhex i int i 3 1 2 Example EXAMPLE1 C Demonstrate the PRINT library features include PRINT C main char 6 Int 1 printstrin Now displaying the alphabet 0 for c A c lt 2 cH version 1 1 PhrozenC user guide printchar c i printstrin printstr Letterycountu u printdec i printstrin 3 2 STRING This library features functions for all string related operations 3 2 1 Declaration get length of string outputs an integer strlen src char src copy string content from src to dst strcpy src dst char x src append stc string to dst strcat src dst char src converts integer to dest or 16 hexadecimal char dst string char dst string base being equals to 10 decimal itoa intvalue dest base int intvalue char base char dest 3 2 2 Example Demonstrate the STRING library features EXAMPLE4 C include PRINT C include STRING C static char bigString 64 main d char
16. mstrad CPC 6128 6128 ROM version the compiler is available as a ROM ap plication that can be executed through RSX usage It makes use of the upper extra 48Kb memory C5 C6 C7 banks but let intact resident memory and bank amp C4 It s recommended to use the ROM version of PhrozenC conjointly with the popular Arnor ROM based devel opment products Protext Maxam and Promerge PhrozenC s usage is really easy Basically it converts a C file and its dependencies directly to a single ASM source file ready to be compiled with Arnor s Maxam or Richard Wilson s WinAPE PhrozenC is a single pass compiler meaning that it does not have to keep the whole source code to be compiled in memory It directly outputs ASM opcodes of C code being read Due to internal usage of SmallC PhrozenC is not an ANSI C compiler but use K amp R style C instead Differences between ANSI C and K amp R style C are relatively small and explained in a later section That said K amp R style C is standard and all compilers on PC platforms are able to compile K amp R style C code GCC VisualStudio Finally PhrozenC does not introduce specific optimizations Developer is able to directly em beed inlined ASM meaning it s possible to include in the earth of a C source code a pure bunch of ASM source code PhrozenC user guide version 1 1 Figure 1 A C source shown under Arnor s Protext word processor 2 First compilation of a C program
17. o constants use DEFINE instead e no function pointers so calls by reference are impossible But you can easily get over this using inlined asm e all functions are assumed to return an int sized output parameter that s why you don t need to specify the return types You can return a char an int a pointer Or nothing e you can t assign a default value to a variable at declaration time e different function headers the types of the parameters are given separately from their names in the space before the functions first open curly brace e one dimensional arrays only multi dimensional arrays are not supported 4 2 Inlined assembly 4 2 1 Declaration PhrozenC allows inlined assembly This means that everything between asm and endasm state ments won t be treated by the C compiler but present in ASM output function asm ld a 65 call amp bb5a endasm 4 2 2 Registers constraints Good news for you at any time you can use ALL registers even the stack if your code does not corrupt it of course 18 PhrozenC user guide version 1 1 4 2 3 Accessing C variables from an assembly block Only global variables can be easily accessed If you declare a global variable like this static int myGloballnt it will be inserted like this in the ASM output file myGloballnt dw 0 As a consequence you can easily write the following sta
18. ozenC user guide version 1 1 jp L3 L5 ld h1 27 jp Li Li pop bc ret printA ld a 65 call amp bb5a L6 ret add2 ld hl 4 add hl sp call Lgint push hl ld h1 4 add hl sp call Lgint pop de add hl de jp L7 L7 ret globalVarA dw 0 globalTable ds 256 Lpint ld a 1 ld de a inc de ld a h ld de a ret Lgint Id a hl inc hl ld h hl td Le ret Lit R ert5 call Lcmp ret 32 PhrozenC user guide version 1 1 Lemp Lcmp1 dec hl ret ld a e sub 1 ld e a ld a d sbc a h ld h1 1 jp m Lcmpi or e ret or e Sek ret 33 PhrozenC user guide version 1 1 6 3 Observations Generated code overall basically generated code use intensively the stack to store its local variables It also makes use of HL and DE 16 bits registers as also the accumulator It will never use something else Generated code speed generated code is absolutely not optimized in terms of speed so you quickly inderstand where you should use C and where it does not apply to the context Generated code size generated code is absolutely not optimized in terms of size but the good news here is that due to its low usage of different ASM instructions it gets packed pretty well Global variables all global variables are put into the same section like this globalVarA dw 0 globalTable ds 256 Local variables all local variable
19. ren 34 7 Frequently asked questions FAQ 35 8 Credits 36 9 Contact amp Closing words 36 PhrozenC user guide version 1 1 1 Introduction PhrozenC is a C compiler based on original SmallC compiler SmallC has been initially created in 1980 by Ron Cain targetting CP M machines at the time which also includes the Amstrad CPC In the beginning of the year 2010 I found out back the compiler s source code on the net and tried to compile it for the PC platform It worked pretty well and I personally found its implementation relatively small in terms of memory footprint For the fun like many projects started I guess I tried making a real Amstrad CPC port at first I was not able to get it working as expected but finally after some tweaks and many headaches I succedeed in the task PhrozenC is available in several versions e Windows PC the compiler is available as a stand alone command line application e Amstrad CPC 464 464 the compiler is available as a stand alone application that use the whole memory of the machine After execution all memory has been plainly used and destroyed previous content This version is released for compatibility purposes and is definitively not the way to go e Amstrad CPC 6128 6128 the compiler is executed through RSX usage It makes use of the full extra 64Kb memory to keep the compiler in its compressed state and also to preserve memory state in the first 64Kb memory area e A
20. s are pushed onto the stack Warning if you are planning to use recursive functions feel free to move the stack pointer at a custom location Inlined ASM Code between asm endasm statements did not have been modified Impor tant note inlined ASM can use ALL registers even the accumulator the second register set EXX the stack DE HL this is a great feature regarding other existing cross platform C compilers CRT functions To get C code working as expected some additional code are integrated into the generated ASM output In the example these are Lpint Lgint L1t and Lemp 34 PhrozenC user guide version 1 1 7 Frequently asked questions FAQ e Do you seriously consider using C to make CPC programs Of course yes Phat and Pheelone demos have been created using a C compiler and it proved to be a completely viable solution That said inlined ASM is still mandatory in term of performances Don t expect bringing a port of DOOM game to CPC it s just impossible You should use plain C to make utilies In the context where performances matters use C to make your initializations file loading structured code big loops but let to the inlined ASM be the slowest part to execute e What did you change from the original SmallC The main logic of SmallC is still here I had to completely rewrote the input output parts integratde the CRT functions embedded with the source understood and tweaked memory management remo
21. tic int myGloballnt function asm ld hl myGloballnt inc hl ld myGloballnt hl endasm 4 2 4 Creating native functions You can write functions that will be entirely implemented in assembly In the following example input parameters are available through the stack and output parameter is always the HL register s content strlen text char text t asm pop bc pop hl HL text push hl push bc ld e 0 strlenloop ld a hl or a jp Zz strlenend inc hl inc e jp strlenloop strlenend ld h 0 HL output value ld 1 e endasm 19 PhrozenC user guide version 1 1 5 Small introduction to C Like PhrozenC features a very small subset of C it s easy to make some kind of tutorial about programming in C 5 1 Hello World This is what looks a basic Hello World program using PhrozenC include PRINT C void main d printstrin Hello World 5 2 Preprocessor DEFINE In all C programs there is a main function which is followed by a and closed by a printStrln function is used to print a string onto the screen The first line tells to the compiler to include the whole content of the file PRINT C which contains the declaration of the printstrln function include PRINT C define HELLO Hello World void main printstrln HELLO In the above example we replaced the string Hello
22. troduce function usage by taking back previous example include PRINT C void main 25 PhrozenC user guide version 1 1 int i int table 5 int ptr int templ table 0 12 table 1 7565 table 2 98 table 3 5 table 4 267 showTable ptr showTable p int p d for i 0 i lt 5 HH tempI ptr i printdec templ What it basically does is to declare a function called showTable that takes as parameter a pointer of type int called p 5 14 Functions returning values Another usage of functions include PRINT C void main int i i add 4 6 printdec i add a b int a int b return a b The above example will display 10 to the user It actually calls the add functions which takes 2 int parameters called a and b In that custom function we returned the sum of the 2 integers If function has to return something else than an integer you don t have to specify its type 26 PhrozenC user guide version 1 1 getStringWithoutFirstchar ptr char ptr return ptr l 5 15 Including multiple C files together It s possible to link several C source code in a one and only file using the include statement MAIN C include PRINT C include ADD C void main int i i add 4 6 printdec i ADD C add a b int a int
23. ved unused parts of code made modifications to the reading code in order to get only one file in reading mode at one time added compilation stop when a first error is found and lots more That said I tried to no introduce hacks to original compilation algorythm I wished to keep a clean and reliable port for the Amstrad CPC platform e Do you have some C optimizing tips to share If you have multiple variables to initialize at the same time with a default values prefer the following int a int b int to this int a int b int II o Also make sure to understand where goes the variable allocations As a reminder local variables lives on stack and global variables lives at static memory address For performance reasons I advise to use global variables if possible when speed matters so that way variables won t be pushed on stack Finally try to use char type instead of int whenever it s possible 35 PhrozenC user guide version 1 1 8 Credits These are the people involved in this production e Original SmallC programming by Ron Cain 1980 e Amstrad CPC port libraries and documentation by Arnaud Storq NoRecess 2010 e Technical support provided by Grim Targhan and Offset Thank you guys e CPCWiki Kevin Thacker for the source for file access info e Third party tools used BitBuster T amp J version WinAPE ManageDSK many thanks to the author
24. xt write content to file putbinary ptr length execPtr char ptr int length char execPtr 3 6 2 Example 14 PhrozenC user guide version 1 1 EXAMPLE2 C Demonstrate the FILE library features include PRINT C include FILE C define TXTFILENAME TESTTEXT BIN define BINFILENAME TESTDATA BIN static char readbuffer 2048 static char writebuffer 2048 main write an ASCII file containing the alphabet printstrin TEST 1 4 WRITE ASCII FILE writeText read the ASCII file and display it to screen printstrin printstrin TEST2 4 jREAD ASCII FILE readText initBinData write a BINARY file containing the alphabet printstrin printstrin TEST 3 4u WRITE BINARY FILE writeBinary read the BINARY file and check that result is OK printstrla printstrln TESTy4 4 4 yREADGBINARYGFILE readBinary T writeText int i if openwrite TXTFILENAME writebuffer 0 T putstrin This jisythe jalphabet return 15 PhrozenC user guide version 1 1 for i ir i lt 2 itt putchar i putstrin closewrite readText t if openread TXTFILENAME readbuffer 0 d return T while iseof 0 printchar getchar closeread define BINARYSIZE 100 static char binWriteData BINARYSIZE stati
25. y using firmware method There is no special constraint in using asm inlined code You can even kill interrupts if you want move stack pointer everywhere you want and also access global variable static char i void main for i 0 i lt 5 it asm ld a i add a 65 call amp BB5A endasm That will display ABCDEF to the user 29 PhrozenC user guide version 1 1 6 Examining ASM output 6 1 C source code Let s take this basic C source code as example static int globalVarA static char globalTable 256 main int iOnStack iOnStack add2 4 5 for iDnStack 2 iOnStack lt 5 iOnStack printA return 27 T printA asm ld a 65 call amp bb5a endasm add2 a b int a int b d return a b 30 PhrozenC user guide version 1 1 6 2 Generated ASM output listing This is the generated ASM output listing main L2 ES L4 org amp 4000 nolist jp main push bc ld h1 65536 add hl sp push hl ld h1 4 push hl ld h1 5 push hl call add2 pop bc pop bc pop de call Lpint ld h1 65536 add hl sp push hl ld h1 2 pop de call Lpint ld h1 65536 add hl sp call Lgint push hl ld h1 5 pop de call Lit ld a h E E p nz L4 p L5 o Cdi Cds ld h1 65536 add hl sp push hl call Lgint inc hl pop de call Lpint dec hl jp L2 call printA 31 Phr
Download Pdf Manuals
Related Search
Related Contents
TRITACARNE - mbm Linksys DVD & Multimedia Player DP-1100 Lean MAST - ThomasNet Sitecom LN-510 85Mbps Homeplug Kit 取扱説明書 - ナック販売 Epson Stylus 1000 Ink Jet Printer Product Brochure maintenance work on chassis and engine Copyright © All rights reserved.
Failed to retrieve file