is a 128/48k test avilable

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

is a 128/48k test avilable

Post by cborn »

Hello
does z88dk have a variable a routine to test in which type off zx the routine is?

mine seems not to work since even with a char i get a 5digit number some how

Code: Select all

 int zxtype() // simple test for zx-type 48k or 128k
 {
 char a ;
 int *p ;
 int address= 2898 ;
 char *type ;

 p = &address ;
 a = *p;
//switch(a)??
if ( a== 214) { type = 48;}
if ( a== 195) { type =128;}

return type ;
 }
 
 void main()
{
static char bitstr[9]="00000000" ;
int page = 20 ;

printf("\xC") ;  //cls

printf("found an %uK Zx Spectrum\n\n", zxtype ) ;


//psysvar( sysvar48[0].offset , sysvar48[0].nbyte , bitstr , page ) ;

//preskey(0);

return ;


}
//-------------------------------------------------
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: is a 128/48k test avilable

Post by dom »

There's a couple of ways to do this:

Code: Select all

#include <arch/zx.h>

// 0 = 48k
// 1 = 128k
// 2 = TS2068
extern int zx_type();


// 0 - unknown
// 1 = 48k
// 2 = 128/+2
// 3 = +2a/pentago
// 4 = +3
// 5 = +2a or +3 fixed for games
// 6 = TS2068
extern int zx_model();

// 0 = Issue 1,2
// 1 = Issue 3 or higher
extern int zx_issue3();

// 0 = Not a 128k or in 48k mode
// 1 = Spectrum is 128k in 128k mode
extern int zx_128mode();

cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

Thank you
my first reaction is that i should have searched for 'zx_type'
so i did now and only get results for 'test' or 'zx'. I know the underscore is used as replacement for the dot
but as a search line it should not be broken up in my opinion. at least not EXcluded !!
this means that MANY (standard) names off routines are broken up, ALWAYS
Its the same thing as with "the new red car got shy", you will never find that frase since its all 3 letter words which in many many time are totaly excluded...

now i go check all those type test becouse i need one for my sysvar checker
cheers
chris
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

here the 3 letter search DOES work , jippie!
https://www.z88dk.org/forum/search.php? ... ed+car+got+
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

Hi
i got some error, which -clib should i use? or at which page can i read about the different libs availble , i am reading the MD files.

zcc +zx -vn -clib=sdcc_iy -startup=31 zxsv05h.c -o zxsv05h -lndos -create-app -lm
sh: 1: zsdcpp: not found

zcc +zx -vn -startup=31 zxsv05h.c -o zxsv05h -lndos -create-app -lm
zxsv05h.c: line 45: file 'arch/zx.h' not found
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: is a 128/48k test avilable

Post by dom »

It should be available with either:

Code: Select all

zcc +zx -vn  zxsv05h.c -o zxsv05h -lndos -create-app -lm

-or-

zcc +zx -vn  zxsv05h.c -o zxsv05h -lndos -create-app -lm -compiler=ddcc
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

Hi,
thanks, but it still does not work. actualy i tried the first example already before asking
its the file from my/the varlist tread https://www.z88dk.org/forum/viewtopic.p ... 98#p19898
if i exclude the #include and zx_type with // marks it will compile with the first compile command

Code: Select all

$ zcc +zx -vn  zxsv05h3b.c -o zxsv05h3b -lndos -create-app -lm
zxsv05h3b.c: line 51: file 'arch/zx.h' not found
$ zcc +zx -vn  zxsv05h3b.c -o zxsv05h3b -lndos -create-app -lm  -compiler=sdcc
sh: 1: zsdcpp: not found
chris@cb:~/Desktop/try-C/c_in_zx/sysvars$ 

User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: is a 128/48k test avilable

Post by dom »

I'm sorry I was wrong. Due to a historical quirk that's not the name of the header (even though it should be), it's actually <spectrum.h>

In the spirit of teaching fishing:

1. Not everything is documented nicely on the wiki
2. Not everything is documented nicely in header files

So it's good to learn how to search through the header files to combat 1, and to find the implementation in libsrc to address 2.

Although find and grep are pretty easy to use, I find using VScode and using its search functionality can make life easier.
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

Hi, well its a long work_in_progress
actually yesterday i looked for spectrum.h and found the directives and target etc upto zx_type.asm
and the historical part is the naming it self i asume. as 'zx' its next to zx80,zx81 etc

but mean while i seem not to have a decent 'zsdcpp'.
last week i was looking to update and did a install instead, it was not planned. i let it run , but could a file be wiped?
sudo ./build.sh -e -C
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

hi
after removing <arch/zx.h> it works again. the accidental reinstall has no other results. nice.
Yet now i get a 16bit answer aswell ... i do someting wrong with the %d vs %u aperently

meanwhile an other mistery rose after making:

Code: Select all

void zx_time(){
// do the longs need pointers ?? TODO make zx_real_time() or zx_rtime()
unsigned long clock;   // /50= 
unsigned long clk50;   //       clk50= clock % 50  ( modulo 50)
unsigned long seconds; // /60=
unsigned long sec60;   //       sec60= seconds % 60
unsigned long minutes; // /60=
unsigned long min60;   //       min60= minutes % 60
unsigned long hours;   // /24=
unsigned long hor24;   //       hor24= hours   % 24
unsigned long days;    // its a 24 bit 'only', days can be char
// modulo MONTH of 28,29,30 or 31 days

         clock = FRAMES & 0x00FFFFFF ; //fetch FRAME when needed aka 'now'
         clk50 = clock % 50 ;
         seconds = clock / 50 ;
         sec60  = seconds % 60 ;
         minutes= seconds / 60 ;
         min60= minutes % 60 ;
         hours= minutes / 60 ;
         hor24= hours  % 24 ;
         days = hours  / 24 ;    // its a 24 bit 'only', days can be char

         printf("%lud: %luh: %lum: %lus: %lufr\n", days ,hor24 , min60 , sec60 , clk50 );

//make a string ??
         return ;
}
it does NOT print the time

while when i put it just in the middle it DOES:

Code: Select all

      case 'T' : // 24bit aka 'time' or 'frames'


unsigned long clock;   // /50= 
unsigned long clk50;   //       clk50= clock % 50  ( modulo 50)
unsigned long seconds; // /60=
unsigned long sec60;   //       sec60= seconds % 60
unsigned long minutes; // /60=
unsigned long min60;   //       min60= minutes % 60
unsigned long hours;   // /24=
unsigned long hor24;   //       hor24= hours   % 24
unsigned long days;    // its a 24 bit 'only', days can be char
// modulo MONTH of 28,29,30 or 31 days

         clock = FRAMES & 0x00FFFFFF ; //fetch FRAME when needed aka 'now'
         clk50 = clock % 50 ;
         seconds = clock / 50 ;
         sec60  = seconds % 60 ;
         minutes= seconds / 60 ;
         min60= minutes % 60 ;
         hours= minutes / 60 ;
         hor24= hours  % 24 ;
         days = hours  / 24 ;    // its a 24 bit 'only', days can be char



         printf("%6u %8s %3u %s %9lu  ", sysadr , sysnm , syslen ,  systype , clock ) ;
         for (f=0 ; f< syslen ; f++ )
            {
             sysadr2 = sysadr +  f ;
             syschar = *sysadr2 ;
             printf("%4u", syschar );
             if (f<syslen-1) printf(",");
            }
         printf("\n");
//works
         printf("%lud: %luh: %lum: %lus: %lufr\n", days ,hor24 , min60 , sec60 , clk50 );
//works NOT
         zx_time ;

         printf("\n");
         break;

www.cborn.nl/c/zxsv05i5.c
www.cborn.nl/c/zxsv05i5.tap
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

its
zx_time()
then it works.
and about zx_time
wel, that needs a () to.
there was no error message so forgetting the () leads to some official c.
is it the adres ?
wel, solved().
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: is a 128/48k test avilable

Post by dom »

I created a short example from your snippet:

Code: Select all

#include <stdio.h>

static __at(23672) unsigned long FRAMES ; // outside 'main' is that 'static' ??


void zx_time(){
// do the longs need pointers ?? TODO make zx_real_time() or zx_rtime()
unsigned long clock;   // /50=
unsigned long clk50;   //       clk50= clock % 50  ( modulo 50)
unsigned long seconds; // /60=
unsigned long sec60;   //       sec60= seconds % 60
unsigned long minutes; // /60=
unsigned long min60;   //       min60= minutes % 60
unsigned long hours;   // /24=
unsigned long hor24;   //       hor24= hours   % 24
unsigned long days;    // its a 24 bit 'only', days can be char
// modulo MONTH of 28,29,30 or 31 days

         clock = FRAMES & 0x00FFFFFF ; //fetch FRAME when needed aka 'now'
         clk50 = clock % 50 ;
         seconds = clock / 50 ;
         sec60  = seconds % 60 ;
         minutes= seconds / 60 ;
         min60= minutes % 60 ;
         hours= minutes / 60 ;
         hor24= hours  % 24 ;
         days = hours  / 24 ;    // its a 24 bit 'only', days can be char

         printf("%lud: %luh: %lum: %lus: %lufr\n", days ,hor24 , min60 , sec60 , clk50 );

//make a string ??
         return ;
}

int main() {
        while( 1) {
                sleep(2);
                zx_time();
        }
}
Which after running for a while yielded this screenshot:
Time running on +zx
Which shows broadly what I'd expect: FRAMES holds the number of 20 millisecond ticks since the machine was turned on.

Moving onto zsdcc. I think from your screenshots you're on a unix like system, in which case you need to follow the instructions on how to install zsdcc: https://github.com/z88dk/z88dk/wiki/ins ... inux--unix

For speed of installation you will want to do the following before starting compiling:

Code: Select all

export BUILD_SDCC=1
export BUILD_SDCC_HTTP=1
These options will first of all enable the building of sdcc and the second one will download a patched tarball rather than clone from the sdcc SVN repository (which can be very, very slow)
You do not have the required permissions to view the files attached to this post.
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

Thank you for your example, its almost a clock now
and i better reinstall indeed.
thank you!
c
cborn
Well known member
Posts: 267
Joined: Tue Oct 06, 2020 7:45 pm

Re: is a 128/48k test avilable

Post by cborn »

Code: Select all



// 1 second = 50 frames or interrupts
// 3bytes time = 0xffffff = 16777215 frames
// @50hz =
// long clock         /50 =   335544.3    > 0.3   *50 =15 frames  left over
// long seconds 335544/60 =     5592.4    > 0.4   *60 =24 seconds left over
// long minutes   5592/60 =       93.2    > 0.2   *60 =30 minutes
// long hours       93/24 =        3.875  > 0.875 *24 =21 hours
// long days         3/ 1 =        3      > 3     * 1 = 3 days
// = 03d:21h:30m:24s:15fr  max time to be counted

// on 128k spectrum 1 tstate = 1/3,546,900 = 0.000,000,282 second  1/3.546900=0.281936339 >>0.000000281936339
// 3.546.900Hz / 70908 Tstate = 50.021154171603 ;https://www.calculator.net/fraction-calculator.html?c3t1=3546900&c3b1=70908&ctype=3&x=76&y=30#fraction2decimal
// 50.021154171603 x 1000 = 50021.154171603 gives 21 (plus) interrupts
// to much for real 50hz interrupt clock in 1000 seconds

// on 48k spectrum 1 tstate  = 1/3,500,000 = 0.000,000,286 second  1/3.500000=0.285714286 >>0.000000285714286
// 3.500.000Hz / 69888 Tstate= 50.08012821                         
// 50.08012821 x 1000 = 50080.12821 gives 80 (plus) interrupts   
// to much for real 50hz interrupt clock in 1000 seconds



Post Reply