PEEKing memory locations with z88dk (for ZX80 randomiser)

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

PEEKing memory locations with z88dk (for ZX80 randomiser)

Post by Shaun_B » Mon Nov 27, 2017 8:45 pm

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: 375
Joined: Wed Apr 22, 2009 9:22 am

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

Post by Shaun_B » Mon Nov 27, 2017 9:45 pm

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: 776
Joined: Thu May 08, 2008 8:30 am
Location: Dauernheim, Germany
Contact:

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

Post by siggi » Tue Nov 28, 2017 8:01 am

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
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
siggi
Posts: 776
Joined: Thu May 08, 2008 8:30 am
Location: Dauernheim, Germany
Contact:

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

Post by siggi » Tue Nov 28, 2017 8:25 am

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
http://zx81-siggi.endoftheinternet.org/index.html

Shaun_B
Posts: 375
Joined: Wed Apr 22, 2009 9:22 am

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

Post by Shaun_B » Tue Nov 28, 2017 9:30 am

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

Regards,

Shaun

User avatar
PokeMon
Posts: 2190
Joined: Sat Sep 17, 2011 5:48 pm

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

Post by PokeMon » Tue Nov 28, 2017 11:26 am

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: 375
Joined: Wed Apr 22, 2009 9:22 am

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

Post by Shaun_B » Tue Nov 28, 2017 7:12 pm

You guys are too clever for me - cheers!

Shaun

dr beep
Posts: 1056
Joined: Thu Jun 16, 2011 7:35 am
Location: Boxmeer

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

Post by dr beep » Wed Nov 29, 2017 2:25 pm

Shaun_B wrote:
Tue Nov 28, 2017 7: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: 375
Joined: Wed Apr 22, 2009 9:22 am

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

Post by Shaun_B » Thu Nov 30, 2017 6:35 am

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: 2190
Joined: Sat Sep 17, 2011 5:48 pm

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

Post by PokeMon » Thu Nov 30, 2017 12:14 pm

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

Who is online

Users browsing this forum: No registered users and 1 guest