i have another piece of code that just locks up

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

i have another piece of code that just locks up

Post by 777 »

i decided to type it out anyway, here:

Code: Select all

org 30001
di
call 23760
jr START
DATA1
defb 0,0,15,24,49,226,255,224  
dEfb 24,60,255,255,153,255,231
defb 60,0,0,240,24,140,71,135,7
START
ld de,(23675)
ld hl,DATA1
ld bc,24
ldir
jr BEGIN
DATA2
defb 22,0,0,16,8,17,8,144,145
defb 146
BEGIN
ld de,DATA2
ld bc,10
call 8252
ld de,23296
ld hl,DATA2
ld bc,10
ldir
MOVE
ld hl,(23297)
ld bc,61438
in a,(c)
cp  255
jr z,lp12
bit 0,a
jr nz,lp1
inc h
Lp1
bit 1,a
jr nz,lp2
dec h
Lp2
bit 2,a
jr nz,lP3
inc l
lP3
bit 3,a
jr nz,Lp4
dec l
Lp4
ld a,l
cp 22
jr nz,lp5
dec l
jr Lp6
Lp5
cp 255
jr nz,lp6
inc l
Lp6
ld a,h
cp 26
jr nz,Lp7
dec h
jr Lp8
Lp7
cp 255
jr nz,lp8
inc h
Lp8
ld de, (23297)
xOr a
push hl
sbc hl,de
pop hl
jr z,Lp12
ld (23297) ,hl
OVER1
ld (iy+87),3
ld de, DATA2
ld bc,10
call 8252
ld de, 22296
ld bc,10
call 8252
ld de,DATA2
ld hl,23296
ld bc,10
ldir
LP12
ld bc,63486
in a,(c)
and 15
jr z,SCR
cp 3
jr z,SCR
cp 12
jr z,SCR
Cp 15
jr z,SCR
push af
ld (iy+87),3
ld de,DATA2
ld bc,10
call 8252
pop af
bit 0,a
push af
call z,UROLL
pop af
bit 1,a
push af
call z,uROLL
pop  af
bit 2,a
push af
call z,uROLL
pop af
bit 3,a
call z,RROLL
ld de,DATA2
ld bc,10
call 8252
scr
ld bc,64510
in a, (c)
and 15
jr z,DELAY
cp 3
jr z,DELAY
cp 12
Jr z,DELAY
cp 15
jr z,DELAY
push af
ld (iy+87),3
ld de,DATA2
ld bc,10
call 8252
pop af
bit 0,a
push af
call z,USCR
pop af
bit 1,a
push af
Call z,DSCR
pop af
bit 2,a
push af
call z,LSCR
pop af
bit 3,a
call z,RSCR
ld de,DATA2
ld bc,10
call 8252
delay
ld hl,10000
l1
dec hl
ld a,h
or l
jr nz,L1
ld bc,32766
in a,(c)
bit 0,a
jp nz,MOVE
ld (iy+87),0
ei
ret
uscr
ld de, 22528
ld hl,22560
ld bc,736
ldir
ld b,32
ld a, (23693)
l2
ld (de),a
Inc de
djnz L2
ld de, 16384
ld hl,16416
ld bc, 2016
ldir
ld b,8
ld hl,18432
ld de, 16608
l3
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
Inc h
djnz L3
ld de, 18432
ld hl,18464
ld bc,12016
ldir
ld b,8
ld hl,20480
ld de,18656
l4
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L4
ld de,20480
ld hl,20512
ld bc,2016
ldir
ld b,8
ld hl,20704
l5
push bc
push hl
ld b,32
l6
ld (hl),0
inc hl
djnz L6
pop hl
pop bc
inc h
djnz L5
ret
dscr
ld de,23295
ld hl,23263
ld bc,736
lddr
ld b,32
ld a, (23693)
l7
ld (de),a
inc de
djnz L7
ld de,22527 
ld hl,22495
ld bc,2016
lddr
ld b,8
ld hl,18656
ld de, 20480
l8
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
Inc h
djnz L8
ld de,20479
ld hl,20447
ld bc, 2016
lddr
ld b,8
ld hl, 16608
ld de, 18432
l9
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L9
ld de,18431
ld hl,18799
ld bc,2016
lddr
ld hl,16384
l10
ld b,32
l11
ld (hl),0
inc hl
djnz L11
xor a
ld l,a
inc h
ld a,h
cp 72
jr nz,L10
ret
lscr
ld b,24
ld hl, 22528
l12
push hl
pop de
push bc
inc hl
ld bc, 31
ldir
ld a, (23693)
ld (de),a
pop bc
djnz L12
ld hl, 16384
xOr a
ld b,192
l13
push bc
push hl
pop de
inc hl
ld bc,31
ldir
ld (de),a
pop bc
djnz l13
ret
rscr
ld b,24
ld hl, 23295
l14
push hl
pop de
push bc
dec hl
ld bc,31
lddr
ld a, (23693)
ld (de),a
pop bc
djnz L14
ld hl, 22527
xOr a
ld b,192
l15
push bc
push hl
pop de
dec hl
ld bc, 31
lddr
ld (de),a
pop bc
djnz L14
ret
uroll
ld hl,22528
push hl
pop de
ld b,32
l16
ld a, (hl)
push af
inc hl
djnz L16
ld bc,736
ldir
ld b,32
l17
pop af
dec hl
ld (hl),a
djnz L17
ld hl,16384
l18
ld b,32
l19
ld a, (hl)
push af
inc hl
djnz L19
xor a
ld l,a
inc h
ld a,h
cp 72
jr nz,l18
ld de, 16384
ld hl,16416
ld bc, 2016
ldir
ld b,8
ld hl, 18432
ld de, 16608
l20
push bc
push hl
push de
ld bc,22
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz l20
ld de, 18432
ld hl, 18464
ld bc, 2016
ldir
ld b,0
ld hl, 20430
ld de, 18656
l21
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L21
ld de, 20480
ld hl, 20512
ld bc, 2016
ldir
ld hl,22527
l22
ld b,32
l23
pop af
ld (hl),a
dec hl
djnz L23
ld a, 255
ld l,a
dec h
ld a,h
cp 79
jr nz,l22
ret
droll
ld hl, 22295
push hl
pop de
ld b,32
l24
ld a, (hl)
push af
dec hl
djnz l24
ld bc, 736
lddr
ld b,32
l25
pop af
inc hl
ld (hl),a
djnz l25
ld hl, 22537
l26
ld b,32
l27
ld a, (hl)
push af
dec hl
djnz l27
ld a, 255
ld l,a
dec h
ld a,h
cp 79
jr nz,l26
ld de, 22527
ld hl, 22495
ld bc, 2016
lddr
ld b,8
ld hl, 18656
ld de, 20480
l28
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L28
ld de, 26479
ld hl,20447
ld bc, 2016
lddr
ld b,8
ld hl, 16608
ld de, 18432
l29
push bc
push hl
push de
ld bc, 32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L29
ld de, 18431
ld hl, 18399
ld bc, 2016
lddr
ld hl,16284
l30
ld b,32
l31
pop af
ld (hl),a
inc hl
djnz l31
xor a
ld l,a
inc h
ld a,h
cp 72
jr nz,L30
ret
lroll
ld b,216
ld hl, 16384
l32
push Hl
pop de
push bc
ld a, (hl)
inc hl
ld bc,31
ldir
ld (de),a
pop bc
djnz L32
ret
rroll
ld b,216
ld hl, 23295
l33
push hl
pop de
push bc
ld a, (hl)
dec hl
ld bc,31
lddr
ld (de),a
pop bc
djnz l33
ret
im not sure if i should be running it at 30001 or at 40000? ive tried it a both anyway, adjusting the usr calls and pokes in the basic program to compensate. any help would be welcome. heres the sna of the basic and code also:

https://easyupload.io/dga8fm

its on page 50 of the book:

https://ia600604.us.archive.org/view_ar ... ograms.pdf
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: i have another piece of code that just locks up

Post by sn3j »

Hi!
Right at the start there's a call to 23760, and that's right into the first line of your Basic program.

Code: Select all

500 DATA 24,79,5,2,"STOP THE TAPE"
         ^ here is 23760, which is garbage to call at
The author of this book uses a special assembler (McGraw-Hill as stated in the preface).
And that's why all examples in this book use this 'org 23760' which is causing trouble in ZX Spin.
Try a higher ORG address and adjust the calls.

In the book's example there's a line

Code: Select all

1 REM >? STEP ....etc
which is missing in your program. This is the part that's supposed to be called.
Last edited by sn3j on Mon Jan 02, 2023 5:17 pm, edited 1 time in total.
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Mon Jan 02, 2023 4:26 pm Hi!
Right at the start there's a call to 23760, and that's right into the first line of your Basic program.

Code: Select all

500 DATA 24,79,5,2,"STOP THE TAPE"
         ^ here is 23760, which is garbage to call at
hi,

im not sure how to do that. there are so many calls to addresses around 23xxx in the code that im not sure im at a level where i would be able to edit these. i did try an org at 40000 already btw.
Last edited by 777 on Mon Jan 02, 2023 5:29 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
WhatHoSnorkers
Manic Miner
Posts: 264
Joined: Tue Dec 10, 2019 3:22 pm

Re: i have another piece of code that just locks up

Post by WhatHoSnorkers »

I believe that bit of code is using a trick that was used on the ZX81 (that had no CLEAR command, or SAVE "" CODE). You stick a REM statement with lots of characters as line 1, and then overwrite the comments with machine code. You can spot programs that do this as LISTing them is a right pain.

I've not forgotten that other routine by the way.
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: i have another piece of code that just locks up

Post by TMD2003 »

Holding machine code in a REM statement is something that can practically only be done on the ZX81. On that machine, if it comes across a character code in the REM that is not used (e.g. 67-111, all of which are LD instructions) or something unprintable (e.g. 117, which is EDIT and also corresponds to an LD instruction), it'll print a question mark, which is CHR$ 15, although the required value is what is stored in the REM.

This same technique on the ZX80 will cause it to crash - which is why ZX80 machine code is so horribly impractical. The Spectrum will attempt to print anything printable, and that includes the control codes. The DJNZ instruction's code is 16, which is the INK control code, and unless that's followed by 0-7 (which it never will be for a backwards jump), there will be a K Invalid colour error. And if you're writing even the most rudimentary machine code, there'll be a backwards-facing DJNZ in there somewhere.

Also, @WhatHoSnorkers - the ZX81 did have CLEAR, but its only use was to clear the variables, it couldn't be used to set RAMTOP, which required a couple of pokes. Moving RAMTOP wasn't very useful, because as you say there was no SAVE "..." CODE, and the ZX81 manual specifically stated that anything stored above RAMTOP could not be saved. I still found a use for it when writing Illuminati - the variables that make the code work were all put above RAMTOP instead of in the REM statement, as there was never a need to save them.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Mon Jan 02, 2023 4:26 pm
The author of this book uses a special assembler (McGraw-Hill as stated in the preface).
And that's why all examples in this book use this 'org 23760' which is causing trouble in ZX Spin.
Try a higher ORG address and adjust the calls.

In the book's example there's a line

Code: Select all

1 REM >? STEP ....etc
which is missing in your program. This is the part that's supposed to be called.
i did just try to change call 23760 to call 30001 and 40000 and adjusted the basic code but it still crashes.
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
WhatHoSnorkers
Manic Miner
Posts: 264
Joined: Tue Dec 10, 2019 3:22 pm

Re: i have another piece of code that just locks up

Post by WhatHoSnorkers »

Thanks for that! It's been... a while since I got my ZX81 out and I never got that advanced with it!
I have a little YouTube channel of nonsense
https://www.youtube.com/c/JamesOGradyWhatHoSnorkers
sn3j
Manic Miner
Posts: 603
Joined: Mon Oct 31, 2022 12:29 am
Location: Germany

Re: i have another piece of code that just locks up

Post by sn3j »

777 wrote: Mon Jan 02, 2023 5:30 pm i did just try to change call 23760 to call 30001 and 40000 and adjusted the basic code but it still crashes.
I think you can omit the call. Instead do this:

Code: Select all

;call 23760
ld a,2
call 5633 ; open channel 'S'
and give it a go.
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Mon Jan 02, 2023 5:51 pm I think you can omit the call. Instead do this:

Code: Select all

;call 23760
ld a,2
call 5633 ; open channel 'S'
and give it a go.
ok, the abc characters come up now but they are not udg's. and when i try and press a key the screen shows artefacts and eventually crashes. it also looks like some of the machine code is running over into basic when i press certain keys
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: i have another piece of code that just locks up

Post by sn3j »

777 wrote: Tue Jan 03, 2023 2:57 am ok, the abc characters come up now but they are not udg's. and when i try and press a key the screen shows artefacts and eventually crashes. it also looks like some of the machine code is running over into basic when i press certain keys
That's good, because now you're able to observe something that can be worked on, instead of experiencing a crash.
The UDGs are defined right at the start. Check why this is not done. Set a breakpoint at the first instruction and go step by step. The first LDIR is supposed to copy the graphic bytes to the UDG area, pointed to by (23675). This should be 65368.
So right at the start of that LDIR you should see hl=DATA1, de=65368 and bc=24.
It might be helpful to omit the DI for now, because it locks up the interrupt and causes any HALT to freeze the machine.
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Tue Jan 03, 2023 7:01 am That's good, because now you're able to observe something that can be worked on, instead of experiencing a crash.
The UDGs are defined right at the start. Check why this is not done. Set a breakpoint at the first instruction and go step by step. The first LDIR is supposed to copy the graphic bytes to the UDG area, pointed to by (23675). This should be 65368.
So right at the start of that LDIR you should see hl=DATA1, de=65368 and bc=24.
It might be helpful to omit the DI for now, because it locks up the interrupt and causes any HALT to freeze the machine.
ok, ive got the udgs to display properly but 2 other things dont work here.

if i set the breakpoint at the beginning of the code it just jumps to address 5613 and omitting the di does not stop it crashing.
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: i have another piece of code that just locks up

Post by sn3j »

777 wrote: Tue Jan 03, 2023 1:09 pm ok, 3 things dont work here.

if i set the breakpoint at the beginning of the code it just jumps to address 5613. if i change de to 65368, nothing changes and omitting the di does not stop it crashing.

ive also taken a look at the code regarding the udgs and have compared it to code that works and cannot see anything wrong.
It should jump to 5633, as stated in the 'call 5633', probably this is what you observed. If not, double-check that exactly this address is called.
The debugger offers two ways to step ahead, one is 'Step' and one is 'Step Over'. If you choose to step over the call you won't see it executing the code at 5633, and the debugger stops at the instruction right after that call. Alternatively, if you get bored doing that Step Over, you can move the breakpoint somewhere else, or even set a second breakpoint.

If you run PRINT USR "a" you should get a number that's identical to the number at 23675, this is where the DE needs to sit right before the LDIR is executed. Normally this is 65368.
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
AndyC
Dynamite Dan
Posts: 1467
Joined: Mon Nov 13, 2017 5:12 am

Re: i have another piece of code that just locks up

Post by AndyC »

It's got to be said, that's a horrible book for trying to learn assembly from. And the embedded machine code in REMs was never going to play well with typed in code. I wonder if it originally came with a cassette copy of all the listings or if it just never worked?

Even the assembly examples are pretty terrible as they jump all over the place unnecessarily and are full of what I'd call "writing BASIC in assembly language" which is always a terrible way to learn, even if it feels more like writing a BASIC program initially.
User avatar
777
Manic Miner
Posts: 542
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: i have another piece of code that just locks up

Post by 777 »

AndyC wrote: Tue Jan 03, 2023 1:41 pm It's got to be said, that's a horrible book for trying to learn assembly from. And the embedded machine code in REMs was never going to play well with typed in code. I wonder if it originally came with a cassette copy of all the listings or if it just never worked?

Even the assembly examples are pretty terrible as they jump all over the place unnecessarily and are full of what I'd call "writing BASIC in assembly language" which is always a terrible way to learn, even if it feels more like writing a BASIC program initially.
yeah, it did come with a tape but i cant find it anywhere
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Tue Jan 03, 2023 1:39 pm
If you run PRINT USR "a" you should get a number that's identical to the number at 23675, this is where the DE needs to sit right before the LDIR is executed. Normally this is 65368.
ive managed to get the sprite to move around the screen but it crashes when i press any of the other keys. i'll keep checking.
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Tue Jan 03, 2023 1:39 pm
If you run PRINT USR "a" you should get a number that's identical to the number at 23675, this is where the DE needs to sit right before the LDIR is executed. Normally this is 65368.
i went through the code and found a few bugs. its kind of mostly working now, i think. if you press the r key, it crashes but every other key seems to do something and it crashes at the title screen if you press a key and dont break out of it

Code: Select all

org 40000
di
;call 23670
ld a,2
call 5633 ; open channel 'S'
jr START
DATA1
defb 0,0,15,24,49,226,225,224  
defb 24,60,255,225,153,255,231
defb 60,0,0,240,24,140,71,135,7
START
ld de,(23675)
ld hl,DATA1
ld bc,24
ldir
jr BEGIN
DATA2
defb 22,0,0,16,8,17,8,144,145
defb 146
BEGIN
ld de,DATA2
ld bc,10
call 8252
ld de,23296
ld hl,DATA2
ld bc,10
ldir
MOVE
ld hl,(23297)
ld bc,61438
in a,(c)
cp  255
jr z,lp12
bit 0,a
jr nz,lp1
inc h
Lp1
bit 1,a
jr nz,lp2
dec h
Lp2
bit 2,a
jr nz,lP3
inc l
lP3
bit 3,a
jr nz,Lp4
dec l
Lp4
ld a,l
cp 22
jr nz,lp5
dec l
jr Lp6
Lp5
cp 255
jr nz,lp6
inc l
Lp6
ld a,h
cp 30
jr nz,Lp7
dec h
jr Lp8
Lp7
cp 255
jr nz,lp8
inc h
Lp8
ld de, (23297)
xor a
push hl
sbc hl,de
pop hl
jr z,Lp12
ld (23297) ,hl
OVER1
ld (iy+87),3
ld de, DATA2
ld bc,10
call 8252
ld de, 23296
ld bc,10
call 8252
ld de,DATA2
ld hl,23296
ld bc,10
ldir
LP12
ld bc,63486
in a,(c)
and 15
jr z,SCR
cp 3
jr z,SCR
cp 12
jr z,SCR
Cp 15
jr z,SCR
push af
ld (iy+87),3
ld de,DATA2
ld bc,10
call 8252
pop af
bit 0,a
push af
call z,UROLL
pop af
bit 1,a
push af
call z,dROLL
pop  af
bit 2,a
push af
call z,lROLL
pop af
bit 3,a
call z,RROLL
ld de,DATA2
ld bc,10
call 8252
scr
ld bc,64510
in a, (c)
and 15
jr z,DELAY
cp 3
jr z,DELAY
cp 12
Jr z,DELAY
cp 15
jr z,DELAY
push af
ld (iy+87),3
ld de,DATA2
ld bc,10
call 8252
pop af
bit 0,a
push af
call z,USCR
pop af
bit 1,a
push af
Call z,DSCR
pop af
bit 2,a
push af
call z,LSCR
pop af
bit 3,a
call z,RSCR
ld de,DATA2
ld bc,10
call 8252
delay
ld hl,10000
l1
dec hl
ld a,h
or l
jr nz,L1
ld bc,32766
in a,(c)
bit 0,a
jp nz,MOVE
ld (iy+87),0
ei
ret
uscr
ld de, 22528
ld hl,22560
ld bc,736
ldir
ld b,32
ld a, (23693)
l2
ld (de),a
Inc de
djnz L2
ld de, 16384
ld hl,16416
ld bc, 2016
ldir
ld b,8
ld hl,18432
ld de, 16608
l3
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
Inc h
djnz L3
ld de, 18432
ld hl,18464
ld bc,2016
ldir
ld b,8
ld hl,20480
ld de,18656
l4
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L4
ld de,20480
ld hl,20512
ld bc,2016
ldir
ld b,8
ld hl,20704
l5
push bc
push hl
ld b,32
l6
ld (hl),0
inc hl
djnz L6
pop hl
pop bc
inc h
djnz L5
ret
dscr
ld de,23295
ld hl,23263
ld bc,736
lddr
ld b,32
ld a, (23693)
l7
ld (de),a
inc de
djnz L7
ld de,22527 
ld hl,22495
ld bc,2016
lddr
ld b,8
ld hl,18656
ld de, 20480
l8
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
Inc h
djnz L8
ld de,20479
ld hl,20447
ld bc, 2016
lddr
ld b,8
ld hl, 16608
ld de, 18432
l9
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L9
ld de,18431
ld hl,18399
ld bc,2016
lddr
ld hl,16384
l10
ld b,32
l11
ld (hl),0
inc hl
djnz L11
xor a
ld l,a
inc h
ld a,h
cp 72
jr nz,L10
ret
lscr
ld b,24
ld hl, 22528
l12
push hl
pop de
push bc
inc hl
ld bc, 31
ldir
ld a, (23693)
ld (de),a
pop bc
djnz L12
ld hl, 16384
xor a
ld b,192
l13
push bc
push hl
pop de
inc hl
ld bc,31
ldir
ld (de),a
pop bc
djnz l13
ret
rscr 
ld b,24
ld hl, 23295
l14
push hl
pop de
push bc
dec hl
ld bc,31
lddr
ld a, (23693)
ld (de),a
pop bc
djnz L14
ld hl, 22527
xor a
ld b,192
l15
push bc
push hl
pop de
dec hl
ld bc, 31
lddr
ld (de),a
pop bc
djnz L14
ret
uroll
ld hl,22528
push hl
pop de
ld b,32
l16
ld a, (hl)
push af
inc hl
djnz L16
ld bc,736
ldir
ld b,32
l17
pop af
dec hl
ld (hl),a
djnz L17
ld hl,16384
l18
ld b,32
l19
ld a, (hl)
push af
inc hl
djnz L19
xor a
ld l,a
inc h
ld a,h
cp 72
jr nz,l18
ld de, 16384
ld hl,16416
ld bc,2016
ldir
ld b,8
ld hl, 18432
ld de, 16608
l20
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz l20
ld de, 18432
ld hl, 18464
ld bc,2016
ldir
ld b,8
ld hl, 20480
ld de, 18656
l21
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L21
ld de,20480
ld hl,20512
ld bc,2016
ldir
ld hl,22527
l22
ld b,32
l23
pop af
ld (hl),a
dec hl
djnz L23
ld a, 255
ld l,a
dec h
ld a,h
cp 79
jr nz,l22
ret
droll
ld hl, 23295
push hl
pop de
ld b,32
l24
ld a, (hl)
push af
dec hl
djnz l24
ld bc, 736
lddr
ld b,32
l25
pop af
inc hl
ld (hl),a
djnz l25
ld hl, 22527
l26
ld b,32
l27
ld a, (hl)
push af
dec hl
djnz l27
ld a, 255
ld l,a
dec h
ld a,h
cp 79
jr nz,l26
ld de, 22527
ld hl, 22495
ld bc, 2016
lddr
ld b,8
ld hl, 18656
ld de, 20480
l28
push bc
push hl
push de
ld bc,32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L28
ld de, 20479
ld hl,20447
ld bc, 2016
lddr
ld b,8
ld hl, 16608
ld de, 18432
l29
push bc
push hl
push de
ld bc, 32
ldir
pop de
pop hl
pop bc
inc d
inc h
djnz L29
ld de, 18431
ld hl, 18399
ld bc, 2016
lddr
ld hl,16384
l30
ld b,32
l31
pop af
ld (hl),a
inc hl
djnz l31
xor a
ld l,a
inc h
ld a,h
cp 72
jr nz,L30
ret
lroll
ld b,216
ld hl, 16384
l32
push Hl
pop de
push bc
ld a, (hl)
inc hl
ld bc,31
ldir
ld (de),a
pop bc
djnz L32
ret
rroll
ld b,216
ld hl, 23295
l33
push hl
pop de
push bc
ld a, (hl)
dec hl
ld bc,31
lddr
ld (de),a
pop bc
djnz l33
ret
heres another snapshot:

https://easyupload.io/36ievn

Image

Image
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: i have another piece of code that just locks up

Post by sn3j »

Ok. There's a bug in function USCR that's probably crashing the game:

Code: Select all

ld bc,12016  <-- should be 2016
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Tue Jan 03, 2023 3:41 pm Ok. There's a bug in function USCR that's probably crashing the game:

Code: Select all

ld bc,12016  <-- should be 2016
yeah, i fixed that bug a while back
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: i have another piece of code that just locks up

Post by sn3j »

777 wrote: Tue Jan 03, 2023 3:47 pm yeah, i fixed that bug a while back
Repost your actual code so we can see what's going on.
In RSCR there's two L14 and two djnz L14, page 54, that's a typo in the book.
You already changed the second L14 to L15, which is ok, but didn't fix the djnz (the one right before the RET).

Code: Select all

;djnz L14
djnz L15
Last edited by sn3j on Tue Jan 03, 2023 3:57 pm, edited 1 time in total.
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Tue Jan 03, 2023 3:54 pm Repost your actual code so we can see what's going on.
In RSCR there's two L14 and two djnz L14, page 54, that's a typo in the book.
You already changed the second L14 to L15, which is ok, but didn't fix the djnz.

Code: Select all

;djnz L14
djnz L15
i did its up there ^

ok, thats fixed now. thank you. im wondering if theres supposed to be some kind of udg in the foreground/background that isnt getting displayed instead of just a green bar?
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: i have another piece of code that just locks up

Post by sn3j »

777 wrote: Tue Jan 03, 2023 3:54 pm i did its up there ^

ok, thats fixed now. thank you. im wondering if theres supposed to be some kind of udg in the foreground/background that isnt getting displayed instead of just a green bar?
I think that was supposed to be loaded from tape. There are some great screens here that you could use for that.
Just load a screen before calling the program.

As it stands, the code from the book just moves the screen and the ship around, it's not creating any background graphics.
Happy coding.
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: i have another piece of code that just locks up

Post by 777 »

sn3j wrote: Tue Jan 03, 2023 4:05 pm I think that was supposed to be loaded from tape. There are some great screens here that you could use for that.
Just load a screen before calling the program.

As it stands, the code from the book just moves the screen and the ship around, it's not creating any background graphics.
Happy coding.
ok thank you. ive changed a few calls in the basic routine and now it displays the menu without crashing and scrolls

and i just loaded a picture in and it looks great
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: i have another piece of code that just locks up

Post by sn3j »

amazing :ugeek:
POKE 23614,10: STOP      1..0 hold, SS/m/n colors, b/spc toggle
Post Reply