Page 1 of 1

Problem unpacking data

Posted: Fri May 15, 2020 9:56 pm
by fraespre
Hello,

So far I have always used data compression using the zx7 tool. However I wanted to try another similar tool aplib, but I have found a mystery that I don't know how to solve.
I go to you to see if anyone can give me a clue about what I am doing wrong or how I could solve it,

Here you can see the code:

Code: Select all

#include <input.h>
#include <malloc.h>
#include <arch/zx.h>
#include <arch/zx/sp1.h>
#include <compress/zx7.h>
#include <compress/aplib.h>

#pragma output CRT_ORG_CODE = 24000
#pragma output REGISTER_SP = 0xd000 
#pragma output CRT_STACK_SIZE = 128
#pragma output CRT_ENABLE_RESTART = 1
#pragma output CRT_ENABLE_CLOSE = 0
#pragma output CRT_ENABLE_STDIO = 0
#pragma output CRT_INITIALIZE_BSS=0
#pragma output CLIB_EXIT_STACK_SIZE = 0
#pragma output CLIB_FOPEN_MAX = -1
#pragma output CLIB_OPEN_MAX = -1
#pragma output CLIB_MALLOC_HEAP_SIZE = -1
#pragma output CLIB_STDIO_HEAP_SIZE = 0
#pragma output CLIB_EXIT_STACK_SIZE = 0 

extern uint8_t  screen_begin[];
static uint8_t *screen_unpack;

struct sp1_Rect AREA_SCREEN= {0, 0, 32, 24};

void printStr(uint8_t x, uint8_t y, uint8_t *str) {
  while(*str) sp1_PrintAtInv(y, x++, INK_BLACK|PAPER_WHITE, *str++);
}

main() {
  sp1_Initialize(SP1_IFLAG_MAKE_ROTTBL|SP1_IFLAG_OVERWRITE_TILES|SP1_IFLAG_OVERWRITE_DFILE, INK_BLACK|PAPER_BLACK, ' ');

  printStr(8, 2, "==  INIT  ==");
  sp1_UpdateNow();
  in_wait_key();
  zx_border(INK_YELLOW);
  
  // --- Reserve dinamic memory ----
  screen_unpack= (uint16_t *)malloc(6912);
  
  // --- Uncompress data ---
  //dzx7_turbo(&screen_begin, screen_unpack);
  aplib_depack(&screen_begin, screen_unpack);
  
  // --- Free dinamic memory ----
  free(screen_unpack);
  
  printStr(8, 2, "==  END  ==");
  sp1_UpdateNow();
  in_wait_key();
  zx_border(INK_BLACK);
}
Briefly, when I compress the data using zx7 and from the code I uncompress it using dzx7_turbo => everything works fine.
However, if I use the apack to do the compression of the data, and after I unpack using aplib_depack => the program crash.
Any hint, advice or recommendation will be welcome.

Anyone who wants to test the code to analyze it in more detail. I've left everything ready to reproduce the problem at the following URL: http://ge.tt/71KJTN33

Thanks in advanced,

Posted: Mon May 18, 2020 9:47 pm
by dom
Shouldn't this be:

aplib_depack(screen_unpack, &screen_begin)

The arguments are the opposite way round to zx7 - presumably to maintain compatibility with the SMS library.

Posted: Tue May 19, 2020 9:55 am
by fraespre
Yes. That was the problem.
A lot of thanks dom.