Хабрахабр

[Из песочницы] Моя первая читалка на основе Sharp PC3000

#include <dir.h>
#include <bios.h>
#include <dos.h>
#include <fcntl.h>
#include <io.h>
#include <stat.h>
#include <alloc.h>
#include <conio.h>
#include <stdio.h>
#include <stat.h>
#include <stdlib.h>
#include <stdarg.h>
#include <graphics.h>
#include <process.h> unsigned char qui,c,membl[2000],fname[20],memtxt[128],Statusin,me;
unsigned int h,pos=0,ads,seg,t,t1,t2,memseg,memoffset,membuff,tx,rx,startbuff,buffoff=0,buffbeg,xcor,ycor,buttons,tb;
int *memblock,xpos,ypos;
long membu,memtext,lenght;
unsigned long textposit;
int memcoord,fontadr;
int GraphDriver,txtfile;
int GraphMode;
double AspectRatio;
int MaxX, MaxY;
int MaxColors;
int ErrorCode;
struct palettetype palette; /*struct ffblk ffblk;*/
unsigned char filelist[192][15];
unsigned char i,x,xp,yp,xl,p,zc;
char *driv,*diskname;
unsigned int key,drive;
int z,filepos,dr,pgs; void main()
if (key==0x4800) { /* up*/ filepos=filepos-1; } if (key==0x4d00) { /* right*/ filepos=filepos+22; } if (key==0x4b00) { /* left*/ filepos=filepos-22; } if (key==0x3B00) { clrscr(); printf("\n National Book Reader v2.0\n\n"); printf(" View only russian and english TXT files\n\n"); printf(" LEFT,RIGHT,UP,DOWN - select file or drive.\n\n"); printf(" ENTER - view file.\n\n"); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n (C) 2000 MSW Computing"); getch(); clrscr(); } if (filepos<0) filepos=0; if (filepos>=i) filepos=i-1; if (key==0x11b) break; } if (key==0x11b) break; key=0; if (filepos<5) { drive=filepos; clrscr(); drivesel(); files(); } if (filepos>4) { clrscr(); strcpy(fname,filelist[filepos]); book(); } } clrscr(); exit(0);
}
void prtmen()
{ unsigned long pages,fl; unsigned int pgs,result; FILE *stream; zc=0; for (xp=0;xp<=4;xp++) { xl=xp*15; for (yp=1;yp<23;yp++) { if (filepos==zc) { gotoxy(xl+1,yp); cprintf(">%s",filelist[zc]); zc=zc+1; gotoxy(1,25); if (zc-1<5){ cprintf("Select drive: %-2s ",filelist[zc-1]); } else { strcpy(fname,filelist[filepos]); if ((stream=fopen(fname,"r"))==NULL) { restorecrtmode(); fprintf(stderr,"Can't open txt file"); exit(1); } result=fseek(stream,0L,SEEK_END); fl=ftell(stream); result=fseek(stream,0L,SEEK_SET); pgs=fl/1920; fclose(stream); cprintf("%-1s:\\%-12s Size: %-10lu ",diskname,filelist[zc-1],fl); gotoxy (60,25); cprintf ("%10u pages",pgs); } } else { gotoxy(xl+1,yp); cprintf(" %s",filelist[zc]); zc=zc+1; } if (zc==i) break; } if (zc==i) break; }
}
void files(void)
{ struct ffblk ffblk; char nam=" "; unsigned long siz=0; FILE *street; textmode(BW80); z=findfirst("*.*",&ffblk,0); strcpy(filelist[0],"A:\\"); strcpy(filelist[1],"B:\\"); strcpy(filelist[2],"C:\\"); strcpy(filelist[3],"D:\\"); strcpy(filelist[4],"E:\\"); for (i=5;i<110;i++) { if (z==-1) break; nam=" "; p=sprintf(nam,"%s",ffblk.ff_name); strcpy(filelist[i],nam); filelist[i][13]=0xa; z=findnext(&ffblk); }
} void drivesel(void)
{ dr=setdisk(drive); if (dr==0) { gotoxy(1,25); cprintf("Not ready %s",filelist[filepos]); delay(2000); setdisk(2); } } void book(void)
{ unsigned int key,i; unsigned char status,a; Initialize(); Oscill(); restorecrtmode();
} void Oscill(void)
{ unsigned char bitq,c,s,asdf,pps,result,resoa; unsigned int key,h,i,x,y,sda,scl,qsel=0,ksearch,xc,yc,zc,zx,fil,er,keypressed=0; unsigned long posit=0,prev[3000],lastz,last; unsigned long fl,pageset,pagesel,pconst=1920; FILE *stream; int pp,ppc,fn,z,dec,sig; struct stat buf; pp=0; prev[pp]=0; if ((stream=fopen(fname,"r"))==NULL) { restorecrtmode(); fprintf(stderr,"Can't open txt file"); exit(1); } result=fseek(stream,0L,SEEK_END); fl=ftell(stream); result=fseek(stream,0L,SEEK_SET); pgs=fl/1920; while (!feof(stream)) { cls(); bitq=0; ypos=0; xpos=0; lastz=ftell(stream); for (h=0;h<24;h++) { ypos=h; last=ftell(stream); for (pps=0;pps<80;pps++) { keypressed=0; result=fgetc(stream); if (result==0xa) break; if (result == 0xFF) { sprintf(memtxt,"End of file. Press [ESC] for quit or [ARROW LEFT] to Page UP\n"); fseek(stream,last,SEEK_SET); xpos=0; ypos=24; zprintf(); while (bioskey(1)==0) ; key=bioskey(0); if (key==0x5000) { /* down*/ keypressed=1; } if (key==0x4800) { /* up*/ keypressed=2; } if (key==0x4d00) { /* right*/ keypressed=3; } if (key==0x4b00) { /* left*/ keypressed=4; } if (key==0x11b) { /*quit*/ keypressed=5; } bitq=1; if (keypressed==5|keypressed==4) break; /*sym='q';*/ } /*end if EOF*/ if (keypressed==5|keypressed==4) break; if (result<32) { memtxt[pps]='.'; } else memtxt[pps]=result; } /*end line*/ if (keypressed==5|keypressed==4) break; memtxt[pps]=0x0a; zprintf(); /*end page*/ posit=ftell(stream); ppc=posit/1920; sprintf(memtxt," File: %s Page: %u Pages: %u (C) 1999 MSW \n ",fname,ppc,pgs); xpos=0; ypos=24; zprintf(); sprintf(memtxt," "); xpos=0; } while (bitq!=1) { while (bioskey(1)==0) ; key=bioskey(0); if (key==0x3C00) { int pagesel; pagesel=ppc; xpos=0; ypos=24; sprintf(memtxt,"Select page: \n"); zprintf(); while (qsel==0) { while (bioskey(1)==0) ; ksearch=bioskey(0); xpos=14; ypos=24; sprintf(memtxt,"%d \n",pagesel); zprintf(); if (ksearch==0x4800) { pagesel=pagesel+1; } if (ksearch==0x5000) { pagesel=pagesel-1; } if (pagesel>pgs) pagesel=pgs; if (pagesel<1) pagesel=0; if (ksearch==0x1c0d) break; } if (pagesel==0) { pageset=0; } else { pageset = pagesel * pconst; } result=fseek(stream,pageset,SEEK_SET); bitq=1; } if (key==0x3B00) { bitq=1; key=0; Help(); bioskey(0); fseek(stream,lastz,SEEK_SET); keypressed=0; } if (key==0x5000) { /* down*/ keypressed=1; } if (key==0x4800) { /* up*/ keypressed=2; } if (key==0x4d00) { /* right*/ keypressed=3; } if (key==0x4b00) { /* left*/ keypressed=4; } if (key==0x11b) { /*quit*/ keypressed=5; } if (keypressed==5) break; if (keypressed==4) { bitq=1; } if (keypressed==3) { pp=pp+1; prev[pp]=posit; bitq=1; } } if (keypressed==4) { pp=pp-1; if (pp<=0) pp=0; fseek(stream,prev[pp],SEEK_SET); } if (keypressed==5) break; } fclose(stream); }
void Search(void)
{
} void Help(void)
{ xpos=0; ypos=0; cls(); sprintf(memtxt," National Book Reader v2.0\n"); zprintf(); xpos=0; ypos=2; sprintf(memtxt," LEFT - page down\n"); zprintf(); xpos=0; ypos=4; sprintf(memtxt," RIGHT - page up\n"); zprintf(); xpos=0; ypos=6; sprintf(memtxt," ESC - exit\n"); zprintf(); xpos=0; ypos=8; sprintf(memtxt," F1 - this screen\n"); zprintf(); xpos=0; ypos=10; sprintf(memtxt," F2 - go to page\n"); zprintf(); sprintf(memtxt," UP - increment value\n"); xpos=0; ypos=12; zprintf(); sprintf(memtxt," DOWN - decrement value\n"); xpos=0; ypos=14; zprintf(); sprintf(memtxt," ENTER - select page\n"); xpos=0; ypos=16; zprintf(); xpos=0; ypos=24; sprintf(memtxt," (C) 2000 MSW Home Computing\n"); zprintf(); } void Quit(void)
{ textcolor(WHITE); textbackground(BLACK); restorecrtmode(); exit(0);
}
void Initialize(void)
{ int xasp, yasp, fontst,errorcode; GraphDriver = DETECT; /*errorcode = registerbgidriver(CGA_driver); if(errorcode < 0) { printf("ЋиЁЎЄ :%s\n",grapherrormessage(errorcode)); printf("„«п бв ­ў ­ ¦¬ЁвҐ «оЎго Є« ўЁиг\n"); getch(); exit(1); } */ initgraph( &GraphDriver, CGAHI, "" ); settextstyle(DEFAULT_FONT,HORIZ_DIR,USER_CHAR_SIZE); ErrorCode = graphresult(); if( ErrorCode != grOk ){ printf(" Graphics System Error\n"); exit( 1 ); } getpalette( &palette ); MaxColors = getmaxcolor() + 1; MaxX = getmaxx(); MaxY = getmaxy(); getaspectratio( &xasp, &yasp ); AspectRatio = (double)xasp / (double)yasp;
} void zprintf(void)
{ unsigned int i,g,z; unsigned char l,w; z=0; c=memtxt[z]; while (c!=0xA) { c=memtxt[z]; if (c>=0x20) { gettextadr(); fontadr=(c-0x20)*8; for (i=0;i<7;i++) { g=fontadr+i; l=membl[g]; pokeb(0xB800,memcoord,l); i=i++; g=fontadr+i; l=membl[g]; pokeb(0xB800,memcoord+8192,l); memcoord=memcoord+80; } xpos=xpos+1; } z=z++; } } void gettextadr(void)
{ memcoord=xpos+(ypos*320);
}
void cls(void)
{ unsigned int cl; for (cl=0;cl<16384;cl++) pokeb (0xb800,cl,0);
}
void loadfont(void)
{ unsigned int fil,i; char c; fil = _open("book.fnt",O_RDONLY); if (fil==-1) { printf("File BOOK.FNT not found\n"); abort(); } if ((_read(fil,membl,1792))==-1) { printf("Can't load national font file"); perror(""); } /*fseek(fil,0,SEEK_SET); for (i=0;i<1792;i++) { fseek(fil,i,SEEK_SET); membl[i]=fgetc(fil); } fclose(fil); */ _close(fil);
}

Теги
Показать больше

Похожие статьи

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Кнопка «Наверх»
Закрыть