Dragonflight_WHDLSlave.asm (12,980 bytes)
2013-05-01 17:57
;*---------------------------------------------------------------------------
; :Program. dragonflight_whdlslave.asm
; :Contents. Slave for "Dragonflight"
; :Author. Dark Angel, Wepl
; :Version. $Id: Dragonflight_WHDLSlave.asm 1.14 2013/05/01 18:54:23 wepl Exp wepl $
; :History. 18.10.01 adpted for whd10+
; fixed for snoop
; disk access (protection?) in pirate town removed
; 22.01.02 support for v3 added
; 23.05.02 rework finished
; 21.06.02 town copylock hopefully final fixed
; 25.06.02 cash limit, disk requesters removed, backup disk removed
; 10.07.02 more diskrequests removed
; cash limit set to 30000
; 01.04.07 support for french version added
; 04.04.07 keyboard fixed
; 01.05.13 modified TT00 french included via wdlt (Denis)
; :Requires. -
; :Copyright. Public Domain
; :Language. 68000 Assembler
; :Translator. Barfly V1.131
; :To Do.
;---------------------------------------------------------------------------*
INCDIR Includes:
INCLUDE whdload.i
INCLUDE whdmacros.i
IFD BARFLY
OUTPUT "wart:dr/dragonflight/DragonFlight.Slave"
BOPT O+ ;enable optimizing
BOPT OG+ ;enable optimizing
BOPT ODd- ;disable mul optimizing
BOPT ODe- ;disable mul optimizing
BOPT w4- ;disable 64k warnings
SUPER
ENDC
;bplcon0 = 4200
;bplmod1/2 = 78
;============================================================================
_base SLAVE_HEADER ;ws_Security + ws_ID
dc.w 13 ;ws_Version
dc.w WHDLF_NoError|WHDLF_EmulTrap ;ws_flags
dc.l $80000 ;ws_BaseMemSize
dc.l 0 ;ws_ExecInstall
dc.w _start-_base ;ws_GameLoader
dc.w dir-_base ;ws_CurrentDir
dc.w 0 ;ws_DontCache
_keydebug dc.b 0 ;ws_keydebug
_keyexit dc.b $5a ;ws_keyexit = NumL
_expmem dc.l $1000 ;ws_ExpMem
dc.w _name-_base ;ws_name
dc.w _copy-_base ;ws_copy
dc.w _info-_base ;ws_info
;============================================================================
IFD BARFLY
DOSCMD "WDate >T:date"
ENDC
_name dc.b "Dragon Flight",0
_copy dc.b "1990 Thalion",0
_info dc.b "installed and fixed by Dark Angel & Wepl",10
dc.b "Version 1.6 "
IFD BARFLY
INCBIN "T:date"
ENDC
dc.b 0
dir dc.b 'DragonflightData',0
boot dc.b 'Boot',0
EVEN
;============================================================================
_start ; A0 = resident loader
;============================================================================
lea whdbase(pc),a1
move.l a0,(a1)
move.l a0,a6
move.l _expmem,a7
add.l #$1000,a7
bsr _cacheon
lea boot(pc),a0
lea $3be4.w,a1
move.l a1,a5 ;a5 = boot
jsr resload_LoadFileDecrunch(a6)
move.l a5,a0
jsr resload_CRC16(a6)
move.l #$726c,d1
move.l #$735a,d2
lea ($1482,a5),a2
lea _pl1,a0
cmp.w #$5b9e,d0 ;german
beq .patch
lea _pl2,a0
cmp.w #$f6e5,d0 ;english
beq .patch
move.l #$3be4+$368c,d1
move.l #$3be4+$377a,d2
lea ($1484,a5),a2
lea _pl3,a0
cmp.w #$e41a,d0 ;german 2
beq .patch
move.l #$3be4+$3666,d1
move.l #$3be4+$3754,d2
lea ($1460,a5),a2
lea _pl4,a0
cmp.w #$736c,d0 ;french
beq .patch
pea TDREASON_WRONGVER
jmp (resload_Abort,a6)
.patch lea _dec1,a1
movem.l d1-d2,(a1)
move.l a5,a1
jsr (resload_Patch,a6)
clr.l -(a7)
pea (a5)
pea WHDLTAG_DBGADR_SET
move.l a7,a0
jsr (resload_Control,a6)
jsr (a2)
bset #6,(-$f9,a6) ; manual protection already done
jmp $400
_pl1234 PL_START
PL_P $292,_retok ;276 requestdisk
PL_PS $2f8,_keyboard
PL_END
_pl12 PL_START
PL_PS $33c0,_f3
PL_PS $3422,_f1
PL_PS $34b8,_f1
PL_PS $34e6,_f2
PL_PS $3508,_f1
PL_PS $3536,_f2
PL_P $3680,_decrunch
PL_P $561e,_savefile
PL_P $57a8,_retok ;298 insert (value -> -$14a)
PL_P $57fc,_retok ;29e backup
PL_P $583c,_loadfile
PL_NEXT _pl1234
_pl1 PL_START
PL_W $8570,30000 ;cash limit
;PL_I $9120
PL_NEXT _pl12
_pl2 PL_START
PL_W $8592,30000 ;cash limit
PL_NEXT _pl12
_pl3 PL_START
PL_PS $33c4,_f3
PL_PS $3426,_f1
PL_PS $34bc,_f1
PL_PS $34ea,_f2
PL_PS $350c,_f1
PL_PS $353a,_f2
PL_P $3684,_decrunch
PL_P $5626,_savefile
PL_P $57b0,_retok ;298 insert (value -> -$14a)
PL_P $5804,_retok ;29e backup
PL_P $5844,_loadfile
PL_W $8580,30000 ;cash limit
PL_NEXT _pl1234
_pl4 PL_START
PL_PS $339e,_f3
PL_PS $3400,_f1
PL_PS $3496,_f1
PL_PS $34c4,_f2
PL_PS $34e6,_f1
PL_PS $3514,_f2
PL_P $365e,_decrunch
PL_P $55fc,_savefile
PL_P $5786,_retok ;298 insert (value -> -$14a)
PL_P $57da,_retok ;29e backup
PL_P $581a,_loadfile
PL_W $854e,30000 ;cash limit
PL_NEXT _pl1234
_f1 cmp.l #$80000,a4
bhi .f11
move.w (a1),(a4)+
and.w d0,(a1)+
move.w ($26,a1),(a4)+
addq.l #2,(a7)
rts
.f11 and.w d0,(a1)+
and.w d0,($26,a1)
and.w d0,($4e,a1)
;addq.l #8,a4
add.l #$34d4-$34bc-6,(a7)
rts
_f2 cmp.l #$80000,a4
bhi .f21
move.w (a1)+,(a4)+
move.w ($26,a1),(a4)+
rts
.f21 addq.l #2,a1
;addq.l #8,a4
add.l #$3548-$353a-6,(a7)
rts
_f3 cmp.l #$80000,a4
bhi .f31
move.w (a1),(a4)+
and.w d2,(a1)+
move.w ($26,a1),(a4)+
addq.l #2,(a7)
rts
.f31 and.w d2,(a1)+
and.w d2,($26,a1)
and.w d2,($4e,a1)
;addq.l #8,a4
add.l #$34d4-$34bc-6,(a7)
rts
_retok moveq #0,d0
rts
_keyboard
;calculate rawkeycode
not.b d0
ror.b #1,d0
cmp.b (_keydebug,pc),d0
beq .debug
cmp.b (_keyexit,pc),d0
beq .exit
;better would be to use the cia-timer to wait, but we arn't know if
;they are otherwise used, so using the rasterbeam
;required minimum waiting is 75 µs, one rasterline is 63.5 µs
;a loop of 3 results in min=127µs max=190.5µs
moveq #3-1,d1
.wait1 move.b (vhposr+_custom),d2
.wait2 cmp.b (vhposr+_custom),d2
beq .wait2
dbf d1,.wait1
add.l #$306-$2f8-6,(a7)
rts
.debug addq.l #4,a7 ;return address
movem.l (a7)+,d0-d2/a6
move.w (a7),(6,a7) ;sr
move.l (2,a7),(a7) ;pc
clr.w (4,a7) ;ext.l sr
pea TDREASON_DEBUG.w
.quit move.l (whdbase,pc),-(a7)
addq.l #resload_Abort,(a7)
rts
.exit pea TDREASON_OK.w
bra .quit
;--- file loader
; IN: d0.b =$41 ; disk 1 side a [+$80 = packed]
; d0.b =$42 ; disk 2 side a
; d0.b =$43 ; disk 2 side b
; d0.b =$44 ; disk 1 side b
; a0 = dest
; a1 = name
; OUT: d0 = length
; a0 = dest
_loadfile
movem.l d1-a6,-(sp)
lea fl_name(pc),a2
.trans move.b (a1)+,(a2)+
bne .trans
lea lastadr,a1
move.l a0,(a1)
;---
lea fl_name(pc),a1
and.b #$7f,d0
cmp #'GO',(a1)
bne.b .nogo
sub.b #$42,d0 ; disk2 side a go(shapes)
add.b d0,1(a0) ; disk2 side b gp(shapes)
bra.b .get
;---
.nogo cmp.l #'UDO0',(a1)
bne.b .noudo0
cmp.b #$43,d0 ; file from disk2 side b was saved
beq.b .get
move.l #$00080008,d0
move.l d0,(a0)+
move.l d0,(a0)
moveq #8,d0
bra.w .nofix
;---
.noudo0 cmp.l #'WMON',(a1)
bne.b .get
cmp.b #$42,d0 ; doesn't exist on disk2 side a
bne.b .get
moveq #-33,d0
bra.w .nofix
;---
.get exg.l a0,a1
move.l whdbase(pc),a6
jsr resload_LoadFileDecrunch(a6)
.nofix movem.l (sp)+,d1-a6
rts
;--- save files
_savefile
movem.l d1/a0-a1/a6,-(a7)
exg.l a0,a1
addq.l #1,a0
move.l whdbase(pc),a6
jsr resload_SaveFile(a6)
movem.l (a7)+,_MOVEMREGS
moveq #0,d0
rts
;--------------------------------
; if last lw = 0 then decuncher2 else decruncher1
; decruncher2 returns unpacked length, decruncher1 not!!! therefore patch
; in: a0=src d0=srclen
; out: d0=dstlen
_decrunch move.l a2,-(a7)
move.l (-4,a0,d0.l),d1
beq .d2
bpl .d1
not.l d1
.d1 move.l d1,-(a7)
move.l _dec1,a2
jsr (a2)
move.l (a7)+,d0
bra .dec
.d2 move.l _dec2,a2
jsr (a2)
.dec move.l (a7)+,a2
ifeq 1
;save all files decompressed
movem.l d0-d1/a0-a3,-(a7)
lea fl_name,a1
.save1 tst.b (a1)+
bne .save1
subq.l #1,a1
move.l a1,a3
move.l #".dec",(a1)+
clr.b (a1)+
lea fl_name,a1
exg.l a0,a1
move.l whdbase,a2
jsr (resload_SaveFile,a2)
clr.b (a3)
movem.l (a7)+,_MOVEMREGS
endc
movem.l d0-d1/a0-a3,-(a7)
lea (.base),a3
;workaround for file STE because has same length on v1 and v3 but different contents
cmp.l #7580,d0
bne .noste
cmp.b #5,($24d,a0)
beq .noste
addq.l #1,d0 ;v1
.noste
.loop move.l (a3)+,d1
beq .end
cmp.l d0,d1 ;length
bne .next
move.w (a3),d1
lea fl_name,a2
lea (.base,pc,d1.w),a1
.cmp move.b (a2)+,d1
cmp.b (a1)+,d1
bne .next
tst.b d1
bne .cmp
move.w (2,a3),d1
lea (.base,pc,d1.w),a1
exg.l a0,a1
move.l whdbase,a3
cmp.w #_delta-.base,d1
bge .delta
jsr (resload_Patch,a3)
bra .end
;copy unpacked data to the end and apply delta
.delta move.l (8,a0),d1
move.l d1,(a7) ;new length
addq.l #3,d1
and.w #$fffc,d1
lea (a1,d1.l),a2
move.l a2,d1
.delta_copy move.l (a1)+,(a2)+
subq.l #4,d0
bcc .delta_copy
move.l a0,a2
move.l d1,a0
move.l (8,a7),a1
jsr (resload_Delta,a3)
bra .end
.next addq.l #4,a3
bra .loop
.end movem.l (a7)+,_MOVEMREGS
rts
.base dc.l 67694
dc.w .n_i2-.base,_p_i2-.base
dc.l 7581 ;faked
dc.w .n_ste-.base,_p1_ste-.base
dc.l 7544
dc.w .n_ste-.base,_p2_ste-.base
dc.l 7580
dc.w .n_ste-.base,_p3_ste-.base
dc.l 7584
dc.w .n_ste-.base,_p4_ste-.base
dc.l 18466
dc.w .n_town-.base,_p124_town-.base
dc.l 18332
dc.w .n_town-.base,_p124_town-.base
dc.l 18442
dc.w .n_town-.base,_p3_town-.base
dc.l 18522
dc.w .n_town-.base,_p124_town-.base
dc.l 24054
dc.w .n_fight-.base,_p1_fight-.base
dc.l 24044
dc.w .n_fight-.base,_p2_fight-.base
dc.l 24134
dc.w .n_fight-.base,_p3_fight-.base
dc.l 24082
dc.w .n_fight-.base,_p4_fight-.base
dc.l 15428
dc.w .n_surf-.base,_p1_surf-.base
dc.l 15442
dc.w .n_surf-.base,_p2_surf-.base
dc.l 15278
dc.w .n_surf-.base,_p3_surf-.base
dc.l 15444
dc.w .n_surf-.base,_p4_surf-.base
dc.l 8954
dc.w .n_tt00-.base,_d4_tt00-.base
dc.l 0
.n_i2 dc.b "I2",0
.n_ste dc.b "STE",0
.n_town dc.b "TOWN",0
.n_fight dc.b "FIGHT",0
.n_surf dc.b "SURF",0
.n_tt00 dc.b "TT00",0
EVEN
;file I2 (thalion logo)
_p_i2 PL_START
PL_PS $ccc4,.1 ;snoop problem
PL_L $7c8,4
PL_P $836,.2
PL_END
.1 move.w (4,a7),$dff096
move.l (a7),(2,a7)
addq.l #2,a7
rts
.2 move.l #-2,(a1)
move.l 4,$dff080
rts
_p124_ste PL_START
PL_B $c44,$60 ; disable disk backup
PL_PS $bba,_p_ste_1
PL_P $c9e,_retok ;getgamedisk
PL_P $cb6,_retok ;getbackupdisk
PL_S $d30,$d5e-$d30 ; expmem check
PL_END
_p1_ste PL_START
PL_STR $19ea,< >
PL_NEXT _p124_ste
_p2_ste PL_START
PL_STR $19d0,< >
PL_NEXT _p124_ste
_p3_ste PL_START
PL_B $c62,$60 ; disable disk backup
PL_PS $bd8,_p_ste_1
PL_P $cbc,_retok ;getgamedisk
PL_P $cd4,_retok ;getbackupdisk
PL_S $d4e,$d7c-$d4e ; expmem check
PL_STR $19ea,< >
PL_END
_p4_ste PL_START
PL_STR $19ef,< >
PL_NEXT _p124_ste
;disable caches for intro (gfx problems)
_p_ste_1 move.l #0,d0
move.l #WCPUF_All,d1
move.l whdbase,a0
jsr (resload_SetCPU,a0)
jsr $18000 ;original
_cacheon move.l #WCPUF_Base_WT|WCPUF_Exp_CB|WCPUF_Slave_CB|WCPUF_IC|WCPUF_BC|WCPUF_SS|WCPUF_SB|WCPUF_NWA,d0
move.l #WCPUF_All,d1
move.l whdbase,a0
jmp (resload_SetCPU,a0)
; list of smc:
; code destination new data
; a80 be4 704c = moveq #$4c,d0 no change?
; bd6 build copylock question
; fc4 2958-2974 chksum2
; 1c5e =chksum2 (old 1d6) two times
; bd6-cd4 chksum3
; 10e4 1c38.l smc + check
; 1ec4 1bc2-1fac chksum (all words added = d7)
; 1f50 1ece.w neg.w
; 1de2.w neg.w
_p124_town PL_START
PL_R $fc2 ;chksum2/3
PL_L $1762,$70004e75 ; moveq #0,d0 rts disk access
PL_S $1d3a,$1d76-$1d3a ;check
PL_R $1e44 ;check_manual
PL_I $1ec4 ;encode
PL_END
_p3_town PL_START
PL_R $f9e ;chksum2/3
PL_L $173c,$70004e75 ; moveq #0,d0 rts disk access
PL_S $1d14,$1d50-$1d14 ;check
PL_R $1e1e ;check_manual
PL_END
;fix 24 bit access fight sequence
_p1_fight PL_START
PL_PS $3f76,_p_fight_1a
PL_PS $406e,_p_fight_1b
PL_END
_p2_fight PL_START
PL_PS $3f6c,_p_fight_1a
PL_PS $4064,_p_fight_1b
PL_END
_p3_fight PL_START
PL_PS $3f94,_p_fight_1a
PL_PS $4090,_p_fight_1b
PL_END
_p4_fight PL_START
PL_PS $3f92,_p_fight_1a
PL_PS $408a,_p_fight_1b
PL_END
_p_fight_1a bsr _p_fight_1
move.l (a7),a5
add.w (a5),a5
addq.l #2,(a7)
rts
_p_fight_1b bsr _p_fight_1
subq.l #4,a7
move.l a0,-(a7)
move.l (8,a7),a0
add.w (a0),a0
move.l a0,(4,a7)
move.l (a7)+,a0
addq.l #2,(4,a7)
rts
_p_fight_1 move.l d0,-(a7)
move.l (8,a3),d0
and.l #$ffffff,d0
move.l d0,a0
move.l (a7)+,d0
rts
_p1_surf PL_START
PL_S $1f60,8 ;disk access
PL_S $2ca2,8 ;disk access
PL_END
_p2_surf PL_START
PL_S $1f6e,8 ;disk access
PL_S $2cb0,8 ;disk access
PL_END
_p3_surf PL_START
PL_S $1f2a,8 ;disk access
PL_S $2c08,8 ;disk access
PL_END
_p4_surf PL_START
PL_S $1f70,8 ;disk access
PL_S $2cb2,8 ;disk access
PL_END
;--------------------------------
_delta
_d4_tt00 INCBIN dragonflight_4_tt00.wdlt
EVEN
;--------------------------------
_dec1 dl 0
_dec2 dl 0
whdbase dc.l 0
lastadr dc.l 0
version dc.w 0
fl_name ds.b 9+5