├── games └── ENVOIGHT │ ├── AMMO.DAT │ ├── ENEMY3.DAT │ ├── AMMO.PCX │ ├── BACKG.PCX │ ├── SHIP.DAT │ ├── SHIP.PCX │ ├── ENEMY1.DAT │ ├── ENEMY1.PCX │ ├── ENEMY2.DAT │ ├── ENEMY2.PCX │ ├── ENEMY3.PCX │ ├── ENVOIGHT.EXE │ ├── SPRT2DAT.EXE │ ├── SPRTCOMP.EXE │ ├── MAKEFILE.2DT │ ├── MAKEFILE.CMP │ ├── GRAPHICS.H │ ├── MAKEFILE.ENV │ ├── PAGE.H │ ├── MAKEFILE │ ├── PAL.C │ ├── PCX.H │ ├── SPRITE.H │ ├── PAGE.C │ ├── GRAPHICS.C │ ├── AMMO.C │ ├── SPRT2DAT.C │ ├── SPRITE.C │ └── ENVOIGHT.C ├── .gitattributes ├── cgaeffects ├── check3d │ ├── README │ ├── MAKEFILE │ └── CHECK3D.C ├── rotozoom80x100 │ ├── PCRETRO.PCX │ ├── MAKEFILE │ ├── PCX.H │ ├── PCX.C │ └── ROTAZOOM.C ├── rotozoom80x50 │ ├── PCRETRO.PCX │ ├── MAKEFILE │ ├── PCX.H │ ├── PCX.C │ └── ROTAZOOM.C ├── rotozoom160x100 │ ├── PCRETRO.PCX │ ├── MAKEFILE │ ├── PCX.H │ ├── PCX.C │ └── ROTAZOOM.C ├── clippedtetrahedron │ ├── CGADEMO2.EXE │ └── MAKEFILE ├── checkboard │ ├── MAKEFILE │ └── CHECKBRD.C ├── wiper │ ├── MAKEFILE │ └── WIPER.C └── 3drotatingblock │ ├── MAKEFILE │ └── 3DROT.C ├── mcga320x200 ├── BMP.EXE ├── teton.bmp └── BMP.C ├── vgaeffects ├── xtplasma │ ├── PLASMA.EXE │ ├── TEST.ASM │ ├── MAKEFILE │ ├── MAKEFILE.2 │ ├── PLASMA.C │ ├── PLASMA2.C │ ├── VGA.ASM │ ├── MCGA.ASM │ └── MCGA2.ASM └── plasma │ ├── MAKEFILE │ ├── PLASMA.C │ └── VGA.ASM ├── MAKEFILE ├── README.md ├── LICENSE ├── cga320x200 ├── small │ ├── README.TXT │ ├── hline.asm │ ├── vline.asm │ └── line.asm ├── efficient │ ├── README.TXT │ ├── hline.asm │ └── vline.asm ├── ludicrous │ ├── README.TXT │ ├── hline.asm │ ├── lineinc.asm │ ├── linewide.asm │ ├── polisect.asm │ └── vline.asm └── fast │ ├── README.TXT │ ├── hline.asm │ └── vline.asm ├── cga160x200 └── ludicrous │ ├── hline.asm │ └── vline.asm ├── cga2.asm ├── cga3.asm ├── cga4.asm ├── fire2.asm └── fire.asm /games/ENVOIGHT/AMMO.DAT: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.asm -text 2 | *.c -text 3 | *.h -text 4 | 5 | -------------------------------------------------------------------------------- /cgaeffects/check3d/README: -------------------------------------------------------------------------------- 1 | 3d Checkerboard (CGA 320x200) 2 | -------------------------------------------------------------------------------- /mcga320x200/BMP.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/mcga320x200/BMP.EXE -------------------------------------------------------------------------------- /games/ENVOIGHT/ENEMY3.DAT: -------------------------------------------------------------------------------- 1 |  TE@DPQDDE@DDDPQUUUUU -------------------------------------------------------------------------------- /mcga320x200/teton.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/mcga320x200/teton.bmp -------------------------------------------------------------------------------- /games/ENVOIGHT/AMMO.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/AMMO.PCX -------------------------------------------------------------------------------- /games/ENVOIGHT/BACKG.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/BACKG.PCX -------------------------------------------------------------------------------- /games/ENVOIGHT/SHIP.DAT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/SHIP.DAT -------------------------------------------------------------------------------- /games/ENVOIGHT/SHIP.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/SHIP.PCX -------------------------------------------------------------------------------- /games/ENVOIGHT/ENEMY1.DAT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/ENEMY1.DAT -------------------------------------------------------------------------------- /games/ENVOIGHT/ENEMY1.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/ENEMY1.PCX -------------------------------------------------------------------------------- /games/ENVOIGHT/ENEMY2.DAT: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/ENEMY2.DAT -------------------------------------------------------------------------------- /games/ENVOIGHT/ENEMY2.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/ENEMY2.PCX -------------------------------------------------------------------------------- /games/ENVOIGHT/ENEMY3.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/ENEMY3.PCX -------------------------------------------------------------------------------- /games/ENVOIGHT/ENVOIGHT.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/ENVOIGHT.EXE -------------------------------------------------------------------------------- /games/ENVOIGHT/SPRT2DAT.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/SPRT2DAT.EXE -------------------------------------------------------------------------------- /games/ENVOIGHT/SPRTCOMP.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/games/ENVOIGHT/SPRTCOMP.EXE -------------------------------------------------------------------------------- /vgaeffects/xtplasma/PLASMA.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/vgaeffects/xtplasma/PLASMA.EXE -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x100/PCRETRO.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/cgaeffects/rotozoom80x100/PCRETRO.PCX -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x50/PCRETRO.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/cgaeffects/rotozoom80x50/PCRETRO.PCX -------------------------------------------------------------------------------- /cgaeffects/rotozoom160x100/PCRETRO.PCX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/cgaeffects/rotozoom160x100/PCRETRO.PCX -------------------------------------------------------------------------------- /cgaeffects/clippedtetrahedron/CGADEMO2.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbhart/CGAGraphics/HEAD/cgaeffects/clippedtetrahedron/CGADEMO2.EXE -------------------------------------------------------------------------------- /cgaeffects/clippedtetrahedron/MAKEFILE: -------------------------------------------------------------------------------- 1 | cgademo2.exe: cgademo2.c cga.obj 2 | tcc -G -O -Z cgademo2 cga.obj 3 | 4 | cga.obj: cga.asm 5 | tasm /mx cga 6 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/TEST.ASM: -------------------------------------------------------------------------------- 1 | .MODEL small 2 | .stack 100h 3 | 4 | .CODE 5 | .386 6 | 7 | start: 8 | mov ah, 4ch 9 | int 21h 10 | 11 | END start 12 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x100/MAKEFILE: -------------------------------------------------------------------------------- 1 | rotazoom.exe: rotazoom.c pcx.obj rotozoom.obj 2 | tcc -G -O -Z -B rotazoom pcx.obj rotozoom.obj 3 | 4 | pcx.obj: pcx.h pcx.c 5 | tcc -G -O -Z -c pcx 6 | 7 | rotozoom.obj: rotozoom.asm 8 | tasm /mx rotozoom.asm 9 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x50/MAKEFILE: -------------------------------------------------------------------------------- 1 | rotazoom.exe: rotazoom.c pcx.obj rotozoom.obj 2 | tcc -G -O -Z -B rotazoom pcx.obj rotozoom.obj 3 | 4 | pcx.obj: pcx.h pcx.c 5 | tcc -G -O -Z -c pcx 6 | 7 | rotozoom.obj: rotozoom.asm 8 | tasm /mx rotozoom.asm 9 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom160x100/MAKEFILE: -------------------------------------------------------------------------------- 1 | rotazoom.exe: rotazoom.c pcx.obj rotozoom.obj 2 | tcc -G -O -Z -B rotazoom pcx.obj rotozoom.obj 3 | 4 | pcx.obj: pcx.h pcx.c 5 | tcc -G -O -Z -c pcx 6 | 7 | rotozoom.obj: rotozoom.asm 8 | tasm /mx rotozoom.asm 9 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/MAKEFILE: -------------------------------------------------------------------------------- 1 | plasma.exe: vga.obj plasma.obj 2 | tlink c:\tc\lib\c0s.obj vga.obj plasma.obj,plasma.exe,,c:\tc\lib\cs.lib+c:\tc\lib\maths.lib 3 | 4 | vga.obj: vga.asm 5 | tasm /ml vga.asm 6 | 7 | plasma.obj: plasma.c 8 | tcc -c plasma.c 9 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/MAKEFILE.2: -------------------------------------------------------------------------------- 1 | plasma.exe: vga.obj plasma.obj 2 | tlink c:\tc\lib\c0s.obj vga.obj plasma.obj,plasma.exe,,c:\tc\lib\cs.lib+c:\tc\lib\maths.lib 3 | 4 | vga.obj: vga.asm 5 | tasm /ml vga.asm 6 | 7 | plasma.obj: plasma.c 8 | tcc -c plasma.c 9 | -------------------------------------------------------------------------------- /vgaeffects/plasma/MAKEFILE: -------------------------------------------------------------------------------- 1 | plasma.exe: vga.obj plasma.obj 2 | tlink c:\tc\lib\c0s.obj vga.obj plasma.obj,plasma.exe,,c:\tc\lib\cs.lib+c:\tc\lib\maths.lib+c:\tc\lib\emu.lib 3 | 4 | vga.obj: vga.asm 5 | tasm /ml vga.asm 6 | 7 | plasma.obj: plasma.c 8 | tcc -c plasma.c 9 | -------------------------------------------------------------------------------- /MAKEFILE: -------------------------------------------------------------------------------- 1 | cgademo3.exe: cgademo3.c line.obj circle.obj ellipse.obj 2 | tcc -G -O -Z cgademo3 line.obj circle.obj ellipse.obj 3 | 4 | line.obj: line.asm 5 | tasm /mx line.asm 6 | 7 | circle.obj: circle.asm 8 | tasm /mx circle.asm 9 | 10 | ellipse.obj: ellipse.asm 11 | tasm /mx ellipse.asm -------------------------------------------------------------------------------- /cgaeffects/check3d/MAKEFILE: -------------------------------------------------------------------------------- 1 | check3d.exe: check3d.c line.obj hline.obj vline.obj 2 | tcc -G -O -Z -B check3d line.obj hline.obj vline.obj 3 | 4 | line.obj: line.asm 5 | tasm /mx line.asm 6 | 7 | hline.obj: hline.asm 8 | tasm /mx hline.asm 9 | 10 | vline.obj: vline.asm 11 | tasm /mx vline.asm 12 | -------------------------------------------------------------------------------- /cgaeffects/checkboard/MAKEFILE: -------------------------------------------------------------------------------- 1 | linetest.exe: checkbrd.c hline.obj vline.obj chckbrd.obj 2 | tcc -G -O -Z -B checkbrd hline.obj vline.obj chckbrd.obj 3 | 4 | hline.obj: hline.asm 5 | tasm /mx hline.asm 6 | 7 | vline.obj: vline.asm 8 | tasm /mx vline.asm 9 | 10 | chckbrd.obj: chckbrd.asm 11 | tasm /mx chckbrd.asm 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CGAGraphics 2 | 3 | Various CGA Graphics files: 4 | 5 | * cga320x200 - Graphics library for CGA 320x200x4 colour mode 6 | * cga160x200 - Graphics library for CGA 160x200x4 colour resolution (in 320x200 mode) 7 | * cgaeffects - Various assembly language demo effects for CGA 8 | 9 | Requires Borland Turbo C v2.01 and Tasm 1.0. 10 | -------------------------------------------------------------------------------- /games/ENVOIGHT/MAKEFILE.2DT: -------------------------------------------------------------------------------- 1 | sprt2dat.exe: sprt2dat.c sprite.obj graphics.obj page.obj 2 | tcc -B -G -O -Z sprt2dat sprite.obj graphics.obj page.obj 3 | 4 | sprite.obj: sprite.c sprite.h 5 | tcc -B -G -O -Z -c sprite.c 6 | 7 | graphics.obj: graphics.c graphics.h 8 | tcc -B -G -O -Z -c graphics.c 9 | 10 | page.obj: page.c page.h 11 | tcc -B -G -O -Z -c page.c 12 | -------------------------------------------------------------------------------- /games/ENVOIGHT/MAKEFILE.CMP: -------------------------------------------------------------------------------- 1 | sprtcomp.exe: sprtcomp.c sprite.obj graphics.obj page.obj 2 | tcc -B -G -O -Z sprtcomp sprite.obj graphics.obj page.obj 3 | 4 | sprite.obj: sprite.c sprite.h 5 | tcc -B -G -O -Z -c sprite.c 6 | 7 | graphics.obj: graphics.c graphics.h 8 | tcc -B -G -O -Z -c graphics.c 9 | 10 | page.obj: page.c page.h 11 | tcc -B -G -O -Z -c page.c 12 | -------------------------------------------------------------------------------- /games/ENVOIGHT/GRAPHICS.H: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICS_H 2 | #define GRAPHICS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "pcx.h" 9 | 10 | /**** General graphics routines ****/ 11 | 12 | int set_video_mode(int n); 13 | 14 | /**** PCX file format ****/ 15 | 16 | void cga_display_pcx(char * filename); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /games/ENVOIGHT/MAKEFILE.ENV: -------------------------------------------------------------------------------- 1 | envoight.exe: envoight.c ship.obj sprite.obj graphics.obj page.obj 2 | tcc -B -G -O -Z envoight ship.obj sprite.obj graphics.obj page.obj 3 | 4 | sprite.obj: sprite.c sprite.h 5 | tcc -B -G -O -Z -c sprite.c 6 | 7 | graphics.obj: graphics.c graphics.h 8 | tcc -B -G -O -Z -c graphics.c 9 | 10 | page.obj: page.c page.h 11 | tcc -B -G -O -Z -c page.c 12 | 13 | ship.obj: ship.c 14 | tcc -B -G -O -Z -c ship.c -------------------------------------------------------------------------------- /cgaeffects/wiper/MAKEFILE: -------------------------------------------------------------------------------- 1 | wiper.exe: wiper.c line.obj hline.obj vline.obj linchnkl.obj linchnkr.obj 2 | tcc -G -O -Z wiper line.obj hline.obj vline.obj linchnkl.obj linchnkr.obj 3 | 4 | line.obj: line.asm 5 | tasm /mx line.asm 6 | 7 | hline.obj: hline.asm 8 | tasm /mx hline.asm 9 | 10 | vline.obj: vline.asm 11 | tasm /mx vline.asm 12 | 13 | linchnkl.obj: linchnkl.asm 14 | tasm /mx linchnkl.asm 15 | 16 | linchnkr.obj: linchnkr.asm 17 | tasm /mx linchnkr.asm 18 | -------------------------------------------------------------------------------- /cgaeffects/3drotatingblock/MAKEFILE: -------------------------------------------------------------------------------- 1 | 3drot.exe: 3drot.c line.obj hline.obj vline.obj linchnkl.obj linchnkr.obj 2 | tcc -G -O -Z 3drot line.obj hline.obj vline.obj linchnkl.obj linchnkr.obj 3 | 4 | line.obj: line.asm 5 | tasm /mx line.asm 6 | 7 | hline.obj: hline.asm 8 | tasm /mx hline.asm 9 | 10 | vline.obj: vline.asm 11 | tasm /mx vline.asm 12 | 13 | linchnkl.obj: linchnkl.asm 14 | tasm /mx linchnkl.asm 15 | 16 | linchnkr.obj: linchnkr.asm 17 | tasm /mx linchnkr.asm 18 | -------------------------------------------------------------------------------- /games/ENVOIGHT/PAGE.H: -------------------------------------------------------------------------------- 1 | #ifndef PAGE_H 2 | #define PAGE_H 3 | 4 | #include 5 | 6 | #define PAGE_MARGIN 64 7 | #define PAGE_LINEB (320/4) 8 | #define PAGE_ODDB ((100+PAGE_MARGIN)*PAGE_LINEB+PAGE_MARGIN/4) 9 | #define PAGE_OFFSET ((PAGE_MARGIN/2)*PAGE_LINEB+PAGE_MARGIN/4) 10 | 11 | unsigned char far * page_alloc(); 12 | 13 | void page_free(unsigned char far * page); 14 | 15 | void page_copy_bg(unsigned char far * page, unsigned char far * video); 16 | 17 | void page_flip_box_aligned(unsigned char far * video, 18 | unsigned char far * page, int x, int y, int xsize, int ysize); 19 | 20 | void page_flip_box_unaligned(unsigned char far * video, 21 | unsigned char far * page, int x, int y, int xsize, int ysize); 22 | 23 | #endif -------------------------------------------------------------------------------- /games/ENVOIGHT/MAKEFILE: -------------------------------------------------------------------------------- 1 | envoight.exe: envoight.c ship.obj sprite.obj graphics.obj page.obj enemy1.obj enemy2.obj enemy3.obj ammo.obj 2 | tcc -B -G -O -Z envoight ship.obj sprite.obj graphics.obj page.obj enemy1.obj enemy2.obj enemy3.obj ammo.obj 3 | 4 | sprite.obj: sprite.c sprite.h 5 | tcc -B -G -O -Z -c sprite.c 6 | 7 | graphics.obj: graphics.c graphics.h 8 | tcc -B -G -O -Z -c graphics.c 9 | 10 | page.obj: page.c page.h 11 | tcc -B -G -O -Z -c page.c 12 | 13 | ship.obj: ship.c 14 | tcc -B -G -O -Z -c ship.c 15 | 16 | enemy1.obj: enemy1.c 17 | tcc -B -G -O -Z -c enemy1.c 18 | 19 | enemy2.obj: enemy2.c 20 | tcc -B -G -O -Z -c enemy2.c 21 | 22 | ammo.obj: ammo.c 23 | tcc -B -G -O -Z -c ammo.c 24 | 25 | enemy3.obj: enemy3.c 26 | tcc -B -G -O -Z -c enemy3.c 27 | 28 | -------------------------------------------------------------------------------- /games/ENVOIGHT/PAL.C: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "dos.h" 3 | 4 | extern void cga_colours(); 5 | 6 | int set_video_mode(int n) 7 | { 8 | union REGS regs; 9 | 10 | regs.h.ah = 0; 11 | regs.h.al = n; 12 | int86(0x10, ®s, ®s); 13 | } 14 | 15 | void set_video_palette_colour(unsigned char colour) 16 | { 17 | asm push ax; 18 | asm push dx; 19 | asm mov dx, 03d9h; 20 | asm mov al, [colour]; 21 | asm out dx, al; 22 | asm pop dx; 23 | asm pop ax; 24 | } 25 | 26 | int main(void) 27 | { 28 | int i; 29 | 30 | set_video_mode(4); 31 | outp(0x3d8, 10); 32 | 33 | for (i = 0; i < 64; i++) 34 | { 35 | set_video_palette_colour(i); 36 | 37 | cga_colours(); 38 | 39 | getchar(); 40 | } 41 | 42 | set_video_mode(3); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /vgaeffects/plasma/PLASMA.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern void vga_plasma(unsigned char * sintab); 6 | extern void text_mode(void); 7 | 8 | int main(void) 9 | { 10 | int i; 11 | unsigned char sintab[64]; 12 | const double pi = 3.1415926536; 13 | const double theta = (2*pi/64); 14 | double angle = 0.0; 15 | 16 | printf("Welcome to Plasma 1.0\n"); 17 | printf("Press a key to begin\n"); 18 | 19 | getch(); 20 | 21 | printf("Computing sin lookup table...\n"); 22 | 23 | for (i = 0; i < 64; i++) 24 | { 25 | sintab[i] = 63.5*(sin(angle) + 1); 26 | angle += theta; 27 | } 28 | 29 | printf("...done\n"); 30 | 31 | getch(); 32 | 33 | vga_plasma(sintab); 34 | 35 | getch(); 36 | 37 | text_mode(); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /cgaeffects/rotozoom160x100/PCX.H: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define PCX_BUFF_SIZE 1024 5 | 6 | typedef struct 7 | { 8 | unsigned char r; 9 | unsigned char g; 10 | unsigned char b; 11 | } colour_s; 12 | 13 | typedef struct 14 | { 15 | char pcx_flag; 16 | char version; 17 | char encoding; 18 | char bits_per_pixel; 19 | int x0; 20 | int y0; 21 | int x1; 22 | int y1; 23 | int hdpi; 24 | int vdpi; 25 | colour_s colour_map[16]; 26 | char reserved; 27 | char nplanes; 28 | int bytes_per_line; 29 | unsigned int palette_info; 30 | int hscreen_size; 31 | int vscreen_size; 32 | char filler[54]; 33 | } pcx_header_s; 34 | 35 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file); 36 | 37 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 38 | int bytes_per_line, int lines); -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x100/PCX.H: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define PCX_BUFF_SIZE 1024 5 | 6 | typedef struct 7 | { 8 | unsigned char r; 9 | unsigned char g; 10 | unsigned char b; 11 | } colour_s; 12 | 13 | typedef struct 14 | { 15 | char pcx_flag; 16 | char version; 17 | char encoding; 18 | char bits_per_pixel; 19 | int x0; 20 | int y0; 21 | int x1; 22 | int y1; 23 | int hdpi; 24 | int vdpi; 25 | colour_s colour_map[16]; 26 | char reserved; 27 | char nplanes; 28 | int bytes_per_line; 29 | unsigned int palette_info; 30 | int hscreen_size; 31 | int vscreen_size; 32 | char filler[54]; 33 | } pcx_header_s; 34 | 35 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file); 36 | 37 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 38 | int bytes_per_line, int lines); -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x50/PCX.H: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define PCX_BUFF_SIZE 1024 5 | 6 | typedef struct 7 | { 8 | unsigned char r; 9 | unsigned char g; 10 | unsigned char b; 11 | } colour_s; 12 | 13 | typedef struct 14 | { 15 | char pcx_flag; 16 | char version; 17 | char encoding; 18 | char bits_per_pixel; 19 | int x0; 20 | int y0; 21 | int x1; 22 | int y1; 23 | int hdpi; 24 | int vdpi; 25 | colour_s colour_map[16]; 26 | char reserved; 27 | char nplanes; 28 | int bytes_per_line; 29 | unsigned int palette_info; 30 | int hscreen_size; 31 | int vscreen_size; 32 | char filler[54]; 33 | } pcx_header_s; 34 | 35 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file); 36 | 37 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 38 | int bytes_per_line, int lines); -------------------------------------------------------------------------------- /games/ENVOIGHT/PCX.H: -------------------------------------------------------------------------------- 1 | #ifndef PCX_H 2 | #define PCX_H 3 | 4 | #include 5 | #include 6 | 7 | #define PCX_BUFF_SIZE 32000 8 | 9 | typedef struct 10 | { 11 | unsigned char r; 12 | unsigned char g; 13 | unsigned char b; 14 | } colour_s; 15 | 16 | typedef struct 17 | { 18 | char pcx_flag; 19 | char version; 20 | char encoding; 21 | char bits_per_pixel; 22 | int x0; 23 | int y0; 24 | int x1; 25 | int y1; 26 | int hdpi; 27 | int vdpi; 28 | colour_s colour_map[16]; 29 | char reserved; 30 | char nplanes; 31 | int bytes_per_line; 32 | unsigned int palette_info; 33 | int hscreen_size; 34 | int vscreen_size; 35 | char filler[54]; 36 | } pcx_header_s; 37 | 38 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file); 39 | 40 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 41 | int bytes_per_line, int lines); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2019, wbhart 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /games/ENVOIGHT/SPRITE.H: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "graphics.h" 6 | 7 | #define SPRITE_WIDTH 64 8 | #define SPRITE_LINEB (320/4) 9 | #define SPRITE_PAGEB ((100+SPRITE_WIDTH)*SPRITE_LINEB+SPRITE_WIDTH/4) 10 | #define SPRITE_OFFSET ((SPRITE_WIDTH/2)*SPRITE_LINEB+SPRITE_WIDTH/4) 11 | 12 | typedef void (*spritefn)(unsigned char far *); 13 | 14 | typedef struct 15 | { 16 | int x; 17 | int y; 18 | int oldx; 19 | int oldy; 20 | int xsize; 21 | int ysize; 22 | spritefn sprite0_odd; 23 | spritefn sprite0_even; 24 | spritefn sprite1_odd; 25 | spritefn sprite1_even; 26 | spritefn sprite2_odd; 27 | spritefn sprite2_even; 28 | spritefn sprite3_odd; 29 | spritefn sprite3_even; 30 | unsigned char * buff; 31 | } sprite_s; 32 | 33 | typedef sprite_s sprite_t[1]; 34 | 35 | /**** Direct sprite functions ****/ 36 | 37 | void sprite_display_direct(unsigned char far * video, 38 | unsigned char * sprite, int xsize, int ysize); 39 | 40 | /**** Sprite functions ****/ 41 | 42 | void sprite_composite(unsigned char far * page, sprite_t s); 43 | 44 | void sprite_flip(unsigned char far * video, 45 | unsigned char far * page, sprite_t s); 46 | 47 | void sprite_save_bg(sprite_t s, unsigned char far * page); 48 | 49 | void sprite_restore_bg(unsigned char far * page, sprite_t s); 50 | 51 | void sprite_wipe(unsigned char far * page, sprite_t s); 52 | 53 | void sprite_move(sprite_t s, int x, int y); 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/PLASMA.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void vga_plasma(unsigned char far * buff); 8 | extern void set_fire_palette(); 9 | 10 | int set_video_mode(int n) 11 | { 12 | union REGS regs; 13 | 14 | regs.h.ah = 0; 15 | regs.h.al = n; 16 | int86(0x10, ®s, ®s); 17 | } 18 | 19 | int main(void) 20 | { 21 | int i, j; 22 | unsigned char sintab[320], shift[200], c; 23 | const double pi = 3.1415926536; 24 | const double theta = 1.5*(pi/64); 25 | const double theta2 = 0.4*(pi/64); 26 | double angle = 0.0, angle2 = 0.0; 27 | unsigned char far * buff; 28 | printf("Welcome to Plasma 1.0\n"); 29 | printf("Press a key to begin\n"); 30 | 31 | getch(); 32 | 33 | buff = farmalloc(64000); 34 | 35 | for (i = 0; i < 320; i++) 36 | { 37 | sintab[i] = 127.5*(sin(angle)+1.0); 38 | angle += theta + theta*sin(angle2)/2; 39 | angle2 += theta2; 40 | } 41 | 42 | angle2 = 0.0; 43 | for (i = 0; i < 200; i++) 44 | { 45 | double factor = 100.0 + 180.0*(sin(angle2) + 1.0); 46 | shift[i] = factor*(sin(angle) + 1.0); 47 | 48 | angle += theta; 49 | angle2 += theta; 50 | } 51 | 52 | for (i = 0; i < 200; i++) 53 | { 54 | for (j = 0; j < 320; j++) 55 | buff[i*320 + j] = sintab[j] + shift[i]; 56 | } 57 | 58 | set_video_mode(19); 59 | set_fire_palette(); 60 | 61 | vga_plasma(buff); 62 | 63 | getch(); 64 | 65 | farfree(buff); 66 | 67 | set_video_mode(3); 68 | 69 | return 0; 70 | } -------------------------------------------------------------------------------- /cga320x200/small/README.TXT: -------------------------------------------------------------------------------- 1 | Small CGA Graphics Library 2 | ========================== 3 | 4 | The small CGA functions aim to provide reasonable performance with a very small 5 | amount of code. 6 | 7 | * Focus on code size, not performance, though not to the extreme 8 | * Generally no duplication of code for speedups 9 | * Interrupts will not be turned off 10 | * Self-modification only if it reduces code size with low overhead 11 | * Very efficient initialisation of routines 12 | * No proliferation of functions 13 | * Generally no approximations in graphics output 14 | 15 | Lines 16 | ===== 17 | 18 | void cga_draw_line(unsigned char far * buff, int x0, int y0, int x1, int y1, unsigned char colour) 19 | 20 | Draw a line of the given colour (0-3) in the CGA buffer (320x200 x 2 bit) 21 | buff from (x0, y0) to (x1, y1) inclusive. No restrictions on input except 22 | that both endpoints be in the screen bounds. 23 | 24 | void cga_draw_hline(unsigned char far * buff, int x0, int x1, int y, unsigned char colour) 25 | 26 | Draw a horizontal line of the given colour (0-3) from (x0, y) to (x1, y) 27 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 28 | that inputs be in the screen bounds and x1 >= x0. 29 | 30 | * rep stosb 31 | 32 | void cga_draw_vline(unsigned char far * buff, int x, int y0, int y1, unsigned char colour) 33 | 34 | Draw a vertical line of the given colour (0-3) from (x, y0) to (x, y1) 35 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 36 | that inputs be in the screen bounds and y1 >= y0. 37 | 38 | -------------------------------------------------------------------------------- /cga320x200/efficient/README.TXT: -------------------------------------------------------------------------------- 1 | Efficient CGA Graphics Library 2 | ============================== 3 | 4 | The efficient CGA functions aim to provide all-round efficiency, both in terms 5 | of speed and space. 6 | 7 | * May be 20-30% slower than the fast versions 8 | * Will not duplicate large quantities of code for small speedups 9 | * Interrupts will not be turned off 10 | * No self-modification 11 | * Efficient initialisation of routines 12 | * No unnecessary proliferation of functions 13 | * Generally no approximations in graphics output 14 | 15 | Lines 16 | ===== 17 | 18 | void cga_draw_line(unsigned char far * buff, int x0, int y0, int x1, int y1, unsigned char colour) 19 | 20 | Draw a line of the given colour (0-3) in the CGA buffer (320x200 x 2 bit) 21 | buff from (x0, y0) to (x1, y1) inclusive. No restrictions on input except 22 | that both endpoints be in the screen bounds. 23 | 24 | * Special case pixels mod 4 in horizontal direction with 4 way unroll 25 | * Deal with odd and even lines in pairs in verticalish case, 2 way unroll 26 | * Reenigne's XOR trick to deal with switching between odd/even lines 27 | * Special layout of cases to maximise short jumps 28 | * As many cases as possible fall through to next case without jump 29 | 30 | void cga_draw_hline(unsigned char far * buff, int x0, int x1, int y, unsigned char colour) 31 | 32 | Draw a horizontal line of the given colour (0-3) from (x0, y) to (x1, y) 33 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 34 | that inputs be in the screen bounds and x1 >= x0. 35 | 36 | * unroll by 2 and use rep stosw 37 | 38 | void cga_draw_vline(unsigned char far * buff, int x, int y0, int y1, unsigned char colour) 39 | 40 | Draw a vertical line of the given colour (0-3) from (x, y0) to (x, y1) 41 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 42 | that inputs be in the screen bounds and y1 >= y0. 43 | 44 | * unroll by 2 45 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x100/PCX.C: -------------------------------------------------------------------------------- 1 | #include "pcx.h" 2 | 3 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file) 4 | { 5 | /* read header */ 6 | fread(header, 1, 128, pcx_file); 7 | } 8 | 9 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 10 | int bytes_per_line, int lines) 11 | { 12 | unsigned char * buff; 13 | int data_length; 14 | int i, j, k, off, count = 0; 15 | unsigned char c, d; 16 | 17 | /* allocate buffer */ 18 | buff = malloc(PCX_BUFF_SIZE+1); 19 | 20 | off = 0; 21 | 22 | data_length = 0; 23 | 24 | i = 0; 25 | while (count < lines) 26 | { 27 | j = 0; 28 | while (j < bytes_per_line) 29 | { 30 | if (i == data_length) 31 | { 32 | data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file); 33 | if (data_length == 0) 34 | { 35 | printf("Unable to read file \n"); 36 | abort(); 37 | } 38 | i = 0; 39 | } 40 | 41 | c = buff[i]; 42 | i++; 43 | 44 | if (c >= 192) /* c is a count */ 45 | { 46 | c -= 192; 47 | 48 | if (i == data_length) 49 | { 50 | data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file); 51 | if (data_length == 0) 52 | { 53 | printf("Unable to read file \n"); 54 | abort(); 55 | } 56 | i = 0; 57 | } 58 | 59 | d = buff[i]; 60 | i++; 61 | 62 | for (k = 0; k < c; k++) 63 | buffer[off + j + k] = d; 64 | 65 | j += c; 66 | } else 67 | { 68 | buffer[off + j] = c; 69 | j++; 70 | } 71 | } 72 | off += bytes_per_line; 73 | count++; 74 | } 75 | 76 | free(buff); 77 | } 78 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x50/PCX.C: -------------------------------------------------------------------------------- 1 | #include "pcx.h" 2 | 3 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file) 4 | { 5 | /* read header */ 6 | fread(header, 1, 128, pcx_file); 7 | } 8 | 9 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 10 | int bytes_per_line, int lines) 11 | { 12 | unsigned char * buff; 13 | int data_length; 14 | int i, j, k, off, count = 0; 15 | unsigned char c, d; 16 | 17 | /* allocate buffer */ 18 | buff = malloc(PCX_BUFF_SIZE+1); 19 | 20 | off = 0; 21 | 22 | data_length = 0; 23 | 24 | i = 0; 25 | while (count < lines) 26 | { 27 | j = 0; 28 | while (j < bytes_per_line) 29 | { 30 | if (i == data_length) 31 | { 32 | data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file); 33 | if (data_length == 0) 34 | { 35 | printf("Unable to read file \n"); 36 | abort(); 37 | } 38 | i = 0; 39 | } 40 | 41 | c = buff[i]; 42 | i++; 43 | 44 | if (c >= 192) /* c is a count */ 45 | { 46 | c -= 192; 47 | 48 | if (i == data_length) 49 | { 50 | data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file); 51 | if (data_length == 0) 52 | { 53 | printf("Unable to read file \n"); 54 | abort(); 55 | } 56 | i = 0; 57 | } 58 | 59 | d = buff[i]; 60 | i++; 61 | 62 | for (k = 0; k < c; k++) 63 | buffer[off + j + k] = d; 64 | 65 | j += c; 66 | } else 67 | { 68 | buffer[off + j] = c; 69 | j++; 70 | } 71 | } 72 | off += bytes_per_line; 73 | count++; 74 | } 75 | 76 | free(buff); 77 | } 78 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom160x100/PCX.C: -------------------------------------------------------------------------------- 1 | #include "pcx.h" 2 | 3 | void pcx_header_read(pcx_header_s * header, FILE * pcx_file) 4 | { 5 | /* read header */ 6 | fread(header, 1, 128, pcx_file); 7 | } 8 | 9 | void pcx_buffer_load(unsigned char far * buffer, FILE * pcx_file, 10 | int bytes_per_line, int lines) 11 | { 12 | unsigned char * buff; 13 | int data_length; 14 | int i, j, k, off, count = 0; 15 | unsigned char c, d; 16 | 17 | /* allocate buffer */ 18 | buff = malloc(PCX_BUFF_SIZE+1); 19 | 20 | off = 0; 21 | 22 | data_length = 0; 23 | 24 | i = 0; 25 | while (count < lines) 26 | { 27 | j = 0; 28 | while (j < bytes_per_line) 29 | { 30 | if (i == data_length) 31 | { 32 | data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file); 33 | if (data_length == 0) 34 | { 35 | printf("Unable to read file \n"); 36 | abort(); 37 | } 38 | i = 0; 39 | } 40 | 41 | c = buff[i]; 42 | i++; 43 | 44 | if (c >= 192) /* c is a count */ 45 | { 46 | c -= 192; 47 | 48 | if (i == data_length) 49 | { 50 | data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file); 51 | if (data_length == 0) 52 | { 53 | printf("Unable to read file \n"); 54 | abort(); 55 | } 56 | i = 0; 57 | } 58 | 59 | d = buff[i]; 60 | i++; 61 | 62 | for (k = 0; k < c; k++) 63 | buffer[off + j + k] = d; 64 | 65 | j += c; 66 | } else 67 | { 68 | buffer[off + j] = c; 69 | j++; 70 | } 71 | } 72 | off += bytes_per_line; 73 | count++; 74 | } 75 | 76 | free(buff); 77 | } 78 | -------------------------------------------------------------------------------- /cga320x200/ludicrous/README.TXT: -------------------------------------------------------------------------------- 1 | Ludicrous CGA Graphics Library 2 | ============================== 3 | 4 | The ludicrous CGA functions provide a no-holds-barred approach to performance, 5 | perhaps for demos, but more often than not for intellectual interest only. 6 | 7 | * Always the fastest possible approach known 8 | * Considerable code duplication possible 9 | * Interrupts may be turned off 10 | * Self-modification is fair game if it enables an interesting approach 11 | * Routines may focus on asymptotic performance to the detriment of small cases 12 | * Additional functions may be added for programs wanting ludicrous performance 13 | * Approximations in graphics output are permitted, but not glitchy artifacts 14 | * Precomputation is permitted, but not purely brute force approaches 15 | * High memory usage is permitted if it demonstrates an interesting approach 16 | * Undocumented features/instructions may be used 17 | 18 | Lines 19 | ===== 20 | 21 | void cga_draw_line(unsigned char far * buff, int x0, int y0, int x1, int y1, unsigned char colour) 22 | 23 | Draw a line of the given colour (0-3) in the CGA buffer (320x200 x 2 bit) 24 | buff from (x0, y0) to (x1, y1) inclusive. No restrictions on input except 25 | that both endpoints be in the screen bounds. 26 | 27 | * all tricks as per fast code 28 | * use two register approximation from div instead of D, dx, dy 29 | * use bx register to hold xor value 30 | 31 | void cga_draw_hline(unsigned char far * buff, int x0, int x1, int y, unsigned char colour) 32 | 33 | Draw a horizontal line of the given colour (0-3) from (x0, y) to (x1, y) 34 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 35 | that inputs be in the screen bounds and x1 >= x0. 36 | 37 | * all tricks as per fast version 38 | * uses SALC undocumented instruction (8088/86 only) 39 | 40 | void cga_draw_vline(unsigned char far * buff, int x, int y0, int y1, unsigned char colour) 41 | 42 | Draw a vertical line of the given colour (0-3) from (x, y0) to (x, y1) 43 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 44 | that inputs be in the screen bounds and y1 >= y0. 45 | 46 | * unroll by 8 47 | * interrupts off and use SP for jump increment 48 | 49 | -------------------------------------------------------------------------------- /cga320x200/fast/README.TXT: -------------------------------------------------------------------------------- 1 | Fast CGA Graphics Library 2 | ========================= 3 | 4 | The fast CGA functions aim to provide very fast performance, somewhat at the 5 | cost of code size. However, some limitations apply. 6 | 7 | * Focus on very high performance 8 | * Will not duplicate large quantities of code for small speedups 9 | * Interrupts will not be turned off 10 | * Self-modification allowed, but only if this improves performance 11 | * Efficient initialisation of routines 12 | * Additional functions may exist for high performance programs 13 | * Generally no approximations in graphics output 14 | * Insane precomputation and memory usage not permitted 15 | 16 | Lines 17 | ===== 18 | 19 | void cga_draw_line(unsigned char far * buff, int x0, int y0, int x1, int y1, unsigned char colour) 20 | 21 | Draw a line of the given colour (0-3) in the CGA buffer (320x200 x 2 bit) 22 | buff from (x0, y0) to (x1, y1) inclusive. No restrictions on input except 23 | that both endpoints be in the screen bounds. 24 | 25 | * All tricks as per the efficient code 26 | * Special case colours 0 and 3 27 | * Hard coded for each individual colour 28 | 29 | void cga_draw_hline(unsigned char far * buff, int x0, int x1, int y, unsigned char colour) 30 | 31 | Draw a horizontal line of the given colour (0-3) from (x0, y) to (x1, y) 32 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 33 | that inputs be in the screen bounds and x1 >= x0. 34 | 35 | * unroll by 2 and use rep stosw 36 | 37 | void cga_draw_vline(unsigned char far * buff, int x, int y0, int y1, unsigned char colour) 38 | 39 | Draw a vertical line of the given colour (0-3) from (x, y0) to (x, y1) 40 | inclusive in the CGA buffer (320x200 x 2 bit) buff. No restrictions except 41 | that inputs be in the screen bounds and y1 >= y0. 42 | 43 | * unroll by 4 44 | 45 | Circles and Ellipses 46 | ==================== 47 | 48 | void cga_draw_ellipse(unsigned char far * buff, int x0, int y0, int r, int s, unsigned char colour) 49 | 50 | Draw an ellipse of the given colour (0-3) centred at (x0, r0) with semiradii 51 | r in the x direction and s in the y direction in the CGA buffer buff 52 | (320x200 x 2 bit). Assumes r <= 160, s <= 100. 53 | 54 | * links against cga_draw_vline/hline. 55 | * lookup tables to ensure pixel perfect (self-modify conditional jumps) 56 | * shift bits so decisions depend on top 16 bits (incl. lookup table adjustment) 57 | 58 | -------------------------------------------------------------------------------- /mcga320x200/BMP.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "bmp.h" 4 | 5 | unsigned char far * load_bmp(char * filename, bitmap_info_header * info) 6 | { 7 | FILE * fptr; 8 | bitmap_file_header header; 9 | unsigned char far * bitmap; 10 | unsigned char * buff; 11 | long i, bytes_read; 12 | unsigned char tmp_rgb; 13 | size_t items_read; 14 | 15 | fptr = fopen(filename, "rb"); 16 | if (fptr == NULL) 17 | { 18 | printf("Unable to open bmp file\n"); 19 | return NULL; 20 | } 21 | 22 | items_read = fread(&header, sizeof(bitmap_file_header), 1, fptr); 23 | 24 | if (items_read != 1) 25 | { 26 | printf("Unable to read file header\n"); 27 | fclose(fptr); 28 | return NULL; 29 | } 30 | 31 | if (header.file_type != 0x4d42) 32 | { 33 | printf("Not a bmp file\n"); 34 | fclose(fptr); 35 | return NULL; 36 | } 37 | 38 | items_read = fread(info, sizeof(bitmap_info_header), 1, fptr); 39 | 40 | if (items_read != 1) 41 | { 42 | printf("Unable to read image header\n"); 43 | fclose(fptr); 44 | return NULL; 45 | } 46 | 47 | fseek(fptr, header.offset_bits, SEEK_SET); 48 | 49 | bitmap = (unsigned char far *) farmalloc(info->size_image); 50 | 51 | if (bitmap == NULL) 52 | { 53 | printf("Insufficient memory\n"); 54 | fclose(fptr); 55 | return NULL; 56 | } 57 | 58 | buff = (unsigned char *) malloc(BUFF_SIZE); 59 | 60 | if (buff == NULL) 61 | { 62 | printf("Unable to allocate memory\n"); 63 | farfree(bitmap); 64 | fclose(fptr); 65 | return NULL; 66 | } 67 | 68 | bytes_read = 0; 69 | while (bytes_read < info->size_image) 70 | { 71 | size_t num = BUFF_SIZE; 72 | 73 | if (info->size_image - bytes_read < BUFF_SIZE) 74 | num = info->size_image - bytes_read; 75 | 76 | items_read = fread(buff, num, 1, fptr); 77 | 78 | if (items_read != 1) 79 | { 80 | printf("Unable to read file\n"); 81 | free(buff); 82 | farfree(bitmap); 83 | fclose(fptr); 84 | return NULL; 85 | } 86 | 87 | for (i = 0; i < num; i++, bytes_read++) 88 | bitmap[bytes_read] = buff[i]; 89 | } 90 | 91 | fclose(fptr); 92 | free(buff); 93 | 94 | return bitmap; 95 | } 96 | 97 | void free_bmp(unsigned char far * bitmap) 98 | { 99 | farfree(bitmap); 100 | } 101 | -------------------------------------------------------------------------------- /cgaeffects/wiper/WIPER.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void cga_draw_line(unsigned char far * buff, 8 | int x0, int y0, int x1, int y1, unsigned char colour); 9 | extern void cga_draw_hline(unsigned char far * buff, 10 | int x0, int x1, int y, unsigned char colour); 11 | extern void cga_draw_vline(unsigned char far * buff, 12 | int x, int y0, int y1, unsigned char colour); 13 | extern void cga_draw_line_chunky_left(unsigned char far * buff, 14 | int x0, int y0, int x1, int y1, unsigned char colour); 15 | extern void cga_draw_line_chunky_right(unsigned char far * buff, 16 | int x0, int y0, int x1, int y1, unsigned char colour); 17 | 18 | int set_video_mode(int n) 19 | { 20 | union REGS regs; 21 | 22 | regs.h.ah = 0; 23 | regs.h.al = n; 24 | int86(0x10, ®s, ®s); 25 | } 26 | 27 | int main(void) 28 | { 29 | int i, j, k, l; 30 | int xstart[6]; 31 | int ystart[4]; 32 | int diff = 3, inc = 0; 33 | int diff2 = 1, trans = 0; 34 | 35 | getchar(); 36 | 37 | set_video_mode(4); 38 | 39 | for (i = 0; i < 200; i++) 40 | cga_draw_hline(MK_FP(0xb800, 0), 0, 199, i, 0); 41 | 42 | diff = 3; 43 | 44 | for (i = 0; i < 66; i++) 45 | cga_draw_hline(MK_FP(0xb800, 0), 100, 250, i, 1); 46 | 47 | for (i = 66; i < 132; i++) 48 | cga_draw_hline(MK_FP(0xb800, 0), 100, 250, i, 2); 49 | 50 | for (i = 132; i < 198; i++) 51 | cga_draw_hline(MK_FP(0xb800, 0), 100, 250, i, 1); 52 | 53 | for (i = 0; i < 10000; i++) 54 | { 55 | inc += diff; 56 | trans += diff2; 57 | 58 | if (inc == 51 || inc == -51) 59 | diff = -diff; 60 | 61 | if (trans == 20 || trans == -50) 62 | diff2 = -diff2; 63 | 64 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 100-inc+trans, 0, 100+inc+trans, 65, 0x55); 65 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 100+inc+trans, 66, 100+inc+trans, 131, 0xaa); 66 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 100+inc+trans, 132, 100-inc+trans, 197, 0x55); 67 | 68 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 250+inc+trans, 0, 250-inc+trans, 65, 0x55); 69 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 250-inc+trans, 66, 250-inc+trans, 131, 0xaa); 70 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 250-inc+trans, 132, 250+inc+trans, 197, 0x55); 71 | } 72 | 73 | getchar(); 74 | 75 | set_video_mode(3); 76 | 77 | return 0; 78 | } 79 |  -------------------------------------------------------------------------------- /cga160x200/ludicrous/hline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | salc macro 6 | db 0d6h 7 | endm 8 | 9 | PUBLIC _cga_draw_hline 10 | _cga_draw_hline PROC 11 | ARG buff:DWORD, x0:WORD, x1:WORD, y:WORD, colour:BYTE 12 | ; draw a line from (x0, y) - (x1, y) including endpoints in the given colour (0-3) 13 | push bp 14 | mov bp, sp 15 | push di 16 | 17 | les di, buff ; get buffer address in es:di 18 | 19 | mov ax, [y] ; set dx to offset of CGA bank (odd/even) 20 | shr ax, 1 21 | sbb dx, dx 22 | and dx, 8192 23 | 24 | shl ax, 1 ; set di to offset address of line y 25 | shl ax, 1 26 | shl ax, 1 27 | shl ax, 1 28 | add dx, ax 29 | shl ax, 1 30 | shl ax, 1 31 | add dx, ax 32 | add di, dx 33 | 34 | mov ax, [x0] ; set bh to left mask based on x0 mod 2 35 | shr ax, 1 36 | sbb bh, bh 37 | not bh 38 | or bh, 0fh 39 | 40 | mov dx, [x1] ; set bl to right mask based on x1 mod 2 41 | shr dx, 1 42 | sbb bl, bl 43 | or bl, 0f0h 44 | 45 | add di, ax ; add x0/2 to offset 46 | 47 | sub dx, ax ; set dx to x1/2 - x0/2 (final offset - initial offset) 48 | 49 | mov ah, [colour] ; put solid colour in ah 50 | shr ah, 1 51 | salc 52 | and al, 055h 53 | shr ah, 1 54 | sbb ah, ah 55 | and ah, 0aah 56 | add ah, al 57 | 58 | mov al, ah ; copy colour in al 59 | 60 | dec dl ; if first and last pixels are not in the same byte 61 | jns hline_long_line 62 | 63 | and bl, bh ; compute overlapped mask and put masked colour in al 64 | and al, bl 65 | not bl 66 | 67 | and bl, es:[di] ; draw pixels 68 | or al, bl 69 | stosb 70 | 71 | pop di 72 | pop bp 73 | ret 74 | 75 | hline_long_line: 76 | and al, bh ; put left hand mask in bh and colour in al 77 | not bh 78 | 79 | and bh, es:[di] ; draw pixels on left side of line 80 | or al, bh 81 | stosb 82 | 83 | mov al, ah ; draw full colour bytes 84 | mov cx, dx 85 | shr cx, 1 86 | jnc hline_even_iter 87 | stosb 88 | hline_even_iter: 89 | rep stosw 90 | 91 | mov al, ah ; put right hand mask in bl and colour in al 92 | and al, bl 93 | not bl 94 | 95 | and bl, es:[di] ; draw right hand pixels 96 | or al, bl 97 | stosb 98 | 99 | pop di 100 | pop bp 101 | ret 102 | _cga_draw_hline ENDP 103 | 104 | END 105 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/PLASMA2.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void vga_plasma(unsigned char far * buff); 8 | extern void set_fire_palette(); 9 | 10 | int set_video_mode(int n) 11 | { 12 | union REGS regs; 13 | 14 | regs.h.ah = 0; 15 | regs.h.al = n; 16 | int86(0x10, ®s, ®s); 17 | } 18 | 19 | int main(void) 20 | { 21 | int i, j, k; 22 | unsigned int ang, ang2; 23 | unsigned char xtab[40][320], shift[40][200], c; 24 | double sintab[256]; 25 | const double pi = 3.1415926535898; 26 | const double alpha = 2.0*(pi/256); 27 | double theta0 = 1.5*(pi/64); 28 | double theta = theta0; 29 | double angle0 = 0.0; 30 | double angle = 0.0; 31 | unsigned char far * buff[40]; 32 | printf("Welcome to Plasma 1.0\n"); 33 | printf("Press a key to begin\n"); 34 | 35 | for (k = 0; k < 40; k++) 36 | buff[k] = farmalloc(6560); 37 | 38 | angle = 0.0; 39 | for (i = 0; i < 256; i++) 40 | { 41 | sintab[i] = sin(angle); 42 | angle += alpha; 43 | } 44 | 45 | set_video_mode(19); 46 | set_fire_palette(); 47 | 48 | for (k = 0; k < 40; k++) 49 | { 50 | for (i = 0, ang2 = 0; i < 200; i++, ang2+=13) 51 | { 52 | xtab[k][i] = 127.5*(sintab[255&(int)(angle/alpha)]+1.0) + (k<<4); 53 | angle += theta + theta*sintab[(ang2>>4)&255]/2; 54 | } 55 | theta0 -= 0.0006; 56 | theta = theta0; 57 | angle0 += 0.1; 58 | angle = angle0; 59 | } 60 | 61 | for (k = 0; k < 40; k++) 62 | { 63 | for (i = 0, ang2 = 0, ang = 0; 64 | i < 160; i++, ang+=(48+k), ang2+=(96+2*k)) 65 | { 66 | double factor = 50.0 + (100.0+((i+k)>>1))*(sintab[(ang2>>4)&255] + 1.0); 67 | buff[k][6400 + 159 - i] = ((((unsigned char) (factor*(sintab[(ang>>5)&255] + 1.0)))>>3)<<3); 68 | } 69 | } 70 | 71 | for (k = 0; k < 40; k++) 72 | { 73 | for (i = 0; i < 32; i++) 74 | { 75 | for (j = 0; j < 200; j++) 76 | buff[k][i*200 + j] = xtab[k][j] + (i<<3); 77 | } 78 | } 79 | 80 | for (i = 0; i < 50; i++) 81 | { 82 | for (k = 0; k < 40; k++) 83 | vga_plasma(buff[k]); 84 | 85 | delay(200); 86 | /* 87 | for (k--; k >= 1; k--) 88 | vga_plasma(buff[k]); 89 | */ 90 | } 91 | 92 | getch(); 93 | 94 | for (k = 0; k < 40; k++) 95 | farfree(buff[k]); 96 | 97 | set_video_mode(3); 98 | 99 | return 0; 100 | } -------------------------------------------------------------------------------- /cga320x200/small/hline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_hline 6 | _cga_draw_hline PROC 7 | ARG buff:DWORD, x0:WORD, x1:WORD, y:WORD, colour:BYTE 8 | ; draw a line from (x0, y) - (x1, y) including endpoints in the given colour (0-3) 9 | push bp 10 | mov bp, sp 11 | push di 12 | 13 | les di, buff ; get buffer address in es:di 14 | 15 | mov ax, [y] ; set dx to offset of CGA bank (odd/even) 16 | shr ax, 1 17 | sbb dx, dx 18 | and dx, 8192 19 | 20 | shl ax, 1 ; set di to offset address of line y 21 | shl ax, 1 22 | shl ax, 1 23 | shl ax, 1 24 | add dx, ax 25 | shl ax, 1 26 | shl ax, 1 27 | add dx, ax 28 | add di, dx 29 | 30 | mov ax, [x0] ; set cl to 2*(x0 mod 4) 31 | mov cx, ax 32 | and cx, 3 33 | shl cx, 1 34 | 35 | mov dx, [x1] ; set bl to 2*(x1 mod 4) 36 | mov bx, dx 37 | and bx, 3 38 | shl bx, 1 39 | 40 | shr ax, 1 ; add x0/4 to offset 41 | shr ax, 1 42 | add di, ax 43 | 44 | shr dx, 1 ; set dx to x1/4 - x0/4 (final offset - initial offset) 45 | shr dx, 1 46 | sub dx, ax 47 | 48 | mov al, [colour] ; put solid colour in ah 49 | shr al, 1 50 | sbb ah, ah 51 | and ah, 055h 52 | shr al, 1 53 | sbb al, al 54 | and al, 0aah 55 | add ah, al 56 | 57 | mov bh, 0ffh ; prepare left mask in bh 58 | shr bh, cl 59 | 60 | mov cl, bl ; prepare right mask in bl 61 | mov bl, 0c0h 62 | sar bl, cl 63 | 64 | mov al, ah ; copy colour in al 65 | 66 | dec dl ; if first and last pixels are not in the same byte 67 | jns hline_long_line 68 | 69 | and bl, bh ; compute overlapped mask and put masked colour in al 70 | and al, bl 71 | not bl 72 | 73 | and bl, es:[di] ; draw pixels 74 | or al, bl 75 | stosb 76 | 77 | pop di 78 | pop bp 79 | ret 80 | 81 | hline_long_line: 82 | and al, bh ; put left hand mask in bh and colour in al 83 | not bh 84 | 85 | and bh, es:[di] ; draw pixels on left side of line 86 | or al, bh 87 | stosb 88 | 89 | mov al, ah ; draw full colour bytes 90 | mov cx, dx 91 | 92 | rep stosb 93 | 94 | mov al, ah ; put right hand mask in bl and colour in al 95 | and al, bl 96 | not bl 97 | 98 | and bl, es:[di] ; draw right hand pixels 99 | or al, bl 100 | stosb 101 | 102 | pop di 103 | pop bp 104 | ret 105 | _cga_draw_hline ENDP 106 | 107 | END 108 | -------------------------------------------------------------------------------- /cga2.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_line1 6 | _cga_draw_line1 PROC 7 | LOCAL yinc:WORD, ycorr:WORD=AUTO_SIZE 8 | ARG x0:WORD, y0:WORD, xdiff:WORD, ydiff:WORD, D:WORD, xend:WORD, colour:BYTE 9 | ; line from (x0, y0) - (xend, ?) including endpoints 10 | ; AX: Acc, BX: 2*dx, DX: 2*dy, CX: Loop, 11 | ; SI: D, DI: Offset, DS: Colour/Mask, ES: B800 12 | push bp 13 | mov bp, sp 14 | sub sp, AUTO_SIZE 15 | push di 16 | push si 17 | push ds 18 | 19 | mov ax, 0b800h ; set segment for CGA memory 20 | mov es, ax 21 | 22 | xor di, di ; compute offset for raster y0 23 | mov ax, [y0] 24 | shr ax, 1 25 | sbb di, 0 26 | and di, 8192 27 | mov cl, 4 28 | shl ax, cl 29 | add di, ax 30 | shl ax, 1 31 | shl ax, 1 32 | add di, ax 33 | 34 | mov bx, [xdiff] ; compute 2*dx 35 | shl bx, 1 36 | 37 | mov dx, [ydiff] ; compute 2*dy 38 | shl dx, 1 39 | 40 | mov [yinc], 8112 ; set up y increment 41 | mov [ycorr], 16304 42 | cmp dx, 0 43 | jge line1_yinc 44 | add [yinc], 80 45 | neg dx 46 | line1_yinc: 47 | 48 | mov si, D ; store D 49 | 50 | mov cx, [x0] ; set up colour and mask 51 | mov ah, [colour] 52 | inc cl 53 | and cl, 3 54 | shl cl, 1 55 | ror ah, cl 56 | mov al, 0fch 57 | ror al, cl 58 | mov ds, ax 59 | 60 | mov ax, [x0] ; get x0 61 | 62 | mov cx, [xend] ; compute loop iterations 63 | sub cx, ax 64 | inc cx 65 | 66 | shr ax, 1 ; adjust offset for column x0 67 | shr ax, 1 68 | add di, ax 69 | 70 | sub si, dx ; compensate for first addition of 2*dy 71 | 72 | mov ax, ds ; get colour and mask information 73 | 74 | line1_loop: 75 | and al, es:[di] ; draw pixel at x, y 76 | or al, ah 77 | stosb 78 | 79 | add si, dx ; D += 2*dy 80 | jle line1_skip_inc_y 81 | 82 | xor ax, ax ; increment y 83 | sub di, [yinc] 84 | sbb ax, ax 85 | and ax, [ycorr] 86 | add di, ax 87 | 88 | sub si, bx ; D -= 2*dx 89 | line1_skip_inc_y: 90 | mov ax, ds ; increment x 91 | ror ah, 1 92 | ror ah, 1 93 | ror al, 1 94 | ror al, 1 95 | sbb di, 0 ; adjust offset 96 | mov ds, ax ; store updated colour and mask 97 | 98 | loop line1_loop 99 | 100 | pop ds 101 | pop si 102 | pop di 103 | add sp, AUTO_SIZE 104 | pop bp 105 | ret 106 | _cga_draw_line1 ENDP 107 | 108 | END 109 | 110 | -------------------------------------------------------------------------------- /cga320x200/fast/hline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_hline 6 | _cga_draw_hline PROC 7 | ARG buff:DWORD, x0:WORD, x1:WORD, y:WORD, colour:BYTE 8 | ; draw a line from (x0, y) - (x1, y) including endpoints in the given colour (0-3) 9 | push bp 10 | mov bp, sp 11 | push di 12 | 13 | les di, buff ; get buffer address in es:di 14 | 15 | mov ax, [y] ; set dx to offset of CGA bank (odd/even) 16 | shr ax, 1 17 | sbb dx, dx 18 | and dx, 8192 19 | 20 | shl ax, 1 ; set di to offset address of line y 21 | shl ax, 1 22 | shl ax, 1 23 | shl ax, 1 24 | add dx, ax 25 | shl ax, 1 26 | shl ax, 1 27 | add dx, ax 28 | add di, dx 29 | 30 | mov ax, [x0] ; set cl to 2*(x0 mod 4) 31 | mov cx, ax 32 | and cx, 3 33 | shl cx, 1 34 | 35 | mov dx, [x1] ; set bl to 2*(x1 mod 4) 36 | mov bx, dx 37 | and bx, 3 38 | shl bx, 1 39 | 40 | shr ax, 1 ; add x0/4 to offset 41 | shr ax, 1 42 | add di, ax 43 | 44 | shr dx, 1 ; set dx to x1/4 - x0/4 (final offset - initial offset) 45 | shr dx, 1 46 | sub dx, ax 47 | 48 | mov al, [colour] ; put solid colour in ah 49 | shr al, 1 50 | sbb ah, ah 51 | and ah, 055h 52 | shr al, 1 53 | sbb al, al 54 | and al, 0aah 55 | add ah, al 56 | 57 | mov bh, 0ffh ; prepare left mask in bh 58 | shr bh, cl 59 | 60 | mov cl, bl ; prepare right mask in bl 61 | mov bl, 0c0h 62 | sar bl, cl 63 | 64 | mov al, ah ; copy colour in al 65 | 66 | dec dl ; if first and last pixels are not in the same byte 67 | jns hline_long_line 68 | 69 | and bl, bh ; compute overlapped mask and put masked colour in al 70 | and al, bl 71 | not bl 72 | 73 | and bl, es:[di] ; draw pixels 74 | or al, bl 75 | stosb 76 | 77 | pop di 78 | pop bp 79 | ret 80 | 81 | hline_long_line: 82 | and al, bh ; put left hand mask in bh and colour in al 83 | not bh 84 | 85 | and bh, es:[di] ; draw pixels on left side of line 86 | or al, bh 87 | stosb 88 | 89 | mov al, ah ; draw full colour bytes 90 | mov cx, dx 91 | shr cx, 1 92 | jnc hline_even_iter 93 | stosb 94 | hline_even_iter: 95 | rep stosw 96 | 97 | mov al, ah ; put right hand mask in bl and colour in al 98 | and al, bl 99 | not bl 100 | 101 | and bl, es:[di] ; draw right hand pixels 102 | or al, bl 103 | stosb 104 | 105 | pop di 106 | pop bp 107 | ret 108 | _cga_draw_hline ENDP 109 | 110 | END 111 | -------------------------------------------------------------------------------- /cga320x200/efficient/hline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_hline 6 | _cga_draw_hline PROC 7 | ARG buff:DWORD, x0:WORD, x1:WORD, y:WORD, colour:BYTE 8 | ; draw a line from (x0, y) - (x1, y) including endpoints in the given colour (0-3) 9 | push bp 10 | mov bp, sp 11 | push di 12 | 13 | les di, buff ; get buffer address in es:di 14 | 15 | mov ax, [y] ; set dx to offset of CGA bank (odd/even) 16 | shr ax, 1 17 | sbb dx, dx 18 | and dx, 8192 19 | 20 | shl ax, 1 ; set di to offset address of line y 21 | shl ax, 1 22 | shl ax, 1 23 | shl ax, 1 24 | add dx, ax 25 | shl ax, 1 26 | shl ax, 1 27 | add dx, ax 28 | add di, dx 29 | 30 | mov ax, [x0] ; set cl to 2*(x0 mod 4) 31 | mov cx, ax 32 | and cx, 3 33 | shl cx, 1 34 | 35 | mov dx, [x1] ; set bl to 2*(x1 mod 4) 36 | mov bx, dx 37 | and bx, 3 38 | shl bx, 1 39 | 40 | shr ax, 1 ; add x0/4 to offset 41 | shr ax, 1 42 | add di, ax 43 | 44 | shr dx, 1 ; set dx to x1/4 - x0/4 (final offset - initial offset) 45 | shr dx, 1 46 | sub dx, ax 47 | 48 | mov al, [colour] ; put solid colour in ah 49 | shr al, 1 50 | sbb ah, ah 51 | and ah, 055h 52 | shr al, 1 53 | sbb al, al 54 | and al, 0aah 55 | add ah, al 56 | 57 | mov bh, 0ffh ; prepare left mask in bh 58 | shr bh, cl 59 | 60 | mov cl, bl ; prepare right mask in bl 61 | mov bl, 0c0h 62 | sar bl, cl 63 | 64 | mov al, ah ; copy colour in al 65 | 66 | dec dl ; if first and last pixels are not in the same byte 67 | jns hline_long_line 68 | 69 | and bl, bh ; compute overlapped mask and put masked colour in al 70 | and al, bl 71 | not bl 72 | 73 | and bl, es:[di] ; draw pixels 74 | or al, bl 75 | stosb 76 | 77 | pop di 78 | pop bp 79 | ret 80 | 81 | hline_long_line: 82 | and al, bh ; put left hand mask in bh and colour in al 83 | not bh 84 | 85 | and bh, es:[di] ; draw pixels on left side of line 86 | or al, bh 87 | stosb 88 | 89 | mov al, ah ; draw full colour bytes 90 | mov cx, dx 91 | shr cx, 1 92 | jnc hline_even_iter 93 | stosb 94 | hline_even_iter: 95 | rep stosw 96 | 97 | mov al, ah ; put right hand mask in bl and colour in al 98 | and al, bl 99 | not bl 100 | 101 | and bl, es:[di] ; draw right hand pixels 102 | or al, bl 103 | stosb 104 | 105 | pop di 106 | pop bp 107 | ret 108 | _cga_draw_hline ENDP 109 | 110 | END 111 | -------------------------------------------------------------------------------- /cga320x200/ludicrous/hline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | salc macro 6 | db 0d6h 7 | endm 8 | 9 | PUBLIC _cga_draw_hline 10 | _cga_draw_hline PROC 11 | ARG buff:DWORD, x0:WORD, x1:WORD, y:WORD, colour:BYTE 12 | ; draw a line from (x0, y) - (x1, y) including endpoints in the given colour (0-3) 13 | push bp 14 | mov bp, sp 15 | push di 16 | 17 | les di, buff ; get buffer address in es:di 18 | 19 | mov ax, [y] ; set dx to offset of CGA bank (odd/even) 20 | shr ax, 1 21 | sbb dx, dx 22 | and dx, 8192 23 | 24 | shl ax, 1 ; set di to offset address of line y 25 | shl ax, 1 26 | shl ax, 1 27 | shl ax, 1 28 | add dx, ax 29 | shl ax, 1 30 | shl ax, 1 31 | add dx, ax 32 | add di, dx 33 | 34 | mov ax, [x0] ; set cl to 2*(x0 mod 4) 35 | mov cx, ax 36 | and cx, 3 37 | shl cx, 1 38 | 39 | mov dx, [x1] ; set bl to 2*(x1 mod 4) 40 | mov bx, dx 41 | and bx, 3 42 | shl bx, 1 43 | 44 | shr ax, 1 ; add x0/4 to offset 45 | shr ax, 1 46 | add di, ax 47 | 48 | shr dx, 1 ; set dx to x1/4 - x0/4 (final offset - initial offset) 49 | shr dx, 1 50 | sub dx, ax 51 | 52 | mov ah, [colour] ; put solid colour in ah 53 | shr ah, 1 54 | salc 55 | and al, 055h 56 | shr ah, 1 57 | sbb ah, ah 58 | and ah, 0aah 59 | add ah, al 60 | 61 | mov bh, 0ffh ; prepare left mask in bh 62 | shr bh, cl 63 | 64 | mov cl, bl ; prepare right mask in bl 65 | mov bl, 0c0h 66 | sar bl, cl 67 | 68 | mov al, ah ; copy colour in al 69 | 70 | dec dl ; if first and last pixels are not in the same byte 71 | jns hline_long_line 72 | 73 | and bl, bh ; compute overlapped mask and put masked colour in al 74 | and al, bl 75 | not bl 76 | 77 | and bl, es:[di] ; draw pixels 78 | or al, bl 79 | stosb 80 | 81 | pop di 82 | pop bp 83 | ret 84 | 85 | hline_long_line: 86 | and al, bh ; put left hand mask in bh and colour in al 87 | not bh 88 | 89 | and bh, es:[di] ; draw pixels on left side of line 90 | or al, bh 91 | stosb 92 | 93 | mov al, ah ; draw full colour bytes 94 | mov cx, dx 95 | shr cx, 1 96 | jnc hline_even_iter 97 | stosb 98 | hline_even_iter: 99 | rep stosw 100 | 101 | mov al, ah ; put right hand mask in bl and colour in al 102 | and al, bl 103 | not bl 104 | 105 | and bl, es:[di] ; draw right hand pixels 106 | or al, bl 107 | stosb 108 | 109 | pop di 110 | pop bp 111 | ret 112 | _cga_draw_hline ENDP 113 | 114 | END 115 | -------------------------------------------------------------------------------- /cga3.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_line1 6 | _cga_draw_line1 PROC 7 | ARG x0:WORD, y0:WORD, xdiff:WORD, ydiff:WORD, D:WORD, xend:WORD, colour:BYTE 8 | ; line from (x0, y0) - (xend, ?) including endpoints 9 | ; AX: Acc, BX: 2*dx, DX: 2*dy, CX: Loop, BP: ydelta 10 | ; SI: D, DI: Offset, DS: Colour/Mask, ES: B800 11 | push bp 12 | mov bp, sp 13 | push di 14 | push si 15 | push ds 16 | 17 | mov ax, 0b800h ; set segment for CGA memory 18 | mov es, ax 19 | 20 | xor di, di ; compute offset for line y0 21 | mov ax, [y0] 22 | shr ax, 1 23 | 24 | mov bx, 8192 ; also compute ydelta 25 | jnc line1_y_even 26 | mov bx, -8112 27 | line1_y_even: 28 | push bx 29 | 30 | sbb di, 0 ; continue computing offset for line y0 31 | and di, 8192 32 | mov cl, 4 33 | shl ax, cl 34 | add di, ax 35 | shl ax, 1 36 | shl ax, 1 37 | add di, ax 38 | 39 | mov bx, [xdiff] ; compute 2*dx 40 | shl bx, 1 41 | 42 | mov dx, [ydiff] ; compute 2*dy 43 | shl dx, 1 44 | 45 | line1_yinc: 46 | 47 | mov si, [D] ; store D 48 | 49 | mov cx, [x0] ; set up colour and mask 50 | mov ah, [colour] 51 | inc cl 52 | and cl, 3 53 | shl cl, 1 54 | ror ah, cl 55 | mov al, 0fch 56 | ror al, cl 57 | mov ds, ax 58 | 59 | mov ax, [x0] ; get x0 60 | 61 | mov cx, [xend] ; compute loop iterations 62 | sub cx, ax 63 | inc cx 64 | 65 | shr ax, 1 ; adjust offset for column x0 66 | shr ax, 1 67 | add di, ax 68 | 69 | sub si, dx ; compensate for first addition of 2*dy 70 | 71 | mov ax, ds ; get colour and mask information 72 | 73 | pop bp ; ydelta 74 | 75 | cli 76 | mov WORD PTR cs:[line1_patch1 + 1], sp 77 | mov sp, dx 78 | mov dx, ax 79 | 80 | line1_loop: 81 | and al, es:[di] ; draw pixel at x, y 82 | or al, dh 83 | stosb 84 | 85 | add si, sp ; D += 2*dy 86 | jle line1_skip_inc_y 87 | 88 | add di, bp ; odd <-> even line (reenigne's trick) 89 | xor bp, -16304 ; adjust ydelta 90 | 91 | sub si, bx ; D -= 2*dx 92 | 93 | line1_skip_inc_y: 94 | 95 | ror dh, 1 ; increment x 96 | ror dh, 1 97 | ror dl, 1 98 | ror dl, 1 99 | sbb di, 0 ; adjust offset 100 | mov al, dl ; store updated colour and mask 101 | 102 | loop line1_loop 103 | 104 | line1_patch1: 105 | mov sp, 1234 106 | sti 107 | pop ds 108 | pop si 109 | pop di 110 | pop bp 111 | ret 112 | _cga_draw_line1 ENDP 113 | 114 | END 115 | 116 | -------------------------------------------------------------------------------- /cga320x200/small/vline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_vline 6 | _cga_draw_vline PROC 7 | ARG buff:DWORD, x:WORD, y0:WORD, y1:WORD, colour:BYTE 8 | ; draw a line from (x, y0) - (x, y1) including endpoints in the give colour (0-3) 9 | push bp 10 | mov bp, sp 11 | push di 12 | push si 13 | push ds 14 | 15 | les di, buff ; get buffer address in es:di 16 | 17 | mov ax, es ; mirror in ds 18 | mov ds, ax 19 | 20 | mov ax, [y0] ; get y0 coordinate 21 | inc ax 22 | shr ax, 1 ; set ax = (y0 + 1)/2 23 | cmc 24 | sbb bx, bx ; bx = -1 if y0 is odd, else bx = 0 25 | 26 | mov dx, [y1] ; get y1 coordinate 27 | shr dx, 1 ; y1/2 28 | cmc 29 | sbb cx, cx ; cx = -1 if y1 even, else cx = 0 30 | 31 | sub dx, ax ; dx = even line iterations 32 | inc dx 33 | 34 | mov si, dx ; si = odd line iterations 35 | add si, cx 36 | sub si, bx 37 | 38 | and bx, -80 ; bx = -80 if y0 is odd, else bx = 0 39 | 40 | shl ax, 1 ; set di to 80*(y0 + 1)/2 = first even line 41 | shl ax, 1 42 | shl ax, 1 43 | shl ax, 1 44 | add di, ax 45 | shl ax, 1 46 | shl ax, 1 47 | add di, ax 48 | 49 | add bx, di ; set bx to 8192 + 80*(y0/2) = first odd line 50 | add bh, 020h 51 | 52 | mov ax, [x] ; get x coordinate 53 | mov cl, al 54 | shr ax, 1 55 | shr ax, 1 ; compute byte of pixel at coord x 56 | add di, ax ; add it to offset of first even line 57 | add bx, ax ; add it to offset of first odd line 58 | 59 | mov ah, [colour] ; shift colour (ah) and mask (dl) into correct bitfields 60 | inc cl 61 | and cl, 3 62 | shl cl, 1 63 | ror ah, cl 64 | mov al, 0fch 65 | ror al, cl 66 | 67 | mov cx, dx ; get iterations 68 | 69 | mov dl, al 70 | 71 | cmp cx, 0 ; check for zero iterations 72 | je vline_done_even 73 | 74 | vline_even: ; display pixels on even lines 75 | 76 | mov al, dl ; write pixel 77 | and al, [di] 78 | or al, ah 79 | stosb 80 | 81 | add di, 79 ; jump to next even line 82 | loop vline_even ; loop 83 | 84 | vline_done_even: 85 | 86 | mov di, bx ; load offset of first odd line 87 | 88 | mov cx, si ; get iterations 89 | 90 | mov bx, 79 ; store jump value 91 | 92 | cmp cx, 0 ; check for zero iterations 93 | je vline_done_odd 94 | 95 | vline_odd: ; display pixels on odd lines 96 | 97 | mov al, dl ; write pixel 98 | and al, [di] 99 | or al, ah 100 | stosb 101 | 102 | add di, bx ; jump to next odd line 103 | loop vline_odd ; loop 104 | 105 | vline_done_odd: 106 | 107 | pop ds 108 | pop si 109 | pop di 110 | pop bp 111 | ret 112 | _cga_draw_vline ENDP 113 | 114 | END -------------------------------------------------------------------------------- /vgaeffects/plasma/VGA.ASM: -------------------------------------------------------------------------------- 1 | .MODEL small 2 | .stack 100h 3 | 4 | .CODE 5 | .386 6 | public _vga_plasma 7 | _vga_plasma PROC 8 | ARG sintab:WORD 9 | push bp 10 | mov bp, sp 11 | push di 12 | 13 | mov ah, 00h 14 | mov al, 13h 15 | int 10h 16 | 17 | mov ax, 0a000h 18 | mov es, ax 19 | xor di, di 20 | 21 | mov al, 1 22 | mov dx, 3c8h 23 | out dx, al 24 | 25 | mov dx, 3c9h 26 | 27 | mov ah, 255 28 | mov bl, 0 29 | 30 | mov cx, 84 31 | 32 | plasma_rg_loop: 33 | sub ah, 3 34 | add bl, 3 35 | mov al, ah 36 | inc al 37 | shr al, 1 38 | shr al, 1 39 | dec al 40 | out dx, al 41 | mov al, bl 42 | inc al 43 | shr al, 1 44 | shr al, 1 45 | dec al 46 | out dx, al 47 | xor al, al 48 | out dx, al 49 | loop plasma_rg_loop 50 | 51 | sub ah, 3 52 | add bl, 3 53 | 54 | xor al, al 55 | out dx, al 56 | mov al, 63 57 | out dx, al 58 | xor al, al 59 | out dx, al 60 | 61 | mov cx, 84 62 | 63 | plasma_gb_loop: 64 | add ah, 3 65 | sub bl, 3 66 | xor al, al 67 | out dx, al 68 | mov al, bl 69 | inc al 70 | shr al, 1 71 | shr al, 1 72 | dec al 73 | out dx, al 74 | mov al, ah 75 | inc al 76 | shr al, 1 77 | shr al, 1 78 | dec al 79 | out dx, al 80 | loop plasma_gb_loop 81 | 82 | mov ah, 63 83 | sub bl, 3 84 | 85 | xor al, al 86 | out dx, al 87 | out dx, al 88 | mov al, ah 89 | out dx, al 90 | 91 | mov cx, 84 92 | 93 | plasma_bw_loop: 94 | add bl, 3 95 | mov al, bl 96 | inc al 97 | shr al, 1 98 | shr al, 1 99 | dec al 100 | out dx, al 101 | out dx, al 102 | mov al, ah 103 | out dx, al 104 | loop plasma_bw_loop 105 | 106 | mov al, ah 107 | out dx, al 108 | out dx, al 109 | out dx, al 110 | 111 | mov bx, sintab 112 | 113 | mov cx, 86 114 | frame_loop: 115 | push cx 116 | 117 | xor di, di 118 | ror ebx, 16 119 | mov bx, cx 120 | rol ebx, 16 121 | 122 | push ebx 123 | 124 | mov dx, 200 125 | line_loop: 126 | 127 | mov si, dx 128 | patch1: 129 | add si, 0 130 | and si, 63 131 | mov ah, [bx+si] 132 | 133 | pop ebx 134 | 135 | ror ebx, 16 136 | add bx, dx 137 | rol ebx, 16 138 | 139 | push ebx 140 | 141 | mov cx, 320 142 | pixel_loop: 143 | 144 | mov al, ah 145 | 146 | mov si, cx 147 | patch2: 148 | add si, 0 149 | and si, 63 150 | add al, [bx+si] 151 | shr al, 1 152 | 153 | ror ebx, 16 154 | add bx, cx 155 | mov si, bx 156 | shr si, 8 157 | rol ebx, 16 158 | 159 | and si, 63 160 | add al, [bx+si] 161 | 162 | inc al 163 | 164 | stosb 165 | loop pixel_loop 166 | 167 | dec dx 168 | jnz line_loop 169 | 170 | add WORD PTR [patch1+2], 1 171 | add WORD PTR [patch2+2], 3 172 | 173 | pop ebx 174 | 175 | pop cx 176 | loop frame_loop 177 | 178 | pop di 179 | pop bp 180 | ret 181 | _vga_plasma ENDP 182 | 183 | public _text_mode 184 | _text_mode PROC 185 | mov ah, 00h 186 | mov al, 03h 187 | int 10h 188 | 189 | ret 190 | _text_mode ENDP 191 | 192 | END 193 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/VGA.ASM: -------------------------------------------------------------------------------- 1 | .MODEL small 2 | .stack 100h 3 | 4 | .CODE 5 | .386 6 | public _vga_plasma 7 | _vga_plasma PROC 8 | ARG sintab:WORD 9 | push bp 10 | mov bp, sp 11 | push di 12 | 13 | mov ah, 00h 14 | mov al, 13h 15 | int 10h 16 | 17 | mov ax, 0a000h 18 | mov es, ax 19 | xor di, di 20 | 21 | mov al, 1 22 | mov dx, 3c8h 23 | out dx, al 24 | 25 | mov dx, 3c9h 26 | 27 | mov ah, 255 28 | mov bl, 0 29 | 30 | mov cx, 84 31 | 32 | plasma_rg_loop: 33 | sub ah, 3 34 | add bl, 3 35 | mov al, ah 36 | inc al 37 | shr al, 1 38 | shr al, 1 39 | dec al 40 | out dx, al 41 | mov al, bl 42 | inc al 43 | shr al, 1 44 | shr al, 1 45 | dec al 46 | out dx, al 47 | xor al, al 48 | out dx, al 49 | loop plasma_rg_loop 50 | 51 | sub ah, 3 52 | add bl, 3 53 | 54 | xor al, al 55 | out dx, al 56 | mov al, 63 57 | out dx, al 58 | xor al, al 59 | out dx, al 60 | 61 | mov cx, 84 62 | 63 | plasma_gb_loop: 64 | add ah, 3 65 | sub bl, 3 66 | xor al, al 67 | out dx, al 68 | mov al, bl 69 | inc al 70 | shr al, 1 71 | shr al, 1 72 | dec al 73 | out dx, al 74 | mov al, ah 75 | inc al 76 | shr al, 1 77 | shr al, 1 78 | dec al 79 | out dx, al 80 | loop plasma_gb_loop 81 | 82 | mov ah, 63 83 | sub bl, 3 84 | 85 | xor al, al 86 | out dx, al 87 | out dx, al 88 | mov al, ah 89 | out dx, al 90 | 91 | mov cx, 84 92 | 93 | plasma_bw_loop: 94 | add bl, 3 95 | mov al, bl 96 | inc al 97 | shr al, 1 98 | shr al, 1 99 | dec al 100 | out dx, al 101 | out dx, al 102 | mov al, ah 103 | out dx, al 104 | loop plasma_bw_loop 105 | 106 | mov al, ah 107 | out dx, al 108 | out dx, al 109 | out dx, al 110 | 111 | mov bx, sintab 112 | 113 | mov cx, 86 114 | frame_loop: 115 | push cx 116 | 117 | xor di, di 118 | ror ebx, 16 119 | mov bx, cx 120 | rol ebx, 16 121 | 122 | push ebx 123 | 124 | mov dx, 200 125 | line_loop: 126 | 127 | mov si, dx 128 | patch1: 129 | add si, 0 130 | and si, 63 131 | mov ah, [bx+si] 132 | 133 | pop ebx 134 | 135 | ror ebx, 16 136 | add bx, dx 137 | rol ebx, 16 138 | 139 | push ebx 140 | 141 | mov cx, 320 142 | pixel_loop: 143 | 144 | mov al, ah 145 | 146 | mov si, cx 147 | patch2: 148 | add si, 0 149 | and si, 63 150 | add al, [bx+si] 151 | shr al, 1 152 | 153 | ror ebx, 16 154 | add bx, cx 155 | mov si, bx 156 | shr si, 8 157 | rol ebx, 16 158 | 159 | and si, 63 160 | add al, [bx+si] 161 | 162 | inc al 163 | 164 | stosb 165 | loop pixel_loop 166 | 167 | dec dx 168 | jnz line_loop 169 | 170 | add WORD PTR [patch1+2], 1 171 | add WORD PTR [patch2+2], 3 172 | 173 | pop ebx 174 | 175 | pop cx 176 | loop frame_loop 177 | 178 | pop di 179 | pop bp 180 | ret 181 | _vga_plasma ENDP 182 | 183 | public _text_mode 184 | _text_mode PROC 185 | mov ah, 00h 186 | mov al, 03h 187 | int 10h 188 | 189 | ret 190 | _text_mode ENDP 191 | 192 | END 193 | -------------------------------------------------------------------------------- /games/ENVOIGHT/PAGE.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "page.h" 4 | 5 | unsigned char far * page_alloc() 6 | { 7 | return farcalloc(2, PAGE_ODDB); 8 | } 9 | 10 | void page_free(unsigned char far * page) 11 | { 12 | farfree(page); 13 | } 14 | 15 | void page_copy_bg(unsigned char far * page, unsigned char far * video) 16 | { 17 | page += PAGE_OFFSET; 18 | 19 | asm push ds 20 | 21 | asm mov bx, 200 22 | asm mov dx, 80 23 | 24 | asm lds si, video 25 | asm les di, page 26 | 27 | asm xor al, al 28 | 29 | next_line: 30 | 31 | asm mov cx, dx 32 | asm shr cx, 1 33 | 34 | asm repz 35 | asm movsw 36 | 37 | asm sub si, dx 38 | asm sub di, dx 39 | 40 | asm xor al, 1 41 | asm jnz even_line 42 | 43 | asm sub si, (8192-80) 44 | asm sub di, (PAGE_ODDB-PAGE_LINEB) 45 | 46 | asm jmp next_iter 47 | 48 | even_line: 49 | 50 | asm add si, 8192 51 | asm add di, PAGE_ODDB 52 | 53 | next_iter: 54 | 55 | asm dec bl 56 | asm jnz next_line 57 | 58 | asm pop ds 59 | } 60 | 61 | void page_flip_box_aligned(unsigned char far * video, 62 | unsigned char far * page, int x, int y, int xsize, int ysize) 63 | { 64 | int off1 = (y>>1)*80 + (x>>2); 65 | int off2 = PAGE_OFFSET+(y>>1)*PAGE_LINEB+(x>>2); 66 | int end, i; 67 | 68 | xsize >>= 2; 69 | 70 | if (y & 1) 71 | { 72 | off1 += 8192; 73 | off2 += PAGE_ODDB; 74 | } 75 | 76 | asm push ds 77 | asm les di, video 78 | asm add di, off1 79 | asm lds si, page 80 | asm add si, off2 81 | 82 | asm mov bl, y 83 | asm and bl, 1 84 | 85 | asm mov dx, ysize 86 | 87 | next_line: 88 | 89 | asm mov cx, xsize 90 | asm shr cx, 1 91 | 92 | asm repz 93 | asm movsw 94 | 95 | asm sub si, xsize 96 | asm sub di, xsize 97 | 98 | asm xor bl, 1 99 | asm jp odd_line 100 | 101 | asm add si, PAGE_ODDB 102 | asm add di, 8192 103 | 104 | asm jmp cont_line 105 | 106 | odd_line: 107 | 108 | asm sub si, (PAGE_ODDB-PAGE_LINEB) 109 | asm sub di, (8192-80) 110 | 111 | cont_line: 112 | 113 | asm dec dx 114 | asm jnz next_line 115 | 116 | asm pop ds 117 | } 118 | 119 | void page_flip_box_unaligned(unsigned char far * video, 120 | unsigned char far * page, int x, int y, int xsize, int ysize) 121 | { 122 | int off1 = (y>>1)*80 + (x>>2); 123 | int off2 = PAGE_OFFSET+(y>>1)*PAGE_LINEB+(x>>2); 124 | int end, i; 125 | 126 | xsize >>= 2; 127 | 128 | if (y & 1) 129 | { 130 | off1 += 8192; 131 | off2 += PAGE_ODDB; 132 | } 133 | 134 | asm push ds 135 | asm les di, video 136 | asm add di, off1 137 | asm lds si, page 138 | asm add si, off2 139 | 140 | asm mov bl, y 141 | asm and bl, 1 142 | 143 | asm mov dx, ysize 144 | 145 | next_line: 146 | 147 | asm mov cx, xsize 148 | 149 | asm repz 150 | asm movsb 151 | 152 | asm sub si, xsize 153 | asm sub di, xsize 154 | 155 | asm xor bl, 1 156 | asm jp odd_line 157 | 158 | asm add si, PAGE_ODDB 159 | asm add di, 8192 160 | 161 | asm jmp cont_line 162 | 163 | odd_line: 164 | 165 | asm sub si, (PAGE_ODDB-PAGE_LINEB) 166 | asm sub di, (8192-80) 167 | 168 | cont_line: 169 | 170 | asm dec dx 171 | asm jnz next_line 172 | 173 | asm pop ds 174 | } 175 | -------------------------------------------------------------------------------- /games/ENVOIGHT/GRAPHICS.C: -------------------------------------------------------------------------------- 1 | #include "graphics.h" 2 | 3 | /****************************************************************************** 4 | * 5 | * General graphics routines 6 | * 7 | ******************************************************************************/ 8 | 9 | int set_video_mode(int n) 10 | { 11 | union REGS regs; 12 | 13 | regs.h.ah = 0; 14 | regs.h.al = n; 15 | int86(0x10, ®s, ®s); 16 | } 17 | 18 | /****************************************************************************** 19 | * 20 | * PCX graphics format 21 | * 22 | ******************************************************************************/ 23 | 24 | /* save some regs by giving these global addresses */ 25 | 26 | unsigned char far * abuff0; 27 | unsigned char far * abuff1; 28 | unsigned char far * pcx_buff; 29 | 30 | void cga_pcx_decode(unsigned char far * buff, 31 | int data_length, int bytes_per_line) 32 | { 33 | abuff0 = MK_FP(0xb800, 0x0000); 34 | abuff1 = MK_FP(0xba00, 0x0000); 35 | pcx_buff = buff; 36 | 37 | asm push bp 38 | asm jmp startproc 39 | 40 | /* store CGA image in buffers */ 41 | 42 | storebyte: 43 | asm _storebyte proc near 44 | 45 | asm stosb 46 | asm inc dx 47 | asm cmp dl, ah 48 | asm je row_ends 49 | asm loop storebyte 50 | asm ret 51 | 52 | asm _storebyte endp 53 | 54 | row_ends: 55 | 56 | asm xor bp, 1 57 | asm sub di, dx 58 | asm add di, 80 59 | asm cmp bp, 1 60 | asm je bank1 61 | asm mov word ptr abuff1, di 62 | asm les di, abuff0 63 | asm xor dx, dx 64 | asm loop storebyte 65 | asm ret 66 | 67 | bank1: 68 | 69 | asm mov word ptr abuff0, di 70 | asm les di, abuff1 71 | asm xor dx, dx 72 | asm loop storebyte 73 | asm ret 74 | 75 | /* main assembly procedure for CGA */ 76 | 77 | startproc: 78 | 79 | asm mov es, word ptr abuff0[2] 80 | asm mov di, word ptr abuff0 81 | asm mov ah, byte ptr bytes_per_line 82 | asm mov bx, data_length 83 | asm mov bp, 0 84 | asm xor cx, cx 85 | asm xor dx, dx 86 | asm mov si, dx 87 | asm cld 88 | 89 | /* loop through input buffer */ 90 | 91 | getbyte: 92 | 93 | asm cmp si, bx 94 | asm je exit 95 | asm push es 96 | asm push di 97 | asm les di, pcx_buff 98 | asm add di, si 99 | asm mov al, [es:di] 100 | asm inc si 101 | asm pop di 102 | asm pop es 103 | asm cmp cl, 0 104 | asm jg multi_data 105 | asm cmp al, 192 106 | asm jb one_data 107 | 108 | /* it's a count byte */ 109 | asm xor al, 192 110 | asm mov cl, al 111 | asm jmp getbyte 112 | 113 | one_data: 114 | 115 | asm mov cl, 1 116 | asm call _storebyte 117 | asm jmp getbyte 118 | 119 | multi_data: 120 | 121 | asm call _storebyte 122 | asm jmp getbyte 123 | 124 | /* finished with buffer */ 125 | 126 | exit: 127 | 128 | asm pop bp 129 | 130 | return; 131 | } 132 | 133 | void cga_display_pcx(char * filename) 134 | { 135 | FILE * pcx_file = fopen(filename, "r+b"); 136 | char * buff; 137 | int bytes_per_line, data_length; 138 | 139 | if (!pcx_file) 140 | { 141 | printf("Unable to open %s\n", filename); 142 | exit(1); 143 | } 144 | 145 | /* allocate buffer */ 146 | buff = malloc(PCX_BUFF_SIZE); 147 | 148 | /* read header into buffer */ 149 | fread(buff, 1, 128, pcx_file); 150 | 151 | bytes_per_line = (int) buff[66]; 152 | 153 | if ((data_length = fread(buff, 1, PCX_BUFF_SIZE, pcx_file)) != 0) 154 | cga_pcx_decode(buff, data_length, bytes_per_line); 155 | 156 | free(buff); 157 | fclose(pcx_file); 158 | } 159 | -------------------------------------------------------------------------------- /cgaeffects/3drotatingblock/3DROT.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void cga_draw_line(unsigned char far * buff, 8 | int x0, int y0, int x1, int y1, unsigned char colour); 9 | extern void cga_draw_hline(unsigned char far * buff, 10 | int x0, int x1, int y, unsigned char colour); 11 | extern void cga_draw_vline(unsigned char far * buff, 12 | int x, int y0, int y1, unsigned char colour); 13 | extern void cga_draw_line_chunky_left(unsigned char far * buff, 14 | int x0, int y0, int x1, int y1, unsigned char colour); 15 | extern void cga_draw_line_chunky_right(unsigned char far * buff, 16 | int x0, int y0, int x1, int y1, unsigned char colour); 17 | 18 | int set_video_mode(int n) 19 | { 20 | union REGS regs; 21 | 22 | regs.h.ah = 0; 23 | regs.h.al = n; 24 | int86(0x10, ®s, ®s); 25 | } 26 | 27 | int main(void) 28 | { 29 | int i, j, k, l; 30 | int xstart[6]; 31 | int ystart[4]; 32 | int costab[158]; 33 | 34 | int diff = 3, inc = 0; 35 | int diff2 = 1, trans = 0; 36 | 37 | for (i = 0; i < 158; i++) 38 | costab[i] = (int) floor(50*cos(i*0.02)+0.5); 39 | 40 | getchar(); 41 | 42 | set_video_mode(4); 43 | 44 | 45 | for (i = 0; i <100; i++) 46 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 50+i, 1); 47 | 48 | for (i = 0; i < 100; i++) 49 | { 50 | for (j = 0; j < 158; j++) 51 | { 52 | diff = 20*(50 - costab[(2*j) % 158])/100; 53 | if (j >= 79) diff = 20 - diff; 54 | 55 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 50, 50-diff, 50-diff, 100-costab[j], 0xaa); 56 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 200, 50-diff, 200+diff, 100-costab[j], 0xaa); 57 | 58 | if (j < 79) 59 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 50-diff, 2); 60 | else 61 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 50-diff-1, 0); 62 | 63 | cga_draw_hline(MK_FP(0xb800, 0), 50-diff, 200+diff, 100-costab[j], 2); 64 | 65 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 50-diff, 100-costab[j]+1, 50, 150+diff, 0x55); 66 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 200+diff, 100-costab[j]+1, 200, 150+diff, 0x55); 67 | 68 | if (j < 79) 69 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 150+diff, 1); 70 | else 71 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 150+diff+1, 0); 72 | } 73 | 74 | for (j = 0; j < 158; j++) 75 | { 76 | diff = 20*(50 - costab[(2*j) % 158])/100; 77 | if (j >= 79) diff = 20 - diff; 78 | 79 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 50, 50-diff, 50-diff, 100-costab[j], 0x55); 80 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 200, 50-diff, 200+diff, 100-costab[j], 0x55); 81 | 82 | if (j < 79) 83 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 50-diff, 1); 84 | else 85 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 50-diff-1, 0); 86 | 87 | cga_draw_hline(MK_FP(0xb800, 0), 50-diff, 200+diff, 100-costab[j], 1); 88 | 89 | cga_draw_line_chunky_left(MK_FP(0xb800, 0), 50-diff, 100-costab[j]+1, 50, 150+diff, 0xaa); 90 | cga_draw_line_chunky_right(MK_FP(0xb800, 0), 200+diff, 100-costab[j]+1, 200, 150+diff, 0xaa); 91 | 92 | if (j < 79) 93 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 150+diff, 2); 94 | else 95 | cga_draw_hline(MK_FP(0xb800, 0), 50, 200, 150+diff+1, 0); 96 | } 97 | } 98 | 99 | getchar(); 100 | 101 | set_video_mode(3); 102 | 103 | return 0; 104 | } 105 |  -------------------------------------------------------------------------------- /games/ENVOIGHT/AMMO.C: -------------------------------------------------------------------------------- 1 | sprite_show_ammo0(unsigned char far * video, char odd) 2 | { 3 | asm mov cl, odd 4 | asm les di, DWORD PTR video 5 | asm mov al, es:[di] 6 | asm and al, 240 7 | asm add al, 15 8 | asm stosb 9 | asm xor cl, 1 10 | asm jz oddline0 11 | asm add di, 13135 12 | asm jmp nextline0 13 | oddline0: 14 | asm sub di, 13057 15 | nextline0: 16 | asm mov al, es:[di] 17 | asm and al, 240 18 | asm add al, 15 19 | asm stosb 20 | } 21 | 22 | void sprite_ammo0_odd(unsigned char far * video) 23 | { 24 | sprite_show_ammo0(video, 1); 25 | } 26 | 27 | void sprite_ammo0_even(unsigned char far * video) 28 | { 29 | sprite_show_ammo0(video, 0); 30 | } 31 | 32 | sprite_show_ammo1(unsigned char far * video, char odd) 33 | { 34 | asm mov cl, odd 35 | asm les di, DWORD PTR video 36 | asm mov al, es:[di] 37 | asm and al, 252 38 | asm add al, 3 39 | asm stosb 40 | asm mov al, es:[di] 41 | asm and al, 63 42 | asm add al, 192 43 | asm stosb 44 | asm xor cl, 1 45 | asm jz oddline0 46 | asm add di, 13134 47 | asm jmp nextline0 48 | oddline0: 49 | asm sub di, 13058 50 | nextline0: 51 | asm mov al, es:[di] 52 | asm and al, 252 53 | asm add al, 3 54 | asm stosb 55 | asm mov al, es:[di] 56 | asm and al, 63 57 | asm add al, 192 58 | asm stosb 59 | } 60 | 61 | void sprite_ammo1_odd(unsigned char far * video) 62 | { 63 | sprite_show_ammo1(video, 1); 64 | } 65 | 66 | void sprite_ammo1_even(unsigned char far * video) 67 | { 68 | sprite_show_ammo1(video, 0); 69 | } 70 | 71 | sprite_show_ammo2(unsigned char far * video, char odd) 72 | { 73 | asm mov cl, odd 74 | asm les di, DWORD PTR video 75 | asm inc di 76 | asm mov al, es:[di] 77 | asm and al, 15 78 | asm add al, 240 79 | asm stosb 80 | asm xor cl, 1 81 | asm jz oddline0 82 | asm add di, 13134 83 | asm jmp nextline0 84 | oddline0: 85 | asm sub di, 13058 86 | nextline0: 87 | asm inc di 88 | asm mov al, es:[di] 89 | asm and al, 15 90 | asm add al, 240 91 | asm stosb 92 | } 93 | 94 | void sprite_ammo2_odd(unsigned char far * video) 95 | { 96 | sprite_show_ammo2(video, 1); 97 | } 98 | 99 | void sprite_ammo2_even(unsigned char far * video) 100 | { 101 | sprite_show_ammo2(video, 0); 102 | } 103 | 104 | sprite_show_ammo3(unsigned char far * video, char odd) 105 | { 106 | asm mov cl, odd 107 | asm les di, DWORD PTR video 108 | asm inc di 109 | asm mov al, es:[di] 110 | asm and al, 195 111 | asm add al, 60 112 | asm stosb 113 | asm xor cl, 1 114 | asm jz oddline0 115 | asm add di, 13134 116 | asm jmp nextline0 117 | oddline0: 118 | asm sub di, 13058 119 | nextline0: 120 | asm inc di 121 | asm mov al, es:[di] 122 | asm and al, 195 123 | asm add al, 60 124 | asm stosb 125 | } 126 | 127 | void sprite_ammo3_odd(unsigned char far * video) 128 | { 129 | sprite_show_ammo3(video, 1); 130 | } 131 | 132 | void sprite_ammo3_even(unsigned char far * video) 133 | { 134 | sprite_show_ammo3(video, 0); 135 | } 136 | 137 | #include 138 | #include "sprite.h" 139 | 140 | void sprite_init_ammo(sprite_t s, int x, int y) 141 | { 142 | s->x = x; 143 | s->y = y; 144 | s->oldx = x; 145 | s->oldy = y; 146 | s->xsize = 8; 147 | s->ysize = 2; 148 | s->sprite0_odd = sprite_ammo0_odd; 149 | s->sprite0_even = sprite_ammo0_even; 150 | s->sprite1_odd = sprite_ammo1_odd; 151 | s->sprite1_even = sprite_ammo1_even; 152 | s->sprite2_odd = sprite_ammo2_odd; 153 | s->sprite2_even = sprite_ammo2_even; 154 | s->sprite3_odd = sprite_ammo3_odd; 155 | s->sprite3_even = sprite_ammo3_even; 156 | s->buff = malloc(s->ysize*s->xsize/4); 157 | } 158 | 159 | void sprite_clear_ammo(sprite_t s) 160 | { 161 | free(s->buff); 162 | } 163 | 164 | -------------------------------------------------------------------------------- /cga320x200/efficient/vline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_vline 6 | _cga_draw_vline PROC 7 | ARG buff:DWORD, x:WORD, y0:WORD, y1:WORD, colour:BYTE 8 | ; draw a line from (x, y0) - (x, y1) including endpoints in the give colour (0-3) 9 | push bp 10 | mov bp, sp 11 | push di 12 | push si 13 | push ds 14 | 15 | les di, buff ; get buffer address in es:di 16 | 17 | mov ax, es ; mirror in ds 18 | mov ds, ax 19 | 20 | mov ax, [y0] ; get y0 coordinate 21 | inc ax 22 | shr ax, 1 ; set ax = (y0 + 1)/2 23 | cmc 24 | sbb bx, bx ; bx = -1 if y0 is odd, else bx = 0 25 | 26 | mov dx, [y1] ; get y1 coordinate 27 | shr dx, 1 ; y1/2 28 | cmc 29 | sbb cx, cx ; cx = -1 if y1 even, else cx = 0 30 | 31 | sub dx, ax ; dx = even line iterations 32 | inc dx 33 | 34 | mov si, dx ; si = odd line iterations 35 | add si, cx 36 | sub si, bx 37 | 38 | and bx, -80 ; bx = -80 if y0 is odd, else bx = 0 39 | 40 | shl ax, 1 ; set di to 80*(y0 + 1)/2 = first even line 41 | shl ax, 1 42 | shl ax, 1 43 | shl ax, 1 44 | add di, ax 45 | shl ax, 1 46 | shl ax, 1 47 | add di, ax 48 | 49 | add bx, di ; set bx to 8192 + 80*(y0/2) = first odd line 50 | add bh, 020h 51 | 52 | mov ax, [x] ; get x coordinate 53 | mov cl, al 54 | shr ax, 1 55 | shr ax, 1 ; compute byte of pixel at coord x 56 | add di, ax ; add it to offset of first even line 57 | add bx, ax ; add it to offset of first odd line 58 | 59 | mov ah, [colour] ; shift colour (ah) and mask (dl) into correct bitfields 60 | inc cl 61 | and cl, 3 62 | shl cl, 1 63 | ror ah, cl 64 | mov al, 0fch 65 | ror al, cl 66 | 67 | mov cx, dx ; get iterations 68 | 69 | mov dl, al 70 | 71 | shr cx, 1 72 | jnc vline_even_iters 73 | 74 | mov al, dl ; write pixel 75 | and al, [di] 76 | or al, ah 77 | stosb 78 | 79 | add di, 79 ; jump to next odd line 80 | 81 | vline_even_iters: 82 | 83 | cmp cx, 0 ; check for zero iterations 84 | je vline_done_even 85 | 86 | vline_even: ; display pixels on even lines (unroll by 2) 87 | 88 | mov al, dl ; write pixel 89 | and al, [di] 90 | or al, ah 91 | stosb 92 | 93 | add di, 79 ; jump to next even line 94 | 95 | mov al, dl ; write pixel 96 | and al, [di] 97 | or al, ah 98 | stosb 99 | 100 | add di, 79 ; jump to next even line 101 | loop vline_even ; loop 102 | 103 | vline_done_even: 104 | 105 | mov di, bx ; load offset of first odd line 106 | 107 | mov cx, si ; get iterations 108 | 109 | mov bx, 79 ; store jump value 110 | 111 | shr cx, 1 ; unroll by 2 112 | jnc vline_odd_iters 113 | 114 | mov al, dl ; write pixel 115 | and al, [di] 116 | or al, ah 117 | stosb 118 | 119 | add di, bx ; jump to next odd line 120 | 121 | vline_odd_iters: 122 | 123 | cmp cx, 0 ; check for zero iterations 124 | je vline_done_odd 125 | 126 | vline_odd: ; display pixels on odd lines (unroll by 2) 127 | 128 | mov al, dl ; write pixel 129 | and al, [di] 130 | or al, ah 131 | stosb 132 | 133 | add di, bx ; jump to next odd line 134 | 135 | mov al, dl ; write pixel 136 | and al, [di] 137 | or al, ah 138 | stosb 139 | 140 | add di, bx ; jump to next odd line 141 | loop vline_odd ; loop 142 | 143 | vline_done_odd: 144 | 145 | pop ds 146 | pop si 147 | pop di 148 | pop bp 149 | ret 150 | _cga_draw_vline ENDP 151 | 152 | END -------------------------------------------------------------------------------- /vgaeffects/xtplasma/MCGA.ASM: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .DATA 4 | 5 | .CODE 6 | 7 | public _set_fire_palette 8 | _set_fire_palette PROC 9 | xor ah, ah 10 | xor bl, bl 11 | xor bh, bh 12 | 13 | mov cx, 42 14 | 15 | fire_br_loop: 16 | inc bh 17 | mov al, bh 18 | mov dx, 3c8h 19 | out dx, al 20 | 21 | mov dx, 3c9h 22 | add ah, 3 23 | mov al, ah 24 | shr al, 1 25 | shr al, 1 26 | out dx, al 27 | xor al, al 28 | out dx, al 29 | xor al, al 30 | out dx, al 31 | 32 | neg bh 33 | mov al, bh 34 | mov dx, 3c8h 35 | out dx, al 36 | neg bh 37 | 38 | mov dx, 3c9h 39 | add ah, 3 40 | mov al, ah 41 | shr al, 1 42 | shr al, 1 43 | out dx, al 44 | xor al, al 45 | out dx, al 46 | xor al, al 47 | out dx, al 48 | loop fire_br_loop 49 | 50 | inc bh 51 | mov al, bh 52 | mov dx, 3c8h 53 | out dx, al 54 | 55 | mov dx, 3c9h 56 | add ah, 3 57 | mov al, ah 58 | shr al, 1 59 | shr al, 1 60 | out dx, al 61 | xor al, al 62 | out dx, al 63 | xor al, al 64 | out dx, al 65 | 66 | mov cx, 42 67 | shr ah, 1 68 | shr ah, 1 69 | 70 | fire_ry_loop: 71 | neg bh 72 | mov al, bh 73 | mov dx, 3c8h 74 | out dx, al 75 | neg bh 76 | 77 | mov dx, 3c9h 78 | add bl, 3 79 | mov al, ah 80 | out dx, al 81 | mov al, bl 82 | shr al, 1 83 | shr al, 1 84 | out dx, al 85 | xor al, al 86 | out dx, al 87 | 88 | inc bh 89 | mov al, bh 90 | mov dx, 3c8h 91 | out dx, al 92 | 93 | mov dx, 3c9h 94 | add bl, 3 95 | mov al, ah 96 | out dx, al 97 | mov al, bl 98 | shr al, 1 99 | shr al, 1 100 | out dx, al 101 | xor al, al 102 | out dx, al 103 | loop fire_ry_loop 104 | 105 | neg bh 106 | mov al, bh 107 | mov dx, 3c8h 108 | out dx, al 109 | neg bh 110 | 111 | mov dx, 3c9h 112 | add bl, 3 113 | mov al, ah 114 | out dx, al 115 | mov al, bl 116 | shr al, 1 117 | shr al, 1 118 | out dx, al 119 | xor al, al 120 | out dx, al 121 | 122 | mov cx, 42 123 | xor bl, bl 124 | 125 | fire_yw_loop: 126 | inc bh 127 | mov al, bh 128 | mov dx, 3c8h 129 | out dx, al 130 | 131 | mov dx, 3c9h 132 | add bl, 3 133 | mov al, ah 134 | out dx, al 135 | out dx, al 136 | mov al, bl 137 | shr al, 1 138 | shr al, 1 139 | out dx, al 140 | 141 | neg bh 142 | mov al, bh 143 | mov dx, 3c8h 144 | out dx, al 145 | neg bh 146 | 147 | mov dx, 3c9h 148 | add bl, 3 149 | mov al, ah 150 | out dx, al 151 | out dx, al 152 | mov al, bl 153 | shr al, 1 154 | shr al, 1 155 | out dx, al 156 | loop fire_yw_loop 157 | 158 | inc bh 159 | mov al, bh 160 | mov dx, 3c8h 161 | out dx, al 162 | 163 | mov dx, 3c9h 164 | add bl, 3 165 | mov al, ah 166 | out dx, al 167 | out dx, al 168 | mov al, bl 169 | shr al, 1 170 | shr al, 1 171 | out dx, al 172 | ret 173 | _set_fire_palette ENDP 174 | 175 | public _vga_plasma 176 | _vga_plasma PROC 177 | ARG buff:DWORD 178 | push bp 179 | mov bp, sp 180 | push di 181 | push si 182 | push ds 183 | 184 | mov ax, 0a000h 185 | mov es, ax 186 | xor di, di 187 | 188 | lds si, buff 189 | 190 | mov bx, 200 191 | line_loop: 192 | mov cx, 160 193 | rep movsw 194 | dec bx 195 | jnz line_loop 196 | 197 | pop ds 198 | pop si 199 | pop di 200 | pop bp 201 | ret 202 | _vga_plasma ENDP 203 | 204 | PUBLIC _mcga_stosw 205 | _mcga_stosw PROC 206 | push bp 207 | mov bp, sp 208 | push di 209 | push si 210 | 211 | mov ax, 0a000h 212 | mov es, ax 213 | 214 | mov ax, 0aaaah 215 | 216 | mov bx, 10 217 | mcga_next_colour: 218 | mov dx, 60 219 | 220 | mcga_next_frame: 221 | 222 | mov cx, 32000 223 | rep stosw 224 | 225 | dec dx 226 | jnz mcga_next_frame 227 | 228 | xor ax, 0ffffh 229 | 230 | dec bx 231 | jnz mcga_next_colour 232 | 233 | pop si 234 | pop di 235 | pop bp 236 | ret 237 | _mcga_stosw ENDP 238 | 239 | END -------------------------------------------------------------------------------- /cgaeffects/check3d/CHECK3D.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void cga_draw_line(unsigned char far * buff, 8 | int x0, int y0, int x1, int y1, unsigned char colour); 9 | extern void cga_draw_hline(unsigned char far * buff, 10 | int x0, int x1, int y, unsigned char colour); 11 | extern void cga_draw_vline(unsigned char far * buff, 12 | int x, int y0, int y1, unsigned char colour); 13 | 14 | int set_video_mode(int n) 15 | { 16 | union REGS regs; 17 | 18 | regs.h.ah = 0; 19 | regs.h.al = n; 20 | int86(0x10, ®s, ®s); 21 | } 22 | 23 | void cga_copy_line(unsigned char far * video, unsigned char far * buff, int line) 24 | { 25 | int i, offset = 0, d; 26 | 27 | if (line & 1) 28 | offset += 8192; 29 | 30 | line = line >> 1; 31 | d = line; 32 | line <<= 2; 33 | d += line; 34 | offset += (d << 4); 35 | 36 | video += offset; 37 | buff += offset; 38 | 39 | for (i = 0; i < 80; i++) 40 | video[i] = buff[i]; 41 | } 42 | 43 | int main(void) 44 | { 45 | int i, j, k, l; 46 | unsigned int b[4]; 47 | unsigned int c[4]; 48 | int lines[4]; 49 | unsigned char far * buff1, far * buff2, far * video; 50 | 51 | getchar(); 52 | 53 | set_video_mode(4); 54 | 55 | video = MK_FP(0xb800, 0); 56 | 57 | buff1 = farmalloc(16384); 58 | buff2 = farmalloc(16384); 59 | 60 | for (i = 0; i < 98; i++) 61 | cga_draw_hline(buff1, 0, 319, i, 0); 62 | for (i = 98; i < 200; i++) 63 | cga_draw_hline(buff1, 0, 319, i, 3); 64 | 65 | l = 1; 66 | for (j = 0, k = 80; j < 320; j += 40, k += 20) 67 | { 68 | for (i = 0; i < 40; i++) 69 | cga_draw_line(buff1, j + i, 199, k, 100, l); 70 | for (i = 0; i < 20; i++) 71 | cga_draw_line(buff1, j + 39, 199, k + i, 100, l); 72 | l = l == 1 ? 2 : 1; 73 | } 74 | 75 | for (i = 0; i < 98; i++) 76 | cga_draw_hline(buff2, 0, 319, i, 0); 77 | for (i = 98; i < 200; i++) 78 | cga_draw_hline(buff2, 0, 319, i, 3); 79 | 80 | l = 2; 81 | for (j = 0, k = 80; j < 320; j += 40, k += 20) 82 | { 83 | for (i = 0; i < 40; i++) 84 | cga_draw_line(buff2, j + i, 199, k, 100, l); 85 | for (i = 0; i < 20; i++) 86 | cga_draw_line(buff2, j + 39, 199, k + i, 100, l); 87 | l = l == 1 ? 2 : 1; 88 | } 89 | 90 | for (i = 0; i < 16384; i++) 91 | video[i] = buff1[i]; 92 | 93 | getchar(); 94 | 95 | for (i = 0; i < 16384; i++) 96 | video[i] = buff2[i]; 97 | 98 | getchar(); 99 | 100 | lines[0] = 100; 101 | lines[1] = 119; 102 | lines[2] = 142; 103 | lines[3] = 169; 104 | 105 | for (i = 0; i < 100; i++) 106 | cga_copy_line(video, buff1, i); 107 | 108 | for (i = lines[0]; i < lines[1]; i++) 109 | cga_copy_line(video, buff1, i); 110 | 111 | for (i = lines[1]; i < lines[2]; i++) 112 | cga_copy_line(video, buff2, i); 113 | 114 | for (i = lines[2]; i < lines[3]; i++) 115 | cga_copy_line(video, buff1, i); 116 | 117 | for (i = lines[3]; i < 200; i++) 118 | cga_copy_line(video, buff2, i); 119 | 120 | getchar(); 121 | 122 | for (k = 0; k < 1000; k++) 123 | { 124 | b[0] = 32768; 125 | b[1] = 40724; 126 | b[2] = 48680; 127 | b[3] = 56636; 128 | c[0] = 0; 129 | c[1] = 202; 130 | c[2] = 8764; 131 | c[3] = 25686; 132 | lines[0] = 100; 133 | lines[1] = 119; 134 | lines[2] = 142; 135 | lines[3] = 169; 136 | 137 | for (i = 0; i < 34; i++) 138 | { 139 | for (j = 0; j < 4; j++) 140 | { 141 | unsigned int d; 142 | 143 | if ((j + k) & 1) 144 | cga_copy_line(video, buff1, lines[j]); 145 | else 146 | cga_copy_line(video, buff2, lines[j]); 147 | 148 | d = c[j] + b[j]; 149 | if (d < c[j]) 150 | lines[j]++; 151 | c[j] = d; 152 | b[j] += 234; 153 | } 154 | } 155 | } 156 | 157 | farfree(buff1); 158 | farfree(buff2); 159 | 160 | getchar(); 161 | 162 | set_video_mode(3); 163 | 164 | return 0; 165 | } 166 |  -------------------------------------------------------------------------------- /cga320x200/ludicrous/lineinc.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | salc macro 6 | db 0d6h 7 | endm 8 | 9 | PUBLIC _get_line_increments 10 | _get_line_increments PROC 11 | ARG buff:WORD, deltax:WORD, deltay:WORD 12 | push bp 13 | mov bp, sp 14 | push di 15 | 16 | mov ax, ds ; set segment for table 17 | mov es, ax 18 | 19 | mov di, [buff] ; get buffer address 20 | inc di ; skip first entry 21 | 22 | mov dx, [deltax] 23 | mov cx, [deltay] 24 | 25 | cmp dx, 0 26 | jl lineinc_left 27 | 28 | cmp dx, cx 29 | jb lineinc_vr 30 | jmp lineinc_hr 31 | 32 | lineinc_vr: 33 | xor ax, ax ; compute increment = round(65536*dx/dy) 34 | div cx 35 | shl dx, 1 36 | adc ax, 0 37 | mov dx, ax 38 | 39 | mov bx, 08000h ; starting value for increments 40 | 41 | add bx, dx ; inc x? 42 | salc 43 | neg al 44 | 45 | inc cx 46 | shr cx, 1 ; compute iterations 47 | 48 | jnc lineinc_vr_mid 49 | jz lineinc_vr_no_iter 50 | 51 | lineinc_vr_loop: 52 | stosb 53 | 54 | add bx, dx ; inc x? 55 | salc 56 | neg al 57 | 58 | lineinc_vr_mid: 59 | stosb 60 | 61 | add bx, dx ; inc x? 62 | salc 63 | neg al 64 | 65 | loop lineinc_vr_loop 66 | 67 | lineinc_vr_no_iter: 68 | 69 | pop di 70 | pop bp 71 | ret 72 | 73 | lineinc_hr: 74 | mov ax, dx ; compute q = dx/dy 75 | div cl 76 | mov bh, al 77 | mov dl, ah 78 | xor dh, dh 79 | 80 | xor ax, ax ; compute increment = round(65536*dx/dy) 81 | div cx 82 | shl dx, 1 83 | adc ax, 0 84 | mov dx, ax 85 | 86 | mov ah, bh ; get q 87 | 88 | mov bx, 08000h ; starting value for increments 89 | 90 | add bx, dx ; extra inc x? 91 | salc 92 | neg al 93 | add al, ah 94 | 95 | inc cx 96 | shr cx, 1 ; compute iterations 97 | 98 | jnc lineinc_hr_mid 99 | jz lineinc_hr_no_iter 100 | 101 | lineinc_hr_loop: 102 | stosb 103 | 104 | add bx, dx ; extra inc x? 105 | salc 106 | neg al 107 | add al, ah 108 | 109 | lineinc_hr_mid: 110 | stosb 111 | 112 | add bx, dx ; extra inc x? 113 | salc 114 | neg al 115 | add al, ah 116 | 117 | loop lineinc_hr_loop 118 | 119 | lineinc_hr_no_iter: 120 | 121 | pop di 122 | pop bp 123 | ret 124 | 125 | lineinc_left: 126 | 127 | neg dx ; make deltax positive 128 | 129 | cmp dx, cx 130 | jb lineinc_vl 131 | jmp lineinc_hl 132 | 133 | lineinc_vl: 134 | xor ax, ax ; compute increment = round(65536*dx/dy) 135 | div cx 136 | shl dx, 1 137 | adc ax, 0 138 | mov dx, ax 139 | 140 | mov bx, 08000h ; starting value for increments 141 | 142 | add bx, dx ; inc x? 143 | salc 144 | 145 | inc cx 146 | shr cx, 1 ; compute iterations 147 | 148 | jnc lineinc_vl_mid 149 | jz lineinc_vl_no_iter 150 | 151 | lineinc_vl_loop: 152 | stosb 153 | 154 | add bx, dx ; inc x? 155 | salc 156 | 157 | lineinc_vl_mid: 158 | stosb 159 | 160 | add bx, dx ; inc x? 161 | salc 162 | 163 | loop lineinc_vl_loop 164 | 165 | lineinc_vl_no_iter: 166 | 167 | pop di 168 | pop bp 169 | ret 170 | 171 | lineinc_hl: 172 | mov ax, dx ; compute q = dx/dy 173 | div cl 174 | mov bh, al 175 | mov dl, ah 176 | xor dh, dh 177 | 178 | xor ax, ax ; compute increment = round(65536*dx/dy) 179 | div cx 180 | shl dx, 1 181 | adc ax, 0 182 | mov dx, ax 183 | 184 | mov ah, bh ; get q 185 | 186 | mov bx, 08000h ; starting value for increments 187 | 188 | add bx, dx ; extra inc x? 189 | salc 190 | sub al, ah 191 | 192 | inc cx 193 | shr cx, 1 ; compute iterations 194 | 195 | jnc lineinc_hl_mid 196 | jz lineinc_hl_no_iter 197 | 198 | lineinc_hl_loop: 199 | stosb 200 | 201 | add bx, dx ; extra inc x? 202 | salc 203 | sub al, ah 204 | 205 | lineinc_hl_mid: 206 | stosb 207 | 208 | add bx, dx ; extra inc x? 209 | salc 210 | sub al, ah 211 | 212 | loop lineinc_hl_loop 213 | 214 | lineinc_hl_no_iter: 215 | 216 | pop di 217 | pop bp 218 | ret 219 | 220 | _get_line_increments ENDP 221 | 222 | END 223 | -------------------------------------------------------------------------------- /vgaeffects/xtplasma/MCGA2.ASM: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .DATA 4 | 5 | .CODE 6 | 7 | public _set_fire_palette 8 | _set_fire_palette PROC 9 | xor ah, ah 10 | xor bl, bl 11 | xor bh, bh 12 | 13 | mov cx, 42 14 | 15 | fire_br_loop: 16 | inc bh 17 | mov al, bh 18 | mov dx, 3c8h 19 | out dx, al 20 | 21 | mov dx, 3c9h 22 | add ah, 3 23 | mov al, ah 24 | shr al, 1 25 | shr al, 1 26 | out dx, al 27 | xor al, al 28 | out dx, al 29 | xor al, al 30 | out dx, al 31 | 32 | neg bh 33 | mov al, bh 34 | mov dx, 3c8h 35 | out dx, al 36 | neg bh 37 | 38 | mov dx, 3c9h 39 | add ah, 3 40 | mov al, ah 41 | shr al, 1 42 | shr al, 1 43 | out dx, al 44 | xor al, al 45 | out dx, al 46 | xor al, al 47 | out dx, al 48 | loop fire_br_loop 49 | 50 | inc bh 51 | mov al, bh 52 | mov dx, 3c8h 53 | out dx, al 54 | 55 | mov dx, 3c9h 56 | add ah, 3 57 | mov al, ah 58 | shr al, 1 59 | shr al, 1 60 | out dx, al 61 | xor al, al 62 | out dx, al 63 | xor al, al 64 | out dx, al 65 | 66 | mov cx, 42 67 | shr ah, 1 68 | shr ah, 1 69 | 70 | fire_ry_loop: 71 | neg bh 72 | mov al, bh 73 | mov dx, 3c8h 74 | out dx, al 75 | neg bh 76 | 77 | mov dx, 3c9h 78 | add bl, 3 79 | mov al, ah 80 | out dx, al 81 | mov al, bl 82 | shr al, 1 83 | shr al, 1 84 | out dx, al 85 | xor al, al 86 | out dx, al 87 | 88 | inc bh 89 | mov al, bh 90 | mov dx, 3c8h 91 | out dx, al 92 | 93 | mov dx, 3c9h 94 | add bl, 3 95 | mov al, ah 96 | out dx, al 97 | mov al, bl 98 | shr al, 1 99 | shr al, 1 100 | out dx, al 101 | xor al, al 102 | out dx, al 103 | loop fire_ry_loop 104 | 105 | neg bh 106 | mov al, bh 107 | mov dx, 3c8h 108 | out dx, al 109 | neg bh 110 | 111 | mov dx, 3c9h 112 | add bl, 3 113 | mov al, ah 114 | out dx, al 115 | mov al, bl 116 | shr al, 1 117 | shr al, 1 118 | out dx, al 119 | xor al, al 120 | out dx, al 121 | 122 | mov cx, 42 123 | xor bl, bl 124 | 125 | fire_yw_loop: 126 | inc bh 127 | mov al, bh 128 | mov dx, 3c8h 129 | out dx, al 130 | 131 | mov dx, 3c9h 132 | add bl, 3 133 | mov al, ah 134 | out dx, al 135 | out dx, al 136 | mov al, bl 137 | shr al, 1 138 | shr al, 1 139 | out dx, al 140 | 141 | neg bh 142 | mov al, bh 143 | mov dx, 3c8h 144 | out dx, al 145 | neg bh 146 | 147 | mov dx, 3c9h 148 | add bl, 3 149 | mov al, ah 150 | out dx, al 151 | out dx, al 152 | mov al, bl 153 | shr al, 1 154 | shr al, 1 155 | out dx, al 156 | loop fire_yw_loop 157 | 158 | inc bh 159 | mov al, bh 160 | mov dx, 3c8h 161 | out dx, al 162 | 163 | mov dx, 3c9h 164 | add bl, 3 165 | mov al, ah 166 | out dx, al 167 | out dx, al 168 | mov al, bl 169 | shr al, 1 170 | shr al, 1 171 | out dx, al 172 | ret 173 | _set_fire_palette ENDP 174 | 175 | public _vga_plasma 176 | _vga_plasma PROC 177 | ARG buff:DWORD 178 | push bp 179 | mov bp, sp 180 | push di 181 | push si 182 | push ds 183 | 184 | mov ax, 0a000h 185 | mov es, ax 186 | xor di, di 187 | add di, 6460 188 | lds si, buff 189 | 190 | push bp 191 | mov bp, si ; save buff 192 | 193 | mov dx, 160 194 | line_loop: 195 | mov bx, bp 196 | add bx, 6399 ; shifts 197 | add bx, dx 198 | mov al, [bx] 199 | xor ah, ah 200 | mov bx, ax 201 | shl ax, 1 202 | shl ax, 1 203 | shl ax, 1 204 | add bx, ax 205 | shl ax, 1 206 | add bx, ax 207 | 208 | mov si, bp 209 | add si, bx 210 | 211 | mov cx, 100 212 | rep movsw 213 | add di, 120 214 | dec dx 215 | jnz line_loop 216 | 217 | pop bp 218 | 219 | pop ds 220 | pop si 221 | pop di 222 | pop bp 223 | ret 224 | _vga_plasma ENDP 225 | 226 | PUBLIC _mcga_stosw 227 | _mcga_stosw PROC 228 | push bp 229 | mov bp, sp 230 | push di 231 | push si 232 | 233 | mov ax, 0a000h 234 | mov es, ax 235 | 236 | mov ax, 0aaaah 237 | 238 | mov bx, 10 239 | mcga_next_colour: 240 | mov dx, 60 241 | 242 | mcga_next_frame: 243 | 244 | mov cx, 32000 245 | rep stosw 246 | 247 | dec dx 248 | jnz mcga_next_frame 249 | 250 | xor ax, 0ffffh 251 | 252 | dec bx 253 | jnz mcga_next_colour 254 | 255 | pop si 256 | pop di 257 | pop bp 258 | ret 259 | _mcga_stosw ENDP 260 | 261 | END -------------------------------------------------------------------------------- /games/ENVOIGHT/SPRT2DAT.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "graphics.h" 7 | #include "sprite.h" 8 | 9 | int line_isblank_h(unsigned char far * video, int y, unsigned char key) 10 | { 11 | int i; 12 | 13 | video += (80*(y/2)); 14 | if (y & 1) 15 | video += 8192; 16 | 17 | for (i = 0; i < 80; i++) 18 | if (video[i] != key) 19 | return 0; 20 | 21 | return 1; 22 | } 23 | 24 | int line_isblank_v(unsigned char far * video, int x, 25 | int y0, int y1, unsigned char key) 26 | { 27 | int i; 28 | 29 | video += (80*(y0/2) + (x/4)); 30 | if (y0 & 1) 31 | video += 8192; 32 | 33 | for (i = y0; i <= y1; i++) 34 | { 35 | if (*video != key) 36 | return 0; 37 | 38 | if (i & 1) 39 | video -= (8192 - 80); 40 | else 41 | video += 8192; 42 | } 43 | 44 | return 1; 45 | } 46 | 47 | void sprite_bounds(int * x0, int * y0, int * x1, int * y1, 48 | unsigned char far * video, char key) 49 | { 50 | int i; 51 | 52 | key |= (key << 2); 53 | key |= (key << 4); 54 | 55 | for (i = 0; i < 200; i++) 56 | { 57 | if (!line_isblank_h(video, i, key)) 58 | break; 59 | } 60 | *y0 = i; 61 | 62 | for (i = 199; i >= 0; i--) 63 | { 64 | if (!line_isblank_h(video, i, key)) 65 | break; 66 | } 67 | *y1 = i; 68 | 69 | for (i = 0; i < 320; i += 4) 70 | { 71 | if (!line_isblank_v(video, i, *y0, *y1, key)) 72 | break; 73 | } 74 | *x0 = i; 75 | 76 | for (i = 316; i >= 0; i -= 4) 77 | { 78 | if (!line_isblank_v(video, i, *y0, *y1, key)) 79 | break; 80 | } 81 | *x1 = i + 3; 82 | 83 | return; 84 | } 85 | 86 | void get_sprite(unsigned char * sprite, unsigned char far * video, 87 | int x0, int y0, int xsize, int ysize) 88 | { 89 | int i, j, off; 90 | xsize >>= 2; 91 | x0 >>= 2; 92 | 93 | off = (80*(y0/2) + x0); 94 | if (y0 & 1) 95 | off += 8192; 96 | 97 | for (i = 0; i < ysize; i++) 98 | { 99 | for (j = 0; j < xsize; j++) 100 | sprite[i*xsize + j] = video[off + j]; 101 | 102 | off ^= 8192; 103 | if ((i + y0) & 1) 104 | off += 80; 105 | } 106 | } 107 | 108 | int main(void) 109 | { 110 | int mode = 0; 111 | int ret, c, v, len, sbytes; 112 | unsigned char far * video = MK_FP(0xb800, 0x0000); 113 | int x0, y0, x1, y1, xsize, ysize; 114 | char filename[20]; 115 | char outfile[20]; 116 | unsigned char * sprite; 117 | FILE * sprite_file; 118 | 119 | printf("Enter video mode: "); 120 | if (!scanf("%d", &mode)) 121 | { 122 | printf("Invalid input\n"); 123 | abort(); 124 | } 125 | 126 | while ((c = getchar()) != '\n' && c != EOF) 127 | /* discard */ ; 128 | 129 | printf("Input file (.pcx): "); 130 | gets(filename); 131 | 132 | strcpy(outfile, filename); 133 | len = strlen(outfile); 134 | strcpy(outfile + len - 4, ".dat"); 135 | 136 | set_video_mode(mode); 137 | 138 | cga_display_pcx(filename); 139 | 140 | sprite_bounds(&x0, &y0, &x1, &y1, video, 0x0); 141 | 142 | xsize = x1 - x0 + 1; 143 | ysize = y1 - y0 + 1; 144 | 145 | sprite = (unsigned char *) malloc(ysize*(xsize/4)); 146 | 147 | get_sprite(sprite, video, x0, y0, xsize, ysize); 148 | 149 | getchar(); 150 | 151 | set_video_mode(3); 152 | 153 | sprite_file = fopen(outfile, "wb"); 154 | 155 | sbytes = fwrite(&xsize, 2, 1, sprite_file); 156 | sbytes += fwrite(&ysize, 2, 1, sprite_file); 157 | sbytes += fwrite(sprite, 1, ysize*(xsize/4), sprite_file); 158 | 159 | printf("x0: %d, y0: %d, x1: %d, y1: %d\n", x0, y0, x1, y1); 160 | printf("%d bytes written to: %s\n", sbytes, outfile); 161 | 162 | fflush(sprite_file); 163 | fclose(sprite_file); 164 | 165 | free(sprite); 166 | 167 | getchar(); 168 | 169 | sprite_file = fopen(outfile, "rb"); 170 | 171 | fread(&xsize, 2, 1, sprite_file); 172 | fread(&ysize, 2, 1, sprite_file); 173 | 174 | printf("Sprite %dx%d\n", xsize, ysize); 175 | getchar(); 176 | 177 | sprite = (unsigned char *) malloc(ysize*(xsize/4)); 178 | 179 | fread(sprite, 1, ysize*(xsize/4), sprite_file); 180 | 181 | set_video_mode(mode); 182 | 183 | sprite_display_direct(video, sprite, xsize, ysize); 184 | 185 | getchar(); 186 | 187 | set_video_mode(3); 188 | 189 | fclose(sprite_file); 190 | 191 | free(sprite); 192 | 193 | return 0; 194 | } 195 |  -------------------------------------------------------------------------------- /cgaeffects/checkboard/CHECKBRD.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern void cga_draw_hline(unsigned char far * buff, 8 | int x0, int x1, int y, unsigned char colour); 9 | extern void cga_draw_vline(unsigned char far * buff, 10 | int x, int y0, int y1, unsigned char colour); 11 | extern void cga_checkboard(void); 12 | 13 | #define SLOW_VERSION 0 14 | 15 | int set_video_mode(int n) 16 | { 17 | union REGS regs; 18 | 19 | regs.h.ah = 0; 20 | regs.h.al = n; 21 | int86(0x10, ®s, ®s); 22 | } 23 | 24 | int main(void) 25 | { 26 | int i, j, k, l; 27 | int xstart[6]; 28 | int ystart[4]; 29 | 30 | getchar(); 31 | 32 | set_video_mode(4); 33 | 34 | #if SLOW_VERSION 35 | 36 | ystart[0] = 0; 37 | ystart[1] = 50; 38 | ystart[2] = 100; 39 | ystart[3] = 150; 40 | 41 | for (i = 0; i < 50; i++) 42 | { 43 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, i, 1); 44 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, i, 2); 45 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, i, 1); 46 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, i, 2); 47 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, i, 1); 48 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, i, 2); 49 | } 50 | 51 | for (i = 50; i < 100; i++) 52 | { 53 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, i, 2); 54 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, i, 1); 55 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, i, 2); 56 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, i, 1); 57 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, i, 2); 58 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, i, 1); 59 | } 60 | 61 | for (i = 100; i < 150; i++) 62 | { 63 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, i, 1); 64 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, i, 2); 65 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, i, 1); 66 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, i, 2); 67 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, i, 1); 68 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, i, 2); 69 | } 70 | 71 | for (i = 150; i < 200; i++) 72 | { 73 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, i, 2); 74 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, i, 1); 75 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, i, 2); 76 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, i, 1); 77 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, i, 2); 78 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, i, 1); 79 | } 80 | 81 | for (i = 0; i < 32000; i++) 82 | { 83 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, ystart[0], 2); 84 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, ystart[0], 1); 85 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, ystart[0], 2); 86 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, ystart[0], 1); 87 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, ystart[0], 2); 88 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, ystart[0], 1); 89 | 90 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, ystart[1], 1); 91 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, ystart[1], 2); 92 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, ystart[1], 1); 93 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, ystart[1], 2); 94 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, ystart[1], 1); 95 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, ystart[1], 2); 96 | 97 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, ystart[2], 2); 98 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, ystart[2], 1); 99 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, ystart[2], 2); 100 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, ystart[2], 1); 101 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, ystart[2], 2); 102 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, ystart[2], 1); 103 | 104 | cga_draw_hline(MK_FP(0xb800, 0), 0, 59, ystart[3], 1); 105 | cga_draw_hline(MK_FP(0xb800, 0), 60, 119, ystart[3], 2); 106 | cga_draw_hline(MK_FP(0xb800, 0), 120, 179, ystart[3], 1); 107 | cga_draw_hline(MK_FP(0xb800, 0), 180, 239, ystart[3], 2); 108 | cga_draw_hline(MK_FP(0xb800, 0), 240, 299, ystart[3], 1); 109 | cga_draw_hline(MK_FP(0xb800, 0), 300, 319, ystart[3], 2); 110 | 111 | ystart[0]++; 112 | if (ystart[0] == 200) 113 | ystart[0] = 0; 114 | 115 | ystart[1]++; 116 | if (ystart[1] == 200) 117 | ystart[1] = 0; 118 | 119 | ystart[2]++; 120 | if (ystart[2] == 200) 121 | ystart[2] = 0; 122 | 123 | ystart[3]++; 124 | if (ystart[3] == 200) 125 | ystart[3] = 0; 126 | } 127 | 128 | #else 129 | for (i = 0; i < 100; i++) 130 | cga_checkboard(); 131 | #endif 132 | 133 | getchar(); 134 | 135 | set_video_mode(3); 136 | 137 | return 0; 138 | } 139 |  -------------------------------------------------------------------------------- /cga4.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_line1 6 | _cga_draw_line1 PROC 7 | ARG x0:WORD, y0:WORD, xdiff:WORD, ydiff:WORD, D:WORD, xend:WORD, colour:BYTE 8 | ; line from (x0, y0) - (xend, ?) including endpoints 9 | ; AX: Acc, BX: 2*dx, SP: 2*dy, CX: Loop, BP: ydelta 10 | ; DX: D, DI: Offset, ES: B800, SI: Jump offset 11 | push bp 12 | mov bp, sp 13 | push di 14 | push si 15 | push ds 16 | 17 | mov ax, 0b800h ; set segment for CGA memory 18 | mov es, ax 19 | 20 | xor di, di ; compute offset for line y0 21 | mov ax, [y0] 22 | shr ax, 1 23 | 24 | mov bx, 8192 ; also compute ydelta 25 | jnc line1_y_even 26 | mov bx, -8112 27 | line1_y_even: 28 | push bx 29 | 30 | sbb di, 0 ; continue computing offset for line y0 31 | and di, 8192 32 | mov cl, 4 33 | shl ax, cl 34 | add di, ax 35 | shl ax, 1 36 | shl ax, 1 37 | add di, ax 38 | 39 | mov bx, [xdiff] ; compute 2*dx 40 | shl bx, 1 41 | 42 | mov si, [ydiff] ; compute 2*dy 43 | shl si, 1 44 | 45 | line1_yinc: 46 | 47 | mov dx, [D] ; store D 48 | 49 | mov cx, [x0] ; compute jump offset 50 | and cl, 3 ; multiply x mod 4 by 20 51 | shl cl, 1 52 | shl cl, 1 53 | mov al, cl 54 | shl cl, 1 55 | shl cl, 1 56 | add al, cl 57 | xor ah, ah 58 | mov ds, ax 59 | 60 | mov ah, [colour] ; patch colours in 61 | ror ah, 1 62 | ror ah, 1 63 | mov BYTE PTR cs:[line1_patch1 + 1], ah 64 | ror ah, 1 65 | ror ah, 1 66 | mov BYTE PTR cs:[line1_patch2 + 1], ah 67 | ror ah, 1 68 | ror ah, 1 69 | mov BYTE PTR cs:[line1_patch3 + 1], ah 70 | ror ah, 1 71 | ror ah, 1 72 | mov BYTE PTR cs:[line1_patch4 + 1], ah 73 | 74 | mov ax, [x0] ; get x0 75 | 76 | shr ax, 1 ; adjust offset for column x0 77 | shr ax, 1 78 | add di, ax 79 | 80 | shl ax, 1 ; round x0 down to nearest multiple of 4 81 | shl ax, 1 82 | 83 | mov cx, [xend] ; compute loop iterations 84 | pop bp ; (get ydelta here so we can push below) 85 | sub cx, ax 86 | inc cx 87 | push cx ; save iterations for prologue 88 | shr cx, 1 89 | shr cx, 1 ; we will unroll by 4 so divide by 4 90 | 91 | sub dx, si ; compensate for first addition of 2*dy 92 | 93 | cli ; save and free up sp 94 | mov WORD PTR cs:[line1_patch5 + 1], sp 95 | mov sp, si 96 | 97 | mov ax, ds ; get jump offset 98 | mov si, ax 99 | lea si, si + line1_loop 100 | jmp si 101 | 102 | line1_loop: 103 | mov al, 03fh 104 | and al, es:[di] ; draw pixel at x, y 105 | line1_patch1: 106 | or al, 040h 107 | add dx, sp ; D += 2*dy 108 | stosb 109 | 110 | jle line1_skip_incy1 111 | 112 | add di, bp ; odd <-> even line (reenigne's trick) 113 | xor bp, -16304 ; adjust ydelta 114 | 115 | sub dx, bx ; D -= 2*dx 116 | line1_skip_incy1: 117 | dec di ; adjust offset 118 | 119 | 120 | mov al, 0cfh 121 | and al, es:[di] ; draw pixel at x, y 122 | line1_patch2: 123 | or al, 010h 124 | add dx, sp ; D += 2*dy 125 | stosb 126 | 127 | jle line1_skip_incy2 128 | 129 | add di, bp ; odd <-> even line (reenigne's trick) 130 | xor bp, -16304 ; adjust ydelta 131 | 132 | sub dx, bx ; D -= 2*dx 133 | line1_skip_incy2: 134 | dec di ; adjust offset 135 | 136 | 137 | mov al, 0f3h 138 | and al, es:[di] ; draw pixel at x, y 139 | line1_patch3: 140 | or al, 04h 141 | add dx, sp ; D += 2*dy 142 | stosb 143 | 144 | jle line1_skip_incy3 145 | 146 | add di, bp ; odd <-> even line (reenigne's trick) 147 | xor bp, -16304 ; adjust ydelta 148 | 149 | sub dx, bx ; D -= 2*dx 150 | line1_skip_incy3: 151 | dec di ; adjust offset 152 | 153 | 154 | mov al, 0fch 155 | and al, es:[di] ; draw pixel at x, y 156 | line1_patch4: 157 | or al, 01h 158 | add dx, sp ; D += 2*dy 159 | stosb 160 | 161 | jle line1_skip_incy4 162 | 163 | add di, bp ; odd <-> even line (reenigne's trick) 164 | xor bp, -16304 ; adjust ydelta 165 | 166 | sub dx, bx ; D -= 2*dx 167 | line1_skip_incy4: 168 | 169 | loop line1_loop 170 | 171 | line1_patch5: 172 | mov sp, 1234 173 | sti 174 | 175 | pop cx ; do remaining iterations (0-3) 176 | ; TODO 177 | 178 | pop ds 179 | pop si 180 | pop di 181 | pop bp 182 | ret 183 | _cga_draw_line1 ENDP 184 | 185 | END 186 | 187 | -------------------------------------------------------------------------------- /fire2.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | jmp_addr DW ? 6 | sp_save DW ? 7 | ss_save DW ? 8 | 9 | PUBLIC _cga_fire2 10 | _cga_fire2 PROC 11 | ARG fire_arr:WORD, rand_arr:WORD 12 | ; al, ah, dl, dh: vals, bx: offset to next line 13 | ; di: cga offset, bp: temp, cl: shift, ch: loop 14 | ; si: offset into fire array 15 | ; rand_array is 160*32 = 5120 bytes of random values in [0, 31] 16 | ; fire_arr is a zeroed array of 160*23 = 3680 bytes 17 | push bp 18 | mov bp, sp 19 | push di 20 | push si 21 | push ds 22 | 23 | mov si, [rand_arr] 24 | mov bx, si 25 | add bx, 5120 26 | mov di, [fire_arr] 27 | add di, 3520 28 | 29 | mov cx, 1000 30 | 31 | cga_fire2_loop: 32 | push cx 33 | push bx 34 | push di 35 | 36 | cmp si, bx 37 | jne cga_fire2_more_rand 38 | sub si, 5120 39 | cga_fire2_more_rand: 40 | 41 | mov ax, ds ; copy random values in final row of array 42 | mov es, ax 43 | mov cx, 80 44 | rep movsw 45 | 46 | push si 47 | 48 | mov si, di 49 | sub si, 3521 ; move to start of fire array 50 | 51 | mov ax, 0b800h ; set up CGA segment and offset 52 | mov es, ax 53 | mov di, 7120 54 | 55 | lodsw ; load initial al, ah, dl, dh values 56 | mov dx, [si] 57 | inc si 58 | inc si 59 | 60 | mov cl, 4 ; used for shifts by a nibble 61 | 62 | mov ch, 15 63 | cga_fire2_loop15: ; 15 lines for which overflow is impossible 64 | push cx 65 | 66 | mov ch, 80 ; 160 "pixels" / 2 pixels at a time 67 | cga_fire2_loop80_15: 68 | 69 | add ah, dl ; compute (a+b+c)*5/16 values 70 | add al, ah 71 | add ah, dh 72 | mov bp, ax ; multiply by 5 73 | shl ax, 1 74 | shl ax, 1 75 | add ax, bp 76 | shr ax, cl 77 | and al, 15 78 | mov [si-163], ax ; write values 79 | shr al, 1 80 | shr ah, 1 81 | shl al, cl 82 | add al, ah 83 | stosb ; draw pixel 84 | 85 | lodsw ; load values 86 | 87 | xchg ax, dx 88 | 89 | dec ch 90 | jnz cga_fire2_loop80_15 91 | 92 | sub di, 8192 ; next CGA line 93 | jnc cga_fire2_odd15 94 | add di, 16304 95 | cga_fire2_odd15: 96 | 97 | pop cx 98 | dec ch 99 | jnz cga_fire2_loop15 100 | 101 | 102 | mov ch, 5 103 | cga_fire2_loop5: ; 5 lines for which only overflow for last add possible 104 | push cx 105 | 106 | mov ch, 80 ; 160 "pixels" / 2 pixels at a time 107 | cga_fire2_loop80_5: 108 | 109 | add ah, dl ; compute (a+b+c)*5/16 values 110 | add al, ah 111 | add ah, dh 112 | push cx 113 | mov cx, ax ; multiply by 5 114 | shl ax, 1 115 | add cx, ax 116 | add al, cl 117 | rcr al, 1 ; may have been overflow 118 | add ah, ch 119 | rcr ah, 1 ; may have been overflow 120 | shr ax, 1 121 | shr ax, 1 122 | shr ax, 1 123 | and al, 31 124 | mov [si-163], ax ; write values 125 | shr al, 1 126 | shr ah, 1 127 | pop cx 128 | shl al, cl 129 | add al, ah 130 | stosb ; draw pixel 131 | 132 | lodsw ; load values 133 | 134 | xchg ax, dx 135 | 136 | dec ch 137 | jnz cga_fire2_loop80_5 138 | 139 | sub di, 8192 ; next CGA line 140 | jnc cga_fire2_odd5 141 | add di, 16304 142 | cga_fire2_odd5: 143 | 144 | pop cx 145 | dec ch 146 | jnz cga_fire2_loop5 147 | 148 | 149 | mov ch, 2 150 | cga_fire2_loop2: ; 2 lines for which two overflows possible 151 | push cx 152 | 153 | mov ch, 80 ; 160 "pixels" / 2 pixels at a time 154 | cga_fire2_loop80_2: 155 | 156 | add ah, dl ; compute (a+b+c)*5/16 values 157 | add al, ah 158 | add ah, dh 159 | push cx 160 | mov cx, ax ; multiply by 5 161 | shl ax, 1 162 | add ch, ah 163 | rcr ch, 1 ; overflow may be possible 164 | adc ah, 0 165 | shr ah, 1 166 | add ah, ch 167 | add cl, al 168 | rcr cl, 1 169 | adc al, 0 170 | shr al, 1 171 | add al, cl 172 | pop cx 173 | shr ax, 1 174 | shr ax, 1 175 | shr ax, 1 176 | and al, 31 177 | mov [si-163], ax ; write values 178 | shr al, 1 179 | shr ah, 1 180 | shl al, cl 181 | add al, ah 182 | stosb ; draw pixel 183 | 184 | lodsw ; load values 185 | 186 | xchg ax, dx 187 | 188 | dec ch 189 | jnz cga_fire2_loop80_2 190 | 191 | sub di, 8192 ; next CGA line 192 | jnc cga_fire2_odd2 193 | add di, 16304 194 | cga_fire2_odd2: 195 | 196 | pop cx 197 | dec ch 198 | jnz cga_fire2_loop2 199 | 200 | pop si 201 | pop di 202 | pop bx 203 | pop cx 204 | dec cx 205 | jcxz cga_fire2_done 206 | jmp cga_fire2_loop 207 | cga_fire2_done: 208 | 209 | pop ds 210 | pop si 211 | pop di 212 | pop bp 213 | ret 214 | _cga_fire2 ENDP 215 | 216 | END -------------------------------------------------------------------------------- /fire.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | jmp_addr DW ? 6 | sp_save DW ? 7 | ss_save DW ? 8 | 9 | PUBLIC _cga_fire 10 | _cga_fire PROC 11 | ARG rand_arr:WORD 12 | ; al, ah, bl, bh, dl, dh: vals 13 | ; di: cga offset, bp: offset inc, cx: loop 14 | push bp 15 | mov bp, sp 16 | push di 17 | push si 18 | push ds 19 | 20 | mov ax, ds 21 | mov es, ax 22 | 23 | mov ax, 0b800h 24 | mov ds, ax 25 | 26 | mov di, [rand_arr] 27 | xor bp, bp 28 | 29 | mov cx, 3000 30 | 31 | cga_fire_loop: 32 | push cx 33 | push di 34 | 35 | cmp bp, 2560 36 | jne cga_fire_more_rand 37 | xor bp, bp 38 | cga_fire_more_rand: 39 | 40 | mov si, 8000 ; copy random values just below visible screen 41 | mov cx, 80 42 | cga_fire_rand_loop: 43 | mov al, es:[di+bp] 44 | mov [si], al 45 | inc si 46 | inc bp 47 | loop cga_fire_rand_loop 48 | 49 | push bp 50 | 51 | mov di, 7360 ; setup di, bp 52 | mov bp, 8193 53 | 54 | mov cx, 16 ; 16 lines at bottom of screen 55 | 56 | cga_fire_loop16: 57 | push cx 58 | 59 | mov cx, 26 ; 78/3 = 26 iterations (unroll by three) 60 | 61 | sub bp, 2 62 | mov dl, ds:[di+bp] ; setup al, ah, bl, bh, dl 63 | inc bp 64 | and dl, 15 65 | mov bl, ds:[di+bp] 66 | inc bp 67 | mov bh, bl 68 | shr bh, 1 69 | shr bh, 1 70 | shr bh, 1 71 | shr bh, 1 72 | and bl, 15 73 | mov al, ds:[di+bp] 74 | mov ah, al 75 | shr ah, 1 76 | shr ah, 1 77 | shr ah, 1 78 | shr ah, 1 79 | and al, 15 80 | 81 | cga_fire_loop26: 82 | push cx 83 | 84 | add ah, bl ; compute sums 85 | add al, ah 86 | add ah, bh 87 | mov si, ax ; compute pixels 88 | shl si, 1 89 | shl si, 1 90 | add ax, si 91 | shr ax, 1 92 | shr ax, 1 93 | shr ax, 1 94 | shr ax, 1 95 | shl al, 1 96 | shl al, 1 97 | shl al, 1 98 | shl al, 1 99 | add al, ah 100 | mov [di], al ; write pixels 101 | inc di 102 | mov dh, ds:[di+bp] ; get next pixels 103 | mov al, dh 104 | shr dh, 1 105 | shr dh, 1 106 | shr dh, 1 107 | shr dh, 1 108 | and al, 15 109 | 110 | add bh, dl ; compute sums 111 | add bl, bh 112 | add bh, dh 113 | mov si, bx ; compute pixels 114 | shl si, 1 115 | shl si, 1 116 | add bx, si 117 | shr bx, 1 118 | shr bx, 1 119 | shr bx, 1 120 | shr bx, 1 121 | shl bl, 1 122 | shl bl, 1 123 | shl bl, 1 124 | shl bl, 1 125 | add bl, bh 126 | mov [di], bl ; write pixels 127 | inc di 128 | mov ah, ds:[di+bp] ; get next pixels 129 | mov bl, ah 130 | shr ah, 1 131 | shr ah, 1 132 | shr ah, 1 133 | shr ah, 1 134 | and bl, 15 135 | 136 | add dh, al ; compute sums 137 | add dl, dh 138 | add dh, ah 139 | mov si, dx ; compute pixels 140 | shl si, 1 141 | shl si, 1 142 | add dx, si 143 | shr dx, 1 144 | shr dx, 1 145 | shr dx, 1 146 | shr dx, 1 147 | shl dl, 1 148 | shl dl, 1 149 | shl dl, 1 150 | shl dl, 1 151 | add dl, dh 152 | mov [di], dl ; write pixels 153 | inc di 154 | mov bh, ds:[di+bp] ; get next pixels 155 | mov dl, bh 156 | shr bh, 1 157 | shr bh, 1 158 | shr bh, 1 159 | shr bh, 1 160 | and dl, 15 161 | 162 | pop cx 163 | dec cx 164 | jcxz cga_fire_loop26_done 165 | jmp cga_fire_loop26 166 | cga_fire_loop26_done: 167 | 168 | ; extra two iterations 169 | add ah, bl ; compute sums 170 | add al, ah 171 | add ah, bh 172 | mov si, ax ; compute pixels 173 | shl si, 1 174 | shl si, 1 175 | add ax, si 176 | shr ax, 1 177 | shr ax, 1 178 | shr ax, 1 179 | shr ax, 1 180 | shl al, 1 181 | shl al, 1 182 | shl al, 1 183 | shl al, 1 184 | add al, ah 185 | mov [di], al ; write pixels 186 | inc di 187 | mov dh, ds:[di+bp] ; get next pixels 188 | mov al, dh 189 | shr dh, 1 190 | shr dh, 1 191 | shr dh, 1 192 | shr dh, 1 193 | and al, 15 194 | 195 | add bh, dl ; compute sums 196 | add bl, bh 197 | add bh, dh 198 | mov si, bx ; compute pixels 199 | shl si, 1 200 | shl si, 1 201 | add bx, si 202 | shr bx, 1 203 | shr bx, 1 204 | shr bx, 1 205 | shr bx, 1 206 | shl bl, 1 207 | shl bl, 1 208 | shl bl, 1 209 | shl bl, 1 210 | add bl, bh 211 | mov [di], bl ; write pixels 212 | inc di 213 | 214 | sub di, 8192 215 | jnc cga_fire_odd 216 | add di, 16304 217 | cga_fire_odd: 218 | 219 | xor bp, 0c050h ; switch between 8193 and -8111 220 | 221 | pop cx 222 | dec cx 223 | jcxz cga_fire_done16 224 | jmp cga_fire_loop16 225 | cga_fire_done16: 226 | 227 | pop bp 228 | pop di 229 | pop cx 230 | dec cx 231 | jcxz cga_fire_done 232 | jmp cga_fire_loop 233 | cga_fire_done: 234 | 235 | pop ds 236 | pop si 237 | pop di 238 | pop bp 239 | ret 240 | _cga_fire ENDP 241 | 242 | END -------------------------------------------------------------------------------- /cga320x200/ludicrous/linewide.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_line_wide 6 | _cga_draw_line_wide PROC 7 | ARG buff:DWORD, x:WORD, y:WORD, incs:WORD, w:WORD, len:WORD, colour:BYTE 8 | ; draw a line with starting point (x, y) and other starting point at 9 | ; (x + w, y) (where w may be negative), with increments in the 10 | ; x direction in inc[i]. Requires width != 0. 11 | push bp 12 | mov bp, sp 13 | push di 14 | push si 15 | 16 | les di, buff ; get buffer address in es:di 17 | 18 | mov ch, [colour] ; put solid colour in ch 19 | mov al, ch 20 | shl al, 1 21 | shl al, 1 22 | shl al, 1 23 | shl al, 1 24 | add ch, al 25 | 26 | xor dx, dx 27 | mov ax, [y] ; set dx to offset of CGA bank (odd/even) 28 | shr ax, 1 29 | jnc line_wide_even_y 30 | mov dx, 8192 31 | ror ch, 1 ; adjust colour for odd/even starting line 32 | ror ch, 1 33 | line_wide_even_y: 34 | 35 | shl ax, 1 ; set di to offset address of line y 36 | shl ax, 1 37 | shl ax, 1 38 | shl ax, 1 39 | add dx, ax 40 | shl ax, 1 41 | shl ax, 1 42 | add dx, ax 43 | add di, dx 44 | 45 | mov si, [incs] ; get address of increments buffer 46 | 47 | mov ax, [x] 48 | mov dx, [w] 49 | dec dx ; rightmost pixel not drawn 50 | jns line_wide_pos 51 | add ax, dx 52 | not dx 53 | line_wide_pos: 54 | add dx, ax 55 | 56 | mov bp, [len] ; get number of horizontal lines 57 | ; last line is not drawn 58 | 59 | inc si 60 | 61 | push ax 62 | push dx 63 | push di 64 | 65 | line_wide_short_loop: 66 | mov cl, al ; set cl to 2*(x0 mod 4) 67 | and cl, 3 68 | shl cl, 1 69 | 70 | mov bl, dl ; set bl to 2*(x1 mod 4) 71 | and bl, 3 72 | shl bl, 1 73 | 74 | shr ax, 1 ; add x0/4 to offset 75 | shr ax, 1 76 | add di, ax 77 | 78 | shr dx, 1 ; set dx to x1/4 - x0/4 (final offset - initial offset) 79 | shr dx, 1 80 | sub dx, ax 81 | 82 | mov bh, 0ffh ; prepare left mask in bh 83 | shr bh, cl 84 | 85 | mov cl, bl ; prepare right mask in bl 86 | mov bl, 0c0h 87 | sar bl, cl 88 | 89 | mov al, ch ; copy colour in al and ah 90 | mov ah, ch 91 | 92 | dec dl ; if first and last pixels are not in the same byte 93 | jns line_wide_long_line 94 | long_wide_short_line: 95 | 96 | and bl, bh ; compute overlapped mask and put masked colour in al 97 | and al, bl 98 | not bl 99 | 100 | and bl, es:[di] ; draw pixels 101 | or al, bl 102 | stosb 103 | 104 | ror ch, 1 105 | ror ch, 1 106 | 107 | pop di 108 | sub di, 8112 ; increment y 109 | sbb ax, ax 110 | and ax, 16304 111 | add di, ax 112 | 113 | pop dx 114 | pop ax 115 | 116 | mov bx, ax 117 | mov al, BYTE PTR [si] 118 | cbw 119 | add dx, ax 120 | add ax, bx 121 | 122 | inc si 123 | 124 | push ax 125 | push dx 126 | push di 127 | 128 | dec bp 129 | jnz line_wide_short_loop 130 | 131 | pop di 132 | pop dx 133 | pop ax 134 | 135 | pop si 136 | pop di 137 | pop bp 138 | ret 139 | 140 | line_wide_long_loop: 141 | mov cl, al ; set cl to 2*(x0 mod 4) 142 | and cl, 3 143 | shl cl, 1 144 | 145 | mov bl, dl ; set bl to 2*(x1 mod 4) 146 | and bl, 3 147 | shl bl, 1 148 | 149 | shr ax, 1 ; add x0/4 to offset 150 | shr ax, 1 151 | add di, ax 152 | 153 | shr dx, 1 ; set dx to x1/4 - x0/4 - 1 (final offset - initial offset - 1) 154 | shr dx, 1 155 | sub dx, ax 156 | 157 | mov bh, 0ffh ; prepare left mask in bh 158 | shr bh, cl 159 | 160 | mov cl, bl ; prepare right mask in bl 161 | mov bl, 0c0h 162 | sar bl, cl 163 | 164 | mov al, ch ; put colour into al and ah 165 | mov ah, ch 166 | 167 | dec dx ; get iterations 168 | js line_wide_short_line 169 | 170 | line_wide_long_line: 171 | and al, bh ; put left hand mask in bh and colour in al 172 | not bh 173 | 174 | and bh, es:[di] ; draw pixels on left side of line 175 | or al, bh 176 | stosb 177 | 178 | mov al, ah ; draw full colour bytes 179 | mov cx, dx 180 | shr cx, 1 181 | jnc line_wide_even_iter 182 | stosb 183 | line_wide_even_iter: 184 | rep stosw 185 | 186 | and al, bl ; put right hand mask in bl and colour in al 187 | not bl 188 | 189 | and bl, es:[di] ; draw right hand pixels 190 | or al, bl 191 | stosb 192 | 193 | mov ch, ah ; save colour 194 | 195 | ror ch, 1 196 | ror ch, 1 197 | 198 | pop di 199 | sub di, 8112 ; increment y 200 | sbb ax, ax 201 | and ax, 16304 202 | add di, ax 203 | 204 | pop dx 205 | pop ax 206 | 207 | mov bx, ax 208 | mov al, BYTE PTR [si] 209 | cbw 210 | add dx, ax 211 | add ax, bx 212 | 213 | inc si 214 | push ax 215 | push dx 216 | push di 217 | 218 | dec bp 219 | jnz line_wide_long_loop 220 | 221 | pop di 222 | pop dx 223 | pop ax 224 | 225 | pop si 226 | pop di 227 | pop bp 228 | ret 229 | _cga_draw_line_wide ENDP 230 | 231 | END 232 | 233 | -------------------------------------------------------------------------------- /cga320x200/fast/vline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_vline 6 | _cga_draw_vline PROC 7 | ARG buff:DWORD, x:WORD, y0:WORD, y1:WORD, colour:BYTE 8 | ; draw a line from (x, y0) - (x, y1) including endpoints in the give colour (0-3) 9 | push bp 10 | mov bp, sp 11 | push di 12 | push si 13 | push ds 14 | 15 | les di, buff ; get buffer address in es:di 16 | 17 | mov ax, es ; mirror in ds 18 | mov ds, ax 19 | 20 | mov ax, [y0] ; get y0 coordinate 21 | inc ax 22 | shr ax, 1 ; set ax = (y0 + 1)/2 23 | cmc 24 | sbb bx, bx ; bx = -1 if y0 is odd, else bx = 0 25 | 26 | mov dx, [y1] ; get y1 coordinate 27 | shr dx, 1 ; y1/2 28 | cmc 29 | sbb cx, cx ; cx = -1 if y1 even, else cx = 0 30 | 31 | sub dx, ax ; dx = even line iterations 32 | inc dx 33 | 34 | mov si, dx ; si = odd line iterations 35 | add si, cx 36 | sub si, bx 37 | 38 | and bx, -80 ; bx = -80 if y0 is odd, else bx = 0 39 | 40 | shl ax, 1 ; set di to 80*(y0 + 1)/2 = first even line 41 | shl ax, 1 42 | shl ax, 1 43 | shl ax, 1 44 | add di, ax 45 | shl ax, 1 46 | shl ax, 1 47 | add di, ax 48 | 49 | add bx, di ; set bx to 8192 + 80*(y0/2) = first odd line 50 | add bh, 020h 51 | 52 | mov ax, [x] ; get x coordinate 53 | mov cl, al 54 | shr ax, 1 55 | shr ax, 1 ; compute byte of pixel at coord x 56 | add di, ax ; add it to offset of first even line 57 | add bx, ax ; add it to offset of first odd line 58 | 59 | mov ah, [colour] ; shift colour (ah) and mask (dl) into correct bitfields 60 | inc cl 61 | and cl, 3 62 | shl cl, 1 63 | ror ah, cl 64 | mov al, 0fch 65 | ror al, cl 66 | 67 | mov cx, dx ; get iterations 68 | 69 | mov dl, al 70 | 71 | shr cx, 1 72 | jnc vline_even_iters 73 | 74 | mov al, dl ; write pixel 75 | and al, [di] 76 | or al, ah 77 | stosb 78 | 79 | add di, 79 ; jump to next odd line 80 | 81 | vline_even_iters: 82 | 83 | shr cx, 1 84 | jnc vline_even4 85 | 86 | mov al, dl ; write pixel 87 | and al, [di] 88 | or al, ah 89 | stosb 90 | 91 | add di, 79 ; jump to next odd line 92 | 93 | mov al, dl ; write pixel 94 | and al, [di] 95 | or al, ah 96 | stosb 97 | 98 | add di, 79 ; jump to next odd line 99 | 100 | vline_even4: 101 | 102 | cmp cx, 0 ; check for zero iterations 103 | je vline_done_even 104 | 105 | vline_even: ; display pixels on even lines (unroll by 4) 106 | 107 | mov al, dl ; write pixel 108 | and al, [di] 109 | or al, ah 110 | stosb 111 | 112 | add di, 79 ; jump to next even line 113 | 114 | mov al, dl ; write pixel 115 | and al, [di] 116 | or al, ah 117 | stosb 118 | 119 | add di, 79 ; jump to next even line 120 | 121 | mov al, dl ; write pixel 122 | and al, [di] 123 | or al, ah 124 | stosb 125 | 126 | add di, 79 ; jump to next even line 127 | 128 | mov al, dl ; write pixel 129 | and al, [di] 130 | or al, ah 131 | stosb 132 | 133 | add di, 79 ; jump to next even line 134 | loop vline_even ; loop 135 | 136 | vline_done_even: 137 | 138 | mov di, bx ; load offset of first odd line 139 | 140 | mov cx, si ; get iterations 141 | 142 | mov bx, 79 ; store jump value 143 | 144 | shr cx, 1 ; unroll by 2 145 | jnc vline_odd_iters 146 | 147 | mov al, dl ; write pixel 148 | and al, [di] 149 | or al, ah 150 | stosb 151 | 152 | add di, bx ; jump to next odd line 153 | 154 | vline_odd_iters: 155 | 156 | shr cx, 1 ; unroll by 4 157 | jnc vline_odd4 158 | 159 | mov al, dl ; write pixel 160 | and al, [di] 161 | or al, ah 162 | stosb 163 | 164 | add di, bx ; jump to next odd line 165 | 166 | mov al, dl ; write pixel 167 | and al, [di] 168 | or al, ah 169 | stosb 170 | 171 | add di, bx ; jump to next odd line 172 | 173 | vline_odd4: 174 | 175 | cmp cx, 0 ; check for zero iterations 176 | je vline_done_odd 177 | 178 | vline_odd: ; display pixels on odd lines (unroll by 4) 179 | 180 | mov al, dl ; write pixel 181 | and al, [di] 182 | or al, ah 183 | stosb 184 | 185 | add di, bx ; jump to next odd line 186 | 187 | mov al, dl ; write pixel 188 | and al, [di] 189 | or al, ah 190 | stosb 191 | 192 | add di, bx ; jump to next odd line 193 | 194 | mov al, dl ; write pixel 195 | and al, [di] 196 | or al, ah 197 | stosb 198 | 199 | add di, bx ; jump to next odd line 200 | 201 | mov al, dl ; write pixel 202 | and al, [di] 203 | or al, ah 204 | stosb 205 | 206 | add di, bx ; jump to next odd line 207 | loop vline_odd ; loop 208 | 209 | vline_done_odd: 210 | 211 | pop ds 212 | pop si 213 | pop di 214 | pop bp 215 | ret 216 | _cga_draw_vline ENDP 217 | 218 | END -------------------------------------------------------------------------------- /cga320x200/ludicrous/polisect.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _poly_intersect 6 | _poly_intersect PROC 7 | ARG buff:WORD, x1R:WORD, y1:WORD, inc1R:WORD, len1:WORD, x2L:WORD, x2R:WORD, y2:WORD, inc2L:WORD, inc2R:WORD, len2:WORD 8 | push bp 9 | mov bp, sp 10 | push di 11 | push si 12 | 13 | mov dx, [y1] 14 | mov bx, [y2] 15 | mov cx, bx 16 | sub cx, dx ; which y comes first 17 | jae poly_intersect_adjust1 18 | 19 | mov di, [inc2L] 20 | add di, bx 21 | add bx, [inc2R] ; will go in bp 22 | 23 | mov ax, [x1R] ; compute differences 24 | mov dx, [x2L] 25 | sub dx, ax 26 | sub ax, [x2R] 27 | neg ax 28 | mov dh, al 29 | 30 | mov ah, BYTE PTR [len2] ; adjust len2 31 | add ah, cl 32 | 33 | mov al, BYTE PTR [len1] 34 | sub al, ah 35 | 36 | jg poly_intersect_force_prologue1 37 | add ah, al ; main iterations in ah 38 | xor al, al ; no prologue iterations 39 | 40 | poly_intersect_force_prologue1: 41 | push ax ; push prologue iterations (in al) 42 | 43 | neg cx ; top adjust iterations 44 | 45 | poly_intersect_adjust2_loop: 46 | inc di ; skip to next inc 47 | inc bx 48 | 49 | add dl, [di] ; apply increments from poly2 50 | add dh, [bx] 51 | loop poly_intersect_adjust2_loop 52 | 53 | mov cl, ah ; get iterations (ch = 0 after loop) 54 | 55 | mov ax, [y1] 56 | mov si, [inc1R] 57 | add si, ax 58 | mov bp, [buff] 59 | add bp, ax 60 | xchg bp, bx 61 | 62 | jmp poly_intersect_skip1 63 | 64 | 65 | poly_intersect_adjust1: 66 | mov si, [inc1R] 67 | add si, dx 68 | mov bx, [buff] 69 | add bx, dx 70 | mov di, [x1R] 71 | 72 | mov dx, [len1] ; adjust len1 73 | 74 | jcxz poly_intersect_skip_adjust1 75 | 76 | sub dx, cx 77 | 78 | poly_intersect_adjust1_loop: 79 | inc si ; skip to next inc 80 | inc bx 81 | 82 | mov al, BYTE PTR [si] ; get increment 83 | mov BYTE PTR [bx], al ; copy out increments 84 | 85 | cbw ; sign extend 86 | add di, ax ; increment x1R 87 | loop poly_intersect_adjust1_loop 88 | 89 | poly_intersect_skip_adjust1: 90 | 91 | mov ax, [x2L] ; adjusted len1 in al 92 | xchg ax, dx 93 | 94 | sub dx, di ; compute differences 95 | mov cx, [x2R] 96 | sub cx, di 97 | mov dh, cl 98 | 99 | mov ah, BYTE PTR [len2] 100 | sub al, ah 101 | jg poly_intersect_force_prologue2 102 | add ah, al 103 | xor al, al ; no prologue iterations 104 | 105 | poly_intersect_force_prologue2: 106 | push ax ; push prologue iterations (in al) 107 | ; main iterations are in ah 108 | 109 | xor ch, ch 110 | 111 | mov cl, ah ; get iterations 112 | 113 | mov ax, [y2] 114 | mov di, [inc2L] 115 | add di, ax 116 | mov bp, [inc2R] 117 | add bp, ax 118 | 119 | 120 | 121 | 122 | poly_intersect_skip1: 123 | 124 | cmp cx, 0 125 | jnz poly_intersect_inc1_loop 126 | jmp prologue 127 | 128 | 129 | poly_intersect_inc1_start1: 130 | add dh, BYTE PTR [bp] ; add inc2R 131 | sub dh, ah ; sub inc1R 132 | 133 | poly_intersect_inc1_start2: 134 | sub al, dl 135 | mov BYTE PTR [bx], al ; write out shift to poly1 136 | 137 | dec cx 138 | jz prologue 139 | 140 | poly_intersect_inc1_loop: 141 | inc di ; move to next incs 142 | inc si 143 | inc bp 144 | inc bx 145 | 146 | mov al, BYTE PTR [di] 147 | add dl, al ; add inc2L 148 | 149 | mov ah, BYTE PTR [si] 150 | sub dl, ah ; sub inc1R 151 | js poly_intersect_inc1_check 152 | 153 | add dh, BYTE PTR [bp] ; add inc2R 154 | 155 | sub dh, ah ; sub inc1R 156 | 157 | mov BYTE PTR [bx], ah ; write out inc1R 158 | 159 | loop poly_intersect_inc1_loop 160 | jmp prologue 161 | 162 | poly_intersect_inc1_check: 163 | add dh, BYTE PTR [bp] ; add inc2R 164 | 165 | sub dh, ah ; sub inc1R 166 | 167 | jns poly_intersect_inc2_start 168 | 169 | mov BYTE PTR [bx], ah ; write out inc1R 170 | 171 | loop poly_intersect_inc1_loop 172 | jmp prologue 173 | 174 | 175 | 176 | poly_intersect_inc2_start: 177 | add ah, dl 178 | mov BYTE PTR [bx], ah ; write out shift to poly2 179 | 180 | dec cx 181 | jz prologue 182 | 183 | poly_intersect_inc2_loop: 184 | inc di ; move to next increment 185 | inc si 186 | inc bp 187 | inc bx 188 | 189 | mov al, BYTE PTR [di] 190 | add dl, al ; add inc2L 191 | 192 | mov ah, BYTE PTR [si] 193 | sub dl, ah ; sub inc1R 194 | jns poly_intersect_inc1_start1 195 | 196 | add dh, BYTE PTR [bp] ; add inc2R 197 | sub dh, ah ; sub inc1R 198 | js poly_intersect_inc1_start2 199 | 200 | mov BYTE PTR [bx], al ; write out inc2L 201 | loop poly_intersect_inc2_loop 202 | 203 | 204 | prologue: 205 | 206 | pop cx ; pop iterations 207 | xor ch, ch 208 | 209 | jcxz poly_intersect_done 210 | 211 | poly_intersect_prologue_loop: 212 | inc si ; move to next inc 213 | inc bx 214 | 215 | mov al, BYTE PTR [si] ; write out inc1R 216 | mov BYTE PTR [bx], al 217 | 218 | loop poly_intersect_prologue_loop 219 | 220 | poly_intersect_done: 221 | 222 | pop si 223 | pop di 224 | pop bp 225 | ret 226 | _poly_intersect ENDP 227 | 228 | END -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x50/ROTAZOOM.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "pcx.h" 8 | 9 | extern void rotozoom(unsigned char far * buff, 10 | unsigned char x, unsigned char y, int xinc, int yinc); 11 | 12 | int set_video_mode(int n) 13 | { 14 | union REGS regs; 15 | 16 | regs.h.ah = 0; 17 | regs.h.al = n; 18 | int86(0x10, ®s, ®s); 19 | } 20 | 21 | void set_video_char_height(unsigned char pixels) 22 | { 23 | unsigned char total = 32*(8/pixels) - 1; 24 | unsigned char displayed = 25*(8/pixels); 25 | unsigned char sync = displayed + 3*(8/pixels); 26 | 27 | pixels--; 28 | 29 | asm push ds 30 | asm push ax 31 | asm push dx 32 | asm push si 33 | 34 | asm mov ax, 0040h /* get current value of mode-set register */ 35 | asm mov ds, ax 36 | asm mov si, 0065h 37 | asm mov al, [si] 38 | 39 | asm xor al, 08h /* disable video */ 40 | asm mov dx, 03d8h 41 | asm out dx, al 42 | asm mov [si], al 43 | 44 | asm xor ax, ax /* get address of video initialisation table */ 45 | asm mov ds, ax 46 | asm mov si, 0074h 47 | asm mov ax, [si] 48 | asm mov ds, ax 49 | asm mov si, [si+2] 50 | 51 | asm mov dx, 03d4h /* set current max scan line address */ 52 | asm mov al, 09h 53 | asm out dx, al 54 | asm mov dx, 03d5h 55 | asm mov al, pixels 56 | asm out dx, al 57 | asm mov [si+9], al 58 | 59 | asm mov dx, 03d4h /* set vertical total */ 60 | asm mov al, 04h 61 | asm out dx, al 62 | asm mov dx, 03d5h 63 | asm mov al, total 64 | asm out dx, al 65 | asm mov [si+4], al 66 | 67 | asm mov dx, 03d4h /* set vertical displayed */ 68 | asm mov al, 06h 69 | asm out dx, al 70 | asm mov dx, 03d5h 71 | asm mov al, displayed 72 | asm out dx, al 73 | asm mov [si+6], al 74 | 75 | asm mov dx, 03d4h /* set vertical sync position */ 76 | asm mov al, 07h 77 | asm out dx, al 78 | asm mov dx, 03d5h 79 | asm mov al, sync 80 | asm out dx, al 81 | asm mov [si+7], al 82 | 83 | asm mov ax, 0040h /* get current value of mode-set register */ 84 | asm mov ds, ax 85 | asm mov si, 0065h 86 | asm mov al, [si] 87 | 88 | asm xor al, 08h /* enable video */ 89 | asm mov dx, 03d8h 90 | asm out dx, al 91 | asm mov [si], al 92 | 93 | asm pop si 94 | asm pop dx 95 | asm pop ax 96 | asm pop ds 97 | } 98 | 99 | void set_video_blink_toggle() 100 | { 101 | asm push ds 102 | asm push ax 103 | asm push dx 104 | asm push si 105 | 106 | asm mov ax, 0040h /* get current value of mode-set register */ 107 | asm mov ds, ax 108 | asm mov si, 0065h 109 | asm mov al, [si] 110 | 111 | asm xor al, 08h /* disable video */ 112 | asm mov dx, 03d8h 113 | asm out dx, al 114 | asm mov [si], al 115 | 116 | asm xor al, 08h /* enable video */ 117 | asm xor al, 020h /* toggle blink */ 118 | asm mov dx, 03d8h 119 | asm out dx, al 120 | asm mov [si], al 121 | 122 | asm pop si 123 | asm pop dx 124 | asm pop ax 125 | asm pop ds 126 | } 127 | 128 | void far * buff_alloc(unsigned long nbytes) 129 | { 130 | void far * buff = farmalloc(nbytes + 8); 131 | if (buff == NULL) 132 | { 133 | printf("Insufficient memory\n"); 134 | abort(); 135 | } 136 | 137 | assert(FP_OFF(buff) == 8); 138 | 139 | return MK_FP(FP_SEG(buff)+1, FP_OFF(buff)-8); 140 | } 141 | 142 | void buff_free(void far * buff) 143 | { 144 | farfree(MK_FP(FP_SEG(buff)-1, FP_OFF(buff)+8)); 145 | } 146 | 147 | void bitplanes_to_rgbi(unsigned char far * rgbi, 148 | unsigned char far * bp, int rows, int bytes_per_row) 149 | { 150 | int n = bytes_per_row/4; 151 | unsigned char p1, p2, p3, p4, t; 152 | int i, j, k; 153 | 154 | for (i = 0; i < rows; i++) 155 | { 156 | for (j = 0, k = 0; j < n; j++, k += 8) 157 | { 158 | p1 = bp[j]; 159 | p2 = bp[j + n]; 160 | p3 = bp[j + 2*n]; 161 | p4 = bp[j + 3*n]; 162 | 163 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 164 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 165 | rgbi[k + 7] = t + (t<<4); 166 | 167 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 168 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 169 | rgbi[k + 6] = t + (t<<4); 170 | 171 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 172 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 173 | rgbi[k + 5] = t + (t<<4); 174 | 175 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 176 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 177 | rgbi[k + 4] = t + (t<<4); 178 | 179 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 180 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 181 | rgbi[k + 3] = t + (t<<4); 182 | 183 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 184 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 185 | rgbi[k + 2] = t + (t<<4); 186 | 187 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 188 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 189 | rgbi[k + 1] = t + (t<<4); 190 | 191 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 192 | rgbi[k] = t + (t<<4); 193 | } 194 | 195 | bp += bytes_per_row; 196 | rgbi += 2*bytes_per_row; 197 | } 198 | } 199 | 200 | int main(void) 201 | { 202 | int i, j, k, l; 203 | int x, y, inc; 204 | unsigned char far * buff, far * bp, far * video; 205 | pcx_header_s header; 206 | FILE * file; 207 | double sintab[100]; 208 | double costab[100]; 209 | double theta = 0.0; 210 | 211 | randomize(); 212 | 213 | printf("WARNING: this demo requires CGA hardware. It may damage EGA/VGA machines\n"); 214 | printf("If you don't have a CGA or clone CGA card press CTRL-C or reset now!\n"); 215 | printf("The responsibility is yours. Press ENTER if you wish to continue.\n"); 216 | 217 | getchar(); 218 | 219 | printf("Computing sine/cosine table \n"); 220 | 221 | for (i = 0; i < 100; i++) 222 | { 223 | sintab[i] = sin(theta); 224 | costab[i] = cos(theta); 225 | theta += 0.0628318; 226 | } 227 | 228 | printf("Loading graphic\n"); 229 | 230 | bp = buff_alloc(33768); 231 | if (bp == NULL) 232 | { 233 | printf("Insufficient memory\n"); 234 | abort(); 235 | } 236 | 237 | buff = buff_alloc(65536); 238 | if (buff == NULL) 239 | { 240 | printf("Insufficient memory\n"); 241 | abort(); 242 | } 243 | 244 | file = fopen("pcretro.pcx", "rb"); 245 | if (file == NULL) 246 | { 247 | printf("Unable to open pcretro.pcx\n"); 248 | abort(); 249 | } 250 | 251 | pcx_header_read(&header, file); 252 | 253 | pcx_buffer_load(bp, file, header.bytes_per_line*header.nplanes, 254 | header.y1 - header.y0 + 1); 255 | fclose(file); 256 | 257 | printf("Converting to RGBI\n"); 258 | 259 | bitplanes_to_rgbi(buff, bp, 256, 128); 260 | buff_free(bp); 261 | 262 | video = MK_FP(0xb800, 0); 263 | 264 | set_video_mode(1); 265 | 266 | for (i = 0; i < 2000; i++) 267 | { 268 | video[2*i+1] = 0; 269 | video[2*i] = 221; 270 | } 271 | 272 | set_video_char_height(4); 273 | set_video_blink_toggle(); 274 | 275 | k = 0; 276 | l = 0; 277 | inc = 4; 278 | for (y = 0; y < 256;) 279 | { 280 | int scale = 768 + 512*sintab[l]; 281 | for (x = 0; x >= 0 && x < 256; x+=inc) 282 | { 283 | rotozoom(buff, x, y, (int) (scale*costab[k]), (int) (scale*sintab[k])); 284 | k++; 285 | if (k == 100) 286 | k = 0; 287 | if ((x & 63) == 60) 288 | { 289 | y++; 290 | l++; 291 | if (l == 100) 292 | l = 0; 293 | scale = 768 + 512*sintab[l]; 294 | } 295 | } 296 | if (x == 256) 297 | x = 252; 298 | if (x == -1) 299 | x = 0; 300 | inc = -inc; 301 | } 302 | 303 | getchar(); 304 | 305 | buff_free(buff); 306 | 307 | set_video_blink_toggle(); 308 | set_video_char_height(8); 309 | set_video_mode(3); 310 | 311 | return 0; 312 | } 313 |  -------------------------------------------------------------------------------- /cga320x200/ludicrous/vline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | sp_save dw ? 6 | 7 | PUBLIC _cga_draw_vline 8 | _cga_draw_vline PROC 9 | ARG buff:DWORD, x:WORD, y0:WORD, y1:WORD, colour:BYTE 10 | ; draw a line from (x, y0) - (x, y1) including endpoints in the give colour (0-3) 11 | push bp 12 | mov bp, sp 13 | push di 14 | push si 15 | push ds 16 | 17 | les di, buff ; get buffer address in es:di 18 | 19 | mov ax, es ; mirror in ds 20 | mov ds, ax 21 | 22 | mov ax, [y0] ; get y0 coordinate 23 | inc ax 24 | shr ax, 1 ; set ax = (y0 + 1)/2 25 | cmc 26 | sbb bx, bx ; bx = -1 if y0 is odd, else bx = 0 27 | 28 | mov dx, [y1] ; get y1 coordinate 29 | shr dx, 1 ; y1/2 30 | cmc 31 | sbb cx, cx ; cx = -1 if y1 even, else cx = 0 32 | 33 | sub dx, ax ; dx = even line iterations 34 | inc dx 35 | 36 | mov si, dx ; si = odd line iterations 37 | add si, cx 38 | sub si, bx 39 | 40 | and bx, -80 ; bx = -80 if y0 is odd, else bx = 0 41 | 42 | shl ax, 1 ; set di to 80*(y0 + 1)/2 = first even line 43 | shl ax, 1 44 | shl ax, 1 45 | shl ax, 1 46 | add di, ax 47 | shl ax, 1 48 | shl ax, 1 49 | add di, ax 50 | 51 | add bx, di ; set bx to 8192 + 80*(y0/2) = first odd line 52 | add bh, 020h 53 | 54 | mov ax, [x] ; get x coordinate 55 | mov cl, al 56 | shr ax, 1 57 | shr ax, 1 ; compute byte of pixel at coord x 58 | add di, ax ; add it to offset of first even line 59 | add bx, ax ; add it to offset of first odd line 60 | 61 | mov ah, [colour] ; shift colour (ah) and mask (dl) into correct bitfields 62 | inc cl 63 | and cl, 3 64 | shl cl, 1 65 | ror ah, cl 66 | mov al, 0fch 67 | ror al, cl 68 | 69 | mov cx, dx ; get iterations 70 | 71 | mov dl, al 72 | 73 | cli ; free up sp 74 | mov cs:[sp_save], sp 75 | 76 | mov sp, 79 77 | 78 | shr cx, 1 79 | jnc vline_even_iters 80 | 81 | mov al, dl ; write pixel 82 | and al, [di] 83 | or al, ah 84 | stosb 85 | 86 | add di, sp ; jump to next odd line 87 | 88 | vline_even_iters: 89 | 90 | shr cx, 1 91 | jnc vline_even4 92 | 93 | mov al, dl ; write pixel 94 | and al, [di] 95 | or al, ah 96 | stosb 97 | 98 | add di, sp ; jump to next odd line 99 | 100 | mov al, dl ; write pixel 101 | and al, [di] 102 | or al, ah 103 | stosb 104 | 105 | add di, sp ; jump to next odd line 106 | 107 | vline_even4: 108 | 109 | shr cx, 1 110 | jnc vline_even8 111 | 112 | mov al, dl ; write pixel 113 | and al, [di] 114 | or al, ah 115 | stosb 116 | 117 | add di, sp ; jump to next odd line 118 | 119 | mov al, dl ; write pixel 120 | and al, [di] 121 | or al, ah 122 | stosb 123 | 124 | add di, sp ; jump to next odd line 125 | 126 | mov al, dl ; write pixel 127 | and al, [di] 128 | or al, ah 129 | stosb 130 | 131 | add di, sp ; jump to next odd line 132 | 133 | mov al, dl ; write pixel 134 | and al, [di] 135 | or al, ah 136 | stosb 137 | 138 | add di, sp ; jump to next odd line 139 | 140 | vline_even8: 141 | 142 | cmp cx, 0 ; check for zero iterations 143 | je vline_done_even 144 | 145 | vline_even: ; display pixels on even lines (unroll by 8) 146 | 147 | mov al, dl ; write pixel 148 | and al, [di] 149 | or al, ah 150 | stosb 151 | 152 | add di, sp ; jump to next even line 153 | 154 | mov al, dl ; write pixel 155 | and al, [di] 156 | or al, ah 157 | stosb 158 | 159 | add di, sp ; jump to next even line 160 | 161 | mov al, dl ; write pixel 162 | and al, [di] 163 | or al, ah 164 | stosb 165 | 166 | add di, sp ; jump to next even line 167 | 168 | mov al, dl ; write pixel 169 | and al, [di] 170 | or al, ah 171 | stosb 172 | 173 | add di, sp ; jump to next even line 174 | 175 | mov al, dl ; write pixel 176 | and al, [di] 177 | or al, ah 178 | stosb 179 | 180 | add di, sp ; jump to next even line 181 | 182 | mov al, dl ; write pixel 183 | and al, [di] 184 | or al, ah 185 | stosb 186 | 187 | add di, sp ; jump to next even line 188 | 189 | mov al, dl ; write pixel 190 | and al, [di] 191 | or al, ah 192 | stosb 193 | 194 | add di, sp ; jump to next even line 195 | 196 | mov al, dl ; write pixel 197 | and al, [di] 198 | or al, ah 199 | stosb 200 | 201 | add di, sp ; jump to next even line 202 | loop vline_even ; loop 203 | 204 | vline_done_even: 205 | 206 | mov di, bx ; load offset of first odd line 207 | 208 | mov cx, si ; get iterations 209 | 210 | shr cx, 1 ; unroll by 2 211 | jnc vline_odd_iters 212 | 213 | mov al, dl ; write pixel 214 | and al, [di] 215 | or al, ah 216 | stosb 217 | 218 | add di, sp ; jump to next odd line 219 | 220 | vline_odd_iters: 221 | 222 | shr cx, 1 ; unroll by 4 223 | jnc vline_odd4 224 | 225 | mov al, dl ; write pixel 226 | and al, [di] 227 | or al, ah 228 | stosb 229 | 230 | add di, sp ; jump to next odd line 231 | 232 | mov al, dl ; write pixel 233 | and al, [di] 234 | or al, ah 235 | stosb 236 | 237 | add di, sp ; jump to next odd line 238 | 239 | vline_odd4: 240 | 241 | shr cx, 1 242 | jnc vline_odd8 243 | 244 | mov al, dl ; write pixel 245 | and al, [di] 246 | or al, ah 247 | stosb 248 | 249 | add di, sp ; jump to next odd line 250 | 251 | mov al, dl ; write pixel 252 | and al, [di] 253 | or al, ah 254 | stosb 255 | 256 | add di, sp ; jump to next odd line 257 | 258 | mov al, dl ; write pixel 259 | and al, [di] 260 | or al, ah 261 | stosb 262 | 263 | add di, sp ; jump to next odd line 264 | 265 | mov al, dl ; write pixel 266 | and al, [di] 267 | or al, ah 268 | stosb 269 | 270 | add di, sp ; jump to next odd line 271 | 272 | vline_odd8: 273 | 274 | cmp cx, 0 ; check for zero iterations 275 | je vline_done_odd 276 | 277 | vline_odd: ; display pixels on odd lines (unroll by 8) 278 | 279 | mov al, dl ; write pixel 280 | and al, [di] 281 | or al, ah 282 | stosb 283 | 284 | add di, sp ; jump to next odd line 285 | 286 | mov al, dl ; write pixel 287 | and al, [di] 288 | or al, ah 289 | stosb 290 | 291 | add di, sp ; jump to next odd line 292 | 293 | mov al, dl ; write pixel 294 | and al, [di] 295 | or al, ah 296 | stosb 297 | 298 | add di, sp ; jump to next odd line 299 | 300 | mov al, dl ; write pixel 301 | and al, [di] 302 | or al, ah 303 | stosb 304 | 305 | add di, sp ; jump to next odd line 306 | 307 | mov al, dl ; write pixel 308 | and al, [di] 309 | or al, ah 310 | stosb 311 | 312 | add di, sp ; jump to next odd line 313 | 314 | mov al, dl ; write pixel 315 | and al, [di] 316 | or al, ah 317 | stosb 318 | 319 | add di, sp ; jump to next odd line 320 | 321 | mov al, dl ; write pixel 322 | and al, [di] 323 | or al, ah 324 | stosb 325 | 326 | add di, sp ; jump to next odd line 327 | 328 | mov al, dl ; write pixel 329 | and al, [di] 330 | or al, ah 331 | stosb 332 | 333 | add di, sp ; jump to next odd line 334 | loop vline_odd ; loop 335 | 336 | vline_done_odd: 337 | 338 | mov sp, cs:[sp_save] 339 | sti 340 | 341 | pop ds 342 | pop si 343 | pop di 344 | pop bp 345 | ret 346 | _cga_draw_vline ENDP 347 | 348 | END -------------------------------------------------------------------------------- /cga320x200/small/line.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | PUBLIC _cga_draw_line 6 | _cga_draw_line PROC 7 | ; Draw a line from (x0, y0) to (x1, y1) in the given colour (0-3) in the CGA buffer buff 8 | ARG buff:DWORD, x0:WORD, y0:WORD, x1:WORD, y1:WORD, colour:BYTE 9 | push bp 10 | mov bp, sp 11 | push di 12 | push si 13 | push ds 14 | 15 | les di, buff ; set ES to segment for graphics memory (CGA or buffer) 16 | mov ax, es 17 | mov ds, ax ; reflect in DS 18 | 19 | mov dx, [x1] ; compute dx 20 | sub dx, [x0] 21 | jae line_dx_pos ; if x1 < x0 switch line endpoints 22 | mov ax, [x0] ; line must always be right moving 23 | xchg ax, [x1] 24 | mov [x0], ax 25 | mov ax, [y0] 26 | xchg ax, [y1] 27 | mov [y0], ax 28 | neg dx 29 | line_dx_pos: 30 | 31 | mov ax, [y0] ; compute offset for line y0 32 | shr ax, 1 ; add 8192 to offset if odd line 33 | sbb si, si 34 | and si, 8192 35 | shl ax, 1 ; add 80*y0 to offset 36 | shl ax, 1 37 | shl ax, 1 38 | shl ax, 1 39 | add si, ax 40 | shl ax, 1 41 | shl ax, 1 42 | add si, ax 43 | mov ax, [x0] ; add x0/4 to offset 44 | shr ax, 1 45 | shr ax, 1 46 | add si, ax 47 | add di, si 48 | 49 | mov cx, [x0] ; compute 2*(x0 mod 4) 50 | inc cx 51 | and cx, 3 52 | shl cx, 1 53 | 54 | mov bx, [y1] ; compute dy 55 | sub bx, [y0] 56 | jae line_down 57 | 58 | neg bx 59 | cmp bx, dx 60 | 61 | mov si, 8111 62 | mov ax, -16304 63 | 64 | jbe line_goto_hu 65 | 66 | mov WORD PTR cs:[line_v_xor1 + 2], ax 67 | mov WORD PTR cs:[line_v_xor2 + 2], ax 68 | jmp line_vu 69 | line_goto_hu: 70 | mov WORD PTR cs:[line_h_xor1 + 2], ax 71 | mov WORD PTR cs:[line_h_xor2 + 2], ax 72 | jmp line_hu 73 | 74 | line_down: 75 | 76 | cmp bx, dx 77 | 78 | mov si, 8191 79 | mov ax, -80 80 | 81 | jb line_hd 82 | jmp line_vd 83 | 84 | line_hd: ; horizontalish, down 85 | mov WORD PTR cs:[line_h_xor1 + 2], ax 86 | mov WORD PTR cs:[line_h_xor2 + 2], ax 87 | line_hu: ; horizontalish, up 88 | 89 | mov ax, dx ; compute iterations 90 | inc ax 91 | push ax ; save iterations 92 | shr ax, 1 ; we unroll by 2 93 | 94 | mov ah, [colour] ; compute initial colour information 95 | ror ah, cl 96 | mov ch, 0fch 97 | ror ch, cl ; compute initial mask 98 | 99 | mov bp, [y0] ; compute initial even/odd offset diff 100 | shr bp, 1 101 | mov bp, si 102 | jnc line_h_even 103 | sub bp, 16304 104 | line_h_even: 105 | 106 | shl bx, 1 ; compute 2*dy 107 | xor si, si ; D = -dx 108 | sub si, dx 109 | shl dx, 1 ; compute 2*dx 110 | 111 | mov cl, al ; get iterations 112 | 113 | mov al, [di] ; get first pixel 114 | 115 | cmp cl, 0 ; check for zero iterations 116 | je line_h_no_iter 117 | 118 | line_h_begin: 119 | add si, bx ; D += 2*dy 120 | jg line_h_Dgt0 ; if D <= 0 121 | 122 | and al, ch ; and with mask 123 | ror ch, 1 ; rotate mask 124 | ror ch, 1 125 | 126 | jnc line_h_3mod4 ; if 0, 1, 2 mod 4 127 | 128 | and al, ch ; and with mask 129 | or al, ah ; or with colour 130 | jmp line_h_Dcmp_end 131 | 132 | line_h_3mod4: ; else if 3 mod 4 133 | or al, ah ; or with colour 134 | stosb ; write out 135 | 136 | mov al, [di] 137 | and al, ch ; and with mask 138 | jmp line_h_Dcmp_end 139 | 140 | line_h_Dgt0: ; else if D > 0 141 | and al, ch ; and with mask 142 | or al, ah ; or with colour 143 | stosb ; write out 144 | 145 | add di, bp ; increase y coord 146 | line_h_xor1: 147 | xor bp, 01234h 148 | 149 | ror ch, 1 ; rotate mask 150 | ror ch, 1 151 | 152 | sbb di, -1 ; if 3 mod 4 increment offset 153 | 154 | mov al, [di] ; get pixel 155 | and al, ch ; and with mask 156 | 157 | sub si, dx ; D -= 2*dx 158 | 159 | line_h_Dcmp_end: 160 | 161 | ror ah, 1 ; rotate colour 162 | ror ah, 1 163 | or al, ah ; or with colour 164 | 165 | add si, bx ; D += 2*dy 166 | 167 | jle line_h_no_inc ; if D < 0 168 | 169 | stosb 170 | 171 | add di, bp ; increase y coord 172 | line_h_xor2: 173 | xor bp, 01234h 174 | 175 | sub si, dx ; D -= 2*dx 176 | 177 | ror ah, 1 ; rotate colour 178 | ror ah, 1 179 | ror ch, 1 ; rotate mask 180 | ror ch, 1 181 | 182 | sbb di, -1 ; if 3 mod 4 increment offset 183 | 184 | mov al, [di] ; get pixel 185 | 186 | dec cl 187 | jnz line_h_begin 188 | 189 | jmp line_h_no_iter 190 | line_h_no_inc: ; else D >= 0 191 | 192 | ror ah, 1 ; rotate colour 193 | ror ah, 1 194 | ror ch, 1 ; rotate mask 195 | ror ch, 1 196 | 197 | jc line_h_skip_write 198 | stosb ; write out 199 | mov al, [di] ; get pixel 200 | line_h_skip_write: 201 | 202 | dec cl 203 | jnz line_h_begin 204 | 205 | line_h_no_iter: 206 | 207 | pop bx ; if iterations is odd 208 | test bl, 1 209 | jz line_h_done 210 | 211 | and al, ch ; and with mask 212 | or al, ah ; or with colour 213 | 214 | line_h_done: 215 | stosb ; write out 216 | 217 | pop ds 218 | pop si 219 | pop di 220 | pop bp 221 | ret 222 | 223 | line_vd: 224 | mov WORD PTR cs:[line_v_xor1 + 2], ax 225 | mov WORD PTR cs:[line_v_xor2 + 2], ax 226 | line_vu: 227 | 228 | mov ax, bx ; compute iterations 229 | inc ax 230 | push ax ; save iterations 231 | shr ax, 1 ; we unroll by 2 232 | 233 | mov ah, [colour] ; compute initial colour information 234 | ror ah, cl 235 | mov ch, 0fch 236 | ror ch, cl ; compute initial mask 237 | 238 | mov bp, [y0] ; compute initial even/odd offset diff 239 | shr bp, 1 240 | mov bp, si 241 | jnc line_v_even 242 | sub bp, 16304 243 | line_v_even: 244 | 245 | shl dx, 1 ; compute 2*dx 246 | xor si, si ; D = -dy 247 | sub si, bx 248 | shl bx, 1 ; compute 2*dy 249 | 250 | mov cl, al ; get iterations 251 | 252 | cmp cl, 0 ; check for zero iterations 253 | je line_v_no_iter 254 | 255 | line_v_begin: 256 | mov al, ch ; get mask 257 | and al, [di] ; and with pixel 258 | or al, ah ; or with colour 259 | stosb ; write out 260 | 261 | add di, bp 262 | line_v_xor1: 263 | xor bp, 01234h 264 | 265 | add si, dx ; D -= 2*dx 266 | jng line_v_Dcmp_end 267 | 268 | inc di 269 | 270 | ror ah, 1 ; rotate colour 271 | ror ah, 1 272 | ror ch, 1 ; rotate mask 273 | ror ch, 1 274 | 275 | jnc line_v_3mod4 ; if 0, 1, 2 mod 4 276 | dec di 277 | line_v_3mod4: 278 | 279 | sub si, bx ; D -= 2*dy 280 | 281 | line_v_Dcmp_end: 282 | 283 | mov al, ch ; get mask 284 | and al, [di] ; and pixel 285 | or al, ah ; or colour 286 | stosb ; write out 287 | 288 | add di, bp ; increment y 289 | line_v_xor2: 290 | xor bp, 01234h 291 | 292 | add si, dx ; D += 2*dx 293 | 294 | jle line_v_no_inc ; if D >= 0 295 | 296 | inc di 297 | 298 | sub si, bx ; D -= 2*dy 299 | 300 | ror ah, 1 ; rotate colour 301 | ror ah, 1 302 | ror ch, 1 ; rotate mask 303 | ror ch, 1 304 | 305 | jnc line_v_no_inc ; if 3 mod 4 306 | dec di 307 | line_v_no_inc: 308 | 309 | dec cl 310 | jnz line_v_begin 311 | 312 | line_v_no_iter: 313 | 314 | pop bx 315 | test bl, 1 316 | jz line_v_done 317 | 318 | mov al, ch ; get mask 319 | and al, [di] ; and pixel 320 | or al, ah ; or colour 321 | stosb ; write out 322 | 323 | line_v_done: 324 | 325 | pop ds 326 | pop si 327 | pop di 328 | pop bp 329 | ret 330 | _cga_draw_line ENDP 331 | 332 | END 333 | 334 | -------------------------------------------------------------------------------- /cgaeffects/rotozoom80x100/ROTAZOOM.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "pcx.h" 8 | 9 | extern void cga_retrace(); 10 | 11 | extern void cga_draw_hline(unsigned char far * buff, 12 | int x0, int x1, int y, unsigned char colour); 13 | 14 | extern void rotozoom(unsigned char far * buff, 15 | unsigned char x, unsigned char y, int xinc, int yinc); 16 | 17 | int set_video_mode(int n) 18 | { 19 | union REGS regs; 20 | 21 | regs.h.ah = 0; 22 | regs.h.al = n; 23 | int86(0x10, ®s, ®s); 24 | } 25 | 26 | void set_video_char_height(unsigned char pixels) 27 | { 28 | unsigned char total = 32*(8/pixels) - 1; 29 | unsigned char displayed = 25*(8/pixels); 30 | unsigned char sync = displayed + 3*(8/pixels); 31 | 32 | pixels--; 33 | 34 | asm push ds 35 | asm push ax 36 | asm push dx 37 | asm push si 38 | 39 | asm mov ax, 0040h /* get current value of mode-set register */ 40 | asm mov ds, ax 41 | asm mov si, 0065h 42 | asm mov al, [si] 43 | 44 | asm xor al, 08h /* disable video */ 45 | asm mov dx, 03d8h 46 | asm out dx, al 47 | asm mov [si], al 48 | 49 | asm xor ax, ax /* get address of video initialisation table */ 50 | asm mov ds, ax 51 | asm mov si, 0074h 52 | asm mov ax, [si] 53 | asm mov ds, ax 54 | asm mov si, [si+2] 55 | 56 | asm mov dx, 03d4h /* set current max scan line address */ 57 | asm mov al, 09h 58 | asm out dx, al 59 | asm mov dx, 03d5h 60 | asm mov al, pixels 61 | asm out dx, al 62 | asm mov [si+9], al 63 | 64 | asm mov dx, 03d4h /* set vertical total */ 65 | asm mov al, 04h 66 | asm out dx, al 67 | asm mov dx, 03d5h 68 | asm mov al, total 69 | asm out dx, al 70 | asm mov [si+4], al 71 | 72 | asm mov dx, 03d4h /* set vertical displayed */ 73 | asm mov al, 06h 74 | asm out dx, al 75 | asm mov dx, 03d5h 76 | asm mov al, displayed 77 | asm out dx, al 78 | asm mov [si+6], al 79 | 80 | asm mov dx, 03d4h /* set vertical sync position */ 81 | asm mov al, 07h 82 | asm out dx, al 83 | asm mov dx, 03d5h 84 | asm mov al, sync 85 | asm out dx, al 86 | asm mov [si+7], al 87 | 88 | asm mov ax, 0040h /* get current value of mode-set register */ 89 | asm mov ds, ax 90 | asm mov si, 0065h 91 | asm mov al, [si] 92 | 93 | asm xor al, 08h /* enable video */ 94 | asm mov dx, 03d8h 95 | asm out dx, al 96 | asm mov [si], al 97 | 98 | asm pop si 99 | asm pop dx 100 | asm pop ax 101 | asm pop ds 102 | } 103 | 104 | void set_video_blink_toggle() 105 | { 106 | asm push ds 107 | asm push ax 108 | asm push dx 109 | asm push si 110 | 111 | asm mov ax, 0040h /* get current value of mode-set register */ 112 | asm mov ds, ax 113 | asm mov si, 0065h 114 | asm mov al, [si] 115 | 116 | asm xor al, 08h /* disable video */ 117 | asm mov dx, 03d8h 118 | asm out dx, al 119 | asm mov [si], al 120 | 121 | asm xor al, 08h /* enable video */ 122 | asm xor al, 020h /* toggle blink */ 123 | asm mov dx, 03d8h 124 | asm out dx, al 125 | asm mov [si], al 126 | 127 | asm pop si 128 | asm pop dx 129 | asm pop ax 130 | asm pop ds 131 | } 132 | 133 | void far * buff_alloc(unsigned long nbytes) 134 | { 135 | void far * buff = farmalloc(nbytes + 8); 136 | if (buff == NULL) 137 | { 138 | printf("Insufficient memory\n"); 139 | abort(); 140 | } 141 | 142 | assert(FP_OFF(buff) == 8); 143 | 144 | return MK_FP(FP_SEG(buff)+1, FP_OFF(buff)-8); 145 | } 146 | 147 | void buff_free(void far * buff) 148 | { 149 | farfree(MK_FP(FP_SEG(buff)-1, FP_OFF(buff)+8)); 150 | } 151 | 152 | void bitplanes_to_rgbi(unsigned char far * rgbi, 153 | unsigned char far * bp, int rows, int bytes_per_row) 154 | { 155 | int n = bytes_per_row/4; 156 | unsigned char p1, p2, p3, p4, t; 157 | int i, j, k; 158 | 159 | for (i = 0; i < rows; i++) 160 | { 161 | for (j = 0, k = 0; j < n; j++, k += 8) 162 | { 163 | p1 = bp[j]; 164 | p2 = bp[j + n]; 165 | p3 = bp[j + 2*n]; 166 | p4 = bp[j + 3*n]; 167 | 168 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 169 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 170 | rgbi[k + 7] = t + (t<<4); 171 | 172 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 173 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 174 | rgbi[k + 6] = t + (t<<4); 175 | 176 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 177 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 178 | rgbi[k + 5] = t + (t<<4); 179 | 180 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 181 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 182 | rgbi[k + 4] = t + (t<<4); 183 | 184 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 185 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 186 | rgbi[k + 3] = t + (t<<4); 187 | 188 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 189 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 190 | rgbi[k + 2] = t + (t<<4); 191 | 192 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 193 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 194 | rgbi[k + 1] = t + (t<<4); 195 | 196 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 197 | rgbi[k] = t + (t<<4); 198 | } 199 | 200 | bp += bytes_per_row; 201 | rgbi += 2*bytes_per_row; 202 | } 203 | } 204 | 205 | int main(void) 206 | { 207 | int i, j, k, l; 208 | int x, y, inc; 209 | unsigned char far * buff, far * bp, far * video; 210 | pcx_header_s header; 211 | FILE * file; 212 | double sintab[100]; 213 | double costab[100]; 214 | double theta = 0.0; 215 | 216 | randomize(); 217 | 218 | printf("WARNING: this demo requires CGA hardware. It may damage EGA/VGA machines\n"); 219 | printf("If you don't have a CGA or clone CGA card press CTRL-C or reset now!\n"); 220 | printf("The responsibility is yours. Press ENTER if you wish to continue.\n"); 221 | 222 | getchar(); 223 | 224 | printf("Computing sine/cosine table \n"); 225 | 226 | for (i = 0; i < 100; i++) 227 | { 228 | sintab[i] = sin(theta); 229 | costab[i] = cos(theta); 230 | theta += 0.0628318; 231 | } 232 | 233 | printf("Loading graphic\n"); 234 | 235 | bp = buff_alloc(33768); 236 | if (bp == NULL) 237 | { 238 | printf("Insufficient memory\n"); 239 | abort(); 240 | } 241 | 242 | buff = buff_alloc(65536); 243 | if (buff == NULL) 244 | { 245 | printf("Insufficient memory\n"); 246 | abort(); 247 | } 248 | 249 | file = fopen("pcretro.pcx", "rb"); 250 | if (file == NULL) 251 | { 252 | printf("Unable to open pcretro.pcx\n"); 253 | abort(); 254 | } 255 | 256 | pcx_header_read(&header, file); 257 | 258 | pcx_buffer_load(bp, file, header.bytes_per_line*header.nplanes, 259 | header.y1 - header.y0 + 1); 260 | fclose(file); 261 | 262 | printf("Converting to RGBI\n"); 263 | 264 | bitplanes_to_rgbi(buff, bp, 256, 128); 265 | buff_free(bp); 266 | 267 | video = MK_FP(0xb800, 0); 268 | 269 | set_video_mode(1); 270 | 271 | for (i = 0; i < 2000; i++) 272 | { 273 | video[2*i+1] = 0; 274 | video[2*i] = 221; 275 | } 276 | 277 | set_video_char_height(2); 278 | set_video_blink_toggle(); 279 | 280 | k = 0; 281 | l = 0; 282 | inc = 4; 283 | for (y = 0; y < 256;) 284 | { 285 | int scale = 768 + 512*sintab[l]; 286 | for (x = 0; x >= 0 && x < 256; x+=inc) 287 | { 288 | rotozoom(buff, x, y, (int) (scale*costab[k]), (int) (scale*sintab[k])); 289 | k++; 290 | if (k == 100) 291 | k = 0; 292 | if ((x & 63) == 60) 293 | { 294 | y++; 295 | l++; 296 | if (l == 100) 297 | l = 0; 298 | scale = 768 + 512*sintab[l]; 299 | } 300 | } 301 | if (x == 256) 302 | x = 252; 303 | if (x == -1) 304 | x = 0; 305 | inc = -inc; 306 | } 307 | 308 | getchar(); 309 | 310 | buff_free(buff); 311 | 312 | set_video_blink_toggle(); 313 | set_video_char_height(8); 314 | set_video_mode(3); 315 | 316 | return 0; 317 | } 318 |  -------------------------------------------------------------------------------- /cgaeffects/rotozoom160x100/ROTAZOOM.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "pcx.h" 8 | 9 | extern void cga_retrace(); 10 | 11 | extern void cga_draw_hline(unsigned char far * buff, 12 | int x0, int x1, int y, unsigned char colour); 13 | 14 | extern void rotozoom(unsigned char far * buff, 15 | unsigned char x, unsigned char y, int xinc, int yinc); 16 | 17 | int set_video_mode(int n) 18 | { 19 | union REGS regs; 20 | 21 | regs.h.ah = 0; 22 | regs.h.al = n; 23 | int86(0x10, ®s, ®s); 24 | } 25 | 26 | void set_video_char_height(unsigned char pixels) 27 | { 28 | unsigned char total = 32*(8/pixels) - 1; 29 | unsigned char displayed = 25*(8/pixels); 30 | unsigned char sync = displayed + 3*(8/pixels); 31 | 32 | pixels--; 33 | 34 | asm push ds 35 | asm push ax 36 | asm push dx 37 | asm push si 38 | 39 | asm mov ax, 0040h /* get current value of mode-set register */ 40 | asm mov ds, ax 41 | asm mov si, 0065h 42 | asm mov al, [si] 43 | 44 | asm xor al, 08h /* disable video */ 45 | asm mov dx, 03d8h 46 | asm out dx, al 47 | asm mov [si], al 48 | 49 | asm xor ax, ax /* get address of video initialisation table */ 50 | asm mov ds, ax 51 | asm mov si, 0074h 52 | asm mov ax, [si] 53 | asm mov ds, ax 54 | asm mov si, [si+2] 55 | 56 | asm mov dx, 03d4h /* set current max scan line address */ 57 | asm mov al, 09h 58 | asm out dx, al 59 | asm mov dx, 03d5h 60 | asm mov al, pixels 61 | asm out dx, al 62 | asm mov [si+019h], al 63 | 64 | asm mov dx, 03d4h /* set vertical total */ 65 | asm mov al, 04h 66 | asm out dx, al 67 | asm mov dx, 03d5h 68 | asm mov al, total 69 | asm out dx, al 70 | asm mov [si+014h], al 71 | 72 | asm mov dx, 03d4h /* set vertical displayed */ 73 | asm mov al, 06h 74 | asm out dx, al 75 | asm mov dx, 03d5h 76 | asm mov al, displayed 77 | asm out dx, al 78 | asm mov [si+016h], al 79 | 80 | asm mov dx, 03d4h /* set vertical sync position */ 81 | asm mov al, 07h 82 | asm out dx, al 83 | asm mov dx, 03d5h 84 | asm mov al, sync 85 | asm out dx, al 86 | asm mov [si+017h], al 87 | 88 | asm mov ax, 0040h /* get current value of mode-set register */ 89 | asm mov ds, ax 90 | asm mov si, 0065h 91 | asm mov al, [si] 92 | 93 | asm xor al, 08h /* enable video */ 94 | asm mov dx, 03d8h 95 | asm out dx, al 96 | asm mov [si], al 97 | 98 | asm pop si 99 | asm pop dx 100 | asm pop ax 101 | asm pop ds 102 | } 103 | 104 | void set_video_blink_toggle() 105 | { 106 | asm push ds 107 | asm push ax 108 | asm push dx 109 | asm push si 110 | 111 | asm mov ax, 0040h /* get current value of mode-set register */ 112 | asm mov ds, ax 113 | asm mov si, 0065h 114 | asm mov al, [si] 115 | 116 | asm xor al, 08h /* disable video */ 117 | asm mov dx, 03d8h 118 | asm out dx, al 119 | asm mov [si], al 120 | 121 | asm xor al, 08h /* enable video */ 122 | asm xor al, 020h /* toggle blink */ 123 | asm mov dx, 03d8h 124 | asm out dx, al 125 | asm mov [si], al 126 | 127 | asm pop si 128 | asm pop dx 129 | asm pop ax 130 | asm pop ds 131 | } 132 | 133 | void far * buff_alloc(unsigned long nbytes) 134 | { 135 | void far * buff = farmalloc(nbytes + 8); 136 | if (buff == NULL) 137 | { 138 | printf("Insufficient memory\n"); 139 | abort(); 140 | } 141 | 142 | assert(FP_OFF(buff) == 8); 143 | 144 | return MK_FP(FP_SEG(buff)+1, FP_OFF(buff)-8); 145 | } 146 | 147 | void buff_free(void far * buff) 148 | { 149 | farfree(MK_FP(FP_SEG(buff)-1, FP_OFF(buff)+8)); 150 | } 151 | 152 | void bitplanes_to_rgbi(unsigned char far * rgbi, 153 | unsigned char far * bp, int rows, int bytes_per_row) 154 | { 155 | int n = bytes_per_row/4; 156 | unsigned char p1, p2, p3, p4, t; 157 | int i, j, k; 158 | 159 | for (i = 0; i < rows; i++) 160 | { 161 | for (j = 0, k = 0; j < n; j++, k += 8) 162 | { 163 | p1 = bp[j]; 164 | p2 = bp[j + n]; 165 | p3 = bp[j + 2*n]; 166 | p4 = bp[j + 3*n]; 167 | 168 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 169 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 170 | rgbi[k + 7] = t + (t<<4); 171 | 172 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 173 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 174 | rgbi[k + 6] = t + (t<<4); 175 | 176 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 177 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 178 | rgbi[k + 5] = t + (t<<4); 179 | 180 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 181 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 182 | rgbi[k + 4] = t + (t<<4); 183 | 184 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 185 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 186 | rgbi[k + 3] = t + (t<<4); 187 | 188 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 189 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 190 | rgbi[k + 2] = t + (t<<4); 191 | 192 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 193 | p4 >>= 1; p3 >>= 1; p2 >>= 1; p1 >>= 1; 194 | rgbi[k + 1] = t + (t<<4); 195 | 196 | t = ((p4&1)<<3) + ((p3&1)<<2) + ((p2&1)<<1) + (p1&1); 197 | rgbi[k] = t + (t<<4); 198 | } 199 | 200 | bp += bytes_per_row; 201 | rgbi += 2*bytes_per_row; 202 | } 203 | } 204 | 205 | int main(void) 206 | { 207 | int i, j, k, l; 208 | int x, y, inc; 209 | unsigned char far * buff, far * bp, far * video; 210 | pcx_header_s header; 211 | FILE * file; 212 | double sintab[100]; 213 | double costab[100]; 214 | double theta = 0.0; 215 | 216 | randomize(); 217 | 218 | printf("WARNING: this demo requires CGA hardware. It may damage EGA/VGA machines\n"); 219 | printf("If you don't have a CGA or clone CGA card press CTRL-C or reset now!\n"); 220 | printf("The responsibility is yours. Press ENTER if you wish to continue.\n"); 221 | 222 | getchar(); 223 | 224 | printf("Computing sine/cosine table \n"); 225 | 226 | for (i = 0; i < 100; i++) 227 | { 228 | sintab[i] = sin(theta); 229 | costab[i] = cos(theta); 230 | theta += 0.0628318; 231 | } 232 | 233 | printf("Loading graphic\n"); 234 | 235 | bp = buff_alloc(33768); 236 | if (bp == NULL) 237 | { 238 | printf("Insufficient memory\n"); 239 | abort(); 240 | } 241 | 242 | buff = buff_alloc(65536); 243 | if (buff == NULL) 244 | { 245 | printf("Insufficient memory\n"); 246 | abort(); 247 | } 248 | 249 | file = fopen("pcretro.pcx", "rb"); 250 | if (file == NULL) 251 | { 252 | printf("Unable to open pcretro.pcx\n"); 253 | abort(); 254 | } 255 | 256 | pcx_header_read(&header, file); 257 | 258 | pcx_buffer_load(bp, file, header.bytes_per_line*header.nplanes, 259 | header.y1 - header.y0 + 1); 260 | fclose(file); 261 | 262 | printf("Converting to RGBI\n"); 263 | 264 | bitplanes_to_rgbi(buff, bp, 256, 128); 265 | buff_free(bp); 266 | 267 | video = MK_FP(0xb800, 0); 268 | 269 | set_video_mode(3); 270 | 271 | for (i = 0; i < 8000; i++) 272 | { 273 | video[2*i+1] = 0; 274 | video[2*i] = 221; 275 | } 276 | 277 | set_video_char_height(2); 278 | set_video_blink_toggle(); 279 | 280 | k = 0; 281 | l = 0; 282 | inc = 4; 283 | for (y = 0; y < 256;) 284 | { 285 | int scale = 768 + 512*sintab[l]; 286 | for (x = 0; x >= 0 && x < 256; x+=inc) 287 | { 288 | rotozoom(buff, x, y, (int) (scale*costab[k]), (int) (scale*sintab[k])); 289 | k++; 290 | if (k == 100) 291 | k = 0; 292 | if ((x & 63) == 60) 293 | { 294 | y++; 295 | l++; 296 | if (l == 100) 297 | l = 0; 298 | scale = 768 + 512*sintab[l]; 299 | } 300 | } 301 | if (x == 256) 302 | x = 252; 303 | if (x == -1) 304 | x = 0; 305 | inc = -inc; 306 | } 307 | 308 | getchar(); 309 | 310 | buff_free(buff); 311 | 312 | set_video_blink_toggle(); 313 | set_video_char_height(8); 314 | set_video_mode(3); 315 | 316 | return 0; 317 | } 318 |  -------------------------------------------------------------------------------- /cga160x200/ludicrous/vline.asm: -------------------------------------------------------------------------------- 1 | DOSSEG 2 | .MODEL small 3 | .CODE 4 | 5 | sp_save dw ? 6 | 7 | salc macro 8 | db 0d6h 9 | endm 10 | 11 | PUBLIC _cga_draw_vline 12 | _cga_draw_vline PROC 13 | ARG buff:DWORD, x:WORD, y0:WORD, y1:WORD, colour:BYTE 14 | ; draw a line from (x, y0) - (x, y1) including endpoints in the give colour (0-3) 15 | push bp 16 | mov bp, sp 17 | push di 18 | push si 19 | push ds 20 | 21 | les di, buff ; get buffer address in es:di 22 | 23 | mov ax, es ; mirror in ds 24 | mov ds, ax 25 | 26 | mov ax, [y0] ; get y0 coordinate 27 | inc ax 28 | shr ax, 1 ; set ax = (y0 + 1)/2 29 | cmc 30 | sbb bx, bx ; bx = -1 if y0 is odd, else bx = 0 31 | 32 | mov dx, [y1] ; get y1 coordinate 33 | shr dx, 1 ; y1/2 34 | cmc 35 | sbb cx, cx ; cx = -1 if y1 even, else cx = 0 36 | 37 | sub dx, ax ; dx = even line iterations 38 | inc dx 39 | 40 | mov si, dx ; si = odd line iterations 41 | add si, cx 42 | sub si, bx 43 | 44 | and bx, -80 ; bx = -80 if y0 is odd, else bx = 0 45 | 46 | shl ax, 1 ; set di to 80*(y0 + 1)/2 = first even line 47 | shl ax, 1 48 | shl ax, 1 49 | shl ax, 1 50 | add di, ax 51 | shl ax, 1 52 | shl ax, 1 53 | add di, ax 54 | 55 | add bx, di ; set bx to 8192 + 80*(y0/2) = first odd line 56 | add bh, 020h 57 | 58 | mov ax, [x] ; get x coordinate 59 | shr ax, 1 ; compute byte of pixel at coord x 60 | sbb cl, cl 61 | add di, ax ; add it to offset of first even line 62 | add bx, ax ; add it to offset of first odd line 63 | 64 | mov ah, [colour] ; get colour 65 | 66 | shr ah, 1 ; put solid colour in ah 67 | salc 68 | and al, 055h 69 | shr ah, 1 70 | sbb ah, ah 71 | and ah, 0aah 72 | add ah, al 73 | 74 | mov al, 0f0h ; colour (ah) and mask (dl) into correct bitfields 75 | xor al, cl 76 | and ah, al 77 | not al 78 | 79 | mov cx, dx ; get iterations 80 | 81 | mov dl, al 82 | 83 | cli ; free up sp 84 | mov cs:[sp_save], sp 85 | 86 | mov sp, 79 87 | 88 | shr cx, 1 89 | jnc vline_even_iters 90 | 91 | mov al, dl ; write pixel 92 | and al, [di] 93 | or al, ah 94 | stosb 95 | 96 | add di, sp ; jump to next odd line 97 | 98 | vline_even_iters: 99 | 100 | shr cx, 1 101 | jnc vline_even4 102 | 103 | mov al, dl ; write pixel 104 | and al, [di] 105 | or al, ah 106 | stosb 107 | 108 | add di, sp ; jump to next odd line 109 | 110 | mov al, dl ; write pixel 111 | and al, [di] 112 | or al, ah 113 | stosb 114 | 115 | add di, sp ; jump to next odd line 116 | 117 | vline_even4: 118 | 119 | shr cx, 1 120 | jnc vline_even8 121 | 122 | mov al, dl ; write pixel 123 | and al, [di] 124 | or al, ah 125 | stosb 126 | 127 | add di, sp ; jump to next odd line 128 | 129 | mov al, dl ; write pixel 130 | and al, [di] 131 | or al, ah 132 | stosb 133 | 134 | add di, sp ; jump to next odd line 135 | 136 | mov al, dl ; write pixel 137 | and al, [di] 138 | or al, ah 139 | stosb 140 | 141 | add di, sp ; jump to next odd line 142 | 143 | mov al, dl ; write pixel 144 | and al, [di] 145 | or al, ah 146 | stosb 147 | 148 | add di, sp ; jump to next odd line 149 | 150 | vline_even8: 151 | 152 | cmp cx, 0 ; check for zero iterations 153 | je vline_done_even 154 | 155 | vline_even: ; display pixels on even lines (unroll by 8) 156 | 157 | mov al, dl ; write pixel 158 | and al, [di] 159 | or al, ah 160 | stosb 161 | 162 | add di, sp ; jump to next even line 163 | 164 | mov al, dl ; write pixel 165 | and al, [di] 166 | or al, ah 167 | stosb 168 | 169 | add di, sp ; jump to next even line 170 | 171 | mov al, dl ; write pixel 172 | and al, [di] 173 | or al, ah 174 | stosb 175 | 176 | add di, sp ; jump to next even line 177 | 178 | mov al, dl ; write pixel 179 | and al, [di] 180 | or al, ah 181 | stosb 182 | 183 | add di, sp ; jump to next even line 184 | 185 | mov al, dl ; write pixel 186 | and al, [di] 187 | or al, ah 188 | stosb 189 | 190 | add di, sp ; jump to next even line 191 | 192 | mov al, dl ; write pixel 193 | and al, [di] 194 | or al, ah 195 | stosb 196 | 197 | add di, sp ; jump to next even line 198 | 199 | mov al, dl ; write pixel 200 | and al, [di] 201 | or al, ah 202 | stosb 203 | 204 | add di, sp ; jump to next even line 205 | 206 | mov al, dl ; write pixel 207 | and al, [di] 208 | or al, ah 209 | stosb 210 | 211 | add di, sp ; jump to next even line 212 | loop vline_even ; loop 213 | 214 | vline_done_even: 215 | 216 | mov di, bx ; load offset of first odd line 217 | 218 | mov cx, si ; get iterations 219 | 220 | shr cx, 1 ; unroll by 2 221 | jnc vline_odd_iters 222 | 223 | mov al, dl ; write pixel 224 | and al, [di] 225 | or al, ah 226 | stosb 227 | 228 | add di, sp ; jump to next odd line 229 | 230 | vline_odd_iters: 231 | 232 | shr cx, 1 ; unroll by 4 233 | jnc vline_odd4 234 | 235 | mov al, dl ; write pixel 236 | and al, [di] 237 | or al, ah 238 | stosb 239 | 240 | add di, sp ; jump to next odd line 241 | 242 | mov al, dl ; write pixel 243 | and al, [di] 244 | or al, ah 245 | stosb 246 | 247 | add di, sp ; jump to next odd line 248 | 249 | vline_odd4: 250 | 251 | shr cx, 1 252 | jnc vline_odd8 253 | 254 | mov al, dl ; write pixel 255 | and al, [di] 256 | or al, ah 257 | stosb 258 | 259 | add di, sp ; jump to next odd line 260 | 261 | mov al, dl ; write pixel 262 | and al, [di] 263 | or al, ah 264 | stosb 265 | 266 | add di, sp ; jump to next odd line 267 | 268 | mov al, dl ; write pixel 269 | and al, [di] 270 | or al, ah 271 | stosb 272 | 273 | add di, sp ; jump to next odd line 274 | 275 | mov al, dl ; write pixel 276 | and al, [di] 277 | or al, ah 278 | stosb 279 | 280 | add di, sp ; jump to next odd line 281 | 282 | vline_odd8: 283 | 284 | cmp cx, 0 ; check for zero iterations 285 | je vline_done_odd 286 | 287 | vline_odd: ; display pixels on odd lines (unroll by 8) 288 | 289 | mov al, dl ; write pixel 290 | and al, [di] 291 | or al, ah 292 | stosb 293 | 294 | add di, sp ; jump to next odd line 295 | 296 | mov al, dl ; write pixel 297 | and al, [di] 298 | or al, ah 299 | stosb 300 | 301 | add di, sp ; jump to next odd line 302 | 303 | mov al, dl ; write pixel 304 | and al, [di] 305 | or al, ah 306 | stosb 307 | 308 | add di, sp ; jump to next odd line 309 | 310 | mov al, dl ; write pixel 311 | and al, [di] 312 | or al, ah 313 | stosb 314 | 315 | add di, sp ; jump to next odd line 316 | 317 | mov al, dl ; write pixel 318 | and al, [di] 319 | or al, ah 320 | stosb 321 | 322 | add di, sp ; jump to next odd line 323 | 324 | mov al, dl ; write pixel 325 | and al, [di] 326 | or al, ah 327 | stosb 328 | 329 | add di, sp ; jump to next odd line 330 | 331 | mov al, dl ; write pixel 332 | and al, [di] 333 | or al, ah 334 | stosb 335 | 336 | add di, sp ; jump to next odd line 337 | 338 | mov al, dl ; write pixel 339 | and al, [di] 340 | or al, ah 341 | stosb 342 | 343 | add di, sp ; jump to next odd line 344 | loop vline_odd ; loop 345 | 346 | vline_done_odd: 347 | 348 | mov sp, cs:[sp_save] 349 | sti 350 | 351 | pop ds 352 | pop si 353 | pop di 354 | pop bp 355 | ret 356 | _cga_draw_vline ENDP 357 | 358 | END -------------------------------------------------------------------------------- /games/ENVOIGHT/SPRITE.C: -------------------------------------------------------------------------------- 1 | #include "page.h" 2 | #include "sprite.h" 3 | #include "pcx.h" 4 | 5 | /****************************************************************************** 6 | * 7 | * Direct sprite functions 8 | * 9 | ******************************************************************************/ 10 | 11 | void sprite_display_direct(unsigned char far * video, 12 | unsigned char * sprite, int xsize, int ysize) 13 | { 14 | int i, j, off = 0; 15 | 16 | xsize >>= 2; 17 | 18 | for (i = 0; i < ysize; i++) 19 | { 20 | for (j = 0; j < xsize; j++) 21 | video[off + j] = sprite[j]; 22 | 23 | off ^= 8192; 24 | if (i&1) 25 | off += 80; 26 | 27 | sprite += xsize; 28 | } 29 | } 30 | 31 | /****************************************************************************** 32 | * 33 | * Paged sprite functions 34 | * 35 | ******************************************************************************/ 36 | 37 | void sprite_composite(unsigned char far * page, sprite_t s) 38 | { 39 | int odd = 0; 40 | 41 | page += ((s->y >> 1)*PAGE_LINEB + (s->x >> 2) + PAGE_OFFSET); 42 | 43 | if (s->y & 1) 44 | { 45 | odd = 1; 46 | page += PAGE_ODDB; 47 | } 48 | 49 | switch (s->x & 3) 50 | { 51 | case 0: 52 | if (odd) 53 | (s->sprite0_odd)(page); 54 | else 55 | (s->sprite0_even)(page); 56 | break; 57 | case 1: 58 | if (odd) 59 | (s->sprite1_odd)(page); 60 | else 61 | (s->sprite1_even)(page); 62 | break; 63 | case 2: 64 | if (odd) 65 | (s->sprite2_odd)(page); 66 | else 67 | (s->sprite2_even)(page); 68 | break; 69 | case 3: 70 | if (odd) 71 | (s->sprite3_odd)(page); 72 | else 73 | (s->sprite3_even)(page); 74 | break; 75 | } 76 | } 77 | 78 | void sprite_flip(unsigned char far * video, 79 | unsigned char far * page, sprite_t s) 80 | { 81 | int x0 = min(s->x, s->oldx); 82 | int y0 = min(s->y, s->oldy); 83 | int x1 = max(s->x + s->xsize, s->oldx + s->xsize); 84 | int y1 = max(s->y + s->ysize, s->oldy + s->ysize); 85 | 86 | if (x0 < 0) x0 = 0; 87 | if (y0 < 0) y0 = 0; 88 | 89 | if (x1 > 320) x1 = 320; 90 | if (y1 > 200) y1 = 200; 91 | 92 | x0 >>= 2; 93 | x1 >>= 2; 94 | 95 | if (x1 > x0 && y1 > y0) 96 | { 97 | video += ((y0 >> 1)*80 + x0); 98 | page += (((PAGE_MARGIN + y0) >> 1)*PAGE_LINEB + 99 | (PAGE_MARGIN >> 2) + x0); 100 | 101 | if (y0 & 1) 102 | { 103 | video += 8192; 104 | page += PAGE_ODDB; 105 | } 106 | 107 | y1 -= y0; 108 | x1 -= x0; 109 | 110 | asm push ds 111 | 112 | asm mov bx, y1 113 | asm mov dx, x1 114 | 115 | asm les di, video 116 | asm lds si, page 117 | 118 | asm mov al, y0 119 | asm and al, 1 120 | 121 | next_line: 122 | 123 | asm mov cx, dx 124 | asm shr cx, 1 125 | 126 | asm repz 127 | asm movsw 128 | 129 | asm test dx, 1 130 | asm jp even_len 131 | 132 | asm movsb 133 | 134 | even_len: 135 | 136 | asm sub si, dx 137 | asm sub di, dx 138 | 139 | asm xor al, 1 140 | asm jnz even_line 141 | 142 | asm sub di, (8192-80) 143 | asm sub si, (PAGE_ODDB-PAGE_LINEB) 144 | 145 | asm jmp next_iter 146 | 147 | even_line: 148 | 149 | asm add di, 8192 150 | asm add si, PAGE_ODDB 151 | 152 | next_iter: 153 | 154 | asm dec bl 155 | asm jnz next_line 156 | 157 | asm pop ds 158 | } 159 | 160 | s->oldx = s->x; 161 | s->oldy = s->y; 162 | } 163 | 164 | void sprite_save_bg(sprite_t s, unsigned char far * page) 165 | { 166 | int x0 = s->x; 167 | int y0 = s->y; 168 | int x1 = s->x + s->xsize; 169 | int y1 = s->y + s->ysize; 170 | unsigned char far * buff = s->buff; 171 | 172 | if (x0 < 0) x0 = 0; 173 | if (y0 < 0) y0 = 0; 174 | 175 | if (x1 > 320) x1 = 320; 176 | if (y1 > 200) y1 = 200; 177 | 178 | if (x1 > x0 && y1 > y0) 179 | { 180 | x0 >>= 2; 181 | x1 >>= 2; 182 | 183 | page += (((PAGE_MARGIN + y0) >> 1)*PAGE_LINEB + 184 | (PAGE_MARGIN >> 2) + x0); 185 | 186 | if (y0 & 1) 187 | page += PAGE_ODDB; 188 | 189 | y1 -= y0; 190 | x1 -= x0; 191 | 192 | asm mov bx, y1 193 | asm mov dx, x1 194 | 195 | asm push ds 196 | 197 | asm lds si, page 198 | asm les di, buff 199 | 200 | asm mov al, y0 201 | asm and al, 1 202 | 203 | next_line: 204 | 205 | asm mov cx, dx 206 | asm shr cx, 1 207 | 208 | asm repz 209 | asm movsw 210 | 211 | asm test dx, 1 212 | asm jp even_len 213 | 214 | asm movsb 215 | 216 | even_len: 217 | 218 | asm sub si, dx 219 | 220 | asm xor al, 1 221 | asm jnz even_line 222 | 223 | asm sub si, (PAGE_ODDB-PAGE_LINEB) 224 | 225 | asm jmp next_iter 226 | 227 | even_line: 228 | 229 | asm add si, PAGE_ODDB 230 | 231 | next_iter: 232 | 233 | asm dec bl 234 | asm jnz next_line 235 | 236 | asm pop ds 237 | } 238 | } 239 | 240 | void sprite_restore_bg(unsigned char far * page, sprite_t s) 241 | { 242 | int x0 = s->x; 243 | int y0 = s->y; 244 | int x1 = s->x + s->xsize; 245 | int y1 = s->y + s->ysize; 246 | unsigned char far * buff = s->buff; 247 | 248 | if (x0 < 0) x0 = 0; 249 | if (y0 < 0) y0 = 0; 250 | 251 | if (x1 > 320) x1 = 320; 252 | if (y1 > 200) y1 = 200; 253 | 254 | if (x1 > x0 && y1 > y0) 255 | { 256 | x0 >>= 2; 257 | x1 >>= 2; 258 | 259 | page += (((PAGE_MARGIN + y0) >> 1)*PAGE_LINEB + 260 | (PAGE_MARGIN >> 2) + x0); 261 | 262 | if (y0 & 1) 263 | page += PAGE_ODDB; 264 | 265 | y1 -= y0; 266 | x1 -= x0; 267 | 268 | asm mov bx, y1 269 | asm mov dx, x1 270 | 271 | asm push ds 272 | 273 | asm les di, page 274 | asm lds si, buff 275 | 276 | asm mov al, y0 277 | asm and al, 1 278 | 279 | next_line: 280 | 281 | asm mov cx, dx 282 | asm shr cx, 1 283 | 284 | asm repz 285 | asm movsw 286 | 287 | asm test dx, 1 288 | asm jp even_len 289 | 290 | asm movsb 291 | 292 | even_len: 293 | 294 | asm sub di, dx 295 | 296 | asm xor al, 1 297 | asm jnz even_line 298 | 299 | asm sub di, (PAGE_ODDB-PAGE_LINEB) 300 | 301 | asm jmp next_iter 302 | 303 | even_line: 304 | 305 | asm add di, PAGE_ODDB 306 | 307 | next_iter: 308 | 309 | asm dec bl 310 | asm jnz next_line 311 | 312 | asm pop ds 313 | } 314 | } 315 | 316 | void sprite_wipe(unsigned char far * page, sprite_t s) 317 | { 318 | int x1 = ((s->oldx + s->xsize) >> 2); 319 | int y1 = s->oldy + s->ysize; 320 | int x0 = s->oldx < 0 ? 0 : (s->oldx >> 2); 321 | int y0 = s->oldy < 0 ? 0 : s->oldy; 322 | int i, j; 323 | 324 | if (x1 < 0) x1 = 0; 325 | if (y1 < 0) y1 = 0; 326 | 327 | if (x1 > 80) x1 = 80; 328 | if (y1 > 200) y1 = 200; 329 | 330 | if (x1 > x0 && y1 > y0) 331 | { 332 | page += (((PAGE_MARGIN + y0) >> 1)*PAGE_LINEB + 333 | (PAGE_MARGIN >> 2) + x0); 334 | 335 | if (y0 & 1) 336 | page += PAGE_ODDB; 337 | 338 | y1 -= y0; 339 | x1 -= x0; 340 | 341 | asm mov bx, y1 342 | asm mov dx, x1 343 | 344 | asm les di, page 345 | 346 | asm mov bh, y0 347 | asm and bh, 1 348 | 349 | asm xor ax, ax 350 | 351 | next_line: 352 | 353 | asm mov cx, dx 354 | asm shr cx, 1 355 | 356 | asm repz 357 | asm stosw 358 | 359 | asm test dx, 1 360 | asm jp even_len 361 | 362 | asm stosb 363 | 364 | even_len: 365 | 366 | asm sub di, dx 367 | 368 | asm xor bh, 1 369 | asm jnz even_line 370 | 371 | asm sub di, (PAGE_ODDB-PAGE_LINEB) 372 | 373 | asm jmp next_iter 374 | 375 | even_line: 376 | 377 | asm add di, PAGE_ODDB 378 | 379 | next_iter: 380 | 381 | asm dec bl 382 | asm jnz next_line 383 | } 384 | } 385 | 386 | void sprite_move(sprite_t s, int x, int y) 387 | { 388 | s->x += x; 389 | s->y += y; 390 | 391 | if (s->x < 0) s->x = 0; 392 | if (s->x + s->xsize > 320) 393 | s->x = 320 - s->xsize; 394 | 395 | if (s->y < -SPRITE_WIDTH) s->y = -SPRITE_WIDTH; 396 | if (s->y + s->ysize > 200 + SPRITE_WIDTH) 397 | s->y = 200 + SPRITE_WIDTH - s->ysize; 398 | } 399 | -------------------------------------------------------------------------------- /games/ENVOIGHT/ENVOIGHT.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "graphics.h" 8 | #include "sprite.h" 9 | 10 | extern void sprite_init_ship(sprite_t s, int x, int y); 11 | extern void sprite_init_enemy1(sprite_t s, int x, int y); 12 | extern void sprite_init_enemy2(sprite_t s, int x, int y); 13 | extern void sprite_init_enemy3(sprite_t s, int x, int y); 14 | extern void sprite_init_ammo(sprite_t s, int x, int y); 15 | 16 | extern void sprite_clear_ship(sprite_t s); 17 | extern void sprite_clear_enemy1(sprite_t s); 18 | extern void sprite_clear_enemy2(sprite_t s); 19 | extern void sprite_clear_enemy3(sprite_t s); 20 | extern void sprite_clear_ammo(sprite_t s); 21 | 22 | extern void cga_retrace(); 23 | 24 | typedef struct 25 | { 26 | unsigned char far * page; 27 | sprite_s * sprites; 28 | int num_sprites; 29 | } raster_ctx_s; 30 | 31 | typedef raster_ctx_s raster_ctx_t[1]; 32 | 33 | int visible[9]; 34 | int ammo_used[5]; 35 | int ammo_unused[5]; 36 | int num_used; 37 | int frame; 38 | int tone; 39 | int noise; 40 | 41 | unsigned char keystate[0x60]; 42 | unsigned char extstate[0x60]; 43 | 44 | void interrupt (*old_kb_int)(); 45 | 46 | void interrupt new_kb_int() 47 | { 48 | static unsigned char last = 0; 49 | unsigned char a, raw = inp(0x60); /* read raw code from k/b */ 50 | int scancode = raw & 0x7f; 51 | 52 | if (last == 0xe0) /* ignore second byte of extended scancode */ 53 | { 54 | if (scancode <0x60) 55 | extstate[scancode] = !(raw & 0x80); 56 | last = 0; 57 | } else if (last >= 0xe1 && last <= 0xe2) 58 | last = 0; /* ignore these */ 59 | else if (raw >= 0xe0 && raw <= 0xe2) 60 | last = raw; /* first byte of extended scancode */ 61 | else if (scancode < 0x60) 62 | keystate[scancode] = !(raw & 0x80); 63 | 64 | /* Signal end of input */ 65 | a = inp(0x61) | 0x80; 66 | outp(0x61, a); 67 | a ^= 0x80; 68 | outp(0x61, a); 69 | 70 | /* End interrupt */ 71 | outp(0x20, 0x20); 72 | } 73 | 74 | void hook_kb_int() 75 | { 76 | unsigned char i; 77 | 78 | for (i = 0; i < 0x60; i++) 79 | keystate[i] = 0x0; 80 | 81 | old_kb_int = getvect(0x09); 82 | setvect(0x09, new_kb_int); 83 | } 84 | 85 | void unhook_kb_int() 86 | { 87 | if (old_kb_int != NULL) 88 | { 89 | setvect(0x09, old_kb_int); 90 | old_kb_int = NULL; 91 | } 92 | } 93 | 94 | void set_freq(int n) 95 | { 96 | int count = n == 0 ? 0 : 1.19318e6 / n; 97 | char b; 98 | 99 | if (count == 0) 100 | { 101 | b = inp(0x61) & 0xfc; 102 | outp(0x61, b); 103 | } else 104 | { 105 | b = inp(0x61) | 0x03; 106 | outp(0x61, b); 107 | 108 | outp(0x43, 0xb6); 109 | 110 | b = (char) count; 111 | outp(0x42, b); 112 | 113 | b = (char) (count >> 8); 114 | outp(0x42, b); 115 | } 116 | } 117 | 118 | void interrupt (*old_int8)(); 119 | 120 | void interrupt new_int8() 121 | { 122 | if (tone != 0) 123 | { 124 | set_freq(2000); 125 | tone--; 126 | } else if (noise != 0) 127 | { 128 | set_freq(random(5000) + 5000); 129 | noise--; 130 | } else 131 | set_freq(0); 132 | 133 | /* End interrupt */ 134 | outp(0x20, 0x20); 135 | } 136 | 137 | void hook_int8() 138 | { 139 | unsigned char i; 140 | 141 | outp(0x43, 0x34); 142 | outp(0x40, 174); 143 | outp(0x40, 77); 144 | 145 | old_int8 = getvect(0x08); 146 | setvect(0x8, new_int8); 147 | } 148 | 149 | void unhook_int8() 150 | { 151 | if (old_int8 != NULL) 152 | { 153 | setvect(0x08, old_int8); 154 | old_int8 = NULL; 155 | } 156 | } 157 | 158 | sprite_s * raster_ctx_init(raster_ctx_t screen, int max_sprites) 159 | { 160 | unsigned char far * video = MK_FP(0xb800, 0x0000); 161 | 162 | screen->page = farcalloc(2, SPRITE_PAGEB); 163 | screen->sprites = malloc(sizeof(sprite_s)*max_sprites); 164 | screen->num_sprites = 0; 165 | 166 | page_copy_bg(screen->page, video); 167 | 168 | return screen->sprites; 169 | } 170 | 171 | void raster_ctx_clear(raster_ctx_t screen) 172 | { 173 | farfree(screen->page); 174 | free(screen->sprites); 175 | } 176 | 177 | void screen_set_num_sprites(raster_ctx_t screen, int num) 178 | { 179 | screen->num_sprites = num; 180 | } 181 | 182 | void screen_draw_sprites(raster_ctx_t screen) 183 | { 184 | int i; 185 | 186 | for (i = 0; i < screen->num_sprites; i++) 187 | sprite_save_bg(screen->sprites + i, screen->page); 188 | 189 | for (i = 0; i < screen->num_sprites; i++) 190 | { 191 | if (visible[i]) 192 | sprite_composite(screen->page, screen->sprites + i); 193 | } 194 | } 195 | 196 | void screen_flip(raster_ctx_t screen) 197 | { 198 | unsigned char far * video = MK_FP(0xb800, 0x0000); 199 | int i; 200 | 201 | for (i = 0; i < screen->num_sprites; i++) 202 | sprite_flip(video, screen->page, screen->sprites + i); 203 | 204 | for (i = 0; i < screen->num_sprites; i++) 205 | sprite_restore_bg(screen->page, screen->sprites + i); 206 | } 207 | 208 | void collision_detect(sprite_s * sprites) 209 | { 210 | int enemy, missile; 211 | 212 | for (enemy = 1; enemy <= 3; enemy++) 213 | { 214 | for (missile = 4; missile <= 8; missile++) 215 | { 216 | sprite_s * e = sprites + enemy; 217 | sprite_s * m = sprites + missile; 218 | 219 | if (visible[enemy] && visible[missile] && 220 | (e->y >= m->y) && 221 | (m->x >= e->x && m->x + m->xsize <= e->x + e->xsize)) 222 | { 223 | visible[enemy] = 0; 224 | visible[missile] = 0; 225 | noise = 20; 226 | } 227 | } 228 | } 229 | } 230 | 231 | void runloop(raster_ctx_t screen) 232 | { 233 | int running = 1, xoff, yoff, c, i, j, k; 234 | 235 | sprite_s * sprites = screen->sprites; 236 | 237 | while (running) 238 | { 239 | screen_draw_sprites(screen); 240 | 241 | screen_flip(screen); 242 | 243 | xoff = 0; 244 | yoff = 0; 245 | 246 | if (keystate[0x4d]) /* right arrow */ 247 | xoff = 2; /* right arrow */ 248 | else if (keystate[0x4b]) /* left arrow */ 249 | xoff = -2; 250 | else if (keystate[0x1d]) /* left ctrl */ 251 | { 252 | if (((frame & 3) == 0) && num_used != 5) 253 | { 254 | sprite_s * s; 255 | int x = (sprites + 0)->x + 15; 256 | int y = (sprites + 0)->y - 2; 257 | int num = ammo_unused[4 - num_used]; 258 | ammo_used[num_used] = num; 259 | s = sprites + num; 260 | sprite_move(s, x - s->x, y - s->y); 261 | num_used += 1; 262 | tone = 6; 263 | visible[num] = 1; 264 | } 265 | } else if (keystate[0x01]) /* Esc */ 266 | running = 0; 267 | 268 | collision_detect(sprites); 269 | 270 | sprite_move(sprites + 0, xoff, yoff); 271 | for (i = 1; i <= 3; i++) 272 | { 273 | sprite_move(sprites + i, 0, 1); 274 | if ((sprites + i)->y >= 200) 275 | { 276 | visible[i] = 1; 277 | (sprites + i)->x = random(304); 278 | (sprites + i)->y = -20; 279 | } 280 | } 281 | 282 | j = 0; 283 | k = 5 - num_used; 284 | for (i = 0; i < num_used; i++) 285 | { 286 | sprite_s * s = sprites + ammo_used[i]; 287 | if (s->y < -1) 288 | { 289 | visible[ammo_used[i]] = 0; 290 | ammo_unused[k] = ammo_used[i]; 291 | k++; 292 | } else 293 | { 294 | ammo_used[j] = ammo_used[i]; 295 | j++; 296 | } 297 | } 298 | num_used = j; 299 | 300 | for (i = 0; i < num_used; i++) 301 | { 302 | sprite_s * s = sprites + ammo_used[i]; 303 | sprite_move(s, 0, -3); 304 | } 305 | 306 | frame++; 307 | } 308 | } 309 | 310 | int main(void) 311 | { 312 | int i, j, c; 313 | raster_ctx_t screen; 314 | sprite_s * sprites; 315 | 316 | set_video_mode(4); 317 | outp(0x3d8, 10); 318 | outp(0x3d9, 25); 319 | 320 | cga_display_pcx("backg.pcx"); 321 | 322 | sprites = raster_ctx_init(screen, 16); 323 | 324 | sprite_init_ship(sprites + 0, 148, 164); 325 | sprite_init_enemy1(sprites + 1, 30, 64); 326 | sprite_init_enemy2(sprites + 2, 70, 124); 327 | sprite_init_enemy3(sprites + 3, 133, 170); 328 | 329 | for (i = 0; i < 5; i++) 330 | { 331 | sprite_init_ammo(sprites + 4 + i, 160, 200); 332 | ammo_unused[i] = 4 + i; 333 | } 334 | num_used = 0; 335 | 336 | screen_set_num_sprites(screen, 9); 337 | 338 | for (i = 0; i < 9; i++) 339 | visible[i] = 1; 340 | 341 | frame = 0; 342 | 343 | set_freq(1000); 344 | delay(500); 345 | set_freq(0); 346 | 347 | tone = 0; 348 | noise = 0; 349 | 350 | hook_int8(); 351 | hook_kb_int(); 352 | runloop(screen); 353 | unhook_kb_int(); 354 | unhook_int8(); 355 | 356 | sprite_clear_ship(sprites + 0); 357 | sprite_clear_enemy1(sprites + 1); 358 | sprite_clear_enemy2(sprites + 2); 359 | sprite_clear_enemy3(sprites + 3); 360 | 361 | for (i = 0; i < 5; i++) 362 | sprite_clear_ammo(sprites + 4 + i); 363 | 364 | raster_ctx_clear(screen); 365 | 366 | set_video_mode(3); 367 | 368 | return 0; 369 | } 370 |  --------------------------------------------------------------------------------