home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USERJL90.MSA / TEXT_CLINIC.DOC < prev    next >
Text File  |  1990-05-15  |  15KB  |  358 lines

  1.                            Programmer's Clinic
  2.  
  3. MATHEW Lodge chairs this month's programmer's problem solving forum covering
  4. such diverse topics as queries about paddles, a fix enabling 0.5Mb and 1Mb
  5. SIMMs to be mixed in STEs. Other items include IMG file routines, a STOS tip,
  6. MIDI queries and a MINIX question.
  7.  
  8. Mixing SIMMs in the STE
  9. ------------------------
  10. One clear fact arose from the recent confusion over STE memory upgrades: You
  11. cannot mix 512K SIMMs with 1MB SIMMs. However, even this is not a fact any
  12. more, since David Hoggan of Southsea, Devon has provided a software patch that
  13. enables STE owners to mix the two types to give a 2.5Mb STE.
  14.     The reason that mixing the two types of SIMM normally doesn't work is that
  15. there is a bug in TOS 1.6 such that the Memory Management Unit (MMU) is
  16. incorrectly programmed during boot-up.
  17.     Memory in STEs (and STs too) is split into two banks. When the STE is
  18. booted, it starts by assuming there is 2Mb in each bank, and by writing a
  19. series of test patterns to various parts of memory it works out exactly how
  20. much memory is fitted.
  21.     Unfortunately, TOS 1.6 in the STE adds up the memory and gets the wrong
  22. answer - when 2.5Mb is fitted, it believes that 4Mb is present. This causes
  23. problems as programs (particularly GEM) attempt to write to memory that doesn't
  24. exist.
  25.     The following program should be assembled and placed in an AUTO folder.
  26. Make sure that it is run before any other AUTO folder programs by copying it
  27. into the folder before anything else is put there. Comments in the source
  28. indicate the order in which the SIMM cards should be fitted.
  29. ------------------------------------------------------------------------------
  30.                              A:\LISTINGS\SIMM.S
  31. ------------------------------------------------------------------------------
  32. * STE SIMM mixer by David Hoggan
  33. * Lets STE configure 2.5 Megs properly
  34. * MUST BE FIRST IN AUTO FOLDER!
  35.  
  36. * This program asssumes 2Mb in bank 0 and 0.5Mb in bank 1.
  37. * It has been found that the other way around doesn't work
  38. * - the MMU configures to a 1Mb machine.
  39.  
  40. * Install your SIMMs as follows:
  41. *
  42. * (back of STE)
  43. *
  44. * |--  1meg SIMM  --|
  45. * |-- .5meg SIMM  --|
  46. * |--  1meg SIMM  --|
  47. * |-- .5meg SIMM  --|
  48. *
  49. * (front of STE)
  50.  
  51.     clr.l   -(sp)
  52.     move.w  #32,-(sp)       Switch to super mode
  53.     trap    #1
  54.     addq.l  #6,sp
  55.  
  56.     cmp.l   #$280000,$42E   RAM <= 2.5 megs?
  57.     ble     already         If so, nothing to do
  58.     cmp.b   #9,$424         Is it installed properly?
  59.     bne     already         If so, nothing to do
  60.  
  61.     move.l  #$280000,$42E   Set phystop
  62.     move.l  $4F2,a0         Find reset address
  63.     jmp     (a0)            Reset system
  64.  
  65. already: move.l d0,-(sp)        Returned stack
  66.     move.w  #32,-(sp)       Switch back to user mode
  67.     trap    #1
  68.     addq.l  #6,sp
  69.     clr.w   -(sp)           Back to TOS
  70.     trap    #1
  71. ------------------------------------------------------------------------------
  72.     David notes that: "While not the most elegant solution, I have had no
  73. problems with compatibility while running any software or hardware combination.
  74. Memory block zero must contain 1Mbit SIMM cards, otherwise the MMU will be
  75. configured for a 1MB machine".
  76.  
  77.  
  78. STOS tip
  79. ---------
  80. Kevin Ware-Lane of High Wycombe, Buckinghamshire, has found an undocumented
  81. feature in STOS BASIC:
  82.     "Create any file, and save it in the root directory of your working copy of
  83. the STOS Basic disk. It must be saved under the file name AUTOEXEC.BAS. Now,
  84. whenever you boot your working copy of STOS, that BASIC program will be loaded
  85. and run."
  86.  
  87.  
  88. GFA takes parameters
  89. ---------------------
  90. Many programmers know how to read the command line passed to a .TTP program, or
  91. the document name of an installed GEM application is when it double clicked on.
  92. However, few people know how to do it in GFA BASIC - this month, Leighton
  93. Cathcart from Bangor, Co. Down in Northern Ireland comes to the rescue.
  94.     "Accessing the command line is very easy as GFA BASIC contains a built-in
  95. variable called BASEPAGE, which holds the address of the basepage of your
  96. program. The command line string is stored 128 bytes further on from this
  97. address.
  98.     The length of the command line string is stored at BASEPAGE+128 and the
  99. string starts at BASEPAGE+129, terminated by a zero. The folowing program is an
  100. example in which the command line is placed in the string ARG$. You should
  101. compile it and give it a .TTP extension".
  102. ------------------------------------------------------------------------------
  103.                              A:\LISTINGS\GFA_TTP.BAS
  104. ------------------------------------------------------------------------------
  105. Rem Read command line in GFA
  106. Rem By Leighton Cathcart
  107.  
  108. Length%=Peek(Basepage+128)
  109. If Length%=0
  110.   Print"No command line"
  111.   End
  112. Else
  113.   For Count%=129 To (129+Length%)
  114.     Char%=Peek(Basepage+Count%)
  115.     Arg$=Arg$+Chr$(Char%)
  116.   Next Count%
  117. Endif
  118. Print"Command line:";Arg$
  119. Repeat
  120. Until Inkey$=Chr$(13)
  121. ------------------------------------------------------------------------------
  122.     "This will work not only for .TTP programs, but also for GEM .PRG programs
  123. as well. When you select Install Application from the desktop, the name of the
  124. file you opened to run your application is also placed at this location in
  125. memory."
  126.  
  127.  
  128. What a GFA dump!
  129. ----------------
  130.     Another GFA user is Giulio Marchesi from Bergamo in Italy. Giulio has
  131. provided a program in GFA BASIC V2 to produce better proportioned screen dumps
  132. for Degas Elite .PI3 pictures. The program was written for an Epson FX-800
  133. 9-pin printer, but it should work on all compatibles.
  134. ------------------------------------------------------------------------------
  135.                              A:\LISTINGS\GFA_DUMP.BAS
  136. ------------------------------------------------------------------------------
  137. Rem Degas PI3 screen dump
  138. Rem By Giulio Marchesi
  139.  
  140. ' print Degas .PI3
  141. INPUT "Filename: ";file$
  142. BLOAD file$,XBIOS(2)-34
  143. GOSUB print_degas
  144. '
  145. PROCEDURE print_degas
  146.   a$=SPACE$(800)        ! buffer for line data
  147.   g$=CHR$(27)+"*"+CHR$(1)+CHR$(800)+CHR$(800/256)
  148.   ' FX 800 graphics mode, double density)
  149.   OPEN "",#99,"LST:"    ! open printer channel
  150.   FOR s%=XBIOS(3) TO s%+79 ! reads screen data
  151.     x%=VARPTR(a$)
  152.     FOR q%=s%+399*80 TO s% STEP -80
  153.       FOR i%=0 TO 1    ! double data for double density
  154.         POKE x%,PEEK(q%)
  155.         INC x%
  156.       NEXT i%
  157.     NEXT q%
  158.     PRINT #99,g$;a$;CHR$(13);       ! one line and CR
  159.     PRINT #99,CHR$(27);"J";CHR$(1); ! 1/216 line feed
  160.     PRINT #99,g$;a$;CHR$(13);       ! print line again
  161.     PRINT #99,CHR$(27);"J";CHR$(23);        ! 23/216 feed
  162.   NEXT s%
  163.   CLOSE #99
  164. RETURN
  165. ------------------------------------------------------------------------------
  166.  
  167.  
  168. Turn over a new leaf
  169. ---------------------
  170. On now to computer literature, and Mark T. White of Toronto, Canada has a plea
  171. for anyone recommending books for further reading: "May I make a plea to all
  172. contributors: If you quote a book, please include its ISBN number, in addition
  173. to the full name, author(s) and publisher.
  174.     "I found Katherine Peel's 'Concise Atari ST 68000 Programmer's Guide'
  175. (Glentop), ISBN 1 85181 172 9, through an advert in ST World. I have been
  176. unable to find Balmer and Fitler's 'Programmer's Guide To GEM' (Sybex) without
  177. knowing the ISBN. Does anyone know it, or where I can get the book?".
  178.  
  179.  
  180. STE is a joy to use
  181. --------------------
  182. Tony Goodhew writes from Birstall, Leicester on the subject of the new
  183. controller ports found on the STE:
  184.     "The STE addendum sheet supplied with the new machine gives pinout
  185. specifications, but no details about how to read the port. I am particularly
  186. interested in pins 5 and 15 - the paddle inputs, as these must be connected to
  187. a four channel analogue to digital converter chip. I would be most grateful for
  188. some help in using these inputs from either HiSoft Power BASIC, or GFA BASIC
  189. V2.
  190.     "A similar input on a BBC Micro has been put to good use in the past for
  191. simple data logging applications, and I forsee many educational uses if this
  192. port can be used in the same manner".
  193.     Atari's  STE Developer Information Addendum provides the necessary
  194. technical data. Four new joystick ports were added for the STE, directly
  195. interfaced to the 68000 bus, rather than using another IKBD controller. The
  196. following table gives the locations of the hardware registers for the
  197. joysticks, paddles and light gun/pen inputs:
  198.  
  199. STE CONTROLLER PORTS
  200.  
  201. Address Usage                Description
  202. =================================================
  203. FF9200  xxxx xxxx xxxx 3210  Fire buttons
  204. FF9202  UDLR UDLR UDLR UDLR  Joystick directions
  205.         Joy3 Joy2 Joy1 Joy0
  206.  
  207. FF9210  xxxx xxxx NNNN NNNN  Paddle 0 X
  208. FF9212  xxxx xxxx NNNN NNNN  Paddle 0 Y
  209. FF9214  xxxx xxxx NNNN NNNN  Paddle 1 X
  210. FF9216  xxxx xxxx NNNN NNNN  Paddle 1 Y
  211.  
  212. FF9220  xxxx xxNN NNNN NNNN  Light pen/gun X
  213. FF9222  xxxx xxNN NNNN NNNN  Light pen/gun Y
  214.  
  215.     Note that the joystick registers are bi-directional and can therefore be
  216. written to as well as read. If the registers are  written, then the outputs are
  217. driven until the registers are read again.
  218.     Two paddle controllers can be connected with eight bit resolution on each
  219. axis, and the current position of each of the four paddles are reported in the
  220. registers shown in the table. No information is given in the data sheets as to
  221. the voltage range that the A/D converters function in, but I would guess that
  222. it is 0-5V. The triggers on the paddles are bits zero and one of $FF9202
  223. (joystick zero left and right.)
  224.     The light gun/pen position is reported in $FF9220 and $FF9222. The x-axis
  225. accuracy is four pixels in low resolution, eight pixels in medium and 16 pixels
  226. in monochrome. The y-axis position is accurate to within one pixel in all
  227. modes.
  228.     The x position only ranges from 0 to 319, and therefore must be left
  229. shifted for other screen modes. Again, no electrical information is provided on
  230. how to implement a light gun/pen.
  231.  
  232.  
  233. The key to the problem
  234. -----------------------
  235. Lloyd Patton provides help for Paul Margetson, who wants to write his own
  236. keyboard interrupt handler in order to test for the depression of more than one
  237. key at once. The problem is that if a replacement interrupt handler is written,
  238. then the operating system does not receive the key press information, and
  239. typing commands into a debugger becomes impossible.
  240.     "Simply placing the keystroke data into the keyboard buffer will be
  241. sufficient. Each keystroke is stored in a circular-list buffer as a 32 bit
  242. integer, in the format returned by the Bconin routine. The low word contains
  243. the character, the high word has the scan code in the lowest 8 bits and the
  244. kbshift variable in the highest 8 bits. Also remember to update the Iorec
  245. structure and take care of rotation around the buffer".
  246.     Here is Lloyd's solution:
  247. ------------------------------------------------------------------------------
  248.                              A:\LISTINGS\INSERT.C
  249. ------------------------------------------------------------------------------
  250. /* Insert keypresses by Lloyd Patton */
  251.  
  252. #include <local.h>
  253. #include <osbind.h>
  254.  
  255. main()
  256.   {
  257.  
  258.   long UpperA = 0x001e0041; /* 'A' */
  259.   long Number0 = 0x000b0030; /* '0' */
  260.   long ch;
  261.  
  262.   appl_init();
  263.   insert_char(UpperA);
  264.   ch = evnt_keybd();  /* test GEM call */
  265.   printf("\nkeystroke should be 0x1e41 and is 0x%lx\n",
  266. ch);
  267.   insert_char(Number0);
  268.   ch = Bconin(2);   /* test BIOS call */
  269.   printf("\nkeystroke should be 0x000b0030 and is
  270. 0x%08lx\n", ch);
  271.   evnt_keybd();
  272.   appl_exit();
  273.   }
  274.  
  275. insert_char(keycode)
  276.   long keycode;
  277.   {
  278.  
  279.   iorec *keybuf;
  280.   long stack;
  281.  
  282.   keybuf = Iorec(1);  /* get Iorec address */
  283.   stack = Super(0L);  /* supervisor mode to access Iorec
  284.  */
  285.  
  286.     /* loop around buffer */
  287.   if ((keybuf->ibuftl += 4) >= keybuf->ibufsiz)
  288.     keybuf->ibuftl = 0;
  289.  
  290.     /* if room in buffer store keystroke */
  291.   if (keybuf->ibuftl != keybuf->ibufhd)
  292.     *(long *)&keybuf->ibuf[keybuf->ibuftl] = keycode;
  293.  
  294.   Super(stack);   /* back to user mode */
  295.   }
  296. ------------------------------------------------------------------------------
  297.  
  298.  
  299. Speedy AUTO solution
  300. ---------------------
  301. Lloyd's also supplies a solution to Pete Ellis' problem of setting the
  302. double-click speed from the AUTO folder:
  303.     "The only call to set this is evnt_dclick() which can be used only after
  304. GEM initialisation and thus after the AUTO folder programs have run. If the
  305. Control Panel is a problem using up a valuable accessory slot then write a
  306. program that is run from the desktop then use the following listing, but if the
  307. problem is memory usage then use a smaller DA like ROCP:"
  308.  
  309. main()
  310. { /* the control panel's dialogue setting is unaffected.
  311.      However, the dclick value does come into effect.    */
  312.   appl_init();
  313.   evnt_dclick(4, 1);
  314.   appl_exit();
  315. }
  316.  
  317.  
  318. MIDI clock
  319. -----------
  320. Finally this month, a query from Rolf Nilsson of Genarp, Sweden, who has been
  321. dabbling with MIDI in assembler and C. "Since I am a musician, my main interest
  322. in programming is about MIDI. I have managed to program some simple MIDI
  323. programs, like getting MIDI bytes in to the ST, then manipulating and sending
  324. them back out again. I've also written a simple sequencer, but I need help.
  325.     "Can anyone suggest how to implement the clock that is the heart of any
  326. sequencer? This is vital if MIDI replay is to be accurate. Is it done through
  327. interrupts?
  328.     "There are some good books on MIDI programming for IBMs and compatibles,
  329. but they don't deal with this problem because the MIDI interface (Roland
  330. MPU-401 or equivalent) takes care of the clock."
  331.  
  332.  
  333. Winding down
  334. -------------
  335. Clinic is more yours than it is mine, so if you know the answer to a problem
  336. then write in. Keep the letters coming - especially the solutions and comments
  337. on other people's problems and ideas, but don't forget that the clinic depends
  338. on your problems too! Remember to include your full name and give your phone
  339. number if possible.
  340.     If you have a listing longer than about 25 lines then please include it on
  341. a disk. Putting the text of your letter on disk is helpful, too, 1st Word
  342. format if possible, but straight ASCII is fine.
  343.     If you are sending a complete program then I also like to see it running
  344. before putting it into the column, so please include a double-clickable version
  345. of your program if at all possible. If you want the disk returning include a
  346. stamped addressed envelope.
  347.  
  348. Mathew Lodge
  349. "Programmer's Clinic"
  350. "Maen Melin"
  351. Holmes Chapel Road
  352. Lach Dennis
  353. Northwich
  354. Cheshire
  355. CW9 7SZ
  356.  
  357. JANET : SOCS18 @ uk.ac.york.vaxa
  358.