Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GAMEHUT.S
- TIMING EQU 0
- ;----------------------------------------------------------
- ; GAMEHUT SHELL
- ; BY JON BURTON - AUG 2018
- ;----------------------------------------------------------
- INCLUDE SYSTEM.S ;INCLUDES LOTS OF SYSTEM CODE TO MAKE ALL THIS POSSIBLE
- INCLUDE RINGS.S
- INCLUDE FLAME.S
- USERRAM: EQU FLAMEEND
- ;----------------------------------------------------------
- ; VRAM MEMORY MAP IN HEXADECIMAL
- ; (NOTE: CHARACTERS ARE 8 X 8 PIXEL BLOCKS)
- ;----------------------------------------------------------
- ; $0000-$0020 BLANK CHARACTER
- ; $0020-$8000 CHARACTERS FOR PLAYFIELDS AND SPRITES
- ; $C000-$D000 CHARACTER MAP FOR PLAYFIELD 1 (4096 BYTES)
- ; $E000-$F000 CHARACTER MAP FOR PLAYFIELD 2 (4096 BYTES)
- ; $F800 SPRITE TABLE (960 BYTES)
- ;----------------------------------------------------------
- ; USER VARIABLES
- ; - PUT ANY VARIABLES YOU NEED HERE
- ;----------------------------------------------------------
- RSSET USERRAM
- PLAYX: RS.L 0
- PLAY1X: RS.W 1 ;X POSITION OF PLAYFIELD 1
- PLAY2X: RS.W 1 ;X POSITION OF PLAYFIELD 2
- PLAYY: RS.L 0
- PLAY1Y: RS.W 1 ;Y POSITION OF PLAYFIELD 1
- PLAY2Y: RS.W 1 ;Y POSITION OF PLAYFIELD 2
- SONICX: RS.W 1 ;SONIC'S X POSITION
- SONICY: RS.W 1 ;SONIC'S Y POSITION
- SONICD: RS.W 1 ;SONIC'S DIRECTION
- TEMPSCREEN: RS.B 4096 ;RAM TO BUILD TEMPORARY SCREEN MAP
- ENDVARS: RS.B 0
- ;----------------------------------------------------------
- ; INITIALISE USER STUFF
- ; - THIS IS WHERE YOU SET UP STUFF BEFORE YOU BEGIN
- ;----------------------------------------------------------
- USERINIT: MOVE.W #0,PLAY1X ;SET START PLAYFIELD 1 X POSITION TO ZERO
- MOVE.W #0,PLAY1Y ;SET START PLAYFIELD 1 Y POSITION TO ZERO
- DMADUMP MAPGFX,4*32,$820 ;DUMP 4 CHARACTERS (SIZE 32 BYTES EACH) TO VRAM LOCATION $820 (MAP GRAPHICS)
- DMADUMP SPRITEGFX,8*32,$1000 ;DUMP 8 CHARACTERS (SIZE 32 BYTES EACH) TO VRAM LOCATION $1000 (SPRITE GRAPHICS)
- DMADUMP RINGGFX,4*32,$1000+$100 ;DUMP 8 CHARACTERS (SIZE 32 BYTES EACH) TO VRAM LOCATION $1100 (SPRITE GRAPHICS, AFTER SONIC)
- LEA.L TEMPSCREEN,A0 ;POINT A0 TO TEMPORARY BUFFER IN RAM TO BUILD MAP BEFORE WE COPY TO VRAM
- MOVE.W #8-1,D3 ;WE'LL MAKE 8 COPIES OF THIS PATTERN
- @L4: LEA.L CHARGFX,A1 ;POINT A1 TO CHARGFX, WHICH IS THE 8 CHARACTER X 4 CHARACTER PATTERN WE'LL COPY MULITPLE TIMES
- MOVE.W #4-1,D1 ;4 ROWS
- @L3: MOVE.W #8-1,D0 ;COPY EACH ROW REPEATED ACROSS THE SCREEN 8 TIMES HORIZONTALLY
- @L2: MOVE.W #4-1,D2 ;4 LONG-WORDS = 8 CHARACTERS WIDE
- @L1: MOVE.L (A1)+,(A0)+ ;COPY FROM CHARGFX TO THE TEMPSCREEN. THE + MEANS INCREMENT THE POINTERS
- DBRA D2,@L1 ;LOOP BACK TO @L1
- SUB.L #16,A1 ;POINT BACK TO THE START OF THE CURRENT CHARGFX ROW
- DBRA D0,@L2 ;LOOP BACK TO @L2
- ADD.L #16,A1 ;MOVE ONTO THE NEXT CHARGFX ROW
- DBRA D1,@L3 ;LOOP BACK TO @L3
- DBRA D3,@L4 ;LOOP BACK TO @L4
- DMADUMP TEMPSCREEN,4096,$C000 ;COPY TEMPSCREEN WHICH IS 4096 BYTES IN SIZE TO VRAM ADDRESS $C000
- LEA.L PALETTE1,A0 ;DOWNLOAD A PALETTE FOR THE MAP TO USE
- BSR SETPAL1 ;OVERRIGHT FIRST PALETTE
- LEA.L PALETTE2,A0 ;DOWNLOAD A PALETTE FOR THE SPRITES TO USE
- BSR SETPAL2 ;OVERRIGHT SECOND PALETTE
- MOVE.W #$80+160-8,SONICX ;SONIC'S X START POSITION
- MOVE.W #$80+112-13,SONICY ;SONIC'S Y START POSITION
- MOVE.W #0,SONICD ;SONIC'S START DIRECTION
- JSR INITFLAME
- JSR RINGINIT
- JSR DUMPCOLS ;COPY ALL PALETTES TO CRAM (COLOUR RAM)
- RTS
- ;------------------------------
- ; MAIN GAME LOOP
- ;------------------------------
- MAIN: WAITVBI ;WAITS FOR THE START OF THE NEXT FRAME
- IF TIMING
- WDEST CRAMW,$0000 ;COLOUR TIMING BAR
- MOVE.W #$000F,VDP_DATA ;IN RED
- ENDC
- JSR DRAWFLAME
- ADD.W #1,PLAY1X ;SCROLL PLAYFIELD 1 RIGHT BY ONE PIXEL
- ADD.W #1,PLAY1Y ;SCROLL PLAYFIELD 1 UP BY ONE PIXEL
- ;ADD SPRITES
- LEA.L SPRITETEMP,A1 ;POINT TO TEMPORARY MEMORY TO BUILD SPRITE LIST
- MOVE.W #1,D7 ;SPRITE NUMBER
- ;FIRST SONIC
- MOVE.W SONICY,(A1)+ ;Y POSITION ($80 IS TOP OF SCREEN)
- MOVE.W #S_2X4,D0 ;SIZE 2X4 CHARACTERS
- ADD.W D7,D0 ;ADD CURRENT SPRITE NUMBER
- MOVE.W D0,(A1)+ ;WRITE TO SPRITE TABLE
- MOVE.W #S_PAL2+$1000/32,D0 ;PALETTE NUMBER+GRAPHIC VRAM LOCATION/32
- ADD.W SONICD,D0 ;ADD SONIC'S DIRECTION
- MOVE.W D0,(A1)+ ;WRITE TO SPRITE TABLE
- MOVE.W SONICX,(A1)+ ;X POSITION ($80 IS LEFT OF SCREEN)
- ADDQ.W #1,D7 ;MOVE ON TO NEXT SPRITE NUMBER
- JSR PROCRING ;ADD ANY RINGS TO SPRITELIST
- ;A1=POINTER TO NEXT SPRITE ENTRY
- ;D7=NEXT SPRITE NUMBER
- ;FINISHED ADDING SPRITES
- MOVE.L #$10000,(A1)+ ;TERMINATE SPRITE LIST
- MOVE.L #1,(A1)+ ; " "
- JSR CONVFLAME
- ;MOVE SONIC
- BTST #J_RIGHT,JOYPAD0
- BNE.S @MOVE1
- ADD.W #1,SONICX
- MOVE.W #0,SONICD
- @MOVE1:
- BTST #J_LEFT,JOYPAD0
- BNE.S @MOVE2
- SUB.W #1,SONICX
- MOVE.W #$800,SONICD
- @MOVE2:
- BTST #J_DOWN,JOYPAD0
- BNE.S @MOVE3
- ADD.W #1,SONICY
- @MOVE3:
- BTST #J_UP,JOYPAD0
- BNE.S @MOVE4
- SUB.W #1,SONICY
- @MOVE4:
- BTST #J_BUT_A,JOYPAD0
- BNE.S @NORING
- ;ADD A RING
- MOVE.W SONICX,D3 ;X POS
- MOVE.W SONICY,D4 ;Y POS
- JSR GETRANDOM ;RETURNS A RANDOM NUMBER FROM 0-255 IN REGISTER D0
- MOVE.L D0,D5
- EXT.W D5 ;NUMBER FROM -126 TO +127
- SWAP D5 ;ADDS PRECISION
- ASR.L #6,D5 ;REMOVE A BIT OF PRECISION - X MOMENTUM
- JSR GETRANDOM ;RETURNS A RANDOM NUMBER FROM 0-255 IN REGISTER D0
- MOVE.L D0,D6
- EXT.W D6 ;NUMBER FROM -126 TO +127
- SWAP D6 ;ADDS PRECISION
- ASR.L #6,D6 ;REMOVE A BIT OF PRECISION
- ADD.L #-$30000,D6 ;Y MOMENTUM
- MOVE.L #$1000,D7 ;GRAVITY
- JSR ADDRING
- @NORING:
- IF TIMING
- WDEST CRAMW,$0000
- MOVE.W #$0000,VDP_DATA
- ENDC
- BRA MAIN ;LOOP BACK TO WAIT FOR NEXT FRAME
- ;----------------------------------------------------------
- ; USER VBI ROUTINES
- ; - PUT TIME CRITICAL CODE THAT MUST CALLED DURING THE VERTICAL BLANK HERE
- ;----------------------------------------------------------
- USERVBI: LEA.L VDP_DATA,A1
- LEA.L VDP_CONTROL,A2
- ;SET HORIZONTAL OFFSETS
- MOVE.L #$7C000003,(A2)
- MOVE.L PLAYX,(A1) ;THIS TELLS THE VDP (VISUAL DISPLAY PROCESSOR) WHAT X POSITION THE PLAYFIELDS SHOULD BE AT
- ;SET VERTICAL OFFSETS
- MOVE.L #$40000010,(A2) ;THIS TELLS THE VDP WHAT Y POSITION THE PLAYFIELDS SHOULD BE AT
- MOVE.L PLAYY,(A1)
- ;COPY SPRITE TABLE TO VRAM
- JSR SPRITEDUMP
- ;READ JOYPAD
- BSR READJOY ;READ THE JOYPAD
- RTS
- ;----------------------------------------------------------
- ; PUT DATA BELOW HERE
- ;----------------------------------------------------------
- ;----------------------------------------------------------
- ; CHARACTER CODES TO BUILD OUR PATTERN
- ;
- ; THE CODE IS IN THE FORMAT $NNNN
- ;
- ; THE LAST TWO NUMBERS ($00NN) REFER TO THE CHARACTER NUMBER IN VRAM TO USE
- ; (THE CHARACTER NUMBER IS THE VRAM ADDRESS DIVIDED BY 32 (OR DIVIDED BY $20 HEXADECIMAL))
- ;
- ; IF THE FIRST NUMBER ($N000) IS '1' IT MEANS MIRROR THE CHARACTER VERTICALLY
- ; IF THE SECOND NUMBER ($0N00) IS '8' IT MEANS MIRROR THE CHARACTER HORIZONTALLY
- ;
- ; SO WHEN WE HAVE A DIAGONAL CHARACTER LINE THIS - / WE CAN MIRROR IT TO GET THIS \
- ; SO WE CAN BUILD THIS - /\
- ; \/ USING ONE DIAGONAL AND MIRRORING
- ;----------------------------------------------------------
- CHARGFX incbin Uncompressed\Mapunc_CHARGFX.bin
- ;----------------------------------------------------------
- ; MAP GRAPHICS
- ;----------------------------------------------------------
- MAPGFX incbin Uncompressed\Artunc_MAPGFX.smd
- ;----------------------------------------------------------
- ; SPRITE GRAPHICS
- ; 2 X 4 CHARACTERS ARRANGED AS FOLLOWS -
- ;
- ; 1 5
- ; 2 6
- ; 3 7
- ; 4 8
- ;----------------------------------------------------------
- SPRITEGFX incbin Uncompressed\Artunc_SPRITEGFX.smd
- ;----------------------------------------------------------
- RINGGFX incbin Uncompressed\Artunc_RINGGFX.smd
- ;----------------------------------------------------------
- ; USER PALETTES
- ;----------------------------------------------------------
- PALETTE1 incbin Palettes\pallet1.bin
- PALETTE2 incbin Palettes\pallet2.bin
- PALETTE3 incbin Palettes\pallet3.bin
- SYSTEM.S
- ;----------------------------------------------------------
- ; REGISTER EQUATES
- ;----------------------------------------------------------
- Z80REQ: EQU $A11100
- Z80RES: EQU $A11200
- Z80RAM: EQU $A00000
- B4: EQU 1<<4
- B30: EQU 1<<30
- VDP_DATA: EQU $FFC00000
- VDP_STATUS: EQU $FFC00004
- VDP_CONTROL: EQU $FFC00004
- VRAMW: EQU %01*B30+%0000*B4
- CRAMW: EQU %11*B30+%0000*B4
- VSRAMW: EQU %01*B30+%0001*B4
- VRAMR: EQU %00*B30+%0000*B4
- CRAMR: EQU %00*B30+%0010*B4
- VSRAMR: EQU %00*B30+%0001*B4
- ;DMA MEMORY BLOCK DESTINATIONS
- DMAVRAM: EQU %01*B30+%1000*B4
- DMACRAM: EQU %11*B30+%1000*B4
- DMAVSRAM: EQU %01*B30+%1001*B4
- STACK_SIZE: EQU 1024
- RSSET $FFFF0000
- WORKRAM: RS.B STACK_SIZE
- ENDSTACK: RS.B 0
- SYSTEMRAM: RS.B 0
- DMANUM: EQU 80
- ;JOYPAD STUFF
- JSDATA1: EQU $00A10003
- JSDATA2: EQU $00A10005
- JSDATA3: EQU $00A10007
- JSCTRL: EQU $00A10009
- JSCTRL1: EQU $00A10009
- JSCTRL2: EQU $00A1000b
- JSCTRL3: EQU $00A1000d
- MDSCTRL1: EQU $00A10013
- MDSCTRL2: EQU $00A10019
- MDSCTRL3: EQU $00A1001f
- J_UP: EQU 0
- J_DOWN: EQU 1
- J_LEFT: EQU 2
- J_RIGHT: EQU 3
- J_BUT_B: EQU 4
- J_BUT_C: EQU 5
- J_BUT_A: EQU 6
- ;SPRITE STUFF
- S_1X1: EQU 0<<8
- S_1X2: EQU 1<<8
- S_1X3: EQU 2<<8
- S_1X4: EQU 3<<8
- S_2X1: EQU 4<<8
- S_2X2: EQU 5<<8
- S_2X3: EQU 6<<8
- S_2X4: EQU 7<<8
- S_3X1: EQU 8<<8
- S_3X2: EQU 9<<8
- S_3X3: EQU 10<<8
- S_3X4: EQU 11<<8
- S_4X1: EQU 12<<8
- S_4X2: EQU 13<<8
- S_4X3: EQU 14<<8
- S_4X4: EQU 15<<8
- S_PAL1: EQU $0000
- S_PAL2: EQU $2000
- S_PAL3: EQU $4000
- S_PAL4: EQU $6000
- ;----------------------------------------------------------
- ; USEFUL MACROS
- ;----------------------------------------------------------
- WAITDMA: MACRO
- @LOOP\@ BTST #1,VDP_STATUS+1
- BNE.S @LOOP\@
- ENDM
- WREG: MACRO
- MOVE #$8000!((\1)<<8)!((\2)&$FF),VDP_CONTROL
- ENDM
- WREGR: MACRO
- AND #$00FF,\2
- OR #VDP_R\1,\2
- MOVE \2,VDP_CONTROL
- ENDM
- WDEST: MACRO
- MOVE.L #\1+((\2)&$3FFF)<<16+(\2)>>14,VDP_CONTROL
- ENDM
- WDESTR: MACRO
- ROL.L #2,\2
- ROR #2,\2
- SWAP \2
- AND.L #$3FFF0003,\2
- OR.L #\1,\2
- MOVE.L \2,VDP_CONTROL
- ENDM
- WAITVBI: MACRO
- MOVE.W #0,VBLANKON
- @LOOP\@: CMP.W #0,VBLANKON
- BEQ.S @LOOP\@
- ENDM
- DMADUMP: MACRO
- MOVE.L #(\2)/2,D0
- MOVE.L #\1,D1
- MOVE.L #\3,D2
- JSR DMADUMPS
- ENDM
- DMAFPAL: MACRO
- MOVE.L #(((\2)/2)&$FF)<<16+(((\2)/2)&$FF00)>>8+$93009400,D0 ;LENGTH
- MOVE.L #((((\1)/2)&$FF)<<16)+((((\1)/2)&$FF00)>>8)+$95009600,D1
- MOVE.W #(((\1)/2)&$7F0000)>>16+$9700,D2 ;SOURCE
- MOVE.W #((\3)&$3FFF)+$C000,D3 ;CRAM
- MOVE.W #((\3)&$C000)>>14+$0080,D4 ;CRAM
- JSR RAMDMAF
- ENDM
- ;----------------------------------------------------------
- ; SYSTEM VARIABLES
- ;----------------------------------------------------------
- RSSET SYSTEMRAM ;POINT AT SYSTEM RAM (AFTER STACK)
- STARTVARS: RS.B 0 ;POINTER TO START OF VARS
- HOTSTART: RS.W 1 ;HOT START FLAG
- VBLANKON: RS.W 1 ;FLAG TO SAY WHEN VERTICAL BLANK CODE IS FINISHED
- VBIVECTOR: RS.L 1 ;LOCATION OF VBLANK ROUTINE
- JOYPAD0: RS.B 1 ;JOYPAD INFORMATION
- JOYPADOLD: RS.B 1 ;JOYPAD INFORMATION FROM LAST FRAME
- RS.W 1 ;QUICK SOURCE UNUSED
- QSOURCE: RS.L 1 ;QUICK SOURCE
- RS.W 1 ;QUICK SOURCE
- QSIZE: RS.L 1 ;QUICK SIZE RAM
- DMAREQ: RS.W DMANUM*7 ;DMA REQUEST STORE
- RS.L 1 ;OVERRUN
- RAMDMA: RS.B 200 ;RAM DMAS
- PALETTES: RS.W 16*4 ;PALETTE ON SCREEN
- SPRITETEMP: RS.W 120*4 ;TABLE FOR SPRITE DATA(80 SPRITES + 40 OVERRUN)
- RANDOM: RS.L 1 ;POINTER TO RANDOM NUMBER
- DECRUNCH: RS.B 8192 ;TEMP AREA FOR STUFF
- SYSTEMEND: RS.B 0
- ;----------------------------------------------------------
- ; CARTRIDGE HEADER INFORMATION
- ;----------------------------------------------------------
- ORG $0000
- DC.L ENDSTACK ;STACK POINTER
- DC.L CODESTART ;PROGRAM COUNTER
- ORG $0068
- DC.L EXTINT
- DC.L ERROR
- DC.L HBLANK
- DC.L ERROR
- DC.L VBLANK
- REPT 33
- DC.L ERROR
- ENDR
- CARTRIDGEDATA: DC.B "SEGA GENESIS "
- DC.B "GAMEHUT 2018.MAR"
- TITLE: DC.B "GAMEHUT TEST SHELL "
- DC.B "GAMEHUT TEST SHELL "
- DC.B "GH 00-0001 -01" ;PRODUCT NO;VERSION
- DC.W 0 ;CHECKSUM
- DC.B "J " ;CONTROL DATA
- DC.L $000000,$3FFFFF ;ROM ADDRESS
- DC.L $FF0000,$FFFFFF ;RAM ADDRESS
- DC.B " " ;EXTERNAL RAM.
- DC.B " " ;MODEM DATA
- DC.B " " ;MEMO
- DC.B "F " ;RELEASE CODES
- ; NORG $0200
- ;----------------------------------------------------------
- ; SYSTEM INIT
- ;----------------------------------------------------------
- CODESTART: MOVE.W #$2700,SR
- MOVE.W #1,HOTSTART
- TST.L $A10008
- BNE.S @HOTSTART
- TST.W $A1000C
- BNE.S @HOTSTART
- CLR.W HOTSTART
- MOVE.B $A10001,D0
- ANDI.B #$F,D0
- BEQ.S @J1
- MOVE.L #'SEGA',$A14000
- @J1:
- MOVE.L #$C0000000,$C00004
- CLR.L D1
- MOVE.W #$3F,D0
- @CLR1: MOVE.W D1,$C00000
- DBF D0,@CLR1
- LEA.L $FFFF0000,A0
- MOVE.W #$3FFF,D0
- @CLR2: MOVE.L D1,(A0)+
- DBF D0,@CLR2
- @HOTSTART: LEA.L ENDSTACK,SP ;SET UP STACK POINTER
- BSR.W INIT_Z80
- MOVE.W #$2300,SR
- WAITDMA ;WAIT FOR ANY DMA'S TO FINISH
- MOVE.W #$2700,SR ;STOP ALL INTERUPTS
- MOVE.L #NULL,VBIVECTOR ;SETUP DUMMY VERTICAL BLANK ROUTINE
- JSR INIT_VDP_REG
- JSR CLEARCRAM
- JSR CLEARVSRAM
- JSR CLEARVRAM
- MOVE #$2000,SR ;ENABLE INTERUPTS
- WREG 1,%01100100 ;ENABLE VBLANK
- WREG 0,%00000100 ;DISABLE HBLANK
- TST.W HOTSTART ;WAS IT A 'HOT START'?
- BNE.S @HOT
- ;HARD RESET CODE HERE IF NEEDED
- BRA.S @SKIP
- @HOT: MOVE.W #50-1,D0 ;STOP RESET BUG
- @PAUSE: WAITVBI
- DBRA D0,@PAUSE
- @SKIP: JSR JOYINIT ;INITIALIZE JOYPADS
- JSR SETUPRAM ;COPY IN PERMANENT RAM ROUTINES
- WDEST VSRAMW,$0000 ;VSCROLL OFFSET
- MOVE.L #0,VDP_DATA
- WDEST VRAMW,$FC00 ;HSCROLL OFFSET
- MOVE.L #0,VDP_DATA
- MOVE.L #$FC00,A0 ;CLEAR HSCROLL TABLE
- MOVE.L #896,D0
- BSR CLEARVRAM2
- MOVE.L #$C000,A0 ;CLEAR MAP1
- MOVE.L #4096,D0
- BSR CLEARVRAM2
- MOVE.L #$E000,A0 ;CLEAR MAP2
- MOVE.L #4096,D0
- BSR CLEARVRAM2
- MOVE.L #$0000,A0 ;CLEAR FIRST BLOCK IN VIDEO MEMORY
- MOVE.L #32,D0
- BSR CLEARVRAM2
- LEA.L SYSPALETTE,A0
- BSR SETPAL1
- LEA.L SYSPALETTE,A0
- BSR SETPAL2
- LEA.L SYSPALETTE,A0
- BSR SETPAL3
- LEA.L SYSPALETTE,A0
- BSR SETPAL4
- JSR DUMPCOLS
- JSR SPRITEINIT
- JSR USERINIT
- MOVE.L #RANDOM_NUMS,RANDOM
- MOVE.L #MAINVBI,VBIVECTOR ;START MAIN VERTICAL BLANK ROUTINE
- JMP MAIN ;JUMP TO START OF USER CODE
- ;----------------------------------------------------------
- ; INITIALIZE VDP
- ; SETUP VIDEO FOR 40 COLUMNS AND
- ; 28 LINES (320x224).
- ;----------------------------------------------------------
- INIT_VDP_REG: WREG 15,%00000010 ;ALWAYS ASSUME WORD INC
- WREG 00,%00000100 ;INTERUPTS OFF
- WREG 01,%00000100 ;SCREEN SETUP
- WREG 02,%00110000 ;SCREEN A
- WREG 03,%00000000 ;WINDOW
- WREG 04,%00000111 ;SCREEN B
- WREG 05,%00000000 ;SPRITE ATTRIBUTE TABLE
- WREG 06,%00000000 ;
- WREG 07,%00000000 ;BACKGROUND COLOUR
- WREG 08,%00000000 ;
- WREG 09,%00000000 ;
- WREG 10,%11111111 ;HORIZ INT COUNT
- WREG 11,%00000000 ;FULL SCROLL
- WREG 12,%10000001 ;320 WIDE NO HALF BRITE
- WREG 13,%00111111 ;HORIZ SCROLL TABLE POINT
- WREG 14,%00000000 ;
- WREG 16,%00000001 ;SCROLL SIZE
- WREG 17,%00000000 ;WINDOW H POS
- WREG 18,%00000000 ;WINDOW V POS
- WREG 15,%00000010 ;ALWAYS ASSUME WORD INC
- RTS
- ;----------------------------------------------------------
- ; CLEAR VRAM TO 0
- ;----------------------------------------------------------
- CLEARVRAM: WDEST VRAMW,$0000
- MOVE.L #$800-1,D0
- MOVEQ.L #$0,D1
- LEA.L VDP_DATA,A0
- @LOOP: MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- MOVE.L D1,(A0)
- DBRA D0,@LOOP
- RTS
- ;----------------------------------------------------------
- ; CLEAR VRAM FROM A0
- ; LENGTH D0 TO 0
- ;----------------------------------------------------------
- CLEARVRAM2: MOVE.L A0,D1
- WDESTR VRAMW,D1
- MOVEQ.L #$0,D1
- LSR.L #2,D0
- SUB.L #1,D0
- LEA.L VDP_DATA,A0
- @LOOP: MOVE.L D1,(A0)
- DBRA D0,@LOOP
- RTS
- ;----------------------------------------------------------
- ; CLEAR COLOUR RAM (CRAM) TO 0
- ;----------------------------------------------------------
- CLEARCRAM: WDEST CRAMW,$0000
- MOVE.L #64-1,D0
- MOVEQ.L #0,D1
- LEA.L VDP_DATA,A0
- @LOOP: MOVE.W D1,(A0)
- DBRA D0,@LOOP
- RTS
- ;----------------------------------------------------------
- ; CLEAR VIDEO RAM (VSRAM) TO 0
- ;----------------------------------------------------------
- CLEARVSRAM: WDEST VSRAMW,$0000
- MOVE.L #128/2-1,D0
- MOVEQ.L #0,D1
- LEA.L VDP_DATA,A0
- @LOOP: MOVE.W D1,(A0)
- DBRA D0,@LOOP
- RTS
- ;----------------------------------------------------------
- ; CLEAR USER RAM TO 0
- ;----------------------------------------------------------
- CLEARRAM: LEA.L STARTVARS,A0
- MOVE.L #(ENDVARS-STARTVARS)-1,D0
- MOVEQ.L #0,D1
- @LOOP: MOVE.B D1,(A0)+
- DBRA D0,@LOOP
- RTS
- ;----------------------------------------------
- ; INITIALIZE THE Z80
- ;----------------------------------------------
- INIT_Z80: MOVE.W #$100,D0
- LEA.L Z80REQ,A0
- LEA.L Z80RES,A1
- MOVE.W D0,(A0)
- MOVE.W D0,(A1)
- @WAIT_Z80: BTST #0,(A0)
- BNE.S @WAIT_Z80
- LEA.L @INITCODE,A2
- LEA.L Z80RAM,A3
- MOVE.W #@CODEEND-@INITCODE-1,D1
- @LOOP: MOVE.B (A2)+,(A3)+
- DBF D1,@LOOP
- CLR.W (A1)
- CLR.W (A0)
- MOVE.W D0,(A1)
- RTS
- @INITCODE incbin Music\Z80_INITCODE.bin
- even
- @CODEEND:
- ;----------------------------------------------------------
- ; INIT JOY
- ;----------------------------------------------------------
- JOYINIT: MOVE.B #$00,MDSCTRL1
- MOVE.B #$00,MDSCTRL2
- MOVE.B #$00,MDSCTRL3
- MOVE.B #$40,JSCTRL
- MOVE.B #$40,JSCTRL1
- MOVE.B #$40,JSCTRL2
- MOVE.B #$40,JSCTRL3
- MOVE.B #$40,JSDATA1
- MOVE.B #$40,JSDATA2
- MOVE.B #$40,JSDATA3
- RTS
- ;----------------------------------------------------------
- ; READ JOYSTICK
- ;----------------------------------------------------------
- JOYGET6: movem.l d1/d2/d3/d4/d5/a0,-(sp)
- moveq #0,d0
- cmp.w #$0002,d1
- bhi @JOYGET6_ERR
- add.w d1,d1
- move.l #$00a10003,a0 ;joystick data port address
- move.b #$40,6(a0,d1.w) ;set TH = output
- nop
- nop
- move.b #$40,(a0,d1.w) ; select [ ? 1 TRG-C TRG-B R L D U ]
- moveq #0,d2
- nop
- nop
- nop
- move.b $00(a0,d1.w),d2 ; d2 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U
- cmp.b #$70,d2 ; checking for mouse or other handshaking device
- beq @JOYGET6_ERR
- move.b #$00,(a0,d1.w) ; select [ ? 0 START TRG-A 0 0 D U ]
- lsl.w #8,d2 ; d2 = ? 1 TRG-C TRG-B R L D U|0 0 0 0 0 0 0 0
- move.b $00(a0,d1.w),d2 ;d2 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 D U
- cmp.b #$3f,d2 ; checking for nothing connected
- beq @JOYGET6_ERR
- move.b #$40,(a0,d1.w) ; select [ ? 1 TRG-C TRG-B R L D U ]
- moveq #0,d3
- nop
- nop
- nop
- move.b $00(a0,d1.w),d3 ; d3 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U
- move.b #$00,(a0,d1.w) ; select [ ? 0 START TRG-A 0 0 D U ]
- lsl.w #8,d3
- move.b $00(a0,d1.w),d3 ;d3 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 D U
- move.b #$40,(a0,d1.w) ; select [ ? 1 TRG-C TRG-B R L D U ]
- moveq #0,d4
- nop
- nop
- nop
- move.b $00(a0,d1.w),d4 ; d4 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U
- move.b #$00,(a0,d1.w) ; select [ ? 0 START TRG-A 0 0 0 0 ]
- lsl.w #8,d4
- move.b $00(a0,d1.w),d4 ;d4 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 0 0
- move.b #$40,(a0,d1.w) ; select [ ? 1 0 0 MD TX TY TZ ]
- moveq #0,d5
- nop
- nop
- nop
- move.b $00(a0,d1.w),d5 ; d5 = 0000|0000|? 1 0 0 MD TX TY TZ
- move.b #$00,(a0,d1.w) ; select [ ? 0 0 0 1 1 1 1 ]
- lsl.w #8,d5
- move.b $00(a0,d1.w),d5 ;d5 = ? 1 0 0 MD TX TY TZ| ? 0 0 0 1 1 1 1
- move.b #$40,(a0,d1.w)
- cmp.w d2,d3
- bne @JOYGET6_ERR ; nothing connected or unknown device
- cmp.w d3,d4
- beq @JOYGET3_PAD ; regular 3 button controller
- and.w #$000f,d4
- bne @JOYGET6_ERR
- move.b d2,d0
- lsl.w #4,d0 ;d0.w = 0000|? 0 St TA 0 0 D U 0 0 0 0
- lsr.w #8,d2 ;d2.w = 0000|0000|? 1 TC TB R L D U
- move.b d2,d0 ;d0.w = 0000|? 0 St TA ? 1 TC TB R L D U
- lsl.b #2,d0 ;d0.w = 0000|? 0 St TA TC TB R L D U 0 0
- lsr.w #2,d0 ;d0.w = 0000|0 0 ? 0|St TA TC TB R L D U
- and.l #$000000ff,d0
- lsl.b #4,d5 ;d5.w = ? 1 0 0 MD TX TY TZ|1 1 1 1 0 0 0 0
- lsl.w #4,d5 ;d5.w = MD TX TY TZ 1 1 1 1 0 0 0 0 0 0 0 0
- or.w d5,d0 ;d0.w = MD TX TY TZ 1 1 1 1 St TA TC TB R L D U
- or.l #$80000000,d0 ;d0.l=1xxx|xxxx|xxxx|xxxx|MD,TX,TY,TZ,St,TA,TC,TB,R,L,D,U
- bra @JOYGET6_ERR
- @JOYGET3_PAD:
- move.b d2,d0
- lsl.w #4,d0 ;d0.w = 0000|? 0 St TA 0 0 D U 0 0 0 0
- lsr.w #8,d2 ;d2.w = 0000|0000|? 1 TC TB R L D U
- move.b d2,d0 ;d0.w = 0000|? 0 St TA ? 1 TC TB R L D U
- lsl.b #2,d0 ;d0.w = 0000|? 0 St TA TC TB R L D U 0 0
- lsr.w #2,d0 ;d0.w = 0000|0 0 ? 0|St TA TC TB R L D U
- and.l #$000000ff,d0 ;d0.l=0xxx|xxxx|xxxx|xxxx|xxxx|xxxx|St,TA,TC,TB,R,L,D,U
- @JOYGET6_ERR:
- movem.l (sp)+,d1/d2/d3/d4/d5/a0
- rts
- ;----------------------------------------------------------
- ; NEW READ JOY
- ;----------------------------------------------------------
- READJOY: MOVE.W #$100,Z80REQ
- @L1: BTST #0,Z80REQ
- BNE.S @L1
- MOVE.B JOYPAD0,JOYPADOLD ;STORE OLD PAD INFO FOR DEBOUNCE IF NEEDED
- MOVE.W #0,D1
- BSR JOYGET6
- MOVE.W #0,Z80REQ
- TST.B D0 ;DID JOYPAD READ FAIL?
- BNE.S @PASS
- MOVE.B #$FF,D0
- @PASS: MOVE.B D0,JOYPAD0
- RTS
- ;----------------------------------------------------------
- ; INTERUPT ROUTINES
- ;----------------------------------------------------------
- ;----------------------------------------------------------
- ; VERTICAL BLANK HANDLER
- ;----------------------------------------------------------
- VBLANK: MOVE.L VBIVECTOR,-(A7)
- RTS
- NULL: MOVE.W #1,VBLANKON
- RTE
- MAINVBI: MOVEM.L A0-A6/D2-D7,-(SP) ;PUSH REGISTERS
- JSR USERVBI
- JSR READJOY
- MOVEM.L (SP)+,A0-A6/D2-D7 ;RESTORE REGISTERS
- MOVE.W #1,VBLANKON ;TELL MAIN LOOP THAT VBI CODE HAS FINISHED
- RTE
- ;----------------------------------------------------------
- ; HORIZONTAL BLANK INTERUPT
- ;----------------------------------------------------------
- HBLANK: RTE
- ;----------------------------------------------------------
- ; EXTERNAL INTERUPT
- ;----------------------------------------------------------
- EXTINT: RTE
- ;------------------------------
- ; ERROR HANDLING CODE
- ;------------------------------
- ERROR: MOVE.W #$2700,SR ;TURN OFF INTERUPTS
- @INF: BRA.S @INF ;INFINITE LOOP
- ;----------------------------------------------------------
- ; DUMP DATA VIA DMA
- ; D0=SIZE IN WORDS
- ; D1=SOURCE ADDRESS
- ; D2=DESTINATION ADDRESS
- ; A0,A1,D3,D4,D5,D6 TRASHED
- ;----------------------------------------------------------
- DMADUMPS: LEA.L VDP_CONTROL,A1
- AND.L #$FFFFFF,D1 ;MAKE SURE IN ROM/RAM
- MOVE.W D0,D3
- ADD.W D3,D3
- MOVE.W D1,D4
- ADD.W D3,D4
- BEQ.S @PASS
- BCS @TWO
- @PASS:
- MOVE.W #$100,Z80REQ
- @L1: BTST #0,Z80REQ
- BNE.S @L1
- WREG 01,%01110100 ;DMA ENABLE
- JSR RAMDMA
- WAITDMA
- WREG 01,%01100100 ;DMA DISABLE
- MOVE.W #0,Z80REQ
- RTS
- @TWO: SUB.W D4,D3
- LSR.W #1,D3
- MOVE.W D3,D0
- MOVE.L D1,D5
- MOVE.L D2,D6
- MOVE.W #$100,Z80REQ
- @L2: BTST #0,Z80REQ
- BNE.S @L2
- WREG 01,%01110100 ;DMA ENABLE
- JSR RAMDMA
- MOVE.L D5,D1
- MOVE.L D6,D2
- ADD.W D3,D2
- ADD.W D3,D2
- ADD.L #$10000,D1
- CLR.W D1
- MOVE.W D4,D0
- LSR.W #1,D0
- JSR RAMDMA
- WAITDMA
- WREG 01,%01100100 ;DMA DISABLE
- MOVE.W #0,Z80REQ
- RTS
- ;----------------------------------------------------------
- ; RAM DMA ROUTINES
- ; A1=VDP_CONTROL
- ; D0=SIZE
- ; D1=SOURCE
- ; D2=DEST
- ; A0,D1,D2 TRASHED
- ;----------------------------------------------------------
- RAMDMAC: LEA.L QSOURCE+10,A0
- LSR.L #1,D1
- LSL.L #2,D2
- LSR.W #2,D2
- SWAP D2
- AND.W #$3,D2
- OR.L #$40000080,D2
- MOVEP.W D0,-3(A0)
- MOVEP.L D1,-11(A0)
- MOVE.W -(A0),(A1)
- MOVE.W -(A0),(A1)
- MOVE.W -(A0),(A1)
- MOVE.W -(A0),(A1)
- MOVE.W -(A0),(A1)
- SWAP D2
- MOVE.W D2,(A1)
- SWAP D2
- MOVE.W D2,(A1)
- RTS
- RAMDMAFC: MOVE.L D0,(A1)
- MOVE.L D1,(A1)
- MOVE.W D2,(A1)
- MOVE.W D3,(A1)
- MOVE.W D4,(A1)
- RTS
- RAMVERTC: LEA.L DMAREQ,A0
- MOVE.W #$8000,D1
- MOVE.W #$8174,(A2) ;DMA ENABLE
- @BACK: MOVE.W (A0)+,D0
- BGE.S @CHECK
- @L1: MOVE.W D0,(A2) ;FIRST PASS
- MOVE.L (A0)+,(A2) ;SIZE/SOURCE
- MOVE.L (A0)+,(A2) ;SOURCE/SOURCE
- MOVE.W (A0)+,(A2) ;DEST
- MOVE.W (A0)+,(A2) ;DEST/MODE
- MOVE.W (A0)+,D0 ;SIZE
- BLT.S @L1
- @CHECK: BEQ.S @DONE ;END
- OR.W D1,D0
- MOVE.W D0,(A2)
- BRA.S @BACK
- @DONE: MOVE.L #0,DMAREQ
- MOVE.W #$8164,(A2) ;DMA DISABLE
- RTS
- RAMDMAEND:
- ;----------------------------------------------------------
- ; COPY RAM ROUTINES TO RAM
- ;----------------------------------------------------------
- SETUPRAM: MOVE.L #$94009300,QSIZE
- MOVE.L #$97009600,QSOURCE
- MOVE.W #$9500,QSOURCE+4
- LEA.L RAMDMAC,A0
- LEA.L RAMDMA,A1
- MOVE.W #RAMDMAEND-RAMDMAC-1,D0
- @L1: MOVE.B (A0)+,(A1)+
- DBRA D0,@L1
- RTS
- RAMDMAF: EQU RAMDMA+(RAMDMAFC-RAMDMAC)
- RAMVERT: EQU RAMDMA+(RAMVERTC-RAMDMAC)
- ;----------------------------------------------------------
- ; PALETTE SETUPS
- ;----------------------------------------------------------
- SETPAL1: MOVE.W #16-1,D0
- LEA.L PALETTES,A1
- @LOOP1: MOVE.W (A0)+,(A1)+
- DBRA D0,@LOOP1
- RTS
- SETPAL2: MOVE.W #16-1,D0
- LEA.L PALETTES+32,A1
- @LOOP1: MOVE.W (A0)+,(A1)+
- DBRA D0,@LOOP1
- RTS
- SETPAL3: MOVE.W #16-1,D0
- LEA.L PALETTES+64,A1
- @LOOP1: MOVE.W (A0)+,(A1)+
- DBRA D0,@LOOP1
- RTS
- SETPAL4: MOVE.W #16-1,D0
- LEA.L PALETTES+96,A1
- @LOOP1: MOVE.W (A0)+,(A1)+
- DBRA D0,@LOOP1
- RTS
- ;----------------------------------------------------------
- ; COPY PALETTE TO MEMORY
- ;----------------------------------------------------------
- DUMPCOLS: MOVEM.L D0-D4,-(SP)
- MOVE.W #$100,Z80REQ
- @L1: BTST #0,Z80REQ
- BNE.S @L1
- WREG 01,%01110100 ;DMA ENABLE
- LEA.L VDP_CONTROL,A1
- DMAFPAL PALETTES,128,$0000
- WREG 01,%01100100 ;DMA DISABLE
- MOVE.W #0,Z80REQ
- MOVEM.L (SP)+,D0-D4
- RTS
- ;----------------------------------------------------------
- ; SPRITE CODE
- ;----------------------------------------------------------
- SPRITEINIT: WREG 5,$7C ;SPRITE ATTRIBUTE TABLE
- LEA.L VDP_DATA,A1
- WDEST VRAMW,$F800
- MOVE.W #1,(A1)
- MOVE.W #0,(A1)
- MOVE.W #0,(A1)
- MOVE.W #1,(A1)
- LEA.L SPRITETEMP,A1
- MOVE.W #1,(A1)+
- MOVE.W #0,(A1)+
- MOVE.W #0,(A1)+
- MOVE.W #1,(A1)+
- JSR SPRITEDUMP
- RTS
- SPRITEDUMP: DMADUMP SPRITETEMP,640,$F800
- RTS
- ;----------------------------------------------------------
- ; GET A RANDOM NUMBER FROM 0-255
- ; TRASHES A0, RETURNS D0
- ;----------------------------------------------------------
- GETRANDOM: MOVE.L RANDOM,A0
- MOVEQ.L #0,D0
- MOVE.B (A0)+,D0
- ADD.L #1,A0
- CMP.L #RANDOM_END,A0
- BLT.S @P1
- MOVE.L #RANDOM_NUMS,A0
- @P1: MOVE.L A0,RANDOM
- RTS
- ;----------------------------------------------------------
- ; SYSTEM PALETTE
- ;----------------------------------------------------------
- SYSPALETTE incbin Palettes\pallet_system.bin
- ;----------------------------------------------------------
- ; RANDOM NUMBER TABLE (1024 ENTRIES)
- ;----------------------------------------------------------
- RANDOM_NUMS incbin Uncompressed\Random_Numunc.bin
- RANDOM_END:
- RINGS.S
- ;----------------------------------------------------------
- ; RING CODE
- ;----------------------------------------------------------
- ;RING STRUCTURE STUFF
- RSSET 0
- RING_X: RS.L 1
- RING_Y: RS.L 1
- RING_MX: RS.L 1
- RING_MY: RS.L 1
- RING_GRAV: RS.L 1
- RING_LIFE: RS.W 1
- RING_SIZE: RS.B 0
- RINGS: EQU 64 ;TOTAL NUMBER OF RINGS
- RSSET SYSTEMEND
- RINGDATA: RS.B RINGS*RING_SIZE ;RING SYSTEM
- RINGEND: RS.B 0
- ;-------------------------
- ; INITIALISE RINGS
- ;-------------------------
- RINGINIT: LEA.L RINGDATA,A0
- MOVE.W #RINGS-1,D0 ;NUMBER OF RINGS TO PROCESS
- MOVE.W #0,D1
- @L1: MOVE.W D1,RING_LIFE(A0) ;SET LIFE SPAN TO 0
- ADD.L #RING_SIZE,A0
- DBRA D0,@L1
- RTS
- ;-------------------------
- ; PROCESS RINGS
- ;-------------------------
- PROCRING: LEA.L RINGDATA,A0
- MOVE.W #RINGS-1,D0
- AND.W #$FF,D7 ;CLEAR AWAY ANY PREVIOUS SIZE INFO FROM SPRITE COUNT
- ADD.W #S_2X2,D7 ;ALL THESE RINGS WILL BE 2X2 IN SIZE
- MOVE.W #S_PAL2+$1100/32,D6 ;ALL RINGS WILL USE THIS PALETTE AND VRAM LOCATION
- @L1: TST.W RING_LIFE(A0)
- BEQ.S @SKIP
- ;ADD SPRITE TO TABLE
- MOVE.W RING_Y(A0),(A1)+ ;Y POSITION
- MOVE.W D7,(A1)+ ;SIZE 2X2 CHARACTERS AND SPRITE NUM
- MOVE.W D6,(A1)+ ;PALETTE NUMBER+GRAPHIC VRAM LOCATION/32
- MOVE.W RING_X(A0),(A1)+ ;X POSITION ($80 IS LEFT OF SCREEN)
- ADD.W #1,D7 ;INCREMENT SPRITE COUNT
- ;PROCESS PHYSICS
- MOVE.L RING_MX(A0),D1
- ADD.L D1,RING_X(A0)
- MOVE.L RING_MY(A0),D1
- ADD.L D1,RING_Y(A0)
- MOVE.L RING_GRAV(A0),D1
- ADD.L D1,RING_MY(A0)
- SUB.W #1,RING_LIFE(A0)
- ;CLIP
- MOVE.W RING_Y(A0),D1 ;Y CLIP
- SUB.W #$80-16,D1
- CMP.W #224+16,D1
- BHI.S @CLIP
- MOVE.W RING_X(A0),D1 ;X CLIP
- SUB.W #$80-16,D1
- CMP.W #320+16,D1
- BLS.S @SKIP
- @CLIP:
- CLR.W RING_LIFE(A0)
- @SKIP: ADD.L #RING_SIZE,A0
- DBRA D0,@L1
- RTS
- ;-------------------------
- ; ADD A RING
- ;-------------------------
- ADDRING: LEA.L RINGDATA,A0
- MOVE.W #RINGS-1,D0
- MOVE.W #10000,D2 ;STORE SHORTEST REMAINING RING LIFE HERE
- MOVE.L A0,A1 ;SHORTEST LIFE RING POSITION
- @L1: MOVE.W RING_LIFE(A0),D1
- BEQ.S @ADD ;RING WITH ZERO LIFE, SO FREE SLOT FOUND
- CMP.W D1,D2 ;SHORTER LIFE THAN CURRENT SHORTEST?
- BLE.S @SKIP
- MOVE.W D1,D2 ;NEW SHORTEST
- MOVE.L A0,A1 ;NEW SHORTEST POSITION
- @SKIP: ADD.L #RING_SIZE,A0
- DBRA D0,@L1
- MOVE.L A1,A0 ;REPLACE RING WITH SHORTEST LIFE LEFT IF ZERO NOT FOUND
- @ADD: SWAP.W D3
- CLR.W D3
- SWAP.W D4
- CLR.W D4
- MOVE.L D3,RING_X(A0)
- MOVE.L D4,RING_Y(A0)
- MOVE.L D5,RING_MX(A0)
- MOVE.L D6,RING_MY(A0)
- MOVE.L D7,RING_GRAV(A0)
- MOVE.W #120,RING_LIFE(A0)
- RTS
- FLAME.S
- ;----------------------------------------------------------
- ; FLAME CODE
- ;----------------------------------------------------------
- RSSET 0
- FLAME_X: RS.W 1
- FLAME_DIR: RS.W 1
- FLAME_TIME: RS.W 1
- FLAME_SIZE: RS.B 0
- RSSET RINGEND
- ;FLAME STUFF
- FBUFFER: RS.W 1 ;BUFFER FOR FLAME
- XPOS: RS.W 1 ;XPOS FOR FLAME
- FLAMES: EQU 12 ;TOTAL NUMBER OF FLAMES
- FLAMEDATA: RS.B FLAMES*FLAME_SIZE
- FLAMEEND: RS.B 0
- FLAMETABLE: EQU DECRUNCH+4096+1160*2
- FLAMEBUF1: EQU DECRUNCH+4096
- FLAMEBUF2: EQU DECRUNCH+4096+1160
- ;----------------------------------------------------------
- ; INIT FLAME
- ;----------------------------------------------------------
- INITFLAME:
- LEA.L PALETTE3,A0 ;FLAME PALETTE
- JSR SETPAL3
- LEA.L DECRUNCH,A0 ;SET UP MASK FOR FLAME PLAYFIELD
- MOVE.W #$8000+S_PAL3,D0
- MOVE.W #(4096/2)-1,D1
- @L1: MOVE.W D0,(A0)+
- DBRA D1,@L1
- LEA.L DECRUNCH+4096,A0 ;CLEAR FLAME BUFFERS
- MOVEQ.L #0,D0
- MOVE.W #((1160*2)/4)-1,D1
- @L3: MOVE.L D0,(A0)+
- DBRA D1,@L3
- ;INIT FLAME CREATORS
- LEA.L FLAMEDATA,A1
- MOVE.W #FLAMES-1,D1
- @L2: MOVE.W #-10000,(A1)+ ;START
- MOVE.W #1,(A1)+ ;SPEED
- MOVE.W #0,(A1)+ ;LIFE
- DBRA D1,@L2
- MOVE.W #0,FBUFFER
- DMADUMP FLAMEGFX1,32*32,$0 ;DUMP 4 CHARACTERS (SIZE 32 BYTES EACH) TO VRAM LOCATION $20 (MAP GRAPHICS)
- BSR CALCFLAME ;CREATE A TABLE USED TO SPEED UP ANTI-ALIAS MATHS
- RTS
- ;----------------------------------------------------------
- ; CALC FLAME TABLE - TO SPEED UP MATHS
- ;----------------------------------------------------------
- CALCFLAME: LEA.L FLAMETABLE,A0
- MOVEQ.L #0,D0
- MOVEQ.L #0,D2
- MOVE.W #255-1,D1
- MOVE.B #0,(A0)+
- @L1: MOVE.B D0,D2
- ASR.W #2,D2
- MOVE.B D2,(A0)+
- ADD.B #1,D0
- DBRA D1,@L1
- RTS
- ;----------------------------------------------------------
- ; CONVERT FLAME - COPY FLAME TO PLAYFIELD
- ;----------------------------------------------------------
- CONVFLAME: LEA.L DECRUNCH+1,A0
- LEA.L FLAMEBUF2,A1
- SUB.W FBUFFER,A1
- MOVE.W #$8000+S_PAL3,D1
- MOVE.W #28-1,D2
- @L2:
- REPT 9
- MOVE.L (A1)+,D1
- MOVEP.L D1,(0,A0) ;VERY SNEAKY
- LEA.L 8(A0),A0
- ENDR
- MOVE.L (A1)+,D1
- MOVEP.L D1,(0,A0)
- LEA.L -72+128(A0),A0
- DBRA D2,@L2
- RTS
- ;----------------------------------------------------------
- ; MAIN FLAME CODE
- ;----------------------------------------------------------
- DRAWFLAME:
- ;DUMP FLAME TO VRAM
- DMADUMP DECRUNCH,4096,$E000
- ;TOGGLE BUFFERS
- CMP.W #0,FBUFFER
- BEQ.S @B1
- MOVE.W #0,FBUFFER
- BRA.S @B2
- @B1: MOVE.W #1160,FBUFFER
- @B2:
- ;ADD AND MOVE FLAME CREATION OBJECTS
- LEA.L FLAMEBUF2+40*28,A0
- SUB.W FBUFFER,A0
- MOVEQ.L #0,D0 ;CLEAR BOTTOM LINE OF FLAME TO AVOID OVER SATURATION
- REPT 10
- MOVE.L D0,(A0)+
- ENDR
- LEA.L FLAMEBUF2+40*28+2,A0
- SUB.W FBUFFER,A0
- LEA.L FLAMEDATA,A1
- MOVE.W #FLAMES-1,D2
- MOVE.W #$1F,D1
- @J1: MOVE.W (A1)+,D0 ;POSITION
- ADD.W (A1)+,D0 ;SPEED/DIR
- BLT.S @D1
- CMP.W #38*8,D0
- BLT.S @D2
- @D1: LEA.L 2(A1),A1
- BRA.S @D3
- @D2: MOVE.W D0,-4(A1)
- ASR.W #3,D0
- LEA.L (A0,D0.W),A2
- MOVE.B D1,-2(A2) ;DRAW CROSS AT RANDOM POSITION
- MOVE.B D1,-1(A2)
- MOVE.B D1,-(40+1)(A2)
- MOVE.B D1,(A2)
- SUB.W #1,(A1)+
- BGE.S @T1
- @D3:
- BTST #5,JOYPAD0
- BNE @SKIP
- MOVE.L A0,A3
- JSR GETRANDOM
- ADD.W #32,D0
- MOVE.W D0,-6(A1) ;POSITION
- JSR GETRANDOM
- AND.W #$1F,D0
- MOVE.W D0,-2(A1) ;TIME
- JSR GETRANDOM
- AND.W #$7,D0
- SUB.W #3,D0
- MOVE.W D0,-4(A1) ;SPEED
- MOVE.L A3,A0
- BRA.S @T1
- @SKIP: MOVE.W #-10000,-6(A1)
- @T1:
- DBRA D2,@J1
- ;NOW ANTI ALIAS TO BUFFER 1
- MOVE.W FBUFFER,D0
- BEQ.S @PP1
- LEA.L FLAMEBUF1+40,A0
- LEA.L FLAMEBUF2+1,A1
- BRA.S @PP2
- @PP1: LEA.L FLAMEBUF2+40-1,A0
- LEA.L FLAMEBUF1,A1
- @PP2:
- LEA.L FLAMETABLE,A2 ;FLAME TABLE
- LEA.L -39(A0),A3
- LEA.L 2(A0),A4
- MOVEQ.L #0,D0
- MOVE.W #(28*40)-1,D5
- @LL1: MOVE.B (A0)+,D0
- ADD.B (A0),D0
- ADD.B (A4)+,D0
- ADD.B (A3)+,D0
- ; ASR.W #2,D0
- ; MOVE.B D0,(A1)+
- MOVE.B (A2,D0.W),(A1)+
- DBRA D5,@LL1
- RTS
- ;----------------------------------------------------------
- ; FLAME GFX
- ;----------------------------------------------------------
- FLAMEGFX1 incbin Uncompressed\Artunc_FLAMEGFX1.smd
- FLAMEGFX2 incbin Uncompressed\Artunc_FLAMEGFX2.smd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement