home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1997 #5 / amigaacscoverdisc1997-051997.i / games / installers / puggsy / src / lib / utils_degrade.asm < prev    next >
Assembly Source File  |  1997-07-20  |  9KB  |  570 lines

  1. ; *** JOTD HD Startup utility library
  2. ; *** Copyright Jean-Francois Fabre 1996-1997
  3.  
  4. ; *** degrader part. Other parts are not distributed
  5.  
  6. ; If you use this source (or parts), I'd appreciate
  7. ; that you credit me about it. Thanks
  8. ;
  9. ; The weakness of this code is the lack of system-friendly
  10. ; sprite resolution set system. It may appear in next releases
  11. ; I personnaly use ResetSprites during game and it works fine 
  12.  
  13.     ; *** For link with C programs
  14.  
  15.     XDEF    _C_Degrade
  16.     XDEF    _C_Enhance
  17.  
  18.     XDEF    _Enhance
  19.     XDEF    _Degrade
  20.     XDEF    _DegradeCpu
  21.     XDEF    _DegradeGfx
  22.     XDEF    _FlushCachesSys
  23.  
  24.     XDEF    _Kick37Test
  25.     XDEF    _KickVerTest
  26.  
  27. RESET_CIA_CODE:MACRO
  28.  
  29. ResetCIAs:
  30.     move.b  #$c0,$bfd200            ;reinit CIAs
  31.     move.b  #$ff,$bfd300            ;for
  32.     move.b  #$03,$bfe201            ;KB
  33. ;    move.b  #$7f,$bfec01
  34.     move.b  #$00,$bfee01
  35.     move.b  #$88,$bfed01
  36.  
  37.     tst.b    $bfdd00            ; acknowledge CIA-B Timer A interrupt
  38.     tst.b    $bfed01            ; acknowledge CIA-A interrupts
  39.  
  40.     bsr    AckKeyboard
  41.  
  42.     rts
  43.  
  44. AckKeyboard:
  45.     bset    #$06,$BFEE01
  46.     nop
  47.     bclr    #$06,$BFEE01
  48.     rts
  49.     ENDM
  50.  
  51.     IFND    HDSTARTUP
  52.  
  53.     ; *** this code is on its own (which is the case :-) )
  54.     
  55.     XREF    _SysBase
  56.  
  57.     include    "libs.i"
  58.     include    "utils_macros.i"
  59.  
  60.     ENDC
  61.  
  62. ; *** Restore degraded things: Display, Caches, VBR...
  63.  
  64. ; internal use (in InGameExitAbs)
  65.  
  66. _C_Enhance:
  67. _Enhance:
  68. Enhance:
  69.     STORE_REGS
  70.  
  71.     tst.b    degraded_cpu
  72.     beq    skipec$
  73.  
  74.     move.l    oldcacheset(pc),D0
  75.     moveq.l    #-1,D1
  76.     bsr    EnaCaches
  77.  
  78.     move.l    oldvbr(pc),D0
  79.     bsr    SetVBR
  80.  
  81. skipec$
  82.  
  83.     tst.b    degraded_gfx
  84.     beq    exit$
  85.  
  86.     move.l    _GfxBase(pc),D0
  87.     beq    exit$
  88.     move.l    D0,A6
  89.     move.l    my_actiview(PC),D0
  90.     beq    1$
  91.     move.l    D0,A1
  92.  
  93.     JSRLIB    LoadView
  94.     JSRLIB    WaitTOF
  95.     JSRLIB    WaitTOF
  96.  
  97. 1$
  98.     lea    $DFF000,A5
  99.     move.l    my_copinit(PC),cop1lc(a5) ; adresse du début de la liste
  100.  
  101.     move.l    _IntuitionBase,D0
  102.     beq    skip$
  103.     move.l    D0,A6
  104.     move.l    TheScreen,D0
  105.     beq    skip$
  106.     move.l    D0,A0
  107.     JSRLIB    CloseScreen
  108.  
  109.     bsr    CloseIntuiLib
  110. skip$
  111.     bsr    CloseGFXLib
  112. exit$
  113.     RESTORE_REGS
  114.     rts
  115.  
  116.  
  117. _DegradeCpu:
  118.     movem.l    D0/D1,-(sp)
  119.     bsr    GetVBR
  120.     move.l    D0,oldvbr
  121.     bsr    ZeroVBR
  122.     movem.l    (sp)+,D0/D1
  123.     bsr    DisCaches
  124.     move.l    D0,oldcacheset
  125.     move.b    #$00,$DE0000        ; DTack (A3000/A4000 users)
  126.     st.b    degraded_cpu
  127.     rts
  128.  
  129.  
  130. _DegradeGfx:
  131.     bsr    OpenGFXLib
  132.     beq    D_Exit
  133.     bsr    OpenIntuiLib
  134.     beq    D_Exit
  135.  
  136.     IFD    HDSTARTUP
  137.     tst.l    reloc_chipmirror
  138.     beq    skip$
  139.     ENDC
  140.  
  141.     move.l    _IntuitionBase,D0
  142.     beq    skip$
  143.     move.l    D0,A6
  144.     sub.l    a0,a0
  145.     lea    ScreenTags,a1
  146.     JSRLIB    OpenScreenTagList
  147.     move.l    d0,TheScreen
  148.  
  149. skip$
  150.     IFD    HDSTARTUP
  151.     tst.l    delay_flag
  152.     beq    nowait$
  153.     move.l    _DosBase,A6
  154.     move.l    #100,D1
  155.     JSRLIB    Delay        ; wait 2 seconds before launching
  156.  
  157. nowait$
  158.     ENDC
  159.  
  160.     move.l    _GfxBase,A6
  161.     move.l    gb_ActiView(A6),my_actiview
  162.     move.l    gb_copinit(A6),my_copinit
  163.     sub.l    A1,A1
  164.     JSRLIB    LoadView
  165.     JSRLIB    WaitTOF
  166.     JSRLIB    WaitTOF
  167.  
  168.     IFD    HDSTARTUP
  169.     JSRGEN    ResetDisplay
  170.     ENDC
  171.  
  172. D_Exit:
  173.     st.b    degraded_gfx
  174.     rts
  175.  
  176. ; *** Degrades everything
  177. ; in: D0,D1: value and mask for caches control
  178. ; (the same format as in CacheControl())
  179.  
  180. _C_Degrade:
  181.     move.l    4(A7),D0
  182.     move.l    8(A7),D1
  183. _Degrade:
  184.     STORE_REGS
  185.  
  186.     bsr    _DegradeCpu
  187.     bsr    _DegradeGfx
  188.     bsr    ResetCIAs        ; re-init keyboard
  189.  
  190.     RESTORE_REGS
  191.     rts
  192.  
  193. DisCaches:
  194.     movem.l    D1-A6,-(sp)
  195.  
  196.     move.l    D0,D6
  197.     move.l    D1,D7
  198.  
  199.     bsr    _Kick37Test
  200.     tst.l    D0
  201.     bne    3$        ; Don't touch if KS 1.x
  202.  
  203.     move.l    D6,D0
  204.     move.l    D7,D1
  205.  
  206.     IFD    HDSTARTUP
  207.     tst.l    nocaches_flag
  208.     beq    5$
  209.     ENDC
  210.  
  211.     moveq.l    #0,D0
  212.     moveq.l    #-1,D1
  213. 5$
  214.     move.l    _SysBase,A6
  215.     JSRLIB    CacheControl
  216.     move.l    D0,D7
  217.  
  218.     move.l    _SysBase,A6
  219.     move.b    AttnFlags+1(A6),D0
  220.     btst    #AFB_68060,D0
  221.     beq    2$
  222.  
  223.     ; *** remove data cache, branch cache, write cache, superscalar mode
  224.  
  225.     lea    DisCacheSup,A5
  226.     move.l    _SysBase,A6
  227.     JSRLIB    Supervisor
  228. 2$
  229.     move.l    D7,D0
  230.     movem.l    (sp)+,D1-A6
  231.     rts
  232.  
  233. 3$
  234.     moveq.l    #0,D0
  235.     bra    2$
  236.  
  237. EnaCaches:
  238.     movem.l    D1-A6,-(sp)
  239.  
  240.     move.l    D0,D7
  241.     bsr    _Kick37Test
  242.     tst.l    D0
  243.     bne    3$        ; Don't touch if KS 1.x
  244.     move.l    D7,D0
  245.     move.l    _SysBase,A6
  246.     JSRLIB    CacheControl
  247.  
  248.     move.l    D0,D7
  249.  
  250.     move.l    _SysBase,A6
  251.     move.b    AttnFlags+1(A6),D0
  252.     btst    #AFB_68060,D0
  253.     beq    2$
  254.  
  255.     lea    EnaCacheSup,A5
  256.     move.l    _SysBase,A6
  257.     JSRLIB    Supervisor
  258. 2$
  259.     move.l    D7,D0
  260.     movem.l    (sp)+,D1-A6
  261.     rts
  262.  
  263. 3$
  264.     moveq.l    #0,D0
  265.     bra    2$
  266.  
  267. ; *** Disable some '060 caches
  268. ; *** Left intact by CacheControl
  269.  
  270. ; internal, only useful (and executed) for 68060 cpus
  271.  
  272. DisCacheSup:
  273.     movem.l    D1-A6,-(sp)
  274.     MACHINE    68060
  275.     ori.w    #$700,sr
  276.     movec    cacr,D0
  277.     andi.l    #$A0800000,D0
  278.     move.l    D0,old060cacr
  279.  
  280.     movec    cacr,D0
  281.     move.l    #$A0800000,D1        ; mask for specific 68060 caches
  282.  
  283.     not.l    D1
  284.     and.l    D1,D0
  285.     movec    D0,cacr
  286.  
  287.     nop
  288.  
  289.     ; *** remove superscalar
  290.  
  291.     bra    nossh$
  292.     movec    pcr,D0
  293.     move.l    D0,old060pcr
  294.     andi.l    #$04300100,D0
  295.     movec    D0,pcr
  296. nossh$
  297.  
  298.     ; *** flush
  299.  
  300.     CPUSHA    BC
  301.     movem.l    (sp)+,D1-A6
  302.     MACHINE    68000
  303.     rte
  304.  
  305. ; *** Enable some '060 caches
  306. ; *** Left intact by CacheControl
  307.  
  308. EnaCacheSup:
  309.     MACHINE    68060
  310.     ori.w    #$700,sr
  311.     movec    cacr,D0
  312.     or.l    old060cacr,D0
  313.     movec    D0,cacr
  314.  
  315.     bra    nossh$
  316.     movec    pcr,D0
  317.     or.l    old060pcr,D0
  318.     movec    D0,pcr
  319. nossh$
  320.  
  321.     CPUSHA    BC
  322.     MACHINE    68000
  323.     rte
  324.  
  325. ; *** Gets VBR value
  326. ; out: D0: VBR value
  327.  
  328. ; VBR is the vector base register (interrupts, traps, exceptions)
  329. ; It exists on 68010, 68020, 68030, 68040, 68060
  330. ; Most of the games don't like it to be different from zero,
  331. ; others are originally HD-Installable :-)
  332. ; Called from a 68000, this function will return 0 in any case (no VBR)
  333.  
  334. GetVBR:
  335.     movem.l    D1-A6,-(sp)
  336.     lea    GetVBRSup,A0
  337.     bsr    OperateVBR
  338.     movem.l    (sp)+,D1-A6
  339.     rts
  340.  
  341. ; *** Sets VBR value
  342. ; in: D0: new VBR value
  343.  
  344. ; Called from a 68000, this function will do nothing (no VBR)
  345. ; It will do nothing if the LEAVEVBR tooltype is set too (debug)
  346.  
  347. SetVBR:
  348.     movem.l    D1-A6,-(sp)
  349.     lea    SetVBRSup,A0
  350.     bsr    OperateVBR
  351.     movem.l    (sp)+,D1-A6
  352.     rts
  353.     
  354. ; *** Sets VBR to zero
  355. ; It will do nothing if the LEAVEVBR tooltype is set (debug)
  356.  
  357. ZeroVBR:
  358.     movem.l    D1-A6,-(sp)
  359.     moveq.l    #0,D0
  360.     bsr    SetVBR
  361.     movem.l    (sp)+,D1-A6
  362.     rts
  363.  
  364. ; *** VBR operation
  365. ; in: A0: supervisor function to call
  366. ;     D0: value to pass to the sup function
  367. ; out D0: return val of the sup function
  368.  
  369. ; It will do nothing if the LEAVEVBR tooltype is set (debug)
  370.  
  371.  
  372. OperateVBR:
  373.     movem.l    D1-D7/A0-A6,-(A7)
  374.     move.l    A0,A5            ; supervisor function
  375.  
  376.     move.l    _SysBase,A6
  377.     move.b    AttnFlags+1(A6),D1
  378.     btst    #AFB_68010,D1        ; At least 68010
  379.     beq    error$
  380.  
  381.     move.l    _SysBase,A6
  382.     JSRLIB    Supervisor
  383. exit$
  384.     movem.l    (A7)+,D1-D7/A0-A6
  385.     rts
  386. error$
  387.     moveq.l    #0,D0
  388.     bra    exit$
  389.  
  390. ; *** Supervisor call to set the VBR
  391.  
  392. SetVBRSup:
  393.     IFD    HDSTARTUP
  394.     tst.l    leavevbr_flag
  395.     bne    exit$
  396.     ENDC
  397.  
  398.     MACHINE 68010
  399.     movec    D0,VBR
  400.     MACHINE 68000
  401. exit$
  402.     rte
  403.  
  404. ; *** Supervisor call to get the VBR
  405.  
  406. GetVBRSup:
  407.     MACHINE 68010
  408.     movec    VBR,D0
  409.     MACHINE 68000
  410.     rte
  411.  
  412. ; *** open graphics library
  413.  
  414. OpenGFXLib:
  415.     movem.l    D1-A6,-(sp)
  416.     lea    grname,A1
  417.     move.l    _SysBase,A6
  418.     moveq.l    #0,D0
  419.     JSRLIB    OpenLibrary
  420.     move.l    D0,_GfxBase
  421.     movem.l    (sp)+,D1-A6
  422.     rts
  423.  
  424. ; *** close graphics library
  425.  
  426. CloseGFXLib:
  427.     movem.l    D0-A6,-(sp)
  428.     move.l    _SysBase,A6
  429.     move.l    _GfxBase,D0
  430.     beq    skip$
  431.     move.l    D0,A1
  432.     JSRLIB    CloseLibrary
  433. skip$
  434.     movem.l    (sp)+,D0-A6
  435.     rts
  436.  
  437. ; *** open intuition library
  438.  
  439. OpenIntuiLib:
  440.     movem.l    D1-A6,-(sp)
  441.     lea    intname,A1
  442.     move.l    _SysBase,A6
  443.     moveq.l    #36,D0
  444.     JSRLIB    OpenLibrary
  445.     move.l    D0,_IntuitionBase
  446.     movem.l    (sp)+,D1-A6
  447.     rts
  448.  
  449. ; *** close intuition library
  450.  
  451. CloseIntuiLib:
  452.     movem.l    D0-A6,-(sp)
  453.     move.l    _SysBase,A6
  454.     move.l    _IntuitionBase,D0
  455.     beq    skip$
  456.     move.l    D0,A1
  457.     JSRLIB    CloseLibrary
  458. skip$
  459.     movem.l    (sp)+,D0-A6
  460.     rts
  461.  
  462.  
  463. ; *** Flushes the caches
  464.  
  465.     cnop    0,4
  466. _FlushCachesSys:
  467.     STORE_REGS
  468.     bsr    _Kick37Test
  469.     tst.l    D0
  470.     bne    2$        ; Don't touch if KS 1.x
  471.     moveq.l    #0,D0
  472.     moveq.l    #0,D1
  473.     move.l    _SysBase,A6
  474.     JSRLIB    CacheControl
  475. 2$
  476.     RESTORE_REGS
  477.     rts
  478.  
  479. ; *** Test ROM version
  480. ; out: D0=0  if KS>36
  481. ;      D0!=0 if KS<=36
  482.  
  483.     cnop    0,4
  484. _Kick37Test:
  485.     move.l    #36,D0
  486.     bsr    _KickVerTest
  487.     rts    
  488.  
  489. ; *** Test if ROM version > a given version
  490. ; in: D0: kickstart version number
  491. ; out:D0=0 newer !=0 older
  492.  
  493.     cnop    0,4
  494. _KickVerTest:
  495.     movem.l    D1/A5/A6,-(sp)
  496.  
  497.     move.l    _SysBase,A6
  498.     move.w    SoftVer(A6),D1
  499.     cmp.w    D0,D1
  500.     bgt.s    newer$
  501.     movem.l    (sp)+,D1/A5/A6
  502.     moveq.l    #-1,D0
  503.     rts
  504. newer$
  505.     movem.l    (sp)+,D1/A5/A6
  506.     moveq.l    #0,D0
  507.     rts
  508.  
  509.  
  510.  
  511. ; *** Reset the CIAs for the keyboard
  512. ; *** Thanks to Alain Malek for this piece of code
  513. ; (see macro definition)
  514.  
  515.     IFND    HDSTARTUP
  516.     RESET_CIA_CODE
  517.     ENDC
  518.  
  519.  
  520. my_actiview:
  521.     dc.l    0
  522. my_copinit:
  523.     dc.l    0
  524. oldvbr:
  525.     dc.l    0
  526. oldcacheset:
  527.     dc.l    0
  528. old060cacr:
  529.     dc.l    0
  530. old060pcr:
  531.     dc.l    0
  532.  
  533. cache_value:
  534.     dc.l    0
  535. cache_mask:
  536.     dc.l    0
  537.  
  538.     IFND    HDSTARTUP
  539. _GfxBase:
  540.     dc.l    0
  541.     ENDC
  542.  
  543. _IntuitionBase:
  544.     dc.l    0
  545.  
  546. TheScreen:
  547.     dc.l    0
  548.  
  549. ScreenTags:
  550.         dc.l    SA_DisplayID,135168    ; PAL lores
  551.         dc.l    SA_Width,320
  552.         dc.l    SA_Height,200
  553.         dc.l    SA_Depth
  554.         dc.l    3
  555.         dc.l    SA_Quiet,-1
  556.         dc.l    SA_AutoScroll,0
  557.         dc.l    0,0
  558.  
  559. grname:
  560.     dc.b    "graphics.library",0
  561. intname:
  562.     dc.b    "intuition.library",0
  563.  
  564. degraded_cpu:
  565.     dc.b    0
  566. degraded_gfx:
  567.     dc.b    0
  568.  
  569.     cnop    0,4
  570.