Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.19 KB | None | 0 0
  1. BltSize MACRO
  2. \1<<6|\2
  3. ENDM
  4.  
  5. WaitBlit:
  6. PUSHL a5
  7.  
  8. move.l #CustomBase,a5
  9. tst dmaconr(a5)
  10. .loop
  11. btst #6,dmaconr(a5)
  12. bne .loop
  13.  
  14. POPL a5
  15. rts
  16.  
  17. WaitForVBL:
  18.  
  19. .loop move.l $dff004,d0
  20. and.l #$1ff00,d0
  21. cmp.l #262<<8,d0
  22. bne.b .loop
  23.  
  24. .loop2 move.l $dff004,d0
  25. and.l #$1ff00,d0
  26. cmp.l #262<<8,d0
  27. bne.b .loop2
  28.  
  29. rts
  30.  
  31. ClearLoRes:
  32. ;a0 = bpl to clear
  33. ;Need to clear 4000 words of memory at a0.
  34. PUSHL a5
  35.  
  36. move.l #CustomBase,a5
  37. bsr WaitBlit
  38.  
  39. move.w #$0100,bltcon0(a5) ;BLTCON0 = ---D, null minterm
  40. move.w #$0,bltcon1(a5) ;no BLTCON1 flags
  41. move.w #0,bltdmod(a5) ;no D modulo
  42. move.l a0,bltdpt(a5) ;D = a0
  43. move.w #(1000<<6)|4,bltsize(a5);blitting 4000 words
  44.  
  45. POPL a5
  46. RTS
  47.  
  48. ;;;;;;;;;;;;;;;;;;;;;;
  49.  
  50. RotatePoint MACRO
  51. move.l \1,d0
  52. move.l \2,d1
  53. move.l \3,d2
  54. JSR _RotatePoint
  55. ENDM
  56.  
  57. PX_WIDE = 320
  58. PX_TALL = 200
  59. PX_COUNT= PX_WIDE*PX_TALL
  60. PX_BYTES= PX_COUNT/8
  61.  
  62. PX_WIDE_BYTES= PX_WIDE/8
  63. PX_TALL_BYTES= PX_TALL/8
  64.  
  65. JUMPPTR start
  66.  
  67. include include/macros.i
  68. include include/equates.i
  69.  
  70. include exec/exec.i
  71. include dos/dos.i
  72. include graphics/gfx.i
  73. include graphics/gfxbase.i
  74. include graphics/copper.i
  75.  
  76. include hardware/blit.i
  77. include hardware/cia.i
  78. include hardware/custom.i
  79. include hardware/dmabits.i
  80.  
  81. include dos/dos_lib.i
  82. include exec/exec_lib.i
  83. include include/mathieeesingbas.i
  84. include include/mathieeesingtrans.i
  85.  
  86. SECTION CODE,CODE_P
  87.  
  88. include include/takeover.s
  89. include include/blitter.s
  90.  
  91. start:
  92. move.l SysBase,a6 ;Exec library base address
  93. lea dos_name,a1
  94. moveq #36,d0
  95. jsr _LVOOpenLibrary(a6)
  96. beq final_exit ;failed to open dos.library
  97. move.l d0,dos_base
  98.  
  99. lea gfx_name,a1
  100. moveq #36,d0
  101. jsr _LVOOpenLibrary(a6)
  102. beq final_exit ;failed to open graphics.library
  103. move.l d0,gfx_base
  104.  
  105. lea mathieeesingbas_name,a1
  106. moveq #36,d0
  107. jsr _LVOOpenLibrary(a6)
  108. beq final_exit
  109. move.l d0,mathieeesingbas_base
  110.  
  111. lea mathieeesingtrans_name,a1
  112. moveq #36,d0
  113. jsr _LVOOpenLibrary(a6)
  114. beq final_exit
  115. move.l d0,mathieeesingtrans_base
  116.  
  117. jsr PrecalculateRadians
  118.  
  119. ;Rotate the square...
  120. RotatePoint #-50,#-50,#45
  121. RotatePoint #50,#-50,#45
  122. RotatePoint #50,#50,#45
  123. RotatePoint #-50,#50,#45
  124.  
  125. move.l #CustomBase,a5
  126. jsr SystemTakeover
  127.  
  128. jsr ResetBitplanePtr
  129.  
  130. ;clear bitplane
  131. move.l #Bitplane1,d0
  132. move.l #Bitplane1,d1
  133. add.l #PX_BYTES,d1
  134.  
  135. move.l d0,a0
  136. move.l d1,a1
  137.  
  138. .bplclear:
  139. move.l #$FF00FF00,(a0)+
  140. cmp.l a0,a1
  141. bne .bplclear
  142.  
  143. move.l #Bitplane1,a0
  144. JSR ClearLoRes
  145.  
  146. DoCoolStuff:
  147. ;TODO: cool stuff
  148. JSR CoolDemoStuff
  149.  
  150. done:
  151. jsr SystemRelease
  152.  
  153. CloseFFPLibs:
  154. move.l mathieeesingtrans_base,d0
  155. move.l d0,a1
  156. move.l SysBase,a6
  157. jsr _LVOCloseLibrary(a6)
  158.  
  159. move.l mathieeesingbas_base,d0
  160. move.l d0,a1
  161. move.l SysBase,a6
  162. jsr _LVOCloseLibrary(a6)
  163.  
  164. CloseGfxLib:
  165. move.l gfx_base,d0
  166. move.l d0,a1
  167. move.l SysBase,a6
  168. jsr _LVOCloseLibrary(a6)
  169.  
  170. CloseDosLib:
  171. move.l dos_base,d0
  172. move.l d0,a1
  173. move.l SysBase,a6
  174. jsr _LVOCloseLibrary(a6)
  175.  
  176. final_exit:
  177. rts
  178.  
  179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  180.  
  181.  
  182. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  183.  
  184. SECTION CoolStuff,CODE_P
  185.  
  186. ;;;;;;;;
  187. ; Draw routines
  188. ;;;;;;;;
  189. SetPixel MACRO
  190. lea \1,a0
  191. move.l \2,d0
  192. move.l \3,d1
  193. JSR _SetPixel
  194. ENDM
  195.  
  196. DrawLine MACRO
  197. lea \1,a0
  198. move.l \2,d0
  199. move.l \3,d1
  200. move.l \4,d2
  201. move.l \5,d3
  202. JSR _DrawLine
  203. ENDM
  204.  
  205. PlotVertex MACRO
  206. lea \1,a0
  207. lea \2,a1
  208. move.l \3,d0
  209. move.l \4,d1
  210. JSR _PlotVertex
  211. ENDM
  212.  
  213. DrawShape MACRO
  214. lea \1,a0
  215. lea \2,a1
  216. move.l \3,d0
  217. move.l \4,d1
  218. JSR _DrawShape
  219. ENDM
  220.  
  221. _DrawShape:
  222. ;a0 = bpl to write
  223. ;a1 = ptr to start of shape data
  224. ;d0 = offset x
  225. ;d1 = offset y
  226.  
  227. LINK a6,#-8
  228.  
  229. move.w d0,-4(a6)
  230. move.w d1,-8(a6)
  231.  
  232. move.l a1,a2 ;preserve
  233. move.l a1,a3 ;preserve
  234. move.w (a1),d7
  235. subi #1,d7
  236.  
  237. lea RotatedVertexBuffer,a4
  238. .rotateLoop
  239. ;Rotate the vertices.
  240. move.w 2(a1),d0
  241. move.w 4(a1),d1
  242. ext.l d0
  243. ext.l d1
  244. move.w shape_rot_deg,d2
  245. JSR _RotatePoint
  246.  
  247. move.w d0,(a4)+
  248. move.w d1,(a4)+
  249.  
  250. add.l #4,a1
  251.  
  252. dbra d7,.rotateLoop
  253.  
  254. .beforeDraw
  255. move.w (a2),d7
  256. subi #1,d7
  257. lea RotatedVertexBuffer,a2
  258. lea RotatedVertexBuffer,a3
  259.  
  260. .drawLoop:
  261. move.w -4(a6),d0 ;X
  262. move.w -8(a6),d1 ;Y
  263. move.l a2,a1 ;retrieve the shape ptr
  264.  
  265. .getV1:
  266. move.w 0(a1),d2
  267. move.w 2(a1),d3
  268. add.w d0,d2 ;d2 += d0
  269. add.w d1,d3 ;d3 += d1
  270.  
  271. add.l #4,a2 ;a2 now = next vertex
  272. move.l a2,a1 ;a2 = current vertex ptr
  273.  
  274. cmp #0,d7 ;are we on the last vertex?
  275. bne .getV2 ;no, continue.
  276.  
  277. move.l a3,a1 ;yes, return to the first vertex
  278.  
  279. .getV2:
  280. move.w 0(a1),d4
  281. move.w 2(a1),d5
  282. add.w d0,d4
  283. add.w d1,d5
  284.  
  285. DrawLine Bitplane1,d2,d3,d4,d5
  286.  
  287. dbra d7,.drawLoop
  288.  
  289. UNLK a6
  290.  
  291. RTS
  292.  
  293. ;;;
  294. _PlotVertex:
  295. ;a0 = bpl to write
  296. ;a1 = pointer to vertex
  297. ;d0 = origin X
  298. ;d1 = origin Y
  299.  
  300. add.w (a1),d0
  301. add.w 2(a1),d1
  302. JSR _SetPixel
  303.  
  304. RTS
  305.  
  306. ;;;
  307. _SetPixel:
  308. ;a0 = bpl to write
  309. ;d0 = x
  310. ;d1 = y
  311. mulu.w #PX_WIDE_BYTES,d1 ;d1 = y*pixelwidth
  312. divu #8,d0 ;d0.h = shift factor
  313. ;d0.l = pixel offset in bytes
  314. add.w d0,d1 ;d1 = y*pixelwidth + offset
  315. swap d0
  316. add.l d1,a0 ;a0 = bpl + (y*pixelwidth+offset)
  317.  
  318. move.b #%10000000,d1
  319. lsr.b d0,d1 ;d1 = shifted pixel to set at a0
  320.  
  321. or.b d1,(a0) ;(a0) = old | new
  322. RTS
  323.  
  324. ;;;
  325.  
  326. _DrawLine
  327. ;a0.l = bpl to write
  328. ;d0.w = x1
  329. ;d1.w = y1
  330. ;d2.w = x2
  331. ;d3.w = y2
  332. ;d4.w = width
  333.  
  334. PRESERVE_A
  335. PRESERVE_D
  336.  
  337. ext.l d0
  338. ext.l d1
  339. ext.l d2
  340. ext.l d3
  341. ext.l d4
  342.  
  343. move.l #PX_WIDE_BYTES,d4
  344.  
  345. lea CustomBase,a1 ; custom address
  346. sub.w d0,d2 ;calculate dX
  347. bmi xneg ;if neg, octant is in [3,4,5,6]
  348. sub.w d1,d3 ;calculate dY octant is in [1,2,7,8]
  349. bmi yneg ;if neg, octant is in [7,8]
  350. cmp.w d3,d2 ; octant is in [1,2]
  351. bmi ygtx ;if y>x, octant is 2
  352. moveq.l #OCTANT1+LINEMODE,d5 ;else octant is 1
  353. bra lineagain
  354.  
  355. ygtx:
  356. exg d2,d3 ;X > Y for proper operation
  357. moveq.l #OCTANT2+LINEMODE,d5 ;octant is 2
  358. bra lineagain
  359.  
  360. yneg:
  361. neg.w d3 ;abs(dY)
  362. cmp.w d3,d2 ;octant is in [7,8]
  363. bmi ynygtx ;if y>x, octant is 7
  364. moveq.l #OCTANT8+LINEMODE,d5 ;else octant is 8
  365. bra lineagain
  366.  
  367. ynygtx:
  368. exg d2,d3 ;X > Y for proper operation
  369. moveq.l #OCTANT7+LINEMODE,d5 ;octant is 7
  370. bra lineagain
  371.  
  372. xneg:
  373. neg.w d2 ;octant is in [3,4,5,6]
  374. sub.w d1,d3 ;calculate dY
  375. bmi xyneg ;if neg, octant is in [5,6]
  376. cmp.w d3,d2 ;else octant is in [3,4]
  377. bmi xnygtx ;if y>x, octant is 3
  378. moveq.l #OCTANT4+LINEMODE,d5 ;else octant is 4
  379. bra lineagain
  380.  
  381. xnygtx:
  382. exg d2,d3 ;ensure X > Y
  383. moveq.l #OCTANT3+LINEMODE,d5 ;octant is 3
  384. bra lineagain
  385.  
  386. xyneg:
  387. neg.w d3 ;octant is in [5,6]
  388. cmp.w d3,d2 ;y > x?
  389. bmi xynygtx ;octant is 6
  390. moveq.l #OCTANT5+LINEMODE,d5 ;else octant is 5
  391. bra lineagain
  392.  
  393. xynygtx:
  394. exg d2,d3 ;ensure X > Y
  395. moveq.l #OCTANT6+LINEMODE,d5 ;octant is 6
  396.  
  397. lineagain:
  398. mulu.w d4,d1 ;calculate y1*width
  399. ror.l #4,d0 ;move upper 4 bits into hi word
  400. add.w d0,d0 ;multiply by 2
  401. add.l d1,a0 ;ptr += (x1 >> 3)
  402. add.w d0,a0 ;ptr += y1*width
  403. swap d0 ;get the 4 bits of x1
  404. or.w #$0BFA,d0 ;OR with USEA|USEC|USED. F=A+C
  405. lsl.w #2,d3 ;Y = 4*Y
  406. add.w d2,d2 ;X = 2*X
  407. move.w d2,d1 ;set up the size word
  408. lsl.w #5,d1 ;shift five left
  409. add.w #$42,d1 ;add 1 to height, 2 to width
  410.  
  411. jsr WaitBlit
  412.  
  413. setBLT:
  414. move.w d3,bltbmod(a1) ;B mod = 4*Y
  415. sub.w d2,d3
  416. ext.l d3
  417. move.l d3,bltapt(a1) ;A ptr = 4*Y - 2*X
  418. bpl lineover
  419. or.w #SIGNFLAG,d5 ;set sign bit if negative
  420.  
  421. lineover:
  422. move.w d0,bltcon0(a1) ;write the control registers
  423. move.w d5,bltcon1(a1)
  424. move.w d4,bltcmod(a1)
  425. move.w d4,bltdmod(a1)
  426. sub.w d2,d3
  427. move.w d3,bltamod(a1) ;A mod = 4*Y - 4*X
  428. move.w #$8000,bltadat(a1)
  429. moveq.l #-1,d5
  430. move.l d5,bltafwm(a1) ;hit both masks at once
  431. move.l a0,bltcpt(a1)
  432. move.l a0,bltdpt(a1)
  433. move.w d1,bltsize(a1)
  434.  
  435. RESTORE_D
  436. RESTORE_A
  437. RTS
  438.  
  439. ;;;;;;;;;;;;;;;;
  440.  
  441. _RotatePoint:
  442. ;Rotate a point (d0.w,d1.w) around (0,0) by d2.w degrees.
  443. ;Returns new coordinates in (d0,d1).
  444. PRESERVE_A
  445. PRESERVE_D
  446.  
  447. LINK a6,#-20
  448.  
  449. move.l mathieeesingbas_base,a4
  450. move.l mathieeesingtrans_base,a5
  451. move.l d0,-4(a6)
  452. move.l d1,-8(a6)
  453.  
  454. jsr IEEESPFlt(a4)
  455. move.l d0,-4(a6)
  456.  
  457. move.l -8(a6),d0
  458. jsr IEEESPFlt(a4)
  459. move.l d0,-8(a6)
  460.  
  461. ;formula: x' = x*cos(theta) - y*sin(theta)
  462. ; y' = y*cos(theta) + x*sin(theta)
  463.  
  464. .calcSinCos
  465. move.w d2,d0
  466. JSR DegreesToRadians
  467.  
  468. move.l d0,-12(a6) ;12(a6) = theta
  469. JSR IEEESPSin(a5)
  470. move.l d0,-16(a6) ;16(a6) = sin(theta)
  471.  
  472. move.l -12(a6),d0
  473. JSR IEEESPCos(a5)
  474. move.l d0,-20(a6) ;20(a6) = cos(theta)
  475.  
  476. .calcXPrime
  477. move.l -20(a6),d1
  478. move.l -4(a6),d0
  479. jsr IEEESPMul(a4)
  480. move.l d0,d6 ;d6 = x*cos(theta)
  481.  
  482. move.l -16(a6),d1
  483. move.l -8(a6),d0
  484. jsr IEEESPMul(a4) ;d0 = y*sin(theta)
  485. move.l d6,d1
  486. jsr IEEESPSub(a4) ;d0 = x*cos(theta) - y*sin(theta)
  487. move.l d0,d5
  488.  
  489. .calcYPrime
  490. move.l -8(a6),d0 ;d0 = y
  491. move.l -20(a6),d1 ;d1 = cos(theta)
  492. jsr IEEESPMul(a4) ;d0 = y*cos(theta)
  493. move.l d0,d6
  494.  
  495. move.l -4(a6),d0 ;d0 = x
  496. move.l -16(a6),d1 ;d1 = sin(theta)
  497. jsr IEEESPMul(a4) ;d0 = x*sin(theta)
  498. move.l d6,d1
  499. jsr IEEESPAdd(a4) ;d0 = y*cos(theta) + x*sin(theta)
  500.  
  501. .backToInteger
  502. jsr IEEESPFix(a4) ;d0 = INT(y)
  503. move.l d0,d1
  504.  
  505. move.l d5,d0
  506. jsr IEEESPFix(a4) ;d0 = INT(x)
  507.  
  508. UNLK a6
  509.  
  510. RESTORE_D
  511. RESTORE_A
  512.  
  513. RTS
  514.  
  515. ;;;
  516.  
  517. ResetBitplanePtr:
  518. move.l #Bitplane1,d0
  519. lea C_BitplanePtr,a1
  520.  
  521. move.w d0,6(a1) ; low word of bitplane ptr
  522. swap d0
  523. move.w d0,2(a1) ; high word of bitplane ptr
  524. rts
  525.  
  526. ;;;
  527.  
  528. DegreesToRadians:
  529. ;d0 = degrees
  530. ;returns single-precision radian value in d0
  531.  
  532. lea RadiansTable,a0
  533. asl.w #2,d0 ;get offset. each entry in table is 4 bytes
  534. add.w d0,a0
  535. move.l (a0),d0 ;retrieve value from table
  536.  
  537. rts
  538.  
  539. RadiansToDegrees:
  540. ;d0 = radians (single-precision)
  541. ;returns integer degrees value in d0.w
  542.  
  543. ;TODO: lookup table
  544. PUSHL a6
  545.  
  546. move.l mathieeesingbas_base,a6
  547.  
  548. move.l ONEEIGHTY_DIV_PI,d1
  549. jsr IEEESPMul(a6)
  550.  
  551. POPL a6
  552. RTS
  553.  
  554. PrecalculateRadians:
  555. ;Calculate
  556.  
  557. ;Populate the Radians table with values for 0-359 degrees.
  558. lea RadiansTable,a0
  559. move.l #0,d7
  560.  
  561. .loop:
  562. move.l mathieeesingbas_base,a6
  563. move.l d7,d0
  564. jsr IEEESPFlt(a6)
  565.  
  566. move.l PI_DIV_ONEEIGHTY,d1
  567. jsr IEEESPMul(a6) ;d0 degrees * 1 degrees in radians
  568.  
  569. move.l d0,(a0)+
  570. addq.w #1,d7
  571. cmp.w #360,d7
  572. bne .loop
  573.  
  574. .done:
  575. rts
  576.  
  577. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  578.  
  579. CoolDemoStuff:
  580. lea Copperlist,a0
  581. move.l a0,cop1lc(a5)
  582. move.w #$8080,dmacon(a5)
  583.  
  584. move.w #0,shape_rot_deg
  585.  
  586. ; SetPixel Bitplane1,#0,#0
  587. ; PlotVertex Bitplane1,Square+2,#100,#100
  588. ; DrawLine Bitplane1,#20,#20,#20,#120
  589.  
  590. FrameLoop:
  591. jsr WaitBlit
  592. addq.w #1,shape_rot_deg
  593. DrawShape Bitplane1,Square,#100,#100
  594. jsr ResetBitplanePtr
  595.  
  596. jsr WaitForVBL
  597. MouseLoop:
  598.  
  599. btst #CIAB_GAMEPORT0,_ciaa
  600. bne.w FrameLoop
  601.  
  602. RTS
  603.  
  604. ;;;
  605. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  606.  
  607. SECTION DATA,DATA_P
  608.  
  609. ;dos.library
  610. dos_name DOSNAME
  611. dos_base dc.l 0
  612.  
  613. ;graphics.library
  614. gfx_name GRAPHICSNAME
  615. even
  616. gfx_base dc.l 0
  617.  
  618. ;mathieeesingbas.library
  619. mathieeesingbas_name dc.b "mathieeesingbas.library",0
  620. mathieeesingbas_base dc.l 0
  621.  
  622. mathieeesingtrans_name dc.b "mathieeesingtrans.library",0
  623. mathieeesingtrans_base dc.l 0
  624. even
  625.  
  626. ;;;
  627. shape_rot_deg dc.w 0
  628.  
  629. PI dc.l $40490fdb ;IEEE 754 format
  630. PI_DIV_ONEEIGHTY dc.l $3c8efa35
  631. ONEEIGHTY_DIV_PI dc.l $42652ee1
  632. RadiansTable blk.l 360 ;precalculated radian value
  633. ;;;
  634. SECTION SHAPES,DATA_P
  635. ;Shape structure
  636. ; data+0 = WORD vertex count
  637. ; data+2 = WORD,WORD vertex X,Y
  638. ; data+6
  639. ; etc...
  640.  
  641. RotatedVertexBuffer: blk.w 128
  642.  
  643. Square:
  644. dc.w 4
  645. dc.w -50,-50
  646. dc.w 50,-50
  647. dc.w 50, 50
  648. dc.w -50, 50
  649.  
  650. SECTION SINE,DATA_P
  651. include include/sine.s
  652.  
  653. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  654.  
  655. SECTION CHIP,DATA_C
  656.  
  657. ;Data for chip mem
  658.  
  659. CNOP 0,4
  660. Copperlist:
  661.  
  662. ;Draw a line to the bitplane before we display
  663. dc.w bplcon0,$1200 ;BPLCON0 = one bitplanes, color on
  664. dc.w bplcon1,$0000 ;BPLCON1 = no scrolling
  665.  
  666. dc.w bpl1mod,$0000 ;Odd bitplane modulo of 0
  667.  
  668. C_BitplanePtr:
  669. dc.w bpl1pth,0
  670. dc.w bpl1ptl,0
  671.  
  672. dc.w diwstrt,$2c81 ;DIWSTRT
  673. dc.w diwstop,$f4c1 ;DIWSTOP
  674. dc.w ddfstrt,$0038 ;DDFSTRT
  675. dc.w ddfstop,$00d0 ;DDFSTOP
  676.  
  677. dc.w color+0,$0000 ;COLOR00
  678. dc.w color+2,$00A0 ;COLOR01
  679.  
  680. dc.w dmacon,$8180 ;DMACON on
  681. dc.w dmacon,$007f ;DMACON off
  682.  
  683. dc.w intena,%1100000000000000 ;INTENA on
  684. dc.w intena,%0011111111111111 ;INTENA off
  685.  
  686. dc.w $ffff,$fffe ;end
  687.  
  688. CNOP 0,4
  689. Bitplane1 blk.b PX_BYTES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement