;************************************************************************** ; FILE: lotto.asm * ; CONTENTS: 'Lottomania' * ; COPYRIGHT: MadLab Ltd. 1995 * ; AUTHOR: James Hutchby * ; UPDATED: 06/10/99 * ;************************************************************************** ; list p=16C54A list p=16C54C include "p16c5x.inc" __config _RC_OSC & _WDT_ON & _CP_ON __idlocs h'AD11' errorlevel -305 ;************************************************************************** ; * ; Specification * ; * ;************************************************************************** ; National Lottery mode :- ; RESET/MODE button clears ; NEXT button generates a random number from 1 to 49 ; subsequently generates a random number from 1 to 48 ; and so on until 6 numbers have been generated ; single die mode :- ; RESET/MODE button clears ; NEXT button generates a random number from 1 to 6 ; double dice mode :- ; RESET/MODE button clears ; NEXT button generates a pair of random numbers from 1 to 6 ; heads or tails mode :- ; RESET/MODE button clears ; NEXT button generates a random heads or tails ; 1-player reaction timer mode :- ; RESET/MODE button clears ; NEXT button starts count after random time interval ; NEXT button stops count and displays reaction time ; count stops at 99 and flashes ; 2-player reaction tester mode :- ; RESET/MODE button clears ; NEXT button displays 'XX' after random time interval ; RESET/MODE button displays '1 ' ; NEXT button displays ' 2' ; tracker game mode :- ; NEXT button displays '55' ; high digit counts up and down at random ; RESET/MODE button counts low digit down ; NEXT button counts low digit up ; digits wrap around 0 to 9 ; if absolute difference between high and low digits is greater ; than 3 then stops counting and flashes digits ; high digit counts progressively faster ; RESET/MODE button held down for ~2 seconds -> mode select ; button held down -> mode cycles ;************************************************************************** ; * ; Port assignments * ; * ;************************************************************************** PORTA_IO equ b'1100' ; port A I/O status PORTB_IO equ b'00000000' ; port B I/O status LEDS equ PORTB ; 7-segment LEDs #define ENABLE_HI PORTA,0 ; high character enable #define ENABLE_LO PORTA,1 ; low character enable BUTTONS equ PORTA ; buttons BUTTON1 equ 2 ; button1 (RESET/MODE) BUTTON2 equ 3 ; button2 (NEXT) CA equ 0 ; set if common anode 7-segment CC equ 1 ; set if common cathode 7-segment ;************************************************************************** ; * ; Constants and timings * ; * ;************************************************************************** CLOCK equ d'2000000' ; processor clock frequency in Hz DELAY_PERIOD equ d'120' ; button poll period (~1/16 s) REACT_PERIOD equ d'12' ; reaction timer poll period DISPLAY_PERIOD equ d'10' ; display multiplex period PATTERN_PERIOD equ d'40' ; pattern cycle period SELECT_PERIOD equ d'35' ; mode select period CYCLE_PERIOD equ d'15' ; mode cycle period MIN_REACT equ d'8' ; minimum reaction wait time MAX_REACT equ d'60' ; maximum reaction wait time MIN_TRACK equ d'22' ; minimum tracker speed MAX_TRACK equ d'4' ; maximum tracker speed TRACK_STEP equ d'100' ; tracker step speed TRACK_INC equ d'5' ; step speed increment NMODES equ d'7' ; number of modes NBALLS equ d'49' ; total number of balls NSELECT equ d'6' ; number of balls to select NBYTES equ (NBALLS+d'7')/d'8' REACT equ MAX_REACT-MIN_REACT ;************************************************************************** ; * ; File register usage * ; * ;************************************************************************** cblock h'07' flags ; various flags work1, work2 ; work registers char ; character to display (0 = high, h'ff' = low) char_hi, char_lo ; high and low characters save_hi, save_lo ; saved characters timer ; timer range ; random number range random ; random number selection react:0 ; reaction time track, track_ ; tracker speed step, step_ ; step speed mode ; mode :- ; 0 = National Lottery ('49') ; 1 = single die (' 6') ; 2 = double dice ('66') ; 3 = heads or tails ('ht') ; 4 = 1-player reaction timer ('G1') ; 5 = 2-player reaction tester ('G2') ; 6 = tracker game ('G3') ball ; ball index mask ; ball flags mask used:NBYTES ; ball used flags endc ; flags RELEASE equ 0 ; set if waiting for release FLASH equ 1 ; set if display to be flashed ;************************************************************************** ; * ; Macros * ; * ;************************************************************************** routine macro label ; routine label endm table macro label ; define lookup table label addwf PCL endm entry macro value ; define table entry retlw value endm index macro label ; index lookup table call label endm jump macro label ; jump through table goto label endm tstw macro ; test w register iorlw 0 endm movff macro f1,f2 ; move file to file movfw f1 movwf f2 endm movlf macro n,f ; move literal to file movlw n movwf f endm org 0 ;************************************************************************** ; * ; lookup tables * ; * ;************************************************************************** SPC equ d'10' DASH equ d'11' HEADS equ d'12' TAILS equ d'13' GAME equ d'14' BARS equ d'15' PATTERN_LO equ d'16' PATTERN_HI equ d'21' ; A = 2, B = 3, C = 6, D = 5, E = 4, F = 0, G = 1, DP = 7 table LEDS_hi ; high 7-segment LEDs entry b'01111101' ; ABCDEF. = '0' entry b'01001000' ; .BC.... = '1' entry b'00111110' ; AB.DE.G = '2' entry b'01101110' ; ABCD..G = '3' entry b'01001011' ; .BC..FG = '4' entry b'01100111' ; A.CD.FG = '5' entry b'01110011' ; ..CDEFG = '6' entry b'01001100' ; ABC.... = '7' entry b'01111111' ; ABCDEFG = '8' entry b'01001111' ; ABC..FG = '9' entry b'00000000' ; ....... = ' ' entry b'00000010' ; ......G = '-' entry b'01010011' ; ..C.EFG = 'h' entry b'00110011' ; ...DEFG = 't' entry b'01110101' ; A.CDEF. = 'G' entry b'00001111' ; AB...FG entry b'00001100' ; AB..... entry b'01001000' ; .BC.... entry b'01100000' ; ..CD... entry b'00110000' ; ...DE.. entry b'00010001' ; ....EF. entry b'00000101' ; A....F. ; A = 2, B = 1, C = 5, D = 7, E = 0, F = 3, G = 6, DP = 4 table LEDS_lo ; low 7-segment LEDs entry b'10101111' ; ABCDEF. = '0' entry b'00100010' ; .BC.... = '1' entry b'11000111' ; AB.DE.G = '2' entry b'11100110' ; ABCD..G = '3' entry b'01101010' ; .BC..FG = '4' entry b'11101100' ; A.CD.FG = '5' entry b'11101001' ; ..CDEFG = '6' entry b'00100110' ; ABC.... = '7' entry b'11101111' ; ABCDEFG = '8' entry b'01101110' ; ABC..FG = '9' entry b'00000000' ; ....... = ' ' entry b'01000000' ; ......G = '-' entry b'01101001' ; ..C.EFG = 'h' entry b'11001001' ; ...DEFG = 't' entry b'10101101' ; A.CDEF. = 'G' entry b'11100001' ; ..CDE.G entry b'00000110' ; AB..... entry b'00100010' ; .BC.... entry b'10100000' ; ..CD... entry b'10000001' ; ...DE.. entry b'00001001' ; ....EF. entry b'00001100' ; A....F. table mode_hi ; mode display high character entry d'4' ; National Lottery entry SPC ; single die entry d'6' ; double dice entry HEADS ; heads or tails entry GAME ; reaction timer entry GAME ; reaction tester entry GAME ; tracker game table mode_lo ; mode display low character entry d'9' ; National Lottery entry d'6' ; single die entry d'6' ; double dice entry TAILS ; heads or tails entry d'1' ; reaction timer entry d'2' ; reaction tester entry d'3' ; tracker game table range_table ; random number range entry NBALLS ; National Lottery entry d'6' ; single die entry d'6'*d'6' ; double dice entry d'2' ; heads or tails entry REACT ; reaction timer entry REACT ; reaction tester entry d'2' ; tracker game table base_table ; number base entry d'10' ; National Lottery entry d'6' ; single die entry d'6' ; double dice entry d'2' ; heads or tails entry d'10' ; reaction timer table mode_jump ; mode jump table goto mode0 goto mode1 goto mode2 goto mode3 goto mode4 goto mode5 goto mode6 ;************************************************************************** ; * ; Procedures * ; * ;************************************************************************** ;-------------------------------------------------------------------------- ; tests the reset/mode button ;-------------------------------------------------------------------------- routine test_reset movlw 1<