why wont this code increase the number displayed on the screen each time?

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

why wont this code increase the number displayed on the screen each time?

Post by 777 »

Code: Select all

org 40000
call 3503
ld a,0
start
inc a
rst 16
jp start
i have no idea...
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
User avatar
PeterJ
Site Admin
Posts: 6873
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: why wont this code increase the number displayed on the screen each time?

Post by PeterJ »

RST is printing the Character code @777. Look at page 135 onwards of the original Spectrum manual in the code column.
Try starting A at 48 which is a 0. After 9, you get the maths symbols then A-Z
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: why wont this code increase the number displayed on the screen each time?

Post by 777 »

sorry, i meant character.

nope, it still gets stuck on 9's...
Last edited by 777 on Sun Apr 24, 2022 2:28 pm, edited 1 time in total.
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
User avatar
PeterJ
Site Admin
Posts: 6873
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: why wont this code increase the number displayed on the screen each time?

Post by PeterJ »

777 wrote: Sun Apr 24, 2022 2:27 pm sorry, i meant character
Yes, so set A to 48
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: why wont this code increase the number displayed on the screen each time?

Post by 777 »

tried that, it still gets stuck on 9's...
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
User avatar
PeterJ
Site Admin
Posts: 6873
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: why wont this code increase the number displayed on the screen each time?

Post by PeterJ »

777 wrote: Sun Apr 24, 2022 2:27 pm
nope, it still gets stuck on 9's...
It will because after 9 comes the maths characters and A-Z

Image
User avatar
Luzie
Manic Miner
Posts: 907
Joined: Fri May 01, 2020 2:07 pm

Re: why wont this code increase the number displayed on the screen each time?

Post by Luzie »

777 wrote: Sun Apr 24, 2022 2:12 pm

Code: Select all

org 40000
call 3503
ld a,0
start
inc a
rst 16
jp start
i have no idea...
Fast idea: Try with PUSH before rst16 and POP after rst16:

Code: Select all

org 40000
call 3503
ld a,0
start
inc a
push af
rst 16
pop af
jp start
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: why wont this code increase the number displayed on the screen each time?

Post by 777 »

ok, i c. so i should use the calculator routine?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
jimmy
Drutt
Posts: 31
Joined: Sun Nov 24, 2019 9:06 pm

Re: why wont this code increase the number displayed on the screen each time?

Post by jimmy »

...because RST 16 does the same as PRINT CHR$(A) in BASIC. It also destroys the value of A when it has finished.
If you want to print a number (0-9999) you can use another ROM routine:

Code: Select all

org 40000
call 3503	;ROM routine CLS
ld bc,0		;start counting from 0
loop:
push bc		;preserve BC as routine below destroys value
call 6683	;ROM routine OUT-NUM
pop bc		;restore BC
inc bc
jr loop
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: why wont this code increase the number displayed on the screen each time?

Post by 777 »

Luzie wrote: Sun Apr 24, 2022 2:30 pm
Fast idea: Try with PUSH before rst16 and POP after rst16:

yea that works, but that is weird cos i tried that before...
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: why wont this code increase the number displayed on the screen each time?

Post by Dr beep »

The RST 16 effects A, so PUSH Iand POP is needed.
Post Reply