ELF(4`4 ( pt444444uu`MPPPDDQtd/lib/ld-linux-armhf.so.3GNUGNUGc:qč4**F%;-($/+684'"& :5*),% 3 .  #19! 027% D B0Ě A@ "@(`AFb 4Q& "#$&'(*,.0124569=9 \AE> E6ZU1}s4|+k[˧ O[1/N=||Fu9v)2u. ʜ2>XyC+>~|@QlAI엩z?Y~AZ+˖HqX|! &vU_ޓnK?ժ?BE췓4q!{|WvT<  B3I p:`My ^Q4.'`M~o@Vp`M;W!fNW}`M4 libSDL-1.2.so.0__gmon_start___Jv_RegisterClasses_init_finilibSDL_image-1.2.so.0SDL_FreeSurfaceSDL_QuitSDL_PollEventSDL_GetMouseStateIMG_LoadSDL_DisplayFormatSDL_MapRGBSDL_SetColorKeySDL_GetErrorSDL_SetPaletteSDL_SetVideoModeSDL_InitSDL_GetVideoInfoSDL_WM_SetCaptionSDL_CreateRGBSurfaceSDL_FillRectSDL_UpperBlitSDL_FlipSDL_Delaylibstdc++.so.6_Znwjlibm.so.6libgcc_s.so.1__aeabi_unwind_cpp_pr0__aeabi_unwind_cpp_pr1__aeabi_idiv__aeabi_idivmodlibc.so.6strcpy_IO_putcfopenputsputcharabortprintfrewindstrtolfgetsstrlenfseekstdoutfclosemallocstrncatfreadstrcmp__libc_start_mainbasenamefree__cxa_atexit_edata__bss_start__bss_start____bss_end____end___endGCC_3.5GLIBC_2.4GLIBCXX_3.4 U&y  ii at)4 8<0@1D.HLP(TX\6` d#hl3pt x|"$'%, !&5:/+4-@-D-PsƏʌPƏʌHƏʌ@Əʌ8Əʌ0Əʌ(Əʌ ƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌƏʌxƏʌpƏʌhƏʌ`ƏʌXƏʌPƏʌHƏʌ@Əʌ8Əʌ0Əʌ(Əʌ ƏʌƏʌƏʌƏʌƏʌƏʌPO-` MP9@ P PN|h PFT zP xL vH qD r@ p< n8 l4 j0 h, f( d$ b ` ^ \ Z aP @z00T#P  P P P: P, lPd: XPP: wP 4rP :  hP cP9   ZP@T(  9LP@T  9>P@T  `9T /P @*P @T  9 P@T -P @T 80s EP @T 8 x8z*PpP @T D8 t48z*T0P @T 8 c7z*XP@T P70s yPl7l'0s#d lP@7@'0s#e DP@T 7  $6ǟx#  \60 P {P @T  6Pʐ6 gP pbP X0  000@V(NP9 IP4 DP/ ?P* :Po 5Pj 0Pa +P\ &P !PlTPLZ~4LH((40,$ ~|zxvtrm<e4hfdb`ZW axVtTpRlPhNdL`J\HXFTD<@T8  ),4@00+/'+#0HBS3     42SPpcP P tܚ̚000 3P0P PQ 4 th.,Xd,PDxHPXdhx-hl pP`tl.(-0d(-,-$8$- 4$,8D4dTP0 L TX0<X (Lh$d4<4-,D-tHx@H<-| @p8@-p@PP0D D̈́dPh SD0S0.R0 T0P008TKK  --- 0E 0 00S/=@b0 R  / @-0S0S3/ A-2b0S0SB@PD~P TXDP 0D1HP ,2 H!LP 2 L!PP 1 P!TP 1 T!XP 1 X!\P 1 \!`P 1 `!|ApP q^UXAP <1  TP 1 T PP z1 P 0S-0$,h 0 S0 P 50 0CP 0R 0 B0`00ST00S`A(X&kP#$00S <44TKKX\ @-<0< $嬅`I PRq\ C!dP \C Q QTD R|\㰔 `C PT P8H\  a80Pğ$ 0 P8!LH \a 80P`$0 ~P8H\  a@0PDğ$$ 0 P8!LH \a @0}P#0 P8H\  a80nPvß# 0 P8!LH \a 80^Ph#0 P8H\  a@0OPrLß,# 0 P8!LH \a @0?P "0 P8H\  a800PJŸ" 0 P8!LH \a 80 Ppp"0 P8H\  a@0P"TŸ4" 0 6P8!LH \a @0Pl!0 &!0 S!0 t!0 |pP!0 {XL,!0 4(!0 !0   0  W 0   0  |t 0  \sP 0  LЍ}4hh-p-(-P-pA-MQ0SS1A X60SMTP q` phX d1`⾀SPI0S T R 4110PP S@tDd* pX `0开2P#0S P0S X0SЍЍA| 0h`40PL88-KKLMK 4@-@2S 2040 , 0S0X0S p04$@c 28<<0 , 0S,0X0S 8<$-4095 read: long page line %d >256 read: %d lines read CreateRGBSurface failed: %s BlitSurface error: %s info: updating video screeninfo: clear screeninfo: background updatedinfo: updating text_page, %dx%d at %d,%d info: page updatedinfo: video screen updatedinfo: file has 0 linesinfo: file has %d lines open: EOF reachedinfo: do info: do info: do Previous Lineinfo: do Previous Pageinfo: showing text pagenextpage: page top set to file line %d nextpage: EOF reachednextline: page top set to file line %d nextline: EOF reachednextline: 0 lines readprevline: page top set to file line %d prevline: EOF reachedprevline: 0 lines readprevpage: page top set to file line %d prevpage: EOF reachedlastpage: page top set to file line %d lastpage: EOF reached (%d) sdlRead (one-file) v%s 1.1.2error: cant open '%s' --version-v--helpCopyright 2016 MiNTed Games Display a text file using image fonts with SDL 1.2 usage: sdlRead-1f [_option_] _option_: -1f one-file (1f) source information --background shown under text (maybe use with --outline) --imagefont used to diplay text (use without for more help) --color set color of font --bgcolor set page background color (when no image) --outline show text with font outline --margin indent pixels from page edge --fullscreen use display maximum WxH --wrap wrap lines of displayed text --nowrap dont wrap lines of displayed text --help This help information --help=font Show ImageFont help information -v|--version Version information--help-imagefont--help=imagefont--help=font--imagefontHelp with ImageFont settings and information. usage: sdlRead-1f --imagefont [_option_] --imagefont 90 char. bitmap image, size = (font-width x 90) x font-height --imagefont 256 char., size = (font-width x 256) x font-height (use --font-256) --imagefont proportional, multicolor font image (detects W & H, see example) --font-width width of font in pixels, if NOT proportional (default %d) --font-height height of font in pixels, if you want to adjust (default %d) --font-256 font has all 256 chars (default is char. 33 to 126, else use key) --font-prop imagefont is proportional font (GuiChan ImageFont) --font-color use custom color for font color --font-key imagefont is proportional and/or not standard 123/256 chars. --color Caps. or lowercase, font color (default WHITE) --bgcolor set page background color (when no image) --page-width width of centered page for text, in pixels --page-height height of centered page for text, in pixels --margin indent page pixels (< & >) and /2 (top) --margin-top indent page pixels from top --cols height of centered page for text, in characters --rows width of centered page for text, in characters --outline plots the font in 4 directions (+1 to width) --outline-color font outline color (default DARKBLUE) 24bit decimal number, CYAN = 65535 24bit hex 0xRRGGBB number, GREEN = 0x00ff00 WHITE, RED, YELLOW, CYAN, BLUE, GREEN, DARKYELLOW DARKRED, DARKBLUE, LIGHTBLUE, DARKGREEN, LIGHTGREEN examples: sdlRead-1f --background nebula.jpg --outline --margin 100 readme.txt sdlRead-1f --imagefont 08x14-VGA_font.png --font-height 14 --margin 50 help.txt sdlRead-1f --imagefont ConsoleFont.bmp --font-width 6 --font-height 13 --font-color 1600000 --margin 10 --outline chasm.txt sdlRead-1f --imagefont techyfontbig.png --font-prop --font-key "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%%&\`'*#=[]\"" scroller.txt -1f--1fCopyright 2016 MiNTed Gamesone-file (1f) source information. usage: sdlRead-1f _option_ --src|--source output attached one-file (1f) source file --src-size size of appended source (in bytes) (%d) --src-type type of source appended (TXT/ZIP) (%s) .cppTo save one-file (1f) source to file use one of the following: sdlRead-1f --src > sdlRead-1f.cpp sdlRead-1f --src > sdlRead-1f`sdlRead-1f --src-type`To verify one-file (1f) source file size: sdlRead-1f --src-size (match this to the size in a directory listing)or use:NAME=sdlRead; if [ `ls -l $NAME-1f.cpp|cut -d \ -f 5` = `./$NAME-1f --src-size` ]; then echo Verified; else echo Failed; fi one-file (1f) options exit with status: 31 no error (0x1f) 32 an error occured (0x20)--source--src--src-type--src-size%d--debug--info--verbose-V--fullscreen--outline--wrap--nowrap--no-wrap--linenumbers--line-numbers--widtherror: page --width needs a number--heighterror: page --height needs a number--marginerror: page --margin needs a number--margin-top--margintop--backgrounderror: --background needs a filenameerror: --imagefont needs a filename--font-widtherror: --font-width needs a number--font-heighterror: --font-height needs a number--font-spaceerror: --font-space needs a number--font-keyerror: --font-key needs a character order listerror: --font-key is limited to 256 characters max.--font-256--font-prop--font-colorerror: --font-color needs a hex number--font-color-number--color-numbererror: --font-color-number needs a number <%d currently color numbers are: 0 WHITE 1 RED 2 YELLOW 3 GREEN 4 CYAN 5 BLUEBLACK (dark navy blue) 6 BLACK (for more use --color or --font-color)--background-color--bgcolorerror: page --background-color needs a hex numberinfo: you probably just forgot to choose a file to read(0h8H Ȳ(ظ \X$L (xX@@av o؄  (hTDooolȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍȍGCC: (Debian 4.6.3-14+rpi1) 4.6.3A.aeabi$6  ,.symtab.strtab.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.text.fini.rodata.ARM.extab.ARM.exidx.eh_frame.init_array.fini_array.jcr.dynamic.got.data.bss.comment.ARM.attributes44#PP 1pp$HDoN ؄V^oll vko `z DD  BTT h  ȍ 0JZZt$ptu  ((hK0"p/I` 4Pp؄l D T  ȍ  (JPMJJ̞JJPM؞؞JM MMč MMHJJM JlJMJ̢MJlMxJMJ8MPJpMJЧMJ MPJMJM(JMJXM`JMJMJHMPJ,MPP0JPMJPMXJ\MJMJMJMJMJM<J MhJMJMJM0JMJM JTM|JMJMJMJJM JJJJ7B JMOJeJtMJ@JJM JxMMJ7JJ   0(Mȍ J؍ M܍ FYfxu~H ,$<.@`MH `X(hx` \l(\&`M2:KH\mhp0`MPlP lL$6=Oar  5CP`MUh} `x +K]oPPpX@P X4,L0]<,k (D|8/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o$d$a/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.ocall_gmon_start/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crtn.osdlRead-1f.cpp_Z11sdlReadTextiii.constprop.5_GLOBAL__sub_I_sdlReadcrtstuff.c__JCR_LIST____do_global_dtors_auxcompleted.5637__do_global_dtors_aux_fini_array_entryframe_dummy__frame_dummy_init_array_entryelf-init.oSatexit.oS__FRAME_END____JCR_END____dso_handle_DYNAMIC__init_array_end__init_array_start_GLOBAL_OFFSET_TABLE__Znwj@@GLIBCXX_3.4SDL_FillRect_Z9loadImagePcSDL_QuitSDL_Flip_Z7cleanUpv_edatastrtol@@GLIBC_2.4free@@GLIBC_2.4fseek@@GLIBC_2.4data_start_Z12sdlRead_initv_IO_stdin_used_Z14loadBackgroundPcSDL_MapRGBmainexit@@GLIBC_2.4printf@@GLIBC_2.4__end___Z10flushInputv_Z10initSystemvputs@@GLIBC_2.4_Z8initVarsvSDL_PollEvent_Z12getUserInputv_Z11getLastPagev_Z14setVideoWindowv_IO_putc@@GLIBC_2.4putchar@@GLIBC_2.4atexitSDL_Delay_finiSDL_GetError_Z11getPrevPagev__bss_end__sdlReadfopen@@GLIBC_2.4_Z11getNextLinevabort@@GLIBC_2.4_Z12showTextPagevSDL_UpperBlit_Z11updateTitlePc_bss_end__SDL_Initstrcpy@@GLIBC_2.4_Z11setVideoMaxvSDL_FreeSurfaceSDL_SetVideoMode_Z15sdlReadFileOpenvSDL_SetPalettegraphicsSDL_WM_SetCaption_startSDL_DisplayFormatrewind@@GLIBC_2.4fread@@GLIBC_2.4_Z14sdlUpdateVideov_init_Jv_RegisterClasses__cxa_atexit@@GLIBC_2.4SDL_GetVideoInfo_Z16toggleFullScreenvSDL_SetColorKeybasename@@GLIBC_2.4_Z16sdlReadMultiLinePcii__aeabi_idivmod@@GCC_3.5__bss_start____data_start_endstrncat@@GLIBC_2.4SDL_CreateRGBSurfacefgets@@GLIBC_2.4__aeabi_idiv@@GCC_3.5__bss_startmalloc@@GLIBC_2.4strlen@@GLIBC_2.4__libc_csu_init_Z18setCustomFontColorP11SDL_Surfacejfclose@@GLIBC_2.4_Z9output_1fPc__aeabi_unwind_cpp_pr1@@GCC_3.5SDL_GetMouseStatestdout@@GLIBC_2.4_Z10clearLinesistrcmp@@GLIBC_2.4_Z11getNextPagev_Z12setFontColorP11SDL_Surfaceiii_Z11getTextFilevIMG_Load_Z16sdlReadFileClosev_Z15sdlReadShowPagev_Z11sdlReadTextiii__libc_csu_fini__aeabi_unwind_cpp_pr0@@GCC_3.5_Z11getPrevLinev_Z9checkKeysv__libc_start_main@@GLIBC_2.4__gmon_start___Z16sdlReadInitFontsv_Z10isOnScreeniiii_Z10version_1fv_Z8loadFontPc/* sdlRead-1f one-file (1f) text file reader (SDL 1.2) Copyright (C) 2016 MiNTed Games All Rights Reserved This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* one-file (-1f) compile g++ `sdl-config --cflags` -Wall -O3 -DVERSION=\"1.2.0\" `sdl-config --libs` -lSDL_image -o sdlRead-1f sdlRead-1f.cpp ; \ g++ `sdl-config --cflags` -Wall -O3 -DVERSION=\"1.2.0\" -DPRG_SIZE=`ls -l sdlRead-1f|cut -d \ -f 5` -DSRC_SIZE=`ls -l sdlRead-1f.cpp|cut -d \ -f 5` `sdl-config --libs` -lSDL_image -o sdlRead-1f sdlRead-1f.cpp ; \ cat sdlRead-1f.cpp >> sdlRead-1f */ /* one-file (-1f) requires libsdl1.2-dev libsdl-image-dev */ /* one-file (1f) headers */ #include #include #include #define LINUX 0 #if LINUX #include #include #include #include #endif #include "SDL/SDL.h" #include "SDL/SDL_image.h" /* one-file source appendage */ #define NO_SIZE 56789 //#define SRC_TYPE ".zip" // if its a ZIP appendage #define SRC_TYPE ".cpp" // if its a TEXT appendage, name the extention #ifndef PRG_SIZE //#define PRG_SIZE 41290 // last checked binary size was ... #define PRG_SIZE NO_SIZE // .. this should be close to actual #endif #ifndef SRC_SIZE // size of 1 text file or 1 zip file //#define SRC_SIZE 55038 // last checked source size was ... #define SRC_SIZE NO_SIZE // .. affects binary size if too small #endif const long offset_1f = PRG_SIZE; // this has never been accurate (EXT4) const long sizeOf_1f = SRC_SIZE; // we use this (-sizeOf_1f) as offset /* one-file (1f) start */ /* one-file (1f) defines */ #define SCREEN_WIDTH 1360 // these are actually dynamic #define SCREEN_HEIGHT 768 #define WINDOW_WIDTH 800 // size when not --fullscreen (ie. windowed) #define WINDOW_HEIGHT 600 #define MAX_TEXTSHAPES 70 #define MAX_FONTSHAPES 8 #define MAX_SHAPES 100 #define DEF_FONT "08x16-Atari_ST-ish.png" #define DEF_FONT_WIDTH 8 #define DEF_FONT_HEIGHT 16 #define DEF_FONT_SPACE DEF_FONT_WIDTH #define DEF_FONT_256 0 #define DEF_FONT_PROP 0 #define DEF_FONT_KEY "" #define DEF_FONT_OUTLINE 0 /* one-file (1f) enums */ // Font Colors enum { FONT_WHITE, FONT_RED, FONT_YELLOW, FONT_GREEN, FONT_CYAN, FONT_BLUE, // FONT_BLACK, // ten off black FONT_CUSTOM // user supplied color }; // matches MAX_FONTSHAPES #define FONT_OUTLINE FONT_BLACK // used to draw outline /* one-file (1f) structs */ typedef struct fontImage { char filename[1024]; // imagefont, any bitmap image, int width; // width of font int height; // height of font int space; // width of a SPACE char (defaults to width) Uint32 color; // default is white int chars; // (calculated) image width / font width = # of chars signed char is256; // image contains ALL 256 chars, otherwise 32>font<128 signed char isProp; // Proportional imagefont requires GuiChan type imagefont signed char inUse; // double-up of sdlRead.cur_font char key[256]; // if NOT is256 && does NOT start with chr(33) (!) } fontImage; typedef struct sdlReadFile { char filename[1024]; // name of file currently being read signed char isOpen; int chr; int line; int lines; char *buffer; FILE *fp; } sldReadFile; typedef struct sdlReadEngineVariables { signed char debug; SDL_Event event; signed char done; float ssx; float ssy; int cursor_x, cursor_y; signed char fullscreen; signed char useBackground; char background[1024]; int display_w; int display_h; int window_w; int window_h; int ox; int oy; int ow; int oh; fontImage fontimage[MAX_FONTSHAPES]; int cur_font; int font_width; int font_height; signed char useOutline; int outlineColorNumber; signed char useFontColorNumber; int fontColorNumber; signed char useFontColor; Uint32 color; signed char useBgColor; Uint32 bgcolor; int next; int current; int playlist; char playList[50][1024]; sldReadFile file; signed char retChar; int line; char lines[256][256]; int page_w; int page_h; int page_m; int page_t; int page_lines; int prev_top; int top; int bottom; int cols; int rows; signed char wrap; signed char linenumbers; signed char info; // This really only applies to Linux users. char userHomeDirectory[1024]; char keyState[350]; signed char section; }; sdlReadEngineVariables sdlRead; typedef struct bRect { int x, y, w, h; bRect *next; } bRect; typedef struct textObject { SDL_Surface *image; unsigned char life; float x, y; signed char fontColor; char text[255]; }; /* one-file (1f) classes */ class sdlReadGraphics { public: Uint32 red; Uint32 darkRed; Uint32 yellow; Uint32 darkYellow; Uint32 green; Uint32 darkGreen; Uint32 blue; Uint32 darkBlue; Uint32 darkerBlue; Uint32 black; Uint32 white; Uint32 lightGrey; Uint32 darkGrey; SDL_Surface *screen, *background; SDL_Surface *text_page; SDL_Surface *shape[MAX_SHAPES]; SDL_Surface *fontShape[MAX_FONTSHAPES]; bRect *bufferHead; bRect *bufferTail; textObject textShape[MAX_TEXTSHAPES]; SDL_Rect blitRect; SDL_Rect scale_rect; SDL_Surface *messageBox; sdlReadGraphics() { bufferHead = new bRect; bufferHead->next = NULL; bufferTail = bufferHead; for (int i = 0 ; i < MAX_SHAPES ; i++) shape[i] = NULL; for (int i = 0 ; i < MAX_SHAPES ; i++) fontShape[i] = NULL; for (int i = 0 ; i < MAX_TEXTSHAPES ; i++) textShape[i].image = NULL; messageBox = NULL; background = NULL; text_page = NULL; } SDL_Surface *setTransparent(SDL_Surface *sprite) { SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(sprite->format, 0, 0, 0)); return sprite; } SDL_Surface *setFontTransparent(SDL_Surface *sprite, Uint32 color) { SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL), color); return sprite; } void addBuffer(int x, int y, int w, int h) { bRect *rect = new bRect; rect->next = NULL; rect->x = x; rect->y = y; rect->w = w; rect->h = h; bufferTail->next = rect; bufferTail = rect; } void blit(SDL_Surface *image, int x, int y, SDL_Surface *dest) { // Set up a rectangle to draw to blitRect.x = x; blitRect.y = y; blitRect.w = image->w; blitRect.h = image->h; //printf("graphics.image->w=%d graphics.image->h=%d\n", image->w, image->h); /* Blit onto the screen surface */ if(SDL_BlitSurface(image, NULL, dest, &blitRect) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); } //printf("graphics.dest->w=%d graphics.dest->h=%d\n", dest->w, dest->h); // addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h); //printf("blitRect.x=%d blitRect.y=%d blitRect.w=%d blitRect.h=%d \n", blitRect.x, blitRect.y, blitRect.w, blitRect.h); } void blit(SDL_Surface *image, int x, int y) { blit(image, x, y, screen); } void blitText(int i) { blit(textShape[i].image, (int)textShape[i].x, (int)textShape[i].y, screen); } void flushBuffer() { bRect *prevRect = bufferHead; bRect *rect = bufferHead; bufferTail = bufferHead; while (rect->next != NULL) { rect = rect->next; prevRect->next = rect->next; delete rect; rect = prevRect; } bufferHead->next = NULL; } void unBuffer() { bRect *prevRect = bufferHead; bRect *rect = bufferHead; bufferTail = bufferHead; while (rect->next != NULL) { rect = rect->next; blitRect.x = rect->x; blitRect.y = rect->y; blitRect.w = rect->w; blitRect.h = rect->h; if (SDL_BlitSurface(background, &blitRect, screen, &blitRect) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); } prevRect->next = rect->next; delete rect; rect = prevRect; } bufferHead->next = NULL; } /* In 16 bit mode this is slow. VERY slow. Don't write directly to a surface that constantly needs updating (eg - the main game screen) */ int renderString(char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest) { signed char doLF; SDL_Rect area; area.x = x; area.y = y; area.w = sdlRead.fontimage[sdlRead.cur_font].width; area.h = sdlRead.fontimage[sdlRead.cur_font].height; SDL_Rect letter; letter.y = 0; letter.w = sdlRead.fontimage[sdlRead.cur_font].width; letter.h = sdlRead.fontimage[sdlRead.cur_font].height; while (*in != '\0') { doLF = 0; if (sdlRead.fontimage[sdlRead.cur_font].is256) { letter.x = *in; letter.x *= sdlRead.fontimage[sdlRead.cur_font].width; /* Blit onto the screen surface */ if(SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); } }else{ if (*in > 32) { letter.x = (*in - 33); letter.x *= sdlRead.fontimage[sdlRead.cur_font].width; /* Blit onto the screen surface */ if(SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); } } } if (*in == 13 || *in == 10) doLF = 1; if(doLF) { sdlRead.file.line++; area.y += sdlRead.fontimage[sdlRead.cur_font].height; if (sdlRead.useOutline) area.y +=2; area.x = x; doLF = 0; }else{ area.x += sdlRead.fontimage[sdlRead.cur_font].width; if (sdlRead.useOutline) area.x++; } if (wrap) { if ((area.x > (dest->w - 70)) && (*in == 32)) { area.y += sdlRead.fontimage[sdlRead.cur_font].height; if (sdlRead.useOutline) area.y +=2; area.x = x; } } /* if ((area.x+sdlRead.fontimage[sdlRead.cur_font].width) >= dest->w) { sdlRead.file.line++; area.y += sdlRead.fontimage[sdlRead.cur_font].height; if (sdlRead.useOutline) area.y +=2; area.x = x; } if ((area.y+sdlRead.fontimage[sdlRead.cur_font].height) >= dest->h) break; */ *in++; } return area.y; } int drawString(char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest) { if(sdlRead.useOutline) { renderString(in, x, y - 1, FONT_OUTLINE, wrap, dest); renderString(in, x, y + 1, FONT_OUTLINE, wrap, dest); renderString(in, x, y + 2, FONT_OUTLINE, wrap, dest); renderString(in, x - 1, y, FONT_OUTLINE, wrap, dest); renderString(in, x - 2, y, FONT_OUTLINE, wrap, dest); renderString(in, x + 1, y, FONT_OUTLINE, wrap, dest); } return renderString(in, x, y, fontColor, wrap, dest); } int drawString(char *in, int x, int y, int fontColor, SDL_Surface *dest) { if (x == -1) { x = (dest->w - (strlen(in) * sdlRead.font_width)) / 2; } return drawString(in, x, y, fontColor, 0, dest); } int drawString(char *in, int x, int y, int fontColor) { if (x == -1) { if(sdlRead.useOutline) x = (sdlRead.page_w - (strlen(in) * sdlRead.fontimage[sdlRead.cur_font].width) + 1) / 2; else x = (sdlRead.page_w - (strlen(in) * sdlRead.fontimage[sdlRead.cur_font].width)) / 2; } return drawString(in, x, y, fontColor, 0, screen); } /* Finds the location of the requested color within the palette and returns it's number. This colors are used for drawing rectangles, circle, etc in the correct colors. */ void setColorIndexes() { red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00); darkRed = SDL_MapRGB(screen->format, 0x66, 0x00, 0x00); yellow = SDL_MapRGB(screen->format, 0xff, 0xff, 0x00); darkYellow = SDL_MapRGB(screen->format, 0x66, 0x66, 0x00); green = SDL_MapRGB(screen->format, 0x00, 0xff, 0x00); darkGreen = SDL_MapRGB(screen->format, 0x00, 0x66, 0x00); blue = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff); darkBlue = SDL_MapRGB(screen->format, 0x00, 0x00, 0x99); darkerBlue = SDL_MapRGB(screen->format, 0x00, 0x00, 0x44); black = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); white = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff); lightGrey = SDL_MapRGB(screen->format, 0xcc, 0xcc, 0xcc); darkGrey = SDL_MapRGB(screen->format, 0x99, 0x99, 0x99); } /* Draws the background surface that has been loaded */ void drawBackGround() { blit(background, 0, 0, screen); } void drawTextPage(int px, int py) { if (sdlRead.debug) printf("info: updating text_page, %dx%d at %d,%d\n", text_page->w, text_page->h, px, py); blit(text_page, px, py, screen); } void clearScreen(Uint32 color) { SDL_FillRect(screen, NULL, color); } void updateScreen() { SDL_Flip(screen); // Give the audio (and possibly the X server) time to work SDL_Delay(1); } /* * get the pixel at (x, y) to the given value */ /* Uint32 getpixel(SDL_Surface *surface, int x, int y) { // Uint32 pixel; unsigned char pixel[4]; int bpp = surface->format->BytesPerPixel; // Here p is the address to the pixel we want to set Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { switch(bpp) { case 1: pixel[0] = p; break; case 2: pixel[0] = (p[0] >> 8) & 0xff; pixel[1] = p[1] & 0xff; break; case 3: pixel[0] = (p[0] >> 16) & 0xff; pixel[1] = (p[1] >> 8) & 0xff; pixel[2] = p[2] & 0xff; break; case 4: pixel = p; break; } }else{ switch(bpp) { case 1: pixel[0] = p; break; case 2: pixel[0] = p[0] & 0xff; pixel[1] = (p[1] >> 8) & 0xff; break; case 3: pixel[0] = p[0] & 0xff; pixel[1] = (p[1] >> 8) & 0xff; pixel[2] = (p[2] >> 16) & 0xff; break; case 4: pixel = p; break; } } return(pixel); } */ /* * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! */ void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } } void drawLine(SDL_Surface *dest, int x1, int y1, int x2, int y2, int col) { int counter = 0; if ( SDL_MUSTLOCK(dest) ) { if ( SDL_LockSurface(dest) < 0 ) { printf("Can't lock screen: %s\n", SDL_GetError()); } } while(1) { putpixel(dest, x1, y1, col); if (x1 > x2) x1--; if (x1 < x2) x1++; if (y1 > y2) y1--; if (y1 < y2) y1++; if ((x1 == x2) && (y1 == y2)) {break;} if (counter == 1000) {printf("Loop Error!\n"); break;} counter++; } if ( SDL_MUSTLOCK(dest) ) { SDL_UnlockSurface(dest); } } void drawLine(int x1, int y1, int x2, int y2, int col) { drawLine(screen, x1, y1, x2, y2, col); } /* A quick(?) circle draw function. This code was posted to the SDL mailing list... I didn't write it myself. */ void circle(int xc, int yc, int R, SDL_Surface *PIX, int col) { int x = 0, xx = 0; int y = R, yy = R+R; int p = 1-R; putpixel(PIX, xc, yc - y, col); putpixel(PIX, xc, yc + y, col); putpixel(PIX, xc - y, yc, col); putpixel(PIX, xc + y, yc, col); while(x < y) { xx += 2; ++x; if (p >= 0) { yy -= 2; --y; p -= yy; } p += xx + 1; putpixel(PIX, xc - x, yc - y, col); putpixel(PIX, xc + x, yc - y, col); putpixel(PIX, xc - x, yc + y, col); putpixel(PIX, xc + x, yc + y, col); putpixel(PIX, xc - y, yc - x, col); putpixel(PIX, xc + y, yc - x, col); putpixel(PIX, xc - y, yc + x, col); putpixel(PIX, xc + y, yc + x, col); } if ((x = y)) { putpixel(PIX, xc - x, yc - y, col); putpixel(PIX, xc + x, yc - y, col); putpixel(PIX, xc - x, yc + y, col); putpixel(PIX, xc + x, yc + y, col); } } void blevelRect(SDL_Surface *dest, int x, int y, int w, int h, Uint8 red, Uint8 green, Uint8 blue) { SDL_Rect r = {x, y, w, h}; SDL_FillRect(dest, &r, SDL_MapRGB(screen->format, red, green, blue)); drawLine(dest, x, y, x + w, y, SDL_MapRGB(screen->format, 255, 255, 255)); drawLine(dest, x, y, x, y + h, SDL_MapRGB(screen->format, 255, 255, 255)); drawLine(dest, x, y + h, x + w, y + h, SDL_MapRGB(screen->format, 128, 128, 128)); drawLine(dest, x + w, y + 1, x + w, y + h, SDL_MapRGB(screen->format, 128, 128, 128)); } void blevelRect(int x, int y, int w, int h, Uint8 red, Uint8 green, Uint8 blue) { blevelRect(screen, x, y, w, h, red, green, blue); } SDL_Surface *createSurface(int width, int height) { SDL_Surface *surface, *newImage; Uint32 rmask, gmask, bmask, amask; /* SDL interprets each pixel as a 32-bit number, so our masks must depend on the endianness (byte order) of the machine */ #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask); if (surface == NULL) { printf("CreateRGBSurface failed: %s\n", SDL_GetError()); } newImage = SDL_DisplayFormat(surface); SDL_FreeSurface(surface); return newImage; } SDL_Surface *textSurface(char *inString, int color) { SDL_Surface *surface = createSurface(strlen(inString) * 9, 16); drawString(inString, 1, 1, color, surface); return setTransparent(surface); } void textSurface(int index, char *inString, int x, int y, int fontColor) { strcpy(textShape[index].text, inString); textShape[index].x = x; textShape[index].y = y; textShape[index].fontColor = fontColor; if (textShape[index].image != NULL) { SDL_FreeSurface(textShape[index].image); } textShape[index].image = textSurface(inString, fontColor); if (x == -1) textShape[index].x = (800 - textShape[index].image->w) / 2; } SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue) { SDL_Surface *surface = createSurface(width, height); SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green, blue)); SDL_SetAlpha(surface, SDL_SRCALPHA|SDL_RLEACCEL, 128); return surface; } SDL_Surface *transparentRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue) { SDL_Surface *surface = createSurface(width, height); SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green, blue)); SDL_SetColorKey(surface, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(surface->format, red, green, blue)); // SDL_SetColorKey(surface, (SDL_SRCCOLORKEY|SDL_RLEACCEL), sge_GetPixel(bitmap,0,0)); return surface; } void createMessageBox(SDL_Surface *face, char *message, signed char transparent) { if (messageBox != NULL) { SDL_FreeSurface(messageBox); messageBox = NULL; } if (transparent) messageBox = alphaRect(550, 60, 0x00, 0x00, 0x00); else messageBox = createSurface(550, 60); signed char x = 60; if (face != NULL) { blevelRect(messageBox, 0, 0, messageBox->w - 1, messageBox->h - 1, 0x00, 0x00, 0xaa); blit(face, 5, 5, messageBox); } else { blevelRect(messageBox, 0, 0, messageBox->w - 1, messageBox->h - 1, 0x00, 0x00, 0x00); x = 10; } drawString(message, x, 5, FONT_WHITE, 1, messageBox); } void freeGraphics() { for (int i = 0 ; i < MAX_SHAPES ; i++) { if (shape[i] != NULL) { SDL_FreeSurface(shape[i]); shape[i] = NULL; } } for (int i = 0 ; i < MAX_FONTSHAPES ; i++) { if (fontShape[i] != NULL) { SDL_FreeSurface(fontShape[i]); fontShape[i] = NULL; } } for (int i = 0 ; i < MAX_TEXTSHAPES ; i++) { if (textShape[i].image != NULL) { SDL_FreeSurface(textShape[i].image); textShape[i].image = NULL; } } if (messageBox != NULL) { SDL_FreeSurface(messageBox); messageBox = NULL; } if (background != NULL) { SDL_FreeSurface(background); background = NULL; } if (text_page != NULL) { SDL_FreeSurface(text_page); text_page = NULL; } } }; sdlReadGraphics graphics; /* one-file (1f) functions */ /* key handling */ void flushInput() { for (int i = 0 ; i < 350 ; i++) sdlRead.keyState[i] = 0; while (SDL_PollEvent(&sdlRead.event)){} } void getUserInput() { // Get the current mouse position int x, y; SDL_GetMouseState(&x, &y); sdlRead.cursor_x = x; sdlRead.cursor_y = y; if (SDL_PollEvent(&sdlRead.event)) { switch (sdlRead.event.type) { case SDL_QUIT: exit(0); break; case SDL_MOUSEBUTTONDOWN: if (sdlRead.event.button.button == SDL_BUTTON_LEFT) sdlRead.keyState[SDLK_SPACE] = 1; if (sdlRead.event.button.button == SDL_BUTTON_RIGHT) sdlRead.keyState[SDLK_ESCAPE] = 1; break; case SDL_KEYDOWN: sdlRead.keyState[sdlRead.event.key.keysym.sym] = 1; break; case SDL_KEYUP: sdlRead.keyState[sdlRead.event.key.keysym.sym] = 0; break; default: break; } } } /* This bit is just for Linux users. It attempts to get the user's home directory, then creates the .parallelrealities and .parallelrealities/starfighter directories so that saves and temporary data files can be written there. Good, eh? :) */ #if LINUX void setupUserHomeDirectory() { char dir[4096]; char *userHome; char *name = getlogin(); passwd *pass; if (name != NULL) pass = getpwnam(name); else pass = getpwuid(geteuid()); if (pass == NULL) { printf("Couldn't determine the user home directory. Exitting.\n"); exit(1); } userHome = pass->pw_dir; strcpy(dir, ""); sprintf(dir, "%s/.1f", userHome); if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) printf("error: cant create dir '%s'", dir); sprintf(dir, "%s/.1f/sdlRead", userHome); if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) printf("error: cant create dir '%s'", dir); sprintf(sdlRead.userHomeDirectory, "%s/.1f/sdlRead/", userHome); } #endif /* image handling */ SDL_Surface *loadImage(char *filename) { SDL_Surface *image, *newImage; image = IMG_Load(filename); if (image == NULL) { if (sdlRead.info || sdlRead.debug) printf("image: %s\n", SDL_GetError()); return NULL; } newImage = SDL_DisplayFormat(image); if ( newImage ) { SDL_FreeSurface(image); } else { // This happens when we are loading the window icon image newImage = image; } return graphics.setTransparent(newImage); } void loadBackground(char *filename) { if (graphics.background != NULL) { SDL_FreeSurface(graphics.background); graphics.background = NULL; } graphics.background = loadImage(filename); if (graphics.background == NULL) { if (sdlRead.info || sdlRead.debug) printf("background: %s\n", SDL_GetError()); }else SDL_SetColorKey(graphics.background, 0, 0); if (sdlRead.info || sdlRead.debug) printf("background: loaded '%s'\n", filename); // graphics.drawBackGround(); } void setFontColor(SDL_Surface *image, int red, int green, int blue) { SDL_Color colors[256]; colors[0].r = 0; colors[0].g = 0; colors[0].b = 0; for (int i = 1 ; i < 256 ; i++) { colors[i].r = red; colors[i].g = green; colors[i].b = blue; } SDL_SetPalette(image, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); } void setCustomFontColor(SDL_Surface *image, Uint32 color) { SDL_Color colors[256]; int red, green, blue; red = (int) (color >> 16) & 0xff; green = (int) (color >> 8) & 0xff; blue = (int) color & 0xff; colors[0].r = 0; colors[0].g = 0; colors[0].b = 0; for (int i = 1 ; i < 256 ; i++) { colors[i].r = red; colors[i].g = green; colors[i].b = blue; } SDL_SetPalette(image, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); } /* Custom loading to alter the font color before doing all other things */ void loadFont(char *filename) { SDL_Surface *image, *newImage; for (int i = 0 ; i < MAX_FONTSHAPES ; i++) { image = IMG_Load(filename); if (image == NULL) { if (sdlRead.info || sdlRead.debug) printf("error: cant load font '%s'\n", SDL_GetError()); loadFont(DEF_FONT); i = MAX_FONTSHAPES; continue; } switch(i) { case 0: setFontColor(image, 255, 255, 255); // FONT_WHITE break; case 1: setFontColor(image, 255, 0, 0); // FONT_RED break; case 2: setFontColor(image, 255, 255, 0); // FONT_YELLOW break; case 3: setFontColor(image, 0, 255, 0); // FONT_GREEN break; case 4: setFontColor(image, 0, 255, 255); // FONT_CYAN break; case 5: setFontColor(image, 0, 0, 255); // FONT_BLUE break; case 6: setFontColor(image, 10, 10, 10); // FONT_BLACK break; case 7: setCustomFontColor(image, sdlRead.color); break; } newImage = SDL_DisplayFormat(image); if (graphics.fontShape[i] != NULL) SDL_FreeSurface(graphics.fontShape[i]); graphics.fontShape[i] = graphics.setTransparent(newImage); SDL_FreeSurface(image); } } int isOnScreen(int x, int y, int w, int h) { if ((x + w > 0) && (x < 800) && (y + h > 0) && (y < 600)) return 1; return 0; } /* initialization */ void sdlRead_init() { sdlRead.debug = 0; sdlRead.fullscreen = 0; sdlRead.useBackground = 0; sdlRead.display_w = SCREEN_WIDTH; // default display size sdlRead.display_h = SCREEN_HEIGHT; sdlRead.window_w = WINDOW_WIDTH; // default window size sdlRead.window_h = WINDOW_HEIGHT; sdlRead.ox = 0; sdlRead.oy = 0; sdlRead.ow = 0; sdlRead.oh = 0; sdlRead.ssx = 0; sdlRead.ssy = 0; for (int i = 0 ; i < 350 ; i++) sdlRead.keyState[i] = 0; strcpy(sdlRead.fontimage[0].filename, DEF_FONT); sdlRead.fontimage[0].width = DEF_FONT_WIDTH; sdlRead.fontimage[0].height = DEF_FONT_HEIGHT; sdlRead.fontimage[0].space = DEF_FONT_SPACE; sdlRead.fontimage[0].color = 0; sdlRead.fontimage[0].is256 = DEF_FONT_256; sdlRead.fontimage[0].isProp = DEF_FONT_PROP; sdlRead.fontimage[0].inUse = 1; sdlRead.cur_font = 0; sdlRead.font_width = 0; sdlRead.font_height = 0; sdlRead.useOutline = DEF_FONT_OUTLINE; sdlRead.outlineColorNumber = 0; sdlRead.fontColorNumber = FONT_WHITE; sdlRead.useFontColor = 0; sdlRead.color = 0; sdlRead.useBgColor = 0; sdlRead.bgcolor = 0; sdlRead.next = 0; sdlRead.current = 0; sdlRead.playlist = 0; strcpy(sdlRead.file.filename, ""); sdlRead.file.isOpen = 0; sdlRead.file.chr = 0; sdlRead.file.line = 0; sdlRead.file.lines = 0; sdlRead.file.buffer = NULL; sdlRead.file.fp = NULL; sdlRead.cols = 0; sdlRead.rows = 0; sdlRead.page_w = 0; sdlRead.page_h = 0; sdlRead.page_m = 0; sdlRead.page_t = 0; sdlRead.page_lines = 0; sdlRead.line = 0; sdlRead.retChar = 0; sdlRead.prev_top = 0; sdlRead.top = 0; sdlRead.bottom = 0; sdlRead.wrap = 0; sdlRead.linenumbers = 0; sdlRead.info = 0; sdlRead.section = 0; } void setVideoMax() { graphics.screen = SDL_SetVideoMode(sdlRead.display_w, sdlRead.display_h, 16, SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN); sdlRead.fullscreen = 1; if (sdlRead.info || sdlRead.debug) printf("info: set %dx%dx16 video mode\n", sdlRead.display_w, sdlRead.display_h); } void setVideoWindow() { graphics.screen = SDL_SetVideoMode(sdlRead.window_w, sdlRead.window_h, 0, SDL_HWSURFACE|SDL_HWPALETTE); sdlRead.fullscreen = 0; if (sdlRead.info || sdlRead.debug) printf("info: set %dx%d window mode\n", sdlRead.window_w, sdlRead.window_h); } void initSystem() { const SDL_VideoInfo* videoInfo; /* Initialize the SDL library */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } if (sdlRead.debug) printf("info: probing video for W x H\n"); videoInfo = SDL_GetVideoInfo(); sdlRead.display_w = videoInfo->current_w; sdlRead.display_h = videoInfo->current_h; SDL_WM_SetCaption("sdlRead", "sdlRead"); // SDL_WM_SetIcon(loadImage("gfx/alienDevice.png"), NULL); if (sdlRead.fullscreen) setVideoMax(); else setVideoWindow(); if (graphics.screen == NULL) { printf("error: Couldn't set video mode: %s\n", SDL_GetError()); exit(1); } graphics.setColorIndexes(); sdlRead.file.buffer = (char*) malloc(4096); } void clearLines(int from) { int rows; rows = sdlRead.rows; if (from == -1) { from = 0; rows = 256; } for (int i=from; i < rows; i++) strcpy(sdlRead.lines[i],""); } void initVars() { if (sdlRead.debug) printf("info: setting system variables\n"); if (sdlRead.useFontColor) sdlRead.fontimage[0].color = sdlRead.color; else sdlRead.fontimage[0].color = SDL_MapRGB(graphics.screen->format, 0xff, 0xff, 0xff); if (sdlRead.useBgColor) sdlRead.fontimage[0].color = sdlRead.bgcolor; else sdlRead.fontimage[0].color = 0; if (sdlRead.page_w < 0) sdlRead.page_w = 0; if (sdlRead.page_h < 0) sdlRead.page_h = 0; if (sdlRead.page_m < 0) sdlRead.page_m = 0; if (sdlRead.page_t < 0) sdlRead.page_t = 0; if (sdlRead.page_m > 0 && sdlRead.page_t == 0) sdlRead.page_t = (int) sdlRead.page_m; sdlRead.font_width = sdlRead.fontimage[sdlRead.cur_font].width; sdlRead.font_height = sdlRead.fontimage[sdlRead.cur_font].height; if (sdlRead.useOutline) { sdlRead.font_width += 1; sdlRead.font_height += 2; } if (sdlRead.cols != 0 && sdlRead.rows == 0) { sdlRead.rows = (int) (sdlRead.display_h / sdlRead.font_height); } if (sdlRead.cols == 0 && sdlRead.rows != 0) { sdlRead.cols = (int) (sdlRead.display_w / sdlRead.font_width); } if (sdlRead.cols != 0 && sdlRead.rows != 0) { sdlRead.page_w = ( sdlRead.font_width * sdlRead.cols ) + sdlRead.page_m; sdlRead.page_h = ( sdlRead.font_height * sdlRead.rows ) + sdlRead.page_m; }else{ if (sdlRead.fullscreen) { sdlRead.page_w = sdlRead.display_w - (sdlRead.page_m * 2); sdlRead.page_h = sdlRead.display_h + sdlRead.page_t; sdlRead.cols = (int) (sdlRead.page_w / sdlRead.font_width); sdlRead.rows = (int) (sdlRead.page_h / sdlRead.font_height); }else{ sdlRead.page_w = sdlRead.window_w - (sdlRead.page_m * 2); sdlRead.page_h = sdlRead.window_h + sdlRead.page_t; sdlRead.cols = (int) (sdlRead.page_w / sdlRead.font_width); sdlRead.rows = (int) (sdlRead.page_h / sdlRead.font_height); } } } void sdlReadInitFonts() { if (sdlRead.debug) printf("info: buffers cols=%d rows=%d\n", sdlRead.cols, sdlRead.rows); clearLines(0); sdlRead.ox = sdlRead.page_m; sdlRead.oy = (int) (sdlRead.page_m / 2); if (sdlRead.debug) printf("info: loading font '%s'\n", sdlRead.fontimage[sdlRead.cur_font].filename); loadFont(sdlRead.fontimage[sdlRead.cur_font].filename); sdlRead.fontimage[sdlRead.cur_font].chars = (int) (graphics.fontShape[0]->w / sdlRead.fontimage[sdlRead.cur_font].width); if (sdlRead.debug) printf("info: %d chars in font\n", sdlRead.fontimage[sdlRead.cur_font].chars); } /* file reader */ int sdlReadFileClose() { if (sdlRead.file.fp != NULL) fclose(sdlRead.file.fp); sdlRead.file.fp = NULL; sdlRead.file.isOpen = 0; return 1; } void cleanUp() { if (sdlRead.info || sdlRead.debug) printf("info: Cleaning Up...\n"); graphics.freeGraphics(); if (sdlRead.debug) printf("close: Free Images\n"); if (sdlRead.debug) printf("close: Free Buffers\n"); clearLines(-1); if (sdlRead.file.buffer != NULL) free(sdlRead.file.buffer); sdlRead.file.buffer = NULL; sdlReadFileClose(); if (sdlRead.debug) printf("close: Close File\n"); SDL_Quit(); if (sdlRead.info || sdlRead.debug) printf("info: ...Done Cleaning Up\nThank You for using sdlRead\n"); } int sdlReadFileOpen() { if (sdlRead.debug) printf("info: opening file\n"); sdlRead.file.fp = fopen(sdlRead.playList[sdlRead.next], "rb"); if (sdlRead.file.fp == NULL) { if (sdlRead.info || sdlRead.debug) printf("error: cant open %s\n", sdlRead.playList[sdlRead.next]); return 0; } if (sdlRead.debug) printf("info: file open '%s'\n", sdlRead.playList[sdlRead.next]); sdlRead.file.isOpen = 1; sdlRead.file.chr = 0; sdlRead.file.line = 0; return 1; } int sdlReadMultiLine(char *in, int chars, int line) { int lines, count, remainder; lines = 0; count = (int) strlen(in) / chars; remainder = (int) strlen(in) % chars; while(lines < count) { strncat(sdlRead.lines[line+lines],in,chars); lines++; for (int i=0; i < chars; i++) *in++; } if (remainder > 0) { strncat(sdlRead.lines[line+lines],in,chars); } return lines; } int sdlReadText(int from_line, int to_line, int file_line) { int lines; signed char readDone; if (sdlRead.file.fp == NULL) sdlReadFileOpen(); sdlRead.file.line = file_line; rewind(sdlRead.file.fp); for (int i=0; i4095\n", sdlRead.file.line); if (strlen(sdlRead.file.buffer) >= 256) if (sdlRead.debug) printf("read: long page line %d >256\n", sdlRead.file.line); if ((int)strlen(sdlRead.file.buffer) > sdlRead.cols && sdlRead.wrap) { lines = sdlReadMultiLine(sdlRead.file.buffer, sdlRead.cols, i); sdlRead.page_lines += lines + 1; i += lines; } else { strcpy(sdlRead.lines[i],sdlRead.file.buffer); sdlRead.page_lines++; } sdlRead.line++; if (readDone) i = sdlRead.rows; } sdlReadFileClose(); if (sdlRead.debug) printf("read: %d lines read\n", sdlRead.line); return readDone; } void sdlReadShowPage() { int px, py, ox, oy; if (graphics.text_page != NULL) SDL_FreeSurface(graphics.text_page); graphics.text_page = graphics.transparentRect(sdlRead.page_w+10, sdlRead.page_h, 0, 0, 0); ox = 0; oy = 0; if (sdlRead.useOutline) { ox = 1; oy = 2; } px = sdlRead.page_m + oy; for (int i=0; i < sdlRead.rows; i++) { py = (i * sdlRead.font_height)+oy; graphics.drawString(sdlRead.lines[i], px, py, sdlRead.fontColorNumber, 0, graphics.text_page); } } void sdlUpdateVideo() { if (sdlRead.debug) printf("info: updating video screen\n"); graphics.clearScreen(sdlRead.bgcolor); if (sdlRead.debug) printf("info: clear screen\n"); if (graphics.background != NULL) graphics.drawBackGround(); if (sdlRead.debug && graphics.background != NULL) printf("info: background updated\n"); if (graphics.text_page != NULL) graphics.drawTextPage(sdlRead.ox, sdlRead.oy); if (sdlRead.debug && graphics.text_page != NULL) printf("info: page updated\n"); graphics.updateScreen(); if (sdlRead.debug) printf("info: video screen updated\n"); } void toggleFullScreen() { if(sdlRead.fullscreen) { setVideoWindow(); }else{ setVideoMax(); } sdlUpdateVideo(); } void updateTitle(char *file) { char title[50]; sprintf(title,"%s", basename(file)); SDL_WM_SetCaption(title, "sdlRead"); } /* slideshow states */ int getTextFile() //#0 { int isEOF; if (sdlRead.next == sdlRead.playlist) exit(0); if (!sdlReadFileOpen()) return 9; sdlRead.current = sdlRead.next; clearLines(0); isEOF = 0; sdlRead.top = 0; sdlRead.bottom = 0; sdlRead.file.lines = 0; while(true) { if(!fgets(sdlRead.file.buffer, 4096, sdlRead.file.fp)) isEOF = 1; if (strlen(sdlRead.file.buffer) == 0) break; sdlRead.file.lines++; if (isEOF) break; } if (sdlRead.file.lines == 0) { if (sdlRead.info || sdlRead.debug) printf("info: file has 0 lines\n"); strcpy(sdlRead.lines[0], ""); }else if (sdlRead.info || sdlRead.debug) printf("info: file has %d lines\n", sdlRead.file.lines); if (sdlReadText(0, sdlRead.rows, 0)) { if (sdlRead.debug) printf("open: EOF reached\n"); strcpy(sdlRead.lines[sdlRead.page_lines], ""); } sdlRead.bottom = sdlRead.line; if (sdlRead.page_lines < sdlRead.rows) clearLines(sdlRead.page_lines); return 2; } int checkKeys() //#1 { SDL_Delay(1); getUserInput(); if (sdlRead.keyState[SDLK_ESCAPE] || sdlRead.keyState[SDLK_q]) { sdlRead.keyState[SDLK_ESCAPE] = 0; sdlRead.keyState[SDLK_q] = 0; return 10; } if (sdlRead.keyState[SDLK_F11]) { sdlRead.keyState[SDLK_F11] = 0; toggleFullScreen(); } if (sdlRead.keyState[SDLK_SPACE]) { sdlRead.keyState[SDLK_SPACE] = 0; return 9; } if (sdlRead.keyState[SDLK_RETURN] || sdlRead.keyState[SDLK_KP_ENTER]) { sdlRead.keyState[SDLK_RETURN] = 0; sdlRead.keyState[SDLK_KP_ENTER] = 0; return 9; } if (sdlRead.keyState[SDLK_BACKSPACE]) { sdlRead.keyState[SDLK_BACKSPACE] = 0; if (sdlRead.next == 0) return 1; --sdlRead.next; return 0; } if (sdlRead.keyState[SDLK_HOME]) { sdlRead.keyState[SDLK_HOME] = 0; if (sdlRead.top == 0) return 1; sdlRead.top = 0; sdlRead.bottom = 0; sdlReadFileClose(); if (sdlRead.debug) printf("info: do \n"); return 0; } if (sdlRead.keyState[SDLK_END]) { sdlRead.keyState[SDLK_END] = 0; if (sdlRead.debug) printf("info: do \n"); return 8; } if (sdlRead.keyState[SDLK_UP]) { sdlRead.keyState[SDLK_UP] = 0; if (sdlRead.top == 0) return 1; if (sdlRead.debug) printf("info: do Previous Line\n"); return 6; } if (sdlRead.keyState[SDLK_PAGEUP]) { sdlRead.keyState[SDLK_PAGEUP] = 0; if (sdlRead.top == 0) return 1; if (sdlRead.debug) printf("info: do Previous Page\n"); return 7; } if (sdlRead.keyState[SDLK_DOWN]) { sdlRead.keyState[SDLK_DOWN] = 0; return 5; } if (sdlRead.keyState[SDLK_PAGEDOWN]) { sdlRead.keyState[SDLK_PAGEDOWN] = 0; return 4; } if (sdlRead.keyState[SDLK_KP_MINUS]) { sdlRead.keyState[SDLK_KP_MINUS] = 0; sdlRead.cur_font--; if(sdlRead.cur_font < 0) sdlRead.cur_font = 0; return 2; } if (sdlRead.keyState[SDLK_KP_PLUS]) { sdlRead.keyState[SDLK_KP_PLUS] = 0; sdlRead.cur_font++; if(sdlRead.cur_font > MAX_FONTSHAPES) sdlRead.cur_font = MAX_FONTSHAPES; return 2; } SDL_Delay(1); return 1; } int showTextPage() //#2 { if (sdlRead.debug) printf("info: showing text page\n"); updateTitle(sdlRead.playList[sdlRead.current]); sdlReadShowPage(); sdlUpdateVideo(); return 1; } int getNextPage() //#4 { // strcpy(sdlRead.lines[0], sdlRead.lines[sdlRead.rows-1]); clearLines(0); sdlRead.prev_top = sdlRead.top; sdlRead.top = sdlRead.bottom; if (sdlRead.debug) printf("nextpage: page top set to file line %d\n", sdlRead.top); // if (sdlReadText(1, sdlRead.rows, sdlRead.bottom)) if (sdlReadText(0, sdlRead.rows, sdlRead.top)) { if (sdlRead.debug) printf("nextpage: EOF reached\n"); strcpy(sdlRead.lines[sdlRead.page_lines], ""); } sdlRead.bottom = sdlRead.file.line; return 2; } int getNextLine() //#5 { // for (int i=1; i < sdlRead.rows; i++) // strcpy(sdlRead.lines[i-1], sdlRead.lines[i]); // clearLines(sdlRead.rows-1); clearLines(0); sdlRead.prev_top++; sdlRead.top++; if (sdlRead.debug) printf("nextline: page top set to file line %d\n", sdlRead.top); // if (sdlReadText(sdlRead.rows - 1, sdlRead.rows, sdlRead.bottom)) if (sdlReadText(0, sdlRead.rows, sdlRead.top)) { if (sdlRead.debug) printf("nextline: EOF reached\n"); strcpy(sdlRead.lines[sdlRead.page_lines], ""); } if (sdlRead.line > 0) sdlRead.bottom++; else if (sdlRead.debug) printf("nextline: 0 lines read\n"); return 2; } int getPrevLine() //#6 { if(sdlRead.top == 0) return 1; clearLines(0); sdlRead.top--; sdlRead.prev_top--; if (sdlRead.prev_top < 0) sdlRead.prev_top = 0; if (sdlRead.debug) printf("prevline: page top set to file line %d\n", sdlRead.top); if (sdlReadText(0, sdlRead.rows, sdlRead.top)) { if (sdlRead.debug) printf("prevline: EOF reached\n"); strcpy(sdlRead.lines[sdlRead.page_lines], ""); } if (sdlRead.line > 0) sdlRead.bottom--; else if (sdlRead.debug) printf("prevline: 0 lines read\n"); return 2; } int getPrevPage() //#7 { if(sdlRead.top == 0) return 1; clearLines(0); sdlRead.top = sdlRead.prev_top; if (sdlRead.debug) printf("prevpage: page top set to file line %d\n", sdlRead.top); if (sdlReadText(0, sdlRead.rows, sdlRead.prev_top)) { if (sdlRead.debug) printf("prevpage: EOF reached\n"); strcpy(sdlRead.lines[sdlRead.page_lines], ""); } sdlRead.prev_top -= (int) (sdlRead.rows / 2); if (sdlRead.prev_top < 0) sdlRead.prev_top = 0; sdlRead.bottom = sdlRead.file.line; return 2; } int getLastPage() //#8 { if(sdlRead.file.lines <= sdlRead.rows) return 1; clearLines(0); sdlRead.top = sdlRead.file.lines - sdlRead.rows; if (sdlRead.top < 0) sdlRead.top = 0; sdlRead.prev_top = (int) sdlRead.top - (sdlRead.rows / 2); if (sdlRead.prev_top < 0) sdlRead.prev_top = 0; if (sdlRead.debug) printf("lastpage: page top set to file line %d\n", sdlRead.top); while (!sdlReadText(0, sdlRead.rows, sdlRead.top)) { clearLines(0); sdlRead.top++; } if (sdlRead.debug) printf("lastpage: EOF reached (%d)\n", (int) (sdlRead.top - sdlRead.prev_top)); strcpy(sdlRead.lines[sdlRead.page_lines], ""); if(sdlRead.page_lines > sdlRead.rows) { int j = sdlRead.page_lines - sdlRead.rows; for (int i=0; i < sdlRead.rows; i++) strcpy(sdlRead.lines[i], sdlRead.lines[i+j]); for (int i=sdlRead.page_lines; i > sdlRead.rows; i--) strcpy(sdlRead.lines[i], ""); } sdlRead.bottom = sdlRead.file.lines; return 2; } /* one-file (1f) specific */ void version_1f() { printf("sdlRead (one-file) v%s\n", VERSION); } void output_1f(char *file_1f) { FILE *source_1f; char out_1f[1]; if (offset_1f == NO_SIZE || sizeOf_1f == NO_SIZE) { version_1f(); printf("error: no source file or zip\n"); exit(32); }else{ source_1f = fopen(file_1f, "rb"); if (source_1f == NULL) { version_1f(); printf("error: cant open '%s'\n", file_1f); exit(32); } // fseek(source_1f, offset_1f + 223, SEEK_SET); // off by ? fseek(source_1f, -sizeOf_1f, SEEK_END); while(true) { if (!fread(out_1f, 1, 1, source_1f)) { fclose(source_1f); break; }else putchar((int) out_1f[0]); } } } /* one-file (1f) main */ int main(int argc, char *argv[]) { /* place used variables here */ int j, argDone, section; /* this is the begining of commandline argument processing */ if ( (argc > 1) && ( (strcmp("--version", argv[1]) == 0) || (strcmp("-v", argv[1]) == 0) ) ) { version_1f(); exit(0); } if ( (argc == 1) || ( (argc > 1) && (strcmp("--help", argv[1]) == 0) ) ) { version_1f(); printf("Copyright 2016 MiNTed Games\n\n"); printf("Display a text file using image fonts with SDL 1.2\n\n"); printf("usage: sdlRead-1f [_option_] \n"); if (argc > 1) { printf("_option_:"); printf("\t-1f one-file (1f) source information\n"); printf("\t--background shown under text (maybe use with --outline) \n"); printf("\t--imagefont used to diplay text (use without for more help) \n"); printf("\t--color set color of font\n"); printf("\t--bgcolor set page background color (when no image)\n"); printf("\t--outline show text with font outline\n"); printf("\t--margin indent pixels from page edge\n"); printf("\t--fullscreen use display maximum WxH\n"); printf("\t--wrap wrap lines of displayed text\n"); printf("\t--nowrap dont wrap lines of displayed text\n"); printf("\t--help This help information\n"); printf("\t--help=font Show ImageFont help information\n"); printf("\t-v|--version Version information\n"); } printf("\n"); exit(0); } if ( (argc == 2) && ( (strcmp("--help-imagefont", argv[1]) == 0) || (strcmp("--help=imagefont", argv[1]) == 0) || (strcmp("--help=font", argv[1]) == 0) || (strcmp("--imagefont", argv[1]) == 0) ) ) { version_1f(); printf("Copyright 2016 MiNTed Games\n\n"); printf("Help with ImageFont settings and information.\n\n"); printf("usage: sdlRead-1f --imagefont [_option_] \n"); printf("_option_:"); printf("\t--background shown under text (maybe use with --outline) \n"); printf("\t--imagefont 90 char. bitmap image, size = (font-width x 90) x font-height\n"); printf("\t--imagefont 256 char., size = (font-width x 256) x font-height (use --font-256) \n"); printf("\t--imagefont proportional, multicolor font image (detects W & H, see example) \n"); printf("\t--font-width width of font in pixels, if NOT proportional (default %d)\n", DEF_FONT_WIDTH); printf("\t--font-height height of font in pixels, if you want to adjust (default %d)\n", DEF_FONT_HEIGHT); printf("\t--font-256 font has all 256 chars (default is char. 33 to 126, else use key)\n"); printf("\t--font-prop imagefont is proportional font (GuiChan ImageFont)\n"); printf("\t--font-color use custom color for font color\n"); printf("\t--font-key imagefont is proportional and/or not standard 123/256 chars.\n"); printf("\t--color Caps. or lowercase, font color (default WHITE)\n"); printf("\t--bgcolor set page background color (when no image)\n"); printf("\t--page-width width of centered page for text, in pixels\n"); printf("\t--page-height height of centered page for text, in pixels\n"); printf("\t--margin indent page pixels (< & >) and /2 (top)\n"); printf("\t--margin-top indent page pixels from top\n"); printf("\t--cols height of centered page for text, in characters\n"); printf("\t--rows width of centered page for text, in characters\n"); printf("\t--outline plots the font in 4 directions (+1 to width)\n"); printf("\t--outline-color font outline color (default DARKBLUE)\n\n"); printf("\t 24bit decimal number, CYAN = 65535\n"); printf("\t 24bit hex 0xRRGGBB number, GREEN = 0x00ff00\n"); printf("\t WHITE, RED, YELLOW, CYAN, BLUE, GREEN, DARKYELLOW\n"); printf("\t DARKRED, DARKBLUE, LIGHTBLUE, DARKGREEN, LIGHTGREEN\n\n"); printf("examples:\n"); printf(" sdlRead-1f --background nebula.jpg --outline --margin 100 readme.txt\n"); printf(" sdlRead-1f --imagefont 08x14-VGA_font.png --font-height 14 --margin 50 help.txt\n"); printf(" sdlRead-1f --imagefont ConsoleFont.bmp --font-width 6 --font-height 13 --font-color 1600000 --margin 10 --outline chasm.txt\n"); printf(" sdlRead-1f --imagefont techyfontbig.png --font-prop --font-key \"abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%%&\\`'*#=[]\\\"\" scroller.txt\n"); printf("\n"); exit(0); } if ( (argc > 1 ) && ( (strcmp("-1f", argv[1]) == 0) || (strcmp("--1f", argv[1]) == 0) ) ) { version_1f(); printf("Copyright 2016 MiNTed Games\n"); printf("one-file (1f) source information.\n\n"); if (offset_1f == 12345 || sizeOf_1f == 12345) { printf("no source file or zip\n"); exit(32); }else{ printf("usage: sdlRead-1f _option_\n"); printf("_option_:\n"); printf("\t--src|--source output attached one-file (1f) source file\n"); printf("\t--src-size size of appended source (in bytes) (%d)\n", (int) sizeOf_1f); printf("\t--src-type type of source appended (TXT/ZIP) (%s)\n", SRC_TYPE); printf("\n"); printf("To save one-file (1f) source to file use one of the following:\n"); printf("\tsdlRead-1f --src > sdlRead-1f.cpp\n"); // printf("\tsdlRead-1f --src > sdlRead-1f.zip\n"); printf("\tsdlRead-1f --src > sdlRead-1f`sdlRead-1f --src-type`\n"); printf("To verify one-file (1f) source file size:\n"); printf("\tsdlRead-1f --src-size (match this to the size in a directory listing)\n"); printf("or use:\n"); printf("NAME=sdlRead; if [ `ls -l $NAME-1f.cpp|cut -d \\ -f 5` = `./$NAME-1f --src-size` ]; then echo Verified; else echo Failed; fi\n"); printf("\none-file (1f) options exit with status:\n"); printf("\t31 no error (0x1f)\n"); printf("\t32 an error occured (0x20)\n"); exit(31); } } if ( (argc > 1) && ( (strcmp("--source", argv[1]) == 0) || (strcmp("--src", argv[1]) == 0) ) ) { output_1f(argv[0]); exit(31); } if ( (argc > 1) && (strcmp("--src-type", argv[1]) == 0) ) { printf(SRC_TYPE); exit(31); } if ( (argc > 1) && (strcmp("--src-size", argv[1]) == 0) ) { printf("%d", SRC_SIZE); exit(31); } /* the rest of your argv[] processing goes here */ sdlRead_init(); j = 0; for (int i = 1; i < argc; i++) { argDone = 0; if (strcmp(argv[i], "--debug") == 0) { sdlRead.debug = 1; argDone = 1; } if (strcmp(argv[i], "--info") == 0 || strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-V") == 0) { sdlRead.info = 1; argDone = 1; } if (strcmp(argv[i], "--fullscreen") == 0) { sdlRead.fullscreen = 1; argDone = 1; } if (strcmp(argv[i], "--outline") == 0) { sdlRead.useOutline = 1; argDone = 1; } if (strcmp(argv[i], "--wrap") == 0) { sdlRead.wrap = 1; argDone = 1; } if (strcmp(argv[i], "--nowrap") == 0 || strcmp(argv[i], "--no-wrap") == 0) { sdlRead.wrap = 0; argDone = 1; } if (strcmp(argv[i], "--linenumbers") == 0 || strcmp(argv[i], "--line-numbers") == 0) { sdlRead.linenumbers = 0; argDone = 1; } if (strcmp(argv[i], "--width") == 0) { i++; if (i == argc) { printf("error: page --width needs a number\n"); exit(1); } sdlRead.page_w = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--height") == 0) { i++; if (i == argc) { printf("error: page --height needs a number\n"); exit(1); } sdlRead.page_h = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--margin") == 0) { i++; if (i == argc) { printf("error: page --margin needs a number\n"); exit(1); } sdlRead.page_m = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--margin-top") == 0 || strcmp(argv[i], "--margintop") == 0) { i++; if (i == argc) { printf("error: page --margin needs a number\n"); exit(1); } sdlRead.page_t = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--background") == 0) { i++; if (i == argc) { printf("error: --background needs a filename\n"); exit(1); } strcpy(sdlRead.background, argv[i]); sdlRead.useBackground = 1; argDone = 1; } if (strcmp(argv[i], "--imagefont") == 0) { i++; if (i == argc) { printf("error: --imagefont needs a filename\n"); exit(1); } strcpy(sdlRead.fontimage[sdlRead.cur_font].filename, argv[i]); argDone = 1; } if (strcmp(argv[i], "--font-width") == 0) { i++; if (i == argc) { printf("error: --font-width needs a number\n"); exit(1); } sdlRead.fontimage[sdlRead.cur_font].width = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--font-height") == 0) { i++; if (i == argc) { printf("error: --font-height needs a number\n"); exit(1); } sdlRead.fontimage[sdlRead.cur_font].height = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--font-space") == 0) { i++; if (i == argc) { printf("error: --font-space needs a number\n"); exit(1); } sdlRead.fontimage[sdlRead.cur_font].space = atoi(argv[i]); argDone = 1; } if (strcmp(argv[i], "--font-key") == 0) { i++; if (i == argc) { printf("error: --font-key needs a character order list\n"); exit(1); } if (strlen(argv[i]) > 255) { printf("error: --font-key is limited to 256 characters max.\n"); exit(1); } strcpy(sdlRead.fontimage[sdlRead.cur_font].key, argv[i]); argDone = 1; } if (strcmp(argv[i], "--font-256") == 0) { sdlRead.fontimage[sdlRead.cur_font].is256 = 1; argDone = 1; } if (strcmp(argv[i], "--font-prop") == 0) { sdlRead.fontimage[sdlRead.cur_font].isProp = 1; argDone = 1; } if (strcmp(argv[i], "--font-color") == 0) { i++; if (i == argc) { printf("error: --font-color needs a hex number\n"); exit(1); } sdlRead.fontimage[sdlRead.cur_font].color = atoi(argv[i]); sdlRead.fontColorNumber = FONT_CUSTOM; sdlRead.color = atoi(argv[i]); sdlRead.useFontColor = 1; argDone = 1; } if (strcmp(argv[i], "--font-color-number") == 0 ||strcmp(argv[i], "--color-number") == 0) { i++; if (i == argc) { printf("error: --font-color needs a hex number\n"); exit(1); } sdlRead.fontColorNumber = atoi(argv[i]); if (sdlRead.fontColorNumber >= MAX_FONTSHAPES) { printf("error: --font-color-number needs a number <%d\n",MAX_FONTSHAPES); printf("currently color numbers are:\n"); printf("\t0 WHITE\n"); printf("\t1 RED\n"); printf("\t2 YELLOW\n"); printf("\t3 GREEN\n"); printf("\t4 CYAN\n"); printf("\t5 BLUEBLACK (dark navy blue)\n"); printf("\t6 BLACK\n"); printf("\t(for more use --color or --font-color)\n"); exit(1); } sdlRead.useFontColorNumber = 1; argDone = 1; } if (strcmp(argv[i], "--background-color") == 0 || strcmp(argv[i], "--bgcolor") == 0) { i++; if (i == argc) { printf("error: page --background-color needs a hex number\n"); exit(1); } sdlRead.bgcolor = atoi(argv[i]); sdlRead.useBgColor = 1; argDone = 1; } if (argDone == 0) { strcpy(sdlRead.playList[j], argv[i]); j++; } } sdlRead.playlist = j; if (sdlRead.playlist == 0) { version_1f(); printf("info: you probably just forgot to choose a file to read\n"); exit(1); } atexit(cleanUp); initSystem(); // Opens video mode and sound if (sdlRead.useBackground) { loadBackground(sdlRead.background); } initVars(); sdlReadInitFonts(); //printf("white:%d",(int)SDL_MapRGB(graphics.screen->format, 0xff, 0xff, 0xff)); section = 0; while (true) { // non-blocking (shows high CPU usage) // should be event driven, but this is faster //printf("%d ",section); switch(section) { case 0: section = getTextFile(); break; case 1: section = checkKeys(); break; case 2: section = showTextPage(); break; case 4: section = getNextPage(); break; case 5: section = getNextLine(); break; case 6: section = getPrevLine(); break; case 7: section = getPrevPage(); break; case 8: section = getLastPage(); break; case 9: sdlRead.next++; sdlRead.top = 0; sdlRead.bottom = 0; section = 0; break; } if (section == 10) exit(0); } /* this is the end, .. my friend, the end */ return(0); }