From f634ec344627a206dd37e916f868febabbdaa1c6 Mon Sep 17 00:00:00 2001 From: Florian Schulze Date: Tue, 19 Feb 2002 16:13:29 +0000 Subject: [PATCH] More cleanups. Added get_pixel and set_pixel functions. --- config.h | 11 ----------- dos/gfx.c | 14 ++++++++++++++ fireworks.c | 25 ++++--------------------- globals.h | 6 +++++- main.c | 42 ++++++------------------------------------ sdl/gfx.c | 34 +++++++++++++++++++++------------- 6 files changed, 50 insertions(+), 82 deletions(-) diff --git a/config.h b/config.h index d96bcfa..14182b3 100644 --- a/config.h +++ b/config.h @@ -1,15 +1,4 @@ #ifndef __CONFIG_H #define __CONFIG_H -#ifdef USE_SDL -# define JNB_WIDTH 400 -# define JNB_HEIGHT 256 -#endif - -/* -#define __USE_XOPEN -#define __USE_BSD -#define __USE_POSIX -*/ - #endif diff --git a/dos/gfx.c b/dos/gfx.c index 64d6314..134d7ba 100644 --- a/dos/gfx.c +++ b/dos/gfx.c @@ -74,6 +74,20 @@ void clear_lines(int page, int y, int count, int color) memset((char *) (0xa0000 + (i+y) * 100 + __djgpp_conventional_base), 0, 100); } +int get_pixel(int page, int x, int y) +{ + outportw(0x3ce, (((x) & 3) << 8) + 0x04); + //outportw(0x3c4, ((1 << ((x) & 3)) << 8) + 0x02); + return *(char *) (0xa0000 + (y * 100 + (x >> 2)) + ((long) page << 15) - __djgpp_base_address); +} + +void set_pixel(int page, int x, int y, int color) +{ + //outportw(0x3ce, (((x) & 3) << 8) + 0x04); + outportw(0x3c4, ((1 << ((x) & 3)) << 8) + 0x02); + *(char *) (0xa0000 + (y * 100 + (x >> 2)) + ((long) page << 15) - __djgpp_base_address) = color; +} + void flippage(int page) { outportw(0x3d4, (page << 23) + 0x0d); diff --git a/fireworks.c b/fireworks.c index 87f6b86..3448ae4 100644 --- a/fireworks.c +++ b/fireworks.c @@ -68,12 +68,7 @@ void fireworks(void) stars[c1].x = stars[c1].old_x = (s1 << 16); stars[c1].y = stars[c1].old_y = (s2 << 16); stars[c1].col = s3; -#ifdef DOS - outportw(0x3ce, ((s1 & 3) << 8) + 0x04); - stars[c1].back[0] = stars[c1].back[1] = *(char *) (0xa0000 + s2 * 100 + (s1 >> 2) - __djgpp_base_address); -#else - stars[c1].back[0] = stars[c1].back[1] = *(char *) get_vgaptr(0, s1, s2); -#endif + stars[c1].back[0] = stars[c1].back[1] = get_pixel(0, s1, s2); } dj_set_nosound(0); @@ -178,15 +173,8 @@ void fireworks(void) update_objects(); for (c1 = 0; c1 < 300; c1++) { -#ifdef DOS - outportw(0x3ce, (((stars[c1].x >> 16) & 3) << 8) + 0x04); - outportw(0x3c4, ((1 << ((stars[c1].x >> 16) & 3)) << 8) + 0x02); - stars[c1].back[main_info.draw_page] = *(char *) (0xa0000 + ((int) main_info.draw_page << 15) + (stars[c1].y >> 16) * 100 + (stars[c1].x >> 18) - __djgpp_base_address); - *(char *) (0xa0000 + ((int) main_info.draw_page << 15) + (stars[c1].y >> 16) * 100 + (stars[c1].x >> 18) - __djgpp_base_address) = stars[c1].col; -#else - stars[c1].back[main_info.draw_page] = *(char *) get_vgaptr(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16); - *(char *) get_vgaptr(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16) = stars[c1].col; -#endif + stars[c1].back[main_info.draw_page] = get_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16); + set_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16, stars[c1].col); } dj_mix(); @@ -206,12 +194,7 @@ void fireworks(void) intr_sysupdate(); for (c1 = 299; c1 >= 0; c1--) { -#ifdef DOS - outportw(0x3c4, ((1 << ((stars[c1].old_x >> 16) & 3)) << 8) + 0x02); - *(char *) (0xa0000 + ((int) main_info.draw_page << 15) + (stars[c1].old_y >> 16) * 100 + (stars[c1].old_x >> 18) - __djgpp_base_address) = stars[c1].back[main_info.draw_page]; -#else - *(char *) get_vgaptr(main_info.draw_page, stars[c1].old_x >> 16, stars[c1].old_y >> 16) = stars[c1].back[main_info.draw_page]; -#endif + set_pixel(main_info.draw_page, stars[c1].old_x >> 16, stars[c1].old_y >> 16, stars[c1].back[main_info.draw_page]); } } diff --git a/globals.h b/globals.h index 97c7f63..7c6cde9 100644 --- a/globals.h +++ b/globals.h @@ -33,6 +33,9 @@ # endif #endif +#define JNB_WIDTH 400 +#define JNB_HEIGHT 256 + #ifndef USE_SDL #define KEY_PL1_LEFT 0xcb #define KEY_PL1_RIGHT 0xcd @@ -223,6 +226,8 @@ void wait_vrt(int mix); void flippage(int page); void clear_page(int page, int color); void clear_lines(int page, int y, int count, int color); +int get_pixel(int page, int x, int y); +void set_pixel(int page, int x, int y, int color); void setpalette(int index, int count, char *palette); void fillpalette(int red, int green, int blue); #ifdef DOS @@ -248,7 +253,6 @@ int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal); long filelength(int handle); #endif void fs_toggle(); -char *get_vgaptr(int, int, int); int intr_sysupdate(); #endif diff --git a/main.c b/main.c index e4788f5..916813e 100644 --- a/main.c +++ b/main.c @@ -1560,32 +1560,14 @@ int add_pob(int page, int x, int y, int image, char *pob_data) void draw_flies(int page) { - char *ptr1; - int c1,c2; + int c2; -#ifdef DOS - ptr1 = (char *) (0xa0000 + ((long) main_info.draw_page << 15) - __djgpp_base_address); - for (c1 = 0; c1 < 4; c1++) { - outportw(0x3ce, (c1 << 8) + 0x04); - outportw(0x3c4, ((1 << c1) << 8) + 0x02); - for (c2 = 0; c2 < NUM_FLIES; c2++) { - if ((flies[c2].x & 3) == c1) { - flies[c2].back[main_info.draw_page] = *(char *) (ptr1 + flies[c2].y * 100 + (flies[c2].x >> 2)); - flies[c2].back_defined[main_info.draw_page] = 1; - if (mask_pic[flies[c2].y * 400 + flies[c2].x] == 0) - *(char *) (ptr1 + flies[c2].y * 100 + (flies[c2].x >> 2)) = 0; - } - } - } -#else - ptr1 = (char *) get_vgaptr(main_info.draw_page, 0, 0); for (c2 = 0; c2 < NUM_FLIES; c2++) { - flies[c2].back[main_info.draw_page] = *(char *) (ptr1 + flies[c2].y * JNB_WIDTH + (flies[c2].x)); + flies[c2].back[main_info.draw_page] = get_pixel(main_info.draw_page, flies[c2].x, flies[c2].y); flies[c2].back_defined[main_info.draw_page] = 1; if (mask_pic[(flies[c2].y * JNB_WIDTH) + flies[c2].x] == 0) - *(char *) (ptr1 + flies[c2].y * JNB_WIDTH + (flies[c2].x)) = 0; + set_pixel(main_info.draw_page, flies[c2].x, flies[c2].y, 0); } -#endif } void draw_pobs(int page) @@ -1607,24 +1589,12 @@ void draw_pobs(int page) void redraw_flies_background(int page) { - char *ptr1; - int c1,c2; -#ifdef DOS - ptr1 = (char *) (0xa0000 + ((long) page << 15) - __djgpp_base_address); - for (c1 = 0; c1 < 4; c1++) { - outportw(0x3c4, ((1 << c1) << 8) + 0x02); - for (c2 = NUM_FLIES - 1; c2 >= 0; c2--) { - if ((flies[c2].old_x & 3) == c1 && flies[c2].back_defined[page] == 1) - *(char *) (ptr1 + flies[c2].old_y * 100 + (flies[c2].old_x >> 2)) = flies[c2].back[page]; - } - } -#else - ptr1 = (char *) get_vgaptr(page, 0, 0); + int c2; + for (c2 = NUM_FLIES - 1; c2 >= 0; c2--) { if (flies[c2].back_defined[page] == 1) - *(char *) (ptr1 + flies[c2].old_y * JNB_WIDTH + (flies[c2].old_x)) = flies[c2].back[page]; + set_pixel(page, flies[c2].old_x, flies[c2].old_y, flies[c2].back[page]); } -#endif } diff --git a/sdl/gfx.c b/sdl/gfx.c index 07277f7..04e12fd 100644 --- a/sdl/gfx.c +++ b/sdl/gfx.c @@ -7,6 +7,15 @@ static int vinited = 0; static unsigned char screen_buffer[JNB_WIDTH*JNB_HEIGHT*2]; +char *get_vgaptr(int page, int x, int y) +{ + if (page == 1) + return &screen_buffer[JNB_WIDTH*JNB_HEIGHT+((y * JNB_WIDTH) + x)]; + else + return &screen_buffer[(y * JNB_WIDTH) + x]; +} + + void open_screen(void) { int lval = 0; @@ -67,6 +76,18 @@ void clear_lines(int page, int y, int count, int color) } +int get_pixel(int page, int x, int y) +{ + return *(char *) get_vgaptr(page, x, y); +} + + +void set_pixel(int page, int x, int y, int color) +{ + *(char *) get_vgaptr(page, x, y) = color; +} + + void flippage(int page) { int h; @@ -93,15 +114,6 @@ void flippage(int page) } -char *get_vgaptr(int page, int x, int y) -{ - if (page == 1) - return &screen_buffer[JNB_WIDTH*JNB_HEIGHT+((y * JNB_WIDTH) + x)]; - else - return &screen_buffer[(y * JNB_WIDTH) + x]; -} - - void setpalette(int index, int count, char *palette) { SDL_Color colors[256]; @@ -359,11 +371,7 @@ void put_pob(int page, int x, int y, int image, char *pob_data, int mask, char * pob_ptr = &pob_data[pob_offset]; -#ifndef USE_SDL - vga_ptr = (char *) (0xa0000 + (long) (page << 15) + (long) y * 100L + ((x + c3) >> 2) + __djgpp_conventional_base); -#else vga_ptr = get_vgaptr(page, x, y); -#endif mask_ptr = (char *) (mask_pic + (y * 400) + x); for (c1 = 0; c1 < draw_height; c1++) { for (c2 = 0; c2 < draw_width; c2++) { -- 2.39.2