SUB.SRC 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. ************************************************************************
  2. * *
  3. * [[[ NOP ]]] COMMON SUBROUTINES *
  4. * by S.OKADA from 91/09/04 Wed 16:22 *
  5. * *
  6. ************************************************************************
  7. XDEF SYS_FIRST_INIT,SYS_SECOND_INIT
  8. XDEF LWORK_INIT,PWORK_INIT,LPWORK_INIT
  9. XDEF FREE_PWORK,FREE_LWORK,AFTER_FREE_WORK
  10. XDEF PWORK_SET
  11. XDEF BIT_FLAG_CLEAR,BYTE_FLAG_CLEAR
  12. XDEF RAND16,RAND8
  13. XDEF SIN,COS,SIN_L,COS_L,MUL32,SEC_TIME,SEC_TIME_BCD
  14. XDEF PLAYABLE
  15. XDEF M_FIX_CLEAR
  16. XDEF OBJ_MAP_SET
  17. XREF ?A5
  18. ;by SUB
  19. XREF INIT_SOUND
  20. SECT.S SYS,,C
  21. INCLUDE NEO_GEO.INC @@@
  22. INCLUDE LABEL.INC
  23. INCLUDE MACRO.INC @@@
  24. INCLUDE CML.INC @@@
  25. ;
  26. ; *** system work initialize ***
  27. ;
  28. SYS_FIRST_INIT:
  29. ; initialize for interrupt enable
  30. MOVE.B D0,PALETTE_BANK0
  31. MOVEQ.L #0,D0
  32. MOVE.L D0,(A5)
  33. MOVE.L D0,4(A5)
  34. MOVE.B D0,ERROR_LEVER(A5)
  35. MOVE.B D0,TEMP_ORDER(A5)
  36. MOVE.W D0,COLOR_BUFFER_0+32*16*0(A5)
  37. MOVE.W D0,COLOR_BUFFER_0+32*16*1(A5)
  38. MOVE.W D0,COLOR_BUFFER_0+32*16*2(A5)
  39. MOVE.W D0,COLOR_BUFFER_0+32*16*3(A5)
  40. MOVE.W D0,COLOR_BUFFER_0+32*16*4(A5)
  41. MOVE.W D0,COLOR_BUFFER_0+32*16*5(A5)
  42. MOVE.W D0,COLOR_BUFFER_0+32*16*6(A5)
  43. MOVE.W D0,COLOR_BUFFER_0+32*16*7(A5)
  44. MOVE.W D0,COLOR_BUFFER_0+32*16*8(A5)
  45. MOVE.W D0,COLOR_BUFFER_0+32*16*9(A5)
  46. MOVE.W D0,COLOR_BUFFER_0+32*16*10(A5)
  47. MOVE.W D0,COLOR_BUFFER_0+32*16*11(A5)
  48. MOVE.W D0,COLOR_BUFFER_0+32*16*12(A5)
  49. MOVE.W D0,COLOR_BUFFER_0+32*16*13(A5)
  50. MOVE.W D0,COLOR_BUFFER_0+32*16*14(A5)
  51. MOVE.W D0,COLOR_BUFFER_0+32*16*15(A5)
  52. MOVE.L D0,OBJ2_MAP(A5)
  53. MOVE.L D0,OBJ2_MAP+4(A5)
  54. MOVE.L D0,OBJ3_MAP(A5)
  55. MOVE.L D0,OBJ3_MAP+4(A5)
  56. MOVE.L D0,OBJ4_MAP(A5)
  57. MOVE.L D0,OBJ4_MAP+4(A5)
  58. MOVE.W #1,OBJ1_MAP(A5)
  59. MOVE.W #380,OBJ1_MAP+2(A5)
  60. MOVE.W #380,OBJ1_MAP+4(A5)
  61. MOVE.W #-1,OBJ1_MAP+6(A5)
  62. MOVE.B #80H,ORDER_BUFFER(A5)
  63. MOVE.B #80H,ORDER_BUFFER+128(A5)
  64. MOVE.B #100B,START_FLAG2(A5)
  65. MOVE.B D0,MESS_BUSY(A5)
  66. MOVE.L #MESS_BUFFER,MESS_POINT(A5)
  67. JSR INIT_SOUND(PC)
  68. BSR INFO_INIT
  69. BSR SECOND_VALUE_SET
  70. RTS
  71. INFO_INIT:
  72. ; tool data infomation intialize
  73. ;*** tool data infomation ***
  74. ALL_INFO_ADRS EQU 0F8H
  75. T_BACK_INFO EQU 20H
  76. T_PAL_IND_INFO EQU 24H
  77. T_OBJT_INFO EQU 30H
  78. T_PALETTE_INFO EQU 40H
  79. MOVE.L ALL_INFO_ADRS,A6
  80. MOVEQ.L #0FH,D0
  81. MOVE.L T_BACK_INFO(A6),BACK_INFO(A5)
  82. AND.W D0,BACK_INFO(A5)
  83. MOVE.L T_PAL_IND_INFO(A6),PAL_IND_INFO(A5)
  84. AND.W D0,PAL_IND_INFO(A5)
  85. MOVE.L T_OBJT_INFO(A6),OBJT_INFO(A5)
  86. AND.W D0,OBJT_INFO(A5)
  87. MOVE.L T_PALETTE_INFO(A6),PALETTE_INFO(A5)
  88. AND.W D0,PALETTE_INFO(A5)
  89. RTS
  90. SECOND_VALUE_SET:
  91. MOVE.B #60,SECOND_VALUE(A5)
  92. MOVE.W V_POSITION,D0
  93. BTST.L #3,D0
  94. BEQ.S SVS_1 NTSC mode
  95. MOVE.B #50,SECOND_VALUE(A5) PAL mode
  96. SVS_1:
  97. RTS
  98. SYS_SECOND_INIT:
  99. ; intialize for all program
  100. JSR LPWORK_INIT(PC)
  101. JSR BIT_FLAG_CLEAR(PC)
  102. JSR BYTE_FLAG_CLEAR(PC)
  103. MOVEQ.L #0,D0
  104. MOVE.W D0,COLOR_STATE(A5)
  105. MOVE.W D0,COLOR_FLAG(A5)
  106. MOVE.W D0,COLOR_TIMER(A5)
  107. MOVE.B D0,START_FLAG2(A5)
  108. MOVE.W D0,STOP_STEP(A5)
  109. MOVE.B D0,FIRST_START(A5)
  110. BCLR.B #0,MAKE_RANDOM(A5)
  111. BCLR.B #0,READ_RANDOM(A5)
  112. MOVE.B D0,LSPC_BUSY(A5)
  113. MOVE.B #1,STOPPER(A5)
  114. MESS_ON
  115. MOVE.L #M_SPRITE0_CLEAR,(A0)+
  116. MOVE.L #M_FIX_CLEAR,(A0)+
  117. MESS_OFF
  118. RTS
  119. M_SPRITE0_CLEAR:
  120. FIX_AUTO 1
  121. FIX_ADRS 0
  122. FIX_SAME 40H,0
  123. FIX_END
  124. M_FIX_CLEAR:
  125. FIX_AUTO 1
  126. FIX_ADRS 0,0
  127. FIX_SAME 020H,020H
  128. FIX_SAME 0E0H,0FFH
  129. FIX_SAME 0E0H,0FFH
  130. FIX_SAME 0E0H,0FFH
  131. FIX_SAME 0E0H,0FFH
  132. FIX_SAME 0E0H,0FFH
  133. FIX_SAME 060H,0FFH
  134. FIX_SAME 020H,020H
  135. FIX_END
  136. ;
  137. ; *** PHYSICAL and LOGICAL WORK INTIALIZE ***
  138. ;
  139. ; P(L)WORK all initialize
  140. ; set TYPE=0
  141. ; WORK_No=itself number
  142. ; use) D0,A6
  143. LWORK_INIT:
  144. LEA.L LWORK_START(A5),A6
  145. MOVEQ.L #11H,D0
  146. LWORK_INIT_1:
  147. MOVE.W #0,TYPE(A6)
  148. MOVE.B D0,WORK_No(A6)
  149. LEA.L 100H(A6),A6
  150. ADDQ.W #1,D0
  151. CMP.W #71H,D0
  152. BCS.S LWORK_INIT_1
  153. RTS
  154. PWORK_INIT:
  155. LEA.L PWORK_START(A5),A6
  156. MOVEQ.L #10H,D0
  157. PWORK_INIT_1:
  158. MOVE.W #0,TYPE(A6)
  159. MOVE.B D0,WORK_No(A6)
  160. LEA.L 100H(A6),A6
  161. ADDQ.W #1,D0
  162. CMP.W #70H,D0
  163. BCS.S PWORK_INIT_1
  164. RTS
  165. LPWORK_INIT:
  166. JSR LWORK_INIT(PC)
  167. JSR PWORK_INIT(PC)
  168. RTS
  169. ;
  170. ; *** SERCH FREE WORK ***
  171. ;
  172. ; out) NE (D0(.w)<>0)
  173. ; find free work A0
  174. ; EQ (D0(.w)=0)
  175. ; not find free work
  176. ; use) D0,A0
  177. FREE_LWORK:
  178. LEA.L LWORK_START+1000H(A5),A0 044 only
  179. MOVEQ.L #79-1,D0
  180. BRA.S FREE_WORK_1
  181. FREE_PWORK:
  182. LEA.L PWORK_START(A5),A0
  183. MOVEQ.L #96-1,D0
  184. FREE_WORK_1:
  185. TST.W TYPE(A0)
  186. BEQ FREE_WORK_2
  187. LEA.L 100H(A0),A0
  188. DBRA D0,FREE_WORK_1
  189. FREE_WORK_2:
  190. ADDQ.W #1,D0
  191. RTS
  192. AFTER_FREE_WORK:
  193. ; in) A6=temporary P(L)WORK
  194. ; out) NE (D0(.b)<>0)
  195. ; find free work A0
  196. ; EQ (D0(.b)=0)
  197. ; not find free work
  198. ; use) D0,A0
  199. LEA.L (A6),A0
  200. MOVE.B WORK_No(A6),D0
  201. AFW_1:
  202. TST.W TYPE(A0)
  203. BEQ AFW_2
  204. LEA.L 100H(A0),A0
  205. ADDQ.B #1,D0
  206. CMP.B #70H,D0
  207. BCS.S AFW_1
  208. AFW_2:
  209. SUB.B #6FH,D0
  210. RTS
  211. PWORK_SET:
  212. ; PWORK initialize
  213. ; in) A0 PWORK adrs
  214. ; D2(.hw) TYPE (.lw) ACT_No
  215. ; D3 (.w) X_POSITION
  216. ; D4 (.w) Y_POSITION
  217. ; D5 (.W) PRIORITY
  218. ; use) D0
  219. CLR.W TYPE(A0)
  220. MOVE.W D2,ACT_No(A0)
  221. SWAP D2
  222. MOVE.W D3,X_POSITION(A0)
  223. MOVE.W D4,Y_POSITION(A0)
  224. MOVE.B D5,PRIORITY(A0)
  225. MOVE.B #1,ACT_DEC(A0)
  226. MOVE.B #00100000B,ACT_ATTR(A0) ACTAT_OFF
  227. MOVEQ.L #0,D0
  228. MOVE.B D0,ACT_FLAG(A0)
  229. MOVE.W D0,X_POSITION+2(A0)
  230. MOVE.W D0,Y_POSITION+2(A0)
  231. MOVE.L D0,Z_POSITION(A0)
  232. MOVE.L D0,VX(A0)
  233. MOVE.L D0,VY(A0)
  234. MOVE.L D0,VZ(A0)
  235. MOVE.W D0,AX(A0)
  236. MOVE.W D0,AY(A0)
  237. MOVE.W D0,AZ(A0)
  238. MOVE.W D0,DISP_X(A0)
  239. MOVE.W D0,DISP_Y(A0)
  240. MOVE.B D0,PALETTE_ADD(A0)
  241. MOVE.B D0,FLASH_PALETTE(A0)
  242. MOVE.B D0,STEP1(A0)
  243. MOVE.B D0,STEP2(A0)
  244. MOVE.B D0,FLAG(A0)
  245. MOVE.B D0,HIT_FLAG(A0)
  246. MOVE.W D0,HIT_ACTIVE(A0)
  247. MOVE.L D0,WORK_N0(A0)
  248. MOVE.B D0,MASTER_No(A0)
  249. MOVE.L D0,HIT_OFS_X(A0)
  250. MOVE.L D0,HIT_LEFT(A0)
  251. MOVE.L D0,HIT_UPPER(A0)
  252. SUBQ.W #1,D0
  253. MOVE.W D0,SPRITE_POS(A0)
  254. MOVE.B D0,ACT_TIMER(A0)
  255. MOVE.B D0,ACT_COUNT(A0)
  256. MOVE.B D0,BIG_X(A0)
  257. MOVE.B D0,BIG_Y(A0)
  258. MOVE.W D2,TYPE(A0)
  259. RTS
  260. ;
  261. ; *** ACTION etc. ***
  262. ;
  263. OBJ_MAP_SET:
  264. ADDQ.B #1,LSPC_BUSY(A5)
  265. ADDQ.B #1,MESS_BUSY(A5)
  266. MOVE.L (A0)+,D0
  267. MOVE.L D0,OBJ1_MAP+OBJ_START(A5)
  268. MOVE.W D0,OBJ1_MAP+OBJ_USE(A5)
  269. MOVE.W (A0)+,OBJ1_MAP+DB_TYPE(A5)
  270. MOVE.L (A0)+,D0
  271. MOVE.L D0,OBJ2_MAP+OBJ_START(A5)
  272. MOVE.W D0,OBJ2_MAP+OBJ_USE(A5)
  273. MOVE.W (A0)+,OBJ2_MAP+DB_TYPE(A5)
  274. MOVE.L (A0)+,D0
  275. MOVE.L D0,OBJ3_MAP+OBJ_START(A5)
  276. MOVE.W D0,OBJ3_MAP+OBJ_USE(A5)
  277. MOVE.W (A0)+,OBJ3_MAP+DB_TYPE(A5)
  278. MOVE.L (A0)+,D0
  279. MOVE.L D0,OBJ4_MAP+OBJ_START(A5)
  280. MOVE.W D0,OBJ4_MAP+OBJ_USE(A5)
  281. MOVE.W (A0)+,OBJ4_MAP+DB_TYPE(A5)
  282. MOVE.L A0,OBJ_DIV_POINT(A5)
  283. LEA.L VPOS_BUFFER+2(A5),A0
  284. MOVEQ.L #0,D0
  285. MOVE.W #(380/2)-1,D7
  286. OBJ_MAP_SET_1:
  287. MOVE.L D0,(A0)+
  288. DBRA D7,OBJ_MAP_SET_1
  289. MOVE.B #80H,ORDER_BUFFER(A5)
  290. MOVE.B #80H,ORDER_BUFFER+128(A5)
  291. SUBQ.B #1,MESS_BUSY(A5)
  292. SUBQ.B #1,LSPC_BUSY(A5)
  293. RTS
  294. ;
  295. ;
  296. ; *** calucurate ***
  297. ;
  298. ;
  299. RAND16:
  300. ; get 16bit random number (non sequencial)
  301. ; out) D0(.w) 16bit random number
  302. ; all register keep
  303. MOVE.L A0,-(SP)
  304. MOVEQ.L #0,D0
  305. ADDQ.B #2,READ_RANDOM(A5)
  306. MOVE.B READ_RANDOM(A5),D0
  307. LEA.L RANDOM_BUFFER(A5),A0
  308. MOVE.W 0(A0,D0.W),D0
  309. MOVE.L (SP)+,A0
  310. RTS
  311. RAND8:
  312. ; get 8bit random number (sequencial)
  313. ; out) D0(.b) 8bit random number
  314. ; all register keep
  315. MOVE.L A0,-(SP)
  316. MOVEQ.L #0,D0
  317. ADDQ.B #1,RANDOM_SEED(A5)
  318. MOVE.B RANDOM_SEED(A5),D0
  319. LEA.L RND_DATA,A0
  320. MOVE.B 0(A0,D0.W),D0
  321. MOVE.L (SP)+,A0
  322. RTS
  323. ; *** sin & cos ***
  324. ; D0(.w)=D0*sin(D1.b),D0*cos(D1.b)
  325. ; 2pi=256
  326. ; use) D0(hi.w),D1(.w),A0
  327. COS:
  328. SUB.B #64,D1 cos(x)=sin(x+pi/2)
  329. SIN:
  330. AND.W #0FFH,D1
  331. NEG.B D1
  332. BPL.S SIN_1
  333. NEG.W D0
  334. SIN_1:
  335. ADD.W D1,D1
  336. LEA.L SIN_DATA,A0
  337. MOVE.W 0(A0,D1.W),D1
  338. CMPI.W #1,D1 sin(D1)=1 ?
  339. BEQ.W SIN_2
  340. TST.W D0
  341. BMI.S SIN_3
  342. MULU.W D1,D0
  343. SWAP D0
  344. SIN_2:
  345. RTS
  346. SIN_3:
  347. NEG.W D0
  348. MULU.W D1,D0
  349. SWAP D0
  350. NEG.W D0
  351. RTS
  352. ; D0(.l)=D0*sin(D1.b),D0*cos(D1.b)
  353. ; 2pi=256
  354. ; use) D1(.w),D2(.l),A0
  355. COS_L:
  356. SUB.B #64,D1 cos(x)=sin(x+pi/2)
  357. SIN_L:
  358. AND.W #0FFH,D1
  359. NEG.B D1
  360. BPL.S SIN_L_1
  361. NEG.L D0
  362. SIN_L_1:
  363. ADD.W D1,D1
  364. LEA.L SIN_DATA,A0
  365. MOVE.W 0(A0,D1.W),D1
  366. CMPI.W #1,D1
  367. BEQ.W SIN_L_2
  368. JSR MUL32(PC)
  369. SIN_L_2:
  370. RTS
  371. MUL32:
  372. ; D0(.l)=D0(.l)*{D1(.w)/10000H}
  373. ; use) D2(.l)
  374. TST.L D0
  375. BMI.S MUL32_NEG
  376. MOVE.W D0,D2
  377. MULU.W D1,D2
  378. CLR.W D2
  379. SWAP D2
  380. SWAP D0
  381. MULU.W D1,D0
  382. ADD.L D2,D0
  383. RTS
  384. MUL32_NEG:
  385. NEG.L D0
  386. MOVE.W D0,D2
  387. MULU.W D1,D2
  388. CLR.W D2
  389. SWAP D2
  390. SWAP D0
  391. MULU.W D1,D0
  392. ADD.L D2,D0
  393. NEG.L D0
  394. RTS
  395. SEC_TIME:
  396. ; second move timer decrement
  397. ; in) A0 timer address
  398. ; out) CS:time out
  399. SUBQ.B #1,1(A0)
  400. BGT.S SEC_TIME_1
  401. MOVE.B SECOND_VALUE(A5),1(A0)
  402. SUBQ.B #1,(A0)
  403. SEC_TIME_1:
  404. RTS
  405. SEC_TIME_BCD:
  406. ; second move BCD timer decrement
  407. ; in) A0 timer address
  408. ; use) D0,D1
  409. SUBQ.B #1,1(A0)
  410. BGT.S SEC_TIME_BCD_1
  411. MOVE.B SECOND_VALUE(A5),1(A0)
  412. SUB.B D0,D0
  413. MOVE.B (A0),D0
  414. MOVE.B #1,D1
  415. SBCD.B D1,D0
  416. MOVE.B D0,(A0)
  417. SEC_TIME_BCD_1:
  418. RTS
  419. ;
  420. ; *** ect. ***
  421. ;
  422. PLAYABLE:
  423. ; check play OK ?
  424. ; out) D0 d0:player 1 d1:player 2
  425. ; 0=can't play
  426. ; 1=play OK
  427. ; all register keep
  428. MOVEM.L D1-D7/A0-A6,-(SP)
  429. MOVE.L #1000000H,CREDIT_DEC(A5)
  430. JSR CREDIT_CHECK
  431. MOVEQ.L #0,D0
  432. TST.B CREDIT_DEC
  433. BEQ.S PLAYABLE_1
  434. MOVEQ.L #1,D0
  435. PLAYABLE_1:
  436. MOVE.W D0,-(SP)
  437. MOVE.W #1,CREDIT_DEC
  438. JSR CREDIT_CHECK
  439. MOVE.W (SP)+,D0
  440. MOVEM.L (SP)+,D1-D7/A0-A6
  441. TST.B CREDIT_DEC+1(A5)
  442. BEQ.S PLAYABLE_2
  443. ADDQ.B #2,D0
  444. PLAYABLE_2:
  445. CLR.L CREDIT_DEC(A5)
  446. RTS
  447. BIT_FLAG_CLEAR:
  448. ; BIT_FLAGK all clear
  449. ; use) D0-D7(.l)=0
  450. ; A0
  451. LEA.L BIT_FLAG+100H(A5),A0
  452. MOVEQ.L #0,D0
  453. MOVE.L D0,D1
  454. MOVE.L D0,D2
  455. MOVE.L D0,D3
  456. MOVE.L D0,D4
  457. MOVE.L D0,D5
  458. MOVE.L D0,D6
  459. MOVE.L D0,D7
  460. REPT 8
  461. MOVEM.L D0-D7,-(A0)
  462. ENDR
  463. RTS
  464. BYTE_FLAG_CLEAR:
  465. ; BYTE_FLAGK all clear
  466. ; use) D0-D7(.l)=0
  467. ; A0
  468. LEA.L BYTE_FLAG+100H(A5),A0
  469. MOVEQ.L #0,D0
  470. MOVE.L D0,D1
  471. MOVE.L D0,D2
  472. MOVE.L D0,D3
  473. MOVE.L D0,D4
  474. MOVE.L D0,D5
  475. MOVE.L D0,D6
  476. MOVE.L D0,D7
  477. REPT 8
  478. MOVEM.L D0-D7,-(A0)
  479. ENDR
  480. RTS
  481. INCLUDE WORK.INC
  482.