From: sparky4 Date: Wed, 2 Jul 2014 03:35:16 +0000 (-0500) Subject: new file: 16/modex16/TEST.EXE X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=3686f3bf9c15445091aef92692ccf3486389efbc;p=16.git new file: 16/modex16/TEST.EXE new file: 16/modex16/TEST.SMP new file: 16/modex16/W new file: 16/modex16/makefile new file: 16/modex16/modex16.c new file: 16/modex16/modex16.h new file: 16/modex16/modex16.obj new file: 16/modex16/palette.c new file: 16/modex16/palette.h new file: 16/modex16/test.c new file: 16/modex16/test.obj new file: 16/modex16/types.h --- diff --git a/16/modex16/TEST.EXE b/16/modex16/TEST.EXE new file mode 100644 index 00000000..bfcdf91a Binary files /dev/null and b/16/modex16/TEST.EXE differ diff --git a/16/modex16/TEST.SMP b/16/modex16/TEST.SMP new file mode 100644 index 00000000..65f59bb6 Binary files /dev/null and b/16/modex16/TEST.SMP differ diff --git a/16/modex16/W b/16/modex16/W new file mode 100644 index 00000000..4b697d8e --- /dev/null +++ b/16/modex16/W @@ -0,0 +1 @@ +500 frames in 8.351648 seconds for 59.868421 fps diff --git a/16/modex16/makefile b/16/modex16/makefile new file mode 100644 index 00000000..f4f4c19d --- /dev/null +++ b/16/modex16/makefile @@ -0,0 +1,10 @@ +all: test.exe + +test.exe: test.obj modex16.obj + wcl -0 -d2 test.obj modex16.obj + +test.obj: test.c modex16.h + wcl -0 -d2 -c test.c + +modex16.obj: modex16.h modex16.c + wcl -0 -d2 -c modex16.c diff --git a/16/modex16/modex16.c b/16/modex16/modex16.c new file mode 100644 index 00000000..47a59687 --- /dev/null +++ b/16/modex16/modex16.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include "modex16.h" + + +byte far* VGA=(byte far*) 0xA0000000; /* this points to video memory. */ + +static void +vgaSetMode(byte mode) +{ + union REGS regs; + + regs.h.ah = SET_MODE; + regs.h.al = mode; + int86(VIDEO_INT, ®s, ®s); +} + + +/* -========================= Entry Points ==========================- */ +void +modexEnter() { + word i; + dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ + word CRTParms[] = { + 0x0d06, /* vertical total */ + 0x3e07, /* overflow (bit 8 of vertical counts) */ + 0x4109, /* cell height (2 to double-scan */ + 0xea10, /* v sync start */ + 0xac11, /* v sync end and protect cr0-cr7 */ + 0xdf12, /* vertical displayed */ + 0x0014, /* turn off dword mode */ + 0xe715, /* v blank start */ + 0x0616, /* v blank end */ + 0xe317 /* turn on byte mode */ + }; + int CRTParmCount = sizeof(CRTParms) / sizeof(CRTParms[0]); + + /* TODO save current video mode and palette */ + vgaSetMode(VGA_256_COLOR_MODE); + + /* disable chain4 mode */ + outpw(SC_INDEX, 0x0604); + + /* synchronous reset while setting Misc Output */ + outpw(SC_INDEX, 0x0100); + + /* select 25 MHz dot clock & 60 Hz scanning rate */ + outp(MISC_OUTPUT, 0xe3); + + /* undo reset (restart sequencer) */ + outpw(SC_INDEX, 0x0300); + + /* reprogram the CRT controller */ + outp(CRTC_INDEX, 0x11); /* VSync End reg contains register write prot */ + outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */ + + /* send the CRTParms */ + for(i=0; i +#include "types.h" + +/* -========================== Types & Macros ==========================- */ +#define PAGE_OFFSET(x,y) ((y<<6)+(y<<4)+(x>>2)) +#define PLANE(x) (1<< (x&3)) +typedef byte far* page_t; +#define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02) + +/* -============================ Functions =============================- */ +void modexEnter(); +void modexLeave(); +void modexShowPage(page_t page); +void modexPanPage(page_t *page, int dx, int dy); +void modexSelectPlane(byte plane); +void modexClearRegion(page_t page, int x, int y, int w, int h, byte color); + +/* -======================= Constants & Vars ==========================- */ +extern byte far* VGA; /* The VGA Memory */ +#define VIDEO_INT 0x10 +#define SET_MODE 0x00 +#define VGA_256_COLOR_MODE 0x13 +#define TEXT_MODE 0x03 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 +#define PAGE_SIZE (word)(SCREEN_WIDTH/4 * SCREEN_HEIGHT) + +#define SC_INDEX 0x03c4 +#define SC_DATA 0x03c5 +#define CRTC_INDEX 0x03d4 +#define CRTC_DATA 0x03d5 +#define MISC_OUTPUT 0x03c2 +#define HIGH_ADDRESS 0x0C +#define LOW_ADDRESS 0x0D +#define VRETRACE 0x08 +#define INPUT_STATUS_1 0x03da +#define DISPLAY_ENABLE 0x01 +#define MAP_MASK 0x02 +#endif diff --git a/16/modex16/modex16.obj b/16/modex16/modex16.obj new file mode 100644 index 00000000..24d9932f Binary files /dev/null and b/16/modex16/modex16.obj differ diff --git a/16/modex16/palette.c b/16/modex16/palette.c new file mode 100644 index 00000000..7a7e7342 --- /dev/null +++ b/16/modex16/palette.c @@ -0,0 +1,160 @@ +/* + * File: PALETTE.C + * Purpose: This file contains routines for manipulating the VGA palette. + */ +#include +#include +#include +#include "palette.h" + +static void fadePalette(byte fade, byte start, word iter, byte *palette); +static byte tmppal[PAL_SIZE]; + +/* fade and flash */ +void +fadeOn(word fade, byte *palette) { + fadePalette(-fade, 64, 64/fade+1, palette); +} + + +void +fadeOff(word fade, byte *palette) { + fadePalette(fade, 0, 64/fade+1, palette); +} + + +void +flashOn(word fade, byte *palette) { + fadePalette(fade, -64, 64/fade+1, palette); +} + + +void +flashOff(word fade, byte *palette) { + fadePalette(-fade, 0, 64/fade+1, palette); +} + + +static void +fadePalette(byte fade, byte start, word iter, byte *palette) { + word i; + byte dim = start; + + /* handle the case where we just update */ + if(iter == 0) { + palUpdate(palette); + return; + } + + while(iter > 0) { /* FadeLoop */ + for(i=0; i 127) { + tmppal[i] = 0; + } else if(tmppal[i] > 63) { + tmppal[i] = 63; + } + } + palUpdate(tmppal); + iter--; + dim += fade; + } +} + + +/* save and load */ +void +palSave(byte *palette) { + int i; + + outp(PEL_READ_REG, 0); /* start at palette entry 0 */ + for(i=0; i + +word far* clock= (word far*) 0x046C; /* 18.2hz clock */ + +void main() { + int plane; + int x, y, i; + word start, end; + page_t page, page2; + word far* ptr; + float elapsed; + + modexEnter(); + + page= VGA; + page2=VGA+PAGE_SIZE; + + /* fill the page with one color */ + modexShowPage(page2); + modexClearRegion(page, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 42); + modexClearRegion(page, 17, 12, 30, 30, 19); + modexShowPage(page); + + start = *clock; + for(i=0; i<500; i++) { + modexShowPage(page); + page+=SCREEN_WIDTH/4; + } + end = *clock; + + modexLeave(); + elapsed = (end-start)/18.2; + printf("500 frames in %f seconds for %f fps\n", elapsed, 500.0/elapsed); +} diff --git a/16/modex16/test.obj b/16/modex16/test.obj new file mode 100644 index 00000000..c075452e Binary files /dev/null and b/16/modex16/test.obj differ diff --git a/16/modex16/types.h b/16/modex16/types.h new file mode 100644 index 00000000..43a42c55 --- /dev/null +++ b/16/modex16/types.h @@ -0,0 +1,10 @@ +/* + * Just some handy typedefs that make it easier to think about the low + * level code + */ + +typedef unsigned char byte; +typedef unsigned short word; +typedef unsigned long dword; +typedef signed short sword; +typedef signed long sdword;