home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / assembler / thesource / volume1 / source / scrollers / turnscroll.lha / TurnScroll.Good.S < prev    next >
Encoding:
Text File  |  1992-12-31  |  12.4 KB  |  460 lines

  1. * This source is a fixed version of Turnscroll.s.  It does the same thing,
  2. * but it has some fixes in it.  First of all, I took out all of the clr's
  3. * to custom chip registers.  THIS IS A NO-NO!  Never do something like
  4. * this:
  5. *        clr.l    $dff064        ; bltdmod (12 cpu cycles +16 for
  6. *                    ;   addr. calc time = 28 clocks)
  7. * This will clear the register fast, but can cause wierd effects because
  8. * all custom chip registers are either read or write.  On a 68000, a clr
  9. * does both a read and a write!  In the original code there are about 15
  10. * clr's like this.  A better way is the following:
  11. *        moveq    #0,d0        ; 4 cycles
  12. *        move.l    d0,$dff064    ; 20 cycles
  13. * Notice the total is LESS than with the clr.
  14. *
  15. * I also fixed the use of self modifing code.  In the original source
  16. * the following appeared:
  17. *        dc.w    $4ef9
  18. * oldirq:    dc.l    0
  19. * What he would do is take the old level three interrupt pointer and write
  20. * it to oldirq.  This would cause it and the previous word to for this:
  21. *        jmp    (whatever he writes here)
  22. * Now, this works just fine, unless you have an instruction cache.  Why?
  23. * The code is fetched while it is still like this:
  24. *        jmp    $0
  25. * Jumping to address 0 is not a very desirable thing to do. :^) The "correct"
  26. * way to do this is have the following:
  27. *        move.l    oldirq,-(sp)
  28. *        rts
  29. * oldirq:    dc.l    0
  30. * Go ahead and write the old int add to old irq.  What happens now, is
  31. * you make that you return address and "return" to that location.  This
  32. * will work on any Amiga.
  33. *
  34. * Another thing that I fixed is the way he waits for the blitter to finish.
  35. * Originally he would do this:
  36. *
  37. * wblit:        btst    #14,$dff02
  38. *            bne.b    wblit
  39. *
  40. * First off, a btst on a memory location is a btst.b, so this is actually
  41. * this:
  42. *            btst.b    #6,$dff002
  43. * Secondly, for compatability with older Agnuses (Agni? :) ) you should
  44. * test it once, ignore that test, and do it again.  If you look at the
  45. * function WaitBlit() in ROM, you will see something more like this:
  46. *             tst.b    $dff002
  47. * wblit:        btst.b    #6,$dff002
  48. *            bne.b    wblit
  49. *
  50. * The last thing that I fixed was the installation of the level 3 int.  Here
  51. * two errors were made.  First of all was the infamous VBR.  On processors
  52. * from a 68010 and up the interrupt vector table can be moved ANYWHERE in
  53. * memory.  By just poking to $6c, you may not be installing an interrupt
  54. * at all!  There is a handy register on these processors called the VBR or
  55. * Vector Base Register.  The routine GetVBR determines if the VBR exists,
  56. * and if it does, determines what it is.
  57. *
  58. * The other error in his interrupt installer is that he left interrupts
  59. * enabled will saveing/installing/restoring the interrupt.  Bad move!  Under
  60. * certain curcumstances if an interrupt is triggered while you are installing,
  61. * you can end up in outer space!
  62. ***********************************************************
  63. * Equates
  64. ***********************************************************
  65.  
  66. offset        EQU    50*34
  67.  
  68. charheight2    EQU    16        ; Height of 1 char in lines
  69. charwidth21    EQU    4        ; Width of 1 char in bytes
  70. planes2        EQU    1        ; Nr of Planes
  71. charsproline2    EQU    10        ; Chars pro line
  72. linewidth2    EQU    40        ; Bytes pro line
  73. charwidth22    EQU    charwidth21/2     ; Need this because SEKA doesn't know
  74.                     ; the normal math rules...!!! 
  75.  
  76. charheight    EQU    34        ; Height of 1 char in lines
  77. charwidth    EQU    4        ; Width of 1 char in bytes
  78. planes        EQU    1        ; Nr of Planes
  79. charsproline    EQU    10        ; Chars pro line
  80. linewidth    EQU    40         ; Bytes pro line
  81. charwidth2    EQU    charwidth/2     ; Need this because SEKA doesn't know
  82.                     ; the normal math rules...!!! 
  83.  
  84. AttnFlags    EQU    296        ; offset of exec base
  85.  
  86. ***********************************************************
  87.  
  88.         section    thecode,code
  89.  
  90. start:        bsr.w    initcop
  91.  
  92.         movea.l    4.w,a6            ; exec base
  93.         jsr    -132(a6)        ; Forbid()
  94.         jsr    -120(a6)        ; Disable()
  95.  
  96.         lea    gfxname,a1
  97.         jsr    -408(a6)        ; OldOpenLibrary
  98.         move.l    d0,gfxbase        ; save ptr to gfx base
  99.         move.l    d0,a6
  100.         jsr    -456(a6)        ; OwnBlitter()
  101.  
  102.         lea    $dff002,a5        ; custom chip base + 2
  103.         bsr.w    waitblt            ; wait for the blitter
  104.  
  105.         move.l    #newcop,$80-2(a5)    ; install our copper
  106.  
  107.         move.l    a5,-(sp)
  108.         bsr.b    GetVBR
  109.         move.l    (sp)+,a5
  110.  
  111.         move.l    $6c(a0),oldirq        ; save old level 3 int
  112.         move.l    #newirq,$6c(a0)        ; install our level 3 int
  113.  
  114.         movea.l    4.w,a6            ; exec base
  115.         jsr    -126(a6)        ; Enable()
  116.  
  117. .wait:        btst.b    #6,$bfe001        ; wait for the lmb
  118.         bne.s    .wait
  119.  
  120.         movea.l    4.w,a6
  121.         jsr    -120(a6)        ; Disable()
  122.         move.l    VectorBase,a0        ; vbr
  123.         move.l    oldirq,$6c(a0)        ; reinstall the old level 3 int
  124.         movea.l    4.w,a6
  125.         jsr    -126(a6)        ; Enable()
  126.  
  127.         move.l    gfxbase,a6        ; ptr to gfxbase
  128.         move.l    $26(a6),$80-2(a5)    ; install system copper
  129.         jsr    -462(a6)        ; DisOwnBlitter()
  130.  
  131.         move.l    a6,a1
  132.         movea.l    4.w,a6            ; exec base
  133.         jsr    -414(a6)        ; CloseLibrary()
  134.         move.w    #$8020,$96-2(a5)    ; enable sprite DMA
  135.  
  136.         jmp    -138(a6)        ; Permit()
  137.         ; the function Permit() will return us to the OS because we
  138.         ; didn't put a return address on the stack.  Call me nasty. :)
  139.                         
  140. ***********************************************************
  141.  
  142. GetVBR:        moveq    #0,d0            ; clear
  143.         movea.l    4.w,a6            ; exec base
  144.         btst.b    #0,AttnFlags+1(a6)    ; are we at least a 68010?
  145.         beq.b    .1            ; nope.
  146.         lea.l    vbr_exception(pc),a5    ; addr of function to get VBR
  147.         jsr    -30(a6)            ; Supervisor()
  148. .1:        move.l    d0,a0
  149.         move.l    d0,VectorBase
  150.         rts                ; return
  151.  
  152. vbr_exception:
  153.     ; movec vbr,Xn is a priv. instr.  You must be supervisor to execute!
  154. ;        movec   vbr,d0
  155.     ; many assemblers don't know the VBR, if yours doesn't, then use this
  156.     ; line instead.
  157.         dc.w    $4e7a $0801
  158.         rte                ; back to user state code
  159.  
  160. ***********************************************************
  161.  
  162. initcop:    move.l    #offset+scrplane,d0
  163.         move.w    d0,scrpl+6
  164.         move.w    d0,scrpl+14
  165.         swap    d0
  166.         move.w    d0,scrpl+2
  167.         move.w    d0,scrpl+10
  168.  
  169.         move.l    #scrplane2,d0
  170.         move.w    d0,scrpl+22
  171.         swap    d0
  172.         move.w    d0,scrpl+18
  173.         rts
  174.  
  175. ***********************************************************
  176.  
  177. newirq:        movem.l    d0-d7/a0-a6,-(a7)
  178.         bsr.L    scroll
  179.         bsr.L    scrollup
  180.         bsr.s    scroll2
  181.         movem.l    (a7)+,d0-d7/a0-a6
  182.         move.l    oldirq,-(sp)
  183.         rts
  184.  
  185. ***********************************************************
  186.  
  187. scroll2:    bsr    waitblt
  188.         moveq    #-1,d0
  189.         move.w    speed12,$40-2(a5)
  190.         move.w    #0,$42-2(a5)
  191.         move.l    d0,$44-2(a5)
  192.  
  193.         move.l    #plane,d0
  194.         move.l    d0,$54-2(a5)
  195.  
  196.         add.l    speed32,d0
  197.         move.l    d0,$50-2(a5)
  198.         move.l    #0,$64-2(a5)
  199.         move.w    #(charheight2*64*planes2)+25,$58-2(a5)
  200.         bsr.L    waitblt
  201.  
  202. noscr2:        subq.b    #1,scrcount2
  203.         beq.s    newtext2
  204.         rts
  205.  
  206. ***********************************************************
  207.  
  208. newtext2:    move.b    speed22,scrcount2
  209.         addq.l    #1,stringpointer2
  210.         move.l    stringpointer2,a0
  211.         clr.w    d0
  212.         move.b    (a0),d0
  213.         cmpi.b    #32,d0
  214.         bne    nspace2
  215.         clr.w    d0
  216.         move.w    #$0900,$40-2(a5)
  217.         bra.s    space2
  218. nspace2:    move.l    #font2,d1
  219.         sub.b    #48,d0
  220.         cmpi.b    #48,d0
  221.         bgt.s    speedchange2
  222. ddd2:        cmpi.b    #charsproline2,d0 
  223.         blt.s    eerste2
  224.         add.l    #charheight2*linewidth2*planes2,d1
  225.         sub.b    #charsproline2,d0
  226.         bra.s    ddd2
  227. eerste2:    move.w    #$09f0,$40-2(a5)    ;BLTCON0
  228. space2:        mulu    #charwidth21,d0
  229.         add.l    d1,d0
  230.         move.l    d0,$50-2(a5)            ;SOURCE A
  231.         move.l    #plane+46,$54-2(a5)        ;DEST D
  232.         move.w    #0,$42-2(a5)            ;BLTCON1
  233.         move.w    #linewidth2-charwidth21,$64-2(a5) ; MOD A
  234.         move.l    #-1,$44-2(a5)            ;MASK
  235.         move.w    #50-charwidth21,$66-2(a5)    ;MOD  D
  236.         move.w    #(charheight2*planes2*64)+charwidth22,$58-2(a5)
  237.         bsr.L    waitblt
  238.  
  239.         cmp.l    #endstring2,stringpointer2
  240.         bne.s    notend2
  241.         move.l    #string2,stringpointer2
  242. notend2:    rts
  243.  
  244. ***********************************************************
  245.  
  246. speedchange2:    sub.b    #49,d0
  247.         mulu    #3,d0
  248.         lea    speedlist,a0
  249.         move.b    (a0,d0.w),speed12
  250.         move.b    2(a0,d0.w),d1
  251.         ext.w    d1
  252.         ext.l    d1
  253.         move.l    d1,speed32
  254.         move.b    1(a0,d0.w),speed22
  255.         bra.L    newtext2
  256.  
  257. scrollup:    bsr.L    waitblt
  258.         move.l    #$09f00000,$40-2(a5)
  259.         move.l    #$ffffffff,$44-2(a5)
  260.         move.l    #scrplane,$54-2(a5)    ;Dest
  261.         move.l    #scrplane+50,$50-2(a5)    ;Source
  262.         move.l    #$00040004,$64-2(a5)    ;Mod
  263.         move.w    #(charheight*planes*2*64)+23,$58-2(a5)
  264.  
  265.         bsr.L    waitblt
  266.         move.l    #$09f00000,$40-2(a5)
  267.         move.l    #$ffffffff,$44-2(a5)
  268.         move.l    #(34*50*2)+scrplane,$54-2(a5)    ;Dest
  269.         move.l    #scrplane,$50-2(a5)        ;Source
  270.         move.l    #0,$64-2(a5)            ;No Mod
  271.         move.w    #64+25,$58-2(a5)
  272.         bsr.L    waitblt
  273.         rts
  274.  
  275. ***********************************************************
  276.  
  277. scroll:        move.w    speed1,$40-2(a5)
  278.         move.w    #0,$42-2(a5)
  279.         move.l    #$ffffff00,$44-2(a5)
  280.         move.l    #scrplane,d0
  281.         move.l    d0,$54-2(a5)
  282.         add.l    speed3,d0
  283.         move.l    d0,$50-2(a5)
  284.         move.l    #0,$64-2(a5)
  285.         move.w    #(2*charheight*(planes+1)*64)+25,$58-2(a5)
  286.         bsr    waitblt
  287. noscr:        subq.b    #1,scrcount
  288.         beq.s    newtext
  289.         rts
  290.  
  291. ***********************************************************
  292.  
  293. newtext:    move.b    speed2,scrcount
  294.         addq.l    #1,stringpointer
  295.         move.l    stringpointer,a0
  296.         clr.w    d0
  297.         move.b    (a0),d0
  298.         cmpi.b    #32,d0
  299.         bne.s    nspace
  300.         clr.w    d0
  301.         move.w    #$0900,$40-2(a5)
  302.         bra.s    space
  303. nspace:        move.l    #font,d1
  304.         sub.b    #48,d0
  305.         cmpi.b    #48,d0
  306.         bgt.L    speedchange
  307. ddd:        cmpi.b    #charsproline,d0 
  308.         blt.s    eerste
  309.         add.l    #charheight*linewidth*planes,d1
  310.         sub.b    #charsproline,d0
  311.         bra.s    ddd
  312. eerste:        move.w    #$09f0,$40-2(a5)    ;BLTCON0
  313. space:        mulu    #charwidth,d0
  314.         add.l    d1,d0
  315.         move.l    d0,$50-2(a5)        ;SOURCE A
  316.         move.l    #offset+scrplane,d0
  317.         add.l    #46,d0
  318.         move.l    d0,$54-2(a5)        ;DEST D
  319.         move.w    #0,$42-2(a5)        ;BLTCON1
  320.         move.w    #linewidth-charwidth,$64-2(a5) ; MOD A
  321.         move.l    #-1,$44-2(a5)        ;MASK
  322.         move.w    #50-charwidth,$66-2(a5)    ;MOD  D
  323.         move.w    #charheight*planes*64+charwidth2,$58-2(a5)
  324.         bsr.s    waitblt
  325.  
  326.         cmp.l    #endstring,stringpointer
  327.         bne.s    notend
  328.         move.l    #string,stringpointer
  329. notend:        rts
  330.  
  331. ***********************************************************
  332.  
  333. waitblt:    tst.b    (a5)
  334. .1:        btst.b    #6,(a5)
  335.         bne.s    .1
  336.         rts
  337.  
  338. ***********************************************************
  339.  
  340. speedchange:    sub.b    #49,d0
  341.         mulu    #3,d0
  342.         lea    speedlist,a0
  343.         move.b    (a0,d0.w),speed1
  344.         move.b    2(a0,d0.w),d1
  345.         ext.w    d1
  346.         ext.l    d1
  347.         move.l    d1,speed3
  348.         move.b    1(a0,d0.w),speed2
  349.         bra.L    newtext
  350.  
  351. ***********************************************************
  352.  
  353.         section    nonchip_data,data
  354.  
  355. oldirq:        dc.l    0
  356. oldcop:        dc.l    0
  357. gfxbase:    dc.l    0
  358. VectorBase:    dc.l    0
  359.  
  360. stringpointer:    dc.l    string
  361. stringpointer2:    dc.l    string2
  362.  
  363. speed3:        dc.l        2
  364. speed1:        dc.w        $49f0
  365. speed2:        dc.b        8
  366. scrcount:    dc.b        1
  367.  
  368. speed32:    dc.l    2
  369. speed12:    dc.w    $49f0
  370. speed22:    dc.b    8
  371. scrcount2:    dc.b    1
  372.  
  373. speedlist:    dc.b    $09,64,0     ; Speed a
  374.         dc.b    $f9,32,2    ; Speed b
  375.         dc.b    $e9,16,2    ; Speed c
  376.         dc.b    $c9,8,2        ; Speed d
  377.         dc.b    $89,4,2        ; Speed e
  378.         dc.b    $09,2,2        ; Speed f
  379.         dc.b    $19,32,0    ; Speed g
  380.         dc.b    $29,16,0    ; Speed h
  381.         dc.b    $49,8,0        ; Speed i
  382.         dc.b    $89,4,0        ; Speed j
  383.         dc.b    $09,2,-2    ; Speed k
  384.         dc.b    $c9,3,2        ; Speed l
  385.  
  386. gfxname:    DC.B    "graphics.library",0
  387.  
  388. string:        DC.B    " dTHE TIMECIRCLE IN 1989 :::"
  389. endstring:    DC.B    32
  390.  
  391. string2:    DC.B    " cANOTHER SOFTY SCROLLER MADE BY BRIAN "
  392.         DC.B    "POSTMA FOR THE NEWSFLASH MAGAZINE ::: A "
  393.         DC.B    "BIG HI TO OUR FELLOW TAIPAN MEMBERS :::"
  394. endstring2:    DC.B    32
  395.  
  396. ***********************************************************
  397.  
  398.         section    chip_data,data_c
  399.  
  400. font:        incbin    'font1.raw'
  401. font2:        incbin    'font2.raw'
  402.  
  403. newcop:    dc.w    $0096,$0020,$0120,$0000,$0122,$0000
  404.     dc.w    $008e,$296a,$0090,$29fa,$0092,$0028
  405.     dc.w    $0094,$00d8,$0180,$0000,$0100,$0000
  406.     dc.w    $0102,$0000,$0104,$0000
  407.     dc.w    $0182,$0fff,$0108,$0004,$010a,-96
  408.  
  409.     dc.w    $018c,$0aaa,$0184,$0f00,$0186,$0fff
  410. scrpl:    dc.w    $e0,0,$e2,0,$e4,0,$e6,0,$e8,0,$ea,0
  411.     dc.w    $9001,$fffe,$0100,$3400
  412.     dc.w    $9007,$fffe,$182,$88,$192,$606
  413.     dc.w    $9107,$fffe,$182,$99
  414.     dc.w    $9207,$fffe,$182,$aa,$192,$707
  415.     dc.w    $9307,$fffe,$182,$bb
  416.     dc.w    $9407,$fffe,$182,$cc,$192,$808
  417.     dc.w    $9507,$fffe,$182,$dd
  418.     dc.w    $9607,$fffe,$182,$ee,$192,$909
  419.     dc.w    $9707,$fffe,$182,$ff
  420.     dc.w    $9807,$fffe,$192,$909
  421.     dc.w    $9901,$fffe,$184,$800,$192,1,$180,$1
  422.     dc.w    $9a01,$fffe,$184,$900,$192,3,$180,$3
  423.     dc.w    $9b01,$fffe,$184,$a00,$192,5,$180,$5
  424.     dc.w    $9c01,$fffe,$184,$b00,$192,7,$180,$7
  425.     dc.w    $9d07,$fffe,$180,$9,$192,9,$184,$c00
  426.     dc.w    $9e07,$fffe,$180,$b,$192,$b,$184,$d00
  427.     dc.w    $9f07,$fffe,$180,$d,$192,$d,$184,$e00
  428.     dc.w    $a007,$fffe,$180,$f,$192,$f,$184,$f00
  429.     dc.w    $a207,$fffe,$180,$d,$192,$d,$184,$e00
  430.     dc.w    $a307,$fffe,$180,$b,$192,$b,$184,$d00
  431.     dc.w    $a407,$fffe,$180,$9,$192,$9,$184,$c00
  432.     dc.w    $a507,$fffe,$180,$7,$192,$7,$184,$b00
  433.     dc.w    $a607,$fffe,$184,$a00,$180,$5,$192,5
  434.     dc.w    $a707,$fffe,$184,$900,$180,$3,$192,3
  435.     dc.w    $a807,$fffe,$184,$800,$180,$1,$192,1
  436.     dc.w    $a907,$fffe,$180,0,$192,$909
  437.  
  438.     dc.w    $ab07,$fffe,$182,$ee,$192,$909
  439.     dc.w    $ac07,$fffe,$182,$dd
  440.     dc.w    $ad07,$fffe,$182,$cc,$192,$808
  441.     dc.w    $ae07,$fffe,$182,$bb
  442.     dc.w    $af07,$fffe,$182,$aa,$192,$707
  443.     dc.w    $b007,$fffe,$182,$99
  444.     dc.w    $b107,$fffe,$182,$88,$192,$606
  445.     dc.w    $b201,$fffe,$0100,$0000
  446.     dc.l    -2,-2        ; some old chips skip the first end of clist
  447.  
  448. ***********************************************************
  449.  
  450.         section    chip_bss,bss_c
  451.  
  452.         ds.b    10000
  453.         ds.b    50
  454. scrplane:    ds.b    50*34*2
  455.         ds.b    50
  456. scrplane2:    ds.b    9*50
  457. plane:        ds.b    25*50
  458.         ds.b    10000
  459.         END
  460.