home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 298.lha / CLI-Colors / CLI-Colors.asm < prev    next >
Assembly Source File  |  1980-12-01  |  11KB  |  283 lines

  1.         TTL        CLI-Colors
  2. *
  3. *******************************************************************************
  4. *                                          *
  5. *    CLI-Colors                                  *
  6. *                                          *
  7. *    Copyright (c) 1987-89 by Michael Sinz    MKSoft Development          *
  8. *                                          *
  9. *    AmigaDOS EXEC release 1.2 or greater...                      *
  10. *                                          *
  11. *******************************************************************************
  12. *                                          *
  13. *    To assemble, I used the Amiga Macro Assembler                  *
  14. *                                          *
  15. *    It should assemble without any problems on most Amiga assemblers      *
  16. *                                          *
  17. *******************************************************************************
  18. *                                          *
  19. *    The code is position independant and fully re-entrant.  Thus you      *
  20. *    can use this as RESIDENT code.  You should set the PURE bit to          *
  21. *    mark this executable as such.                          *
  22. *                                          *
  23. *******************************************************************************
  24. *                                          *
  25. *    Reading legal mush can turn your bain into guacamole!              *
  26. *                                          *
  27. *        So here is some of that legal mush:                  *
  28. *                                          *
  29. * Permission is hereby granted to distribute this program's source          *
  30. * executable, and documentation for non-comercial purposes, so long as the    *
  31. * copyright notices are not removed from the sources, executable or          *
  32. * documentation.  This program may not be distributed for a profit without    *
  33. * the express written consent of the author Michael Sinz.              *
  34. *                                          *
  35. * This program is not in the public domain.                      *
  36. *                                          *
  37. * Fred Fish is expressly granted permission to distribute this program's      *
  38. * source and executable as part of the "Fred Fish freely redistributable      *
  39. * Amiga software library."                              *
  40. *                                          *
  41. * Permission is expressly granted for this program and it's source to be      *
  42. * distributed as part of the Amicus Amiga software disks, and the          *
  43. * First Amiga User Group's Hot Mix disks.                      *
  44. *                                          *
  45. *******************************************************************************
  46. *
  47. * The following INCLUDE files are needed to make this program assemble.
  48. * They come with Amiga Macro-Assembler Packages and the developer updates.
  49. *
  50.     NOLIST                    ; No need to list these
  51.     INCLUDE    "EXEC/Types.i"
  52.     INCLUDE    "EXEC/Libraries.i"
  53.     INCLUDE    "EXEC/Ables.i"
  54.     INCLUDE    "EXEC/EXECbase.i"
  55.     INCLUDE    "EXEC/funcdef.i"
  56.     INCLUDE    "EXEC/EXEC_lib.i"
  57.     INCLUDE    "Libraries/DOSextens.i"
  58.     INCLUDE    "Intuition/IntuitionBase.i"
  59.     INCLUDE    "Intuition/Intuition.i"
  60.     LIST                    ; Ok, lets start the listing
  61. *
  62. *******************************************************************************
  63. *
  64. * We need to define a structure that has StandardPacket and InfoData in it...
  65. * This is used when we send the packet to the console device for our window
  66. * in order to find the Intuition Window Pointer for it...
  67. *
  68.     STRUCTURE        FindWindow,0
  69.             STRUCT    FW_Pack,sp_SIZEOF
  70.             STRUCT    FW_Info,id_SIZEOF
  71.             LABEL    FW_SIZEOF
  72. *
  73. *******************************************************************************
  74. *
  75. * This is the only fixed address in the system...
  76. *
  77.         xref    _AbsExecBase
  78. *
  79. *******************************************************************************
  80. *
  81. * Some macros that make calling the system routines easier...
  82. *
  83. CALLSYS        MACRO
  84.         xref    _LVO\1        ; Set the external reference
  85.         CALLLIB    _LVO\1        ; Call the EXEC definied macro
  86.         ENDM
  87. *
  88. *******************************************************************************
  89. *                                          *
  90. * Register usage through this system...                          *
  91. *                                          *
  92. *    a0    - Scrap                                  *
  93. *    a1    - Scrap                                  *
  94. *    a2    - Pointer to FW_Info                          *
  95. *    a3    - EXEC base save                          *
  96. *    a4    - Task                                  *
  97. *    a5    - FindWindow struct                          *
  98. *    a6    - ExecBase / IntuitionBase                      *
  99. *    a7    - Stack pointer...  What else?                      *
  100. *                                          *
  101. *    d0    - Scrap                                  *
  102. *    d1    - Scrap                                  *
  103. *    d2    - Window pointer                          *
  104. *    d3    - pr_Console handler                          *
  105. *    d4    - Block pen color                          *
  106. *    d5    - Detail pen color                          *
  107. *    d6    - CLI Task number (Used to make the colors)              *
  108. *    d7    - Zero...                              *
  109. *                                          *
  110. *******************************************************************************
  111. *
  112. CLIColors:    move.l    _AbsExecBase,a6        ; Get EXECbase...
  113.         move.l    a6,a3            ; Save it in a3 for later...
  114.         moveq.l    #0,d7            ; Clear our ZERO register...
  115.         move.l    d7,a1            ; Clear a1 for find-task...
  116.         CALLSYS    FindTask        ; Get our task...
  117.         move.l    d0,a4            ; Store the task...
  118.         tst.l    pr_CLI(a4)        ; Check if started from CLI
  119.         bne.s    FromCLI            ; If from CLI, all ok...
  120. *
  121. *******************************************************************************
  122. *
  123. * Since this program is to change CLI colors, if started from WorkBench, we
  124. * will just exit cleanly...
  125. *
  126.         lea    pr_MsgPort(a1),a0    ; Get message port...
  127.         move.l    a0,a2            ; Temp Storage...
  128.         CALLSYS    WaitPort        ; wait for WorkBench message...
  129.         move.l    a2,a0            ; Get message port again...
  130.         CALLSYS    GetMsg            ; Get the message...
  131.         move.l    d0,a1            ; Put message into a1
  132.         FORBID
  133.                         ; You must FORBID before
  134.         CALLSYS    ReplyMsg        ;    returning the WB message.
  135.         rts                ; And exit...
  136. *
  137. *******************************************************************************
  138. *
  139. * So, we are a CLI task, so lets generate the colors we want...
  140. *
  141. FromCLI:    move.l    pr_TaskNum(a4),d6    ; Get CLI task number...
  142.         move.l    d6,d4            ; Get the task number...
  143.         andi.w    #3,d4            ; Mask out most of it...
  144.         ori.w    #2,d4            ; Color should be 2 or 3...
  145.         move.l    d6,d5            ; Get task number...
  146.         addq.l    #1,d5            ; Add 1...
  147.         asr.w    #1,d5            ; Divide by 2...
  148.         add.w    d4,d5            ; Add the other color...
  149.         andi.w    #3,d5            ; There are only 2-bit planes
  150.         cmp.w    d5,d4            ; Check if they are the same...
  151.         bne.s    ColorIt            ; If not, all ok...
  152.         moveq    #1,d4            ; Set BlockPen to 1...
  153. *
  154. *******************************************************************************
  155. *
  156. * Now to find the window...    Need to send packet...  :-(
  157. *
  158. ColorIt:    move.l    pr_ConsoleTask(a4),d3    ; Get console task...
  159.         beq    ErrorExit        ; Exit if no console task...
  160. *
  161. *******************************************************************************
  162. *
  163. * This is my little Packet Sending code.  In this case, I have defined a
  164. * new structure that contains the StandardPacket structure and the InfoData
  165. * structure needed for this call.  For quick work and smaller code, I allocate
  166. * the packet from the stack.  Since packets *MUST* be long word aligned, a bit
  167. * of work must be done to make sure that the memory is aligned...
  168. *
  169.         lea    -(FW_SIZEOF+4)(sp),sp    ; Move stack to allocate space
  170. *
  171. * I allocate 4 bytes more than needed since I may need to move the pointer
  172. * a bit.  I could actually do this by allocating 2 bytes more since
  173. * the stack is always word aligned.  However, if the stack is long-word
  174. * aligned, I want to keep it that way since code runs faster on the 68020/030
  175. * when the stack is long-word aligned.
  176. *
  177. * As you can see, the address we get from the stack is then bumped by 3 and
  178. * then the bottom 2 bits are cleared.  The new address is then either
  179. * the original or 2 bytes further down the stack.  (Stack was already
  180. * word aligned so those are the only possibilities.)
  181. *
  182.         move.l    sp,d1            ; Get address
  183.         addq.l    #3,d1            ;   and make sure
  184.         and.b    #$FC,d1            ;   it is long word aligned
  185.         move.l    d1,a5            ; Point to the thing...
  186. *
  187. * Ok, so we have a packet at a5.  Now, we need to set the stange links
  188. * that packets use.  Address of the packet gets stored in the messages
  189. * list node name pointer  (??Weird stuf??)  and the packet's link stores
  190. * the pointer to the message structure...
  191. *
  192.         lea    (FW_Pack+sp_Pkt)(a5),a1    ; Get adress of FW_Pack.sp_Pkt
  193.         move.l    a1,(FW_Pack+sp_Msg+LN_NAME)(a5)    ; Store sp_Pkt in name
  194.         move.l    a5,(FW_Pack+sp_Pkt+dp_Link)(a5)    ; Store sp_Msg in link
  195. *
  196. * Packets are weird in that the packet reply port is not the standard
  197. * message reply port (packets use their own reply methods...)
  198. *
  199.         lea    pr_MsgPort(a4),a0    ; Set the reply port...
  200.         move.l    a0,(FW_Pack+sp_Pkt+dp_Port)(a5)
  201. *
  202. * To get the address of the window a console task has, we do a packet
  203. * of type ACTION_DISK_INFO.  (?!?)  This packet type takes a special
  204. * InfoData structure that will contain the results of this call.
  205. *
  206.         move.l    #ACTION_DISK_INFO,(FW_Pack+sp_Pkt+dp_Type)(a5)
  207. *
  208. * So, we now have to set up a pointer to the InfoData structure.  However,
  209. * this pointer is defined (due to BCPL AmigaDOS) as a BCPL pointer.  These
  210. * pointers are simply the address of the item pointed to left-shifted 2.
  211. * In other words, the bottom two bits are dropped.  This is why all of the
  212. * AmigaDOS structures MUST BE long word aligned.  AmigaDOS can not address
  213. * (via BCPL) non-long word addresses.
  214. *
  215.         lea    FW_Info(a5),a2        ; InfoData structre address
  216.         move.l    a2,d2
  217.         asr.l    #2,d2            ; Make BPTR out of it...
  218.         move.l    d2,(FW_Pack+sp_Pkt+dp_Arg1)(a5)
  219. *
  220. * Ok, the packet is set up and ready to go.  We take our reply port
  221. * (which is still in a0 from the steps above) and store it in a register
  222. * that will not get modified by the call.  Then we just send the packet
  223. * and wait for it to return.
  224. *
  225.         move.l    a0,d2        ; Save our port address
  226.         move.l    d3,a0        ; Get console port address
  227.         move.l    a5,a1        ; Get message packet address
  228.         CALLSYS    PutMsg        ; Send Packet
  229.         move.l    d2,a0        ; Our message port...
  230.         CALLSYS    WaitPort    ; Wait for return
  231.         move.l    d2,a0        ; Restore it again...
  232.         CALLSYS    GetMsg        ; Get it from the port
  233. *
  234. * The packet came back and we should now do some testing for errors.
  235. *
  236.         move.l    id_VolumeNode(a2),d2        ; Get window
  237.         move.l    (FW_Pack+sp_Pkt+dp_Res1)(a5),d0    ; Check return code...
  238.         lea    (FW_SIZEOF+4)(sp),sp    ; Move stack to deallocate
  239.         addq.l    #1,d0            ; Bump TRUE return to 0...
  240.         bne.s    ErrorExit        ; Exit if returned error...
  241.         tst.l    d2            ; Check the window...
  242.         beq.s    ErrorExit        ; Do color if there is one...
  243. *
  244. *******************************************************************************
  245. *
  246. ColorOk:    lea    intuitionName(pc),a1    ; Now open Intuition...
  247.         move.l    d7,d0            ; ANY version will do...
  248.         CALLSYS    OpenLibrary        ; Open it...
  249.         move.l    d0,a6            ; Save it as our pointer...
  250.         tst.l    d0            ; Check it...
  251.         beq.s    ErrorExit        ; If none, exit...
  252.         move.l    d2,a0            ; Window into address register
  253.         move.b    d5,wd_DetailPen(a0)    ; Store the colors
  254.         move.b    d4,wd_BlockPen(a0)    ;   that we just made...
  255.         CALLSYS    RefreshWindowFrame    ; Refresh it...
  256. *
  257. *******************************************************************************
  258. *
  259. * Now, close intuition and we are done...
  260. *
  261. NoWindow:    move.l    a6,a1            ; Get intuitionbase...
  262.         move.l    a3,a6            ; (Get execbase back...)
  263.         CALLSYS    CloseLibrary
  264. *
  265. *******************************************************************************
  266. *
  267. ErrorExit:    move.l    d7,d0            ; Clear return result
  268.         rts                ; Exit...
  269. *
  270. *******************************************************************************
  271. *
  272. * Data...
  273. *
  274. intuitionName:    dc.b    'intuition.library',0
  275. *
  276. *******************************************************************************
  277. *
  278. * And, with that we come to the end of another full-length feature staring
  279. * that wonderful MC680x0 and the Amiga system.  Join us again next time
  280. * for more Wonderful World of Amiga...  Until next time, keep boinging...
  281. *
  282.         END
  283.