;note this code need iram or sdCard startup ;********************************************************************* ; includes ;********************************************************************* .incdir "F:\git\goldmomo_endlos\assembler_files\ucore\" .include "include\ucore_ctrl.i" ;********************************************************************* ; start ;********************************************************************* spacePilotCore ; ram ; ; $0000 0000 frame buffer 0 ; $0001 4a78 frame buffer 1 ; $0002 94f0 rom mirror (star at $0001 7f68) font colored ; $0002 c3f0 rom mirror bobs ; ;setup video dexti >setupVideo movei r0,setupVideo gpci r7,2 ;next 4 + X jmpi r0,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;*************************************** welcome start welcomeStart ;set welcome stone count movei r6,gfxObjectStoneCount movei r0,gfxObjectStoneCountMax moveih r6,>gfxObjectStoneCount nop st r6,r0 ;reset PS2 buffer gpci r7,2 ;next 4 + X br PS2Reset nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;*************************************** welcome loop welcomeLoop ;frame switch dexti >switchAndClearFrame movei r0,switchAndClearFrame gpci r7,2 jmpi r0,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw object (stone) gpci r7,2 br drawStones nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;move and check stones gpci r7,2 br moveAndCheckStones nop ;delay slot nop ;delay slot nop ;delay slot nop ;draw welcome message gpci r7,2 br drawWelcomeMessage nop ;delay slot nop ;delay slot nop ;delay slot nop ;debug output gpci r7,2 br debugOutput nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;process keys gpci r7,2 ;next 4 + X br PS2Process nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;test space key gpci r7,2 ;next 4 + X br PS2TestKey movei r0,$29 ;space key delay slot nop ;delay slot nop ;delay slot nop ;delay slot cmpeqi r0,1 ;space pressed? brtc welcomeLoop ;no welcome again nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;*************************************** ;reset data dexti >resetData movei r0,resetData gpci r7,2 ;next 4 + X jmpi r0,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;*************************************** game loop gameLoop ;switch and clear frames dexti >switchAndClearFrame movei r0,switchAndClearFrame gpci r7,2 jmpi r0,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;process keys gpci r7,2 ;next 4 + X br PS2Process nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw object (stone) gpci r7,2 br drawStones nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;update ship coordinates gpci r7,2 br moveAnimShip nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw and test object (ship) gpci r7,2 br clipAndTestAndDrawObject ;return r1 != 0 collsion movei r6,gfxObjectShip ;delay slot nop ;delay slot moveih r6,>gfxObjectShip ;delay slot nop ;delay slot gpci r7,2 br checkAndDrawShipExplosion nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;check and process collision gpci r7,2 br checkAndProcessCollision nop ;delay slot nop ;delay slot nop ;delay slot nop push r0 ;store collsiom value ;draw energie bar gpci r7,2 br drawEnergieBar nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;update and draw status gpci r7,2 br updateAndDrawStatus movei r2,1 ;update timer delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;game over? rqpop nop nop pop r0 nop cmpeqi r0,0 ;game over energie out brts gameOver nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;move and check stones gpci r7,2 br moveAndCheckStones nop ;delay slot nop ;delay slot nop ;delay slot nop ;debug output gpci r7,2 br debugOutput nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot br gameLoop nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;************************ game over gameOver dexti >switchAndClearFrame movei r0,switchAndClearFrame gpci r7,2 jmpi r0,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw object (stone) gpci r7,2 br drawStones nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw energie bar gpci r7,2 br drawEnergieBar nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;update and draw status gpci r7,2 br updateAndDrawStatus movei r2,0 ;dont update paly timer delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw and test object (ship) gpci r7,2 br clipAndTestAndDrawObject ;return r1 != 0 collsion movei r6,gfxObjectShip ;delay slot nop ;delay slot moveih r6,>gfxObjectShip ;delay slot nop gpci r7,2 br checkAndDrawShipExplosion movei r1,1 ;do explode delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;move ship out of screen gpci r7,2 br moveShipOut nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;draw game over gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringGameOver ;text delay slot movei r1,18 ;x delay slot moveih r0,>stringGameOver ; delay slot movei r2,6 ;y gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringGameOver2 ;text delay slot movei r1,11 ;x delay slot moveih r0,>stringGameOver2 ; delay slot movei r2,7 ;y ;move and check stones gpci r7,2 br moveAndCheckStones nop ;delay slot nop ;delay slot nop ;delay slot nop ;wait for space waitForGameOverKeyPressed ;process keys gpci r7,2 ;next 4 + X br PS2Process nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;test space key gpci r7,2 ;next 4 + X br PS2TestKey movei r0,$29 ;space key delay slot nop ;delay slot nop ;delay slot nop ;delay slot cmpeqi r0,1 ;space pressed brtc gameOver ;not pressed nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot waitForGameOverKeyRelease ;process keys gpci r7,2 ;next 4 + X br PS2Process nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;test space key gpci r7,2 ;next 4 + X br PS2TestKey movei r0,$29 ;space key delay slot nop ;delay slot nop ;delay slot nop ;delay slot cmpeqi r0,1 ;space pressed brts waitForGameOverKeyRelease ;pressed nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;goto welcome start br welcomeStart nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot end br end nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;********************************************************************* ;* included functions ;********************************************************************* .include "components\drawText.s" .include "components\ps2keyboard.s" ;********************************************************************* ;* functions ;********************************************************************* ;****************************** ;* ;* moveShipOut ;* moveShipOut dexti >gfxObjectShip movei r6,gfxObjectShip nop rqldi r6,1 ;y nop nop ld r0 ;y addi r6,1 addi r0,1 movei r1,230 cmplosi r0,230 movets r0,r0,r1 jmpi r7,0 st r6,r0 ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* checkAndDrawShipExplosion (not optimized ..) ;* ;* r1 != 0 draw explosion ;* checkAndDrawShipExplosion push r1 push r7 cmpeqi r1,0 brts noExplosionToDraw nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;test and increment anim count dexti >gfxAnimCounterExplosion movei r5,gfxAnimCounterExplosion nop rqldi r5,0 nop nop ld r0 movei r1,$3 addi r0,1 nop and r0,r0,r1 nop st r5,r0 ;copy anim to object movei r5,gfxObjectExplosionAnim muli r0,4 moveih r5,>gfxObjectExplosionAnim movei r6,gfxObjectExplosion add r5,r5,r0 ;source moveih r6,>gfxObjectExplosion ;destination rqldi r5,0 ;w rqldi r5,1 ;h rqldi r5,2 ;x ld r0 ld r1 ld r2 rqldi r5,3 ;y nop addi r6,2 ld r3 stinc r6,r0 nop stinc r6,r1 nop stinc r6,r2 nop stinc r6,r3 nop ;copy x , y from real space ship movei r6,gfxObjectShip movei r5,gfxObjectExplosion moveih r6,>gfxObjectShip moveih r5,>gfxObjectExplosion rqldi r6,0 ;x rqldi r6,1 ;y nop ld r0 ld r1 subi r0,6 ;x adjust subi r1,2 ;y adjust stinc r5,r0 nop stinc r5,r1 ;draw it gpci r7,2 br clipAndDrawObject ;return r1 != 0 collsion movei r6,gfxObjectExplosion ;delay slot nop ;delay slot moveih r6,>gfxObjectExplosion ;delay slot nop ;epilog noExplosionToDraw rqpop rqpop nop pop r7 pop r1 jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* drawChar ;* ;* r0 value ;* r1 x ;* r2 y ;* ;* trash r0 drawChar push r1 push r2 push r3 push r4 push r5 push r6 push r7 ;destination base (sram base 0) muli r1,8 ;x * 8 dexti >drawFrame movei r4,drawFrame nop rqldi r4,1 ;low rqldi r4,0 ;high nop ld r4 ;low ld r5 ;high add r4,r4,r1 ;address+x addtqi r5,r5,0 dexti $17 movei r1,$80 ;(360*16)*16 nop mul r1,r1,r2 ;*y gmulhi r2 add r4,r4,r1 ;address+(y*360+16) addt r5,r5,r2 ;font source dexti >fontAddress movei r2,fontAddress nop rqldi r2,1 ;low rqldi r2,0 ;high nop ld r2 ;low ld r3 ;high muli r0,8 ;value * 8 nop add r2,r2,r0 ;add to source addtqi r3,r3,0 ; movei r0,15 ;16 [y] dcYloop esadr r3,r2 erqldi 0 erqldi 1 erqldi 2 erqldi 3 erqldi 4 erqldi 5 erqldi 6 erqldi 7 addi r2,8 addtqi r3,r3,0 movei r1,7 ;8 [x] dcXloop eld r6 esadr r5,r4 extri r6,15 estts r6,0 subi r1,1 ;x- brts dcXloop addi r4,1 ;delay slot addtqi r5,r5,0 ;delay slot nop ;delay slot nop ;delay slot ; movei r1,$70 nop moveih r1,$1 ;r1 = 360+16-8 nop add r4,r4,r1 ;dest + 360+16-8 addtqi r5,r5,0 ; movei r1,$e8 nop moveih r1,$2 ;r1 = 752-8 nop subi r0,1 ;y- brts dcYloop add r2,r2,r1 ;source + 752-8 delay slot addtqi r3,r3,0 ; delay slot nop ;delay slot nop ;delay slot ; rqpop rqpop rqpop pop r7 pop r6 pop r5 rqpop rqpop nop pop r4 pop r3 rqpop rqpop jmpi r7,0 pop r2 ;delay slot pop r1 ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* drawWelcomeMessage ;* drawWelcomeMessage push r7 gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringWelcome1 ;text delay slot movei r1,5 ;x delay slot moveih r0,>stringWelcome1 ; delay slot movei r2,2 ;y gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringWelcome2 ;text delay slot movei r1,8 ;x delay slot moveih r0,>stringWelcome2 ; delay slot movei r2,4 ;y gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringWelcome3 ;text delay slot movei r1,9 ;x delay slot moveih r0,>stringWelcome3 ; delay slot movei r2,6 ;y gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringWelcome4 ;text delay slot movei r1,9 ;x delay slot moveih r0,>stringWelcome4 ; delay slot movei r2,7 ;y gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringWelcome5 ;text delay slot movei r1,9 ;x delay slot moveih r0,>stringWelcome5 ; delay slot movei r2,8 ;y gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringWelcome6 ;text delay slot movei r1,12 ;x delay slot moveih r0,>stringWelcome6 ; delay slot movei r2,10 ;y rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* updateAndDrawStatus ;* ;* r2 = update playtimer (1 = yes, 0 is no) ;* updateAndDrawStatus push r7 ;update timer dexti >playTimeCounter movei r1,playTimeCounter nop rqldi r1,0 nop nop ld r0 nop add r0,r0,r2 nop st r1,r0 moveih r0,0 ;and $ff nop cmpeqi r0,$ff brtc noStoneIncrease nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;add one stone dexti >gfxObjectStoneCount movei r1,gfxObjectStoneCount nop rqldi r1,0 nop nop ld r0 nop cmpeqi r0,gfxObjectStoneCountMax brts noStoneIncrease nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot addi r0,1 nop st r1,r0 noStoneIncrease ;draw status dexti >playTimeCounter movei r1,playTimeCounter nop rqldi r1,0 nop nop ld r0 nop movei r2,$89 ;pseudo div 60 nop moveih r2,$88 nop mul r0,r0,r2 nop gmulhi r0 nop lsri r0,5 nop push r0 gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringTime ;text delay slot movei r1,1 ;x delay slot moveih r0,>stringTime ; delay slot movei r2,1 ;y rqpop nop nop nop gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringPower ;text delay slot movei r1,1 ;x delay slot moveih r0,>stringPower ; delay slot movei r2,0 ;y delay slot ;meteorids dexti >gfxObjectStoneCount movei r1,gfxObjectStoneCount nop rqldi r1,0 nop nop ld r0 nop addi r0,1 nop push r0 gpci r7,2 ;next 4 + X br drawTextFormated movei r0,stringMeteoroids ;text delay slot movei r1,33 ;x delay slot moveih r0,>stringMeteoroids ; delay slot movei r2,1 ;y rqpop nop nop nop rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* moveAndCheckStones ;* moveAndCheckStones push r7 dexti >gfxObjectStoneCount movei r3,gfxObjectStoneCount nop rqldi r3,0 nop nop ld r7 ;r7 is stone counter nop moveAndCheckStoneLoop push r7 ; dexti >gfxObjectStones movei r5,gfxObjectStones nop add r5,r5,r7 ;+ counter nop rqldi r5,0 nop movei r6,8 ld r5 ;stone address nop add r6,r5,r6 ;stone address + 8 nop ;r5 = stone low ;r6 = stone high ; 0 1 2 3 4 ; 0 1 2 3 4 5 6 7 8 9 a b c ; x y w h sx sy srclow srchigh yspeed S1 cox coy colsize yintern ;add yspeed to y intern rqldi r6,0 rqldi r6,4 nop ld r0 ;y speed ld r1 ;y intern addqi r4,r6,4 ;y intern add r1,r1,r0 nop st r4,r1 ;store to y intern ;check of screen and recalc (r1 = yintern) dexti $3 movei r0,$ff nop cmplos r1,r0 ;yintern < 256*4-1 brts inScreen nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;rand y = 0-[(0..255)+50]*4 gpci r7,2 br rand ;r0 = 0..65535 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot movei r1,200 lsri r0,6 ; movei r2,0 add r0,r0,r1 addqi r4,r6,4 ;y intern sub r2,r2,r0 nop st r4,r2 ;store to y intern ;rand x gpci r7,2 br rand ;r0 = 0..65535 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot or r1,r0,r0 lsri r0,8 ;0..255 lsri r1,10 ;0..63 nop add r1,r1,r0 gpci r7,2 br rand ;r0 = 0..65535 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot lsri r0,11 ;0..31 nop add r1,r1,r0 ;r1 = new x value nop st r5,r1 ;rand yspeed gpci r7,2 br rand ;r0 = 0..65535 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot lsri r0,13 ;0..7 nop addi r0,4 ;start at one pixel nop st r6,r0 ;yspeed ;.stop inScreen ;convert y intern to y rqldi r6,4 nop nop ld r0 addqi r4,r5,1 ;y address asri r0,2 ;/4 nop st r4,r0 ; rqpop nop nop pop r7 nop subi r7,1 brts moveAndCheckStoneLoop nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ; rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* checkAndProcessCollision ;* ;* r1 != 0 collision detected ;* ;* return ;* ;* r0 = 0 game over ;* checkAndProcessCollision push r7 movei r2,1 movei r3,0 cmpeqi r1,0 movets r4,r3,r2 ;sub form energie bar dexti >Energie movei r6,Energie nop rqldi r6,0 nop nop ld r2 nop cmpeqi r2,0 brts checkAndProcessEnergieOutDetected nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot sub r2,r2,r4 nop st r6,r2 movei r0,1 ;no collision checkAndProcessCollisionEnd rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot checkAndProcessEnergieOutDetected br checkAndProcessCollisionEnd movei r0,0 ;collision delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* drawStones ;* drawStones push r7 dexti >gfxObjectStoneCount movei r3,gfxObjectStoneCount nop rqldi r3,0 nop nop ld r3 nop stoneLoop push r3 dexti >gfxObjectStones movei r6,gfxObjectStones nop add r6,r6,r3 nop rqldi r6,0 nop nop ld r6 ; ; gpci r7,2 br clipAndDrawObject nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ; rqpop nop nop pop r3 nop subi r3,1 brts stoneLoop nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* drawEnergieBar ;* drawEnergieBar push r7 movei r3,drawFrame movei r6,Energie moveih r3,>drawFrame moveih r6,>Energie rqldi r3,0 ;high rqldi r3,1 ;low movei r4,$8 ld r3 ;high ld r2 ;low rqldi r6,0 nop moveih r4,$9 ;y offset (x = 7*8; y = 6) ld r6 ;energie value nop cmpeqi r6,0 ;no energie brts drawEnergieBarExit nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot add r2,r2,r4 ;+xstart +ystart addtqi r3,r3,0 dexti $1 movei r4,$78 ;360 + 16 drawEnergieBarLoop or r1,r3,r3 or r0,r2,r2 nop ;load first to prevent latency esadr r1,r0 erqldi 0 add r0,r0,r4 addtqi r1,r1,0 nop esadr r1,r0 erqldi 0 add r0,r0,r4 addtqi r1,r1,0 nop esadr r1,r0 erqldi 0 add r0,r0,r4 addtqi r1,r1,0 nop esadr r1,r0 erqldi 0 add r0,r0,r4 addtqi r1,r1,0 nop esadr r1,r0 erqldi 0 add r0,r0,r4 addtqi r1,r1,0 nop esadr r1,r0 erqldi 0 add r0,r0,r4 addtqi r1,r1,0 nop or r1,r3,r3 or r0,r2,r2 nop ;store movei r7,$0f esadr r1,r0 eld r5 add r0,r0,r4 or r5,r5,r7 ;no t out addtqi r1,r1,0 est r5,0 movei r7,$3f esadr r1,r0 eld r5 add r0,r0,r4 or r5,r5,r7 ;no t out addtqi r1,r1,0 est r5,0 esadr r1,r0 eld r5 add r0,r0,r4 or r5,r5,r7 ;no t out addtqi r1,r1,0 est r5,0 esadr r1,r0 eld r5 add r0,r0,r4 or r5,r5,r7 ;no t out addtqi r1,r1,0 est r5,0 esadr r1,r0 eld r5 add r0,r0,r4 or r5,r5,r7 ;no t out addtqi r1,r1,0 est r5,0 movei r7,$0f esadr r1,r0 eld r5 add r0,r0,r4 or r5,r5,r7 ;no t out addtqi r1,r1,0 est r5,0 addi r2,1 addtqi r3,r3,0 subi r6,1 brts drawEnergieBarLoop nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot drawEnergieBarExit rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* checkCollision (spheric collision detection, nut used yet) ;* ;* r5 = object a ;* r6 = object b ;* ;* return ;* ;* r4 = 1 if collosion is detcted else 0 ;* checkCollision push r1 push r2 push r3 ;obj a rqldi r6,0 ;x rqldi r6,1 ;y addi r6,8 ;next 8 ld r0 ld r1 rqldi r6,1 rqldi r6,2 rqldi r6,3 ld r2 ;cx ld r3 ;cy ld r4 ;radius add r2,r2,r0 ;total x add r3,r3,r1 ;total y push r2 push r3 push r4 ;obj b rqldi r5,0 ;x rqldi r5,1 ;y addi r5,8 ;next 8 ld r0 ld r1 rqldi r5,1 rqldi r5,2 rqldi r5,3 ld r4 ;cx ld r3 ;cy ld r2 ;radius add r0,r4,r0 ;total x add r1,r3,r1 ;total y rqpop rqpop rqpop pop r5 pop r4 pop r3 ;obja r0 = x r1 = y r2 = r ;objb r3 = x r4 = y r5 = r ;test collision movei r6,0 add r2,r2,r5 ;ra + rb sub r0,r0,r3 ;dx sub r1,r1,r4 ;dy sub r3,r6,r0 ;-dx sub r4,r6,r1 ;-dy cmplosi r0,0 ;dx<0? movets r0,r3,r0 ;dx = -dx else dx = dx (abs) cmplosi r1,0 ;dy<0? movets r1,r4,r1 ;dy = -dy else dy = dy (abs) ;overflow prevention (dx or dy > 128 is never a collision) cmploi r0,128 brtc checkCollisionOverflow movei r4,0 ;mark as no collision nop ;delay slot nop ;delay slot nop ;delay slot cmploi r1,128 brtc checkCollisionOverflow movei r4,0 ;mark as no collision nop ;delay slot nop ;delay slot nop ;delay slot ;calculate difference mul r0,r0,r0 ;dx*dx (note: unsigned mul) mul r1,r1,r1 ;dy*dy mul r2,r2,r2 ;r*r add r1,r0,r1 ;dx*dx + dy*dy movei r3,1 ; movei r4,0 cmplo r2,r1 ;dx*dx + dy*dy < r*r movets r4,r4,r3 ;r4 = 1 if collosion is detcted checkCollisionOverflow rqpop rqpop rqpop pop r3 pop r2 pop r1 jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* debugOutput ;* debugOutput push r7 dexti >UcRSwichtWLedG movei r0,UcRSwichtWLedG nop rqldi r0,0 nop nop ld r0 ;sw nop extri r0,0 brtc debugModeDisabled movei r0,UcVideoRVCountWHSYNC ; delay slot nop ; delay slot moveih r0,>UcVideoRVCountWHSYNC ;vblank address delay slot nop ; delay slot rqldi r0,0 ;vcount nop nop ld r0 nop subi r0,30 nop lsri r0,2 ;/4 dexti 1 movei r1,$78 ;width movei r3,drawFrame mul r0,r1,r0 ;r0 = low moveih r3,>drawFrame gmulhi r1 ;r1 = high rqldi r3,0 ;high rqldi r3,1 ;low nop ld r3 ;high ld r2 ;low nop add r2,r2,r0 ;low addt r3,r3,r1 ;high movei r0,$e0 addi r2,8 ;first 8 pixels are invisible addtqi r3,r3,0 moveih r0,$ff esadr r3,r2 est r0,0 est r0,1 est r0,2 est r0,3 est r0,4 est r0,5 est r0,6 est r0,7 debugModeDisabled rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* screenClipObject ;* ;* r6 = object in ;* (will ever store in object tmp) ;* ;* return r0 == 0 (out of view dont draw) ;* screenClipObject push r7 ;copy not calculated part to temp struct rqldi r6,6 ;source low rqldi r6,7 ;source high movei r2,gfxObjectTemp ld r0 ld r1 moveih r2,>gfxObjectTemp nop addi r2,6 nop st r2,r0 ;source low addi r2,1 nop st r2,r1 ;source high ;************ x test rqldi r6,0 rqldi r6,2 rqldi r6,4 ld r3 ;dest x ld r4 ;width ld r5 ;source x ;clip left cmplosi r3,0 ;r3<0 brtc screenClipXLowInRange nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot add r4,r4,r3 ;width + (-x) sub r5,r5,r3 ;source - (-x) movei r3,0 ;x = 0 ;width <= 7 (<8) -> out of view cmplosi r4,8 brts screenClipOutOfView nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot screenClipXLowInRange ;clip right movei r0,$78 nop moveih r0,1 ;360+16 nop add r1,r3,r4 ;r1 = width + x nop cmplo r1,r0 ;width + x < 360+16 brts screenClipXHighInScreen nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot sub r4,r0,r3 ;width = 360+16 - x nop cmplosi r4,8 ; brts screenClipOutOfView nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot screenClipXHighInScreen ;store back (x, width, source x) dexti >gfxObjectTemp movei r0,gfxObjectTemp nop st r0,r3 addi r0,2 nop st r0,r4 addi r0,2 nop st r0,r5 ;************ y test rqldi r6,1 rqldi r6,3 rqldi r6,5 ld r3 ;dest y ld r4 ;hight ld r5 ;source y ;clip up cmplosi r3,0 ;r3<0 brtc screenClipYLowInRange nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot add r4,r4,r3 ;height + (-y) sub r5,r5,r3 ;source - (-y) movei r3,0 ;y = 0 cmplosi r4,1 ;y < 1 brts screenClipOutOfView nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot screenClipYLowInRange ;clip down movei r0,$e0 ;total_height = 224 nop add r1,r3,r4 ;r1 = height + y nop cmplo r1,r0 ;height + y < total_height brts screenClipYHighInScreen nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot sub r4,r0,r3 ;height = total_height+16 - y nop cmplosi r4,1 ; brts screenClipOutOfView nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot screenClipYHighInScreen ;store back (y, hight, source y) dexti >gfxObjectTemp movei r0,gfxObjectTemp nop addi r0,1 nop st r0,r3 addi r0,2 nop st r0,r4 addi r0,2 nop st r0,r5 ;all in view movei r0,1 screenClipEnd rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot screenClipOutOfView br screenClipEnd movei r0,0 ;out of view delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* moveAnimShip ;* ;* reads from keyboard / move ship / anim ship ;* moveAnimShip push r7 ;check keys and set shipMoveStore movei r4,0 ;OURL ;left gpci r7,2 ;next 4 + X br PS2TestKey movei r0,251 ;left arrow delay slot nop ;delay slot nop ;delay slot nop ;delay slot add r4,r4,r0 ;if pressed ;right gpci r7,2 ;next 4 + X br PS2TestKey movei r0,$04 ;right arrow delay slot nop ;delay slot moveih r0,1 ;delay slot nop ;delay slot muli r0,2 nop add r4,r4,r0 ;if pressed ;up gpci r7,2 ;next 4 + X br PS2TestKey movei r0,$05 ;up arrow delay slot nop ;delay slot moveih r0,1 ;delay slot nop ;delay slot muli r0,8 nop add r4,r4,r0 ;if pressed ;down gpci r7,2 ;next 4 + X br PS2TestKey movei r0,$02 ;down arrow delay slot nop ;delay slot moveih r0,1 ;delay slot nop ;delay slot muli r0,4 nop add r4,r4,r0 ;if pressed ;store for later processing dexti >shipMoveStore movei r3,shipMoveStore nop st r3,r4 ;now real update ship coords movei r3,shipMoveStore movei r4,gfxObjectShip moveih r3,>shipMoveStore moveih r4,>gfxObjectShip rqldi r3,0 rqldi r4,0 rqldi r4,1 ld r0 ;ship OURL ld r1 ;x ld r2 ;y extri r0,0 brtc shipNotLeft nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot subi r1,1 shipNotLeft extri r0,1 brtc shipNotRight nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot addi r1,1 shipNotRight extri r0,2 brtc shipNotDown nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot addi r2,1 shipNotDown extri r0,3 brtc shipNotUp nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot subi r2,1 shipNotUp ;check x y ranges movei r3,0 cmplosi r1,0 ;x<0 movets r1,r3,r1 movei r3,0 cmplosi r2,0 ;y<0 movets r2,r3,r2 movei r3,$50 ;360+8-40=335=$150 nop moveih r3,$1 nop cmplo r1,r3 ;x=>335 movets r1,r1,r3 movei r3,$b5 ;225-44=$b5 nop cmplo r2,r3 ;x=>181 movets r2,r2,r3 ;store back st r4,r1 ;x addi r4,1 nop st r4,r2 ;y ;animate (timer/counter updates) dexti >gfxAnimCounterShip movei r3,gfxAnimCounterShip nop rqldi r3,0 nop nop ld r1 ;anim counter 0..2 nop cmpeqi r1,2 ;anim overflow brtc noAnimUpdate addi r1,1 ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot movei r1,0 ;anim counter to 0 noAnimUpdate nop st r3,r1 ;store anim counter ;update ship object struct with correct source x,y,w,h from animation counter movei r2,gfxObjectShip movei r3,gfxAnimCounterShip movei r5,shipMoveStore movei r4,gfxObjectShipAnimNormal moveih r2,>gfxObjectShip moveih r3,>gfxAnimCounterShip moveih r5,>shipMoveStore moveih r4,>gfxObjectShipAnimNormal ;check left right up down anim rqldi r5,0 nop nop ld r5 ;UDRL ;normal left right ;UD = 0 ;L = 12 ;R = 24 movei r1,0 ;normal movei r0,12 ;left extri r5,0 ;left ? movets r6,r0,r1 movei r0,24 ;right extri r5,1 ;right ? movets r6,r0,r6 ; rqldi r3,0 addi r2,2 ;w/h/x/y offset nop ld r0 ;animcounter nop muli r0,4 ;4 word per data nop add r0,r0,r6 ;left right offset nop add r4,r4,r0 ;add to anim offset nop rqldi r4,0 rqldi r4,1 rqldi r4,2 ld r0 ;w ld r1 ;h ld r5 ;x rqldi r4,3 nop nop ld r6 ;y st r2,r0 addi r2,1 nop st r2,r1 addi r2,1 nop st r2,r5 addi r2,1 nop st r2,r6 ; rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* clipAndDrawObject ;* ;* r6 = object ;* clipAndDrawObject push r7 ;srceen clip object gpci r7,2 br screenClipObject nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot cmpeqi r0,0 ;out of view brts skipObjectDraw nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;temp object (is generated by clipping) dexti >gfxObjectTemp movei r6,gfxObjectTemp nop ;start calculate and draw ;dest address rqldi r6,0 rqldi r6,1 nop ld r0 ;x ld r1 ;y movei r2,$78 movei r3,drawFrame moveih r2,$1 moveih r3,>drawFrame mul r1,r1,r2 ;y * (360+16) gmulhi r2 ;r2:r1 add r1,r1,r0 addtqi r2,r2,0 ;r2:r1 = y * (360+16) +x rqldi r3,1 ;draw frame low rqldi r3,0 ;draw frame high nop ld r0 ;low ld r3 ;high add r1,r1,r0 addt r2,r2,r3 ;r2:r1 + dest frame nop push r1 push r2 ;source address rqldi r6,6 rqldi r6,7 nop ld r1 ;low source addr ld r0 ;high source addr rqldi r6,4 ;source x rqldi r6,5 ;source y nop ld r2 ;x ld r3 ;y movei r4,0 nop moveih r4,1 nop mul r3,r3,r4 nop add r3,r3,r2 ;+x gmulhi r5 add r1,r1,r3 addt r0,r0,r5 nop push r1 ;source adr high push r0 ;source adr low ;source / dest offset rqldi r6,3 rqldi r6,2 nop ld r3 ;height ld r2 ;width movei r5,$78 movei r4,$00 moveih r5,$01 ;dest width = 360+16 = 376 moveih r4,$01 ;source width = 256 lsri r2,3 ;width / 8 nop muli r2,8 ;*8 (witdh is only setable by mult of 8) nop sub r1,r5,r2 ;total dest width - object width sub r0,r4,r2 ;total source width - object width push r1 ;dest offset push r0 ;source offset ;setup width and height lsri r2,3 ;width / 8 nop ; subi r2,1 ;width / 8 -1 subi r3,1 ;height -1 push r2 ;width push r3 ;height ;draw it gpci r7,2 br copyMasked nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot rqpop rqpop rqpop rqpop rqpop rqpop rqpop rqpop nop nop nop ; skipObjectDraw rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* clipAndTestAndDrawObject ;* ;* r6 = object ;* clipAndTestAndDrawObject push r7 ;srceen clip object gpci r7,2 br screenClipObject nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot cmpeqi r0,0 ;out of view brts skipClipAndTestAndDrawObject nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;temp object (is generated by clipping) dexti >gfxObjectTemp movei r6,gfxObjectTemp nop ;start calculate and draw ;dest address rqldi r6,0 rqldi r6,1 nop ld r0 ;x ld r1 ;y movei r2,$78 movei r3,drawFrame moveih r2,$1 moveih r3,>drawFrame mul r1,r1,r2 ;y * (360+16) gmulhi r2 ;r2:r1 add r1,r1,r0 addtqi r2,r2,0 ;r2:r1 = y * (360+16) +x rqldi r3,1 ;draw frame low rqldi r3,0 ;draw frame high nop ld r0 ;low ld r3 ;high add r1,r1,r0 addt r2,r2,r3 ;r2:r1 + dest frame nop push r1 push r2 ;source address rqldi r6,6 rqldi r6,7 nop ld r1 ;low source addr ld r0 ;high source addr rqldi r6,4 ;source x rqldi r6,5 ;source y nop ld r2 ;x ld r3 ;y movei r4,0 nop moveih r4,1 nop mul r3,r3,r4 nop add r3,r3,r2 ;+x gmulhi r5 add r1,r1,r3 addt r0,r0,r5 nop push r1 ;source adr high push r0 ;source adr low ;source / dest offset rqldi r6,3 rqldi r6,2 nop ld r3 ;height ld r2 ;width movei r5,$78 movei r4,$00 moveih r5,$01 ;dest width = 360+16 = 376 moveih r4,$01 ;source width = 256 lsri r2,3 ;width / 8 nop muli r2,8 ;*8 (witdh is only setable by mult of 8) nop sub r1,r5,r2 ;total dest width - object width sub r0,r4,r2 ;total source width - object width push r1 ;dest offset push r0 ;source offset ;setup width and height lsri r2,3 ;width / 8 nop ; subi r2,1 ;width / 8 -1 subi r3,1 ;height -1 push r2 ;width push r3 ;height ;draw it gpci r7,2 br copyMaskedAndTest nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot rqpop rqpop rqpop rqpop rqpop rqpop rqpop rqpop nop nop nop ; skipClipAndTestAndDrawObject rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* copyMasked ;* ;* sp+0 height-1 ;* sp+1 width/8-1 ;* sp+2 source offset ;* sp+3 dest offset ;* sp+4 source adr high ;* sp+5 source adr low ;* sp+6 dest adr high ;* sp+7 dest adr low ;* copyMasked push r7 getsp r7,0 nop addi r7,1 ;go to data offset nop rqldi r7,4 rqldi r7,5 rqldi r7,6 ld r4 ;source low ld r3 ;source high ld r6 ;dest high rqldi r7,7 nop nop ld r5 ;dest low copyMaskedy rqldi r7,1 ;width nop nop ld r2 ; copyMasked8x esadr r4,r3 erqldi 0 erqldi 1 erqldi 2 erqldi 3 erqldi 4 erqldi 5 erqldi 6 erqldi 7 esadr r6,r5 eld r0 eld r1 extri r0,15 estts r0,0 extri r1,15 estts r1,1 eld r0 eld r1 extri r0,15 estts r0,2 extri r1,15 estts r1,3 eld r0 eld r1 extri r0,15 estts r0,4 extri r1,15 estts r1,5 eld r0 eld r1 extri r0,15 estts r0,6 extri r1,15 estts r1,7 subi r2,1 brts copyMasked8x addi r3,8 ;delay slot addtqi r4,r4,0 ;delay slot addi r5,8 ;delay slot addtqi r6,r6,0 ;delay slot ; rqldi r7,2 ;source offset rqldi r7,3 ;dest offset rqldi r7,0 ;hight ld r0 ld r1 ld r2 add r3,r3,r0 ;add source x offset addtqi r4,r4,0 subi r2,1 ;hight -- brts copyMaskedy st r7,r2 ;store to hight delay slot add r5,r5,r1 ;add dest x offset delay slot addtqi r6,r6,0 ;delay slot nop ;delay slot ;clear stack rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* copyMaskedAndTest ;* ;* sp+0 height-1 ;* sp+1 width/8-1 ;* sp+2 source offset ;* sp+3 dest offset ;* sp+4 source adr high ;* sp+5 source adr low ;* sp+6 dest adr high ;* sp+7 dest adr low ;* ;* return ;* ;* r1 = is dest and source pixel of (not 0 if there is a pixel to pixel collision) ;* copyMaskedAndTest push r7 getsp r7,0 movei r1,0 ;pixel to pixel collision addi r7,1 ;go to data offset nop rqldi r7,4 rqldi r7,5 rqldi r7,6 ld r4 ;source low ld r3 ;source high ld r6 ;dest high rqldi r7,7 nop nop ld r5 ;dest low copyMaskedAndTesty rqldi r7,1 ;width nop nop ld r2 ; copyMaskedAndTest8x esadr r4,r3 erqldi 0 esadr r6,r5 erqldi 0 esadr r4,r3 erqldi 1 esadr r6,r5 erqldi 1 esadr r4,r3 erqldi 2 esadr r6,r5 erqldi 2 esadr r4,r3 erqldi 3 esadr r6,r5 erqldi 3 esadr r4,r3 erqldi 4 esadr r6,r5 erqldi 4 esadr r4,r3 erqldi 5 esadr r6,r5 erqldi 5 esadr r4,r3 erqldi 6 esadr r6,r5 erqldi 6 esadr r4,r3 erqldi 7 esadr r6,r5 erqldi 7 eld r0 ;bob nop extri r0,15 estts r0,0 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,1 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,2 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,3 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,4 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,5 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,6 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data eld r0 ;bob nop extri r0,15 estts r0,7 eld r0 ;back nop orts r1,r0 ;or bg if bob has valid data subi r2,1 brts copyMaskedAndTest8x addi r3,8 ;delay slot addtqi r4,r4,0 ;delay slot addi r5,8 ;delay slot addtqi r6,r6,0 ;delay slot ; rqldi r7,2 ;source offset rqldi r7,0 ;hight nop ld r0 ld r2 add r3,r3,r0 ;add source x offset addtqi r4,r4,0 rqldi r7,3 ;dest offset subi r2,1 ;hight -- brts copyMaskedAndTesty ld r0 ;dest offset delay slot st r7,r2 ;store to hight delay slot add r5,r5,r0 ;add dest x offset delay slot addtqi r6,r6,0 ;delay slot ; add r1,r1,r1 ;push out msb ;clear stack rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* switchAndClearFrame ;* ;* ;* switchAndClearFrame push r7 ;wait vpos (930) gpci r7,2 ;next 4 + X br waitVPos movei r0,$a1 ;delay slot nop ;delay slot moveih r0,$3 ;delay slot nop ;delay slot ;switch frames gpci r7,2 ;next 4 + X br switchFrames nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;set display address to video movei r0,displayFrame movei r1,UcVideoMEMStartAdrLow movei r2,UcVideoMEMLatch moveih r0,>displayFrame moveih r1,>UcVideoMEMStartAdrLow ;low memstart moveih r2,>UcVideoMEMLatch ;latch out rqldi r0,1 rqldi r0,0 nop ld r3 ld r4 addi r3,8 ;offset nop st r1,r3 addi r1,1 nop st r1,r4 st r2,r7 ;latch out ;clear draw frame movei r0,drawFrame movei r1,$4f ;clear (360+16)*225 / 8 = $294f moveih r0,>drawFrame moveih r1,$29 rqldi r0,1 rqldi r0,0 nop ld r2 ld r3 gpci r7,2 br memSet8Words movei r0,0 ;clear value delay slot nop ;delay slot nop ;delay slot nop ;delay slot rqpop nop nop pop r7 nop jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* extCopy8 ;* ;* r1:r0 source ;* r3:r2 dest ;* r4 count - 1 (8 words per count) ;* extCopy8 push r5 push r6 extCopy8Loop esadr r1,r0 erqldi 0 erqldi 1 erqldi 2 erqldi 3 erqldi 4 erqldi 5 erqldi 6 erqldi 7 esadr r3,r2 eld r5 eld r6 est r5,0 est r6,1 eld r5 eld r6 est r5,2 est r6,3 eld r5 eld r6 est r5,4 est r6,5 eld r5 eld r6 est r5,6 est r6,7 subi r4,1 brts extCopy8Loop addi r0,8 ;delay slot addtqi r1,r1,0 ;delay slot addi r2,8 ;delay slot addtqi r3,r3,0 ;delay slot rqpop rqpop jmpi r7,0 pop r6 ;delay slot pop r7 ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* switchFrames ;* switchFrames push r0 push r1 push r2 push r3 push r4 push r5 movei r0,displayFrame movei r1,drawFrame moveih r0,>displayFrame moveih r1,>drawFrame rqldi r0,0 rqldi r0,1 nop ld r2 ld r3 rqldi r1,0 rqldi r1,1 nop ld r4 ld r5 st r0,r4 addi r0,1 nop st r0,r5 st r1,r2 addi r1,1 nop st r1,r3 rqpop rqpop rqpop pop r5 pop r4 pop r3 rqpop rqpop rqpop pop r2 pop r1 pop r0 jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* waitVPos ;* ;* r0 pos ;* waitVPos push r1 push r2 ;check emulator to prevent face freez ..... dexti >UuLedR movei r1,UuLedR ;emulator nop rqldi r1,0 nop nop ld r2 nop cmpeqi r2,1 brts waitVEmulator nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot waitVRealHardWare dexti >UcVideoRVCountWHSYNC movei r1,UcVideoRVCountWHSYNC ;vcount nop waitV rqldi r1,0 nop nop ld r2 ;get vcount nop cmpeq r0,r2 brtc waitV nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot rqpop rqpop jmpi r7,0 pop r2 ;delay slot pop r1 ;delay slot nop ;delay slot nop ;delay slot waitVEmulator dexti >UcVideoRVCountWHSYNC movei r1,UcVideoRVCountWHSYNC ;vcount nop waitVE rqldi r1,0 nop nop ld r2 ;get vcount nop cmplo r0,r2 brts waitVE nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot rqpop rqpop jmpi r7,0 pop r2 ;delay slot pop r1 ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* memSet8Words ;* ;* r0 value ;* r1 count-1 (8 words)) ;* r3:r2 dest ; memSet8Words clearLoop esadr r3,r2 est r0,0 est r0,1 est r0,2 est r0,3 est r0,4 est r0,5 subi r1,1 brts clearLoop addi r2,8 ;delay slot addtqi r3,r3,0 ;delay slot est r0,6 ;delay slot est r0,7 ;delay slot jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* rand (optimzed) ;* ;* return r0 = result ;* rand push r1 push r2 push r3 push r4 push r5 movei r5,randSeed movei r0,$39 moveih r5,>randSeed movei r1,$6d movei r2,$c6 rqldi r5,0 rqldi r5,1 moveih r0,$30 ;r0 = 12345 ld r3 ;low seed ld r4 ;high seed moveih r1,$4e moveih r2,$41 ;r2:r1 = $41c6 4e6d = 1103515245 mul r3,r3,r0 ;r3 = seed * 12345 , low gmulhi r4 ;r0 = ... high add r3,r3,r1 ; addt r4,r4,r2 ; st r5,r3 ;low seed addi r5,1 or r0,r3,r3 ;result = high seed st r5,r4 ;high seed rqpop rqpop rqpop pop r5 pop r4 pop r3 rqpop rqpop jmpi r7,0 pop r2 ;delay slot pop r1 ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* resetData ;* resetData ;clear stone count movei r6,gfxObjectStoneCount movei r0,0 moveih r6,>gfxObjectStoneCount nop st r6,r0 ;clear stones movei r3,gfxObjectStoneCountMax clearStonesLoop dexti >gfxObjectStones movei r6,gfxObjectStones nop add r6,r6,r3 nop rqldi r6,0 nop movei r0,$ff ld r5 ;ptr to stone moveih r0,3 ;1024 addi r5,12 ;yintern nop st r5,r0 ;rest yintern to start value subi r3,1 brts clearStonesLoop nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;reset energie movei r6,Energie movei r0,$2c moveih r6,>Energie moveih r0,$1 ;300 nop st r6,r0 ;reset ship movei r6,gfxObjectShip movei r0,168 moveih r6,>gfxObjectShip movei r1,182 st r6,r0 ;x addi r6,1 nop st r6,r1 ;y ;reset timer movei r6,playTimeCounter movei r0,0 moveih r6,>playTimeCounter nop st r6,r0 jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;****************************** ;* ;* setupVideo ;* setupVideo movei r0,videoDefault ;source movei r1,UcTimer2Ctrl ;dest-1 moveih r0,>videoDefault moveih r1,>UcTimer2Ctrl movei r2,26 ;27-1 setupVideoLoop rqldi r0,0 addi r0,1 addi r1,1 ld r3 subi r2,1 brts setupVideoLoop st r1,r3 ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot jmpi r7,0 nop ;delay slot nop ;delay slot nop ;delay slot nop ;delay slot ;********************************************************************* ;* data ;********************************************************************* videoDefault ;AD NAME NEW DEFAULT word $0001 ;10 VIDEO_ON 1 (ON) word $0097 ;11 HSYNC (D = 11 .. 0) 152-1 word $017f ;12 HSTART (D = 11 .. 0) 384-1 word $017d ;13 HMEMSTART (D = 11 .. 0) 382-1 word $071f ;14 HSTOP (D = 11 .. 0) 1824-1 word $076f ;15 HTOTAL (D = 11 .. 0) 1904-1 word $0002 ;16 VSYNC (D = 10 .. 0) 3-1 word $001e ;17 VSTART (D = 10 .. 0) 31-1 word $03a2 ;18 VSTOP (D = 10 .. 0) 931-1 word $03a3 ;19 VTOTAL (D = 10 .. 0) 932-1 word $0000 ;1a LC ADDER LOW $0000 word $0040 ;1b LC ADDER HIGH $0040 word $0000 ;1c LC ADDER LATCH X word $0000 ;1d LC START (10 .. 0) Pixeloffset $0000 word $0000 ;1e X word $0000 ;1f X word $0008 ;20 HLOADSTART 8 word $00bc ;21 HLOADSTOP 180+8 word $001e ;22 VLOADSTART 31-1 word $03a2 ;23 VLOADSTOP 931-1 word $0004 ;24 VLOADNEXT 4 word $0008 ;25 MEM_STARTADR_store low $0000 word $d000 ;26 MEM_STARTADR_store high $f000 word $0010 ;27 MEM_LINEOFFSET_store low $0000 word $0000 ;28 MEM_LINEOFFSET_store high $0000 word $0002 ;29 MEM_MODE_store 2 (X1R5G5B5X1R5G5B5) word $0000 ;2a LATCH MEM_STARTADR/LINEOFFSET/MODE X ;********************************************************************* ;* data ;********************************************************************* stringWelcome1 .string "goldmomo presents on goldmomo_endlos" word 0 stringWelcome2 .string "-= SPACE PILOT OF DEATH =-" word 0 stringWelcome3 .string "Programming by goldmomo" word 0 stringWelcome4 .string "GFX by arboris" word 0 stringWelcome5 .string "SFX not implemented yet" word 0 stringWelcome6 .string "Press space to start" word 0 stringPower .string "Power" word 0 stringTime .string "Time %us" word 0 stringMeteoroids .string "Meteoroids %u" word 0 stringGameOver .string "GAME OVER" word 0 stringGameOver2 .string "Press space to restart" word 0 playTimeCounter word 0 randSeed word $dead word $beef ;Energie bar Energie word 300 ;GFX / ctrl gfxObjectTemp .space 8 ;for clip to draw object ;********************** .def gfxObjectStoneCountMax 63 ;+1 gfxObjectStoneCount word 63 ;n+1 gfxObjectStones word gfxObjectStone1 word gfxObjectStone2 word gfxObjectStone3 word gfxObjectStone4 word gfxObjectStone5 word gfxObjectStone6 word gfxObjectStone7 word gfxObjectStone8 word gfxObjectStone9 word gfxObjectStoneA word gfxObjectStoneB word gfxObjectStoneC word gfxObjectStoneD word gfxObjectStoneE word gfxObjectStoneF word gfxObjectStoneG word gfxObjectStoneH word gfxObjectStoneI word gfxObjectStoneJ word gfxObjectStoneK word gfxObjectStoneL word gfxObjectStoneM word gfxObjectStoneN word gfxObjectStoneO word gfxObjectStoneP word gfxObjectStoneQ word gfxObjectStoneR word gfxObjectStoneS word gfxObjectStoneT word gfxObjectStoneU word gfxObjectStoneV word gfxObjectStoneW word gfxObjectStone21 word gfxObjectStone22 word gfxObjectStone23 word gfxObjectStone24 word gfxObjectStone25 word gfxObjectStone26 word gfxObjectStone27 word gfxObjectStone28 word gfxObjectStone29 word gfxObjectStone2A word gfxObjectStone2B word gfxObjectStone2C word gfxObjectStone2D word gfxObjectStone2E word gfxObjectStone2F word gfxObjectStone2G word gfxObjectStone2H word gfxObjectStone2I word gfxObjectStone2J word gfxObjectStone2K word gfxObjectStone2L word gfxObjectStone2M word gfxObjectStone2N word gfxObjectStone2O word gfxObjectStone2P word gfxObjectStone2Q word gfxObjectStone2R word gfxObjectStone2S word gfxObjectStone2T word gfxObjectStone2U word gfxObjectStone2V word gfxObjectStone2W ; 0 1 2 3 4 ; 0 1 2 3 4 5 6 7 8 9 a b c ; x y w h sx sy srclow srchigh yspeed S1 cox coy colsize yintern gfxObjectStone1 .data 4, -60, 24, 21, 94, 316, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone2 .data 273, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone3 .data 82, -60, 24, 21, 94, 316, $c3f0, $d002, 24, 10, 10, 9, 1024 gfxObjectStone4 .data 200, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone5 .data 186, -60, 32, 31, 64, 262, $c3f0, $d002, 24, 20, 15, 14, 1024 gfxObjectStone6 .data 109, -60, 16, 12, 105, 270, $c3f0, $d002, 24, 9, 6, 6, 1024 gfxObjectStone7 .data 53, -60, 56, 42, 0, 306, $c3f0, $d002, 24, 33, 22, 21, 1024 gfxObjectStone8 .data 324, -60, 24, 26, 63, 315, $c3f0, $d002, 24, 5, 13, 9, 1024 gfxObjectStone9 .data 304, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStoneA .data 184, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStoneB .data 314, -60, 24, 21, 94, 316, $c3f0, $d002, 24, 10, 10, 9, 1024 gfxObjectStoneC .data 209, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStoneD .data 98, -60, 32, 31, 64, 262, $c3f0, $d002, 24, 20, 15, 14, 1024 gfxObjectStoneE .data 17, -60, 16, 12, 105, 270, $c3f0, $d002, 24, 9, 6, 5, 1024 gfxObjectStoneF .data 168, -60, 56, 42, 0, 306, $c3f0, $d002, 24, 33, 22, 21, 1024 gfxObjectStoneG .data 71, -60, 24, 26, 63, 315, $c3f0, $d002, 24, 5, 13, 9, 1024 gfxObjectStoneH .data 156, -60, 56, 53, 2, 246, $c3f0, $d002, 3, 28, 21, 25, 1024 gfxObjectStoneI .data 115, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStoneJ .data 351, -60, 24, 21, 94, 316, $c3f0, $d002, 2, 10, 10, 9, 1024 gfxObjectStoneK .data 253, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStoneL .data 107, -60, 32, 31, 64, 262, $c3f0, $d002, 3, 20, 15, 14, 1024 gfxObjectStoneM .data 8, -60, 16, 12, 105, 270, $c3f0, $d002, 4, 9, 6, 6, 1024 gfxObjectStoneN .data 132, -60, 56, 42, 0, 306, $c3f0, $d002, 2, 33, 22, 21, 1024 gfxObjectStoneO .data 282, -60, 24, 26, 63, 315, $c3f0, $d002, 2, 5, 13, 9, 1024 gfxObjectStoneP .data 4, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStoneQ .data 334, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStoneR .data 172, -60, 24, 21, 94, 316, $c3f0, $d002, 3, 10, 10, 9, 1024 gfxObjectStoneS .data 255, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStoneT .data 7, -60, 32, 31, 64, 262, $c3f0, $d002, 3, 20, 15, 14, 1024 gfxObjectStoneU .data 301, -60, 16, 12, 105, 270, $c3f0, $d002, 4, 9, 6, 5, 1024 gfxObjectStoneV .data 19, -60, 56, 42, 0, 306, $c3f0, $d002, 3, 33, 22, 21, 1024 gfxObjectStoneW .data 24, -60, 24, 26, 63, 315, $c3f0, $d002, 3, 5, 13, 9, 1024 gfxObjectStone21 .data 4, -60, 24, 21, 94, 316, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone22 .data 273, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone23 .data 82, -60, 24, 21, 94, 316, $c3f0, $d002, 24, 10, 10, 9, 1024 gfxObjectStone24 .data 200, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone25 .data 186, -60, 32, 31, 64, 262, $c3f0, $d002, 24, 20, 15, 14, 1024 gfxObjectStone26 .data 109, -60, 16, 12, 105, 270, $c3f0, $d002, 24, 9, 6, 6, 1024 gfxObjectStone27 .data 53, -60, 56, 42, 0, 306, $c3f0, $d002, 24, 33, 22, 21, 1024 gfxObjectStone28 .data 324, -60, 24, 26, 63, 315, $c3f0, $d002, 24, 5, 13, 9, 1024 gfxObjectStone29 .data 304, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone2A .data 184, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone2B .data 314, -60, 24, 21, 94, 316, $c3f0, $d002, 24, 10, 10, 9, 1024 gfxObjectStone2C .data 209, -60, 56, 53, 2, 246, $c3f0, $d002, 24, 28, 21, 25, 1024 gfxObjectStone2D .data 98, -60, 32, 31, 64, 262, $c3f0, $d002, 24, 20, 15, 14, 1024 gfxObjectStone2E .data 17, -60, 16, 12, 105, 270, $c3f0, $d002, 24, 9, 6, 5, 1024 gfxObjectStone2F .data 168, -60, 56, 42, 0, 306, $c3f0, $d002, 24, 33, 22, 21, 1024 gfxObjectStone2G .data 71, -60, 24, 26, 63, 315, $c3f0, $d002, 24, 5, 13, 9, 1024 gfxObjectStone2H .data 156, -60, 56, 53, 2, 246, $c3f0, $d002, 3, 28, 21, 25, 1024 gfxObjectStone2I .data 115, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStone2J .data 351, -60, 24, 21, 94, 316, $c3f0, $d002, 2, 10, 10, 9, 1024 gfxObjectStone2K .data 253, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStone2L .data 107, -60, 32, 31, 64, 262, $c3f0, $d002, 3, 20, 15, 14, 1024 gfxObjectStone2M .data 8, -60, 16, 12, 105, 270, $c3f0, $d002, 4, 9, 6, 6, 1024 gfxObjectStone2N .data 132, -60, 56, 42, 0, 306, $c3f0, $d002, 2, 33, 22, 21, 1024 gfxObjectStone2O .data 282, -60, 24, 26, 63, 315, $c3f0, $d002, 2, 5, 13, 9, 1024 gfxObjectStone2P .data 4, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStone2Q .data 334, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStone2R .data 172, -60, 24, 21, 94, 316, $c3f0, $d002, 3, 10, 10, 9, 1024 gfxObjectStone2S .data 255, -60, 56, 53, 2, 246, $c3f0, $d002, 2, 28, 21, 25, 1024 gfxObjectStone2T .data 7, -60, 32, 31, 64, 262, $c3f0, $d002, 3, 20, 15, 14, 1024 gfxObjectStone2U .data 301, -60, 16, 12, 105, 270, $c3f0, $d002, 4, 9, 6, 5, 1024 gfxObjectStone2V .data 19, -60, 56, 42, 0, 306, $c3f0, $d002, 3, 33, 22, 21, 1024 gfxObjectStone2W .data 24, -60, 24, 26, 63, 315, $c3f0, $d002, 3, 5, 13, 9, 1024 ;********************** gfxObjectShip word 168 ;0 dest pos x word 182 ;1 dest pos y word 40 ;2 width word 40 ;3 height word 41 ;4 source x word 3 ;5 source y word $c3f0 ;6 source low word $d002 ;7 source high word 0 ;8 0 no speed word 20 ;9 1 collision offset x word 23 ;a 2 collision offset y word 18 ;b 3 collision size gfxObjectShipAnimNormal ; w h x y .data 40, 36, 41, 3 .data 40, 43, 41, 43 .data 40, 40, 41, 89 gfxObjectShipAnimLeft ; w h x y .data 40, 36, 0, 3 .data 40, 43, 0, 43 .data 40, 40, 0, 89 gfxObjectShipAnimRight ; w h x y .data 40, 36, 85, 3 .data 40, 43, 85, 43 .data 40, 40, 85, 89 gfxAnimCounterShip word 0 ;********************** gfxObjectExplosion word 168 ;0 dest pos x word 182 ;1 dest pos y word 48 ;2 width word 48 ;3 height word 2 ;4 source x word 195 ;5 source y word $c3f0 ;6 source low word $d002 ;7 source high word 0 ;8 0 no speed word 0 ;9 1 collision offset x word 0 ;a 2 collision offset y word 22 ;b 3 collision size gfxObjectExplosionAnim ; w h x y .data 48, 49, 0, 195 .data 56, 49, 53, 195 .data 56, 49, 124, 195 .data 56, 49, 192, 196 gfxAnimCounterExplosion word 0 ;********************** shipMoveStore word 0 ;UDRL displayFrame .data $d000,$0000 drawFrame .data $d001,$4a78 fontAddress .data $d002,$94f0