home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / amiga / programm / 18269 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  4.8 KB

  1. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!think.com!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!dkuug!imada!news
  2. From: breese@monet.imada.ou.dk (Bjoern Reese)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Hardware bashing demo takes an OS friendly turn.
  5. Message-ID: <1993Jan7.113238.1139@imada.ou.dk>
  6. Date: 7 Jan 93 11:32:38 GMT
  7. Sender: news@imada.ou.dk (USENET News System)
  8. Organization: Dept. of Math. & Computer Science, Odense University, Denmark
  9. Lines: 139
  10.  
  11. The recent discussion on hardware bashing made me wonder if I
  12. could adjust one of my demos to be more OS friendly. I took
  13. a demo which I did at the end of 1990 (in fact the last demo
  14. that I released: "Dexion XMas Demo 1990" - well, it was more
  15. like an intro.) My old routines looked like this (a5 points
  16. to my data section in both examples)
  17.  
  18. ;--- Hardware bashing example --------------------------------------
  19. custom    = $DFF000
  20.  
  21. SystemOff:
  22.     lea    custom,a6
  23.     move.w    intenar(a6),OldIntena(a5)
  24.     move.w    dmaconr(a6),OldDmacon(a5)
  25.     move.w    #$7fff,intena(a6)        ;Kill all interrupts & DMA
  26.     move.w    #$7fff,intreq(a6)
  27.     move.w    #$07ff,dmacon(a6)
  28.     move.l    VectorBase(a5),a1        ;VectorBase found elsewhere
  29.     move.l    $6c(a1),OldLevel3(a5)        ;Save old interrupt pointer
  30.     lea    IntLevel3(pc),a0
  31.     move.l    a0,$6c(a1)            ;Install new interrupt
  32.     move.w    #$c020,intena(a6)        ;Turn on the interrupts
  33.     move.w    #$83e0,dmacon(a6)        ;& DMA that I need
  34.     rts
  35.  
  36. SystemOn:
  37.     lea    custom,a6
  38.     move.w    #$7fff,intena(a6)
  39.     move.w    #$7fff,intreq(a6)
  40.     move.w    #$07ff,dmacon(a6)
  41.     move.w    OldDmacon(a5),d0
  42.     ori.w    #$8100,d0
  43.     move.w    d0,dmacon(a6)        ;Restore DMAs
  44.     move.l    GfxBase(a5),a0
  45.     move.l    38(a0),cop1lc(a6)    ;Restore system copperlists
  46.     move.l    50(a0),cop2lc(a6)
  47.     clr.w    copjmp1(a6)
  48.     move.l    VectorBase(a5),a1
  49.     move.l    OldLevel3(a5),$6c(a1)    ;Restore interrupt pointer
  50.     move.w    OldIntena(a5),d0
  51.     ori.w    #$c000,d0
  52.     move.w    d0,intena(a6)        ;Restore interrupts
  53.     rts
  54. ;------------------------------------------------------------------
  55.  
  56. I substituted them with the routines below (might look a
  57. little messy, because I cut out pieces here, there and
  58. everywhere.)
  59.  
  60. ;--- OS friendly example -------------------------------------------
  61. CALL:    MACRO
  62.     jsr    _LVO\1(a6)
  63.     ENDM
  64.  
  65. SystemOff:
  66.     move.l    GfxBase(a5),a6
  67.     suba.l    a1,a1
  68.     CALL    LoadView        ;Get default view
  69.     CALL    WaitTOF
  70.     CALL    WaitTOF
  71.     CALL    OwnBlitter        ;Claim ownership of blitter
  72.     move.l    $0004.w,a6
  73.     CALL    Forbid            ;Forbid multitasking
  74.     moveq.l    #5,d0            ;VERTB
  75.     lea    VBlankServer(pc),a1
  76.     CALL    AddIntServer        ;Add my interrupt to system list
  77.     rts
  78.  
  79. SystemOn:
  80.     move.l    $0004.w,a6
  81.     moveq.l    #5,d0
  82.     lea    VBlankServer(pc),a1
  83.     CALL    RemIntServer        ;Remove my interrupt
  84.     CALL    Permit            ;Permit multitasking
  85.     move.l    GfxBase(a5),a6
  86.     CALL    DisownBlitter        ;Give blitter back
  87.     move.l    MyView(a5),a1
  88.     CALL    LoadView        ;Load original view
  89.     rts
  90.  
  91. IntLevel3:
  92.     movem.l    d0-d7/a0-a6,-(sp)
  93.     ...
  94.     movem.l    (sp)+,d0-d7/a0-a6
  95.     rts                ;Not rte!!!
  96.  
  97. VBlankServer:
  98.     dc.l    0,0        ;ln_Succ,ln_Pred
  99.     dc.b    2,0        ;ln_Type,ln_Pri
  100.     dc.l    IntName        ;ln_Name
  101.     dc.l    0,IntLevel3    ;is_Data,is_Code
  102.  
  103. IntName:dc.b    "Dexion IntLevel3",0
  104.     EVEN
  105. ;------------------------------------------------------------------
  106.  
  107. where MyView(a5) is filled in immediately after graphics.library
  108. have been opened:
  109.  
  110.     ...
  111.     move.l    GfxBase(a5),a1
  112.     move.l    gb_ActiView(a1),MyView(a5)
  113.     ...
  114.  
  115. And guess what. It works without any problems!
  116.  
  117. The original version would crash on M68010+ CPUs, because I
  118. failed to realize that MOVEC VBR,A0 , which I used to obtain
  119. the vectorbase, was a priviledged instruction :( Not know I
  120. don't need it anymore.
  121.  
  122. I had to give up using WaitBlit() in preference of testing the
  123. BBUSY bit in the dmaconr hardware register by myself. Using
  124. WaitBlit() increased the execution time about 1/5 of a frame
  125. (which I could afford), but as I depended on the preservation
  126. of all data registers and most address registers I had to dump
  127. the scratch registers on the stack, which increased execution
  128. time about 1/2 frame (and that I couldn't afford).
  129.  
  130. Just to give you an idea of what I was doing, the demo consisted
  131. of a scroller which rotated and twisted at the same time (rotation
  132. on the screen, rotation around itself, and a sine.) I used 16 bit
  133. long (short :) lines with the blitter mask containing the font data
  134. to draw the scroller. _240 blitter lines_ were needed. I used
  135. Bresenhams line algorithm to calculate the rotating coordinates
  136. of the scroller. I also used a sprite multiplexer with 16 sprites
  137. (using shellsort.) Oh yes, and another full-screen scroller, which
  138. used ring-buffer, so it didn't really take much time.
  139.  
  140.  
  141. I am posting these code fragments in the hope that someone could
  142. find them useful (the OS friendly fragments, _not_ the bashing-only
  143. fragments.) I would urge hardware bashers to read 'howtocode2.txt'
  144. which can be fould on any aminet site (/pub/aminet/text/docs/)
  145.  
  146. --
  147.  
  148. Bjoern Reese                   |     Email: breese@imada.ou.dk
  149. Odense University, Denmark     |     Voice: +45 65 932 182 (private)
  150.