home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK3 / DFUE_100 / FAMISRC.ZIP / HDMADEMO.ZIP / HDMADEMO.SRC < prev    next >
Text File  |  1993-08-30  |  12KB  |  381 lines

  1. ; equates
  2. joypad1lo  equ $0000
  3. joypad1hi  equ $0001
  4. p0scrollx  equ $0002
  5. p0scrolly  equ $0004
  6. hdmaStart  equ $0006
  7. fishIndex  equ $0008
  8. p1xscrolls equ $1000
  9.  
  10. ; assemble at $8000
  11.     org $8000
  12.  
  13. ; program start
  14. start
  15.     sei             ; disable interrupts
  16.     phk             ; push current bank on stack
  17.     plb             ; pop it off the stack and make it the current programming bank
  18.     clc
  19.     xce             ; native 16-bit mode
  20.  
  21. ; initialise SNES
  22.     sep #$30        ; make X, Y, A all 8-bits
  23.     lda #$80        ; screen off, no brightness
  24.     sta $2100       ; brightness & screen enable register
  25.     lda #$00
  26.     sta $2101       ; sprite register (size & address in VRAM)
  27.     sta $2102       ; sprite registers (address of sprite memory [OAM])
  28.     sta $2103       ; sprite registers (address of sprite memory [OAM])
  29.     sta $2105       ; graphic mode register
  30.     sta $2106       ; mosaic register
  31.     sta $2107       ; plane 0 map VRAM location
  32.     sta $2108       ; plane 1 map VRAM location
  33.     sta $2109       ; plane 2 map VRAM location
  34.     sta $210A       ; plane 3 map VRAM location
  35.     sta $210B       ; plane 0 & 1 Tile data location
  36.     sta $210C       ; plane 2 & 3 Tile data location
  37.     sta $210D       ; plane 0 scroll x (first 8 bits)
  38.     sta $210D       ; plane 0 scroll x (last 3 bits)
  39.     sta $210E       ; plane 0 scroll y (first 8 bits)
  40.     sta $210E       ; plane 0 scroll y (last 3 bits)
  41.     sta $210F       ; plane 1 scroll x (first 8 bits)
  42.     sta $210F       ; plane 1 scroll x (last 3 bits)
  43.     sta $2110       ; plane 1 scroll y (first 8 bits)
  44.     sta $2110       ; plane 1 scroll y (last 3 bits)
  45.     sta $2111       ; plane 2 scroll x (first 8 bits)
  46.     sta $2111       ; plane 2 scroll x (last 3 bits)
  47.     sta $2112       ; plane 2 scroll y (first 8 bits)
  48.     sta $2112       ; plane 2 scroll y (last 3 bits)
  49.     sta $2113       ; plane 3 scroll x (first 8 bits)
  50.     sta $2113       ; plane 3 scroll x (last 3 bits)
  51.     sta $2114       ; plane 3 scroll y (first 8 bits)
  52.     sta $2114       ; plane 3 scroll y (last 3 bits)
  53.     lda #$80        ; increase VRAM address after writing to $2119
  54.     sta $2115       ; VRAM address increment register
  55.     lda #$00
  56.     sta $2116       ; VRAM address low
  57.     sta $2117       ; VRAM address high
  58.     sta $211A       ; initial mode 7 setting register
  59.     sta $211B       ; mode 7 matrix parameter A register (low)
  60.     lda #$01
  61.     sta $211B       ; mode 7 matrix parameter A register (high)
  62.     lda #$00
  63.     sta $211C       ; mode 7 matrix parameter B register (low)
  64.     sta $211C       ; mode 7 matrix parameter B register (high)
  65.     sta $211D       ; mode 7 matrix parameter C register (low)
  66.     sta $211D       ; mode 7 matrix parameter C register (high)
  67.     sta $211E       ; mode 7 matrix parameter D register (low)
  68.     lda #$01
  69.     sta $211E       ; mode 7 matrix parameter D register (high)
  70.     lda #$00
  71.     sta $211F       ; mode 7 center position X register (low)
  72.     sta $211F       ; mode 7 center position X register (high)
  73.     sta $2120       ; mode 7 center position Y register (low)
  74.     sta $2120       ; mode 7 center position Y register (high)
  75.     sta $2121       ; color number register ($00-$ff)
  76.     sta $2123       ; bg1 & bg2 window mask setting register
  77.     sta $2124       ; bg3 & bg4 window mask setting register
  78.     sta $2125       ; obj & color window mask setting register
  79.     sta $2126       ; window 1 left position register
  80.     sta $2127       ; window 2 left position register
  81.     sta $2128       ; window 3 left position register
  82.     sta $2129       ; window 4 left position register
  83.     sta $212A       ; bg1, bg2, bg3, bg4 window logic register
  84.     sta $212B       ; obj, color window logic register (or, and, xor, xnor)
  85.     lda #$01
  86.     sta $212C       ; main screen designation (planes, sprites enable)
  87.     lda #$00
  88.     sta $212D       ; sub screen designation
  89.     sta $212E       ; window mask for main screen
  90.     sta $212F       ; window mask for sub screen
  91.     lda #$30
  92.     sta $2130       ; color addition & screen addition init setting
  93.     lda #$00
  94.     sta $2131       ; add/sub sub designation for screen, sprite, color
  95.     lda #$E0
  96.     sta $2132       ; color data for addition/subtraction
  97.     lda #$00
  98.     sta $2133       ; screen setting (interlace x,y/enable SFX data)
  99.     sta $4200       ; enable v-blank, interrupt, joypad register
  100.     lda #$FF
  101.     sta $4201       ; programmable I/O port
  102.     lda #$00
  103.     sta $4202       ; multiplicand A
  104.     sta $4203       ; multiplier B
  105.     sta $4204       ; multiplier C
  106.     sta $4205       ; multiplicand C
  107.     sta $4206       ; divisor B
  108.     sta $4207       ; horizontal count timer
  109.     sta $4208       ; horizontal count timer MSB
  110.     sta $4209       ; vertical count timer
  111.     sta $420A       ; vertical count timer MSB
  112.     sta $420B       ; general DMA enable (bits 0-7)
  113.     sta $420C       ; horizontal DMA (HDMA) enable (bits 0-7)
  114.     sta $420D       ; access cycle designation (slow/fast rom)
  115.  
  116. ; set register modes
  117.     rep #$30        ; make X, Y, A all 16-bits
  118.     sep #$20        ; make A 8-bits
  119.  
  120. ; initialise graphics hardware
  121.     lda #$01        ; graphics mode 1
  122.     sta $2105
  123.  
  124.     lda #$03        ; enable planes 0 & 1
  125.     sta $212c
  126.  
  127.     lda #$01        ; set plane 0 memory to $0000, 64 chars wide
  128.     sta $2107
  129.     lda #$08        ; set plane 1 memory to $0800
  130.     sta $2108
  131.     lda #$31        ; set plane 0 character set to $1000, plane 1 to $3000
  132.     sta $210b
  133.  
  134. ; copy screen map data
  135.     ldx.w #$0000    ; set VRAM pointer to plane 0 memory location, screen 1
  136.     stx $2116
  137.     ldx.w #$1801    ; dma to $2118
  138.     stx $4300
  139.     ldx.w #picData1&$FFFF ; source offset
  140.     stx $4302
  141.     lda #picData1/$10000&$FF ; source bank
  142.     sta $4304
  143.     ldx.w #$0800    ; number of bytes
  144.     stx $4305
  145.     lda #$01        ; do dma
  146.     sta $420B
  147.  
  148. ; clear plane 0, screen 2
  149.     ldx.w #$0400
  150. clearLoop
  151.     stz $2118
  152.     stz $2119
  153.     dex
  154.     bpl clearLoop
  155.  
  156. ; set colour registers
  157.     lda #$00        ; select colour register 0
  158.     sta $2121
  159.     ldx.w #$2200    ; dma to $2122
  160.     stx $4300
  161.     ldx.w #picData1+$800&$FFFF ; source offset
  162.     stx $4302
  163.     lda #picData1+$800/$10000 ; source bank
  164.     sta $4304
  165.     ldx.w #$20      ; number of bytes
  166.     stx $4305
  167.     lda #$01        ; do dma
  168.     sta $420B
  169.  
  170. ; set tile data
  171.     ldx.w #$1000     ; set VRAM pointer to character set location
  172.     stx $2116
  173.     ldx.w #$1801    ; dma to $2118
  174.     stx $4300
  175.     ldx.w #picData1+$820&$FFFF ; source offset
  176.     stx $4302
  177.     lda #picData1+$820/$10000 ; source bank
  178.     sta $4304
  179.     ldx.w #$3940    ; number of bytes
  180.     stx $4305
  181.     lda #$01        ; do dma
  182.     sta $420B
  183.  
  184. ; copy screen map data
  185.     ldx.w #$0800    ; set VRAM pointer to plane 1 memory location
  186.     stx $2116
  187.     ldx.w #$1801    ; dma to $2118
  188.     stx $4300
  189.     ldx.w #picData2&$FFFF ; source offset
  190.     stx $4302
  191.     lda #picData2/$10000&$FF ; source bank
  192.     sta $4304
  193.     ldx.w #$0800    ; number of bytes
  194.     stx $4305
  195.     lda #$01        ; do dma
  196.     sta $420B
  197.  
  198. ; set colour registers
  199.     lda #$10        ; select colour register 16
  200.     sta $2121
  201.     ldx.w #$2200    ; dma to $2122
  202.     stx $4300
  203.     ldx.w #picData2+$800&$FFFF ; source offset
  204.     stx $4302
  205.     lda #picData2+$800/$10000 ; source bank
  206.     sta $4304
  207.     ldx.w #$20      ; number of bytes
  208.     stx $4305
  209.     lda #$01        ; do dma
  210.     sta $420B
  211.  
  212. ; set tile data
  213.     ldx.w #$3000    ; set VRAM pointer to character set location
  214.     stx $2116
  215.     ldx.w #$1801    ; dma to $2118
  216.     stx $4300
  217.     ldx.w #picData2+$820&$FFFF ; source offset
  218.     stx $4302
  219.     lda #picData2+$820/$10000 ; source bank
  220.     sta $4304
  221.     ldx.w #$7440    ; number of bytes
  222.     stx $4305
  223.     lda #$01        ; do dma
  224.     sta $420B
  225.  
  226. ; initialise variables
  227.     ldx.w #$0000
  228.     stx p0scrollx
  229.     stx p0scrolly
  230.     stx hdmaStart
  231.     stx fishIndex
  232.     jsr evaluateHdmaValues
  233.  
  234. ; configure horizontal dma
  235.     lda #$02        ; 2 byte format (count, byte1, byte2)
  236.     sta $4300
  237.     lda #$0F        ; plane 1 x-scroll at $210F
  238.     sta $4301
  239.     ldx.w #p1xscrolls&$FFFF ; hdma list location
  240.     stx $4302
  241.     lda #p1xscrolls/$10000 ; hdma list bank
  242.     sta $4304
  243.  
  244.     lda #$81        ; enable vertical blank interrupt & joypad read
  245.     sta $4200
  246.  
  247.     cli
  248.  
  249.     lda #$0F        ; enable screen, full brightness
  250.     sta $2100
  251.  
  252.     lda #$01        ; enable hdma 1
  253.     sta $420c
  254.  
  255. mainLoop
  256.  
  257.     wai
  258.  
  259. ; scroll fish horizontally
  260.     ldx p0scrollx
  261.     dex
  262.     stx p0scrollx
  263.  
  264. ; scroll fish vertically
  265.     ldx fishIndex
  266.     lda sineFishTable,x
  267.     inx
  268.     sta p0scrolly
  269.     lda sineFishTable,x
  270.     inx
  271.     sta p0scrolly+$01
  272.     cpx.w #$100
  273.     bne saveFishIndex
  274.     ldx.w #$00
  275. saveFishIndex
  276.     stx fishIndex
  277.  
  278. ; scroll reef background
  279.     jsr evaluateHdmaValues
  280.  
  281.     bra mainLoop
  282.  
  283. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  284. ;; set the hdma values                                                     ;;
  285. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  286. evaluateHdmaValues
  287.     ldx.w #$0000
  288.     ldy hdmaStart
  289. hdmaLoop
  290.     lda #$01
  291.     sta p1xscrolls,x
  292.     inx
  293.     lda sineHdmaTable,y
  294.     iny
  295.     sta p1xscrolls,x
  296.     inx
  297.     lda sineHdmaTable,y
  298.     iny
  299.     sta p1xscrolls,x
  300.     inx
  301.     cpx.w #$02A0
  302.     bne hdmaLoop
  303.     lda #$00
  304.     sta p1xscrolls,x
  305.  
  306.     ldx hdmaStart
  307.     inx
  308.     inx
  309.     cpx.w #$01C0
  310.     bne storeNextHdmaStart
  311.     ldx.w #$0000
  312. storeNextHdmaStart
  313.     stx hdmaStart
  314.  
  315.     rts
  316.  
  317. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  318. ;; vertical blank interrupt routine                                        ;;
  319. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  320. verticalBlankInterrupt
  321.     pha             ; save accumulator
  322.  
  323.     lda p0scrollx
  324.     sta $210d
  325.     lda p0scrollx+$01
  326.     sta $210d
  327.  
  328.     lda p0scrolly
  329.     sta $210e
  330.     lda p0scrolly+$01
  331.     sta $210e
  332.  
  333. waitForJoypad       ; otherwise read joypad
  334.     lda $4212       ; wait until the joypad is ready to read
  335.     and #$01
  336.     bne waitForJoypad
  337.  
  338.     lda $4218       ; read joypad
  339.     sta joypad1lo
  340.     lda $4219
  341.     sta joypad1hi
  342.  
  343.     pla             ; restore accumulator
  344.     rti             ; exit vertical blank
  345.  
  346. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  347. ;; sine table for hdma                                                     ;;
  348. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  349. sineHdmaTable
  350.     incbin "sine.bin"
  351.  
  352. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  353. ;; sine table for fish                                                     ;;
  354. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  355. sineFishTable
  356.     incbin "fishsine.bin"
  357.  
  358. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  359. ;; picture 1 data (big fish)                                               ;;
  360. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  361. picData1
  362.     incbin "butrfish.dat"
  363.  
  364. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  365. ;; vertical blank & run/reset vectors                                      ;;
  366. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  367.  
  368.     pad $FFEA
  369.     dc.w verticalBlankInterrupt
  370.  
  371.     pad $FFFC
  372.     dc.w start
  373.  
  374.     pad
  375.  
  376. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  377. ;; picture 2 data (reef)                                                   ;;
  378. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  379. picData2
  380.     incbin "reef.dat"
  381.