home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / lynxlib / colsws.s < prev    next >
Text File  |  1993-10-23  |  4KB  |  173 lines

  1. ; This source file is part of the LynxLib miscellaneous library by
  2. ; Robert Fischer, and is Copyright 1990 by Robert Fischer.  It costs no
  3. ; money, and you may not make money off of it, but you may redistribute
  4. ; it.  It comes with ABSOLUTELY NO WARRANTY.  See the file LYNXLIB.DOC
  5. ; for more details.
  6. ; To contact the author:
  7. ;     Robert Fischer \\80 Killdeer Rd \\Hamden, CT   06517   USA
  8. ;     (203) 288-9599     fischer-robert@cs.yale.edu
  9.  
  10. .include "atari.s"
  11. ; This is the companion .S file for colsw.c
  12.  
  13. ; This is test code:
  14. ;    Physbase
  15. ;    move.l    d0, d7
  16. ;    Fopen    #test, #0
  17. ;    move.l    d0, d6
  18. ;    Fread     d6, #128, #buf
  19. ;    Fread    d6, #32000, d7
  20. ;    Fclose    d6
  21.  
  22. ;    move.l    #pal, -(sp)
  23. ;    move.l    d7, -(sp)
  24. ;    bsr.s    _change_colors
  25. ;    addq.l    #8, sp
  26.  
  27. *    Physbase
  28. *    move.l    d0, d7
  29. *    Fcreate    #test2, #0
  30. *    move.l    d0, d6
  31. *    Fwrite    d6, #128, #buf
  32. *    Fwrite    d6, #32000, d7
  33. *    Fclose    d6
  34.  
  35. ;    Cnecin
  36. ;    Pterm0
  37. ;*-------------------------------------------------------------
  38.  
  39. _switch_colors:: .cargs .pic.l, .pal.l
  40. ;* Does the main work.
  41. ;* .pic: the pointer to the 32000 bytes of picture
  42. ;* .pal: the pointer to the 16 words of color changing information.
  43. ;*       This will change color x to color x(.pal)
  44. ;
  45. ;*    Register use:
  46. ;*        a0: current point in picture
  47. ;*        a1: pointer to palette
  48. ;*        a3: last byte in picture + 1
  49. ;*        a4: temporary
  50.  
  51. ;*        d0: word 0 in a set of four words which represent four bit planes
  52. ;*        d1: word 1.......
  53. ;*        d2: word 2.......
  54. ;*        d3: word 3.......
  55. ;*        d4: temp
  56. ;*        d5: color word
  57. ;*        d6, d7: temp
  58.     move.l    4(sp), a0        ;* Picture stuff
  59.     move.l    8(sp), a1        ;* Palette stuff
  60.  
  61.     ;* Convert the 1*16 table of colors to 16*16
  62.     ;* a4 is memory counter
  63.     ;* d0 is counter for rows
  64.     ;* d1 is counter for the columns
  65.     ;* d2 is the high-order nybble for the rows
  66.     move.l    sp, a4
  67.     sub.l    #256, sp
  68.     move.w    #15, d0        ;* Counter for the rows
  69.     .maketab:
  70.         move.b    0(a1, d0), d2    ; Get high-order nybble
  71.         lsl.b    #4, d2
  72.  
  73.         move.w    #15, d1
  74.         .innermtab:
  75.             ;* d4 is the new color value for the low order
  76.             ;* d3 is a temporary
  77.             move.b    0(a1, d1), d4
  78.             or.b    d2, d4
  79.             move.b    d4, -(a4)
  80.         dbra d1, .innermtab        ;* Stop when d1 goes < 0
  81.     dbra    d0, .maketab        ;* Stop when d0 goes < 0
  82.  
  83.     ;* Load up all the registers
  84.     move.l    a4, a1
  85.     lea        32000(a0), a3
  86.  
  87.     .startloop:
  88.     cmpa.l    a3, a0        ;* for (; a0 < a3; a0 += 8) {
  89.     beq        .endloop
  90.  
  91. .macro LDREG xreg, xoffset
  92.     move.w    \xoffset(a0), \xreg    ;* Load up the d registers for this
  93.     swap    \xreg
  94.     move.w    8+\xoffset(a0), \xreg
  95. .endm
  96.  
  97.         LDREG    d0, 0    ; Load up the registers
  98.         LDREG    d1, 2
  99.         LDREG    d2, 4
  100.         LDREG    d3, 6
  101.  
  102.         bsr.s        transpose
  103.  
  104.         movem.l        d0/d1/d2/d3, regsv    ; Put in temporary memory
  105.  
  106.         lea            regsv, a4        ; Do the actual lookup work
  107.         move.w    #16, d4
  108.         .workloop:
  109.             move.b    (a4), d5        ; Look up 1 byte at a time
  110.             move.b    0(a1, d5), (a4)+
  111.         dbra    d4, .workloop
  112.  
  113.         movem.l        regsv, d0/d1/d2/d3
  114.  
  115.         bsr.s        transpose
  116.  
  117. .macro SVREG xreg, xoffset
  118.     move.w    \xreg, 8+\xoffset(a0)    ;* Save the d registers for this
  119.     swap    \xreg
  120.     move.w    \xreg, \xoffset(a0)
  121. .endm
  122.  
  123.         SVREG    d0, 0    ; Save the registers
  124.         SVREG    d1, 2
  125.         SVREG    d2, 4
  126.         SVREG    d3, 6
  127.  
  128.     add.l    #16, a0
  129.     bra        .startloop
  130.     .endloop:
  131.  
  132.     lea        256(sp), sp    ;* Pop our table off the stack
  133.  
  134.     rts
  135. ;*-------------------------------------------------------------
  136.  
  137.         ; Transpose the matrix
  138. .macro TRANSPOSE reg1, reg2, bits
  139.     move.l    \reg1, d6    ; Make 1st set of alternating bits
  140.     and.l    d4, d6
  141.     eor.l    d6, \reg1
  142.     move.l    \reg2, d7    ; Make 2nd set of alternating bits
  143.     and.l    d4, \reg2
  144.     eor.l    \reg2, d7
  145.     lsl.l    #\bits, d6    ; Mesh the bits
  146.     lsr.l    #\bits, d7
  147.     or.l    d6, \reg2
  148.     or.l    d7, \reg1
  149. .endm
  150.  
  151. mask2 = %00110011001100110011001100110011
  152. mask1 = %01010101010101010101010101010101
  153. transpose:
  154.     move.l        #mask2, d4
  155.     TRANSPOSE    d3, d1, 2
  156.     TRANSPOSE    d2, d0, 2
  157.     move.l        #mask1, d4
  158.     TRANSPOSE    d3, d2, 1
  159.     TRANSPOSE    d1, d0, 1
  160.     rts
  161.  
  162.  
  163.  
  164.     .data
  165. test: dc.b "TEST.NEO"
  166. test2: dc.b "TEST2.NEO"
  167. pal: dc.w 0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13
  168. ;pal: dc.b 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  169. ;pal: dc.b 15, 14, 13, 12, 11, 10, 9,8,7,6,5,4,3,2,1,0
  170.     .bss
  171. buf: ds.b    128
  172. regsv: ds.l    4
  173.