home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI03.ARJ / ictari.03 / ASSEMBLY / SPECTRUM / LOADSPX2.S next >
Text File  |  1985-11-20  |  14KB  |  518 lines

  1. * this routine loads one spectrum pic and shows on screen
  2.  
  3. flock     equ     $43E
  4. _vbl_list equ     $4CE
  5. video_adr equ     $FF8209 
  6. palette   equ     $FF8240 
  7.  
  8.           movea.l a7,a5 
  9.           movea.l #stack,a7     ;SP
  10.           movea.l 4(a5),a5      ;calculate memory size
  11.           move.l  $C(a5),d0 
  12.           add.l   $14(a5),d0
  13.           add.l   $1C(a5),d0
  14.           addi.l  #$100,d0
  15.           move.l  d0,-(a7)
  16.           move.l  a5,-(a7)
  17.           move.w  #0,-(a7)          
  18.           move.w  #$4A,-(a7)    ;Mshrink 
  19.           trap    #1
  20.           add.l   #12,a7 
  21.  
  22.           move.w  #2,-(a7)      ;Physbase
  23.           trap    #14           
  24.           addq.l  #2,a7 
  25.           move.l  d0,physbase   ;save physical screen address
  26.  
  27.           move.l  #m_off,-(a7)  ;Zeiger auf $12
  28.           move.w  #0,-(a7)      ;send one byte to keyboard
  29.           move.w  #$19,-(a7)    ;ikbdws  
  30.           trap    #14           ;mouse off
  31.           addq.l  #8,a7 
  32.  
  33.           move.l  #save_pal,-(a7) ;save palette
  34.           move.w  #$26,-(a7)      ;and 60 Hz on
  35.           trap    #14
  36.           addq.l  #4,a7 
  37.  
  38.           move.w  #4,-(a7)        ;get resolution
  39.           trap    #14
  40.           addq.l  #2,a7 
  41.           move.w  d0,rez          ;low resolution ?
  42.  
  43.           beq     low_res       
  44.           move.w  #0,-(a7)        ;No, then set low resolution
  45.           move.l  #-1,-(a7)     
  46.           move.l  #-1,-(a7)
  47.           move.w  #5,-(a7)
  48.           trap    #14
  49.           add.l   #12,a7 
  50.  
  51. low_res:   move.l  #c_pal,-(a7)  ;clear color palette
  52.           move.w  #$26,-(a7)    ;exec in supervisor mode
  53.           trap    #14
  54.           addq.l  #6,a7 
  55.  
  56. *-------------- read picture file ---------------------------
  57.  
  58.           lea     picfile,a5
  59.           move.w  #0,-(a7)      ;read only
  60.           move.l  a5,-(a7)      ;filename
  61.           move.w  #$3D,-(a7)    ;and open
  62.           trap    #1
  63.           addq.l  #8,a7
  64.  
  65.           tst.w   d0            ;Fopen was successful ?
  66.           bmi     error         ;No, exit
  67.  
  68.           move.w  d0,handle     ;read header
  69.           move.l  #header,-(a7) 
  70.           move.l  #12,-(a7)     ;12 Bytes
  71.           move.w  handle,-(a7)
  72.           move.w  #$3F,-(a7) 
  73.           trap    #1
  74.           add.l   #14,a7 
  75.  
  76.           tst.l   d0            ;error in Fread ?
  77.           bmi     error         ;Yes, exit
  78.           cmp.l   #12,d0        ;all 12 bytes read ?
  79.           bne     error         ;No, exit
  80.  
  81.           cmpi.w  #$5350,header ;check magic, ASCII 'SP'.. ($10EA8)
  82.           bne     error
  83.  
  84.           move.l  #chunk1,-(a7) ;address of picture data
  85.           move.l  size1,-(a7)   ;length of picture data
  86.           move.w  handle,-(a7)  ;and read
  87.           move.w  #$3F,-(a7)
  88.           trap    #1
  89.           add.l   #12,a7 
  90.  
  91.           tst.l   d0            ;error in Fread ?
  92.           bmi     error         ;yes, exit
  93.  
  94.           cmp.l   size1,d0      ;all bytes read ?
  95.           bne     error         ;no, exit
  96.  
  97.           move.l  #chunk2,-(a7) ;address of color data
  98.           move.l  size2,-(a7)   ;length of color data
  99.           move.w  handle,-(a7)  ;and read
  100.           move.w  #$3F,-(a7)
  101.           trap    #1
  102.           add.l   #12,a7 
  103.  
  104.           tst.l   d0
  105.           bmi     error
  106.           cmp.l   size2,d0      ;all bytesread ?
  107.           bne     error
  108.  
  109.           move.w  handle,-(a7)  ;close file
  110.           move.w  #$3E,-(a7)
  111.           trap    #1
  112.           addq.l  #4,a7 
  113.  
  114.           tst.w   d0            ;error in Fclose ?
  115.           bmi     error
  116.  
  117.           bsr     decode        ;decompress picture data
  118.  
  119.           move.l  #init,-(a7)   ;install new VBL
  120.           move.w  #$26,-(a7)
  121.           trap    #14
  122.           addq.l  #6,a7 
  123.  
  124. dispwait: move.w  #2,-(a7)          
  125.           move.w  #1,-(a7)      ;Bconstat: is a key pressed ?
  126.           trap    #13
  127.           addq.l  #4,a7 
  128.  
  129.           tst.w   d0
  130.           beq     dispwait      ;no, continue waiting
  131.  
  132.  
  133. error:
  134.           move.l  #restvbl,-(a7)        ;restore old VBL
  135.           move.w  #$26,-(a7)
  136.           trap    #14
  137.           addq.l  #6,a7 
  138.  
  139. er_exit:  move.w  rez,d0 
  140.           beq     ist_lo
  141.           move.w  d0,-(a7)      ;restore old resolution
  142.           move.l  #-1,-(a7)
  143.           move.l  #-1,-(a7)
  144.           move.w  #5,-(a7)
  145.           trap    #14
  146.           add.l   #12,a7
  147.  
  148. ist_lo:   move.l  #oldpal,-(a7) ;restore old color palette
  149.           move.w  #6,-(a7)
  150.           trap    #14
  151.           addq.l  #6,a7 
  152.  
  153.           move.l  #m_on,-(a7)   ;mouse on
  154.           move.w  #0,-(a7)          
  155.           move.w  #$19,-(a7)
  156.           trap    #14 
  157.           addq.l  #8,a7 
  158.  
  159.           clr.w   -(a7)      ;exit programm
  160.           trap    #1
  161.           rts
  162. *------------------------------------------------------------
  163. save_pal: lea     palette,a0    ;save palette
  164.           lea     oldpal,a1 
  165.           move.w  #15,d7
  166. copypal:  move.w  (a0)+,(a1)+ 
  167.           dbf     d7,copypal 
  168.  
  169.           move.b  $ffff820a,d7  ;get Syncmode
  170.           and.b    #$fd,d7      ;switch to 60 Hz
  171.           move.b  d7,$FFFF820a  ;write new mode
  172.           rts 
  173. *------------------------------------------------------------
  174. c_pal:    lea     palette,a0    ;clear palette
  175.           move.w  #15,d7
  176. c_pal_lp: clr.w   (a0)+ 
  177.           dbf     d7,c_pal_lp 
  178.           rts
  179. *-------------------------------------------------------------
  180. init:
  181.           move.l  _vbl_list,vbl 
  182.           move.l  #new_vbl,_vbl_list
  183.           rts 
  184. restvbl:
  185.           move.l  vbl,_vbl_list 
  186.           rts 
  187.  
  188. *------------------------- decompress picture data -----------
  189.  
  190. decode:   lea     chunk1,a0     ;decompress picture data
  191.           movea.l physbase,a1 
  192.           move.w  #1,d1         ;d1: distance 1st Byte to the 2nd Byte in a word of a plane
  193.           move.w  #7,d7         ;d7: distance 2nd Byte in a word to the 1st in the next word of the same plane
  194.           lea     32000(a1),a2  ;a2: end of the screen memory
  195.           lea     8(a2),a3      ;end-label
  196. nxtplane: lea     -31840(a2),a1 ;minus 31840, that means 199 lines back
  197.  
  198. expand:   move.b  (a0)+,d6      ;get byte from chunk
  199.           ext.w   d6            ;extend to word size: if D6>=0, then
  200.           bmi     negativ       ;get D6 bytes direct from file
  201. exp_lp:   move.b  (a0)+,(a1)    ;positive number: next byte to screen
  202.           adda.w  d1,a1         ;next byte of *this* Plane
  203.           exg     d1,d7         ;exchange the distance 1 and 7
  204.           dbf     d6,exp_lp 
  205.           bra     weiter
  206.  
  207. negativ:  neg.w   d6            ;d6:=-d6+1
  208.           addq.w  #1,d6
  209.           move.b  (a0)+,d0      ;get one byte from chunk
  210. exp2_lp:  move.b  d0,(a1)       ;and repeat *this* Byte D6 times
  211.           adda.w  d1,a1 
  212.           exg     d1,d7 
  213.           dbf     d6,exp2_lp 
  214.  
  215. weiter:   cmpa.l  a2,a1         ;end of picture data ?
  216.           bcs     expand        ;No, continue
  217.  
  218.           bne     abort         ;Hu ? Something's wrong!
  219.           addq.l  #2,a2         ;one more plane
  220.           cmpa.l  a3,a2         ;8(A2) already reached ?
  221.           bcs     nxtplane
  222.  
  223.           move.l  a0,d0         ;first address after the chunk
  224.           addq.l  #1,d0         ;add 1
  225.           bclr.l  #0,d0         ;and make even
  226.           subi.l  #chunk1,d0    ;calculate absolute size
  227.           cmp.l   size1,d0      ;are they equal ?
  228.           bne     abort         ;No: something's wrong !
  229.  
  230.           lea     chunk2,a0     ;decompress color data
  231.           lea     colreg,a1 
  232.           move.w  #596,d7       ;199 lines with 3 palettes = 597 palettes
  233.           clr.w   d0            ;d0: black
  234. nxtregs:  move.w  #13,d6        ;14 colors, color 0 and 15: black
  235.           move.w  (a0)+,d1      ;get control byte from color chunk
  236.           lsr.w   #1,d1         ;least significant bit: don't care
  237.           move.w  d0,(a1)+      ;black one time
  238. inner:    lsr.w   #1,d1         ;test bits from right to left
  239.           bcc     Bit_0         ;set bits show used colors
  240.  
  241.           move.w  (a0)+,(a1)+   ;get next byte
  242.           dbf     d6,inner
  243.           bra     common        ;loop finished
  244.  
  245. Bit_0:    move.w  d0,(a1)+      ;get black
  246.           dbf     d6,inner 
  247.  
  248. common:   move.w  d0,(a1)+      ;most significant bit black, too
  249.           dbf     d7,nxtregs    ;get next set of registers
  250.           suba.l  #chunk2,a0    ;check length
  251.           cmpa.l  size2,a0      ;ok ?
  252. abort:     rts 
  253.  
  254. *-------------------- Coded for 60 Hz !! ----------------------
  255. new_vbl: 
  256.           tst.w   flock         ;time critical code
  257.           bne     short         ;Yes, then short cut
  258.           move    sr,-(a7)
  259.           ori     #$700,sr      ;disable interrupts
  260.  
  261.           lea     palette,a4    ;hardware palette
  262.           lea     video_adr,a5  ;video address counter
  263.           lea     delay,a6      ;delay table
  264.           lea     colrs,a3      ;color table
  265.           move.w  #198,d7       ;199 lines
  266.           clr.l   d0            ;clear for later address calculation
  267. wt_low:   tst.b   (a5)          ;video addresse, lowbyte=0 ?
  268.           beq     wt_low        ;wait for the end of VBL
  269.  
  270.           move.b  (a5),d0       ;lowbyte of video address + buffer
  271.           add.l   d0,a6 
  272.           jmp     (a6)          ;and synchronise
  273.  
  274. delay:       NOP
  275.         NOP
  276.         NOP
  277.         NOP
  278.         NOP
  279.         NOP
  280.         NOP
  281.         NOP
  282.         NOP
  283.         NOP
  284.         NOP
  285.         NOP
  286.         NOP
  287.         NOP
  288.          NOP
  289.         NOP
  290.         NOP
  291.         NOP
  292.         NOP
  293.         NOP
  294.         NOP
  295.         NOP
  296.         NOP
  297.         NOP
  298.         NOP
  299.         NOP
  300.         NOP
  301.         NOP
  302.         NOP
  303.         NOP
  304.         NOP
  305.         NOP
  306.         NOP
  307.         NOP
  308.         NOP
  309.         NOP
  310.         NOP
  311.         NOP
  312.         NOP
  313.         NOP
  314.         NOP
  315.         NOP
  316.         NOP
  317.         NOP
  318.         NOP
  319.         NOP
  320.         NOP
  321.         NOP
  322.         NOP
  323.         NOP
  324.         NOP
  325.         NOP
  326.         NOP
  327.         NOP
  328.         NOP
  329.         NOP
  330.         NOP
  331.         NOP
  332.         NOP
  333.         NOP
  334.         NOP
  335.         NOP
  336.         NOP
  337.         NOP
  338.         NOP
  339.         NOP
  340.         NOP
  341.         NOP
  342.         NOP
  343.         NOP
  344.         NOP
  345.         NOP
  346.         NOP
  347.         NOP
  348.         NOP
  349.         NOP
  350.         NOP
  351.         NOP
  352.         NOP
  353.         NOP
  354.         NOP
  355.         NOP
  356.         NOP
  357.         NOP
  358.         NOP
  359.         NOP
  360.         NOP
  361.         NOP
  362.         NOP
  363.         NOP
  364.         NOP
  365.         NOP
  366.         NOP
  367.         NOP
  368.         NOP
  369.         NOP
  370.         NOP
  371.         NOP
  372.         NOP
  373.         NOP
  374.         NOP
  375.         NOP
  376.         NOP
  377.         NOP
  378.         NOP
  379.         NOP
  380.         NOP
  381.         NOP
  382.         NOP
  383.         NOP
  384.         NOP
  385.         NOP
  386.         NOP
  387.         NOP
  388.         NOP
  389.         NOP
  390.         NOP
  391.         NOP
  392.         NOP
  393.         NOP
  394.         NOP
  395. setcolor:  nop
  396.           lea     (a4),a0       ;set a0-a2 to the palette register
  397.           lea     (a4),a1 
  398.           lea     (a4),a2 
  399.  
  400.           move.l  (a3)+,(a0)+   ;load first picture palette
  401.           move.l  (a3)+,(a0)+ 
  402.           move.l  (a3)+,(a0)+ 
  403.           move.l  (a3)+,(a0)+ 
  404.           move.l  (a3)+,(a0)+ 
  405.           move.l  (a3)+,(a0)+ 
  406.           move.l  (a3)+,(a0)+ 
  407.           move.l  (a3)+,(a0)+ 
  408.  
  409.           move.l  (a3)+,(a1)+   ;load second picture palette
  410.           move.l  (a3)+,(a1)+ 
  411.           move.l  (a3)+,(a1)+ 
  412.           move.l  (a3)+,(a1)+ 
  413.           move.l  (a3)+,(a1)+ 
  414.           move.l  (a3)+,(a1)+ 
  415.           move.l  (a3)+,(a1)+ 
  416.           move.l  (a3)+,(a1)+ 
  417.  
  418.           move.l  (a3)+,(a2)+   ;load third picture palette
  419.           move.l  (a3)+,(a2)+ 
  420.           move.l  (a3)+,(a2)+ 
  421.           move.l  (a3)+,(a2)+ 
  422.           move.l  (a3)+,(a2)+ 
  423.           move.l  (a3)+,(a2)+ 
  424.           move.l  (a3)+,(a2)+ 
  425.           move.l  (a3)+,(a2)+ 
  426.           dbf     d7,setcolor   ;repeat at all 199 times
  427.  
  428. ;one more line
  429.           lea     (a4),a0       ;set A0-A2 to the palette register
  430.           lea     (a4),a1 
  431.           lea     (a4),a2 
  432.           move.l  (a3)+,(a0)+   ;load first picture palette
  433.           move.l  (a3)+,(a0)+ 
  434.           move.l  (a3)+,(a0)+ 
  435.           move.l  (a3)+,(a0)+ 
  436.           move.l  (a3)+,(a0)+ 
  437.           move.l  (a3)+,(a0)+ 
  438.           move.l  (a3)+,(a0)+ 
  439.           move.l  (a3)+,(a0)+ 
  440.  
  441.           move.l  (a3)+,(a1)+   ;load second picture palette
  442.           move.l  (a3)+,(a1)+ 
  443.           move.l  (a3)+,(a1)+ 
  444.           move.l  (a3)+,(a1)+ 
  445.           move.l  (a3)+,(a1)+ 
  446.           move.l  (a3)+,(a1)+ 
  447.           move.l  (a3)+,(a1)+ 
  448.           move.l  (a3)+,(a1)+ 
  449.  
  450.           move.l  (a3)+,(a2)+   ;load third picture palette
  451.           move.l  (a3)+,(a2)+ 
  452.           move.l  (a3)+,(a2)+ 
  453.           move.l  (a3)+,(a2)+ 
  454.           move.l  (a3)+,(a2)+ 
  455.           move.l  (a3)+,(a2)+ 
  456.           move.l  (a3)+,(a2)+ 
  457.           move.l  (a3)+,(a2)+ 
  458.  
  459. ;and oooonce again
  460.           lea     (a4),a0       ;set a0-a2 to the palette register
  461.           lea     (a4),a1 
  462.           lea     (a4),a2 
  463.           lea     -19040(a3),a4 ;go 19040 Bytes back
  464.           nop                   ;(198 lines)
  465.           nop 
  466.           move.l  (a3)+,(a0)+   ;first picture palette
  467.           move.l  (a3)+,(a0)+ 
  468.           move.l  (a3)+,(a0)+ 
  469.           move.l  (a3)+,(a0)+ 
  470.           move.l  (a3)+,(a0)+ 
  471.           move.l  (a3)+,(a0)+ 
  472.           move.l  (a3)+,(a0)+ 
  473.           move.l  (a3)+,(a0)+ 
  474.  
  475.           move.l  (a3)+,(a1)+   ;second picture palette
  476.           move.l  (a3)+,(a1)+ 
  477.           move.l  (a3)+,(a1)+ 
  478.           move.l  (a3)+,(a1)+ 
  479.           move.l  (a3)+,(a1)+ 
  480.           move.l  (a3)+,(a1)+ 
  481.           move.l  (a3)+,(a1)+ 
  482.           move.l  (a3)+,(a1)+ 
  483.  
  484.           move.l  (a4)+,(a2)+   ;attention: these are the colors from
  485.           move.l  (a4)+,(a2)+   ;199 lines ago
  486.           move.l  (a4)+,(a2)+ 
  487.           move.l  (a4)+,(a2)+ 
  488.           move.l  (a4)+,(a2)+ 
  489.           move.l  (a4)+,(a2)+ 
  490.           move.l  (a4)+,(a2)+ 
  491.           move.l  (a4)+,(a2)+ 
  492.           move    (a7)+,sr      ;enable interrupts
  493. short:     rts 
  494.  
  495. picfile:  dc.b    'madonna.spc',0
  496. m_on:     dc.b    8
  497. m_off:    dc.b    18
  498.  
  499.           section bss
  500.           even
  501.  
  502. physbase: ds.l    1
  503. rez:      ds.l    1
  504. vbl:      ds.l    1
  505. oldpal:   ds.l    8
  506. header:   ds.l    1
  507. size1:    ds.l    1
  508. size2:    ds.l    1
  509. handle:   ds.w    1
  510.  
  511. chunk1:   ds.b    $7F7C         ;buffer for picture data
  512. chunk2:   ds.b    $45F6         ;buffer for color data
  513. colreg:   ds.w    16            ;area for color register
  514. colrs:    ds.b    $4A80
  515.  
  516.          ds.w    200           ;Stack
  517. stack:   ds.w    1
  518.