From: sparky4 Date: Tue, 9 Dec 2014 17:52:47 +0000 (-0600) Subject: modified: scroll.exe X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=f1c9c170d9fc5f657ef887201410021017fd9a46;p=16.git modified: scroll.exe modified: src/lib/lib_head.h new file: src/lib/xms.c new file: src/lib/xms.h modified: src/scroll.c --- diff --git a/SCROLL.SMP b/SCROLL.SMP deleted file mode 100644 index 398f5786..00000000 Binary files a/SCROLL.SMP and /dev/null differ diff --git a/scroll.exe b/scroll.exe index 96f972a0..e240c28d 100644 Binary files a/scroll.exe and b/scroll.exe differ diff --git a/src/lib/lib_head.h b/src/lib/lib_head.h index 86b55b89..19b59f18 100644 --- a/src/lib/lib_head.h +++ b/src/lib/lib_head.h @@ -8,6 +8,7 @@ /* Control codes for all keys on the keyboard */ //here temperarly +/* #define KEY_A (0x1E) #define KEY_B (0x30) #define KEY_C (0x2E) @@ -44,17 +45,17 @@ #define KEY_8 (0x09) #define KEY_9 (0x0A) #define KEY_0 (0x0B) -#define KEY_DASH (0x0C) /* -_ */ -#define KEY_EQUAL (0x0D) /* =+ */ -#define KEY_LBRACKET (0x1A) /* [{ */ -#define KEY_RBRACKET (0x1B) /* ]} */ -#define KEY_SEMICOLON (0x27) /* ;: */ -#define KEY_RQUOTE (0x28) /* '" */ -#define KEY_LQUOTE (0x29) /* `~ */ -#define KEY_PERIOD (0x33) /* .> */ -#define KEY_COMMA (0x34) /* ,< */ -#define KEY_SLASH (0x35) /* /? */ -#define KEY_BACKSLASH (0x2B) /* \| */ +#define KEY_DASH (0x0C) // -_ +#define KEY_EQUAL (0x0D) // =+ +#define KEY_LBRACKET (0x1A) // [{ +#define KEY_RBRACKET (0x1B) // ]} +#define KEY_SEMICOLON (0x27) // ;: +#define KEY_RQUOTE (0x28) // '" +#define KEY_LQUOTE (0x29) // `~ +#define KEY_PERIOD (0x33) // .> +#define KEY_COMMA (0x34) // ,< +#define KEY_SLASH (0x35) // /? +#define KEY_BACKSLASH (0x2B) // \| #define KEY_F1 (0x3B) #define KEY_F2 (0x3C) #define KEY_F3 (0x3D) @@ -95,7 +96,7 @@ #define KEY_LWIN (0x73) #define KEY_RWIN (0x74) #define KEY_MENU (0x75) - +*/ //typedef unsigned char byte; //typedef unsigned int word; diff --git a/src/lib/xms.c b/src/lib/xms.c new file mode 100644 index 00000000..fb428a54 --- /dev/null +++ b/src/lib/xms.c @@ -0,0 +1,185 @@ +/* This file implements rudimentary XMS memory handling. + * Documentation on the XMS API was found on http://www.qzx.com/pc-gpe/xms30.txt + */ + +#include "src\lib\xms.h" + +/* Set up the XMS driver, returns 0 on success and non-zero on failure */ +static int initxms(void) +{ + char XMSStatus = 0; + + if ( XMSControl == 0 ) + { + __asm { + ; Is an XMS driver installed? + mov ax,4300h + int 2Fh + mov [XMSStatus], al + } + + if ( XMSStatus == 0x80 ) + { + __asm { + ; Get the address of the driver control function + mov ax,4310h + int 2Fh + mov word ptr [XMSControl] ,bx + mov word ptr [XMSControl+2],es + } + } + } + + return ( XMSControl == 0 ); +} + +/* Allocate a slab of memory from XMS */ +void huge * xmsmalloc(long unsigned int size) +{ + unsigned int kB; + unsigned int XMSStatus = 0; + unsigned int XMSHandle = 0; + void huge * XMSPointer = NULL; + int n; + + /* If we can not initialize XMS, the allocation fails */ + if ( initxms() ) + return NULL; + + /* It is not possible to allocate more kilobytes than a 16-bit register can hold :-) */ + if ( size / 1024 > UINT_MAX ) + return NULL; + + /* Get the next free entry in the handle <-> pointer mapping */ + for ( n = 0; n < MAX_XMS_ALLOCATIONS; n++ ) + { + if ( allocMapXMS[n].XMSPointer == NULL ) + break; + } + + if ( n == MAX_XMS_ALLOCATIONS ) + return NULL; + + kB = size / 1024 + (size % 1024 > 0); + + __asm { + ; Allocate [kB] kilobytes of XMS memory + mov ah, 09h + mov dx, [kB] + call [XMSControl] + mov [XMSStatus], ax + mov [XMSHandle], dx + } + + /* Check if XMS allocation failed */ + if ( XMSStatus == 0) + return NULL; + + __asm { + ; Convert XMS handle to normal pointer + mov ah, 0Ch + mov dx, [XMSHandle] + call [XMSControl] + mov [XMSStatus], ax + + mov word ptr [XMSPointer], bx + mov word ptr [XMSPointer+2],dx + } + + if ( XMSStatus == 0 ) + { + /* Lock failed, deallocate the handle */ + __asm { + ; Free XMS handle + mov ah, 0Ah + mov dx, [XMSHandle] + call [XMSControl] + + ; Return value is not really interesting + ; mov [XMSStatus], ax + } + return NULL; + } + + /* Create an entry in the handle <-> pointer mapping */ + allocMapXMS[n].XMSHandle = XMSHandle; + allocMapXMS[n].XMSPointer = XMSPointer; + + return XMSPointer; +} + +/* Free a pointer allocated with xmsalloc */ +void xmsfree(void huge * XMSPointer) +{ + int n; + + if ( XMSPointer == NULL ) + return; + + if ( initxms() ) + return; + + for ( n = 0; n < MAX_XMS_ALLOCATIONS; n++ ) + { + if ( allocMapXMS[n].XMSPointer == XMSPointer ) + { + int XMSHandle = allocMapXMS[n].XMSHandle; + + __asm { + ; Unlock handle so we can free the memory block + mov ah, 0Dh + mov dx, [XMSHandle] + call [XMSControl] + + ; Free XMS memory + mov ah, 0Ah + mov dx, [XMSHandle] + call [XMSControl] + + ; Return value ignored + } + + /* Clear handle <-> pointer map entry so it can be reused */ + allocMapXMS[n].XMSHandle = 0; + allocMapXMS[n].XMSPointer = NULL; + + return; + } + } +} + +/* Write a memory report for debugging purposes */ +void xmsreport(FILE * stream) +{ + int XMSVersionNumber = 0; + unsigned int XMSLargestBlock = 0; + unsigned int XMSTotal = 0; + + if ( initxms() ) + { + puts("Could not initialize XMS Driver!"); + return; + } + + __asm { + ; Get the driver version number + mov ah,00h + call [XMSControl] ; Get XMS Version Number + mov [XMSVersionNumber], ax + + ; Get the amount of free XMS memory + mov ah, 08h + call [XMSControl] + mov [XMSLargestBlock], ax + mov [XMSTotal], dx + } + + fprintf(stream, "XMS Version number: %d\n", XMSVersionNumber); + fprintf(stream, "Largest available block: %d kB (%d kB total)\n", XMSLargestBlock, XMSTotal); +} + +/*int main() +{ + xmsreport(fopen("xms.log", "w")); + return 0; +}*/ diff --git a/src/lib/xms.h b/src/lib/xms.h new file mode 100644 index 00000000..100db362 --- /dev/null +++ b/src/lib/xms.h @@ -0,0 +1,28 @@ +#ifndef _XMS_H_ +#define _XMS_H_ +#include /* Definition of NULL */ +#include /* Definition of UINT_MAX */ +#include /* fprintf and (FILE *) */ + +/* Allow external configuration of maximum concurrent XMS allocations */ +#ifndef MAX_XMS_ALLOCATIONS +#define MAX_XMS_ALLOCATIONS 4 +#endif + +/* Address of the XMS driver */ +static long XMSControl; + +/* Mapping of XMS handle <-> normal pointer */ +typedef struct { + unsigned int XMSHandle; + void huge * XMSPointer; +} XMSHandleMap; + +static XMSHandleMap allocMapXMS[MAX_XMS_ALLOCATIONS]; + +static int initxms(void); +void huge * xmsmalloc(long unsigned int size); +void xmsfree(void huge * XMSPointer); +void xmsreport(FILE * stream); + +#endif/*_XMS_H_*/ diff --git a/src/scroll.c b/src/scroll.c index cdf1011e..c214348e 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -2,7 +2,8 @@ #include #include #include "src\lib\dos_kb.h" -#include "src\lib\wtest\wtest.c" +#include "src\lib\wtest\wtest.c" +#include "src\lib\xms.c" //word far *clock= (word far*) 0x046C; /* 18.2hz clock */ @@ -441,7 +442,7 @@ void main() { } //modexClearRegion(mask->page, 66, 66, 2, 40, 0); - if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER))||(player.tx == 5 && player.ty == 5)) + if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(0x1C))||(player.tx == 5 && player.ty == 5)) { short i; for(i=800; i>=400; i--) @@ -451,7 +452,7 @@ void main() { nosound(); } if(player.q == (TILEWH/SPEED)+1 && player.d > 0 && (player.triggerx == 5 && player.triggery == 5)){ player.hp--; } - if(keyp(0x0E)) while(1){ if(malloc(24)) break; } + if(keyp(0x0E)) while(1){ if(xmsmalloc(24)) break; } } /* fade back to text mode */ @@ -494,7 +495,8 @@ allocMap(int w, int h) { result.width =w; result.height=h; - result.data = malloc(sizeof(byte) * w * h); + if(initxms()) result.data = malloc(sizeof(byte) * w * h); + else result.data = xmsmalloc(sizeof(byte) * w * h); return result; } @@ -505,14 +507,17 @@ initMap(map_t *map) { /* just a place holder to fill out an alternating pattern */ int x, y; int i; - int tile = 1; - map->tiles = malloc(sizeof(tiles_t)); + int tile = 1; + if(initxms()) map->tiles = malloc(sizeof(tiles_t)); + else map->tiles = xmsmalloc(sizeof(tiles_t)); /* create the tile set */ - map->tiles->data = malloc(sizeof(bitmap_t)); + if(initxms()) map->tiles = malloc(sizeof(tiles_t)); + else map->tiles->data = xmsmalloc(sizeof(bitmap_t)); map->tiles->data->width = (TILEWH*2); - map->tiles->data->height= TILEWH; - map->tiles->data->data = malloc((TILEWH*2)*TILEWH); + map->tiles->data->height= TILEWH; + if(initxms()) map->tiles->data->data = malloc((TILEWH*2)*TILEWH); + else map->tiles->data->data = xmsmalloc((TILEWH*2)*TILEWH); map->tiles->tileHeight = TILEWH; map->tiles->tileWidth =TILEWH; map->tiles->rows = 1;