1 ##################################################
4 # --register-prefix-optional --bitwise-or #
6 ##################################################
12 ##################################################
14 # Register and bitmask definitions #
16 ##################################################
18 .equ GFXDATA, 0xc00000
19 .equ GFXCNTL, 0xc00004
22 .equ VDP0_E_DISPLAY, 0x02
23 .equ VDP0_PLTT_FULL, 0x04
25 .equ VDP1_SMS_MODE, 0x80
26 .equ VDP1_E_DISPLAY, 0x40
31 .equ VDP1_RESERVED, 0x04
34 .equ VDP12_SCREEN_V224, 0x00
35 .equ VDP12_SCREEN_V448, 0x04
36 .equ VDP12_PROGRESSIVE, 0x00
37 .equ VDP12_INTERLACED, 0x02
38 .equ VDP12_SCREEN_H256, 0x00
39 .equ VDP12_SCREEN_H320, 0x81
41 .equ VDP16_MAP_V32, 0x00
42 .equ VDP16_MAP_V64, 0x10
43 .equ VDP16_MAP_V128, 0x30
44 .equ VDP16_MAP_H32, 0x00
45 .equ VDP16_MAP_H64, 0x01
46 .equ VDP16_MAP_H128, 0x03
50 ##################################################
54 ##################################################
57 /* Write val to VDP register reg */
58 .macro write_vdp_reg reg val
59 move.w #((\reg << 8) + 0x8000 + \val),(a3)
63 /* For immediate addresses */
64 .macro VRAM_ADDR reg adr
65 move.l #(((0x4000 + (\adr & 0x3fff)) << 16) + (\adr >> 14)),\reg
69 .macro CRAM_ADDR reg adr
70 move.l #(((0xc000 + (\adr & 0x3fff)) << 16) + (\adr >> 14)),\reg
74 # make VDP word from address adr and store in d0
75 .macro XRAM_ADDR_var adr
85 .macro VRAM_ADDR_var adr
91 .macro CRAM_ADDR_var adr
97 .macro VSCROLL_ADDR reg adr
98 move.l #(((0x4000 + (\adr & 0x3fff)) << 16) + ((\adr >> 14) | 0x10)),\reg
102 .macro HSCROLL_ADDR reg adr
103 move.l #(((0x4000 + (\adr & 0x3fff)) << 16) + (\adr >> 14)),\reg
107 # convert tile coords in d0, d1 to nametable addr to a0
116 # check if some d-pad button (and modifier) is pressed
117 .macro do_dpad bit op val
125 #################################################
129 #################################################
132 dc.w 0x0000,0x0eee,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
133 dc.w 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
134 dc.w 0x0000,0x02e2,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
135 dc.w 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
136 dc.w 0x0000,0x0e44,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
137 dc.w 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
142 /* Y size link attr X */
143 dc.w 0; dc.b 0x05; dc.b 0; dc.w 0x6002; dc.w 0
146 ##################################################
150 ##################################################
155 /* mask irqs during init */
163 move.b #0x40,(0xa10009).l
164 move.b #0x40,(0xa10003).l
169 /* Load color data */
172 moveq.l #(colors_end-colors)/2,d0
181 /* generate A layer map */
189 0: move.l #0x00000000,(a0)
195 /* generate B layer map */
200 0: move.l #0x00000000,(a0)
203 /* upload sprite data */
206 movea.l #sprite_data,a1
208 move.l #(sprite_data_end-sprite_data)/2-1,d3
214 ##################################################
218 ##################################################
221 # a6 = page_start[31:8]|cursor_offs[7:0]
222 # d7 = old_inputs[31:16]|byte_mode[15]|g_mode[10:8]|irq_cnt[7:0]
223 # d6 = autorep_cnt[3:0]
235 movem.l d0-d5/a0-a5,-(a7)
241 move.l (jumptab,pc,d0),a0
253 ##################### main #######################
260 move.l d0,a1 /* current addr */
263 add.b #27-1,d1 /* line where the cursor sits */
267 move.l #27-1,d5 /* line counter for dbra */
294 move.l #(' '<<16)|' ',(a0)
314 movea.l #0xe004+64*2*27,a0
325 jsr get_input /* x0cbrldu x1sa00du */
327 btst.l #16+4,d0 /* A - scroll modifier */
330 do_dpad 16+0, sub, #0x0800
331 do_dpad 16+1, add, #0x0800
332 do_dpad 16+10, sub, #0xd800
333 do_dpad 16+11, add, #0xd800
338 neg.b d1 /* 1 if word sel */
341 do_dpad 0, subq, #0x0008
342 do_dpad 1, addq, #0x0008
348 btst.l #12,d0 /* B - switch byte/word mode */
353 sub.l d1,a6 /* make even, just in case */
356 btst.l #13,d0 /* C - edit selected byte */
359 or.w #0x0100,d7 /* switch to edit mode */
360 write_vdp_reg 12,(VDP12_SCREEN_V224 | VDP12_SCREEN_H320 | VDP12_STE)
378 movem.l (a7)+,d0-d5/a0-a5
384 and.l #7,d0 /* byte offs */
386 lsr.b #1,d1 /* which word */
389 add.b d2,d1 /* num of chars to skip */
413 jsr load_prepare /* restore a0 */
418 ##################### edit #######################
424 #################################################
426 # Initialize VDP registers #
428 #################################################
432 write_vdp_reg 0,(VDP0_E_DISPLAY | VDP0_PLTT_FULL)
433 write_vdp_reg 1,(VDP1_E_VBI | VDP1_E_DISPLAY | VDP1_E_DMA | VDP1_RESERVED)
434 write_vdp_reg 2,(0xe000 >> 10) /* Screen map a adress */
435 write_vdp_reg 3,(0xe000 >> 10) /* Window address */
436 write_vdp_reg 4,(0xc000 >> 13) /* Screen map b address */
437 write_vdp_reg 5,(0xfc00 >> 9) /* Sprite address */
439 write_vdp_reg 7,0 /* Backdrop color */
440 write_vdp_reg 10,1 /* Lines per hblank interrupt */
441 write_vdp_reg 11,0 /* 2-cell vertical scrolling */
442 write_vdp_reg 12,(VDP12_SCREEN_V224 | VDP12_SCREEN_H320)
443 write_vdp_reg 13,(0x8000 >> 10) /* Horizontal scroll address */
445 write_vdp_reg 16,(VDP16_MAP_V32 | VDP16_MAP_H64) /* layer size */
447 write_vdp_reg 18,0xff
451 # read single phase from controller
456 move.b #0x40,(0xa10003)
461 move.b #0x00,(0xa10003)
469 eor.w d0,d1 /* changed btns */
470 move.w d0,d7 /* old val */
472 and.w d0,d1 /* what changed now */
477 and.b #7,d2 /* do autorepeat every 8 frames */
488 # Load tile data from ROM
490 # a1: pattern address
491 # d0: number of tiles to load
497 move.l d0,(GFXCNTL).l
509 # Prepare to write to VDP RAM @a3
510 # sets a0 to VDP data port for convenience
516 move.l d0,(GFXCNTL).l
521 # Load color data from ROM
523 # a1: color list address
524 # d0: number of colors to load
530 move.l d0,(GFXCNTL).l
568 # d3 - digit_cnt[0:7]|tile_bits[11:15]
569 # destroys a0, preserves d3
580 ror.l d0,d2 /* prep value */
581 subq.l #1,d1 /* count */
583 and.w #0xf800,d0 /* keep upper bits in d0 */
596 dbra d1,_print_hex_loop
601 #################################################
603 # Wait for next VBlank interrupt #
605 #################################################
616 #################################################
620 #################################################
628 # vim:filetype=asmM68k