'>Hxtr3-0.BSx 'ver 3.1 update prog6 dmo0 menu line DEBUG "prog0" '============================================================== 'debug cls 'Parallax bug fix for Windoz Editor ver1.1 'must have a debug stmnt as first executable stmnt in page0 'otherwise editor will not always load some higher pages. '================================================================ '{$stamp BS2sx,Hxtr3-1,Hxtr3-2,Hxtr3-3,Hxtr3-4,Hxtr3-5,Hxtr3-6,Hxtr3-7} 'Unfortunately that was a long line, ask Parallax. '============================================================== 'Hxtr3-0.BSx - Main 'Hxtr3-1.BSx - Activity sequencer 'Hxtr3-2.BSx - US Behaviour 'Hxtr3-3.BSx - Direct Control 'Hxtr3-4.BSx - Prog4 'Hxtr3-5.BSx - Prog5 'Hxtr3-6.BSx - LCD menu 'Hxtr3-7.BSx - Utils- LCD control and IR remote 'Hxtr3-Doc.BSx - Meta Commands and Program Headers '============================================================== 'Milford Instruments http://www.milinst.com 'Hextor Design, Bug Commander - Behavioural Operating System 'and the Behavioural Controller programs by David Buckley '============================================================== 'New '--- 'LCD-menu and Main-Behaviour-Controller moved to Prog6 'flags moved from CommonRAM9 to CommonRAM10 'CommonRAM7,8,9 now mopts,menc,mendo 'get 10,flags moved to init: update flags put in init1: 'Qutil: used dmenc now uses menc 'Dprog 11,Dmenc 12 added to Common Ram 'Option 1 added to save Dprog, Dmenc in EEPROM 'init and following rewritten to allow for ' default action in EEPROM ' Prog0 Option1 ' LCD menu in Prog6 'BOSver asked for at ColdStart ->CRAM14 'Default Prog and Option written to CRAM so Menu6 knows the defaults ' 'Required knowledge: ' 'Common RAM: Dprog 11,Dmenc 12, BOSver 14, added 'Constants: 'Variables: 'Routine: warmS, coldS, O6_1_setdflt 'Subroutine: 'Labels: Dflt 'LCD text: 'Behaviours: '============================================================== 'Activities name-table program1 '------------------------------ A_null CON 0 A_chirp1 CON 1 A_beep2 CON 2 A_wiggle1 CON 3 A_wiggle2 CON 4 A_wiggle3 CON 5 A_Qs4r170 CON 6 A_Ts0r200 CON 7 A_tround CON 8 A_beg CON 9 A_Rface CON 10 A_Lface CON 11 A_F5 CON 12 A_R5 CON 13 A_L5 CON 14 A_BR CON 15 A_BL CON 16 A_L3 CON 17 A_R3 CON 18 A_L2 CON 19 A_R2 CON 20 A_Iflash CON 21 A_Fbump CON 22 A_FbumpRI1 CON 23 A_FbumpLI2 CON 24 A_FbumpBI3 CON 25 A_last CON 25 'last routine 'Ultrasonic-behaviour name-table program2 '---------------------------------------- US_null CON 0 US_sitby CON 1 US_beg CON 2 US_hello CON 3 US_wander CON 4 US_user1 CON 5 US_user2 CON 6 US_user3 CON 7 US_user4 CON 8 US_last CON 8 'last routine 'Utilities name-table program7 '------------------------------ U_KlcdCon CON 1 U_KirCon CON 2 U_last CON 2 'last routine '-------------------------------------------------------------- 'common RAM '0 program to return to - all '1 Program option - Activity to do, USrules to do, Options '2 current Utility routine '3 usyawn0 - US-behaviour '4 usyawn1 - US-behaviour '5 irin - current IR value on change of pgm '6 oldbtn - current button on change of pgm '7 mopts - active menu OAUIP '8 menc - active menu displayed choice '9 mendo - selected choice '10 flags - various flag bits ' bit0=irwatch - 0=>ignore IR signal, 1=>act on it ' bit1=useLEDs - 0=>ignore LED cmnds, 1=>enable LEDs ' (for if pins remapped) ' bit2=usefeelers - 0=>ignore feelers ' bit3=useUS - 0=>don't run US routines ' bit4=warmIR - 1=>IR chip needs no warmup time ' bit7=flagsvalid - 0 after download, 1->ok '11 Dprog - Default program to run '12 Dmenc - Default option '13 lcmnds - number of learned BOScmnds Prog7LCDmenu '14 BOSver - BOS version '15 BOScmnd for Learning and Playing - to pass between Prog5 and Prog7 '16 Act - current Act being Learned/Played - used by Prog5/7 '17 pAct - current step in Act - used by Prog5 '18 IRpage 'Note there is no test for the stack being too big, beware of 'the stack growing down through RAM variables! '60 down sequence stack '61 sequence stack pointer '62 letterbox for push and pop '63 active program number used by BS2Sx '-------------------------------------------------------------- 'LCD commands. 'For more detailed information see the ILM-216 User Manual. 'Function ASCII '-------- ----- 'Null 0 'Cursor home 1 'Hide cursor 4 'Show underline cursor 5 'Show blinking-block cursor 6 'Bell (not implemented with Hextor LCD) 7 'Backspace 8 'Horezontal tab (4 columns) 9 'Smart linefeed (cursor down one line) 10 'Vertical tab (cursor up one line) 11 'Formfeed (clear screen) 12 'Carriage return 13 'Backlight on 14 'Backlight off 15 'Accept cursor position entry 16 ' 64 is the start of the first line ' 80 is the start of the second line 'Format right aligned text 18 'Escape (ESC; start multipart instruction) 27 ' ------------------- ' | LCD | ' ------------------- 'LCD keys - bit0 bit1 bit2 bit3 '--------- initialisation data -------------------------------- dDprog DATA @0 dDoption DATA @1 dflagb DATA @2 '-------------------------------------------------------------- BOStx CON 0 'pin serial to BOS processor BOSrx CON 1 'pin serial from BOS processor epower CON 2 'pin high turns on power to electronics BOShalt CON 3 'pin high halts current BOS move BOSbusy VAR IN4 'pin BOS processor busy => high irrx CON 5 'pin infra red comms in, i96n lcdtx CON 6 'pin to send to LCD lcdrx CON 7 'pin to receive from LCD Rled CON 8 'pin high turns on right green led Lled CON 9 'pin high turns on left red led outRled VAR OUT8 'pin high turns on right green led outLled VAR OUT9 'pin high turns on left red led ustx CON 14 'pin ultrasonic commands, i96n usrx CON 15 'pin ultrasonic data in, i96n i96n CON 16624 '9600 baud, 8 bit, no parity, inverted tpace CON 50 'transmit pace time poweruptime CON 1500 'pause before powering up electronics 'nocmnd con 15 'Kir - no command pending BOScmnd VAR Byte 'byte to send to BOS processor arg VAR Word arg1 VAR arg.LOWBYTE 'command argument arg2 VAR arg.HIGHBYTE 'command argument argl VAR arg.LOWBYTE argh VAR arg.HIGHBYTE Prog VAR argh.HIGHNIB 'irin var byte 'infra-red command lcdbtns VAR Byte 'button states are in lower nibble tempb VAR lcdbtns option VAR tempb 'btn1state var lcdbtns.bit0 'btn2state var lcdbtns.bit1 'btn3state var lcdbtns.bit2 'btn4state var lcdbtns.bit3 'btn var lcdbtns.highnib '0 - 4 current button 'oldbtn var nib '0 - 4 last button state 'lcdmsg var word 'pointer to current char in text 'lcdchar var byte 'character to send to LCD menc VAR Byte 'current menu Choice 'mopts var byte 'Menu options set 'mendo var byte 'selection chosen by OK 'name var byte stkp VAR Byte 'point to top of CommonRam stack 'dmbase var word 'pointer to entry 0 of current menu Fdefaults CON %10001110 'default Fvalid,x,x,x,FusON,FeelON,LEDsON,irOFF flags VAR Byte 'various flags 'Firwatch var flags.bit0 '1=>watch for IR 'Fuseleds var flags.bit1 'future prog1 'Fusefeel var flags.bit2 'future prog1 'FusekUS var flags.bit3 'future prog2 'FwarmIR var flags.bit4 'write6,write7 'Flearn var flags.bit5 'write7 Fflagsvalid VAR flags.BIT7 'during downloading the power to the electronics is turned off, 'if it is turned back on again too soon the electronics do not 'power up properly,so wait 1 second before turning power on. 'Also lcd needs to initialise after power turned on. init: OUTPUT Rled OUTPUT Lled HIGH Rled HIGH Lled GET 10,flags IF Fflagsvalid=1 THEN warmS coldS: 'coldStart 'if Fflagsvalid=0 then PowerOn/Reset Run0 DEBUG"cold" GOSUB getBOSver PUT 61,61 'initialise stack pointer GET 61,stkp 'get stack pointer READ dflagb,flags IF Fflagsvalid=1 THEN putF '=0 until initialised flags =Fdefaults 'not valid so initialise WRITE dflagb,flags putF: PUT 10,flags PAUSE poweruptime READ 0,Prog 'default DO program PUT 11,Prog 'write default DO Program READ 1,tempb 'read Default Option PUT 12,tempb 'write default DO Option PUT 1,tempb 'put it in CRAM1-option IF Prog+tempb=0 THEN warmS 'if Prog and Option both are 0 then nothing to run Dflt: SEROUT lcdtx,i96n,[12,16,64,"Default",16,80,"any key to quit"] RUN Prog 'Default DO warmS: 'warmStart - omit stack initialisation and poweron wait GET 10,flags 'bit0 - irwatch 1=>watch WRITE dflagb,flags 'update flags GET 61,stkp 'get stack pointer HIGH epower 'turn on electronics BOScmnd ="V" 'beep GOSUB tellBOSc 'once PAUSE 200 GOSUB tellBOSc 'and again GET 1,option 'read doActivity PUT 1,0 'so we don't do it again and ... 'DEBUG?option IF option=1 THEN O6_1_setdflt Qutil: GET 2,menc 'current utility routine? 'DEBUG?menc IF menc=0 THEN Qstack RUN 7 'continue with utility routine Qstack: 'DEBUG ?stkp IF stkp<>61 THEN stackstart 'some routine on stack LCDmenu: RUN 6 'otherwise do LCDmenu stackstart: GOSUB pop_arg 'get which Prog=argh.HIGHNIB GOSUB push_arg 'put info back PUT 1,0 'no common ram info on routine RUN Prog 'Option1 from 6-LCDMenu O6_1_setdflt: GET 12 ,tempb 'DefaultOption WRITE dDoption,tempb 'save GET 11 ,tempb 'DefaultProg WRITE dDprog,tempb 'save RUN 6 'back LCDmenu '------------- subroutines --------------------- getBOSver: 'for some reason after poweron BOS reports 118 the first time asked!!!??? BOScmnd ="?" arg1 ="v" GOSUB tellBOScc GOSUB BOSreplyd PUT 14,arg1 'put BOSver in commonRAM14 'DEBUG"BOSver",DEC arg1 BOScmnd ="?" arg1 ="v" GOSUB tellBOScc GOSUB BOSreplyd PUT 14,arg1 'put BOSver in commonRAM14 DEBUG"BOS",DEC arg1 RETURN '------------------------------- push: 'stacks the single byte in letterbox=CRAM62 GET 61,stkp '61 is stack pointer stkp =stkp -1 'next location GET 62,tempb 'read letterbox PUT stkp,tempb 'push byte PUT 61,stkp 'save pointer RETURN '------------------------------- pop: 'unstacks a single byte into letterbox=CRAM62 GET 61,stkp '61 is stack pointer GET stkp,tempb 'pop byte stkp =stkp+1 MAX 61 'previous max top+1 PUT 62,tempb 'byte to letter box PUT 61,stkp 'save pointer RETURN '------------------------------- push_arg: 'stacks the word arg PUT 62,argl GOSUB push PUT 62,argh GOSUB push RETURN '------------------------------- pop_arg: 'unstacks the word arg GOSUB pop GET 62,argh GOSUB pop GET 62,argl RETURN '-------------------- tellBOSc: 'used for the initialisation beeps PAUSE 10 'give the BOS time to go into receive mode IF BOSbusy=1 THEN tellBOSc 'wait until BOS not busy SEROUT BOStx,i96n,[BOScmnd] RETURN '-------------------- tellBOScc: PAUSE 10 'give the BOS time to go into receive mode IF BOSbusy=1 THEN tellBOScc 'wait until BOS not busy SEROUT BOStx,i96n,tpace,[BOScmnd,arg1] RETURN '-------------------- BOSreplyd: 'wait min 40 SERIN BOSrx,i96n,100,_BOSr1d,[DEC arg1] 'get byte _BOSr1d: RETURN '-------------------- '------------------------ end program -------------------------