home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USEROC90.MSA
/
TEXT_CLINIC.DOC
< prev
next >
Wrap
Text File
|
1990-08-19
|
15KB
|
322 lines
PROGRAMMERS' CLINIC
Questions and answers about Spectrum 512 pictures, bombing programs, and
changing dialog button text make Mathew Lodge's clinic this month. Setting the
double click speed from the AUTO folder also makes a comeback.
Back To The Double-Click III
============================
A few months ago when the Clinic was still in ST World, I had a query from Pete
Ellis - he wanted to set the GEM double click speed to five using a program in
the AUTO folder to improve mouse response. The general consensus was that you
couldn't do it, but several "workarounds" were presented. Nigel Garvey of
Wellesbourne, Warwickshire has done some research on the problem which is
presented here:
"The way to set or read the double-click speed is to use the AES routine
evnt_dclick, whose parameters are the same as those in the Control Panel. This
would seem to be the answer, but for two problems:
"Firstly, AUTO folder programs run before the AES is activated, so any TRAP
#2 calls just hit a dummy RTE instruction and do nothing. The other problem,
which I only discovered while working on this, is that entering the desktop
automatically sets a default double-click speed of three. Even the saved
Control Panel setting counts for nothing here, as accessories are started up
before the Desktop starts. If the double click speed is set within an
application the new setting will survive until the application quits.
Accessories don't terminate, so leaving them doesn't affect the setting.
"My compromise solution (Program 1), accepts defeat by the desktop, but
automatically sets the double click speed whenever an AES application is run.
It claws its way through a series of parasitic processes, using an idea filched
from HiSoft's replacement file selector, HFSEL.PRG.
"The AUTO part of the program re-routes TRAP #13 BIOS calls through an
intercept routine. This routine waits for a setexc call to be made in
supervisor mode, to reset the critical error handler vector to an address
within the operating system. This is assumed to be the boot process switching
in the GEM error handler, with the implication that the TRAP #2 vector is now
pointing to a working GEM entry point.
"On return from this setexc call, another intercept is hooked up to the
TRAP #2 vector. This one waits for the AES's appl_init function to be called
(normally the first move by any application seeking legitimacy) and smuggles in
an evnt_dclick call under the same exception."
-------------------- Program 1 : Set Double Click Speed ----------------------
* ASETDCLK.PRG
* By Nigel Garvey, 8th-26th April 1990
* AUTO folder program to set the mouse double-click time
* Effective only during clickable programs which use the AES
* Assembler: DevpacST v.2.08
* Double-click time equate. Set to taste (machine defaults to 3):
dclick_time EQU 4 Values: 0 (longest) to 4 (shortest)
start BRA auto_prg Branch to AUTO-folder bit
tr13_intcpt
* TRAP #13 calls diverted through here. Watch for critical error vector
reset:
BTST #5,(A7) Call made from supervisor mode?
BEQ.S jmp_bios Jump straight to BIOS if not
CMPI.L #$50101,6(A7) setexc call re vector #$101?
BNE.S jmp_bios Jump to BIOS if not
TST.L 10(A7) Address parameter or read only?
BMI.S jmp_bios Jump to BIOS if read only
MOVE.L D0,-(A7) (Store D0, just in case)
MOVE.L 10+4(A7),D0 Get address parameter
CMP.L $4F2.W,D0 Compare with OS base pointer
MOVEM.L (A7)+,D0 (Restore D0, preserving CCR flags)
BLO.S jmp_bios Jump if address not in OS
MOVE.L 2(A7),setxc_out+2 Move ret addr to ch_tr2v exit jump
MOVE.L #ch_tr2v,2(A7) Make ch_tr2v entry the new return addr
jmp_bios JMP 0000 (dummy) Jump to BIOS
ch_tr2v
* The doctored setexc call RTE's to here. Reset the TRAP #2 vector:
LEA tr2_intcpt(PC),A0 Get address of tr2_intcpt routine
CMPA.L $88.W,A0 TRAP #2 vector (still) pointing there?
BEQ.S setxc_out Leave alone if so
MOVE.L $88.W,jmp_gem+2 Else move GEM addr to exit jump
MOVE.L A0,$88.W Move routine's address to vector
setxc_out JMP 0000 (dummy) Return from setexc call
tr2_intcpt
* TRAP #2 calls diverted through here. Watch for appl_init:
CMPI.W #$C8,D0 AES call?
BNE.S jmp_gem Jump straight to GEM if not
MOVE.L A0,-(A7) (Store A0, just in case)
MOVEA.L D1,A0 Get call's parameter block address
MOVEA.L (A0),A0 Find the control array
CMPI.W #10,(A0) appl_init call?
MOVEA.L (A7)+,A0 (Restore A0, CCR not affected)
BNE.S jmp_gem Jump if not
MOVE.W (A7)+,rte_sr Else store stacked status register
MOVE.L (A7)+,rte_addr Ditto return address
PEA do_evdclk(PC) Substitute do_evdclk address...
MOVE.W SR,-(A7) ...and current SR
BRA.S jmp_gem Do appl_init
do_evdclk
* The doctored appl_init call RTE's to here. Slip in evnt_dclick:
MOVE.L #aes_pblk,D1 Address of own parameter block
MOVE.W #$C8,D0 AES call code
MOVE.L rte_addr(PC),-(A7) Use original return address
MOVE.W rte_sr(PC),-(A7) Ditto original SR
jmp_gem JMP 0000 (dummy) Jump to GEM
* Own AES parameter tables, preset for evnt_dclick:
aes_pblk DC.L control,global,int_in,int_out,addr_in,addr_out
control DC.W 26,2,1,0,0
global DS.W 14
int_in DC.W dclick_time,1
int_out DS.W 1
addr_in DS.L 1
addr_out DS.L 1
* Storage for appl_init call RTE info (can't store on super stack):
rte_addr DS.L 1
rte_sr DS.W 1
auto_prg
* The AUTO-folder program. Installs and starts the above intercepts
* Inform the user:
LEA message_a(PC),A0 Print first part of message -
BSR.S print
LEA message_b(PC),A0 Get base address of setting strings
MOVEQ.L #dclick_time,D0 Take the required time setting
ASL.L #4,D0 Multiply by 16 (length of strings)
ADDA.L D0,A0 Add as offset to base address
BSR.S print Print relevent setting
LEA message_c(PC),A0 Print end of message -
BSR.S print
* Reset the TRAP #13 vector:
PEA ch_tr13v(PC) Address of ch_tr13v subroutine
MOVE.W #$26,-(A7) Perform in supervisor mode (supexec):
TRAP #14
ADDQ.L #6,A7
* Protect the program memory and exit:
CLR.W -(A7) (No errors!)
MOVE.L #auto_prg-start+$100,-(A7) No. of bytes to retain
MOVE.W #$31,-(A7) p_termres
TRAP #1
ch_tr13v
* Subroutine to revector TRAP #13 calls through tr13_intcpt (above):
MOVE.L $B4.W,jmp_bios+2 BIOS address to routine's exit jump
MOVE.L #tr13_intcpt,$B4.W Routine's address to TRAP #13 vect
RTS
print
* Subroutine to print out a string to the screen:
MOVE.L A0,-(A7) String address passed in A0
MOVE.W #9,-(A7) c_conws
TRAP #1
ADDQ.L #6,A7
RTS
message_a DC.B 13,10,10,"ASETDCLK.PRG by Nigel Garvey
1990",13,10,10
DC.B "The mouse double-click time will be",13,10
DC.B "set at ",0
message_b DC.B "0 (longest)",0,0,0,0,0
DC.B "1 (longish)",0,0,0,0,0
DC.B "2 (medium)",0,0,0,0,0,0
DC.B "3 (shortish)",0,0,0,0
DC.B "4 (shortest)",0,0,0,0
message_c DC.B " during clickable",13,10
DC.B "applications which use the AES.",13,10,10,0
EVEN
END
------------------------------------------------------------------------------7
Bombing Out
===========
How many times have you had a program crash and the familiar line of bombs
appear on your screen. As most STers know, the number of bombs tells you what
caused the crash, but you have to look up the reason against the number of
bombs. The next query comes from Jonny Rodin in Harrow, Middlesex, who has been
writing a program to display an English message instead of the bombs.
"The program sometimes fails to intercept the exceptions for some unknown
reason. The program uses the bios 5 call (setexec) to change the exception
vector and terminates with Gemdos 31 (Ptermres or Keep Process). I wonder if
anyone could enlighten me as to the reason why my program fails to work
sometimes or possibly they could give me a solution - the only reason I can
think of is that sometimes the OS decides to reset the vectors. If this is
true, the only solution would probably be to have the program running under
interrupt continuously setting them."
Paint your ST
=============
A.J. Dolan has been trying to display Spectrum 512 and Quantum paint pictures
in their full 512 colour glory. These programs require carefully coded and
timed routines to switch colour palettes at just the right moment.
"Is there anybody who can explain how to achieve stable palette switching
on each scan line, or even parts of one. I have tried many ways, including the
program given by Jonathan Millar in ST World 27, May 88, but none of them give
a completely satisfactory result. It's obvious it can be done, but how?"
Dialogue Button Text Change
===========================
Les Kneeling, from Ilford, Essex has a reply to the query from Ian McCall about
changing the text in a dialog box in Laser C.
"The ob_spec field of the OBJECT definition (shown below), is indeed a
character pointer to the text to be held in the G_BUTTON. All that is necessary
to put your own text in the button is to redirect this pointer to your own
string. In the event of the new text being longer than the old, it is also
necessary to change the width of the object accordingly. The listing also shows
how to position the object by changing the ob_x and ob_y values.
"Just to show that the Megamax object definition is correct I have
included it in the listing (Program 2) instead of #including the usual
header."
----------------------- Program 2 : Change button text -----------------------
#include <stdio.h>
/* The supplied Megamax definition of an object */
typedef struct object {
int ob_next; /* -> object's next sibling */
int ob_head; /* -> head of object's children */
int ob_tail; /* -> tail of object's children */
unsigned int ob_type; /* type of object- BOX, CHAR,.. */
unsigned int ob_flags; /* flags */
unsigned int ob_state; /* state- SELECTED, OPEN, ... */
char *ob_spec; /* "out"- -> anything else */
int ob_x; /* upper left corner of object */
int ob_y; /* upper left corner of object */
int ob_width; /* width of obj */
int ob_height; /* height of obj */
} OBJECT;
#define TREE00 0 /* Standard information created in RCP */
#define BUTTON 1
unsigned char BUTTONDEF[] = {
0,0,0,44,0,44,0,44,0,44,0,44,0,36,0,44,0,44, /* A dialog box */
0,92,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0,96, /* containing a */
66,85,84,84,79,78,0,0,255,255,0,1,0,1,0,20,0,0, /* single button */
0,16,0,2,17,0,0,0,0,0,0,17,0,3,0,0,255,255, /* with the text */
255,255,0,26,0,39,0,0,0,0,0,36,0,2,0,1,0,13, /* 'BUTTON' in it */
0,1,0,0,0,44
};
OBJECT *dialog; /* The object pointer */
char newtext[40] = "A longer piece of text";
/* The new text for the button */
main()
{
appl_init(); /* Initialise ROMS */
mrsrc_load( BUTTONDEF ); /* 'Load' the resource definition */
rsrc_gaddr(0, TREE00, &dialog ); /* Get the address */
dialog[TREE00].ob_x = 20; /* Position the dialog box on the */
dialog[TREE00].ob_y = 20; /* screen */
objc_draw( dialog, TREE00, 1, 0, 0, 640, 400 ); /* Show the dialog */
dialog[TREE00].ob_y = 80; /* Reposition the dialog box so we */
dialog[BUTTON].ob_spec = newtext; /* can see the new text */
dialog[TREE00].ob_width = 224; /* Make the boxes wide enough to */
dialog[BUTTON].ob_width = 192; /* contain the longer text */
objc_draw( dialog, TREE00, 1, 0, 0, 640, 400 ); /* Show it again */
getchar(); /* Wait */
appl_exit();
}
------------------------------------------------------------------------------
Finally, Jim Taylor of Cleadon, Sunderland has some tips for retrieving
floating point numbers from dialog boxes.
"Like G.A. Cox I encountered the problem of retrieving floating point
numbers from the dialog box. This is quite easily done in BASIC by splitting
the string into a mantissa part and a fractional part, converting them to real
values then adding them together."
Winding down
============
Keep the letters coming - especially the solutions and comments on other
people's problems and ideas, but don't forget that the clinic depends on your
problems too! Remember to include your full name (or title, if preferred), and
give your phone number if possible.
If you have a listing longer than about 25 lines then please include it on
a disk - I haven't got time to type long listings in. Putting the text of your
letter on disk is doubly helpful - First Word or First Word Plus format if
possible, but straight ASCII is fine. While on the subject of file formats, I
can't decipher tokenised Fast Basic .BSC files - please send an ASCII version.
If you are sending a complete program, then I also like to see it running
before putting it into the column, so please include a double-clickable version
of your program if at all possible. If you want the disk and/or listing back,
also include a stamped addressed envelope. No SAE, no disk.
Mathew Lodge
"Programmer's Clinic"
"Maen Melin"
Holmes Chapel Road
Lach Dennis
Northwich
Cheshire
CW9 7SZ