Newbie ZX Spectrum question

New to FreeBASIC? Post your questions here.
pmra
Posts: 7
Joined: Mar 23, 2021 16:20

Newbie ZX Spectrum question

Post by pmra »

Hi,

I'm new to FreeBasic and this forum, so first I'd like to greet everyone here and thank you all for your work.
Second I want to say that I am NOT a developper, I only like to learn. I just found FreeBasic and, maybe stupidly, started asking this.

Because of so much pandemic 'free' time, I reopened an old book, containing a ZXSpectrum BASIC listing, something I actually coded and used on a ZX 128K disk 'PC' about 30+ years ago.
So, my question here would be, can that code be somehow converted to FreeBasic? Can I write it and get it converted?
Just to start with the right foot, I found https://www.fbide.freebasic.net/, is this the more appropriate tool to edit/code? Are there others?

Much obliged by any answer, and apologies for the ignorance.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Newbie ZX Spectrum question

Post by BasicCoder2 »

There are probably ZX Spectrum emulators out there.
https://dotneteer.github.io/spectnetide/
Translating old code is a pain. Ideally you simply rewrite the program. All programs can be described at a higher level. Just translate up that old code to that higher level and then translate back down to the language you want to use.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Newbie ZX Spectrum question

Post by MrSwiss »

pmra wrote:... is this the more appropriate tool to edit/code? Are there others?
See: FreeBASIC IDEs/Editors listed.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Newbie ZX Spectrum question

Post by jj2007 »

Hi pmra,

My second BASIC computer was a ZX Spectrum, too, but I don't have listings any more. As BasicCoder2 wrote above, rewriting is probably easier - but in order to judge what to do, we should have a look at your listings. Can you post something, please? I admit I am curious ;-)
pmra
Posts: 7
Joined: Mar 23, 2021 16:20

Re: Newbie ZX Spectrum question

Post by pmra »

BasicCoder2 wrote:There are probably ZX Spectrum emulators out there.
https://dotneteer.github.io/spectnetide/
Translating old code is a pain. Ideally you simply rewrite the program. All programs can be described at a higher level. Just translate up that old code to that higher level and then translate back down to the language you want to use.
Thanks for answering! I kind of was expecting this. I'll look for a good Freebasic course/tutorial.
pmra
Posts: 7
Joined: Mar 23, 2021 16:20

Re: Newbie ZX Spectrum question

Post by pmra »

MrSwiss wrote:
pmra wrote:... is this the more appropriate tool to edit/code? Are there others?
See: FreeBASIC IDEs/Editors listed.
Thanks for answering! Will do.
pmra
Posts: 7
Joined: Mar 23, 2021 16:20

Re: Newbie ZX Spectrum question

Post by pmra »

jj2007 wrote:Hi pmra,

My second BASIC computer was a ZX Spectrum, too, but I don't have listings any more. As BasicCoder2 wrote above, rewriting is probably easier - but in order to judge what to do, we should have a look at your listings. Can you post something, please? I admit I am curious ;-)
Thanks for your interest! Here goes, its about 25 A5 pages of this:
https://imgur.com/a/NwQjx5m
Since I don't have it on digital form, rewriting is definitely the way.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Newbie ZX Spectrum question

Post by jj2007 »

Agreed! It will be a bit of typing, but it's worth the effort. Note that FreeBasic does not have line numbers - you will use proper names instead. For example:

Code: Select all

If qs="1" then
  Action1
elseif qs="2" 
  Action2
elseif qs="3" 
  Action3
endif
....
Sub Action1
  ... more code, whatever must be done if q$="1" ...
End Sub
That looks different at first sight, but it's much easier to use, and less confusing than "GOTO 123" ;-)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Newbie ZX Spectrum question

Post by BasicCoder2 »

@pmra
Here goes, its about 25 A5 pages of this:
https://imgur.com/a/NwQjx5m
Since I don't have it on digital form, rewriting is definitely the way.
Ouch! How unreadable old code was! I would scan the code and perhaps use an OCR to translate it into text. If I was really keen on translating the old code I think I would work on a program to help with the task.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Newbie ZX Spectrum question

Post by dodicat »

Freebasic can use line numbers if option #lang "qb" or lang "fblite" is used.
Example:

Code: Select all

'rem prime factors
#lang "qb"

1 lowers%=30000
2 uppers%=30500

10 For counts% = lowers% To uppers%
20 number% = counts%
30
40 Print number%;"= ";
50 divisor% = 2
60 While divisor% <= number%
70 Gosub 490
80 divisor% = divisor% + 1
90 Wend       
100 Print
101 Next counts%
102 Print

rem subroutine
490
500 If number%/divisor%-Int(number%/divisor%) = 0 Then
510 c$="x"
520 number% = number% / divisor%
530 If number% = 1 Then c$=""
540 Print divisor%;c$;
550 Goto 490
560 End If
570 If counts%<=uppers% Then Return

580 Sleep 
merge or list or eval or plot (and many others I reckon) are not freebasic keywords.
You only need the salient line numbers for the goto's, gosubs, but writing in the others does no harm.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Newbie ZX Spectrum question

Post by deltarho[1859] »

pmra wrote:I'll look for a good Freebasic course/tutorial.
Go to the following link. Not many people mention this, but it is well-structured and well written.

FreeBASIC Tutorials

The right-hand pane may be blank, click on FreeBasic at the top of the left-hand pane.

There are quite a few example programs - try them.

BTW, the correct spelling is FreeBASIC.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Newbie ZX Spectrum question

Post by BasicCoder2 »

I printed a page of FreeBASIC source code and then scanned it into an image.
I then used an online ocr to convert it back to text. It seemed to work fine.
A nice clean scanned image would be required as when I tried
https://imgur.com/a/NwQjx5m
it didn't convert much of it only a few characters.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Newbie ZX Spectrum question

Post by deltarho[1859] »

It has been hinted at but the way to go is

Code: Select all

Old code -> Pseudo code -> New code

Code: Select all

Old code -> New code
will drive you mad.

Code: Select all

Pseudo code -> New code
needs more than a passing acquaintance of 'New code'. Understand the fundamentals of 'New code' and then consider 'Pseudo code -> New code'.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Newbie ZX Spectrum question

Post by jj2007 »

Hi pmra,

deltarho[1859] is right: start with pseudocode describing the conditions (if qs="1" Then ...) and actions required. Then look into the help file to see which commands you need for the "actions". Members here will help you with that. You will soon see that FreeBasic is much clearer and easier than Spectrum BASIC ;-)

Code: Select all

If qs="1" then
  Action1  ' ex GOTO 3460
elseif qs="2"
  Action2  ' ex GOTO q11
elseif qs="3"
  Action3  ' ex GOTO 2020
endif
....
Sub Action1
  ... more code, whatever must be done if q$="1" ...
End Sub
Image
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Newbie ZX Spectrum question

Post by deltarho[1859] »

Come to think of it prma may not know what pseudocode is. Back in the ZX Spectrum days we talked about top-down programming and flow charts.

Pseudocode
Post Reply