home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ArachnoPhobia 34
/
ArachnoPhobia_34_2005-04-16_Spiders-Crew_ROLE.d64
/
38mmcdrv.s
< prev
next >
Wrap
Text File
|
2023-02-26
|
9KB
|
406 lines
; c64 mmc iNTERFACE v1.38
; tESTPROGRAM READS sECTOR AFTER sECTOR WHEN YOU PRESS sPACE kEY
; FROM YOUR fat16 FORMATED mmc cARD
; a RED bOARDER SHOWS YOU AN eRROR WITH cARD OR rEADER
;
;
; cOPYRIGHT (c) 2005 mARC sCHWARZBURG
;
; tHIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
; IT UNDER THE TERMS OF THE gnu gENERAL pUBLIC lICENSE AS PUBLISHED BY
; THE fREE sOFTWARE fOUNDATION; EITHER VERSION 2 OF THE lICENSE, OR
; (AT YOUR OPTION) ANY LATER VERSION.
;
; tHIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
; BUT without any warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF
; merchantability OR fitness for a particular purpose. sEE THE
; gnu gENERAL pUBLIC lICENSE FOR MORE DETAILS.
;
; yOU SHOULD HAVE RECEIVED A COPY OF THE gnu gENERAL pUBLIC lICENSE
; ALONG WITH THIS PROGRAM; IF NOT, WRITE TO THE fREE sOFTWARE
; fOUNDATION, iNC., 59 tEMPLE pLACE, sUITE 330, bOSTON, ma 02111-1307 usa
;
; mmc lOWlEVEL dRIVER v1.37 (c64asm source)
; (c) 2004 mARC sCHWARZBURG wIEN
; cONTACT ME : ROBTHECAT@FREENET.DE
;
;
; tEST SYSTEM
;
; 3.2 nEUES spi iNTERFACE, INPUT SCHIEBT NICHT RICHTIG
; 3.3 port dEBUGGER AUF $4000 EINGERICHTET
; SOME GLOBALS
; 3.4 rCKWERT WIEDER AUSGEWWRTET
; 3.5 bROWSE SOME bLOCKS (512 bYTE), eRRORPRINT AT cmd
; 3.6 sECTOREN PASSEN NICHT, pROTOCOL FEHLER
; kONZEPT ZUM lOADER DES cmd UND spi mODIFICATIONS !!
; 3.7 sTIMMT JETZT WENN MAN SICHS RICHTIG AUSRECCHNET WO EIN sEKTOR BEGINNT
; 3.8 oPTIMIZED FOR sPEED, ALLE sLEEPS RAUS !
;
; dIESES sYSTEM IST NOCH nicht sPEEDoPTIMIERT !!!
; wER zEIT HAT KANN DIE pORT wRITES oPTIMIEREN
; iCH GEHE JEDE pEGEL{$e4}NDERUNG ALS JSR STORE AN DIE hARDWARE WEITER !!
; ALSO:
;LDA OUT
;AND #$FD
; STA OUT
;JSR STORE
; mETHODE sTORE:
; {CBM--}BERNEHME wERT IM aKKUMULATOR UND iNVERTIERE ALLE bITS (WEGEN DEM tREIBERBAUSTEIN, DER nEGIERT ALLES !)
; sCHREIBE WERT NACH $DD01 !!
;
; gEHT ALS:
;
; LDA PORT
; ORA #$02
; STA PORT
;
SETNAM = $FFBD
SETLFS = $FFBA
OPEN = $FFC0
CLOSE = $FFC3
CHKIN = $FFC6
CHRIN = $FFCF
BSOUT = $FFD2
CLRCH = $FFCC
PORTD = $DD03
PORT = $DD01
OUT = $02
MMCMDRESET = $40
MMCMDINIT = $41
WAIT=5
* = $C000
JMP MAIN
;
; yOU cAN USE THIS pROGRAM AT YOUR OWN rISK OF DAMAGING YOUR dATA,hARDWARE,
; sOFTWARE, bRAIN OR WHATEVER !
; i{$e1}M NOT RESPONSIBLE FOR THIS.
; iF YOU WANT TO DO SOMETHING WITH THAT WORK, I.E COMPILE IT, YOU *HAVE TO* LET THE cOPYRIGHT
; AND MY nAME INSIDE YOUR sOURCE *AND bINARY* fILES.
.TEXT "mmc/sd cARD iNTERFACE v1.38"
.TEXT "(c) mARC sCHWARZBURG/vIENNA mAILTO: ROBTHECAT@FREENET.DE"
;O PB0 = /CS
;O PB1 DATA
;O PB2 CLK
;I PB3 READ
;
; XXXX0---
; lADEN WIR MAL LOS
;
INIT LDA #7
STA PORTD
LDA #0
LDA #%0000001
STA OUT
JSR STORE
RTS
; STORE BYTE INVERTED TO PORT
STORE EOR #$07 ; iNVERTIERE ALLE bITS, WEGEN tREIBERIC
STA PORT
; DEBUG
;JSR DEBUGGER
RTS
; READ bYTE AND INVERTS IT
READ LDA PORT
EOR #$FF
LSR
LSR
LSR
AND #$01
RTS
; sLEEPLOOP IF YOUR WIRES TO MMC ARE TO LONG !
SLEEP TXA
PHA
LDX #WAIT
SLEEP1 DEX
BNE SLEEP1
PLA
TAX
RTS
;------------------ spi ----------------------------
SPI STA $03 ; BUFFER OUPUT REGISTER
LDA#0
STA $FA ; BUFFER INPUT REGISTER
;
LDX #0
SPI2 ;
LDA OUT ; CLK =0 FB 1011
AND #$FB
STA OUT
JSR STORE
;
; bIT 7 TO OUTPUT
CLC
ASL $03
BCS SPI3
LDA OUT ; dATA = 0
AND #$FD
SPI4 STA OUT
JSR STORE
;
;
CLC
ASL $FA ; sHIFT INPUT LEFT
LDA OUT ; CLK = 1
ORA #$04
STA OUT
JSR STORE
;
;
; LESEN
JSR READ ; rEAD DATAIN pIN TO BIT0
ORA $FA ; CONNECT IT
STA $FA
; oNE BIT OUT, ONE BIT IN, SAME TIME
INX
CPX #08
BNE SPI2
; 3.6
; AT THE eND SEND dATA = h !!
LDA OUT ; dATA = 1
ORA #$02
STA OUT
JSR STORE
;
LDA $FA
RTS
;
SPI3 LDA OUT ; dATA = 1
ORA #$02
JMP SPI4
; -------------------- cOMMAND -----------------
CMD ; 3.6 cs = h
LDA OUT
ORA #01
STA OUT
JSR STORE
;
; 3.6- sEND 8 cLOCKS
LDA #$FF
JSR SPI
; cs = l
LDA OUT
AND #$FE
STA OUT
JSR STORE
;
;
; COMMAND
LDA $0502
JSR SPI
; 32BIT ADDRESS
LDA $0503
JSR SPI
LDA $0504
JSR SPI
LDA $0505
JSR SPI
LDA $0506
JSR SPI
; cHECKSUM nEEDED
LDA $0507
JSR SPI
; rESPONSE hi
; 3.6 READ WHILE INPUT = FF
CMD1 LDA #$FF
JSR SPI
CMP #$FF
BEQ CMD1
;LDA #$FF
;JSR SPI
NOP
;LESE R{$fc}CKGABEWERT
RTS
; ------------------- mmc iNIT --------------
MMCINIT LDA OUT ; cs = 1
ORA #$01
STA OUT
JSR STORE
; sTART mmc IN spi mODE
LDY #$00
MMCINIT1 LDA #$FF
JSR SPI
INY
CPY #12
BNE MMCINIT1
LDA OUT ; cs = 0
AND #$FE
STA OUT
JSR STORE
; cmd 0 = rESET
LDA #MMCMDRESET
STA $0502
LDA #0
STA $0503
STA $0504
STA $0505
STA $0506
LDA #$95
STA $0507
JSR CMD
STA $D021 ; sHOW ME IN BORDER
; ---- cARD READY ??
CMP #$01
BNE fEHLER ; nO cARD = <>1
;
LDA #MMCMDINIT ; lOOP WHILE NOT READY
STA $0502 ; sEND init TO mmc cARD
LDA #$FF
STA $0507 ; dUMMY cHECKSUM
MMCINIT2 JSR CMD
STA $D021 ; sHOW ME IN BORDER
CMP #$00
BNE MMCINIT2
; 3.6 cs = h
LDA OUT
ORA #$01
STA OUT
JSR STORE
;
RTS
;
fEHLER LDA #02
STA $D020
LDA #<ERROR2
LDY #>ERROR2
JSR $AB1E
RTS
ERROR2 .BYTE $0D
.TEXT "nO cARD FOUND, INSERT AGAIN."
;.TEXT "nkEINE kARTE VORHANDEN - bITTE NOCHMAL REINSTECKEN." ;GERMAN
.BYTE 0
; cOMMAND eRRPR : ZB. oUT OF aDRESS, WRONG pARAMETER, INTERFACE NOT SYNCHRON.
fEHLER2 PHA
LDA #02
STA $D021
LDA #<ERROR
LDY #>ERROR
JSR $AB1E
PLA
PHA
LSR
LSR
LSR
LSR
TAX
LDA HEXCODE,X
JSR $FFD2
PLA
AND #$0F
TAX
LDA HEXCODE,X
JSR $FFD2
LDA #$0D
JSR $FFD2
;
RTS
HEXCODE .TEXT "0123456789ABCDEF"
ERROR .BYTE $0D
.TEXT "CMD-ERROR: "
;.TEXT "kOMMANDO FEHLGESCHLAGEN - fEHLER: " ; GERMAN
.BYTE 0
; ------------------------------------
MAIN JSR INIT
JSR MMCINIT
;
; lESE MAL 512 BYTES NACH 0600
; wIE FUNKTIONIERTS ??
; aLS eRSTERS WANDELST dU dEINE ADRESSE UM
; cOMMAND 51, hh,hl,lh,ll,ff
; DIE VIER bYTES hh,hl,lh,ll STELLEN DIE 32 bIT aDRESSE DA
; dAS SIND aDRESSEN UND keine sECTOREN ODER GAR cLUSTER !!
; eIN rEADsECTOR = IMMER 512 bYTE D.H DIE vARIABLE ll = IMMER
; lEER, DIE vARIABLE lh = GERADER wERT (0,2,4,6,8)
; vARIABLE hl GEHT VVON 0-255
; vARIABLE hh GEHT VON 0-1 BEI MEINER 32 mb tESTKARTE
; wEIL MEHR GIBTS NICHT -> ERROR 20 (WRONG aDRESS)
;
; UM BEISPIELSWEISE ALLE sEKTOREN ZU ZEIGEN,
; LADE 0,0,0,0 IN DEN cmd51
; INC lh
; INC lh
;BNE WEITER
; INC hl
; BNE WEITER
; INC hh
; JMP rEADsECTOR
;
; IT MEANS:
; yOU HAVE TO CALCULATE THE aDDRESS FROM AN SECTOR VIEW
; rEMEMBER: aDDRESS = sECTORNUMBER * 512
; tHIS IS A 32 bIT vALUE (hh,hl,lh,ll)
;
LDA #$51
STA $0502 ; cOMMAND
LDA #$00 ; sECTOR hi h
STA $0503
LDA #$00 ; sECTOR hi l
STA $0504
LDA #$50 ; sECTOR lo h vALUES ONLY even !!
STA $0505
LDA #$00 ; sECTOR lo l ALWAYS 00
STA $0506
LDA #$FF ; dUMMY crc
STA $0507
NEXTBLOCK JSR CMD ; sECTOR rEAD cOMMAND
;
CMP #0
BNE fEHLER2
MAIN2 LDA #$FF
JSR SPI
CMP #$FE
BNE MAIN2 ; WAIT TILL ok ($fe)
LDY #0
MAIN3 LDA #$FF
JSR SPI
STA $0600,Y
INY
BNE MAIN3
MAIN4 LDA #$FF
JSR SPI
STA $0700,Y
INY
BNE MAIN4
; 2 BYTE DONT CARE
LDA #$FF
JSR SPI
LDA #$FF
JSR SPI
; GIVE A SPARE OF 8 CYCLES BETWEEN cOMMANDS
LDA #$FF
JSR SPI
;
KEY LDA $DC01
CMP #$EF
BNE KEY
INC $0505 ; sECTOR +1
INC $0505
BNE MAIN5
INC $0504
BNE MAIN5
INC $0503
MAIN5 JMP NEXTBLOCK
RTS
; -------------------------------------------------------