DRUID Development Docs: gout_com.inc

Gadget Sourcecode: gout_com.inc

; Justice Unlimited Gadget Microcode
; (C) 2004 Nathan (Acorn) Pooley 
;
; gout_com.inc
;
;@DOC@ code for outputing characters to the display
;@DOC@ This code is common;  ie it is not specific to the
;@DOC@ serial or the parallel interface
;


;
; high level output functions (common to serial vs parallel)
;

;############################################
;############### DISPLAY NAMED STRING #######
;############################################

    ;
    ; display string
    ; w is index of string to show (0-255)
    ;
puts:
    rcall   string_find     ; find the string

    ;
    ; fall thru to display string
    ;


;############################################
;############### DISPLAY ADDRESSED STRING ###
;############################################
    ;
    ; display string
    ; v_str_addrlo, v_str_addrhi should hold address of string
    ;
puts_addr:
    rcall   string_setup_read   ; setup to read from v_str_addrhi/lo

    tblrd*+             ; read len and increment to first data byte
    movff   TABLAT,v_str_cnt    ; length of string
    
puts_loop:
    tblrd*+                 ; get character
    movf    TABLAT,w
    rcall   putc
    decfsz  v_str_cnt
    bra     puts_loop   

    return  

;############################################
;############### GET NEXT CHAR FROM STRING ##
;############################################
    ;
    ; This is used by special character functions
    ; to get the next character from the current string
    ; This should be called from within puts.
    ;
    ; next char is returned in w
puts_nextc:
    tblrd*+                 ; get character
    movf    TABLAT,w
    decfsz  v_str_cnt
    return

    bra     error_nextc     ; if this is last char then TROUBLE!



;############################################
;############### FIND NAMED STRING ##########
;############################################

    ;
    ; find string
    ; w is index of string to show (0-255)
    ;
string_find:
    movwf   v_str_cnt
    movlw   LOW strings
    movwf   v_str_addrlo
    movlw   HIGH strings
    movwf   v_str_addrhi

    bra string_add_cnt  ; find the string

;############################################
;############### ADD STRINGS ################
;############################################

    ;
    ; find next string
    ;
string_inc:
    movlw   0x01

    ;
    ; add w to v_str_addrhi, v_str_addrlo
    ; w can be 0 (and nothing is added)
    ;
string_add:
    movwf   v_str_cnt

    ;
    ; add v_str_cnt to v_str_addrhi, v_str_addrlo
    ; v_str_cnt can be 0 (and nothing is added)
    ;
string_add_cnt:
    movf    v_str_cnt,f
    bz      string_add_done
    rcall   string_setup_read   ; setup to read from v_str_addrhi/lo

string_add_loop:
    tblrd*+             ; read len and increment to first data byte

    movf    TABLAT,w    ; add len to get to next string
    addwf   TBLPTRL,f
    clrf    WREG
    addwfc  TBLPTRH,f
    
    decfsz  v_str_cnt,f
    bra     string_add_loop

    movff   TBLPTRL, v_str_addrlo
    movff   TBLPTRH, v_str_addrhi

string_add_done:
    return

;############################################
;############### PREPARE TO READ STRING DATA 
;############################################

    ;
    ; setup to read data from v_str_addrhi/lo
    ;
string_setup_read:
    bcf     b_cfgs      ; access program mem (not config regs)
    bsf     b_eepgd     ; access program mem (not eeprom)
    movff   v_str_addrlo, TBLPTRL
    movff   v_str_addrhi, TBLPTRH
    clrf    TBLPTRU     ; zero the pointer
    return

;############################################
;############### PUT LINE ###################
;############################################
    ;
    ; put string at line 0 or 1
    ;   Will draw spaces to fill up remainder of line
    ;   w should contain string ID
    ;   v_linenum should contain line (only low bit is used)
    ;        xxxxxxx0 = line1
    ;        xxxxxxx1 = line2
    ;
putl:
    rcall   string_find

    ;
    ; same as putl, but string is in v_str_addrhi/lo
    ;
putl_addr:
    ;
    ; move cursor to start of line
    ;
    rcall   put_position_linestart

    ;
    ; draw string, counting characters
    ;
    rcall   puts_addr

    ;
    ; how many characters left on line?
    ;
    movlw   LOW -20
    addwf   v_putc_cnt,f

    movf    v_putc_cnt,w    ; cnt
    addlw   LOW -20         ; cnt-20
    bnn     putl_end        ; no spaces needed
putl_loop:
    movlw   0x20            ; draw a space
    rcall   putc_raw
    movf    v_putc_cnt,w
    bn      putl_loop

putl_end:
    return




;############################################
;############### SPECIAL CHARACTERS #########
;############################################

    ;
    ; print game time
    ;
sc_game_time:
    movf    v_time_h,w
sc_time_common:
    movff   v_time_m, v_ptime_min
    movff   v_time_s, v_ptime_sec
sc_time_common2:
    bsf     b_showing_time
    bra     put_time

    ;
    ; print real time (12 hour clock)
    ;
sc_real_time:
    movf    v_time_h,w
    addlw   GAME_START_HOUR
sc_real_time_loop:
    addlw   LOW -12
    btfss   STATUS,Z        
    bnn     sc_real_time_loop

    addlw   12
    bra     sc_time_common

sc_clue_time:
    movf    v_cluetime_h,w
    movff   v_cluetime_m, v_ptime_min
    movff   v_cluetime_s, v_ptime_sec
    movf    v_cluenum,f
    btfss   STATUS,Z
    bra     sc_time_common2
    clrf    WREG
    clrf    v_ptime_min
    clrf    v_ptime_sec
    bra     sc_time_common2


#if REPORT_ERRORS
    ;
    ; error counts
    ;
#if 0
sc_oerr_restart:
    movf    v_oerrcnt_restart,w
    bra     putnum_w
sc_oerr_noack:
    movf    v_oerrcnt_noack,w
    bra     putnum_w
sc_oerr_en_retry:
    movf    v_oerrcnt_en_retry,w
    bra     putnum_w
sc_oerr_bus:
    movf    v_oerrcnt_bus,w
    bra     putnum_w
sc_oerr_wcol:
    movf    v_oerrcnt_wcol,w
    bra     putnum_w
sc_oerr_nosspif:
    movf    v_oerrcnt_nosspif,w
    bra     putnum_w
#endif
sc_cnt_turnon:
    movf    v_cnt_turnon,w
    bra     putnum_w
sc_cnt_outenab:
    movf    v_cnt_outenab,w
    bra     putnum_w

#else
sc_oerr_restart:
sc_oerr_noack:
sc_oerr_enable:
sc_oerr_en_retry:
sc_oerr_bus:
sc_oerr_wcol:
sc_oerr_nosspif:
sc_cnt_turnon:
sc_cnt_outenab:
    movlw   '?'
    bra     putc
#endif


#if 1
    ;
    ; print ir rx results
    ;
sc_irlook:
    rcall   input_disable
    rcall   light_stay_off

    ENABLE_IR
    movlw   1
    movwf   v_ircnt     ; track counts
    clrf    v_ircnt2
    bcf     b_int0if

sc_irlook_1:
    movlw   4
    movwf   v_ircnt2

sc_irlook_2:

    movlw   150
    movwf   v_tmp
sc_irlook_3
    btfss   but_click
    bra     sc_irlook_done  ; finish on click

    btfss   b_int0if
    bra     sc_irlook_4

    bcf     b_int0if

    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_OFF   

    incf    v_ircnt,f
    movf    v_ircnt,w
    addlw   -20
    btfsc   STATUS,Z
    decf    v_ircnt,f


sc_irlook_4:
    decfsz  v_tmp,f
    bra     sc_irlook_3

    call    reset_sleep_time


    dcfsnz  v_ircnt,f
    incf    v_ircnt,f

    decfsz  v_ircnt2,f
    bra     sc_irlook_2

    movlw   20
    rcall   put_position

    incf    v_ircnt,w
    movwf   v_tmp

sc_irlook_bar:
    movlw   0xff        ; black square
    rcall   putc
    decfsz  v_tmp,f
    bra     sc_irlook_bar


    movf    v_ircnt,w   
    sublw   21
    movwf   v_tmp

sc_irlook_spc:
    movlw   ' '
    rcall   putc
    decfsz  v_tmp,f
    bra     sc_irlook_spc



    bra     sc_irlook_1


sc_irlook_done:
    call    reset_sleep_time
    DISABLE_IR
    btfss   but_click
    bra     sc_irlook_done      ; wait for no button pressed

    movlw   func_fn_pop
    bsf     b_spinchange        ; ensure it is displayed again
    movwf   v_func_spinchange
    movwf   v_func_btn0_click
    movlw   20
    movwf   v_putc_cnt
    return


#else
    ;
    ; print ir rx results
    ;
sc_irlook:
    rcall   reset_sleep_time    ; do not fall asleep
    bsf     b_spinchange        ; ensure it is displayed again

    incf    v_ircnt2,f

    btfsc   disab_irrx
    bra     sc_irlook_first     ; first time? - do setup
    btfss   b_int0if
    bra     sc_irlook_none
    bcf     b_int0if
    incf    v_ircnt,f
    incf    v_ircnt,f

;   call    snd_click
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_OFF

sc_irlook_none:
    dcfsnz  v_ircnt,f
    incf    v_ircnt,f       ; min = 1

    movf    v_ircnt,w       
    addlw   -20
    btfsc   STATUS,C
    movlw   -1
    addlw   20


    movwf   v_ircnt


    incf    v_ircnt,w
    movwf   v_tmp

sc_irlook_bar:
    movlw   0xff        ; black square
    rcall   putc
    decfsz  v_tmp,f
    bra     sc_irlook_bar


sc_irlook_first:
    DISABLE_SPINNER
    ENABLE_IR
    movlw   1
    movwf   v_ircnt     ; track counts
    clrf    v_ircnt2
    bcf     b_int0if
    return
#endif

#if 0
    ; draw bar of len=W, w=0..19

draw_bar:
    addwf   LOW -19
    btfsc   STATUS,C
    movlw   LOW -1
    addlw   20
    movwf   v_tmp

    movlw   20
    rcall   putc_position

    movlw   0xff
draw_bar_loop:
    rcall   putc
    decfsz  v_tmp,f
    bra     draw_bar_loop

    movlw   19
    movwf   v_tmp
    movlw   ' '
draw_bar_spc:
    rcall   putc
    decfsz  v_tmp,f
    bra     draw_bar_spc

    return

#endif




This file Copyright (C) 2004 by Nathan (Acorn) Pooley
Go to DRUID Development page
Go to DRUID page
Go to JU Gadgets page
Go to Justice Unlimited homepage
Go to Acorn's personal webpage
Contact Acorn
See comments from others
Post your own comments
File created by do_doc at Wed Aug 4 17:55:00 2004