More help please gentlemen.

Discussion about ZX80 / ZX81 Software
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

More help please gentlemen.

Post by Moggy »

I recently asked for some help with a problem in M/C and you guys responded superbly so I wonder if you could help me once more with another problem?



The problem.

Imagine a REM containing exactly 100 random BYTES.

1 REMxxxxxxx....(100)

Now a second REM with 800 BYTES.

2 REMxxxxxxx....(800)


What I need to do is to take a BYTE one at a time from the first REM, convert it into binary then poke the 8 successive binary digits into the second REM then move onto the next until all 100 BYTES of the first REM are converted then poked into the 800 BYTES of the second REM.


For example if the first BYTE of REM 1 is 255...

1 REM COPY....

then the first 8 positions of REM 2 should look like..

2 REM 11111111....


A third REM should hold the code to achieve this.


3 REM (code for the routine)



I can do this in BASIC but it is taking far too long.


Any help or pointers in the right direction would be much appreciated but it has to be kept simple as I’m not the brightest when it comes to programming.


Many thanks in advance.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: More help please gentlemen.

Post by XavSnap »

Hi i had to retrieve my ASM code to convert a byte to a 8 binary value… somewhere on this forum…

But, to diet your code, delete the first REM line… the random table array…

Just get a random ROM offset, and get the byte from this offset.

You will keep 105 bytes !
Last edited by XavSnap on Mon Nov 09, 2020 11:01 pm, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: More help please gentlemen.

Post by Moggy »

Hi Xav.

I'm not trying to create any RND numbers. The RND numbers in the first REM are very important and it is those specific numbers I need to convert to binary and then using the other routines you and the guys supplied I can check the frequency of zeros and ones.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: More help please gentlemen.

Post by XavSnap »

Code: Select all

FOR A=16514 TO 16514+100
POKE A,256*RND
NEXT A
Not my pretty code ??? :::

Code: Select all

LET D=16514
FOR A=50+RND*1000 TO 4E4 STEP RND*4
POKE D,PEEK A
LET D=D+1
IF D<16615 THEN NEXT A
[!perhaps!] It's faster !
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: More help please gentlemen.

Post by Moggy »

Again I don't need to create any RND numbers they are already done in another program and are important.

I just need something that will turn these 100 RND numbers into 800 bits of binary then poke it to the second REM.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: More help please gentlemen.

Post by XavSnap »

:lol:
another program and are important
this is the lottery number ?
Cool…
I had to retrieve my working Byte>Binary routine…
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: More help please gentlemen.

Post by Moggy »

Not lottery but RND numbers created by outside sources then manually entered into the ZX81 for use in encryption.

The frequency of ones and zeros is checked to see the quality/weight of the RND number generator used and so far the 81's own RND generator is performing better that a Mersenne twister! :lol:
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: More help please gentlemen.

Post by XavSnap »

8-)

Code: Select all

#RANDOM VALUES.
     0  REM [HEX:\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF,00,FF,00,FF,\
00,FF,00,FF ]
#BINARY BUFFER
     1  REM [HEX:\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00  ]

#COUNTER ROUTINE 
     2  REM [HEX:\
21,EC,40,01,00,00,3E,1D,\
BE,20,01,03,23,3E,76,BE,\
20,F4,C9 ]

#GET LINE 0 VALUES AND STORE BINARY VALUES IN LINE 1.
     3  REM [HEX:\
21,82,40,11,EC,40,01,64,\
08,06,08,79,FE,00,C8,7E,\
CB,7F,EB,28,04,36,1D,18,\
02,36,1C,EB,13,CB,07,10,\
EF,23,0D,18,E4 ]

#FILL THE LINE 1.
5 FOR A=16514 TO 16514+99
6 POKE A,255*RND
7 NEXT A

#CONVERT
10 LET N=USR 17451

#COUNT
20 LET N=USR 17426
30 PRINT "1=";N,"0=";800-N
ASM:

Code: Select all

.ORG 16514
	LD HL,16514
	LD DE,16514+106 ;Target
	LD BC,$0864
NEXTBYTE:
	
	LD B,8
	LD A,C
	CP 0
	RET Z
	LD A,(HL)

NXTBIT:
	BIT 7,A
	EX DE,HL
	JR Z,GET0

	LD (HL),$1D
	JR NEXT
GET0:
	LD (HL),$1C
NEXT:
	EX DE,HL
	INC DE
	RLC A
	DJNZ NXTBIT
	INC HL
	DEC C
	JR NEXTBYTE
.end
BINARY.P
(1.98 KiB) Downloaded 174 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
zsolt
Posts: 214
Joined: Wed Apr 20, 2011 11:43 am
Location: Fót, Hungary

Re: More help please gentlemen.

Post by zsolt »

Hi,

Code: Select all

	; 3 REM
	.org 17426	; 16514+106+806

	ld de,16514	; 1 REM (100 bytes)
	ld hl,16620	; 2 REM (800 bytes)
	ld c,100	; 100 bytes to convert
nxt_byte
	ld a,(de)	; a byte to convert
	ld b,8		; 8 bits in a byte
next_bit
	ld (hl),$1C	; code "0"
	rla		; test bit 7
	jr nc,equ_zero	; skip if zero

	inc (hl)	; else set "1"
equ_zero
	inc hl		; set bit pointer
	djnz next_bit	; last bit in byte?

	inc de		; set byte pointer
	dec c		; set byte counter
	jr nz,nxt_byte	; back until done

	ret		; 
.end
25 bytes for the 3rd REM.
;)
Zsolt
ZX81 (8K), ENTERPRISE 128, [ZX SPECTRUM (48K,+,+128K,+2,+2A), TS1000, TS1500, TS2068, Cambridge Z88, PRIMO A64 (red)]
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: More help please gentlemen.

Post by Moggy »

Thank you Gentlemen you have helped me once again :ugeek: , how I wish I had your skills. :oops:

The people on this forum never cease to amaze me especially with their helpfulness. :D
Post Reply