PEEKing memory locations with z88dk (for ZX80 randomiser)

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by Shaun_B »

Hi,

I've found this program for the Sinclair ZX80 Programming Course:

Code: Select all

    10 FOR I=1 to 20* RND(100)
    20 NEXT I
    30 POKE 16414,0
    40 POKE 16415,0
    50 PRINT "HIT RETURN"
    60 INPUT C$
    70 LET A=PEEK(16414)
    80 LET B=PEEK(16415)
    90 PRINT "YOUR REACTION TIME WAS";(B**256+A-4) *20;	"MS";
Does anyone know how to PEEK memory with z88dk?, as I need a better randomiser than what I have. I'm asking here as www.z88dk.org seems to be down at the moment.

Thanks,

Shaun
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by Shaun_B »

It's okay, I think that I've guessed a solution, as follows:

Code: Select all


int main();
void ramdomiser();

unsigned char random;
unsigned char stringBuffer;

/**
 * Random number generator based on
 * how long the user interacts with the
 * program - prints random numbers
 * between 0 and 15
 * DONKEYSOFT MMXVII
 */
int main()
{
    unsigned char i, r;
    for(i = 0; i < 20; i++)
    {
        randomiser();
        r = srand(random) % 16;
        printf("%d", r);
        gets(stringBuffer);
    }
}

/**
 * Sets the unsigned char random to
 * the current low byte value of $401e
 * If this routine causes issues with
 * your program then push hl and a
 * to the stack and restore them, or
 * exchange for the shadow registers
 */
void randomiser()
{
    __asm
        ld hl, ($401e)
        ld a, l
        ld (_random), a
    __endasm;
}
When writing to 'globals' in your assembly listing, you need to put an underscore before the variable name (_random is where we are storing the value passed to a, so each time randomiser() is called, it will update the value in random).

Enjoy!

Shaun
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by siggi »

Hi Shaun
use somthing like that:

Code: Select all

char *ptr;
char ch;
ptr = (char *) 0x4711; /* address to be peeked */
c  = *ptr;
Regards
Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by siggi »

Or to PEEK/POKE system variables (or other fixed memory locations) just create a variable there and use it like usual:

Code: Select all


int sysvar @ 0x401e;

if (sysvar ==0x4711)
 sysvar = 0;
 
Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by Shaun_B »

Thanks for the tips siggi, the @ thing looks like something very powerful.

Regards,

Shaun
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by PokeMon »

Isn't it usual /classic defined in C this way ? 8-)

Code: Select all

int *sysvar=0x401e;
if (*sysvar==0x4711) *sysvar=0;
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by Shaun_B »

You guys are too clever for me - cheers!

Shaun
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by dr beep »

Shaun_B wrote: Tue Nov 28, 2017 8:12 pm You guys are too clever for me - cheers!

Shaun
Is this a standard answer, Shaun?
I got the same in a different code-effort.
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by Shaun_B »

Hi dr beep,

Not a standard response but a default position; I retrained into the world of computer science from health and social care around 8 years ago and my aim is always to be a better developer in six months time than I am today. But because I didn't keep up with computer science for around 20 years I feel like a big dumb dinosaur sometimes.

Regards,

Shaun.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by PokeMon »

My comment was because the declaration below is in my eyes not C standard but some z88dk special syntax.

Code: Select all

int sysvar @ 0x401e;
So if you do further C developments with other kits and targets you might benefit from getting familiar with pointers (*) and casting declarations in C. ;)
Post Reply