This is the second time I have started this article. The first version is in limbo lost in a mess of disks somewhere & it will be quicker to rewrite than to search through 20 disks & half a dozen corrupted remnants. I find Quill is great at trashing disks. It’s usual trick is to write a file into the directory.
Anyway, minor bitching aside, there are three things I want to get to in this play, two of which will fit. These are the difference between jobs, procedures, & basic, as well as the screen format, but first a word about modems.
I have verified that a 1200 baud modem can be hooked up to the QL without a Modaptor using the following connections.
QL[SER2ir] Modem [DB-9] [DB-25] Pin 1 - GND ------> 7 - Signal Ground 2 - TxD ------> 2 - TD 3 - RxD -------> 3 - RD 4 - No Connection 5 - No Connection 9 - +12v ------> 20 - DTR 9 - +12v ------> 4 - ???
I have used the above connections with an Avatex 1200 modem. Incidentally, the pins 6,7,8 on the North American QL DB-9 are tied to ground. [That info is verified by Wilf Rigter.] This is not mentioned in the QL User Guide presumably because in the UK a British Telecom type of connector with 6 pins is used.
Jobs. This can be confusing, particularly if you are not disposed to the hacking mentality in the least. However, I know some people have got it bass ackward, so I will attempt to unravel…and throw in a curve or two, as clarity demands.
Superbasic is a job. Superbasic is a special kind of a job, the root job and as such it always exists. It might be suspended, ie. not running or taking any processor time, but it is always there.
A superbasic program which you type in is not a job. The program itself is data which the superbasic job interprets.
However, if you take your superbasic program and compile it with Supercharge, Q_Liberator or Turbo the output of that process is a job.
The Psion quartet are all jobs. In general jobs are started with EXEC, EXEC_W, EX or EW. Each job has a distinct ID number allocated to it by QDOS. This number consists of a tag which is the nth job which QDOS has created and an offset in the Job table which QDOS maintains. You can switch between QL jobs by typing <CTRL><C>. You can change this character by poking the System Variable SV.CQCH, which stands for Change Keyboard Queue Character. This is a Word value at $28092 or Decimal 163986.
A procedure in Superbasic is the code you put between:
DEFine PROCedure Such_and_Such
:
END DEFine Such_and_Such
You can also define a Machine Language Procedure with the following format:
Word : Number of Procedures Word : Pointer to Routine Byte : Length of Name Bytes: Characters of the name Word : 0 [ a Seperator ] Word : Number of Functions Word : Pointer to Routine Byte : Length of Name Bytes: Characters of the Name Word : 0 [ End of list ]
There is an example of this format in actual code below. Note that Machine Language Functions can also be defined. This is what makes Superbasic extensible, a unique & wonderful feature.
Here is the first tricky bit. We have seen that machine language can be a Procedure, a Job, but did you know it could also be something else…a Task? A task as defined by QDOS is an piece of asynchronous code executed to take care of some operating system business. An example is checking the status of a Floppy Disk Controller chip & taking appropriate action. The code can be started on interrupt or on the scheduler loop. It would seem then that conceptually all of the operating system stands apart from the Jobs/Procedure structure.
Another tricky bit here is the fact that these terms are used differently by most operating system writers. Unix talks of Processes, the Amiga talks of Tasks, the QL talks of Jobs and they all have different curves to them.
Machine language procedures can do anything. In particular, if I can raise the topic without being confusing, they can start jobs. This sort of situation lets you do something like just type ‘EDITOR’ and start an editor job. Here is an example of such code:
*
**********************************************************************
* This code Initializes the PROCEDURE "EDITOR"
*
INIT_PROC LEA PROCLIST,A1 * POINTER TO PROC DEF LIST
MOVE.W BP_INIT,A2
JSR (A2)
MOVEQ #0,D0 * NO ERRORS
INIT_EXIT RTS
*
PROCLIST DC.W 1 * NUMBER OF PROC
DC.W EDIT_PROC-* * POINTER TO PROC
DC.B 6 * LEN.B
DC.B 'EDITOR'
DC.W 0 * END OF PROC
DC.W 0 * NUMBER OF FUNCTIONS
DC.W 0 * END OF LIST
*
**********************************************************************
* This is the PROCEDURE "EDITOR"
*
EDIT_PROC MOVEQ #0,D1 * BASIC IS JOB OWNER
MOVE.L #2048,D2 * CODE LEN.L
MOVE.L #0,D3 * DATA LEN.L
SUBA.L A1,A1 * START ADDRESS OR 0
MOVEQ #MT_CJOB,D0 * QDOS CREATE JOB
TRAP #1
TST.L D0 * RETURNS A0=BASE,D1=JOB ID
BNE.S ABORT_PROC * IF ANY ERROR: ABORT
MOVE.W #$4EF9,(A0)+ * JMP.L 2
LEA EDITOR,A1
MOVE.L A1,(A0)+ * TO EDITOR 4
MOVE.W #$4AFB,(A0)+ * QDOS JOB FLAG 2
MOVE.W #$000C,(A0)+ * LEN.W 2
MOVE.L #'EDIT',(A0)+ 4
MOVE.L #'OR 0',(A0)+ * INSERT NAME 4
MOVE.L #'.99 ',(A0)+ 4
* ----
* 22
MOVE.L D1,(A0)+ * INSERT JOB ID 4
* ----
* 26 BYTES
MOVE.W #DATA_LEN-1,D0 * DEFINED ELSEWHERE
DATAINIT MOVE.B #0,(A0)+
DBRA D0,DATAINIT
*
MOVEQ #8,D2 * SET PRIORITY
MOVEQ #0,D3 * TIMEOUT 0=EXEC : -1=EXEC_W
MOVEQ #MT_ACTIV,D0 * QDOS : MANAGER TRAP
TRAP #1 * ACTIVATE JOB
BRA.S EXIT_PROC
*
ABORT_PROC: MOVE.W UT_ERR0,A2 * REPORT D0 ERROR CODE TO CHANNEL 0 CONSOLE
JSR (A2)
EXIT_PROC: MOVEQ #0,D0
RTS
*
**********************************************************************
* The Start of the Editor JOB code
EDITOR ...
*
**********************************************************************
* How it works.
This code would be loaded into memory with LBYTES filename,respr(16384)
Then called from superbasic [ with CALL RESPR(0)]. That will cause the
Procedure Initialize code to be executed, which will add the Machine Language
Procedure EDITOR to the Superbasic Name List.
Then when you type "EDITOR", the procedure creates the job with MT_CJOB.
Note that the job doesn't yet start to execute. All QDOS does is reserve the
memory for you and set up its various tables. The Trap returns the base of
the allocated memory. In this memory you put the code
JMP.L Editor and the QDOS Job flag and standard name format.
At this point, about all you have to do is start the job with MT_ACTIV.
Now for the screen format. The QL display has 2 modes, a 4 colour mode and an 8 colour mode. These are controlled from basic by the keyword MODE n, where n is 4 or 8.
The video ram in the QL normally consists of 32K bytes starting at $20000 or decimal 131072. The QL can have 2 screens of video ram, but the implementation of the dual screens is incomplete. The problem is that QDOS is locked into having the System variables start at $28000 & there is just no two ways around that, because it is hard coded in the ROM.
The QL screens are what you might call interleaved bit planes. In mode 4, the information is setup as follows:
Word 0 1 2 3
Byte 0 1 2 3 4 5 6 7
Bits 7654321076543210765432107654321076543210765432107654321076543210
GGGGGGGGRRRRRRRRGGGGGGGGRRRRRRRRGGGGGGGGRRRRRRRRGGGGGGGGRRRRRRRR
The G stands for Green, the R stands for Red. You can play with the screen directly by poking a value into the video ram. A command such as POKE 131072,255 will set every green bit in the first word of video ram and draw a short green line in the upper left hand corner of the screen.
POKE 131073,255 will similarly set all the red bits.
POKE 131072,255 : POKE 131073,255 will set all the green and red bits and give you a white line. The fourth colour black is the absence of light with all bits clear ie. zero.
The very first pixel of the first line is controlled by bit 7 of byte 0 [for Green] and bit 7 of byte 1 [for Red]. The second pixel is similarly controlled by bit 6 of the two bytes and so on.
A screen resolution of 512 pixels thus requires 512/8 = 64 words [128 bytes].
In mode 8, the information is setup as follows:
Word 0 1 2 3
Byte 0 1 2 3 4 5 6 7
Bits 7654321076543210765432107654321076543210765432107654321076543210
GFGFGFGFRBRBRBRBGFGFGFGFRBRBRBRBGFGFGFGFRBRBRBRBGFGFGFGFRBRBRBRB
F stands for Flash and B stands for Blue. Clearly with 3 bits controlling the colour there are 2^3 or 8 colours as you know. One wonders if the Sinclair engineers considered using 16 colours rather than implementing a FLASH.
A screen resolution of 256 pixels thus requires 256/4 = 64 words.
As usual, let me say that if you are a QL enthusiast feel free to write c/o the Editor.
This assembly language is a subroutine I developed to write directly to the screen in MODE 8.
>eof
**********************************************************************
*
* PLOT POINT DIRECTLY
* SCREEN 128 BYTES WIDE ! 2 BITS BYTE0 & 2 BITS BYTE1 !
* 4 PIXELS / WORD ==> 256 PIXELS
* 256 ROWS DEEP !
*
* EXPECTS D7 = COUNT
* D0 = ROW (0-255)
* D1 = COL (0-255)
* RETURNS D0 = ERROR CODE
*
* WANT TO PUT 0-7 IN BITS RGB, WITH F CLEAR ALWAYS
*
* BIT7 BIT6 BIT5 BIT4 BIT3 BIT2 BIT1 BIT0
* EVEN BYTE G F G F G F G F
* ODD BYTE R B R B R B R B
* OR
* CARRY BIT X/C 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
* G F G F G F G F R B R B R B R B
* - - - -
*
PLOT_PNT MOVEM.L D1-D3/D7/A0,-(A7) * SAVE SOME REGISTERS
*
RANGECHK TST.W D0
BLO OR_ERROR
CMPI.W #256,D0 * TEST IF ROW 0-255?
BHS OR_ERROR
TST.W D1
BLO OR_ERROR
CMPI.W #256,D1 * TEST IF COL 0-255?
BHS OR_ERROR
*
MOVE.L #$00027F80,A0 * BOTTOM LEFT HAND CORNER OF SCREEN
*
MULU #128,D0 * CALCULATE ROW DISTANCE IN BYTES
SUBA.L D0,A0 * CALC LEFT HAND CORNER OF ROW
*
MOVEQ #0,D2 * CLEAR TOP
MOVE.W D1,D2 * COPY COLUMN
LSR.W #1,D2 * /2 CALC BYTE # : 255-127 & 3 BELOW
BCLR #0,D2 * MAKE SURE WORD BOUNDARY
ADDA.L D2,A0 * A0=> APPROPRIATE WORD
ANDI.W #$03,D1 * MASK OFF 0-3
* 4 CASES D1=0,1,2,3
MOVEQ #0,D3 * TARGET MASK
ANDI.W #$07,D7 * MASK OFF COUNT 0-7
*
TST.W D1
BNE.S TEST1
EQUALS0 MOVE.W #$3F3F,D2 * CLR MASK
LSR.B #1,D7 * BIT0 TO X/C
ROXR.W #1,D3 * X/C TO BIT15
LSR.B #1,D7 * BIT1 TO X/C
ROXR.B #1,D3 * X/C TO BIT7
LSR.B #1,D7 * BIT2 TO X/C
ROXR.B #1,D3 * X/C TO BIT 7, BIT7 TO BIT6
BRA.S PUT_DATA
TEST1 CMPI.W #$01,D1
BNE.S TEST2
MOVE.W #$CFCF,D2 * CLR MASK
LSR.B #1,D7 * BIT0 TO X/C
ROXR.W #3,D3 * X/C TO BIT13
LSR.B #1,D7 * BIT1 TO X/C
ROXR.B #1,D3 * X/C TO BIT7
LSR.B #1,D7 * BIT2 TO X/C
ROXR.B #3,D3 * X/C TO BIT5, BIT7 TO BIT4
BRA.S PUT_DATA
TEST2 CMPI.W #$02,D1
BNE.S TEST3
MOVE.W #$F3F3,D2 * CLR MASK
LSR.B #1,D7 * BIT0 TO X/C
ROXR.W #5,D3 * X/C TO BIT11
LSR.B #1,D7 * BIT1 TO X/C
ROXR.B #1,D3 * X/C TO BIT7
LSR.B #1,D7 * BIT2 TO X/C
ROXR.B #5,D3 * BIT7 TO BIT2,X/C TO BIT3
BRA.S PUT_DATA
TEST3 CMPI.W #$03,D1
BNE NC_ERROR
MOVE.W #$FCFC,D2 * CLR MASK
LSR.B #1,D7 * BIT0 TO X/C
ROXR.W #7,D3 * X/C TO BIT9
LSR.B #1,D7 * BIT1 TO X/C
ROXR.B #1,D3 * X/C TO BIT7
LSR.B #1,D7 * BIT2 TO X/C
ROXR.B #7,D3 * BIT7 TO BIT0,X/C TO BIT1
PUT_DATA AND.W D2,(A0) * G/F/R/B TO 0'S
OR.W D3,(A0) * INSERT DATA
OK_EXIT MOVEQ #0,D0
PP_EXIT MOVEM.L (A7)+,D1-D3/D7/A0 * RESTORE REGISTERS
RTS * RETURN WITH ERROR CODE
NC_ERROR MOVEQ #-1,D0 * NC_ERR = -1
BRA.S PP_EXIT
OR_ERROR MOVEQ #-4,D0 * OR_ERR = -4
BRA.S PP_EXIT
*
*
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.