Advertisement
Guest User

crt0.s for Jaguar

a guest
Jan 24th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.06 KB | None | 0 0
  1. | Jaguar support code
  2. | by Chilly Willy
  3.  
  4. #include <jaguar.h>
  5.  
  6. | First equates control the bitmap size and depth, and screen mode
  7.  
  8. .equ BMP_WIDTH, 320 /* Width in Pixels */
  9. .equ BMP_HEIGHT, 224 /* Height in Pixels */
  10. .equ BMP_DEPTH, O_DEPTH16 /* Depth of Bitmap */
  11. .equ PPP, 4 /* Pixels per Phrase (16-bit) */
  12. .equ SCR_MODE, RGB16 /* Video Mode (CRY16, RGB16, or RGB24) */
  13. .equ PIX_WIDTH, PWIDTH4 /* Pixel width of video mode */
  14. .equ PIX_SHIFT, 2 /* 2^PIX_SHIFT == PIX_WIDTH */
  15.  
  16. .equ BMP_PHRASES, (BMP_WIDTH/PPP) /* Width in Phrases */
  17. .equ BMP_LINES, (BMP_HEIGHT*2) /* Height in Half Scanlines */
  18. .equ BITMAP_OFF, (2*8) /* Two Phrases */
  19. .equ LISTSIZE, 5 /* List length (in phrases) */
  20.  
  21. .text
  22.  
  23. | Jaguar startup at 0x2000 (CART) or 0x4000 (BJL)
  24.  
  25. .global _start
  26. _start:
  27. move #0x2700,sr /* disable interrupts */
  28. move.l #0x70007,G_END /* big-endian mode */
  29. move.l #0x70007,D_END
  30. move.w #0xFFFF,VI /* disable video interrupts */
  31.  
  32. | Clear BSS
  33. lea __bss_start,a0
  34. lea __bss_end,a1
  35. moveq #0,d0
  36. 1:
  37. move.l d0,(a0)+
  38. cmpa.l a0,a1
  39. bhi.b 1b
  40.  
  41. .ifdef CART_BUILD
  42.  
  43. | Copy code and initialized variables from ROM to RAM
  44.  
  45. lea _code_start(pc),a0
  46. lea _code_start,a1
  47. move.l #__code_size+__data_size,d0
  48. lsr.l #2,d0
  49. 2:
  50. move.l (a0)+,(a1)+
  51. subq.l #1,d0
  52. bne.b 2b
  53. jmp _code_start
  54.  
  55. .align 2
  56. _code_start:
  57.  
  58. .endif
  59.  
  60. lea INITSTACK,a0
  61. movea.l a0,sp /* set stack pointer to top of main DRAM */
  62. link.w a6,#-8 /* set up initial stack frame */
  63.  
  64. jsr init_hardware /* initialize the console hardware */
  65.  
  66. jsr __INIT_SECTION__ /* do all program initializers */
  67. jsr main /* call program main() */
  68. jsr __FINI_SECTION__ /* do all program finishers */
  69.  
  70. jmp _start+0x800000
  71.  
  72. | Procedure: InitVBint
  73. | Install our vertical blank handler and enable interrupts
  74.  
  75. InitVBint:
  76. move.l #UpdateList,LEVEL0 /* Install 68K LEVEL0 handler */
  77.  
  78. move.w a_vde,d0 /* Must be ODD */
  79. ori.w #1,d0
  80. move.w d0,VI
  81.  
  82. move.w #C_VIDENA,INT1 /* Enable video interrupts */
  83.  
  84. move.w sr,d0
  85. andi.w #0xF8FF,d0 /* Lower 68k IPL to allow */
  86. move.w d0,sr /* interrupts */
  87. rts
  88.  
  89. | Procedure: InitVideo (same as in vidinit.s)
  90. | Build values for hdb, hde, vdb, and vde and store them.
  91.  
  92. InitVideo:
  93. move.w CONFIG,d0 /* Also is joystick register */
  94. andi.w #VIDTYPE,d0 /* 0 = PAL, 1 = NTSC */
  95. beq.b palvals
  96.  
  97. move.w #NTSC_HMID,d2
  98. move.w #NTSC_WIDTH,d0
  99.  
  100. move.w #NTSC_VMID,d6
  101. move.w #NTSC_HEIGHT,d4
  102.  
  103. bra.b calc_vals
  104. palvals:
  105. move.w #PAL_HMID,d2
  106. move.w #PAL_WIDTH,d0
  107.  
  108. move.w #PAL_VMID,d6
  109. move.w #PAL_HEIGHT,d4
  110.  
  111. calc_vals:
  112. move.w d0,width
  113. move.w d4,height
  114.  
  115. move.w d0,d1
  116. asr.w #1,d1 /* Width/2 */
  117.  
  118. sub.w d1,d2 /* Mid - Width/2 */
  119. addq.w #4,d2 /* (Mid - Width/2)+4 */
  120.  
  121. subq.w #1,d1 /* Width/2 - 1 */
  122. ori.w #0x0400,d1 /* (Width/2 - 1)|0x400 */
  123.  
  124. move.w d1,a_hde
  125. move.w d1,HDE
  126.  
  127. move.w d2,a_hdb
  128. move.w d2,HDB1
  129. move.w d2,HDB2
  130.  
  131. move.w d6,d5
  132. sub.w d4,d5
  133.  
  134. move.w d5,a_vdb
  135.  
  136. add.w d4,d6
  137. move.w d6,a_vde
  138. move.w a_vdb,VDB
  139. move.w #0xFFFF,VDE
  140.  
  141. move.l #0,BORD1 /* Black border */
  142. move.w #0,BG /* Init line buffer to black */
  143. rts
  144.  
  145. | InitLister: Initialize Object List Processor List
  146.  
  147. InitLister:
  148. lea listbuf,a0
  149. move.l a0,d2 /* Copy */
  150.  
  151. addi.l #(LISTSIZE-1)*8,d2 /* Address of STOP object */
  152. move.l d2,d3 /* Copy for low half */
  153.  
  154. lsr.l #8,d2 /* Shift high half into place */
  155. lsr.l #3,d2
  156.  
  157. swap d3 /* Place low half correctly */
  158. clr.w d3
  159. lsl.l #5,d3
  160.  
  161. | Write first BRANCH object (branch if YPOS > a_vde )
  162.  
  163. clr.l d0
  164. move.l #(BRANCHOBJ|O_BRLT),d1 /* 0x4000 = VC < YPOS */
  165. or.l d2,d0 /* Do LINK overlay */
  166. or.l d3,d1
  167.  
  168. move.w a_vde,d4 /* for YPOS */
  169. lsl.w #3,d4 /* Make it bits 13-3 */
  170. or.w d4,d1
  171.  
  172. move.l d0,(a0)+
  173. move.l d1,(a0)+
  174.  
  175. | Write second branch object (branch if YPOS < a_vdb)
  176. | Note: LINK address is the same so preserve it
  177.  
  178. andi.l #0xFF000007,d1 /* Mask off CC and YPOS */
  179. ori.l #O_BRGT,d1 /* 0x8000 = VC > YPOS */
  180. move.w a_vdb,d4 /* for YPOS */
  181. lsl.w #3,d4 /* Make it bits 13-3 */
  182. or.w d4,d1
  183.  
  184. move.l d0,(a0)+
  185. move.l d1,(a0)+
  186.  
  187. | Write a standard BITMAP object
  188.  
  189. move.l d2,d0
  190. move.l d3,d1
  191.  
  192. ori.l #BMP_HEIGHT<<14,d1 /* Height of image */
  193.  
  194. move.w height,d4 /* Center bitmap vertically */
  195. sub.w #BMP_HEIGHT,d4
  196. add.w a_vdb,d4
  197. andi.w #0xFFFE,d4 /* Must be even */
  198. lsl.w #3,d4
  199. or.w d4,d1 /* Stuff YPOS in low phrase */
  200.  
  201. move.l #_vidmem,d4
  202. lsl.l #8,d4
  203. or.l d4,d0
  204. move.l d0,(a0)+
  205. move.l d1,(a0)+
  206. movem.l d0-d1,bmp1update
  207.  
  208. move.l #_vidmem+(BMP_PHRASES*BMP_HEIGHT*8*2),d4
  209. lsl.l #8,d4
  210. or.l d4,d0
  211. movem.l d0-d1,bmp2update
  212.  
  213. | Second Phrase of Bitmap
  214.  
  215. move.l #BMP_PHRASES>>4,d0 /* Only part of top LONG is IWIDTH */
  216. move.l #BMP_DEPTH|O_NOGAP,d1 /* Bit Depth, Contiguous data */
  217.  
  218. move.w width,d4 /* Get width in clocks */
  219. lsr.w #PIX_SHIFT,d4 /* Pixel Divisor */
  220. sub.w #BMP_WIDTH,d4
  221. lsr.w #1,d4 /* horz offset */
  222. or.w d4,d1
  223.  
  224. ori.l #(BMP_PHRASES<<18)|(BMP_PHRASES<<28),d1 /* DWIDTH|IWIDTH */
  225.  
  226. move.l d0,(a0)+
  227. move.l d1,(a0)+
  228.  
  229. | Write a STOP object at end of list
  230.  
  231. clr.l (a0)+
  232. move.l #(STOPOBJ|O_STOPINTS),(a0)+
  233. rts
  234.  
  235. | Procedure: UpdateList
  236. | Handle Video Interrupt and update object list fields
  237. | destroyed by the object processor.
  238.  
  239. UpdateList:
  240. move.l a0,-(sp)
  241.  
  242. move.l #listbuf+BITMAP_OFF,a0
  243.  
  244. tst.b frame+1
  245. bne.b 0f /* second bitmap */
  246.  
  247. move.l bmp1update,(a0) /* phrase = d1.l/d0.l */
  248. move.l bmp1update+4,4(a0)
  249. bra.b 1f
  250. 0:
  251. move.l bmp2update,(a0) /* phrase = d1.l/d0.l */
  252. move.l bmp2update+4,4(a0)
  253. 1:
  254. move.b frame+1,frame /* update bitmap frame selected */
  255. addq.l #1,ticks /* increment ticks */
  256.  
  257. move.w #0x0101,INT1 /* signal we're done */
  258. move.w #0x0000,INT2
  259.  
  260. move.l (sp)+,a0
  261. rte
  262.  
  263. init_hardware:
  264. clr.l ticks
  265. clr.w frame
  266.  
  267. jsr InitVideo /* setup our video registers */
  268. jsr InitLister /* initialize Object Display List */
  269. jsr InitVBint /* initialize our VBLANK routine */
  270.  
  271. | sneaky trick to cause display to popup at first VB
  272.  
  273. move.l #0x0,listbuf+BITMAP_OFF
  274. move.l #0xC,listbuf+BITMAP_OFF+4
  275.  
  276. move.l #listbuf,OLP /* setting with 68000 may be dangerous */
  277.  
  278. move.w #(PIX_WIDTH|BGEN|CSYNC|SCR_MODE|VIDEN),VMODE /* configure Video */
  279. rts
  280.  
  281.  
  282. .bss
  283. .balign 16
  284.  
  285. .comm listbuf, LISTSIZE*8 /* Object List (in phrases) */
  286. .comm bmp1update, 8 /* One Phrase of First Bitmap for Refresh */
  287. .comm bmp2update, 8 /* One Phrase of Second Bitmap for Refresh */
  288. .comm ticks, 4 /* Incrementing # of ticks */
  289. .comm a_hdb, 2
  290. .comm a_hde, 2
  291. .comm a_vdb, 2
  292. .comm a_vde, 2
  293. .comm width, 2
  294. .comm height, 2
  295. .comm frame, 2 /* Bitmap selector: MSB = current frame, LSB = frame to select next VBI */
  296.  
  297.  
  298. .balign 4
  299.  
  300. .comm __stack_save, 4
  301.  
  302. .balign 16
  303.  
  304. .comm _vidmem, (BMP_PHRASES*BMP_HEIGHT*8*2)
  305.  
  306.  
  307. .text
  308.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement