; Joypad emulation by keyboard
;
; Allows to emulate CD32 joypad buttons
; and to fake a joypad, since some games demand
; the joypad (e.g. Robocod CD32)
;
; By Jean-François Fabre 1999


*»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*

*## For the Startup.asm:

StartSkip	=	0		;0=WB/CLI, 1=CLI only (from AsmOne)
Processor	=	0		;0/680x0/0x0/x0
MathProc	=	0		;0/68881/68882/68040/68060

*## Default includes:

	INCDIR	Include:

	Include	"Startup.asm"
	include	"libs.i"
	include	"LVOs.i"

	INCLUDE	"workbench/workbench.i"
	INCLUDE	"workbench/startup.i"
	INCLUDE	"hardware/custom.i"
	INCLUDE	"libraries/lowlevel.i"

*»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
Init
	TaskName	KillFakepad		;from AsmOne
	DefEnd

Start
	move.l	$4.w,_SysBase
	bsr	init

*·············································································*
Close	Return	0


	dc.b	0,"$VER: Kill Fakepad v0.1 by JF Fabre",0
	cnop	0,4
init:
	move.l	_SysBase,A6

	lea	lowname,A1
	moveq.l	#0,D0
	JSRLIB	OpenLibrary
	move.l	D0,lowbase
	beq	.err

	move.l	lowbase,A6
	add.l	#_LVOReadJoyPort+2,A6
	move.l	(A6),A5
	move.l	(2,A5),D0
	cmp.l	#'JOYP',D0
	bne	.err			; not there

	move.l	_SysBase,A6
	JSRLIB	Disable

	move.l	lowbase,A1
	move.l	#_LVOReadJoyPort,A0
	move.l	(10,A5),D0
	JSRLIB	SetFunction

	move.l	A5,A1		; tsr location
	move.l	(6,A5),D0
	JSRLIB	FreeMem

	move.l	_SysBase,A6
	JSRLIB	Enable

	move.l	lowbase,A1
	JSRLIB	CloseLibrary	; close lowlevel lib

	moveq.l	#0,D0
	rts

	; error
.err
	moveq.l	#5,D0
	rts

_SysBase:
	dc.l	0
lowbase:
	dc.l	0

lowname:
	dc.b	"lowlevel.library",0
