***************************************************************************** * * Utility routines for genesis * * ***************************************************************************** include "SEGA.I" include "globals.h" section .bss xdef dmabuf dmabuf ds.w 16 xdef currndnum1 currndnum1 ds.w 1 xdef currndnum2 currndnum2 ds.w 1 xdef j1val, j2val j1val ds.l 1 j2val ds.l 1 section .text *LZW decompressor * input: a3.l = source: compressed data in ROM * a1.l = destination: in RAM/VRAM * xdef Decompress Decompress: movem.l d0-d5/a1-a3,-(sp) move.w (a3)+,d2 moveq #1,d1 .decodeloop subq.w #1,d1 bne.s .skpnewbits move.b (a3)+,d0 moveq #8,d1 .skpnewbits add.b d0,d0 bcs.s .token move.b (a3)+,(a1)+ dbra d2,.decodeloop bra .fini .token move.b (a3)+,d3 bmi.s .lztoken and.w #$007f,d3 addq.w #2,d3 sub.w d3,d2 move.b (a3)+,d4 .fillloop move.b d4,(a1)+ dbra d3,.fillloop dbra d2,.decodeloop bra .fini .lztoken move.b (a3)+,d4 lsl.w #3,d4 move.b d3,d5 lsr.b #4,d5 and.w #7,d5 or.b d5,d4 and.w #$07ff,d4 and.w #$0f,d3 addq.w #2,d3 sub.w d3,d2 move.l a1,a2 suba.w d4,a2 .moveloop move.b (a2)+,(a1)+ dbra d3,.moveloop dbra d2,.decodeloop .fini movem.l (sp)+,d0-d5/a1-a3 rts Z80BusReq equ $A11100 * bit 8 (high=BusReq) Z80Reset equ $A11200 * bit 8 (low=Reset) *********************************************************************************** * _JOYGET6 joystick data get ( six button and three button ) * THIS DRIVER READS BOTH THE SIX AND THREE BUTTON PADS * ID checking and distinguishing between the three button and the * six button controllers is done while driver actually gets data * from the controllers. The above feature will allow the user to * interchange controllers. * If any device that uses a handshaking scheme( eg MOUSE) is plugged * in, the routine returns value 0 in register d0.l Also if nothing is * connected, the driver returns value 0 in register d0.l * In case of three and six button controllers the driver * cannot return value zero in register d0.l * * Access this routine from within the V_INT. * SOJ recomends that the six button driver must be called from * within V_INT. * The Z80 Enable/Disable code is provided as a safety check, to * prevent unfavorable bus access. Also refer to note under mods * * in d1.w : port number ( 0..2 ) * * out d0.l : for case of six pad * d0.l= 1xxx|xxxx|xxxx|xxxx|MD,TX,TY,TZ,1,1,1,1,St,TA,TC,TB,R,L,D,U * for case of three pad * d0.l= 0xxx|xxxx|xxxx|xxxx|xxxx|xxxx|St,TA,TC,TB,R,L,D,U * x denotes don't care bits * flag bit is bit 31 in d0.l * bit 31 = 0 i.e three button controller * bit 31 = 1 i.e six button controller * error (unknown controller/ nothing connected) is reported by * d0.l = 0 * * REGISTERS: * registers d0 to d5 are used by this routine. * register d1 is exclusively used for input to the routine. * register d0 is used for output * * EXECUTION TIME: * six button controller, takes 722 cycles approx 90.25usecs * three button controller, takes 688 cycles approx 86usecs * ************************************************************************************** xdef GetJoy6 GetJoy6 movem.l d1/d2/d3/d4/d5/a0,-(sp) move.w #$100,Z80BusReq * Z80 bus request move.w #$100,Z80Reset * Z80 reset line high (NORMAL RUN STATE) btst.b #0,Z80BusReq * Z80 bus grant acknowledge? bne.s *-8 * wait until bus granted moveq #0,d0 cmp.w #$0002,d1 bhi JOYGET6_ERR add.w d1,d1 move.l #$00a10003,a0 *joystick data port address move.b #$40,6(a0,d1.w) *set TH = output nop nop move.b #$40,(a0,d1.w) * select [ ? 1 TRG-C TRG-B R L D U ] moveq #0,d2 move.b $00(a0,d1.w),d2 * d2 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U cmp.b #$70,d2 * checking for mouse or other handshaking device beq JOYGET6_ERR move.b #$00,(a0,d1.w) * select [ ? 0 START TRG-A 0 0 D U ] lsl.w #8,d2 * d2 = ? 1 TRG-C TRG-B R L D U|0 0 0 0 0 0 0 0 move.b $00(a0,d1.w),d2 * d2 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 D U cmp.b #$3f,d2 * checking for nothing connected beq JOYGET6_ERR move.b #$40,(a0,d1.w) * select [ ? 1 TRG-C TRG-B R L D U ] moveq #0,d3 move.b $00(a0,d1.w),d3 * d3 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U move.b #$00,(a0,d1.w) * select [ ? 0 START TRG-A 0 0 D U ] lsl.w #8,d3 move.b $00(a0,d1.w),d3 *d3 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 D U move.b #$40,(a0,d1.w) * select [ ? 1 TRG-C TRG-B R L D U ] moveq #0,d4 move.b $00(a0,d1.w),d4 * d4 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U move.b #$00,(a0,d1.w) * select [ ? 0 START TRG-A 0 0 0 0 ] lsl.w #8,d4 move.b $00(a0,d1.w),d4 * d4 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 0 0 move.b #$40,(a0,d1.w) * select [ ? 1 0 0 MD TX TY TZ ] moveq #0,d5 move.b $00(a0,d1.w),d5 * d5 = 0000|0000|? 1 0 0 MD TX TY TZ move.b #$00,(a0,d1.w) * select [ ? 0 0 0 1 1 1 1 ] lsl.w #8,d5 move.b $00(a0,d1.w),d5 * d5 = ? 1 0 0 MD TX TY TZ| ? 0 0 0 1 1 1 1 move.b #$40,(a0,d1.w) cmp.w d2,d3 bne JOYGET6_ERR * nothing connected or unknown device cmp.w d3,d4 beq JOYGET3_PAD * regular 3 button controller and.w #$000f,d4 bne JOYGET6_ERR move.b d2,d0 lsl.w #4,d0 * d0.w = 0000|? 0 St TA 0 0 D U 0 0 0 0 lsr.w #8,d2 * d2.w = 0000|0000|? 1 TC TB R L D U move.b d2,d0 * d0.w = 0000|? 0 St TA ? 1 TC TB R L D U lsl.b #2,d0 * d0.w = 0000|? 0 St TA TC TB R L D U 0 0 lsr.w #2,d0 * d0.w = 0000|0 0 ? 0|St TA TC TB R L D U and.l #$000000ff,d0 lsl.b #4,d5 * d5.w = ? 1 0 0 MD TX TY TZ|1 1 1 1 0 0 0 0 lsl.w #4,d5 * d5.w = MD TX TY TZ 1 1 1 1 0 0 0 0 0 0 0 0 or.w d5,d0 * d0.w = MD TX TY TZ 1 1 1 1 St TA TC TB R L D U or.l #$10000000,d0 * d0.l = 1xxx|xxxx|xxxx|xxxx|MD,TX,TY,TZ,St,TA,TC,TB,R,L,D,U bra JOYGET6_ERR JOYGET3_PAD: move.b d2,d0 lsl.w #4,d0 * d0.w = 0000|? 0 St TA 0 0 D U 0 0 0 0 lsr.w #8,d2 * d2.w = 0000|0000|? 1 TC TB R L D U move.b d2,d0 * d0.w = 0000|? 0 St TA ? 1 TC TB R L D U lsl.b #2,d0 * d0.w = 0000|? 0 St TA TC TB R L D U 0 0 lsr.w #2,d0 * d0.w = 0000|0 0 ? 0|St TA TC TB R L D U and.l #$000000ff,d0 * d0.l = 0xxx|xxxx|xxxx|xxxx|xxxx|xxxx|St,TA,TC,TB,R,L,D,U JOYGET6_ERR: move.w #0,Z80BusReq * Z80 bus release movem.l (sp)+,d1/d2/d3/d4/d5/a0 rts xdef putchx *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; *; FUNCTION: putchx - console I/O function! *; DESCRIPTION: Console I/O to the Genesis screen - Assumes that the Genesis *; is in a 40 col mode. *; MAP A will receive the text, the ASCII font shoud have been *; loaded. MAP A should be located at $C000 *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; putchx: move.w texty,D1 lsl.w #6,D1 ; D0=(ScreenRow*64+ScreenCol)*2 add.w textx,D1 ; lsl.w #1,D1 add.w #$c000,D1 ; adjust for address... CalcVramWrtAddrCode D1,D2 move.l D2,VCTRL ; Set vram write address cmp.b #10,D0 ; Is linefeed? bne PC_1 addq.w #1,texty bra PC_3 PC_1: cmp.b #13,D0 ; is a CR? bne PC_2 move.w #0,textx bra PC_3 PC_2: add.w #17,d0 ; Adjust for our character set move.w d0,VDATA ; and set the map addq.w #1,textx PC_3: cmp.w #39,textx ; At last col? bls PC_4 addq.w #1,texty move.w #0,textx ; If so, go to the next row PC_4: cmp.w #26,texty ; At last row? bls PC_5 ; No, go around * * Scroll the screen up here * AutoIncrement 1 ShadowRegister 1,D0 ; Load whatever the prev register value was.. or.b #$10,D0 ; Enable DMA SetVdpRegisterCode 1,D0 SetVdpRegister 19,$00 SetVdpRegister 20,$0D ; Setup DMA length SetVdpRegister 21,$80 SetVdpRegister 22,$C0 ; DMA source address - $c080 SetVdpRegister 23,$C0 ; DMA VRAM copy mode... MOVE.L #$000000C3,VCTRL ;Set DMA destination ** We should be DMA'ing now PC_4A: MOVE.W VCTRL,D0 BTST #1,D0 BNE PC_4A ; Wait for DMA SUBQ.W #1,texty PC_5: rts xdef puts *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; *; FUNCTION: puts - console I/O function! *; DESCRIPTION: print the string on the genesis screen - Assumes that the Genesis *; is in a 40 col mode. *; MAP A will receive the text, the ASCII font shoud have been *; loaded. MAP A should be located at $C000 *; PARAMETERS: *; A0 = address of NULL terminated 'C' string *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; puts moveq.l #0,d0 .1 move.b (a0)+,d0 beq .2 movem.l a0/d0,-(a7) bsr putchx movem.l (a7)+,a0/d0 bra.s .1 .2 rts xdef rnd16 * returns a psuedo-random 16 bit number in d0 rnd16: movem.l d1-d2,-(sp) move.w #$3D6C,d0 move.w currndnum2,d1 or.w d1,d0 bne.s notzip move.w #$1037,d0 mulu d1,d0 bra.s rndfini notzip: move.w currndnum1,d1 mulu d1,d0 move.w d0,d2 move.w #$1037,d0 mulu currndnum2,d0 add.w d2,d0 move.w #$1037,d0 mulu d1,d0 swap d0 add d0,d2 swap d0 rndfini: add.l #$269ec3,d0 move.w d0,currndnum1 swap d0 move.w d0,currndnum2 and.w #$7FFF,d0 movem.l (sp)+,d1-d2 rts ************* * Purpose: Write VRAM with DMA * Input: * A0.L = ptr to source data * D0.W = byte count to move * D1.W = Vram address * Returns: * Uses: ************* xdef dodma dodma: move.l #dmabuf,a1 clr.l d2 move.w d1,d2 ;copy whole amount over! lsl.l #2,d2 ;shift out top two bits! move.w d1,d2 ;move unshifted part over and.w #$3FFF,d2 ;nuke opcode bits! or.w #$4000,d2 ;put a VRAM/Write opcode in DMA_W_Vram1: swap d2 ;put the high low,last first or.w #$0080,d2 ;put a DMA transfer on bit in DMA_W_Vram2: move.l d2,DMA_DstAdr1(a1) move.b d0,DMA_Length1+1(a1) ;Source Length lsr #8,d0 move.b d0,DMA_Length2+1(a1) move.l a0,d0 ;Destination Address lsr.l #1,d0 move.b d0,DMA_SrcAdr1+1(a1) lsr.l #8,d0 move.b d0,DMA_SrcAdr2+1(a1) lsr.w #8,d0 move.b d0,DMA_SrcAdr3+1(a1) move.l #VCTRL,a0 move.w #8,d0 Start_DMA1: move.w (a1)+,(a0) ;Send DMA commands dbra d0,Start_DMA1 move.w (a1)+,(a0) ;Turn DMA off rts xdef DMA_buffer DMA_buffer dc.w $8F02 ;byte increment dc.w $9300 ;Length dc.w $9400 dc.w $9500 ;Source address dc.w $9600 dc.w $9700 dc.w $8174 ;turn DMA on dc.w $0000 ;Destination address dc.w $0000 dc.w $8164 ;turn DMA off dc.w $8F02 ;byte increment dc.w $9300 ;Length dc.w $9400 dc.w $9500 ;Source address dc.w $9600 dc.w $9700 dc.w $8134 ;turn DMA on dc.w $0000 ;Destination address dc.w $0000 dc.w $8164 ;turn DMA off * dma the entire sprite xdef dmasprites dmasprites: move.l #sprites,a0 move.w #320,d0 move.w #spriteaddr,d1 bsr dodma rts * transfer a palette to Color Ram * A0 = ptr to palette * D0 = number of colors to load xdef LoadPal LoadPal: CramWrtAddr $0,VCTRL ; Set CRAM ADDRESS sub.w #1,d0 ldpal: move.w (a0)+,VDATA ; write logo pallette dbra d0,ldpal xdef FillMap ************* * Purpose: Fill Vram rectangle * Input: D1 = start address * D3 = x width * D4 = Y height * D5 = fill char * Returns: * Uses: ************* FillMap: move.w d3,d0 ;One full line! bsr FillMaps add.w #128,d1 ;add in one more row! dbra d4,FillMap rts FillMaps: move.l d1,d2 ;copy whole amount over! lsl.l #2,d2 ;shift out top two bits! move.w d1,d2 ;move unshifted part over and.w #$3FFF,d2 ;nuke opcode bits! or.w #$4000,d2 ;put a VRAM/Write opcode in swap d2 ;put the high low,last first move.l d2,VCTRL ;slamma, jamma, ramma! FillMaps1: move.w d5,VDATA dbra d0,FillMaps1 rts xdef FillVram ************* * Purpose: Fill VRAM w/value * Input: D0.W = Word to fill * D1.w = start VRAM address * D2.w = word count to fill * Returns: * Uses: ************* FillVram: sub.w #1,d2 move.l d1,d3 ;copy whole amount over! lsl.l #2,d3 ;shift out top two bits! move.w d1,d3 ;move unshifted part over and.w #$3FFF,d3 ;nuke opcode bits! or.w #$4000,d3 ;put a VRAM/Write opcode in swap d3 ;put the high low,last first move.l d3,VCTRL ;slamma, jamma, ramma! FillVram1: move.w d0,VDATA dbra d2,FillVram1 rts end