home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Painting / DIGIPAINTIII.DMS / in.adf / HeyStuff / HeyLINE.asm < prev    next >
Encoding:
Assembly Source File  |  1989-07-12  |  8.0 KB  |  322 lines

  1. ****** This program's (this section and all modules on disk) source code is
  2. ******       Copyright © 1987,1988 by Jamie D. Purdon  (Cleveland, Ohio)
  3. ** 1> HeyLine DigiPaint count#rgb line# r# g# b#  (r,g,b range 0..1023)
  4. ** causes digipaint to fill line# with count#rgb pixels of r#,g#,b# color
  5. *
  6. *** builds 
  7. * msg    {
  8. *        standard msg node
  9. *        'REMO'
  10. *        'Dlvb',Count.W,Line.W,n(rgb) 'remainder of cmdline'
  11. *    }
  12.  
  13.     section    Startup,CODE
  14.  
  15.     include "exec/types.i"
  16.     include "exec/nodes.i"
  17.     include "exec/lists.i"
  18.     include "exec/ports.i"
  19.     ;include "exec/tasks.i"
  20.     include "exec/execbase.i"
  21.     include "libraries/dosextens.i"    ; for pr_... process struct
  22.     include "exec/memory.i" ;for AllocMem types
  23.     ;include "exec/funcdef.i" 
  24.     include "libraries/dos.i" 
  25.  
  26.  
  27.  STRUCTURE MyVariables,0 ;<<=THIS IS WHERE WE POINT A5 (BP) ....
  28.  LONG CmdLineLen_ original, from dos or zero
  29.  LONG CmdLineAdr_ original, from dos or modified -> icon name
  30.  LONG HisPort_    ;digipaint's paint, which we look for...
  31.  STRUCT DigiPortName_,40    ;name of port to send msg to
  32.  STRUCT OnlyPort_,MP_SIZE    ;standard exec message port
  33. ; STRUCT CustMsg_,128        ;lotsa room, msgs are small anyway
  34.  STRUCT CustMsg_,(128+(6*1024))        ;LOTSA room,...wholeline of max#rgb's
  35.  LABEL BP_SIZEOF    ;size of scratch / bss section / variables
  36.  
  37. BP equr A5
  38. CALLIB macro
  39.   ifnd _LVO\1
  40.     xref    _LVO\1
  41.   endc
  42.     jsr    _LVO\1(a6)
  43.     endm
  44.  
  45. ******************** Start of Code *************************
  46.  
  47. ;Allocate a 'basepage' and point A5 to it
  48. start:    move.l    $0004,a6        ;we only need exec calls!
  49.     movem.l    d0/a0,-(sp)        ;cmdline args if any
  50.     move.l    #((BP_SIZEOF+7)&$ffffFFF8),d0    ;basepage size, roundup 2xlword
  51.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;pub for msg=shared mem
  52.     CALLIB    AllocMem
  53.     tst.l    d0            ;set/clr zero flag
  54.     move.l    d0,BP            ;register A5, basepage, vars at +offsets
  55.     movem.l    (sp)+,d0/a0        ;cmdline args if any (moveM no Z effect)
  56.     beq    nomem_atall        ;abort!, no base avail!
  57.  
  58. ;Ensure CLI-type startup (any shell should work)
  59.     movem.l d0/a0,CmdLineLen_(BP)
  60.     move.l    ThisTask(a6),A4        ;execbase, us, we're alive, right?
  61.     tst.l    pr_CLI(A4)        ;A4=OUR TASK do we have a cli struct?
  62.     beq    Boom            ;boom. (from wbench?), CLI ONLY!!!
  63.  
  64. ;Grab portname from cmd line
  65.     lea    DigiPortName_(BP),a1    ;a0=cmdline ptr
  66. grabname:
  67.     move.b    (a0)+,d1    ;char from cmdline
  68.     beq.s    endname
  69.     cmp.b    #$0a,d1
  70.     beq.s    endname
  71.     cmp.b    #' ',d1
  72.     beq.s    endname
  73.     move.b    d1,(a1)+    ;...to string at end of custmsg
  74.     subq    #1,d0
  75.     bne.s    grabname
  76. endname:        ;string 'digiportname' on basepage, a0=resta cmd line
  77.     clr.b    (a1)    ;NULL to end 'digiportname'
  78.  
  79. ;Copy rest of cmd line to custom message
  80.     lea    CustMsg_(BP),a1    ;A1=msgptr
  81.     move.b    #NT_MESSAGE,LN_TYPE(a1)    ;fill in (alloc'd clear) msg struct
  82.     lea    OnlyPort_(BP),a2
  83.     move.l    a2,MN_REPLYPORT(a1)    ;point back to our port for reply
  84.  
  85.     lea    MN_SIZE(a1),a2    ;a2=ptr end of message
  86.     move.l    a2,LN_NAME(a1)    ;name of 'our' msg...
  87.     move.l    #'REMO',(a2)+    ;gonna builda name
  88.  
  89.  
  90.  
  91.  IFC 't','f'
  92.     subq    #1,d0    ;d0=db' type loop ctr, LEN of remainder of cmd line
  93. grabcl:    move.b    (a0)+,d1    ;char from cmd line
  94.     beq.s    endmsg
  95.     cmp.b    #$0a,d1        ;eol?
  96.     beq.s    endmsg
  97.     move.b    d1,(a2)+
  98.     dbf    d0,grabcl
  99. endmsg:            ;string 'digiportname' on basepage
  100.   ENDC
  101.     
  102.  
  103.     move.l    #'Dlvb',(a2)+    ;'DeLiVer Binary action code'
  104.     ;move.W    #96,(a2)+    ;COUNT (deliver this many)
  105.     bsr    cva2i
  106.     move.w    d0,(a2)+    ;COUNT from cmd line WATCH NO ERROR CHECKING
  107.     ;move.w    #10,(a2)+    ;line# on digipaint screen
  108.     bsr    cva2i
  109.     move.w    d0,(a2)+    ;line# from cmd line WATCH NO ERROR CHECKING
  110.  
  111.     ;ConVertAscii2Integer:
  112.     ;-skips digits after decimal point
  113.     ;-no negative #s, result must be WORD size....64k-1
  114.  
  115.     ;a0=point to string, returns d0=#, a0 advanced just past # (DESTROYS D1)
  116.     bsr cva2i
  117.     move.w    d0,-(sp)    ;RED
  118.     bsr cva2i
  119.     move.w    d0,-(sp)    ;GREEN
  120.     bsr cva2i
  121.  
  122.     move.w    #$03ff,d3    ;max blue
  123.     move.w    d3,d2    ;max gr
  124.     move.w    d3,d1    ;max red
  125.  
  126.     and.w    d0,d3        ;BLUE
  127.     and.w    (sp)+,d2    ;GREEN
  128.     and.w    (sp)+,d1    ;RED
  129.  
  130.     
  131.     move.w    -4(a2),d0    ;count, from cmd line (pull frm blding msg)
  132.     subq    #1,d0        ;dbf' type loop
  133. packit:    move.w    d1,(a2)+    ;red
  134.     move.w    d2,(a2)+    ;gr
  135.     move.w    d3,(a2)+    ;blue
  136.     dbf    d0,packit
  137.  
  138.  
  139.  
  140.     lea    DigiPortName_(BP),a1
  141.     CALLIB    FindPort
  142.     move.l    d0,HisPort_(BP)    ;digipaint's msg port
  143.     beq    Boom
  144.  
  145. ;Make a port named "REMOblahblah" ANNOUNCE OURSELVES
  146.     LEA    OnlyPort_(BP),a2    ;A2=PORT
  147.     moveq    #-1,d0
  148.     CALLIB    AllocSignal    ;d0=return
  149.     moveq    #-1,d1
  150.     cmp.l    d0,d1    ;-1 indicates bad signal
  151.     beq    Boom
  152.     move.b    d0,MP_SIGBIT(a2)
  153.     move.b    #PA_SIGNAL,MP_FLAGS(a2)
  154.     move.b    #NT_MSGPORT,LN_TYPE(a2)
  155.     clr.b    LN_PRI(a2)
  156.     move.l    A4,MP_SIGTASK(a2)    ;task cached at start....
  157.  
  158.     lea    MP_MSGLIST(a2),a0    ;new port's list header
  159.     NEWLIST    a0            ;use macro from exec/lists.i
  160.  
  161.     lea    CustMsg_(BP),a1        ;A1=msgptr
  162.     lea    MN_SIZE(a1),a1    ;stringptr 'REMO'blahblah
  163.     move.l    a1,LN_NAME(a2)        ;portname=
  164.  
  165.     move.l    a2,a1            ;A2=A1=PORT
  166.     CALLIB    AddPort to the system list, let everyone see I'm here...
  167.  
  168. ;Send CustMsg to HisPort
  169.     move.l    HisPort_(BP),a0    ;DigiPaint's port
  170.     lea    CustMsg_(BP),a1
  171.     CALLIB    PutMsg            ;send msg to digipaint
  172.  
  173. waitonm:
  174.     lea    OnlyPort_(BP),a0
  175.     CALLIB    WaitPort
  176.     lea    OnlyPort_(BP),a0
  177.     CALLIB    GetMsg
  178.     tst.l    d0        ;we got a signal, did we get a mesg?
  179.     beq.s    waitonm
  180.     move.l    d0,a1        ;msgptr in a1 for ReplyMsg call
  181.     ;lea    CustMsg_(BP),a2    ;our msg, did it come back?
  182.     ;cmp.l    a1,a2
  183.     cmp.b    #NT_REPLYMSG,LN_TYPE(a1) ;=NT_REPLYMSG (back from digipaint?)
  184.     beq.s    endsig
  185.     CALLIB    ReplyMsg    ;be polite and reply all unknown msgs
  186.     bra.s    waitonm
  187. endsig:        ;got a 'reply' back from digipaint to 'our' msg
  188.  
  189.     lea    OnlyPort_(BP),a1
  190.     CALLIB    RemPort
  191.  
  192.     lea    OnlyPort_(BP),a1
  193.     moveq    #0,d0    ;Clear upper 3/4 of d0
  194.     move.b    MP_SIGBIT(a1),d0
  195.     beq.s    9$
  196.     CALLIB    FreeSignal
  197. 9$
  198. Boom:
  199.     move.l    BP,a1
  200.     move.l    #((BP_SIZEOF+7)&$ffffFFF8),d0    ;basepage size, roundup 2xlword
  201.     CALLIB    FreeMem
  202.  
  203.     moveq    #0,d0    ;error code?
  204.     rts    ;th-th-th-that's all folks
  205.  
  206. nomem_atall:
  207.     moveq    #103,d0    ;nomem?
  208.     rts
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.     ;ConVertAscii2Integer:
  218.     ;-skips digits after decimal point
  219.     ;-no negative #s, result must be WORD size....64k-1
  220.  
  221. cva2i:    ;a0=point to string, returns d0=#, a0 advanced just past # (DESTROYS D1)
  222.     ;"suitably" commented out to 1) NOT ALLOW NEGATIVE, 2) MAX=64K-1(?)
  223.     move.l    d3,-(sp)
  224.     moveq    #0,d0        ;start with zero
  225.     moveq    #0,d1        ;clear upper bytes
  226.     moveq    #10,d3        ;assume BASE 10
  227.  
  228. cva_findstart:
  229.     move.b    (a0)+,d1    ;get characters from start
  230.     beq    bodyDone
  231.     cmp.b    #$0a,d1
  232.     beq    err_cvaout
  233.     cmp.b    #'.',d1        ;DOT endzittoo
  234.     beq    skipfrac    ;bodyDone    ;boom
  235.     ; cmpi.b    #'0',d1
  236.     ; beq.s    cva_findstart    ;chuck initial zeros
  237.     cmpi.b    #' ',d1
  238.     beq.s    cva_findstart    ;chuck initial blanks
  239.     cmpi.b    #'x',d1        ;check for hex forms
  240.     beq.s    initialHex
  241.     cmpi.b    #'$',d1    
  242.     beq.s    initialHex
  243.     bra.s    cva_ck1st
  244. initialHex:
  245.     move.w    #16,d3        ;show base of 16, preserving minus
  246.  
  247. bodyStr:
  248.     move.b    (a0)+,d1    ;get next character
  249. bodyConvert:
  250.     beq    bodyDone    ;null @ end of string?
  251.     cmp.b    #' ',d1        ;blank endzittoo
  252.     beq    bodyDone
  253.     cmp.b    #'/',d1        ;slash is a delimiter, too
  254.     beq    bodyDone
  255.     cmp.b    #'.',d1        ;DOT endzittoo
  256.     beq.s    skipfrac    ;bodyDone
  257. cva_ck1st:
  258.     cmp.b    #$0d,d1        ;cr?
  259.     beq    bodyDone
  260.     cmp.b    #$0a,d1        ;lf?
  261.     beq.s    bodyDone
  262.     cmp.b    #$09,d1        ;tab?
  263.     beq.s    bodyDone
  264.                 ;prob'ly have a valid digit, shift accum
  265.     mulu    d3,d0        ;result=result*base
  266.     cmpi.b    #'0',d1
  267.     blt.s    badChar
  268.     cmpi.b    #'9',d1
  269.     bgt.s    perhapsHex
  270.     subi.b    #'0',d1
  271.     add.W    d1,d0        ;binary value now, accum.
  272.     bra.s    bodyStr        ;go get another char
  273.  
  274. perhapsHex:
  275.     cmp.w    #16,d3        ;working in hex (base 16) now?
  276.     bne.s    badChar
  277.     cmpi.b    #'A',d1
  278.     blt.s    badChar
  279.     cmpi.b    #'F',d1
  280.     bgt.s    perhapsLCHex
  281.     subi.b    #'A'-10,d1
  282.     add.w    d1,d0
  283.     bra.s    bodyStr
  284.  
  285. perhapsLCHex:
  286.     cmpi.b    #'a',d1
  287.     blt.s    badChar
  288.     cmpi.b    #'f',d1
  289.     bgt.s    badChar
  290.     subi.b    #'a'-10,d1
  291.     add.w    d1,d0        ;binary, accum.
  292.     bra.s    bodyStr
  293.  
  294. badChar:
  295.     tst.l    d0        ;if we already have a #...
  296.     bne.s    enda_cva2i    ;... end on non-# char
  297. err_cvaout:
  298.     moveq    #-1,d0        ;else flag error as minus
  299.     bra.s    enda_cva2i
  300. skipfrac:        ;done scanning, found a 'dot'...skip fract digits
  301.     move.b    (a0)+,d1
  302.     beq.s    bodyDone    ;null @ end of string?
  303.     cmp.b    #' ',d1        ;blank endzittoo
  304.     beq.s    bodyDone
  305.     cmp.b    #'.',d1        ;DOT endzittoo
  306.     beq.s    skipfrac    ;bodyDone
  307.     cmp.b    #$0d,d1        ;cr?
  308.     beq.s    bodyDone
  309.     cmp.b    #$0a,d1        ;lf?
  310.     beq.s    bodyDone
  311.     cmp.b    #$09,d1        ;tab?
  312.     beq.s    bodyDone
  313.     cmp.b    #'/',d1        ;slash ok too
  314.     ;beq.s    bodyDone
  315.     bne.s    skipfrac
  316. bodyDone:
  317. enda_cva2i:
  318.     move.l    (sp)+,d3
  319.     tst.l    d0    ;be nice, test for minus after subr call for errchk
  320.     rts    ;cva2i
  321.  
  322.   END