News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_EgoTrip

[cpctelera]Bit Arrays

Started by EgoTrip, 23:51, 24 February 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ronaldo

#25
Quote from: EgoTrip on 18:32, 26 February 16
This isnt the only reason I have given up. I keep encountering bugs that I can't fix and appear for no apparent reason, its stressing me out and im not having any fun doing this so whats the point.
Well, I think most of us understand perfectly your feeling. This is normal when programming. Every programming project takes 1/3 of time for creative tasks and 2/3 for debugging and "have-to-do" tasks. That's the reason why it is so hard finishing projects and it is so valuable.

You've finished some projects already. That speaks well of you, specially if you had harsh moments like this one and continued till the end.

Your project looks very nice. I'd recommend you to take time to feel better and then decide on continuing or not. If you think it is going too complex, simplify it (remove features) and finish it. It is always better a smaller finished game than a greater unfinished one. Moreover, everything you learnt will let you face greater projects next time.

No matter what you decide, the most important thing is finding the way to enjoying it (even when it is difficult). Believe me if I say that you have plenty of reasons to be proud and enjoy what you are doing :) .

EgoTrip

Quote from: Arnaud on 18:30, 26 February 16
I tried an easy solution :

       
  • creation of a file with your data level.
  • use exomizer to compress in command line the data level : 160 -> 76 Bytes
  • convert with cpctelera the binary file into data.h
  • decompress the data level with the function cpc_UnExo from the cpcrslib
cpc_UnExo(dataLevelCompress, currentLevel);

That all !

Can you do a step by step guide showing me exactly what to do please? Including getting the cpcrslib and using it with a CPCtelera project? Thanks.

Arnaud

#27
Hello,
here a full project for cpctelera with your level in compressed file (level.bin) automatically converted in C file (level.c).

For information :
#include <cpctelera.h>
#include <cpcrslib.h>
#include <stdio.h>

extern const unsigned char G_level[76];
static unsigned char gCurrentLevel[160];

void main(void)
{
    int i, j, k = 0;
    cpc_UnExo(G_level, (int)gCurrentLevel);
   
    for (i = 0; i < 10; i++)
        for (j = 0; j < 16; j++)
        {
            if (j == 0)
                printf("\r\n");
            printf("%02X", gCurrentLevel[k++]);
        }

   while (1);
}


- To create the file of level data i used HxD (hexadecimal editor)
- To compress i used exomizer with the following commands line :
exomizer.exe raw level.dat -o t.out
exoopt.exe t.out level.bin

- And i moved level.bin directly in the src folder of cpctelera project


EgoTrip

How/where do I install cpcsrlib?

SRS

Quote from: EgoTrip on 18:59, 27 February 16
How/where do I install cpcsrlib?

you could download "level" (above), there it is included (*.h and *.lib). both files into your main path of game or compiler - then it should work

ronaldo

#30
@EgoTrip if you are running out of memory, adding cpcrslib to your project is not a good idea. Depending on how you use it, it will add many bytes of code to your project. Taking into account that you are running out of memory, that's not the best solution.

It will be easier if you only add the function for unexomizing buffers. You only need to add a .s file with the assembly code of the function, and a header file to include with the declaration of the function. That will be faster and more efficient for your project.


EDIT: Attached you have a zip file the code for unexomizing. Uncompress it and put UnExoOpt.s in the src/ folder of your project. It will be automatically compiled. Then, when you wanted to use the function for uncompressing, you will need to declare the function with this line:
void cpc_UnExo(const u8* source, u8* dest) __z88dk_callee;

EgoTrip

@ronaldo how do I find the ASM? I opened the files in the zip and there was the header file and another file with loads of bytes and some unreadable data.

ronaldo

#32
@EgoTrip : I've just edited my last post and attached the file for you. In fact, I have reviewed the file and add a little patch to ensure it does not produce any kind of new bug.


I have not tested it, but it should work. If it gives any problem, report it here and we will have a look at it.


EDIT: Also, take into account that this code for exomizing takes 358 bytes of memory. I assume you will recover a lot more from compressing your data, but take this into account :).

Arnaud

I have updated my project with asm in case you need working example.

EgoTrip

How do I convert the data RGAS outputs to a binary format exomiser can use?

ronaldo

#35
If you put your arrays in individual files, the compiler can do that for you. I'll show you an example.


1. Create a file examplemap.c which will only contain an imaginary map, and put it in src/ folder. (You could do this with any kind of data, be it maps, sprites or whatever).


#include <cpctelera.h>


const u8 an_example_map[] = {
   20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
   20,  0,  0,  0,  0,  0,  0,  0,  0, 20,
   20,  0,  3,  3,  3,  3,  3,  3,  0, 20,
   20,  0,  0,  0,  0,  0,  0,  0,  0, 20,
   20,  0,  2,  2,  0,  0,  2,  2,  0, 20,
   20,  0,  2,  2,  0,  0,  2,  2,  0, 20,
   20,  0,  2,  2,  0,  0,  2,  2,  0, 20,
   20,  0,  0,  0,  0,  0,  0,  0,  0, 20,
   20,  0,  0,  0,  1,  1,  0,  0,  0, 20, 
   20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
};



2. Compile the project. After compilation, a file obj/examplemap.rel is created, which contains this data, along with some information to link it to other files.


3. Enter obj/ folder and use sdcc to convert the REL file to an intel IHX binary:

   cd obj/
   sdcc examplemap.rel

This will create examplemap.ihx (also LK, MAP and MEM files, that are of no interest for us). If you open this file, you will see it is almost what we wanted.


4. Use hex2bin to convert de IHX file to a proper BIN file containing only our map data.

   hex2bin examplemap.ihx



With these simple commands, we have a perfect binary file containing exacly this:
[attachimg=1]


So, summing up, if you put your data in individual .c files, you can create binaries after compilation entering the obj/ folder and typing this:

   sdcc file2convert.rel && hex2bin file2convert.ihx

As simple as that, in the end.


PD: You will need to have sdcc and hex2bin in the PATH. If they are not in the path, you can insert them with this

export PATH=$PATH:${CPCT_PATH}/tools/hex2bin-2.0/bin/:${CPCT_PATH}/tools/sdcc-3.5.5/bin/

as both tools are included within CPCtelera tools/ folder. (Depending on the release of CPCtelera you are using, sdcc version might be a different one).

Arnaud

To convert C to bin in manual way :

- From the C file i keep only the hexa values, with replace function of notepad  :

const unsigned char G_NewSprite1[36] = {
    0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBB,
}


to

AA 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 BB


- i used hxd (simple hexadecimal editor) : mh-nexus
- create new file
- copy / past from notepad text
- save

The binary file is created

ronaldo

@Arnaud : having a manual way for doing things like this is always useful. In fact, it is interesting for everybody to start doing things manually to understand them better.

The automatic way is the way to go later on. For instance, if @EgoTrip has around 20 maps, converting them on every modification he does could be painful. So, once command-driven conversion has been manually tested, a simple script would relief from pain:

#!/bin/bash

## Paths and files required for this script to work
FILES2CONVERT=( map1 map2 map3 finalmap )
SDCC=${CPCT_PATH}/tools/sdcc-3.5.5/bin/sdcc
HEX2BIN=${CPCT_PATH}/tools/hex2bin-2.0/bin/hex2bin
EXOMIZER=/path/to/exomizer

## Function that converts and exomizes 1 REL file
function convertAndExomize {
   $SDCC "${1}.rel"
   $HEX2BIN  "${1}.ihx"
   $EXOMIZER raw "${1}.bin" "${1}.exo"
}

## Enter obj/ folder and convert to binary and exomize all desired files one by one
cd obj/
for F in ${FILES2CONVERT[@]}; do
   convertAndExomize "$F"
done
cd -


With a script like this, you only have to run it along with your compilation line, and conversion gets automated.

   make && exomizeScript


You could even modify it to move the resulting files to the place where you wanted them to be.

EgoTrip

Theres no exoopt.exe in the exomizer zip. Can I just not use the data that the t.out file contains?

ronaldo

#39
@EgoTrip : I think you got confused by the name of the asm file UnExoOpt.s. The "Opt" in that name stands for "Optimized" and refers to the assembly code, not to the exomizer format. The output exomizer gives you using "raw" modifier should be perfectly decompressed by cpc_UnExo function.

Arnaud

Here the file, i don't remember from where i download it.

ronaldo

Sorry, I was wrong with my previous comment. Didn't know of the exoopt (thanks, @Arnaud). I've been reading about it. As far as I've read, the latest version I've found of exoopt is from 28/01/2013 (attached). @Arnaud , I think you should review your version, as it seems earlier to this one. Could you make a comparison of the outputs?

Arnaud

I tried to use this version but now it needs parameters and i don't understand how use it (i think it's for asm generated)

EgoTrip

#43
Its working! Thanks for all your help everyone.

SRS

#44
Quote
## Function that converts and exomizes 1 REL file
function convertAndExomize {
   $SDCC "${1}.rel"
   $HEX2BIN  "${1}.ihx"
   $EXOMIZER raw "${1}.bin" "${1}.exo"
}


is not working for me. I need to  $EXOMIZER raw "${1}.bin" -o "${1}.exo" else exomizer complains.

Question: if I put the "*.c" into SRC (lets say a 64 u8 "00"), the *.rel is way bigger (inlucdes crt0 at least ?) ->
so compressing the *.rel from "Make" really the right way ?

EXAMPLE ->

Raw Tile G_...c -> MAKE (CPCTeleraproject ...) -> putting *.REL to *.IHX to *.BIN and this back to C with
"cpct_bin2c G_Blank.bin > help.txt"

-> [attach=2]

ronaldo

Let's go with your problems one by one:

       
  • The script I wrote here was untested: I wrote it directly in the post. I should have labelled it as untested. Sorry about that. I'm glad you tested and fixed it. That would be nice for others :) .
  • REL files are not OBJ files. They are not binaries. In fact, they are text files: you can open them with your text editor and you will easily understand why they take more space than your C file.
  • Compressing a REL file with exomizer is unuseful, due to what you can deduct from step 2. That's why It has to be compiled with SDCC, then converted with HEX2BIN then, finally, exomized as binary.
  • Some part of this chain of steps is missing in your files. If I follow these steps manually starting with your G_Blank.rel, I get a totally different result (image attached). I have followed manually the 3 steps that are in the function: "sdcc G_Blank.rel; hex2bin G_Blank.ihx; exomizer raw G_Blank.bin -o G_Blank.exo".
I think either you may have used an incorrect file at any given step, or my script does not work properly under some circumpstances I cannot see right now.
[attachimg=1]

SRS

#46
Quote from: ronaldo on 16:26, 10 March 16

       
  • Some part of this chain of steps is missing in your files. If I follow these steps manually starting with your G_Blank.rel, I get a totally different result (image attached). I have followed manually the 3 steps that are in the function: "sdcc G_Blank.rel; hex2bin G_Blank.ihx; exomizer raw G_Blank.bin -o G_Blank.exo".
I think either you may have used an incorrect file at any given step, or my script does not work properly under some circumpstances I cannot see right now.


Okay, lets try it manually:

***/cygdrive/e/cygwin64/home/Standardsurf/projekte/amy/obj
$ sdcc gblank.rel
-bash: sdcc: Kommando nicht gefunden.

Seems my cygwin PATH does not contain SDCC (but "Make" works, weired)  :picard: .


**********************

Try script, but only SDCC Pat, rest commented out:

#!/bin/bash

## Paths and files required for this script to work
FILES2CONVERT=( gblank GFRUIT1 GJEWEL1 GKEY1)
SDCC=${CPCT_PATH}/tools/sdcc-3.5.5/bin/sdcc
HEX2BIN=${CPCT_PATH}/tools/hex2bin-2.0/bin/hex2bin
EXOMIZER=${CPCT_PATH}/tools/exomizer/exomizer

## Function that converts and exomizes 1 REL file
function convertAndExomize {
   $SDCC "${1}.rel"
   ##$HEX2BIN  "${1}.ihx"
   ##$EXOMIZER raw "${1}.bin" -o "${1}.exo"
   ##cpct_bin2c "${1}.exo" > "${1}.txt"
}

## Enter obj/ folder and convert to binary and exomize all desired files one by one
cd obj/
for F in ${FILES2CONVERT[@]}; do
   convertAndExomize "$F"
done
cd -


Quote$ ./cruncher.sh

?ASlink-Warning-Undefined Global '_main' referenced by module 'crt0'

?ASlink-Warning-Undefined Global '_main' referenced by module 'crt0'

?ASlink-Warning-Undefined Global '_main' referenced by module 'crt0'

?ASlink-Warning-Undefined Global '_main' referenced by module 'crt0'
/home/Standardsurf/projekte/amy


the IHX generated now
:03000000C3000139
:02000800ED4DBC
:02001000ED4DB4
:02001800ED4DAC
:02002000ED4DA4
:02002800ED4D9C
:02003000ED4D94
:02003800ED4D8C
:0C010000310000CD4A02CD0000C3040213
:0A0200003E02CFC93E00CF7618FD84
:10024A0001000078B12808110080214A02EDB0C9E6
:20020A000000007000000070000000A0000010200000204010E04040211CF080433B874062
:20022A00873A0EEC872D0EDC872D0F12872D0F1E432D0F1E211E0F2C10E0874800007080DF
:00000001FF



scripted hex2bin only give :

Quotehex2bin v2.0, Copyright (C) 2015 Jacques Pelletier & contributors

Binary file start = 00000000
Records start     = 00000000
Highest address   = 00000259
Pad Byte          = FF
hex2bin v2.0, Copyright (C) 2015 Jacques Pelletier & contributors

This is to big. No wonder, the generated bin shows ->[attach=2]

So it seems compiling / linking it always with some crt0



SRS

Okay, brand new project, no main, compiling the C alone - still it seems it does not make "plain code"

see screener and zip.

The "knackpunkt" seems the way my sdcc compiles this C. it is not plain ...



ronaldo

Ok, @SRS , you are plainly right. This was my mistake from the start.

The problem is that SDCC 3.5.0 has different behaviour to SDCC 3.5.5 (which is the one included in latest CPCtelera). I have SDCC 3.5.0 in my $PATH, so it was working for me, but it won't work for you as you are using SDCC 3.5.5.

With SDCC 3.5.5 you have to do this change:

-#   $SDCC "${1}.rel"
+#   $SDCC "${1}.rel" --no-std-crt0

You were correct, SDCC is including aditional bytes from the standard CRT0.

Sorry for not spotting this one earlier on and thank you for all your detailed tests and contribution :)

SRS

#49
@ronaldo, thx for your patience and quick responses.

>joke mode on<
You better "make cleanall make" all your examples for CPCtelera if it still works with your new PATH/SDCC ?  ;D
<joke mode off>

Now it works!

Inbetween I tried @Arnaud method. Works like charm once you know how to use the hex editor !

Sadly the tiles i wanted to compress get out bigger after exomizing then in "raw", so no use for @EgoTrip game here. But for sure in future games.


For all that need the full skript: (windows user don't forget to save it in UNIX-mode (LF only, no CR + LF), else cygwin will not run it ...)

You need latest CPCTelera and have to download/copy "exomizer.exe" to the tool path of CPCTelera (see below), too !

#!/bin/bash

## Paths and files (ttlmus is just an example) required for this script to work
FILES2CONVERT=( ttlmus )
SDCC=${CPCT_PATH}/tools/sdcc-3.5.5/bin/sdcc
HEX2BIN=${CPCT_PATH}/tools/hex2bin-2.0/bin/hex2bin
EXOMIZER=${CPCT_PATH}/tools/exomizer/exomizer

## Function that converts and exomizes 1 REL file
function convertAndExomize {
   $SDCC "${1}.rel" --no-std-crt0
   $HEX2BIN  "${1}.ihx"
   $EXOMIZER raw "${1}.bin" -o "${1}.exo"
   cpct_bin2c "${1}.exo" > "${1}.txt"
}

## Enter obj/ folder and convert to binary and exomize all desired files one by one
cd obj/
for F in ${FILES2CONVERT[@]}; do
   convertAndExomize "$F"
done
cd -

Powered by SMFPacks Menu Editor Mod