Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Signed-off-by: Meir Tsvi <meir.tsvi@live.com>

  • Loading branch information...
commit 82edb5be1ec457ffae0729265bdeff209158d1fb 1 parent 9c72776
@meirtsvi authored
Showing with 10,557 additions and 0 deletions.
  1. +1 −0  HEAD
  2. +22 −0 WazeWP7/AboutDialog.xaml
  3. +32 −0 WazeWP7/AboutDialog.xaml.cs
  4. +19 −0 WazeWP7/App.xaml
  5. +142 −0 WazeWP7/App.xaml.cs
  6. +394 −0 WazeWP7/AsyncNet.cs
  7. +378 −0 WazeWP7/BLUElet.java
  8. +616 −0 WazeWP7/CRunTime.cs
  9. +565 −0 WazeWP7/CRunTime.java
  10. +158 −0 WazeWP7/CRunTimeMemoryInputStream.cs
  11. +3,564 −0 WazeWP7/CibylCallTable.cs
  12. +36 −0 WazeWP7/CibylConfig.cs
  13. +165 −0 WazeWP7/ConfirmDialog.java
  14. +49 −0 WazeWP7/DeviceSpecific.java
  15. +171 −0 WazeWP7/EditBoxScreen.java
  16. +18 −0 WazeWP7/FileConnection.cs
  17. +44 −0 WazeWP7/FreeMapMainScreen.xaml
  18. +1,248 −0 WazeWP7/FreeMapMainScreen.xaml.cs
  19. +867 −0 WazeWP7/FreemapApp.cs
  20. +236 −0 WazeWP7/GpsBT.java
  21. +181 −0 WazeWP7/GpsCellId.java
  22. +16 −0 WazeWP7/GpsIntr.java
  23. +352 −0 WazeWP7/GpsLocation.java
  24. +299 −0 WazeWP7/GpsManager.cs
  25. +227 −0 WazeWP7/GpsManager.cs.bak
  26. +27 −0 WazeWP7/InputDialog.xaml
  27. +81 −0 WazeWP7/InputDialog.xaml.cs
  28. +38 −0 WazeWP7/Logger.cs
  29. +101 −0 WazeWP7/MessageBoxFactory.cs
  30. +140 −0 WazeWP7/PopupScreenButton.java
  31. +16 −0 WazeWP7/ProgressDialog.xaml
  32. +61 −0 WazeWP7/ProgressDialog.xaml.cs
  33. +6 −0 WazeWP7/Properties/AppManifest.xml
  34. +35 −0 WazeWP7/Properties/AssemblyInfo.cs
  35. +31 −0 WazeWP7/Properties/WMAppManifest.xml
  36. +108 −0 WazeWP7/RecordStore.cs
  37. +23 −0 WazeWP7/RecordStoreException.cs
  38. +74 −0 WazeWP7/RemoteDeviceUI.java
  39. BIN  WazeWP7/Resources/1_route.bin
  40. BIN  WazeWP7/Resources/1_route.png
  41. BIN  WazeWP7/Resources/2_route.bin
  42. BIN  WazeWP7/Resources/2_route.png
  43. BIN  WazeWP7/Resources/3_route.bin
  44. BIN  WazeWP7/Resources/3_route.png
  45. BIN  WazeWP7/Resources/77001_index.wdf
  46. BIN  WazeWP7/Resources/ApplicationIcon.png
  47. BIN  WazeWP7/Resources/Arrow.bin
  48. BIN  WazeWP7/Resources/Arrow.png
  49. BIN  WazeWP7/Resources/Bubble_01.bin
  50. BIN  WazeWP7/Resources/Bubble_01.png
  51. BIN  WazeWP7/Resources/Bubble_02.bin
  52. BIN  WazeWP7/Resources/Bubble_02.png
  53. BIN  WazeWP7/Resources/CrossHair.bin
  54. BIN  WazeWP7/Resources/CrossHair.png
  55. BIN  WazeWP7/Resources/Departure.bin
  56. BIN  WazeWP7/Resources/Departure.png
  57. BIN  WazeWP7/Resources/Destination.bin
  58. BIN  WazeWP7/Resources/Destination.png
  59. BIN  WazeWP7/Resources/Header_Black_Mid.bin
  60. BIN  WazeWP7/Resources/Header_Black_Mid.png
  61. BIN  WazeWP7/Resources/Header_Black_left.bin
  62. BIN  WazeWP7/Resources/Header_Black_left.png
  63. BIN  WazeWP7/Resources/Header_Black_right.bin
  64. BIN  WazeWP7/Resources/Header_Black_right.png
  65. BIN  WazeWP7/Resources/Info.bin
  66. BIN  WazeWP7/Resources/Info.png
  67. BIN  WazeWP7/Resources/LOL-female.bin
  68. BIN  WazeWP7/Resources/LOL-female.png
  69. BIN  WazeWP7/Resources/LOL.bin
  70. BIN  WazeWP7/Resources/LOL.png
  71. BIN  WazeWP7/Resources/On_map_anonymous.bin
  72. BIN  WazeWP7/Resources/On_map_anonymous.png
  73. BIN  WazeWP7/Resources/On_map_nickname.bin
  74. BIN  WazeWP7/Resources/On_map_nickname.png
  75. BIN  WazeWP7/Resources/PointerComment.bin
  76. BIN  WazeWP7/Resources/PointerComment.png
  77. BIN  WazeWP7/Resources/PointerMenu.bin
  78. BIN  WazeWP7/Resources/PointerMenu.png
  79. BIN  WazeWP7/Resources/RT0Stars.bin
  80. BIN  WazeWP7/Resources/RT0Stars.png
  81. BIN  WazeWP7/Resources/RT1Star.bin
  82. BIN  WazeWP7/Resources/RT1Star.png
  83. BIN  WazeWP7/Resources/RT2Stars.bin
  84. BIN  WazeWP7/Resources/RT2Stars.png
  85. BIN  WazeWP7/Resources/RT3Stars.bin
  86. BIN  WazeWP7/Resources/RT3Stars.png
  87. BIN  WazeWP7/Resources/RT4Stars.bin
  88. BIN  WazeWP7/Resources/RT4Stars.png
  89. BIN  WazeWP7/Resources/RT5Stars.bin
  90. BIN  WazeWP7/Resources/RT5Stars.png
  91. BIN  WazeWP7/Resources/SUV.bin
  92. BIN  WazeWP7/Resources/SUV.png
  93. BIN  WazeWP7/Resources/SearchBox_left.bin
  94. BIN  WazeWP7/Resources/SearchBox_left.png
  95. BIN  WazeWP7/Resources/SearchBox_middle.bin
  96. BIN  WazeWP7/Resources/SearchBox_middle.png
  97. BIN  WazeWP7/Resources/SearchBox_right.bin
  98. BIN  WazeWP7/Resources/SearchBox_right.png
  99. BIN  WazeWP7/Resources/Selection.bin
  100. BIN  WazeWP7/Resources/Selection.png
  101. BIN  WazeWP7/Resources/TS_top_mood_baby.bin
  102. BIN  WazeWP7/Resources/TS_top_mood_baby.png
  103. BIN  WazeWP7/Resources/Tweeter-logo.bin
  104. BIN  WazeWP7/Resources/Tweeter-logo.png
  105. BIN  WazeWP7/Resources/Txtbox_left.bin
  106. BIN  WazeWP7/Resources/Txtbox_left.png
  107. BIN  WazeWP7/Resources/Txtbox_left_selected.bin
  108. BIN  WazeWP7/Resources/Txtbox_left_selected.png
  109. BIN  WazeWP7/Resources/Txtbox_middle.bin
  110. BIN  WazeWP7/Resources/Txtbox_middle.png
  111. BIN  WazeWP7/Resources/Txtbox_middle_selected.bin
  112. BIN  WazeWP7/Resources/Txtbox_middle_selected.png
  113. BIN  WazeWP7/Resources/Txtbox_right.bin
  114. BIN  WazeWP7/Resources/Txtbox_right.png
  115. BIN  WazeWP7/Resources/Txtbox_right_selected.bin
  116. BIN  WazeWP7/Resources/Txtbox_right_selected.png
  117. BIN  WazeWP7/Resources/about.bin
  118. BIN  WazeWP7/Resources/about.png
  119. BIN  WazeWP7/Resources/alert_icon_accident.bin
  120. BIN  WazeWP7/Resources/alert_icon_accident.png
  121. BIN  WazeWP7/Resources/alert_icon_addon_comment.bin
  122. BIN  WazeWP7/Resources/alert_icon_addon_comment.png
  123. BIN  WazeWP7/Resources/alert_icon_addon_twitter.bin
  124. BIN  WazeWP7/Resources/alert_icon_addon_twitter.png
  125. BIN  WazeWP7/Resources/alert_icon_addon_user.bin
  126. BIN  WazeWP7/Resources/alert_icon_addon_user.png
  127. BIN  WazeWP7/Resources/alert_icon_addon_waze.bin
  128. BIN  WazeWP7/Resources/alert_icon_addon_waze.png
  129. BIN  WazeWP7/Resources/alert_icon_chit_chat.bin
  130. BIN  WazeWP7/Resources/alert_icon_chit_chat.png
  131. BIN  WazeWP7/Resources/alert_icon_hazard.bin
  132. BIN  WazeWP7/Resources/alert_icon_hazard.png
  133. BIN  WazeWP7/Resources/alert_icon_other.bin
  134. BIN  WazeWP7/Resources/alert_icon_other.png
  135. BIN  WazeWP7/Resources/alert_icon_police.bin
  136. BIN  WazeWP7/Resources/alert_icon_police.png
  137. BIN  WazeWP7/Resources/alert_icon_road_construction.bin
  138. BIN  WazeWP7/Resources/alert_icon_road_construction.png
  139. BIN  WazeWP7/Resources/alert_icon_traffic_info.bin
  140. BIN  WazeWP7/Resources/alert_icon_traffic_info.png
  141. BIN  WazeWP7/Resources/alert_icon_traffic_jam.bin
  142. BIN  WazeWP7/Resources/alert_icon_traffic_jam.png
  143. BIN  WazeWP7/Resources/alert_marker_small.bin
  144. BIN  WazeWP7/Resources/alert_marker_small.png
  145. BIN  WazeWP7/Resources/alert_pin_accident.bin
  146. BIN  WazeWP7/Resources/alert_pin_accident.png
  147. BIN  WazeWP7/Resources/alert_pin_addon_attachment.bin
  148. BIN  WazeWP7/Resources/alert_pin_addon_attachment.png
  149. BIN  WazeWP7/Resources/alert_pin_addon_comment.bin
  150. BIN  WazeWP7/Resources/alert_pin_addon_comment.png
  151. BIN  WazeWP7/Resources/alert_pin_addon_twitter.bin
  152. BIN  WazeWP7/Resources/alert_pin_addon_twitter.png
  153. BIN  WazeWP7/Resources/alert_pin_chit_chat.bin
  154. BIN  WazeWP7/Resources/alert_pin_chit_chat.png
  155. BIN  WazeWP7/Resources/alert_pin_hazard.bin
  156. BIN  WazeWP7/Resources/alert_pin_hazard.png
  157. BIN  WazeWP7/Resources/alert_pin_loads.bin
  158. BIN  WazeWP7/Resources/alert_pin_loads.png
  159. BIN  WazeWP7/Resources/alert_pin_other.bin
  160. BIN  WazeWP7/Resources/alert_pin_other.png
  161. BIN  WazeWP7/Resources/alert_pin_parking.bin
  162. BIN  WazeWP7/Resources/alert_pin_parking.png
  163. BIN  WazeWP7/Resources/alert_pin_police.bin
  164. BIN  WazeWP7/Resources/alert_pin_police.png
  165. BIN  WazeWP7/Resources/alert_pin_road_construction.bin
  166. BIN  WazeWP7/Resources/alert_pin_road_construction.png
  167. +13 −0 WazeWP7/Resources/alerts.menu
  168. +3 −0  WazeWP7/Resources/alerts_offline.menu
  169. BIN  WazeWP7/Resources/all.bin
  170. BIN  WazeWP7/Resources/all.png
  171. BIN  WazeWP7/Resources/all_routes.bin
  172. BIN  WazeWP7/Resources/all_routes.png
  173. BIN  WazeWP7/Resources/attachment.bin
  174. BIN  WazeWP7/Resources/attachment.png
  175. BIN  WazeWP7/Resources/attachment_white.bin
  176. BIN  WazeWP7/Resources/attachment_white.png
  177. BIN  WazeWP7/Resources/battery_0.bin
  178. BIN  WazeWP7/Resources/battery_0.png
  179. BIN  WazeWP7/Resources/battery_1.bin
  180. BIN  WazeWP7/Resources/battery_1.png
  181. BIN  WazeWP7/Resources/battery_2.bin
  182. BIN  WazeWP7/Resources/battery_2.png
  183. BIN  WazeWP7/Resources/battery_3.bin
  184. BIN  WazeWP7/Resources/battery_3.png
  185. BIN  WazeWP7/Resources/battery_4.bin
  186. BIN  WazeWP7/Resources/battery_4.png
  187. BIN  WazeWP7/Resources/battery_charging.bin
  188. BIN  WazeWP7/Resources/battery_charging.png
  189. BIN  WazeWP7/Resources/beetle.bin
  190. BIN  WazeWP7/Resources/beetle.png
  191. BIN  WazeWP7/Resources/border_black_bottom.bin
  192. BIN  WazeWP7/Resources/border_black_bottom.png
  193. BIN  WazeWP7/Resources/border_black_bottom_left.bin
  194. BIN  WazeWP7/Resources/border_black_bottom_left.png
  195. BIN  WazeWP7/Resources/border_black_bottom_no_frame.bin
  196. BIN  WazeWP7/Resources/border_black_bottom_no_frame.png
  197. BIN  WazeWP7/Resources/border_black_bottom_right.bin
  198. BIN  WazeWP7/Resources/border_black_bottom_right.png
  199. BIN  WazeWP7/Resources/border_black_left.bin
  200. BIN  WazeWP7/Resources/border_black_left.png
  201. BIN  WazeWP7/Resources/border_black_right.bin
  202. BIN  WazeWP7/Resources/border_black_right.png
  203. BIN  WazeWP7/Resources/border_black_top.bin
  204. BIN  WazeWP7/Resources/border_black_top.png
  205. BIN  WazeWP7/Resources/border_black_top_left.bin
  206. BIN  WazeWP7/Resources/border_black_top_left.png
  207. BIN  WazeWP7/Resources/border_black_top_right.bin
  208. BIN  WazeWP7/Resources/border_black_top_right.png
  209. BIN  WazeWP7/Resources/border_white_bottom.bin
  210. BIN  WazeWP7/Resources/border_white_bottom.png
  211. BIN  WazeWP7/Resources/border_white_bottom_left.bin
  212. BIN  WazeWP7/Resources/border_white_bottom_left.png
  213. BIN  WazeWP7/Resources/border_white_bottom_right.bin
  214. BIN  WazeWP7/Resources/border_white_bottom_right.png
  215. BIN  WazeWP7/Resources/border_white_left.bin
  216. BIN  WazeWP7/Resources/border_white_left.png
  217. BIN  WazeWP7/Resources/border_white_right.bin
  218. BIN  WazeWP7/Resources/border_white_right.png
  219. BIN  WazeWP7/Resources/border_white_top.bin
  220. BIN  WazeWP7/Resources/border_white_top.png
  221. BIN  WazeWP7/Resources/border_white_top_left.bin
  222. BIN  WazeWP7/Resources/border_white_top_left.png
  223. BIN  WazeWP7/Resources/border_white_top_right.bin
  224. BIN  WazeWP7/Resources/border_white_top_right.png
  225. BIN  WazeWP7/Resources/bored-female.bin
  226. BIN  WazeWP7/Resources/bored-female.png
  227. BIN  WazeWP7/Resources/bored.bin
  228. BIN  WazeWP7/Resources/bored.png
  229. BIN  WazeWP7/Resources/bottom_bar_background.bin
  230. BIN  WazeWP7/Resources/bottom_bar_background.png
  231. BIN  WazeWP7/Resources/bus.bin
  232. BIN  WazeWP7/Resources/bus.png
  233. BIN  WazeWP7/Resources/busy-female.bin
  234. BIN  WazeWP7/Resources/busy-female.png
  235. BIN  WazeWP7/Resources/busy.bin
  236. BIN  WazeWP7/Resources/busy.png
  237. BIN  WazeWP7/Resources/button_down.bin
  238. BIN  WazeWP7/Resources/button_down.png
  239. BIN  WazeWP7/Resources/button_image_attachment_down.bin
  240. BIN  WazeWP7/Resources/button_image_attachment_down.png
  241. BIN  WazeWP7/Resources/button_image_attachment_up.bin
  242. BIN  WazeWP7/Resources/button_image_attachment_up.png
  243. BIN  WazeWP7/Resources/button_meters.bin
  244. BIN  WazeWP7/Resources/button_meters.png
  245. BIN  WazeWP7/Resources/button_miles.bin
  246. BIN  WazeWP7/Resources/button_miles.png
  247. BIN  WazeWP7/Resources/button_up.bin
  248. BIN  WazeWP7/Resources/button_up.png
  249. BIN  WazeWP7/Resources/cancel.png
  250. BIN  WazeWP7/Resources/car_blue.bin
  251. BIN  WazeWP7/Resources/car_blue.png
  252. BIN  WazeWP7/Resources/car_gray.bin
  253. BIN  WazeWP7/Resources/car_gray.png
  254. BIN  WazeWP7/Resources/car_green.bin
  255. BIN  WazeWP7/Resources/car_green.png
  256. BIN  WazeWP7/Resources/car_race.bin
  257. BIN  WazeWP7/Resources/car_race.png
  258. BIN  WazeWP7/Resources/car_red.bin
  259. BIN  WazeWP7/Resources/car_red.png
  260. BIN  WazeWP7/Resources/car_yellow.bin
  261. BIN  WazeWP7/Resources/car_yellow.png
  262. BIN  WazeWP7/Resources/checkbox_off.bin
  263. BIN  WazeWP7/Resources/checkbox_off.png
  264. BIN  WazeWP7/Resources/checkbox_on.bin
  265. BIN  WazeWP7/Resources/checkbox_on.png
  266. BIN  WazeWP7/Resources/compas.png
  267. BIN  WazeWP7/Resources/compass_bg.bin
  268. BIN  WazeWP7/Resources/compass_bg.png
  269. BIN  WazeWP7/Resources/container_bg.bin
  270. BIN  WazeWP7/Resources/container_bg.png
  271. BIN  WazeWP7/Resources/container_bg_night.bin
  272. BIN  WazeWP7/Resources/container_bg_night.png
  273. BIN  WazeWP7/Resources/context_menu_popup_left.bin
  274. BIN  WazeWP7/Resources/context_menu_popup_left.png
  275. BIN  WazeWP7/Resources/context_menu_popup_right.bin
  276. BIN  WazeWP7/Resources/context_menu_popup_right.png
  277. BIN  WazeWP7/Resources/cool-female.bin
  278. BIN  WazeWP7/Resources/cool-female.png
  279. BIN  WazeWP7/Resources/cool.bin
  280. BIN  WazeWP7/Resources/cool.png
  281. BIN  WazeWP7/Resources/crown.bin
  282. BIN  WazeWP7/Resources/crown.png
  283. BIN  WazeWP7/Resources/cursor.bin
  284. BIN  WazeWP7/Resources/cursor.png
  285. BIN  WazeWP7/Resources/default_checkbox_off.bin
  286. BIN  WazeWP7/Resources/default_checkbox_off.png
  287. BIN  WazeWP7/Resources/default_checkbox_on.bin
  288. BIN  WazeWP7/Resources/default_checkbox_on.png
  289. BIN  WazeWP7/Resources/default_day_1_schema_j2me
  290. BIN  WazeWP7/Resources/default_day_2_schema_j2me
  291. BIN  WazeWP7/Resources/default_day_3_schema_j2me
  292. BIN  WazeWP7/Resources/default_day_4_schema_j2me
  293. BIN  WazeWP7/Resources/default_day_5_schema_j2me
  294. BIN  WazeWP7/Resources/default_day_6_schema_j2me
  295. BIN  WazeWP7/Resources/default_day_schema_j2me
  296. BIN  WazeWP7/Resources/default_night_schema_j2me
  297. BIN  WazeWP7/Resources/detectreceiver.bin
  298. BIN  WazeWP7/Resources/detectreceiver.png
  299. BIN  WazeWP7/Resources/edit_left.bin
  300. BIN  WazeWP7/Resources/edit_left.png
Sorry, we could not display the entire diff because too many files (4,462) changed.
View
1  HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
View
22 WazeWP7/AboutDialog.xaml
@@ -0,0 +1,22 @@
+<UserControl x:Class="WazeWP7.AboutDialog"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d"
+ FontFamily="{StaticResource PhoneFontFamilyNormal}"
+ FontSize="{StaticResource PhoneFontSizeNormal}"
+ Foreground="{StaticResource PhoneForegroundBrush}"
+ d:DesignHeight="334" d:DesignWidth="458">
+
+ <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Height="333" Width="456">
+ <TextBlock Height="35" HorizontalAlignment="Center" Margin="139,12,181,0" Name="textBlock1" Text="Waze for WP7" VerticalAlignment="Top" Width="136" FontFamily="Segoe WP Bold" TextAlignment="Center" />
+ <TextBlock Height="30" HorizontalAlignment="Center" Margin="93,102,88,0" Name="textBlock2" Text="Ported to WP7 by Meir Tsvi" VerticalAlignment="Top" FontFamily="Segoe WP" Width="275" />
+ <TextBlock Height="32" HorizontalAlignment="Center" Margin="47,147,41,0" Name="textBlock3" Text="Uses Cibyl, NBidi, SharpBox, ZlibWP7 libs" VerticalAlignment="Top" Width="368" FontFamily="Segoe WP" />
+ <TextBlock Height="30" HorizontalAlignment="Center" Margin="97,202,87,0" Name="textBlock4" Text="Refer any support questions to" VerticalAlignment="Top" FontFamily="Segoe WP" />
+ <TextBlock Height="30" HorizontalAlignment="Center" Margin="137,239,155,0" Name="textBlock5" Text="meir.tsvi@live.com" VerticalAlignment="Top" FontFamily="Segoe WP" TextAlignment="Center" />
+ <TextBlock Height="24" HorizontalAlignment="Right" Margin="0,54,220,0" Name="textBlock6" Text="Version:" VerticalAlignment="Top" Width="90" FontFamily="Segoe WP" />
+ <TextBlock Height="30" HorizontalAlignment="Right" Margin="0,54,145,0" Name="Version" Text="{Binding}" VerticalAlignment="Top" Width="93" FontFamily="Segoe WP" />
+ <Button Content="OK" Height="59" HorizontalAlignment="Left" Margin="133,274,0,0" Name="button1" VerticalAlignment="Top" Width="171" FontSize="16" Click="button1_Click" />
+ </Grid>
+</UserControl>
View
32 WazeWP7/AboutDialog.xaml.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+
+namespace WazeWP7
+{
+ public partial class AboutDialog : UserControl
+ {
+ public AboutDialog()
+ {
+ InitializeComponent();
+ }
+
+ public void SetVersion(string version)
+ {
+ Version.Text = version;
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+ FreeMapMainScreen.get().LayoutRoot.Children.Remove(this);
+ }
+ }
+}
View
19 WazeWP7/App.xaml
@@ -0,0 +1,19 @@
+<Application
+ x:Class="WazeWP7.App"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
+ xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
+
+ <!--Application Resources-->
+ <Application.Resources>
+ </Application.Resources>
+
+ <Application.ApplicationLifetimeObjects>
+ <!--Required object that handles lifetime events for the application-->
+ <shell:PhoneApplicationService
+ Launching="Application_Launching" Closing="Application_Closing"
+ Activated="Application_Activated" Deactivated="Application_Deactivated"/>
+ </Application.ApplicationLifetimeObjects>
+
+</Application>
View
142 WazeWP7/App.xaml.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+
+namespace WazeWP7
+{
+ public partial class App : Application
+ {
+ /// <summary>
+ /// Provides easy access to the root frame of the Phone Application.
+ /// </summary>
+ /// <returns>The root frame of the Phone Application.</returns>
+ public PhoneApplicationFrame RootFrame { get; private set; }
+
+ /// <summary>
+ /// Constructor for the Application object.
+ /// </summary>
+ public App()
+ {
+ // Global handler for uncaught exceptions.
+ UnhandledException += Application_UnhandledException;
+
+ // Show graphics profiling information while debugging.
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // Display the current frame rate counters.
+ Application.Current.Host.Settings.EnableFrameRateCounter = true;
+
+ // Show the areas of the app that are being redrawn in each frame.
+ //Application.Current.Host.Settings.EnableRedrawRegions = true;
+
+ // Enable non-production analysis visualization mode,
+ // which shows areas of a page that are being GPU accelerated with a colored overlay.
+ //Application.Current.Host.Settings.EnableCacheVisualization = true;
+ }
+
+ // Standard Silverlight initialization
+ InitializeComponent();
+
+ // Phone-specific initialization
+ InitializePhoneApplication();
+ }
+
+ // Code to execute when the application is launching (eg, from Start)
+ // This code will not execute when the application is reactivated
+ private void Application_Launching(object sender, LaunchingEventArgs e)
+ {
+// IsolatedStorageExplorer.Explorer.Start("meir-pc");
+ }
+
+ // Code to execute when the application is activated (brought to foreground)
+ // This code will not execute when the application is first launched
+ private void Application_Activated(object sender, ActivatedEventArgs e)
+ {
+// IsolatedStorageExplorer.Explorer.RestoreFromTombstone();
+ }
+
+ // Code to execute when the application is deactivated (sent to background)
+ // This code will not execute when the application is closing
+ private void Application_Deactivated(object sender, DeactivatedEventArgs e)
+ {
+ }
+
+ // Code to execute when the application is closing (eg, user hit Back)
+ // This code will not execute when the application is deactivated
+ private void Application_Closing(object sender, ClosingEventArgs e)
+ {
+ }
+
+ // Code to execute if a navigation fails
+ private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // A navigation has failed; break into the debugger
+ System.Diagnostics.Debugger.Break();
+
+ }
+
+// MessageBox.Show(string.Format("Page {0} failed to load because of with error: {1}", e.Uri.ToString(), e.Exception.StackTrace)); e.Handled = true;
+ }
+
+ // Code to execute on Unhandled Exceptions
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
+ {
+ if (System.Diagnostics.Debugger.IsAttached)
+ {
+ // An unhandled exception has occurred; break into the debugger
+ System.Diagnostics.Debugger.Break();
+ }
+
+// MessageBox.Show(string.Format("Page {0} failed to load because of with error: {1}", e.ExceptionObject)); e.Handled = true;
+ }
+
+ #region Phone application initialization
+
+ // Avoid double-initialization
+ private bool phoneApplicationInitialized = false;
+
+ // Do not add any additional code to this method
+ private void InitializePhoneApplication()
+ {
+ if (phoneApplicationInitialized)
+ return;
+
+ // Create the frame but don't set it as RootVisual yet; this allows the splash
+ // screen to remain active until the application is ready to render.
+ RootFrame = new PhoneApplicationFrame();
+ RootFrame.Navigated += CompleteInitializePhoneApplication;
+
+ // Handle navigation failures
+ RootFrame.NavigationFailed += RootFrame_NavigationFailed;
+
+ // Ensure we don't initialize again
+ phoneApplicationInitialized = true;
+ }
+
+ // Do not add any additional code to this method
+ private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
+ {
+ // Set the root visual to allow the application to render
+ if (RootVisual != RootFrame)
+ RootVisual = RootFrame;
+
+ // Remove this handler since it is no longer needed
+ RootFrame.Navigated -= CompleteInitializePhoneApplication;
+ }
+
+ #endregion
+ }
+}
View
394 WazeWP7/AsyncNet.cs
@@ -0,0 +1,394 @@
+using System;
+using System.IO;
+using System.Threading;
+using System.Collections;
+using System.Net;
+using System.Collections;
+using System.Collections.Generic;
+
+/*
+ * This class implements the Networking, along with roadmap_net.c
+ * Each AsyncNet object represents a different connection to a different url.
+ * The Networking is run through a queue of AsyncNet objects, and run in its own thread.
+ * The header string is not received directly but through an API, so we get the relevant
+ * header parts manually, and then create a header string to send to C. ( C expects
+ * a complete header string to parse ).
+ *
+ * After the socket connection is made, we call the the c function
+ * do_async_connect_cb, and after we finished reading we call the "roadmap_main_input_ready function.
+ *
+ */
+public class AsyncNet : UIWorker.ValidityCheck
+{
+
+ private static int c_do_async_connect_cb;
+ private static int c_input_ready_cb;
+
+ private string url;
+ private string updateTime;
+ private int method;
+ private WebRequest conn;
+ private Stream Stream;
+ private int cb_addr;
+ private int context;
+
+ private int input_id = -1;
+ private byte[] buffer;
+ private int buffer_cur_ptr;
+ private int buffer_len;
+
+ private bool quit = false;
+ private bool eof = false;
+ private bool do_read = false;
+ private bool is_valid = true;
+
+
+
+ private static NetQueue queue;
+
+ public AsyncNet(string url, int method, string updateTime,
+ int cb_addr, int context)
+ {
+ this.url = url;
+ this.method = method;
+ this.updateTime = updateTime;
+ this.cb_addr = cb_addr;
+ this.context = context;
+
+ try
+ {
+ if (c_do_async_connect_cb == 0)
+ {
+ c_do_async_connect_cb = CibylCallTable.getAddressByName("do_async_connect_cb");
+ c_input_ready_cb = CibylCallTable.getAddressByName("roadmap_main_input_ready");
+ }
+ }
+ catch (Exception e)
+ {
+ Logger.log("Exception in do_async_connect_cb: " + e);
+
+ throw; //todomt
+ //Environment.Exit(0);
+
+ }
+
+ if (queue == null)
+ {
+ // assumes that this is called async
+ queue = new NetQueue();
+ queue.init();
+ }
+
+ queue.add(this);
+ }
+
+ public bool isValid()
+ {
+ return is_valid;
+ }
+
+ static HttpWebResponse resp = null;
+ static ManualResetEvent http_response_sync = new ManualResetEvent(false);
+ public void runNetLoop()
+ {
+ int registeredHandle = 0;
+ try
+ {
+ conn = HttpWebRequest.Create(url);//todomt (HttpConnection)Connector.open(url);
+ //System.Net.ServicePointManager.Expect100Continue = false;
+
+ if (method == 0) conn.Method = "GET";
+ else conn.Method = "POST";
+
+ /* todomt
+ if (updateTime != null) {
+ conn.setRequestProperty("If-Modified-Since", updateTime);
+ }
+ */
+
+ registeredHandle = CRunTime.registerObject(conn);
+
+ }
+ catch (Exception e)
+ {
+ quit = true;
+ Logger.log(e.ToString());
+ UIWorker.addUIEventLog("Async Net : Exception opening URL " + e);
+ }
+
+ int handle = registeredHandle;
+
+ UIWorker.addUIEventValid(c_do_async_connect_cb, handle, cb_addr, context, 0, false, this);
+ if (quit) return;
+
+ while (!quit)
+ {
+ lock (conn)
+ {
+ if (!do_read)
+ {
+ try
+ {
+ Monitor.Wait(conn);
+ }
+ catch (SynchronizationLockException e)
+ {
+ }
+ if (quit) return;
+ if (!do_read) continue;
+ }
+ }
+
+ try
+ {
+ if (Stream == null)
+ {
+ resp = null;
+ try
+ {
+ http_response_sync.Reset();
+ conn.BeginGetResponse(delegate(IAsyncResult result)
+ {
+ try
+ {
+ Logger.log("downloading " + conn.RequestUri);
+ resp = (HttpWebResponse)conn.EndGetResponse(result);
+ http_response_sync.Set();
+ }
+ catch (WebException we)
+ {
+ resp = null;
+ http_response_sync.Set();
+ }
+ catch (NotSupportedException nse)
+ {
+ resp = null;
+ http_response_sync.Set();
+ }
+ }, null);
+ }
+ catch (InvalidOperationException ioe)
+ {
+ resp = null;
+ http_response_sync.Set();
+ }
+
+ http_response_sync.WaitOne();
+
+ if (resp != null)
+ {
+ Stream = resp.GetResponseStream();
+ int status = (int)resp.StatusCode;
+ long data_size = resp.ContentLength;
+ string lastModifiedStr = resp.Headers["Last-Modified"];
+ //Logger.log("Java header, s is " + lastModifiedStr);
+
+ /*
+ * We need to send c a complete header string, so we fake it by creating the
+ * res string. More header fields can be added later on besides the content length and last-modified
+ *
+ */
+ string res = "HTTP/1.1 " + status + " OK\r\nContent-Length: " + data_size + "\r\n";
+ if (lastModifiedStr != null)
+ res += "Last-Modified:" + lastModifiedStr + "\r\n\r\n";
+ else
+ res += "\r\n";
+
+ buffer = new byte[4096];
+ byte[] res_bytes = Syscalls.StringToAscii(res);
+ res_bytes.CopyTo(buffer, 0);
+ buffer_len = res_bytes.Length;
+ buffer_cur_ptr = 0;
+ }
+ else
+ {
+ //buffer = new byte[4096];
+ string res = "HTTP/1.1 404 Not Found\r\n";
+ /*byte[] res_bytes*/buffer = Syscalls.StringToAscii(res);
+ //res_bytes.CopyTo(buffer, 0);
+ buffer_len = /*res_bytes.Length;*/buffer.Length;
+ buffer_cur_ptr = 0;
+ do_read = false;
+ }
+ }
+ else
+ {
+ if (buffer_cur_ptr == buffer_len)
+ {
+ buffer_len = Stream.Read(buffer,0,buffer.Length);
+ if (buffer_len == -1) eof = true;
+ buffer_cur_ptr = 0;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ UIWorker.addUIEventLog("Exception in async net read: " + e);
+ eof = true;
+ quit = true;
+ }
+ lock (conn)
+ {
+ do_read = false;
+ }
+
+ // Call read CB
+ if (is_valid) UIWorker.addUIEventValid(c_input_ready_cb, input_id, 0, 0, 0, false, this);
+ }
+ }
+
+ public void startRead(int input_id)
+ {
+ if (conn == null)
+ {
+ UIWorker.addUIEventLog("startRead with no connection!");
+ eof = true;
+ Monitor.Pulse(conn);
+ }
+
+ this.input_id = input_id;
+ lock (conn)
+ {
+ do_read = true;
+ Monitor.Pulse(conn);
+ }
+ }
+
+ public void stopRead()
+ {
+ if (conn != null)
+ {
+ lock (conn)
+ {
+ quit = true;
+ Monitor.Pulse(conn);
+ }
+ }
+ }
+
+ public void close()
+ {
+ is_valid = false;
+ if (conn != null)
+ {
+ lock (conn)
+ {
+ quit = true;
+ Monitor.Pulse(conn);
+ }
+ }
+ }
+
+ public int read(int addr, int len)
+ {
+ if (eof || (buffer_len == 0)) return -1;
+
+ if (len > buffer_len - buffer_cur_ptr) len = buffer_len - buffer_cur_ptr;
+
+ CRunTime.memcpy(addr, buffer, buffer_cur_ptr, len);
+ buffer_cur_ptr += len;
+
+ lock (conn)
+ {
+ do_read = true;
+ Monitor.Pulse(conn);
+ }
+
+ return len;
+ }
+
+
+ /*
+ * returns true iff this AsyncNet object is currently in a "reading state".
+ */
+ public int isReading()
+ {
+ if (input_id != -1)
+ return 1;
+ else
+ return 0;
+ }
+
+ /*
+ * For debugging : prints the url we are trying to access, if an exception was thrown
+ */
+ public static void printUrl(int c_connection)
+ {
+ try
+ {
+ HttpWebRequest httpConnection = (HttpWebRequest)CRunTime.getRegisteredObject(c_connection);
+ UIWorker.addUIEventLog("AsyncNet:printUrl : URL is " + httpConnection.RequestUri);
+ }
+ catch (Exception e)
+ {
+ UIWorker.addUIEventLog("Exception in AsyncNet:printUrl");
+ }
+ }
+}
+
+class Worker
+{
+ public Worker(NetQueue netqueue)
+ {
+ netqueue.SetWorker(this);
+ }
+
+ public List<object> queue = new List<object>(50);
+ private bool quit = false;
+
+ public void run()
+ {
+ AsyncNet net;
+
+ while (true)
+ {
+ lock (queue)
+ {
+ while (!quit && (queue.Count == 0))
+ {
+ try
+ {
+ Monitor.Wait(queue);
+ }
+ catch (SynchronizationLockException e)
+ {
+ }
+ }
+ if (quit) return;
+
+ net = (AsyncNet)queue[0];
+ queue.RemoveAt(0);
+ }
+
+ net.runNetLoop();
+ }
+ }
+}
+
+class NetQueue
+{
+ Worker worker;
+
+ public void init()
+ {
+ for (int i = 0; i < 2; i++)
+ {
+ Worker worker = new Worker(this);
+ new Thread((ThreadStart)delegate { worker.run(); }).Start();
+ }
+ }
+
+ public void SetWorker(Worker worker)
+ {
+ this.worker = worker;
+ }
+
+ public void add(AsyncNet net)
+ {
+ lock(worker.queue)
+ {
+ worker.queue.Add(net);
+ Monitor.Pulse(worker.queue);
+ }
+ }
+}
View
378 WazeWP7/BLUElet.java
@@ -0,0 +1,378 @@
+import java.util.*;
+import javax.bluetooth.*;
+import javax.microedition.lcdui.*;
+import javax.microedition.midlet.*;
+
+/**
+*
+* <p>Title: Bluetooth Application Utility GUI Component</p>
+* <p>Description:
+*
+* Note: This class must be used as singleton.
+* </p>
+* @author Ben Hui (www.benhui.net)
+* @version 1.0
+*
+* LICENSE:
+* This code is licensed under GPL. (See http://www.gnu.org/copyleft/gpl.html)
+*/
+public class BLUElet implements CommandListener
+{
+ // Commands used in callback to idenfity BLUElet events.
+ // COMPLETED - When both device and service discovery are completed.
+ public static Command COMPLETED = new Command( "COMPLETED", Command.SCREEN, 1 );
+ // SELECTED - When user has selected a Bluetooth device for service search
+ public static Command SELECTED = new Command( "SELECTED", Command.SCREEN, 1 );
+ // BACK - When user press Back button on Bluetooth Devices screen (RemoteDeviceUI)
+ public static Command BACK = new Command( "Back", Command.BACK, 1 );
+
+
+ // your MIDlet reference
+ public static MIDlet host;
+ // your callback CommandListener
+ public static CommandListener callback;
+ // self instance of BLUEletUI
+ public static BLUElet instance;
+ // reference to GUI display
+ public static Display display;
+
+ public static Vector devices = new Vector();
+ public static Vector deviceClasses = new Vector();
+ public static Vector services = new Vector();
+ public static int selectedDevice = -1;
+// public static int selectedService = -1;
+
+
+ // discovery mode in device inquiry
+ public int discoveryMode;
+ // list of UUID to match during service discovery
+ public UUID[] serviceUUIDs = null;
+
+ // Bluetooth return code from device inquiry operation
+ // see DiscoveryListener
+ public int deviceReturnCode;
+ // Bluetooth return code from service discovery operation
+ // see DiscoveryListener
+ public int serviceReturnCode;
+
+
+
+ private RemoteDeviceUI remotedeviceui = null;
+ private LocalDevice device;
+ private DiscoveryAgent agent;
+
+ static String m_wait_msg = "Please wait...";
+ static String m_not_found_msg = "No Bluetooth device found.";
+
+ /**
+ * Creae a new BLUElet.
+ * @param host MIDlet
+ * @param listener CommandListener
+ */
+ public BLUElet(MIDlet host, CommandListener listener, String wait_msg,
+ String not_found_msg)
+ {
+ this.host = host;
+ this.callback = listener;
+ this.m_wait_msg = wait_msg;
+ this.m_not_found_msg = not_found_msg;
+ instance = this;
+ }
+
+ /**
+ * Mirror MIDlet.startApp(), should be called by your MIDlet startApp().
+ */
+ public void startApp() {
+
+ display = Display.getDisplay(host);
+
+ remotedeviceui = new RemoteDeviceUI();
+ remotedeviceui.showui();
+ }
+
+ /**
+ * Mirror MIDlet.pauseApp(), should be called by your MIDlet pauseApp().
+ */
+ public void pauseApp()
+ {
+ // do nothing
+ }
+
+ /**
+ * Mirror MIDlet.destroyApp(), should be called by your MIDlet destroyApp().
+ */
+ public void destroyApp(boolean unconditional)
+ {
+ }
+
+
+ /**
+ * Utility function to write log message.
+ * @param s String
+ */
+ public static void log(String s)
+ {
+ //System.out.println(s);
+ }
+
+ /**
+ * Obtain reference to device selection screen component.
+ * You should show this screen when user invoke device search.
+ * @return Screen
+ */
+ public Screen getUI()
+ {
+ return remotedeviceui;
+ }
+
+ /**
+ * Get all discovered services from selected remote device.
+ * Your application call this method after your app receive COMPLETED callback
+ * event. This will return all services that match your UUIDs in startInquiry().
+ * @return ServiceRecord[]
+ */
+ public ServiceRecord[] getDiscoveredServices()
+ {
+ ServiceRecord[] r = new ServiceRecord[ services.size() ];
+ services.copyInto( r );
+ return r;
+ }
+
+ /**
+ * Get the first discovered service from selected remote device.
+ * Your application call this method after your app receives COMPLETED
+ * callback event. This will return the first service that match your
+ * UUIDs in startInquiry().
+ *
+ * @return ServiceRecord null if no service discovered
+ */
+ public ServiceRecord getFirstDiscoveredService()
+ {
+ if ( services.size() > 0 )
+ return (ServiceRecord) services.elementAt(0);
+ else
+ return null;
+ }
+
+ /**
+ * Return the Bluetooth result code from device inquiry.
+ * This is the result code obtained in DiscoveryListener.inquiryCompleted().
+ * Your application cal call this method after a COMPLETED callback event
+ * is received.
+ * @return int
+ */
+ public int getDeviceDiscoveryReturnCode()
+ {
+ return deviceReturnCode;
+ }
+
+
+ /**
+ * Return the Bluetooth result code from service discovery.
+ * This is the result code obtained in DiscoveryListener.serviceSearchCompleted().
+ * Your application cal call this method after a COMPLETED callback event
+ * is received.
+ * @return int
+ */
+ public int getServiceDiscoveryReturnCode()
+ {
+ return serviceReturnCode;
+ }
+
+ /**
+ * Return user selected remote device that is used for service discovery.
+ * Your application can call this after your app received SELECTED callback
+ * event.
+ * @return RemoteDevice null if user didn't select anything
+ */
+ public RemoteDevice getSelectedDevice()
+ {
+ if ( selectedDevice != -1 )
+ return (RemoteDevice) devices.elementAt(selectedDevice);
+ else
+ return null;
+ }
+
+ /**
+ * Start device inquiry. Your application call this method to start inquiry.
+ * @param mode int one of DiscoveryAgent.GIAC or DiscoveryAgent.LIAC
+ * @param serviceUUIDs UUID[]
+ */
+ public void startInquiry( int mode, UUID[] serviceUUIDs )
+ {
+ try
+ {
+ this.discoveryMode = mode;
+ this.serviceUUIDs = serviceUUIDs;
+
+ // clear previous values first
+ devices.removeAllElements();
+ deviceClasses.removeAllElements();
+
+ //
+ // initialize the JABWT stack
+ device = LocalDevice.getLocalDevice(); // obtain reference to singleton
+ device.setDiscoverable(DiscoveryAgent.GIAC); // set Discover Mode
+ agent = device.getDiscoveryAgent(); // obtain reference to singleton
+
+
+ boolean result = agent.startInquiry( mode, new Listener() );
+
+ // update screen with "Please Wait" message
+ remotedeviceui.setMsg(m_wait_msg);
+
+ } catch ( BluetoothStateException e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ *
+ * @param c Command
+ * @param d Displayable
+ */
+ public void commandAction(Command c, Displayable d)
+ {
+ if ( d == remotedeviceui && c.getLabel().equals("Search") )
+ {
+ startInquiry( discoveryMode, serviceUUIDs );
+
+ } else if ( d == remotedeviceui && c.getLabel().equals("Back") )
+ {
+ callback.commandAction( BACK, remotedeviceui);
+
+ } else if ( d == remotedeviceui && c.getLabel().equals("Select") )
+ {
+ // get selected device
+ selectedDevice = remotedeviceui.getSelectedIndex();
+ if (selectedDevice >= devices.size()) return;
+ // System.out.println("Selected:" + selectedDevice + " size:" + devices.size());
+ RemoteDevice remoteDevice = (RemoteDevice) devices.elementAt( selectedDevice );
+
+ // remove all existing record first
+ services.removeAllElements();
+
+ try
+ {
+ agent.searchServices(null,
+ serviceUUIDs,
+ remoteDevice,
+ new Listener() );
+
+ // tell callback device selected
+ display.callSerially(new Worker(ID_DEVICE_SELECTED));
+ remotedeviceui.setMsg(m_wait_msg);
+
+ } catch (BluetoothStateException ex)
+ {
+ ex.printStackTrace();
+ }
+
+ }
+ }
+
+ /**
+ * Bluetooth listener object.
+ * Register this listener object to DiscoveryAgent in device inqury and service discovery.
+ */
+ class Listener implements DiscoveryListener
+ {
+
+ public void deviceDiscovered(RemoteDevice remoteDevice,
+ DeviceClass deviceClass)
+ {
+ log("A remote Bluetooth device is discovered:");
+ //Util.printRemoteDevice( remoteDevice, deviceClass );
+ devices.addElement( remoteDevice );
+ deviceClasses.addElement( deviceClass );
+ }
+
+ public void inquiryCompleted(int complete)
+ {
+ log("device discovery is completed with return code:"+complete);
+ log(""+devices.size()+" devices are discovered");
+
+ deviceReturnCode = complete;
+
+ if ( devices.size() == 0 )
+ {
+ Alert alert = new Alert( "Bluetooth", m_not_found_msg, null, AlertType.INFO );
+ alert.setTimeout(3000);
+ remotedeviceui.showui();
+ display.setCurrent( alert, remotedeviceui );
+
+ } else
+ {
+ remotedeviceui.showui();
+ display.setCurrent( remotedeviceui );
+ }
+
+ }
+
+ public void servicesDiscovered(int transId, ServiceRecord[] records)
+ {
+ // note: we do not use transId because we only have one search at a time
+ log("Remote Bluetooth services is discovered:");
+ for ( int i=0; i< records.length; i ++ )
+ {
+ ServiceRecord record = records[i];
+ //Util.printServiceRecord( record );
+ services.addElement( record );
+ }
+ }
+
+ public void serviceSearchCompleted(int transId, int complete)
+ {
+ // note: we do not use transId because we only have one search at a time
+ log("service discovery completed with return code:"+complete);
+ log(""+services.size()+" services are discovered");
+
+ serviceReturnCode = complete;
+
+ // we cannot callback in this thread because this is a Bluetooth
+ // subsystem thread. we do not want to block it.
+ display.callSerially( new Worker( ID_SERVICE_COMPLETED ) );
+
+ }
+
+ } // Listener
+
+ private final static int ID_SERVICE_COMPLETED = 1;
+ private final static int ID_DEVICE_COMPLETED = 2;
+ private final static int ID_DEVICE_SELECTED = 3;
+ /**
+ * Worker thread that invoke callback CommandListener upon Bluetooth event occurs.
+ */
+ class Worker implements Runnable
+ {
+ int cmd = 0;
+
+ public Worker( int cmd )
+ {
+ this.cmd = cmd;
+ }
+ public void run()
+ {
+ switch (cmd) {
+ case ID_SERVICE_COMPLETED:
+ callback.commandAction( COMPLETED, remotedeviceui);
+
+ break;
+ case ID_DEVICE_COMPLETED:
+ callback.commandAction( COMPLETED, remotedeviceui);
+
+ break;
+ case ID_DEVICE_SELECTED:
+ callback.commandAction( SELECTED, remotedeviceui);
+
+ break;
+ default:
+ break;
+
+ }
+ }
+ }
+
+}
View
616 WazeWP7/CRunTime.cs
@@ -0,0 +1,616 @@
+/*********************************************************************
+ *
+ * Copyright (C) 2006, Blekinge Institute of Technology
+ *
+ * Filename: CRunTime.java
+ * Author: Simon Kagstrom <ska@bth.se>
+ * Description: C runtime support (compiled)
+ *
+ * $Id: CRunTime.java 14117 2007-03-10 09:32:26Z ska $
+ *
+ ********************************************************************/
+using System;
+using System.IO;
+using System.Text;
+using System.Collections;
+using System.Collections.Generic;
+
+ public class CRunTime
+ {
+ public static int[] memory;
+
+ public static int saved_v1; /* Result from functions */
+ public static int ra; /* For the debug target */
+
+ /* Pointer to the top of the event stack */
+ public static int eventStackPointer;
+
+ public static Object[] objectRepository;
+ private static int maxRepositoryObjects;
+ private static int firstFree;
+ private static Dictionary<string, int> callbacksByName;
+
+ /**
+ * Initialize the C runtime. This must be called before the C
+ * runtime is used.
+ *
+ * @param memoryImage the contents of the .data and .rodata sections
+ * @param memorySize the total size of the memory, should be larger
+ * than memoryImage to fit the .bss, the heap and the stack
+ */
+ public static void init(Stream codeStream, int memorySize)
+ {
+ CRunTime.maxRepositoryObjects = 2048;
+ CRunTime.callbacksByName = new Dictionary<string, int>();
+ CRunTime.objectRepository = new Object[CRunTime.maxRepositoryObjects];
+ CRunTime.objectRepository[0] = null;
+
+ /* 0 is the invalid object, 1 is the exception object */
+ CRunTime.firstFree = 2;
+
+ CRunTime.memory = new int[memorySize / 4];
+
+ /* Copy memory */
+ int len = (int)codeStream.Length / 4;
+ for (int i = 0; i < len; i++)
+ {
+ int b0 = codeStream.ReadByte();
+ int b1 = codeStream.ReadByte();
+ int b2 = codeStream.ReadByte();
+ int b3 = codeStream.ReadByte();
+ CRunTime.memory[i] = ((b0 & 0xff) << 24) | ((b1 & 0xff) << 16) | ((b2 & 0xff) << 8) | (b3 & 0xff);
+ }
+
+ CRunTime.memory[1] = CibylConfig.stackSize;
+ CRunTime.memory[3] = memorySize - (CibylConfig.eventStackSize - 8);
+ }
+
+ public static void init(Stream codeStream)
+ {
+ CRunTime.memory = null;
+ CRunTime.objectRepository = null;
+ //System.gc();
+
+ int memorySize = (int)(51200000 * 4 /* Runtime.getRuntime().freeMemory() */ * CibylConfig.cibylMemoryProportion);
+
+ if (CibylConfig.memorySize != 0)
+ memorySize = CibylConfig.memorySize;
+
+ if (CibylConfig.faultMemoryIn)
+ memorySize = (int)CRunTime.faultMemoryIn(CibylConfig.memorySize);
+
+ /* See to it that the memory is aligned to 8. This caused a very
+ * fun bug before in printf when called with "%f".
+ *
+ * Also setup the event stack at the very top of the memory
+ */
+ memorySize -= (memorySize & 7);
+ CRunTime.eventStackPointer = memorySize - 8;
+
+ int len = (int)codeStream.Length / 4;
+
+ if (len < 5)
+ {
+ /* This binary is broken - we need the header data */
+ throw new Exception("Data input is too small");
+ }
+
+ CRunTime.init(codeStream, memorySize);
+ }
+
+ /**
+ * TastePhone : Taste your MIDP Phone with this test MIDlet.<br>
+ * <br>
+ * Copyright (c) 2004, Thibaut REGNIER<br>
+ * All rights reserved.<br>
+ * <br>
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:<br>
+ * <br>
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.<br>
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.<br>
+ * * Neither the name of the "Club des Utilisateurs de Java" nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior written permission.<br>
+ * <br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @author Thibaut Regnier : mobilette@club-java.com
+ */
+ private static long faultMemoryIn(int size)
+ {
+ long lout = 0;
+ List<object> v = new List<object>(256);
+ int i = 0;
+
+ try
+ {
+ // We run the garbage collector to be sure we have the maximum space available.
+ while (i < size / 1024)
+ {
+ int[] array = new int[256]; // int = 4 bytes => 256*4 = 1kB
+ v.Add(array);
+ i++;
+ lout = lout + 1024;
+ }
+ }
+ catch (Exception t)
+ { // Should get an OutOfMemoryError but we prefer to catch everything.
+ v = null;
+ //lout = Runtime.getRuntime().totalMemory();
+ //System.gc();
+ }
+
+ return lout;
+ }
+
+ public static Object getRegisteredObject(int handle)
+ {
+ return CRunTime.objectRepository[handle];
+ }
+
+ public static int registerObject(Object obj)
+ {
+ int ret = CRunTime.firstFree;
+ int i;
+
+ // Invalid object
+ if (obj == null)
+ return 0;
+
+ int r = 0;
+ CRunTime.objectRepository[ret] = obj;
+ for (i = CRunTime.firstFree; i < CRunTime.objectRepository.Length; i++)
+ {
+ if (CRunTime.objectRepository[i] == null)
+ {
+ CRunTime.firstFree = i;
+
+ if (firstFree == 0)
+ ret = 1;
+
+ return ret;
+ }
+ }
+
+ if (i == CRunTime.objectRepository.Length)
+ {
+ CRunTime.maxRepositoryObjects = CRunTime.maxRepositoryObjects * 2;
+ Object[] tmp = new Object[CRunTime.maxRepositoryObjects];
+
+ for (i = 0; i < CRunTime.objectRepository.Length; i++)
+ tmp[i] = CRunTime.objectRepository[i];
+ tmp[i] = obj;
+ CRunTime.objectRepository = tmp;
+
+ ret = i;
+ }
+
+ if (ret == 0)
+ ret = 1;
+ return ret;
+ }
+
+ public static Object deRegisterObject(int handle)
+ {
+ Object lout = CRunTime.getRegisteredObject(handle);
+
+ if (handle == 0)
+ return lout;
+
+ if (CRunTime.firstFree > handle)
+ CRunTime.firstFree = handle;
+ CRunTime.objectRepository[handle] = null;
+
+ return lout;
+ }
+
+ /**
+ * Publish a new callback. This is supposed to be called from Java
+ * during startup to get a callback identifier.
+ *
+ * @param name the name of the callback
+ *
+ * @return a callback ID
+ */
+ public static int publishCallback(String name)
+ {
+ int id = CRunTime.registerObject(0); /* Used to get an id, 0 means nothing here */
+ int intObject = id;
+
+ CRunTime.callbacksByName.Add(name, intObject); /* Register name:id */
+
+ return id;
+ }
+
+ /**
+ * Register a callback function for a particular string.
+ *
+ * @param charPtr a C char* with the name of the callback
+ * @param fnPtr the function pointer that implements the callback
+ *
+ * @return the callback id
+ */
+ public static int registerCallback(int charPtr, int fnPtr)
+ {
+ String name = CRunTime.charPtrToString(charPtr);
+ int id = (int)CRunTime.callbacksByName[name];
+ int old = (int)CRunTime.objectRepository[id];
+
+ CRunTime.objectRepository[id] = fnPtr; /* Replace with the fn ptr */
+
+ return old;
+ }
+
+ /* Invoke a registered callback */
+ public static long invokeCallback(int which, int a0, int a1, int a2, int a3)
+ {
+ int id = (int)CRunTime.objectRepository[which];
+
+ /* If this callback is not yet registered, just return 0 */
+ if (id == 0)
+ return 0;
+
+ return CibylCallTable.fcall(id,
+ CRunTime.eventStackPointer,
+ a0, a1, a2, a3); /* a0 ... a3 */
+ }
+
+ /* Misc. utils */
+ public static String charPtrToString(int address)
+ {
+ int startAddress = address;
+ int i = 0;
+ int len = 0;
+
+ while (CRunTime.memoryReadByte(startAddress + len) != 0)
+ {
+ len++;
+ }
+
+ if (len == 0)
+ return "";
+
+ byte[] vec = new byte[len];
+
+ for (i = 0; i < len; i++)
+ {
+ vec[i] = (byte)CRunTime.memoryReadByte(startAddress + i);
+ }
+ try
+ {
+ String str;
+ if (CibylConfig.stringEncoding == null)
+ str = new System.Text.UTF8Encoding().GetString(vec,0,vec.Length);
+ else
+ str = BitConverter.ToString(vec); // tofix new String(vec, CibylConfig.stringEncoding);
+
+ return str;
+ }
+ catch (Exception e)
+ {
+ return "UnSupportedEncodingException happened";
+ }
+ }
+
+ public static void memoryWriteByte(int address, int ins)
+ {
+ int value = ins & 0xff;
+ int cur = CRunTime.memory[address / 4];
+ int b = (3 - (address & 3)) << 3;
+
+ cur &= ~(0xff << b);
+
+ cur |= (value << b);
+ CRunTime.memory[address / 4] = cur;
+ }
+
+ public static void memoryWriteShort(int address, int ins)
+ {
+ int value = ins & 0xffff;
+ int cur = CRunTime.memory[address / 4];
+ int b = (2 - (address & 2)) << 3;
+
+ cur &= ~(0xffff << b);
+
+ cur |= (value << b);
+ CRunTime.memory[address / 4] = cur;
+ }
+
+ public static void memoryWriteWord(int address, int ins)
+ {
+ CRunTime.memory[address / 4] = ins;
+ }
+
+ public static void memoryWriteLong(int address, long ins)
+ {
+ CRunTime.memory[address >> 2] = (int)(ins >> 32);
+ CRunTime.memory[(address + 4) >> 2] = (int)(ins & 0xffffffffl);
+ }
+
+
+ public static void memoryWriteBytePc(int pc, int address, int ins)
+ {
+ CRunTime.assertMemoryWrite("1-byte", pc, address, ins);
+ CRunTime.memoryWriteByte(address, ins);
+ }
+
+ public static void memoryWriteShortPc(int pc, int address, int ins)
+ {
+ CRunTime.assertMemoryWrite("2-byte", pc, address, ins);
+ CRunTime.memoryWriteShort(address, ins);
+ }
+
+ public static void memoryWriteWordPc(int pc, int address, int ins)
+ {
+ CRunTime.assertMemoryWrite("4-byte", pc, address, ins);
+ CRunTime.memoryWriteWord(address, ins);
+ }
+
+
+
+ public static long memoryReadLong(int address)
+ {
+ long low = ((long)CRunTime.memory[(address + 4) >> 2]) & 0xffffffffl;
+ long high = ((long)CRunTime.memory[address >> 2]) & 0xffffffffl;
+ long lout = (high << 32) | low;
+
+ return lout;
+ }
+
+ public static int memoryReadWord(int address)
+ {
+ return CRunTime.memory[address >> 2];
+ }
+
+ public static int memoryReadByteUnsigned(int address)
+ {
+ int val = CRunTime.memory[address >> 2];
+ int b = (3 - (address & 3)) << 3;
+
+ return (val >> b) & 0xff;
+ }
+
+
+ public static int memoryReadByte(int address)
+ {
+ int val = CRunTime.memory[address >> 2];
+ int b = (3 - (address & 3)) << 3;
+ int lout = (val >> b) & 0xff;
+
+ /* Sign-extend */
+ if ((lout & (1 << 7)) != 0)
+ return (int)(lout | 0xffffff00);
+
+ return lout;
+ }
+
+ public static int memoryReadShortUnsigned(int address)
+ {
+ int val = CRunTime.memory[address >> 2];
+ int b = (2 - (address & 2)) << 3;
+
+ return (val >> b) & 0xffff;
+ }
+
+ public static int memoryReadShort(int address)
+ {
+ int lout = CRunTime.memoryReadShortUnsigned(address);
+
+ /* Sign-extend */
+ if ((lout & (1 << 15)) != 0)
+ return (int)(lout | 0xffff0000);
+
+ return lout;
+ }
+
+ public static void memcpy(int addr, byte[] bytes, int off, int size)
+ {
+ while (((addr & 0x3) != 0) && (size > 0))
+ {
+ byte b = bytes[off++];
+ CRunTime.memoryWriteByte(addr, b);
+ addr++;
+ size--;
+ if (size == 0) return;
+ }
+
+ while (size > 3)
+ {
+ int i = 0;
+ for (int j = 0; j < 4; j++)
+ {
+ i = i << 8;
+ int b = bytes[off++] & 0xff;
+ i |= b;
+ }
+
+ CRunTime.memoryWriteWord(addr, i);
+ addr += 4;
+ size -= 4;
+ }
+
+ while (size > 0)
+ {
+ byte b = bytes[off++];
+ CRunTime.memoryWriteByte(addr, b);
+ addr++;
+ size--;
+ }
+ }
+
+ public static void memcpy(byte[] bytes, int off, int addr, int size)
+ {
+ while (size > 0)
+ {
+ bytes[off++] = (byte)CRunTime.memoryReadByte(addr);
+ addr++;
+ size--;
+ }
+
+ return;
+ }
+
+ /* The nasty lwl/lwr and swl/swr instructions */
+ public static int memoryReadWordLeft(int address)
+ {
+ int b0 = CRunTime.memoryReadByteUnsigned(address + 3);
+ int b1 = CRunTime.memoryReadByteUnsigned(address + 2);
+ int b2 = CRunTime.memoryReadByteUnsigned(address + 1);
+ int b3 = CRunTime.memoryReadByteUnsigned(address + 0);
+
+ return (b0 | (b1 << 8) | (b2 << 16) | (b3 << 24));
+ }
+
+ public static void memoryWriteWordLeft(int address, int rtVal)
+ {
+ CRunTime.memoryWriteByte(address + 3, (rtVal));
+ CRunTime.memoryWriteByte(address + 2, (rtVal >> 8));
+ CRunTime.memoryWriteByte(address + 1, (rtVal >> 16));
+ CRunTime.memoryWriteByte(address + 0, (rtVal >> 24));
+ }
+
+ public static void memoryWriteWordLeftPc(int pc, int address, int rtVal)
+ {
+ CRunTime.assertMemoryWrite("lwl", pc, address, rtVal);
+ CRunTime.memoryWriteWordLeft(address, rtVal);
+ }
+
+ public static void kill()
+ {
+ CRunTime.memory[-1] = 0;
+ }
+
+ public static long divu(int rsVal, int rtVal)
+ {
+ long low, high;
+
+ if (rsVal < 0 || rtVal < 0)
+ {
+ long a = rsVal;
+ long b = rtVal;
+
+ a &= 0xffffffffl;
+ b &= 0xffffffffl;
+
+ low = a / b;
+ high = a % b;
+ }
+ else
+ {
+ low = rsVal / rtVal;
+ high = rsVal % rtVal;
+ }
+
+ return (high << 32) | low;
+ }
+
+ public static long multu(int rsVal, int rtVal)
+ {
+ long a = (long)rsVal;
+ long b = (long)rtVal;
+
+ a &= 0xffffffffl;
+ b &= 0xffffffffl;
+
+ return a * b;
+ }
+
+ public static int sltu(int aVal, int bVal)
+ {
+ long a = (long)aVal;
+ long b = (long)bVal;
+
+ a &= 0xffffffffl;
+ b &= 0xffffffffl;
+ if (a < b)
+ return 1;
+
+ return 0;
+ }
+
+ private static int functionNesting;
+ public static void emitFunctionEnterTrace(String str)
+ {
+ for (int i = 0; i < CRunTime.functionNesting; i++)
+ str = " " + str;
+ CRunTime.functionNesting++;
+ CRunTime.emitTrace(str);
+ }
+
+ public static void emitFunctionExitTrace(String str)
+ {
+ CRunTime.functionNesting--;
+ }
+
+ public static void assertMemoryWrite(String type, int pc, int address, int ins)
+ {
+ if (address >= CRunTime.memoryReadWord(16) && address < CRunTime.memoryReadWord(20))
+ {
+ Logger.log(type + " on 0x" + pc + " memory[0x" + address + "] = 0x" + ins + "");
+ }
+ }
+
+ // private static Console console;
+ /* Used by cibyl-mips2java when tracing is turned on */
+ public static void emitTrace(String str)
+ {
+ // if ( console == null)
+ // CRunTime.console = new Console();
+ // CRunTime.console.push(str);
+ Logger.log(str);
+ }
+
+ public static void emitRegisterTrace(int rs, int rt, int rd)
+ {
+ Logger.log(" rs: 0x" + rs + " rt: 0x" + rt + " rd: 0x" + rd);
+ }
+
+ public static Int32 floatToIntBits(Single f)
+ {
+ return BitConverter.ToInt32(BitConverter.GetBytes(f), 0);
+ }
+
+ public static float intBitsToFloat(int bits)
+ {
+ int sign = ((bits & 0x80000000) == 0) ? 1 : -1;
+ int exponent = ((bits & 0x7f800000) >> 23);
+ int mantissa = (bits & 0x007fffff);
+
+ mantissa |= 0x00800000;
+
+ // Calculate the result:
+ return (float)(sign * mantissa * Math.Pow(2, exponent - 150));
+ }
+
+ public static Int64 DoubleToInt64Bits(Double f)
+ {
+ return BitConverter.ToInt64(BitConverter.GetBytes(f), 0);
+ }
+
+ public static double Int64BitsToDouble(long bits)
+ {
+ return BitConverter.ToDouble(BitConverter.GetBytes(bits), 0);
+ /*
+ int sign = ((bits & 0x80000000) == 0) ? 1 : -1;
+ int exponent = ((bits & 0x7f800000) >> 23);
+ int mantissa = (bits & 0x007fffff);
+
+ mantissa |= 0x00800000;
+
+ // Calculate the result:
+ return (float)(sign * mantissa * Math.Pow(2, exponent - 150));*/
+ }
+
+
+
+ }
+
View
565 WazeWP7/CRunTime.java
@@ -0,0 +1,565 @@
+/*********************************************************************
+ *
+ * Copyright (C) 2006, Blekinge Institute of Technology
+ *
+ * Filename: CRunTime.java
+ * Author: Simon Kagstrom <ska@bth.se>
+ * Description: C runtime support (compiled)
+ *
+ * $Id: CRunTime.java 14117 2007-03-10 09:32:26Z ska $
+ *
+ ********************************************************************/
+import java.io.*;
+import java.util.*;
+
+public class CRunTime
+{
+ public static int memory[];
+
+ public static int saved_v1; /* Result from functions */
+ public static int ra; /* For the debug target */
+
+ /* Pointer to the top of the event stack */
+ public static int eventStackPointer;
+
+ public static Object objectRepository[];
+ private static int maxRepositoryObjects;
+ private static int firstFree;
+ private static Hashtable callbacksByName;
+
+ public static final int printtheint(int i)
+ {
+ System.out.println("i:" + i);
+ return 1;
+ }
+
+ /**
+ * Initialize the C runtime. This must be called before the C
+ * runtime is used.
+ *
+ * @param memoryImage the contents of the .data and .rodata sections
+ * @param memorySize the total size of the memory, should be larger
+ * than memoryImage to fit the .bss, the heap and the stack
+ */
+ public static final void init(InputStream codeStream, int memorySize) throws Exception
+ {
+ CRunTime.maxRepositoryObjects = 256;
+ CRunTime.callbacksByName = new Hashtable();
+ CRunTime.objectRepository = new Object[ CRunTime.maxRepositoryObjects ];
+ CRunTime.objectRepository[0] = null;
+
+ /* 0 is the invalid object, 1 is the exception object */
+ CRunTime.firstFree = 2;
+
+ CRunTime.memory = new int[memorySize / 4];
+
+ /* Copy memory */
+ int len = codeStream.available() / 4;
+ for (int i=0; i<len; i++)
+ {
+ int b0 = codeStream.read();
+ int b1 = codeStream.read();
+ int b2 = codeStream.read();
+ int b3 = codeStream.read();
+ CRunTime.memory[i] = ((b0 & 0xff) << 24) | ((b1 & 0xff) << 16) | ((b2 & 0xff) << 8) | (b3 & 0xff);
+ }
+
+ CRunTime.memory[1] = CibylConfig.stackSize;
+ CRunTime.memory[3] = memorySize - (CibylConfig.eventStackSize - 8);
+ }
+
+ public static final void init(InputStream codeStream) throws Exception
+ {
+ CRunTime.memory = null;
+ CRunTime.objectRepository = null;
+ System.gc();
+
+ int memorySize = (int)(Runtime.getRuntime().freeMemory() * CibylConfig.cibylMemoryProportion);
+
+ if (CibylConfig.memorySize != 0)
+ memorySize = CibylConfig.memorySize;
+
+ if (CibylConfig.faultMemoryIn)
+ memorySize = (int)CRunTime.faultMemoryIn(CibylConfig.memorySize);
+
+ /* See to it that the memory is aligned to 8. This caused a very
+ * fun bug before in printf when called with "%f".
+ *
+ * Also setup the event stack at the very top of the memory
+ */
+ memorySize -= (memorySize & 7);
+ CRunTime.eventStackPointer = memorySize - 8;
+
+ int len = codeStream.available() / 4;
+
+ if (len < 5)
+ {
+ /* This binary is broken - we need the header data */
+ throw new Exception("Data input is too small");
+ }
+
+ CRunTime.init(codeStream, memorySize);
+ }
+
+ /**
+ * TastePhone : Taste your MIDP Phone with this test MIDlet.<br>
+ * <br>
+ * Copyright (c) 2004, Thibaut REGNIER<br>
+ * All rights reserved.<br>
+ * <br>
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:<br>
+ * <br>
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.<br>
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.<br>
+ * * Neither the name of the "Club des Utilisateurs de Java" nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior written permission.<br>
+ * <br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @author Thibaut Regnier : mobilette@club-java.com
+ */
+ private static final long faultMemoryIn(int size)
+ {
+ long out = 0;
+ Vector v= new Vector(1024, 256);
+ int i = 0;
+
+ try
+ {
+ // We run the garbage collector to be sure we have the maximum space available.
+ System.gc();
+ while (i < size / 1024)
+ {
+ int[] array= new int[256]; // int = 4 bytes => 256*4 = 1kB
+ v.addElement(array);
+ i++;
+ out = out + 1024;
+ }
+ }
+ catch (Throwable t)
+ { // Should get an OutOfMemoryError but we prefer to catch everything.
+ v= null;
+ out = Runtime.getRuntime().totalMemory();
+ System.gc();
+ }
+
+ return out;
+ }
+
+ public static Object getRegisteredObject(int handle)
+ {
+ return CRunTime.objectRepository[handle];
+ }
+
+ public static int registerObject(Object obj)
+ {
+ int ret = CRunTime.firstFree;
+ int i;
+
+ // Invalid object
+ if (obj == null)
+ return 0;
+
+ CRunTime.objectRepository[ret] = obj;
+ for (i=CRunTime.firstFree; i < CRunTime.objectRepository.length; i++)
+ {
+ if (CRunTime.objectRepository[i] == null)
+ {
+ CRunTime.firstFree = i;
+ return ret;
+ }
+ }
+
+ if (i == CRunTime.objectRepository.length)
+ {
+ CRunTime.maxRepositoryObjects = CRunTime.maxRepositoryObjects * 2;
+ Object tmp[] = new Object[CRunTime.maxRepositoryObjects];
+
+ for (i = 0; i < CRunTime.objectRepository.length; i++)
+ tmp[i] = CRunTime.objectRepository[i];
+ tmp[i] = obj;
+ CRunTime.objectRepository = tmp;
+
+ ret = i;
+ }
+
+ return ret;
+ }
+
+ public static Object deRegisterObject(int handle)
+ {
+ Object out = CRunTime.getRegisteredObject(handle);
+
+ if (CRunTime.firstFree > handle)
+ CRunTime.firstFree = handle;
+ CRunTime.objectRepository[handle] = null;
+
+ return out;
+ }
+
+ /**
+ * Publish a new callback. This is supposed to be called from Java
+ * during startup to get a callback identifier.
+ *
+ * @param name the name of the callback
+ *
+ * @return a callback ID
+ */
+ public static int publishCallback(String name)
+ {
+ int id = CRunTime.registerObject(new Integer(0)); /* Used to get an id, 0 means nothing here */
+ Integer intObject = new Integer(id);
+
+ CRunTime.callbacksByName.put(name, intObject); /* Register name:id */
+
+ return id;
+ }
+
+ /**
+ * Register a callback function for a particular string.
+ *
+ * @param charPtr a C char* with the name of the callback
+ * @param fnPtr the function pointer that implements the callback
+ *
+ * @return the callback id
+ */
+ public static int registerCallback(int charPtr, int fnPtr)
+ {
+ String name = CRunTime.charPtrToString(charPtr);
+ Integer id = (Integer)CRunTime.callbacksByName.get(name);
+ Integer old = (Integer)CRunTime.objectRepository[id.intValue()];
+
+ CRunTime.objectRepository[id.intValue()] = new Integer(fnPtr); /* Replace with the fn ptr */
+
+ return old.intValue();
+ }
+
+ /* Invoke a registered callback */
+ public static long invokeCallback(int which, int a0, int a1, int a2, int a3) throws Exception
+ {
+ Integer id = (Integer)CRunTime.objectRepository[which];
+
+ /* If this callback is not yet registered, just return 0 */
+ if (id.intValue() == 0)
+ return 0;
+
+ return CibylCallTable.call(id.intValue(),
+ CRunTime.eventStackPointer,
+ a0, a1, a2, a3); /* a0 ... a3 */
+ }
+
+ /* Misc. utils */
+ public static String charPtrToString(int address)
+ {
+ int startAddress = address;
+ int i = 0;
+ int len = 0;
+
+ while (CRunTime.memoryReadByte(startAddress + len) != 0)
+ {
+ len++;
+ }
+
+ if (len == 0)
+ return "";
+
+ byte vec[] = new byte[len];
+
+ for (i = 0; i < len; i++)
+ {
+ vec[i] = (byte)CRunTime.memoryReadByte(startAddress + i);
+ }
+ try
+ {
+ String str;
+ if (CibylConfig.stringEncoding == null)
+ str = new String(vec);
+ else
+ str = new String(vec, CibylConfig.stringEncoding);
+
+ return str;
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ return "";
+ }
+ }
+
+ public static final void memoryWriteByte(int address, int in)
+ {
+ int value = in & 0xff;
+ int cur = CRunTime.memory[address / 4];
+ int b = (3 - (address & 3)) << 3;
+
+ cur &= ~(0xff << b);
+
+ cur |= (value << b);
+ CRunTime.memory[address / 4] = cur;
+ }
+
+ public static final void memoryWriteShort(int address, int in)
+ {
+ int value = in & 0xffff;
+ int cur = CRunTime.memory[address / 4];
+ int b = (2 - (address & 2)) << 3;
+
+ cur &= ~(0xffff << b);
+
+ cur |= (value << b);
+ CRunTime.memory[address / 4] = cur;
+ }
+
+ public static final void memoryWriteWord(int address, int in)
+ {
+ CRunTime.memory[address / 4] = in;
+ }
+
+ public static final void memoryWriteLong(int address, long in)
+ {
+ CRunTime.memory[ address >> 2 ] = (int)(in >> 32);
+ CRunTime.memory[ (address + 4) >> 2 ] = (int)(in & 0xffffffffl);
+ }
+
+
+ public static final void memoryWriteBytePc(int pc, int address, int in)
+ {
+ CRunTime.assertMemoryWrite("1-byte", pc, address, in);
+ CRunTime.memoryWriteByte(address, in);
+ }
+
+ public static final void memoryWriteShortPc(int pc, int address, int in)
+ {
+ CRunTime.assertMemoryWrite("2-byte", pc, address, in);
+ CRunTime.memoryWriteShort(address, in);
+ }
+
+ public static final void memoryWriteWordPc(int pc, int address, int in)
+ {
+ CRunTime.assertMemoryWrite("4-byte", pc, address, in);
+ CRunTime.memoryWriteWord(address, in);
+ }
+
+
+
+ public static final long memoryReadLong(int address)
+ {
+ long low = ((long)CRunTime.memory[ (address + 4) >> 2 ]) & 0xffffffffl;
+ long high = ((long)CRunTime.memory[ address >> 2 ]) & 0xffffffffl;
+ long out = (high << 32) | low;
+
+ return out;
+ }
+
+ public static final int memoryReadWord(int address)
+ {
+ return CRunTime.memory[address >> 2];
+ }
+
+ public static final int memoryReadByteUnsigned(int address)
+ {
+ int val = CRunTime.memory[address >> 2];
+ int b = (3 - (address & 3)) << 3;
+
+ return (val >>> b) & 0xff;
+ }
+
+
+ public static final int memoryReadByte(int address)
+ {
+ int val = CRunTime.memory[address >> 2];
+ int b = (3 - (address & 3)) << 3;
+ int out = (val >>> b) & 0xff;
+
+ /* Sign-extend */
+ if ( (out & (1<<7)) != 0 )
+ return out | 0xffffff00;
+
+ return out;
+ }
+
+ public static final int memoryReadShortUnsigned(int address)
+ {
+ int val = CRunTime.memory[address >> 2];
+ int b = (2 - (address & 2)) << 3;
+
+ return (val >>> b) & 0xffff;
+ }
+
+ public static final int memoryReadShort(int address)
+ {
+ int out = CRunTime.memoryReadShortUnsigned(address);
+
+ /* Sign-extend */
+ if ( (out & (1<<15)) != 0 )
+ return out | 0xffff0000;
+
+ return out;
+ }
+
+ public static final void memcpy(int addr, byte[] bytes, int off, int size)
+ {
+ while (((addr & 0x3) != 0) && (size > 0)) {
+ byte b = bytes[off++];
+ CRunTime.memoryWriteByte(addr, b);
+ addr++;
+ size--;
+ if (size == 0) return;
+ }
+
+ while (size > 3) {
+ int i = 0;
+ for (int j=0; j<4; j++) {
+ i = i << 8;
+ int b = bytes[off++] & 0xff;
+ i |= b;
+ }
+
+ CRunTime.memoryWriteWord(addr, i);
+ addr += 4;
+ size -= 4;
+ }
+
+ while (size > 0) {
+ byte b = bytes[off++];
+ CRunTime.memoryWriteByte(addr, b);
+ addr++;
+ size--;
+ }
+ }
+
+ public static final void memcpy(byte[] bytes, int off, int addr, int size)
+ {
+ while (size > 0) {
+ bytes[off++] = (byte)CRunTime.memoryReadByte(addr);
+ addr++;
+ size--;
+ }
+
+ return;
+ }
+
+ /* The nasty lwl/lwr and swl/swr instructions */
+ public static final int memoryReadWordLeft(int address)
+ {
+ int b0 = CRunTime.memoryReadByteUnsigned(address + 3);
+ int b1 = CRunTime.memoryReadByteUnsigned(address + 2);
+ int b2 = CRunTime.memoryReadByteUnsigned(address + 1);
+ int b3 = CRunTime.memoryReadByteUnsigned(address + 0);
+
+ return (b0 | (b1 << 8) | (b2 << 16) | (b3 << 24));
+ }
+
+ public static final void memoryWriteWordLeft(int address, int rtVal)
+ {
+ CRunTime.memoryWriteByte(address + 3, (rtVal));
+ CRunTime.memoryWriteByte(address + 2, (rtVal >> 8));
+ CRunTime.memoryWriteByte(address + 1, (rtVal >> 16));
+ CRunTime.memoryWriteByte(address + 0, (rtVal >> 24));
+ }
+
+ public static final void memoryWriteWordLeftPc(int pc, int address, int rtVal)
+ {
+ CRunTime.assertMemoryWrite("lwl", pc, address, rtVal);
+ CRunTime.memoryWriteWordLeft(address, rtVal);
+ }
+
+ public static final void kill()
+ {
+ CRunTime.memory[-1] = 0;
+ }
+
+ public static final long divu(int rsVal, int rtVal)
+ {
+ long low, high;
+
+ if (rsVal < 0 || rtVal < 0)
+ {
+ long a = rsVal;
+ long b = rtVal;
+
+ a &= 0xffffffffl;
+ b &= 0xffffffffl;
+
+ low = a / b;
+ high = a % b;
+ }
+ else
+ {
+ low = rsVal / rtVal;
+ high = rsVal % rtVal;
+ }
+
+ return (high << 32) | low;
+ }
+
+ public static final long multu(int rsVal, int rtVal)
+ {
+ long a = (long)rsVal;
+ long b = (long)rtVal;
+
+ a &= 0xffffffffl;
+ b &= 0xffffffffl;
+
+ return a * b;
+ }
+