************************************************************************** * Direct memory access graphic functions. Created by Robert W Stiles. * * See notice at end of file. * ************************************************************************** There was a day when I got fed-up with the VDI putpixel and getpixel. There ploting speed was nothing less then SLOW! So I sent a little time and created a few routines myself. No dought there not the fastest, but they are many times faster then the VDI routines. Here is a list of then and there use. *************************************************************************** This is the function you must call before you can use any of the graphics function. It's responsible for setting up vector tables and allocating memory. int pinit(int max_x, int max_y, void *video_buffer, int planes); max_x = maximum resoltion in the x direction. max_y = maximum resoltion in the y direction. video_buffer = is the location of video ram or buffer. planes = number of video planes. Example 1: To run on ATARI ST monochrome display. pinit(640, 400, Logbase(), 1); Example 2: To run on FALCON030 256 color VGA display. pinit(640, 480, Logbase(), 8); Example 3: If you dont want to worry about it. Let VDI get the information. appl_init(); for ( i = 1; i < 10; work_in[i++] = 1 ); work_in[10] = 2; phys_handle = graf_handle( &gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox ); work_in[0] = handle = phys_handle; v_opnvwk( work_in, &handle, work_out ); vq_extnd(handle, 1, extend_out); pinit(work_out[0]+1, work_out[1]+1, (void *)Logbase(), extend_out[4]); ... (What ever you need to do). pexit(); v_clsvwk( handle ); appl_exit( ); Note: max_x and max_y doesnt have to be any ST/TT/FALCON standard resolution. Video_buffer can be any memory location. But you must make sure there is enough memory for the give resolution selected. Generally planes will be one of the following. 1,2,4,8,16. Value 16 isnt the number of planes. In this case it will configure the grahics functions to work in HIGHCOLOR mode. Which is 16 bits per pixel. *************************************************************************** This function releases allocated memory by. void pexit(void); Example: pexit(); *************************************************************************** The following routines are the indirect graphics routines. If you use these it will make proramming easier between the different resolutions. Because pinit() will assign the correct graphic function to the resolution selected. *************************************************************************** Plot a pixel at x,y with index color. int (*p_pixel)(int x, int y, int color); Example: To place a pixel at location 100, 100, with color 2. (*p_pixel)(100, 100, 2); *************************************************************************** Get the color index value at location x,y. int (*g_pixel)(int x, int y); Example: To return the color value a location 100, 100 (*g_pixel)(100, 100, 2); *************************************************************************** Draw a line from x1,y1 to x2,y2 with index color. int (*d_line)(int x1, int y1, int x2, int y2, int color); Example: To plot a line from 100,100 to 200,200 with color 3 (*d_line)(100, 100, 200, 200, 3); *************************************************************************** Draw a horizontal line from x1,x2 on y with index color. int (*d_hline)(int x1, int x2, int y, int color); Example: To plot a horizontal line from 100,100 on 200 with color 3 (*d_hline)(100, 100, 200, 3); *************************************************************************** Convert color index to raw data, directly usable in ATARI video ram. This is usefull when plot data that runs in horizonal directions. Like .GIF, .BMP, and other picture files. However it does have a few restrictions. 1. Both buffers have to be WORD aligned. 2. Conversion is done in groups of 16 bytes (color indexes). Both buffers can be the same. If the destination data location is the same as the source data. Then the source data will overwrite the destination after the conversion is completed. This routine is much faster the p_pixel() when ploting data in sequence. It's also written in assembler. Which means it will only run with 'C' function compiled with Pure 'C'. Pure 'C' uses registers to pass data. If your compiler uses a different method you'll have to modify the source. int (*byte2raw)(char *colors, char *buffer); Example: To plot a complete horizontal line of data to the video ram. char color[640] = { 1,4,35,6,7,44,44,...}; screen = Logbase(); for (x = 0; x < 640;) { screen += (*byte2raw)(&color[x], screen); x += 16; screen += (*byte2raw)(&color[x], screen); x += 16; screen += (*byte2raw)(&color[x], screen); x += 16; screen += (*byte2raw)(&color[x], screen); x += 16; } byte2raw() returns the number of bytes written to the buffer. This makes incrementing the buffer easier. Since each video resolution will require different amounts of memory. *************************************************************************** Draw a circle at coordinates x,y with radius and color. void circle(int x, int y, int radius, int color); Example: To display a circle at position 100,100 with a radius of 50 using the color index of 3. circle(100, 100, 50, 3); *************************************************************************** Draw a filled circle at coordinates x,y with radius and color. void disk(int x, int y, int radius, int color); Example: To display a filled circle at position 100,100 with a radius of 50 using the color index of 3. disk(100, 100, 50, 3); *************************************************************************** These are the direct calling functions. *************************************************************************** See p_pixel for there use: int set_pixel1(int x, int y, int color); /* Monochrome */ int set_pixel2(int x, int y, int color); /* 4 color */ int set_pixel4(int x, int y, int color); /* 16 color */ int set_pixel8(int x, int y, int color); /* 256 color */ int set_pixel16(int x, int y, int color); /* Highcolor */ *************************************************************************** See g_pixel for there use: int get_pixel1(int x, int y); /* Monochrome */ int get_pixel2(int x, int y); /* 4 color */ int get_pixel4(int x, int y); /* 16 color */ int get_pixel8(int x, int y); /* 256 color */ int get_pixel16(int x, int y); /* Highcolor */ *************************************************************************** See byte2raw for there use: int byte2raw8(char *color, char *buffer); /* Monochrome */ int byte2raw4(char *color, char *buffer); /* 4 color */ int byte2raw2(char *color, char *buffer); /* 16 color */ int byte2raw1(char *color, char *buffer); /* 256 color */ *************************************************************************** NOTICE: Since the files herein are only source code. And once released into the public domain. I will not have much control over what happens to it. So here goes... User or programmer are responsible for any negative effects that results from the use of this software in either hardware or softwware. No warranties are in effect either expressed or implied. blaw, blaw, blaw.... Copyright (C) 1994 by Robert W Stiles I hereby grant the release of this source code into the public domain for free distribution and use. All other rights (if any) are reserved. I can be reached at the following locations. Amature Packet Radio: KD6GEO @ N5RKJ.#CTX.TX.USA.NOAM Internet: r.stilesstil@genis.com Genie: R.STILESSTIL