Why does BASIC add a space?

Started by OldSchoolGamer, 18:34, 01 December 21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

OldSchoolGamer

This is probably a numpty question, but here goes... I never owned a CPC but I did use them quite a lot back in the 80s when I worked in games publishing. Anyway, I have need to emulate a CPC for a project I am working on, and I have to enter a BASIC listing taken from an old issue of Amtix! magazine. I am using a recent version of Caprice, but have also tried this in an old WinApe with the same results.


This is just an excerpt from the full BASIC listing, but when the following line is entered, the emulated CPC always adds a space...


10 FOR N=9FDF TO 1E09


... yet when you LIST it shows this ...


10 FOR N=9 FDF TO 1E+09


Adding the + automatically is not an issue, but the space always means that the program won't run, as it reports a Syntax Error.


Why is the CPC doing this? Any ideas how to avoid it? (Obviously this is part of a FOR NEXT loop, where it reads data and pokes some values into specific addresses).


Any help much appreciated! :-)










Sid_

And if you use hexadecimal annotation beginning by a '&' ?

eto

Quote from: OldSchoolGamer on 18:34, 01 December 21Adding the + automatically is not an issue, but the space always means that the program won't run, as it reports a Syntax Error.

There seems to be something wrong. This should probably be memory addresses in hex. They should  have a & in front of the number. Without that, the interpreter sees a number followed by a string and tries to make sense of it - which fails. Therefore the Syntax Error. The + between 1e and 09 is an issue. This is the exponential representation of a number and means 1*10^9, or 1000000000.

But even if you put a & in front of the numbers, I still see an issue as usually you go from low numbers to high numbers, but &1e09 is smaller than &9fdf... You might check this again, if that's really correct.

OldSchoolGamer

Okay, the listing covers cheats for a certain well known Amstrad CPC game. It was published in an issue of Amtix, and it did have a typo which was corrected in a later issue (and the correction is present in the BASIC code listed below). However, the problem I have been experiencing was never mentioned in later issues. Here it is in full, and if anyone can suggest a tweak to this so it does work, that would be very helpful!




50 MEMORY &3AFF:MODE 1: BORDER 0
60 INK 0,0: INK 1,10: INK 2,18: INK 3,8
70 WINDOW #1,14,26,12,12: WINDOW #2,14,26,14,14
80 LOAD "!ELITE1"
90 POKE &3BD1,247: POKE 48,195: POKE 49,0: POKE 50,160
100 FOR N=9FDF TO 1E+09: READ A$:IF A$<> "END" THEN POKE N,VAL("&"+A$): NEXT
110 CALL &9FDF,1486
120 DATA a4,5a,5a,4b,4a,21,df,9f,11,00
130 DATA a0,06,1b,1a,cb,41,28,03,86,18
140 DATA 01,ae,12,1c1, O,f3,23,0d,20,ea
150 DATA c3,00,3b,d7,5b,63,56,15,9b,56
160 DATA 8f,84,96,74,cc,8c,bf,a2,54,dc
170 DATA 74,77,f5,bf,23,40,de,35,41,ea
180 REM THE POKES START HERE!
190 REM NO ENERGY LOSS
200 DATA 42,be,43
210 REM INFINITE MISSILES
220 DATA 32,11,46
230 REM MISSILES BLOW UP SPACE STATIONS
240 DATA 32,49,94
250 REM SPACE STATIONS LAUNCH THARGOIDS
260 DATA 32,26,93
270 REM ONE HIT TO DESTROY SPACE SHIP
280 DATA 32,a9,87
290 REM NO LASER TEMP RISE
300 DATA32,51,87
310 REM INFINITE FUEL
320 DATA 32,01,74
330 REM NO HYPERSPACE LIMIT
340 DATA 32,0d,71,32,17,71
350 REM CONSTANT GALACTIC HYPERSPACE
360 DATA 32,f9,70
370 REM CONSTANT ESCAPE POD
380 DATA 32,2c,46
390 REM NO CARGO LOSS ON ESCAPE
400 DATA 32,48,46
410 REM INFINITE CARGO
420 DATA 32,b0,50
430 REM CONSTANT ENERGY BOMB
440 DATA 32,d4,30
450 REM NO ENERGY BOMB SCREEN FLASH
460 DATA 3e,c9,32,e3,30
470 REM INFINITE CREDITS
480 DATA 3e,03,32,75,fe,3e,18,32,83,fe
490 REM ECM ENERGY JAMMER
500 DATA af,32,9b,5a,32,a5,5a,3e,18,32,ed,92
510 REM CLOAKING DEVICE
520 DATA 3e,21,32,da,5a,3e,f6,32,de,5a,af,32,ed,5a
530 REM INDESTRUCTIBILITY
540 DATA 3e,c3,32,2a,13,af,32,81,85,32,60,88
550 REM ALTER CHAR SET
560 DATA 3e,1f,32,ea,5c
570 REM END OF POKES
580 DATA c3,60,00,END

Fessor

Since I've been dealing with Disassembling/Expanding Elite for some time...
Are there Details available for the Listing? Amtix-Issue-Number?
It seems to me that this listing is thought for the Tape-Version. On the Disc-Versions there is no File with Name "Elite1".
AFAIK there is a Disc-Version available that has this Pokes.





Urusergi

Quote from: Fessor on 22:06, 01 December 21
Are there Details available for the Listing? Amtix-Issue-Number?


Issue 12 page 72


Fessor

As thought, its for the english Tape-Version.IMHO It should look like this:
50 MEMORY &3AFF:MODE 1: BORDER 0
60 INK 0,0: INK 1,10: INK 2,18: INK 3,8
70 WINDOW #1,14,26,12,12: WINDOW #2,14,26,14,14
80 LOAD "!ELITE1"
90 POKE &3BD1,247: POKE 48,195: POKE 49,0: POKE 50,160
100 FOR N=&9FDF TO &A07F: READ A$:IF A$<> "END" THEN POKE N,VAL("&"+A$): NEXT
110 CALL &9FDF,1486
120 DATA a4,5a,5a,4b,4a,21,df,9f,11,00
130 DATA a0,06,1b,1a,cb,41,28,03,86,18
140 DATA 01,ae,12,1c,1O,f3,23,0d,20,ea
150 DATA c3,00,3b,d7,5b,63,56,15,9b,56
160 DATA 8f,84,96,74,cc,8c,bf,a2,54,dc
170 DATA 74,77,f5,bf,23,40,de,35,41,ea
180 REM THE POKES START HERE!
190 REM NO ENERGY LOSS
200 DATA 42,be,43
210 REM INFINITE MISSILES
220 DATA 32,11,46
230 REM MISSILES BLOW UP SPACE STATIONS
240 DATA 32,49,94
250 REM SPACE STATIONS LAUNCH THARGOIDS
260 DATA 32,26,93
270 REM ONE HIT TO DESTROY SPACE SHIP
280 DATA 32,a9,87
290 REM NO LASER TEMP RISE
300 DATA32,51,87
310 REM INFINITE FUEL
320 DATA 32,01,74
330 REM NO HYPERSPACE LIMIT
340 DATA 32,0d,71,32,17,71
350 REM CONSTANT GALACTIC HYPERSPACE
360 DATA 32,f9,70
370 REM CONSTANT ESCAPE POD
380 DATA 32,2c,46
390 REM NO CARGO LOSS ON ESCAPE
400 DATA 32,48,46
410 REM INFINITE CARGO
420 DATA 32,b0,50
430 REM CONSTANT ENERGY BOMB
440 DATA 32,d4,30
450 REM NO ENERGY BOMB SCREEN FLASH
460 DATA 3e,c9,32,e3,30
470 REM INFINITE CREDITS
480 DATA 3e,03,32,75,fe,3e,18,32,83,fe
490 REM ECM ENERGY JAMMER
500 DATA af,32,9b,5a,32,a5,5a,3e,18,32,ed,92
510 REM CLOAKING DEVICE
520 DATA 3e,21,32,da,5a,3e,f6,32,de,5a,af,32,ed,5a
530 REM INDESTRUCTIBILITY
540 DATA 3e,c3,32,2a,13,af,32,81,85,32,60,88
550 REM ALTER CHAR SET
560 DATA 3e,1f,32,ea,5c
570 REM END OF POKES
580 DATA c3,60,00,END


Dont know if it will work. Looks like the coder has encrypted his routine...

org #9fdf
.l9fdf
and h
ld e,d
ld e,d
ld c,e
ld c,d
ld hl,l9fdf
.l9fe7
ld de,la000
ld b,#1b
ld a,(de)
bit 0,c
jr z,l9ff4
add (hl)
jr l9ff5
.l9ff4
xor (hl)
.l9ff5
ld (de),a
inc e
ld bc,#23f3
dec c
jr nz,l9fe7
jp #3b00
.la000
rst #10
ld e,e
ld h,e
ld d,(hl)
dec d
sbc e
ld d,(hl)
adc a
add h
sub (hl)
ld (hl),h
call z,#bf8c
and d
ld d,h
call c,#7774
push af
cp a
inc hl
ld b,b
sbc #35
ld b,c
jp pe,#be42
ld b,e
ld (#4611),a
ld (#9449),a
ld (#9326),a
ld (#87a9),a
ld (#7401),a
ld (#710d),a
ld (#7117),a
ld (#70f9),a
ld (#462c),a
ld (#4648),a
ld (#50b0),a
ld (#30d4),a
ld a,#c9
ld (#30e3),a
ld a,#03
ld (#fe75),a
ld a,#18
ld (#fe83),a
xor a
ld (#5a9b),a
ld (#5aa5),a
ld a,#18
ld (#92ed),a
ld a,#21
ld (#5ada),a
ld a,#f6
ld (#5ade),a
xor a
ld (#5aed),a
ld a,#c3
ld (#132a),a
xor a
ld (#8581),a
ld (#8860),a
ld a,#1f
ld (#5cea),a
jp #0060






Johnny Olsen

The Amtix version is copied from Amstrad computer user and contains a lot of type errors.

You can see the original version here

https://www.cpcwiki.eu/index.php/ACU_Issue_6,_1986

page 19

10 '        Program 1
20 ' Elite Hack Program  ZZKJ 1/4/86
30 MEMORY &3AFF:MODE 1:BORDER 0
40 INK 0,0:INK 1,24:INK 2,15:INK 3,6
50 WINDOW#1,14,26,12,12:WINDOW#2,14,26,14,14
60 LOAD"!ELITE1"
70 POKE &3BD1,247:POKE 48,195:POKE 49,0:POKE 50,160
80 FOR n=&9FDF TO 1E+09:READ A$:IF A$<> "END" THEN POKE N,VAL("&"+A$):NEXT
90 CALL &9FDF,1486
100 DATA A4,5A,5A,4B,4A,21,DF,9F,11,00
110 DATA A0,06,1B,1A,CB,41,28,03,86,18
120 DATA 01,AE,12,1C,10,F3,23,0D,20,EA
130 DATA C3,00,3B,D7,5B,63,56,15,9B,56
140 DATA 6F,84,96,74,CC,8C,BF,A2,54,DC
150 DATA 74,77,F5,BF,23,40,DE,35,41,EA
160 ' ***** START OF POKES *****
170 REM No Energy Loss
180 DATA 32,c1,43
190 REM INFINITE MISSILES
200 DATA 32,14,46
210 REM MISSILES BLOW UP SPACE STATIONS
220 DATA 32,49,94
230 REM SPACE STATIONS LAUNCH THARGOIDS
240 DATA 32,26,93
250 REM ONE HIT TO DESTROY SPACESHIPS
260 DATA 32,a9,87
270 REM NO LASER TEMP RISE
280 DATA 32,51,87
290 REM INFINITE FUEL
300 DATA 32,01,74
310 REM NO HYPERSPACE RANGE LIMIT
320 DATA 32,0d,71,32,17,71
330 REM CONSTANT GALACTIC HYPERSPACE
340 DATA 32,f9,70
350 REM CONSTANT ESCAPE POD
360 DATA 32,2f,46
370 REM NO CARGO LOSS ON ESCAPE
380 DATA 32,4b,46
390 REM INFINITE CARGO
400 DATA 32,b3,50
410 REM CONSTANT ENERGY BOMB
420 DATA 32,d7,30
430 REM NO ENERGY BOMB SCREEN FLASH
440 DATA 3e,c9,32,e6,30
450 REM INFINITE CASH
460 DATA 3e,03,32,75,fe,3e,18,32,83,fe
470 REM E.C.M. SYSTEM JAMMER
480 DATA af,32,9e,5a,32,a8,5a,3e,18,32,ed,92
490 REM CLOAKING DEVICE
500 DATA 3e,21,32,dd,5a,3e,f6,32,e1,5a,af,32,e3,5a
510 REM INDESTRUCTABILITY
520 DATA 3e,c3,32,2a,13,af,32,81,85,32,60,88
530 REM LOAD ALTERED CHARACTER
540 DATA 3e,1f,32,ed,5c
550 '      *** END OF POKES ***
560 DATA c3,60,00,END


ralferoo

As the last post says, the original does have the & for hex on the first one.

100 FOR N=&9FDF TO 1E+09: READ A$:IF A$<> "END" THEN POKE N,VAL("&"+A$): NEXT
110 CALL &9FDF,1486

Also, if you look at the logic at the next part, the author is using 1E+09 to effectively mean infinite, and then checking the string for END to terminate the loop. Weird because it relies on the NEXT being run as part of the conditional, but it should work fine.

Anyway, you're rediscovering the "joys" of 80s type-ins. Massive long things and if you make a single mistake, nothing works, so you have to save the program before you run it as it could easily wipe all the memory, and then painstakingly check every single character against the original. Even when you knew what line was at fault here, you still didn't notice the missing &. Remember, if you don't understand what it's doing, every character is potentially significant in these progams.

Most longer type-ins for larger programs using poke-loops would start adding simple checksums per line, so at least you could work out where your mistake was.

Johnny Olsen

Quote from: ralferoo on 11:29, 02 December 21Also, if you look at the logic at the next part, the author is using 1E+09 to effectively mean infinite, and then checking the string for END to terminate the loop. Weird because it relies on the NEXT being run as part of the conditional, but it should work fine.

Not wierd. This poke almost ruins the game, therefore you have the opportunity to leave out
some of the cheat eg delete line 200

if you had loop like this
100 FOR N=&9FDF TO &A081:READ A$:POKE N,VAL("&"+A$):NEXT
you will get an error message "DATA exhausted in 100" if you deleted some DATA.


ralferoo

It's weirder than just setting N=&9FDF and then doing N=N+1 and GOTO.

Powered by SMFPacks Menu Editor Mod