Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
DLL Projects:
Browse files Browse the repository at this point in the history
- LOGGER.DLL: Created a logger DLL.
    - Implemented to log to file, write logs in "LOGS\%date\%hour.LOG" (using full DOS filename format).
    - Implemented console to show last n log entries in screen (not finished yet).
    - Created LOGGER.PRG program test.
- GIF.DLL:
    - GIF.CPP:
        - Implemented frame delay logic.
        - Improved some previous code.
    - gifdec.cpp:
        - Fixed types to match stdio implementation.
        - Fixed some cast conversions from div_malloc() calls.
- COMMON.CPP:
    - Implemented getDateTime() function to get current date and time values.
    - Reimplementd strAlloc() function (implemented as pure function instead of define macro). Now set to null char all allocated memory.
- PROCESS.CPP: Improved code style.
- Updated TEST.CPP and TEST.PRG.
- Recompiled DLLs.
  • Loading branch information
José Miguel Sánchez Fernández committed Jun 4, 2020
1 parent a6bc46c commit 8c97cce
Show file tree
Hide file tree
Showing 20 changed files with 354 additions and 34 deletions.
15 changes: 15 additions & 0 deletions DLL/COMMON.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ void *div_realloc(void *ptr, size_t size)
return newPtr;
}

char* strAlloc(size_t size)
{
size_t len = size + 1;
char* ptr = (char*)div_malloc(len);
memset(ptr, '\0', len);
return ptr;
}

void strCase(char* str, const int mode)
{
int len = strlen(str);
Expand Down Expand Up @@ -67,3 +75,10 @@ void strReplace(char * str, const char o, const char n)
if (str[i] == o) str[i] = n;
}
}

struct tm *getDateTime()
{
time_t now;
time(&now);
return localtime(&now);
}
9 changes: 7 additions & 2 deletions DLL/COMMON.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

#define GLOBALS
#include "div.h"
Expand All @@ -29,8 +30,6 @@

// Gets the string parameter from DIV call:
#define getStrParm() (char*)&mem[text_offset + getparm()]
// Allocate string pointer in div memory:
#define strAlloc(len) (char*)div_malloc(len + 1)
// Convert string to upper case:
#define strUpr(s) strCase(s, 0)
// Convert string to lower case:
Expand All @@ -39,9 +38,15 @@
// Custom implementation of realloc to works with DIV memory:
void *div_realloc(void *ptr, size_t size);

// Allocate string pointer in div memory (full set to null chars):
char* strAlloc(size_t size);

// String functions:
void strCase(char* str, const int mode);
void strTrim(char* str);
void strReplace(char * str, const char o, const char n);

// Return current date time:
struct tm *getDateTime();

#endif
Binary file modified DLL/CONFIG.DLL
Binary file not shown.
41 changes: 27 additions & 14 deletions DLL/GIF/GIF.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,25 @@ void startGIF()
char* filename = getStrParm();

animation = gd_open_gif(filename);
startTime = clock();

retval(animation != NULL);
retval(animation != NULL ? RESULT_OK : RESULT_ERROR);
}

/** End and unload GIF animation.
*
* @return {int} - Returns RESULT_OK if GIF is stoped and unloaded to reproduce or RESULT_ERROR if any error ocurrs.
*/
/** End and unload GIF animation. */
void endGIF()
{
gd_close_gif(animation);
animation = NULL;
startTime = 0;
retval(RESULT_OK);
}

/** Reset GIF animation.
*
* @return {int} - Returns RESULT_OK if GIF is rewinded or RESULT_ERROR if any error ocurrs.
*/
/** Reset GIF animation. */
void resetGIF()
{
gd_rewind(animation);
startTime = 0;
retval(RESULT_OK);
}

Expand All @@ -54,18 +52,31 @@ void resetGIF()
*/
void frameGIF()
{
// TODO: Implement frame delay.
int res = gd_get_frame(animation);
int res = RESULT_ERROR;

if (res != 0)
if (file_loaded)
{
// TODO: Write animation->palette
// TODO: Write animation->frame data to DIV screen buffer.
if (update_frame)
{
startTime = clock();
res = gd_get_frame(animation);

if (res != 0)
{
// TODO: Write animation->palette
// TODO: Write animation->frame data to DIV screen buffer.
}
}
}

retval(ret);
}

void post_process_buffer(void)
{

}

void __export divlibrary(LIBRARY_PARAMS)
{
COM_export("start_gif", startGIF, 3);
Expand All @@ -77,4 +88,6 @@ void __export divlibrary(LIBRARY_PARAMS)
void __export divmain(COMMON_PARAMS)
{
GLOBAL_IMPORT();

DIV_export("post_process_buffer",post_process_buffer);
}
10 changes: 10 additions & 0 deletions DLL/GIF/GIF.H
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@
* https://github.com/lecram/gifdec
* ---------------------------------------------------------------------------- */

#include <time.h>
#include "..\common.h"
#include "gifdec.h"

#define file_loaded animation != NULL

#define palette_size animation->palette->size
#define palette_data animation->palette->colors

#define frame_length animation->width * animation->height
#define frame_duration animation->gce.delay
#define frame_data animation->frame

#define update_frame (clock() - startTime) > frame_duration;

uint8_t *screen_buffer;
uint8_t *palette_buffer;

gd_GIF *animation;
int startTime;

void startGIF();
void endGIF();
Expand Down
10 changes: 5 additions & 5 deletions DLL/GIF/gifdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct Table {
} Table;

static uint16_t
read_num(int fd)
read_num(FILE *fd)
{
uint8_t bytes[2];

Expand All @@ -35,7 +35,7 @@ read_num(int fd)
gd_GIF *
gd_open_gif(const char *fname)
{
int fd;
FILE *fd;
uint8_t sigver[3];
uint16_t width, height, depth;
uint8_t fdsz, bgidx, aspect;
Expand Down Expand Up @@ -77,7 +77,7 @@ gd_open_gif(const char *fname)
fgets(&aspect, 1, fd); // read(fd, &aspect, 1);
/* Create gd_GIF Structure. */
//gif = calloc(1, sizeof(*gif) + 4 * width * height);
gif = div_malloc(sizeof(*gif) + 4 * width * height);
gif = (gd_GIF *)div_malloc(sizeof(*gif) + 4 * width * height);
if (!gif) goto fail;
gif->fd = fd;
gif->width = width;
Expand Down Expand Up @@ -224,7 +224,7 @@ new_table(int key_size)
{
int key;
int init_bulk = _max(1 << (key_size + 1), 0x100);
Table *table = div_malloc(sizeof(*table) + sizeof(Entry) * init_bulk);
Table *table = (Table *)div_malloc(sizeof(*table) + sizeof(Entry) * init_bulk);
if (table) {
table->bulk = init_bulk;
table->nentries = (1 << key_size) + 2;
Expand All @@ -245,7 +245,7 @@ add_entry(Table **tablep, uint16_t length, uint16_t prefix, uint8_t suffix)
Table *table = *tablep;
if (table->nentries == table->bulk) {
table->bulk *= 2;
table = div_realloc(table, sizeof(*table) + sizeof(Entry) * table->bulk);
table = (Table *)div_realloc(table, sizeof(*table) + sizeof(Entry) * table->bulk);
if (!table) return -1;
table->entries = (Entry *) &table[1];
*tablep = table;
Expand Down
2 changes: 1 addition & 1 deletion DLL/GIF/gifdec.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct gd_GCE {
} gd_GCE;

typedef struct gd_GIF {
int fd;
FILE *fd;
off_t anim_start;
uint16_t width, height;
uint16_t depth;
Expand Down
Binary file modified DLL/INPUT.DLL
Binary file not shown.
Binary file added DLL/LOGGER.DLL
Binary file not shown.
Loading

0 comments on commit 8c97cce

Please sign in to comment.