Author: [email protected]
Date: Fri Apr 24 12:12:31 2009
New Revision: 939
Modified:
trunk/include/jal/print.jal
Log:
Not yet finished, but maybe Joep you can check if this is what you mean.
I will go on a short holiday Tuesday 28-04 and be back Thursday 07-05
and then continuing with print.jal.
greetz
Richard
Modified: trunk/include/jal/print.jal
==============================================================================
--- trunk/include/jal/print.jal (original)
+++ trunk/include/jal/print.jal Fri Apr 24 12:12:31 2009
@@ -1,6 +1,7 @@
-- Title: Writes variables to output device
--- Author: Joep Suijs, Copyright (c) 2007..2008, all rights reserved.
--- Adapted-by: Joep Suijs
+-- Author: Joep Suijs and Stef Mientki, Copyright (c) 2007..2008, all
rights reserved.
+-- Adapted-by: Joep Suijs, Richard Zengerink
+--
-- Compiler: >=2.2
--
-- This file is part of jallib (http://jallib.googlecode.com)
@@ -24,21 +25,47 @@
--
-- Notes:
--
-
-include jascii
-
+
; prototypes
-procedure _print_universal_dec(volatile byte out device, dword in data,
sdword in digit_divisor, byte in digit_number)
-procedure _print_suniversal_dec(volatile byte out device, sdword in data,
sdword in digit_divisor, byte in digit_number)
+
procedure print_byte_binary(volatile byte out device, byte in data)
+procedure _print_universal_dec (volatile byte out device, dword in data,
byte in digit_number, byte in decp)
+procedure _print_suniversal_dec (volatile byte out device, sdword in data,
byte in digit_number, byte in decp)
const byte nibble2hex[] = "0123456789ABCDEF" -- conversion string
-var bit print_prefix = false
+
+--
-----------------------------------------------------------------------------
+-- global vars
+--
-----------------------------------------------------------------------------
+
+var bit _print_signed
+var bit _print_overflow
+
+--
-----------------------------------------------------------------------------
+--
-----------------------------------------------------------------------------
+--procedure _write_digit(volatile byte out device, byte in digit, bit in
point) is
+
+-- _format_digit = digit
+-- if point then
+-- _write_real_digit(device)
+-- device = "."
+-- else
+ -- if _format_digit == 0 then device = _format_leader
+ -- else _write_real_digit(device)
+ -- end if
+ -- end if
+
+--end procedure
+--
-----------------------------------------------------------------------------
+
+
+
+
procedure print_crlf(volatile byte out device) is
- device = ASCII_CR -- cariage return
- device = ASCII_LF -- line feed
+ device = 13 -- ASCII CR (cariage return)
+ device = 10 -- ASCII LF (line feed)
end procedure
procedure print_string(volatile byte out device, byte in str[]) is
@@ -89,11 +116,6 @@
procedure print_dword_binary(volatile byte out device, dword in data) is
- if (print_prefix) then
- device = "0"
- device = "b"
- end if
-
print_byte_binary(device, byte(data>>24))
print_byte_binary(device, byte(data>>16))
print_byte_binary(device, byte(data>>8))
@@ -102,11 +124,6 @@
end procedure
procedure print_word_binary(volatile byte out device, word in data) is
-
- if (print_prefix) then
- device = "0"
- device = "b"
- end if
print_byte_binary(device, byte(data>>8))
print_byte_binary(device, byte(data))
@@ -115,12 +132,7 @@
procedure print_byte_binary(volatile byte out device, byte in data) is
- if (print_prefix) then
- device = "0"
- device = "b"
- end if
-
- for 8 loop
+ for 8 loop
if ((data & 0x80) != 0) then
device = "1"
else
@@ -133,12 +145,7 @@
end procedure
procedure print_dword_hex(volatile byte out device, dword in data) is
-
- if (print_prefix) then
- device = "0"
- device = "x"
- end if
-
+
device = nibble2hex[0x0F & (data>>28)]
device = nibble2hex[0x0F & (data>>24)]
device = nibble2hex[0x0F & (data>>20)]
@@ -151,11 +158,6 @@
end procedure
procedure print_word_hex(volatile byte out device, word in data) is
-
- if (print_prefix) then
- device = "0"
- device = "x"
- end if
device = nibble2hex[0x0F & (data>>12)]
device = nibble2hex[0x0F & (data>>8)]
@@ -164,89 +166,309 @@
end procedure
-procedure print_byte_hex(volatile byte out device, byte in data) is
-
- if (print_prefix) then
- device = "0"
- device = "x"
- end if
+procedure print_byte_hex(volatile byte out device, byte in data) is
device = nibble2hex[0x0F & (data>>4)]
device = nibble2hex[0x0F & (data)]
end procedure
-procedure print_sdword_dec(volatile byte out device, sdword in data) is
+procedure print_sdword_dec (volatile byte out device, sdword in data, byte
in digit_number, byte in decp) is
- _print_suniversal_dec(device, data, 1000000000, 10)
+ _print_suniversal_dec (device, data, digit_number, decp)
end procedure
-procedure print_sword_dec(volatile byte out device, sword in data) is
+procedure print_sword_dec(volatile byte out device, sword in data, byte in
digit_number, byte in decp) is
- _print_suniversal_dec(device, data, 10000, 5)
+ _print_suniversal_dec (device, data, digit_number, decp)
end procedure
-procedure print_sbyte_dec(volatile byte out device, sbyte in data) is
+procedure print_sbyte_dec(volatile byte out device, sbyte in data, byte in
digit_number, byte in decp) is
- _print_suniversal_dec(device, data, 100, 3)
+ _print_suniversal_dec (device, data, digit_number, decp)
end procedure
-procedure print_dword_dec(volatile byte out device, dword in data) is
+procedure print_dword_dec (volatile byte out device, dword in data, byte
in digit_number, byte in decp) is
+
+ _print_universal_dec (device, data, digit_number, decp)
+
+end procedure
+
- _print_universal_dec(device, data, 1000000000, 10)
+procedure print_word_dec(volatile byte out device, word in data, byte in
digit_number, byte in decp) is
+
+ _print_universal_dec (device, data, digit_number, decp)
end procedure
-procedure print_word_dec(volatile byte out device, word in data) is
- _print_universal_dec(device, data, 10000, 5)
+procedure print_byte_dec (volatile byte out device, byte in data, byte in
digit_number, byte in decp) is
+ _print_universal_dec (device, data, digit_number, decp)
+
end procedure
-procedure print_byte_dec(volatile byte out device, byte in data) is
+--
----------------------------------------------------------------------------
+procedure _print_suniversal_dec (volatile byte out device, sdword in data,
byte in digit_number, byte in decp) is
+
+ _print_signed = false
+
+ if (data < 0) then
+ data = -data
+ _print_signed = true
+ digit_number = digit_number - 1
+ end if
- _print_universal_dec(device, data, 100, 3)
+ _print_universal_dec (device, data, digit_number, decp)
end procedure
-procedure _print_suniversal_dec(volatile byte out device, sdword in data,
sdword in digit_divisor, byte in digit_number) is
-
- if (data < 0) then
- data = -data
- device = "-"
+--
----------------------------------------------------------------------------
+
+procedure _print_universal_dec (volatile byte out device, dword in data,
byte in digit_number, byte in decp) is
+ var dword max_value = 1
+ var dword max_value_dp = 1
+ var byte digit
+ var byte maxdigit = 0
+
+ var bit no_digits_printed_yet = true;
+ var bit dp_set = false
+
+
+ _print_overflow = false
+ maxdigit = digit_number
+
+
+ if (decp != 0) then
+ digit_number = digit_number - 1
+ else
+ dp_set = true
+ end if
+
+ for digit_number loop
+ max_value = max_value * 10
+ end loop
+
+ if data >= max_value then
+ _print_overflow = true
+ end if
+
+ if digit_number == 0 then
+ _print_overflow = true
+ maxdigit = 1
+ end if
+
+ if _print_overflow | (decp > maxdigit) then
+ for maxdigit loop
+ device = "#"
+ end loop
+ return
+ end if
+
+ if _print_signed then
+ device = "-"
+ _print_signed = false
+ end if
+
+ if (data == 0) then
+ device = "0"
+ for ( digit_number - 1) loop
+ device = " "
+ end loop
+ return
+ end if
+
+ for decp loop
+ max_value_dp = max_value_dp * 10
+ end loop
+
+ if data < max_value_dp then
+ device = "0"
+ no_digits_printed_yet = false
+ end if
+
+ while (max_value > 0) loop
+ if decp == digit_number & !dp_set then
+ device = "."
+ dp_set = true
+
+ else
+ digit = byte ( data / max_value )
+ data = data % max_value
+ max_value = max_value / 10
+ if ((digit != 0) | (no_digits_printed_yet ==
false)) then
+ device = digit | "0"
+ no_digits_printed_yet = false
+ digit_number = digit_number - 1
+ end if
+ end if
+ end loop
+
+ if digit_number > 0 then
+ for digit_number loop
+ device = " "
+ end loop
+ end if
+end procedure
+
+
+--
-----------------------------------------------------------------------------
+-- Displays a date in DD[seperator]MM[seperator]YY if YEAR < 99 and
day_mounth_notation = true
+-- or DD[seperator]MM[seperator]YYYY if YEAR > 99 and day_mounth_notation
= true
+-- or switches DD and MM if day_mounth_notation = false
+--
-----------------------------------------------------------------------------
+procedure print_date ( volatile byte out device, byte in day, byte in
mounth, word in year, byte in seperator, bit in day_mounth_notation ) is
+ var byte day_digit0 = 0 ;l
+ var byte day_digit1 = 0 ;10
+ var byte mounth_digit0 = 0 ;1
+ var byte mounth_digit1 = 0 ;10
+ var word year_digit0 = 0 ;1
+ var byte year_digit1 = 0 ;10
+ var byte year_digit2 = 0 ;100
+ var byte year_digit3 = 0 ;1000
+ var word year_mem = year
+
+
+ while day >= 10 loop
+ day_digit1 = day_digit1 + 1
+ day = day - 10
+ end loop
+ day_digit0 = day + 48
+ day_digit1 = day_digit1 + 48
+ while mounth >= 10 loop
+ mounth_digit1 = mounth_digit1 + 1
+ mounth = mounth - 10
+ end loop
+ mounth_digit0 = mounth +48
+ mounth_digit1 = mounth_digit1 + 48
+
+
+
+ while year >= 1000 loop
+ year_digit3 = year_digit3 + 1
+ year = year - 1000
+ end loop
+
+ while year >= 100 loop
+ year_digit2 = year_digit2 + 1
+ year = year - 100
+ end loop
+
+ while year >= 10 loop
+ year_digit1 = year_digit1 + 1
+ year = year - 10
+ end loop
+ year_digit3 = year_digit3 + 48
+ year_digit2 = year_digit2 + 48
+ year_digit1 = year_digit1 + 48
+ year_digit0 = year + 48
+
+
+ if !day_mounth_notation then
+ device = mounth_digit1
+ device = mounth_digit0
+ device = seperator
+ device = day_digit1
+ device = day_digit0
+ device = seperator
+ else
+ device = day_digit1
+ device = day_digit0
+ device = seperator
+ device = mounth_digit1
+ device = mounth_digit0
+ device = seperator
end if
- _print_universal_dec(device, data, digit_divisor, digit_number)
-
+ if year_mem > 99 then
+ device = year_digit3
+ device = year_digit2
+ else
+ device = "'"
+ end if
+
+ device = year_digit1
+ device = year_digit0
+
end procedure
+--
----------------------------------------------------------------------------
-procedure _print_universal_dec(volatile byte out device, dword in data,
sdword in digit_divisor, byte in digit_number) is
- var byte digit
- var bit no_digits_printed_yet;
-
- if (data == 0) then
- device = "0"
- return
- end if
+--
-----------------------------------------------------------------------------
+-- Displays a time in HH:MM notation at specified position
+-- Hours and minutes are specified separate
+--
-----------------------------------------------------------------------------
+procedure print_time_hm(volatile byte out device,byte in HH, byte in MM) is
+ var byte D10
- no_digits_printed_yet = true
- while (digit_divisor > 0) loop
- digit = byte ( data / digit_divisor )
- data = data % digit_divisor
- digit_divisor = digit_divisor / 10
-
- if ((digit != 0) | (no_digits_printed_yet == false)) then
- device = digit | "0"
- no_digits_printed_yet = false
- end if
- digit_number = digit_number - 1
- end loop
-
+ D10 = HH / 10
+ HH = HH % 10
+
+ -- always dsiplay Zeroes
+ device = "0" + D10
+ device = "0" + HH
+ device = ":"
+
+ D10 = MM / 10
+ MM = MM % 10
+
+ device = "0" + D10
+ device = "0" + MM
+end procedure
+--
-----------------------------------------------------------------------------
+
+--
-----------------------------------------------------------------------------
+-- Displays a time in HH:MM:SS notation at specified position
+-- Hours and minutes and secounds are specified separate
+--
-----------------------------------------------------------------------------
+procedure print_time_hms(volatile byte out device,byte in HH, byte in MM,
byte in SS) is
+ var byte D10
+
+ D10 = HH / 10
+ HH = HH % 10
+
+ -- always display Zeroes
+ device = "0" + D10
+ device = "0" + HH
+ device = ":"
+
+ D10 = MM / 10
+ MM = MM % 10
+
+ device = "0" + D10
+ device = "0" + MM
+ device = ":"
+
+ D10 = SS / 10
+ SS = SS % 10
+
+ device = "0" + D10
+ device = "0" + SS
+end procedure
+--
-----------------------------------------------------------------------------
+
+
+--
-----------------------------------------------------------------------------
+-- Displays a time in HH:MM notation at specified position
+-- the input is specified in minutes
+--
-----------------------------------------------------------------------------
+procedure print_time_hm_word(volatile byte out device,word in minutes) is
+ var byte D10
+ var byte HH
+ var byte MM
+
+ HH = byte(minutes / 60)
+ MM = byte(minutes % 60)
+ HH = HH % 24
+
+ print_time_hm(device, HH, MM)
end procedure
+--
-----------------------------------------------------------------------------
+
+
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---