home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / lib / asm / scrwin.s < prev    next >
Encoding:
Text File  |  1998-10-04  |  17.8 KB  |  929 lines

  1. ;
  2. ; scrwin.s -- an ACE linked library module: screen and window functions.
  3. ; Copyright (C) 1998 David Benn
  4. ; This program is free software; you can redistribute it and/or
  5. ; modify it under the terms of the GNU General Public License
  6. ; as published by the Free Software Foundation; either version 2
  7. ; of the License, or (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. ;
  18. ; Author: David J Benn
  19. ;   Date: 3rd-30th November, 1st-13th December 1991,
  20. ;      20th, 23rd,25th-27th January 1992, 
  21. ;         2nd,4th,6th,12th-19th,21st-24th,29th February 1992,
  22. ;      1st,14th March 1992,
  23. ;      4th,7th,21st,22nd,26th April 1992,
  24. ;      2nd,3rd,5th,7th,8th,10th-17th May 1992,
  25. ;      6th,8th,11th,12th,28th,30th June 1992,
  26. ;      1st-3rd,13th,14th,18th-20th,22nd July 1992,
  27. ;      9th August 1992,
  28. ;      5th,12th,13th,19th December 1992,
  29. ;      18th February 1993,
  30. ;      1st March 1993,
  31. ;      6th,12th June 1993,
  32. ;      9th,10th,24th-26th,29th,31st October 1993,
  33. ;      1st November 1993,
  34. ;      25th December 1993,
  35. ;      16th February 1994,
  36. ;      6th,7th,19th March 1994,
  37. ;      12th,25th,28th July 1994,
  38. ;      10th,28th August 1994,
  39. ;      11th September 1994
  40. ;
  41. ; registers d0-d6 and a0-a3 are modified by some of the following. BEWARE!
  42. ;
  43. ; a4,a5 are used by link/unlk.
  44. ; a6 is library base holder.
  45. ; a7 is stack pointer. 
  46. ; d7 is used for array index calculations.
  47. ;
  48.  
  49. ; * CONSTANTS *
  50. MAXSTRINGSIZE     equ 1024
  51. Width        equ 8
  52. Height        equ 10
  53. cp_x        equ 36
  54. cp_y        equ 38
  55. BitMap        equ 184
  56. Depth        equ 5
  57. Font        equ 52
  58. tf_YSize    equ 20
  59. tf_XSize    equ 24
  60. lib_Version    equ 20
  61. CTRL_C_BREAK    equ 4096
  62. VANILLAKEY    equ $00200000
  63. UserPort    equ 86
  64.  
  65. Class        equ 0        ; member of IntuiInfo structure
  66. Code        equ 4        ; member of IntuiInfo structure
  67.                 ; (see intuievent.h)
  68.  
  69. SCREEN_OPEN_ERR equ 600
  70.  
  71.  
  72.     ; window & screen routines
  73.     xdef    _openscreen
  74.     xdef    _closescreen
  75.     xdef    _change_screen_depth
  76.     xdef    _changetextcolor
  77.     xdef    _palette
  78.     xdef    _shortprints
  79.     xdef    _longprints
  80.     xdef    _singleprints
  81.     xdef    _stringprints
  82.     xdef    _horiz_tab
  83.     xdef    _printsLF
  84.     xdef    _printsTAB
  85.     xdef    _printsSPC
  86.     xdef    _cls
  87.     xdef    _ptab
  88.     xdef    _ctrl_c_test
  89.  
  90.        ; external references
  91.     xref    _locate
  92.     xref    _scroll_screen
  93.     xref    _slash
  94.     xref    _radconv
  95.     xref    _longtemp
  96.     xref    _formfeed
  97.     xref    _forcebgndcolr
  98.     xref    _textcolr
  99.     xref    _raw
  100.     xref    _Wdw_width_list
  101.     xref    _Wdw_height_list
  102.     xref    _fgdpen_list
  103.     xref    _bgpen_list
  104.     xref    _Wdw_list
  105.     xref    _RPort_list
  106.     xref    _stdout_list
  107.     xref    _stdin_list
  108.     xref    _mode_oldfile
  109.     xref    _ScreenWdw
  110.     xref    _ScreenRPort
  111.     xref    _ScreenViewPort
  112.     xref    _Screen_list
  113.     xref    _newscreen
  114.     xref    _newwindow
  115.     xref    _horiz_tabstring
  116.     xref    _NULL_string
  117.  
  118.     xref    _x1
  119.     xref    _x2
  120.     xref    _y1
  121.     xref    _y2
  122.     xref    _titleaddr
  123.     xref    _tempstr
  124.     xref    _rawname
  125.     xref    _tempWdw_id
  126.     xref    _screen_id
  127.     xref    _rport_addr
  128.     xref    _viewport_addr
  129.     xref    _screen_addr
  130.     xref    _scr_wdw_addr
  131.     xref    _color_id
  132.     xref    _red
  133.     xref    _green
  134.     xref    _blue
  135.     xref    _strbuf
  136.     xref    _max_line
  137.     xref    _font_height
  138.     xref    _wdth
  139.     xref    _hgt
  140.     xref    _horiz_pos
  141.     
  142.     xref    _putchar
  143.     xref    _sprintf
  144.     xref    _strcpy    
  145.     xref    _strcat
  146.     xref    _strlen
  147.     xref    _strshort
  148.     xref    _strlong
  149.     xref    _strsingle
  150.     xref    _IntuitionBase
  151.      xref      _stdout
  152.     xref    _stdin
  153.     xref     _AbsExecBase
  154.     xref    _LVOSetSignal
  155.     xref    _GfxBase
  156.     xref    _LVOMove
  157.     xref    _LVOText
  158.     xref    _LVOSetAPen
  159.     xref    _LVOSetRGB4
  160.     xref    _LVOClearScreen
  161.     xref    _LVOScrollRaster
  162.     xref    _LVOOpenScreen
  163.     xref    _LVOCloseScreen
  164.     xref    _LVOOpenWindow
  165.     xref    _LVOCloseWindow
  166.     xref    _LVOScreenToFront
  167.     xref    _LVOScreenToBack
  168.     xref    _DOSBase
  169.     xref    _LVOWrite
  170.     xref    _LVOOpen
  171.     xref    _LVOClose
  172.     xref    _MathBase
  173.     xref    _MathTransBase
  174.     xref    _LVOSPFix
  175.     xref    _LVOSPMul
  176.     xref    _RPort
  177.     xref    _ViewPort
  178.     xref    _Scrn
  179.     xref    _Wdw
  180.     xref    _Wdw_width
  181.     xref    _Wdw_height
  182.     xref    _Wdw_id
  183.     xref    _WBWdw
  184.     xref    _WBRPort
  185.     xref    _WBViewPort
  186.     xref    _WBScrn
  187.     xref    _WBbgpen
  188.     xref    _WBfgdpen
  189.     xref    _IntuiMode
  190.     xref    _fgdpen
  191.     xref    _bgpen
  192.     xref    _tg_initx
  193.     xref    _tg_tx
  194.     xref    _tg_inity
  195.     xref    _tg_ty
  196.     xref    _tg_degs
  197.     xref    _tg_pen
  198.     xref    _tg_xy_ratio
  199.     xref    _cursorON
  200.     xref    _turncursoron
  201.     xref    _turncursoroff
  202.     xref    _pos
  203.     xref    _csrlin
  204.     xref    _last_IDCMP_event
  205.     xref    _only_shell_is_active
  206.     xref    _check_for_open_window
  207.     xref    _GetIntuiEvent
  208.     xref    _ClearIntuiEvent
  209.  
  210.     xref    _error_code
  211.  
  212.     SECTION scrwin_code,CODE
  213.  
  214. ;
  215. ; PTAB(n) - moves to nth pixel position in current output window.
  216. ;      - d0 = n = x-position.
  217. ;
  218. _ptab:
  219.     movea.l    _GfxBase,a6
  220.     movea.l    _RPort,a1
  221.     move.w    cp_y(a1),d1
  222.     jsr    _LVOMove(a6)
  223.         
  224.     lea    _NULL_string,a0        ; dummy string
  225.  
  226.     rts
  227.     
  228. ;
  229. ; TAB(n) - moves cursor to nth column in current output window.
  230. ;     - d0 = # of columns to move right. Control string returned in a0
  231. ;       for use by _printstring. This is the NULL string if we're in
  232. ;       IntuiMode since a LOCATE is performed.
  233. ;
  234. _horiz_tab:
  235.         subi.w    #1,d0            ; shift back 1 column
  236.     move.w    d0,_horiz_pos        ; store it
  237.  
  238.        ; make sure not too high
  239.     cmpi.w    #80,d0
  240.     ble.s    _tab_mode
  241.     move.w    #80,d0            ; columns > 80 so columns=80 
  242.     move.w    d0,_horiz_pos
  243.  
  244. _tab_mode:
  245.     ; are we in IntuiMode?
  246.     cmpi.b    #1,_IntuiMode
  247.     bne.s    _get_tab_digits        ; NO -> DOS window TAB
  248.     
  249.     ; YES -> re-LOCATE to nth column on current line
  250.     addi.w    #1,_horiz_pos        ; adjust for screen/window
  251.  
  252.     cmpi.w    #0,_horiz_pos
  253.     blt.s    _exit_intuitab        ; do nothing more if column<=0
  254.  
  255.     jsr    _csrlin
  256.     move.w    _horiz_pos,d1
  257.     jsr    _locate
  258.  
  259. _exit_intuitab:
  260.     lea    _NULL_string,a0
  261.     
  262.     rts
  263.  
  264. _get_tab_digits:
  265.     ; convert column value to 2 ASCII digits and place in tab string
  266.     ext.l    d0
  267.     divu    #10,d0
  268.     move.l    d0,_longtemp
  269.     lea    _horiz_tabstring,a0
  270.     add.w    #48,d0
  271.     and.b    #$ff,d0
  272.     move.b    d0,1(a0)
  273.     move.l    _longtemp,d0
  274.     swap    d0
  275.     add.w    #48,d0
  276.     and.b    #$ff,d0
  277.     move.b    d0,2(a0)
  278.  
  279.     ; move print position to leftmost column
  280.     move.l    #13,-(sp)        ; CR
  281.     jsr    _putchar
  282.     addq    #4,sp
  283.  
  284.     cmpi.w    #0,_horiz_pos
  285.     ble.s    _quit_horiz_tab        ; do nothing more if column<=0
  286.         
  287.     lea    _horiz_tabstring,a0    ; control string to be printed  
  288.  
  289. _quit_horiz_tab:
  290.     rts
  291.  
  292. ;
  293. ; CLS - clear the screen (window).
  294. ;
  295. _cls:
  296.     ; check whether in Screen Mode
  297.     cmpi.b    #0,_IntuiMode
  298.     beq.s    _wbscreencls    
  299.  
  300.     ; clear a user-defined intuition window
  301.     movea.l    _GfxBase,a6
  302.     move.l    _RPort,a1
  303.     move.w    #0,d0
  304.     move.w    #0,d1
  305.     jsr    _LVOMove(a6)
  306.  
  307.     move.l    _RPort,a1
  308.     jsr    _LVOClearScreen(a6)
  309.     
  310.     move.w    #1,d0    
  311.     move.w    #1,d1
  312.     jsr    _locate
  313.  
  314.     rts
  315.  
  316. _wbscreencls:
  317.     ; first set the background colour 
  318.     ; (only necessary under 2.04)
  319.  
  320.     ; check version (ExecBase->LibNode.lib_Version)
  321.     movea.l    _AbsExecBase,a0
  322.     move.w    lib_Version(a0),d0
  323.     cmpi.w    #34,d0
  324.     ble.s    _justclearscreen    ; if Exec version <= 34, just do CLS
  325.  
  326.     lea    _forcebgndcolr,a0
  327.     move.w    _bgpen,d0
  328.     addi.b    #48,d0
  329.     move.b    d0,2(a0)        ; modify the CSI>[n]m string
  330.  
  331.     move.l    _DOSBase,a6
  332.     move.l    _stdout,d1
  333.     move.l    #_forcebgndcolr,d2    ; force background colour to change
  334.     move.l    #4,d3
  335.     jsr    _LVOWrite(a6)
  336.  
  337. _justclearscreen:    
  338.     ; now clear the window!
  339.     move.l    _DOSBase,a6
  340.     move.l    _stdout,d1
  341.     move.l    #_formfeed,d2        ; form feed = CLS
  342.     move.l    #1,d3
  343.     jsr    _LVOWrite(a6)
  344.  
  345.     rts
  346.  
  347. ;
  348. ; change color of text foreground and background (d0=fgnd, d1=bgnd).
  349. ;
  350. _changetextcolor:
  351.     ; only do it if in a window!
  352.     cmpi.b    #1,_IntuiMode
  353.     beq.s    _exitchangetextcolor
  354.  
  355.     ; convert colors to ASCII
  356.     add.w    #48,d0
  357.     add.w    #48,d1
  358.     
  359.     ; change the color command string
  360.     lea    _textcolr,a0
  361.     move.b    d0,4(a0)
  362.     move.b    d1,7(a0)
  363.  
  364.     ; apply the text colors
  365.     move.l    _DOSBase,a6
  366.     move.l    _stdout,d1
  367.     move.l    #_textcolr,d2
  368.     move.l    #9,d3
  369.     jsr    _LVOWrite(a6)
  370.  
  371. _exitchangetextcolor:
  372.     rts
  373.  
  374. ;
  375. ; turn cursor ON (after printing).
  376. ;
  377. _turncursoron:
  378.     move.l    _stdout,d1
  379.     move.l    #_cursorON,d2
  380.     moveq    #3,d3
  381.     move.l    _DOSBase,a6
  382.     jsr    _LVOWrite(a6)
  383.     rts
  384.  
  385. ;
  386. ; open a screen - d0=screen-id,d1=width,d2=height,d3=depth,d4=mode.
  387. ;
  388. _openscreen:
  389.     ; store screen-id
  390.     move.w    d0,_screen_id
  391.  
  392.     ; check parameters
  393.     cmpi.w    #1,d0        ; screen-id < 1?
  394.     blt    _quitopenscreen
  395.     cmpi.w    #9,d0        ; screen-id > 9?
  396.     bgt    _quitopenscreen
  397.  
  398.     cmpi.w    #1,d1        ; width < 1?
  399.     blt    _quitopenscreen
  400.     cmpi.w    #640,d1        ; width > 640?
  401.     bgt    _quitopenscreen
  402.  
  403.     cmpi.w    #1,d2        ; height < 1?
  404.     blt    _quitopenscreen
  405.     cmpi.w    #512,d2        ; height > 512?     * this is arbitrarily large! *
  406.     bgt    _quitopenscreen
  407.  
  408.     cmpi.w    #1,d3        ; depth < 1?
  409.     blt    _quitopenscreen
  410.     cmpi.w    #6,d3        ; depth > 6?
  411.     bgt    _quitopenscreen
  412.  
  413.     cmpi.w    #1,d4        ; mode < 1?
  414.     blt    _quitopenscreen
  415.     cmpi.w    #6,d4        ; mode > 6?
  416.     bgt    _quitopenscreen
  417.  
  418.     ; calculate place in screen lists
  419.     move.w    _screen_id,d0
  420.     mulu    #4,d0        ; offset from start of screen lists
  421.  
  422.     move.l    #_ScreenWdw,d5
  423.     add.l    d0,d5
  424.     move.l    d5,_scr_wdw_addr
  425.  
  426.     move.l    #_ScreenRPort,d5
  427.     add.l    d0,d5
  428.     move.l    d5,_rport_addr
  429.  
  430.     move.l    #_ScreenViewPort,d5
  431.     add.l    d0,d5
  432.     move.l    d5,_viewport_addr
  433.  
  434.     move.l    #_Screen_list,d5
  435.     add.l    d0,d5
  436.     move.l    d5,_screen_addr
  437.         
  438.     ; is this screen-id being used?
  439.     movea.l    _screen_addr,a0
  440.     move.l    (a0),d0
  441.     cmpi.l    #0,d0
  442.     bne    _quitopenscreen    ; if not ZERO -> quit!
  443.  
  444.     ; complete NewScreen and NewWindow structures.    
  445.  
  446.     lea    _newwindow,a0
  447.     move.w    d1,4(a0)    ; width
  448.     move.w    d2,6(a0)    ; height
  449.  
  450.     lea    _newscreen,a0
  451.     move.w    d1,4(a0)    ; width
  452.     move.w    d2,6(a0)    ; height
  453.     move.w    d3,8(a0)    ; depth
  454.     
  455.     ; screen mode
  456.     cmpi.w    #1,d4
  457.     bne.s    _hires1
  458.     move.w    #0,12(a0)        ; lo-res
  459.     move.l    #$f0000140,_tg_xy_ratio    ; ratio = 0.9375
  460.     bra.s    _openthescreen
  461. _hires1:
  462.     cmpi.w    #2,d4
  463.     bne.s    _lores2
  464.     move.w    #$8000,12(a0)        ; hi-res
  465.     move.l    #$f0000141,_tg_xy_ratio    ; ratio = 1.875
  466.     bra.s    _openthescreen
  467. _lores2:
  468.     cmpi.w    #3,d4
  469.     bne.s    _hires2
  470.     move.w    #4,12(a0)        ; lo-res, interlaced
  471.     move.l    #$f000013f,_tg_xy_ratio    ; ratio = 0.46875
  472.     bra.s    _openthescreen    
  473. _hires2:
  474.     cmpi.w    #4,d4
  475.     bne.s    _ham
  476.     move.w    #$8004,12(a0)        ; hi-res, interlaced
  477.     move.l    #$f0000140,_tg_xy_ratio    ; ratio = 0.9375
  478.     bra.s    _openthescreen
  479. _ham:
  480.     cmpi.w    #5,d4
  481.     bne.s    _halfbrite
  482.     move.w    #$800,12(a0)        ; hold-and-modify
  483.     move.l    #$f0000140,_tg_xy_ratio    ; ratio = 0.9375
  484.     bra.s    _openthescreen
  485. _halfbrite:
  486.     move.w    #$80,12(a0)        ; extra-halfbrite
  487.     move.l    #$f0000140,_tg_xy_ratio    ; ratio = 0.9375
  488.     
  489. _openthescreen:
  490.     ; open the screen
  491.     movea.l    _IntuitionBase,a6
  492.     lea    _newscreen,a0
  493.     jsr    _LVOOpenScreen(a6)
  494.     move.l    d0,_Scrn
  495.     cmpi.l    #0,d0
  496.     beq    _quitopenscreen    ; quit if can't open screen!
  497.     
  498.     ; open a borderless window 
  499.     movea.l    _IntuitionBase,a6
  500.     lea    _newwindow,a0
  501.     move.l    _Scrn,30(a0)    ; link to screen just opened
  502.     jsr    _LVOOpenWindow(a6)
  503.     move.l    d0,_Wdw
  504.     cmpi.l    #0,d0
  505.     beq    _quitopenscreen    ; quit if can't open window!
  506.     
  507.     ; update lists and set screen mode
  508.     move.b    #1,_IntuiMode
  509.  
  510.     ; store screen
  511.     movea.l    _screen_addr,a0
  512.     move.l    _Scrn,(a0)
  513.     
  514.     ; store window
  515.     movea.l    _scr_wdw_addr,a0
  516.     move.l    _Wdw,(a0)
  517.  
  518.     movea.l    _rport_addr,a0
  519.     movea.l    _Wdw,a1
  520.     move.l    50(a1),(a0)
  521.     move.l    50(a1),_RPort
  522.     
  523.     ; store viewport
  524.     movea.l    _viewport_addr,a0
  525.     move.l    _Scrn,d0
  526.     add.l    #44,d0
  527.     move.l    d0,(a0)
  528.     move.l    d0,_ViewPort
  529.  
  530.     ; set first PRINT position in screen's default window
  531.     moveq    #3,d0
  532.     moveq    #1,d1
  533.     jsr    _locate
  534.  
  535.     ; set foreground pen in window
  536.     movea.l    _GfxBase,a6
  537.     movea.l    _RPort,a1
  538.     moveq    #1,d0
  539.     jsr    _LVOSetAPen(a6)
  540.     
  541.     rts        
  542.  
  543. _quitopenscreen:    
  544.     move.l    #SCREEN_OPEN_ERR,_error_code    ; !! ERROR !!
  545.     rts
  546.  
  547. ;
  548. ; close a screen - d0=screen-id.
  549. ;
  550. _closescreen:
  551.     ; store screen-id
  552.     move.w    d0,_screen_id
  553.  
  554.     ; check parameters
  555.     cmpi.w    #1,d0        ; screen-id < 1?
  556.     blt    _quitclosescreen
  557.     cmpi.w    #9,d0        ; screen-id > 9?
  558.     bgt    _quitclosescreen
  559.  
  560.     ; calculate place in screen lists
  561.     move.w    _screen_id,d0
  562.     mulu    #4,d0        ; offset from start of screen lists
  563.  
  564.     move.l    #_Screen_list,d5
  565.     add.l    d0,d5
  566.     movea.l    d5,a0
  567.  
  568.     ; is screen-id being used?
  569.     move.l    (a0),d0
  570.     cmpi.l    #0,d0
  571.     beq    _quitclosescreen    ; if ZERO -> quit!
  572.     
  573.      ; close the window
  574.     movea.l    _IntuitionBase,a6
  575.     move.w    _screen_id,d0
  576.     mulu    #4,d0
  577.     move.l    #_ScreenWdw,d5
  578.     add.l    d0,d5
  579.     movea.l    d5,a1
  580.     movea.l    (a1),a0
  581.     jsr    _LVOCloseWindow(a6)
  582.  
  583.     ; close the screen
  584.     movea.l    _IntuitionBase,a6
  585.     move.w    _screen_id,d0
  586.     mulu    #4,d0
  587.     move.l    #_Screen_list,d5
  588.     add.l    d0,d5
  589.     movea.l    d5,a1
  590.     movea.l    (a1),a0
  591.     jsr    _LVOCloseScreen(a6)
  592.     
  593.     ; zero all list elements -> screen,rastport,viewport
  594.     move.w    _screen_id,d0
  595.     mulu    #4,d0        ; offset from start of screen lists
  596.  
  597.     move.l    #_Screen_list,d5
  598.     add.l    d0,d5
  599.     movea.l    d5,a0
  600.     move.l    #0,(a0)
  601.  
  602.     move.l    #_ScreenWdw,d5
  603.     add.l    d0,d5
  604.     movea.l    d5,a0
  605.     move.l    #0,(a0)
  606.     
  607.     move.l    #_ScreenRPort,d5
  608.     add.l    d0,d5
  609.     movea.l    d5,a0
  610.     move.l    #0,(a0)
  611.  
  612.     move.l    #_ScreenViewPort,d5
  613.     add.l    d0,d5
  614.     movea.l    d5,a0
  615.     move.l    #0,(a0)
  616.  
  617.     ; find open screen (starting from 9)
  618.     move.w    #10,d1
  619. _findopenscreen:
  620.     sub.w    #1,d1        ; start counter at 9
  621.     cmpi.w    #0,d1
  622.     beq    _foundwbscreen    ; no open screens except Wb
  623.  
  624.     move.w    d1,d0
  625.     mulu    #4,d0        ; offset from start of screen lists
  626.     
  627.     move.l    #_Screen_list,d5
  628.     add.l    d0,d5
  629.     movea.l    d5,a0
  630.     cmpi.l    #0,(a0)
  631.     beq.s    _findopenscreen    ; try next screen list position    
  632.     
  633.     ; there is still an open screen -> update _Scrn,_RPort,_ViewPort 
  634.     move.l    (a0),_Scrn
  635.  
  636.     move.l    #_ScreenWdw,d5
  637.     add.l    d0,d5            ; d0=offset from start of list
  638.     movea.l    d5,a0
  639.     move.l    (a0),_Wdw
  640.     
  641.     move.l    #_ScreenRPort,d5
  642.     add.l    d0,d5            ; d0=offset from start of list
  643.     movea.l    d5,a0
  644.     move.l    (a0),_RPort
  645.  
  646.     move.l    #_ScreenViewPort,d5
  647.     add.l    d0,d5            ; d0=offset from start of list
  648.     movea.l    d5,a0
  649.     move.l    (a0),_ViewPort
  650.  
  651.     ; Is there an open window on this new screen?
  652.     ; If so, make the highest numbered one the current output window.
  653.     jsr    _check_for_open_window
  654.  
  655.     bra.s    _quitclosescreen
  656.  
  657. _foundwbscreen:
  658.     ; only Wb screen open -> update _Scrn,_RPort,_ViewPort,_fgdpen,_bgpen
  659.     ; and reset _IntuiMode if only a shell/CLI is open.
  660.     move.l    _WBWdw,_Wdw
  661.     move.l    _WBRPort,_RPort
  662.     move.l    _WBScrn,_Scrn
  663.     move.l    _WBViewPort,_ViewPort
  664.     move.l    _WBfgdpen,_fgdpen
  665.     move.l    _WBbgpen,_bgpen    
  666.  
  667.     jsr    _only_shell_is_active
  668.     cmpi.w    #0,d0
  669.     beq.s    _quitclosescreen
  670.  
  671.     move.b    #0,_IntuiMode
  672.         
  673. _quitclosescreen:
  674.     rts
  675.  
  676. ;
  677. ; SCREEN FORWARD | BACK screen-id. 
  678. ;
  679. ; d0 = screen_id; d1 = forward/back (1 or 2).
  680. ;
  681. _change_screen_depth:
  682.     ; check parameters
  683.     cmpi.w    #1,d0        ; screen-id < 1?
  684.     blt    _quit_change_screen_depth
  685.     cmpi.w    #9,d0        ; screen-id > 9?
  686.     bgt    _quit_change_screen_depth
  687.  
  688.     ; calculate place in screen list
  689.     mulu    #4,d0        ; offset from start of screen lists
  690.  
  691.     move.l    #_Screen_list,d5
  692.     add.l    d0,d5
  693.     movea.l    d5,a0
  694.  
  695.     ; is screen-id being used?
  696.     move.l    (a0),d0
  697.     cmpi.l    #0,d0
  698.     beq.s    _quit_change_screen_depth    ; store screen-id
  699.  
  700.     ; change the screen's depth!
  701.     cmpi.w    #1,d1
  702.     bne.s    _test_for_screen_back_move
  703.     movea.l    _IntuitionBase,a6
  704.     movea.l    d0,a0
  705.     jsr    _LVOScreenToFront(a6)        ; SCREEN FRONT
  706.     rts
  707.  
  708. _test_for_screen_back_move:
  709.     cmpi.w    #2,d1
  710.     bne.s    _quit_change_screen_depth
  711.     movea.l    _IntuitionBase,a6
  712.     movea.l    d0,a0
  713.     jsr    _LVOScreenToBack(a6)        ; SCREEN BACK
  714.     
  715. _quit_change_screen_depth:
  716.     rts
  717.  
  718. ;
  719. ; define palette for current viewport. d0=color-id,d1=red,d2=green,d3=blue. 
  720. ;
  721. _palette:
  722.     ; store color-id
  723.     move.w    d0,_color_id
  724.  
  725.     ; check for legal color-id
  726.     cmpi.w    #0,d0
  727.     blt    _quitpalette    ; color-id < 0?
  728.     
  729.     cmpi.w    #63,d0
  730.     bgt    _quitpalette    ; color-id > 63?
  731.  
  732.     ; store RGB values.
  733.     move.l    d1,_red
  734.     move.l    d2,_green
  735.     move.l    d3,_blue
  736.  
  737.     ; Convert single-precision RGB values (0-1) to integers (0-15).
  738.     ; Each FFP value must be multiplied by 15.
  739.  
  740.     movea.l    _MathBase,a6
  741.         
  742.     move.l    _red,d0
  743.     move.l    #$f0000044,d1    ; 15
  744.     jsr    _LVOSPMul(a6)
  745.     jsr    _LVOSPFix(a6)
  746.     move.l    d0,_red
  747.  
  748.     move.l    _green,d0
  749.     move.l    #$f0000044,d1    ; 15
  750.     jsr    _LVOSPMul(a6)
  751.     jsr    _LVOSPFix(a6)
  752.     move.l    d0,_green
  753.  
  754.     move.l    _blue,d0
  755.     move.l    #$f0000044,d1    ; 15
  756.     jsr    _LVOSPMul(a6)
  757.     jsr    _LVOSPFix(a6)
  758.     move.l    d0,_blue    
  759.  
  760.     ; change colormap values with SetRGB4
  761.     movea.l    _GfxBase,a6
  762.     movea.l    _ViewPort,a0
  763.     move.w    _color_id,d0        
  764.     move.l    _red,d1
  765.     and.b    #$ff,d1
  766.     move.l    _green,d2
  767.     and.b    #$ff,d2
  768.     move.l    _blue,d3
  769.     and.b    #$ff,d3
  770.     jsr    _LVOSetRGB4(a6)
  771.         
  772. _quitpalette:
  773.     rts
  774.  
  775. ;
  776. ; print a short integer on current screen. d0=short integer to be printed.
  777. ;
  778. _shortprints:
  779.     lea    _strbuf,a0
  780.     jsr    _strshort
  781.     jsr    _stringprints
  782.         
  783.     rts
  784.  
  785. ;
  786. ; print a long integer on current screen. d0=long integer to be printed.
  787. ;
  788. _longprints:
  789.     lea    _strbuf,a0
  790.     jsr    _strlong
  791.     jsr    _stringprints
  792.  
  793.     rts
  794.  
  795. ;
  796. ; print a single-precision value on current screen. 
  797. ; d0=single-precision float to be printed.
  798. ;
  799. _singleprints:
  800.     move.l    d0,-(sp)
  801.     jsr    _strsingle
  802.     addq    #4,sp
  803.     move.l    d0,a0
  804.     jsr    _stringprints
  805.     
  806.     rts
  807.  
  808. ;
  809. ; print a string on current screen. a0=string to be printed.
  810. ;
  811. _stringprints:
  812.     ; find length of string
  813.     movea.l    a0,a2
  814.     jsr    _strlen        ; d0=length 
  815.     and.w    #$ffff,d0
  816.  
  817.     ; print it
  818.     movea.l    _RPort,a1
  819.     movea.l _GfxBase,a6
  820.     jsr    _LVOText(a6)    
  821.     
  822.     rts
  823.  
  824. ;
  825. ; print a line feed in current screen using locate,
  826. ; scrolling if necessary.
  827. ;
  828. _printsLF:
  829.     jsr    _csrlin
  830.     addq    #1,d0    ; d0=LINE
  831.     
  832.     move.w    #1,d1    ; d1=COLUMN
  833.  
  834.     jsr    _locate
  835.     jsr    _scroll_screen
  836.  
  837.     rts
  838.  
  839. ;
  840. ; print a BASIC TAB in current Intuition window using LOCATE.
  841. ; *note* that this is not the same as the CON/RAW window comma-TAB
  842. ; used by print which consists of CHR$(9) x 2.
  843. _printsTAB:
  844.     jsr    _csrlin     ; d0=LINE
  845.     move.w    d0,-(sp) ; store LINE
  846.     
  847.     jsr    _pos
  848.     move.w    d0,d1
  849.  
  850. _seekintuitabpos:
  851.     ; find the next tab position (every 10 character positions)
  852.     add.w    #1,d1     ; d1=COLUMN
  853.     move.w    d1,d2
  854.     ext.l    d2
  855.     divu    #10,d2
  856.     swap    d2     ; d2 MOD 10 
  857.     cmpi.w    #0,d2    
  858.     bne.s    _seekintuitabpos
  859.  
  860.     move.w    (sp)+,d0 ; pop LINE
  861.  
  862.     jsr    _locate
  863.  
  864.     rts
  865.  
  866. ;
  867. ; print a single space in current screen using locate.
  868. ;
  869. _printsSPC:
  870.     jsr    _csrlin     ; d0=LINE
  871.     move.w    d0,-(sp) ; store LINE
  872.  
  873.     jsr    _pos
  874.     move.w    d0,d1
  875.     addq    #1,d1     ; d1=COLUMN
  876.     move.w    (sp)+,d0 ; pop LINE
  877.  
  878.     jsr    _locate
  879.  
  880.     rts
  881.  
  882. ;
  883. ; Test for a control-c break. Return 0L or non-zero value in d0. 
  884. ;
  885. _ctrl_c_test:
  886.     cmpi.b    #1,_IntuiMode
  887.     beq.s    _intui_ctrl_c_test
  888.  
  889.     ; DOS window ctrl-c signal test
  890.     movea.l    _AbsExecBase,a6
  891.     moveq    #0,d0
  892.     move.l    #CTRL_C_BREAK,d1
  893.     jsr    _LVOSetSignal(a6)
  894.     andi.l    #CTRL_C_BREAK,d0    ; Quit with 0 or 4096
  895.     rts
  896.  
  897. _intui_ctrl_c_test:
  898.     ; Test for ASCII 3 from IDCMP for current window
  899.     movea.l    _Wdw,a0
  900.     move.l    UserPort(a0),-(sp)
  901.     jsr    _GetIntuiEvent
  902.     addq    #4,sp
  903.     tst.l    d0
  904.     beq.s    _exit_ctrl_c_test    ; No message! Quit with 0
  905.  
  906.     movea.l    d0,a0            ; pointer to IntuiInfo structure
  907.     move.l    Class(a0),d1        ; Message->Class
  908.     andi.l    #VANILLAKEY,d1
  909.     cmpi.l    #VANILLAKEY,d1
  910.     beq.s    _get_vanilla_key    ; No vanillakey event: quit
  911.     moveq    #0,d0            ; Quit with 0
  912.     rts
  913.  
  914. _get_vanilla_key:
  915.     moveq    #0,d0            ; assume it's not ASCII 3 -> 0 result
  916.     move.w    Code(a0),d1        ; Message->Code
  917.     cmpi.w    #3,d1
  918.     bne.s    _exit_ctrl_c_test
  919.     jsr    _ClearIntuiEvent
  920.     moveq    #1,d0            ; Quit with 1 -> it's an ASCII 3!
  921.                 
  922. _exit_ctrl_c_test:
  923.     rts
  924.     
  925.     END
  926.