Exemple #1
0
main()
{
    static byte sides;
    srand(oztime());
    ozfont(FONT_OZ_LARGE);
    ozputs(0,10,"Sides? (1-9)");
    sides=ozgetch()-'0';
    ozputch(115,30,'0'+(rand()%sides));
    ozgetch();
}
Exemple #2
0
main()
{
    ozputs(10,10,"Saving screen!");
    ozsavescreen();
    ozgetch();
    ozputs(10,10,"Saved the screen!");
    ozgetch();
    ozrestorescreen();
    ozgetch();
}
Exemple #3
0
int oznkeyhit(void)
{
    static unsigned c;
    for(;;)
    {
      if(!ozkeyhit()) return 0;
      c=ozgetch();
      switch(c)
        {
            case KEY_POWER:
            case KEY_MAIN:
            case KEY_TELEPHONE:
            case KEY_SCHEDULE:
                ozexitto(c);
            case KEY_MYPROGRAMS:
                exit(0);
            case KEY_BACKLIGHT:
                oztogglelight();
                break;
            default:
                ozungetch(c);
                return 1;
        }
    }
}
Exemple #4
0
getinitials(byte x3,byte y3)
{
    static byte i;
    static unsigned k;
    i=0;
    while(i<3)
    {
        switch(k=ozgetch())
        {
/*          case KEY_BACKSPACE:
            case 8:
                if(i)
                {
                    i--;
                    x3-=ozputs(x3,y3,initials+i);
                    ozputs(x3,y3,"   ");
                }
                break;*/
            case KEY_LOWER_ESC:
            case KEY_UPPER_ESC:
                exit(0);
            default:
                if(k<127 && (isalpha(k) || isdigit(k)))
                {
                    initials[i]=toupper(k);
                    initials[i+1]=0;
                    x3=ozputs(x3,y3,initials+i);
                    i++;
                }
                break;
        }
    }
}
Exemple #5
0
int write_file(void)
{
    static unsigned pos,size;
    ozcls();
    ozputs0(0,"Writing...");
    if(open1(filename,O_WRONLY)<0)
    {
        ozcls();
        ozputs0(0,"Error opening file!");
        ozgetch();
        return -1;
    }
    pos=0;
    clear_wrap_to_end(0);
    while(pos<file_length)
    {
        if(pos+LINE_BUF_LEN<=file_length) size=LINE_BUF_LEN;
          else size=file_length-pos;
        ozreadauxmem(pos,line_buf,size);
        if(write1(line_buf,size)<size)
        {
            ozcls();
            ozputs0(0,"Error writing!");
            close1();
            return -1;
        }
        pos+=size;
    }
    close1();
}
Exemple #6
0
main()
{
	int i;
	for(i=0;i<200;i++) putchar(i+'A');
	_ozputsprite(10,10,4,"\x0F\xF0\x09\xF6\x09\xF6\x0F\xF0");
	ozgetch();
}
Exemple #7
0
main()
{
    static char s[26];
    s[0]=0;
    ozeditline(0,0,s,26,100);
    ozputs(10,10,s);
    ozgetch();
}
Exemple #8
0
main()
{
   checkpage(0,0x404);
   checkpage(10,0x405);
   ozputs(0,20,"Fill?");
   if(ozgetch()!='y') return;
   fillpage(0x404);
   fillpage(0x405);
   return;
}
Exemple #9
0
void read_file(void)
{
    static int r;
    static byte i;
    static byte b;
    ozcls();
    ozputs0(0,"Reading...");
    file_length=0;
    if(open1(filename,O_RDONLY)<0)
    {
        ozputs0(20,"Cannot open!  Create new? [Y/n]");
        if(ozgetch()=='n') exit(0);
        return;
    }
    do
    {
        r=read1(line_buf,LINE_BUF_LEN);
        if(file_length+r>MAX_FILE_LENGTH)
        {
            ozcls();
            ozputs0(0,"File too long!");
            ozputs0(10,"Truncate? [y/N]");
            if(ozgetch()!='y') exit(0);
            r=MAX_FILE_LENGTH-file_length;
        }
        for(i=0;i<r;i++)
        {
            b=line_buf[i];
            b&=0x7f;
            if(b<32) b='*';
            line_buf[i]=b;
        }
        if(r>0)
        {
            ozwriteauxmem(file_length,line_buf,r);
            file_length+=r;
        }
    } while(r==LINE_BUF_LEN && file_length<MAX_FILE_LENGTH);
     /* note: LINE_BUF_LEN does not divide MAX_FILE_LENGTH, and this
        is important for truncate message to work */
    close1();
}
Exemple #10
0
play()
{
	ozcls();
	ozsetactivepage(0);
	ozsetdisplaypage(0);
	ozcls();
	if(shots<1)
	{
		ozcls();
		ozputs(0,0,"Out of Bullets!  Game Over!");
		ozngetch();
		exit(0);
	}
	ozsetfont(FONT_OZ_NORMAL);
	drawgun();
	addtoscore(0);
	addtoshots(0);
	sprintf(bullseye,"Bullseyes: %ld",bullseyes);
	ozputs(170,60,bullseye);
	accuracy(170,70);
	getsound();
	ozputs(0,70,soundstat);
	ozputs(0,30,"Press <ENTER> to pull, then <SPACE> to fire.");
	switch(ozgetch())
	{
		case KEY_BACKLIGHT: oztogglelight(); break;
		case KEY_MYPROGRAMS: endgameswitch(); exit(0);
		case KEY_LOWER_ESC: endgameswitch(); main();
		case KEY_LOWER_ENTER: pull(); break;
		case KEY_LEFT: gunpos=LEFT; break;
		case KEY_RIGHT: gunpos=RIGHT; break;
		case KEY_LOWER_MENU: help(); break;
		case 'h': help(); break;
		case 's': changesound(); break;
		case KEY_NEWLINE: ozsnap(); break;
	}
	play();
}
Exemple #11
0
unsigned ozngetch(void)
{
    static unsigned c;
    for(;;)
    {
        switch(c=ozgetch())
        {
            case KEY_POWER:
            case KEY_MAIN:
            case KEY_TELEPHONE:
            case KEY_MEMO:
            case KEY_SCHEDULE:
                ozexitto(c);
            case KEY_MYPROGRAMS:
                exit(0);
            case KEY_BACKLIGHT:
                oztogglelight();
                break;
            default:
                return c;
        }
    }
}
Exemple #12
0
void frommemo(void)
#endif
{
    static unsigned loc,page,offset,recnum;
    register char *p;
    static char filename[32];
    static char parthead[21];
    static char continued;
    static unsigned int sum;
    static byte val;
    static byte version2;
    static int i;
    static unsigned j;
    static int c;
    static int partnumber;
    static char checksum[6];
    page=0;
    offset=0;
    while(loc=ozfindnext(TYPE_MEMO,&page,&offset,&recnum))
    {
        partnumber=0;
        p=ozloadcluster(loc);
        if(p[24]!='~' || p[25]!='~'
         || p[26]!='z'
         || strncmp(p+2+13+9+15,"00000",5)
         || strncmp(p+2+13+9+21,"**LIBOZ_UPLOAD*",15)) continue;
        do
        {
            strcpy(parthead,p+24);
            if(ozopenfile(loc)==-1)
            {
              ozwarn("Error opening memo!",anykey);
              return;
            }
            for(i=0;i<13+9+21+15;i++) ozreadfilebyte();
            continued=ozreadfilebyte();
            p=filename;
            while('\r'!=(c=ozreadfilebyte()) && '\n'!=c && p-filename<MAX_FILENAMELEN)
            {
                if(partnumber)
                {
                    if(c!=*p)
                    {
                        ozputs(0,70,"You may have the remains of "
                        "another download.");
                        ozclosefile();
                        close1();
                        unlink(filename);
                        ozgetch();
                        return;
                    }
                }
                else *p=c;
                p++;
            }
            if(p-filename>MAX_FILENAMELEN)
            {
                ozwarn("Filename too long!",anykey);
                return;
            }
            *p=0;
            ozputs(0,10,filename);
            ozputs(0,20,parthead);
            if(!partnumber)
            {
                ozsetowner(atoi(parthead+3));
                if(open1(filename,O_WRONLY)==-1)
                {
                    ozwarn("Error opening file!",anykey);
                    return;
                }
            }
            sum=0;
            p=filebuf;
            if(!partnumber)
            {
                c=ozreadfilebyte();
                if(c==TOMEMO2_MARKER)
                {
                   version2=1;
                   for(j=0;j<NUMSPECIALS;j++)
                   {
                      c=ozreadfilebyte();
                      table[j]=(c-HEX)|((ozreadfilebyte()-HEX)<<4);
                   }
                }
                else
                {
                   version2=0;
                   goto PROCESS_VERSION1;
                }
            }
            if(version2)
            {
                while(-1!=(c=ozreadfilebyte()) && (byte)c!=EOF_MARKER)
                {
                    if((byte)c>=SPECIAL)
                        val=table[c-SPECIAL];
                    else
                        val=(c-HEX)|((ozreadfilebyte()-HEX)<<4);
                    sum+=val;
                    *p++=val;
                }
                if(c==EOF_MARKER)
                   c='*';
            }
            else
            {
                while(-1!=(c=ozreadfilebyte()))
                {
                    PROCESS_VERSION1:
                    if((byte)c=='*') break;
                    if((byte)c=='~')
                    {
                        while(-1!=(c=ozreadfilebyte()) && '~'!=(byte)c)
                        {
                            sum+=(byte)c;
                            *p++=c;
                        }
                    }
                    else
                    {
                        if('0'<=(byte)c && (byte)c<='9') val=(c-'0')<<4;
                          else val=(c+(10-'a'))<<4;
                        c=ozreadfilebyte();
                        if('0'<=(byte)c && (byte)c<='9') val+=(c-'0');
                          else val+=(c+(10-'a'));
                        *p++=val;
                        sum+=(byte)val;
                    }
                }
                c=ozreadfilebyte();
            }
            if('*'==c)
            {
                for(i=0;i<5;i++) checksum[i]=ozreadfilebyte();
                checksum[5]=0;
            }
            if('*'!=c || (unsigned)(atoi(checksum))!=sum)
            {
                ozclosefile();
                close1();
                unlink(filename);
                ozwarn("Error in memo!",anykey);
                return;
            }
            ozclosefile();
            if(write1(filebuf,p-filebuf) < (p-filebuf) )
            {
               close1();
               unlink(filename);
               ozwarn("Error in writing!",anykey);
               return;
            }
            if(ozunlink(TYPENUM_MEMO,recnum))
            {
                if(ozwarn("Error unlinking!  Continue?",yn)!=KEY_LOWER_ENTER) return;
            }
/*            ozputch(0,0,continued); */
            if(continued=='L')
                break;
            partnumber++;
            strcpy(parthead+15,utoa_0n(partnumber,5));
            page=offset=0;
            while(loc=ozfindmemo(parthead,&page,&offset,&recnum))
            {
                p=ozloadcluster(loc);
                if(strncmp(p+2+13+9+21,"**LIBOZ_UPLOAD*",15)) continue;
                break;
            }
            if(loc==0)
            {
                close1();
                unlink(filename);
                ozwarn("Error: Cannot find next part!",anykey);
                return;
            }
        } while(loc);
        close1();
        page=offset=0;
    }
}
Exemple #13
0
void view(void)
{
	static byte mod;
	static unsigned k;
    static unsigned long delta;
    static byte i;
	load_headers();
    in_buf=0;
    ateof=0;
    atstart=1;
    scrollbar_pos=0xa000+29;
    if(last==0) last=header_length;
    goto_pos(last);
	mod=1;
    ozcls();
	while(1)
	{
        if(mod)
        {
            if(!backandforth)position_save();
            show();
            unbar();
            scrollbar();
            backandforth=mod=0;
        }
        switch(k=ozgetchblank())
		{
            case KEY_LEFT:
            case KEY_BACKSPACE:
#ifdef DEBUG
                putformatted(0,0,"positionptr=| numpositions=|  ",
                positionptr,numpositions);
                ozgetch();
#endif
                if(positionptr<=1) break;
                goto_pos(positions[(--positionptr)-1]);
                if(!positionptr) positionptr=1;
                backandforth=mod=1;
#ifdef DEBUG
                putformatted(0,0,"positionptr=| numpositions=|  ",
                positionptr,numpositions);
                ozgetch();
#endif
                break;
            case KEY_RIGHT:
#ifdef DEBUG
                putformatted(0,0,"positionptr=| numpositions=|  ",
                positionptr,numpositions);
                ozgetch();
#endif
                if(positionptr>=numpositions) break;
                goto_pos(positions[positionptr]);
                positionptr++;
                backandforth=mod=1;
#ifdef DEBUG
                putformatted(0,0,"positionptr=| numpositions=|  ",
                positionptr,numpositions);
                ozgetch();
#endif
                break;
            case 'm':
                /* mark position */
                if(numbookmarks>=MAX_BOOKMARKS)
                {
                    for(i=0;i<MAX_BOOKMARKS-1;i++)
                    {
                        bookmarks[i]=bookmarks[i+1];
                    }
                    numbookmarks--;
                }
                bookmarkptr=numbookmarks;
                bookmarks[numbookmarks++]=screen_offset+buffer_offset;
                bookmarksmod=1;
                break;
            case 'b':
                if(numbookmarks)
                {
                    goto_pos(bookmarks[bookmarkptr]);
                    if(bookmarkptr) bookmarkptr--;
                     else bookmarkptr=numbookmarks-1;
                    mod=1;
                }
                break;
            case 'r':
                show_bar=!show_bar;
                bookmarksmod=1;
                unbar();
                scrollbar();
                break;
            case 'h':
            case KEY_UPPER_MENU:
            case KEY_LOWER_MENU:
                dohelp();
                ozcls();
                mod=1;
                break;
            case 'i':
                _ozfilledbox(0,0,WIDTH,line_height,0);
                delta=screen_offset+buffer_offset-header_length;
                putformatted(0,0,"$ : ^/^=|%",filename,
                    delta,length-header_length,
                    (unsigned int)(delta*100/(length-header_length)) );
                _ozfilledbox(0,0,WIDTH,line_height,XOR);
                ozgetchblank();
                mod=1;
                ozcls();
                break;
            case 'c':
                if(numbookmarks && ozwarn("Delete all bookmarks?",yn)==KEY_LOWER_ENTER
                    )
                    {
                        bookmarksmod=1;
                        numbookmarks=0;
                    }
                mod=1;
                ozcls();
                break;
            case '-':
			case KEY_PAGEUP:
                for(i=0;i<num_lines-1;i++)
				{
					checkshiftup();
					backline();
				}
				mod=1;
				break;
            case 's':
                if(myfont) break;
                line_height++;
                if(line_height==11) line_height=8;
                if(line_height!=9) num_lines=80/line_height;
                    else num_lines=9;
                bookmarksmod=1;
                mod=1;
                ozcls();
                break;
			case KEY_PAGEDOWN:
            case KEY_LOWER_ENTER:
            case KEY_UPPER_ENTER:
            case KEY_RETURN:
            case ' ':
                for(i=0;i<num_lines-1;i++)
				{
					checkshiftdown();
					forwardline();
				}
				mod=1;
				break;
            case KEY_UP:
                checkshiftup();
                if(!backline()) break;
                unbar();
                ozscrolldown(line_height*30);
                dcompline(filebuf+screen_offset);
                puttextline(0);
                position_save();
                scrollbar();
                break;
            case KEY_DOWN:
                checkshiftdown();
                if(forwardline())
                {
                    mod=1;
                    showbot=1;
                    unbar();
                    ozscroll(line_height*30);
                }
                break;
            case KEY_LEFT_SHIFT | MASKSHIFT:
            case KEY_RIGHT_SHIFT | MASKSHIFT:
                switch(ozgetch() & 0xF0FF)
                {
                    case '-':
                        ozclick(!ozgetclick());
                        ozsavekeysettings();
                        break;
                    case KEY_PAGEUP:
                    case KEY_UP:
                        tenpercent(-1);
                        mod=1;
                        break;
                    case KEY_PAGEDOWN:
                    case KEY_DOWN:
                        tenpercent(1);
                        mod=1;
                        break;
                }
                break;
            case KEY_UP | MASKSHIFT:
            case KEY_PAGEUP | MASKSHIFT:
                tenpercent(-1);
                mod=1;
                break;
            case KEY_PAGEDOWN | MASKSHIFT:
            case KEY_DOWN | MASKSHIFT:
                tenpercent(1);
                mod=1;
                break;
			case KEY_2ND:
                switch(ozgetch() & 0xF0FF )
				{
                    case '-':
                        ozclick(!ozgetclick());
                        ozsavekeysettings();
                        break;
                    case KEY_PAGEUP:
					case KEY_UP:
                        goto_pos(header_length);
						mod=1;
						break;
					case KEY_PAGEDOWN:
					case KEY_DOWN:
                        goto_pos(length);
						mod=1;
						break;
				}
				break;
			case KEY_LOWER_ESC:
			case KEY_UPPER_ESC:
			case KEY_MYPROGRAMS:
				exit(0);
			case KEY_MAIN:
			case KEY_CALENDAR:
			case KEY_TELEPHONE:
			case KEY_MEMO:
				ozexitto(k);
			case KEY_BACKLIGHT:
                oztogglelight();
				break;
		}
	}
}
Exemple #14
0
main()
{
    ozputs(0,70,"Hello!");
    while(ozgetch()!='q')
        ozscrollclear();
}
Exemple #15
0
static unsigned ozkeyread(byte read)
{
	static byte isshifted=0;
	static byte is2nded=0;
	static byte iscapslock=0;
	static byte shiftheld=0;
	static byte secondheld=0;
	static unsigned int c;
	static unsigned int origc;
/*	  termputch(isshifted?'+':'-'); */
	if(!read && !ozkeyhit()) return NO_KEY;
	origc=ozgetch();
	c=origc&0xF0FF;
	switch(c)
	{
		case KEY_LEFT_SHIFT & 0xF0FF:
		   if(is2nded)
		   {
              iscapslock^=1;
              is2nded=0;
			  return NO_KEY;
		   }
		case KEY_RIGHT_SHIFT:
/*			 termputch('!'); */
           isshifted^=1;
		   return NO_KEY;
		case KEY_2ND:
           is2nded^=1;
		   return NO_KEY;
		case KEY_DEL:
		   c=8;
		   break;
		case KEY_LOWER_ESC:
		   c=27;
		   break;
		case KEY_LOWER_ENTER:
		case KEY_UPPER_ENTER:
		case '\r':
           if(c=='\r' || enterisreturn)
           {
              if(mapreturn) c='\n'; else c='\r';
           }
		default:
		   if(!read) break;
		   if(isshifted || origc&MASKSHIFT) shiftheld=1; else shiftheld=0;
		   if(is2nded || origc&MASK2ND) secondheld=1; else secondheld=0;
		   c&=0xF0FF;
           if((shiftheld || iscapslock) && c<128 && isalpha(c)
               && !secondheld)
               {
                    if(shiftheld ^ iscapslock) c+='A'-'a';
               }
           else if((shiftheld /* || secondheld */) && c=='-')
			   c='_';
           else if(shiftheld && c<128 && isdigit(c))
			   c=")!@#$%^&*("[c-'0'];
           else if((/* secondheld || */ shiftheld) && c=='.')
			   c=':';
           else if((/* secondheld || */ shiftheld) && c==',')
               c='\'';
		   else if(secondheld)
		   {
			  switch(c)
			  {
				case 'e': c='*'; break;
				case 'i': c='?'; break;
				case 'o': c='"'; break;
				case 'p': c=';'; break;
				case 'q': c='+'; break;
				case 'r': c='/'; break;
				case 't': c='='; break;
				case 'w': c='-'; break;
                default: c|=MASK2ND; break;
			  }
              if(shiftheld) c|=MASKSHIFT;
		   }
           else if(shiftheld)
           {
               c|=MASKSHIFT;
           }
	 }
	if(!read)
		ozungetch(origc);
	else
        isshifted=is2nded=0;
	return c;
}
Exemple #16
0
int main(void)
{
	static Vector_t rot;
	static Vector_t t;
	static Point_t p[8];
	static unsigned c = 0;
	static int i;
	static int zf = 0;
#ifdef TIMING
    extern unsigned _oz64hz_word;
    static unsigned frames;
#endif
    //ozinitprofiler();
	//ozsetactivepage(1);
	//ozsetdisplaypage(0);
#ifdef TIMING
    frames=0;
    _oz64hz_word=0;
#endif
	while(c != 13) {
		//if(ozkeyhit()) c = ozngetch();
		//if(getk()) c = fgetc_cons();
		c=getk();
		switch(c) {
			case '1':
				zf -= 10;
				if(zf < -100) zf = -100;
				break;
			case '2':
				zf += 10;
				if(zf > 300) zf = 300;
				break;
			case '3':
				exit (0);
		}
		c = 0;
		for(i = 0; i < 8; i++) {
			ozcopyvector(&t,&cube[i]);
			ozrotatepointx(&t, rot.x);
			ozrotatepointy(&t, rot.y);
			t.z += zf; /* zoom factor */
			ozplotpoint(&t, &p[i]);
		}
		rot.y = (rot.y+1)%360;
		rot.x = (rot.x+2)%360;
		clg();
		/* top face */
		draw(p[0].x + MX, p[0].y + MY, p[1].x + MX, p[1].y + MY);
		draw(p[1].x + MX, p[1].y + MY, p[2].x + MX, p[2].y + MY);
		draw(p[2].x + MX, p[2].y + MY, p[3].x + MX, p[3].y + MY);
		draw(p[3].x + MX, p[3].y + MY, p[0].x + MX, p[0].y + MY);
		/* bottom face */
		draw(p[4].x + MX, p[4].y + MY, p[5].x + MX, p[5].y + MY);
		draw(p[5].x + MX, p[5].y + MY, p[6].x + MX, p[6].y + MY);
		draw(p[6].x + MX, p[6].y + MY, p[7].x + MX, p[7].y + MY);
		draw(p[7].x + MX, p[7].y + MY, p[4].x + MX, p[4].y + MY);
		/* side faces */
		draw(p[0].x + MX, p[0].y + MY, p[4].x + MX, p[4].y + MY);
		draw(p[1].x + MX, p[1].y + MY, p[5].x + MX, p[5].y + MY);
		draw(p[2].x + MX, p[2].y + MY, p[6].x + MX, p[6].y + MY);
		draw(p[3].x + MX, p[3].y + MY, p[7].x + MX, p[7].y + MY);
        //ozsetdisplaypage(!ozgetdisplaypage());
#ifdef TIMING
        frames++;
        if(_oz64hz_word>64*10)
        {
            static char buf[80];
            sprintf(buf,"%d frames in 10 seconds",frames);
            ozputs(0,0,buf);
            ozgetch();
            _oz64hz_word=0;
            frames=0;
        }
#endif
		//ozsetactivepage(!ozgetactivepage());
	}
}