another piece of code from assembly language for games and other fast spectrum programs that doesnt work

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

another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by 777 »

it tried typing this in and the code does absolutely nothing. its supposed to move a spaceship around. ive double checked the code and cant find any errors:

Code: Select all

org 23760
;disable keyboard
di
jr start
;udg data
data1
;chr$ 144
defb 0,0,15,24,49,226,255,224
;chr$ 145
defb 24,60,255,255,153,255,231,60
;chr$ 146
defb 0,0,240,24,140,71,135,7
start
;set up udg's
ld de,(23675)
ld hl,data1
ld bc,24
ldir
jr begin
;print chr$ data at x,y ink 8 paper 8
;chr$ 144 145 146
data2
defb 22,0,0,16,17,8
defb 144,145,146
begin
;border 5
ld(iy+14),40
;paper 1 ink 7
ld(iy+83),15
;cls
ld a,2
call 5633
call 3435
;print string
ld a,2
call 5633
ld de,data2
ld bc,10
call 8252
l7
;transfer data2 to store
ld de,23296
ld hl,data2
ld bc,10
ldir
;get x,y from store
ld hl,(23297)
;check key pressed
ld bc,61438
in a,(c)
bit 0,a
jr nz,l1
inc h
l1
bit 1,a
jr nz,l2
dec h
l2
ld bc,63486
in a,(c)
bit 0,a
jr nz,l3
dec l
l3
ld bc,64510
in a,(c)
bit 0,a
jr nz,l4
inc l
l4
;check still on screen
ld a,1
cp 22
jr nz,l5
dec l
jr l6
l5
cp 225
jr nz,l6
inc l
l6
ld a,h
cp 30
jr nz,l8
dec h
jr l9
l8
cp 255
jr nz,l9
inc h
l9
;check no move
ld de,23297
xor a
push hl
sbc hl,de
pop hl
;if no move then skip
;print over 1
jr z,l12
;store new parameters
ld (23297),hl
;set over 1
ld (iy+87),3
;erase old position
ld de,data2
ld bc,10
call 8252
;reprint in new position
ld de,23296
ld bc,10
call 8252
;update data2 for next time
ld de,data2
ld hl,23296
ld bc,10
ldir
;delay loop
ld hl,5000
l11
dec hl
ld a,h
or l
jr nz,l11
;check 'space' pressed
l12
ld bc,32766
in a,(c)
bit 0,a
jp nz,l7
;reset over 0
ld (iy+87),0
;make keyboard active
ei
ret
https://ia600604.us.archive.org/view_ar ... ograms.pdf

its from page 42. im assuming you execute it from address 23760

if anyone fancies typing in the full program from page 50, that would be great. as i dont think ive got the will or patience to do it
i started programming the spectrum when i was 8 :-

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

http://zxspeccy.great-site.net/
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by sn3j »

Code: Select all

;check still on screen
ld a,1   <-- this should be the letter 'l'
...
l5
cp 225  <-- 255
If it matters, though.

Code: Select all

data2
defb 22,0,0,16,  17,8
defb 144,145,146
This is only 9 bytes but 10 are going to be printed. Probably a color byte is missing between 16 and 17.

Code: Select all

;check no move
ld de,23297   <-- should be:  ld de,(23297)
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by 777 »

sn3j wrote: Sat Dec 31, 2022 5:53 am
tried all of these still the same result
i started programming the spectrum when i was 8 :-

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

http://zxspeccy.great-site.net/
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by sn3j »

777 wrote: Sat Dec 31, 2022 10:26 am tried all of these still the same result
With all fixes applied the code should do ok.
Does it clear the screen and do you see the spaceship?

Ink value should be 8 btw:

Code: Select all

defb 22,0,0,16,  8,  17,8
Last edited by sn3j on Sat Dec 31, 2022 11:01 am, edited 1 time in total.
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
User avatar
Stefan
Manic Miner
Posts: 834
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by Stefan »

Are the results of your object code identical to the hexadecimal bytes shown in the listing?

This should catch any typo that may have been made by you or the author.
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by 777 »

sn3j wrote: Sat Dec 31, 2022 10:49 am With all fixes applied the code should do ok.
Does it clear the screen and do you see the spaceship?

Ink value should be 8 btw:

Code: Select all

defb 22,0,0,16,  8,  17,8
no, it does nothing
i started programming the spectrum when i was 8 :-

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

http://zxspeccy.great-site.net/
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by sn3j »

777 wrote: Sat Dec 31, 2022 1:39 pm no, it does nothing
This could be an emulator issue. Try it without the DI instruction.
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
User avatar
Stefan
Manic Miner
Posts: 834
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by Stefan »

sn3j wrote: Sat Dec 31, 2022 2:09 pm This could be an emulator issue. Try it without the DI instruction.
The OP made four mistakes, two of which have already been pointed out, all of which could have been found if the OP had checked the output of his assembly with that of the book.
  1. the data2 line is missing a byte defb 22,0,0,16,17,8 should be defb 22,0,0,16,8,17,8
  2. ld a,1 should be ld a,l
  3. at l5 cp 225 should be cp 255
  4. at l9 ld de,23297 should be ld de,(23297)
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by 777 »

sn3j wrote: Sat Dec 31, 2022 2:09 pm This could be an emulator issue. Try it without the DI instruction.
no, still does the same thing
i started programming the spectrum when i was 8 :-

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

http://zxspeccy.great-site.net/
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by sn3j »

777 wrote: Sat Dec 31, 2022 2:14 pm no, still does the same thing
How do you compile and start the code?
Make sure you didn't run an old binary.
Sorry for asking this kind of stuff but I don't use compilers myself and don't know how you do it over there.
Stefan wrote: Sat Dec 31, 2022 2:14 pm The OP made four mistakes, two of which have already been pointed out, all of which could have been found if the OP had checked the output of his assembly with that of the book.
  1. the data2 line is missing a byte defb 22,0,0,16,17,8 should be defb 22,0,0,16,8,17,8
  2. ld a,1 should be ld a,l
  3. at l5 cp 225 should be cp 255
  4. at l9 ld de,23297 should be ld de,(23297)
Yep according to what I've read that's fixed so far. Issue 2-4 isn't that critical.
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by sn3j »

ORG address 23760 is very low. On a ZX 48 the program area starts at 23755.
Perhaps a higher value like 32000 and issuing a CLEAR 31999 statement helps.
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by 777 »

sn3j wrote: Sat Dec 31, 2022 2:34 pm How do you compile and start the code?
Make sure you didn't run an old binary.
Sorry for asking this kind of stuff but I don't use compilers myself and don't know how you do it over there.


Yep according to what I've read that's fixed so far. Issue 2-4 isn't that critical.
i just used spin assembler to compile it
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
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by 777 »

sn3j wrote: Sat Dec 31, 2022 2:41 pm ORG address 23760 is very low. On a ZX 48 the program area starts at 23755.
Perhaps a higher value like 32000 and issuing a CLEAR 31999 statement helps.
yeah, it works. thank you
i started programming the spectrum when i was 8 :-

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

http://zxspeccy.great-site.net/
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: another piece of code from assembly language for games and other fast spectrum programs that doesnt work

Post by sn3j »

777 wrote: Sat Dec 31, 2022 8:29 pm yeah, it works. thank you
Great. I think the reason for this low ORG address is that it is supposed to be placed inside a '1 REM...' statement.
Because 23760 sits exactly there (23755 + 2 bytes line number + 2 bytes line size + 'REM').
This is something to consider when putting all the pieces together to a larger program (I didn't read the book but it looks like a puzzle piece that's going to be used later on).
Happy coding.
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
Post Reply