home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USEROC90.MSA / LISTINGS_COLOURS.S < prev    next >
Text File  |  1990-08-19  |  9KB  |  290 lines

  1. * System variables for interrupts
  2.  
  3. VBLNO   EQU     $454            No of Vblank routines
  4. VBLQU   EQU     $456            Vblank queue
  5. HBLANK  EQU     $120            Hblank vector
  6. KEYHND  EQU     $118            Key handler vector
  7.  
  8. * Display registers
  9.  
  10. SSHMOD  EQU     $FF8240         Shift mode
  11. COLOR0  EQU     $FF8240         Palette colour 0
  12.  
  13. * MFP 68901 Addresses
  14.  
  15. IEA     EQU     $FFFA07         Interrupt Enable A
  16. IEB     EQU     $FFFA09         Interrupt Enable B
  17. ISRA    EQU     $FFFA0F         In Service A
  18. IMA     EQU     $FFFA13         Interrupt Mask A
  19. TBCR    EQU     $FFFA1B         Timer B Control
  20. TBDR    EQU     $FFFA21         Timer B Data
  21.  
  22. * Start of program
  23.  
  24. START   JSR     INIT            Set everything up
  25. WAITKEY CLR.W   D0
  26.         MOVE.W  #7,-(A7)        Raw input call
  27.         TRAP    #1
  28.         ADDQ    #2,A7
  29.         CMP.B   #$20,D0         Wait for Space to be pressed
  30.         BNE.S   WAITKEY
  31.         BRA     FIN             Controlled exit via FIN routine
  32.  
  33. * Subroutine to make any necessary calls to the OS
  34.  
  35. INIT    MOVE.W  #4,-(A7)        Get screen resolution
  36.         TRAP    #14
  37.         ADDQ    #2,A7
  38.         TST.W   D0              
  39.         BNE     THEEND           If not 0 set to 0
  40.  
  41.         CLR.L   -(A7)           Set supervisor mode
  42.         MOVE.W  #32,-(A7)
  43.         TRAP    #1
  44.         ADDQ    #6,A7
  45.         MOVE.L  #STK,A6         Save value of old stack
  46.         MOVE.L  D0,(A6)
  47.         
  48.         MOVE.W  #-1,-(A7)       Turn cursor off
  49.         MOVE.W  #0,-(A7)
  50.         MOVE.W  #21,-(A7)
  51.         TRAP    #14
  52.         ADDQ    #6,A7
  53.  
  54.         MOVE.W  #3,-(A7)
  55.         TRAP    #14             Get screen base address
  56.         ADDQ    #2,A7           and save in SCRAD 
  57.         MOVE.L  D0,SCRAD
  58.  
  59.         MOVE.L  #OLDPAL,A6        Save old palette
  60.         JSR     SAVEPAL
  61.  
  62.         MOVE.L  #RED,A6         Load new initial palette
  63.         JSR     RESTPAL
  64.  
  65.         MOVE.L  SCRAD,A0        
  66.         ADD.L   #16,A0          Copy colours onto screen
  67.         MOVE.L  #LINES,A1       from predefined block
  68.         MOVE.L  A1,A2
  69.         MOVE.L  #191,D0
  70. SETSC   MOVE.L  #31,D1        
  71. SETLN   MOVE.L  (A1)+,(A0)+
  72.         DBRA    D1,SETLN
  73.         ADD.W   #32,A0
  74.         MOVE.L  A2,A1
  75.         DBRA    D0,SETSC
  76.  
  77.         MOVE.L  #KEYHND,A0      Get old key handler
  78.         MOVE.L  (A0),A1
  79.         MOVE.L  A1,OLDKEY       Save it
  80.         MOVE.L  #NEWOKY,A2
  81.         ADDQ    #2,A2           Give address to new routine
  82.         MOVE.L  A1,(A2)
  83.         MOVE.L  #NEWKEY,(A0)    Replace old with new one
  84.  
  85.         MOVEQ   #0,D0   
  86.         MOVE.W  VBLNO,D0        Get old number of Vblank routines
  87.         MOVE.W  D0,D1
  88.         MOVE.W  D0,OLDVBN       Save old number
  89.         MOVE.L  VBLQU,A0        Get old Vblank Queue address
  90.         MOVE.L  A0,OLDVBQ       Save old address
  91.         MOVE.L  #NEWQU,A1       
  92.         SUBQ    #1,D0
  93. COPYQU  MOVE.L  (A0)+,(A1)+     Copy old queue into our new one
  94.         DBRA    D0,COPYQU
  95.         MOVE.L  #NEWQU,VBLQU    Set our queue as new one
  96.         MOVE.L  #VBL_RTN,(A1)+  Add new routine to queue
  97.         ADDQ    #1,D1           
  98.         MOVE.W  D1,$454         Add one to number of routines
  99.         
  100.         MOVE.L  #OLDMK,A0
  101.         MOVE.B  IEB,(A0)+       Save old Interrupt register values
  102.         MOVE.B  IEA,(A0)+
  103.         MOVE.B  IMA,(A0)+
  104.  
  105.         MOVE.L  #OLDHBV,A0      Save old Hblank vector
  106.         MOVE.L  HBLANK,(A0)
  107.  
  108.         AND.B   #$DF,IEB        Disable 200Hz Interrupt
  109.         AND.B   #$FE,IEA        Disable Hblank Interrupt
  110.  
  111.         MOVE.L  #HBL_RTN,A0     Replace old Hblank vector with
  112.         MOVE.L  A0,HBLANK               the address of our routine
  113.  
  114.         OR.B    #1,IEA          Re-enable Hblank interrupt
  115.         OR.B    #1,IMA
  116.  
  117.         MOVE.B  #0,GRNCNT       Set counter for green to 0
  118.  
  119.         RTS
  120.  
  121. * New key handling routine to stop mouse disrupting display
  122.  
  123. NEWKEY  MOVE.W  #$2500,SR
  124. NEWOKY  JMP     $0              Jump to old routine
  125.  
  126. * Vblank routine which is added to queue and called every Vblank
  127.  
  128. VBL_RTN MOVE.B  #0,TBCR         Stop timer
  129.  
  130.         MOVE.L  #COLOR0,A6      
  131.         MOVE.L  #GRN,A5
  132.         MOVEQ   #0,D0
  133.         MOVE.B  GRNCNT,D0
  134.         MOVE.W  D0,D1
  135.         DIVU    #4,D0
  136.         MULU    #2,D0           Get next palette in list of 
  137.         ADD.W   D0,A5           green paletes
  138.         MOVE.W  (A5),D7
  139.  
  140.         MOVE.L  #15,D2
  141. SETGRN  MOVE.W  (A6),D6
  142.         MOVE.B  #0,D6           Set blue to 0 as we replace
  143.         OR.B    D7,D6           old green value with new one,
  144.         MOVE.W  D6,(A6)+        thus setting blue palette for 
  145.         DBRA    D2,SETGRN       first 12 lines
  146.  
  147.         BTST.B  #0,GDIR         Check for direction
  148.         BNE     GDWN    
  149.         ADDQ    #1,D1           If up add 1 to counter
  150.         CMP.B   #60,D1          and check for end of list
  151.         BNE.S   NEWGRN
  152.         MOVE.B  #1,GDIR         If end change direction
  153.         BRA     NEWGRN
  154. GDWN    SUBQ    #1,D1           If down decrement counter
  155.         CMP.B   #0,D1           and check for start of list
  156.         BNE.S   NEWGRN
  157.         MOVE.B  #0,GDIR         If start change direction
  158. NEWGRN  MOVE.B  D1,GRNCNT       Save new value of counter
  159.  
  160.         MOVE.B  #1,BLUCNT       Set blue counter to second palette
  161.  
  162.         MOVE.B  #12,TBDR        Set number of Scan lines per Hblank
  163.         MOVE.B  #8,TBCR         Restart timer
  164.         RTS
  165.         
  166. * HBlank routine called every 12 lines
  167.  
  168. HBL_RTN MOVEM.L A6/D0-D1,-(A7)  Save the registers used by routine
  169.         MOVEQ   #0,D0
  170.         MOVE.B  BLUCNT,D0       Get count for next blue palette
  171.         MOVE.L  D0,D1
  172.         MULU    #2,D0
  173.         MOVE.L  #BLU,A6
  174.         ADD.W   D0,A6           Set address of correct palette
  175.         ADDQ    #1,D1
  176.         MOVE.B  D1,BLUCNT       Increment and save counter
  177.         MOVE.W  (A6),D1
  178.         MOVE.L  #COLOR0,A6
  179.         MOVE.W  #15,D0
  180. SETBLU  AND.W   #$FFF0,(A6)     Set new blue level for all colours
  181.         OR.W    D1,(A6)+
  182.         DBRA    D0,SETBLU
  183.        
  184.         BCLR    #0,ISRA         Re-enbale lower level interupts
  185.         MOVEM.L (A7)+,A6/D0-D1  Restore registers
  186.         RTE
  187.  
  188. * Routine to make a controlled exit, restoring anything we have 
  189. * changed and retruning to desktop
  190.  
  191. FIN     MOVE.L  #OLDPAL,A6      
  192.         JSR     RESTPAL         Restore original palette
  193.  
  194.         MOVE.L  OLDKEY,A0       Restore old key handler
  195.         MOVE.L  A0,KEYHND
  196.  
  197.         MOVE.L  OLDHBV,A0       Restore old Hblank handler
  198.         MOVE.L  A0,HBLANK
  199.  
  200.         MOVE.L  #OLDMK,A0       Restore MFP registers
  201.         MOVE.B  (A0)+,IEB
  202.         MOVE.B  (A0)+,IEA
  203.         MOVE.B  (A0),IMA
  204.  
  205.         MOVE.L  OLDVBQ,A0       Restore Vblank queue
  206.         MOVE.L  A0,VBLQU
  207.  
  208.         MOVE.W  OLDVBN,D0       and coorect number of vectors
  209.         MOVE.W  D0,VBLNO
  210.  
  211.         LEA     STK,A6          restore value of original stack
  212.         MOVE.L  (A6),-(A7)
  213.         MOVE.W  #32,-(A7)
  214.         TRAP    #1              and return to user mode
  215.         ADDQ    #6,A7
  216.  
  217.         MOVE.W  #0,-(A7)        Return to desktop
  218.         TRAP    #1
  219.  
  220. * Subroutine to save palette to address in A6
  221. * A5,D0 Corrupted
  222.  
  223. SAVEPAL MOVE.L  #COLOR0,A5
  224.         MOVEQ   #7,D0
  225. SAVE    MOVE.L  (A5)+,(A6)+
  226.         DBRA    D0,SAVE
  227.         RTS
  228.  
  229. * Subroutine to Restore Palette at address in A6
  230. * A5,D0 Corrupted
  231.  
  232. RESTPAL MOVE.L  #COLOR0,A5
  233.         MOVEQ   #7,D0
  234. REST    MOVE.L  (A6)+,(A5)+
  235.         DBRA    D0,REST
  236.         RTS
  237.  
  238. * Storage for:
  239.  
  240. STK     DS.L    1               Initial value of stack          
  241. OLDKEY  DS.L    1               Initial key handler vector
  242. OLDVBN  DS.W    1               Initial number of Vblank routines
  243. OLDVBQ  DS.L    1               Initial Vblank queue address
  244. OLDHBV  DS.L    1               Initial Hblank vector
  245. OLDMK   DS.B    3               Initial state of MFP
  246. OLDPAL  DS.L    8               Initial palette
  247. NEWQU   DS.L    20              New Vblank queue
  248. SCRAD   DS.L    1               Address of screen in memory
  249. GDIR    DS.B    1               Direction of green shift
  250. GRNCNT  DS.B    1               Green shift counter
  251. BLUCNT  DS.B    1               Blue shift counter
  252.  
  253. * Initial palette with red set
  254.  
  255. RED     DC.W    $000,$800,$100,$900,$200,$A00,$300,$B00
  256.         DC.W    $400,$C00,$500,$D00,$600,$E00,$700,$F00
  257.  
  258. * Blue settings for colours
  259.  
  260. BLU     DC.W    $000,$008,$001,$009,$002,$00A,$003,$00B
  261.         DC.W    $004,$00C,$005,$00D,$006,$00E,$007,$00F
  262.   
  263. * Green settings for colours
  264.  
  265. GRN     DC.W    $000,$080,$010,$090,$020,$0A0,$030,$0B0
  266.         DC.W    $040,$0C0,$050,$0D0,$060,$0E0,$070,$0F0
  267.  
  268. * Block to copy onto screen to get 16 colours
  269.  
  270. LINES   DC.W $0000,$0000,$0000,$0000
  271.         DC.W $FFFF,$0000,$0000,$0000
  272.         DC.W $0000,$FFFF,$0000,$0000
  273.         DC.W $FFFF,$FFFF,$0000,$0000
  274.         DC.W $0000,$0000,$FFFF,$0000
  275.         DC.W $FFFF,$0000,$FFFF,$0000  
  276.         DC.W $0000,$FFFF,$FFFF,$0000
  277.         DC.W $FFFF,$FFFF,$FFFF,$0000 
  278.         DC.W $0000,$0000,$0000,$FFFF
  279.         DC.W $FFFF,$0000,$0000,$FFFF
  280.         DC.W $0000,$FFFF,$0000,$FFFF
  281.         DC.W $FFFF,$FFFF,$0000,$FFFF
  282.         DC.W $0000,$0000,$FFFF,$FFFF
  283.         DC.W $FFFF,$0000,$FFFF,$FFFF
  284.         DC.W $0000,$FFFF,$FFFF,$FFFF
  285.         DC.W $FFFF,$FFFF,$FFFF,$FFFF
  286.  
  287. * The end
  288.  
  289. THEEND  END
  290.