Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BltSize MACRO
- \1<<6|\2
- ENDM
- WaitBlit:
- PUSHL a5
- move.l #CustomBase,a5
- tst dmaconr(a5)
- .loop
- btst #6,dmaconr(a5)
- bne .loop
- POPL a5
- rts
- WaitForVBL:
- .loop move.l $dff004,d0
- and.l #$1ff00,d0
- cmp.l #262<<8,d0
- bne.b .loop
- .loop2 move.l $dff004,d0
- and.l #$1ff00,d0
- cmp.l #262<<8,d0
- bne.b .loop2
- rts
- ClearLoRes:
- ;a0 = bpl to clear
- ;Need to clear 4000 words of memory at a0.
- PUSHL a5
- move.l #CustomBase,a5
- bsr WaitBlit
- move.w #$0100,bltcon0(a5) ;BLTCON0 = ---D, null minterm
- move.w #$0,bltcon1(a5) ;no BLTCON1 flags
- move.w #0,bltdmod(a5) ;no D modulo
- move.l a0,bltdpt(a5) ;D = a0
- move.w #(1000<<6)|4,bltsize(a5);blitting 4000 words
- POPL a5
- RTS
- ;;;;;;;;;;;;;;;;;;;;;;
- RotatePoint MACRO
- move.l \1,d0
- move.l \2,d1
- move.l \3,d2
- JSR _RotatePoint
- ENDM
- PX_WIDE = 320
- PX_TALL = 200
- PX_COUNT= PX_WIDE*PX_TALL
- PX_BYTES= PX_COUNT/8
- PX_WIDE_BYTES= PX_WIDE/8
- PX_TALL_BYTES= PX_TALL/8
- JUMPPTR start
- include include/macros.i
- include include/equates.i
- include exec/exec.i
- include dos/dos.i
- include graphics/gfx.i
- include graphics/gfxbase.i
- include graphics/copper.i
- include hardware/blit.i
- include hardware/cia.i
- include hardware/custom.i
- include hardware/dmabits.i
- include dos/dos_lib.i
- include exec/exec_lib.i
- include include/mathieeesingbas.i
- include include/mathieeesingtrans.i
- SECTION CODE,CODE_P
- include include/takeover.s
- include include/blitter.s
- start:
- move.l SysBase,a6 ;Exec library base address
- lea dos_name,a1
- moveq #36,d0
- jsr _LVOOpenLibrary(a6)
- beq final_exit ;failed to open dos.library
- move.l d0,dos_base
- lea gfx_name,a1
- moveq #36,d0
- jsr _LVOOpenLibrary(a6)
- beq final_exit ;failed to open graphics.library
- move.l d0,gfx_base
- lea mathieeesingbas_name,a1
- moveq #36,d0
- jsr _LVOOpenLibrary(a6)
- beq final_exit
- move.l d0,mathieeesingbas_base
- lea mathieeesingtrans_name,a1
- moveq #36,d0
- jsr _LVOOpenLibrary(a6)
- beq final_exit
- move.l d0,mathieeesingtrans_base
- jsr PrecalculateRadians
- ;Rotate the square...
- RotatePoint #-50,#-50,#45
- RotatePoint #50,#-50,#45
- RotatePoint #50,#50,#45
- RotatePoint #-50,#50,#45
- move.l #CustomBase,a5
- jsr SystemTakeover
- jsr ResetBitplanePtr
- ;clear bitplane
- move.l #Bitplane1,d0
- move.l #Bitplane1,d1
- add.l #PX_BYTES,d1
- move.l d0,a0
- move.l d1,a1
- .bplclear:
- move.l #$FF00FF00,(a0)+
- cmp.l a0,a1
- bne .bplclear
- move.l #Bitplane1,a0
- JSR ClearLoRes
- DoCoolStuff:
- ;TODO: cool stuff
- JSR CoolDemoStuff
- done:
- jsr SystemRelease
- CloseFFPLibs:
- move.l mathieeesingtrans_base,d0
- move.l d0,a1
- move.l SysBase,a6
- jsr _LVOCloseLibrary(a6)
- move.l mathieeesingbas_base,d0
- move.l d0,a1
- move.l SysBase,a6
- jsr _LVOCloseLibrary(a6)
- CloseGfxLib:
- move.l gfx_base,d0
- move.l d0,a1
- move.l SysBase,a6
- jsr _LVOCloseLibrary(a6)
- CloseDosLib:
- move.l dos_base,d0
- move.l d0,a1
- move.l SysBase,a6
- jsr _LVOCloseLibrary(a6)
- final_exit:
- rts
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- SECTION CoolStuff,CODE_P
- ;;;;;;;;
- ; Draw routines
- ;;;;;;;;
- SetPixel MACRO
- lea \1,a0
- move.l \2,d0
- move.l \3,d1
- JSR _SetPixel
- ENDM
- DrawLine MACRO
- lea \1,a0
- move.l \2,d0
- move.l \3,d1
- move.l \4,d2
- move.l \5,d3
- JSR _DrawLine
- ENDM
- PlotVertex MACRO
- lea \1,a0
- lea \2,a1
- move.l \3,d0
- move.l \4,d1
- JSR _PlotVertex
- ENDM
- DrawShape MACRO
- lea \1,a0
- lea \2,a1
- move.l \3,d0
- move.l \4,d1
- JSR _DrawShape
- ENDM
- _DrawShape:
- ;a0 = bpl to write
- ;a1 = ptr to start of shape data
- ;d0 = offset x
- ;d1 = offset y
- LINK a6,#-8
- move.w d0,-4(a6)
- move.w d1,-8(a6)
- move.l a1,a2 ;preserve
- move.l a1,a3 ;preserve
- move.w (a1),d7
- subi #1,d7
- lea RotatedVertexBuffer,a4
- .rotateLoop
- ;Rotate the vertices.
- move.w 2(a1),d0
- move.w 4(a1),d1
- ext.l d0
- ext.l d1
- move.w shape_rot_deg,d2
- JSR _RotatePoint
- move.w d0,(a4)+
- move.w d1,(a4)+
- add.l #4,a1
- dbra d7,.rotateLoop
- .beforeDraw
- move.w (a2),d7
- subi #1,d7
- lea RotatedVertexBuffer,a2
- lea RotatedVertexBuffer,a3
- .drawLoop:
- move.w -4(a6),d0 ;X
- move.w -8(a6),d1 ;Y
- move.l a2,a1 ;retrieve the shape ptr
- .getV1:
- move.w 0(a1),d2
- move.w 2(a1),d3
- add.w d0,d2 ;d2 += d0
- add.w d1,d3 ;d3 += d1
- add.l #4,a2 ;a2 now = next vertex
- move.l a2,a1 ;a2 = current vertex ptr
- cmp #0,d7 ;are we on the last vertex?
- bne .getV2 ;no, continue.
- move.l a3,a1 ;yes, return to the first vertex
- .getV2:
- move.w 0(a1),d4
- move.w 2(a1),d5
- add.w d0,d4
- add.w d1,d5
- DrawLine Bitplane1,d2,d3,d4,d5
- dbra d7,.drawLoop
- UNLK a6
- RTS
- ;;;
- _PlotVertex:
- ;a0 = bpl to write
- ;a1 = pointer to vertex
- ;d0 = origin X
- ;d1 = origin Y
- add.w (a1),d0
- add.w 2(a1),d1
- JSR _SetPixel
- RTS
- ;;;
- _SetPixel:
- ;a0 = bpl to write
- ;d0 = x
- ;d1 = y
- mulu.w #PX_WIDE_BYTES,d1 ;d1 = y*pixelwidth
- divu #8,d0 ;d0.h = shift factor
- ;d0.l = pixel offset in bytes
- add.w d0,d1 ;d1 = y*pixelwidth + offset
- swap d0
- add.l d1,a0 ;a0 = bpl + (y*pixelwidth+offset)
- move.b #%10000000,d1
- lsr.b d0,d1 ;d1 = shifted pixel to set at a0
- or.b d1,(a0) ;(a0) = old | new
- RTS
- ;;;
- _DrawLine
- ;a0.l = bpl to write
- ;d0.w = x1
- ;d1.w = y1
- ;d2.w = x2
- ;d3.w = y2
- ;d4.w = width
- PRESERVE_A
- PRESERVE_D
- ext.l d0
- ext.l d1
- ext.l d2
- ext.l d3
- ext.l d4
- move.l #PX_WIDE_BYTES,d4
- lea CustomBase,a1 ; custom address
- sub.w d0,d2 ;calculate dX
- bmi xneg ;if neg, octant is in [3,4,5,6]
- sub.w d1,d3 ;calculate dY octant is in [1,2,7,8]
- bmi yneg ;if neg, octant is in [7,8]
- cmp.w d3,d2 ; octant is in [1,2]
- bmi ygtx ;if y>x, octant is 2
- moveq.l #OCTANT1+LINEMODE,d5 ;else octant is 1
- bra lineagain
- ygtx:
- exg d2,d3 ;X > Y for proper operation
- moveq.l #OCTANT2+LINEMODE,d5 ;octant is 2
- bra lineagain
- yneg:
- neg.w d3 ;abs(dY)
- cmp.w d3,d2 ;octant is in [7,8]
- bmi ynygtx ;if y>x, octant is 7
- moveq.l #OCTANT8+LINEMODE,d5 ;else octant is 8
- bra lineagain
- ynygtx:
- exg d2,d3 ;X > Y for proper operation
- moveq.l #OCTANT7+LINEMODE,d5 ;octant is 7
- bra lineagain
- xneg:
- neg.w d2 ;octant is in [3,4,5,6]
- sub.w d1,d3 ;calculate dY
- bmi xyneg ;if neg, octant is in [5,6]
- cmp.w d3,d2 ;else octant is in [3,4]
- bmi xnygtx ;if y>x, octant is 3
- moveq.l #OCTANT4+LINEMODE,d5 ;else octant is 4
- bra lineagain
- xnygtx:
- exg d2,d3 ;ensure X > Y
- moveq.l #OCTANT3+LINEMODE,d5 ;octant is 3
- bra lineagain
- xyneg:
- neg.w d3 ;octant is in [5,6]
- cmp.w d3,d2 ;y > x?
- bmi xynygtx ;octant is 6
- moveq.l #OCTANT5+LINEMODE,d5 ;else octant is 5
- bra lineagain
- xynygtx:
- exg d2,d3 ;ensure X > Y
- moveq.l #OCTANT6+LINEMODE,d5 ;octant is 6
- lineagain:
- mulu.w d4,d1 ;calculate y1*width
- ror.l #4,d0 ;move upper 4 bits into hi word
- add.w d0,d0 ;multiply by 2
- add.l d1,a0 ;ptr += (x1 >> 3)
- add.w d0,a0 ;ptr += y1*width
- swap d0 ;get the 4 bits of x1
- or.w #$0BFA,d0 ;OR with USEA|USEC|USED. F=A+C
- lsl.w #2,d3 ;Y = 4*Y
- add.w d2,d2 ;X = 2*X
- move.w d2,d1 ;set up the size word
- lsl.w #5,d1 ;shift five left
- add.w #$42,d1 ;add 1 to height, 2 to width
- jsr WaitBlit
- setBLT:
- move.w d3,bltbmod(a1) ;B mod = 4*Y
- sub.w d2,d3
- ext.l d3
- move.l d3,bltapt(a1) ;A ptr = 4*Y - 2*X
- bpl lineover
- or.w #SIGNFLAG,d5 ;set sign bit if negative
- lineover:
- move.w d0,bltcon0(a1) ;write the control registers
- move.w d5,bltcon1(a1)
- move.w d4,bltcmod(a1)
- move.w d4,bltdmod(a1)
- sub.w d2,d3
- move.w d3,bltamod(a1) ;A mod = 4*Y - 4*X
- move.w #$8000,bltadat(a1)
- moveq.l #-1,d5
- move.l d5,bltafwm(a1) ;hit both masks at once
- move.l a0,bltcpt(a1)
- move.l a0,bltdpt(a1)
- move.w d1,bltsize(a1)
- RESTORE_D
- RESTORE_A
- RTS
- ;;;;;;;;;;;;;;;;
- _RotatePoint:
- ;Rotate a point (d0.w,d1.w) around (0,0) by d2.w degrees.
- ;Returns new coordinates in (d0,d1).
- PRESERVE_A
- PRESERVE_D
- LINK a6,#-20
- move.l mathieeesingbas_base,a4
- move.l mathieeesingtrans_base,a5
- move.l d0,-4(a6)
- move.l d1,-8(a6)
- jsr IEEESPFlt(a4)
- move.l d0,-4(a6)
- move.l -8(a6),d0
- jsr IEEESPFlt(a4)
- move.l d0,-8(a6)
- ;formula: x' = x*cos(theta) - y*sin(theta)
- ; y' = y*cos(theta) + x*sin(theta)
- .calcSinCos
- move.w d2,d0
- JSR DegreesToRadians
- move.l d0,-12(a6) ;12(a6) = theta
- JSR IEEESPSin(a5)
- move.l d0,-16(a6) ;16(a6) = sin(theta)
- move.l -12(a6),d0
- JSR IEEESPCos(a5)
- move.l d0,-20(a6) ;20(a6) = cos(theta)
- .calcXPrime
- move.l -20(a6),d1
- move.l -4(a6),d0
- jsr IEEESPMul(a4)
- move.l d0,d6 ;d6 = x*cos(theta)
- move.l -16(a6),d1
- move.l -8(a6),d0
- jsr IEEESPMul(a4) ;d0 = y*sin(theta)
- move.l d6,d1
- jsr IEEESPSub(a4) ;d0 = x*cos(theta) - y*sin(theta)
- move.l d0,d5
- .calcYPrime
- move.l -8(a6),d0 ;d0 = y
- move.l -20(a6),d1 ;d1 = cos(theta)
- jsr IEEESPMul(a4) ;d0 = y*cos(theta)
- move.l d0,d6
- move.l -4(a6),d0 ;d0 = x
- move.l -16(a6),d1 ;d1 = sin(theta)
- jsr IEEESPMul(a4) ;d0 = x*sin(theta)
- move.l d6,d1
- jsr IEEESPAdd(a4) ;d0 = y*cos(theta) + x*sin(theta)
- .backToInteger
- jsr IEEESPFix(a4) ;d0 = INT(y)
- move.l d0,d1
- move.l d5,d0
- jsr IEEESPFix(a4) ;d0 = INT(x)
- UNLK a6
- RESTORE_D
- RESTORE_A
- RTS
- ;;;
- ResetBitplanePtr:
- move.l #Bitplane1,d0
- lea C_BitplanePtr,a1
- move.w d0,6(a1) ; low word of bitplane ptr
- swap d0
- move.w d0,2(a1) ; high word of bitplane ptr
- rts
- ;;;
- DegreesToRadians:
- ;d0 = degrees
- ;returns single-precision radian value in d0
- lea RadiansTable,a0
- asl.w #2,d0 ;get offset. each entry in table is 4 bytes
- add.w d0,a0
- move.l (a0),d0 ;retrieve value from table
- rts
- RadiansToDegrees:
- ;d0 = radians (single-precision)
- ;returns integer degrees value in d0.w
- ;TODO: lookup table
- PUSHL a6
- move.l mathieeesingbas_base,a6
- move.l ONEEIGHTY_DIV_PI,d1
- jsr IEEESPMul(a6)
- POPL a6
- RTS
- PrecalculateRadians:
- ;Calculate
- ;Populate the Radians table with values for 0-359 degrees.
- lea RadiansTable,a0
- move.l #0,d7
- .loop:
- move.l mathieeesingbas_base,a6
- move.l d7,d0
- jsr IEEESPFlt(a6)
- move.l PI_DIV_ONEEIGHTY,d1
- jsr IEEESPMul(a6) ;d0 degrees * 1 degrees in radians
- move.l d0,(a0)+
- addq.w #1,d7
- cmp.w #360,d7
- bne .loop
- .done:
- rts
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- CoolDemoStuff:
- lea Copperlist,a0
- move.l a0,cop1lc(a5)
- move.w #$8080,dmacon(a5)
- move.w #0,shape_rot_deg
- ; SetPixel Bitplane1,#0,#0
- ; PlotVertex Bitplane1,Square+2,#100,#100
- ; DrawLine Bitplane1,#20,#20,#20,#120
- FrameLoop:
- jsr WaitBlit
- addq.w #1,shape_rot_deg
- DrawShape Bitplane1,Square,#100,#100
- jsr ResetBitplanePtr
- jsr WaitForVBL
- MouseLoop:
- btst #CIAB_GAMEPORT0,_ciaa
- bne.w FrameLoop
- RTS
- ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- SECTION DATA,DATA_P
- ;dos.library
- dos_name DOSNAME
- dos_base dc.l 0
- ;graphics.library
- gfx_name GRAPHICSNAME
- even
- gfx_base dc.l 0
- ;mathieeesingbas.library
- mathieeesingbas_name dc.b "mathieeesingbas.library",0
- mathieeesingbas_base dc.l 0
- mathieeesingtrans_name dc.b "mathieeesingtrans.library",0
- mathieeesingtrans_base dc.l 0
- even
- ;;;
- shape_rot_deg dc.w 0
- PI dc.l $40490fdb ;IEEE 754 format
- PI_DIV_ONEEIGHTY dc.l $3c8efa35
- ONEEIGHTY_DIV_PI dc.l $42652ee1
- RadiansTable blk.l 360 ;precalculated radian value
- ;;;
- SECTION SHAPES,DATA_P
- ;Shape structure
- ; data+0 = WORD vertex count
- ; data+2 = WORD,WORD vertex X,Y
- ; data+6
- ; etc...
- RotatedVertexBuffer: blk.w 128
- Square:
- dc.w 4
- dc.w -50,-50
- dc.w 50,-50
- dc.w 50, 50
- dc.w -50, 50
- SECTION SINE,DATA_P
- include include/sine.s
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- SECTION CHIP,DATA_C
- ;Data for chip mem
- CNOP 0,4
- Copperlist:
- ;Draw a line to the bitplane before we display
- dc.w bplcon0,$1200 ;BPLCON0 = one bitplanes, color on
- dc.w bplcon1,$0000 ;BPLCON1 = no scrolling
- dc.w bpl1mod,$0000 ;Odd bitplane modulo of 0
- C_BitplanePtr:
- dc.w bpl1pth,0
- dc.w bpl1ptl,0
- dc.w diwstrt,$2c81 ;DIWSTRT
- dc.w diwstop,$f4c1 ;DIWSTOP
- dc.w ddfstrt,$0038 ;DDFSTRT
- dc.w ddfstop,$00d0 ;DDFSTOP
- dc.w color+0,$0000 ;COLOR00
- dc.w color+2,$00A0 ;COLOR01
- dc.w dmacon,$8180 ;DMACON on
- dc.w dmacon,$007f ;DMACON off
- dc.w intena,%1100000000000000 ;INTENA on
- dc.w intena,%0011111111111111 ;INTENA off
- dc.w $ffff,$fffe ;end
- CNOP 0,4
- Bitplane1 blk.b PX_BYTES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement