Main Page Data Structures File List Data Fields Globals Related Pages

# mp3v2.cpp.002.cpp

Go to the documentation of this file.

    00001 /*  mp3player hardware test
    00002
    00003     15.05.2001: tk, initial implementation.
    00004
    00005     Copyright (c)2000 by Thomas Kindler, thomas.kindler@gmx.de
    00006
    00007     This program is free software; you can redistribute it and/or
    00008     modify it under the terms of the GNU General Public License as
    00009     published by the Free Software Foundation; either version 2 of
    00010     the License, or (at your option) any later version. Read the
    00011     full License at http://www.gnu.org/copyleft for more details.
    00012 */
    00013
    00014 // include files -----
    00015 //
    00016 #include <mem.h>
    00017 #include <malloc.h>
    00018 #include <stdio.h>
    00019 #include <math.h>
    00020 #include <conio.h>
    00021 #include <io.h>
    00022 #include <stdlib.h>
    00023 #include "misc.h"
    00024 #include "ztimer.h"
    00025 #include "vs1001.h"
    00026 #include "rtos.h"
    00027 #include "checkbios.h"
    00028 #include "gfxcore.h"
    00029 #include "gfxdriver.h"
    00030 #include "gfxutil.h"
    00031 #include "gfxfont.h"
    00032 #include "remote.h"
    00033 #include "ztimer.h"
    00034
    00035 Font   *font;
    00036
    00037
    00051 void GFX_LineX(Graphics *gfx, int x1, int y1, int x2, int y2)
    00052 {
    00053   int dx = (x2-x1)*2;
    00054   if (dx<0) dx=-dx;
    00055
    00056   int dy = (y2-y1)*2;
    00057   if (dy<0) dy=-dy;
    00058
    00059
    00060   if (dx > dy) {
    00061     int fraction = dy - (dx >> 1);   // same as 2*dy - dx
    00062
    00063     // always draw left-to-right.
    00064     //
    00065     if (x2<x1) { swap(x1, x2);  swap(y1, y2); }
    00066
    00067     int w = (x2-x1)+1;
    00068     char *dst = &gfx->bitmap->bmBits[x1 + (y1>>3)*gfx->bitmap->width];
    00069     unsigned char mask = 1 << (y1 & 7);
    00070
    00071     if (y1 < y2) {
    00072       while (w--) {
    00073         *dst++ |= mask;
    00074         if (fraction >= 0) {
    00075           mask <<= 1;
    00076           if (!mask) {
    00077             mask = 0x01;
    00078             dst += gfx->bitmap->width;
    00079           }
    00080           fraction -= dx;
    00081         }
    00082         fraction += dy;
    00083       }
    00084     } else {
    00085       while (w--) {
    00086         *dst++ |= mask;
    00087         if (fraction >= 0) {
    00088           mask >>= 1;
    00089           if (!mask) {
    00090             mask = 0x80;
    00091             dst -= gfx->bitmap->width;
    00092           }
    00093           fraction -= dx;
    00094         }
    00095         fraction += dy;
    00096       }
    00097     }
    00098
    00099   } else {
    00100     int fraction = dx - (dy >> 1);   // same as 2*dy - dx
    00101
    00102     // always draw top-down
    00103     //
    00104     if (y2<y1) { swap(x1, x2);  swap(y1, y2); }
    00105     int h = (y2-y1)+1;
    00106
    00107     char *dst = &gfx->bitmap->bmBits[x1 + (y1>>3)*gfx->bitmap->width];
    00108     unsigned char mask = 1 << (y1 & 7);
    00109
    00110     if (x1 < x2) {
    00111       while (h--) {
    00112         *dst  |= mask;
    00113         mask <<= 1;
    00114         if (!mask) {
    00115           mask = 1;
    00116           dst += gfx->bitmap->width;
    00117         }
    00118         if (fraction >= 0) {
    00119           dst++;
    00120           fraction -= dy;
    00121         }
    00122         fraction += dx;
    00123       }
    00124     } else {
    00125       while (h--) {
    00126         *dst |= mask;
    00127         mask <<= 1;
    00128         if (!mask) {
    00129           mask = 1;
    00130           dst += gfx->bitmap->width;
    00131         }
    00132         if (fraction >= 0) {
    00133           dst--;
    00134           fraction -= dy;
    00135         }
    00136         fraction += dx;
    00137       }
    00138     }
    00139
    00140   }
    00141 }
    00142
    00143
    00144 void  gfxTest()
    00145 {
    00146   Bitmap *screen = BM_Alloc(122, 32);
    00147   Bitmap *logo   = BM_Load("test.bmp");
    00148
    00149   Graphics  gfx;
    00150   GFX_Init(&gfx, screen);
    00151   GFX_SetFont(&gfx, font);
    00152
    00153
    00154   BM_Info(screen);
    00155   BM_Info(logo);
    00156
    00157   int x=32, y=16, u=8, v=8, w=16, h=16, op = 0;
    00158   while (!kbhit()) {
    00159
    00160     long key = RC_GetKey();
    00161 //    printf("%c", 12);
    00162     switch (key & ~RCKEY_REPEAT) {
    00163       case 0x10d52a10:   return;
    00164
    00165       case 0x10d52a14:   x--; break;
    00166       case 0x10d52a02:   x++; break;
    00167       case 0x10d52a18:   y--; break;
    00168       case 0x10d52a01:   y++; break;
    00169
    00170       case 0x10d52a17:   u--; break;
    00171       case 0x10d52a08:   u++; break;
    00172       case 0x10d52a04:   v--; break;
    00173       case 0x10d52a07:   v++; break;
    00174
    00175       case 0x10d52a1a:   w--; break;
    00176       case 0x10d52a03:   w++; break;
    00177       case 0x10d52a06:   h--; break;
    00178       case 0x10d52a09:   h++; break;
    00179
    00180       case 0x10d52a13:   op++; break;
    00181
    00182       case 0x10d52a19:
    00183         BM_Save(screen, "www\\shot.bmp");
    00184         break;
    00185
    00186       default:
    00187         printf("unkown code: 0x%lx\n", key);
    00188         break;
    00189     }
    00190     BM_Clear(screen);
    00191
    00192 /*
    00193     GFX_PrintAt(&gfx, 0,  0, "PalmOS Fonts rul0r3n!");
    00194     GFX_PrintAt(&gfx, 0,  8, "K/oS MP3 Player v2");
    00195     GFX_PrintfAt(&gfx, 0, 16, "www.kreapc.de op=%d", op);
    00196     op &= 15;
    00197     BM_Blit(screen, x, y, logo, u, v, -1, -1, op);
    00198 */
    00199
    00200 /*    GFX_SetFillStyle(&gfx, xHatchFill);
    00201     ZTimer_Start();
    00202     GFX_FillRect(&gfx, x, y, w, h);
    00203     int time1 = ZTimer_Stop();
    00204     GFX_MoveTo(&gfx, 0, 0);
    00205     GFX_Printf(&gfx, "%d,%d,%d,%d: %d us ", x, y, w, h, time1);
    00206 */
    00207
    00208     ZTimer_Start();
    00209     if (w&1)
    00210       GFX_LineX(&gfx, 1, 1, 120, 30);
    00211     else
    00212       GFX_LineX(&gfx, x, y, x+u, y+v);
    00213     int time = ZTimer_Stop();
    00214
    00215     GFX_PrintfAt(&gfx, 61, -1, "%d us", time);
    00216
    00217     LCD_Update(screen);
    00218   }
    00219 }
    00220
    00221
    00222 void main(int argc, char* argv[])
    00223 {
    00224   if (!CheckBIOS())
    00225     return;
    00226
    00227   LCD_Init();
    00228   RC_Init();
    00229   VS_Init();
    00230
    00231   font = GFX_LoadFont("fonts\\compac~1.fnt");
    00232   font->firstChar--;
    00233   //  font = GFX_LoadFont("fonts\\foo.fnt");
    00234   if (font)
    00235     gfxTest();
    00236
    00237   VS_Done();
    00238   RC_Done();
    00239   LCD_Done();
    00240 }