;----------------------------------------------------------------------------
;	RamCard.mcm by Guido Mersmann
;----------------------------------------------------------------------------
; This is an example code! I didnīt made any optimizations to make the
; code easy to understand! So donīt blame me!
;----------------------------------------------------------------------------
	include "Include.i"
	;include "SRC.MC_ModuleInclude"
	output Sourcecodes:MCControl/Modules/RamCard.mcm
	opt o+,w-
;----------------------------------------------------------------------------
Version = 1
Revision = 4
Day = 21
Month = 11
Year = 99
;----------------------------------------------------------------------------
;--- Macros
Version_String	MACRO
	dc.b "$VER: ",\1,' \<Version>.\<Revision>'," (\<Day>.\<Month>.\<Year>) ",'\2',0
	ENDM
;----------------------------------------------------------------------------
;--- Your defines
;----------------------------------------------------------------------------
Card_Frame_SIZEOF	= 128
;----------------------------------------------------------------------------
	RSSET Module_SIZEOF
;--- User Data
Module_UserData	rs.b 0
;--- Insert Userdata here!
Module_CurrentPage	rs.l 1
Module_UserData_End	rs.b 0
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
DModule_Code	rts
DModule_Version	dc.w 1
DModule_ID	dc.l Module_Identifier
DModule_Flags	dc.l ModuleF_MultiPage|ModuleF_DirectAccess
DModule_Exec_Base	dc.l 0 ;Filled by MCControl
DModule_Dos_Base	dc.l 0 ;Filled by MCControl
DModule_Intuition_Base	dc.l 0 ;Filled by MCControl
;--- Card Data
DModule_DelayReadByte	dc.l 0 ;Filled by MCControl
DModule_DelayReadBit	dc.l 0 ;Filled by MCControl
DModule_DelayWriteByte	dc.l 0 ;Filled by MCControl
DModule_DelayWriteBit	dc.l 0 ;Filled by MCControl
	ds.l 10 ;reserved
;--- Jump Table
DModule_Delay	ds.w 3 ;Delay
	bra DModule_Open
	nop
	bra DModule_Close
	nop
	bra DModule_FrameOpen
	nop
	bra DModule_FrameClose
	nop
	bra DModule_ReadCommand
	nop
	bra DModule_WriteCommand
	nop
	bra DModule_PADOpen
	nop
	bra DModule_PADClose
	nop
	bra DModule_PADCommand
	nop
	bra DModule_DirectFrame
	nop
	bra DModule_DirectPage
	nop
	ds.w 3*8 ;reserved
	ds.b Module_UserData_End-Module_UserData
;----------------------------------------------------------------------------
	Version_String "RamCard.mcm",<by Guido Mersmann>
	even
;----------------------------------------------------------------------------
DModule_Open	lea	RAMCARD_Page1,a0
	move.l	a0,Module_CurrentPage(a4)
DModule_FrameOpen
DModule_FrameClose
DModule_ReadCommand
DModule_WriteCommand
DModule_PADOpen
DModule_PADClose
DModule_PADCommand

DModule_Close	moveq	#Module_Error_NoError,d0
	rts
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;	DModule_DirectFrame
;	>a0.l Pointer on Buffer
;	>d0.w Number of Frame
;	<d0.l NULL = OK, -1 = Error
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
DModule_DirectFrame	ext.l	d0
	subq.l	#Module_DirectFrame_Write,d1
	beq	Card_WriteFrame
;----------------------------------------------------------------------------
Card_ReadFrame	move.l	Module_CurrentPage(a4),a1
	mulu	#Card_Frame_SIZEOF,d0
	add.l	d0,a1
	moveq	#Card_Frame_SIZEOF-1,d0
.Loop	move.b	(a1)+,(a0)+
	dbra	d0,.Loop
	moveq	#0,d0 ;NoError
	rts
;----------------------------------------------------------------------------
Card_WriteFrame	move.l	Module_CurrentPage(a4),a1
	mulu	#Card_Frame_SIZEOF,d0
	add.l	d0,a1
	moveq	#Card_Frame_SIZEOF-1,d0
.Loop	move.b	(a0)+,(a1)+
	dbra	d0,.Loop
	moveq	#0,d0 ;NoError
	rts
;----------------------------------------------------------------------------
;	DModule_DirectPage
;	>d0.w Number
;	>d1.l Mode
; We only have two pages, so there is no need to check d1 for Next or Prev
; Page!!
;----------------------------------------------------------------------------
DModule_DirectPage	lea	RAMCARD_Page1,a0
	lea	RAMCARD_Page2,a1
	cmp.l	Module_CurrentPage(a4),a1
	beq	.UseA0
	move.l	a1,a0
.UseA0	move.l	a0,Module_CurrentPage(a4)
	moveq	#0,d0 ;NoError
	rts
;----------------------------------------------------------------------------
	Section "RamCard",BSS
RAMCARD_Page1	ds.b 2*65536
RAMCARD_Page2	ds.b 2*65536
