ASM_LIB.a 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. ; extern void __asm AsmRenderMaze(register __a0 long *,register __a1 long *);
  2. ; extern void __asm AsmClearBackground(register __a0 long *,register __d0 long,register __d1 long);
  3. ; extern void __asm AsmChunky2Planar(register __a0 long *,register __a1 long *);
  4. XDEF _AsmRenderMaze
  5. XDEF _AsmClearBackground
  6. XDEF _AsmChunky2Planar
  7. section AsmGfxRoutines,code
  8. ; ------------------ G L O B A L D E F I N E S ------------------
  9. DISPLAY_DEPTH equ 4 ; These define the physical display
  10. DISPLAY_WIDTH equ 320
  11. DISPLAY_HEIGHT equ 200
  12. ; These define the maze viewing area
  13. VIEW_WIDTH equ 128 ; size in pixels of wolf maze view (must be divisible by 8)
  14. VIEW_HEIGHT equ 64 ; size in rows of wolf maze view
  15. VIEW_LEFT equ 100 ; Column with in the framebuffer where the wolf view starts
  16. VIEW_TOP equ 68 ; First row to draw into
  17. VIEW_RIGHT equ ((VIEW_WIDTH+VIEW_LEFT)-1)
  18. VIEW_BOTTOM equ ((VIEW_HEIGHT+VIEW_TOP)-1)
  19. VIEW_CENTER_ROW equ ((VIEW_HEIGHT)/2)
  20. VIEW_CENTER_COL equ ((VIEW_LEFT+VIEW_RIGHT)/2)
  21. PlaneSize equ (DISPLAY_WIDTH*DISPLAY_HEIGHT)/8 ;
  22. BufferSize equ (DISPLAY_WIDTH*DISPLAY_HEIGHT) ;
  23. VIEW_MIDDLE equ (DISPLAY_WIDTH*(VIEW_HEIGHT/2))
  24. ;--------------------------------------------------------------------
  25. ;AsmChunky2Planar
  26. ;
  27. ;FUNCTION:
  28. ; Convert a chunky graphics bitmap into 4 planar bitmap planes
  29. ;
  30. ;PARAMETERS:
  31. ; a0 -> chunky pixel buffer
  32. ; a1 -> plane0 (assume other 3 planes are allocated contiguously)
  33. ;
  34. ;RETURNS:
  35. ; none
  36. ;
  37. ;NOTE:
  38. ; This is a modified version of the c2p routine: peterm/chunky4.s
  39. ; by Peter McGavin (peterm@ker
  40. ;--------------------------------------------------------------------
  41. ; ------------------------ D E F I N E S --------------------------
  42. buffer equr a0
  43. plane0 equr a1
  44. plane1 equr a2
  45. plane2 equr a3
  46. plane3 equr a4
  47. count equr d0
  48. const1 equr d5
  49. const2 equr d6
  50. ; ---------------------------- M A I N ----------------------------
  51. ; adda.l #(VIEW_TOP*DISPLAY_WIDTH),buffer
  52. ; adda.l #((DISPLAY_WIDTH/8)*VIEW_TOP),plane0
  53. Psize equ (DISPLAY_WIDTH*VIEW_HEIGHT)/8
  54. _AsmChunky2Planar:
  55. movem.l d2-d6/a2-a4,-(sp)
  56. adda.l #(VIEW_TOP*DISPLAY_WIDTH),buffer
  57. adda.l #((DISPLAY_WIDTH/8)*VIEW_TOP),plane0
  58. moveq #0,d0
  59. move.l #$55555555,const1 ; d6 = constant $55555555
  60. move.l #$3333cccc,const2 ; d5 = constant $3333cccc
  61. move.w #PlaneSize,d0
  62. movea.l plane0,plane1
  63. adda.l d0,plane1
  64. movea.l plane1,plane2
  65. adda.l d0,plane2
  66. movea.l plane2,plane3
  67. adda.l d0,plane3
  68. move.w #Psize,count ; Working on 4 planes at a time
  69. ; processes 8 chunky pixels at a time
  70. C2Pmain move.l (a0)+,d2 ; 12 get next 4 chunky pixels in d0
  71. move.l (a0)+,d3 ; 12 get next 4 chunky pixels in d1
  72. lsl.l #4,d2 ; 16
  73. or.l d3,d2 ; 8
  74. move.l d2,d3 ; 4
  75. and.l const2,d3 ; 8
  76. move.w d3,d1 ; 4
  77. clr.w d3 ; 4
  78. lsl.l #2,d3 ; 12
  79. lsr.w #2,d1 ; 10
  80. or.w d1,d3 ; 4
  81. swap d2 ; 4
  82. and.l const2,d2 ; 8
  83. or.l d2,d3 ; 8
  84. move.l d3,d2 ; 4
  85. lsr.l #7,d2 ; 22
  86. move.l d3,d1 ; 4
  87. and.l const1,d1 ; 8
  88. eor.l d1,d3 ; 8
  89. move.l d2,d4 ; 4
  90. and.l const1,d4 ; 8
  91. eor.l d4,d2 ; 8
  92. or.l d4,d3 ; 8
  93. lsr.l #1,d3 ; 10
  94. or.l d1,d2 ; 8 inner loop thus far is 220
  95. move.b d3,(plane3)+ ; Write 8 pixels to the 4 bitplanes
  96. swap d3
  97. move.b d3,(plane1)+
  98. move.b d2,(plane2)+
  99. swap d2
  100. move.b d2,(plane0)+
  101. subq.w #1,count ; check if end of buffer is reached
  102. bne.b C2Pmain ; no continue as usual
  103. FINC2P: movem.l (sp)+,d2-d6/a2-a4
  104. rts
  105. ;--------------------------------------------------------------------
  106. ;--------------------------------------------------------------------
  107. ;--------------------------------------------------------------------
  108. ;AsmClearBackground
  109. ;
  110. ;FUNCTION:
  111. ; Clears the upper and lower region of the wolf background
  112. ; with two colours. The upper region's colour is found in d0,
  113. ; and the lower region's colour is found in d1.
  114. ;
  115. ;PARAMETERS:
  116. ; a0 -> chunky pixel buffer
  117. ; d0 -> colour 1
  118. ; d1 -> colour 2
  119. ;
  120. ;RETURNS:
  121. ; none
  122. ;
  123. ;NOTE:
  124. ; this routine requires the view area to be longword aligned
  125. ; and for the width to be evenly divisible by 4
  126. ;--------------------------------------------------------------------
  127. ; ------------------------- D E F I N E S -------------------------
  128. CLR_ADDROFFSET equ ((VIEW_TOP*DISPLAY_WIDTH)+VIEW_LEFT)
  129. CLR_HALFSIZE equ (((VIEW_WIDTH*VIEW_HEIGHT)/8)/(VIEW_WIDTH/4))
  130. ; ---------------------------- M A I N ----------------------------
  131. _AsmClearBackground
  132. movem.l d2-d3/a0-a1,-(sp)
  133. moveq #0,d2
  134. adda.l #CLR_ADDROFFSET,a0
  135. movea.l a0,a1
  136. ; PASS 1 - clear the upper region
  137. CLR_PASS1: ; with the colours found in D0
  138. move.l #CLR_HALFSIZE-1,d3
  139. ClearTop:
  140. move.w #VIEW_WIDTH/4-1,d2 ; Used for clearing a single row
  141. ClearRow1:
  142. move.l d0,(a0)+
  143. dbra d2,ClearRow1
  144. adda.w #DISPLAY_WIDTH,a1
  145. movea.l a1,a0
  146. dbra d3,ClearTop
  147. ; PASS 2 - clear the lower region
  148. CLR_PASS2: ; with the colours found in D0
  149. move.l #CLR_HALFSIZE-1,d3
  150. ClearBottom:
  151. move.w #VIEW_WIDTH/4-1,d2 ; Used for clearing a single row
  152. ClearRow2:
  153. move.l d1,(a0)+
  154. dbra d2,ClearRow2
  155. adda.w #DISPLAY_WIDTH,a1
  156. movea.l a1,a0
  157. dbra d3,ClearBottom
  158. CLRFIN: movem.l (sp)+,d2-d3/a0-a1
  159. rts
  160. ;--------------------------------------------------------------------
  161. ;--------------------------------------------------------------------
  162. ;--------------------------------------------------------------------
  163. ;AsmRenderMaze
  164. ;
  165. ;FUNCTION:
  166. ; Render the visible maze walls into the frame buffer.
  167. ;
  168. ;PARAMETERS:
  169. ; a0 -> &xBUFFER[VIEW_LEFT]
  170. ; a1 -> frame buffer
  171. ;
  172. ;RETURNS:
  173. ; none
  174. ;
  175. ;--------------------------------------------------------------------
  176. ; ------------------------- D E F I N E S -------------------------
  177. half_fBUFF EQU VIEW_MIDDLE ; BufferSize/2
  178. X EQUR d0
  179. yinc EQUR d1
  180. yrinc equr d2
  181. HC EQUR d3
  182. temp1 EQUR d4
  183. endY EQUR d5
  184. errY EQUR d6
  185. VIEWR EQUR d7
  186. xBUFF EQUR a0
  187. fBUFF EQUR a1
  188. fBUFF2 equr a2
  189. LHC EQUR a3
  190. BMP EQUR a4
  191. LBMP EQUR a5
  192. wall1 EQUR a3
  193. wall2 EQUR a5
  194. VIEWC EQUR a6
  195. ;+-------+ +-------+
  196. ;|walls | ---\ |Create |
  197. ;|doors | ----| |xBuffer|
  198. ;|objects| ---/ | |
  199. ;+-------+ +-------+
  200. ; ---------------------------- M A I N ----------------------------
  201. _AsmRenderMaze:
  202. INIT: movem.l d2-d7/a2-a6,-(sp)
  203. move.l #VIEW_LEFT,X
  204. move.l X,LHC
  205. move.l X,LBMP
  206. move.l #DISPLAY_WIDTH,VIEWR
  207. move.l #VIEW_TOP,d3
  208. muls.w VIEWR,d3
  209. adda.l d3,fBUFF
  210. movea.l #VIEW_CENTER_ROW,VIEWC
  211. ; -----------------------------------------------------------
  212. xLoop: move.l (xBUFF)+,HC ; Fetch height, column from xBUFFER
  213. movea.l (xBUFF)+,BMP ; Fetch bitmap from xBUFFER
  214. cmp.l LHC,HC ; Is Height = LastHeight & Column = LastColumn?
  215. bne.b ScaleColumn ; No
  216. cmp.l LBMP,BMP ; Is Bitmap = LastBitmap?
  217. bne.b ScaleColumn ; No
  218. ; -------------------------------
  219. CopyColumn:
  220. move.l fBUFF,-(sp) ; make a backup of fBUFF
  221. adda.l X,fBUFF ; startY = fBUFF = X
  222. adda.l #half_fBUFF,fBUFF
  223. move.l fBUFF,fBUFF2
  224. cmp.w VIEWC,HC ; Is height > ViewCenterY+1?
  225. ble.b copySmall ; no
  226. ; -------------------------------
  227. copyBig:
  228. move.l VIEWC,temp1
  229. bra.b PreCpy
  230. copySmall:
  231. move.l HC,temp1
  232. PreCpy: subq.l #1,temp1
  233. COPY: suba.l VIEWR,fBUFF2
  234. move.b -1(fBUFF),(fBUFF)
  235. adda.l VIEWR,fBUFF
  236. move.b -1(fBUFF2),(fBUFF2)
  237. dbra temp1,COPY
  238. EndCpy: move.l (sp)+,fBUFF ; restore fBUFF
  239. bra.b NextX
  240. ; -------------------------------
  241. ScaleColumn:
  242. ; if any future unexplained problems occur, try checking for HC > 0
  243. tst.w HC ; Empty column?
  244. beq.b NextX ; Yup, skip this column
  245. move.l fBUFF,-(sp)
  246. adda.l X,fBUFF ; startY = fBUFF = X
  247. add.l #half_fBUFF,fBUFF
  248. movea.l fBUFF,fBUFF2
  249. move.l HC,temp1 ; Initialize the wall bitmap ptrs
  250. swap temp1
  251. ext.l temp1 ; temp1 = column
  252. lsl.w #6,temp1 ; temp1 = column * 64
  253. move.l BMP,wall1
  254. adda.l temp1,wall1 ; bitmap+column*64
  255. lea 31(wall1),wall1
  256. move.l wall1,wall2 ; wall2 = bitmap+column*64+63-scrY
  257. addq.l #1,wall1 ; wall1 = bitmap+column*64+scrY
  258. moveq #32,yrinc ; do scaling division
  259. moveq #0,yinc
  260. cmp.w yrinc,HC
  261. bgt.b SetErr
  262. DoDiv: divs.w HC,yrinc ;
  263. move.w yrinc,yinc ; yinc = 32 / height
  264. swap yrinc ; yrinc = 32 % height
  265. SetErr: move.w HC,errY ; errY = -height
  266. neg.w errY
  267. cmp.w VIEWC,HC ; Is height > ViewCenterY+1 ?
  268. ble.b scaleSmall ; no
  269. scaleBig:
  270. move.l VIEWC,endY
  271. bra.b MoreScaleInit
  272. ; -------------------------------
  273. NextX: addq.w #1,X
  274. cmp.w #VIEW_RIGHT+1,X
  275. bne.b xLoop
  276. FIN: movem.l (sp)+,d2-d7/a2-a6
  277. rts
  278. ; -------------------------------
  279. scaleSmall:
  280. move.l HC,endY
  281. ; -------------------------------
  282. MoreScaleInit:
  283. subq.l #1,endY
  284. tst.w yinc
  285. beq.b SCALE2
  286. ; -------------------------------
  287. SCALE1: suba.l VIEWR,fBUFF2
  288. move.b (wall1),(fBUFF)
  289. adda.l yinc,wall1
  290. move.b (wall2),(fBUFF2)
  291. suba.l yinc,wall2
  292. add.w yrinc,errY
  293. blt.b Check1ScaleFin
  294. sub.w HC,errY
  295. addq.l #1,wall1
  296. subq.l #1,wall2
  297. Check1ScaleFin:
  298. adda.l VIEWR,fBUFF
  299. dbra endY,SCALE1
  300. move.l HC,LHC
  301. move.l BMP,LBMP
  302. move.l (sp)+,fBUFF
  303. bra.b NextX
  304. ; -------------------------------
  305. SCALE2: suba.l VIEWR,fBUFF2
  306. move.b (wall1),(fBUFF)
  307. move.b (wall2),(fBUFF2)
  308. add.w yrinc,errY
  309. blt.b Check2ScaleFin
  310. sub.w HC,errY
  311. addq.l #1,wall1
  312. subq.l #1,wall2
  313. Check2ScaleFin:
  314. adda.l VIEWR,fBUFF
  315. dbra endY,SCALE2
  316. move.l (sp)+,fBUFF
  317. move.l HC,LHC
  318. move.l BMP,LBMP
  319. bra.b NextX
  320. ;--------------------------------------------------------------------
  321. ;--------------------------------------------------------------------
  322. end