This shows you the differences between two versions of the page.
— |
project:gba:code [2007/04/27 00:21] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Code ====== | ||
+ | The project is complete, all code was tidied and presented in the project report (available on the [[: | ||
+ | ===== Random snippets of code ===== | ||
+ | |||
+ | ==== BitTest ==== | ||
+ | |||
+ | <code cpp> | ||
+ | // BitTest - initialize two variables and output the | ||
+ | // results of applying the ~, &, | and ^ | ||
+ | // operations | ||
+ | |||
+ | #include < | ||
+ | |||
+ | char* toBinary(int n){ | ||
+ | static char sResult[(sizeof(n)*8)]; | ||
+ | |||
+ | // Use bit-wise AND to check if the LSB of n is set, and place into | ||
+ | // our string accordingly (filling right-> | ||
+ | for(int i=sizeof(sResult); | ||
+ | sResult[i] = (n & 1) ? ' | ||
+ | n >>= 1; | ||
+ | } | ||
+ | |||
+ | return sResult; // Return a pointer | ||
+ | } | ||
+ | |||
+ | int main(int nArg, char* pszArgs[]){ | ||
+ | |||
+ | // | ||
+ | int nArg1 = 0x0f0f; | ||
+ | int nArg2 = 0xf0f0; | ||
+ | |||
+ | //now perform each operation in turn | ||
+ | //first the unary NOT operator | ||
+ | cout << " | ||
+ | cout << " | ||
+ | cout << " | ||
+ | cout << " | ||
+ | |||
+ | //now the binary operators | ||
+ | cout << "nArg1 & nArg2 = b" << toBinary(nArg1 & nArg2) << endl; | ||
+ | cout << "nArg1 | nArg2 = b" << toBinary(nArg1 | nArg2) << endl; | ||
+ | cout << "nArg1 ^ nArg2 = b" << toBinary(nArg1 ^ nArg2) << endl; | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== CommsProbe ==== | ||
+ | |||
+ | <code cpp> | ||
+ | #define false 0 | ||
+ | #define true 1 | ||
+ | |||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | short SC, SD, SI, SO, IO; | ||
+ | int data; | ||
+ | |||
+ | MULTIBOOT | ||
+ | int main(void) | ||
+ | { | ||
+ | ham_Init(); | ||
+ | ham_InitText(0); | ||
+ | |||
+ | SC = SD = SI = SO = IO = 0; | ||
+ | while(1) | ||
+ | { | ||
+ | if(F_CTRLINPUT_LEFT_PRESSED) SC=(SC+1)%2; | ||
+ | if(F_CTRLINPUT_RIGHT_PRESSED) SD=(SD+1)%2; | ||
+ | if(F_CTRLINPUT_B_PRESSED) SI=(SI+1)%2; | ||
+ | if(F_CTRLINPUT_A_PRESSED) SO=(SO+1)%2; | ||
+ | | ||
+ | if(F_CTRLINPUT_L_PRESSED) IO=1; | ||
+ | if(F_CTRLINPUT_R_PRESSED) IO=0; | ||
+ | |||
+ | set_comms(SC, | ||
+ | | ||
+ | int i=0; | ||
+ | while(i< | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Where '' | ||
+ | <code cpp> | ||
+ | #ifndef SIO_MULTIPLAYER_H | ||
+ | #define SIO_MULTIPLAYER_H 1 | ||
+ | |||
+ | //RCNT is used for mode selection | ||
+ | #define R_RCNT | ||
+ | |||
+ | #include < | ||
+ | |||
+ | /* GBAtek 1.4: | ||
+ | 134h - RCNT (R) - SIO Mode, usage in GENERAL-PURPOSE Mode (R/W) | ||
+ | Interrupts can be requested when SI changes from HIGH to LOW, as General Purpose mode does | ||
+ | not require a serial shift clock, this interrupt may be produced even when the GBA is in | ||
+ | Stop (low power standby) state. | ||
+ | |||
+ | Bit Expl. | ||
+ | 0 SC Data Bit | ||
+ | 1 SD Data Bit | ||
+ | 2 SI Data Bit | ||
+ | 3 SO Data Bit | ||
+ | 4 SC Direction | ||
+ | 5 SD Direction | ||
+ | 6 SI Direction | ||
+ | 7 SO Direction | ||
+ | 8 | ||
+ | 9-13 Not used | ||
+ | 14 Must be " | ||
+ | 15 Must be " | ||
+ | |||
+ | SI should be always used as Input to avoid problems with other hardware which does not | ||
+ | expect data to be output there. | ||
+ | */ | ||
+ | |||
+ | // Accept a string input of 0 and 1 chars | ||
+ | void set_comms(short SC, short SD, short SI, short SO, short IO){ | ||
+ | u16 data; | ||
+ | data = (1*SC) + (2*SD) + (4*SI) + (8*SO); | ||
+ | data = data + (IO * 0xf0); | ||
+ | data = data + 0x8000; | ||
+ | |||
+ | R_RCNT = data; | ||
+ | |||
+ | char st[100]; | ||
+ | sprintf(st," | ||
+ | ham_DrawText(1, | ||
+ | |||
+ | if(IO) ham_DrawText(1, | ||
+ | |||
+ | if(0x1 & R_RCNT) ham_DrawText(1, | ||
+ | if(0x2 & R_RCNT) ham_DrawText(5, | ||
+ | if(0x4 & R_RCNT) ham_DrawText(10, | ||
+ | if(0x8 & R_RCNT) ham_DrawText(15, | ||
+ | } | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== SuspendTest ==== | ||
+ | NB, has occasional problems with interrupt-driven progress indicator at present, so it's been disabled. | ||
+ | |||
+ | <code cpp> | ||
+ | #include " | ||
+ | |||
+ | MULTIBOOT | ||
+ | |||
+ | u32 count=0; | ||
+ | |||
+ | void interrupt(); | ||
+ | char* toBinary(u8 n); | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | ham_Init(); | ||
+ | ham_InitText(0); | ||
+ | ham_InitPad(); | ||
+ | |||
+ | |||
+ | // Setup the keypad interrupt register | ||
+ | R_CTRLINT= | ||
+ | 256+ // Button R | ||
+ | 512+ // Button L | ||
+ | 4+ // Select | ||
+ | 16384+ | ||
+ | 32768 // Enable logical AND mdoe (all button required) | ||
+ | ; | ||
+ | |||
+ | // Enable keypad interrupt handling | ||
+ | ham_StartIntHandler(INT_TYPE_KEY,& | ||
+ | | ||
+ | ham_DrawText(1, | ||
+ | ham_DrawText(1, | ||
+ | |||
+ | while(1) | ||
+ | { | ||
+ | ham_UpdatePad(); | ||
+ | | ||
+ | if(Pad.Pressed.A) | ||
+ | { | ||
+ | // BIOS ' | ||
+ | asm volatile(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | |||
+ | void interrupt() | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | char* toBinary(u8 n){ | ||
+ | static char sResult[(sizeof(n)*8)]; | ||
+ | |||
+ | // Use bit-wise AND to check if the LSB of n is set, and place into | ||
+ | // our string accordingly (filling right-> | ||
+ | int i=sizeof(sResult); | ||
+ | while(i> | ||
+ | sResult[i] = (n & 1) ? ' | ||
+ | n >>= 1; | ||
+ | i--; | ||
+ | } | ||
+ | |||
+ | return sResult; // Return a pointer | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== SRAM Backup ==== | ||
+ | Written to solve problems with my brother' | ||
+ | |||
+ | This is designed to use a [[http:// | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | MULTIBOOT | ||
+ | |||
+ | int i = 0; | ||
+ | const int SRAM_size = 65536; | ||
+ | |||
+ | void displayProgress(); | ||
+ | |||
+ | int main (void) | ||
+ | { | ||
+ | ham_Init(); | ||
+ | ham_InitText(0); | ||
+ | ham_DrawText(1, | ||
+ | |||
+ | char c; | ||
+ | int l = 1; | ||
+ | FILE fp = 0; | ||
+ | |||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | |||
+ | // Get character from PC keyboard | ||
+ | c = dgetch (); | ||
+ | | ||
+ | dprintf(" | ||
+ | R_WAITCNT = 3; // Set SRAM wait state for reliable reading/ | ||
+ | | ||
+ | // Setup a timer and interrupt for displaying progress indicators | ||
+ | M_TIM0CNT_SPEED_SELECT_SET(1); | ||
+ | M_TIM0COUNT_SET(3); | ||
+ | M_TIM0CNT_TIMER_START; | ||
+ | M_TIM0CNT_IRQ_ENABLE; | ||
+ | | ||
+ | // Disabled as it's randomly causing the program to hang | ||
+ | // | ||
+ | |||
+ | // Backup | ||
+ | if(c == ' | ||
+ | { | ||
+ | // Copy SRAM or Flash backup to PC | ||
+ | switch(c){ | ||
+ | case ' | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | fp = dfopen(" | ||
+ | break; | ||
+ | case ' | ||
+ | case ' | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | fp = dfopen(" | ||
+ | break; | ||
+ | } | ||
+ | for (i = 0; i != SRAM_size; i++) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | ham_DrawText(1, | ||
+ | dfclose(fp); | ||
+ | dprintf(" | ||
+ | } | ||
+ | |||
+ | // Restore | ||
+ | if(c == ' | ||
+ | { | ||
+ | // Copy PC to SRAM | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | fp = dfopen(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | |||
+ | for (i = 0; i != SRAM_size; i++) | ||
+ | { | ||
+ | *(unsigned char *)(i + 0xE000000) = dfgetc (fp); | ||
+ | } | ||
+ | dprintf(" | ||
+ | dfclose(fp); | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | ham_DrawText(1, | ||
+ | } | ||
+ | |||
+ | // Verify | ||
+ | if(c == ' | ||
+ | { | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | fp = dfopen(" | ||
+ | dprintf(" | ||
+ | dprintf(" | ||
+ | |||
+ | int errors = 0; | ||
+ | for (i = 0; i != SRAM_size; i++) | ||
+ | { | ||
+ | // File char != SRAM char | ||
+ | if(dfgetc (fp) != *(unsigned char *)(i+0xE000000)) | ||
+ | { | ||
+ | errors++; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | { | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Backup to after.bin | ||
+ | if(c == ' | ||
+ | { | ||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | fp = dfopen(" | ||
+ | for (i = 0; i != SRAM_size; i++) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | ham_DrawText(1, | ||
+ | dfclose(fp); | ||
+ | dprintf(" | ||
+ | } | ||
+ | | ||
+ | // Remove interrupt to ensure clean restart | ||
+ | ham_StopIntHandler(INT_TYPE_TIM0); | ||
+ | M_TIM0CNT_TIMER_STOP; | ||
+ | M_TIM0CNT_IRQ_DISABLE; | ||
+ | |||
+ | displayProgress(); | ||
+ | |||
+ | ham_DrawText(1, | ||
+ | dprintf(" | ||
+ | dgetch (); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | void displayProgress() | ||
+ | { | ||
+ | M_INTMST_DISABLE; | ||
+ | |||
+ | ham_DrawText(1, | ||
+ | |||
+ | M_INTMST_ENABLE; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | where mbv2lib.c is | ||
+ | <code cpp> | ||
+ | |||
+ | #define __ANSI_NAMES 0 | ||
+ | // | ||
+ | // v1.40 - Initial release. | ||
+ | // v1.41 - Put received keyboard & file data in separate buffers | ||
+ | // to prevent mixing of data during simultaneous use. | ||
+ | // Added dfprintf library function. | ||
+ | // v1.42 - Fixed bug in dfputc() where escape characters caused | ||
+ | // | ||
+ | // Tim Schuerewegen for finding this bug. | ||
+ | // | ||
+ | // MB v1.41 or later pc software is required to use this library | ||
+ | // software. | ||
+ | // | ||
+ | // NOTE: THIS LIBRARY USES GLOBAL INITIALIZED DATA SO YOU MUST USE | ||
+ | // A CRT0.S AND A LINKER SCRIPT THAT SUPPORTS THIS AS WELL. GET | ||
+ | // CRTLS V1.1 OR LATER FROM HTTP:// | ||
+ | // | ||
+ | // The following library functions are supported: | ||
+ | // | ||
+ | // Library name | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // If you wish to use the standard naming conventions | ||
+ | // rather than the library names then change " | ||
+ | // to " | ||
+ | // | ||
+ | // Notes: | ||
+ | // | ||
+ | // Currently only ONE file may be open at a time. | ||
+ | // | ||
+ | // If you are sending raw binary data to a PC file, use | ||
+ | // dfputc instead of dfprintf. Dfprintf will insert | ||
+ | // carriage return characters before linefeed characters | ||
+ | // on the PC side if the PC console software is running on | ||
+ | // dos/windows for proper text formatting. | ||
+ | // | ||
+ | // If you are missing some .h files during compile than get | ||
+ | // ' | ||
+ | // Apps / C Compilers section. | ||
+ | // | ||
+ | // Example command line: | ||
+ | // mb -s file.mb -c -w 50 -x 255 -m | ||
+ | // | ||
+ | // In this example, after transferring " | ||
+ | // the PC goes into console/ | ||
+ | // shows all of the file open/file close/ | ||
+ | // (-m) on screen. The -w value should be a large enough value | ||
+ | // where the -s is reliable and the -x value should be a large | ||
+ | // enough value where the -c is reliable with the GBA. | ||
+ | // | ||
+ | // [Sending a file & console mode each have | ||
+ | // their own delay settings because they | ||
+ | // each use a different method for transferring | ||
+ | // data. Each method is about ideal for it's | ||
+ | // | ||
+ | // | ||
+ | // Example GBA Code: | ||
+ | // | ||
+ | // #include " | ||
+ | // | ||
+ | // int main (void) | ||
+ | // { | ||
+ | // | ||
+ | // int i,j,k; | ||
+ | // FILE fp; | ||
+ | // | ||
+ | // dprintf (" | ||
+ | // | ||
+ | // // Get character from PC keyboard | ||
+ | // i = dgetch (); | ||
+ | // | ||
+ | // // Copy SRAM or Flash backup to PC | ||
+ | // fp = dfopen(" | ||
+ | // for (i = 0; i != 0x8000; i++) | ||
+ | // | ||
+ | // dfclose(fp); | ||
+ | // | ||
+ | // // Copy PC to SRAM | ||
+ | // fp = dfopen(" | ||
+ | // for (i = 0; i != 0x8000; i++) | ||
+ | // | ||
+ | // dfclose(fp); | ||
+ | |||
+ | // // Read data from file | ||
+ | // fp = dfopen (" | ||
+ | // i = dfgetc (fp); | ||
+ | // j = dfgetc (fp); | ||
+ | // k = dfgetc (fp); | ||
+ | // dfclose (fp); | ||
+ | // | ||
+ | // } | ||
+ | |||
+ | // Data transfer format | ||
+ | // -------------------- | ||
+ | // | ||
+ | // PC -> GBA Comms: | ||
+ | // Raw data is PC File read data. | ||
+ | // ESCCHR 0x00 = nada (used for input polling) | ||
+ | // ESCCHR 0x01 = Escape character from PC file read | ||
+ | // ESCCHR 0x08 0x?? = Keyboard read data | ||
+ | // | ||
+ | // | ||
+ | // GBA -> PC comms | ||
+ | // Raw data is console print data. | ||
+ | // ESCCHR = escape sequence | ||
+ | // ESCCHR 0x00 = nada (used for input polling) | ||
+ | // ESCCHR 0x01 = Escape character for console print | ||
+ | // ESCCHR 0x02 = file open (gba -> PC) | ||
+ | // ESCCHR 0x03 = file close (gba -> PC) | ||
+ | // ESCCHR 0x04 = fgetc (gba -> PC) | ||
+ | // ESCCHR 0x05 0x?? = fputc (gba -> PC) | ||
+ | // ESCCHR 0x06 = rewind (gba -> PC) | ||
+ | // ESCCHR 0x07 = fputc processed (gba -> pC) (Add CR before LF char if win/DOS machine) | ||
+ | |||
+ | #define FILE int | ||
+ | |||
+ | // Uncomment the following line to define the following types if needed | ||
+ | //#define INC_SHORT_NAME_TYPES 1 | ||
+ | |||
+ | #ifdef INC_SHORT_NAME_TYPES | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | #endif | ||
+ | |||
+ | #ifdef INC_REG_DEFS | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | #endif | ||
+ | |||
+ | #include " | ||
+ | |||
+ | #define __DOUTBUFSIZE 256 | ||
+ | #define __FINBUFSIZE 256 //Must be a multiple of 2! (ex: 32, | ||
+ | #define __KINBUFSIZE 64 // | ||
+ | #define __ESCCHR 27 | ||
+ | |||
+ | #define __ESC_NADA | ||
+ | #define __ESC_ESCCHR 1 | ||
+ | #define __ESC_FOPEN | ||
+ | #define __ESC_FCLOSE 3 | ||
+ | #define __ESC_FGETC | ||
+ | #define __ESC_FPUTC | ||
+ | #define __ESC_REWIND 6 | ||
+ | #define __ESC_FPUTC_PROCESSED 7 // PC side add CR before LF if DOS machine | ||
+ | #define __ESC_KBDCHR 8 | ||
+ | |||
+ | unsigned char __outstr[__DOUTBUFSIZE]; | ||
+ | unsigned char __finstr[__FINBUFSIZE]; | ||
+ | unsigned char __kinstr[__KINBUFSIZE]; | ||
+ | int finptr = 0; | ||
+ | int foutptr = 0; | ||
+ | int kinptr = 0; | ||
+ | int koutptr = 0; | ||
+ | |||
+ | int __dputchar (int c) | ||
+ | { | ||
+ | int rcv; | ||
+ | | ||
+ | | ||
+ | |||
+ | // Set non-general purpose comms mode | ||
+ | *(u16 *)REG_RCNT = 0; | ||
+ | |||
+ | // Init normal comms, 8 bit transfer, receive clocking | ||
+ | *(u16 *)REG_SIODATA8 = c; | ||
+ | *(u16 *)REG_SIOCNT = 0x80; | ||
+ | |||
+ | // Wait until transfer is complete | ||
+ | while (*(vu16 *)REG_SIOCNT & 0x80) {} | ||
+ | |||
+ | // Wait until SC is low | ||
+ | while (*(vu16 *)REG_RCNT & 1) {} | ||
+ | |||
+ | // Force SD high | ||
+ | *(u16 *)REG_RCNT = 0x8022; | ||
+ | |||
+ | // Wait until SC is high | ||
+ | while ((*(vu16 *)REG_RCNT & 1)==0) {} | ||
+ | |||
+ | rcv = *(vu16 *)REG_SIODATA8; | ||
+ | |||
+ | if (KbdCharNext) | ||
+ | { | ||
+ | // Put into keyboard buffer | ||
+ | __kinstr[kinptr++] = rcv; | ||
+ | kinptr &= (__KINBUFSIZE-1); | ||
+ | |||
+ | KbdCharNext = 0; | ||
+ | |||
+ | // Make received char look like a NADA character | ||
+ | // so that it won't be buffered elsewhere. | ||
+ | LastChar = __ESCCHR; | ||
+ | rcv = __ESC_NADA; | ||
+ | } | ||
+ | |||
+ | if (LastChar == __ESCCHR) | ||
+ | { | ||
+ | // Process escape character | ||
+ | switch (rcv) | ||
+ | { | ||
+ | case __ESC_ESCCHR: | ||
+ | __finstr[finptr++] = __ESCCHR; | ||
+ | finptr &= (__FINBUFSIZE-1); | ||
+ | break; | ||
+ | case __ESC_KBDCHR: | ||
+ | KbdCharNext = 1; | ||
+ | break; | ||
+ | } | ||
+ | LastChar = 0; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if (rcv == __ESCCHR) | ||
+ | | ||
+ | else | ||
+ | { | ||
+ | // If char received from PC then save in receive FIFO | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | int dputchar (int c) | ||
+ | { | ||
+ | | ||
+ | if (c == __ESCCHR) | ||
+ | (void) __dputchar(__ESC_ESCCHR); | ||
+ | | ||
+ | } | ||
+ | |||
+ | void __PrintStr (char *str) | ||
+ | { | ||
+ | while (*str) | ||
+ | (void) dputchar(*str++); | ||
+ | } | ||
+ | |||
+ | int dgetch (void) | ||
+ | { | ||
+ | int c; | ||
+ | |||
+ | // If no character is in FIFO then wait for one. | ||
+ | while (kinptr == koutptr) | ||
+ | { | ||
+ | __dputchar(__ESCCHR); | ||
+ | __dputchar(__ESC_NADA); | ||
+ | } | ||
+ | |||
+ | c = __kinstr[koutptr++]; | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | int dfgetch (void) | ||
+ | { | ||
+ | int c; | ||
+ | |||
+ | // If no character is in FIFO then wait for one. | ||
+ | while (finptr == foutptr) | ||
+ | { | ||
+ | __dputchar(__ESCCHR); | ||
+ | __dputchar(__ESC_NADA); | ||
+ | } | ||
+ | |||
+ | c = __finstr[foutptr++]; | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | int dkbhit (void) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | |||
+ | FILE dfopen (const char *file, const char *type) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | |||
+ | while (*file) | ||
+ | (void) dputchar(*file++); | ||
+ | | ||
+ | |||
+ | while (*type) | ||
+ | (void) dputchar(*type++); | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | int dfclose (FILE fp) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | int dfgetc (FILE fp) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | int dfputc (int ch, FILE fp) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | void drewind (FILE fp) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | void __PrintStrToFile (FILE fp, char *str) | ||
+ | { | ||
+ | while (*str) | ||
+ | { | ||
+ | __dputchar(__ESCCHR); | ||
+ | __dputchar(__ESC_FPUTC_PROCESSED); | ||
+ | |||
+ | dputchar(*str++); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | #ifndef dprintf | ||
+ | #define dprintf(x...) ({ dsprintf(__outstr, | ||
+ | #endif | ||
+ | #define dfprintf(y, | ||
+ | |||
+ | #ifdef __ANSI_NAMES | ||
+ | #define printf | ||
+ | #define fprintf dfprintf | ||
+ | #define putchar dputchar | ||
+ | #define getch | ||
+ | #define kbhit | ||
+ | |||
+ | #define fopen | ||
+ | #define fclose | ||
+ | #define fgetc | ||
+ | #define fputc | ||
+ | #define rewind | ||
+ | #endif | ||
+ | </ | ||
+ | |||
+ | ==== RS232 Terminal ==== | ||
+ | Adapted from [[http:// | ||
+ | |||
+ | [[http:// |