mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-25 03:30:39 +00:00
Added some block functions - more work to do here
This commit is contained in:
parent
762c847d02
commit
e49504d577
4 changed files with 99 additions and 0 deletions
|
@ -16,6 +16,15 @@ void *memset(void *dest, int val, unsigned len)
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *memcpy(void *dest, const void *src, unsigned len)
|
||||||
|
{
|
||||||
|
char *d = dest;
|
||||||
|
const char *s = src;
|
||||||
|
while (len--)
|
||||||
|
*d++ = *s++;
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
int abs(int i)
|
int abs(int i)
|
||||||
{
|
{
|
||||||
return i < 0 ? -i : i;
|
return i < 0 ? -i : i;
|
||||||
|
|
|
@ -47,6 +47,7 @@ extern short bx,by,tx,ty;
|
||||||
// ######## HELPER FUNCTIONS ########
|
// ######## HELPER FUNCTIONS ########
|
||||||
|
|
||||||
void *memset(void *dest, int val, unsigned len);
|
void *memset(void *dest, int val, unsigned len);
|
||||||
|
void *memcpy(void *dest, const void *src, unsigned len);
|
||||||
int abs(int i);
|
int abs(int i);
|
||||||
int strlen(const char *str);
|
int strlen(const char *str);
|
||||||
|
|
||||||
|
@ -80,3 +81,8 @@ void wtextbackground (unsigned int col);
|
||||||
void wtexttransparent (short transparent);
|
void wtexttransparent (short transparent);
|
||||||
void wtextgrid (short onoff);
|
void wtextgrid (short onoff);
|
||||||
void wregionfill (short x, short y);
|
void wregionfill (short x, short y);
|
||||||
|
void wfreeblock (block ptr);
|
||||||
|
short wgetblockwidth (block ptr);
|
||||||
|
short wgetblockheight (block ptr);
|
||||||
|
block wnewblock (short x, short y, short x2, short y2);
|
||||||
|
block wallocblock (short width, short height);
|
||||||
|
|
20
part12-wgt/wmiscb.c
Normal file
20
part12-wgt/wmiscb.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "wgt.h"
|
||||||
|
#include "include/mem.h"
|
||||||
|
|
||||||
|
extern short bx,by,tx,ty;
|
||||||
|
|
||||||
|
void wfreeblock (block ptr)
|
||||||
|
{
|
||||||
|
free (ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
short wgetblockwidth (block ptr)
|
||||||
|
{
|
||||||
|
return *(short *)ptr; /* Width is first 2 bytes of data */
|
||||||
|
}
|
||||||
|
|
||||||
|
short wgetblockheight (block ptr)
|
||||||
|
{
|
||||||
|
ptr += 2; /* Skip width */
|
||||||
|
return *(short *)ptr; /* Height is second 2 bytes of data */
|
||||||
|
}
|
64
part12-wgt/wnpblock.c
Normal file
64
part12-wgt/wnpblock.c
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
#include "wgt.h"
|
||||||
|
#include "include/mem.h"
|
||||||
|
|
||||||
|
block wnewblock (short x, short y, short x2, short y2)
|
||||||
|
{
|
||||||
|
block ptr,orig;
|
||||||
|
int temp,width,height;
|
||||||
|
int dispofs;
|
||||||
|
int size;
|
||||||
|
int ctr;
|
||||||
|
|
||||||
|
width = abs (x - x2) + 1;
|
||||||
|
height = abs (y - y2) + 1;
|
||||||
|
size = (int)width * (int)height + 5;
|
||||||
|
if (x2 < x)
|
||||||
|
{
|
||||||
|
temp = x; x = x2; x2 = temp;
|
||||||
|
}
|
||||||
|
if (y2 < y)
|
||||||
|
{
|
||||||
|
temp = y; y = y2; y2 = temp;
|
||||||
|
}
|
||||||
|
ptr = malloc (size);
|
||||||
|
if (ptr == NULL)
|
||||||
|
return NULL;
|
||||||
|
orig = ptr;
|
||||||
|
*(short *)ptr = width; /* store the width */
|
||||||
|
ptr += 2; /* and height */
|
||||||
|
*(short *)ptr = height;
|
||||||
|
ptr += 2;
|
||||||
|
|
||||||
|
dispofs = y * WGT_SYS.xres + x;
|
||||||
|
temp = width;
|
||||||
|
if (temp > WGT_SYS.xres)
|
||||||
|
temp = WGT_SYS.xres;
|
||||||
|
for (ctr = y; ctr <= y2; ctr++)
|
||||||
|
{
|
||||||
|
memcpy (ptr, &abuf[dispofs], temp);
|
||||||
|
/* read off the screen */
|
||||||
|
ptr += width;
|
||||||
|
dispofs += WGT_SYS.xres;
|
||||||
|
/* into the new ptr */
|
||||||
|
}
|
||||||
|
return orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
block wallocblock (short width, short height)
|
||||||
|
{
|
||||||
|
block ptr,orig;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = (int)width * (int)height + 5;
|
||||||
|
ptr = malloc (size);
|
||||||
|
if (ptr == NULL)
|
||||||
|
return NULL;
|
||||||
|
orig = ptr;
|
||||||
|
*(short *)ptr = width; /* store the width */
|
||||||
|
ptr += 2;
|
||||||
|
*(short *)ptr = height; /* and height */
|
||||||
|
ptr += 2;
|
||||||
|
|
||||||
|
memset (ptr, 0, size - 4);
|
||||||
|
return orig;
|
||||||
|
}
|
Loading…
Reference in a new issue