News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

loop is only run once at cpctelera

Started by funkheld, 18:45, 21 July 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

funkheld



hello good day.

why will this loop only run once at cpctelera?

thank you
greeting


//-----------------------------LICENSE NOTICE------------------------------------
//  This file is part of CPCtelera: An Amstrad CPC Game Engine
//  Copyright (C) 2015 ronaldo / Fremos / Cheesetea / ByteRealms (@FranGallegoBR)
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------


#include <cpctelera.h>


void screenasm(u8 *pAddress, u8 dat)
{
__asm
LD L, 4(IX)
LD H, 5(IX)
LD C, 6(IX)
LD (HL),A
__endasm;
}


void main(void) {
  u16 nByte = 0;
  u16 adr;
  u8 z;
 
__asm
ld   a, #2
call   #0xBC0E
__endasm;
 
  z = 129;


  adr=0xc000;
  for(nByte = 0; nByte < 0x3FFF; nByte++)
  {
    screenasm(adr+nByte,z);
  }
 
  while(1);
}

mahlemiut

- Barry Rodewald

ronaldo

#2
Quote from: funkheld on 18:45, 21 July 20
why will this loop only run once at cpctelera?

void screenasm(u8 *pAddress, u8 dat)
{
__asm
LD L, 4(IX)
LD H, 5(IX)
LD C, 6(IX)
LD (HL),A
__endasm;
}

Simply because you are messing things up with code I believe you do not quite comprehend. You should never do this. Using inline-asm with IX as stack-pointing register is deprecated in SDCC since version 2.6 (and CPCtelera includes version 3.6.8 ) . IX is not guaranteed to point to the base of the frame of your function (in fact, here it won't be), so you are getting a random address into HL and then writting a random byte (A) into it. You are also loading a random byte into C register to no effect. Therefore, this code makes absolutetly no sense at all.

Moreover, don't know why you would like to use a function to load a value into a memory address. You can easily do that using a pointer an writting into where it points to:

u8* pmemory = (u8*) 0xBFFF;
u8 value = 129;
do {
   ++pmemory;
   *pmemory = value;
} while (pmemory != 0xFFFF);

That's normal way to do it in C and it converts to straight-forward asm. There is no point at all to do this in the way you are trying to do it.

So, again, I give you the same advice of last time: you need to invest more time in learning. And learning means knowing what your current level is and doing exercises, problems and projects adjusted to your current level. Do not try to use code you do not fully understand. If you do not understand something, either invest time into fully understanding it or discard it. There is nothing good to be gained on using code you don't master: the only thing you will obtain is behaviour that you don't comprehend and then an impossibility for you to track origins and make changes you desire.

If you really want to progress, start with simple things adjusted to your current level of mastery. Progress from that to slightly more complex things only when you fully master what you are already doing. Otherwise, you will continue writting 3/4 posts a day with many things you do not comprehend, because you are working at a level much higher than your current abilities. Summarizing: don't try to make a long jump of 8 metters in your first training session. This is the best advice I can give you.

funkheld

#3

how can you pass variables to an asm in the same c program?



the demos are from here:
http://www.cpcmania.com/Docs/Programming/Programming.htm

how else should you learn sdcc?

thank you

ervin

Yes. What ronaldo said just above is THE BEST advice possible for someone learning a new programming language.

funkheld

#5

what should you learn from if all the tips are no longer correct. there is nothing from sdcc in the bible and I have it at home.


help for the cpctelera :



void drawLine(u16 x1, u16 y1, u16 x2, u16 y2) {
x1;x2;y1;y2;
__asm
  ld e,8(ix)
  ld d,9(ix)
  ld l,10(ix)
  ld h,11(ix)
  call 0xbbc0; Move to x1, y1
  ld e,4(ix)
  ld d,5(ix)
  ld l,6(ix)
  ld h,7(ix)
  call 0xbbf6; Draw to x2, y2
  ret
__endasm;
}


thanks.

greeting

ronaldo

#6
Quote from: funkheld on 18:21, 22 July 20
what should you learn from if all the tips are no longer correct. there is nothing from sdcc in the bible and I have it at home.
thanks.
greeting

You are using inappropriate sources for learning. That's not tips being incorrect, that's a bad selection of outdated sources. You have a folder in CPCtelera full of examples to start. You don't need inline assembly as a starting point. In fact, you are constantly asking about things that are not from CPCtelera: you are asking on how to program, how to use SDCC compiler and how to call CPC firmware functions. All of this is not CPCtelera: this is programming the CPC. It has nothing to do with CPCtelera. CPCtelera is just providing you the compiler and the build system.

My Youtube channel is full of videos in which I teach how to program the CPC using CPCtelera also (This list is for programming in C, for instance). They are in Spanish, but you can use them as sources for learning assembly and C programming for the Amstrad (either just by looking at the images or using automatic translation, which is far from perfect, but may be worthwhile). Another thing you need to learn is who calling conventions work, and which calling conventions does SDCC use if you want to create assembly functions.

As I told you before, you should start with examples up to your level. Start with drawing and moving a sprite using CPCtelera. You have ready-to-use examples in the examples folder. Why not to start playing with some of them? Why start inlining assembly, doing everything lowlevel and by-hand? If that is what you want to learn, you may think of assembly programming tutorials and books. You can also program assembly directly with CPCtelera.

In this example you have the very same mistake you had in the previous example. SDCC does not put IX pointing to the frame base of the stack anymore. Therefore, you are simply filling your registers with random values, as IX will be pointing anywere (probably to 0000 in this example). This fails exactly the same way as your previous example failed, and you are gaining nothing by copying/pasting these examples one by one without knowing what happens. It's much preferable that you start with C examples (like those in CPCtelera folder) that do not require you to know about assembly calling conventions and how the compiler works.

Anyway, a proper version of this example would be this one:

void BasicMove(u16 x, u16 y) __naked __z88dk_callee {
    x;y;
    __asm
        pop hl
        pop de
        ex  (sp), hl
        jp 0xBBC0
    __endasm;
}

void BasicDraw(u16 x, u16 y) __naked __z88dk_callee {
    x;y;
    __asm
        pop hl
        pop de
        ex  (sp), hl
        jp 0xBBF6
    __endasm;
}

void drawLine(u16 x1, u16 y1, u16 x2, u16 y2) {
    BasicMove(x1,y1);
    BasicDraw(x2,y2);
}

int main() {
    drawLine(0,0,100,25);
    drawLine(0,50,100,25);
    drawLine(0,150,100,25);
    while(1);
}


So, for proper learning:

       
  • SDCC is a C compiler. Most important part is programming in C, not in SDCC. Learning should be: first master C, then carefully read SDCC manual.
  • CPCtelera is a build system + a low-level library. If you know how to program in C, you can use it from the start. No need for assembly: just call CPCtelera functions, like in the examples. Use the examples as a start point for learning, then go to the documentation to understand what the functions do. Then use them in your own creative ways
  • For amstrad CPC Firmware calls (like BBC0 and BBF6) you can read in the Firmware manual.
  • For Z80 assembly you have many books on the subject, and many of them also dedicated to the Amstrad. There are many of such resources here in the forum.
  • Finally, if you know assembly, C, calling conventions, Amstrad internals and know how SDCC internally works, then you can write your own assembly functions to be called from C. This is, by far, the most difficult and final part of the way. And you are trying to start from here.
Complementary, there is all the videos from my own youtube channel and others (like Keith / Chibi Akumas, for instance) and many other resources that you may use.

funkheld

#7

Hi good afternoon.

thank you for your helpful learning method.
will now only devote myself to cpctelera soon.
I'll watch your videos and read on in cpctelera.

you're right, this inline method can be pushed back completely. there are a lot of commands in cpctelera for that
to get to know cpc-system.



the method of your inline example above is
one thing i will save.

thank you.
greeting

Powered by SMFPacks Menu Editor Mod