home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC24Teach / Teach.asm / UWindow.asm < prev   
Encoding:
Assembly Source File  |  1990-05-25  |  27.6 KB  |  1,024 lines  |  [04] ASCII Text (0x0000)

  1. ***********************************************************************
  2. *
  3. * teach uwindow.aii -- Version 3.0 
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * Developer Technical Support Apple II Sample Code
  10. *
  11. * This file contains the code which implements  
  12. * windows in the Teach program.
  13. *
  14. ***********************************************************************
  15.  
  16.                case on
  17.  
  18.                copy 2/ainclude/e16.types
  19.                copy 2/ainclude/e16.gsos
  20.                copy 2/ainclude/e16.resources
  21.                copy 2/ainclude/e16.stdfile
  22.                copy 2/ainclude/e16.textedit
  23.                copy teach.equ
  24.  
  25.                mcopy macros/uwindow.macros
  26.  
  27.                longi on
  28.                longa on
  29.  
  30. ***********************************************************************
  31. *
  32. * smartGetWTitle
  33. *
  34. * This function returns a pointer to the window title pascal string.
  35. * This is a little more complicated than it used to be, given that
  36. * NewWindow2 clones the string for the window into an unlocked handle.
  37. * GetWTitle returns a handle with the hi-bit set (to distinguish it
  38. * from a reguler pointer).  If the hi-bit is set, then we want to
  39. * dereference the handle to a pointer, and return that instead.
  40. *
  41. smartGetWTitle start
  42.  
  43.                DefineStack
  44.  
  45. saveDPage      word
  46. returnAddr     word
  47.  
  48. wptr           long                     ;Parameters.
  49. wtitle         long                     ;Result.
  50.  
  51. ******************
  52.  
  53.                phd                      ;Save directPage register.
  54.                tsc                      ;Set directPage register.
  55.                tcd
  56.  
  57.                pha                      ;Result space.
  58.                pha
  59.                pei wptr+2               ;wtitle is result space
  60.                pei wptr
  61.                _GetWTitle
  62.                pla
  63.                sta wtitle
  64.                pla
  65.                sta wtitle+2
  66.                bpl exit
  67.  
  68.                ldy #2
  69.                lda [wtitle],y
  70.                tax
  71.                lda [wtitle]
  72.                sta wtitle
  73.                stx wtitle+2
  74.  
  75. exit           pld                      ;Restore directPage register.
  76.                plx                      ;Save return address.
  77.                pla                      ;Remove passed parameters.
  78.                pla
  79.                phx                      ;Restore return address and return.
  80.                rts
  81.  
  82.                end
  83.  
  84. ***********************************************************************
  85. *
  86. * drawThisWindow -- called from the tools (via JSL)
  87. *
  88. * This routine draws the contents of all the windows.
  89. *
  90. drawThisWindow start
  91.  
  92.                pha
  93.                pha
  94.                _GetPort
  95.                _DrawControls
  96.                rtl
  97.  
  98.                end
  99.  
  100. ***********************************************************************
  101. *
  102. * doCloseTop
  103. *
  104. * This routine closes the topmost window.
  105. *
  106. doCloseTop     start
  107.  
  108.                pha                      ;GetWRefCon result space
  109.                pha
  110.                pha                      ;FrontWindow result space
  111.                pha
  112.                _FrontWindow
  113.                _GetWRefCon
  114.                lda 1,s
  115.                ora 3,s
  116.                beq null                 ;Stuff on stack will be
  117. *                                       ;result space for FrontWindow
  118.  
  119.                _DisposeHandle           ;Get rid of the pathname handle
  120.                pha                      ;that we keep in the refCon.
  121.                pha                      ;Result space for FrontWindow
  122.  
  123. null           _FrontWindow
  124.                _CloseWindow
  125.  
  126.                rts
  127.  
  128.                end
  129.  
  130. ***********************************************************************
  131. *
  132. * PutFileIntoWindow
  133. *
  134. * This routine opens the specified file, reads its contents in and sets
  135. * the text of the text edit control of the top window to that text.
  136. *
  137. putFileIntoWindow start
  138.  
  139.                DefineStack
  140.  
  141. theHndl        long                     ;Must be at 1,s
  142. c1ptr          long
  143.  
  144. saveDPage      word
  145. returnAddr     word
  146.  
  147. c1hndl         long
  148.  
  149. ******************
  150.  
  151.                phd                      ;Save directPage register.
  152.                pha                      ;Make space for locals.
  153.                pha
  154.                pha
  155.                pha
  156.                tsc                      ;Set directPage register.
  157.                tcd
  158.  
  159.                pei c1hndl+2             ;Lock down the passed handle.
  160.                pei c1hndl
  161.                _HLock
  162.  
  163.                ldy #2                   ;Dereference the handle and skip
  164.                lda [c1hndl],y           ;the C1Output buffer size word.
  165.                tax
  166.                lda [c1hndl]
  167.                clc
  168.                adc #2
  169.                bcc aa
  170.                inx
  171. aa             sta c1ptr
  172.                stx c1ptr+2
  173.  
  174.                sta obpathname           ;Set up the openBlock
  175.                stx obpathname+2
  176.                lda #0
  177.                sta obrequestAccess
  178.                sta obresourceNumber
  179.                sta oboptionList
  180.                sta oboptionList+2
  181.                _OpenGS openBlock        ;Open the file.
  182.                bcc ab
  183.                jsr doErrorWindow
  184.                brl unlockExit
  185.  
  186. ab             lda obrefNum             ;Set up closeBlock.
  187.                sta clbrefNum
  188.                sta rbrefNum
  189.  
  190.                PushLong obeof
  191.                PushWord userID
  192.                lda #0
  193.                pha                      ;0
  194.                pha                      ;NULL
  195.                pha
  196.                _NewHandle               ;Result in theHndl
  197.                bcc ac
  198.                lda #$8E                 ;Not enough ram -- close some windows.
  199.                jsr doErrorWindow
  200.                brl closeUnlockExit
  201.  
  202. ac             pei theHndl+2
  203.                pei theHndl
  204.                _HLock
  205.  
  206.                ldy #2                   ;Dereference handle to get
  207.                lda [theHndl],y          ;the readBlock data buffer.
  208.                sta rbdataBuffer+2
  209.                lda [theHndl]
  210.                sta rbdataBuffer
  211.  
  212.                lda obeof                ;How big the open eof is tells
  213.                ldx obeof+2              ;us how many bytes to request
  214.                sta rbrequestCount       ;for read.
  215.                stx rbrequestCount+2
  216.                _ReadGS readBlock
  217.                bcc ad
  218.                jsr doErrorWindow
  219.                brl disposeCloseUnlockExit
  220.  
  221. ad             _CloseGS closeBlock
  222.                bcc ae
  223.                jsr doErrorWindow
  224.                brl disposeUnlockExit
  225.  
  226. ae             pea refIsHandle*8+teDataIsTextBlock
  227.                pei theHndl+2
  228.                pei theHndl
  229.                lda #0
  230.                pha                      ;NULL
  231.                pha
  232.                pha                      ;0
  233.                pha                      ;NULL
  234.                pha
  235.                pha                      ;GetCtlHandleFromID result space
  236.                pha
  237.                pha                      ;FrontWindow result space
  238.                pha
  239.                _FrontWindow
  240.                PushLong #MainWindowID
  241.                _GetCtlHandleFromID
  242.                _TESetText
  243.  
  244. disposeUnlockExit anop
  245.                pei theHndl+2            ;All done with this handle.
  246.                pei theHndl              ;Dispose it, finish up and leave.
  247.                _DisposeHandle
  248.                bra unlockExit
  249.  
  250. disposeCloseUnlockExit anop
  251.                pei theHndl+2            ;All done with this handle.
  252.                pei theHndl
  253.                _DisposeHandle
  254.  
  255. closeUnlockExit _CloseGS closeBlock     ;Close the file.
  256.  
  257. unlockExit     pei c1hndl+2             ;Unlock handle passed to us.
  258.                pei c1hndl
  259.                _HUnlock
  260.  
  261.                pla                      ;Remove local variable space.
  262.                pla
  263.                pla
  264.                pla
  265.                pld                      ;Restore directPage register.
  266.                plx                      ;Save return address.
  267.                pla                      ;Remove passed parameters.
  268.                pla
  269.                phx                      ;Restore return address and return.
  270.                rts
  271.  
  272. doErrorWindow  pha
  273.                ldx #0
  274.                phx
  275.                phx
  276.                phx
  277.                pha
  278.                _ErrorWindow
  279.                pla
  280.                rts
  281.  
  282. openBlock      ANOP
  283. obpCount       dc i2'15'
  284. obrefNum       dc i2'0'
  285. obpathname     dc i4'0'
  286. obrequestAccess dc i2'0'
  287. obresourceNumber dc i2'0'
  288. obaccess       dc i2'0'
  289. obfileType     dc i2'0'
  290. obauxType      dc i4'0'
  291. obstorageType  dc i2'0'
  292. obcreateDateTime ds 8
  293. obmodDateTime  ds 8
  294. oboptionList   dc i4'0'
  295. obeof          dc i4'0'
  296. obblocksUsed   dc i4'0'
  297. obresourceEOF  dc i4'0'
  298. obresourceBlocks dc i4'0'
  299.  
  300. closeBlock     ANOP
  301. clbpCount      dc i2'1'
  302. clbrefNum      dc i2'0'
  303.  
  304. readBlock      ANOP
  305. rbpCount       dc i2'4'
  306. rbrefNum       dc i2'0'
  307. rbdataBuffer   dc i4'0'
  308. rbrequestCount dc i4'0'
  309. rbtransferCount dc i4'0'
  310.  
  311.                end
  312.  
  313. ***********************************************************************
  314. *
  315. * putWindowIntoFile
  316. *
  317. * This routine opens the specified file, writes the window contents.
  318. *
  319. putWindowIntoFile start
  320.  
  321.                DefineStack
  322.  
  323. theHndl        long                     ;Must be at 1,s
  324. c1ptr          long
  325. totalSize      long
  326.  
  327. saveDPage      word
  328. returnAddr     word
  329.  
  330. c1hndl         long
  331.  
  332. ******************
  333.  
  334.                phd                      ;Save directPage register.
  335.                pha                      ;Make space for locals.
  336.                pha
  337.                pha
  338.                pha
  339.                pha
  340.                pha
  341.                tsc                      ;Set directPage register.
  342.                tcd
  343.  
  344.                pei c1hndl+2             ;Lock down the passed handle.
  345.                pei c1hndl
  346.                _HLock
  347.  
  348.                ldy #2                   ;Dereference the handle and skip
  349.                lda [c1hndl],y           ;the C1Output buffer size word.
  350.                tax
  351.                lda [c1hndl]
  352.                clc
  353.                adc #2
  354.                bcc aa
  355.                inx
  356. aa             sta c1ptr
  357.                stx c1ptr+2
  358.  
  359.                sta dbname               ;Destroy block pathname.
  360.                stx dbname+2
  361.                sta cbpathname           ;Create block pathname.
  362.                stx cbpathname+2
  363.                sta obpathname           ;Open block pathname.
  364.                stx obpathname+2
  365.                _DestroyGS destroyBlock  ;Destroy the file always.
  366.                bcc ab
  367.                cmp #fileNotFound        ;It may have not been there.
  368.                beq ab
  369.                jsr doErrorWindow
  370.                brl unlockExit
  371.  
  372. ab             lda #$C3
  373.                sta cbaccess
  374.                lda #$04
  375.                sta cbfileType
  376.                lda #0
  377.                sta cbauxType
  378.                sta cbauxType+2
  379.                _CreateGS createBlock
  380.                bcc ac
  381.                jsr doErrorWindow
  382.                brl unlockExit
  383.  
  384. ac             lda #0
  385.                sta obrequestAccess
  386.                sta obresourceNumber
  387.                sta oboptionList
  388.                sta oboptionList+2
  389.                _OpenGS openBlock
  390.                bcc ad
  391.                pha                      ;Keep error code.
  392.                _DestroyGS destroyBlock
  393.                pla
  394.                jsr doErrorWindow
  395.                brl unlockExit
  396.  
  397. ad             lda obrefNum
  398.                sta clbrefNum
  399.                sta wbrefNum
  400.  
  401.                PushLong #1
  402.                lda userID
  403.                pha
  404.                lda #0
  405.                pha
  406.                pha
  407.                pha
  408.                _NewHandle               ;Result in theHndl
  409.                bcc ae
  410.                pha                      ;Keep error code.
  411.                _CloseGS closeBlock
  412.                _DestroyGS destroyBlock
  413.                pla
  414.                jsr doErrorWindow
  415.                brl unlockExit
  416.  
  417. ae             pha                      ;Result space
  418.                pha
  419.                pea refIsHandle*8+teDataIsTextBlock
  420.                pei theHndl+2
  421.                pei theHndl
  422.                lda #0
  423.                pha                      ;NULL
  424.                pha
  425.                pha                      ;0
  426.                pha                      ;NULL
  427.                pha
  428.                pha                      ;Result space for GetCtlHandleFromID
  429.                pha
  430.                pha                      ;Result space for FrontWindow
  431.                pha
  432.                _FrontWindow
  433.                PushLong #MainWindowID
  434.                _GetCtlHandleFromID
  435.                _TEGetText
  436.                plx
  437.                stx totalSize
  438.                plx
  439.                stx totalSize+2
  440.                bcc af
  441.                pha
  442.                _CloseGS closeBlock
  443.                _DestroyGS destroyBlock
  444.                pla
  445.                jsr doErrorWindow
  446.                brl disposeUnlockExit
  447.  
  448. af             pei theHndl+2
  449.                pei theHndl
  450.                _HLock
  451.  
  452.                ldy #2
  453.                lda [theHndl],y
  454.                sta wbdataBuffer+2
  455.                lda [theHndl]
  456.                sta wbdataBuffer
  457.                lda totalSize
  458.                ldx totalSize+2
  459.                sta wbrequestCount
  460.                stx wbrequestCount+2
  461.                _WriteGS writeBlock
  462.                bcc ag
  463.                pha
  464.                _CloseGS closeBlock
  465.                _DestroyGS destroyBlock
  466.                pla
  467.                jsr doErrorWindow
  468.                brl disposeUnlockExit
  469.  
  470. ag             _CloseGS closeBlock
  471.                bcc disposeUnlockExit
  472.                pha
  473.                _DestroyGS destroyBlock
  474.                pla
  475.                jsr doErrorWindow
  476.  
  477.  
  478. disposeUnlockExit anop
  479.                pei theHndl+2
  480.                pei theHndl
  481.                _DisposeHandle
  482.  
  483. unlockExit     pei c1hndl+2
  484.                pei c1hndl
  485.                _HUnlock
  486.  
  487.                pla                      ;Remove local variable space.
  488.                pla
  489.                pla
  490.                pla
  491.                pla
  492.                pla
  493.                pld                      ;Restore directPage register.
  494.                plx                      ;Save return address.
  495.                pla                      ;Remove passed parameters.
  496.                pla
  497.                phx                      ;Restore return address and return.
  498.                rts
  499.  
  500.  
  501. doErrorWindow  pha
  502.                ldx #0
  503.                phx
  504.                phx
  505.                phx
  506.                pha
  507.                _ErrorWindow
  508.                pla
  509.                rts
  510.  
  511.  
  512. destroyBlock   ANOP
  513. dbpCount       dc i2'1'
  514. dbname         dc i4'0'
  515.  
  516. createBlock    ANOP
  517. cbpCount       dc i2'4'
  518. cbpathname     dc i4'0'
  519. cbaccess       dc i2'0'
  520. cbfileType     dc i2'0'
  521. cbauxType      dc i4'0'
  522.  
  523. openBlock      ANOP
  524. obpCount       dc i2'15'
  525. obrefNum       dc i2'0'
  526. obpathname     dc i4'0'
  527. obrequestAccess dc i2'0'
  528. obresourceNumber dc i2'0'
  529. obaccess       dc i2'0'
  530. obfileType     dc i2'0'
  531. obauxType      dc i4'0'
  532. obstorageType  dc i2'0'
  533. obcreateDateTime ds 8
  534. obmodDateTime  ds 8
  535. oboptionList   dc i4'0'
  536. obeof          dc i4'0'
  537. obblocksUsed   dc i4'0'
  538. obresourceEOF  dc i4'0'
  539. obresourceBlocks dc i4'0'
  540.  
  541. closeBlock     ANOP
  542. clbpCount      dc i2'1'
  543. clbrefNum      dc i2'0'
  544.  
  545. writeBlock     ANOP
  546. wbpCount       dc i2'4'
  547. wbrefNum       dc i2'0'
  548. wbdataBuffer   dc i4'0'
  549. wbrequestCount dc i4'0'
  550. wbtransferCount dc i4'0'
  551.  
  552.                end
  553.  
  554. ***********************************************************************
  555. *
  556. * placeAndShowWindow
  557. *
  558. * This routine moves the specified window based on stagger count
  559. * and shows it.
  560. *
  561. placeAndShowWindow start
  562.  
  563.                DefineStack
  564.  
  565. saveDPage      word
  566. returnAddr     word
  567.  
  568. wptr           long
  569.  
  570. ******************
  571.  
  572.                phd                      ;Save directPage register.
  573.                tsc                      ;Set directPage register.
  574.                tcd
  575.  
  576.                lda staggerCount
  577.                asl a
  578.                asl a
  579.                asl a
  580.                adc #8
  581.                pha
  582.                adc #20
  583.                pha
  584.                pei wptr+2
  585.                pei wptr
  586.                _MoveWindow
  587.  
  588.                lda staggerCount
  589.                inc a
  590.                and #$07
  591.                sta staggerCount
  592.  
  593.                pei wptr+2
  594.                pei wptr
  595.                _ShowWindow
  596.                pei wptr+2
  597.                pei wptr
  598.                _SelectWindow
  599.  
  600.                pld                      ;Restore directPage register.
  601.                plx                      ;Save return address.
  602.                pla                      ;Remove passed parameters.
  603.                pla
  604.                phx                      ;Restore return address and return.
  605.                rts
  606.  
  607.                end
  608.  
  609. ***********************************************************************
  610. *
  611. * doOpenWindow
  612. *
  613. * This routine either asks the user what file to open and opens it.
  614. *
  615. doOpenWindow   start
  616.  
  617.                DefineStack
  618.  
  619. wptr           long                     ;Must be at 1,s
  620. myReply        block oReplyRec2size
  621. pstr           long
  622.  
  623. stkFrameSize   EndLocals
  624.  
  625. saveDPage      word
  626. returnAddr     word
  627.  
  628. ******************
  629.  
  630.                phd                      ;Save directPage register.
  631.                tsc
  632.                sec
  633.                sbc #stkFrameSize        ;Make space for locals.
  634.                tcs
  635.                tcd                      ;Set directPage register.
  636.  
  637.                pea 1
  638.                _SFAllCaps
  639.  
  640.                lda #refIsNewHandle
  641.                sta myReply+onameRefDesc
  642.                sta myReply+opathRefDesc
  643.  
  644.                tsc                      ;Calculate pointer to myReply.
  645.                clc
  646.                adc #myReply
  647.                tax
  648.                pea 10
  649.                pea 35
  650.                pea refIsPointer
  651.                PushLong #promptStr
  652.                lda #0
  653.                pha                      ;NULL
  654.                pha
  655.                pha                      ;NULL
  656.                pha
  657.                pha                      ;Pointer to myReply
  658.                phx
  659.                _SFGetFile2
  660.                lda myReply+ogood
  661.                beq exit
  662.  
  663.                pei myReply+onameRef+2
  664.                pei myReply+onameRef
  665.                _HLock
  666.  
  667.                ldy #2
  668.                lda [myReply+onameRef],y
  669.                tax
  670.                lda [myReply+onameRef]
  671.                sta pstr
  672.                stx pstr+2
  673.                shortm
  674.                lda [pstr],y             ;2 in yreg.
  675.                iny
  676.                sta [pstr],y
  677.                longm
  678.                tya                      ;3 in yreg.
  679.                clc
  680.                adc pstr
  681.                bcc aa
  682.                inx
  683.  
  684. aa             phx                      ;Pointer to window title.
  685.                pha
  686.                pei myReply+opathRef+2
  687.                pei myReply+opathRef
  688.                PushLong #drawThisWindow
  689.                lda #0
  690.                pha
  691.                pha
  692.                pea refIsResource
  693.                PushLong #MainWindowID
  694.                pea rWindParam1
  695.                _NewWindow2
  696.  
  697.                pei myReply+onameRef+2
  698.                pei myReply+onameRef
  699.                _DisposeHandle
  700.  
  701.                pei wptr+2
  702.                pei wptr
  703.                jsr placeAndShowWindow
  704.  
  705.                pei myReply+opathRef+2
  706.                pei myReply+opathRef
  707.                jsr putFileIntoWindow
  708.  
  709. exit           tsc                      ;Remove local space.
  710.                clc
  711.                adc #stkFrameSize
  712.                tcs
  713.                pld                      ;Restore directPage register.
  714.                rts
  715.  
  716. promptStr      str 'Pick a file, any file.'
  717.  
  718.                end
  719.  
  720. ***********************************************************************
  721. *
  722. * doSaveAs
  723. *
  724. * This routine either saves the file in the place indicated by the user.
  725. *
  726. doSaveAs       start
  727.  
  728.                DefineStack
  729.  
  730. myReply        block oReplyRec2size
  731. wtitle         long
  732. pstr           long
  733. wtptr          long
  734. wthndl         long
  735. wtlen          word
  736. refCon         long
  737.  
  738. stkFrameSize   EndLocals
  739.  
  740. saveDPage      word
  741. returnAddr     word
  742.  
  743. ******************
  744.  
  745.                phd                      ;Save directPage register.
  746.                tsc
  747.                sec
  748.                sbc #stkFrameSize        ;Make space for locals.
  749.                tcs
  750.                tcd                      ;Set directPage register.
  751.  
  752.                pea 1
  753.                _SFAllCaps
  754.  
  755.                lda #refIsNewHandle
  756.                sta myReply+onameRefDesc
  757.                sta myReply+opathRefDesc
  758.  
  759.                pha                      ;Point to the window title.
  760.                pha
  761.                pha
  762.                pha
  763.                _FrontWindow
  764.                jsr smartGetWTitle
  765.                pla
  766.                sta wtitle
  767.                pla
  768.                sta wtitle+2
  769.  
  770.                lda [wtitle]             ;How long is the title?
  771.                and #$FF
  772.                sta wtlen
  773.  
  774.                pha                      ;Create a handle for the title
  775.                pha                      ;that will be big enough for
  776.                pea 0                    ;the text and a word length.
  777.                lda wtlen
  778.                clc
  779.                adc #2
  780.                pha
  781.                lda userID
  782.                pha
  783.                lda #0
  784.                pha
  785.                pha
  786.                pha
  787.                _NewHandle
  788.                pla
  789.                sta wthndl
  790.                pla
  791.                sta wthndl+2
  792.                bcc aa
  793.  
  794. aa             ldy #2                   ;Point to this handle.
  795.                lda [wthndl],y
  796.                sta wtptr+2
  797.                lda [wthndl]
  798.                sta wtptr
  799.  
  800.                pha                      ;Re-dereference the window
  801.                pha                      ;title pointer, since it may
  802.                pha                      ;be stored in a handle, and the
  803.                pha                      ;handle may have moved.
  804.                _FrontWindow
  805.                jsr smartGetWTitle
  806.                pla
  807.                sta wtitle
  808.                pla
  809.                sta wtitle+2
  810.  
  811.                lda wtitle               ;Point to the title, skipping the
  812.                ldx wtitle+2             ;length byte.
  813.                inc a
  814.                bne ab
  815.                inx
  816. ab             phx
  817.                pha
  818.                lda wtptr                ;Point to the handle created to
  819.                ldx wtptr+2              ;hold the title, skipping the
  820.                clc                      ;length word.
  821.                adc #2
  822.                bcc ac
  823.                inx
  824. ac             phx
  825.                pha
  826.                pea 0                    ;Push the number of bytes to copy.
  827.                pei wtlen
  828.                _BlockMove
  829.  
  830.                lda wtlen                ;Store the length word in the
  831.                sta [wtptr]              ;beginning of the handle.
  832.  
  833.                pei wthndl+2             ;Lock the handle, since SFPutFile2
  834.                pei wthndl               ;may move things around.
  835.                _HLock
  836.  
  837.                tsc                      ;Calculate pointer to myReply.
  838.                clc
  839.                adc #myReply
  840.                tax
  841.                pea 180
  842.                pea 35
  843.                pea refIsPointer
  844.                PushLong #promptPtr
  845.                pea refIsPointer
  846.                pei wtptr+2
  847.                pei wtptr
  848.                pea 0                    ;Pointer to myReply.
  849.                phx
  850.                _SFPutFile2
  851.  
  852.                pei wthndl+2             ;We are done with the window title.
  853.                pei wthndl
  854.                _DisposeHandle
  855.  
  856.                lda myReply+ogood        ;See if the user clicked cancel.
  857.                beq exit
  858.  
  859.                pha                      ;We may have a handle in the refCon.
  860.                pha                      ;If we do, then we need to dispose it.
  861.                pha
  862.                pha
  863.                _FrontWindow
  864.                _GetWRefCon
  865.                pla
  866.                sta refCon
  867.                pla
  868.                sta refCon+2
  869.                ora refCon
  870.                beq ad
  871.                pei refCon+2
  872.                pei refCon
  873.                _DisposeHandle
  874.  
  875. ad             pei myReply+opathRef+2   ;This is the new handle for
  876.                pei myReply+opathRef     ;the refCon.
  877.                pha
  878.                pha
  879.                _FrontWindow
  880.                _SetWRefCon
  881.  
  882.                ldy #2                   ;We have a handle that is a
  883.                lda [myReply+onameRef],y ;C1Output string.  We want this
  884.                tax                      ;to be a pascal string.  This
  885.                lda [myReply+onameRef]   ;is accomplished by moving byte
  886.                sta pstr                 ;2 to byte 3, and then pointing
  887.                stx pstr+2               ;3 bytes into the handle.
  888.                shortm
  889.                lda [pstr],y             ;2 in yreg.
  890.                iny
  891.                sta [pstr],y
  892.                longm
  893.                tya
  894.                clc
  895.                adc pstr                 ;3 in yreg.
  896.                bcc ae
  897.                inx
  898. ae             phx
  899.                pha
  900.                pha
  901.                pha
  902.                _FrontWindow
  903.                _SetWTitle
  904.  
  905.                pei myReply+onameRef+2   ;We are done with the name now.
  906.                pei myReply+onameRef
  907.                _DisposeHandle
  908.  
  909.                pei myReply+opathRef+2
  910.                pei myReply+opathRef
  911.                jsr putWindowIntoFile
  912.  
  913. exit           tsc                      ;Remove local space.
  914.                clc
  915.                adc #stkFrameSize
  916.                tcs
  917.                pld                      ;Restore directPage register.
  918.                rts
  919.  
  920. promptPtr      str 'Give it a name, any name.'
  921.  
  922.                end
  923.  
  924. ***********************************************************************
  925. *
  926. * doSave
  927. *
  928. * This routine either saves the file (unless it is new then it does a save 
  929. * as).
  930. *
  931. doSave         start
  932.  
  933.                DefineStack
  934.  
  935. wptr           long                     ;Must be at 1,s
  936. refCon         long
  937.  
  938. saveDPage      word
  939. returnAddr     word
  940.  
  941. ******************
  942.  
  943.                phd                      ;Save directPage register.
  944.                pha                      ;Make space for locals.
  945.                pha
  946.                pha
  947.                pha
  948.                tsc                      ;Set directPage register.
  949.                tcd
  950.  
  951.                _FrontWindow             ;Get the refCon.
  952.                pha
  953.                pha
  954.                pei wptr+2
  955.                pei wptr
  956.                _GetWRefCon
  957.                pla
  958.                sta refCon
  959.                pla
  960.                sta refCon+2
  961.                ora refCon               ;If the refCon is not NULL, then
  962.                bne aa                   ;we already have a name for this file.
  963.                jsr doSaveAs             ;We don't have a name yet, so do
  964.                bra exit                 ;a save as.
  965.  
  966. aa             pei refCon+2             ;We have a name, so go for it.
  967.                pei refCon
  968.                jsr putWindowIntoFile
  969.  
  970. exit           plx
  971.                pla                      ;Remove local space
  972.                pla
  973.                pla
  974.                pla
  975.                pld                      ;Restore directPage register.
  976.                phx
  977.                rts
  978.  
  979.                end
  980.  
  981. ***********************************************************************
  982. *
  983. * NewWindow
  984. *
  985. * This routine opens a new untitled window.
  986. *
  987. doNewWindow    start
  988.  
  989.                pha                      ;Result space
  990.                pha
  991.                PushLong #promptPtr      ;Window title
  992.                ldx #0
  993.                phx                      ;NULL
  994.                phx
  995.                PushLong #drawThisWindow
  996.                phx                      ;NULL
  997.                phx
  998.                pea refIsResource
  999.                PushLong #MainWindowID
  1000.                pea rWindParam1
  1001.                _NewWindow2
  1002.  
  1003.                jsr placeAndShowWindow   ;Uses above result space
  1004.                rts
  1005.  
  1006. promptPtr      str 'Untitled'
  1007.  
  1008.                end
  1009.  
  1010. ***********************************************************************
  1011. *
  1012. * SetUpWindows
  1013. *
  1014. * Sets up WindowList record for use through out the program.
  1015. *
  1016. setupWindows   start
  1017.  
  1018.                jsr doNewWindow
  1019.                rts
  1020.  
  1021.                end
  1022.  
  1023.                END
  1024.