Author: jsuijs
Date: Sun Oct 19 05:36:13 2008
New Revision: 432

Added:
    trunk/unvalidated/sample/test/jal/test_serial_format.jal
Modified:
    trunk/unvalidated/include/jal/format.jal

Log:
added format_dword_hex

Modified: trunk/unvalidated/include/jal/format.jal
==============================================================================
--- trunk/unvalidated/include/jal/format.jal    (original)
+++ trunk/unvalidated/include/jal/format.jal    Sun Oct 19 05:36:13 2008
@@ -80,12 +80,12 @@
  -- writes decimal formatted byte to output device
  -- the output can be specified as a fraction
  --   n_tot = the total length (including sign and decimal point)
---   N2   = number of digits behind the point
+--   n2   = number of digits behind the point
  --  
-----------------------------------------------------------------------------
-procedure format_byte_dec(volatile byte out device, byte in data, byte in  
n_tot, byte in N2) is
+procedure format_byte_dec(volatile byte out device, byte in data, byte in  
n_tot, byte in n2) is

-   const word C100   = 100
-   const word C10    = 10
+   const word c100   = 100
+   const word c10    = 10
     var byte digit

     -- start with spaces as a leader
@@ -93,15 +93,15 @@

     -- determine the next digit and display it
     if n_tot >= 3 then
-      digit = byte(data / C100)
-      data  = byte(data % C100)
-      _write_digit(device, digit, N2==2)
+      digit = byte(data / c100)
+      data  = byte(data % c100)
+      _write_digit(device, digit, n2==2)
     end if

     if n_tot >= 2 then
-      digit = byte(data / C10)
-      data  = byte(data % C10)
-      _write_digit(device, digit, N2==1)
+      digit = byte(data / c10)
+      data  = byte(data % c10)
+      _write_digit(device, digit, n2==1)
     end if

     -- last digit must always be written
@@ -119,10 +119,10 @@
  --  
-----------------------------------------------------------------------------
  procedure format_word_dec(volatile byte out device, word in data, byte in  
n_tot, byte in n2) is

-   const word C10000 = 10000
-   const word C1000  = 1000
-   const word C100   = 100
-   const word C10    = 10
+   const word c10000 = 10000
+   const word c1000  = 1000
+   const word c100   = 100
+   const word c10    = 10
     var byte digit

     -- start with spaces as a leader
@@ -130,26 +130,26 @@

     -- determine the next digit and display it
     if n_tot >=5 then
-      digit = byte(data / C10000)
-      data  = data % C10000
+      digit = byte(data / c10000)
+      data  = data % c10000
        _write_digit(device, digit, n2==4)
     end if

     if n_tot >= 4 then
-      digit = byte(data / C1000)
-      data  = data % C1000
+      digit = byte(data / c1000)
+      data  = data % c1000
        _write_digit(device, digit, n2==3)
     end if

     if n_tot >= 3 then
-      digit = byte(data / C100)
-      data  = data % C100
+      digit = byte(data / c100)
+      data  = data % c100
        _write_digit(device, digit, n2==2)
     end if

     if n_tot >= 2 then
-      digit = byte(data / C10)
-      data  = data % C10
+      digit = byte(data / c10)
+      data  = data % c10
        _write_digit(device, digit, n2==1)
     end if

@@ -167,15 +167,15 @@
  --  
-----------------------------------------------------------------------------
  procedure format_dword_dec(volatile byte out device, dword in data, byte  
in n_tot, byte in n2) is

-   const dword C1_000_000_000    = 1_000_000_000
-   const dword C100_000_000      = 100_000_000
-   const dword C10_000_000       = 10_000_000
-   const dword C1_000_000        = 1_000_000
-   const dword C100_000          = 100_000
-   const word  C10_000           = 10_000
-   const word  C1000             = 1000
-   const word  C100              = 100
-   const word  C10               = 10
+   const dword c1_000_000_000    = 1_000_000_000
+   const dword c100_000_000      = 100_000_000
+   const dword c10_000_000       = 10_000_000
+   const dword c1_000_000        = 1_000_000
+   const dword c100_000          = 100_000
+   const word  c10_000           = 10_000
+   const word  c1000             = 1000
+   const word  c100              = 100
+   const word  c10               = 10
     var byte digit

     -- start with spaces as a leader
@@ -183,57 +183,57 @@

     -- determine the next digit and display it
     if n_tot >=10 then
-      digit = byte(data / C1_000_000_000)
-      data  = data % C1_000_000_000
-      _write_digit(device, digit, N2==9)
+      digit = byte(data / c1_000_000_000)
+      data  = data % c1_000_000_000
+      _write_digit(device, digit, n2==9)
     end if

     if n_tot >=9 then
-      digit = byte(data / C100_000_000)
-      data  = data % C10_000_000
-      _write_digit(device, digit, N2==8)
+      digit = byte(data / c100_000_000)
+      data  = data % c10_000_000
+      _write_digit(device, digit, n2==8)
     end if

     if n_tot >=8 then
-      digit = byte(data / C10_000_000)
-      data  = data % C10_000_000
-      _write_digit(device, digit, N2==7)
+      digit = byte(data / c10_000_000)
+      data  = data % c10_000_000
+      _write_digit(device, digit, n2==7)
     end if

     if n_tot >=7 then
-      digit = byte(data / C1_000_000)
-      data  = data % C1_000_000
-      _write_digit(device, digit, N2==6)
+      digit = byte(data / c1_000_000)
+      data  = data % c1_000_000
+      _write_digit(device, digit, n2==6)
     end if

     if n_tot >=6 then
-      digit = byte(data / C100_000)
-      data  = data % C100_000
-      _write_digit(device, digit, N2==5)
+      digit = byte(data / c100_000)
+      data  = data % c100_000
+      _write_digit(device, digit, n2==5)
     end if

     if n_tot >=5 then
-      digit = byte(data / C10_000)
-      data  = data % C10_000
-      _write_digit(device, digit, N2==4)
+      digit = byte(data / c10_000)
+      data  = data % c10_000
+      _write_digit(device, digit, n2==4)
     end if

     if n_tot >= 4 then
-      digit = byte(data / C1000)
-      data  = data % C1000
-      _write_digit(device, digit, N2==3)
+      digit = byte(data / c1000)
+      data  = data % c1000
+      _write_digit(device, digit, n2==3)
     end if

     if n_tot >= 3 then
-      digit = byte(data / C100)
-      data  = data % C100
-      _write_digit(device, digit, N2==2)
+      digit = byte(data / c100)
+      data  = data % c100
+      _write_digit(device, digit, n2==2)
     end if

     if n_tot >= 2 then
-      digit = byte(data / C10)
-      data  = data % C10
-      _write_digit(device, digit, N2==1)
+      digit = byte(data / c10)
+      data  = data % c10
+      _write_digit(device, digit, n2==1)
     end if

     -- last digit must always be written
@@ -246,9 +246,9 @@
  -- writes decimal formatted signed byte to output device
  -- the output can be specified as a fraction
  --   n_tot = the total length (including sign and decimal point)
---   N2   = number of digits behind the point
+--   n2   = number of digits behind the point
  --  
-----------------------------------------------------------------------------
-procedure format_sbyte_dec(volatile byte out device, sbyte in data, byte  
in n_tot, byte in N2) is
+procedure format_sbyte_dec(volatile byte out device, sbyte in data, byte  
in n_tot, byte in n2) is

     var bit sign at data:7

@@ -260,7 +260,7 @@
     end if

     _format_signed = true
-   format_byte_dec(device, data, n_tot-1, N2)
+   format_byte_dec(device, data, n_tot-1, n2)
  end procedure
  --  
-----------------------------------------------------------------------------

@@ -269,9 +269,9 @@
  -- writes decimal formatted signed word to output device
  -- the output can be specified as a fraction
  --   n_tot = the total length (including sign and decimal point)
---   N2   = number of digits behind the point
+--   n2   = number of digits behind the point
  --  
-----------------------------------------------------------------------------
-procedure format_sword_dec(volatile byte out device, sword in data, byte  
in n_tot, byte in N2) is
+procedure format_sword_dec(volatile byte out device, sword in data, byte  
in n_tot, byte in n2) is

     ;var byte digit
     ;var byte B[2] at data
@@ -286,7 +286,7 @@
     end if

     _format_signed = true
-   format_word_dec(device, data, n_tot-1, N2)
+   format_word_dec(device, data, n_tot-1, n2)
  end procedure
  --  
-----------------------------------------------------------------------------

@@ -308,7 +308,7 @@
     end if

     _format_signed = true
-   format_dword_dec(device, data, n_tot-1, N2)
+   format_dword_dec(device, data, n_tot-1, n2)
  end procedure
  --  
-----------------------------------------------------------------------------

@@ -347,6 +347,27 @@
     -- determine the next digit and display it
     for 4 loop
        digit = (B[1] & 0xF0) >> 4
+      data  = data << 4
+      _write_digit(device,digit,false)
+   end loop
+
+end procedure
+--  
-----------------------------------------------------------------------------
+
+--  
-----------------------------------------------------------------------------
+-- writes hex formatted dword to output device
+--  
-----------------------------------------------------------------------------
+procedure format_dword_hex(volatile byte out device, dword in data) is
+
+   var byte digit
+   var byte B[4] at data
+
+   -- start with zeroes as a leader
+   _format_leader = "0"
+
+   -- determine the next digit and display it
+   for 8 loop
+      digit = (B[3] & 0xF0) >> 4
        data  = data << 4
        _write_digit(device,digit,false)
     end loop

Added: trunk/unvalidated/sample/test/jal/test_serial_format.jal
==============================================================================
--- (empty file)
+++ trunk/unvalidated/sample/test/jal/test_serial_format.jal    Sun Oct 19  
05:36:13 2008
@@ -0,0 +1,107 @@
+include delay_any_mc
+
+-- set all IO as digital
+enable_digital_io()
+
+-- ok, now setup serial
+const usart_hw_serial = true   -- true = RS232, false = SPI
+const serial_hw_baudrate = 115_200
+include serial_hardware
+serial_hw_init()
+
+include format
+
+procedure plingcrlf() is
+   serial_hw_data = "!"
+   serial_hw_data = 13
+   serial_hw_data = 10
+end procedure
+
+procedure line() is
+   for 20 loop
+      serial_hw_data = "-"
+   end loop
+   serial_hw_data = 13
+   serial_hw_data = 10
+end procedure
+
+forever loop                                  -- loop forever
+
+   serial_hw_data = "T"    serial_hw_data = "e"    serial_hw_data = "s"     
serial_hw_data = "t"    serial_hw_data = ":"    serial_hw_data = " "
+   plingcrlf()
+   line()
+
+   -- hex byte output
+   format_byte_hex(serial_hw_data, 0xEA)
+   plingcrlf()
+
+   -- hex word output
+   format_word_hex(serial_hw_data, 0xFD22) -- VIC20 reset vector ;-)
+   plingcrlf()
+
+   -- hex word output
+   format_dword_hex(serial_hw_data, 0x12345678)
+   plingcrlf()
+   line()
+
+   -- decimal output ' 1.2'
+   format_byte_dec(serial_hw_data, 12, 3, 1)
+   plingcrlf()
+
+   -- decimal output '0.12'
+   format_byte_dec(serial_hw_data, 12, 3, 2)
+   plingcrlf()
+
+   -- decimal output ' 12'
+   format_byte_dec(serial_hw_data, 12, 3, 0)
+   plingcrlf()
+
+   -- decimal output '12.0'
+   format_byte_dec(serial_hw_data, 120, 3, 1)
+   plingcrlf()
+   line()
+
+   -- decimal output '-12'
+   format_sbyte_dec(serial_hw_data, -12, 4, 0)
+   plingcrlf()
+
+   -- decimal output '-1.2'
+   format_sbyte_dec(serial_hw_data, -12, 4, 1)
+   plingcrlf()
+
+   -- decimal output '-0.12'
+   format_sbyte_dec(serial_hw_data, -12, 4, 2)
+   plingcrlf()
+   line()
+
+   -- decimal output ' 0.012'
+   format_word_dec(serial_hw_data, 12, 6, 3)
+   plingcrlf()
+
+   -- decimal output '   1.2'
+   format_word_dec(serial_hw_data, 12, 6, 1)
+   plingcrlf()
+
+   -- decimal output '   12'
+   format_word_dec(serial_hw_data, 12, 6, 0)
+   plingcrlf()
+
+   -- decimal output ' -0.012'
+   format_sword_dec(serial_hw_data, -12, 6, 3)
+   plingcrlf()
+
+   -- decimal output '23:55'
+   format_time_bytes(serial_hw_data, 23, 55)  -- 5 minutes to midnight
+   plingcrlf()
+
+   -- decimal output '23:56'
+   format_time_word(serial_hw_data, 23 * 60 + 56)  -- 4 minutes to midnight
+   plingcrlf()
+
+   serial_hw_data = "E"    serial_hw_data = "n"    serial_hw_data = "d"
+   plingcrlf()
+   plingcrlf()
+
+   delay_100ms(30)
+
+end loop
\ No newline at end of file

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to