Close

BASIC Program to Read SD Card

A project log for OSI SD Card Operating System (OSISDOS)

Ohio Scientific / UK101 SD Card based Operating System under Multicomp FPGA Computer

land-boards.comland-boards.com 07/24/2020 at 12:150 Comments

From the SD card VHDL code:

-- Wait until SDSTATUS=0x80 (ensures previous cmd has completed)
-- Write SDLBA0, SDLBA1 SDLBA2 to select block index to read from
-- Write 0 to SDCONTROL to issue read command
-- Loop 512 times:
--     Wait until SDSTATUS=0xE0 (read byte ready, block busy)
--     Read byte from SDDATA

First cut at a sector dumper in BASIC:

 100 REM OSISDOS PROTOTYPE READ SD CARD IN BASIC
 120 DT=61456:REM SDDAT
 130 ST=61457:REM SDSTATUS/SDCONTROL
 140 A0=61458:REM SDLBA0
 150 A1=61459:REM SDLBA1
 160 A2=61460:REM SDLBA2
 200 L0=0:REM FIRST SECTOR LOWEST ADDRESS BYTE
 210 L1=0:REM FIRST SECTOR MIDDLE ADDRESS BYTE
 220 L2=0:REM FIRST SECTOR HIGHEST ADDRESS BYTE
 230 INPUT "LBA0 :";L0
 240 INPUT "LBA1 :";L1
 250 INPUT "LBA2 :";L2
 300 POKE A0,L0:REM WRITE ADDRESS REGISTERS
 310 POKE A1,L1
 320 POKE A2,L2
 400 SC=PEEK(ST):REM LOAD AT INITIAL STATUS, S/B 128
 410 PRINT "INIT STAT =";SC
 420 POKE ST,0:REM WRITE 0 TO CONTROL REG FOR READ BLOCK
 425 FOR J=0 TO 3:REM FORMATTED OUTPUT
 427 PRINT
 428 PRINT "OFFSET";128*J
 430 FOR I=0 TO 127
 440 SV=PEEK(ST)
 450 IF SV <> 224 GOTO 440:REM WAIT FOR READ VALUE READY
 460 DV=PEEK(DT)
 470 GOSUB 600
 480 NEXT I
 482 IF J=3 GOTO 490
 485 INPUT "HIT LETTER";Z$
 490 NEXT J
 500 END
 600 REM PRINT NUMBER AS HEX
 610 NB=(DV AND 240)/16
 620 GOSUB 650
 630 NB=DV AND 15
 640 GOSUB 650
 642 PRINT CHR$(32);
 645 RETURN
 650 IF NB>9 GOTO 700
 660 VL=NB+48
 670 PRINT CHR$(VL);
 680 RETURN
 700 VL=NB+55
 710 PRINT CHR$(VL);
 720 RETURN

Discussions