retro/native: work on the ata driver (user configurable read/write delays, name the I/O ports used, start refactoring)

FossilOrigin-Name: 13f0507b61e115d449396ef3332d4ac132e9e13af1997bbe2f82f953c2c07abe
This commit is contained in:
crc 2020-02-29 15:50:19 +00:00
parent 4370fd4011
commit 50e969d0e5
4 changed files with 457 additions and 1669 deletions

View file

@ -2,13 +2,14 @@ all: native386 clean
native386:
cp ../../ngaImage nativeImage
../../bin/retro-extend nativeImage x86/common.retro x86/cmos-rtc.retro x86/serial.retro x86/display.retro x86/ata.retro x86/listener.retro x86/Block-Editor.retro
../../bin/retro-extend nativeImage x86/common.retro x86/cmos-rtc.retro x86/serial.retro x86/display.retro x86/ata.retro x86/listener.retro
# x86/Block-Editor.retro
../../bin/retro-embedimage nativeImage >image.c
cc -fno-pie -Wall -m32 -DTARGET_X86 -c retro.c -o retro_qwerty.o
cc -fno-pie -Wall -m32 -DTARGET_X86 -DUSE_DVORAK -c retro.c -o retro_dvorak.o
nasm -f elf 386.s
ld -nostdlib -m elf_i386 -n -T 386.ld 386.o retro_qwerty.o -o bin/rnf_qwerty.386
ld -nostdlib -m elf_i386 -n -T 386.ld 386.o retro_dvorak.o -o bin/rnf_dvorak.386
ld -z notext -nostdlib -m elf_i386 -T 386.ld 386.o retro_qwerty.o -o bin/rnf_qwerty.386
ld -z notext -nostdlib -m elf_i386 -T 386.ld 386.o retro_dvorak.o -o bin/rnf_dvorak.386
clean:
rm -f *.o

File diff suppressed because it is too large Load diff

View file

@ -6,47 +6,82 @@ sector to/from a dedicated `ata:Sector` buffer. No checks
are made to validate the sector number. Using these (esp.
`ata:write`) is likely to cause data loss.
# Settings
~~~
#10000 'ata:Delay var<n>
~~~
# Constants
~~~
0x20 'ata:READ const
0x30 'ata:WRITE const
0xE7 'ata:FLUSH-CACHE const
0x1F0 'ata:PRIMARY const
0x1F0 'ata:DATA const
0x1F1 'ata:ERROR const
0x1F1 'ata:FEATURES const
0x1F2 'ata:SECTOR-COUNT const
0x1F3 'ata:SECTOR-NUMBER const
0x1F4 'ata:CYLINDER-LOW const
0x1F5 'ata:CYLINDER-HIGH const
0x1F6 'ata:DRIVE const
0x1F6 'ata:HEAD const
0x1F7 'ata:STATUS const
0x1F7 'ata:COMMAND const
0x3F6 'ata:PRIMARY-DCR-AS const
~~~
# Common
~~~
:ata:clear-bsy (-)
[ 0x1F7 pio:in-byte 0x80 and n:zero? ] until ;
[ ata:COMMAND pio:in-byte 0x80 and n:zero? ] until ;
:ata:set-sector (n-)
0xE0 0x1F6 pio:out-byte
0x00 0x1F1 pio:out-byte
0x01 0x1F2 pio:out-byte
dup 0x1F3 pio:out-byte
dup #8 shift 0x1F4 pio:out-byte
#16 shift 0x1F5 pio:out-byte ;
0xE0 ata:HEAD pio:out-byte
0x00 ata:FEATURES pio:out-byte
0x01 ata:SECTOR-COUNT pio:out-byte
dup ata:SECTOR-NUMBER pio:out-byte
dup #8 shift ata:CYLINDER-LOW pio:out-byte
#16 shift ata:CYLINDER-HIGH pio:out-byte ;
~~~
# Reading a Sector
~~~
:mask 0xFF and ;
:delay @ata:Delay [ ] times ;
:ata:read-word
ata:PRIMARY pio:in-word ;
:store-word
[ mask over store n:inc ] sip #8 shift over store n:inc ;
:ata:read (an-)
ata:set-sector
ata:READ 0x1F7 pio:out-byte
#10000 [ ] times
#256 [ ata:PRIMARY pio:in-word [ 0xFF and over store n:inc ] sip #8 shift over store n:inc ] times drop ;
ata:READ ata:COMMAND pio:out-byte
delay
#256 [ ata:read-word store-word ] times drop ;
~~~
# Writing a Sector
~~~
:ata:write-word
ata:PRIMARY pio:out-word ;
:fetch-word
fetch-next [ fetch-next #-8 shift ] dip + ;
:ata:write (an-)
ata:set-sector
ata:WRITE 0x1F7 pio:out-byte
#10000 [ ] times
#256 [ fetch-next [ fetch-next #-8 shift ] dip + ata:PRIMARY pio:out-word ] times drop
0xE7 (cache_flush) 0x1F7 pio:out-byte ata:clear-bsy ;
ata:WRITE ata:COMMAND pio:out-byte
delay
#256 [ fetch-word ata:write-word ] times drop
ata:FLUSH-CACHE ata:COMMAND pio:out-byte ata:clear-bsy ;
~~~

View file

@ -9,7 +9,7 @@
:check-bs (c-c)
dup [ #8 eq? ] [ #127 eq? ] bi or [ buffer:get buffer:get drop-pair ] if ;
---reveal---
:c:get (-c) hook as{ 'liii.... i #1 d }as dup c:put ;
:c:get (-c) hook \liii.... `1 dup c:put ;
:s:get-word (-s) [ #1025 buffer:set
[ c:get dup buffer:add check-bs eol? ] until