home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / MAGGIE25.ARJ / MAGGIE25.MSA / GOODIES / JPGD.ZIP / jpgd.s < prev   
Text File  |  1998-03-04  |  6KB  |  294 lines

  1. ;
  2. ; jpeg test source code
  3. ; steve tattersall
  4. ; jpeg decoder (c) Brainstorm
  5. ;
  6. ; for maggie 25
  7. ;
  8. ;
  9. ;
  10.  
  11.         output    e:\jpeg.prg
  12.  
  13. screen        equ    1        ; output to screen?
  14.                     ; if yes, make sure you're in
  15.                     ; a 320*xxx truecolour mode!
  16.  
  17. incbin        equ    1        ; if 0, needs the auto folder driver
  18.                     ; if 1, includes the executable
  19.  
  20.         move.l    a7,a5
  21.         move.l    4(a5),a5
  22.         move.l    $c(a5),d0
  23.         add.l    $14(a5),d0
  24.         add.l    $1c(a5),d0
  25.         move.l    d0,-(a7)
  26.         move.l    a5,-(a7)
  27.         clr.w    -(a7)
  28.         move.w    #$4a,-(a7)
  29.         trap    #1
  30.         lea    12(a7),a7    ;reserve enough memory
  31.                     ;for the program
  32.  
  33.         pea    jpgd_find_cookie(pc)
  34.         move.w    #$26,-(a7)
  35.         trap    #14
  36.         addq.l    #6,a7
  37.  
  38.         pea    jpgd_decode(pc)
  39.         move.w    #$26,-(a7)
  40.         trap    #14
  41.         addq.l    #6,a7
  42.  
  43.  
  44.         clr.w    -(a7)
  45.         trap    #1
  46.  
  47. ;-----------------------------------------------------------------
  48. ;
  49. ;
  50. ; Example code to decode a sample picture to either memory or
  51. ; the default screen address
  52. ;
  53. ;
  54. ;-----------------------------------------------------------------
  55.  
  56. jpgd_decode:
  57.         ifne    screen
  58. ; Set the output to decode directly to the visible screen!
  59.         move.l    $44e.w,jpgd_output_addr
  60.         endc
  61.  
  62. ;
  63. ;
  64. ; install the process:
  65.         lea    jpgd_buffer(pc),a0
  66.         moveq    #1,d0
  67.         bsr    jpgd_callcommand
  68.         tst.l    d0            ;test for failure here
  69.  
  70. ; This part sets how the picture is to be decoded:
  71.  
  72.         lea    jpgd_buffer(pc),a0
  73.         move.l    #mypic,jpgd_picaddr(a0)
  74.         move.l    #mypiclen,jpgd_length(a0)
  75.  
  76. ; This part sets the input and output type expected
  77. ; (Best to specify 24 bit in both cases!)
  78. ; See the supplementary doc
  79.  
  80.         move.w    #3,jpgd_inputtype(a0)    ;24bit input from file
  81.         move.w    #3,jpgd_outputtype(a0)    ;24bit output to me
  82.         move.w    #4*3,jpgd_pixel_size    ;always 4*output size
  83.  
  84.         move.l    #jpgd_receive_pixel,jpgd_pixel_routine
  85.  
  86.         bsr    jpgd_setup_decoding
  87.  
  88. ; Now call the actual decoder parts
  89. ; a0 remains unchanged so can be reused
  90.         moveq    #4,d0
  91.         bsr    jpgd_callcommand
  92.         moveq    #5,d0
  93.         bsr    jpgd_callcommand
  94.         moveq    #6,d0
  95.         bsr    jpgd_callcommand
  96. ; Do a test for failure here:
  97.         tst.l    d0
  98.     
  99. ; Now de-install the decoder:
  100.         lea    jpgd_buffer(pc),a0
  101.         moveq    #2,d0
  102.         bsr    jpgd_callcommand
  103.         tst.l    d0
  104.  
  105. ; Wait for the space key before exit:
  106. .sp        cmp.b    #$39,$fffffc02.w
  107.         bne    .sp
  108.         rts
  109.  
  110.  
  111.  
  112. ;-----------------------------------------------------------------
  113. ; jpgd_setup_decoding:
  114. ;
  115. ; Next part sets up which routines capture the data that the
  116. ; decoder sends back
  117.  
  118. jpgd_setup_decoding:
  119.         move.w    #$ffff,jpgd_ready_flag(a0)    ;go!
  120.         move.l    #jpgd_ok,jpgd_outrout0(a0)
  121.                         ;output file flag (dummy)
  122.         move.l    #jpgd_copy_routine,jpgd_outrout1(a0)
  123.         move.l    #jpgd_ok,jpgd_outrout2(a0)
  124.                         ;dummy
  125.         move.l    #jpgd_rts,jpgd_stopdelete(a0)
  126.                         ;prevents a file deletion!
  127.         move.l    #jpgd_ok,jpgd_outrout3(a0)
  128.                         ;dummy 
  129.         rts
  130.  
  131. ;-----------------------------------------------------------------
  132. ; jpgd_find_cookie:
  133. ;
  134. ; Code to find the AUTO folder-installed cookie
  135. ; (only needed for the AUTO folder version)
  136.  
  137. jpgd_find_cookie:
  138.         move.l    $5a0.w,a0
  139. .find_cookie:
  140.         tst.l    (a0)
  141.         beq.s    .fail
  142.         cmp.l    #"_jpd",(a0)
  143.         beq.s    .succeed
  144.         addq.l    #8,a0
  145.         bra.s    .find_cookie
  146.  
  147. .fail:        moveq    #-1,d0
  148.         rts
  149.  
  150. .succeed:
  151.         move.l    4(a0),a1
  152.         move.l    a1,jpgd_address
  153.         rts
  154.  
  155.  
  156. ;-----------------------------------------------------------------
  157. ; jpgd_callcommand:
  158. ;
  159. ; executes the routine number passed in d0 where 1<=d0<=6
  160. ;
  161.  
  162. jpgd_callcommand:
  163.         ifeq    incbin
  164.         move.l    jpgd_address,a1
  165.         move.l    (a1,d0.w*4),a1
  166.         jsr    (a1)
  167.         rts
  168.         endc
  169.  
  170.         ifne    incbin
  171.         jmp    .mylist-4(pc,d0.w*4)
  172. .mylist:
  173.         bra.w    jpgd_driverbin+0
  174.         bra.w    jpgd_driverbin+70
  175.         bra.w    jpgd_driverbin+126
  176.         bra.w    jpgd_driverbin+134
  177.         bra.w    jpgd_driverbin+214
  178.         bra.w    jpgd_driverbin+386
  179.         endc
  180.  
  181.  
  182. ;-----------------------------------------------------------------
  183. ; jpgd_copy_routine:
  184. ; jpgd_ok:
  185. ; jpgd_rts:
  186. ;
  187. ; Routines used in the actual decoding process
  188.  
  189. jpgd_copy_routine:
  190.         movem.l    a0-a6/d1-d7,-(a7) 
  191.         movea.l    a0,a6 
  192.         movea.l    jpgd_block_output(a6),a0
  193.                         ;where to get data from
  194.         movea.l    jpgd_output_addr,a1     ;where to send it to
  195.         moveq    #0,d0 
  196.         moveq    #0,d1 
  197.         moveq    #0,d6
  198.         move.w    jpgd_bytessent(a6),d6    ;number of bytes sent
  199.         divu.w    jpgd_pixel_size,d6
  200.         subq.w    #1,d6 
  201.         move.w    jpgd_blocks_to_decode(a6),-(a7)
  202.                         ;fetch the number of
  203.                         ;blocks to decode
  204. .line_loop:
  205.         move.w    d6,d4 
  206.         moveq    #1,d7 
  207. .block_loop:
  208.         moveq    #7,d5 
  209. .pixel_loop:    
  210.         jsr    ([jpgd_pixel_routine.l])
  211.  
  212.         dbf    d5,.pixel_loop
  213.         dbf    d4,.block_loop
  214.         subq.w    #1,(a7)
  215.         bne.s    .line_loop
  216.         addq.w    #2,a7 
  217.  
  218.         move.l    a1,jpgd_output_addr
  219.         moveq    #0,d0             ;flag that it's OK
  220.         movem.l    (a7)+,a0-a6/d1-d7 
  221.         rts 
  222. jpgd_ok:    moveq    #0,d0
  223. jpgd_rts:    rts
  224.  
  225.  
  226. ; jpgd_receive_pixel
  227. ;
  228. ; fetches a 24-bit pixel and outputs it as a 16-bit truecolour value
  229. ; change this routine as required!
  230.  
  231. jpgd_receive_pixel:
  232.         movem.l    d0-d7/a2-a6,-(a7)
  233.         move.b    (a0)+,d1        ;ignore red
  234.         move.b    (a0)+,d0        ;use the green value
  235.         move.b    (a0)+,d1        ;ignore blue
  236.         ext.w    d0
  237.         asr.w    #3,d0            ;convert to 5 bits
  238.         mulu.w    #$841,d0
  239.         move.w    d0,(a1)+        ;output
  240.         movem.l    (a7)+,d0-d7/a2-a6
  241.         rts
  242.  
  243.  
  244. ;-----------------------------------------------------------------
  245. ; decoder data block structure:
  246. ;-----------------------------------------------------------------
  247.  
  248. jpgd_picaddr        equ    0
  249. jpgd_nameaddr        equ    4
  250. jpgd_length        equ    8
  251. jpgd_datasize        equ    12
  252. jpgd_inputtype        equ    18
  253. jpgd_outputtype        equ    20
  254. jpgd_ready_flag        equ    22
  255. jpgd_outrout0        equ    28
  256. jpgd_outrout1        equ    32
  257. jpgd_outrout2        equ    36
  258. jpgd_stopdelete        equ    40
  259. jpgd_outrout3        equ    60
  260. jpgd_block_output    equ    64
  261. jpgd_blocks_to_decode    equ    70
  262. jpgd_width        equ    86
  263. jpgd_height        equ    88
  264. jpgd_bytessent        equ    90
  265.  
  266. ;--------------------------------------------------------------------
  267.             section    data
  268. jpgd_address:        ds.l    1
  269. jpgd_pixel_size:    ds.w    1
  270. jpgd_decode_routine:    ds.l    1
  271. jpgd_output_addr:    dc.l    myblock
  272. jpgd_pixel_routine:    ds.l    1
  273.  
  274.  
  275. ;--------------------------------------------------------------------
  276. mypic            incbin    320x200g.jpg
  277. mypiclen        equ    *-mypic
  278.  
  279.             ifne    incbin
  280. jpgd_driverbin        incbin    'jpegd.bin'
  281. ; The driver needs 10K of blank data after it for internal storage!
  282.             ds.b    10000
  283.             endc
  284.  
  285. ;--------------------------------------------------------------------
  286.             section    bss
  287. jpgd_buffer:        ds.b    5288
  288.  
  289. ; This is the buffer where the output goes by default
  290.  
  291. myblock:        ds.b    110000
  292.  
  293.  
  294.