retroforth/vm/nga-c-native-x86/x86/common.retro

57 lines
1.3 KiB
Forth
Raw Normal View History

# x86 Device Drivers
This exposes the low level port I/O device to RETRO. These
will be used in the implementation of the device drivers.
~~~
{{
'io:X86 var
:identify
@io:X86 n:zero? [
#2000 io:scan-for dup n:negative?
[ drop 'IO_DEVICE_TYPE_2000_NOT_FOUND s:put nl ]
[ !io:X86 ] choose ] if ;
---reveal---
:io:x86 identify @io:X86 io:invoke ;
}}
~~~
# I/O Ports
~~~
:pio:in-byte (p-n) #0 io:x86 ;
:pio:out-byte (vp-) #1 io:x86 ;
:pio:in-word (p-n) #6 io:x86 ;
:pio:out-word (vp-) #7 io:x86 ;
~~~
# Access to Physical RAM
~~~
:ram:store (va-) #2 io:x86 ;
:ram:fetch (a-v) #3 io:x86 ;
:ram:store-byte (va-) #4 io:x86 ;
:ram:fetch-byte (a-v) #5 io:x86 ;
~~~
# Hexadecimal
Since most resources list the values and ports in hex, I
am defining a prefix to be used. This will allow for hex
values to be specified like `0xC3`. They must be caps, and
negative values are not supported.
~~~
{{
:hex (s-n)
dup fetch $- eq? [ n:inc #-1 ] [ #0 ] choose swap
#0 swap [ '0123456789ABCDEF swap s:index-of + #16 * ] s:for-each
#16 / swap 0; * ;
---reveal---
:prefix:0 (s-...)
dup n:dec d:lookup n:-zero?
[ n:dec d:lookup [ d:xt fetch ] [ d:class fetch ] bi call ] if;
n:inc hex class:data ; immediate
}}
~~~