Conway's Game of Life - 3D 68000er Assembler-Code für 8x8x8 Game of Life.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gol3d.s 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. ; Game of life
  2. ; 3D
  3. ; implements a 3d-game of life
  4. ; with 3d graphics output
  5. ; and output on the serial interface
  6. ; game of life parameters
  7. ; 2**sizexp border length in x,y,z
  8. sizexp equ 3
  9. ; no need to change below here
  10. size equ (1<<sizexp)
  11. sizesq equ size*size
  12. sizecube equ sizesq*size
  13. sizex equ (size+2)
  14. sizexsq equ sizex*sizex
  15. sizexcube equ sizexsq*sizex
  16. .TEXT
  17. ; free unused memory
  18. movea.l 4(sp),a0
  19. lea stack,sp
  20. move.l #$100,d0
  21. add.l $c(a0),d0
  22. add.l $14(a0),d0
  23. add.l $1c(a0),d0
  24. move.l d0,-(sp)
  25. move.l a0,-(sp)
  26. clr.w -(sp)
  27. move.w #$4a,-(sp)
  28. trap #1
  29. lea $c(sp),sp
  30. ; save resolution and physical screen address
  31. bsr getrez
  32. move.w d0,saverez
  33. cmpi.w #2,d0
  34. blt.s colorscreen
  35. bra exitbw
  36. colorscreen:
  37. bsr getscreen
  38. move.l d0,screen1
  39. ; crucial:
  40. ; we assume that the physical screen address is - as is default - top of ram minus 32000 bytes, i.e. at $78000
  41. ; in the following, there might be calculations done in .w, which rely on the
  42. ; fact that there is no overflow to the next word
  43. ; if the initial screen address is "wrong", everything might blow up
  44. ; switch to low resolution with physical screen -$8000 as logical screen address
  45. ; again, we count on no word overflow
  46. move.w #0,d0
  47. movea.l screen1,a0
  48. movea.l a0,a1
  49. suba.l #$8000,a1
  50. move.l a1,screen2
  51. bsr setrez
  52. bsr waitvbi
  53. bsr hide_mse
  54. pea save_palette_sup
  55. move.w #$26,-(sp)
  56. trap #14
  57. addq.l #6,sp
  58. ; movem.l $ffff8240,d0-d7
  59. ; lea stdpalette,a0
  60. ; movem.l d0-d7,(a0)
  61. bsr palette_set
  62. ; prepare point coordinates
  63. move.w my_npts,d7
  64. ; beq exit
  65. move.w d7,oncoords
  66. move.w d7,npts
  67. beq prepare_coords
  68. subq.w #1,d7
  69. move.w d7,d0
  70. lea my_ptscolour,a2
  71. lea col_lst,a3
  72. ptloop0:
  73. move.w (a2)+,(a3)+
  74. dbra d0,ptloop0
  75. lea ocoordsx,a1
  76. lea my_ptsx,a0
  77. lea ocoordsy,a3
  78. lea my_ptsy,a2
  79. lea ocoordsz,a5
  80. lea my_ptsz,a4
  81. ptloop1:
  82. move.w (a0)+,(a1)+
  83. move.w (a2)+,(a3)+
  84. move.w (a4)+,(a5)+
  85. dbra d7,ptloop1
  86. ; prepare coordinates
  87. prepare_coords:
  88. move.w my_npoly,d7
  89. beq exit
  90. move.w d7,npoly
  91. subq.w #1,d7
  92. lea my_nedges,a0
  93. lea snedges,a1
  94. lea my_colour,a2
  95. lea col_lst,a3
  96. ; append to the points color list
  97. move.w npts,d0
  98. add.w d0,d0
  99. lea 0(a3,d0.w),a3
  100. move.w d7,d0
  101. loop0:
  102. move.w (a0)+,(a1)+
  103. move.w (a2)+,(a3)+
  104. dbra d0,loop0
  105. move.w d7,d0
  106. lea my_nedges,a6
  107. clr.w d1
  108. clr.w d2
  109. loop1:
  110. add.w (a6),d1
  111. add.w (a6)+,d2
  112. addq.w #1,d2
  113. dbra d0,loop1
  114. subq.w #1,d2
  115. lea my_edglst,a0
  116. lea sedglst,a1
  117. move.w npts,d0
  118. loop2:
  119. ; move.w (a0)+,(a1)+
  120. ; offset by number of points...
  121. move.w (a0)+,(a1)
  122. add.w d0,(a1)+
  123. dbra d2,loop2
  124. ; methinks this is only correct for polygons, not for (non-closed) polylines or single points...
  125. ; move.w d1,oncoords
  126. ; subq.w #1,d1
  127. ; so, we use the number provided in my_nocoords
  128. move.w my_nocoords,d1
  129. ; move.w d1,oncoords
  130. ; append to the points...
  131. add.w d1,oncoords
  132. subq.w #1,d1
  133. lea ocoordsx,a1
  134. lea my_datax,a0
  135. lea ocoordsy,a3
  136. lea my_datay,a2
  137. lea ocoordsz,a5
  138. lea my_dataz,a4
  139. ; append to points
  140. move.w npts,d0
  141. add.w d0,d0
  142. lea 0(a1,d0.w),a1
  143. lea 0(a3,d0.w),a3
  144. lea 0(a5,d0.w),a5
  145. loop3:
  146. move.w (a0)+,(a1)+
  147. move.w (a2)+,(a3)+
  148. move.w (a4)+,(a5)+
  149. dbra d1,loop3
  150. move.w my_xmin,xmin
  151. move.w my_xmax,xmax
  152. move.w my_ymin,ymin
  153. move.w my_ymax,ymax
  154. ; move.w #200,Oox
  155. ; move.w #200,Ooz
  156. ; clr.w Ooy
  157. ; cube center
  158. move.w #250,Oox
  159. clr.w Ooy
  160. move.w #300,Ooz
  161. clr.w otheta
  162. ; move.w #50,ophi
  163. clr.w ophi
  164. clr.w ogamma
  165. movea.l screen1,a0
  166. bsr clearscreen
  167. movea.l screen2,a0
  168. bsr clearscreen
  169. jsr main
  170. exit:
  171. move.w saverez,d0
  172. movea.l screen1,a0
  173. movea.l screen1,a1
  174. bsr setrez
  175. ; bsr palette_reset
  176. ; restore palette
  177. ; movem.l stdpalette,d0-d7
  178. ; movem.l d0-d7,$ffff8240
  179. pea restore_palette_sup
  180. move.w #$26,-(sp)
  181. trap #14
  182. addq.l #6,sp
  183. bsr waitvbi
  184. exitbw:
  185. clr.w -(sp)
  186. trap #1
  187. ; move.w #0,-(sp)
  188. ; move.w #$4c,-(sp)
  189. ; trap #1
  190. save_palette_sup:
  191. movem.l $ffff8240,d0-d7
  192. lea stdpalette,a0
  193. movem.l d0-d7,(a0)
  194. rts
  195. restore_palette_sup:
  196. movem.l stdpalette,d0-d7
  197. movem.l d0-d7,$ffff8240
  198. rts
  199. scan_keys:
  200. move.w #2,-(sp)
  201. move.w #1,-(sp)
  202. trap #13
  203. addq.l #4,sp
  204. rts
  205. read_key:
  206. move.w #2,-(sp)
  207. move.w #2,-(sp)
  208. trap #13
  209. addq.l #4,sp
  210. rts
  211. hide_mse:
  212. .DC.w $a000
  213. .DC.w $a00a
  214. rts
  215. getrez:
  216. move.w #4,-(sp)
  217. trap #14
  218. addq.l #2,sp
  219. rts
  220. setrez:
  221. move.w d0,-(sp)
  222. move.l a0,-(sp)
  223. move.l a1,-(sp)
  224. move.w #5,-(sp)
  225. trap #14
  226. lea $c(sp),sp
  227. rts
  228. getscreen:
  229. move.w #2,-(sp)
  230. trap #14
  231. addq.l #2,sp
  232. rts
  233. waitvbi:
  234. move.w #37,-(sp)
  235. trap #14
  236. addq.l #2,sp
  237. rts
  238. ; clear the screen - address in a0
  239. ; destroys d0-d7, a1-a6
  240. clearscreen:
  241. adda.l #32000,a0
  242. ; move.w #614,d7
  243. moveq.l #0,d0
  244. move.l d0,d1
  245. move.l d1,d2
  246. move.l d2,d3
  247. move.l d3,d4
  248. move.l d4,d5
  249. move.l d5,d6
  250. move.l d6,d7
  251. movea.l d7,a1
  252. movea.l a1,a2
  253. movea.l a2,a3
  254. movea.l a3,a4
  255. movea.l a4,a5
  256. movea.l a5,a6
  257. ;clrloop:
  258. ; 571 * 56 bytes = 31976
  259. .REPT 571
  260. movem.l d0-d7/a1-a6,-(a0)
  261. .ENDR
  262. ; the missing 24 bytes
  263. movem.l d0-d5,-(a0)
  264. ; dbf d7,clrloop
  265. rts
  266. clearboard:
  267. lea board,a0
  268. move.w #sizecube,d1
  269. lsr.w #2,d1
  270. subq.w #1,d1
  271. cbloop:
  272. clr.l (a0)+
  273. dbra d1,cbloop
  274. rts
  275. initboard:
  276. bsr clearboard
  277. lea board,a0
  278. move.w #(size*sizesq/2)+(sizesq/2)+(size/2),d0 ; pattern "I"
  279. move.b #1,0(a0,d0.w)
  280. addi.w #sizesq,d0
  281. move.b #1,-1(a0,d0.w)
  282. move.b #1,1(a0,d0.w)
  283. move.b #1,size(a0,d0.w)
  284. move.b #1,-size(a0,d0.w)
  285. addi.w #sizesq,d0
  286. move.b #1,1(a0,d0.w)
  287. move.b #1,-1(a0,d0.w)
  288. rts
  289. initboardglider:
  290. bsr clearboard
  291. lea board,a0
  292. move.w #((size/2)*sizesq-1)+2*size+size/4,d0
  293. move.b #1,2(a0,d0.w)
  294. move.b #1,3(a0,d0.w)
  295. move.b #1,2+size(a0,d0.w)
  296. move.b #1,size+3(a0,d0.w)
  297. addi.w #sizesq,d0
  298. move.b #1,1(a0,d0.w)
  299. move.b #1,4(a0,d0.w)
  300. move.b #1,1+size(a0,d0.w)
  301. move.b #1,4+size(a0,d0.w)
  302. addi.w #sizesq+size,d0
  303. move.b #1,2(a0,d0.w)
  304. move.b #1,3(a0,d0.w)
  305. rts
  306. initboardrnd:
  307. lea board,a6
  308. move.l #sizecube-1,d3
  309. initbloop:
  310. clr.l d0
  311. clr.b d6
  312. move.w #$11,-(sp)
  313. trap #14
  314. addq.l #2,sp
  315. ; andi.l #$00ffffff,d0
  316. ; 24 bit random number in d0
  317. ; check if bit 16 (arbitrary) is set
  318. btst.l #16,d0
  319. beq initbcont
  320. move.b #1,d6
  321. initbcont:
  322. move.b d6,(a6)+
  323. dbra d3,initbloop
  324. rts
  325. clearneighbours:
  326. lea neighbours,a0
  327. move.w #sizexcube,d1
  328. lsr.w #2,d1 ; not bytes but longwords
  329. subq.w #1,d1
  330. cnloop:
  331. clr.l (a0)+
  332. dbra d1,cnloop
  333. rts
  334. countneighbours:
  335. clr.w d4
  336. clr.w d5
  337. ; clr.w d6
  338. move.l #sizecube-1,d1
  339. lea board,a0
  340. lea neighbours,a1
  341. ; move the pointer to start of board
  342. lea sizexsq+sizex+1(a1),a1
  343. countnloop:
  344. move.b (a0)+,d0
  345. beq countn0
  346. add.b d0,-1(a1)
  347. add.b d0,1(a1)
  348. add.b d0,-1-sizex(a1)
  349. add.b d0,-sizex(a1)
  350. add.b d0,1-sizex(a1)
  351. add.b d0,-1+sizex(a1)
  352. add.b d0,sizex(a1)
  353. add.b d0,1+sizex(a1)
  354. add.b d0,-sizexsq-sizex-1(a1)
  355. add.b d0,-sizexsq-sizex(a1)
  356. add.b d0,-sizexsq-sizex+1(a1)
  357. add.b d0,-sizexsq-1(a1)
  358. add.b d0,-sizexsq(a1)
  359. add.b d0,-sizexsq+1(a1)
  360. add.b d0,-sizexsq+sizex-1(a1)
  361. add.b d0,-sizexsq+sizex(a1)
  362. add.b d0,-sizexsq+sizex+1(a1)
  363. add.b d0,sizexsq-sizex-1(a1)
  364. add.b d0,sizexsq-sizex(a1)
  365. add.b d0,sizexsq-sizex+1(a1)
  366. add.b d0,sizexsq-1(a1)
  367. add.b d0,sizexsq(a1)
  368. add.b d0,sizexsq+1(a1)
  369. add.b d0,sizexsq+sizex-1(a1)
  370. add.b d0,sizexsq+sizex(a1)
  371. add.b d0,sizexsq+sizex+1(a1)
  372. countn0:
  373. addq.l #1,a1
  374. addq.w #1,d4
  375. cmpi.w #size,d4
  376. blt countncont
  377. clr.w d4
  378. addq.l #2,a1 ; skip border pixels
  379. addq.w #1,d5
  380. cmpi.w #size,d5
  381. blt countncont
  382. clr.w d5
  383. lea 2*sizex(a1),a1
  384. ; adda.l #2*sizex,a1 ; skip border lines
  385. ; addq.w #1,d6
  386. countncont:
  387. dbra d1,countnloop
  388. rts
  389. modulus:
  390. clr.l d0
  391. clr.l d1
  392. clr.l d2
  393. ; wrap the neighbours around
  394. ; very first plane -> last regular plane
  395. lea neighbours,a0
  396. movea.l a0,a1
  397. adda.l #sizexcube-sizexsq-sizexsq,a1
  398. ; the following may be too large
  399. ; lea sizexcube-sizexsq-sizexsq(a1),a1
  400. move.w #sizexsq-1,d0
  401. modulus0:
  402. move.b (a0)+,d1
  403. add.b d1,(a1)+
  404. dbra d0,modulus0
  405. ; very last plane -> first regular plane
  406. ; a1 is at very last plane, a0 at first regular
  407. move.w #sizexsq-1,d0
  408. modulus1:
  409. move.b (a1)+,d1
  410. add.b d1,(a0)+
  411. dbra d0,modulus1
  412. ; now we handle the regular planes, top row wraps around to last regular row
  413. lea neighbours+sizexsq,a0
  414. lea sizexsq-sizex-sizex(a0),a1
  415. move.w #size-1,d2
  416. modulus2:
  417. move.w #sizex-1,d0
  418. modulus3:
  419. move.b (a0)+,d1
  420. add.b d1,(a1)+
  421. dbra d0,modulus3
  422. lea sizexsq-sizex(a0),a0
  423. lea sizexsq-sizex(a1),a1
  424. dbra d2,modulus2
  425. ; bottom row wraps around to first regular row
  426. lea neighbours+sizexsq+sizex,a1
  427. lea sizexsq-sizex-sizex(a1),a0
  428. move.w #size-1,d2
  429. modulus4:
  430. move.w #sizex-1,d0
  431. modulus5:
  432. move.b (a0)+,d1
  433. add.b d1,(a1)+
  434. dbra d0,modulus5
  435. lea sizexsq-sizex(a0),a0
  436. lea sizexsq-sizex(a1),a1
  437. dbra d2,modulus4
  438. ; very first column wraps around to last regular column
  439. ; (only consider regular rows now)
  440. lea neighbours+sizexsq+sizex,a0
  441. lea neighbours+sizexsq+sizex+sizex-2,a1
  442. move.w #size-1,d2
  443. modulus6:
  444. move.w #size-1,d0
  445. modulus7:
  446. move.b (a0),d1
  447. add.b d1,(a1)
  448. adda.l #sizex,a0
  449. adda.l #sizex,a1
  450. dbra d0,modulus7
  451. lea 2*sizex(a0),a0
  452. lea 2*sizex(a1),a1
  453. dbra d2,modulus6
  454. ; very last column wraps around to first regular column
  455. ; (only consider regular rows now)
  456. lea neighbours+sizexsq+sizex+1,a1
  457. lea neighbours+sizexsq+sizex+sizex-1,a1
  458. move.w #size-1,d2
  459. modulus8:
  460. move.w #size-1,d0
  461. modulus9:
  462. move.b (a0),d1
  463. add.b d1,(a1)
  464. adda.l #sizex,a0
  465. adda.l #sizex,a1
  466. dbra d0,modulus9
  467. lea 2*sizex(a0),a0
  468. lea 2*sizex(a1),a1
  469. dbra d2,modulus8
  470. ; still TODO: handle the 8 corners correctly!
  471. rts
  472. setboard:
  473. movem.l d7,-(sp)
  474. clr.w d0
  475. clr.w d1
  476. ; move.w #0,d0 ; x coordinate
  477. ; move.w #0,d1 ; y coordinate
  478. ; move.b Fl,d5
  479. ; move.b Fu,d6
  480. ; movea.b El,a2
  481. ; movea.b Eu,a3
  482. lea board,a5
  483. lea neighbours,a6
  484. lea sizexsq+sizex+1(a6),a6 ; move to beginning of board data
  485. move.l #sizecube-1,d7
  486. setbloop:
  487. move.b (a6)+,d4
  488. move.b (a5),d3
  489. tst.b d3
  490. bne wasfull
  491. wasempty:
  492. ; check vs fertility rate
  493. cmp.b Fl,d4 ; Fl
  494. blt.s contsb
  495. cmp.b Fu,d4 ; Fu
  496. bgt.s contsb
  497. ; a new cell is born
  498. move.b #1,d3
  499. bra.s contsb
  500. wasfull:
  501. ; check vs extinction rate
  502. move.b #0,d3
  503. cmp.b El,d4 ; El
  504. blt.s contsb
  505. cmp.b Eu,d4 ; Eu
  506. bgt.s contsb
  507. ; the cell lives on
  508. move.b #1,d3
  509. contsb:
  510. move.b d3,(a5)+
  511. addq.w #1,d0
  512. cmpi.w #size,d0
  513. blt.s contsb0
  514. clr.w d0
  515. addq.l #2,a6 ; skip border
  516. addq.w #1,d1
  517. cmpi.w #size,d1
  518. blt.s contsb0
  519. clr.w d1
  520. lea 2*sizex(a6),a6
  521. contsb0:
  522. dbra d7,setbloop
  523. movem.l (sp)+,d7
  524. rts
  525. allzero:
  526. clr.b d1
  527. move.w #sizecube,d0
  528. lsr.w #2,d0 ; not bytes, but longwords
  529. subq.w #1,d0
  530. lea board,a0
  531. allzloop:
  532. tst.l (a0)+
  533. bne nonzero
  534. dbra d0,allzloop
  535. rts
  536. nonzero:
  537. move.b #1,d1
  538. rts
  539. initser:
  540. ; init serial interface
  541. ; read current ucr setting
  542. move.w #-1,-(sp) ; scr
  543. move.w #-1,-(sp) ; tsr
  544. move.w #-1,-(sp) ; rsr
  545. move.w #-1,-(sp) ; ucr
  546. move.w #-1,-(sp) ; flow
  547. move.w #-1,-(sp) ; speed
  548. move.w #$f,-(sp)
  549. trap #14
  550. lea $e(sp),sp
  551. ; current register values in d0
  552. ; bits 31..24: ucr
  553. ; bits 23..16: rsr
  554. ; bits 15..8: tsr
  555. ; bits 7..0: scr
  556. move.l d0,d1
  557. andi.l #$00ff00ff,d1 ; scr in d1.w rsr in d1(high word)
  558. move.l d0,d2
  559. lsr.l #8,d2
  560. ;andi.l #$00ff00ff,d2 ; tsr in d2.w, ucr in d2(high word)
  561. andi.l #%00000000100000010000000011111111,d2 ; clear some bits
  562. ori.l #%00000000000010000000000000000000,d2 ; set one bit (for 1 stop bit)
  563. move.w d1,-(sp)
  564. move.w d2,-(sp)
  565. swap.w d1
  566. move.w d1,-(sp)
  567. swap.w d2
  568. move.w d2,-(sp)
  569. move.w #0,-(sp)
  570. move.w baudrate,-(sp)
  571. move.w #$f,-(sp)
  572. trap #14
  573. lea $e(sp),sp
  574. ; synchron character - unused
  575. ; move.w #-1,-(sp) ; scr
  576. ; move.w #-1,-(sp) ; tsr
  577. ; move.w #-1,-(sp) ; rsr
  578. ; usart control register 8N1
  579. ; move.w #%0000000000010000,-(sp) ; ucr
  580. ; move.w #%0000000000001000,-(sp) ; ucr
  581. ; move.w #0,-(sp) ; flowctl no
  582. ;; move.w #0,-(sp) ; speed 19200
  583. ;; move.w #1,-(sp) ; speed 9600
  584. ; move.w baudrate,-(sp)
  585. ; move.w #$f,-(sp)
  586. ; trap #14
  587. ; lea $e(sp),sp
  588. rts
  589. sendboard:
  590. move.l #sizecube-1,d5
  591. lea board,a6
  592. move.w #65,-(sp) ; A
  593. move.w #1,-(sp)
  594. move.w #3,-(sp)
  595. trap #13
  596. addq.l #6,sp
  597. clr.w d6
  598. sendbloop:
  599. move.b (a6)+,d6
  600. addi.b #48,d6
  601. move.w d6,-(sp)
  602. move.w #1,-(sp) ; serial port
  603. move.w #3,-(sp)
  604. trap #13
  605. addq.l #6,sp
  606. dbra d5,sendbloop
  607. move.w #69,-(sp) ; E
  608. move.w #1,-(sp)
  609. move.w #3,-(sp)
  610. trap #13
  611. addq.l #6,sp
  612. rts
  613. helptext:
  614. pea helpstr1
  615. move.w #9,-(sp)
  616. trap #1
  617. addq.l #6,sp
  618. rts
  619. palette_set:
  620. pea palette
  621. move.w #6,-(sp)
  622. trap #14
  623. addq.l #6,sp
  624. rts
  625. palette_reset:
  626. pea stdpalette
  627. move.w #6,-(sp)
  628. trap #14
  629. addq.l #6,sp
  630. rts
  631. main:
  632. bsr initser
  633. jsr clearboard
  634. jsr initboardglider
  635. jsr clearneighbours
  636. jsr countneighbours
  637. jsr modulus
  638. jsr setboard
  639. jsr sendboard
  640. move.w #1,screenflag
  641. move.l screen2,screen
  642. jsr mse_rel
  643. jsr init_mse
  644. mainloop:
  645. ; tst.w mse_click
  646. ; beq nomouse
  647. ; move.w #0,mse_click
  648. ; move.w mouse_dx,d0
  649. ; move.w #0,mouse_dx
  650. ; asr.w #3,d0
  651. move.w rotatetheta,d0
  652. add.w d0,otheta
  653. tstthetapos:
  654. tst.w otheta
  655. bge thetapos
  656. addi.w #360,otheta
  657. bra.s tstthetapos
  658. thetapos:
  659. cmpi.w #360,otheta
  660. blt.s thetaok
  661. subi.w #360,otheta
  662. bra.s thetapos
  663. thetaok:
  664. ; move.w mouse_dy,d0
  665. ; move.w #0,mouse_dy
  666. ; asr.w #3,d0
  667. move.w rotategamma,d0
  668. add.w d0,ogamma
  669. tstgammapos:
  670. tst.w ogamma
  671. bge gammapos
  672. addi.w #360,ogamma
  673. bra.s tstgammapos
  674. gammapos:
  675. cmpi.w #360,ogamma
  676. blt.s gammaok
  677. subi.w #360,ogamma
  678. bra.s gammapos
  679. gammaok:
  680. ; bra angleok
  681. nomouse:
  682. ; subi.w #0,ogamma
  683. ; bge.s angleok
  684. ; gamma: about z axis
  685. ; phi: about y axis
  686. ; theta: about x axis
  687. ; move.w #360,ogamma
  688. angleok:
  689. ; otranw: rotation from occordx,ocoordy,ocoordz to wcoordsx,wcoordsy,wcoordsz
  690. bsr otranw
  691. move.w oncoords,d7
  692. move.w d7,vncoords
  693. subq.w #1,d7
  694. lea wcoordsx,a0
  695. lea wcoordsy,a1
  696. lea wcoordsz,a2
  697. lea vcoordsx,a3
  698. lea vcoordsy,a4
  699. lea vcoordsz,a5
  700. loop6:
  701. move.w (a0)+,(a3)+
  702. move.w (a1)+,(a4)+
  703. move.w (a2)+,(a5)+
  704. dbra d7,loop6
  705. bsr perspective
  706. ; bsr polywire
  707. ; bsr read_key
  708. ;mainloop:
  709. addq.w #1,computecounter
  710. move.w computedelay,d1
  711. cmp.w computecounter,d1
  712. bge draw_poly
  713. clr.w computecounter
  714. jsr allzero
  715. tst.b d1
  716. bne maincont
  717. jsr initboardrnd
  718. maincont:
  719. jsr clearneighbours
  720. jsr countneighbours
  721. jsr modulus
  722. jsr setboard
  723. jsr sendboard
  724. draw_poly:
  725. move.w npts,d0
  726. subq.w #1,d0
  727. lea board,a2
  728. lea col_lst,a3
  729. clr.w d1
  730. colloop:
  731. move.b (a2)+,d1
  732. move.w d1,(a3)+
  733. dbra d0,colloop
  734. bsr polywire
  735. bsr polypoints
  736. ; clr.l d7
  737. ; move.w #360-1,d7
  738. ;lines:
  739. ; movem.l d7,-(sp)
  740. ; move.w #160,d0
  741. ; move.w #100,d1
  742. ;; move.w #10,d2
  743. ; move.w d7,d2
  744. ; lsr.w #1,d2
  745. ; addi.w #10,d2
  746. ; move.w #10,d3
  747. ; movea.l screen,a0
  748. ; adda.w plane,a0
  749. ;; adda.l #2,a0
  750. ; bsr line
  751. ;
  752. ; movem.l (sp)+,d7
  753. ; movem.l d7,-(sp)
  754. ;
  755. ; move.w #160,d2
  756. ; move.w #100,d3
  757. ;; move.w #10,d2
  758. ; move.w d7,d0
  759. ; lsr.w #2,d0
  760. ; addi.w #10,d0
  761. ; move.w #190,d1
  762. ; movea.l screen,a0
  763. ; adda.w plane,a0
  764. ;; adda.l #2,a0
  765. ; bsr line
  766. ;
  767. ; movem.l (sp)+,d7
  768. ; movem.l d7,-(sp)
  769. ;
  770. ; move.w #160,d0
  771. ; move.w #100,d1
  772. ; move.w #10,d2
  773. ; move.w d7,d3
  774. ; lsr.w #1,d3
  775. ; addi.w #10,d3
  776. ; movea.l screen,a0
  777. ; adda.w plane,a0
  778. ;; adda.l #2,a0
  779. ; bsr line
  780. ;
  781. ; movem.l (sp)+,d7
  782. ; movem.l d7,-(sp)
  783. ;
  784. ; move.w #160,d0
  785. ; move.w #100,d1
  786. ; move.w #300,d2
  787. ; move.w d7,d3
  788. ; lsr.w #1,d3
  789. ; addi.w #10,d3
  790. ; movea.l screen,a0
  791. ; adda.w plane,a0
  792. ;; adda.l #2,a0
  793. ; bsr line
  794. ;
  795. ; move.w #5,d0
  796. ; move.w #5,d1
  797. ; move.w #316,d2
  798. ;;;move.w d7,d3
  799. ;;;lsr.w #2,d3
  800. ; move.w #5,d3
  801. ; movea.l screen,a0
  802. ; adda.w plane,a0
  803. ;;; adda.l #2,a0
  804. ; bsr line
  805. ;
  806. ; move.w #5,d0
  807. ; move.w #196,d1
  808. ; move.w #316,d2
  809. ;;;move.w d7,d3
  810. ;;;lsr.w #2,d3
  811. ; move.w #196,d3
  812. ; movea.l screen,a0
  813. ; adda.w plane,a0
  814. ;;; adda.l #2,a0
  815. ; bsr line
  816. ;
  817. ; movem.l (sp)+,d7
  818. ; dbra d7,lines
  819. tst.w screenflag
  820. beq.s switch2
  821. move.w #0,screenflag
  822. movea.l screen2,a0
  823. movea.l screen1,a1
  824. move.l a1,screen
  825. move.w #-1,d0
  826. bsr setrez
  827. move.w #37,-(sp)
  828. trap #14
  829. addq.l #2,sp
  830. movea.l screen1,a0
  831. bsr clearscreen
  832. bra.s switch
  833. switch2:
  834. move.w #1,screenflag
  835. movea.l screen1,a0
  836. movea.l screen2,a1
  837. move.l a1,screen
  838. move.w #-1,d0
  839. bsr setrez
  840. move.w #37,-(sp)
  841. trap #14
  842. addq.l #2,sp
  843. movea.l screen2,a0
  844. bsr clearscreen
  845. switch:
  846. ; wait for vbi
  847. ; move.w #37,-(sp)
  848. ; trap #14
  849. ; addq.l #2,sp
  850. addq.w #2,plane
  851. andi.w #7,plane
  852. bsr scan_keys
  853. tst.w d0
  854. beq mainloop
  855. bsr read_key
  856. swap.w d0
  857. cmpi.b #$39,d0 ; space
  858. bne keytst0
  859. clr.w ophi
  860. clr.w otheta
  861. clr.w ogamma
  862. bra mainloop
  863. keytst0:
  864. cmpi.b #$1,d0 ; esc
  865. beq keyexit
  866. cmpi.b #$13,d0 ; r
  867. bne keytst1
  868. jsr initboardrnd
  869. move.w #0,computecounter
  870. bra mainloop
  871. keytst1:
  872. cmpi.b #$23,d0 ; h
  873. bne keytst1a
  874. bra.s showhlp
  875. keytst1a:
  876. cmpi.b #$62,d0 ; help
  877. bne keytst2
  878. showhlp:
  879. movea.l screen1,a0
  880. bsr clearscreen
  881. movea.l screen2,a0
  882. bsr clearscreen
  883. bsr helptext
  884. tst.w screenflag
  885. beq.s switchhlp2
  886. move.w #0,screenflag
  887. movea.l screen2,a0
  888. movea.l screen1,a1
  889. move.l a1,screen
  890. move.w #-1,d0
  891. bsr setrez
  892. move.w #37,-(sp)
  893. trap #14
  894. addq.l #2,sp
  895. movea.l screen1,a0
  896. bsr clearscreen
  897. bra.s switchhlp
  898. switchhlp2:
  899. move.w #1,screenflag
  900. movea.l screen1,a0
  901. movea.l screen2,a1
  902. move.l a1,screen
  903. move.w #-1,d0
  904. bsr setrez
  905. move.w #37,-(sp)
  906. trap #14
  907. addq.l #2,sp
  908. movea.l screen2,a0
  909. bsr clearscreen
  910. switchhlp:
  911. bsr read_key
  912. bra mainloop
  913. keytst2:
  914. cmpi.b #$05,d0 ; 4
  915. bne.s keytst3
  916. ; use 4555
  917. move.b #4,El
  918. move.b #5,Eu
  919. move.b #5,Fl
  920. move.b #5,Fu
  921. jsr initboardrnd
  922. move.w #0,computecounter
  923. bra mainloop
  924. keytst3:
  925. cmpi.b #$06,d0 ; 5
  926. bne.s keytst4
  927. ; use 5766
  928. move.b #5,El
  929. move.b #7,Eu
  930. move.b #6,Fl
  931. move.b #6,Fu
  932. jsr initboardrnd
  933. move.w #0,computecounter
  934. bra mainloop
  935. keytst4:
  936. cmpi.b #$22,d0 ; g
  937. bne.s keytst5
  938. move.b #4,El ; glider requires rule 4555
  939. move.b #5,Eu
  940. move.b #5,Fl
  941. move.b #5,Fu
  942. jsr initboardglider
  943. move.w #0,computecounter
  944. bra mainloop
  945. keytst5:
  946. cmpi.b #$30,d0 ; b
  947. bne.s keytst6
  948. move.w #1,d0
  949. sub.w baudrate,d0
  950. move.w d0,baudrate
  951. bsr initser
  952. bra mainloop
  953. keytst6:
  954. cmpi.b #$4d,d0 ; right arrow
  955. bne.s keytst7
  956. cmpi.w #10,rotatetheta
  957. bge mainloop
  958. addq.w #1,rotatetheta
  959. bra mainloop
  960. keytst7:
  961. cmpi.b #$4b,d0 ; left
  962. bne.s keytst8
  963. cmpi.w #-10,rotatetheta
  964. ble mainloop
  965. subq.w #1,rotatetheta
  966. bra mainloop
  967. keytst8:
  968. cmpi.b #$48,d0 ; up
  969. bne.s keytst9
  970. cmpi.w #10,rotategamma
  971. bge mainloop
  972. addq.w #1,rotategamma
  973. bra mainloop
  974. keytst9:
  975. cmpi.b #$50,d0 ; down
  976. bne.s keytst10
  977. cmpi.w #-10,rotategamma
  978. ble mainloop
  979. subq.w #1,rotategamma
  980. bra mainloop
  981. keytst10:
  982. cmpi.b #$18,d0 ; O
  983. bne.s keytst11
  984. clr.w rotategamma
  985. clr.w rotatetheta
  986. bra mainloop
  987. keytst11:
  988. cmpi.b #$4e,d0 ; +
  989. bne.s keytst12
  990. cmpi.w #1,computedelay
  991. ble mainloop
  992. subq.w #1,computedelay
  993. bra mainloop
  994. keytst12:
  995. cmpi.b #$4a,d0 ; -
  996. bne.s keytst13
  997. cmpi.w #10,computedelay
  998. bgt mainloop
  999. addq.w #1,computedelay
  1000. bra mainloop
  1001. keytst13:
  1002. bra mainloop
  1003. keyexit:
  1004. jsr mse_term
  1005. ; bsr read_key
  1006. rts
  1007. .INCLUDE 'SYSTM_03.IS'
  1008. .INCLUDE 'CORE_03.IS'
  1009. .INCLUDE 'POLYZOOM.IS'
  1010. .DATA
  1011. palette:
  1012. .DC.w $0777,$0000,$0700,$0300,$0000,$0000,$0000,$0000
  1013. .DC.w $0070,$0030,$0330,$0330,$0000,$0000,$0000,$0000
  1014. stdpalette:
  1015. .DC.w $0777,$0700,$0070,$0770,$0007,$0707,$0077,$0555
  1016. .DC.w $0333,$0733,$0373,$0773,$0337,$0737,$0377,$0000
  1017. rotatetheta: .DC.w 0
  1018. rotategamma: .DC.w 0
  1019. computedelay: .DC.w 3
  1020. ; expiry lower and upper
  1021. ;El equ 4
  1022. ;Eu equ 5
  1023. ; fertility lower and upper
  1024. ;Fl equ 5
  1025. ;Fu equ 5
  1026. ; best choices:
  1027. ; 4555 or 5766 for El Eu Fl Fu
  1028. El: .DC.b 4
  1029. Eu: .DC.b 5
  1030. Fl: .DC.b 5
  1031. Fu: .DC.b 5
  1032. helpstr1:
  1033. .DC.b 27,"b",1
  1034. ; .DC.b 27,"c",0
  1035. ; .DC.b 27,"p"
  1036. .DC.b 27,"E"
  1037. .DC.b "Conway's Game of Life - 3D"
  1038. .DC.b 27,"B",27,"l",27,"D"
  1039. .DC.b "=========================="
  1040. .DC.b 27,"B",27,"l",27,"D"
  1041. .DC.b " "
  1042. .DC.b 27,"B",27,"l",27,"D"
  1043. .DC.b "r: reset board (random)"
  1044. .DC.b 27,"B",27,"l",27,"D"
  1045. .DC.b "g: reset board (4555 glider)"
  1046. .DC.b 27,"B",27,"l",27,"D"
  1047. .DC.b " "
  1048. .DC.b 27,"B",27,"l",27,"D"
  1049. .DC.b "Keypad +: increase speed"
  1050. .DC.b 27,"B",27,"l",27,"D"
  1051. .DC.b "Keypad -: decrease speed"
  1052. .DC.b 27,"B",27,"l",27,"D"
  1053. .DC.b " "
  1054. .DC.b 27,"B",27,"l",27,"D"
  1055. .DC.b "SPACE: reset view"
  1056. .DC.b 27,"B",27,"l",27,"D"
  1057. .DC.b "ARROW KEYS: rotate view"
  1058. .DC.b 27,"B",27,"l",27,"D"
  1059. .DC.b "o: stop rotation"
  1060. .DC.b 27,"B",27,"l",27,"D"
  1061. .DC.b " "
  1062. .DC.b 27,"B",27,"l",27,"D"
  1063. .DC.b "b: toggle baud rate"
  1064. .DC.b 27,"B",27,"l",27,"D"
  1065. .DC.b " "
  1066. .DC.b 27,"B",27,"l",27,"D"
  1067. .DC.b "4: switch to rule 4555 (El,Eu,Fl,Fu)"
  1068. .DC.b 27,"B",27,"l",27,"D"
  1069. .DC.b "5: switch to rule 5766 (El,Eu,Fl,Fu)"
  1070. .DC.b 27,"B",27,"l",27,"D"
  1071. .DC.b " "
  1072. .DC.b 27,"B",27,"l",27,"D"
  1073. .DC.b "ESC: exit"
  1074. .DC.b 27,"Y",24+32,3+32
  1075. .DC.b "68000 assembler code by tecer 2017"
  1076. ; .DC.b 27,"q"
  1077. .DC.b 0
  1078. .EVEN
  1079. plane: .DC.w 0
  1080. computecounter: .DC.w 0
  1081. baudrate: .DC.w 0
  1082. .INCLUDE 'DATA_01.IS'
  1083. .INCLUDE 'DATA_03.IS'
  1084. .BSS
  1085. board:
  1086. .DS.b sizecube
  1087. ; extended neighbours (1 pixel buffer everywhere)
  1088. neighbours:
  1089. .DS.b sizexcube
  1090. saverez: .DS.w 1
  1091. screen1: .DS.l 1
  1092. screen2: .DS.l 1
  1093. screen: .DS.l 1
  1094. screenflag: .DS.w 1
  1095. xbuf: .DS.l 400
  1096. hln_tbl: .DS.w 256
  1097. otheta: .DS.w 1
  1098. ophi: .DS.w 1
  1099. ogamma: .DS.w 1
  1100. ocoordsx: .DS.w 2048
  1101. ocoordsy: .DS.w 2048
  1102. ocoordsz: .DS.w 2048
  1103. oncoords: .DS.w 1
  1104. Oox: .DS.w 1
  1105. Ooy: .DS.w 1
  1106. Ooz: .DS.w 1
  1107. wcoordsx: .DS.w 2048
  1108. wcoordsy: .DS.w 2048
  1109. wcoordsz: .DS.w 2048
  1110. o_wmatx: .DS.w 9
  1111. stheta: .DS.w 1
  1112. ctheta: .DS.w 1
  1113. sphi: .DS.w 1
  1114. cphi: .DS.w 1
  1115. sgamma: .DS.w 1
  1116. cgamma: .DS.w 1
  1117. crds_in: .DS.w 2048
  1118. crds_out: .DS.w 2048
  1119. no_in: .DS.w 1
  1120. no_out: .DS.w 1
  1121. colour: .DS.w 1
  1122. xmax: .DS.w 1
  1123. xmin: .DS.w 1
  1124. ymin: .DS.w 1
  1125. ymax: .DS.w 1
  1126. scoordsx: .DS.w 2048
  1127. scoordsy: .DS.w 2048
  1128. sedglst: .DS.w 2048
  1129. snedges: .DS.w 1024
  1130. npoly: .DS.w 1
  1131. col_lst: .DS.w 1024
  1132. vcoordsx: .DS.w 2048
  1133. vcoordsy: .DS.w 2048
  1134. vcoordsz: .DS.w 2048
  1135. vncoords: .DS.w 1
  1136. npts: .DS.w 1
  1137. .DS.l 1000
  1138. stack:
  1139. .DS.l 2
  1140. .END