From: sparky4 Date: Sun, 4 May 2014 01:46:19 +0000 (-0500) Subject: new file: 16/BANKBLIT.C X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=a1fbf46bbb19827c9bec7fe3db49414cc364f800;p=16.git new file: 16/BANKBLIT.C new file: 16/BANKBLIT.EXE modified: 16/DOS_GFX.EXE modified: 16/Project 16.bfproject new file: 16/Q.BAT modified: 16/dos_gfx.cpp modified: 16/dos_gfx.h --- diff --git a/16/BANKBLIT.C b/16/BANKBLIT.C new file mode 100644 index 00000000..306f6c45 --- /dev/null +++ b/16/BANKBLIT.C @@ -0,0 +1,415 @@ +/*---------------------------------------------------------------------------- +blit() function for VBE 1.x banked framebuffer +Chris Giese http://my.execpc.com/~geezer/ +This code is public domain (no copyright). +You can do whatever you want with it. + +Compile with any of the following DOS compilers: +- Turbo C++ 1.0 +- Borland C++ 3.1 +- 16-bit Watcom C +- DJGPP + +April 4, 2008 +- Initial release + +More notes: +- The 'BPP' macro can be changed to 2, 3, or 4 to work with color + depths 16, 24, and 32, respectively. BPP can also be a run- + time variable; letting you use the same blit() function for + various color depths. +- Some video boards (Intel i810 integrated video) report compliance + with VBE 2.x but _still_ do not support a linear framebuffer +- Left as an exercise for the reader: it should be easy to convert + blit_mem_to_fb() to blit_fb_to_mem() +- Left as an exercise for the reader: it should be easy to convert + blit_mem_to_fb() to blot_fb(); a function that draws a solid + filled rectangle. (Hint: replace MEMCPY()s with MEMSET()s) +- To handle arbitrary blitting in a system with a banked framebuffer, + you need four functions: blit_mem_to_mem(), blit_mem_to_fb(), + blit_fb_to_mem(), and blit_fb_to_fb() +----------------------------------------------------------------------------*/ +#include /* memset(), [_f]memcpy() */ +/* EOF, FILE, fopen(), fwrite(), fputc(), fclose(), remove(), printf() */ +#include +#include /* getch(), outp[ortb]() */ +/* union REGS, struct SREGS, int86(), int86x() */ +#include /* FP_SEG(), FP_OFF(), MK_FP() */ +#if 0 +/* C99 fixed-width types */ +#include +#else +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; +#endif + +#if defined(__TURBOC__) +#if __TURBOC__==0x401 +#error Sorry, 'huge' is broken in Turbo C++ 3.0 +#endif + +/* This code exposes some bugs in Borland C++ 3.1, so... */ +#if __TURBOC__==0x410 +#pragma option -Od /* ...disable all optimizations */ +#endif + +#define HUGE huge +#define MEMCPY(D,S,N) _fmemcpy(D,S,N) +#define MEMSET(D,C,N) _fmemset(D,C,N) + +#elif defined(__WATCOMC__)&&!defined(__386__) +#define outportb(P,V) outp(P,V) +#define HUGE huge +#define MEMCPY(D,S,N) _fmemcpy(D,S,N) +#define MEMSET(D,C,N) _fmemset(D,C,N) + +#elif defined(__DJGPP__) +/* __djgpp_conventional_base, __djgpp_nearptr_enable() */ +#include +#include /* __dpmi_regs, __dpmi_int(), __dpmi_allocate_dos_memory() */ +#include /* _CRT0_FLAG_NEARPTR, _crt0_startup_flags */ + +#define __386__ 1 +#define HUGE /* nothing */ +#define MEMCPY(D,S,N) memcpy(D,S,N) +#define MEMSET(D,C,N) memset(D,C,N) + +#else +#error Sorry, unsupported compiler +#endif + +#define MIN(X,Y) (((X) < (Y)) ? (X) : (Y)) + +/* structure used by INT 10h AX=4F01h */ +#pragma pack(1) +typedef struct +{ + uint16_t mode_attrib; /* b5=1 for non-VGA mode */ + uint8_t win_a_attrib; + uint8_t win_b_attrib; + uint16_t k_per_gran; + uint16_t win_size; + uint16_t win_a_seg; + uint16_t win_b_seg; + char reserved1[4]; +/* this is not always the expected value; +rounded up to the next power of 2 for some video boards: */ + uint16_t bytes_per_row; +/* OEM modes and VBE 1.2 only: */ + uint16_t wd; + uint16_t ht; + uint8_t char_wd; + uint8_t char_ht; + uint8_t planes; + uint8_t depth; + uint8_t banks; + uint8_t memory_model; + uint8_t k_per_bank; + uint8_t num_pages; /* ? */ + char reserved2; +/* VBE 1.2 only */ + uint8_t red_width; + uint8_t red_shift; + uint8_t green_width; + uint8_t green_shift; + uint8_t blue_width; + uint8_t blue_shift; + char reserved3[3]; + uint32_t lfb_adr; + char reserved4[212]; +} vbe_mode_info_t; + +typedef struct +{ + unsigned wd, ht; + unsigned long bytes_per_row; + unsigned char HUGE *raster; +} img_t; + +typedef struct +{ + int src_x, src_y, dst_x, dst_y; + unsigned wd, ht; +} clip_t; + +static img_t g_fb; +static unsigned g_use_win_a, g_gran_per_64k; +/***************************************************************************** +no _fmemcpy() in Turbo C++ 1.0 +*****************************************************************************/ +#if defined(__TURBOC__) +#if __TURBOC__<0x300 +void far * far _fmemcpy(void far *dst_ptr, const void far *src_ptr, + unsigned n) +{ + unsigned char huge *dst = dst_ptr; + unsigned char huge *src = src_ptr; + + for(; n != 0; n--) + { + *dst = *src; + dst++; + src++; + } + return dst_ptr; +} +#endif +#endif +/***************************************************************************** +*****************************************************************************/ +static void set_bank(unsigned b) +{ + static unsigned curr_bank = -1u; +/**/ + union REGS regs; + + if(b == curr_bank) + return; + curr_bank = b; + regs.x.ax = 0x4F05; +/* g_use_win_a and g_gran_per_64k were set by INT 10h AX=4F01h */ + regs.x.bx = g_use_win_a ? 0x0000 : 0x0001; + regs.x.dx = b * g_gran_per_64k; + int86(0x10, ®s, ®s); +} +/***************************************************************************** +If using Borland C, compile this without optimizations. +Even without optimizations, it probably won't work with Turbo C++ 3.0 +*****************************************************************************/ +#define BPP 1 /* bytes per pixel */ +static void blit_mem_to_fb(img_t *src_img, clip_t *clip) +{ + unsigned bank, y, row_with_bank_switch, max_y; + unsigned char HUGE *src; + unsigned long off32; + uint16_t off16, i; + + src = src_img->raster + + src_img->bytes_per_row * clip->src_y + clip->src_x * BPP; +/* calculate 32-bit offset into framebuffer corresponding to +(clip->dst_x, clip->dst_y) */ + off32 = g_fb.bytes_per_row * clip->dst_y + clip->dst_x * BPP; +/* use low 16 bits for offset into 64K bank; use top 16 bits for bank */ + off16 = (uint16_t)off32; + off32 >>= 16; + bank = (uint16_t)off32; +/* set bank and increment bank number */ + set_bank(bank); + bank++; + for(y = clip->dst_y; ; ) + { +/* in which row does the next bank-switch occur? */ + off32 = bank; + off32 <<= 16; + row_with_bank_switch = (unsigned) + (off32 / g_fb.bytes_per_row); +/* blit until we reach that row or until we reach (clip->dst_y + clip->ht) */ + max_y = MIN(clip->dst_y + clip->ht, row_with_bank_switch); + for(; y < max_y; y++) + { + MEMCPY(g_fb.raster + off16, src, clip->wd * BPP); + off16 += g_fb.bytes_per_row; + src += src_img->bytes_per_row; + } +/* exit now if done */ + if(y >= clip->dst_y + clip->ht) + break; +/* else it's a row with bank switch. There are 3 possibilities: +line of pixels in this row starts AFTER bank switch */ + if(off16 < g_fb.bytes_per_row) /* overflowed 64K (clever!) */ + { + set_bank(bank); + MEMCPY(g_fb.raster + off16, src, clip->wd * BPP); + } +/* line of pixels in this row ends BEFORE bank switch */ + else if(off16 + (unsigned long)clip->wd * BPP <= 0x10000L) + { + MEMCPY(g_fb.raster + off16, src, clip->wd * BPP); + set_bank(bank); + } +/* line of pixels in this row STRADDLES bank switch */ + else + { + i = (uint16_t)(0x10000uL - off16); + MEMCPY(g_fb.raster + off16, src + 0, + i); + set_bank(bank); + MEMCPY(g_fb.raster + 0 , src + i, + clip->wd * BPP - i); + } + off16 += g_fb.bytes_per_row; + src += src_img->bytes_per_row; + bank++; + y++; + } +} +/***************************************************************************** +*****************************************************************************/ +int main(void) +{ + static const unsigned vbe_mode_num = 0x101; /* 640x480x256 */ +/* 14x14 test bitmap */ + static unsigned char raster[] = + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x02\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x03\x03\x03\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x04\x04\x04\x04\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x05\x05\x05\x05\x05\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x06\x06\x06\x06\x06\x06\x06\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x07\x07\x07\x07\x07\x07\x07\x07\x08\x09\x0A\x0B\x0C\x0D" + "\x08\x08\x08\x08\x08\x08\x08\x08\x08\x09\x0A\x0B\x0C\x0D" + "\x09\x09\x09\x09\x09\x09\x09\x09\x09\x09\x0A\x0B\x0C\x0D" + "\x0A\x0A\x0A\x0A\x0A\x0A\x0A\x0A\x0A\x0A\x0A\x0B\x0C\x0D" + "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0C\x0D" + "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0D" + "\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D\x0D"; +/**/ + union REGS regs; + unsigned i; + clip_t clip; + img_t img; + +#if !defined(__386__) + static vbe_mode_info_t vbe_mode_info; + struct SREGS sregs; + +/* get info for VBE mode */ + regs.x.ax = 0x4F01; + regs.x.cx = vbe_mode_num; + sregs.es = FP_SEG(&vbe_mode_info); + regs.x.di = FP_OFF(&vbe_mode_info); + int86x(0x10, ®s, ®s, &sregs); + if(regs.x.ax != 0x004F) + { + printf("Error getting info for VBE mode 0x%X\n", + vbe_mode_num); + return 1; + } +/* init g_fb */ + g_fb.wd = vbe_mode_info.wd; + g_fb.ht = vbe_mode_info.ht; + g_fb.bytes_per_row = vbe_mode_info.bytes_per_row; + g_gran_per_64k = 64 / vbe_mode_info.k_per_gran; + if(vbe_mode_info.win_a_attrib == 7) + { + g_fb.raster = (unsigned char HUGE *) + MK_FP(vbe_mode_info.win_a_seg, 0); + g_use_win_a = 1; + } + else if(vbe_mode_info.win_b_attrib == 7) + { + g_fb.raster = (unsigned char HUGE *) + MK_FP(vbe_mode_info.win_b_seg, 0); + g_use_win_a = 0; + } + else + { + printf("Error locating banked framebuffer " + "for VBE mode 0x%X\n", vbe_mode_num); + return -1; + } +#else /* if defined(__DJGPP__) */ + vbe_mode_info_t *vbe_mode_info; + int conv_mem_seg, conv_mem_sel; + __dpmi_regs dregs; + +/* turn off data segment limit, for nearptr access */ + if(!(_crt0_startup_flags & _CRT0_FLAG_NEARPTR)) + { + if(!__djgpp_nearptr_enable()) + { + printf("Error: can't enable near pointer " + "access to framebuffer (WinNT/2k/XP?)\n"); + return 1; + } + } +/* allocate conventional memory for INT 10h AX=4F01h buffer */ + conv_mem_seg = __dpmi_allocate_dos_memory(256 / 16, &conv_mem_sel); + if(conv_mem_seg == -1) + { + printf("Error: can't allocate conventional memory\n"); + return 1; + } + vbe_mode_info = (vbe_mode_info_t *) + (conv_mem_seg * 16uL + __djgpp_conventional_base); +printf("vbe_mode_info: sel=0x%X, real-mode seg=0x%X, linear=0x%lX, near=0x%p\n", + conv_mem_sel, conv_mem_seg, conv_mem_seg * 16uL, vbe_mode_info); +/* get info for VBE mode */ + dregs.x.ax = 0x4F01; + dregs.x.cx = vbe_mode_num; + dregs.x.es = conv_mem_seg; + dregs.x.di = 0; + __dpmi_int(0x10, &dregs); + if(dregs.x.ax != 0x004F) + { + printf("Error getting info for VBE mode 0x%X\n", + vbe_mode_num); + return 1; + } +/* init g_fb */ + g_fb.wd = vbe_mode_info->wd; + g_fb.ht = vbe_mode_info->ht; + g_fb.bytes_per_row = vbe_mode_info->bytes_per_row; + g_gran_per_64k = 64 / vbe_mode_info->k_per_gran; + if(vbe_mode_info->win_a_attrib == 7) + { + g_fb.raster = (unsigned char HUGE *) + (vbe_mode_info->win_a_seg * 16uL + + __djgpp_conventional_base); + g_use_win_a = 1; + } + else if(vbe_mode_info->win_b_attrib == 7) + { + g_fb.raster = (unsigned char HUGE *) + (vbe_mode_info->win_b_seg * 16uL + + __djgpp_conventional_base); + g_use_win_a = 0; + } + else + { + printf("Error locating banked framebuffer " + "for VBE mode 0x%X\n", vbe_mode_num); + return -1; + } +#endif +/* init img */ + img.wd = 14; + img.ht = 14; + img.bytes_per_row = img.wd; + img.raster = raster; +/* init clip_t */ + clip.wd = img.wd; + clip.ht = img.ht; + clip.src_x = 0; + clip.src_y = 0; +/* set graphics mode */ + regs.x.bx = vbe_mode_num; + regs.x.ax = 0x4F02; + int86(0x10, ®s, ®s); +/* green palette */ +#define VGA_DAC_WRITE_INDEX 0x3C8 +#define VGA_DAC_DATA 0x3C9 + outportb(VGA_DAC_WRITE_INDEX, 0); + for(i = 0; i < 16; i++) + { + outportb(VGA_DAC_DATA, /* red= */0 >> 2); + outportb(VGA_DAC_DATA, /* green= */i * 3); + outportb(VGA_DAC_DATA, /* blue= */0 >> 2); + } +/* test banked blit function */ + clip.dst_y = 0; + for(; clip.dst_y + clip.ht < g_fb.ht; clip.dst_y += clip.ht) + { + clip.dst_x = 0; + for(; clip.dst_x + clip.wd < g_fb.wd; clip.dst_x += clip.wd) + blit_mem_to_fb(&img, &clip); + } + if(getch() == 0) + (void)getch(); +/* set text mode */ + regs.x.ax = 0x0003; + int86(0x10, ®s, ®s); + return 0; +} diff --git a/16/BANKBLIT.EXE b/16/BANKBLIT.EXE new file mode 100644 index 00000000..98f92de9 Binary files /dev/null and b/16/BANKBLIT.EXE differ diff --git a/16/DOS_GFX.EXE b/16/DOS_GFX.EXE index bbd903d7..1cdab212 100644 Binary files a/16/DOS_GFX.EXE and b/16/DOS_GFX.EXE differ diff --git a/16/Project 16.bfproject b/16/Project 16.bfproject index b0ae9e97..75219118 100644 --- a/16/Project 16.bfproject +++ b/16/Project 16.bfproject @@ -1,13 +1,21 @@ c2e.convert_special: 0 e2c.convert_num: 0 -openfiles: /dos/z/16/16/dos_gfx.h:0:0:0: +openfiles: /dos/z/16/16/dos_gfx.cpp:6903:6589:1: +openfiles: /dos/z/16/16/dos_gfx.h:1122:268:0: +openfiles: /dos/z/16/16/dos_kb.c:1870:1395:0: openfiles: /dos/z/16/16/dos_kb.h:0:0:0: -openfiles: /dos/z/16/16/lib_com.h:0:0:0: -openfiles: /dos/z/16/16/dos_kb.c:0:0:0: -openfiles: /dos/z/16/16/dos_gfx.cpp:0:0:0: openfiles: /dos/z/16/16/lib_com.cpp:0:0:0: +openfiles: /dos/z/16/16/lib_com.h:0:0:0: openfiles: /dos/z/16/16/16.txt:0:0:0: -openfiles: /dos/z/16/16/project16.txt:0:0:1: +openfiles: /dos/z/16/16/project16.txt:1737:476:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/FONT1.H:0:0:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/FONT2.H:0:0:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/TAURON.H:0:0:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/MODES_C.INC:0:7495:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/PALETTE.INC:1213:2412:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/CLEAR.CPP:1394:2142:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/MODES.CPP:0:0:0: +openfiles: /dos/z/4x4_16/tauron/C_SRC/TESTS.CPP:3437:3167:0: snr_recursion_level: 0 convertcolumn_horizontally: 0 adv_open_matchname: 0 @@ -19,12 +27,14 @@ view_left_panel: 0 default_mime_type: text/plain e2c.convert_xml: 1 c2e.convert_iso: 0 -opendir: file:///dos/z/16/16 +opendir: file:///dos/z/4x4_16/tauron/C_SRC wrap_text_default: 0 bookmarks_filename_mode: 1 +ssearch_text: fill_plane( snr_casesens: 0 view_blocks: 1 name: project 16 +replacelist: てすと fb_show_hidden_f: 0 editor_tab_width: 4 show_visible_spacing: 1 @@ -38,10 +48,27 @@ ssearch_regex: 0 e2c.convert_iso: 0 ssearch_casesens: 0 charmap_block: 1 -recent_files: file:///dos/z/16/16/16.txt +recent_files: file:///dos/z/16/16/dos_gfx.h +recent_files: file:///dos/z/16/16/lib_com.cpp +recent_files: file:///dos/z/16/16/lib_com.h +recent_files: file:///dos/z/16/16/dos_kb.h +recent_files: file:///dos/z/16/16/dos_kb.c +recent_files: file:///dos/z/16/16/dos_gfx.cpp recent_files: file:///dos/z/16/16/project16.txt +recent_files: file:///dos/z/16/16/16.txt +recent_files: file:///dos/z/grdemo.c +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/PALETTE.INC +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/DUAL.CPP +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/TAURON.H +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/MAINC.CPP +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/CLEAR.CPP +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/MODES_C.INC +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/FONT2.H +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/FONT1.H +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/TESTS.CPP +recent_files: file:///dos/z/4x4_16/tauron/C_SRC/MODES.CPP snr_replacetype: 0 -savedir: file:///dos/z/4x4_16/tweak16/XINTRO +savedir: file:///dos/z/16/16 spell_check_default: 1 spell_insert_entities: 0 last_filefilter: @@ -51,15 +78,45 @@ snr_escape_chars: 0 htmlbar_view: 1 spell_lang: en ssearch_dotmatchall: 0 +searchlist: ‚Ä‚·‚Æ +searchlist: LGQ +searchlist: plot +searchlist: out +searchlist: put +searchlist: put +searchlist: print +searchlist: d put +searchlist: print +searchlist: tile +searchlist: fill_plane +searchlist: red +searchlist: rext +searchlist: rect`- +searchlist: fill_plane( autocomplete: 1 outputb_show_all_output: 0 bookmarks_show_mode: 0 snippets_show_as_menu: 1 adv_open_recursive: 0 -encoding: UTF-8 +encoding: SHIFT_JIS e2c.convert_special: 0 autoindent: 1 fb_viewmode: 0 +filegloblist: *.txt +filegloblist: *.shtml +filegloblist: *.py +filegloblist: *.pl +filegloblist: *.php +filegloblist: *.js +filegloblist: *.java +filegloblist: *.htm +filegloblist: *.html +filegloblist: *.h +filegloblist: *.css +filegloblist: *.cpp +filegloblist: *.cgi +filegloblist: *.c +filegloblist: * recent_dirs: file:///dos/z/16/16 fb_focus_follow: 1 ssearch_unescape: 0 diff --git a/16/Q.BAT b/16/Q.BAT new file mode 100644 index 00000000..5d1b5845 --- /dev/null +++ b/16/Q.BAT @@ -0,0 +1,5 @@ +call hres +vi dos_gfx.cpp +call x +pause +dos_gfx.exe diff --git a/16/W b/16/W new file mode 100644 index 00000000..f5334d49 --- /dev/null +++ b/16/W @@ -0,0 +1,5 @@ +3 +Where to next? It's your move! wwww +bakapi ver. 1.04.09a +is made by sparky4i†ƒÖ…j feel free to use it ^^ +Licence: GPL v2 diff --git a/16/dos_gfx.cpp b/16/dos_gfx.cpp index 76ab683a..5f31ad4e 100644 --- a/16/dos_gfx.cpp +++ b/16/dos_gfx.cpp @@ -36,6 +36,8 @@ */ + + /* * We 'require' a large data model simply to get rid of explicit 'far' * pointers and compiler specific '_fmemset()' functions and the likes. @@ -240,6 +242,63 @@ void set320x240x256_X(void) height = 240; } + + +/*tile*/ +// This is Bresenham's Line Drawing Algorithm +void drawline(int x1, int y1, int x2, int y2, char col) +{ + int d, x, y, ax, ay, sx, sy, dx, dy; + + dx = x2-x1; + ax = ABS(dx) << 1; + sx = SGN(dx); + dy = y2-y1; + ay = ABS(dy) << 1; + sy = SGN(dy); + + x = x1; + y = y1; + if( ax > ay ) + { + d = ay - (ax >> 1); + while( x != x2 ) + { + putPixel_X( x, y, col ); + if( d >= 0 ) + { + y += sy; + d -= ax; + } + x += sx; + d += ay; + } + } + else + { + d = ax - (ay >> 1); + while( y != y2 ) + { + putPixel_X( x, y, col ); + if( d >= 0 ) + { + x += sx; + d -= ay; + } + y += sy; + d += ax; + } + } + return; +} + +void drawrect(int x1, int y1, int x2, int y2, char color) +{ + drawline(x1,y1,x2,y1,color); + drawline(x1,y2,x2,y2,color); + drawline(x1,y1,x1,y2,color); + drawline(x2,y1,x2,y2+1,color); +} /*-----------XXXX-------------*/ @@ -379,8 +438,9 @@ int ding(int q){ int d3y; //++++ if(q <= 4 && q!=2 && gq == BONK-1) coor = rand()%HGQ; - if((q == 2 - ||q==4 + if((q == 2 + ||q==4 + ||q==16 ) && gq == BONK-1){ if(coor < HGQ && coor < LGQ) coor = LGQ; if(coor < HGQ-1){ @@ -408,7 +468,7 @@ int ding(int q){ gq++; }else gq = LGQ; } - if(q<5 && gq1){ - xx++; - } - if(!bakay){ - yy--; - }else if(bakay>1){ - yy++; + if(q==16) + { + if(!bakax){ + xx--;//=TILEWH; + }else if(bakax>0){ + xx++;//=TILEWH; + } + if(!bakay){ + yy--;//=TILEWH; + }else if(bakay>0){ + yy++;//=TILEWH; + } + }else{ + if(!bakax){ + xx-=TILEWH; + }else if(bakax>1){ + xx+=TILEWH; + } + if(!bakay){ + yy-=TILEWH; + }else if(bakay>1){ + yy+=TILEWH; + } } } // fixer - /*if(xx<0) xx=width; - if(yy<0) yy=height; - if(xx>width) xx=0; - if(yy>height) yy=0;*/ + if(q!=16){ + if(xx<0) xx=width; + if(yy<0) yy=height; + if(xx>width) xx=0; + if(yy>height) yy=0; + } + +//interesting effects + if(q==16) + { + int tx=0,ty=0; + tx+=xx+16; + ty+=yy+16; + putPixel_X(tx, ty, coor); + //drawrect(tx, ty, tx+TILEWH, ty+TILEWH, coor); + //printf("%d %d %d %d %d %d\n", xx, yy, tx, ty, TILEWH); // plot the pixel //---- ppf(xx, yy, coor, vga); - putPixel_X(xx, yy, coor); +//++++0000 putPixel_X(xx, yy, coor); + }else drawrect(xx, yy, xx+TILEWH-1, yy+TILEWH-1, coor); //---- if(q==2) ppf(rand()%, rand()%height, 0, vga); - if(q==2) putPixel_X(rand()%width, rand()%height, 0); - if(q==2||q==4){ bakax = rand()%3; bakay = rand()%3; } + if(q==2||q==16) putPixel_X(rand()%width, rand()%height, 0); + if(q==2||q==4||q==16){ bakax = rand()%3; bakay = rand()%3; } gq++; //if(xx<0||xx>320||yy<0||yy>240) // printf("%d %d %d %d %d %d\n", xx, yy, coor, bakax, bakay, getPixel_X(xx,yy)); @@ -489,38 +576,38 @@ void doTest(void) int p, x, y, pages; /* This is the way to calculate the number of pages available. */ - pages = 65536L/(widthBytes*height); // apparently this takes the A000 address + pages = 65536L/(widthBytes*height); // apparently this takes the A000 address + + printf("%d\n", pages); - printf("%d\n", pages); - for (p = 0; p <= pages; ++p) { setActivePage(p); /* On each page draw a single colored border, and dump the palette - onto a small square about the middle of the page. */ - + onto a small square about the middle of the page. */ + //{ for (x = 0; x <= width; ++x) { putPixel_X(x, 0, p+1); - if(p!=pages) putPixel_X(x, height-1, p+1); + if(p!=pages) putPixel_X(x, height-1, p+1); else putPixel_X(x, 99-1, p+1); } for (y = 0; y <= height; ++y) { putPixel_X(0, y, p+1); - if(p!=pages) putPixel_X(width-1, y, p+1); + if(p!=pages) putPixel_X(width-1, y, p+1); else putPixel_X(width-1, y, p+1); } for (x = 0; x < 16; ++x) for (y = 0; y < 16; ++y) putPixel_X(x+(p+2)*16, y+(p+2)*16, x + y*16); - //} - - drawText(0, 0, 15, p); + //} + + drawText(0, 0, 15, p); } @@ -528,7 +615,7 @@ void doTest(void) through all the pages by pressing a key. */ for (p = 0; p <= pages; ++p) { - setVisiblePage(p); + setVisiblePage(p); //drawText(0, 240, 15, "bakapi"); getch(); } @@ -574,9 +661,9 @@ int main(void) } }*/ // else off while(!kbhit()){ // conditions of screen saver - ding(4); - } - //end of screen savers + ding(4); + } + //end of screen savers doTest(); setvideo(0); puts("Where to next? It's your move! wwww"); diff --git a/16/dos_gfx.h b/16/dos_gfx.h index 08908b04..b95f0159 100644 --- a/16/dos_gfx.h +++ b/16/dos_gfx.h @@ -9,7 +9,10 @@ //static hgq=NUM_COLORS/(1/8) #define BONK 400 #define LGQ 32 -#define HGQ 56 +#define HGQ 56 +#define TILEWH 16 +#define ABS(a) ((a < 0) ? -a : a) +#define SGN(a) ((a < 0) ? -1 : 1) //#define VMEM 0xA000 // = vga //int width = 320; //int height = 240; @@ -22,7 +25,9 @@ void setvideo(/*byte mode, */int vq); void cls(byte color, byte *Where); //void clearscr(); //void plotpixel(int x, int y, byte color, byte *Where); -//void plotpixelfast(int x, int y, byte color, byte *Where); +//void plotpixelfast(int x, int y, byte color, byte *Where); +void putPixel_X(int x, int y, byte color); +void putTile(int x, int y, byte color); //void BlockMove(); //void eraseplayer(int x, int y); //void drawplayer(int x, int y, int color);