i get an error message but i dont know why
~/Desktop/try-C/c_in_zx/farkle$ zcc +zx -vn dice_096c.c -o dice096c -lndos -create-app -zorg=32768
dice_096c.c:146:9: warning: Implicit definition of function 'memset' it will return an int. Prototype it explicitly if this is not what you want. [-Wimplicit-function-definition]
dice_096c.c:172:7: fatal error: Must be lvalue
Compilation aborted
Its becouse of the sort routine.
But it worked without any error when it was inside main().
Now i have separated it as a routine it suddenly insist on a 'lvalue' which was NOT any problem before.
Its a character array to be sorted with a very simple exchange sort.
I can replace it with other sortings i found, but those are INT based and this one is CHAR based .
https://www.tutorialride.com/c-programm ... amming.htm
in asm you just putin that value, but c insist on so much different ways of doing the same....
eg using %d or %c changes the BEHAVIOR of the scanf routine, i mean the BEHAVIOR of the routine is changed by using an INT or an CHAR
thats very anoying ...
what do i have to do extra to explain to C what i want ???
Code: Select all
/* C source start */
/* by chris born ad 2020 as homework for z88dk, farkle */
/* classic (not needed but BUILD_SDCC=0 or BUILD_SDCC=undefined) */
/* zcc +zx -vn dice_096c.c -o dice096c -lndos -create-app -zorg=32768 */
#include <spectrum.h>
#include <stdio.h>
#include <stdlib.h>
#include <input.h>
void rndseed() // not realy very random, still needs better one
{
#asm // uses HL, A, B register
di // 4t
ld hl,23672 // 10t raises only once in 69288 tstate with 1 per frame
ld a,r // 9t raises every ~4~24 tstate with 1 or maybe 2 per instruction , inner LDR , LDI instructions counted.
bit 0,a // 8t
jp z,r1 // 10t z=0=even
cpl //| 4t the value of 'r' now decreases instead of raising
jp n1 //| 10t odd is now even 0xff=0x00
r1:
inc a //~ 4t raise and even is now odd 0x00=0x01
jp n1 //~ 10t jp=only for timing sake here, DELAY
n1:
xor (hl) // 7t xor on FRAMES value
ld b,a // 4t
inc hl // 7t raise once per 256 FRAMES of 69288 = after ~5.5 seconds
ld a,r // 9t
bit 0,a // 8t
jp z,r2 // 10t z=0=even
rlca //| 4t
jp n2 //| 10t
r2:
rrca //~ 4t
jp n2 //~ 10t
n2:
xor (hl) // 7t
ld h,b // 4t
ld l,a // 4t
ld (23670),hl // 15t write new seed
ei // 4t
ret // 10t
#endasm // always(*) equal timing = 4+10+9+8+10 +4+10 +7+4+7+9+8+10 +4+10 +7+4+4 +15+4+10 =158 tstate
} // (*) in NON contended memory
//----------------------------------
void setrand()
{
rndseed() ;
char* sd = 23670 ;
srand(*sd) ;
}
//----------------------------------
int dice(int aods) // aods = amount of dice sides
{
// randomize() ;
char d = rand()%aods +1 ;
return d ;
}
//----------------------------------
void sortit(char h[] , int hod)
{
char t ;
int x ;
sorting:
t=0 ; // mind chr$0
for ( x=0 ; x < hod-1 ; x++ )
{
if ( h[x] > h[x+1] )
{
t = h[x] ;
h[x]=h[x+1] ;
h[x+1]=t ;
}
} //endx
if ( t != 0 ) { goto sorting ; }
return ;
}
//++++++++++++++++++++++++++++++++++
int main()
{
unsigned char x , number , hand[256] , hand2[256] , p8 , i8 , select[6][6] ;
int hand_of_dice , players , play , round , key , key2 , k , amount_of_dice_sides , all[256] ;
setrand() ;
zx_cls() ;
// printf("Give number of sides of dice:\n") ;
// scanf("%d", &amount_of_dice_sides) ;
amount_of_dice_sides=6 ;
// printf("how many dice do you want:\n") ;
// scanf("%d", &hand_of_dice) ;
// printf(" amount of dice %d ",hand_of_dice );
// if (hand_of_dice > 255)
// {
// hand_of_dice = 255 ;
// printf(" is now %d", hand_of_dice) ;
// }
// printf("\n") ;
// farkle
hand_of_dice=6 ;
// https://stackoverflow.com/questions/64331843/in-c-char-foofoo-is-not-allowed-but-why-and-how-to-use-input-as-declaration
// char *hand = malloc(hand_of_dice * sizeof *hand);
// char *hand2 = malloc(hand_of_dice * sizeof *hand2);
// char *all = malloc(amount_of_dice_sides * sizeof *all);
//
printf("Give number of players:") ;
scanf("%d", &players) ;
printf("\n\n%d players use %d dice", players, hand_of_dice ) ;
sleep(3) ;
round = 1 ;
char p[]={ 17,' ',16,' ','P','l','a','y','e','r',' ' } ; // 4 spaces reserved for colour info \x10 etc
// p[0]=17 ; //paper
// p[2]=16 ; //ink
start:
zx_cls() ;
memset(hand2, '' , amount_of_dice_sides+1 ) ;
for (play=1 ; play<=players ; play++)
{
k=0 ;
i8= play % 8 ; //integer modulo cuts off rest // just some colour information for ZX
i8++ ; // avoid / 0 null terminator
p8=55 - 7*(i8 ==7 || i8==8);
p[1]=p8 ; //paper colour
p[3]=i8 ; // ink colour
printf("%s%2d : \x10\x10\x11\x37", p , play ) ;
for ( x=0 ; x<hand_of_dice ; x++ )
{
number=dice(amount_of_dice_sides) ;
hand[x]=number ; // only to 255
hand2[number]++ ; // only to 255
all[number]++ ;
printf("%4d",hand[x]) ;
}
//sort for easy picking dice for farkle, or do it manualy ??
hand=sortit( hand , hand_of_dice ) ;
printf(".") ;
for ( x=0 ; x < hand_of_dice ; x++ )
{ printf("%4d" , hand[x] ) ; }
printf("\n") ;
// while(1)
// {
rekey:
key = in_Inkey() ;
if (key2 == key) {goto rekey ; }
if (key == 32)
{
if ( k == 1) { printf("\n") ; }
k = 0 ;
goto next ;
}
if ( key > 48 && key < hand_of_dice+1+48 && hand[key-49] !='X')
{
select[key-49][0]=hand[key-49] ;
hand[key-49]='X' ;
printf("d%d=%d | ", key-48, select[key-49][0] ) ;
k = 1 ;
}
key2 = key ;
goto rekey ;
// } //end of while
next:
} //end player
printf("\n statistics 'dicevalue=amount' with %d times %d = %d dice\n", players , hand_of_dice , players* hand_of_dice);
printf(" last round (%dX%d) : \n ",round,players) ;
for (x=1 ; x<=amount_of_dice_sides ;x++) { printf("%5d |",x) ; }
printf("\n ") ;
for (x=1 ; x<=amount_of_dice_sides ;x++) { printf("%5d |",hand2[x]) ; }
printf("\n overall results(%d): \n ",round*players) ;
for (x=1 ; x<=amount_of_dice_sides ;x++) { printf("%5d |",all[x]) ; }
printf("\npress key to dice again, '0' will stop") ;
scanf("%d",&key ) ;
if (key != 0)
{
round++ ;
goto start ;
}
return 0 ;
} //endmain
/* C source end */
edit:
i just tried with
#include <string.h>
and now i have solved the other error about memset
~/Desktop/try-C/c_in_zx/farkle$ zcc +zx -vn dice_096e.c -o dice096e -lndos -create-app -zorg=32768
dice_096e.c:173:7: fatal error: Must be lvalue
Compilation aborted