home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / asm / DemoStartUP.lha / DemoStartUPv1.0 / sources / start.asm < prev    next >
Encoding:
Assembly Source File  |  2001-05-02  |  24.6 KB  |  1,420 lines

  1. ;- [ 8bit START UP v1.0 ] -
  2. ; AGA/CGX/CGX Window/P61
  3. ; by Nemanja Bondzulic aka Cyborg/iNDUSTRY <cyborg@indus3.org>
  4.  
  5. ;///XDEF
  6.     xdef    _CPU
  7.     xdef    _FPU
  8.     xdef    _blit
  9.     xdef    _CGX
  10.         xdef    _WIN
  11.     xdef    _screen
  12.     xdef    _window
  13.     xdef    _newpal
  14.     xdef    _cls
  15.     xdef    _gettime
  16.  
  17.     xdef    _DosBase
  18.     xdef    _IntuitionBase
  19.     xdef    _GfxBase
  20.     xdef    _CyberGfxBase
  21.  
  22.     xdef    _thisTasksigf
  23.     xdef    _thisTask
  24.  
  25.     xdef    _nfsc
  26. ;///
  27. ;///XREF
  28.     xref    _C2P
  29.     xref    _InitC2P
  30.     xref    _InitPlayer
  31.     xref    _StopPlayer
  32.     xref    _P61_E8
  33.     xref    _InitPreDEMO
  34.     xref    _Main
  35.     xref    _chunky
  36.     xref    _AslCgxModeRequester
  37.     xref    _displayid
  38.     xref    _SoftIRQ
  39.     xref    _StartSoftInt
  40.     xref    _StopSoftInt
  41.     xref    _si_micro
  42.     xref    _si_secs
  43.     xref    _si_func
  44. ;///
  45. ;///Includes
  46.     include    "basemacros.i"
  47.  
  48.     incdir    include:
  49.  
  50.     include    devices/timer.i
  51.  
  52.     include exec/interrupts.i
  53.     include    exec/lists.i
  54.     include    exec/execbase.i
  55.     include exec/types.i
  56.     include    exec/exec.i
  57.     include exec/libraries.i
  58.     include exec/io.i
  59.     include exec/memory.i
  60.     include exec/ports.i
  61.  
  62.     include utility/tagitem.i
  63.  
  64.     include    intuition/intuition.i
  65.  
  66.     include dos/dostags.i
  67.  
  68.     include    hardware/blit.i
  69.     include    hardware/custom.i
  70.         include hardware/dmabits.i
  71.     include    hardware/intbits.i
  72.     include hardware/rawkeys.i
  73.  
  74.     include    LVO/graphics_lib.i
  75.     include    LVO/dos_lib.i
  76.     include LVO/exec_lib.i
  77.     include    LVO/intuition_lib.i
  78.     include    LVO/cybergraphics_lib.i
  79.     include    LVO/asl_lib.i
  80.     include    LVO/icon_lib.i
  81.  
  82.     include    libraries/asl.i
  83.         include    libraries/dosextens.i
  84.  
  85.     include cybergraphx/cybergraphics.i
  86.  
  87.     include    graphics/view.i
  88.  
  89.     include    workbench/workbench.i
  90.     include    workbench/startup.i
  91. ;///
  92.  
  93.     section asmstart,code
  94.  
  95. ;///_asmstart
  96. _asmstart
  97.         movem.l    d0/a0,-(sp)
  98.  
  99.     sub.l    a1,a1
  100.     callExe    FindTask
  101.     move.l    d0,_thisTask
  102.  
  103.     move.l    d0,a4
  104.  
  105.     tst.l    pr_CLI(a4)
  106.     bne.s   .fromCLI
  107.  
  108.     move.b    #TRUE,WB
  109.  
  110.     lea    pr_MsgPort(a4),a0
  111.     callExe WaitPort
  112.     lea    pr_MsgPort(a4),a0
  113.     callExe GetMsg
  114.     move.l    d0,returnMsg
  115.  
  116. .fromCLI
  117.     movem.l    (sp)+,d0/a0
  118.  
  119.     ;Set own priority to 1
  120.     move.l    _thisTask,a1
  121.     moveq    #1,d0
  122.     callExe SetTaskPri
  123.  
  124.     bsr.s    determinePU
  125.  
  126.     ;Open dos.library
  127.     lea    DosName(pc),a1
  128.     moveq    #39,d0
  129.     callExe    OpenLibrary
  130.     move.l    d0,_DosBase
  131.     beq.w    .nodos
  132.  
  133.         ;Read arguments if started from CLI
  134.         tst.b    WB
  135.         bne.s    .skipreadargs
  136.     move.l    #template,d1
  137.         move.l    #argarray,d2
  138.         moveq    #0,d3
  139.         callDos    ReadArgs
  140.     move.l    d0,rdargs
  141.  
  142.         lea    argarray,a0
  143.     move.l    ARG_LIMITFPS(a0),a0
  144.         tst.l    a0
  145.         beq.s    .nolimitfps
  146.     move.l    (a0),d0
  147.         ble.s   .nolimitfps
  148.         and.l    #$ff,d0
  149.         move.l    d0,limitfps
  150. .nolimitfps
  151.  
  152.  
  153.         bra.s    .skiptooltypes
  154. .skipreadargs
  155.  
  156.         ;Lock current directory
  157.     move.l    returnMsg,a2
  158.         move.l    sm_ArgList(a2),d0
  159.         beq.s    .domain
  160.     move.l    d0,a0
  161.     move.l    wa_Lock(a0),d1
  162.     callDos    DupLock
  163.     move.l    d0,curdir
  164.     move.l    d0,d1
  165.     callDos    CurrentDir
  166. .domain
  167.         ;Get WB program name
  168.     move.l    returnMsg,a0
  169.     move.l    sm_ArgList(a0),a0
  170.         move.l    wa_Name(a0),programname
  171.  
  172.         ;Open icon.library
  173.     lea    IconName(pc),a1
  174.     moveq    #36,d0
  175.     callExe    OpenLibrary
  176.     move.l    d0,_IconBase
  177.     beq.w    .unlockdir
  178.  
  179.            ;Get icon
  180.         move.l    programname,a0
  181.         callIco    GetDiskObject
  182.         move.l    d0,diskobject
  183.         beq.s    .unlockdir
  184.  
  185.     ;Find tooltypes
  186.         lea    argarray,a2
  187.  
  188.         move.l    diskobject,a0
  189.         move.l    do_ToolTypes(a0),a0
  190.         lea    TT_SCREENMODE,a1
  191.     callIco    FindToolType
  192.         tst.l    d0
  193.         beq.s    .notooltypesm
  194.         move.l    #TRUE,ARG_SCREENMODE(a2)
  195. .notooltypesm
  196.         move.l    diskobject,a0
  197.         move.l    do_ToolTypes(a0),a0
  198.         lea    TT_AGA,a1
  199.     callIco    FindToolType
  200.         tst.l    d0
  201.         beq.s    .notooltypeaga
  202.         move.l    #TRUE,ARG_AGA(a2)
  203. .notooltypeaga
  204.         move.l    diskobject,a0
  205.         move.l    do_ToolTypes(a0),a0
  206.         lea    TT_WINDOW,a1
  207.     callIco    FindToolType
  208.         tst.l    d0
  209.         beq.s    .notooltypewin
  210.         move.l    #TRUE,ARG_WINDOW(a2)
  211. .notooltypewin
  212.         move.l    diskobject,a0
  213.         move.l    do_ToolTypes(a0),a0
  214.         lea    TT_NOCHK,a1
  215.     callIco    FindToolType
  216.         tst.l    d0
  217.         beq.s    .notooltypenochk
  218.         move.l    #TRUE,ARG_NOCHK(a2)
  219. .notooltypenochk
  220.         move.l    diskobject,a0
  221.         move.l    do_ToolTypes(a0),a0
  222.         lea    TT_LIMITFPS,a1
  223.     callIco    FindToolType
  224.         tst.l    d0
  225.         beq.s    .notooltypelimitfps
  226.  
  227.     move.l    d0,d1
  228.         move.l    #limitfps,d2
  229.         callDos    StrToLong
  230. .notooltypelimitfps
  231.         move.l    diskobject,a0
  232.         move.l    do_ToolTypes(a0),a0
  233.         lea    TT_PUBSCREEN,a1
  234.     callIco    FindToolType
  235.         tst.l    d0
  236.         beq.s    .notooltypepubscreen
  237.         move.l    d0,ARG_PUBSCREEN(a2)
  238. .notooltypepubscreen
  239.  
  240. .unlockdir
  241.     ;Unlock current directory
  242.     move.l    curdir,d1
  243.         beq.s    .wasnolock
  244.     callDos    UnLock
  245. .wasnolock
  246. .skiptooltypes
  247.         ;Open intuition.library
  248.     lea    IntName(pc),a1
  249.     moveq    #39,d0
  250.     callExe    OpenLibrary
  251.     move.l    d0,_IntuitionBase
  252.     beq.w    .noint
  253.  
  254.     ;Open graphics.library
  255.     lea    GfxName(pc),a1
  256.     moveq    #39,d0
  257.     callExe    OpenLibrary
  258.     move.l    d0,_GfxBase
  259.     beq.w    .nogfx
  260.  
  261.     ;Center screens
  262.     move.l    #LORES_KEY,a0
  263.     move.w    #OSCAN_TEXT,d0
  264.     lea    rectangle,a1
  265.     callInt    QueryOverscan
  266.     tst.l    d0
  267.     beq.s    .nooverscan
  268.  
  269.     lea    rectangle,a1
  270.     moveq    #0,d0
  271.     move.l    d0,d1
  272.     move.w    ra_MaxX(a1),d0
  273.     move.w    ra_MaxY(a1),d1
  274.     sub.w    ra_MinX(a1),d0
  275.     sub.w    #SCREEN_WIDTH-1,d0
  276.     bmi.s    .nooverscan2
  277.     lsr.w    #1,d0
  278.     move.l    d0,cgxscrl
  279.     move.l    d0,agascrl
  280. .nooverscan2
  281.     sub.w    ra_MinY(a1),d1
  282.     sub.w    #SCREEN_HEIGHT-1,d1
  283.     bmi.s    .nooverscan
  284.     lsr.w    #1,d1
  285.     move.l    d1,cgxscrt
  286.     move.l    d1,agascrt
  287. .nooverscan
  288.  
  289.         ;Test if AGA switch is used
  290.         lea    argarray,a0
  291.         tst.b    ARG_AGA(a0)
  292.     beq.s    .noagaswitch
  293.     ;Force AGA
  294.     bra.w   .nocgx
  295. .noagaswitch
  296.     
  297.     ;Open cybergraphics.library
  298.     lea    CyberName(pc),a1
  299.     move.l    #41,d0
  300.     callExe    OpenLibrary
  301.     move.l    d0,_CyberGfxBase
  302.     beq.w    .nocgx
  303.  
  304.  
  305.     ;Test if WINDOW switch is used
  306.     lea    argarray,a0
  307.         tst.b    ARG_WINDOW(a0)
  308.     beq.s    .cgx
  309.  
  310.         move.b  #TRUE,_WIN
  311.         bra.s   .both
  312.  
  313.  
  314. .cgx    ;CGX!
  315.     move.w    #TRUE,_CGX
  316.         move.b    #FALSE,_WIN
  317.     move.l    #SCREEN_HEIGHT*2,winh8
  318.  
  319.         ;Find best CGX mode
  320.         lea    bestcmodeidtaglist(pc),a0
  321.     callCgx    BestCModeIDTagList
  322.     move.l    d0,cgxmode
  323.  
  324.         ;Test if SCREENMODE switch is used
  325.         lea    argarray,a0
  326.         tst.b    ARG_SCREENMODE(a0)
  327.     bne.s    .modereq
  328.     
  329.         ;Check for SHIFT key
  330.     move.b    $bfec01,d0
  331.     not.b    d0
  332.     ror.b    #1,d0
  333.     move.b    #$0,$bfec01
  334.     move.b    #%10001000,$bfee01
  335.     cmp.b    #KEY_LSHIFT,d0
  336.     beq.s    .modereq
  337.     cmp.b    #KEY_RSHIFT,d0
  338.     beq.s    .modereq
  339.  
  340.     ;Best CGX mode gotten?
  341.     tst.l    cgxmode
  342.     bne.s    .cgxmodefound
  343. .modereq
  344.     bsr.w    _AslCgxModeRequester
  345.     move.l    _displayid,d0
  346.     beq.w    .noscreen
  347.     move.l    d0,cgxmode
  348.     
  349. .cgxmodefound
  350.     ;Check depth of this mode
  351.     move.l    #CYBRIDATTR_DEPTH,d0
  352.     move.l    cgxmode,d1
  353.     callCgx    GetCyberIDAttr
  354.     cmp.w    #8,d0
  355.     bne.s    .modereq
  356.  
  357.     ;Check pixel format of this mode
  358.     move.l    #CYBRIDATTR_PIXFMT,d0
  359.     move.l    cgxmode,d1
  360.     callCgx    GetCyberIDAttr
  361.     cmp.w    #PIXFMT_LUT8,d0
  362.     bne.s    .modereq
  363.  
  364.     ;Set backdrop window width
  365.     move.l    #CYBRIDATTR_WIDTH,d0
  366.     move.l    cgxmode,d1
  367.     callCgx    GetCyberIDAttr
  368.     move.l    d0,winwi
  369.  
  370.     ;Set backdrop window and screen height
  371.     move.l    #CYBRIDATTR_HEIGHT,d0
  372.     move.l    cgxmode,d1
  373.     callCgx    GetCyberIDAttr
  374.     cmp.l    #SCREEN_HEIGHT,d0
  375.     bge.s    .zh
  376.     move.l    #SCREEN_HEIGHT,d0
  377. .zh
  378.     add.l   d0,d0
  379.     move.l  d0,cgxscrh
  380.     move.l    d0,winh8
  381.     
  382.         ;Open CGX screen
  383.     move.l    #0,a0
  384.     lea    cgxscreentags(pc),a1
  385.     callInt    OpenScreenTagList
  386.     move.l    d0,_screen
  387.     beq.w    .noscreen
  388.  
  389.     ;Check if it is CGX bitmap
  390.         move.l    _screen,a0
  391.         move.l    (sc_RastPort+rp_BitMap)(a0),a0
  392.         move.l    #CYBRMATTR_ISCYBERGFX,d0
  393.     callCgx    GetCyberMapAttr
  394.         tst.l    d0
  395.         beq.w    .notcgxmap
  396.  
  397.     ;Check if it is linear accesable
  398.         move.l    _screen,a0
  399.         move.l    (sc_RastPort+rp_BitMap)(a0),a0
  400.         move.l    #CYBRMATTR_ISLINEARMEM,d0
  401.     callCgx    GetCyberMapAttr
  402.         tst.l    d0
  403.         beq.s    .nolinearcgxmem
  404.  
  405.     ;Get CGX bitmap info by locking
  406.     move.l  _screen,a0
  407.     move.l  (sc_RastPort+rp_BitMap)(a0),a0
  408.     lea     cgxinfotaglist(pc),a1
  409.     callCgx LockBitMapTagList
  410.     move.l  d0,cgxbitmaplock
  411.     beq.s   .nocgxlock
  412.  
  413.     ;Unlock CGX bitmap
  414.     move.l  cgxbitmaplock(pc),a0
  415.     callCgx UnLockBitMap
  416.  
  417.     move.l  cgxbitmap_height,d0
  418.     lsr.l    #1,d0
  419.  
  420.     move.w  d0,cgxh8
  421.     move.w    d0,scrpart
  422.     move.l  cgxbitmap_bytesperrow,d1
  423.     mulu.l    d0,d1
  424.     move.l    d1,cgxadd
  425.     
  426.         bra.s    .both
  427.  
  428. .nocgxlock
  429. .nolinearcgxmem
  430.     ;Close screen
  431.         tst.l    _screen
  432.         beq.s    .noscreen
  433.     move.l    _screen,a0
  434.     callInt    CloseScreen
  435.  
  436.  
  437.  
  438. .nocgx  ;NO CGX! ONLY AGA!
  439.     move.w    #FALSE,_CGX
  440.  
  441.     ;Allocate CHIP Memory
  442.     move.l    #SCREEN_WIDTH*SCREEN_HEIGHT,d0
  443.     move.l    #MEMF_CHIP|MEMF_CLEAR,d1
  444.     callExe    AllocVec
  445.     move.l    d0,bmp1pointer
  446.     beq.s    .exitsequence
  447.  
  448.     move.l    #SCREEN_WIDTH*SCREEN_HEIGHT,d0
  449.     move.l    #MEMF_CHIP|MEMF_CLEAR,d1
  450.     callExe    AllocVec
  451.     move.l    d0,bmp2pointer
  452.     beq.s    .exitsequence
  453.  
  454.     lea    bm,a0
  455.     move.l    bmp1pointer,d3
  456.     lea    bm2,a1
  457.     move.l    bmp2pointer,d4
  458.  
  459.     move.l    #SCREEN_WIDTH*SCREEN_HEIGHT/8,d0
  460.     move.w    #8-1,d1
  461. .setplanes
  462.     move.l    d3,(a0)+
  463.     add.l    d0,d3
  464.     move.l    d4,(a1)+
  465.     add.l    d0,d4
  466.     dbf    d1,.setplanes
  467.  
  468.     ;Open AGA screen.
  469.     move.l    #0,a0
  470.     lea.l    agascreentags(pc),a1
  471.     callInt    OpenScreenTagList
  472.     move.l    d0,_screen    
  473.     beq.w    .nowindow
  474.  
  475.     ;Put BitMap1 into _Screen->ViewPort.RasInfo
  476.     move.l  _screen,a0
  477.     move.l  sc_ViewPort+vp_RasInfo(a0),a1
  478.     move.l  #BitMap1,ri_BitMap(a1)
  479.  
  480.         ;Initialize C2P routine
  481.     jsr    _InitC2P
  482.  
  483.  
  484.     ;do for both AGA and CGX
  485. .both
  486.     ;WINDOW mode?
  487.         tst.b    _WIN
  488.         beq.s    .bkwin
  489.  
  490.     ;Yep...Lock public screen
  491.         lea    argarray,a0
  492.     move.l    ARG_PUBSCREEN(a0),a0
  493.     move.l    a0,pubscr
  494.         callInt    LockPubScreen
  495.         move.l    d0,pubscrlock
  496.         beq.s    .cgx    ;can't lock pub screen, try cgx screen
  497.  
  498.         ;Check if pub screen has 8+ bits depth
  499.            move.l    pubscrlock,a0
  500.         move.l    sc_RastPort+rp_BitMap(a0),a0
  501.         move.l    #BMA_DEPTH,d1
  502.         callGfx    GetBitMapAttr
  503.     cmp.l    #8,d0
  504.         ble.s    .nowindow
  505.     
  506.         move.l    pubscrlock,_screen
  507.  
  508.         ;Center window
  509.         move.l    _screen,a0
  510.         moveq    #0,d0
  511.         move.l    d0,d1
  512.         move.w    sc_Width(a0),d0
  513.         sub.w    #SCREEN_WIDTH,d0
  514.         lsr.w    #1,d0
  515.         move.l    d0,wleft
  516.         move.w    sc_Height(a0),d1
  517.         sub.w    #SCREEN_HEIGHT,d1
  518.         lsr.w    #1,d1
  519.         move.l    d1,wtop
  520.  
  521.         ;Open window
  522.     sub.l    a0,a0
  523.         lea    windowtags(pc),a1
  524.     callInt    OpenWindowTagList
  525.     move.l    d0,_window
  526.     beq.w    .nowindow
  527.  
  528.  
  529.     ;Unlock public screen
  530.         move.l    pubscrlock,a1
  531.         sub.l    a0,a0
  532.         callInt    UnlockPubScreen
  533.         move.l    #0,pubscrlock
  534.     bra.s    .nnx
  535.  
  536.  
  537. .bkwin  ;Nope...backdrop window
  538.     sub.l    a0,a0
  539.     lea    bkwindowtags(pc),a1
  540.     callInt    OpenWindowTagList
  541.     move.l    d0,_window
  542.     beq.w    .nowindow
  543.  
  544. .nnx
  545.         ;Set nfsc if NOFRONTSCREENCHECK switch is used
  546. .argts
  547.     lea    argarray,a0
  548.         move.b    ARG_NOCHK(a0),_nfsc
  549.  
  550.         ;Create timer
  551.     callExe    CreateMsgPort
  552.     move.l    d0,TimerMP
  553.     beq.w    .nomp
  554.  
  555.     move.l    TimerMP,a0
  556.     move.l    #IOTV_SIZE,d0
  557.     callExe    CreateIORequest
  558.     move.l    d0,TimerIO
  559.     beq.s    .noio
  560.  
  561.     lea    TimerName,a0
  562.     move.l    #UNIT_MICROHZ,d0    ;UNIT_VBLANK,d0
  563.     move.l    TimerIO,a1
  564.     moveq.l    #0,d1
  565.     callExe    OpenDevice
  566.     tst.l    d0
  567.     bne.s    .nodev
  568.  
  569.     ;Allocate double buffering structure
  570.     move.l    _screen,a0
  571.     lea    sc_ViewPort(a0),a0
  572.     callGfx    AllocDBufInfo
  573.     move.l    d0,mydbi
  574.     beq.s    .exitsequence
  575.  
  576.     ;Create message ports for double buffering
  577.     callExe    CreateMsgPort
  578.     move.l    d0,safewrite
  579.     beq.s    .exitsequence
  580.         move.l    mydbi(pc),a0
  581.     move.l    d0,(dbi_SafeMessage+MN_REPLYPORT)(a0)
  582.  
  583.     callExe    CreateMsgPort
  584.     move.l    d0,safeswap
  585.     beq.s    .exitsequence
  586.     move.l    mydbi(pc),a0
  587.     move.l    d0,(dbi_DispMessage+MN_REPLYPORT)(a0)
  588.  
  589.     ;Allocate signal for first screen
  590.     moveq    #-1,d0
  591.     callExe    AllocSignal
  592.         moveq    #0,d1
  593.     bset    d0,d1
  594.     move.l    d0,_thisTasksig
  595.     move.l    d1,_thisTasksigf
  596.  
  597.     ;Start interrupt
  598.         move.l    limitfps,d0
  599.         bgt.s    .validlimit
  600.         move.l    #50,d0
  601. .validlimit
  602.     move.l    #1000000,d1
  603.         divu.l    d0,d1
  604.         move.l    d1,_si_micro
  605.         move.l    #0,_si_secs
  606.     lea    _SoftIRQ,a0
  607.     move.l    a0,_si_func
  608.     bsr    _StartSoftInt
  609.  
  610.     jsr     _InitPreDEMO
  611.         jsr     _Main
  612.     IFNE    MUSIC
  613.         jsr     _StopPlayer
  614.     ENDC
  615.  
  616. .exitsequence
  617.     ;Remove soft IRQ
  618.     bsr    _StopSoftInt
  619.  
  620.     ;Free signal
  621.     move.l    _thisTasksig,d0
  622.     cmp.l    #-1,d0
  623.     beq.s    .wasnosignal
  624.     callExe    FreeSignal
  625. .wasnosignal
  626.  
  627.         ;Remove double buffering resources
  628. .while2
  629.     move.l  safeswap,a0
  630.     tst.l    a0
  631.     beq.s    .safe2swap
  632.  
  633.     tst.w    safe2swap
  634.     bne.s    .safe2swap
  635.  
  636.     move.l  safeswap,a0
  637.     callExe    GetMsg
  638.     tst.l    d0
  639.     bne.s   .safe2swap
  640.     moveq    #0,d0
  641.     move.l    d0,d1
  642.     move.l    safeswap,a0
  643.     move.b    MP_SIGBIT(a0),d1
  644.     bset    d1,d0
  645.     callExe    Wait
  646.     bra.s    .while2
  647. .safe2swap
  648. .while1
  649.     move.l  safewrite,a0
  650.     tst.l    a0
  651.     beq.s    .safe2write
  652.  
  653.     tst.w    safe2write
  654.     bne.s    .safe2write
  655.     
  656.         move.l  safewrite,a0
  657.     callExe    GetMsg
  658.     tst.l    d0
  659.     bne.s   .safe2write
  660.     moveq    #0,d0
  661.     move.l    d0,d1
  662.     move.l    safewrite,a0
  663.     move.b    MP_SIGBIT(a0),d1
  664.     bset    d1,d0
  665.     callExe    Wait
  666.     bra.s    .while1
  667. .safe2write
  668.     move.l    safeswap,a0
  669.     tst.l    a0
  670.     beq.s    .noswapmsg
  671.     callExe    DeleteMsgPort
  672. .noswapmsg
  673.     move.l    safewrite,a0
  674.     tst.l    a0
  675.     beq.s    .nowritemsg
  676.     callExe    DeleteMsgPort
  677. .nowritemsg
  678.     move.l    mydbi,a1
  679.     tst.l    a1
  680.     beq.s    .nodbi
  681.     callGfx    FreeDBufInfo
  682. .nodbi
  683.  
  684.     ;Remove timer
  685.         move.l    TimerIO,a1
  686.     tst.l    a1
  687.     beq.s    .nodev
  688.     callExe    CloseDevice
  689. .nodev
  690.     move.l    TimerIO,a0
  691.     tst.l    a0
  692.     beq.s    .noio
  693.     callExe    DeleteIORequest
  694. .noio
  695.     move.l    TimerMP,a0
  696.     tst.l    a0
  697.     beq.s    .nomp
  698.     callExe    DeleteMsgPort
  699. .nomp
  700.  
  701.     ;Close window
  702.     tst.l    _window
  703.     beq.s    .nowindow
  704.     move.l    _window,a0
  705.     callInt    CloseWindow
  706. .nowindow
  707.  
  708.     ;Unlock public screen
  709.         move.l    pubscrlock,a1
  710.         tst.l    a1
  711.         beq.s    .nopubscrlock
  712.         sub.l    a0,a0
  713.         callInt    UnlockPubScreen
  714. .nopubscrlock
  715. .notcgxmap
  716.     ;Close screen
  717.         tst.l    _screen
  718.         beq.s    .noscreen
  719.         tst.b    _WIN
  720.         bne.s    .noscreen
  721.     move.l    _screen,a0
  722.     callInt    CloseScreen
  723. .noscreen
  724.  
  725.     
  726.         ;Deallocate CHIP memory
  727.     move.l    bmp1pointer,a1
  728.     tst.l    a1
  729.     beq.s    .notmem1
  730.     callExe    FreeVec
  731. .notmem1
  732.     move.l    bmp2pointer,a1
  733.     tst.l    a1
  734.     beq.s    .notmem2
  735.     callExe    FreeVec
  736. .notmem2
  737.     
  738.         ;Close cybergraphics.library
  739.     tst.l    _CyberGfxBase
  740.         beq.s    .wasnocyber
  741.     move.l    _CyberGfxBase(pc),a1
  742.     callExe    CloseLibrary
  743. .wasnocyber
  744.         ;Close graphics.library
  745.     move.l    _GfxBase(pc),a1
  746.     callExe    CloseLibrary
  747. .nogfx
  748.         ;Close intuition.library
  749.     move.l    _IntuitionBase(pc),a1
  750.     callExe    CloseLibrary
  751. .noint
  752.     ;Free icon
  753.         move.l    diskobject,a0
  754.         tst.l    a0
  755.         beq.s    .nodskobj
  756.         callIco    FreeDiskObject
  757. .nodskobj
  758.         ;Close icon.library
  759.     move.l    _IconBase(pc),a1
  760.         tst.l    a1
  761.         beq.s    .noicon
  762.     callExe    CloseLibrary
  763. .noicon
  764.  
  765.         ;Free arguments
  766.         move.l    rdargs,d1
  767.         beq.s    .noargs
  768.         callDos    FreeArgs
  769. .noargs
  770.         ;Close dos.library
  771.     move.l    _DosBase(pc),a1
  772.     callExe    CloseLibrary
  773. .nodos
  774.  
  775.     tst.l    returnMsg
  776.     beq.s    exitToDOS
  777.     callExe    Forbid
  778.     move.l    returnMsg(pc),a1
  779.     callExe    ReplyMsg
  780. exitToDOS
  781.     moveq    #0,d0
  782.     rts
  783. ;///
  784.  
  785. ;///Data
  786. returnMsg    dc.l     0
  787. _thisTask    dc.l    0
  788. _thisTasksig    dc.l    -1
  789. _thisTasksigf    dc.l    0
  790. curdir        dc.l    0
  791.  
  792. _IntuitionBase    dc.l    0
  793. _GfxBase    dc.l    0
  794. _DosBase    dc.l    0
  795. _CyberGfxBase    dc.l    0
  796. _IconBase    dc.l    0
  797. TimerMP        dc.l    0
  798. TimerIO        dc.l    0
  799.  
  800. TimerName    dc.b    "timer.device",0
  801. IntName        dc.b    "intuition.library",0
  802. GfxName        dc.b    "graphics.library",0
  803. DosName        dc.b    "dos.library",0
  804. CyberName    dc.b    "cybergraphics.library",0
  805. IconName    dc.b    "icon.library",0
  806.     even
  807.  
  808. bestcmodeidtaglist
  809.         dc.l    CYBRBIDTG_Depth,8
  810.     dc.l    CYBRBIDTG_NominalWidth,SCREEN_WIDTH
  811.     dc.l    CYBRBIDTG_NominalHeight,SCREEN_HEIGHT
  812.     dc.l    TAG_END
  813.  
  814. cgxinfotaglist
  815.         dc.l    LBMI_WIDTH,cgxbitmap_width
  816.         dc.l    LBMI_HEIGHT,cgxbitmap_height
  817.         dc.l    LBMI_DEPTH,cgxbitmap_depth
  818.         dc.l    LBMI_PIXFMT,cgxbitmap_pixfmt
  819.     dc.l    LBMI_BYTESPERPIX,cgxbitmap_bytesperpix
  820.     dc.l    LBMI_BYTESPERROW,cgxbitmap_bytesperrow
  821.     dc.l    LBMI_BASEADDRESS,cgxbitmap_baseaddress
  822.     dc.l    TAG_END
  823.  
  824. cgxbitmaplock    dc.l    0
  825.  
  826. cgxbitmap_width        dc.l    0
  827. cgxbitmap_height    dc.l    0
  828. cgxbitmap_depth        dc.l    0
  829. cgxbitmap_pixfmt    dc.l    0
  830. cgxbitmap_bytesperpix    dc.l    0
  831. cgxbitmap_bytesperrow    dc.l    0
  832. cgxbitmap_baseaddress    dc.l    0
  833.  
  834. cgxscreentags
  835.     dc.l    SA_DisplayID
  836. cgxmode    dc.l    0
  837.     dc.l    SA_Left
  838. cgxscrl    dc.l    0
  839.     dc.l    SA_Top
  840. cgxscrt    dc.l    0
  841.     dc.l    SA_Width,SCREEN_WIDTH
  842.     dc.l    SA_Height
  843. cgxscrh dc.l    SCREEN_HEIGHT*2
  844.     dc.l    SA_Depth,8
  845.     dc.l    SA_Quiet,1
  846.     dc.l    SA_Colors32,blackpal
  847.     dc.l    SA_ShowTitle,0
  848.     dc.l    SA_Draggable,0
  849.     dc.l    TAG_END
  850.  
  851. agascreentags
  852.     dc.l    SA_DisplayID,LORES_KEY
  853.     dc.l    SA_Left
  854. agascrl    dc.l    0
  855.     dc.l    SA_Top
  856. agascrt    dc.l    0
  857.     dc.l    SA_Width,SCREEN_WIDTH
  858.     dc.l    SA_Height,SCREEN_HEIGHT
  859.     dc.l    SA_Depth,8
  860.     dc.l    SA_ShowTitle,FALSE
  861.     dc.l    SA_BitMap,BitMap1
  862.     dc.l    SA_Quiet,TRUE
  863.     dc.l    SA_Type,CUSTOMSCREEN
  864.     dc.l    SA_Colors32,blackpal
  865.     dc.l    SA_Draggable,FALSE
  866.     dc.l    TAG_END
  867.  
  868. BitMap1:
  869.     dc.w    SCREEN_WIDTH/8,SCREEN_HEIGHT,8,0
  870. bm    dcb.l    9
  871.  
  872. BitMap2:
  873.     dc.w    SCREEN_WIDTH/8,SCREEN_HEIGHT,8,0
  874. bm2    dcb.l    9
  875.  
  876. bmp1pointer    dc.l    0
  877. bmp2pointer    dc.l    0
  878.  
  879. safeswap    dc.l    0
  880. safewrite    dc.l    0
  881.  
  882. mydbi        dc.l    0
  883.  
  884. safe2swap    dc.w    1
  885. safe2write    dc.w    1
  886.  
  887. rectangle    ds.b    ra_SIZEOF
  888.  
  889.     ;Backdrop window
  890. bkwindowtags
  891.     dc.l    WA_Top,0
  892.     dc.l    WA_Left,0
  893.     dc.l    WA_Width
  894. winwi    dc.l    SCREEN_WIDTH
  895.     dc.l    WA_Height
  896. winh8   dc.l    SCREEN_HEIGHT
  897.     dc.l    WA_CustomScreen
  898. _screen    dc.l    0
  899.     dc.l    WA_NoCareRefresh,TRUE
  900.     dc.l    WA_Backdrop,TRUE
  901.     dc.l    WA_Borderless,TRUE
  902.     dc.l    WA_Activate,TRUE
  903.     dc.l    WA_Pointer,pointer
  904.     dc.l    WA_RMBTrap,TRUE
  905.     dc.l    WA_IDCMP,IDCMP_MOUSEBUTTONS
  906.     dc.l    TAG_END
  907.  
  908.     ;Window on WB screen
  909. windowtags
  910.     dc.l    WA_Top
  911. wtop    dc.l    0
  912.     dc.l    WA_Left
  913. wleft    dc.l    0
  914.     dc.l    WA_InnerWidth
  915.     dc.l    SCREEN_WIDTH
  916.     dc.l    WA_InnerHeight
  917.     dc.l    SCREEN_HEIGHT
  918.     dc.l    WA_NoCareRefresh,TRUE
  919.     dc.l    WA_Borderless,FALSE
  920.     dc.l    WA_Activate,TRUE
  921.         dc.l    WA_DepthGadget,TRUE
  922.         dc.l    WA_CloseGadget,TRUE
  923.         dc.l    WA_DragBar,TRUE
  924.     dc.l    WA_IDCMP,IDCMP_CLOSEWINDOW
  925.     dc.l    WA_RMBTrap,TRUE
  926.         dc.l    WA_Title,wintitle
  927.         dc.l    WA_PubScreenName
  928. pubscr    dc.l    0
  929.     dc.l    TAG_END
  930.  
  931. wintitle    
  932.     dc.b    "Happy Go Fucked Up",0
  933.     even
  934.  
  935. _window    dc.l    0
  936.  
  937. pubscrlock
  938.     dc.l    0
  939.  
  940. blackpal
  941.     dc.w    256,0
  942.     dcb.l    256*3
  943.     dc.w    0
  944.  
  945. pointer
  946.     dc.l    nullpointer
  947.     dcb.w    8
  948.  
  949. limitfps    dc.l    50    ;DEFAULT LIMIT 50fps!
  950.  
  951. rdargs        dc.l    0
  952. argarray    ds.l    ARG_Count+1
  953. template
  954.     dc.b    "SCREENMODE=SM/S,AGA/S,WINDOW=WIN/S,PUBSCREEN=PUB/K,NOFRONTSCREENCHECK=NOCHK/S,LIMITFPS/N",0
  955.     even
  956.  
  957. programname    dc.l    0
  958.  
  959. diskobject    ds.b    do_SIZEOF
  960.  
  961. TT_SCREENMODE    dc.b    "SCREENMODE",0
  962. TT_AGA        dc.b    "AGA",0
  963. TT_WINDOW    dc.b    "WINDOW",0
  964. TT_NOCHK    dc.b    "NOFRONTSCREENCHECK",0
  965. TT_LIMITFPS    dc.b    "LIMITFPS",0
  966. TT_PUBSCREEN    dc.b    "PUBSCREEN",0
  967.  
  968. WB    dc.b    0
  969. _nfsc    dc.b    0
  970. _WIN    dc.b    0
  971.     even
  972. _CPU    dc.l    0
  973. _FPU    dc.l    0
  974. _CGX    dc.w    0
  975. ;///
  976.  
  977. ;///determinePU
  978. determinePU
  979.     ;Determine CPU type
  980.     move.l    $4.w,a6
  981.     move.w    AttnFlags(a6),d0
  982.     move.l    #68000,_CPU
  983.     btst    #AFB_68010,d0
  984.     beq.s    .cpu68010
  985.     move.l    #68010,_CPU
  986. .cpu68010
  987.     btst    #AFB_68020,d0
  988.     beq.s    .cpu68020
  989.     move.l    #68020,_CPU
  990. .cpu68020
  991.     btst    #AFB_68030,d0
  992.     beq.s    .cpu68030
  993.     move.l    #68030,_CPU
  994. .cpu68030
  995.     btst    #AFB_68040,d0
  996.     beq.s    .cpu68040
  997.     move.l    #68040,_CPU
  998. .cpu68040
  999.     btst    #AFB_68060,d0
  1000.     beq.s    .cpu68060
  1001.     move.l    #68060,_CPU
  1002. .cpu68060
  1003.     ;Determine FPU type
  1004.     move.l    #0,_FPU
  1005.     btst    #AFB_68881,d0
  1006.     beq.s    .fpu68881
  1007.     move.l    #68881,_FPU
  1008. .fpu68881
  1009.     btst    #AFB_68882,d0
  1010.     beq.s    .fpu68882
  1011.     move.l    #68882,_FPU
  1012. .fpu68882
  1013.     btst    #AFB_FPU40,d0
  1014.     beq.b    .fpu68040
  1015.     btst    #AFB_68040,d0
  1016.     beq.b    .fpu68040
  1017.     move.l    #68040,_FPU
  1018. .fpu68040
  1019.     rts
  1020. ;///
  1021. ;///_gettime
  1022.     cnop    0,4
  1023. _gettime
  1024.     ;output:
  1025.     ; D0 = current time [1/500 seconds]
  1026.  
  1027.         move.l    TimerIO,a1
  1028.     move.w    #TR_GETSYSTIME,IO_COMMAND(a1)
  1029.  
  1030.     move.l    TimerIO,a1
  1031.     callExe    DoIO
  1032.  
  1033.     move.l    TimerIO,a0
  1034.     move.l    (IO_SIZE+TV_SECS)(a0),d0    ;seconds
  1035.     move.l    (IO_SIZE+TV_MICRO)(a0),d1    ;micros
  1036.  
  1037.     mulu.l    #500,d0
  1038.     divu.l    #2000,d1
  1039.  
  1040.         add.l    d1,d0
  1041.     rts
  1042. ;///
  1043. ;///getscreen
  1044.     cnop    0,4
  1045. getscreen
  1046.     ;output:
  1047.     ; A1 = PlanePtr of Undisplayed BitMap
  1048.     ; A2 = Undisplayed BitMap
  1049.     ; A3 = _Screen->Viewport.RasInfo
  1050.     move.l    _screen(pc),a3
  1051.     move.l    sc_ViewPort+vp_RasInfo(a3),a3
  1052.     move.l    #BitMap1,a2
  1053.     add.l    #BitMap2,a2
  1054.     sub.l    ri_BitMap(a3),a2
  1055.     move.l    bm_Planes(a2),a1
  1056.     rts
  1057. ;///
  1058. ;///_blit
  1059.     cnop    0,4
  1060. _blit
  1061.     ;A0 = chunky buffer
  1062.  
  1063.         tst.w    _WIN
  1064.         bne.s    windowblit
  1065.     tst.w    _CGX
  1066.     bne.s   cyberblit
  1067.  
  1068. agablit
  1069.     move.l    a0,a4
  1070.     ;input:    A4 = Chunky buffer
  1071.  
  1072.     movem.l    d0-a6,-(sp)
  1073.  
  1074.         tst.b    _nfsc
  1075.         bne.s    .skipfrontscreenwait
  1076.     
  1077.         move.l    _thisTasksigf,d0
  1078.         callExe    Wait
  1079.  
  1080. .skipfrontscreenwait
  1081.  
  1082.         tst.w    safe2write
  1083.     bne.s    .safe2write
  1084. .while1
  1085.     move.l  safewrite,a0
  1086.     callExe    GetMsg
  1087.     tst.l    d0
  1088.     bne.s   .safe2write
  1089.  
  1090.     move.l    safewrite,a0
  1091.     moveq    #0,d0
  1092.     move.l    d0,d1
  1093.     move.b    MP_SIGBIT(a0),d1
  1094.     bset    d1,d0
  1095.     callExe    Wait
  1096.  
  1097.     bra.s    .while1
  1098. .safe2write
  1099.     move.w    #TRUE,safe2write
  1100.     
  1101.     bsr.s    getscreen     ;a1 - planeptr
  1102.     move.l    a4,a0
  1103.     jsr    _C2P
  1104.  
  1105.     bsr.s    setpalette
  1106.  
  1107.         tst.w    safe2swap
  1108.     bne.s    .safe2swap
  1109. .while2
  1110.     move.l  safeswap,a0
  1111.     callExe    GetMsg
  1112.     tst.l    d0
  1113.     bne.s   .safe2swap
  1114.  
  1115.     moveq    #0,d1
  1116.     move.l    d1,d0
  1117.     move.l    safeswap,a0
  1118.     move.b    MP_SIGBIT(a0),d1
  1119.     bset    d1,d0
  1120.     callExe    Wait
  1121.  
  1122.     bra.s    .while2
  1123. .safe2swap
  1124.     move.w    #TRUE,safe2swap
  1125.     
  1126.     bsr.s   getscreen
  1127.     move.l  a2,a1
  1128.     move.l  _screen(pc),a0
  1129.     lea    sc_ViewPort(a0),a0
  1130.     move.l    mydbi,a2
  1131.     callGfx    ChangeVPBitMap
  1132.  
  1133.     move.w    #FALSE,safe2swap
  1134.     move.w    #FALSE,safe2write
  1135.  
  1136.     movem.l    (sp)+,d0-a6
  1137.     rts
  1138.  
  1139.  
  1140.     cnop    0,4
  1141. cyberblit
  1142.         movem.l    d0-a6,-(sp)
  1143.  
  1144.     move.l    a0,a2
  1145.     ;input:    A2 = Chunky buffer
  1146.  
  1147.         tst.b    _nfsc
  1148.         bne.s    .skipfrontscreenwait
  1149.  
  1150.     move.l    _thisTasksigf,d0
  1151.         callExe    Wait
  1152.  
  1153. .skipfrontscreenwait
  1154.  
  1155.         tst.w    safe2write
  1156.     bne.s    .safe2write
  1157. .while1
  1158.     move.l  safewrite,a0
  1159.     callExe    GetMsg
  1160.     tst.l    d0
  1161.     bne.s   .safe2write
  1162.  
  1163.     move.l    safewrite,a0
  1164.     moveq    #0,d0
  1165.     move.l    d0,d1
  1166.     move.b    MP_SIGBIT(a0),d1
  1167.     bset    d1,d0
  1168.     callExe    Wait
  1169.  
  1170.     bra.s    .while1
  1171. .safe2write
  1172.     move.w    #TRUE,safe2write
  1173.  
  1174.     bsr.s   setpalette
  1175.  
  1176.         ;Get CGX bitmap info by locking
  1177.         move.l    _screen,a0
  1178.         move.l    (sc_RastPort+rp_BitMap)(a0),a0
  1179.     lea    cgxinfotaglist(pc),a1
  1180.     callCgx    LockBitMapTagList
  1181.         move.l    d0,cgxbitmaplock
  1182.         beq.w    .nolock
  1183.  
  1184.     move.l    cgxbitmap_bytesperrow(pc),d1
  1185.     sub.l    #SCREEN_WIDTH,d1
  1186.     move.l    cgxbitmap_baseaddress(pc),a1
  1187.     tst.l    a1
  1188.     beq.w    .unlock
  1189.  
  1190.     tst.w    scrpart
  1191.     beq.s    .next
  1192.     add.l    cgxadd,a1
  1193. .next
  1194.     move.w  #SCREEN_WIDTH*SCREEN_HEIGHT/4/80-1,d0
  1195. .copy
  1196.     rept    80
  1197.     move.l  (a2)+,(a1)+
  1198.     endr
  1199.     add.l   d1,a1
  1200.     dbf     d0,.copy
  1201. .unlock
  1202.         ;Unlock CGX bitmap
  1203.         move.l    cgxbitmaplock(pc),a0
  1204.     callCgx    UnLockBitMap
  1205. .nolock
  1206.     
  1207.         tst.w    safe2swap
  1208.     bne.s    .safe2swap
  1209. .while2
  1210.     move.l  safeswap,a0
  1211.     callExe    GetMsg
  1212.     tst.l    d0
  1213.     bne.s   .safe2swap
  1214.  
  1215.     moveq    #0,d1
  1216.     move.l    d1,d0
  1217.     move.l    safeswap,a0
  1218.     move.b    MP_SIGBIT(a0),d1
  1219.     bset    d1,d0
  1220.     callExe    Wait
  1221.  
  1222.     bra.s    .while2
  1223. .safe2swap
  1224.     move.w    #TRUE,safe2swap
  1225.  
  1226.     move.l  _screen(pc),a0
  1227.     move.l    a0,a3
  1228.     move.l  (sc_ViewPort+vp_RasInfo)(a3),a3
  1229.     move.w  scrpart,ri_RyOffset(a3)
  1230.     lea     sc_ViewPort(a0),a0
  1231.     callGfx ScrollVPort
  1232.  
  1233.     move.l    _screen(pc),a0
  1234.     move.l    a0,a1
  1235.     lea    sc_ViewPort(a0),a0
  1236.     move.l    (sc_RastPort+rp_BitMap)(a1),a1
  1237.     move.l    mydbi,a2
  1238.     callGfx    ChangeVPBitMap
  1239.  
  1240.     move.w    #FALSE,safe2swap
  1241.     move.w    #FALSE,safe2write
  1242.  
  1243.     tst.w    scrpart
  1244.     beq.s    .xc
  1245.     clr.w   scrpart
  1246.     bra.s    .nxc
  1247. .xc
  1248.     move.w  cgxh8,scrpart
  1249. .nxc
  1250.     movem.l    (sp)+,d0-a6
  1251.     rts
  1252.  
  1253. scrpart    dc.w    0
  1254. cgxadd    dc.l    SCREEN_WIDTH*SCREEN_HEIGHT
  1255. cgxh8   dc.w    SCREEN_HEIGHT
  1256.  
  1257.  
  1258.     cnop    0,4
  1259. windowblit
  1260.         movem.l    d0-a6,-(sp)
  1261.  
  1262.     move.l    a0,a2
  1263.     ;input:    A2 = Chunky buffer
  1264.  
  1265.         tst.b    _nfsc
  1266.         bne.s    .skipfrontscreenwait
  1267.  
  1268.     move.l    _thisTasksigf,d0
  1269.         callExe    Wait
  1270.  
  1271. .skipfrontscreenwait
  1272.  
  1273.  
  1274.         tst.w    safe2write
  1275.     bne.s    .safe2write
  1276. .while1
  1277.     move.l  safewrite,a0
  1278.     callExe    GetMsg
  1279.     tst.l    d0
  1280.     bne.s   .safe2write
  1281.  
  1282.     move.l    safewrite,a0
  1283.     moveq    #0,d0
  1284.     move.l    d0,d1
  1285.     move.b    MP_SIGBIT(a0),d1
  1286.     bset    d1,d0
  1287.     callExe    Wait
  1288.  
  1289.     bra.s    .while1
  1290. .safe2write
  1291.     move.w    #TRUE,safe2write
  1292.  
  1293.  
  1294.     bsr.s    setpalette
  1295.  
  1296.         move.l    a2,a0           ;srcRect
  1297.         move.w    #0,d0            ;srcX
  1298.         move.w    d0,d1            ;srcY
  1299.         move.w    d0,d3
  1300.         move.w    d0,d4
  1301.         move.l    #SCREEN_WIDTH,d2        ;srcMod
  1302.         move.l    _window,a2
  1303.         move.l    wd_RPort(a2),a1      ;RastPort
  1304.         move.b    wd_BorderLeft(a2),d3    ;destX
  1305.     move.b    wd_BorderTop(a2),d4    ;destY
  1306.         move.w    #SCREEN_WIDTH,d5       ;width
  1307.         move.w    #SCREEN_HEIGHT,d6    ;height
  1308.         move.l    #CTABFMT_XRGB8,d7
  1309.         lea    winpal,a2
  1310.         callCgx    WriteLUTPixelArray
  1311.  
  1312.  
  1313.         tst.w    safe2swap
  1314.     bne.s    .safe2swap
  1315. .while2
  1316.     move.l  safeswap,a0
  1317.     callExe    GetMsg
  1318.     tst.l    d0
  1319.     bne.s   .safe2swap
  1320.  
  1321.     moveq    #0,d1
  1322.     move.l    d1,d0
  1323.     move.l    safeswap,a0
  1324.     move.b    MP_SIGBIT(a0),d1
  1325.     bset    d1,d0
  1326.     callExe    Wait
  1327.  
  1328.     bra.s    .while2
  1329. .safe2swap
  1330.     move.w    #TRUE,safe2swap
  1331.  
  1332.     move.l    _screen(pc),a0
  1333.     move.l    a0,a1
  1334.     lea    sc_ViewPort(a0),a0
  1335.     move.l    (sc_RastPort+rp_BitMap)(a1),a1
  1336.     move.l    mydbi,a2
  1337.     callGfx    ChangeVPBitMap
  1338.  
  1339.     move.w    #FALSE,safe2swap
  1340.     move.w    #FALSE,safe2write
  1341.  
  1342.         movem.l    (sp)+,d0-a6
  1343.  
  1344.     rts
  1345.  
  1346. ;///
  1347. ;///setpalette
  1348.     cnop    0,4
  1349. setpalette
  1350.     ;Set palette address to _newpal
  1351.     ;Palette format is RRGGBB
  1352.     movem.l    d0-d2/a0-a2/a6,-(sp)
  1353.     
  1354.         move.l    _newpal(pc),a0
  1355.     tst.l    a0
  1356.     beq.s    .out
  1357.  
  1358.         tst.b    _WIN
  1359.         beq.s    .notwin
  1360.  
  1361.         move.w    #256-1,d0
  1362.     lea    winpal+1,a1
  1363. .wl    move.w    (a0)+,(a1)+
  1364.     move.b    (a0)+,(a1)
  1365.         addq.w    #2,a1
  1366.     dbf    d0,.wl
  1367.  
  1368.         bra.s    .out
  1369. .notwin
  1370.         lea    .data(pc),a1
  1371.     lea    4(a1),a2
  1372.     move.w    #256-1,d2
  1373. .loop:    move.b    (a0)+,(a2)
  1374.     addq.l    #4,a2
  1375.     move.b    (a0)+,(a2)
  1376.     addq.l    #4,a2
  1377.     move.b    (a0)+,(a2)
  1378.     addq.l    #4,a2
  1379.     dbf    d2,.loop
  1380.  
  1381.     move.l    _screen,a0
  1382.     lea    sc_ViewPort(a0),a0
  1383.     callGfx    LoadRGB32
  1384. .out
  1385.     move.l    #0,_newpal
  1386.     movem.l    (sp)+,d0-d2/a0-a2/a6
  1387.     rts
  1388. .data:
  1389.     dc.w    256,0   
  1390.     dcb.l    256*3
  1391.     dc.l    0
  1392.  
  1393. winpal
  1394.     dcb.l    256
  1395.  
  1396. _newpal    dc.l    0
  1397.  
  1398. ;///
  1399. ;///_cls
  1400.     cnop    0,4
  1401. _cls
  1402.     ;Clear SCREEN_WIDTH x SCREEN_HEIGHT area
  1403.     moveq    #0,d1
  1404.     lea    _chunky,a0
  1405.     move.l    #SCREEN_WIDTH*SCREEN_HEIGHT/4/16-1,d0
  1406. .l1
  1407.     rept    16
  1408.     move.l    d1,(a0)+
  1409.     endr
  1410.     dbf    d0,.l1
  1411.     rts
  1412. ;///
  1413.  
  1414. ;///Pointer Data
  1415.     section killdabastard, data_c
  1416.     cnop    0,8
  1417. nullpointer
  1418.     dcb.w    20
  1419. ;///
  1420.