/* Control codes for all keys on the keyboard */
//here temperarly
+/*
#define KEY_A (0x1E)
#define KEY_B (0x30)
#define KEY_C (0x2E)
#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)
#define KEY_LWIN (0x73)
#define KEY_RWIN (0x74)
#define KEY_MENU (0x75)
-
+*/
//typedef unsigned char byte;
//typedef unsigned int word;
--- /dev/null
+/* 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;
+}*/
--- /dev/null
+#ifndef _XMS_H_
+#define _XMS_H_
+#include <stddef.h> /* Definition of NULL */
+#include <limits.h> /* Definition of UINT_MAX */
+#include <stdio.h> /* 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_*/
#include <stdio.h>\r
#include <stdlib.h>\r
#include "src\lib\dos_kb.h"\r
-#include "src\lib\wtest\wtest.c"\r
+#include "src\lib\wtest\wtest.c"
+#include "src\lib\xms.c"\r
\r
//word far *clock= (word far*) 0x046C; /* 18.2hz clock */\r
\r
}\r
//modexClearRegion(mask->page, 66, 66, 2, 40, 0);\r
- if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(KEY_ENTER))||(player.tx == 5 && player.ty == 5))\r
+ if(((player.triggerx == TRIGGX && player.triggery == TRIGGY) && keyp(0x1C))||(player.tx == 5 && player.ty == 5))\r
{\r
short i;\r
for(i=800; i>=400; i--)\r
nosound();\r
}
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; }\r
+ if(keyp(0x0E)) while(1){ if(xmsmalloc(24)) break; }\r
}\r
\r
/* fade back to text mode */\r
\r
result.width =w;\r
result.height=h;\r
- result.data = malloc(sizeof(byte) * w * h);\r
+ if(initxms()) result.data = malloc(sizeof(byte) * w * h);
+ else result.data = xmsmalloc(sizeof(byte) * w * h);\r
\r
return result;\r
}\r
/* just a place holder to fill out an alternating pattern */\r
int x, y;\r
int i;\r
- int tile = 1;\r
- map->tiles = malloc(sizeof(tiles_t));\r
+ int tile = 1;
+ if(initxms()) map->tiles = malloc(sizeof(tiles_t));\r
+ else map->tiles = xmsmalloc(sizeof(tiles_t));\r
\r
/* create the tile set */\r
- map->tiles->data = malloc(sizeof(bitmap_t));\r
+ if(initxms()) map->tiles = malloc(sizeof(tiles_t));
+ else map->tiles->data = xmsmalloc(sizeof(bitmap_t));\r
map->tiles->data->width = (TILEWH*2);\r
- map->tiles->data->height= TILEWH;\r
- map->tiles->data->data = malloc((TILEWH*2)*TILEWH);\r
+ map->tiles->data->height= TILEWH;
+ if(initxms()) map->tiles->data->data = malloc((TILEWH*2)*TILEWH);\r
+ else map->tiles->data->data = xmsmalloc((TILEWH*2)*TILEWH);\r
map->tiles->tileHeight = TILEWH;\r
map->tiles->tileWidth =TILEWH;\r
map->tiles->rows = 1;\r