Main Page | Data Structures | File List | Data Fields | Globals

ex8.c

00001 /*=========================================================================
00002 
00003 GFX EXAMPLE CODE - #8
00004         "alphabets"
00005 
00006 Copyright (C) 2004  Rafael de Oliveira Jannone
00007 
00008 This example's source code is Public Domain.
00009 
00010 WARNING: The author makes no guarantees and holds no responsibility for 
00011 any damage, injury or loss that may result from the use of this source 
00012 code. USE IT AT YOUR OWN RISK.
00013 
00014 Contact the author:
00015         by e-mail : rafael AT jannone DOT org
00016         homepage  : http://jannone.org/gfxlib
00017         ICQ UIN   : 10115284
00018 
00019 =========================================================================*/
00020 
00021 #include <stdio.h>
00022 #include "gfx.h"
00023 
00024 #define VRAM_OFFS       0
00025 #define FILE_OFFS       7
00026 #define MAX_BUF         (256 * 8)
00027 
00028 // binary data
00029 
00030 #asm
00031 
00032 psect data
00033 
00034 global _square
00035 _square:
00036         defb 11100111B
00037         defb 10000001B
00038         defb 10000001B
00039         defb 00000000B
00040         defb 00000000B
00041         defb 10000001B
00042         defb 10000001B
00043         defb 11100111B
00044 
00045 #endasm
00046 
00047 // cursor shape
00048 extern u_char square[];
00049 
00050 // zooms into a char shape
00051 void preview_char(u_char* p) {
00052         int x, y, addr;
00053         u_char c;
00054 
00055         for (y = 0; y < 8; y++) {
00056                 addr = map_pixel(22 * 8, (y << 3) + 8);
00057                 c = *p++;
00058                 for (x = 0; x < 8; x++) {
00059                         fill(addr, (c & 128) ? 255 : 0, 8);
00060                         c <<= 1;
00061                         addr += 8;
00062                 }
00063         }
00064 }
00065 
00066 // do the whole preview table and stuff :)
00067 void do_preview(u_char* buf) {
00068         int asc, x, y, addr;
00069         u_char st;
00070 
00071         set_color(15, 4, 4);
00072         set_sprite_8(0, square);
00073 
00074         fill(MODE2_ATTR, 0xF0, MODE2_MAX);
00075 
00076         // start blitting buffer at pixel (16,16)
00077         addr = map_block(16, 16);
00078 
00079         // 16 chars of width (*8), 16 "lines", jump 256 in VRAM for each line
00080         blit_ram_vram(buf, addr, 16 * 8, 16, 16 * 8, 256);
00081 
00082         // fill yellow background
00083         blit_fill_vram(MODE2_ATTR + map_block(8, 8), 0x1A, 8 * 18, 18, 256);
00084 
00085         x = 0; y = 0;
00086 
00087         // preview loop
00088         while (!get_trigger(0)) {
00089                 // move the cursor and set the zooming
00090                 st = st_dir[get_stick(0)];
00091 
00092                 x += (st & st_right) ? 1 : ((st & st_left) ? -1 : 0);
00093                 y += (st & st_down) ? 1 : ((st & st_up) ? -1 : 0);
00094 
00095                 x &= 15;
00096                 y &= 15;
00097                 asc = (y << 4) + x;
00098                 put_sprite_8(0, (x + 2) << 3, (y + 2) << 3, 0, 9);
00099 
00100                 preview_char(buf + (asc << 3));
00101         }       
00102 }
00103 
00104 main(int argc, char *argv[]) {
00105         FILE* f;
00106         bool preview;
00107         u_char buf[MAX_BUF];
00108 
00109         // bouring argv stuff
00110         if (!--argc) {
00111                 printf("Usage: ex8 [-]file.alf\n");
00112                 printf("\t- : preview mode\n");
00113                 printf("file must be of type GRAPHOS ALPHABET (.ALF)\n");
00114                 return 1;
00115         }
00116 
00117         preview = false;
00118 
00119         ++argv;
00120         if (*argv[0] == '-') {
00121                 (*argv)++;
00122                 preview = true;
00123                 printf("preview mode on\n");
00124         }
00125 
00126         // read file
00127         f = fopen(*argv, "rb");
00128 
00129         if (!f) {
00130                 printf("couldn't open file %s\n", *argv);
00131                 return 2;
00132         }
00133 
00134         fseek(f, FILE_OFFS, 0);
00135         fread(buf + 8, 1, MAX_BUF - 8, f);
00136         fclose(f);
00137 
00138         buf[0]=buf[1]=buf[2]=buf[3]=buf[4]=buf[5]=buf[6]=buf[7]=0;
00139 
00140         // here is the thing: when not previewing, the vwrite will set
00141         // your whole char table with the given alphabet. nice :)
00142 
00143         set_mode((preview) ? mode_2 : mode_1);
00144 
00145         if (preview) {
00146                 do_preview(buf);
00147                 set_mode(mode_0);
00148         } else
00149                 vwrite(buf + 8, VRAM_OFFS, MAX_BUF);
00150 }

Generated on Thu Mar 3 19:55:01 2005 for GFX lib by  doxygen 1.4.1