Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/simulator.asm @ 0:96a35aeda5f2
Initial setup
| author | heinrichsweikamp |
|---|---|
| date | Tue, 12 Jan 2010 15:05:59 +0100 |
| parents | |
| children | 73014f788032 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:96a35aeda5f2 |
|---|---|
| 1 | |
| 2 ; OSTC - diving computer code | |
| 3 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
| 4 | |
| 5 ; This program is free software: you can redistribute it and/or modify | |
| 6 ; it under the terms of the GNU General Public License as published by | |
| 7 ; the Free Software Foundation, either version 3 of the License, or | |
| 8 ; (at your option) any later version. | |
| 9 | |
| 10 ; This program is distributed in the hope that it will be useful, | |
| 11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 ; GNU General Public License for more details. | |
| 14 | |
| 15 ; You should have received a copy of the GNU General Public License | |
| 16 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | |
| 18 | |
| 19 ; menu "Simulator" | |
| 20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
| 21 ; written: 081210 | |
| 22 ; last updated: 081210 | |
| 23 ; known bugs: | |
| 24 ; ToDo: | |
| 25 | |
| 26 menu_simulator: | |
| 27 movlw d'1' | |
| 28 movwf logbook_temp1 ; Bottom time | |
| 29 movlw d'15' | |
| 30 movwf logbook_temp2 ; Max. Depth | |
| 31 movlw d'1' | |
| 32 movwf menupos | |
| 33 | |
| 34 menu_simulator1: | |
| 35 clrf timeout_counter2 | |
| 36 bsf menubit | |
| 37 bsf cursor | |
| 38 call PLED_ClearScreen | |
| 39 call PLED_simulator_mask | |
| 40 | |
| 41 menu_simulator2: | |
| 42 bcf switch_left | |
| 43 bcf switch_right | |
| 44 bcf menubit2 | |
| 45 bcf menubit3 | |
| 46 call PLED_simulator_data | |
| 47 call PLED_menu_cursor | |
| 48 | |
| 49 menu_simulator_loop: | |
| 50 call check_switches_menu | |
| 51 menu_simulator_loop2: | |
| 52 btfss onesecupdate | |
| 53 bra menu_simulator_loop3 | |
| 54 | |
| 55 call timeout_surfmode | |
| 56 call set_dive_modes | |
| 57 call test_charger ; check if charger IC is active | |
| 58 call get_battery_voltage ; get battery voltage | |
| 59 | |
| 60 bcf onesecupdate ; End of one second tasks | |
| 61 | |
| 62 menu_simulator_loop3: | |
| 63 btfsc menubit2 | |
| 64 goto menu_simulator_do ; call submenu | |
| 65 | |
| 66 btfss menubit | |
| 67 goto menu ; exit setup menu and return to main menu | |
| 68 | |
| 69 btfsc sleepmode | |
| 70 goto more_menu | |
| 71 | |
| 72 btfsc divemode | |
| 73 goto restart ; exit menu, restart and enter divemode | |
| 74 | |
| 75 bra menu_simulator_loop | |
| 76 | |
| 77 menu_simulator_do: ; calls submenu | |
| 78 dcfsnz menupos,F | |
| 79 bra simulator_startdive | |
| 80 dcfsnz menupos,F | |
| 81 bra simulator_inc_bottomtime | |
| 82 dcfsnz menupos,F | |
| 83 bra simulator_inc_maxdepth | |
| 84 dcfsnz menupos,F | |
| 85 bra simulator_calc_deco | |
| 86 dcfsnz menupos,F | |
| 87 bra simulator_show_decoplan | |
| 88 movlw d'4' | |
| 89 movwf menupos | |
| 90 goto more_menu2 ; exit... | |
| 91 | |
| 92 simulator_inc_bottomtime: | |
| 93 movlw d'2' | |
| 94 addwf logbook_temp1,F ; Here: Bottomtime in m | |
| 95 movlw d'199' | |
| 96 cpfslt logbook_temp1 | |
| 97 movwf logbook_temp1 | |
| 98 movlw d'2' | |
| 99 movwf menupos | |
| 100 bra menu_simulator2 | |
| 101 | |
| 102 simulator_inc_maxdepth: | |
| 103 movlw d'3' | |
| 104 addwf logbook_temp2,F ; Here: Maxdepth in m | |
| 105 movlw d'99' | |
| 106 cpfslt logbook_temp2 | |
| 107 movwf logbook_temp2 | |
| 108 movlw d'3' | |
| 109 movwf menupos | |
| 110 bra menu_simulator2 | |
| 111 | |
| 112 simulator_startdive: | |
| 113 ; Descent to -3m depth | |
| 114 ; Set standalone_simulator flag (Displays Simulator menu during simulation by pressing ENTER button) | |
| 115 ; Clear standalone_simulator after (any) dive | |
| 116 bsf simulatormode_active ; normal simulator mode | |
| 117 bsf standalone_simulator ; Standalone Simulator active | |
| 118 | |
| 119 movff logbook_temp2,xA+0 | |
| 120 clrf xA+1 | |
| 121 movlw d'100' | |
| 122 movwf xB+0 | |
| 123 clrf xB+1 | |
| 124 call mult16x16 ;xA*xB=xC ; Depth in m*100 | |
| 125 | |
| 126 movlw LOW d'1000' | |
| 127 addwf xC+0,F | |
| 128 movlw HIGH d'1000' | |
| 129 addwfc xC+1,F ; Add 1000mBar | |
| 130 | |
| 131 movff xC+0,sim_pressure+0 | |
| 132 movff xC+1,sim_pressure+1 | |
| 133 | |
| 134 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values | |
| 135 movff sim_pressure+1,amb_pressure+1 | |
| 136 | |
| 137 bcf menubit2 | |
| 138 bcf menubit3 | |
| 139 bcf menubit | |
| 140 bcf switch_left | |
| 141 bcf switch_right | |
| 142 | |
| 143 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3 | |
| 144 | |
| 145 bsf divemode ; Set divemode flag | |
| 146 ostc_debug 'P' ; Sends debug-information to screen if debugmode active | |
| 147 goto diveloop ; Start Divemode | |
| 148 | |
| 149 simulator_save_tissue_data: | |
| 150 bsf restore_deco_data ; Set restore flag | |
| 151 ostc_debug 'S' ; Sends debug-information to screen if debugmode active | |
| 152 call main_push_tissues_to_vault | |
| 153 movlb 0x01 ; Back to RAM Bank1 | |
| 154 ostc_debug 'T' ; Sends debug-information to screen if debugmode active | |
| 155 return | |
| 156 | |
| 157 simulator_restore_tissue_data: | |
| 158 bcf restore_deco_data ; clear restore flag | |
| 159 ostc_debug 'S' ; Sends debug-information to screen if debugmode active | |
| 160 call main_pull_tissues_from_vault | |
| 161 movlb 0x01 ; Back to RAM Bank1 | |
| 162 ostc_debug 'T' ; Sends debug-information to screen if debugmode active | |
| 163 | |
| 164 ostc_debug 'G' ; Sends debug-information to screen if debugmode active | |
| 165 call deco_main_calc_desaturation_time ; calculate desaturation time | |
| 166 movlb b'00000001' ; select ram bank 1 | |
| 167 call calculate_noflytime ; Calc NoFly time | |
| 168 ostc_debug 'H' ; Sends debug-information to screen if debugmode active | |
| 169 return | |
| 170 | |
| 171 simulator_show_decoplan: | |
| 172 call PLED_ClearScreen | |
| 173 call divemenu_see_decoplan | |
| 174 | |
| 175 bcf switch_left | |
| 176 bcf switch_right | |
| 177 | |
| 178 simulator_show_decoplan2: | |
| 179 btfss onesecupdate | |
| 180 bra simulator_show_decoplan3 | |
| 181 | |
| 182 call timeout_surfmode | |
| 183 call set_dive_modes | |
| 184 call test_charger ; check if charger IC is active | |
| 185 call get_battery_voltage ; get battery voltage | |
| 186 | |
| 187 bcf onesecupdate ; End of one second tasks | |
| 188 | |
| 189 simulator_show_decoplan3: | |
| 190 btfsc switch_left | |
| 191 bra simulator_show_decoplan4 ; Quit display | |
| 192 | |
| 193 btfsc switch_right | |
| 194 bra simulator_show_decoplan4 ; Quit display | |
| 195 | |
| 196 btfsc sleepmode | |
| 197 goto more_menu | |
| 198 | |
| 199 btfsc divemode | |
| 200 goto restart ; exit menu, restart and enter divemode | |
| 201 | |
| 202 bra simulator_show_decoplan2 | |
| 203 | |
| 204 simulator_show_decoplan4: | |
| 205 movlw d'5' | |
| 206 movwf menupos | |
| 207 bra menu_simulator1 | |
| 208 | |
| 209 | |
| 210 simulator_calc_deco: | |
| 211 call diveloop_boot ; configure gases, etc. | |
| 212 | |
| 213 bsf simulatormode_active ; normal simulator mode | |
| 214 bsf standalone_simulator ; Standalone Simulator active | |
| 215 | |
| 216 | |
| 217 movff logbook_temp2,xA+0 | |
| 218 clrf xA+1 | |
| 219 movlw d'100' | |
| 220 movwf xB+0 | |
| 221 clrf xB+1 | |
| 222 call mult16x16 ;xA*xB=xC ; Depth in m*100 | |
| 223 | |
| 224 movlw LOW d'1000' | |
| 225 addwf xC+0,F | |
| 226 movlw HIGH d'1000' | |
| 227 addwfc xC+1,F ; Add 1000mBar | |
| 228 | |
| 229 movff xC+0,sim_pressure+0 | |
| 230 movff xC+1,sim_pressure+1 | |
| 231 | |
| 232 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values | |
| 233 movff sim_pressure+1,amb_pressure+1 | |
| 234 | |
| 235 call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3 | |
| 236 | |
| 237 WIN_INVERT .1 | |
| 238 DISPLAYTEXT .12 ;" Wait.." | |
| 239 WIN_INVERT .0 | |
| 240 | |
| 241 simulator_calc_deco_loop1: | |
| 242 movlw d'30' | |
| 243 movwf logbook_temp3 ; 30x/Minute | |
| 244 call PLED_simulator_data | |
| 245 | |
| 246 ; movlw .011 | |
| 247 ; call PLED_SetColumn | |
| 248 ; movlw .009 | |
| 249 ; call PLED_SetRow | |
| 250 ; lfsr FSR2,letter | |
| 251 ; movff char_O_array_decodepth+0,lo ; Get Depth | |
| 252 ; bsf leftbind | |
| 253 ; output_8 | |
| 254 ; bcf leftbind | |
| 255 ; movlw ' ' | |
| 256 ; movwf POSTINC2 | |
| 257 ;call word_processor | |
| 258 | |
| 259 | |
| 260 simulator_calc_deco_loop2: | |
| 261 call toggle_LEDr | |
| 262 | |
| 263 call divemode_check_decogases ; Checks for decogases and sets the gases | |
| 264 call divemode_prepare_flags_for_deco | |
| 265 | |
| 266 call deco_main_calc_hauptroutine ; calc_tissue | |
| 267 movlb b'00000001' ; rambank 1 selected | |
| 268 ostc_debug 'C' ; Sends debug-information to screen if debugmode active | |
| 269 | |
| 270 decfsz logbook_temp3,F | |
| 271 bra simulator_calc_deco_loop2 | |
| 272 decfsz logbook_temp1,F | |
| 273 bra simulator_calc_deco_loop1 | |
| 274 | |
| 275 movff char_O_deco_status,deco_status ; | |
| 276 tstfsz deco_status ; deco_status=0 if decompression calculation done | |
| 277 bra simulator_calc_deco2 ; Not finished | |
| 278 | |
| 279 simulator_calc_deco3: | |
| 280 call set_LEDr | |
| 281 | |
| 282 call simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3 | |
| 283 | |
| 284 bcf simulatormode_active ; normal simulator mode | |
| 285 bcf standalone_simulator ; Standalone Simulator active | |
| 286 | |
| 287 WAITMS d'250' | |
| 288 WAITMS d'250' | |
| 289 WAITMS d'250' ; Wait for Pressure Sensor to get real pressure again... | |
| 290 | |
| 291 call clear_LEDr | |
| 292 | |
| 293 movlw d'1' | |
| 294 movwf logbook_temp1 ; Bottom time>0! | |
| 295 | |
| 296 movlw d'5' ; Pre-Set Cursor to "Show Decoplan" | |
| 297 movwf menupos | |
| 298 bra menu_simulator1 ; Done. | |
| 299 | |
| 300 simulator_calc_deco2: | |
| 301 call divemode_check_decogases ; Checks for decogases and sets the gases | |
| 302 call divemode_prepare_flags_for_deco | |
| 303 | |
| 304 call deco_main_calc_hauptroutine ; calc_tissue | |
| 305 movlb b'00000001' ; rambank 1 selected | |
| 306 | |
| 307 movff char_O_deco_status,deco_status ; | |
| 308 tstfsz deco_status ; deco_status=0 if decompression calculation done | |
| 309 bra simulator_calc_deco2 ; Not finished | |
| 310 bra simulator_calc_deco3 ; finished! |
