Re: Hello - and where to begin?

View: New views
5 Messages — Rating Filter:   Alert me  

Re: Hello - and where to begin?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Having found that Howerd Oakford's CFDOS4 floppy boots
reliably on my 3GHz 64bit PC, I think I have also found
a use
for the CF instruction "a" (the one that Chuck commented
as
"never used?").  It can be used to return the high 32
half of the
64 bit clock counter RDTSC, which is in EDX (same as the
 CF
address register "a").  Chuck's assembly code for the CF
word
"time" returns only the low 32 half, which is in EAX
(same as
CF data stack).  On a 3 GHz clock the lower half counter

whizzes around 3 times per second, which upsets Howerd's

code for time calibration "cal" and millisecond delay
"ms"
(block 28) and hence for sounds via the 16 bit timer PIT
2 (block 68).  I have corrected this, and am willing to
write
it up in sordid detail if anyone is interested.

Incidentally, I also changed the values that need to be
written to PIT control register 43 in order to "tie"
PIT2 to IRPort 61 and
"untie" it.  Howerd uses 4f and 4d; I use f and d,
because
Intel's book ICH7 says that bit 6 (40h) ought to be 0
when writing to IRPort 61.  If you want to use the
interrupts, Tie
can be reduced to 3 and Untie to 1.    
 
Caritas,

NickM


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: Hello - and where to begin?

by Ray St. Marie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dr. Nick, :-)    Ray here.

On Fri, Mar 7, 2008 at 6:16 AM, Nick Maroudas
<alice@...> wrote:
>
> Having found that Howerd Oakford's CFDOS4 floppy boots
> reliably on my 3GHz 64bit PC,

Well done. This IS excellent news. Willing to bet you've got cf on the
first 64 bit machine. Again, great stickin'-to-it-iveness.

> I think I have also found
> a use
> for the CF instruction "a" (the one that Chuck commented
> as
> "never used?").

Might be a good way to store an address you are using in one task
while PAUSEing to do another.

>It can be used to return the high 32
> half of the
> 64 bit clock counter RDTSC, which is in EDX (same as the
>  CF
> address register "a").

Neat! Well found!

> Chuck's assembly code for the CF
> word
> "time" returns only the low 32 half, which is in EAX
> (same as
> CF data stack).  On a 3 GHz clock the lower half counter
>
> whizzes around 3 times per second, which upsets Howerd's
>
> code for time calibration "cal" and millisecond delay
> "ms"
> (block 28) and hence for sounds via the 16 bit timer PIT
> 2 (block 68).  I have corrected this, and am willing to
> write
> it up in sordid detail if anyone is interested.

Pick me! pick me! i'm interested! :-)  Basically I'm interested in
every way colorforth is used.

> Incidentally, I also changed the values that need to be
> written to PIT control register 43 in order to "tie"
> PIT2 to IRPort 61 and
> "untie" it.  Howerd uses 4f and 4d; I use f and d,
> because
> Intel's book ICH7 says that bit 6 (40h) ought to be 0
> when writing to IRPort 61.  If you want to use the
> interrupts, Tie
> can be reduced to 3 and Untie to 1.

I'm not sure I understand what is being said here. This is ( like many
things) over my head a tad, I'm not ashamed to say. Please, Nick, vas
es PIT2 und IRPort 61, control reg 43, and when you say tie you mean
that PIT2 feeds IRPort 61 and then to do that you need register PIT 43
to connect these devices... um yeah? I don't know what I just said.


>
> Caritas,
>
> NickM
>

I'm glad you are having this success!
Ray

--
Raymond St. Marie ii,

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: Hello - and where to begin?

by Ray St. Marie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Mar 9, 2008 at 1:14 AM, Ray St. Marie <ray.stmarie@...> wrote:

> Hi Dr. Nick, :-)    Ray here.
>
> On Fri, Mar 7, 2008 at 6:16 AM, Nick Maroudas
> <alice@...> wrote:
>
> > Chuck's assembly code for the CF
> > word
> > "time" returns only the low 32 half, which is in EAX
> > (same as
> > CF data stack).  On a 3 GHz clock the lower half counter
> >
> > whizzes around 3 times per second, which upsets Howerd's
> >
> > code for time calibration "cal" and millisecond delay
> > "ms"
> > (block 28) and hence for sounds via the 16 bit timer PIT
> > 2 (block 68).  I have corrected this, and am willing to
> > write
> > it up in sordid detail if anyone is interested.
>


After thought...

I've done timed execution with cf in the past for chuckbot proggies,
but i've never used the timer. I used the PAUSE or I created a wait
with a nasty  for nul-action next loop.

I'd like to learn to use the system timer and if anyone would care to
enlighten me... please?

Ray

> >
> > Caritas,
> >
> > NickM


--
Raymond St. Marie ii,

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: Hello - and where to begin?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting "Ray St. Marie" <ray.stmarie@...>:
> On Sun, Mar 9, 2008 at 1:14 AM, Ray St. Marie
> <ray.stmarie@...> wrote:
>
> I'd like to learn to use the system timer and if
> anyone would care to
> enlighten me... please?
>
> Ray
>

Nick here: Dear Ray,

Thanks for your interest, below are further details;
rather long, but might be suitable for one of John
Drake's tutorials.

Caritas,

NickM

***************************

Timing and Music - Tutorial  

Howerd Oakford's CFDOS4 has three blocks which
illustrate
the use of PC timers.  You can make a boot floppy from
DOS
by following the instructions on Howerd's website; or  
just copy his bootable image cfdos4.blk with Linux,  
   dd   if=cfdos4.blk   of=/dev/fd0

The PC has 3 timers.  The newest and fastest is the 64
bit
RDTSC (Time Stamp Counter) which ticks at CPU rate, ns,

and loads the time, in clock ticks, onto EAX lo  &  EDX
hi.  
CF has a macro word "time" which calls RDTSC, with lo 32
 
bits on stack, EAX.  The first thing Howerd does is to
bring  
this macro word "time" into his forth dictionary, block
20,

forth   : time  time ;    --u

I find it useful to stack the higher 32 bits as well.
This can
be called by the the forth word "a", which stacks EDX.
So my version of "time" is "clk",

( still in forth)    : clk  time  a ;    --ulo uhi  

Block 28 uses the fast 64 bit PC timer to make delays in

msec "ms" and "secs".  Howard uses the PC's second timer

for calibration.  Real Time Clock (RTC) at port 70h,
ticks
hi and lo every second.   Howerd defines a variable
"khz"
to store the number of PC CPU ticks in one sec, divided
by
1000 to bring it to ms.  (I find "1ms" a useful memnonic
for
"khz").  The word "cal" ought to put your CPU's clock
rate
into the variable "khz".  

 : cal   hi lo time invert  ( howerd's word to change
sign)
          hi lo  time   +      ( time diff, no of clks
in 1 sec)
          1000 /   khz !   ;    ( ditto, in 1 msec)  

But if the CPU is faster than 1GHz,  a one sec
calibration
period will be too long, because the lower 32 bit
register
of the RDTS counter will overflow.  Hence I call the
higher
32 bit register as well, and scale the 2 numbers
appropriately
before adding them to make a 32 bit time scale.

: clk   time 10 shr   a 31 and 22 shl   + ;   --u (
hi+lo, scaled)

: cal   clk invert   clk +   1000 /   khz !   ;  

Having calibrated his time interval (for length of a
note)
Howerd then uses the PC's 3rd timer to set the
frequency.    
The Programmable Interrupt Timers (PIT) tick microsec.
See Mark Feldman's tutorial "Controlling the PC speaker"
 
on the popular Australian website, "JollySWAGman"

 http://www.bsdg.org/SWAG/SOUND/0107.PAS.html

The PC speaker is tied to the NMI status port 61h.
There
are caveats about writing to some other bits (see Intel
doc
ICH7) but, essentially, bit 0 will activate the speaker
and
bit 1 will tie it to the pulses from PIT 2.  This timer
is
selected by writing a byte to port 43, and its
oscillatory
half-period is entered as hibyte lobyte--  to port 42h.
 
Therefor Howerd introduces the macro word "swapbytes"
and defines a forth word to "split" 16bits into 2 bytes,

before moving on to make music.

Block 68 is straightforward, and rather neat.  It save a
bit
of repetitive naming by use of the CF facility where one
word
can elide into its successor if its   ";"   is omited.

 : tn   ( this is the note length t, scaled to msec)

 : hz  ( this is the PIT rate 1,193,000 ticks per sec,
divided
           by the freq in Hz - actually, this is the
pulse period)

 : tone  ( the period is split and written to PIT2,
which sets
              up oscillation freq; PIT2 output is tied
to speaker
              by writing a 3 to port 61, then it is
untied - after  
              t msec - by replacing the 3 with a 1; this
silences  
              the tone, plus 20 ms delay before next
tone)  ;  


*************************

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: Hello - and where to begin?

by Ray St. Marie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Mar 10, 2008 at 2:58 AM, Nick Maroudas
<alice@...> wrote:

>
> Nick here: Dear Ray,
>
> Thanks for your interest, below are further details;
> rather long, but might be suitable for one of John
> Drake's tutorials.
>
> Caritas,
>
> NickM
>
> ***************************
>
> Timing and Music - Tutorial
>
> Howerd Oakford's CFDOS4 has three blocks which
> illustrate
> the use of PC timers.  You can make a boot floppy from
> DOS
> by following the instructions on Howerd's website; or
> just copy his bootable image cfdos4.blk with Linux,
>   dd   if=cfdos4.blk   of=/dev/fd0
>
> The PC has 3 timers.  The newest and fastest is the 64
> bit
> RDTSC (Time Stamp Counter) which ticks at CPU rate, ns,
>
> and loads the time, in clock ticks, onto EAX lo  &  EDX
> hi.
> CF has a macro word "time" which calls RDTSC, with lo 32
>
> bits on stack, EAX.  The first thing Howerd does is to
> bring
> this macro word "time" into his forth dictionary, block
> 20,
>
> forth   : time  time ;    --u
>
> I find it useful to stack the higher 32 bits as well.
> This can
> be called by the the forth word "a", which stacks EDX.
> So my version of "time" is "clk",
>
> ( still in forth)    : clk  time  a ;    --ulo uhi
>
> Block 28 uses the fast 64 bit PC timer to make delays in
>
> msec "ms" and "secs".  Howard uses the PC's second timer
>
> for calibration.  Real Time Clock (RTC) at port 70h,
> ticks
> hi and lo every second.   Howerd defines a variable
> "khz"
> to store the number of PC CPU ticks in one sec, divided
> by
> 1000 to bring it to ms.  (I find "1ms" a useful memnonic
> for
> "khz").  The word "cal" ought to put your CPU's clock
> rate
> into the variable "khz".
>
>  : cal   hi lo time invert  ( howerd's word to change
> sign)
>          hi lo  time   +      ( time diff, no of clks
> in 1 sec)
>          1000 /   khz !   ;    ( ditto, in 1 msec)
>
> But if the CPU is faster than 1GHz,  a one sec
> calibration
> period will be too long, because the lower 32 bit
> register
> of the RDTS counter will overflow.  Hence I call the
> higher
> 32 bit register as well, and scale the 2 numbers
> appropriately
> before adding them to make a 32 bit time scale.
>
> : clk   time 10 shr   a 31 and 22 shl   + ;   --u (
> hi+lo, scaled)
>
> : cal   clk invert   clk +   1000 /   khz !   ;
>
> Having calibrated his time interval (for length of a
> note)
> Howerd then uses the PC's 3rd timer to set the
> frequency.
> The Programmable Interrupt Timers (PIT) tick microsec.
> See Mark Feldman's tutorial "Controlling the PC speaker"
>
> on the popular Australian website, "JollySWAGman"
>
>  http://www.bsdg.org/SWAG/SOUND/0107.PAS.html
>
> The PC speaker is tied to the NMI status port 61h.
> There
> are caveats about writing to some other bits (see Intel
> doc
> ICH7) but, essentially, bit 0 will activate the speaker
> and
> bit 1 will tie it to the pulses from PIT 2.  This timer
> is
> selected by writing a byte to port 43, and its
> oscillatory
> half-period is entered as hibyte lobyte--  to port 42h.
>
> Therefor Howerd introduces the macro word "swapbytes"
> and defines a forth word to "split" 16bits into 2 bytes,
>
> before moving on to make music.
>
> Block 68 is straightforward, and rather neat.  It save a
> bit
> of repetitive naming by use of the CF facility where one
> word
> can elide into its successor if its   ";"   is omited.
>
>  : tn   ( this is the note length t, scaled to msec)
>
>  : hz  ( this is the PIT rate 1,193,000 ticks per sec,
> divided
>           by the freq in Hz - actually, this is the
> pulse period)
>
>  : tone  ( the period is split and written to PIT2,
> which sets
>              up oscillation freq; PIT2 output is tied
> to speaker
>              by writing a 3 to port 61, then it is
> untied - after
>              t msec - by replacing the 3 with a 1; this
> silences
>              the tone, plus 20 ms delay before next
> tone)  ;
>
>
> *************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: colorforth-unsubscribe@...
> For additional commands, e-mail: colorforth-help@...
> Main web page - http://www.colorforth.com
>
>

Thank you for this, Nick!

Thank you, also, for the link to SWAG. It's been a long time since
I've been to that site. Great resource. Soon as I get done catching up
there, I'm going to load "Howerd" ( what I call any of his sources,
normally the very last otherwise I tend to add a digit as in Howerd2
or HowO-4 even )  and follow along with your tutorial here.

I've read Howerd's code in the past but unless you have used the
timers or have some frame of ref, the code is pretty but thats not
enough, sometimes. :-)

So again, Thanks!
Ray

--
Raymond St. Marie ii,

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com

LightInTheBox - Buy quality products at wholesale price