News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_ronaldo

#CPCtelera 1.4.2. release

Started by ronaldo, 11:59, 11 May 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ronaldo

#400
Quote from: funkheld on 11:35, 23 July 20
without sdcc principles you can't get any further. there are examples: http://www.cpcmania.com/Docs/Programming/Programming.htm
they no longer work with the new sdcc from tpctelera.

cpctelera makes internal changes with the commands that you do not yet know and surprises you when you mix your own sdcc routines with the code from the cpctelera.
These examples have nothing to do with CPCtelera. In fact, they were written many years before CPCtelera even existed. And they do not work because they are more than a decade old and the COMPILER (SDCC) has changed. CPCtelera is not SDCC. SDCC is an independent compiler and CPCtelera just includes it as a tool for compiling.

CPCtelera does not make any change to any internal commands at all. It is just a bunch of coordinated tools (a framework) and a library you can optionally use which, in fact, you are NOT yet using. So the only addition to the tools that CPCtelera makes is exactly what you are not using yet.

If you want help, we can give you help, but criticizing things you do not comprehend yet is quite a extrange way to ask for it.

asertus

I think it would be better, if you are following that course from CPCMania that you just get the closest version of SDCC, 3.1, and try it independently from cpctelera, http://sdcc.sourceforge.net/previous.php


You may just use visual Studio code, the compiler, and the tools in CPCMania... You will have less issues..

funkheld

#402
Hi good afternoon.
I also think cpctelera is wonderful as a German.
but you probably did not develop cpctelera for the elite, but also for us ordinary people
who want to continue learning fromcpc also from the system.

the new sdcc now has this type of programming:
---------------------------------
void poke(u16 a)
{
__asm
ld h,5(ix)
ld l,4(ix)
ld (hl),#129
__endasm;
}
-------------------------------
this loop with : sdcc-20200722-11758-setup.exe

no loop with cpctelera.
how does this asm work in cpctelera?

you say you don't program something like that.

but have already asked the question of how to do something like this,
it is not just about poke, but about the principle of this way of doing something in cpctelera.

thank you.
greeting

ervin

Hi funkheld.
I think you are misunderstanding what ronaldo is saying.
We don't do something in cpctelera.
cpctelera is a library of routines which we use with sdcc.

ronaldo

#404
Quote from: funkheld on 13:12, 23 July 20
the new sdcc now has this type of programming:
---------------------------------
void poke(int a)
{
__asm
ld h,5(ix)
ld l,4(ix)
ld (hl),#129
__endasm;
}
-------------------------------
You are not understanding what I have told you 3 times already. This is not about the syntax, is about the assembly. You cannot use IX register directly to get the parameters. This will not work! And you don't need assembly (much less a function) to do a poke, you can do it in plain C:

// More readable way
u8 *mem = (u8*)0xC000; // Put your own address here
*mem = 129;

// More compact way
*((u8*)0xC000) = 129;  // Change 0xC000 by your own address


However, if you insist on using assembly, your assembly is incorrect for SDCC. And if you insist on using IX, you have to do it this way

void poke(void* address, unsigned char value) {
   address; value;
   __asm
      ld ix, #0
      add ix, sp  ;; THIS IS NEEDED TO MAKE IX POINT TO THE STACK
      ld h, 3(ix)
      ld l, 2(ix)
      ld a, 4(ix)
      ld (hl), a
   __endasm;
}

Check at what the compiler generates in both cases: https://godbolt.org/z/4be8do. You'll see it's much better to use C for this task. Again, this has nothing to do with CPCtelera. This is programming. You can do same with any C compiler, and without CPCtelera, because this is only programming. CPCtelera is doing nothing here.

funkheld

#405

hello, thank you for your help and info.
maybe you will need your help again.


if have the mister for cpc6128 with core-cpc6128:
https://manuferhi.com/p/mister-fpga
https://github.com/MiSTer-devel/Main_MiSTer/wiki


my mister with wlan , mouse mit cpc-core and "tmhwscr.dsk" from cpctelera.

thank you.
greeting

XeNoMoRPH

your amstrad news source in spanish language : https://auamstrad.es

billamu

Quote from: XeNoMoRPH on 20:35, 05 February 22
https://twitter.com/FranGallegoBR/status/1490040646060683268

This setup is great! But how do I get the VM to operate in English? The VM is protected with a password, so I can't change its settings.

ronaldo

Sometimes, the answer to most of our questions is already there, just waiting for us to read it carefully ;)

[attach=1,msg212249]

However, your question is relevant, because I think it would be more wise to put the machine in English by default.

Thank you for your consideration  :)

billamu

Quote from: ronaldo on 18:32, 08 February 22Sometimes, the answer to most of our questions is already there, just waiting for us to read it carefully
:picard:
Hahaha thank you for answering so quickly - I'm sure I would have found it eventually :D

voxbremen

Changing the CPCtelera 1.5 VM settings to English

I finally got around to trying CPCtelera - great work, and a big thank you to all involved. 
I used the VM mentioned above with version 1.5, however, as some have noted before that is configured in Spanish, which makes it a bit difficult to use for non native speakers.

It took me quite a bit of time to adjust the configuration to English, so just in case someone else is trying to do that, here are my steps:

Before you start create a snapshot of the working (Spanish) Version of the VM state as a fall-back

Start the VM

go into setting (little spanner icon on top of "start menu")

select
> "Gestor de configuracion de Manjaro"

and then
> Configuracion regional

> right click English (United States) and select "Establever como idioma y formato preferido"

> click "Applicar" button

(Authenticate with passwprd found above :-)

> click "Salir" button


create a file  ".i18n" in your HOME directory to export the English language settings

> open a terminal , e.g. using the "Terminator" icon
> nano .i18n
> paste the following lines (right click + "pegar")
> press CTRL+O to save
> press CTRL-X to exit

file content to copy and paste:

export LANGUAGE=en_US.utf8
export LANG=en_US.utf8
export LC_ALL=en_US.utf8

restart the VM

for some reason it took two restart to do the trick with my installation
if this doesn´t work google "change interface language in Xfce" - there are a few more options to force the export, e.g. adding the .i18n file to the xinitrc

you should then be able to adjust the other settings (e.g. keyboard layout) using the english interface

once you are happy with the setup, shut down the VM, create a new Snapshot or Clone of the modified VM and use that...

Good luck!

ivavilagu

Hi,

I want to get some random numbers using cpctelera functions. Usually PC time is used to seed algorithm but doesn´t work in cpctelera.


#include <time.h>

time_t t;
u8 a;

cpct_srand(time(&t));
a = cpct_rand() % 10;

SpDizzy

Hi ivavilagu,
CPCTelera has it's own powerful routines for random numbers, coded directly on assembler.
For seed, you might search for an entropy source on execution time, like a keypress from the player for instance. This is more powefull and specific for any Z80 need than the custom time.h library, and much much more memory saver too, being this very important on any 8 bit project.

ivavilagu

Quote from: SpDizzy on 16:41, 19 September 22Hi ivavilagu,
CPCTelera has it's own powerful routines for random numbers, coded directly on assembler.
For seed, you might search for an entropy source on execution time, like a keypress from the player for instance. This is more powefull and specific for any Z80 need than the custom time.h library, and much much more memory saver too, being this very important on any 8 bit project.

I don´t like to add libraries due to memory limitations but the random generation is in the initialization project, no keys pressed still. The code has not user action from the beginning until random number requeried.

SpDizzy

#414
Quote from: ivavilagu on 16:57, 19 September 22
Quote from: SpDizzy on 16:41, 19 September 22Hi ivavilagu,
CPCTelera has it's own powerful routines for random numbers, coded directly on assembler.
For seed, you might search for an entropy source on execution time, like a keypress from the player for instance. This is more powefull and specific for any Z80 need than the custom time.h library, and much much more memory saver too, being this very important on any 8 bit project.

I don´t like to add libraries due to memory limitations but the random generation is in the initialization project, no keys pressed still. The code has not user action from the beginning until random number requeried.

You will need an entropy source, being that whatever you want. You can catch a keyboard press on a menu, or showing a message on screen "Any key to start...". If you have firmware enabled during execution, or during initialization, you may get entropy from 'KL TIME PLEASE' (&BD0D). Or you may use 'R' register as seed.

awergh

#415
When I used cpct_srand() I had a game timer that was incremented in the interrupt handler.
u16 gameTimer = 0;
void timerInterruptHandler()
{
    // Timer increases and wraps round to 0.
    gameTimer++;
}

I then used the game timer to generate my seed which I could then feed to cpct_srand.
u8 seed = gameTimer % 200;
cpct_srand(seed);

This worked fairly well with generating random as the player can start the game at anytime resulting in a slightly different seed each time they play.

reidrac

I'm not super familiar with the CPCTelera, but it is likely that the random number generator updates the seed, so you only need a good seed once.

What is a good seed? Good question. It may depend on the type of game. I would suggest you set a fixed value at the start of the game (depending on the random number generator, for example, zero may not be great).

Your game may have a menu with a way for the player to start the game. You can keep generating random numbers as the game waits for the player to start, and that will give you good randomness (the player is the source of entropy here).

Again, it all depends on the type of game. For example: in Brick Rick I'm using a fixed seed, and that's OK. Sure, at first the game may always behave the same, but because these games have branches in the enemy logic based on the player input, eventually the randomness will be OK. If the player always does the same moves, the game will behave mostly the same and patterns will emerge (a different matter is if the player can actually *see* those patterns); and for a skill game, that's perfect.

IMHO full randomness is not really good in a skill game: players can't learn if that's the case. I believe most of the perceived difficulty in Brick Rick is with the enemies that rely on randomness (e.g. is that alien going to fire?).
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

ivavilagu

All right, I understand the menu 'trick' to have differents seeds. 

In other way, I'm fighting with double buffer. Studying the cpctelera example

https://github.com/lronaldo/cpctelera/blob/master/examples/medium/doubleBuffer/src/main.c

I don´t understand the drawing sprite into while statment (line 102). Always paint in  CPCT_VMEM_START address. 

Shouldn´t paint the sprite alternating memory addresses between 0xC000 and 0x4000?


Arnaud

In the begining a Cpctelera sprite is draw at 0x4000

   
pvmem = cpct_getScreenPtr(SCR_BUFF, 0,   52);
cpct_drawSprite(G_CPCt_left,  pvmem,          CPCT_W, CPCT_H);
cpct_drawSprite(G_CPCt_right, pvmem + CPCT_W, CPCT_W, CPCT_H);

In main loop it switchs between buffers every 2.5s with the function changeVideoMemoryPage.
Then during 2.5s we'll see moving sprite in buffer at 0xC000 then, static cpctelera sprite will be display from other buffer at 0x4000 during 2.5s and go on.

   
while(1) {
   // Draw the ByteRealms logo at its current Y location on the screen. Moving
   // the logo does not leave a trail because we move it pixel to pixel and the
   // sprite has a 0x00 frame around it in its pixel definition.
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 10, br_y);  // Locate sprite at (10,br_y) in Default Video Memory
   cpct_drawSprite(G_BR, pvmem, BR_W, BR_H);       // Draw the sprite

   // Change video memory page (from Screen Memory to Back Buffer and vice-versa)
   // every 2.5 secs (125 VSYNCs)
   changeVideoMemoryPage(125);



ronaldo

Quote from: voxbremen on 10:59, 16 September 22Changing the CPCtelera 1.5 VM settings to English

I finally got around to trying CPCtelera - great work, and a big thank you to all involved.
I used the VM mentioned above with version 1.5, however, as some have noted before that is configured in Spanish, which makes it a bit difficult to use for non native speakers.


You are quite right, man. I'm usually doing everything in English except my lessons and didn't think of the language configuration of the VM.

Thank you very much for sharing your steps to changing it into English. That will be useful for many users until I add a version already configured in English. Hope that will be much more comfortable for non-Spanish speakers :).

ronaldo

Quote from: ivavilagu on 15:49, 19 September 22Hi,

I want to get some random numbers using cpctelera functions. Usually PC time is used to seed algorithm but doesn´t work in cpctelera.

Well, that's because there is no PC time on the CPC :). Time library in PC relies on the clock() and that relies on the Operative System. However, when you program games for the CPC, you usually disable the firmware, which is "sort of" the "Operative System" of the CPC. You do that because the firmware consumes both CPU and RAM space and introduces many restrictions we don't usually want when programming games. The firmware would be the one responsible for keeping up the TIME value, through counting interrupts (300 Hz). Moreover, in order for you to be able to use time.h header, CPCtelera (or your code) should implement the functions that return the TIME, because these functions should ask for it to CPC's firmware. Of course, the compiler vendor does not have versions implemented for the CPC firmware. CPCtelera does not have these functions implemented because they would require you to use the firmware, which you usually don't want to.

So, as @SpDizzy already pointed you, you need a different source of entropy than the system TIME, to initialize the SEED of the pseudo-random number generator. Importantly, as @reidrac says, you only need to do this once. You can imagine the random number generator as an algorithm that organizes all the numbers in a unique circular sequence. The SEED gives the algorithm the starting point in this sequence. After that moment, the algorithm just moves to the next element in the sequence and returns some bits of that number to you. These bits returned are used as a number, and they have some statistical properties measured, that make it reasonably impredictable (i.e. random). Don't worry about the sequence being circular and repeating. It indeed does repeat, but only after 4.294.967.295 iterations (2³²-1). For practical effects on an Amstrad Game, you may consider it never repeating (unless you use it intensively for procedurally generating vast worlds or something similar).

Quote from: ivavilagu on 16:57, 19 September 22I don´t like to add libraries due to memory limitations but the random generation is in the initialization project, no keys pressed still. The code has not user action from the beginning until random number requeried.

Another interesting thing you should know. When you use CPCtelera functions, you only "pay" for what you use. In your final binary, only the functions you actually use will be included. In fact, the whole library would be impossible, as it takes more than 100KB.

However, if you include C header files, that would most probably link with parts of libc, adding function definitions to your binary. Specially, using things like printf or sprintf are greatly painful, as they take up to 4-6KB of space. Use C standard library with care, only for things you really need.

Powered by SMFPacks Menu Editor Mod