Knoware.no

Anything QL Software or Programming Related.
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Knoware.no

Post by Tinyfpga »

I was not expecting to be actually asked to write a 4 line program, then I realised that I use one on regular basis. When I looked at it, I thought some might see the 4 lines as a cheat, so I wrote a genuine 4 line program in the sense that it only contains one instruction per line. The whole caboodle is best shown in a screen shot as follows:-
4 lines of code.JPG
Having checked if this post looks ok, I wondered why I had placed a clear_screen statement in line 3. I tried the program sans CLI #1 and found that bits of other widows can be left behind if it's not there.
This is the sort of thing that is probably not mentioned clearly in any manual.
Last edited by Tinyfpga on Thu Oct 21, 2021 11:05 pm, edited 2 times in total.


User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Knoware.no

Post by pjw »

Tinyfpga wrote:<>To his mix I would also add a smattering of wit, such as Norm's opening line "Assembly language is very,very simple"<>
Perhaps he wasnt joking! Assembler is easy! Its like each instruction is as simple as a stone; and anyone can put one stone on top of another. But going from there to building a cathedral, thats the hard part!


Per
dont be happy. worry
- ?
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Knoware.no

Post by tofro »

pjw wrote:
Tinyfpga wrote:<>To his mix I would also add a smattering of wit, such as Norm's opening line "Assembly language is very,very simple"<>
Perhaps he wasnt joking! Assembler is easy! Its like each instruction is as simple as a stone; and anyone can put one stone on top of another. But going from there to building a cathedral, thats the hard part!
Assembly instructions are like very, very small stones. ;)

And it's particularily hard to build cathedrals from gravel ;)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Knoware.no

Post by pjw »

tofro wrote:
pjw wrote:
Tinyfpga wrote:<>To his mix I would also add a smattering of wit, such as Norm's opening line "Assembly language is very,very simple"<>
Perhaps he wasnt joking! Assembler is easy! Its like each instruction is as simple as a stone; and anyone can put one stone on top of another. But going from there to building a cathedral, thats the hard part!
Assembly instructions are like very, very small stones. ;)

And it's particularily hard to build cathedrals from gravel ;)
I guess thats why most sane people mix it with cement and just pour it into predefined forms, or APIs ;)
Still, I like playing in the sandpit.


Per
dont be happy. worry
- ?
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Knoware.no

Post by Tinyfpga »

I was not really thinking very hard when I quoted Norm's clever opening line. He was presumably inspired to write this to encourage the reader.

The problem that a hands-on person like me has with engineering ( is software an engineering subject? - I think so) is that I learn by doing, more than by envisioning, so I immediately want to "get stuck in" such that I will be able to see ( in a window on my screen) what assembler instructions actually do. (a bit like the Ben Eater stuff mentioned below)

I superb example of the "get stuck in" approach to learning can be found in Ben Eater's Youtube series titled "how do CPU,s read machine code?" and "Hello world" from scratch on a 6502.

I am thus frustrated because I don't know how to install an assembler or how to use one. The first thing wanted to do when I started to write BASIC programs was to learn how to create a window in which I could see what BASIC instructions actually did.

I don't normally use the INPUT instruction for screen entry so it wasn't until I had to write the four line program that I discovered that I didn't know how to use it. I had to read the manual and then test it quite a few times before I could understand how it worked.

The first thing I wanted to do when reading Norm's excellent book on assembler was to do the same.

To encourage the hopeless but aspiring programmer such as myself, how about an addendum to the book that explains what an assembler is, how it assembles and how it it is "installed" in SMSQ/E, followed by a machine code program equivalent to my 4 line BASIC program.

To simply be able to write an assembly program in QD, press a button and watch a small window popup on my screen would be great. I could then read the manual to try and understand what had just happened with the actual results displayed in front of me. I might even be able to modify the code to change the size of the window and thus begin to build pjw's cathedral.
Last edited by Tinyfpga on Thu Oct 21, 2021 9:00 pm, edited 4 times in total.


User avatar
RalfR
Aurora
Posts: 870
Joined: Fri Jun 15, 2018 8:58 pm

Re: Knoware.no

Post by RalfR »

Tinyfpga wrote:The whole caboodle is best shown in a screen shot as follows
Wow, what kind of a perfect program in four lines :D :D


4E75 7000
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Knoware.no

Post by pjw »

Tinyfpga wrote:<>
To simply be able to write an assembly program in QD, press a button and watch a small window popup on my screen would be great. I could then read the manual to try and understand what had just happened with the actual results displayed in front of me. I might even be able to modify the code to change the size of the window and thus begin to build pjw's cathedral.
I may reply to more later, but as to your wish above, it is entirely possible. This is exactly what I do.
You need FileInfo2 (FI2) for this. I sincerely hope you are acquainted with this essential utility. Then you need an assembler, linker and Make utility. If you download the SMSQ/E sources, or at least the extras directory, you get a very competent assembler and linker, namely the Qmac suit. If you balk at the idea of downloading the complete sources, you could do worse than getting the keys and mac directories too, while youre at it. But honestly, youre best off to get the whole caboodle in one fell swoop on its own "win" disk rather than pussyfooting around it or youll regret it later ;)

Configure FI2 to use the Qmac assembler for asm files. Ive got 4 actions for asm files: Edit (QD), Assemble (nolink) [<<devn_name_ext>> -nolink -errors], Assemble (SROFF) [<<devn_name_ext>> -errors] and another variant.

QD should be configured only to use the QD/SBAS Thing for BASIC, I think it otherwise uses FI2 by default.

So thats it. To assemble a simple file (like the one below) from QD you then only need to save it and the press F10, and like Brexit, its oven ready to run!

Linking and Making is the next step. I wont say any more here and now. If you want a longer, more rambling version, there is a lot more of this on my website. Youll find a link off the toolkits page.

Now for the four-liner you asked for - in assembler:

Code: Select all

* Some Qmac directives

        section code
        filetype 0

* Definitions found in SMSQ/E sources

        include dev8_keys_qlv
        include dev8_keys_qdos_io
        include dev8_keys_qdos_ioa


* Start of code

        lea.l label,a1                  point  a1 to label below
        move.w opw.con,a2               opw.con is the routine to use
        jsr (a2)                        use it!

        moveq #iow.clra,d0              CLS uses a trap
        moveq #-1,d3                    timeout
        trap #3                         do it!

        lea.l message,a1                point a1 to message
        move.w ut.wtext,a2              this routine writes the message
        jsr (a2)                        go!

        moveq #iob.fbyt,d0              Fetch a byte routine (BGET)
        moveq #-1,d3                    wait forever
        trap #3

        moveq #ioa.clos,d0              Close channel
        trap #2

exit
        rts                             Return to BASIC

* Data

* Three routines, which must be called in user mode, set up console
* or screen windows using a parameter list, pointed to by A1.

* In the first case, the window is opened using a name which has been
* supplied, a block of parameters defining the border, and the paper,
* strip and ink colours. The window is set up and cleared for use.

* The parameter block is as follows:

label
        dc.b    255     $00 border colour (byte)
        dc.b      1     $01 border width (byte)
        dc.b      7     $02 paper/strip colour (byte)
        dc.b      2     $03 ink colour (byte)

* For the second and third routines a further four words will
* need to be added to the parameter block to define the window:

x equ 100               Define some values
y equ  50

* Since this will be CALLed from BASIC it is dependent on BASIC's OUTLine.
* So if BASIC isnt in its usual place and hasnt its usual size, ie
* 512x256a0x0, this may not look right!

        dc.w    x        $04 width (word)
        dc.w    y        $06 height (word)
        dc.w   (512-x)/2 $08 X-origin (word)
        dc.w   (256-y)/2 $0A Y-origin (word)

message
        dc.w endmsg-startmsg
startmsg
        dc.b 'Hello World!',10
endmsg
        dc.w    0        In case length is odd..

*
        end
Since its not a job or a toolkit, it has to be CALLed from BASIC:

Code: Select all

10 a = ALCHP(100)
20 LBYTES 'win1_tst_simple_bin',a
30 CALL a
40 RECHP a
Of course theres a lot more going on. SMSQ/E is doing all the hard work! These are just a series of calls to system routines. Off the top of my head I cant begin to think about how to draw a single glyf on to the screen - Luckily, its all done for us! In other words: The foundations for the cathedral are already in place! The rest is up to us.


Per
dont be happy. worry
- ?
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Knoware.no

Post by Tinyfpga »

pjw posted:-
I miss those hefty, fat manuals of yore, yet I wouldn't have them back! They take up too much room, are hard to search, and, of course, can't easily be updated. No, the online solution is better for this kind of thing.
I agree, online stuff is easy to disseminate and maintain but If I find something I like, I download it and use it offline. I am unable to properly digest information on screen especially large quantities. It is why I paid to have Norm's assembler manual published in spiral form.
See:- viewtopic.php?f=9&t=3294&hilit=assemble ... =40#p35207

The result, apart from having a great manual, seems to have been that someone read it and found a load of errors. The online version was then updated, leaving the printed version without the corrections. This rather confirms your post.

I have a large number books at home so the fat-manual storage problem is not really a problem for me and since I like and need fat-manuals and would like to "publish" more SMS manuals. I need to find a solution to the updating problem.

1. Computer automated self publishing in may ways solves the problem. The manuals are low cost and are printed on demand. Norms manual costs about £10 inc delivery in the UK. So one could just throw away the out of date manual and buy another. (I am happy to pay the one-off update fee)

2. As the manuals are spiral bound one could simply print replacement pages and get a high-street print bureau to re-bind them. As mad as it may seem this operation could easily cost more than buying a new manual.

3. One could print replacement pages and stick them over the originals or one could "tippex" the corrections manually.

I realise, after a brief read of your post, that I will not be able to understand what you are saying without having it in printed form. Once I have done this I will make the effort to modify my setup and place everything on it's own "Win" disc as you suggest.
I don't like flipping around websites and often collate sites into a printable format. For example I would like to "read" your site in such a form.


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Knoware.no

Post by NormanDunbar »

Afternoon All,

I originally wrote that "Assembly language is very, very simple" because it is. Each instruction is a single small step on the way to a journey of 1,000 miles -- or to the end of a working, useful program. ;)

It is, as someone pointed out, a problem to put the steps together in the right way to make said program. Is it? Really? If you code in SuperBASIC, you still need to work out the steps required to get from "here" to where you want to be. Assembly is no different, except the steps are smaller, baby steps. Clearing the screen, for example, easy in SuperBASIC, a quick CLS and it's done, the default channel is cleared. In Assembly, there's no default channel, plus you have to get the channel ID, and CLS that -- none of that #1 nonsense here! Assembly programmers do it in the dirt!

Building a cathedral with gravel, yes, might be problematic, but not impossible. I suppose it depends on the size of the cathedral and the structural integrity of the concrete you make the gravel into I suppose. If Tony Tebby can write an OS in assembly, if Jan Jones, a "mere" woman, can write a SuperBASIC interpreter in assembly, then how hard can it be for mortal chaps like us to do something simpler? And don't get me started on Marcel or Wolfgang! ;)

("Mere" is in quotes for the obvious reason!)

The thing I like about assembly language is that it teaches you, in my case eventually, to think about the way you will write the code. You don't just dive in and start coding -- that way, dragons lie. And dragons are not a good thing to have around. (Guards! Gaurds! excepted. (Terry Pratchett))


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Derek_Stewart
Font of All Knowledge
Posts: 3929
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Knoware.no

Post by Derek_Stewart »

Hi,

I use QDasm Thing distrbutrd with QD, to compile songle file assrmbler programmes.

As suggested QD/SBAS can run a basic programme to assemble the same file.

Or use QMAKE an QD to compile and edit the assembler files.

Looking athis from a beginners point of view, it is hard to envision all the include files that are assembled in a modular fashion.


Regards,

Derek
Post Reply