The Noob's Machine Code Thread

Anything QL Software or Programming Related.
stevepoole
Super Gold Card
Posts: 715
Joined: Mon Nov 24, 2014 2:03 pm

Re: The Noob's Machine Code Thread

Post by stevepoole »

Hi Folks,
Yes, you can use some keywords as variables, as many are rededinable...... to allow programmers to improve them if necessary.

Just try using say 'PRINT=0' as a LOCal variable. It works, but notice that the original 'PRINT' procedure then gets clobbered, as you have redefined it.

So unless you are very sure you don't need to PRINT or whatever again, DON'T ever use this feature....

This said, I have used the feature as an anti-copy device, but that was just an experiment, as anyone can copy my programs if they wish !

Regards,
Steve.
________________________


User avatar
TMD2003
Trump Card
Posts: 168
Joined: Sat Oct 10, 2020 12:18 pm

Re: The Noob's Machine Code Thread

Post by TMD2003 »

Good advice on the procedures, there! It seems I''ve done something I curse Spectrum programmers for when I'm using BASin to write with - it gets very angry if, say, the programmer has used any token names to define a variable - IN, OUT, IF and TO being the most obvious offenders. I wasn't thinking about DIR at the time, but at least it works.

Right now, I'm translating the BASIC bits of the ZX81 listing for the VIC-20. I have at least found a way of doing it with a text editor, in which I can put PRINT"{clear}" instead of the inverse heart that Commodore BASIC represents the control code with. Bread Bin listings always look like a proper mess of inverse graphics characters and more POKEs than any sane person would ever want to have to deal with. And with only three registers to play with, the machine code is going to be fun (though I only use A, B and D in the revised Z80 code so maybe I'll not have too much trouble).

It also seems a bit traitorous when the Spectrum's 40th birthday is coming up on Saturday. But on a better note: did you know, on that wonderful day, 40 years ago, even the 48K Spectrum cost less than a VIC-20 with its enormous galaxy-brain 3.5K of usable RAM? I'll probably need an extension of 8K to get this game going, at least. That'd have cost a few bob in 1982.


Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Derek_Stewart
Font of All Knowledge
Posts: 3970
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: The Noob's Machine Code Thread

Post by Derek_Stewart »

Hi,

The problem of porting BASIC programs gets worse, I have been porting some Spectrum programmes which apart from the Spectrum PRINT statement being different on the QL, that is no formatting statements allowed in the QL PRINT command.

The main problem area is that Spectrum BASIC allows varaibles and arrays to have the same name.

In QL Superbasic is is an error and not allowed. Fortuneatley BASin lists all the variables and arrays in the export file.

This I find a major failing in Spectrum BASIC.

With regards to programming assembler on a Spectrum, I used to use the ZEUS Assembler, so the transition to QL assembler with QMAC wa fairly straight forward.

Also the Macro facilities in QMAC are brilliant, allowing some Z80 mneumonics to be replaced with a 68000 coded macro.


Regards,

Derek
User avatar
dex
Gold Card
Posts: 286
Joined: Thu Dec 23, 2010 1:40 pm

Re: The Noob's Machine Code Thread

Post by dex »

Thanks for the Basic-only version of QLluminati!


User avatar
TMD2003
Trump Card
Posts: 168
Joined: Sat Oct 10, 2020 12:18 pm

Re: The Noob's Machine Code Thread

Post by TMD2003 »

Derek_Stewart wrote:The problem of porting BASIC programs gets worse, I have been porting some Spectrum programmes which apart from the Spectrum PRINT statement being different on the QL, that is no formatting statements allowed in the QL PRINT command.
The main problem area is that Spectrum BASIC allows varaibles and arrays to have the same name.
In QL Superbasic is is an error and not allowed. Fortuneatley BASin lists all the variables and arrays in the export file.
This I find a major failing in Spectrum BASIC.
I always keep track of what variables I've used on a printed spreadsheet, to make it as immediately obvious as possible. For Spectrum programming, I'll reserve single-letter numeric variables for loop variables or arrays - never both - and any other numeric variable will have two letters. Hence, I'll never use PRINT AT r,c; or PLOT x,y - it'll always be PRINT AT ro,co; or PLOT xp,yp. The QL has the added advantage of allowing multiple-letter string variables and the % integer variables.

In retrospect I should probably have applied the same method to the VIC-20 conversion of Illuminati (for which I have a working BASIC-only version after wrestling with some of Commodore BASIC's... idiosyncrasies). At least, keeping track of the loop variables might have not seen me try to FORN=0TO9 inside another FORN=TO9 (all scrunched-up characters with no spaces have been included. I know memory is tight on a VIC-20, but seriously...)

On the subject of variables, late last year, I had a shot at programming three computers that were available in 1977. The hardest of the three was the TRS-80 Model I, which really needed thinking outside the box to work round its limitations. There are 26 single-letter numeric variables - which can at least handle floating point, unlike the original BASIC on the Apple II (that cost four times as much in its most rudimentary spec - see it's not just Millennial hipsters who have been paying over the odds for Apple products!). But you only get two string variables, A$ and B$, and they're limited to 16 characters each. And the one solitary array, A(N), has one dimension, and there is no DIM command - how many array elements you get depends on the size of the program, and there's only 4K to play with. Other than the floating point arithmetic and the slightly larger memory, that's ZX80 levels of minimalism. A ZX81 with a 16K RAM pack would blow the Trash-80 into the weeds - though I suppose that's four years of progress. After all, from the ZX80 to the QL was four years...
dex wrote:Thanks for the Basic-only version of QLluminati!
Consider it a bonus that none of the other released versions will receive... except that I've "hidden" it on the .MDV image as well as in "files2". Will anyone who downloads the CSSCGC-reviewed version notice? Will any of them know where to look? It's not as if I haven't been showing off what I've done on the QL on the two main Spectrum forums.

I wonder, though, should I post "My First 68008 Machine Code Listing" here so you can all see what it says? Maybe even alongside the Z80 equivalents?


Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Post Reply