mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 14:30:55 +11:00
Compare commits
No commits in common. "29a6ee128d07fe437944c328cbcec87301b7fc53" and "052c7440002e7c71ac04edfcd6d4a9849b654c49" have entirely different histories.
29a6ee128d
...
052c744000
4
blk/038
4
blk/038
@ -2,8 +2,8 @@
|
|||||||
FORGET x -- Rewind the dictionary (both CURRENT and HERE)
|
FORGET x -- Rewind the dictionary (both CURRENT and HERE)
|
||||||
up to x's previous entry.
|
up to x's previous entry.
|
||||||
PREV a -- a Return a wordref's previous entry.
|
PREV a -- a Return a wordref's previous entry.
|
||||||
WORD( a -- a Get wordref's beginning addr.
|
WHLEN a -- n Get word header length from wordref. That is,
|
||||||
|
name length + 3. a is a wordref
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
89
drv/sdc.fs
89
drv/sdc.fs
@ -1,3 +1,12 @@
|
|||||||
|
: SDC_CSHIGH 6 ;
|
||||||
|
: SDC_CSLOW 5 ;
|
||||||
|
: SDC_SPI 4 ;
|
||||||
|
|
||||||
|
: _sdcSR SDC_SPI PC! SDC_SPI PC@ ;
|
||||||
|
|
||||||
|
: _sel 0 SDC_CSLOW PC! ;
|
||||||
|
: _desel 0 SDC_CSHIGH PC! ;
|
||||||
|
|
||||||
( -- n )
|
( -- n )
|
||||||
: _idle 0xff _sdcSR ;
|
: _idle 0xff _sdcSR ;
|
||||||
|
|
||||||
@ -84,31 +93,30 @@
|
|||||||
|
|
||||||
( cmd arg1 arg2 -- r )
|
( cmd arg1 arg2 -- r )
|
||||||
( Send a command that expects a R1 response, handling CS. )
|
( Send a command that expects a R1 response, handling CS. )
|
||||||
: SDCMDR1 _sdcSel _cmd _sdcDesel ;
|
: SDCMDR1 _sel _cmd _desel ;
|
||||||
|
|
||||||
( cmd arg1 arg2 -- r arg1 arg2 )
|
( cmd arg1 arg2 -- r arg1 arg2 )
|
||||||
( Send a command that expects a R7 response, handling CS. A R7
|
( Send a command that expects a R7 response, handling CS. A R7
|
||||||
is a R1 followed by 4 bytes. arg1 contains bytes 0:1, arg2
|
is a R1 followed by 4 bytes. arg1 contains bytes 0:1, arg2
|
||||||
has 2:3 )
|
has 2:3 )
|
||||||
: SDCMDR7
|
: SDCMDR7
|
||||||
_sdcSel
|
_sel
|
||||||
_cmd ( r )
|
_cmd ( r )
|
||||||
_idle 256 * ( r h )
|
_idle 256 * ( r h )
|
||||||
_idle + ( r arg1 )
|
_idle + ( r arg1 )
|
||||||
_idle 256 * ( r arg1 h )
|
_idle 256 * ( r arg1 h )
|
||||||
_idle + ( r arg1 arg2 )
|
_idle + ( r arg1 arg2 )
|
||||||
_sdcDesel
|
_desel
|
||||||
;
|
;
|
||||||
|
|
||||||
: _err _sdcDesel ABORT" SDerr" ;
|
|
||||||
|
|
||||||
( Initialize a SD card. This should be called at least 1ms
|
( Initialize a SD card. This should be called at least 1ms
|
||||||
after the powering up of the card. )
|
after the powering up of the card. r is result.
|
||||||
|
Zero means success, non-zero means error. )
|
||||||
: SDC$
|
: SDC$
|
||||||
( Wake the SD card up. After power up, a SD card has to
|
( Wake the SD card up. After power up, a SD card has to
|
||||||
receive at least 74 dummy clocks with CS and DI high. We
|
receive at least 74 dummy clocks with CS and DI high. We
|
||||||
send 80. )
|
send 80. )
|
||||||
10 0 DO _idle DROP LOOP
|
10 0 DO 0xff SDC_SPI PC! LOOP
|
||||||
|
|
||||||
( call cmd0 and expect a 0x01 response (card idle)
|
( call cmd0 and expect a 0x01 response (card idle)
|
||||||
this should be called multiple times. we're actually
|
this should be called multiple times. we're actually
|
||||||
@ -120,16 +128,16 @@
|
|||||||
SDCMDR1
|
SDCMDR1
|
||||||
DUP 0x01 = IF LEAVE THEN
|
DUP 0x01 = IF LEAVE THEN
|
||||||
LOOP
|
LOOP
|
||||||
0x01 = NOT IF _err THEN
|
0x01 = NOT IF 1 EXIT THEN
|
||||||
|
|
||||||
( Then comes the CMD8. We send it with a 0x01aa argument
|
( Then comes the CMD8. We send it with a 0x01aa argument
|
||||||
and expect a 0x01aa argument back, along with a 0x01 R1
|
and expect a 0x01aa argument back, along with a 0x01 R1
|
||||||
response. )
|
response. )
|
||||||
0b01001000 0 0x1aa ( CMD8 )
|
0b01001000 0 0x1aa ( CMD8 )
|
||||||
SDCMDR7 ( r arg1 arg2 )
|
SDCMDR7 ( r arg1 arg2 )
|
||||||
0x1aa = NOT IF _err THEN ( arg2 check )
|
0x1aa = NOT IF 2 EXIT THEN ( arg2 check )
|
||||||
0 = NOT IF _err THEN ( arg1 check )
|
0 = NOT IF 3 EXIT THEN ( arg1 check )
|
||||||
0x01 = NOT IF _err THEN ( r check )
|
0x01 = NOT IF 4 EXIT THEN ( r check )
|
||||||
|
|
||||||
( Now we need to repeatedly run CMD55+CMD41 (0x40000000)
|
( Now we need to repeatedly run CMD55+CMD41 (0x40000000)
|
||||||
until the card goes out of idle mode, that is, when
|
until the card goes out of idle mode, that is, when
|
||||||
@ -139,23 +147,24 @@
|
|||||||
BEGIN
|
BEGIN
|
||||||
0b01110111 0 0 ( CMD55 )
|
0b01110111 0 0 ( CMD55 )
|
||||||
SDCMDR1
|
SDCMDR1
|
||||||
0x01 = NOT IF _err THEN
|
0x01 = NOT IF 5 EXIT THEN
|
||||||
0b01101001 0x4000 0x0000 ( CMD41 )
|
0b01101001 0x4000 0x0000 ( CMD41 )
|
||||||
SDCMDR1
|
SDCMDR1
|
||||||
DUP 0x01 > IF _err THEN
|
DUP 0x01 > IF DROP 6 EXIT THEN
|
||||||
NOT UNTIL
|
NOT UNTIL
|
||||||
( Out of idle mode! Success! )
|
( Out of idle mode! Success! )
|
||||||
|
0
|
||||||
;
|
;
|
||||||
|
|
||||||
( dstaddr blkno -- )
|
( dstaddr blkno -- f )
|
||||||
: _sdc@
|
: SDC@
|
||||||
_sdcSel
|
_sel
|
||||||
0x51 ( CMD17 )
|
0x51 ( CMD17 )
|
||||||
0 ROT ( a cmd 0 blkno )
|
0 ROT ( a cmd 0 blkno )
|
||||||
_cmd
|
_cmd
|
||||||
IF _err THEN
|
IF _desel 0 EXIT THEN
|
||||||
_wait
|
_wait
|
||||||
0xfe = NOT IF _err THEN
|
0xfe = NOT IF _desel 0 EXIT THEN
|
||||||
0 SWAP ( crc a )
|
0 SWAP ( crc a )
|
||||||
512 0 DO ( crc a )
|
512 0 DO ( crc a )
|
||||||
DUP ( crc a a )
|
DUP ( crc a a )
|
||||||
@ -170,46 +179,6 @@
|
|||||||
_idle 256 *
|
_idle 256 *
|
||||||
_idle + ( crc2 )
|
_idle + ( crc2 )
|
||||||
_wait DROP
|
_wait DROP
|
||||||
_sdcDesel
|
_desel
|
||||||
= NOT IF _err THEN
|
= ( success if crc1 == crc2 )
|
||||||
;
|
|
||||||
|
|
||||||
: SDC@
|
|
||||||
2 * DUP BLK( SWAP ( b a b )
|
|
||||||
_sdc@
|
|
||||||
1+ BLK( 512 + SWAP
|
|
||||||
_sdc@
|
|
||||||
;
|
|
||||||
|
|
||||||
( srcaddr blkno -- )
|
|
||||||
: _sdc!
|
|
||||||
_sdcSel
|
|
||||||
0x58 ( CMD24 )
|
|
||||||
0 ROT ( a cmd 0 blkno )
|
|
||||||
_cmd
|
|
||||||
IF _err THEN
|
|
||||||
_idle DROP
|
|
||||||
0xfe _sdcSR DROP
|
|
||||||
0 SWAP ( crc a )
|
|
||||||
512 0 DO ( crc a )
|
|
||||||
C@+ ( crc a+1 n )
|
|
||||||
ROT OVER ( a n crc n )
|
|
||||||
_crc16 ( a n crc )
|
|
||||||
SWAP ( a crc n )
|
|
||||||
_sdcSR DROP ( a crc )
|
|
||||||
SWAP ( crc a )
|
|
||||||
LOOP
|
|
||||||
DROP ( crc )
|
|
||||||
256 /MOD ( lsb msb )
|
|
||||||
_sdcSR DROP ( lsb )
|
|
||||||
_sdcSR DROP
|
|
||||||
_wait DROP
|
|
||||||
_sdcDesel
|
|
||||||
;
|
|
||||||
|
|
||||||
: SDC!
|
|
||||||
2 * DUP BLK( SWAP ( b a b )
|
|
||||||
_sdc!
|
|
||||||
1+ BLK( 512 + SWAP
|
|
||||||
_sdc!
|
|
||||||
;
|
;
|
||||||
|
21
drv/sdc.z80
21
drv/sdc.z80
@ -1,21 +0,0 @@
|
|||||||
( n -- n )
|
|
||||||
( Initiate SPI exchange with the SD card. n is the data to
|
|
||||||
send. )
|
|
||||||
CODE _sdcSR
|
|
||||||
HL POPqq,
|
|
||||||
chkPS,
|
|
||||||
A L LDrr,
|
|
||||||
SDC_SPI OUTnA,
|
|
||||||
NOP, NOP,
|
|
||||||
SDC_SPI INAn,
|
|
||||||
L A LDrr,
|
|
||||||
HL PUSHqq,
|
|
||||||
;CODE
|
|
||||||
|
|
||||||
CODE _sdcSel
|
|
||||||
SDC_CSLOW OUTnA,
|
|
||||||
;CODE
|
|
||||||
|
|
||||||
CODE _sdcDesel
|
|
||||||
SDC_CSHIGH OUTnA,
|
|
||||||
;CODE
|
|
@ -183,6 +183,7 @@ void sdc_spi_wr(SDC *sdc, uint8_t val)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cmd == 24) {
|
if (cmd == 24) {
|
||||||
|
fprintf(stderr, "cmd24\n");
|
||||||
if (sdc->fp) {
|
if (sdc->fp) {
|
||||||
fseek(sdc->fp, arg2*512, SEEK_SET);
|
fseek(sdc->fp, arg2*512, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,9 @@
|
|||||||
( During a CASE, the stack grows by 1 at each ENDOF so that
|
( During a CASE, the stack grows by 1 at each ENDOF so that
|
||||||
we can fill all those ENDOF branching addrs. So that we
|
we can fill all those ENDOF branching addrs. So that we
|
||||||
know when to stop, we put a 0 on PSP. That's our stopgap. )
|
know when to stop, we put a 0 on PSP. That's our stopgap. )
|
||||||
: CASE 0 COMPILE >R ; IMMEDIATE
|
: CASE 0 ; IMMEDIATE
|
||||||
: OF
|
: OF
|
||||||
COMPILE I COMPILE =
|
COMPILE OVER COMPILE =
|
||||||
[COMPILE] IF
|
[COMPILE] IF
|
||||||
; IMMEDIATE
|
; IMMEDIATE
|
||||||
: ENDOF [COMPILE] ELSE ; IMMEDIATE
|
: ENDOF [COMPILE] ELSE ; IMMEDIATE
|
||||||
@ -70,11 +70,10 @@
|
|||||||
hit 0. )
|
hit 0. )
|
||||||
: ENDCASE
|
: ENDCASE
|
||||||
BEGIN
|
BEGIN
|
||||||
DUP NOT IF
|
DUP NOT IF DROP EXIT THEN
|
||||||
DROP COMPILE R> COMPILE DROP EXIT
|
|
||||||
THEN
|
|
||||||
[COMPILE] THEN
|
[COMPILE] THEN
|
||||||
AGAIN
|
AGAIN
|
||||||
|
COMPILE DROP
|
||||||
; IMMEDIATE
|
; IMMEDIATE
|
||||||
|
|
||||||
: CREATE
|
: CREATE
|
||||||
@ -155,18 +154,17 @@
|
|||||||
- ( a-o )
|
- ( a-o )
|
||||||
;
|
;
|
||||||
|
|
||||||
: WORD(
|
: WHLEN
|
||||||
DUP 1- C@ ( name len field )
|
1- C@ ( name len field )
|
||||||
127 AND ( 0x7f. remove IMMEDIATE flag )
|
127 AND ( 0x7f. remove IMMEDIATE flag )
|
||||||
3 + ( fixed header len )
|
3 + ( fixed header len )
|
||||||
-
|
|
||||||
;
|
;
|
||||||
|
|
||||||
: FORGET
|
: FORGET
|
||||||
' DUP ( w w )
|
' DUP ( w w )
|
||||||
( HERE must be at the end of prev's word, that is, at the
|
( HERE must be at the end of prev's word, that is, at the
|
||||||
beginning of w. )
|
beginning of w. )
|
||||||
WORD( HERE ! ( w )
|
DUP WHLEN - HERE ! ( w )
|
||||||
PREV CURRENT !
|
PREV CURRENT !
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
1+
|
1+
|
||||||
;
|
;
|
||||||
|
|
||||||
|
( Get word addr, starting at name's address )
|
||||||
|
: '< ' DUP WHLEN - ;
|
||||||
|
|
||||||
( Relink atom at a, applying offset o with limit ol.
|
( Relink atom at a, applying offset o with limit ol.
|
||||||
Returns a, appropriately skipped.
|
Returns a, appropriately skipped.
|
||||||
)
|
)
|
||||||
@ -124,10 +127,6 @@
|
|||||||
The output of this word is 3 numbers: top copied address,
|
The output of this word is 3 numbers: top copied address,
|
||||||
top copied CURRENT, and then the beginning of the copied dict
|
top copied CURRENT, and then the beginning of the copied dict
|
||||||
at the end to indicate that we're finished processing.
|
at the end to indicate that we're finished processing.
|
||||||
|
|
||||||
Note that the last word is always skipped because it's not
|
|
||||||
possible to reliably detect its end. If you need that last
|
|
||||||
word, define a dummy word before calling RLDICT.
|
|
||||||
)
|
)
|
||||||
( target -- )
|
( target -- )
|
||||||
: RLDICT
|
: RLDICT
|
||||||
@ -143,7 +142,7 @@
|
|||||||
( H@+2 == offset )
|
( H@+2 == offset )
|
||||||
H@ 2+ ! ( )
|
H@ 2+ ! ( )
|
||||||
( We have our offset, now let's copy our memory chunk )
|
( We have our offset, now let's copy our memory chunk )
|
||||||
H@ @ WORD( ( src )
|
H@ @ DUP WHLEN - ( src )
|
||||||
DUP H@ -^ ( src u )
|
DUP H@ -^ ( src u )
|
||||||
DUP ROT SWAP ( u src u )
|
DUP ROT SWAP ( u src u )
|
||||||
H@ 4 + ( u src u dst )
|
H@ 4 + ( u src u dst )
|
||||||
@ -155,9 +154,9 @@
|
|||||||
offset by u+4. +4 before, remember, we're using 4 bytes
|
offset by u+4. +4 before, remember, we're using 4 bytes
|
||||||
as variable space. )
|
as variable space. )
|
||||||
4 + ( u+4 )
|
4 + ( u+4 )
|
||||||
DUP CURRENT @ WORD( + ( u we )
|
DUP H@ + ( u we )
|
||||||
DUP .X CRLF
|
DUP .X CRLF
|
||||||
SWAP CURRENT @ PREV + ( we wr )
|
SWAP CURRENT @ + ( we wr )
|
||||||
DUP .X CRLF
|
DUP .X CRLF
|
||||||
BEGIN ( we wr )
|
BEGIN ( we wr )
|
||||||
DUP ROT ( wr wr we )
|
DUP ROT ( wr wr we )
|
||||||
@ -170,7 +169,7 @@
|
|||||||
DUP ( wr wr )
|
DUP ( wr wr )
|
||||||
PREV ( oldwr newwr )
|
PREV ( oldwr newwr )
|
||||||
SWAP ( wr oldwr )
|
SWAP ( wr oldwr )
|
||||||
WORD( ( wr we )
|
DUP WHLEN - ( wr we )
|
||||||
SWAP ( we wr )
|
SWAP ( we wr )
|
||||||
( Are we finished? We're finished if wr-4 <= H@ )
|
( Are we finished? We're finished if wr-4 <= H@ )
|
||||||
DUP 4 - H@ <=
|
DUP 4 - H@ <=
|
||||||
|
@ -10,7 +10,6 @@ BOOTSRCS = conf.fs \
|
|||||||
$(FDIR)/boot.fs \
|
$(FDIR)/boot.fs \
|
||||||
$(FDIR)/z80c.fs \
|
$(FDIR)/z80c.fs \
|
||||||
$(BASEDIR)/drv/acia.z80 \
|
$(BASEDIR)/drv/acia.z80 \
|
||||||
$(BASEDIR)/drv/sdc.z80 \
|
|
||||||
$(FDIR)/icore.fs \
|
$(FDIR)/icore.fs \
|
||||||
$(EDIR)/xstop.fs
|
$(EDIR)/xstop.fs
|
||||||
|
|
||||||
|
@ -2,8 +2,5 @@
|
|||||||
0xf000 CONSTANT RS_ADDR
|
0xf000 CONSTANT RS_ADDR
|
||||||
0x80 CONSTANT ACIA_CTL
|
0x80 CONSTANT ACIA_CTL
|
||||||
0x81 CONSTANT ACIA_IO
|
0x81 CONSTANT ACIA_IO
|
||||||
4 CONSTANT SDC_SPI
|
|
||||||
5 CONSTANT SDC_CSLOW
|
|
||||||
6 CONSTANT SDC_CSHIGH
|
|
||||||
RAMSTART 0x70 + CONSTANT ACIA_MEM
|
RAMSTART 0x70 + CONSTANT ACIA_MEM
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user