looking for sysvar list

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
cborn
Member
Posts: 25
Joined: Tue Oct 06, 2020 7:45 pm

looking for sysvar list

Post by cborn »

Hi,
is there a system variable list somewhere ?
I was experimenting a bit for a sysvar viewer but probably such sysvar list already exsist.

I had a little struggle to make mine since i want it al 'int' or al 'char' since that is easier to use.
but a char is 8bits and valid for a single byte sysvar and int is 16bit and valid for a doublebyte sysvar

this is my TEST and a bit off nonsence

Code: Select all

 /* zcc +zx -vn sysRAM017.c -o sysRAM017 -lndos -create-app */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

unsigned int sysword(unsigned char *a[])
 {
  int word;
  word = (int)*a[0]  +256 * (int)*a[1] ;
  printf("x: %d %d %d \n", *a[0], *a[1], word);
  return word ;
 }

int sword(unsigned char *a , unsigned char *b)
 {
  unsigned int word = *a  +256 * *b  ;
  return word ;
 }

//  - - - - - - - - - - - - - - -

int sysvar()
{
unsigned int rmtp , rmtop ,mrtop ;
unsigned char  *RAMTOP     = 23730 ;
unsigned char  *RAMTOP2    = 23731 ;
unsigned char  *RAMTP[2]   = 23730 ;
unsigned int   *_RAMTOP    = 23730 ;
rmtp =*RAMTOP  +256 * *RAMTOP2  ;
rmtop=*RAMTP[0]+256 * *RAMTP[1] ;
mrtop=RAMTP ;

printf("\xC");  //cls
printf("a:\n  char *RAMTOP  %3d\n  RAMTOP  %3d\n", *RAMTOP , RAMTOP ) ;
printf("  char *RAMTOP2 %3d\n  RAMTOP2 %3d\n", *RAMTOP2, RAMTOP2 ) ;
printf("  int rmtp=*RAMTOP   +256 * *RAMTOP2 =  %5d\n", rmtp ) ;
printf("  int mrtop=RAMTOP  %5d\n", mrtop ) ;
printf("b:\n  char *RAMTP[0] %3d\n  RAMTP[0] %3d\n", *RAMTP[0] , RAMTP[0] ) ;
printf("  char *RAMTP[1] %3d\n  RAMTP[1] %3d\n", *RAMTP[1] , RAMTP[1] ) ;
printf("  int rmtop=*RAMTP[0]+256 * *RAMTP[1] =  %5d\n", rmtop ) ;
printf("c:\n  int *_RAMTOP %5d  _RAMTOP %5d\n",  *_RAMTOP ,  _RAMTOP ) ;
printf("d: sysword( *RAMTP  )           %5d \n",sysword(*RAMTP) ) ;
printf("e: sysword( *_RAMTOP)           %5d \n",sysword(*_RAMTOP) ) ;
printf("f: sword(*RAMTOP   , *RAMTOP2 ) %5d \n",sword(*RAMTOP   , *RAMTOP2   ) ) ;
printf("g: sword(RAMTOP    , RAMTOP2 )  %5d \n",sword(RAMTOP   , RAMTOP2   ) ) ;
printf("h: sword(RAMTP[0] , RAMTP[1]) %5d \n",sword(RAMTP[0] , RAMTOP[1] ) ) ;
return ;
}
//--------------------------------------
void main()
{
sysvar();
return ;
}
so now i have this:

Code: Select all

 /* zcc +zx -vn sysRAM018.c -o sysRAM018 -lndos -create-app */
 #include <stdio.h>
 #include <stdlib.h>
 
int sysword(unsigned char *a , unsigned char *b)
 {
  unsigned int sysword = *a  +256 * *b  ;
  return sysword ;
 }
//  - - - - - - - - - - - - - - -
int sysvar()
{
unsigned char  *RAMTOP1 = 23730 ;
unsigned char  *RAMTOP2 = 23731 ;
int RAMTOP= sysword(RAMTOP1 , RAMTOP2 );
printf("RAMTOP =%6d", RAMTOP );
return ;
}
//--------------------------------------
void main()
{
printf("\xC");  //cls
sysvar();
return ;
}
probably a bit to much for a 16bit value, but now they are all defined as CHAR and per adres reachable.
int *ramtop=23730; is shorter, but you cant fit a 8bit value in it as like with SCRCT needed , far as i understood.
probably i do to much, as usual.
like (edited):

Code: Select all

  /* zcc +zx -vn sysvar027.c -o sysvar027 -lndos -create-app */

 #include <stdio.h>

int sysword(unsigned char *a , unsigned char *b)
 {
  unsigned int sysword = *a  +256 * *b  ;
  return sysword ;
 }

//  - - - - - - - - - - - - - - -
int sysvar()
{
unsigned char  *KSTATE0 = 23552 ;
unsigned char  *KSTATE1 = 23553 ;
unsigned char  *KSTATE2 = 23554 ;
unsigned char  *KSTATE3 = 23555 ;
unsigned char  *KSTATE4 = 23556 ;
unsigned char  *KSTATE5 = 23557 ;
unsigned char  *KSTATE6 = 23558 ;
unsigned char  *KSTATE7 = 23559 ;

unsigned char  *LASTK   = 23560 ;
printf("LASTK  =%6d\n", *LASTK );

unsigned char  *REPDEL  = 23561 ;
printf("REPDEL =%6d\n", *REPDEL );

unsigned char  *REPPER  = 23562 ;
printf("REPPER =%6d\n", *REPPER );

unsigned char  *DEFADD1 = 23563 ;
unsigned char  *DEFADD2 = 23564 ;
int DEFADD= sysword(DEFADD1 ,DEFADD2 );
printf("DEFADD =%6d\n", DEFADD );

unsigned char  *KDATA   = 23565 ;
printf("KDATA  =%6d\n", *KDATA );

unsigned char  *TVDATA1 = 23566 ;
unsigned char  *TVDATA2 = 23567 ;
int TVDATA= sysword(TVDATA1 ,TVDATA2 );
printf("TVDATA =%6d\n", TVDATA );

unsigned char  *STRMS00 = 23568 ; // #-3 or #fd
unsigned char  *STRMS01 = 23569 ;
unsigned char  *STRMS02 = 23570 ; // #-2 or #fe
unsigned char  *STRMS03 = 23571 ;
unsigned char  *STRMS04 = 23572 ; // #-1 or #ff
unsigned char  *STRMS05 = 23573 ;
unsigned char  *STRMS06 = 23574 ; // #0
unsigned char  *STRMS07 = 23575 ;
unsigned char  *STRMS08 = 23576 ; // #1
unsigned char  *STRMS09 = 23577 ;
unsigned char  *STRMS10 = 23578 ; // #2
unsigned char  *STRMS11 = 23579 ;
unsigned char  *STRMS12 = 23580 ; // #3
unsigned char  *STRMS13 = 23581 ;
unsigned char  *STRMS14 = 23582 ; // #4
unsigned char  *STRMS15 = 23583 ;
unsigned char  *STRMS16 = 23584 ; // #5
unsigned char  *STRMS17 = 23585 ;
unsigned char  *STRMS18 = 23586 ; // #6
unsigned char  *STRMS19 = 23587 ;
unsigned char  *STRMS20 = 23588 ; // #7
unsigned char  *STRMS21 = 23589 ;
unsigned char  *STRMS22 = 23590 ; // #8
unsigned char  *STRMS23 = 23591 ;
unsigned char  *STRMS24 = 23592 ; // #9
unsigned char  *STRMS25 = 23593 ;
unsigned char  *STRMS26 = 23594 ; // #10
unsigned char  *STRMS27 = 23595 ;
unsigned char  *STRMS28 = 23596 ; // #11
unsigned char  *STRMS29 = 23597 ;
unsigned char  *STRMS30 = 23598 ; // #12
unsigned char  *STRMS31 = 23599 ;
unsigned char  *STRMS32 = 23600 ; // #13
unsigned char  *STRMS33 = 23601 ;
unsigned char  *STRMS34 = 23602 ; // #14
unsigned char  *STRMS35 = 23603 ;
unsigned char  *STRMS36 = 23604 ; // #15
unsigned char  *STRMS37 = 23605 ;

unsigned char  *CHARS1  = 23606 ;
unsigned char  *CHARS2  = 23607 ;
int CHARS= sysword(CHARS1 ,CHARS2 );
printf("CHARS  =%6d\n", CHARS );

unsigned char  *RASP    = 23608 ;
printf("RASP   =%6d\n", *RASP );

unsigned char  *PIP     = 23609 ;
printf("PIP    =%6d\n", *PIP );

unsigned char  *ERRNR   = 23610 ;
printf("ERRNR  =%6d\n", *ERRNR );

unsigned char  *FLAGS   = 23611 ; //
printf("FLAGS  =%6d\n", *FLAGS );

unsigned char  *TVFLAGS = 23612 ; //
printf("TVFLAGS=%6d\n", *TVFLAGS );

unsigned char  *ERRSP1  = 23613 ;
unsigned char  *ERRSP2  = 23614 ;
int ERRSP= sysword(ERRSP1 ,ERRSP2 );
printf("ERRSP  =%6d\n", ERRSP );

unsigned char  *LISTSP1 = 23615 ;
unsigned char  *LISTSP2 = 23616 ;
int LISTSP= sysword(LISTSP1 ,LISTSP2 );
printf("LISTSP =%6d\n", LISTSP );

unsigned char  *MODE    = 23617 ; //
printf("MODE   =%6d\n", *MODE );

unsigned char  *NEWPPC1 = 23618 ;
unsigned char  *NEWPPC2 = 23619 ;
int NEWPPC= sysword(NEWPPC1 ,NEWPPC2 );
printf("NEWPPC =%6d\n", NEWPPC );

unsigned char  *NSPPC   = 23620 ;
printf("NSPPC  =%6d\n", *NSPPC );

unsigned char  *PPC1    = 23621 ;
unsigned char  *PPC2    = 23622 ;
int PPC= sysword(PPC1 ,PPC2 );
printf("PPC    =%6d\n", PPC );

unsigned char  *SUBPPC  = 23623 ;
printf("SUBPPC =%6d\n", *SUBPPC );

unsigned char  *BORDCR  = 23624 ;
printf("BORDCR =%6d\n", *BORDCR );

unsigned char  *EPPC1   = 23625 ;
unsigned char  *EPPC2   = 23626 ;
int EPPC= sysword(EPPC1 ,EPPC2 );
printf("EPPC   =%6d\n", EPPC );

unsigned char  *VARS1   = 23627 ;
unsigned char  *VARS2   = 23628 ;
int VARS= sysword(VARS1 ,VARS2 );
printf("VARS   =%6d\n", VARS );

unsigned char  *DEST1   = 23629 ;
unsigned char  *DEST2   = 23630 ;
int DEST= sysword(DEST1 ,DEST2 );
printf("DEST   =%6d\n", DEST );

unsigned char  *CHANS1  = 23631 ;
unsigned char  *CHANS2  = 23632 ;
int CHANS= sysword(CHANS1 ,CHANS2 );
printf("CHANS  =%6d\n", CHANS );

unsigned char  *CURCHL1 = 23633 ;
unsigned char  *CURCHL2 = 23634 ;
int CURCHL= sysword(CURCHL1 ,CURCHL2 );
printf("CURCHL =%6d\n", CURCHL );

unsigned char  *PROG1   = 23635 ;
unsigned char  *PROG2   = 23636 ;
int PROG= sysword(PROG1 ,PROG2 );
printf("PROG   =%6d\n", PROG );

unsigned char  *NXTLIN1 = 23637 ;
unsigned char  *NXTLIN2 = 23638 ;
int NXTLIN= sysword(NXTLIN1 ,NXTLIN2 );
printf("NXTLIN =%6d\n", NXTLIN );

unsigned char  *DATADD1 = 23639 ;
unsigned char  *DATADD2 = 23640 ;
int DATADD= sysword(DATADD1 ,DATADD2 );
printf("DATADD =%6d\n", DATADD );

unsigned char  *ELINE1  = 23641 ;
unsigned char  *ELINE2  = 23642 ;
int ELINE= sysword(ELINE1 ,ELINE2 );
printf("ELINE  =%6d\n", ELINE );

unsigned char  *KCUR1   = 23643 ;
unsigned char  *KCUR2   = 23644 ;
int KCUR= sysword(KCUR1 ,KCUR2 );
printf("KCUR   =%6d\n", KCUR );

unsigned char  *CHADD1  = 23645 ;
unsigned char  *CHADD2  = 23646 ;
int CHADD= sysword(CHADD1 ,CHADD2 );
printf("CHADD  =%6d\n", CHADD );

unsigned char  *XPTR1   = 23647 ;
unsigned char  *XPTR2   = 23648 ;
int XPTR= sysword(XPTR1 ,XPTR2 );
printf("XPTR   =%6d\n", XPTR );

unsigned char  *WORKSP1 = 23649 ;
unsigned char  *WORKSP2 = 23650 ;
int WORKSP= sysword(WORKSP1 ,WORKSP2 );
printf("WORKSP =%6d\n", WORKSP );

unsigned char  *STKBOT1 = 23651 ;
unsigned char  *STKBOT2 = 23652 ;
int STKBOT= sysword(STKBOT1 ,STKBOT2 );
printf("STKBOT =%6d\n", STKBOT );

unsigned char  *STKEND1 = 23653 ;
unsigned char  *STKEND2 = 23654 ;
int STKEND= sysword(STKEND1 ,STKEND2 );
printf("STKEND =%6d\n", STKEND );

unsigned char  *BREG    = 23655 ;
printf("BREG   =%6d\n", *BREG );

unsigned char  *MEM1    = 23656 ;
unsigned char  *MEM2    = 23657 ;
int MEM= sysword(MEM1 ,MEM2 );
printf("MEM    =%6d\n", MEM );

unsigned char  *FLAGS_2 = 23658 ; //
printf("FLAGS_2=%6d\n", *FLAGS_2 );

unsigned char  *DFSZ    = 23659 ;
printf("DFSZ   =%6d\n", *DFSZ );

unsigned char  *S_TOP1  = 23660 ;
unsigned char  *S_TOP2  = 23661 ;
int S_TOP= sysword(S_TOP1 ,S_TOP2 );
printf("S_TOP  =%6d\n", S_TOP );

unsigned char  *OLDPPC1 = 23662 ;
unsigned char  *OLDPPC2 = 23663 ;
int OLDPPC= sysword(OLDPPC1 ,OLDPPC2 );
printf("OLDPPC =%6d\n", OLDPPC );

unsigned char  *OSPPC   = 23664 ;
printf("OSPPC  =%6d\n", *OSPPC );

unsigned char  *FLAGX   = 23665 ; //
printf("FLAGX  =%6d\n", *FLAGX );

unsigned char  *STRLEN1 = 23666 ;
unsigned char  *STRLEN2 = 23667 ;
int STRLEN= sysword(STRLEN1 ,STRLEN2 );
printf("STRLEN =%6d\n", STRLEN );

unsigned char  *TADDR1  = 23668 ;
unsigned char  *TADDR2  = 23669 ;
int TADDR= sysword(TADDR1 ,TADDR2 );
printf("TADDR  =%6d\n", TADDR );

unsigned char  *SEED1   = 23670 ;
unsigned char  *SEED2   = 23671 ;
int SEED= sysword(SEED1 ,SEED2 );
printf("SEED   =%6d\n", SEED );

unsigned char  *FRAMES1 = 23672 ;
unsigned char  *FRAMES2 = 23673 ;
unsigned char  *FRAMES3 = 23674 ;

unsigned char  *UDG1    = 23675 ;
unsigned char  *UDG2    = 23676 ;
int UDG= sysword(UDG1 ,UDG2 );
printf("UDG    =%6d\n", UDG );

unsigned char  *COORDX  = 23677 ;
unsigned char  *COORDY  = 23678 ;

unsigned char  *PPOSN   = 23679 ;
printf("PPOSN  =%6d\n", *PPOSN );

unsigned char  *PRCC1   = 23680 ;
unsigned char  *PRCC2   = 23681 ;
int PRCC= sysword(PRCC1 ,PRCC2 );
printf("PRCC   =%6d\n", PRCC );

unsigned char  *ECHOE1  = 23682 ;
unsigned char  *ECHOE2  = 23683 ;
int ECHOE= sysword(ECHOE1 ,ECHOE2 );
printf("ECHOE  =%6d\n", ECHOE );

unsigned char  *DFCC1   = 23684 ;
unsigned char  *DFCC2   = 23685 ;
int DFCC= sysword(DFCC1 ,DFCC2 );
printf("DFCC   =%6d\n", DFCC );

unsigned char  *DFCCL1  = 23686 ;
unsigned char  *DFCCL2  = 23687 ;
int DFCCL= sysword(DFCCL1 ,DFCCL2 );
printf("DFCCL  =%6d\n", DFCCL );

unsigned char  *SPOSUC  = 23688 ;
unsigned char  *SPOSUL  = 23689 ;
unsigned char  *SPOSLC  = 23690 ;
unsigned char  *SPOSLL  = 23691 ;

unsigned char  *SCRCT   = 23692 ;
printf("SCRCT  =%6d\n", *SCRCT );

unsigned char  *ATTRP   = 23693 ;
printf("ATTRP  =%6d\n", *ATTRP );
unsigned char  *MASKP   = 23694 ;
printf("MASKP  =%6d\n", *MASKP );

unsigned char  *ATTRT   = 23695 ;
printf("ATTRT  =%6d\n", *ATTRT );
unsigned char  *MASKT   = 23696 ;
printf("MASKT  =%6d\n", *MASKT );

unsigned char  *PFLAG   = 23697 ;
printf("PFLAG  =%6d\n", *PFLAG );

unsigned char  *MEMBOT00= 23698 ;
unsigned char  *MEMBOT01= 23699 ;
unsigned char  *MEMBOT02= 23700 ;
unsigned char  *MEMBOT03= 23701 ;
unsigned char  *MEMBOT04= 23702 ;
unsigned char  *MEMBOT05= 23703 ;
unsigned char  *MEMBOT06= 23704 ;
unsigned char  *MEMBOT07= 23705 ;
unsigned char  *MEMBOT08= 23706 ;
unsigned char  *MEMBOT09= 23707 ;

unsigned char  *MEMBOT10= 23708 ;
unsigned char  *MEMBOT11= 23709 ;
unsigned char  *MEMBOT12= 23710 ;
unsigned char  *MEMBOT13= 23711 ;
unsigned char  *MEMBOT14= 23712 ;
unsigned char  *MEMBOT15= 23713 ;
unsigned char  *MEMBOT16= 23714 ;
unsigned char  *MEMBOT17= 23715 ;
unsigned char  *MEMBOT18= 23716 ;
unsigned char  *MEMBOT19= 23717 ;

unsigned char  *MEMBOT20= 23718 ;
unsigned char  *MEMBOT21= 23719 ;
unsigned char  *MEMBOT22= 23720 ;
unsigned char  *MEMBOT23= 23721 ;
unsigned char  *MEMBOT24= 23722 ;
unsigned char  *MEMBOT25= 23723 ;
unsigned char  *MEMBOT26= 23724 ;
unsigned char  *MEMBOT27= 23725 ;
unsigned char  *MEMBOT28= 23726 ;
unsigned char  *MEMBOT29= 23727 ;

unsigned char  *NONAME1 = 23728 ;
unsigned char  *NONAME2 = 23629 ;
int NONAME= sysword(NONAME1 ,NONAME2 );
printf("NONAME =%6d\n", NONAME );

unsigned char  *RAMTOP1 = 23730 ;
unsigned char  *RAMTOP2 = 23731 ;
int RAMTOP= sysword(RAMTOP1 , RAMTOP2 );
printf("RAMTOP =%6d\n", RAMTOP );

unsigned char  *PRAMT1  = 23632 ;
unsigned char  *PRAMT2  = 23633 ;
int PRAMT= sysword(PRAMT1 , PRAMT2 );
printf("PRAMT  =%6d\n", PRAMT  );

return ;
}


//--------------------------------------

void main()
{
printf("\xC");  //cls
sysvar();
printf("\n\n\n");
return ;
}
any comment is very welcome
cborn
Member
Posts: 25
Joined: Tue Oct 06, 2020 7:45 pm

Re: looking for sysvar list

Post by cborn »

Hello
The return value from all unsigned ints and chars still is a signed integer.
what do i do wrong?

Code: Select all

 /* zcc +zx -vn sysRAM019.c -o sysRAM019 -lndos -create-app -zorg=50000 */
 #include <stdio.h>
unsigned int sysword(unsigned char *a , unsigned char *b)
 {
  unsigned int sysword = *a  +256 * *b  ;
  return sysword ;
 }
//  - - - - - - - - - - - - - - -
int sysvar()
{
unsigned char  *RAMTOP1 = 23730 ;
unsigned char  *RAMTOP2 = 23731 ;
unsigned int RAMTOP= sysword(RAMTOP1 , RAMTOP2 );
printf("RAMTOP =%6d", RAMTOP );
return ;
}
//--------------------------------------
void main()
{
printf("\xC");  //cls
printf("startadres set to 50000 at compile time,\n");
printf("RAMTOP has to be 49999 now.\n\n");
sysvar();
return ;
}
cborn
Member
Posts: 25
Joined: Tue Oct 06, 2020 7:45 pm

Re: looking for sysvar list

Post by cborn »

hmm
unsigned char *RAMTOP1 = 23730;

in my mind i set the memory location to 23730, but is not how it works.
an unknown memory location is filled with TWO bytes, as a 2byte string.
in gcc it will print 23730 with printf("%6d", RAMTOP1)
and give a segmentation error
or tells me i do some stupid with variating the source
sysRAM019.c:16:27: warning: initialization of ‘unsigned char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
unsigned char *RAMTOP1 = 23730 ;


so the 'c' system insist that i use an integer as pointer,
well, thats my conclusion.
and the difference for a 1 byte or 2 byte variable?
i hope to understand.
cborn
Member
Posts: 25
Joined: Tue Oct 06, 2020 7:45 pm

Re: looking for sysvar list

Post by cborn »

OK,
last message for now
i feel like a certain dog chacing its own tail.

Code: Select all

 /* zcc +zx -vn sysRAM_024.c -o sysRAM_024 -lndos -create-app -zorg=50000 */
 #include <stdio.h>
unsigned int sysword(unsigned char *a , unsigned char *b)
 {
  unsigned char x=*a , y=*b ;
  unsigned int sysword = x  +256 * y  ;
  return sysword ;
 }
//  - - - - - - - - - - - - - - -
int sysvar()
{
unsigned char  *RAMTOP1 = 23730 ;
unsigned char  *RAMTOP2 = 23731 ;
unsigned int *RMTP = 23730 ;

unsigned int RAMTOP= sysword(RAMTOP1 , RAMTOP2 );
unsigned int word ;

word =*RAMTOP1+ 256* *RAMTOP2 ;

printf(" RAMTOP1 =%6d\n", RAMTOP1 );

printf("*RAMTOP1 =%6d\n", *RAMTOP1 );

printf(" RAMTOP2 =%6d\n", RAMTOP2 );

printf("*RAMTOP2 =%6d\n", *RAMTOP2 );

printf(" RAMTOP  =%6d\n", RAMTOP  );

printf("*RAMTOP1 + 256* *RAMTOP2  =%6d\n", *RAMTOP1 + 256* *RAMTOP2  );

printf(" word  =%6d\n", word );

printf(" RMTP  =%6d\n", RMTP );

printf("*RMTP  =%6d\n", *RMTP );

return 0;
}
//--------------------------------------
void main()
{
printf("\xC");  //cls
printf("startadres set to 50000 at compile time,\n");
printf("RAMTOP has to be 49999 now.\n\n");
sysvar();
return ;
}
and in gcc
~/Desktop/try-C/c_in_zx/sysvars$ gcc sysRAM_024.c -o sysRAM024
sysRAM_024.c: In function ‘sysvar’:
sysRAM_024.c:17:27: warning: initialization of ‘unsigned char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
unsigned char *RAMTOP1 = 23730 ;
^~~~~
sysRAM_024.c:18:27: warning: initialization of ‘unsigned char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
unsigned char *RAMTOP2 = 23731 ;
^~~~~
sysRAM_024.c:19:22: warning: initialization of ‘unsigned int *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
unsigned int *RMTP = 23730 ;
^~~~~
~/Desktop/try-C/c_in_zx/sysvars$ ./sysRAM024

startadres set to 50000 at compile time,
RAMTOP has to be 49999 now.

Segmentation fault
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 1235
Joined: Sun Jul 15, 2007 10:01 pm

Re: looking for sysvar list

Post by dom »

You're printing with %d which prints the integer as if it is signed, if the value is unsigned you need to use %u.

Sometimes it's easier to look at the generated assembler to see what's going on if you're not too certain:

Code: Select all

unsigned int *RAMTOP = 23670;

__at(23670) unsigned int RAMTOP2;

unsigned int ramtop;

int main() {
        ramtop = *RAMTOP;

        ramtop = RAMTOP2;
}
Here we're doing the same thing in two different ways: using a pointer as you were using, the assignment of an integer is a little non-standard, but on a z80 sizeof(int) = sizeof(int *) so it's safe, and a fairly common paradigm. We're also using the (nonstandard) __at(NNN) placement syntax to demonstrate an alternate way of doing the same thing. This syntax indicates that a variable of the specified type is at the address indicated.

Compiling with the -a option yields:

Code: Select all

._RAMTOP
        defw    23670
        SECTION code_compiler

        ld      hl,(_RAMTOP)
        call    l_gint  ;
        ld      (_ramtop),hl
        ld      hl,(_RAMTOP2)
        ld      (_ramtop),hl
        ret

        SECTION bss_compiler
._ramtop        defs    2
        
        defc    _RAMTOP2     = 23670
The end effect is the same, l_gint does ld hl,(hl), however, using the __at syntax generates much better code and means that we don't need two bytes to hold the pointer.
cborn
Member
Posts: 25
Joined: Tue Oct 06, 2020 7:45 pm

Re: looking for sysvar list

Post by cborn »

thank %u

even the printing itselve has different behaviour.
just changing %d to %u does the job.

Now i can have a look at the extra home work.
thanks for explaining
and with _at() i can use the adres i insist to. thats a very nice feature.
Post Reply