converting a zx81 routine to a zx spectrum

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

converting a zx81 routine to a zx spectrum

Post by 777 »

how difficult is it to convert a zx81 assembly routine to a zx spectrum one? and how different are they?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
PQR
Manic Miner
Posts: 245
Joined: Sat May 12, 2018 11:35 am
Contact:

Re: converting a zx81 routine to a zx spectrum

Post by PQR »

They're different computers so it could be incredibly difficult. But also not. It really depends on what that the code is doing.
User avatar
WhatHoSnorkers
Manic Miner
Posts: 264
Joined: Tue Dec 10, 2019 3:22 pm

Re: converting a zx81 routine to a zx spectrum

Post by WhatHoSnorkers »

They're both Z80 machines so that's good. But the memory address of the screen is going to different, also ROM calls and that. So as usual "it depends" :)
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: converting a zx81 routine to a zx spectrum

Post by 777 »

WhatHoSnorkers wrote: Mon May 01, 2023 2:18 pm They're both Z80 machines so that's good. But the memory address of the screen is going to different, also ROM calls and that. So as usual "it depends" :)
well heres the code anyway. i think ive managed to extract it from the rem statements properly. its 730 bytes long. its supposed to draw a car on the screen and then scroll a crosshatched background vertically. ive moved the code from 16538 to 40000

Code: Select all

org 40000
ld a, (iy+52)
ld (iy+60), a
ld (iy+61), 5
ld (iy+62), 0
ld (iy+63), 6
ld (iy+66), 6
ld hl, (16396)
ld bc, 780
add hl, bc
ld (hl), 28
ld a, (iy+60)
cp (iy+52)
jr z, 40034
dec (iy+60)
call 3910
ret nc
dec (iy+61)
jr nz, 40092
ld (iy+61), 5
ld hl, (16396)
ld bc, 770
add hl, bc
inc (hl)
ld a, (hl)
cp 38
jr c, 40092
ld (hl), 28
dec hl
dec hl
inc (hl)
ld a, (hl)
cp 38
jr c, 40092
ld (hl), 28
dec hl
inc (hl)
ld a, (hl)
cp 34
jr c, 40092
ld (hl), 28
dec hl
dec hl
inc (hl)
call 16944
call 16987
ld a, (iy+62)
and a
jr z, 40149
res 7, (iy+66)
bit 0, a
call nz, 16944
dec (iy+62)
jr nz, 40031
ld hl, (16396)
ld bc, 561
add hl, bc
ld b, 0
ld c, (iy+65)
add hl, bc
ld a, c
add a, 2
bit 7, (hl)
jr z, 40140
sub 4
ld (iy+65), a
call 16987
jp 16560
ld hl, 16453
ld b, 7
bit 7, (hl)
jr nz, 40164
ld (iy+62), 151
jr 40092
inc hl
djnz 40154
dec (iy+63)
jr nz, 40203
ld (iy+63), 8
ld a, 239
in a, (254)
cpl
and 3
jr z, 40203
call 16944
rra
jr nc, 40194
inc (iy+65)
rra
jr nc, 40200
dec (iy+65)
call 16987
ld a, (iy+66)
and 128
ld c, a
ld a, 251
in a, (254)
and 4
rra
or c
ld c, a
ld a, 253
in a, (254)
and 4
or c
ld c, a
cpl
and (iy+66)
ld d, a
ld (iy+66), c
ld hl, (16396)
ld bc, 780
add hl, bc
ld a, (hl)
bit 2, d
jr z, 40251
cp 29
jr c, 40251
dec (hl)
bit 1, d
jr z, 40260
cp 33
jr nc, 40260
inc (hl)
ld a, (hl)
cp 29
jr nc, 40276
res 7, (iy+66)
ld (iy+64), 1
jp 16569
dec (iy+64)
jp nz, 16569
cpl
add a, 36
ld (iy+64), a
ld a, (iy+66)
xor 128
ld (iy+66), a
rla
jp c, 16569
call 16944
ld hl, (16396)
ld bc, 693
add hl, bc
push hl
ld bc, 33
add hl, bc
ld d, h
ld e, l
pop hl
ld bc, 694
lddr
call 16987
ld a, (iy+69)
cp 134
ret z
ld c, 128
ld de, (16451)
ld a, d
or e
jr z, 40353
dec de
ld (16451), de
ld a, d
or e
jr nz, 40353
ld c, 134
ld hl, (16507)
add hl, de
ld d, h
ld e, l
ld hl, (16396)
ld a, (de)
rra
rra
rra
and 31
ld b, a
inc hl
ld (hl), 8
djnz 40369
ld a, (de)
and 7
add a, 8
ld b, a
inc hl
ld (hl), c
djnz 40380
inc hl
ld (hl), 8
ld hl, (16396)
ld bc, 791
add hl, bc
ld a, 37
inc (hl)
cp (hl)
jp nc, 16569
ld (hl), 28
dec hl
jr 40396
ld hl, (16396)
ld bc, 529
add hl, bc
ld b, 0
ld c, (iy+65)
add hl, bc
ld d, h
ld e, l
ld hl, 16453
ld bc, 3
ldir
ex de, hl
ld bc, 31
add hl, bc
ex de, hl
ldi
ex de, hl
ld bc, 31
add hl, bc
ex de, hl
ld bc, 3
ldir
ret
ld hl, (16396)
ld bc, 529
add hl, bc
ld b, 0
ld c, (iy+65)
add hl, bc
ld de, 16453
bit 7, (iy+66)
ldi
dec hl
ld (hl), 5
jr z, 40478
ld (hl), 128
inc hl
ldi
dec hl
ld (hl), 22
inc hl
ldi
dec hl
ld (hl), 133
jr z, 40494
ld (hl), 128
ld bc, 32
add hl, bc
ldi
dec hl
ld (hl), 52
ld bc, 32
add hl, bc
ldi
dec hl
ld (hl), 5
jr z, 40516
ld (hl), 128
inc hl
ldi
dec hl
ld (hl), 9
inc hl
ldi
dec hl
ld (hl), 133
jr z, 40532
ld (hl), 128
ret
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
rla
rla
dec (hl)
dec de
add hl, hl
ccf
ld l, 60
ld l, 52
scf
rla
rla
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
ld a, (16444)
xor 128
ld (16444), a
ld c, (iy+65)
ld a, c
and 15
inc a
ld b, a
ld de, (16447)
bit 7, (iy+60)
jr nz, 40605
dec d
bit 6, c
jr nz, 40605
inc d
inc d
call 17189
bit 5, c
jr nz, 40615
call 17189
djnz 40592
dec b
bit 7, (iy+60)
ret nz
bit 4, c
jr nz, 40635
inc e
bit 6, c
jr z, 40641
dec d
jr 40641
dec e
bit 6, c
jr nz, 40641
inc d
call 17189
ret
pop bc
set 7, (iy+60)
ret
ld a, e
cp 5
jr nc, 40645
add a, d
cp 24
jr nc, 40645
ld a, d
and a
jr z, 40645
ld (16447), de
rla
rla
rla
or e
ld de, (16445)
dec de
ld (16445), de
ld hl, (16507)
add hl, de
ld (hl), a
ld hl, 16
dec de
sbc hl, de
ld de, (16447)
ret c
jr nz, 40673
pop bc
ld bc, 0
jr 40673
halt
nop
ld bc, 2
jp pe, 118
ld h, h
ld (bc), a
nop
call po, 118
ld l, (hl)
ld (bc), a
nop
defb 253
halt
nop
ld a, b
rrca
nop
jp (hl)
its from this

Code: Select all

   0 REM \97\00\35\1B\29\3F\2E\3C\2E\34\37\1A\00\32\26\3E\00\1D\25\24\1F\76\FF\FF\FD\7E\34\FD\77\3C\FD\36\3D\05\FD\36\3E\00\FD\36\3F\06\FD\36\42\06\2A\0C\40\01\0C\03\09\36\1C\FD\7E\3C\FD\BE\34\28\FB\FD\35\3C\CD\46\0F\D0\FD\35\3D\20\29\FD\36\3D\05\2A\0C\40\01\02\03\09\34\7E\FE\26\38\18\36\1C\2B\2B\34\7E\FE\26\38\0E\36\1C\2B\34\7E\FE\22\38\05\36\1C\2B\2B\34\CD\30\42\CD\5B\42\FD\7E\3E\A7\28\2D\FD\CB\42\BE\CB\47\C4\30\42\FD\35\3E\20\A9\2A\0C\40\01\31\02\09\06\00\FD\4E\41\09\79\C6\02\CB\7E\28\02\D6\04\FD\77\41\CD\5B\42\C3\B0\40\21\45\40\06\07\CB\7E\20\06\FD\36\3E\97\18\B8\23\10\F3\FD\35\3F\20\1F\FD\36\3F\08\3E\EF\DB\FE\2F\E6\03\28\12\CD\30\42\1F\30\03\FD\34\41\1F\30\03\FD\35\41\CD\5B\42\FD\7E\42\E6\80\4F\3E\FB\DB\FE\E6\04\1F\B1\4F\3E\FD\DB\FE\E6\04\B1\4F\2F\FD\A6\42\57\FD\71\42\2A\0C\40\01\0C\03\09\7E\CB\52\28\05\FE\1D\38\01\35\CB\4A\28\05\FE\21\30\01\34\7E\FE\1D\30\0B\FD\CB\42\BE\FD\36\40\01\C3\B9\40\FD\35\40\C2\B9\40\2F\C6\24\FD\77\40\FD\7E\42\EE\80\FD\77\42\17\DA\B9\40\CD\30\42\2A\0C\40\01\B5\02\09\E5\01\21\00\09\54\5D\E1\01\B6\02\ED\B8\CD\5B\42\FD\7E\45\FE\86\C8\0E\80\ED\5B\43\40\7A\B3\28\0B\1B\ED\53\43\40\7A\B3\20\02\0E\86\2A\7B\40\19\54\5D\2A\0C\40\1A\1F\1F\1F\E6\1F\47\23\36\08\10\FB\1A\E6\07\C6\08\47\23\71\10\FC\23\36\08\2A\0C\40\01\17\03\09\3E\25\34\BE\D2\B9\40\36\1C\2B\18\F6\2A\0C\40\01\11\02\09\06\00\FD\4E\41\09\54\5D\21\45\40\01\03\00\ED\B0\EB\01\1F\00\09\EB\ED\A0\EB\01\1F\00\09\EB\01\03\00\ED\B0\C9\2A\0C\40\01\11\02\09\06\00\FD\4E\41\09\11\45\40\FD\CB\42\7E\ED\A0\2B\36\05\28\02\36\80\23\ED\A0\2B\36\16\23\ED\A0\2B\36\85\28\02\36\80\01\20\00\09\ED\A0\2B\36\34\01\20\00\09\ED\A0\2B\36\05\28\02\36\80\23\ED\A0\2B\36\09\23\ED\A0\2B\36\85\28\02\36\80\C9\00\00\00\00\00\00\00\00\00\00\00\00\00\00\17\17\35\1B\29\3F\2E\3C\2E\34\37\17\17\00\00\00\00\00\00\00\00\00\00\00\00\3A\3C\40\EE\80\32\3C\40\FD\4E\41\79\E6\0F\3C\47\ED\5B\3F\40\FD\CB\3C\7E\20\07\15\CB\71\20\02\14\14\CD\25\43\CB\69\20\03\CD\25\43\10\E7\05\FD\CB\3C\7E\C0\CB\61\20\08\1C\CB\71\28\09\15\18\06\1D\CB\71\20\01\14\CD\25\43\C9\C1\FD\CB\3C\FE\C9\7B\FE\05\30\F5\82\FE\18\30\F0\7A\A7\28\EC\ED\53\3F\40\17\17\17\B3\ED\5B\3D\40\1B\ED\53\3D\40\2A\7B\40\19\77\21\10\00\1B\ED\52\ED\5B\3F\40\D8\20\E5\C1\01\00\00\18\DF
   1 REM 
 100 SLOW 
 110 CLEAR 
 120 DIM R$(984)
 130 LET LENH=INT (LEN R$/256)
 140 LET LENL=LEN R$-LENH*256
 150 LET ST=PEEK 16400+256*PEEK 16401+6
 160 POKE 16508,INT (ST/256)
 170 POKE 16507,ST-256*PEEK 16508
 180 LET L$=STR$ (LEN R$+16)
 190 DIM T$(6)
 200 POKE 16418,0
 510 LET TITLE=1000
 520 LET INSTRUCTIONS=2000
 530 LET PLAY=3000
 550 LET BORDER=5010
 560 LET TRACK=6000
 600 GOSUB TITLE
 620 GOSUB INSTRUCTIONS
 640 GOSUB PLAY
 650 GOTO 620
1010 PRINT "\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##   \##   \##   % %      \## \## \## \##\##\##   \##\## \##\##\## \## \## %  % %  %  %  \## \## \## \##\##\## \## \##\##  \##\## \## \##    %  %  %  \## \## \## \##\##\##   \##\## \##\##\## \## \## \##\## %  % % %  %  \## \## \##\##\## \## \##\## \##\##\##   \## \##\## %  % % %  %    \##   \## \## \##"
1020 PRINT "\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##   \## % %  %    % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\## \## \##  %  %  % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##   \## \## \## %   %   % %    \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\## \## \## % %  %  % % % \##\##\##\##\##\##\##\##\##"
1030 PRINT "\##\##\##\##\##\##\##\##\##\##   \## % %  %    \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % \: -\ :% % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % %0% % % % \##\##\##\##\##\##\##\##\##\##\##\##"
1040 PRINT "\##\##\##\##\##\##\##\##\##\##\##\##% % \: \,,\ :% % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % \##\##\##\##\##\##\##\##\##\##"
1060 FOR K=1 TO 75
1070 IF INKEY$<>"" THEN RETURN 
1080 NEXT K
1090 PRINT AT 23,3;"PRESS ANY KEY TO CONTINUE"
1100 FOR K=1 TO 75
1110 IF INKEY$<>"" THEN RETURN 
1130 GOTO 1050
2010 GOSUB BORDER
2020 PRINT AT 2,4;"IT IS THE DAY BEFORE THE";TAB 4;"SINCLAIR GRAND PRIX; IN";TAB 2;"TODAYS LAP TIMINGS YOU WILL";TAB 4;"HAVE TO STEER YOUR HIGH"
2030 PRINT TAB 3;"SPEED, FIVE-GEAR, FORMULA";TAB 3;"ONE CAR AROUND THE CIRCUIT";TAB 5;"IN AS SHORT A TIME AS";TAB 12;"POSSIBLE." 
2040 PRINT AT 11,2;"EACH LAP IS ";L$;" UNITS LONG.";TAB 3;"IF YOU HIT THE EDGE OF THE";TAB 2;"TRACK YOU WILL INCUR A THREE";TAB 9;"SECOND PENALTY."
2050 PRINT TAB 2;"STEER THE CAR LEFT/RIGHT BY";TAB 8;"PRESSING ""9""/""0"".";TAB 3;"CHANGE UP/DOWN ONE GEAR BY";TAB 5;"PRESSING ""E""/""D"" ONCE."
2060 PRINT AT 20,3;"PLEASE WAIT WHILE I DESIGN";TAB 9;"THE RACE TRACK."
2070 GOSUB TRACK
2100 PRINT AT 20,3;"     **TRACK READY**      ";TAB 5;"PRESS ANY KEY TO START"
2110 PRINT AT 20,8;"**";TAB 21;"**"
2120 FOR K=1 TO 10
2130 IF INKEY$>"" THEN RETURN 
2140 NEXT K
2150 PRINT AT 20,8;"  ";TAB 21;"  "
2160 FOR K=1 TO 10
2170 IF INKEY$>"" THEN RETURN 
2180 NEXT K
2190 GOTO 2110
3010 CLS 
3020 FOR K=1 TO 21
3030 PRINT "\##\##\##\##\##\##\##\##\##\##\##\##% % % % % % % % % \##\##\##\##\##\##\##\##\##\##\##"
3040 NEXT K
3050 PRINT AT 23,0;"TIME=0:00.0    GEAR=0   DIST=000"
3060 PRINT AT 16,1;"COUNTDOWN:\##\'.\'.\'.\'.\'.\'.\'.\'.\'."
3070 POKE 16451,LENL
3080 POKE 16452,LENH
3090 POKE 16449,15
3100 POKE 16448,1
3110 RAND USR 16987
3120 FOR K=0 TO 9
3130 PRINT AT 16,22;"TEN\##\##NINE\##EIGHTSEVENSIX\##\##FIVE\##FOUR\##THREETWO\##\##ONE\##\##"(5*K+1 TO 5*K+5)
3140 FOR J=1 TO 19
3150 NEXT J
3160 NEXT K
3200 PRINT AT 16,22;"**GO**"
3210 RAND USR 16538
3220 FOR K=1 TO 6
3230 PRINT AT 23,4+K;
3240 LET T$(K)=CHR$ PEEK (PEEK 16398+256*PEEK 16399)
3250 NEXT K
3300 LET SPEED=INT (VAL L$*9/(VAL T$(1)*60+VAL T$(3 TO 6)))
3510 LET C$="SLOW"
3520 IF SPEED>=70 THEN LET C$="POOR"
3530 IF SPEED>=85 THEN LET C$="FAIR"
3540 IF SPEED>=100 THEN LET C$="FAST"
4010 GOSUB BORDER
4020 PRINT AT 2,2;"LAP: ";LAP;TAB 2;"YOUR TIME WAS ";T$(1);" MIN ";T$(3 TO 6);" SEC"
4030 PRINT TAB 2;"AVERAGE SPEED WAS ";SPEED;" MPH";TAB 2;"THIS IS RATED AS ";C$;"."
4040 IF T$<W$ AND LAP>1 THEN GOTO 4080
4050 LET W$=T$
4060 LET WSTLAP=LAP
4070 IF LAP>2 THEN PRINT AT 6,2;"--SLOWEST TIME YET--"
4080 IF T$>B$ AND LAP>1 THEN GOTO 4120
4090 LET B$=T$
4100 LET BSTLAP=LAP
4110 IF LAP>2 THEN PRINT AT 6,2;"**FASTED LAP SO FAR**"
4120 PRINT AT 8,2;" BEST TIME=";B$;" (LAP ";BSTLAP;")"
4130 PRINT AT 9,2;"WORST TIME=";W$;" (LAP ";WSTLAP;")"
4140 FOR K=1 TO 6
4150 LET X$(K)=X$(K+1)
4160 NEXT K
4170 LET X$(7,1 TO 6)=T$
4180 LET X$(7,9 TO 11)=STR$ SPEED
4190 LET X$(7,14 TO 17)=C$
4200 PRINT 
4210 FOR K=1 TO 7
4220 IF X$(K,1)>" " THEN PRINT TAB 3;"LAP ";FSTLAP+K;":";TAB 11;X$(K)
4230 NEXT K
4300 LET FSTLAP=FSTLAP+1
4310 LET LAP=LAP+1
4500 PRINT AT 19,2;"PRESS %A FOR ANOTHER LAP OF";TAB 4;"THE CIRCUIT.";TAB 2;"PRESS %N FOR A NEW CIRCUIT."
4510 IF INKEY$="A" THEN GOTO PLAY
4520 IF INKEY$="N" THEN RETURN 
4530 GOTO 4510
5010 CLS 
5020 PRINT "\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'FOMULA\.'ONE\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'";
5030 FOR K=1 TO 22
5040 PRINT TAB 31;"\.'\.'";
5050 NEXT K
5060 PRINT "\.'\.'\.'\.'\.'\.'\.'\.'\.'FORMULA\.'ONE\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'";
5070 RETURN 
6010 RAND 
6060 POKE 16444,0
6070 POKE 16445,LENL
6080 POKE 16446,LENH
6090 POKE 16447,1
6100 POKE 16448,12
6110 POKE 16449,INT (RND*128)
6120 IF USR 17110 THEN GOTO 6110
6200 DIM X$(7,17)
6210 LET LAP=1
6220 LET W$=""
6230 LET WSTLAP=0
6240 LET B$=""
6250 LET BSTLAP=0
6260 LET FSTLAP=-6
6270 RETURN 
7000 SAVE "FORMULA ON%E"
7010 RUN 
9000 POKE 16511,220
9010 POKE 16512,2
9020 FOR K=0 TO 91
9030 SCROLL 
9040 PRINT CHR$ (51+INT (K/10));CHR$ (28+10*(K/10-INT (K/10)));")";
9050 LET TOT=0
9060 FOR J=0 TO 7
9070 INPUT I$
9080 IF I$="X" THEN LET K=K-1
9090 IF I$="X" THEN GOTO 9030
9100 IF LEN I$<>2 THEN GOTO 9070
9110 PRINT " ";I$;
9120 LET N=16*(CODE I$-28)+(CODE I$(2)-28)
9130 POKE 16514+8*K+J,N
9140 LET TOT=TOT+N
9150 NEXT J
9160 PRINT "=";TOT
9170 NEXT K
some of the characters in this program have not come out correctly, unfortunately
Last edited by 777 on Mon May 01, 2023 4:31 pm, edited 2 times in total.
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
1024MAK
Bugaboo
Posts: 3176
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: converting a zx81 routine to a zx spectrum

Post by 1024MAK »

Please note, the post below was written before the OP posted their code.

With a ZX Spectrum, there are more places to store machine code. And more importantly, this machine has a SAVE and LOAD commands that can save and load code. The ZX81 can only save and load BASIC programs. Hence small machine code routines are often incorporated in a REM statement. Normally the REM is placed at line 1 so that it’s address in RAM is known.

That does not mean that machine code can’t be stored elsewhere. However, the ZX81 does not have the CLEAR command that the ZX Spectrum has. If you wan5 to store code above the BASIC controlled area, you have to POKE in a new value of RAM top to the relevant system variable. Then do a NEW. Then enter your program.

Advanced techniques are used for mainly machine code programs.

The ROMs are different. The ZX Spectrum ROM may be an evolution of the ZX81 ROM, but it’s double the size and mostly different. The system variables are also mostly different.

The display file / video RAM is at a different address in memory. Indeed the ZX81 display file is not at a particular fixed address. It is laid out completely differently. Plus a stock ZX81 uses a compressed display file. Only if there are 3¾k bytes or more of RAM, will the display file will be fully expanded to its full size.

The ZX81 needs certain Z80 registers to be left undisturbed if using display and compute (slow) mode, otherwise the system will crash when attempting to produce the display.

If not using FAST mode, then due to the Z80 switching between display generation and running your code, it will overall, run slower than on a ZX Spectrum.

If the machine code is mot relocatable, then any jumps or other fixed memory addresses will need to be recalculated.

The part of the ZX81 manual that discusses machine code is here (chapter 26) and should be read before writing or adapting any machine code for the ZX81.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer being good this year.
AndyC
Dynamite Dan
Posts: 1468
Joined: Mon Nov 13, 2017 5:12 am

Re: converting a zx81 routine to a zx spectrum

Post by AndyC »

The ZX81 display is character based, whereas the Speccy display is a bitmap. So converting to the routine is going to be significant effort, probably more than just recreating the same effect. And this is one of the few cases where the Spectrum may end up a lot slower, as it has to shift a lot more memory around to scroll the screen than the ZX81 does
User avatar
1024MAK
Bugaboo
Posts: 3176
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: converting a zx81 routine to a zx spectrum

Post by 1024MAK »

Well, it depends… a ZX81 display file when fully expanded, is arranged in a more logical manner compared to the ZX Spectrum.

Under BASIC, yes, the display file (the normal term for the area of screen memory on a ZX81) is a character based system. It’s actually 33 characters per line, but the last character on each line has to be a “NEWLINE” (118 dec, 76 hex, a Z80 HALT instruction). As it is this that tells the display system that the end of the line has been reached.

As the normal display is a character based system. You would either have to use the BASIC ROMs PLOT command or write your own. As in order to display a chunky pixel, you have to write the correct ‘semigraphics’ character to the display file.

See chapter 27

It is possible to have a bit mapped display on a ZX81. However, you have to use a machine code routine that generates the display instead of the normal routine in the ROM. Routines like this are known as Hi-Res graphics routines. This is definitely for advanced programmers.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer being good this year.
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: converting a zx81 routine to a zx spectrum

Post by TMD2003 »

Something else that was pointed out to me a while ago while I was learning the hard way:

The ZX81 uses IX for some essential system routines, whereas the Spectrum uses IY. Hence, any uses of IY on the ZX81 listing should be switched to IX for the Spectrum conversion.

16396 is (without me looking in the manual) very likely to be a system variable with a Spectrum equivalent.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Dr beep
Manic Miner
Posts: 388
Joined: Mon Oct 01, 2018 8:53 pm

Re: converting a zx81 routine to a zx spectrum

Post by Dr beep »

You are asking for a solution. I would like to know the problem first.
There might be other more easier solutions.


Why would you want to convert the routine to the ZX Spectrum?
Dr beep
Manic Miner
Posts: 388
Joined: Mon Oct 01, 2018 8:53 pm

Re: converting a zx81 routine to a zx spectrum

Post by Dr beep »

I found the game and played it on my emulator on the ZX Spectrum



Image
Dr beep
Manic Miner
Posts: 388
Joined: Mon Oct 01, 2018 8:53 pm

Re: converting a zx81 routine to a zx spectrum

Post by Dr beep »

TMD2003 wrote: Mon May 01, 2023 7:57 pm Something else that was pointed out to me a while ago while I was learning the hard way:

The ZX81 uses IX for some essential system routines, whereas the Spectrum uses IY. Hence, any uses of IY on the ZX81 listing should be switched to IX for the Spectrum conversion.

16396 is (without me looking in the manual) very likely to be a system variable with a Spectrum equivalent.
IX is used for the displayroutines from the ROM and IY is used the same way as on the ZX Spectrum, a pointer to the sysvar area.
The value of IY is different since the sysvar on the ZX81 start at #4000 and on the ZX Spectrum #5C3A
User avatar
1024MAK
Bugaboo
Posts: 3176
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: converting a zx81 routine to a zx spectrum

Post by 1024MAK »

The programming manual for the ZX Spectrum is here.

Some web pages describing the screen layout and how it’s display file is laid out are:
http://www.breakintoprogram.co.uk/hardw ... ory-layout

https://www.overtakenbyevents.com/lets- ... en-layout/

https://www.overtakenbyevents.com/lets- ... -part-two/

As you can see from the above, each pixel is part of a byte. With the colours stored in a separate attribute byte in a different location in memory.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer being good this year.
Post Reply